@knocklabs/node 1.7.0 → 1.9.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.
Files changed (124) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +48 -0
  3. package/core/resource.d.mts +1 -1
  4. package/core/resource.d.mts.map +1 -1
  5. package/core/resource.d.ts +1 -1
  6. package/core/resource.d.ts.map +1 -1
  7. package/core/resource.js.map +1 -1
  8. package/core/resource.mjs.map +1 -1
  9. package/internal/headers.d.mts.map +1 -1
  10. package/internal/headers.d.ts.map +1 -1
  11. package/internal/headers.js +4 -4
  12. package/internal/headers.js.map +1 -1
  13. package/internal/headers.mjs +4 -4
  14. package/internal/headers.mjs.map +1 -1
  15. package/internal/qs/formats.d.mts +1 -0
  16. package/internal/qs/formats.d.mts.map +1 -1
  17. package/internal/qs/formats.d.ts +1 -0
  18. package/internal/qs/formats.d.ts.map +1 -1
  19. package/internal/qs/formats.js +4 -2
  20. package/internal/qs/formats.js.map +1 -1
  21. package/internal/qs/formats.mjs +2 -1
  22. package/internal/qs/formats.mjs.map +1 -1
  23. package/internal/qs/stringify.d.mts.map +1 -1
  24. package/internal/qs/stringify.d.ts.map +1 -1
  25. package/internal/qs/stringify.js +15 -17
  26. package/internal/qs/stringify.js.map +1 -1
  27. package/internal/qs/stringify.mjs +17 -19
  28. package/internal/qs/stringify.mjs.map +1 -1
  29. package/internal/qs/utils.d.mts +1 -0
  30. package/internal/qs/utils.d.mts.map +1 -1
  31. package/internal/qs/utils.d.ts +1 -0
  32. package/internal/qs/utils.d.ts.map +1 -1
  33. package/internal/qs/utils.js +14 -13
  34. package/internal/qs/utils.js.map +1 -1
  35. package/internal/qs/utils.mjs +12 -12
  36. package/internal/qs/utils.mjs.map +1 -1
  37. package/internal/uploads.js +1 -1
  38. package/internal/uploads.js.map +1 -1
  39. package/internal/uploads.mjs +1 -1
  40. package/internal/uploads.mjs.map +1 -1
  41. package/internal/utils/log.js +1 -1
  42. package/internal/utils/log.js.map +1 -1
  43. package/internal/utils/log.mjs +1 -1
  44. package/internal/utils/log.mjs.map +1 -1
  45. package/internal/utils/path.d.mts.map +1 -1
  46. package/internal/utils/path.d.ts.map +1 -1
  47. package/internal/utils/path.js.map +1 -1
  48. package/internal/utils/path.mjs +1 -1
  49. package/internal/utils/path.mjs.map +1 -1
  50. package/internal/utils/values.d.mts +2 -0
  51. package/internal/utils/values.d.mts.map +1 -1
  52. package/internal/utils/values.d.ts +2 -0
  53. package/internal/utils/values.d.ts.map +1 -1
  54. package/internal/utils/values.js +4 -1
  55. package/internal/utils/values.js.map +1 -1
  56. package/internal/utils/values.mjs +2 -0
  57. package/internal/utils/values.mjs.map +1 -1
  58. package/lib/tokenSigner.d.mts.map +1 -1
  59. package/lib/tokenSigner.d.ts.map +1 -1
  60. package/lib/tokenSigner.js +40 -31
  61. package/lib/tokenSigner.js.map +1 -1
  62. package/lib/tokenSigner.mjs +7 -30
  63. package/lib/tokenSigner.mjs.map +1 -1
  64. package/package.json +9 -2
  65. package/resources/objects/bulk.d.mts +2 -0
  66. package/resources/objects/bulk.d.mts.map +1 -1
  67. package/resources/objects/bulk.d.ts +2 -0
  68. package/resources/objects/bulk.d.ts.map +1 -1
  69. package/resources/objects/objects.d.mts +4 -0
  70. package/resources/objects/objects.d.mts.map +1 -1
  71. package/resources/objects/objects.d.ts +4 -0
  72. package/resources/objects/objects.d.ts.map +1 -1
  73. package/resources/objects/objects.js.map +1 -1
  74. package/resources/objects/objects.mjs.map +1 -1
  75. package/resources/providers/slack.d.mts +5 -3
  76. package/resources/providers/slack.d.mts.map +1 -1
  77. package/resources/providers/slack.d.ts +5 -3
  78. package/resources/providers/slack.d.ts.map +1 -1
  79. package/resources/recipients/preferences.d.mts +2 -0
  80. package/resources/recipients/preferences.d.mts.map +1 -1
  81. package/resources/recipients/preferences.d.ts +2 -0
  82. package/resources/recipients/preferences.d.ts.map +1 -1
  83. package/resources/tenants/tenants.d.mts +2 -0
  84. package/resources/tenants/tenants.d.mts.map +1 -1
  85. package/resources/tenants/tenants.d.ts +2 -0
  86. package/resources/tenants/tenants.d.ts.map +1 -1
  87. package/resources/tenants/tenants.js.map +1 -1
  88. package/resources/tenants/tenants.mjs.map +1 -1
  89. package/resources/users/bulk.d.mts +8 -7
  90. package/resources/users/bulk.d.mts.map +1 -1
  91. package/resources/users/bulk.d.ts +8 -7
  92. package/resources/users/bulk.d.ts.map +1 -1
  93. package/resources/users/bulk.js +8 -7
  94. package/resources/users/bulk.js.map +1 -1
  95. package/resources/users/bulk.mjs +8 -7
  96. package/resources/users/bulk.mjs.map +1 -1
  97. package/resources/users/users.d.mts +6 -0
  98. package/resources/users/users.d.mts.map +1 -1
  99. package/resources/users/users.d.ts +6 -0
  100. package/resources/users/users.d.ts.map +1 -1
  101. package/resources/users/users.js.map +1 -1
  102. package/resources/users/users.mjs.map +1 -1
  103. package/src/core/resource.ts +1 -1
  104. package/src/internal/headers.ts +5 -5
  105. package/src/internal/qs/formats.ts +2 -1
  106. package/src/internal/qs/stringify.ts +17 -20
  107. package/src/internal/qs/utils.ts +14 -14
  108. package/src/internal/uploads.ts +2 -2
  109. package/src/internal/utils/log.ts +1 -1
  110. package/src/internal/utils/path.ts +1 -1
  111. package/src/internal/utils/values.ts +3 -0
  112. package/src/lib/tokenSigner.ts +16 -39
  113. package/src/resources/objects/bulk.ts +2 -0
  114. package/src/resources/objects/objects.ts +4 -0
  115. package/src/resources/providers/slack.ts +5 -3
  116. package/src/resources/recipients/preferences.ts +2 -0
  117. package/src/resources/tenants/tenants.ts +2 -0
  118. package/src/resources/users/bulk.ts +8 -7
  119. package/src/resources/users/users.ts +6 -0
  120. package/src/version.ts +1 -1
  121. package/version.d.mts +1 -1
  122. package/version.d.ts +1 -1
  123. package/version.js +1 -1
  124. package/version.mjs +1 -1
@@ -1,10 +1,13 @@
1
1
  import { RFC1738 } from './formats';
2
2
  import type { DefaultEncoder, Format } from './types';
3
+ import { isArray } from '../utils/values';
3
4
 
4
- const has = Object.prototype.hasOwnProperty;
5
- const is_array = Array.isArray;
5
+ export let has = (obj: object, key: PropertyKey): boolean => (
6
+ (has = (Object as any).hasOwn ?? Function.prototype.call.bind(Object.prototype.hasOwnProperty)),
7
+ has(obj, key)
8
+ );
6
9
 
7
- const hex_table = (() => {
10
+ const hex_table = /* @__PURE__ */ (() => {
8
11
  const array = [];
9
12
  for (let i = 0; i < 256; ++i) {
10
13
  array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());
@@ -20,7 +23,7 @@ function compact_queue<T extends Record<string, any>>(queue: Array<{ obj: T; pro
20
23
 
21
24
  const obj = item.obj[item.prop];
22
25
 
23
- if (is_array(obj)) {
26
+ if (isArray(obj)) {
24
27
  const compacted: unknown[] = [];
25
28
 
26
29
  for (let j = 0; j < obj.length; ++j) {
@@ -56,13 +59,10 @@ export function merge(
56
59
  }
57
60
 
58
61
  if (typeof source !== 'object') {
59
- if (is_array(target)) {
62
+ if (isArray(target)) {
60
63
  target.push(source);
61
64
  } else if (target && typeof target === 'object') {
62
- if (
63
- (options && (options.plainObjects || options.allowPrototypes)) ||
64
- !has.call(Object.prototype, source)
65
- ) {
65
+ if ((options && (options.plainObjects || options.allowPrototypes)) || !has(Object.prototype, source)) {
66
66
  target[source] = true;
67
67
  }
68
68
  } else {
@@ -77,14 +77,14 @@ export function merge(
77
77
  }
78
78
 
79
79
  let mergeTarget = target;
80
- if (is_array(target) && !is_array(source)) {
80
+ if (isArray(target) && !isArray(source)) {
81
81
  // @ts-ignore
82
82
  mergeTarget = array_to_object(target, options);
83
83
  }
84
84
 
85
- if (is_array(target) && is_array(source)) {
85
+ if (isArray(target) && isArray(source)) {
86
86
  source.forEach(function (item, i) {
87
- if (has.call(target, i)) {
87
+ if (has(target, i)) {
88
88
  const targetItem = target[i];
89
89
  if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') {
90
90
  target[i] = merge(targetItem, item, options);
@@ -101,7 +101,7 @@ export function merge(
101
101
  return Object.keys(source).reduce(function (acc, key) {
102
102
  const value = source[key];
103
103
 
104
- if (has.call(acc, key)) {
104
+ if (has(acc, key)) {
105
105
  acc[key] = merge(acc[key], value, options);
106
106
  } else {
107
107
  acc[key] = value;
@@ -254,7 +254,7 @@ export function combine(a: any, b: any) {
254
254
  }
255
255
 
256
256
  export function maybe_map<T>(val: T[], fn: (v: T) => T) {
257
- if (is_array(val)) {
257
+ if (isArray(val)) {
258
258
  const mapped = [];
259
259
  for (let i = 0; i < val.length; i += 1) {
260
260
  mapped.push(fn(val[i]!));
@@ -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 = 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
@@ -138,7 +138,7 @@ export const createForm = async <T = Record<string, unknown>>(
138
138
 
139
139
  // We check for Blob not File because Bun.File doesn't inherit from File,
140
140
  // but they both inherit from Blob and have a `name` property at runtime.
141
- const isNamedBlob = (value: object) => value instanceof Blob && 'name' in value;
141
+ const isNamedBlob = (value: unknown) => value instanceof Blob && 'name' in value;
142
142
 
143
143
  const isUploadable = (value: unknown) =>
144
144
  typeof value === 'object' &&
@@ -58,7 +58,7 @@ const noopLogger = {
58
58
  debug: noop,
59
59
  };
60
60
 
61
- let cachedLoggers = 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;
@@ -60,4 +60,4 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
60
60
  /**
61
61
  * URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
62
62
  */
63
- export const path = createPathTagFunction(encodeURIPath);
63
+ export const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
@@ -9,6 +9,9 @@ export const isAbsoluteURL = (url: string): boolean => {
9
9
  return startsWithSchemeRegexp.test(url);
10
10
  };
11
11
 
12
+ export let isArray = (val: unknown): val is unknown[] => ((isArray = Array.isArray), isArray(val));
13
+ export let isReadonlyArray = isArray as (val: unknown) => val is readonly unknown[];
14
+
12
15
  /** Returns an object if the given value isn't an object, otherwise returns as-is */
13
16
  export function maybeObj(x: unknown): object {
14
17
  if (typeof x !== 'object') {
@@ -2,7 +2,7 @@
2
2
  * Token signing functionality for Knock authentication
3
3
  */
4
4
 
5
- import * as crypto from 'crypto';
5
+ import type { JWTPayload, JWTHeaderParameters } from 'jose';
6
6
  import type { TokenEntity, TokenGrant, TokenGrantOptions } from './userTokens';
7
7
 
8
8
  // Default hostname for Knock API
@@ -65,38 +65,20 @@ function prepareTokenEntityUri(entity: TokenEntity): string {
65
65
  }
66
66
 
67
67
  /**
68
- * Create and sign a JWT using Node.js crypto
68
+ * Create and sign a JWT using jose
69
69
  */
70
- function createJWT(header: object, payload: object, privateKey: string): string {
71
- // Base64Url encode the header
72
- const headerBase64 = Buffer.from(JSON.stringify(header))
73
- .toString('base64')
74
- .replace(/=/g, '')
75
- .replace(/\+/g, '-')
76
- .replace(/\//g, '_');
77
-
78
- // Base64Url encode the payload
79
- const payloadBase64 = Buffer.from(JSON.stringify(payload))
80
- .toString('base64')
81
- .replace(/=/g, '')
82
- .replace(/\+/g, '-')
83
- .replace(/\//g, '_');
84
-
85
- // Create the content to sign
86
- const signatureContent = `${headerBase64}.${payloadBase64}`;
87
-
88
- // Sign the content
89
- const signer = crypto.createSign('RSA-SHA256');
90
- signer.update(signatureContent);
91
-
92
- const signature = signer
93
- .sign(privateKey, 'base64')
94
- .replace(/=/g, '')
95
- .replace(/\+/g, '-')
96
- .replace(/\//g, '_');
97
-
98
- // Combine to create the JWT
99
- return `${signatureContent}.${signature}`;
70
+ async function createJWT(
71
+ header: JWTHeaderParameters,
72
+ payload: JWTPayload,
73
+ privateKey: string,
74
+ ): Promise<string> {
75
+ const { SignJWT, importPKCS8 } = await import('jose');
76
+ const key = await importPKCS8(privateKey, 'RS256');
77
+
78
+ const jwt = new SignJWT(payload);
79
+ jwt.setProtectedHeader(header);
80
+
81
+ return jwt.sign(key);
100
82
  }
101
83
 
102
84
  /**
@@ -144,27 +126,22 @@ export function buildUserTokenGrant(entity: TokenEntity, grants: TokenGrantOptio
144
126
  */
145
127
  export async function signUserToken(userId: string, options?: SignUserTokenOptions): Promise<string> {
146
128
  const signingKey = prepareSigningKey(options?.signingKey);
147
-
148
129
  // JWT NumericDates specified in seconds
149
130
  const currentTime = Math.floor(Date.now() / 1000);
150
-
151
131
  // Default to 1 hour from now
152
132
  const expireInSeconds = options?.expiresInSeconds ?? 60 * 60;
153
133
 
154
- // Create JWT header
155
- const header = {
134
+ const header: JWTHeaderParameters = {
156
135
  alg: 'RS256',
157
136
  typ: 'JWT',
158
137
  };
159
138
 
160
- // Create JWT payload
161
- const payload = {
139
+ const payload: JWTPayload = {
162
140
  sub: userId,
163
141
  grants: maybePrepareUserTokenGrants(options?.grants),
164
142
  iat: currentTime,
165
143
  exp: currentTime + expireInSeconds,
166
144
  };
167
145
 
168
- // Create and sign the JWT
169
146
  return createJWT(header, payload, signingKey);
170
147
  }
@@ -154,6 +154,8 @@ export namespace BulkSetParams {
154
154
 
155
155
  /**
156
156
  * Inline set preferences for a recipient, where the key is the preference set id.
157
+ * Preferences that are set inline will be merged into any existing preferences
158
+ * rather than replacing them.
157
159
  */
158
160
  preferences?: PreferencesAPI.InlinePreferenceSetRequest | null;
159
161
 
@@ -439,6 +439,8 @@ export interface InlineObjectRequest {
439
439
 
440
440
  /**
441
441
  * Inline set preferences for a recipient, where the key is the preference set id.
442
+ * Preferences that are set inline will be merged into any existing preferences
443
+ * rather than replacing them.
442
444
  */
443
445
  preferences?: PreferencesAPI.InlinePreferenceSetRequest | null;
444
446
 
@@ -686,6 +688,8 @@ export interface ObjectSetParams {
686
688
 
687
689
  /**
688
690
  * Inline set preferences for a recipient, where the key is the preference set id.
691
+ * Preferences that are set inline will be merged into any existing preferences
692
+ * rather than replacing them.
689
693
  */
690
694
  preferences?: PreferencesAPI.InlinePreferenceSetRequest;
691
695
 
@@ -171,12 +171,13 @@ export namespace SlackListChannelsParams {
171
171
  cursor?: string;
172
172
 
173
173
  /**
174
- * Set to true to exclude archived channels from the list.
174
+ * Set to true to exclude archived channels from the list. Defaults to `true` when
175
+ * not explicitly provided.
175
176
  */
176
177
  exclude_archived?: boolean;
177
178
 
178
179
  /**
179
- * The maximum number of channels to return.
180
+ * The maximum number of channels to return. Defaults to 200.
180
181
  */
181
182
  limit?: number;
182
183
 
@@ -187,7 +188,8 @@ export namespace SlackListChannelsParams {
187
188
 
188
189
  /**
189
190
  * Mix and match channel types by providing a comma-separated list of any
190
- * combination of public_channel, private_channel, mpim, im.
191
+ * combination of public_channel, private_channel, mpim, im. Defaults to
192
+ * `"public_channel,private_channel"`.
191
193
  */
192
194
  types?: string;
193
195
  }
@@ -8,6 +8,8 @@ export class Preferences extends APIResource {}
8
8
 
9
9
  /**
10
10
  * Inline set preferences for a recipient, where the key is the preference set id.
11
+ * Preferences that are set inline will be merged into any existing preferences
12
+ * rather than replacing them.
11
13
  */
12
14
  export type InlinePreferenceSetRequest = Record<string, PreferenceSetRequest>;
13
15
 
@@ -177,6 +177,8 @@ export interface TenantRequest {
177
177
 
178
178
  /**
179
179
  * Inline set preferences for a recipient, where the key is the preference set id.
180
+ * Preferences that are set inline will be merged into any existing preferences
181
+ * rather than replacing them.
180
182
  */
181
183
  preferences?: PreferencesAPI.InlinePreferenceSetRequest | null;
182
184
 
@@ -9,8 +9,7 @@ import { RequestOptions } from '../../internal/request-options';
9
9
 
10
10
  export class Bulk extends APIResource {
11
11
  /**
12
- * Deletes multiple users in a single operation. Accepts up to 100 user IDs to
13
- * delete and returns a bulk operation that can be queried for progress.
12
+ * Permanently deletes up to 1,000 users at a time.
14
13
  *
15
14
  * @example
16
15
  * ```ts
@@ -25,8 +24,8 @@ export class Bulk extends APIResource {
25
24
 
26
25
  /**
27
26
  * Identifies multiple users in a single operation. Allows creating or updating up
28
- * to 100 users in a single batch with various properties, preferences, and channel
29
- * data.
27
+ * to 1,000 users in a single batch with various properties, preferences, and
28
+ * channel data.
30
29
  *
31
30
  * @example
32
31
  * ```ts
@@ -47,9 +46,11 @@ export class Bulk extends APIResource {
47
46
  }
48
47
 
49
48
  /**
50
- * Sets preferences for multiple users in a single operation. Supports either
51
- * setting the same preferences for multiple users or specific preferences for each
52
- * user.
49
+ * Bulk sets the preferences for up to 1,000 users at a time. The preference
50
+ * set `:id` can be either `default` or a `tenant.id`. Learn more
51
+ * about [per-tenant preferences](/preferences/tenant-preferences). Note that this
52
+ * is a destructive operation and will replace any existing users' preferences with
53
+ * the preferences sent.
53
54
  *
54
55
  * @example
55
56
  * ```ts
@@ -389,6 +389,8 @@ export interface IdentifyUserRequest {
389
389
 
390
390
  /**
391
391
  * Inline set preferences for a recipient, where the key is the preference set id.
392
+ * Preferences that are set inline will be merged into any existing preferences
393
+ * rather than replacing them.
392
394
  */
393
395
  preferences?: PreferencesAPI.InlinePreferenceSetRequest | null;
394
396
 
@@ -453,6 +455,8 @@ export interface InlineIdentifyUserRequest {
453
455
 
454
456
  /**
455
457
  * Inline set preferences for a recipient, where the key is the preference set id.
458
+ * Preferences that are set inline will be merged into any existing preferences
459
+ * rather than replacing them.
456
460
  */
457
461
  preferences?: PreferencesAPI.InlinePreferenceSetRequest | null;
458
462
 
@@ -579,6 +583,8 @@ export interface UserUpdateParams {
579
583
 
580
584
  /**
581
585
  * Inline set preferences for a recipient, where the key is the preference set id.
586
+ * Preferences that are set inline will be merged into any existing preferences
587
+ * rather than replacing them.
582
588
  */
583
589
  preferences?: PreferencesAPI.InlinePreferenceSetRequest | null;
584
590
 
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '1.7.0'; // x-release-please-version
1
+ export const VERSION = '1.9.0'; // x-release-please-version
package/version.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "1.7.0";
1
+ export declare const VERSION = "1.9.0";
2
2
  //# sourceMappingURL=version.d.mts.map
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "1.7.0";
1
+ export declare const VERSION = "1.9.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '1.7.0'; // x-release-please-version
4
+ exports.VERSION = '1.9.0'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '1.7.0'; // x-release-please-version
1
+ export const VERSION = '1.9.0'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map