Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ${{ github.repository == 'stainless-sdks/zoriapi-typescript' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up Node
uses: actions/setup-node@v4
Expand All @@ -41,7 +41,7 @@ jobs:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up Node
uses: actions/setup-node@v4
Expand All @@ -57,7 +57,7 @@ jobs:
- name: Get GitHub OIDC Token
if: github.repository == 'stainless-sdks/zoriapi-typescript'
id: github-oidc
uses: actions/github-script@v6
uses: actions/github-script@v8
with:
script: core.setOutput('github_token', await core.getIDToken());

Expand All @@ -74,7 +74,7 @@ jobs:
runs-on: ${{ github.repository == 'stainless-sdks/zoriapi-typescript' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up Node
uses: actions/setup-node@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up Node
uses: actions/setup-node@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-doctor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
if: github.repository == 'ZoriHQ/typescript-api-sdk' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next')

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Check release environment
run: |
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.22.0"
".": "0.22.1"
}
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog

## 0.22.1 (2026-02-06)

Full Changelog: [v0.22.0...v0.22.1](https://github.com/ZoriHQ/typescript-api-sdk/compare/v0.22.0...v0.22.1)

### Bug Fixes

* **client:** avoid memory leak with abort signals ([b396469](https://github.com/ZoriHQ/typescript-api-sdk/commit/b396469b91bbb976d25f9d1f8aaae1b1dec75b4a))
* **client:** avoid removing abort listener too early ([13d1580](https://github.com/ZoriHQ/typescript-api-sdk/commit/13d158066b35eb0fac9c7fb641ccdb4c18210fb9))


### Chores

* break long lines in snippets into multiline ([f85789d](https://github.com/ZoriHQ/typescript-api-sdk/commit/f85789d01d922f9057d91184fa84ac794c2b19dc))
* **ci:** upgrade `actions/github-script` ([86354b9](https://github.com/ZoriHQ/typescript-api-sdk/commit/86354b97179e2baff126ef082b97e0f8a6a85167))
* **client:** do not parse responses with empty content-length ([b84b54f](https://github.com/ZoriHQ/typescript-api-sdk/commit/b84b54f6a499c264529cdd2ee081905fdfb3e641))
* **client:** restructure abort controller binding ([ab480be](https://github.com/ZoriHQ/typescript-api-sdk/commit/ab480be2f117f230bdca77535e34aaadfb2476ce))
* **internal:** codegen related update ([63fc931](https://github.com/ZoriHQ/typescript-api-sdk/commit/63fc9315660b9c7589191dd80ca471dae26d574b))
* **internal:** update `actions/checkout` version ([04e5e52](https://github.com/ZoriHQ/typescript-api-sdk/commit/04e5e52fdae1d4af94e7d481b3f0ad5114e27c9b))
* **internal:** upgrade babel, qs, js-yaml ([af1ea44](https://github.com/ZoriHQ/typescript-api-sdk/commit/af1ea44c69a1944f7230beb21aa07009b3bad083))

## 0.22.0 (2025-12-08)

Full Changelog: [v0.21.0...v0.22.0](https://github.com/ZoriHQ/typescript-api-sdk/compare/v0.21.0...v0.22.0)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2025 Zoriapi
Copyright 2026 Zoriapi

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ Unlike `.asResponse()` this method consumes the body, returning once it is parse
```ts
const client = new Zoriapi();

const response = await client.v1.auth.login({ password: 'password', username: 'username' }).asResponse();
const response = await client.v1.auth
.login({ password: 'password', username: 'username' })
.asResponse();
console.log(response.headers.get('X-My-Header'));
console.log(response.statusText); // access the underlying Response object

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zorihq",
"version": "0.22.0",
"version": "0.22.1",
"description": "The official TypeScript library for the Zoriapi API",
"author": "Zoriapi <support@zorihq.com>",
"types": "dist/index.d.ts",
Expand Down
11 changes: 9 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,10 @@ export class Zoriapi {
controller: AbortController,
): Promise<Response> {
const { signal, method, ...options } = init || {};
if (signal) signal.addEventListener('abort', () => controller.abort());
const abort = this._makeAbort(controller);
if (signal) signal.addEventListener('abort', abort, { once: true });

const timeout = setTimeout(() => controller.abort(), ms);
const timeout = setTimeout(abort, ms);

const isReadableBody =
((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||
Expand Down Expand Up @@ -664,6 +665,12 @@ export class Zoriapi {
return headers.values;
}

private _makeAbort(controller: AbortController) {
// note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
// would capture all request options, and cause a memory leak.
return () => controller.abort();
}

private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
bodyHeaders: HeadersLike;
body: BodyInit | undefined;
Expand Down
6 changes: 6 additions & 0 deletions src/internal/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export async function defaultParseResponse<T>(client: Zoriapi, props: APIRespons
const mediaType = contentType?.split(';')[0]?.trim();
const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
if (isJSON) {
const contentLength = response.headers.get('content-length');
if (contentLength === '0') {
// if there is no content we can't do anything
return undefined as T;
}

const json = await response.json();
return json as T;
}
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = '0.22.0'; // x-release-please-version
export const VERSION = '0.22.1'; // x-release-please-version
66 changes: 55 additions & 11 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ describe('instantiate client', () => {
error: jest.fn(),
};

const client = new Zoriapi({ logger: logger, logLevel: 'debug', apiKey: 'My API Key' });
const client = new Zoriapi({
logger: logger,
logLevel: 'debug',
apiKey: 'My API Key',
});

await forceAPIResponseForClient(client);
expect(debugMock).toHaveBeenCalled();
Expand All @@ -107,7 +111,11 @@ describe('instantiate client', () => {
error: jest.fn(),
};

const client = new Zoriapi({ logger: logger, logLevel: 'info', apiKey: 'My API Key' });
const client = new Zoriapi({
logger: logger,
logLevel: 'info',
apiKey: 'My API Key',
});

await forceAPIResponseForClient(client);
expect(debugMock).not.toHaveBeenCalled();
Expand Down Expand Up @@ -157,7 +165,11 @@ describe('instantiate client', () => {
};

process.env['ZORIAPI_LOG'] = 'debug';
const client = new Zoriapi({ logger: logger, logLevel: 'off', apiKey: 'My API Key' });
const client = new Zoriapi({
logger: logger,
logLevel: 'off',
apiKey: 'My API Key',
});

await forceAPIResponseForClient(client);
expect(debugMock).not.toHaveBeenCalled();
Expand All @@ -173,7 +185,11 @@ describe('instantiate client', () => {
};

process.env['ZORIAPI_LOG'] = 'not a log level';
const client = new Zoriapi({ logger: logger, logLevel: 'debug', apiKey: 'My API Key' });
const client = new Zoriapi({
logger: logger,
logLevel: 'debug',
apiKey: 'My API Key',
});
expect(client.logLevel).toBe('debug');
expect(warnMock).not.toHaveBeenCalled();
});
Expand Down Expand Up @@ -267,7 +283,11 @@ describe('instantiate client', () => {
return new Response(JSON.stringify({}), { headers: { 'Content-Type': 'application/json' } });
};

const client = new Zoriapi({ baseURL: 'http://localhost:5000/', apiKey: 'My API Key', fetch: testFetch });
const client = new Zoriapi({
baseURL: 'http://localhost:5000/',
apiKey: 'My API Key',
fetch: testFetch,
});

await client.patch('/foo');
expect(capturedRequest?.method).toEqual('PATCH');
Expand Down Expand Up @@ -345,7 +365,11 @@ describe('instantiate client', () => {

describe('withOptions', () => {
test('creates a new client with overridden options', async () => {
const client = new Zoriapi({ baseURL: 'http://localhost:5000/', maxRetries: 3, apiKey: 'My API Key' });
const client = new Zoriapi({
baseURL: 'http://localhost:5000/',
maxRetries: 3,
apiKey: 'My API Key',
});

const newClient = client.withOptions({
maxRetries: 5,
Expand Down Expand Up @@ -385,7 +409,11 @@ describe('instantiate client', () => {
});

test('respects runtime property changes when creating new client', () => {
const client = new Zoriapi({ baseURL: 'http://localhost:5000/', timeout: 1000, apiKey: 'My API Key' });
const client = new Zoriapi({
baseURL: 'http://localhost:5000/',
timeout: 1000,
apiKey: 'My API Key',
});

// Modify the client properties directly after creation
client.baseURL = 'http://localhost:6000/';
Expand Down Expand Up @@ -531,7 +559,11 @@ describe('retries', () => {
return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });
};

const client = new Zoriapi({ apiKey: 'My API Key', timeout: 10, fetch: testFetch });
const client = new Zoriapi({
apiKey: 'My API Key',
timeout: 10,
fetch: testFetch,
});

expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 });
expect(count).toEqual(2);
Expand Down Expand Up @@ -561,7 +593,11 @@ describe('retries', () => {
return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });
};

const client = new Zoriapi({ apiKey: 'My API Key', fetch: testFetch, maxRetries: 4 });
const client = new Zoriapi({
apiKey: 'My API Key',
fetch: testFetch,
maxRetries: 4,
});

expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 });

Expand All @@ -585,7 +621,11 @@ describe('retries', () => {
capturedRequest = init;
return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });
};
const client = new Zoriapi({ apiKey: 'My API Key', fetch: testFetch, maxRetries: 4 });
const client = new Zoriapi({
apiKey: 'My API Key',
fetch: testFetch,
maxRetries: 4,
});

expect(
await client.request({
Expand Down Expand Up @@ -647,7 +687,11 @@ describe('retries', () => {
capturedRequest = init;
return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });
};
const client = new Zoriapi({ apiKey: 'My API Key', fetch: testFetch, maxRetries: 4 });
const client = new Zoriapi({
apiKey: 'My API Key',
fetch: testFetch,
maxRetries: 4,
});

expect(
await client.request({
Expand Down
Loading
Loading