@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.
- package/CHANGELOG.md +18 -0
- package/README.md +17 -40
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +14 -0
- package/dist/api/debug.d.ts +1 -0
- package/dist/api/debug.d.ts.map +1 -1
- package/dist/api/debug.js +42 -1
- package/dist/api/debug.test.d.ts +2 -0
- package/dist/api/debug.test.d.ts.map +1 -0
- package/dist/api/debug.test.js +59 -0
- package/dist/api/schemas.d.ts +451 -251
- package/dist/api/schemas.d.ts.map +1 -1
- package/dist/api/schemas.js +51 -29
- package/dist/index.cjs +1149 -751
- package/dist/index.d.mts +2359 -2161
- package/dist/index.d.ts +3 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/index.mjs +1143 -743
- package/dist/plugins/apps/index.d.ts +4 -0
- package/dist/plugins/apps/index.d.ts.map +1 -1
- package/dist/plugins/findFirstAuthentication/index.d.ts +1 -1
- package/dist/plugins/findFirstAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/findFirstAuthentication/index.js +9 -1
- package/dist/plugins/findFirstAuthentication/index.test.js +3 -4
- package/dist/plugins/findFirstAuthentication/schemas.d.ts +5 -3
- package/dist/plugins/findFirstAuthentication/schemas.d.ts.map +1 -1
- package/dist/plugins/findUniqueAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/findUniqueAuthentication/index.js +4 -0
- package/dist/plugins/findUniqueAuthentication/schemas.d.ts +5 -3
- package/dist/plugins/findUniqueAuthentication/schemas.d.ts.map +1 -1
- package/dist/plugins/getAction/index.d.ts.map +1 -1
- package/dist/plugins/getAction/index.js +10 -0
- package/dist/plugins/getAction/schemas.d.ts +5 -3
- package/dist/plugins/getAction/schemas.d.ts.map +1 -1
- package/dist/plugins/getApp/index.d.ts +2 -7
- package/dist/plugins/getApp/index.d.ts.map +1 -1
- package/dist/plugins/getApp/index.js +17 -9
- package/dist/plugins/getApp/index.test.js +3 -3
- package/dist/plugins/getApp/schemas.d.ts +3 -1
- package/dist/plugins/getApp/schemas.d.ts.map +1 -1
- package/dist/plugins/getApp/schemas.js +2 -4
- package/dist/plugins/getAuthentication/index.d.ts.map +1 -1
- package/dist/plugins/getAuthentication/index.js +8 -0
- package/dist/plugins/getAuthentication/index.test.js +1 -1
- package/dist/plugins/getProfile/index.d.ts.map +1 -1
- package/dist/plugins/getProfile/index.js +4 -0
- package/dist/plugins/getProfile/schemas.d.ts.map +1 -1
- package/dist/plugins/getProfile/schemas.js +4 -3
- package/dist/plugins/listActions/index.d.ts +2 -4
- package/dist/plugins/listActions/index.d.ts.map +1 -1
- package/dist/plugins/listActions/index.js +10 -1
- package/dist/plugins/listActions/index.test.js +4 -4
- package/dist/plugins/listActions/schemas.d.ts +5 -3
- package/dist/plugins/listActions/schemas.d.ts.map +1 -1
- package/dist/plugins/listActions/schemas.js +2 -4
- package/dist/plugins/listApps/index.d.ts +4 -7
- package/dist/plugins/listApps/index.d.ts.map +1 -1
- package/dist/plugins/listApps/index.js +37 -17
- package/dist/plugins/listApps/index.test.js +23 -3
- package/dist/plugins/listApps/schemas.d.ts.map +1 -1
- package/dist/plugins/listApps/schemas.js +3 -9
- package/dist/plugins/listAuthentications/index.d.ts +2 -4
- package/dist/plugins/listAuthentications/index.d.ts.map +1 -1
- package/dist/plugins/listAuthentications/index.js +12 -0
- package/dist/plugins/listAuthentications/index.test.js +39 -13
- package/dist/plugins/listAuthentications/schemas.d.ts +8 -3
- package/dist/plugins/listAuthentications/schemas.d.ts.map +1 -1
- package/dist/plugins/listAuthentications/schemas.js +4 -0
- package/dist/plugins/listInputFieldChoices/index.d.ts.map +1 -1
- package/dist/plugins/listInputFieldChoices/index.js +14 -2
- package/dist/plugins/listInputFieldChoices/schemas.d.ts +5 -3
- package/dist/plugins/listInputFieldChoices/schemas.d.ts.map +1 -1
- package/dist/plugins/listInputFieldChoices/schemas.js +10 -19
- package/dist/plugins/listInputFields/index.d.ts.map +1 -1
- package/dist/plugins/listInputFields/index.js +14 -2
- package/dist/plugins/listInputFields/index.test.js +5 -9
- package/dist/plugins/listInputFields/schemas.d.ts +5 -3
- package/dist/plugins/listInputFields/schemas.d.ts.map +1 -1
- package/dist/plugins/manifest/index.d.ts +25 -9
- package/dist/plugins/manifest/index.d.ts.map +1 -1
- package/dist/plugins/manifest/index.js +239 -67
- package/dist/plugins/manifest/index.test.js +426 -171
- package/dist/plugins/manifest/schemas.d.ts +5 -1
- package/dist/plugins/manifest/schemas.d.ts.map +1 -1
- package/dist/plugins/manifest/schemas.js +1 -0
- package/dist/plugins/registry/index.d.ts.map +1 -1
- package/dist/plugins/registry/index.js +8 -2
- package/dist/plugins/request/index.d.ts.map +1 -1
- package/dist/plugins/request/index.js +1 -0
- package/dist/plugins/runAction/index.d.ts.map +1 -1
- package/dist/plugins/runAction/index.js +12 -0
- package/dist/plugins/runAction/schemas.d.ts +5 -3
- package/dist/plugins/runAction/schemas.d.ts.map +1 -1
- package/dist/resolvers/actionKey.d.ts +13 -7
- package/dist/resolvers/actionKey.d.ts.map +1 -1
- package/dist/resolvers/actionType.d.ts +8 -7
- package/dist/resolvers/actionType.d.ts.map +1 -1
- package/dist/resolvers/appKey.d.ts +2 -6
- package/dist/resolvers/appKey.d.ts.map +1 -1
- package/dist/resolvers/authenticationId.d.ts +7 -7
- package/dist/resolvers/authenticationId.d.ts.map +1 -1
- package/dist/resolvers/authenticationId.js +16 -7
- package/dist/resolvers/index.d.ts +3 -35
- package/dist/resolvers/index.d.ts.map +1 -1
- package/dist/resolvers/index.js +4 -87
- package/dist/resolvers/inputFieldKey.d.ts +11 -0
- package/dist/resolvers/inputFieldKey.d.ts.map +1 -0
- package/dist/resolvers/inputFieldKey.js +23 -0
- package/dist/resolvers/inputs.d.ts +11 -6
- package/dist/resolvers/inputs.d.ts.map +1 -1
- package/dist/resolvers/inputs.js +17 -0
- package/dist/schemas/Action.d.ts +8 -8
- package/dist/schemas/Action.d.ts.map +1 -1
- package/dist/schemas/Action.js +8 -3
- package/dist/schemas/App.d.ts +183 -11
- package/dist/schemas/App.d.ts.map +1 -1
- package/dist/schemas/App.js +7 -9
- package/dist/schemas/Auth.d.ts +12 -12
- package/dist/schemas/Auth.js +1 -1
- package/dist/schemas/Field.d.ts +5 -98
- package/dist/schemas/Field.d.ts.map +1 -1
- package/dist/schemas/Field.js +24 -52
- package/dist/schemas/Run.d.ts +3 -0
- package/dist/schemas/Run.d.ts.map +1 -0
- package/dist/schemas/Run.js +31 -0
- package/dist/schemas/UserProfile.d.ts +11 -11
- package/dist/schemas/UserProfile.d.ts.map +1 -1
- package/dist/schemas/UserProfile.js +21 -7
- package/dist/sdk.d.ts +15 -14
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +1 -4
- package/dist/types/plugin.d.ts +6 -0
- package/dist/types/plugin.d.ts.map +1 -1
- package/dist/types/properties.d.ts +3 -1
- package/dist/types/properties.d.ts.map +1 -1
- package/dist/types/sdk.d.ts +11 -3
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/utils/domain-utils.d.ts +17 -16
- package/dist/utils/domain-utils.d.ts.map +1 -1
- package/dist/utils/domain-utils.js +53 -78
- package/dist/utils/domain-utils.test.js +157 -3
- package/dist/utils/file-utils.d.ts +4 -0
- package/dist/utils/file-utils.d.ts.map +1 -0
- package/dist/utils/file-utils.js +74 -0
- package/dist/utils/file-utils.test.d.ts +2 -0
- package/dist/utils/file-utils.test.d.ts.map +1 -0
- package/dist/utils/file-utils.test.js +51 -0
- package/dist/utils/schema-utils.d.ts +44 -21
- package/dist/utils/schema-utils.d.ts.map +1 -1
- package/dist/utils/schema-utils.js +17 -11
- package/package.json +1 -1
- package/src/api/client.ts +12 -0
- package/src/api/debug.test.ts +76 -0
- package/src/api/debug.ts +46 -2
- package/src/api/schemas.ts +51 -29
- package/src/index.ts +5 -6
- package/src/plugins/apps/index.ts +9 -2
- package/src/plugins/findFirstAuthentication/index.test.ts +8 -5
- package/src/plugins/findFirstAuthentication/index.ts +14 -2
- package/src/plugins/findUniqueAuthentication/index.ts +4 -0
- package/src/plugins/getAction/index.ts +14 -0
- package/src/plugins/getApp/index.test.ts +3 -3
- package/src/plugins/getApp/index.ts +20 -14
- package/src/plugins/getApp/schemas.ts +7 -12
- package/src/plugins/getAuthentication/index.test.ts +1 -1
- package/src/plugins/getAuthentication/index.ts +8 -0
- package/src/plugins/getProfile/index.ts +4 -0
- package/src/plugins/getProfile/schemas.ts +4 -6
- package/src/plugins/listActions/index.test.ts +8 -7
- package/src/plugins/listActions/index.ts +12 -3
- package/src/plugins/listActions/schemas.ts +20 -25
- package/src/plugins/listApps/index.test.ts +24 -3
- package/src/plugins/listApps/index.ts +50 -25
- package/src/plugins/listApps/schemas.ts +17 -26
- package/src/plugins/listAuthentications/index.test.ts +52 -15
- package/src/plugins/listAuthentications/index.ts +15 -2
- package/src/plugins/listAuthentications/schemas.ts +4 -0
- package/src/plugins/listInputFieldChoices/index.ts +21 -1
- package/src/plugins/listInputFieldChoices/schemas.ts +61 -76
- package/src/plugins/listInputFields/index.test.ts +5 -9
- package/src/plugins/listInputFields/index.ts +20 -2
- package/src/plugins/manifest/index.test.ts +503 -197
- package/src/plugins/manifest/index.ts +338 -82
- package/src/plugins/manifest/schemas.ts +9 -2
- package/src/plugins/registry/index.ts +8 -2
- package/src/plugins/request/index.ts +1 -0
- package/src/plugins/runAction/index.ts +18 -0
- package/src/resolvers/actionKey.ts +15 -13
- package/src/resolvers/actionType.ts +10 -12
- package/src/resolvers/appKey.ts +2 -6
- package/src/resolvers/authenticationId.ts +25 -19
- package/src/resolvers/index.ts +7 -113
- package/src/resolvers/inputFieldKey.ts +38 -0
- package/src/resolvers/inputs.ts +28 -10
- package/src/schemas/Action.ts +8 -3
- package/src/schemas/App.ts +7 -9
- package/src/schemas/Auth.ts +1 -1
- package/src/schemas/Field.ts +24 -57
- package/src/schemas/Run.ts +40 -0
- package/src/schemas/UserProfile.ts +24 -7
- package/src/sdk.ts +18 -12
- package/src/types/plugin.ts +8 -0
- package/src/types/sdk.ts +31 -21
- package/src/utils/domain-utils.test.ts +196 -2
- package/src/utils/domain-utils.ts +77 -102
- package/src/utils/file-utils.test.ts +73 -0
- package/src/utils/file-utils.ts +94 -0
- package/src/utils/schema-utils.ts +96 -44
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/plugins/lockVersion/index.d.ts +0 -24
- package/dist/plugins/lockVersion/index.d.ts.map +0 -1
- package/dist/plugins/lockVersion/index.js +0 -72
- package/dist/plugins/lockVersion/index.test.d.ts +0 -2
- package/dist/plugins/lockVersion/index.test.d.ts.map +0 -1
- package/dist/plugins/lockVersion/index.test.js +0 -129
- package/dist/plugins/lockVersion/schemas.d.ts +0 -10
- package/dist/plugins/lockVersion/schemas.d.ts.map +0 -1
- package/dist/plugins/lockVersion/schemas.js +0 -6
- package/src/plugins/lockVersion/index.test.ts +0 -176
- package/src/plugins/lockVersion/index.ts +0 -112
- package/src/plugins/lockVersion/schemas.ts +0 -9
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { groupVersionedAppKeysByType, groupAppKeysByType, } from "./domain-utils";
|
|
2
|
+
import { groupVersionedAppKeysByType, groupAppKeysByType, toAppLocator, } from "./domain-utils";
|
|
3
3
|
describe("domain-utils", () => {
|
|
4
4
|
describe("groupVersionedAppKeysByType", () => {
|
|
5
5
|
it("should reject UUID app keys", () => {
|
|
@@ -105,10 +105,12 @@ describe("domain-utils", () => {
|
|
|
105
105
|
"FormatterCLIAPI@1.0.0",
|
|
106
106
|
"slack@2.1.0", // exact duplicate
|
|
107
107
|
"FormatterCLIAPI@1.0.0", // exact duplicate
|
|
108
|
+
"slack@2.1.1",
|
|
109
|
+
"FormatterCLIAPI@1.0.1",
|
|
108
110
|
]);
|
|
109
111
|
expect(result).toEqual({
|
|
110
|
-
selectedApi: ["FormatterCLIAPI@1.0.0"],
|
|
111
|
-
slug: ["slack@2.1.0"],
|
|
112
|
+
selectedApi: ["FormatterCLIAPI@1.0.0", "FormatterCLIAPI@1.0.1"],
|
|
113
|
+
slug: ["slack@2.1.0", "slack@2.1.1"],
|
|
112
114
|
});
|
|
113
115
|
});
|
|
114
116
|
});
|
|
@@ -189,4 +191,156 @@ describe("domain-utils", () => {
|
|
|
189
191
|
});
|
|
190
192
|
});
|
|
191
193
|
});
|
|
194
|
+
describe("toAppLocator", () => {
|
|
195
|
+
it("should reject UUID app keys", () => {
|
|
196
|
+
expect(() => {
|
|
197
|
+
toAppLocator("61e47557-af91-4b0c-a3e0-c28606357664");
|
|
198
|
+
}).toThrow("UUID app keys are not supported. Use app slug or implementation ID instead of: 61e47557-af91-4b0c-a3e0-c28606357664");
|
|
199
|
+
});
|
|
200
|
+
it("should reject UUID app keys with versions", () => {
|
|
201
|
+
expect(() => {
|
|
202
|
+
toAppLocator("61e47557-af91-4b0c-a3e0-c28606357664@1.0.0");
|
|
203
|
+
}).toThrow("UUID app keys are not supported. Use app slug or implementation ID instead of: 61e47557-af91-4b0c-a3e0-c28606357664@1.0.0");
|
|
204
|
+
});
|
|
205
|
+
it("should reject uppercase UUID app keys", () => {
|
|
206
|
+
expect(() => {
|
|
207
|
+
toAppLocator("61E47557-AF91-4B0C-A3E0-C28606357664");
|
|
208
|
+
}).toThrow("UUID app keys are not supported. Use app slug or implementation ID instead of: 61E47557-AF91-4B0C-A3E0-C28606357664");
|
|
209
|
+
});
|
|
210
|
+
it("should handle simple slug without version", () => {
|
|
211
|
+
const result = toAppLocator("slack");
|
|
212
|
+
expect(result).toEqual({
|
|
213
|
+
lookupAppKey: "slack",
|
|
214
|
+
slug: "slack",
|
|
215
|
+
implementationName: undefined,
|
|
216
|
+
version: undefined,
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
it("should handle slug with version", () => {
|
|
220
|
+
const result = toAppLocator("slack@1.0.0");
|
|
221
|
+
expect(result).toEqual({
|
|
222
|
+
lookupAppKey: "slack",
|
|
223
|
+
slug: "slack",
|
|
224
|
+
implementationName: undefined,
|
|
225
|
+
version: "1.0.0",
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
it("should handle dashified slug", () => {
|
|
229
|
+
const result = toAppLocator("google-sheets");
|
|
230
|
+
expect(result).toEqual({
|
|
231
|
+
lookupAppKey: "google-sheets",
|
|
232
|
+
slug: "google-sheets",
|
|
233
|
+
implementationName: undefined,
|
|
234
|
+
version: undefined,
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
it("should handle dashified slug with version", () => {
|
|
238
|
+
const result = toAppLocator("google-sheets@2.1.3");
|
|
239
|
+
expect(result).toEqual({
|
|
240
|
+
lookupAppKey: "google-sheets",
|
|
241
|
+
slug: "google-sheets",
|
|
242
|
+
implementationName: undefined,
|
|
243
|
+
version: "2.1.3",
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
it("should handle snake_cased slug and convert to dash", () => {
|
|
247
|
+
const result = toAppLocator("google_sheets");
|
|
248
|
+
expect(result).toEqual({
|
|
249
|
+
lookupAppKey: "google_sheets",
|
|
250
|
+
slug: "google-sheets",
|
|
251
|
+
implementationName: undefined,
|
|
252
|
+
version: undefined,
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
it("should handle snake_cased slug with version and convert to dash", () => {
|
|
256
|
+
const result = toAppLocator("google_sheets@2.1.3");
|
|
257
|
+
expect(result).toEqual({
|
|
258
|
+
lookupAppKey: "google_sheets",
|
|
259
|
+
slug: "google-sheets",
|
|
260
|
+
implementationName: undefined,
|
|
261
|
+
version: "2.1.3",
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
it("should handle leading underscore snake_cased slug", () => {
|
|
265
|
+
const result = toAppLocator("_100hires_ats");
|
|
266
|
+
expect(result).toEqual({
|
|
267
|
+
lookupAppKey: "_100hires_ats",
|
|
268
|
+
slug: "100hires-ats",
|
|
269
|
+
implementationName: undefined,
|
|
270
|
+
version: undefined,
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
it("should handle leading underscore snake_cased slug with version", () => {
|
|
274
|
+
const result = toAppLocator("_100hires_ats@3.0.0");
|
|
275
|
+
expect(result).toEqual({
|
|
276
|
+
lookupAppKey: "_100hires_ats",
|
|
277
|
+
slug: "100hires-ats",
|
|
278
|
+
implementationName: undefined,
|
|
279
|
+
version: "3.0.0",
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
it("should handle implementation name without version", () => {
|
|
283
|
+
const result = toAppLocator("SlackCLIAPI");
|
|
284
|
+
expect(result).toEqual({
|
|
285
|
+
lookupAppKey: "SlackCLIAPI",
|
|
286
|
+
slug: undefined,
|
|
287
|
+
implementationName: "SlackCLIAPI",
|
|
288
|
+
version: undefined,
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
it("should handle implementation name with version", () => {
|
|
292
|
+
const result = toAppLocator("SlackCLIAPI@1.29.0");
|
|
293
|
+
expect(result).toEqual({
|
|
294
|
+
lookupAppKey: "SlackCLIAPI",
|
|
295
|
+
slug: undefined,
|
|
296
|
+
implementationName: "SlackCLIAPI",
|
|
297
|
+
version: "1.29.0",
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
it("should handle edge cases with complex version numbers", () => {
|
|
301
|
+
const result = toAppLocator("slack@1.2.3-beta.4+build.5");
|
|
302
|
+
expect(result).toEqual({
|
|
303
|
+
lookupAppKey: "slack",
|
|
304
|
+
slug: "slack",
|
|
305
|
+
implementationName: undefined,
|
|
306
|
+
version: "1.2.3-beta.4+build.5",
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
it("should handle single character app keys", () => {
|
|
310
|
+
const result = toAppLocator("a");
|
|
311
|
+
expect(result).toEqual({
|
|
312
|
+
lookupAppKey: "a",
|
|
313
|
+
slug: "a",
|
|
314
|
+
implementationName: undefined,
|
|
315
|
+
version: undefined,
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
it("should handle app keys with numbers", () => {
|
|
319
|
+
const result = toAppLocator("app123");
|
|
320
|
+
expect(result).toEqual({
|
|
321
|
+
lookupAppKey: "app123",
|
|
322
|
+
slug: "app123",
|
|
323
|
+
implementationName: undefined,
|
|
324
|
+
version: undefined,
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
it("should handle mixed case app keys that aren't implementation names", () => {
|
|
328
|
+
const result = toAppLocator("SlackBot");
|
|
329
|
+
expect(result).toEqual({
|
|
330
|
+
lookupAppKey: "SlackBot",
|
|
331
|
+
slug: undefined,
|
|
332
|
+
implementationName: "SlackBot",
|
|
333
|
+
version: undefined,
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
it("should handle empty version (app key ending with @)", () => {
|
|
337
|
+
const result = toAppLocator("slack@");
|
|
338
|
+
expect(result).toEqual({
|
|
339
|
+
lookupAppKey: "slack",
|
|
340
|
+
slug: "slack",
|
|
341
|
+
implementationName: undefined,
|
|
342
|
+
version: "",
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
});
|
|
192
346
|
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function resolve(path: string, basePath?: string): Promise<string>;
|
|
2
|
+
export declare function writeFile(filePath: string, content: string): Promise<void>;
|
|
3
|
+
export declare function readFile(filePath: string): Promise<string>;
|
|
4
|
+
//# sourceMappingURL=file-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-utils.d.ts","sourceRoot":"","sources":["../../src/utils/file-utils.ts"],"names":[],"mappings":"AA6BA,wBAAsB,OAAO,CAC3B,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,MAAY,GACrB,OAAO,CAAC,MAAM,CAAC,CA8BjB;AAED,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC,CAUf;AAED,wBAAsB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAchE"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// In-memory filesystem fallback for browser environments
|
|
2
|
+
const inMemoryFiles = {};
|
|
3
|
+
// Lazy-loaded modules
|
|
4
|
+
let fsPromises = null;
|
|
5
|
+
let pathModule = null;
|
|
6
|
+
async function loadFsPromises() {
|
|
7
|
+
if (fsPromises)
|
|
8
|
+
return fsPromises;
|
|
9
|
+
try {
|
|
10
|
+
fsPromises = await import("fs/promises");
|
|
11
|
+
return fsPromises;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function loadPathModule() {
|
|
18
|
+
if (pathModule)
|
|
19
|
+
return pathModule;
|
|
20
|
+
try {
|
|
21
|
+
pathModule = await import("path");
|
|
22
|
+
return pathModule;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export async function resolve(path, basePath = "/") {
|
|
29
|
+
const pathModule = await loadPathModule();
|
|
30
|
+
if (pathModule) {
|
|
31
|
+
return pathModule.resolve(path);
|
|
32
|
+
}
|
|
33
|
+
// Simple fallback path resolution assuming root "/" location
|
|
34
|
+
if (path.startsWith("/")) {
|
|
35
|
+
return path;
|
|
36
|
+
}
|
|
37
|
+
if (path.startsWith("./")) {
|
|
38
|
+
// Remove ./ prefix and join to base
|
|
39
|
+
const cleanPath = path.slice(2);
|
|
40
|
+
return basePath.endsWith("/")
|
|
41
|
+
? basePath + cleanPath
|
|
42
|
+
: basePath + "/" + cleanPath;
|
|
43
|
+
}
|
|
44
|
+
if (path.startsWith("../")) {
|
|
45
|
+
// Remove ../ prefix since we're already at root
|
|
46
|
+
const cleanPath = path.replace(/^(\.\.\/)+/, "");
|
|
47
|
+
return basePath.endsWith("/")
|
|
48
|
+
? basePath + cleanPath
|
|
49
|
+
: basePath + "/" + cleanPath;
|
|
50
|
+
}
|
|
51
|
+
// No slash prefix, join to base
|
|
52
|
+
return basePath.endsWith("/") ? basePath + path : basePath + "/" + path;
|
|
53
|
+
}
|
|
54
|
+
export async function writeFile(filePath, content) {
|
|
55
|
+
const fs = await loadFsPromises();
|
|
56
|
+
if (fs) {
|
|
57
|
+
await fs.writeFile(filePath, content, "utf8");
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// Fallback to in-memory filesystem
|
|
61
|
+
inMemoryFiles[filePath] = content;
|
|
62
|
+
}
|
|
63
|
+
export async function readFile(filePath) {
|
|
64
|
+
const fs = await loadFsPromises();
|
|
65
|
+
if (fs) {
|
|
66
|
+
return await fs.readFile(filePath, "utf8");
|
|
67
|
+
}
|
|
68
|
+
// Fallback to in-memory filesystem
|
|
69
|
+
const content = inMemoryFiles[filePath];
|
|
70
|
+
if (content !== undefined) {
|
|
71
|
+
return content;
|
|
72
|
+
}
|
|
73
|
+
throw new Error(`File not found: ${filePath}`);
|
|
74
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-utils.test.d.ts","sourceRoot":"","sources":["../../src/utils/file-utils.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { resolve, writeFile, readFile } from "./file-utils";
|
|
3
|
+
// Mock the dynamic imports to simulate missing modules
|
|
4
|
+
vi.mock("fs/promises", () => {
|
|
5
|
+
throw new Error("Module not found");
|
|
6
|
+
});
|
|
7
|
+
vi.mock("path", () => {
|
|
8
|
+
throw new Error("Module not found");
|
|
9
|
+
});
|
|
10
|
+
describe("file-utils", () => {
|
|
11
|
+
describe("resolve", () => {
|
|
12
|
+
it("should handle absolute paths", async () => {
|
|
13
|
+
expect(await resolve("/absolute/path")).toBe("/absolute/path");
|
|
14
|
+
});
|
|
15
|
+
it("should handle relative paths with ./", async () => {
|
|
16
|
+
expect(await resolve("./relative/path")).toBe("/relative/path");
|
|
17
|
+
expect(await resolve("./relative/path", "/base")).toBe("/base/relative/path");
|
|
18
|
+
expect(await resolve("./relative/path", "/base/")).toBe("/base/relative/path");
|
|
19
|
+
});
|
|
20
|
+
it("should handle parent directory paths with ../", async () => {
|
|
21
|
+
expect(await resolve("../parent/path")).toBe("/parent/path");
|
|
22
|
+
expect(await resolve("../../nested/parent/path")).toBe("/nested/parent/path");
|
|
23
|
+
expect(await resolve("../parent/path", "/base")).toBe("/base/parent/path");
|
|
24
|
+
});
|
|
25
|
+
it("should handle paths without prefix", async () => {
|
|
26
|
+
expect(await resolve("simple/path")).toBe("/simple/path");
|
|
27
|
+
expect(await resolve("simple/path", "/base")).toBe("/base/simple/path");
|
|
28
|
+
expect(await resolve("simple/path", "/base/")).toBe("/base/simple/path");
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
describe("writeFile and readFile with in-memory filesystem", () => {
|
|
32
|
+
it("should write and read files using in-memory filesystem when fs is not available", async () => {
|
|
33
|
+
const filePath = "/test/file.txt";
|
|
34
|
+
const content = "Hello, world!";
|
|
35
|
+
await writeFile(filePath, content);
|
|
36
|
+
const readContent = await readFile(filePath);
|
|
37
|
+
expect(readContent).toBe(content);
|
|
38
|
+
});
|
|
39
|
+
it("should throw error when reading non-existent file", async () => {
|
|
40
|
+
await expect(readFile("/non/existent/file.txt")).rejects.toThrow("File not found: /non/existent/file.txt");
|
|
41
|
+
});
|
|
42
|
+
it("should handle multiple files in in-memory filesystem", async () => {
|
|
43
|
+
await writeFile("/file1.txt", "content1");
|
|
44
|
+
await writeFile("/file2.txt", "content2");
|
|
45
|
+
await writeFile("/dir/file3.txt", "content3");
|
|
46
|
+
expect(await readFile("/file1.txt")).toBe("content1");
|
|
47
|
+
expect(await readFile("/file2.txt")).toBe("content2");
|
|
48
|
+
expect(await readFile("/dir/file3.txt")).toBe("content3");
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -1,45 +1,68 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import type { ZapierSdk } from "../types/sdk";
|
|
3
|
+
import type { InputFieldItem } from "../schemas/Field";
|
|
2
4
|
export interface FormattedItem {
|
|
3
5
|
title: string;
|
|
4
|
-
|
|
6
|
+
id?: string;
|
|
7
|
+
key?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
data?: unknown;
|
|
5
10
|
details: Array<{
|
|
6
11
|
text: string;
|
|
7
12
|
style: "normal" | "dim" | "accent" | "warning" | "success";
|
|
8
13
|
}>;
|
|
9
14
|
}
|
|
10
|
-
export interface FormatMetadata {
|
|
11
|
-
format: (item:
|
|
15
|
+
export interface FormatMetadata<TItem = unknown> {
|
|
16
|
+
format: (item: TItem) => FormattedItem;
|
|
12
17
|
}
|
|
13
|
-
export declare function withFormatter<T extends z.ZodType>(schema: T, formatMeta: FormatMetadata): T;
|
|
14
|
-
export declare function getFormatMetadata(schema: z.ZodType): FormatMetadata | undefined;
|
|
15
|
-
export declare function withOutputSchema<T extends z.ZodType>(inputSchema: T, outputSchema: z.ZodType): T;
|
|
18
|
+
export declare function withFormatter<T extends z.ZodType>(schema: T, formatMeta: FormatMetadata<z.infer<T>>): T;
|
|
16
19
|
export declare function getOutputSchema(inputSchema: z.ZodType): z.ZodType | undefined;
|
|
17
|
-
export
|
|
20
|
+
export declare function withOutputSchema<T extends z.ZodType>(inputSchema: T, outputSchema: z.ZodType): T & {
|
|
21
|
+
_def: T["_def"] & {
|
|
22
|
+
outputSchema: z.ZodType;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export interface PromptConfig {
|
|
26
|
+
type: "list";
|
|
27
|
+
name: string;
|
|
28
|
+
message: string;
|
|
29
|
+
choices: Array<{
|
|
30
|
+
name: string;
|
|
31
|
+
value: unknown;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
export interface Resolver {
|
|
35
|
+
type: string;
|
|
36
|
+
depends?: readonly string[] | string[];
|
|
37
|
+
}
|
|
38
|
+
export interface StaticResolver extends Resolver {
|
|
18
39
|
type: "static";
|
|
19
40
|
inputType?: "text" | "password" | "email";
|
|
20
41
|
placeholder?: string;
|
|
21
42
|
}
|
|
22
|
-
export interface DynamicResolver {
|
|
43
|
+
export interface DynamicResolver<TItem = unknown, TParams = Record<string, unknown>> extends Resolver {
|
|
23
44
|
type: "dynamic";
|
|
24
|
-
fetch: (sdk:
|
|
25
|
-
prompt: (items:
|
|
26
|
-
depends?: string[];
|
|
45
|
+
fetch: (sdk: ZapierSdk, resolvedParams: TParams) => Promise<TItem[]>;
|
|
46
|
+
prompt: (items: TItem[], params: TParams) => PromptConfig;
|
|
27
47
|
}
|
|
28
|
-
export interface FieldsResolver {
|
|
48
|
+
export interface FieldsResolver<TParams = Record<string, unknown>> extends Resolver {
|
|
29
49
|
type: "fields";
|
|
30
|
-
fetch: (sdk:
|
|
31
|
-
depends?: string[];
|
|
50
|
+
fetch: (sdk: ZapierSdk, resolvedParams: TParams) => Promise<InputFieldItem[]>;
|
|
32
51
|
}
|
|
33
|
-
export type ResolverMetadata = StaticResolver | DynamicResolver | FieldsResolver
|
|
34
|
-
export interface ResolverConfig {
|
|
35
|
-
resolver: ResolverMetadata
|
|
52
|
+
export type ResolverMetadata<TItem = unknown, TParams = Record<string, unknown>> = StaticResolver | DynamicResolver<TItem, TParams> | FieldsResolver<TParams>;
|
|
53
|
+
export interface ResolverConfig<TItem = unknown, TParams = Record<string, unknown>> {
|
|
54
|
+
resolver: ResolverMetadata<TItem, TParams>;
|
|
36
55
|
}
|
|
37
|
-
export declare function withResolver<T extends z.ZodType
|
|
56
|
+
export declare function withResolver<T extends z.ZodType, TItem = unknown, TParams = Record<string, unknown>>(schema: T, config: ResolverConfig<TItem, TParams>): T;
|
|
38
57
|
export declare function getSchemaDescription(schema: z.ZodSchema): string | undefined;
|
|
39
|
-
export declare function getFieldDescriptions(schema: z.ZodObject<
|
|
58
|
+
export declare function getFieldDescriptions(schema: z.ZodObject<z.ZodRawShape>): Record<string, string>;
|
|
40
59
|
export interface PositionalMetadata {
|
|
41
|
-
|
|
60
|
+
positionalMeta: {
|
|
61
|
+
positional: true;
|
|
62
|
+
};
|
|
42
63
|
}
|
|
43
|
-
export declare function withPositional<T extends z.ZodType>(schema: T): T
|
|
64
|
+
export declare function withPositional<T extends z.ZodType>(schema: T): T & {
|
|
65
|
+
_def: T["_def"] & PositionalMetadata;
|
|
66
|
+
};
|
|
44
67
|
export declare function isPositional(schema: z.ZodType): boolean;
|
|
45
68
|
//# sourceMappingURL=schema-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-utils.d.ts","sourceRoot":"","sources":["../../src/utils/schema-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"schema-utils.d.ts","sourceRoot":"","sources":["../../src/utils/schema-utils.ts"],"names":[],"mappings":"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"}
|
|
@@ -2,23 +2,23 @@ import { z } from "zod";
|
|
|
2
2
|
// Helper function to add format metadata to schemas
|
|
3
3
|
export function withFormatter(schema, formatMeta) {
|
|
4
4
|
// Store format metadata on the schema definition
|
|
5
|
-
schema._def
|
|
5
|
+
Object.assign(schema._def, {
|
|
6
|
+
formatMeta: formatMeta,
|
|
7
|
+
});
|
|
6
8
|
return schema;
|
|
7
9
|
}
|
|
8
|
-
// Helper function to get
|
|
9
|
-
export function
|
|
10
|
-
return
|
|
10
|
+
// Helper function to get output schema from an input schema
|
|
11
|
+
export function getOutputSchema(inputSchema) {
|
|
12
|
+
return inputSchema._def.outputSchema;
|
|
11
13
|
}
|
|
12
14
|
// Helper function to link input schemas to output schemas
|
|
13
15
|
export function withOutputSchema(inputSchema, outputSchema) {
|
|
14
16
|
// Store output schema reference on the input schema
|
|
15
|
-
inputSchema._def
|
|
17
|
+
Object.assign(inputSchema._def, {
|
|
18
|
+
outputSchema,
|
|
19
|
+
});
|
|
16
20
|
return inputSchema;
|
|
17
21
|
}
|
|
18
|
-
// Helper function to get output schema from an input schema
|
|
19
|
-
export function getOutputSchema(inputSchema) {
|
|
20
|
-
return inputSchema._def.outputSchema;
|
|
21
|
-
}
|
|
22
22
|
// Helper function to add resolver metadata to schemas
|
|
23
23
|
export function withResolver(schema, config) {
|
|
24
24
|
// Store resolver metadata on the schema definition
|
|
@@ -44,13 +44,19 @@ export function getFieldDescriptions(schema) {
|
|
|
44
44
|
// Helper function to mark a parameter as positional for CLI
|
|
45
45
|
export function withPositional(schema) {
|
|
46
46
|
// Store positional metadata on the schema definition
|
|
47
|
-
schema._def
|
|
47
|
+
Object.assign(schema._def, {
|
|
48
|
+
positionalMeta: { positional: true },
|
|
49
|
+
});
|
|
48
50
|
return schema;
|
|
49
51
|
}
|
|
52
|
+
function schemaHasPositionalMeta(schema) {
|
|
53
|
+
return "positionalMeta" in schema._def;
|
|
54
|
+
}
|
|
50
55
|
// Helper function to check if a parameter should be positional
|
|
51
56
|
export function isPositional(schema) {
|
|
52
57
|
// Check the current schema first
|
|
53
|
-
if (schema
|
|
58
|
+
if (schemaHasPositionalMeta(schema) &&
|
|
59
|
+
schema._def.positionalMeta?.positional) {
|
|
54
60
|
return true;
|
|
55
61
|
}
|
|
56
62
|
// If this is a ZodOptional, check the inner type
|
package/package.json
CHANGED
package/src/api/client.ts
CHANGED
|
@@ -188,6 +188,18 @@ class ZapierApiClient implements ApiClient {
|
|
|
188
188
|
if ("errors" in data && Array.isArray(data.errors)) {
|
|
189
189
|
if (this.isApiErrorArray(data.errors)) {
|
|
190
190
|
return data.errors[0].detail || data.errors[0].title;
|
|
191
|
+
} else if (data.errors.length > 0) {
|
|
192
|
+
// Handle simple string errors array
|
|
193
|
+
const firstError = data.errors[0];
|
|
194
|
+
if (typeof firstError === "string") {
|
|
195
|
+
return firstError;
|
|
196
|
+
}
|
|
197
|
+
// For non-string errors, stringify them
|
|
198
|
+
try {
|
|
199
|
+
return JSON.stringify(firstError);
|
|
200
|
+
} catch {
|
|
201
|
+
return String(firstError);
|
|
202
|
+
}
|
|
191
203
|
}
|
|
192
204
|
}
|
|
193
205
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { censorHeaders } from "./debug";
|
|
3
|
+
|
|
4
|
+
describe("censorHeaders", () => {
|
|
5
|
+
it("should return undefined for undefined headers", () => {
|
|
6
|
+
expect(censorHeaders(undefined)).toBeUndefined();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it("should return headers unchanged for non-auth headers", () => {
|
|
10
|
+
const headers = {
|
|
11
|
+
"Content-Type": "application/json",
|
|
12
|
+
"User-Agent": "test",
|
|
13
|
+
};
|
|
14
|
+
const result = censorHeaders(headers);
|
|
15
|
+
// Headers API normalizes header names to lowercase
|
|
16
|
+
expect(result!["content-type"]).toBe("application/json");
|
|
17
|
+
expect(result!["user-agent"]).toBe("test");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should censor authorization header with Bearer prefix - long token", () => {
|
|
21
|
+
const headers = { authorization: "Bearer abcdef1234567890xyz" };
|
|
22
|
+
const result = censorHeaders(headers);
|
|
23
|
+
|
|
24
|
+
expect(result!.authorization).toBe("Bearer abcd...0xyz");
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should censor authorization header with Bearer prefix - short token", () => {
|
|
28
|
+
const headers = { authorization: "Bearer short123" };
|
|
29
|
+
const result = censorHeaders(headers);
|
|
30
|
+
|
|
31
|
+
expect(result!.authorization).toBe("Bearer s...");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should censor x-api-key header - long token", () => {
|
|
35
|
+
const headers = { "x-api-key": "sk-1234567890abcdefghij" };
|
|
36
|
+
const result = censorHeaders(headers);
|
|
37
|
+
|
|
38
|
+
expect(result!["x-api-key"]).toBe("sk-1...ghij");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should censor x-api-key header - short token", () => {
|
|
42
|
+
const headers = { "x-api-key": "short" };
|
|
43
|
+
const result = censorHeaders(headers);
|
|
44
|
+
|
|
45
|
+
expect(result!["x-api-key"]).toBe("s...");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should handle Headers object input", () => {
|
|
49
|
+
const headers = new Headers();
|
|
50
|
+
headers.set("authorization", "Bearer verylongtoken123456789");
|
|
51
|
+
|
|
52
|
+
const result = censorHeaders(headers);
|
|
53
|
+
expect(result!.authorization).toBe("Bearer very...6789");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("should handle mixed case authorization headers", () => {
|
|
57
|
+
const headers = { Authorization: "Bearer mixedcasetoken123" };
|
|
58
|
+
const result = censorHeaders(headers);
|
|
59
|
+
|
|
60
|
+
expect(result!.authorization).toBe("Bearer mixe...n123");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("should preserve non-auth headers while censoring auth headers", () => {
|
|
64
|
+
const headers = {
|
|
65
|
+
"Content-Type": "application/json",
|
|
66
|
+
authorization: "Bearer shouldbecensored123456789",
|
|
67
|
+
"User-Agent": "test-agent",
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const result = censorHeaders(headers);
|
|
71
|
+
|
|
72
|
+
expect(result!["content-type"]).toBe("application/json");
|
|
73
|
+
expect(result!["user-agent"]).toBe("test-agent");
|
|
74
|
+
expect(result!.authorization).toBe("Bearer shou...6789");
|
|
75
|
+
});
|
|
76
|
+
});
|
package/src/api/debug.ts
CHANGED
|
@@ -12,11 +12,55 @@ export function createDebugLogger(enabled: boolean): DebugLogger {
|
|
|
12
12
|
return () => {}; // No-op function when debug is disabled
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
return (message: string, data?:
|
|
15
|
+
return (message: string, data?: unknown) => {
|
|
16
16
|
console.log(`[Zapier SDK] ${message}`, data || "");
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
export function censorHeaders(
|
|
21
|
+
headers?: HeadersInit,
|
|
22
|
+
): Record<string, string> | undefined {
|
|
23
|
+
if (!headers) return headers;
|
|
24
|
+
|
|
25
|
+
const headersObj = new Headers(headers);
|
|
26
|
+
const authKeys = ["authorization", "x-api-key"];
|
|
27
|
+
|
|
28
|
+
for (const [key, value] of headersObj.entries()) {
|
|
29
|
+
if (authKeys.some((authKey) => key.toLowerCase() === authKey)) {
|
|
30
|
+
// Find space after prefix (like "Bearer ")
|
|
31
|
+
const spaceIndex = value.indexOf(" ");
|
|
32
|
+
if (spaceIndex > 0 && spaceIndex < value.length - 1) {
|
|
33
|
+
const prefix = value.substring(0, spaceIndex + 1); // Include the space
|
|
34
|
+
const token = value.substring(spaceIndex + 1);
|
|
35
|
+
|
|
36
|
+
if (token.length > 12) {
|
|
37
|
+
// Show first 4 and last 4 chars, truncate middle
|
|
38
|
+
const start = token.substring(0, 4);
|
|
39
|
+
const end = token.substring(token.length - 4);
|
|
40
|
+
headersObj.set(key, `${prefix}${start}...${end}`);
|
|
41
|
+
} else {
|
|
42
|
+
// Short token, use first character + three dots
|
|
43
|
+
const firstChar = token.charAt(0);
|
|
44
|
+
headersObj.set(key, `${prefix}${firstChar}...`);
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
// No prefix found, truncate the whole value
|
|
48
|
+
if (value.length > 12) {
|
|
49
|
+
const start = value.substring(0, 4);
|
|
50
|
+
const end = value.substring(value.length - 4);
|
|
51
|
+
headersObj.set(key, `${start}...${end}`);
|
|
52
|
+
} else {
|
|
53
|
+
// Short token, use first character + three dots
|
|
54
|
+
const firstChar = value.charAt(0);
|
|
55
|
+
headersObj.set(key, `${firstChar}...`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return Object.fromEntries(headersObj);
|
|
62
|
+
}
|
|
63
|
+
|
|
20
64
|
export function createDebugFetch(options: {
|
|
21
65
|
originalFetch: typeof globalThis.fetch;
|
|
22
66
|
debugLog: DebugLogger;
|
|
@@ -30,7 +74,7 @@ export function createDebugFetch(options: {
|
|
|
30
74
|
const method = options?.method || "GET";
|
|
31
75
|
|
|
32
76
|
debugLog(`→ ${method} ${url}`, {
|
|
33
|
-
headers: options?.headers,
|
|
77
|
+
headers: censorHeaders(options?.headers),
|
|
34
78
|
body:
|
|
35
79
|
options?.body && typeof options.body === "string"
|
|
36
80
|
? (() => {
|