@knocklabs/node 1.10.3 → 1.11.1

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.
Files changed (152) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/client.d.mts +5 -3
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +5 -3
  5. package/client.d.ts.map +1 -1
  6. package/client.js +12 -9
  7. package/client.js.map +1 -1
  8. package/client.mjs +12 -9
  9. package/client.mjs.map +1 -1
  10. package/index.d.mts +1 -0
  11. package/index.d.mts.map +1 -1
  12. package/index.d.ts +1 -0
  13. package/index.d.ts.map +1 -1
  14. package/index.js +4 -1
  15. package/index.js.map +1 -1
  16. package/index.mjs +1 -0
  17. package/index.mjs.map +1 -1
  18. package/internal/request-options.d.mts +42 -0
  19. package/internal/request-options.d.mts.map +1 -1
  20. package/internal/request-options.d.ts +42 -0
  21. package/internal/request-options.d.ts.map +1 -1
  22. package/internal/request-options.js.map +1 -1
  23. package/internal/request-options.mjs.map +1 -1
  24. package/internal/types.d.mts +8 -6
  25. package/internal/types.d.mts.map +1 -1
  26. package/internal/types.d.ts +8 -6
  27. package/internal/types.d.ts.map +1 -1
  28. package/internal/uploads.js +1 -1
  29. package/internal/uploads.js.map +1 -1
  30. package/internal/uploads.mjs +1 -1
  31. package/internal/uploads.mjs.map +1 -1
  32. package/internal/utils/log.js +1 -1
  33. package/internal/utils/log.js.map +1 -1
  34. package/internal/utils/log.mjs +1 -1
  35. package/internal/utils/log.mjs.map +1 -1
  36. package/internal/utils/path.d.mts.map +1 -1
  37. package/internal/utils/path.d.ts.map +1 -1
  38. package/internal/utils/path.js +26 -5
  39. package/internal/utils/path.js.map +1 -1
  40. package/internal/utils/path.mjs +26 -5
  41. package/internal/utils/path.mjs.map +1 -1
  42. package/package.json +2 -7
  43. package/resources/audiences.d.mts +3 -3
  44. package/resources/audiences.d.ts +3 -3
  45. package/resources/integrations/census.d.mts +6 -2
  46. package/resources/integrations/census.d.mts.map +1 -1
  47. package/resources/integrations/census.d.ts +6 -2
  48. package/resources/integrations/census.d.ts.map +1 -1
  49. package/resources/integrations/hightouch.d.mts +6 -2
  50. package/resources/integrations/hightouch.d.mts.map +1 -1
  51. package/resources/integrations/hightouch.d.ts +6 -2
  52. package/resources/integrations/hightouch.d.ts.map +1 -1
  53. package/resources/messages/batch.d.mts +16 -6
  54. package/resources/messages/batch.d.mts.map +1 -1
  55. package/resources/messages/batch.d.ts +16 -6
  56. package/resources/messages/batch.d.ts.map +1 -1
  57. package/resources/messages/messages.d.mts +44 -14
  58. package/resources/messages/messages.d.mts.map +1 -1
  59. package/resources/messages/messages.d.ts +44 -14
  60. package/resources/messages/messages.d.ts.map +1 -1
  61. package/resources/messages/messages.js.map +1 -1
  62. package/resources/messages/messages.mjs.map +1 -1
  63. package/resources/objects/bulk.d.mts +3 -1
  64. package/resources/objects/bulk.d.mts.map +1 -1
  65. package/resources/objects/bulk.d.ts +3 -1
  66. package/resources/objects/bulk.d.ts.map +1 -1
  67. package/resources/objects/objects.d.mts +12 -4
  68. package/resources/objects/objects.d.mts.map +1 -1
  69. package/resources/objects/objects.d.ts +12 -4
  70. package/resources/objects/objects.d.ts.map +1 -1
  71. package/resources/objects/objects.js.map +1 -1
  72. package/resources/objects/objects.mjs.map +1 -1
  73. package/resources/providers/slack.d.mts +2 -1
  74. package/resources/providers/slack.d.mts.map +1 -1
  75. package/resources/providers/slack.d.ts +2 -1
  76. package/resources/providers/slack.d.ts.map +1 -1
  77. package/resources/recipients/channel-data.d.mts +6 -4
  78. package/resources/recipients/channel-data.d.mts.map +1 -1
  79. package/resources/recipients/channel-data.d.ts +6 -4
  80. package/resources/recipients/channel-data.d.ts.map +1 -1
  81. package/resources/recipients/preferences.d.mts +15 -5
  82. package/resources/recipients/preferences.d.mts.map +1 -1
  83. package/resources/recipients/preferences.d.ts +15 -5
  84. package/resources/recipients/preferences.d.ts.map +1 -1
  85. package/resources/recipients/subscriptions.d.mts +3 -1
  86. package/resources/recipients/subscriptions.d.mts.map +1 -1
  87. package/resources/recipients/subscriptions.d.ts +3 -1
  88. package/resources/recipients/subscriptions.d.ts.map +1 -1
  89. package/resources/schedules/bulk.d.mts +7 -5
  90. package/resources/schedules/bulk.d.mts.map +1 -1
  91. package/resources/schedules/bulk.d.ts +7 -5
  92. package/resources/schedules/bulk.d.ts.map +1 -1
  93. package/resources/schedules/schedules.d.mts +21 -15
  94. package/resources/schedules/schedules.d.mts.map +1 -1
  95. package/resources/schedules/schedules.d.ts +21 -15
  96. package/resources/schedules/schedules.d.ts.map +1 -1
  97. package/resources/shared.d.mts +1 -1
  98. package/resources/shared.d.ts +1 -1
  99. package/resources/users/feeds.d.mts +18 -4
  100. package/resources/users/feeds.d.mts.map +1 -1
  101. package/resources/users/feeds.d.ts +18 -4
  102. package/resources/users/feeds.d.ts.map +1 -1
  103. package/resources/users/feeds.js +14 -2
  104. package/resources/users/feeds.js.map +1 -1
  105. package/resources/users/feeds.mjs +14 -2
  106. package/resources/users/feeds.mjs.map +1 -1
  107. package/resources/users/guides.d.mts +30 -10
  108. package/resources/users/guides.d.mts.map +1 -1
  109. package/resources/users/guides.d.ts +30 -10
  110. package/resources/users/guides.d.ts.map +1 -1
  111. package/resources/users/users.d.mts +15 -11
  112. package/resources/users/users.d.mts.map +1 -1
  113. package/resources/users/users.d.ts +15 -11
  114. package/resources/users/users.d.ts.map +1 -1
  115. package/resources/users/users.js +3 -3
  116. package/resources/users/users.js.map +1 -1
  117. package/resources/users/users.mjs +3 -3
  118. package/resources/users/users.mjs.map +1 -1
  119. package/resources/workflows.d.mts +7 -5
  120. package/resources/workflows.d.mts.map +1 -1
  121. package/resources/workflows.d.ts +7 -5
  122. package/resources/workflows.d.ts.map +1 -1
  123. package/src/client.ts +16 -11
  124. package/src/index.ts +3 -0
  125. package/src/internal/request-options.ts +53 -0
  126. package/src/internal/types.ts +9 -6
  127. package/src/internal/uploads.ts +1 -1
  128. package/src/internal/utils/log.ts +1 -1
  129. package/src/internal/utils/path.ts +32 -7
  130. package/src/resources/audiences.ts +3 -3
  131. package/src/resources/integrations/census.ts +2 -2
  132. package/src/resources/integrations/hightouch.ts +2 -2
  133. package/src/resources/messages/batch.ts +6 -6
  134. package/src/resources/messages/messages.ts +19 -14
  135. package/src/resources/objects/bulk.ts +1 -1
  136. package/src/resources/objects/objects.ts +8 -10
  137. package/src/resources/providers/slack.ts +2 -1
  138. package/src/resources/recipients/channel-data.ts +11 -7
  139. package/src/resources/recipients/preferences.ts +9 -11
  140. package/src/resources/recipients/subscriptions.ts +1 -1
  141. package/src/resources/schedules/bulk.ts +5 -5
  142. package/src/resources/schedules/schedules.ts +15 -15
  143. package/src/resources/shared.ts +1 -1
  144. package/src/resources/users/feeds.ts +16 -4
  145. package/src/resources/users/guides.ts +10 -10
  146. package/src/resources/users/users.ts +15 -17
  147. package/src/resources/workflows.ts +5 -5
  148. package/src/version.ts +1 -1
  149. package/version.d.mts +1 -1
  150. package/version.d.ts +1 -1
  151. package/version.js +1 -1
  152. 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,7 +294,7 @@ 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
- 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)({
296
298
  ...this._options,
297
299
  baseURL: this.baseURL,
298
300
  maxRetries: this.maxRetries,
@@ -304,6 +306,7 @@ export class Knock {
304
306
  apiKey: this.apiKey,
305
307
  ...options,
306
308
  });
309
+ return client;
307
310
  }
308
311
 
309
312
  /**
@@ -321,7 +324,7 @@ export class Knock {
321
324
  return;
322
325
  }
323
326
 
324
- protected authHeaders(opts: FinalRequestOptions): NullableHeaders | undefined {
327
+ protected async authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
325
328
  return buildHeaders([{ Authorization: `Bearer ${this.apiKey}` }]);
326
329
  }
327
330
 
@@ -437,7 +440,9 @@ export class Knock {
437
440
 
438
441
  await this.prepareOptions(options);
439
442
 
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
+ });
441
446
 
442
447
  await this.prepareRequest(req, { url, options });
443
448
 
@@ -515,7 +520,7 @@ export class Knock {
515
520
  } with status ${response.status} in ${headersTime - startTime}ms`;
516
521
 
517
522
  if (!response.ok) {
518
- const shouldRetry = this.shouldRetry(response);
523
+ const shouldRetry = await this.shouldRetry(response);
519
524
  if (retriesRemaining && shouldRetry) {
520
525
  const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
521
526
 
@@ -633,7 +638,7 @@ export class Knock {
633
638
  }
634
639
  }
635
640
 
636
- private shouldRetry(response: Response): boolean {
641
+ private async shouldRetry(response: Response): Promise<boolean> {
637
642
  // Note this is not a standard header.
638
643
  const shouldRetryHeader = response.headers.get('x-should-retry');
639
644
 
@@ -710,10 +715,10 @@ export class Knock {
710
715
  return sleepSeconds * jitter * 1000;
711
716
  }
712
717
 
713
- buildRequest(
718
+ async buildRequest(
714
719
  inputOptions: FinalRequestOptions,
715
720
  { retryCount = 0 }: { retryCount?: number } = {},
716
- ): { req: FinalizedRequestInit; url: string; timeout: number } {
721
+ ): Promise<{ req: FinalizedRequestInit; url: string; timeout: number }> {
717
722
  const options = { ...inputOptions };
718
723
  const { method, path, query, defaultBaseURL } = options;
719
724
 
@@ -721,7 +726,7 @@ export class Knock {
721
726
  if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
722
727
  options.timeout = options.timeout ?? this.timeout;
723
728
  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 });
725
730
 
726
731
  const req: FinalizedRequestInit = {
727
732
  method,
@@ -737,7 +742,7 @@ export class Knock {
737
742
  return { req, url, timeout: options.timeout };
738
743
  }
739
744
 
740
- private buildHeaders({
745
+ private async buildHeaders({
741
746
  options,
742
747
  method,
743
748
  bodyHeaders,
@@ -747,7 +752,7 @@ export class Knock {
747
752
  method: HTTPMethod;
748
753
  bodyHeaders: HeadersLike;
749
754
  retryCount: number;
750
- }): Headers {
755
+ }): Promise<Headers> {
751
756
  let idempotencyHeaders: HeadersLike = {};
752
757
  if (this.idempotencyHeader && method !== 'get') {
753
758
  if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey();
@@ -763,7 +768,7 @@ export class Knock {
763
768
  ...(options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {}),
764
769
  ...getPlatformHeaders(),
765
770
  },
766
- this.authHeaders(options),
771
+ await this.authHeaders(options),
767
772
  this._options.defaultHeaders,
768
773
  bodyHeaders,
769
774
  options.headers,
package/src/index.ts CHANGED
@@ -21,3 +21,6 @@ export {
21
21
  PermissionDeniedError,
22
22
  UnprocessableEntityError,
23
23
  } from './core/error';
24
+
25
+ // Explicitly exported to follow pre-stainless implementation of this package.
26
+ export { signUserToken } from './lib/tokenSigner';
@@ -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;
@@ -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> = [unknown] extends [T] ? never : 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 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>;
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<NodeFetchRequestInit>
84
+ | NotAny<NodeFetch2RequestInit>
85
+ | NotAny<NodeFetch3RequestInit>
83
86
  | NotAny<RequestInit>
84
87
  | NotAny<FetchRequestInit>;
85
88
 
@@ -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 = /** @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>();
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 = /** @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();
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
- return (
26
- previousValue +
27
- currentValue +
28
- (index === params.length ? '' : (postPath ? encodeURIComponent : pathEncoder)(String(params[index])))
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(`Path parameters result in path with invalid segments:\n${path}\n${underline}`);
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 ID for the user that you set when identifying them in Knock.
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 ID for the user that you set when identifying them in Knock.
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 ID for the user that you set when identifying them in Knock.
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?: Record<string, unknown>;
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?: Record<string, unknown>;
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?: Record<string, unknown>;
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?: Record<string, unknown>;
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
- * The content of a push notification.
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?: Record<string, unknown> | null;
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: Record<string, unknown>;
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?: Record<string, unknown> | null;
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?: Record<string, unknown> | null;
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?: Record<string, unknown> | null;
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?: Record<string, unknown> | null;
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?: Record<string, unknown> | null;
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?: Record<string, unknown> | null;
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 | Record<string, unknown>;
518
+ body?: string | { [key: string]: unknown };
514
519
 
515
520
  /**
516
521
  * The headers that were sent with the request.
517
522
  */
518
- headers?: Record<string, unknown> | null;
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 | Record<string, unknown>;
553
+ body?: string | { [key: string]: unknown };
549
554
 
550
555
  /**
551
556
  * The headers that were received with the response.
552
557
  */
553
- headers?: Record<string, unknown> | null;
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?: Record<string, unknown> | null;
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
- * The content of a push notification.
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?: Record<string, unknown> | null;
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: Record<string, unknown>;
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?: Record<string, unknown> | null;
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?: Record<string, unknown> | null;
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?: Record<string, unknown>;
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?: Record<string, unknown> | null;
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?: Record<string, unknown>;
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?: Record<string, unknown> | null;
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?: Record<
725
- string,
726
- boolean | ObjectSetPreferencesParams.PreferenceSetWorkflowCategorySettingObject
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?: Record<
739
- string,
740
- boolean | ObjectSetPreferencesParams.PreferenceSetWorkflowCategorySettingObject
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
  }