Skip to content

Commit

Permalink
release: 0.0.5 (#17)
Browse files Browse the repository at this point in the history
* chore(internal): codegen related update (#16)

* chore(tests): update prism version (#18)

* feat(api): update via SDK Studio (#19)

* fix(compat): remove ReadableStream polyfill redundant since node v16 (#21)

Note that this breaks streaming in Node v14, which has been unsupported since v4.0.0 of this library.

* chore(docs): fix incorrect client var names (#22)

* chore(internal): add constant for default timeout (#23)

* feat(api): OpenAPI spec update via Stainless API (#24)

* feat(api): update via SDK Studio (#25)

* chore(internal): codegen related update (#26)

* chore(ci): correctly tag pre-release npm packages (#27)

* chore(internal): codegen related update (#28)

* release: 0.0.5

---------

Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
  • Loading branch information
stainless-app[bot] authored Aug 1, 2024
1 parent 5923664 commit 617733b
Show file tree
Hide file tree
Showing 31 changed files with 275 additions and 227 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
pull_request:
branches:
- main
- next

jobs:
lint:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release-doctor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Release Doctor
on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.prism.log
node_modules
yarn-error.log
codegen.log
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.0.4"
".": "0.0.5"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 38
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/plastic-labs%2Fhoncho-7967581df14089cda98ce7bd258102d5da5ec541dc5b17aa918f96be11a2bde8.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/plastic-labs%2Fhoncho-9b368f4c227f4695fb1b16d44996ca0dcaab52c7ee1433491ce2989fee846115.yml
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Changelog

## 0.0.5 (2024-08-01)

Full Changelog: [v0.0.4...v0.0.5](https://github.com/plastic-labs/honcho-node/compare/v0.0.4...v0.0.5)

### Features

* **api:** OpenAPI spec update via Stainless API ([#24](https://github.com/plastic-labs/honcho-node/issues/24)) ([f1760b0](https://github.com/plastic-labs/honcho-node/commit/f1760b014808b25acacea1dbe58d0e67e78b0709))
* **api:** update via SDK Studio ([#19](https://github.com/plastic-labs/honcho-node/issues/19)) ([d58ce64](https://github.com/plastic-labs/honcho-node/commit/d58ce641232a10967d41d45be9ff159f3c6f1583))
* **api:** update via SDK Studio ([#25](https://github.com/plastic-labs/honcho-node/issues/25)) ([d2b2c76](https://github.com/plastic-labs/honcho-node/commit/d2b2c76c4a28c3f2452492aedb240d563f33238c))


### Bug Fixes

* **compat:** remove ReadableStream polyfill redundant since node v16 ([#21](https://github.com/plastic-labs/honcho-node/issues/21)) ([697784b](https://github.com/plastic-labs/honcho-node/commit/697784bdd6d64b700cdc6ab1572a4ad130725d6b))


### Chores

* **ci:** correctly tag pre-release npm packages ([#27](https://github.com/plastic-labs/honcho-node/issues/27)) ([1f718ec](https://github.com/plastic-labs/honcho-node/commit/1f718eccfe135dc2bad1f9c31a43d1014e3831be))
* **docs:** fix incorrect client var names ([#22](https://github.com/plastic-labs/honcho-node/issues/22)) ([b19d486](https://github.com/plastic-labs/honcho-node/commit/b19d4865708dee7c6f5ac0af9ad74487709554e7))
* **internal:** add constant for default timeout ([#23](https://github.com/plastic-labs/honcho-node/issues/23)) ([67519e0](https://github.com/plastic-labs/honcho-node/commit/67519e0ebfbf52350f0dcbfd4b699285d5b765ec))
* **internal:** codegen related update ([#16](https://github.com/plastic-labs/honcho-node/issues/16)) ([8fd8961](https://github.com/plastic-labs/honcho-node/commit/8fd89613e59d87ecd9bf6822d69dc01e17cba411))
* **internal:** codegen related update ([#26](https://github.com/plastic-labs/honcho-node/issues/26)) ([5f40103](https://github.com/plastic-labs/honcho-node/commit/5f40103250bd1c732e9cd0e99c8f06e41f088a08))
* **internal:** codegen related update ([#28](https://github.com/plastic-labs/honcho-node/issues/28)) ([a87faf6](https://github.com/plastic-labs/honcho-node/commit/a87faf690c13f796027a92a18e8759846997aa8d))
* **tests:** update prism version ([#18](https://github.com/plastic-labs/honcho-node/issues/18)) ([09748fe](https://github.com/plastic-labs/honcho-node/commit/09748fe2cec34eb7c7d7ed1f839212e4c65642ea))

## 0.0.4 (2024-05-23)

Full Changelog: [v0.0.3...v0.0.4](https://github.com/plastic-labs/honcho-node/compare/v0.0.3...v0.0.4)
Expand Down
52 changes: 22 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Honcho Node API Library

[![NPM version](https://img.shields.io/npm/v/honcho-ai.svg)](https://npmjs.org/package/honcho-ai)
[![NPM version](https://img.shields.io/npm/v/honcho-ai.svg)](https://npmjs.org/package/honcho-ai) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/honcho-ai)

This library provides convenient access to the Honcho REST API from server-side TypeScript or JavaScript.

The REST API documentation can be found [on docs.honcho.dev](https://docs.honcho.dev). The full API of this library can be found in [api.md](api.md).
The REST API documentation can be found on [docs.honcho.dev](https://docs.honcho.dev). The full API of this library can be found in [api.md](api.md).

It is generated with [Stainless](https://www.stainlessapi.com/).

Expand All @@ -22,13 +22,13 @@ The full API of this library can be found in [api.md](api.md).
```js
import Honcho from 'honcho-ai';

const honcho = new Honcho({
const client = new Honcho({
apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted
environment: 'demo', // defaults to 'local'
environment: 'local', // defaults to 'demo'
});

async function main() {
const app = await honcho.apps.create({ name: 'string' });
const app = await client.apps.create({ name: 'name' });

console.log(app.id);
}
Expand All @@ -44,14 +44,14 @@ This library includes TypeScript definitions for all request params and response
```ts
import Honcho from 'honcho-ai';

const honcho = new Honcho({
const client = new Honcho({
apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted
environment: 'demo', // defaults to 'local'
environment: 'local', // defaults to 'demo'
});

async function main() {
const params: Honcho.AppCreateParams = { name: 'string' };
const app: Honcho.App = await honcho.apps.create(params);
const params: Honcho.AppCreateParams = { name: 'name' };
const app: Honcho.App = await client.apps.create(params);
}

main();
Expand All @@ -68,7 +68,7 @@ a subclass of `APIError` will be thrown:
<!-- prettier-ignore -->
```ts
async function main() {
const app = await honcho.apps.create({ name: 'string' }).catch(async (err) => {
const app = await client.apps.create({ name: 'name' }).catch(async (err) => {
if (err instanceof Honcho.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
Expand Down Expand Up @@ -106,12 +106,12 @@ You can use the `maxRetries` option to configure or disable this:
<!-- prettier-ignore -->
```js
// Configure the default for all requests:
const honcho = new Honcho({
const client = new Honcho({
maxRetries: 0, // default is 2
});

// Or, configure per-request:
await honcho.apps.create({ name: 'string' }, {
await client.apps.create({ name: 'name' }, {
maxRetries: 5,
});
```
Expand All @@ -123,12 +123,12 @@ Requests time out after 1 minute by default. You can configure this with a `time
<!-- prettier-ignore -->
```ts
// Configure the default for all requests:
const honcho = new Honcho({
const client = new Honcho({
timeout: 20 * 1000, // 20 seconds (default is 1 minute)
});

// Override per-request:
await honcho.apps.create({ name: 'string' }, {
await client.apps.create({ name: 'name' }, {
timeout: 5 * 1000,
});
```
Expand All @@ -146,7 +146,7 @@ You can use `for await … of` syntax to iterate through items across all pages:
async function fetchAllAppsUsers(params) {
const allAppsUsers = [];
// Automatically fetches more pages as needed.
for await (const user of honcho.apps.users.list('REPLACE_ME')) {
for await (const user of client.apps.users.list('REPLACE_ME')) {
allAppsUsers.push(user);
}
return allAppsUsers;
Expand All @@ -156,7 +156,7 @@ async function fetchAllAppsUsers(params) {
Alternatively, you can make request a single page at a time:

```ts
let page = await honcho.apps.users.list('REPLACE_ME');
let page = await client.apps.users.list('REPLACE_ME');
for (const user of page.items) {
console.log(user);
}
Expand All @@ -178,13 +178,13 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi

<!-- prettier-ignore -->
```ts
const honcho = new Honcho();
const client = new Honcho();

const response = await honcho.apps.create({ name: 'string' }).asResponse();
const response = await client.apps.create({ name: 'name' }).asResponse();
console.log(response.headers.get('X-My-Header'));
console.log(response.statusText); // access the underlying Response object

const { data: app, response: raw } = await honcho.apps.create({ name: 'string' }).withResponse();
const { data: app, response: raw } = await client.apps.create({ name: 'name' }).withResponse();
console.log(raw.headers.get('X-My-Header'));
console.log(app.id);
```
Expand Down Expand Up @@ -285,13 +285,13 @@ import http from 'http';
import { HttpsProxyAgent } from 'https-proxy-agent';

// Configure the default for all requests:
const honcho = new Honcho({
const client = new Honcho({
httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
});

// Override per-request:
await honcho.apps.create(
{ name: 'string' },
await client.apps.create(
{ name: 'name' },
{
httpAgent: new http.Agent({ keepAlive: false }),
},
Expand All @@ -316,14 +316,6 @@ TypeScript >= 4.5 is supported.

The following runtimes are supported:

- Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
- Deno v1.28.0 or higher, using `import Honcho from "npm:honcho-ai"`.
- Bun 1.0 or later.
- Cloudflare Workers.
- Vercel Edge Runtime.
- Jest 28 or greater with the `"node"` environment (`"jsdom"` is not supported at this time).
- Nitro v2.6 or greater.

Note that React Native is not supported at this time.

If you are interested in other runtime environments, please open or upvote an issue on GitHub.
20 changes: 18 additions & 2 deletions bin/publish-npm
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@

set -eux

npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
npm config set '//registry.npmjs.org/:_authToken' "$NPM_TOKEN"

# Build the project
yarn build

# Navigate to the dist directory
cd dist
yarn publish --access public

# Get the version from package.json
VERSION="$(node -p "require('./package.json').version")"

# Extract the pre-release tag if it exists
if [[ "$VERSION" =~ -([a-zA-Z]+) ]]; then
# Extract the part before any dot in the pre-release identifier
TAG="${BASH_REMATCH[1]}"
else
TAG="latest"
fi

# Publish with the appropriate tag
yarn publish --access public --tag "$TAG"
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "honcho-ai",
"version": "0.0.4",
"version": "0.0.5",
"description": "The official TypeScript library for the Honcho API",
"author": "Honcho <[email protected]>",
"types": "dist/index.d.ts",
Expand All @@ -16,7 +16,6 @@
"scripts": {
"test": "./scripts/test",
"build": "./scripts/build",
"prepack": "echo 'to pack, run yarn build && (cd dist; yarn pack)' && exit 1",
"prepublishOnly": "echo 'to publish, run yarn build && (cd dist; yarn publish)' && exit 1",
"format": "prettier --write --cache --cache-strategy metadata . !dist",
"prepare": "if ./scripts/utils/check-is-in-git-install.sh; then ./scripts/build; fi",
Expand All @@ -31,8 +30,7 @@
"agentkeepalive": "^4.2.1",
"form-data-encoder": "1.7.2",
"formdata-node": "^4.3.2",
"node-fetch": "^2.6.7",
"web-streams-polyfill": "^3.2.1"
"node-fetch": "^2.6.7"
},
"devDependencies": {
"@swc/core": "^1.3.102",
Expand Down
4 changes: 2 additions & 2 deletions scripts/mock
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ echo "==> Starting mock server with URL ${URL}"

# Run prism mock on the given spec
if [ "$1" == "--daemon" ]; then
npm exec --package=@stoplight/prism-cli@~5.8 -- prism mock "$URL" &> .prism.log &
npm exec --package=@stainless-api/[email protected].4 -- prism mock "$URL" &> .prism.log &

# Wait for server to come online
echo -n "Waiting for server"
Expand All @@ -37,5 +37,5 @@ if [ "$1" == "--daemon" ]; then

echo
else
npm exec --package=@stoplight/prism-cli@~5.8 -- prism mock "$URL"
npm exec --package=@stainless-api/[email protected].4 -- prism mock "$URL"
fi
4 changes: 1 addition & 3 deletions src/_shims/node-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import { Readable } from 'node:stream';
import { type RequestOptions } from '../core';
import { MultipartBody } from './MultipartBody';
import { type Shims } from './registry';

// @ts-ignore (this package does not have proper export maps for this export)
import { ReadableStream } from 'web-streams-polyfill/dist/ponyfill.es2018.js';
import { ReadableStream } from 'node:stream/web';

type FileFromPathOptions = Omit<FilePropertyBag, 'lastModified'>;

Expand Down
35 changes: 27 additions & 8 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
type HeadersInit,
} from './_shims/index';
export { type Response };
import { isMultipartBody } from './uploads';
import { BlobLike, isBlobLike, isMultipartBody } from './uploads';
export {
maybeMultipartFormRequestOptions,
multipartFormRequestOptions,
Expand Down Expand Up @@ -235,7 +235,17 @@ export abstract class APIClient {
path: string,
opts?: PromiseOrValue<RequestOptions<Req>>,
): APIPromise<Rsp> {
return this.request(Promise.resolve(opts).then((opts) => ({ method, path, ...opts })));
return this.request(
Promise.resolve(opts).then(async (opts) => {
const body =
opts && isBlobLike(opts?.body) ? new DataView(await opts.body.arrayBuffer())
: opts?.body instanceof DataView ? opts.body
: opts?.body instanceof ArrayBuffer ? new DataView(opts.body)
: opts && ArrayBuffer.isView(opts?.body) ? new DataView(opts.body.buffer)
: opts?.body;
return { method, path, ...opts, body };
}),
);
}

getAPIList<Item, PageClass extends AbstractPage<Item> = AbstractPage<Item>>(
Expand All @@ -257,6 +267,8 @@ export abstract class APIClient {
const encoded = encoder.encode(body);
return encoded.length.toString();
}
} else if (ArrayBuffer.isView(body)) {
return body.byteLength.toString();
}

return null;
Expand All @@ -266,7 +278,9 @@ export abstract class APIClient {
const { method, path, query, headers: headers = {} } = options;

const body =
isMultipartBody(options.body) ? options.body.body
ArrayBuffer.isView(options.body) || (options.__binaryRequest && typeof options.body === 'string') ?
options.body
: isMultipartBody(options.body) ? options.body.body
: options.body ? JSON.stringify(options.body, null, 2)
: null;
const contentLength = this.calculateContentLength(body);
Expand Down Expand Up @@ -721,7 +735,9 @@ export type Headers = Record<string, string | null | undefined>;
export type DefaultQuery = Record<string, string | undefined>;
export type KeysEnum<T> = { [P in keyof Required<T>]: true };

export type RequestOptions<Req = unknown | Record<string, unknown> | Readable> = {
export type RequestOptions<
Req = unknown | Record<string, unknown> | Readable | BlobLike | ArrayBufferView | ArrayBuffer,
> = {
method?: HTTPMethod;
path?: string;
query?: Req | undefined;
Expand All @@ -735,6 +751,7 @@ export type RequestOptions<Req = unknown | Record<string, unknown> | Readable> =
signal?: AbortSignal | undefined | null;
idempotencyKey?: string;

__binaryRequest?: boolean | undefined;
__binaryResponse?: boolean | undefined;
};

Expand All @@ -755,6 +772,7 @@ const requestOptionsKeys: KeysEnum<RequestOptions> = {
signal: true,
idempotencyKey: true,

__binaryRequest: true,
__binaryResponse: true,
};

Expand All @@ -767,10 +785,11 @@ export const isRequestOptions = (obj: unknown): obj is RequestOptions => {
);
};

export type FinalRequestOptions<Req = unknown | Record<string, unknown> | Readable> = RequestOptions<Req> & {
method: HTTPMethod;
path: string;
};
export type FinalRequestOptions<Req = unknown | Record<string, unknown> | Readable | DataView> =
RequestOptions<Req> & {
method: HTTPMethod;
path: string;
};

declare const Deno: any;
declare const EdgeRuntime: any;
Expand Down
Loading

0 comments on commit 617733b

Please sign in to comment.