@knocklabs/node 1.10.2 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/client.d.mts +5 -3
- package/client.d.mts.map +1 -1
- package/client.d.ts +5 -3
- package/client.d.ts.map +1 -1
- package/client.js +13 -9
- package/client.js.map +1 -1
- package/client.mjs +13 -9
- package/client.mjs.map +1 -1
- package/internal/request-options.d.mts +42 -0
- package/internal/request-options.d.mts.map +1 -1
- package/internal/request-options.d.ts +42 -0
- package/internal/request-options.d.ts.map +1 -1
- package/internal/request-options.js.map +1 -1
- package/internal/request-options.mjs.map +1 -1
- package/internal/types.d.mts +8 -6
- package/internal/types.d.mts.map +1 -1
- package/internal/types.d.ts +8 -6
- package/internal/types.d.ts.map +1 -1
- package/internal/uploads.js +1 -1
- package/internal/uploads.js.map +1 -1
- package/internal/uploads.mjs +1 -1
- package/internal/uploads.mjs.map +1 -1
- package/internal/utils/log.js +1 -1
- package/internal/utils/log.js.map +1 -1
- package/internal/utils/log.mjs +1 -1
- package/internal/utils/log.mjs.map +1 -1
- package/internal/utils/path.d.mts.map +1 -1
- package/internal/utils/path.d.ts.map +1 -1
- package/internal/utils/path.js +26 -5
- package/internal/utils/path.js.map +1 -1
- package/internal/utils/path.mjs +26 -5
- package/internal/utils/path.mjs.map +1 -1
- package/package.json +1 -1
- package/resources/audiences.d.mts +3 -3
- package/resources/audiences.d.ts +3 -3
- package/resources/integrations/census.d.mts +6 -2
- package/resources/integrations/census.d.mts.map +1 -1
- package/resources/integrations/census.d.ts +6 -2
- package/resources/integrations/census.d.ts.map +1 -1
- package/resources/integrations/hightouch.d.mts +6 -2
- package/resources/integrations/hightouch.d.mts.map +1 -1
- package/resources/integrations/hightouch.d.ts +6 -2
- package/resources/integrations/hightouch.d.ts.map +1 -1
- package/resources/messages/batch.d.mts +16 -6
- package/resources/messages/batch.d.mts.map +1 -1
- package/resources/messages/batch.d.ts +16 -6
- package/resources/messages/batch.d.ts.map +1 -1
- package/resources/messages/messages.d.mts +44 -14
- package/resources/messages/messages.d.mts.map +1 -1
- package/resources/messages/messages.d.ts +44 -14
- package/resources/messages/messages.d.ts.map +1 -1
- package/resources/messages/messages.js.map +1 -1
- package/resources/messages/messages.mjs.map +1 -1
- package/resources/objects/bulk.d.mts +3 -1
- package/resources/objects/bulk.d.mts.map +1 -1
- package/resources/objects/bulk.d.ts +3 -1
- package/resources/objects/bulk.d.ts.map +1 -1
- package/resources/objects/objects.d.mts +12 -4
- package/resources/objects/objects.d.mts.map +1 -1
- package/resources/objects/objects.d.ts +12 -4
- package/resources/objects/objects.d.ts.map +1 -1
- package/resources/objects/objects.js.map +1 -1
- package/resources/objects/objects.mjs.map +1 -1
- package/resources/providers/slack.d.mts +2 -1
- package/resources/providers/slack.d.mts.map +1 -1
- package/resources/providers/slack.d.ts +2 -1
- package/resources/providers/slack.d.ts.map +1 -1
- package/resources/recipients/channel-data.d.mts +6 -4
- package/resources/recipients/channel-data.d.mts.map +1 -1
- package/resources/recipients/channel-data.d.ts +6 -4
- package/resources/recipients/channel-data.d.ts.map +1 -1
- package/resources/recipients/preferences.d.mts +15 -5
- package/resources/recipients/preferences.d.mts.map +1 -1
- package/resources/recipients/preferences.d.ts +15 -5
- package/resources/recipients/preferences.d.ts.map +1 -1
- package/resources/recipients/subscriptions.d.mts +3 -1
- package/resources/recipients/subscriptions.d.mts.map +1 -1
- package/resources/recipients/subscriptions.d.ts +3 -1
- package/resources/recipients/subscriptions.d.ts.map +1 -1
- package/resources/schedules/bulk.d.mts +7 -5
- package/resources/schedules/bulk.d.mts.map +1 -1
- package/resources/schedules/bulk.d.ts +7 -5
- package/resources/schedules/bulk.d.ts.map +1 -1
- package/resources/schedules/schedules.d.mts +21 -15
- package/resources/schedules/schedules.d.mts.map +1 -1
- package/resources/schedules/schedules.d.ts +21 -15
- package/resources/schedules/schedules.d.ts.map +1 -1
- package/resources/shared.d.mts +1 -1
- package/resources/shared.d.ts +1 -1
- package/resources/users/feeds.d.mts +18 -4
- package/resources/users/feeds.d.mts.map +1 -1
- package/resources/users/feeds.d.ts +18 -4
- package/resources/users/feeds.d.ts.map +1 -1
- package/resources/users/feeds.js +14 -2
- package/resources/users/feeds.js.map +1 -1
- package/resources/users/feeds.mjs +14 -2
- package/resources/users/feeds.mjs.map +1 -1
- package/resources/users/guides.d.mts +30 -10
- package/resources/users/guides.d.mts.map +1 -1
- package/resources/users/guides.d.ts +30 -10
- package/resources/users/guides.d.ts.map +1 -1
- package/resources/users/users.d.mts +15 -11
- package/resources/users/users.d.mts.map +1 -1
- package/resources/users/users.d.ts +15 -11
- package/resources/users/users.d.ts.map +1 -1
- package/resources/users/users.js +3 -3
- package/resources/users/users.js.map +1 -1
- package/resources/users/users.mjs +3 -3
- package/resources/users/users.mjs.map +1 -1
- package/resources/workflows.d.mts +7 -5
- package/resources/workflows.d.mts.map +1 -1
- package/resources/workflows.d.ts +7 -5
- package/resources/workflows.d.ts.map +1 -1
- package/src/client.ts +17 -11
- package/src/internal/request-options.ts +53 -0
- package/src/internal/types.ts +9 -6
- package/src/internal/uploads.ts +1 -1
- package/src/internal/utils/log.ts +1 -1
- package/src/internal/utils/path.ts +32 -7
- package/src/resources/audiences.ts +3 -3
- package/src/resources/integrations/census.ts +2 -2
- package/src/resources/integrations/hightouch.ts +2 -2
- package/src/resources/messages/batch.ts +6 -6
- package/src/resources/messages/messages.ts +19 -14
- package/src/resources/objects/bulk.ts +1 -1
- package/src/resources/objects/objects.ts +8 -10
- package/src/resources/providers/slack.ts +2 -1
- package/src/resources/recipients/channel-data.ts +11 -7
- package/src/resources/recipients/preferences.ts +9 -11
- package/src/resources/recipients/subscriptions.ts +1 -1
- package/src/resources/schedules/bulk.ts +5 -5
- package/src/resources/schedules/schedules.ts +15 -15
- package/src/resources/shared.ts +1 -1
- package/src/resources/users/feeds.ts +16 -4
- package/src/resources/users/guides.ts +10 -10
- package/src/resources/users/users.ts +15 -17
- package/src/resources/workflows.ts +5 -5
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/src/client.ts
CHANGED
|
@@ -167,6 +167,8 @@ export interface ClientOptions {
|
|
|
167
167
|
*
|
|
168
168
|
* Note that request timeouts are retried by default, so in a worst-case scenario you may wait
|
|
169
169
|
* much longer than this timeout before the promise succeeds or fails.
|
|
170
|
+
*
|
|
171
|
+
* @unit milliseconds
|
|
170
172
|
*/
|
|
171
173
|
timeout?: number | undefined;
|
|
172
174
|
/**
|
|
@@ -292,17 +294,19 @@ export class Knock {
|
|
|
292
294
|
* Create a new client instance re-using the same options given to the current client with optional overriding.
|
|
293
295
|
*/
|
|
294
296
|
withOptions(options: Partial<ClientOptions>): this {
|
|
295
|
-
|
|
297
|
+
const client = new (this.constructor as any as new (props: ClientOptions) => typeof this)({
|
|
296
298
|
...this._options,
|
|
297
299
|
baseURL: this.baseURL,
|
|
298
300
|
maxRetries: this.maxRetries,
|
|
299
301
|
timeout: this.timeout,
|
|
300
302
|
logger: this.logger,
|
|
301
303
|
logLevel: this.logLevel,
|
|
304
|
+
fetch: this.fetch,
|
|
302
305
|
fetchOptions: this.fetchOptions,
|
|
303
306
|
apiKey: this.apiKey,
|
|
304
307
|
...options,
|
|
305
308
|
});
|
|
309
|
+
return client;
|
|
306
310
|
}
|
|
307
311
|
|
|
308
312
|
/**
|
|
@@ -320,7 +324,7 @@ export class Knock {
|
|
|
320
324
|
return;
|
|
321
325
|
}
|
|
322
326
|
|
|
323
|
-
protected authHeaders(opts: FinalRequestOptions): NullableHeaders | undefined {
|
|
327
|
+
protected async authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
|
|
324
328
|
return buildHeaders([{ Authorization: `Bearer ${this.apiKey}` }]);
|
|
325
329
|
}
|
|
326
330
|
|
|
@@ -436,7 +440,9 @@ export class Knock {
|
|
|
436
440
|
|
|
437
441
|
await this.prepareOptions(options);
|
|
438
442
|
|
|
439
|
-
const { req, url, timeout } = this.buildRequest(options, {
|
|
443
|
+
const { req, url, timeout } = await this.buildRequest(options, {
|
|
444
|
+
retryCount: maxRetries - retriesRemaining,
|
|
445
|
+
});
|
|
440
446
|
|
|
441
447
|
await this.prepareRequest(req, { url, options });
|
|
442
448
|
|
|
@@ -514,7 +520,7 @@ export class Knock {
|
|
|
514
520
|
} with status ${response.status} in ${headersTime - startTime}ms`;
|
|
515
521
|
|
|
516
522
|
if (!response.ok) {
|
|
517
|
-
const shouldRetry = this.shouldRetry(response);
|
|
523
|
+
const shouldRetry = await this.shouldRetry(response);
|
|
518
524
|
if (retriesRemaining && shouldRetry) {
|
|
519
525
|
const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
|
|
520
526
|
|
|
@@ -632,7 +638,7 @@ export class Knock {
|
|
|
632
638
|
}
|
|
633
639
|
}
|
|
634
640
|
|
|
635
|
-
private shouldRetry(response: Response): boolean {
|
|
641
|
+
private async shouldRetry(response: Response): Promise<boolean> {
|
|
636
642
|
// Note this is not a standard header.
|
|
637
643
|
const shouldRetryHeader = response.headers.get('x-should-retry');
|
|
638
644
|
|
|
@@ -709,10 +715,10 @@ export class Knock {
|
|
|
709
715
|
return sleepSeconds * jitter * 1000;
|
|
710
716
|
}
|
|
711
717
|
|
|
712
|
-
buildRequest(
|
|
718
|
+
async buildRequest(
|
|
713
719
|
inputOptions: FinalRequestOptions,
|
|
714
720
|
{ retryCount = 0 }: { retryCount?: number } = {},
|
|
715
|
-
): { req: FinalizedRequestInit; url: string; timeout: number } {
|
|
721
|
+
): Promise<{ req: FinalizedRequestInit; url: string; timeout: number }> {
|
|
716
722
|
const options = { ...inputOptions };
|
|
717
723
|
const { method, path, query, defaultBaseURL } = options;
|
|
718
724
|
|
|
@@ -720,7 +726,7 @@ export class Knock {
|
|
|
720
726
|
if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
|
|
721
727
|
options.timeout = options.timeout ?? this.timeout;
|
|
722
728
|
const { bodyHeaders, body } = this.buildBody({ options });
|
|
723
|
-
const reqHeaders = this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
|
|
729
|
+
const reqHeaders = await this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
|
|
724
730
|
|
|
725
731
|
const req: FinalizedRequestInit = {
|
|
726
732
|
method,
|
|
@@ -736,7 +742,7 @@ export class Knock {
|
|
|
736
742
|
return { req, url, timeout: options.timeout };
|
|
737
743
|
}
|
|
738
744
|
|
|
739
|
-
private buildHeaders({
|
|
745
|
+
private async buildHeaders({
|
|
740
746
|
options,
|
|
741
747
|
method,
|
|
742
748
|
bodyHeaders,
|
|
@@ -746,7 +752,7 @@ export class Knock {
|
|
|
746
752
|
method: HTTPMethod;
|
|
747
753
|
bodyHeaders: HeadersLike;
|
|
748
754
|
retryCount: number;
|
|
749
|
-
}): Headers {
|
|
755
|
+
}): Promise<Headers> {
|
|
750
756
|
let idempotencyHeaders: HeadersLike = {};
|
|
751
757
|
if (this.idempotencyHeader && method !== 'get') {
|
|
752
758
|
if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey();
|
|
@@ -762,7 +768,7 @@ export class Knock {
|
|
|
762
768
|
...(options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {}),
|
|
763
769
|
...getPlatformHeaders(),
|
|
764
770
|
},
|
|
765
|
-
this.authHeaders(options),
|
|
771
|
+
await this.authHeaders(options),
|
|
766
772
|
this._options.defaultHeaders,
|
|
767
773
|
bodyHeaders,
|
|
768
774
|
options.headers,
|
|
@@ -9,17 +9,70 @@ import { type HeadersLike } from './headers';
|
|
|
9
9
|
export type FinalRequestOptions = RequestOptions & { method: HTTPMethod; path: string };
|
|
10
10
|
|
|
11
11
|
export type RequestOptions = {
|
|
12
|
+
/**
|
|
13
|
+
* The HTTP method for the request (e.g., 'get', 'post', 'put', 'delete').
|
|
14
|
+
*/
|
|
12
15
|
method?: HTTPMethod;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The URL path for the request.
|
|
19
|
+
*
|
|
20
|
+
* @example "/v1/foo"
|
|
21
|
+
*/
|
|
13
22
|
path?: string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Query parameters to include in the request URL.
|
|
26
|
+
*/
|
|
14
27
|
query?: object | undefined | null;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The request body. Can be a string, JSON object, FormData, or other supported types.
|
|
31
|
+
*/
|
|
15
32
|
body?: unknown;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* HTTP headers to include with the request. Can be a Headers object, plain object, or array of tuples.
|
|
36
|
+
*/
|
|
16
37
|
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
|
+
*/
|
|
17
45
|
maxRetries?: number;
|
|
46
|
+
|
|
18
47
|
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
|
+
*/
|
|
19
55
|
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
|
+
*/
|
|
20
61
|
fetchOptions?: MergedRequestInit;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* An AbortSignal that can be used to cancel the request.
|
|
65
|
+
*/
|
|
21
66
|
signal?: AbortSignal | undefined | null;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A unique key for this request to enable idempotency.
|
|
70
|
+
*/
|
|
22
71
|
idempotencyKey?: string;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Override the default base URL for this specific request.
|
|
75
|
+
*/
|
|
23
76
|
defaultBaseURL?: string | undefined;
|
|
24
77
|
|
|
25
78
|
__binaryResponse?: boolean | undefined;
|
package/src/internal/types.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type KeysEnum<T> = { [P in keyof Required<T>]: true };
|
|
|
7
7
|
|
|
8
8
|
export type FinalizedRequestInit = RequestInit & { headers: Headers };
|
|
9
9
|
|
|
10
|
-
type NotAny<T> = [
|
|
10
|
+
type NotAny<T> = [0] extends [1 & T] ? never : T;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Some environments overload the global fetch function, and Parameters<T> only gets the last signature.
|
|
@@ -64,13 +64,15 @@ type OverloadedParameters<T> =
|
|
|
64
64
|
* [1]: https://www.typescriptlang.org/tsconfig/#typeAcquisition
|
|
65
65
|
*/
|
|
66
66
|
/** @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>;
|
|
68
68
|
/** @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>;
|
|
70
70
|
/** @ts-ignore For users with \@types/bun */
|
|
71
71
|
type BunRequestInit = globalThis.FetchRequestInit;
|
|
72
|
-
/** @ts-ignore For users with node-fetch */
|
|
73
|
-
type
|
|
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>;
|
|
74
76
|
/** @ts-ignore For users who use Deno */
|
|
75
77
|
type FetchRequestInit = NonNullable<OverloadedParameters<typeof fetch>[1]>;
|
|
76
78
|
/* eslint-enable */
|
|
@@ -79,7 +81,8 @@ type RequestInits =
|
|
|
79
81
|
| NotAny<UndiciTypesRequestInit>
|
|
80
82
|
| NotAny<UndiciRequestInit>
|
|
81
83
|
| NotAny<BunRequestInit>
|
|
82
|
-
| NotAny<
|
|
84
|
+
| NotAny<NodeFetch2RequestInit>
|
|
85
|
+
| NotAny<NodeFetch3RequestInit>
|
|
83
86
|
| NotAny<RequestInit>
|
|
84
87
|
| NotAny<FetchRequestInit>;
|
|
85
88
|
|
package/src/internal/uploads.ts
CHANGED
|
@@ -90,7 +90,7 @@ export const multipartFormRequestOptions = async (
|
|
|
90
90
|
return { ...opts, body: await createForm(opts.body, fetch) };
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
-
const supportsFormDataMap =
|
|
93
|
+
const supportsFormDataMap = /* @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>();
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
96
|
* node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
|
|
@@ -58,7 +58,7 @@ const noopLogger = {
|
|
|
58
58
|
debug: noop,
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
let cachedLoggers =
|
|
61
|
+
let cachedLoggers = /* @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();
|
|
62
62
|
|
|
63
63
|
export function loggerFor(client: Knock): Logger {
|
|
64
64
|
const logger = client.logger;
|
|
@@ -12,25 +12,43 @@ export function encodeURIPath(str: string) {
|
|
|
12
12
|
return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
16
|
+
|
|
15
17
|
export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
|
|
16
18
|
function path(statics: readonly string[], ...params: readonly unknown[]): string {
|
|
17
19
|
// If there are no params, no processing is needed.
|
|
18
20
|
if (statics.length === 1) return statics[0]!;
|
|
19
21
|
|
|
20
22
|
let postPath = false;
|
|
23
|
+
const invalidSegments = [];
|
|
21
24
|
const path = statics.reduce((previousValue, currentValue, index) => {
|
|
22
25
|
if (/[?#]/.test(currentValue)) {
|
|
23
26
|
postPath = true;
|
|
24
27
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const value = params[index];
|
|
29
|
+
let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
|
|
30
|
+
if (
|
|
31
|
+
index !== params.length &&
|
|
32
|
+
(value == null ||
|
|
33
|
+
(typeof value === 'object' &&
|
|
34
|
+
// handle values from other realms
|
|
35
|
+
value.toString ===
|
|
36
|
+
Object.getPrototypeOf(Object.getPrototypeOf((value as any).hasOwnProperty ?? EMPTY) ?? EMPTY)
|
|
37
|
+
?.toString))
|
|
38
|
+
) {
|
|
39
|
+
encoded = value + '';
|
|
40
|
+
invalidSegments.push({
|
|
41
|
+
start: previousValue.length + currentValue.length,
|
|
42
|
+
length: encoded.length,
|
|
43
|
+
error: `Value of type ${Object.prototype.toString
|
|
44
|
+
.call(value)
|
|
45
|
+
.slice(8, -1)} is not a valid path parameter`,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return previousValue + currentValue + (index === params.length ? '' : encoded);
|
|
30
49
|
}, '');
|
|
31
50
|
|
|
32
51
|
const pathOnly = path.split(/[?#]/, 1)[0]!;
|
|
33
|
-
const invalidSegments = [];
|
|
34
52
|
const invalidSegmentPattern = /(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
|
|
35
53
|
let match;
|
|
36
54
|
|
|
@@ -39,9 +57,12 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
|
|
|
39
57
|
invalidSegments.push({
|
|
40
58
|
start: match.index,
|
|
41
59
|
length: match[0].length,
|
|
60
|
+
error: `Value "${match[0]}" can\'t be safely passed as a path parameter`,
|
|
42
61
|
});
|
|
43
62
|
}
|
|
44
63
|
|
|
64
|
+
invalidSegments.sort((a, b) => a.start - b.start);
|
|
65
|
+
|
|
45
66
|
if (invalidSegments.length > 0) {
|
|
46
67
|
let lastEnd = 0;
|
|
47
68
|
const underline = invalidSegments.reduce((acc, segment) => {
|
|
@@ -51,7 +72,11 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
|
|
|
51
72
|
return acc + spaces + arrows;
|
|
52
73
|
}, '');
|
|
53
74
|
|
|
54
|
-
throw new KnockError(
|
|
75
|
+
throw new KnockError(
|
|
76
|
+
`Path parameters result in path with invalid segments:\n${invalidSegments
|
|
77
|
+
.map((e) => e.error)
|
|
78
|
+
.join('\n')}\n${path}\n${underline}`,
|
|
79
|
+
);
|
|
55
80
|
}
|
|
56
81
|
|
|
57
82
|
return path;
|
|
@@ -81,7 +81,7 @@ export interface AudienceMember {
|
|
|
81
81
|
user: UsersAPI.User;
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
|
-
* The
|
|
84
|
+
* The unique identifier of the user.
|
|
85
85
|
*/
|
|
86
86
|
user_id: string;
|
|
87
87
|
|
|
@@ -145,7 +145,7 @@ export namespace AudienceAddMembersParams {
|
|
|
145
145
|
*/
|
|
146
146
|
export interface User {
|
|
147
147
|
/**
|
|
148
|
-
* The
|
|
148
|
+
* The unique identifier of the user.
|
|
149
149
|
*/
|
|
150
150
|
id?: string;
|
|
151
151
|
}
|
|
@@ -181,7 +181,7 @@ export namespace AudienceRemoveMembersParams {
|
|
|
181
181
|
*/
|
|
182
182
|
export interface User {
|
|
183
183
|
/**
|
|
184
|
-
* The
|
|
184
|
+
* The unique identifier of the user.
|
|
185
185
|
*/
|
|
186
186
|
id?: string;
|
|
187
187
|
}
|
|
@@ -25,7 +25,7 @@ export interface CensusCustomDestinationResponse {
|
|
|
25
25
|
/**
|
|
26
26
|
* The result of the RPC call.
|
|
27
27
|
*/
|
|
28
|
-
result?:
|
|
28
|
+
result?: { [key: string]: unknown };
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export interface CensusCustomDestinationParams {
|
|
@@ -47,7 +47,7 @@ export interface CensusCustomDestinationParams {
|
|
|
47
47
|
/**
|
|
48
48
|
* The parameters for the method.
|
|
49
49
|
*/
|
|
50
|
-
params?:
|
|
50
|
+
params?: { [key: string]: unknown };
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
export declare namespace Census {
|
|
@@ -25,7 +25,7 @@ export interface HightouchEmbeddedDestinationResponse {
|
|
|
25
25
|
/**
|
|
26
26
|
* The result of the RPC call.
|
|
27
27
|
*/
|
|
28
|
-
result?:
|
|
28
|
+
result?: { [key: string]: unknown };
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export interface HightouchEmbeddedDestinationParams {
|
|
@@ -47,7 +47,7 @@ export interface HightouchEmbeddedDestinationParams {
|
|
|
47
47
|
/**
|
|
48
48
|
* The parameters for the method.
|
|
49
49
|
*/
|
|
50
|
-
params?:
|
|
50
|
+
params?: { [key: string]: unknown };
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
export declare namespace Hightouch {
|
|
@@ -275,7 +275,7 @@ export namespace BatchGetContentResponse {
|
|
|
275
275
|
}
|
|
276
276
|
|
|
277
277
|
/**
|
|
278
|
-
*
|
|
278
|
+
* Push channel data.
|
|
279
279
|
*/
|
|
280
280
|
export interface MessagePushContent {
|
|
281
281
|
/**
|
|
@@ -301,7 +301,7 @@ export namespace BatchGetContentResponse {
|
|
|
301
301
|
/**
|
|
302
302
|
* Additional data payload for the push notification.
|
|
303
303
|
*/
|
|
304
|
-
data?:
|
|
304
|
+
data?: { [key: string]: unknown } | null;
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
/**
|
|
@@ -316,7 +316,7 @@ export namespace BatchGetContentResponse {
|
|
|
316
316
|
/**
|
|
317
317
|
* The channel data connection from the recipient to the underlying provider.
|
|
318
318
|
*/
|
|
319
|
-
connection:
|
|
319
|
+
connection: { [key: string]: unknown };
|
|
320
320
|
|
|
321
321
|
/**
|
|
322
322
|
* The template structure for the chat message.
|
|
@@ -326,7 +326,7 @@ export namespace BatchGetContentResponse {
|
|
|
326
326
|
/**
|
|
327
327
|
* Additional metadata associated with the chat message.
|
|
328
328
|
*/
|
|
329
|
-
metadata?:
|
|
329
|
+
metadata?: { [key: string]: unknown } | null;
|
|
330
330
|
}
|
|
331
331
|
|
|
332
332
|
export namespace MessageChatContent {
|
|
@@ -342,7 +342,7 @@ export namespace BatchGetContentResponse {
|
|
|
342
342
|
/**
|
|
343
343
|
* The JSON content of the message.
|
|
344
344
|
*/
|
|
345
|
-
json_content?:
|
|
345
|
+
json_content?: { [key: string]: unknown } | null;
|
|
346
346
|
|
|
347
347
|
/**
|
|
348
348
|
* The summary of the chat message.
|
|
@@ -515,7 +515,7 @@ export interface BatchMarkAsInteractedParams {
|
|
|
515
515
|
/**
|
|
516
516
|
* Metadata about the interaction.
|
|
517
517
|
*/
|
|
518
|
-
metadata?:
|
|
518
|
+
metadata?: { [key: string]: unknown } | null;
|
|
519
519
|
}
|
|
520
520
|
|
|
521
521
|
export interface BatchMarkAsReadParams {
|
|
@@ -300,7 +300,7 @@ export interface Activity {
|
|
|
300
300
|
/**
|
|
301
301
|
* The workflow trigger `data` payload associated with the activity.
|
|
302
302
|
*/
|
|
303
|
-
data?:
|
|
303
|
+
data?: { [key: string]: unknown } | null;
|
|
304
304
|
|
|
305
305
|
/**
|
|
306
306
|
* Timestamp when the activity was created.
|
|
@@ -362,7 +362,7 @@ export interface Message {
|
|
|
362
362
|
* after a [batch step](/designing-workflows/batch-function), includes the payload
|
|
363
363
|
* `data` from the most-recent trigger request (the final `activity` in the batch).
|
|
364
364
|
*/
|
|
365
|
-
data?:
|
|
365
|
+
data?: { [key: string]: unknown } | null;
|
|
366
366
|
|
|
367
367
|
/**
|
|
368
368
|
* A list of engagement statuses.
|
|
@@ -387,7 +387,7 @@ export interface Message {
|
|
|
387
387
|
/**
|
|
388
388
|
* The metadata associated with the message.
|
|
389
389
|
*/
|
|
390
|
-
metadata?:
|
|
390
|
+
metadata?: { [key: string]: unknown } | null;
|
|
391
391
|
|
|
392
392
|
/**
|
|
393
393
|
* Timestamp when the message was read.
|
|
@@ -458,6 +458,11 @@ export namespace Message {
|
|
|
458
458
|
* The ID of the version of the workflow that triggered the message.
|
|
459
459
|
*/
|
|
460
460
|
version_id: string;
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* The step reference for the step in the workflow that generated the message
|
|
464
|
+
*/
|
|
465
|
+
step_ref?: string | null;
|
|
461
466
|
}
|
|
462
467
|
}
|
|
463
468
|
|
|
@@ -510,12 +515,12 @@ export namespace MessageDeliveryLog {
|
|
|
510
515
|
/**
|
|
511
516
|
* The body content that was sent with the request.
|
|
512
517
|
*/
|
|
513
|
-
body?: string |
|
|
518
|
+
body?: string | { [key: string]: unknown };
|
|
514
519
|
|
|
515
520
|
/**
|
|
516
521
|
* The headers that were sent with the request.
|
|
517
522
|
*/
|
|
518
|
-
headers?:
|
|
523
|
+
headers?: { [key: string]: unknown } | null;
|
|
519
524
|
|
|
520
525
|
/**
|
|
521
526
|
* The host to which the request was sent.
|
|
@@ -545,12 +550,12 @@ export namespace MessageDeliveryLog {
|
|
|
545
550
|
/**
|
|
546
551
|
* The body content that was received with the response.
|
|
547
552
|
*/
|
|
548
|
-
body?: string |
|
|
553
|
+
body?: string | { [key: string]: unknown };
|
|
549
554
|
|
|
550
555
|
/**
|
|
551
556
|
* The headers that were received with the response.
|
|
552
557
|
*/
|
|
553
|
-
headers?:
|
|
558
|
+
headers?: { [key: string]: unknown } | null;
|
|
554
559
|
|
|
555
560
|
/**
|
|
556
561
|
* The HTTP status code of the response.
|
|
@@ -608,7 +613,7 @@ export interface MessageEvent {
|
|
|
608
613
|
/**
|
|
609
614
|
* The data associated with the message event. Only present for some event types.
|
|
610
615
|
*/
|
|
611
|
-
data?:
|
|
616
|
+
data?: { [key: string]: unknown } | null;
|
|
612
617
|
}
|
|
613
618
|
|
|
614
619
|
/**
|
|
@@ -713,7 +718,7 @@ export namespace MessageGetContentResponse {
|
|
|
713
718
|
}
|
|
714
719
|
|
|
715
720
|
/**
|
|
716
|
-
*
|
|
721
|
+
* Push channel data.
|
|
717
722
|
*/
|
|
718
723
|
export interface MessagePushContent {
|
|
719
724
|
/**
|
|
@@ -739,7 +744,7 @@ export namespace MessageGetContentResponse {
|
|
|
739
744
|
/**
|
|
740
745
|
* Additional data payload for the push notification.
|
|
741
746
|
*/
|
|
742
|
-
data?:
|
|
747
|
+
data?: { [key: string]: unknown } | null;
|
|
743
748
|
}
|
|
744
749
|
|
|
745
750
|
/**
|
|
@@ -754,7 +759,7 @@ export namespace MessageGetContentResponse {
|
|
|
754
759
|
/**
|
|
755
760
|
* The channel data connection from the recipient to the underlying provider.
|
|
756
761
|
*/
|
|
757
|
-
connection:
|
|
762
|
+
connection: { [key: string]: unknown };
|
|
758
763
|
|
|
759
764
|
/**
|
|
760
765
|
* The template structure for the chat message.
|
|
@@ -764,7 +769,7 @@ export namespace MessageGetContentResponse {
|
|
|
764
769
|
/**
|
|
765
770
|
* Additional metadata associated with the chat message.
|
|
766
771
|
*/
|
|
767
|
-
metadata?:
|
|
772
|
+
metadata?: { [key: string]: unknown } | null;
|
|
768
773
|
}
|
|
769
774
|
|
|
770
775
|
export namespace MessageChatContent {
|
|
@@ -780,7 +785,7 @@ export namespace MessageGetContentResponse {
|
|
|
780
785
|
/**
|
|
781
786
|
* The JSON content of the message.
|
|
782
787
|
*/
|
|
783
|
-
json_content?:
|
|
788
|
+
json_content?: { [key: string]: unknown } | null;
|
|
784
789
|
|
|
785
790
|
/**
|
|
786
791
|
* The summary of the chat message.
|
|
@@ -1000,7 +1005,7 @@ export interface MessageMarkAsInteractedParams {
|
|
|
1000
1005
|
/**
|
|
1001
1006
|
* Metadata about the interaction.
|
|
1002
1007
|
*/
|
|
1003
|
-
metadata?:
|
|
1008
|
+
metadata?: { [key: string]: unknown };
|
|
1004
1009
|
}
|
|
1005
1010
|
|
|
1006
1011
|
Messages.Batch = Batch;
|
|
@@ -121,7 +121,7 @@ export namespace BulkAddSubscriptionsParams {
|
|
|
121
121
|
/**
|
|
122
122
|
* The custom properties associated with the subscription relationship.
|
|
123
123
|
*/
|
|
124
|
-
properties?:
|
|
124
|
+
properties?: { [key: string]: unknown } | null;
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
|
|
@@ -479,7 +479,7 @@ export interface Object {
|
|
|
479
479
|
/**
|
|
480
480
|
* The custom properties associated with the object.
|
|
481
481
|
*/
|
|
482
|
-
properties?:
|
|
482
|
+
properties?: { [key: string]: unknown };
|
|
483
483
|
}
|
|
484
484
|
|
|
485
485
|
/**
|
|
@@ -524,7 +524,7 @@ export interface ObjectAddSubscriptionsParams {
|
|
|
524
524
|
/**
|
|
525
525
|
* The custom properties associated with the subscription relationship.
|
|
526
526
|
*/
|
|
527
|
-
properties?:
|
|
527
|
+
properties?: { [key: string]: unknown } | null;
|
|
528
528
|
}
|
|
529
529
|
|
|
530
530
|
export interface ObjectDeleteSubscriptionsParams {
|
|
@@ -721,10 +721,9 @@ export interface ObjectSetPreferencesParams {
|
|
|
721
721
|
* An object where the key is the category and the values are the preference
|
|
722
722
|
* settings for that category.
|
|
723
723
|
*/
|
|
724
|
-
categories?:
|
|
725
|
-
string
|
|
726
|
-
|
|
727
|
-
> | null;
|
|
724
|
+
categories?: {
|
|
725
|
+
[key: string]: boolean | ObjectSetPreferencesParams.PreferenceSetWorkflowCategorySettingObject;
|
|
726
|
+
} | null;
|
|
728
727
|
|
|
729
728
|
/**
|
|
730
729
|
* Channel type preferences.
|
|
@@ -735,10 +734,9 @@ export interface ObjectSetPreferencesParams {
|
|
|
735
734
|
* An object where the key is the workflow key and the values are the preference
|
|
736
735
|
* settings for that workflow.
|
|
737
736
|
*/
|
|
738
|
-
workflows?:
|
|
739
|
-
string
|
|
740
|
-
|
|
741
|
-
> | null;
|
|
737
|
+
workflows?: {
|
|
738
|
+
[key: string]: boolean | ObjectSetPreferencesParams.PreferenceSetWorkflowCategorySettingObject;
|
|
739
|
+
} | null;
|
|
742
740
|
}
|
|
743
741
|
|
|
744
742
|
export namespace ObjectSetPreferencesParams {
|
|
@@ -189,7 +189,8 @@ export namespace SlackListChannelsParams {
|
|
|
189
189
|
/**
|
|
190
190
|
* Mix and match channel types by providing a comma-separated list of any
|
|
191
191
|
* combination of public_channel, private_channel, mpim, im. Defaults to
|
|
192
|
-
* `"public_channel,private_channel"`.
|
|
192
|
+
* `"public_channel,private_channel"`. If the user's Slack ID is unavailable, this
|
|
193
|
+
* option is ignored and only public channels are returned.
|
|
193
194
|
*/
|
|
194
195
|
types?: string;
|
|
195
196
|
}
|