@zapier/zapier-sdk 0.8.3 → 0.10.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 (222) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +17 -40
  3. package/dist/api/client.d.ts.map +1 -1
  4. package/dist/api/client.js +14 -0
  5. package/dist/api/debug.d.ts +1 -0
  6. package/dist/api/debug.d.ts.map +1 -1
  7. package/dist/api/debug.js +42 -1
  8. package/dist/api/debug.test.d.ts +2 -0
  9. package/dist/api/debug.test.d.ts.map +1 -0
  10. package/dist/api/debug.test.js +59 -0
  11. package/dist/api/schemas.d.ts +451 -251
  12. package/dist/api/schemas.d.ts.map +1 -1
  13. package/dist/api/schemas.js +51 -29
  14. package/dist/index.cjs +1149 -751
  15. package/dist/index.d.mts +2359 -2161
  16. package/dist/index.d.ts +3 -5
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +2 -4
  19. package/dist/index.mjs +1143 -743
  20. package/dist/plugins/apps/index.d.ts +4 -0
  21. package/dist/plugins/apps/index.d.ts.map +1 -1
  22. package/dist/plugins/findFirstAuthentication/index.d.ts +1 -1
  23. package/dist/plugins/findFirstAuthentication/index.d.ts.map +1 -1
  24. package/dist/plugins/findFirstAuthentication/index.js +9 -1
  25. package/dist/plugins/findFirstAuthentication/index.test.js +3 -4
  26. package/dist/plugins/findFirstAuthentication/schemas.d.ts +5 -3
  27. package/dist/plugins/findFirstAuthentication/schemas.d.ts.map +1 -1
  28. package/dist/plugins/findUniqueAuthentication/index.d.ts.map +1 -1
  29. package/dist/plugins/findUniqueAuthentication/index.js +4 -0
  30. package/dist/plugins/findUniqueAuthentication/schemas.d.ts +5 -3
  31. package/dist/plugins/findUniqueAuthentication/schemas.d.ts.map +1 -1
  32. package/dist/plugins/getAction/index.d.ts.map +1 -1
  33. package/dist/plugins/getAction/index.js +10 -0
  34. package/dist/plugins/getAction/schemas.d.ts +5 -3
  35. package/dist/plugins/getAction/schemas.d.ts.map +1 -1
  36. package/dist/plugins/getApp/index.d.ts +2 -7
  37. package/dist/plugins/getApp/index.d.ts.map +1 -1
  38. package/dist/plugins/getApp/index.js +17 -9
  39. package/dist/plugins/getApp/index.test.js +3 -3
  40. package/dist/plugins/getApp/schemas.d.ts +3 -1
  41. package/dist/plugins/getApp/schemas.d.ts.map +1 -1
  42. package/dist/plugins/getApp/schemas.js +2 -4
  43. package/dist/plugins/getAuthentication/index.d.ts.map +1 -1
  44. package/dist/plugins/getAuthentication/index.js +8 -0
  45. package/dist/plugins/getAuthentication/index.test.js +1 -1
  46. package/dist/plugins/getProfile/index.d.ts.map +1 -1
  47. package/dist/plugins/getProfile/index.js +4 -0
  48. package/dist/plugins/getProfile/schemas.d.ts.map +1 -1
  49. package/dist/plugins/getProfile/schemas.js +4 -3
  50. package/dist/plugins/listActions/index.d.ts +2 -4
  51. package/dist/plugins/listActions/index.d.ts.map +1 -1
  52. package/dist/plugins/listActions/index.js +10 -1
  53. package/dist/plugins/listActions/index.test.js +4 -4
  54. package/dist/plugins/listActions/schemas.d.ts +5 -3
  55. package/dist/plugins/listActions/schemas.d.ts.map +1 -1
  56. package/dist/plugins/listActions/schemas.js +2 -4
  57. package/dist/plugins/listApps/index.d.ts +4 -7
  58. package/dist/plugins/listApps/index.d.ts.map +1 -1
  59. package/dist/plugins/listApps/index.js +37 -17
  60. package/dist/plugins/listApps/index.test.js +23 -3
  61. package/dist/plugins/listApps/schemas.d.ts.map +1 -1
  62. package/dist/plugins/listApps/schemas.js +3 -9
  63. package/dist/plugins/listAuthentications/index.d.ts +2 -4
  64. package/dist/plugins/listAuthentications/index.d.ts.map +1 -1
  65. package/dist/plugins/listAuthentications/index.js +12 -0
  66. package/dist/plugins/listAuthentications/index.test.js +39 -13
  67. package/dist/plugins/listAuthentications/schemas.d.ts +8 -3
  68. package/dist/plugins/listAuthentications/schemas.d.ts.map +1 -1
  69. package/dist/plugins/listAuthentications/schemas.js +4 -0
  70. package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -1
  71. package/dist/plugins/listInputFieldChoices/index.js +14 -2
  72. package/dist/plugins/listInputFieldChoices/schemas.d.ts +5 -3
  73. package/dist/plugins/listInputFieldChoices/schemas.d.ts.map +1 -1
  74. package/dist/plugins/listInputFieldChoices/schemas.js +10 -19
  75. package/dist/plugins/listInputFields/index.d.ts.map +1 -1
  76. package/dist/plugins/listInputFields/index.js +14 -2
  77. package/dist/plugins/listInputFields/index.test.js +5 -9
  78. package/dist/plugins/listInputFields/schemas.d.ts +5 -3
  79. package/dist/plugins/listInputFields/schemas.d.ts.map +1 -1
  80. package/dist/plugins/manifest/index.d.ts +25 -9
  81. package/dist/plugins/manifest/index.d.ts.map +1 -1
  82. package/dist/plugins/manifest/index.js +239 -67
  83. package/dist/plugins/manifest/index.test.js +426 -171
  84. package/dist/plugins/manifest/schemas.d.ts +5 -1
  85. package/dist/plugins/manifest/schemas.d.ts.map +1 -1
  86. package/dist/plugins/manifest/schemas.js +1 -0
  87. package/dist/plugins/registry/index.d.ts.map +1 -1
  88. package/dist/plugins/registry/index.js +8 -2
  89. package/dist/plugins/request/index.d.ts.map +1 -1
  90. package/dist/plugins/request/index.js +1 -0
  91. package/dist/plugins/runAction/index.d.ts.map +1 -1
  92. package/dist/plugins/runAction/index.js +12 -0
  93. package/dist/plugins/runAction/schemas.d.ts +5 -3
  94. package/dist/plugins/runAction/schemas.d.ts.map +1 -1
  95. package/dist/resolvers/actionKey.d.ts +13 -7
  96. package/dist/resolvers/actionKey.d.ts.map +1 -1
  97. package/dist/resolvers/actionType.d.ts +8 -7
  98. package/dist/resolvers/actionType.d.ts.map +1 -1
  99. package/dist/resolvers/appKey.d.ts +2 -6
  100. package/dist/resolvers/appKey.d.ts.map +1 -1
  101. package/dist/resolvers/authenticationId.d.ts +7 -7
  102. package/dist/resolvers/authenticationId.d.ts.map +1 -1
  103. package/dist/resolvers/authenticationId.js +16 -7
  104. package/dist/resolvers/index.d.ts +3 -35
  105. package/dist/resolvers/index.d.ts.map +1 -1
  106. package/dist/resolvers/index.js +4 -87
  107. package/dist/resolvers/inputFieldKey.d.ts +11 -0
  108. package/dist/resolvers/inputFieldKey.d.ts.map +1 -0
  109. package/dist/resolvers/inputFieldKey.js +23 -0
  110. package/dist/resolvers/inputs.d.ts +11 -6
  111. package/dist/resolvers/inputs.d.ts.map +1 -1
  112. package/dist/resolvers/inputs.js +17 -0
  113. package/dist/schemas/Action.d.ts +8 -8
  114. package/dist/schemas/Action.d.ts.map +1 -1
  115. package/dist/schemas/Action.js +8 -3
  116. package/dist/schemas/App.d.ts +183 -11
  117. package/dist/schemas/App.d.ts.map +1 -1
  118. package/dist/schemas/App.js +7 -9
  119. package/dist/schemas/Auth.d.ts +12 -12
  120. package/dist/schemas/Auth.js +1 -1
  121. package/dist/schemas/Field.d.ts +5 -98
  122. package/dist/schemas/Field.d.ts.map +1 -1
  123. package/dist/schemas/Field.js +24 -52
  124. package/dist/schemas/Run.d.ts +3 -0
  125. package/dist/schemas/Run.d.ts.map +1 -0
  126. package/dist/schemas/Run.js +31 -0
  127. package/dist/schemas/UserProfile.d.ts +11 -11
  128. package/dist/schemas/UserProfile.d.ts.map +1 -1
  129. package/dist/schemas/UserProfile.js +21 -7
  130. package/dist/sdk.d.ts +15 -14
  131. package/dist/sdk.d.ts.map +1 -1
  132. package/dist/sdk.js +1 -4
  133. package/dist/types/plugin.d.ts +6 -0
  134. package/dist/types/plugin.d.ts.map +1 -1
  135. package/dist/types/properties.d.ts +3 -1
  136. package/dist/types/properties.d.ts.map +1 -1
  137. package/dist/types/sdk.d.ts +11 -3
  138. package/dist/types/sdk.d.ts.map +1 -1
  139. package/dist/utils/domain-utils.d.ts +17 -16
  140. package/dist/utils/domain-utils.d.ts.map +1 -1
  141. package/dist/utils/domain-utils.js +53 -78
  142. package/dist/utils/domain-utils.test.js +157 -3
  143. package/dist/utils/file-utils.d.ts +4 -0
  144. package/dist/utils/file-utils.d.ts.map +1 -0
  145. package/dist/utils/file-utils.js +74 -0
  146. package/dist/utils/file-utils.test.d.ts +2 -0
  147. package/dist/utils/file-utils.test.d.ts.map +1 -0
  148. package/dist/utils/file-utils.test.js +51 -0
  149. package/dist/utils/schema-utils.d.ts +44 -21
  150. package/dist/utils/schema-utils.d.ts.map +1 -1
  151. package/dist/utils/schema-utils.js +17 -11
  152. package/package.json +1 -1
  153. package/src/api/client.ts +12 -0
  154. package/src/api/debug.test.ts +76 -0
  155. package/src/api/debug.ts +46 -2
  156. package/src/api/schemas.ts +51 -29
  157. package/src/index.ts +5 -6
  158. package/src/plugins/apps/index.ts +9 -2
  159. package/src/plugins/findFirstAuthentication/index.test.ts +8 -5
  160. package/src/plugins/findFirstAuthentication/index.ts +14 -2
  161. package/src/plugins/findUniqueAuthentication/index.ts +4 -0
  162. package/src/plugins/getAction/index.ts +14 -0
  163. package/src/plugins/getApp/index.test.ts +3 -3
  164. package/src/plugins/getApp/index.ts +20 -14
  165. package/src/plugins/getApp/schemas.ts +7 -12
  166. package/src/plugins/getAuthentication/index.test.ts +1 -1
  167. package/src/plugins/getAuthentication/index.ts +8 -0
  168. package/src/plugins/getProfile/index.ts +4 -0
  169. package/src/plugins/getProfile/schemas.ts +4 -6
  170. package/src/plugins/listActions/index.test.ts +8 -7
  171. package/src/plugins/listActions/index.ts +12 -3
  172. package/src/plugins/listActions/schemas.ts +20 -25
  173. package/src/plugins/listApps/index.test.ts +24 -3
  174. package/src/plugins/listApps/index.ts +50 -25
  175. package/src/plugins/listApps/schemas.ts +17 -26
  176. package/src/plugins/listAuthentications/index.test.ts +52 -15
  177. package/src/plugins/listAuthentications/index.ts +15 -2
  178. package/src/plugins/listAuthentications/schemas.ts +4 -0
  179. package/src/plugins/listInputFieldChoices/index.ts +21 -1
  180. package/src/plugins/listInputFieldChoices/schemas.ts +61 -76
  181. package/src/plugins/listInputFields/index.test.ts +5 -9
  182. package/src/plugins/listInputFields/index.ts +20 -2
  183. package/src/plugins/manifest/index.test.ts +503 -197
  184. package/src/plugins/manifest/index.ts +338 -82
  185. package/src/plugins/manifest/schemas.ts +9 -2
  186. package/src/plugins/registry/index.ts +8 -2
  187. package/src/plugins/request/index.ts +1 -0
  188. package/src/plugins/runAction/index.ts +18 -0
  189. package/src/resolvers/actionKey.ts +15 -13
  190. package/src/resolvers/actionType.ts +10 -12
  191. package/src/resolvers/appKey.ts +2 -6
  192. package/src/resolvers/authenticationId.ts +25 -19
  193. package/src/resolvers/index.ts +7 -113
  194. package/src/resolvers/inputFieldKey.ts +38 -0
  195. package/src/resolvers/inputs.ts +28 -10
  196. package/src/schemas/Action.ts +8 -3
  197. package/src/schemas/App.ts +7 -9
  198. package/src/schemas/Auth.ts +1 -1
  199. package/src/schemas/Field.ts +24 -57
  200. package/src/schemas/Run.ts +40 -0
  201. package/src/schemas/UserProfile.ts +24 -7
  202. package/src/sdk.ts +18 -12
  203. package/src/types/plugin.ts +8 -0
  204. package/src/types/sdk.ts +31 -21
  205. package/src/utils/domain-utils.test.ts +196 -2
  206. package/src/utils/domain-utils.ts +77 -102
  207. package/src/utils/file-utils.test.ts +73 -0
  208. package/src/utils/file-utils.ts +94 -0
  209. package/src/utils/schema-utils.ts +96 -44
  210. package/tsconfig.tsbuildinfo +1 -1
  211. package/dist/plugins/lockVersion/index.d.ts +0 -24
  212. package/dist/plugins/lockVersion/index.d.ts.map +0 -1
  213. package/dist/plugins/lockVersion/index.js +0 -72
  214. package/dist/plugins/lockVersion/index.test.d.ts +0 -2
  215. package/dist/plugins/lockVersion/index.test.d.ts.map +0 -1
  216. package/dist/plugins/lockVersion/index.test.js +0 -129
  217. package/dist/plugins/lockVersion/schemas.d.ts +0 -10
  218. package/dist/plugins/lockVersion/schemas.d.ts.map +0 -1
  219. package/dist/plugins/lockVersion/schemas.js +0 -6
  220. package/src/plugins/lockVersion/index.test.ts +0 -176
  221. package/src/plugins/lockVersion/index.ts +0 -112
  222. package/src/plugins/lockVersion/schemas.ts +0 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @zapier/zapier-sdk
2
2
 
3
+ ## 0.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 3184903: No more global resolver registry, each plugin function has its own resolvers. Plugin function meta also stores output schema and some function type info to avoid some special case code for handling lists, documenting functions, etc. findFirstAuthentication throws an error to make all item functions consistent. Various other schema and output cleanup.
8
+
9
+ ## 0.9.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 3cfed98: Reducing any usages
14
+
15
+ ## 0.9.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 5ccaec6: AST-based type gen instead of string-based. Added `add` function for locking app versions and generating types. Removed `lockVersion` and `generateTypes functions. Manifest matching on slug or implementation name.
20
+
3
21
  ## 0.8.3
4
22
 
5
23
  ### Patch Changes
package/README.md CHANGED
@@ -25,8 +25,6 @@
25
25
  - [`listAuthentications`](#listauthentications)
26
26
  - [HTTP Requests](#http-requests)
27
27
  - [`request`](#request)
28
- - [Utilities](#utilities)
29
- - [`lockVersion`](#lockversion)
30
28
 
31
29
  ## Installation
32
30
 
@@ -68,7 +66,7 @@ Get current user's profile information
68
66
 
69
67
  **Parameters:** None
70
68
 
71
- **Returns:** `Promise<UserProfile>`
69
+ **Returns:** `Promise<ProfileItem>`
72
70
 
73
71
  **Example:**
74
72
 
@@ -172,7 +170,7 @@ Get the input fields required for a specific action
172
170
  | `pageSize` | `number` | ❌ | — | — | Number of input fields per page |
173
171
  | `maxItems` | `number` | ❌ | — | — | Maximum total items to return across all pages |
174
172
 
175
- **Returns:** `Promise<PaginatedResult<ActionField>>`
173
+ **Returns:** `Promise<PaginatedResult<InputFieldItem>>`
176
174
 
177
175
  **Example:**
178
176
 
@@ -200,7 +198,7 @@ Execute an action with the given inputs
200
198
  | `pageSize` | `number` | ❌ | — | — | Number of results per page |
201
199
  | `maxItems` | `number` | ❌ | — | — | Maximum total items to return across all pages |
202
200
 
203
- **Returns:** `Promise<ActionExecutionResult>`
201
+ **Returns:** `Promise<PaginatedResult<ActionResultItem>>`
204
202
 
205
203
  **Example:**
206
204
 
@@ -271,7 +269,7 @@ Find the first authentication matching the criteria
271
269
  | `accountId` | `string` | ❌ | — | — | Filter by account ID |
272
270
  | `owner` | `string` | ❌ | — | — | Filter by owner |
273
271
 
274
- **Returns:** `Promise<Authentication | null>`
272
+ **Returns:** `Promise<AuthenticationItem>`
275
273
 
276
274
  **Example:**
277
275
 
@@ -293,7 +291,7 @@ Find a unique authentication matching the criteria
293
291
  | `accountId` | `string` | ❌ | — | — | Filter by account ID |
294
292
  | `owner` | `string` | ❌ | — | — | Filter by owner |
295
293
 
296
- **Returns:** `Promise<Authentication | null>`
294
+ **Returns:** `Promise<AuthenticationItem>`
297
295
 
298
296
  **Example:**
299
297
 
@@ -311,7 +309,7 @@ Get a specific authentication by ID
311
309
  | ------------------ | -------- | -------- | ------- | --------------- | ----------------------------- |
312
310
  | `authenticationId` | `number` | ✅ | — | — | Authentication ID to retrieve |
313
311
 
314
- **Returns:** `Promise<Authentication>`
312
+ **Returns:** `Promise<AuthenticationItem>`
315
313
 
316
314
  **Example:**
317
315
 
@@ -327,17 +325,18 @@ List available authentications with optional filtering
327
325
 
328
326
  **Parameters:**
329
327
 
330
- | Name | Type | Required | Default | Possible Values | Description |
331
- | ----------- | -------- | -------- | ------- | --------------- | -------------------------------------------------------- |
332
- | `appKey` | `string` | ❌ | — | — | App key of authentications to list (e.g., 'SlackCLIAPI') |
333
- | `search` | `string` | ❌ | — | — | Search term to filter authentications by title |
334
- | `title` | `string` | ❌ | — | — | Filter authentications by exact title match |
335
- | `accountId` | `string` | ❌ | — | — | Filter by account ID |
336
- | `owner` | `string` | ❌ | — | — | Filter by owner |
337
- | `pageSize` | `number` | ❌ | — | — | Number of authentications per page |
338
- | `maxItems` | `number` | ❌ | — | — | Maximum total items to return across all pages |
328
+ | Name | Type | Required | Default | Possible Values | Description |
329
+ | ------------------- | -------- | -------- | ------- | --------------- | -------------------------------------------------------- |
330
+ | `appKey` | `string` | ❌ | — | — | App key of authentications to list (e.g., 'SlackCLIAPI') |
331
+ | `authenticationIds` | `array` | ❌ | — | — | List of authentication IDs to filter by |
332
+ | `search` | `string` | ❌ | — | — | Search term to filter authentications by title |
333
+ | `title` | `string` | ❌ | — | — | Filter authentications by exact title match |
334
+ | `accountId` | `string` | ❌ | — | — | Filter by account ID |
335
+ | `owner` | `string` | ❌ | — | — | Filter by owner |
336
+ | `pageSize` | `number` | ❌ | — | — | Number of authentications per page |
337
+ | `maxItems` | `number` | ❌ | — | — | Maximum total items to return across all pages |
339
338
 
340
- **Returns:** `Promise<PaginatedResult<Authentication>>`
339
+ **Returns:** `Promise<PaginatedResult<AuthenticationItem>>`
341
340
 
342
341
  **Example:**
343
342
 
@@ -374,26 +373,4 @@ const result = await sdk.request({
374
373
  });
375
374
  ```
376
375
 
377
- ### Utilities
378
-
379
- #### `lockVersion`
380
-
381
- Execute lockVersion
382
-
383
- **Parameters:**
384
-
385
- | Name | Type | Required | Default | Possible Values | Description |
386
- | -------- | -------- | -------- | ------- | --------------- | -------------------------------------------------------- |
387
- | `appKey` | `string` | ✅ | — | — | The app key to lock version for (e.g., 'slack', 'gmail') |
388
-
389
- **Returns:** `Promise<any>`
390
-
391
- **Example:**
392
-
393
- ```typescript
394
- const result = await sdk.lockVersion({
395
- appKey: "example-key",
396
- });
397
- ```
398
-
399
376
  <!-- End Generated API Reference -->
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAGjB,MAAM,SAAS,CAAC;AA6bjB,eAAO,MAAM,eAAe,GAAI,SAAS,gBAAgB,KAAG,SAqB3D,CAAC"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAGjB,MAAM,SAAS,CAAC;AAycjB,eAAO,MAAM,eAAe,GAAI,SAAS,gBAAgB,KAAG,SAqB3D,CAAC"}
@@ -167,6 +167,20 @@ class ZapierApiClient {
167
167
  if (this.isApiErrorArray(data.errors)) {
168
168
  return data.errors[0].detail || data.errors[0].title;
169
169
  }
170
+ else if (data.errors.length > 0) {
171
+ // Handle simple string errors array
172
+ const firstError = data.errors[0];
173
+ if (typeof firstError === "string") {
174
+ return firstError;
175
+ }
176
+ // For non-string errors, stringify them
177
+ try {
178
+ return JSON.stringify(firstError);
179
+ }
180
+ catch {
181
+ return String(firstError);
182
+ }
183
+ }
170
184
  }
171
185
  }
172
186
  return undefined;
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import type { DebugLogger } from "./types";
8
8
  export declare function createDebugLogger(enabled: boolean): DebugLogger;
9
+ export declare function censorHeaders(headers?: HeadersInit): Record<string, string> | undefined;
9
10
  export declare function createDebugFetch(options: {
10
11
  originalFetch: typeof globalThis.fetch;
11
12
  debugLog: DebugLogger;
@@ -1 +1 @@
1
- {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/api/debug.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW,CAQ/D;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,aAAa,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IACvC,QAAQ,EAAE,WAAW,CAAC;CACvB,IAEe,OAAO,WAAW,GAAG,GAAG,EAAE,UAAU,WAAW,uBA0C9D"}
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/api/debug.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW,CAQ/D;AAED,wBAAgB,aAAa,CAC3B,OAAO,CAAC,EAAE,WAAW,GACpB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAwCpC;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,aAAa,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IACvC,QAAQ,EAAE,WAAW,CAAC;CACvB,IAEe,OAAO,WAAW,GAAG,GAAG,EAAE,UAAU,WAAW,uBA0C9D"}
package/dist/api/debug.js CHANGED
@@ -12,6 +12,47 @@ export function createDebugLogger(enabled) {
12
12
  console.log(`[Zapier SDK] ${message}`, data || "");
13
13
  };
14
14
  }
15
+ export function censorHeaders(headers) {
16
+ if (!headers)
17
+ return headers;
18
+ const headersObj = new Headers(headers);
19
+ const authKeys = ["authorization", "x-api-key"];
20
+ for (const [key, value] of headersObj.entries()) {
21
+ if (authKeys.some((authKey) => key.toLowerCase() === authKey)) {
22
+ // Find space after prefix (like "Bearer ")
23
+ const spaceIndex = value.indexOf(" ");
24
+ if (spaceIndex > 0 && spaceIndex < value.length - 1) {
25
+ const prefix = value.substring(0, spaceIndex + 1); // Include the space
26
+ const token = value.substring(spaceIndex + 1);
27
+ if (token.length > 12) {
28
+ // Show first 4 and last 4 chars, truncate middle
29
+ const start = token.substring(0, 4);
30
+ const end = token.substring(token.length - 4);
31
+ headersObj.set(key, `${prefix}${start}...${end}`);
32
+ }
33
+ else {
34
+ // Short token, use first character + three dots
35
+ const firstChar = token.charAt(0);
36
+ headersObj.set(key, `${prefix}${firstChar}...`);
37
+ }
38
+ }
39
+ else {
40
+ // No prefix found, truncate the whole value
41
+ if (value.length > 12) {
42
+ const start = value.substring(0, 4);
43
+ const end = value.substring(value.length - 4);
44
+ headersObj.set(key, `${start}...${end}`);
45
+ }
46
+ else {
47
+ // Short token, use first character + three dots
48
+ const firstChar = value.charAt(0);
49
+ headersObj.set(key, `${firstChar}...`);
50
+ }
51
+ }
52
+ }
53
+ }
54
+ return Object.fromEntries(headersObj);
55
+ }
15
56
  export function createDebugFetch(options) {
16
57
  const { originalFetch, debugLog } = options;
17
58
  return async (input, options) => {
@@ -20,7 +61,7 @@ export function createDebugFetch(options) {
20
61
  const url = typeof input === "string" ? input : input.toString();
21
62
  const method = options?.method || "GET";
22
63
  debugLog(`→ ${method} ${url}`, {
23
- headers: options?.headers,
64
+ headers: censorHeaders(options?.headers),
24
65
  body: options?.body && typeof options.body === "string"
25
66
  ? (() => {
26
67
  try {
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=debug.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.test.d.ts","sourceRoot":"","sources":["../../src/api/debug.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,59 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { censorHeaders } from "./debug";
3
+ describe("censorHeaders", () => {
4
+ it("should return undefined for undefined headers", () => {
5
+ expect(censorHeaders(undefined)).toBeUndefined();
6
+ });
7
+ it("should return headers unchanged for non-auth headers", () => {
8
+ const headers = {
9
+ "Content-Type": "application/json",
10
+ "User-Agent": "test",
11
+ };
12
+ const result = censorHeaders(headers);
13
+ // Headers API normalizes header names to lowercase
14
+ expect(result["content-type"]).toBe("application/json");
15
+ expect(result["user-agent"]).toBe("test");
16
+ });
17
+ it("should censor authorization header with Bearer prefix - long token", () => {
18
+ const headers = { authorization: "Bearer abcdef1234567890xyz" };
19
+ const result = censorHeaders(headers);
20
+ expect(result.authorization).toBe("Bearer abcd...0xyz");
21
+ });
22
+ it("should censor authorization header with Bearer prefix - short token", () => {
23
+ const headers = { authorization: "Bearer short123" };
24
+ const result = censorHeaders(headers);
25
+ expect(result.authorization).toBe("Bearer s...");
26
+ });
27
+ it("should censor x-api-key header - long token", () => {
28
+ const headers = { "x-api-key": "sk-1234567890abcdefghij" };
29
+ const result = censorHeaders(headers);
30
+ expect(result["x-api-key"]).toBe("sk-1...ghij");
31
+ });
32
+ it("should censor x-api-key header - short token", () => {
33
+ const headers = { "x-api-key": "short" };
34
+ const result = censorHeaders(headers);
35
+ expect(result["x-api-key"]).toBe("s...");
36
+ });
37
+ it("should handle Headers object input", () => {
38
+ const headers = new Headers();
39
+ headers.set("authorization", "Bearer verylongtoken123456789");
40
+ const result = censorHeaders(headers);
41
+ expect(result.authorization).toBe("Bearer very...6789");
42
+ });
43
+ it("should handle mixed case authorization headers", () => {
44
+ const headers = { Authorization: "Bearer mixedcasetoken123" };
45
+ const result = censorHeaders(headers);
46
+ expect(result.authorization).toBe("Bearer mixe...n123");
47
+ });
48
+ it("should preserve non-auth headers while censoring auth headers", () => {
49
+ const headers = {
50
+ "Content-Type": "application/json",
51
+ authorization: "Bearer shouldbecensored123456789",
52
+ "User-Agent": "test-agent",
53
+ };
54
+ const result = censorHeaders(headers);
55
+ expect(result["content-type"]).toBe("application/json");
56
+ expect(result["user-agent"]).toBe("test-agent");
57
+ expect(result.authorization).toBe("Bearer shou...6789");
58
+ });
59
+ });