Skip to content

Commit 2f8aaae

Browse files
release: 1.11.0 (#108)
* refactor(types): replace Record with mapped types * feat(api): api update * fix(ci): release-doctor — report correct token name * fix(client): get fetchOptions type more reliably * feat(api): api update * chore(ci): only run for pushes and fork pull requests * chore(client): improve path param validation * codegen metadata * feat(api): api update * chore: add docs to RequestOptions type * codegen metadata * codegen metadata * codegen metadata * codegen metadata * feat(api): api update * chore: make some internal functions async * release: 1.11.0 --------- Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
1 parent 5bb3945 commit 2f8aaae

33 files changed

+449
-170
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
timeout-minutes: 10
1818
name: lint
1919
runs-on: ${{ github.repository == 'stainless-sdks/knock-typescript' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
20+
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
2021
steps:
2122
- uses: actions/checkout@v4
2223

@@ -35,6 +36,7 @@ jobs:
3536
timeout-minutes: 5
3637
name: build
3738
runs-on: ${{ github.repository == 'stainless-sdks/knock-typescript' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
39+
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
3840
permissions:
3941
contents: read
4042
id-token: write
@@ -70,6 +72,7 @@ jobs:
7072
timeout-minutes: 10
7173
name: test
7274
runs-on: ${{ github.repository == 'stainless-sdks/knock-typescript' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
75+
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
7376
steps:
7477
- uses: actions/checkout@v4
7578

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "1.10.3"
2+
".": "1.11.0"
33
}

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 89
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/knock%2Fknock-c15e6924891ae19a301d5e878d353bda7cf6aa486c13be9525fe9d4d06eb140f.yml
3-
openapi_spec_hash: 397a88d71e81d4339d41c151a61e12b9
4-
config_hash: b4c547c1d4c8cd0834bc793ddf5388ee
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/knock%2Fknock-592610bb4a05ea45115eba7544acd8efbab327749d0f78bd83e164aa305dc0a7.yml
3+
openapi_spec_hash: 6a65b9127625d9479ba6bff2ba3f8d37
4+
config_hash: f71d01a8d81174e45c21483122979e6b

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
# Changelog
22

3+
## 1.11.0 (2025-07-10)
4+
5+
Full Changelog: [v1.10.3...v1.11.0](https://github.com/knocklabs/knock-node/compare/v1.10.3...v1.11.0)
6+
7+
### Features
8+
9+
* **api:** api update ([647d271](https://github.com/knocklabs/knock-node/commit/647d2714cda96e42ac0a7816b3da0130a83978db))
10+
* **api:** api update ([7a4ae6b](https://github.com/knocklabs/knock-node/commit/7a4ae6b5a7ed2317ffabb62d0ea762f292ee83a4))
11+
* **api:** api update ([c713cd6](https://github.com/knocklabs/knock-node/commit/c713cd61a345818a81c51bd3467c566306c4d39a))
12+
* **api:** api update ([cc912aa](https://github.com/knocklabs/knock-node/commit/cc912aa8707cebfd79d0301b471c1f38bce27d63))
13+
14+
15+
### Bug Fixes
16+
17+
* **ci:** release-doctor — report correct token name ([90c9bdd](https://github.com/knocklabs/knock-node/commit/90c9bdd59997ee1fd2fcd4e81f6869687e256dca))
18+
* **client:** get fetchOptions type more reliably ([556dcce](https://github.com/knocklabs/knock-node/commit/556dcce102e461b5578627b9d007b3a6d90c92e3))
19+
20+
21+
### Chores
22+
23+
* add docs to RequestOptions type ([4fc8c09](https://github.com/knocklabs/knock-node/commit/4fc8c09b1814c7889f4948bec2bd87d5805d24e4))
24+
* **ci:** only run for pushes and fork pull requests ([4a906c7](https://github.com/knocklabs/knock-node/commit/4a906c7eef1f1eb31ea94d28107e9ae58a1417b2))
25+
* **client:** improve path param validation ([f9dc449](https://github.com/knocklabs/knock-node/commit/f9dc44909dfaf17278992d446caa389f10748f06))
26+
* make some internal functions async ([fde6b31](https://github.com/knocklabs/knock-node/commit/fde6b318974a544bfc349597ec8afdda10a5c950))
27+
28+
29+
### Refactors
30+
31+
* **types:** replace Record with mapped types ([8377542](https://github.com/knocklabs/knock-node/commit/83775423c67655fe2c5e5c1b7449b355d1cf6d22))
32+
333
## 1.10.3 (2025-06-21)
434

535
Full Changelog: [v1.10.2...v1.10.3](https://github.com/knocklabs/knock-node/compare/v1.10.2...v1.10.3)

bin/check-release-environment

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
errors=()
44

55
if [ -z "${NPM_TOKEN}" ]; then
6-
errors+=("The KNOCK_NPM_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets")
6+
errors+=("The NPM_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets")
77
fi
88

99
lenErrors=${#errors[@]}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@knocklabs/node",
3-
"version": "1.10.3",
3+
"version": "1.11.0",
44
"description": "The official TypeScript library for the Knock API",
55
"author": "Knock <[email protected]>",
66
"types": "dist/index.d.ts",

src/client.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ export interface ClientOptions {
167167
*
168168
* Note that request timeouts are retried by default, so in a worst-case scenario you may wait
169169
* much longer than this timeout before the promise succeeds or fails.
170+
*
171+
* @unit milliseconds
170172
*/
171173
timeout?: number | undefined;
172174
/**
@@ -292,7 +294,7 @@ export class Knock {
292294
* Create a new client instance re-using the same options given to the current client with optional overriding.
293295
*/
294296
withOptions(options: Partial<ClientOptions>): this {
295-
return new (this.constructor as any as new (props: ClientOptions) => typeof this)({
297+
const client = new (this.constructor as any as new (props: ClientOptions) => typeof this)({
296298
...this._options,
297299
baseURL: this.baseURL,
298300
maxRetries: this.maxRetries,
@@ -304,6 +306,7 @@ export class Knock {
304306
apiKey: this.apiKey,
305307
...options,
306308
});
309+
return client;
307310
}
308311

309312
/**
@@ -321,7 +324,7 @@ export class Knock {
321324
return;
322325
}
323326

324-
protected authHeaders(opts: FinalRequestOptions): NullableHeaders | undefined {
327+
protected async authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
325328
return buildHeaders([{ Authorization: `Bearer ${this.apiKey}` }]);
326329
}
327330

@@ -437,7 +440,9 @@ export class Knock {
437440

438441
await this.prepareOptions(options);
439442

440-
const { req, url, timeout } = this.buildRequest(options, { retryCount: maxRetries - retriesRemaining });
443+
const { req, url, timeout } = await this.buildRequest(options, {
444+
retryCount: maxRetries - retriesRemaining,
445+
});
441446

442447
await this.prepareRequest(req, { url, options });
443448

@@ -515,7 +520,7 @@ export class Knock {
515520
} with status ${response.status} in ${headersTime - startTime}ms`;
516521

517522
if (!response.ok) {
518-
const shouldRetry = this.shouldRetry(response);
523+
const shouldRetry = await this.shouldRetry(response);
519524
if (retriesRemaining && shouldRetry) {
520525
const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
521526

@@ -633,7 +638,7 @@ export class Knock {
633638
}
634639
}
635640

636-
private shouldRetry(response: Response): boolean {
641+
private async shouldRetry(response: Response): Promise<boolean> {
637642
// Note this is not a standard header.
638643
const shouldRetryHeader = response.headers.get('x-should-retry');
639644

@@ -710,18 +715,18 @@ export class Knock {
710715
return sleepSeconds * jitter * 1000;
711716
}
712717

713-
buildRequest(
718+
async buildRequest(
714719
inputOptions: FinalRequestOptions,
715720
{ retryCount = 0 }: { retryCount?: number } = {},
716-
): { req: FinalizedRequestInit; url: string; timeout: number } {
721+
): Promise<{ req: FinalizedRequestInit; url: string; timeout: number }> {
717722
const options = { ...inputOptions };
718723
const { method, path, query, defaultBaseURL } = options;
719724

720725
const url = this.buildURL(path!, query as Record<string, unknown>, defaultBaseURL);
721726
if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
722727
options.timeout = options.timeout ?? this.timeout;
723728
const { bodyHeaders, body } = this.buildBody({ options });
724-
const reqHeaders = this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
729+
const reqHeaders = await this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
725730

726731
const req: FinalizedRequestInit = {
727732
method,
@@ -737,7 +742,7 @@ export class Knock {
737742
return { req, url, timeout: options.timeout };
738743
}
739744

740-
private buildHeaders({
745+
private async buildHeaders({
741746
options,
742747
method,
743748
bodyHeaders,
@@ -747,7 +752,7 @@ export class Knock {
747752
method: HTTPMethod;
748753
bodyHeaders: HeadersLike;
749754
retryCount: number;
750-
}): Headers {
755+
}): Promise<Headers> {
751756
let idempotencyHeaders: HeadersLike = {};
752757
if (this.idempotencyHeader && method !== 'get') {
753758
if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey();
@@ -763,7 +768,7 @@ export class Knock {
763768
...(options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {}),
764769
...getPlatformHeaders(),
765770
},
766-
this.authHeaders(options),
771+
await this.authHeaders(options),
767772
this._options.defaultHeaders,
768773
bodyHeaders,
769774
options.headers,

src/internal/request-options.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,70 @@ import { type HeadersLike } from './headers';
99
export type FinalRequestOptions = RequestOptions & { method: HTTPMethod; path: string };
1010

1111
export type RequestOptions = {
12+
/**
13+
* The HTTP method for the request (e.g., 'get', 'post', 'put', 'delete').
14+
*/
1215
method?: HTTPMethod;
16+
17+
/**
18+
* The URL path for the request.
19+
*
20+
* @example "/v1/foo"
21+
*/
1322
path?: string;
23+
24+
/**
25+
* Query parameters to include in the request URL.
26+
*/
1427
query?: object | undefined | null;
28+
29+
/**
30+
* The request body. Can be a string, JSON object, FormData, or other supported types.
31+
*/
1532
body?: unknown;
33+
34+
/**
35+
* HTTP headers to include with the request. Can be a Headers object, plain object, or array of tuples.
36+
*/
1637
headers?: HeadersLike;
38+
39+
/**
40+
* The maximum number of times that the client will retry a request in case of a
41+
* temporary failure, like a network error or a 5XX error from the server.
42+
*
43+
* @default 2
44+
*/
1745
maxRetries?: number;
46+
1847
stream?: boolean | undefined;
48+
49+
/**
50+
* The maximum amount of time (in milliseconds) that the client should wait for a response
51+
* from the server before timing out a single request.
52+
*
53+
* @unit milliseconds
54+
*/
1955
timeout?: number;
56+
57+
/**
58+
* Additional `RequestInit` options to be passed to the underlying `fetch` call.
59+
* These options will be merged with the client's default fetch options.
60+
*/
2061
fetchOptions?: MergedRequestInit;
62+
63+
/**
64+
* An AbortSignal that can be used to cancel the request.
65+
*/
2166
signal?: AbortSignal | undefined | null;
67+
68+
/**
69+
* A unique key for this request to enable idempotency.
70+
*/
2271
idempotencyKey?: string;
72+
73+
/**
74+
* Override the default base URL for this specific request.
75+
*/
2376
defaultBaseURL?: string | undefined;
2477

2578
__binaryResponse?: boolean | undefined;

src/internal/types.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export type KeysEnum<T> = { [P in keyof Required<T>]: true };
77

88
export type FinalizedRequestInit = RequestInit & { headers: Headers };
99

10-
type NotAny<T> = [unknown] extends [T] ? never : T;
10+
type NotAny<T> = [0] extends [1 & T] ? never : T;
1111

1212
/**
1313
* Some environments overload the global fetch function, and Parameters<T> only gets the last signature.
@@ -64,13 +64,15 @@ type OverloadedParameters<T> =
6464
* [1]: https://www.typescriptlang.org/tsconfig/#typeAcquisition
6565
*/
6666
/** @ts-ignore For users with \@types/node */
67-
type UndiciTypesRequestInit = NotAny<import('../node_modules/undici-types').RequestInit> | NotAny<import('../../node_modules/undici-types').RequestInit> | NotAny<import('../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici-types').RequestInit>;
67+
type UndiciTypesRequestInit = NotAny<import('../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit>;
6868
/** @ts-ignore For users with undici */
69-
type UndiciRequestInit = NotAny<import('../node_modules/undici').RequestInit> | NotAny<import('../../node_modules/undici').RequestInit> | NotAny<import('../../../node_modules/undici').RequestInit> | NotAny<import('../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici').RequestInit>;
69+
type UndiciRequestInit = NotAny<import('../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici/index.d.ts').RequestInit>;
7070
/** @ts-ignore For users with \@types/bun */
7171
type BunRequestInit = globalThis.FetchRequestInit;
72-
/** @ts-ignore For users with node-fetch */
73-
type NodeFetchRequestInit = NotAny<import('../node_modules/node-fetch').RequestInit> | NotAny<import('../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/node-fetch').RequestInit>;
72+
/** @ts-ignore For users with node-fetch@2 */
73+
type NodeFetch2RequestInit = NotAny<import('../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit>;
74+
/** @ts-ignore For users with node-fetch@3, doesn't need file extension because types are at ./@types/index.d.ts */
75+
type NodeFetch3RequestInit = NotAny<import('../node_modules/node-fetch').RequestInit> | NotAny<import('../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/node-fetch').RequestInit>;
7476
/** @ts-ignore For users who use Deno */
7577
type FetchRequestInit = NonNullable<OverloadedParameters<typeof fetch>[1]>;
7678
/* eslint-enable */
@@ -79,7 +81,8 @@ type RequestInits =
7981
| NotAny<UndiciTypesRequestInit>
8082
| NotAny<UndiciRequestInit>
8183
| NotAny<BunRequestInit>
82-
| NotAny<NodeFetchRequestInit>
84+
| NotAny<NodeFetch2RequestInit>
85+
| NotAny<NodeFetch3RequestInit>
8386
| NotAny<RequestInit>
8487
| NotAny<FetchRequestInit>;
8588

src/internal/uploads.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const multipartFormRequestOptions = async (
9090
return { ...opts, body: await createForm(opts.body, fetch) };
9191
};
9292

93-
const supportsFormDataMap = /** @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>();
93+
const supportsFormDataMap = /* @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>();
9494

9595
/**
9696
* node-fetch doesn't support the global FormData object in recent node versions. Instead of sending

0 commit comments

Comments
 (0)