@zapier/zapier-sdk 0.13.6 → 0.13.7

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 (114) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.mjs +1 -1
  4. package/package.json +7 -2
  5. package/src/api/auth.ts +0 -28
  6. package/src/api/client.ts +0 -491
  7. package/src/api/debug.test.ts +0 -76
  8. package/src/api/debug.ts +0 -154
  9. package/src/api/index.ts +0 -90
  10. package/src/api/polling.test.ts +0 -405
  11. package/src/api/polling.ts +0 -253
  12. package/src/api/schemas.ts +0 -465
  13. package/src/api/types.ts +0 -152
  14. package/src/auth.ts +0 -72
  15. package/src/constants.ts +0 -16
  16. package/src/index.ts +0 -111
  17. package/src/plugins/api/index.ts +0 -43
  18. package/src/plugins/apps/index.ts +0 -203
  19. package/src/plugins/apps/schemas.ts +0 -64
  20. package/src/plugins/eventEmission/builders.ts +0 -115
  21. package/src/plugins/eventEmission/index.test.ts +0 -169
  22. package/src/plugins/eventEmission/index.ts +0 -294
  23. package/src/plugins/eventEmission/transport.test.ts +0 -214
  24. package/src/plugins/eventEmission/transport.ts +0 -135
  25. package/src/plugins/eventEmission/types.ts +0 -58
  26. package/src/plugins/eventEmission/utils.ts +0 -121
  27. package/src/plugins/fetch/index.ts +0 -83
  28. package/src/plugins/fetch/schemas.ts +0 -37
  29. package/src/plugins/findFirstAuthentication/index.test.ts +0 -209
  30. package/src/plugins/findFirstAuthentication/index.ts +0 -68
  31. package/src/plugins/findFirstAuthentication/schemas.ts +0 -47
  32. package/src/plugins/findUniqueAuthentication/index.test.ts +0 -197
  33. package/src/plugins/findUniqueAuthentication/index.ts +0 -77
  34. package/src/plugins/findUniqueAuthentication/schemas.ts +0 -49
  35. package/src/plugins/getAction/index.test.ts +0 -239
  36. package/src/plugins/getAction/index.ts +0 -75
  37. package/src/plugins/getAction/schemas.ts +0 -41
  38. package/src/plugins/getApp/index.test.ts +0 -181
  39. package/src/plugins/getApp/index.ts +0 -60
  40. package/src/plugins/getApp/schemas.ts +0 -33
  41. package/src/plugins/getAuthentication/index.test.ts +0 -294
  42. package/src/plugins/getAuthentication/index.ts +0 -95
  43. package/src/plugins/getAuthentication/schemas.ts +0 -38
  44. package/src/plugins/getProfile/index.ts +0 -60
  45. package/src/plugins/getProfile/schemas.ts +0 -24
  46. package/src/plugins/listActions/index.test.ts +0 -526
  47. package/src/plugins/listActions/index.ts +0 -132
  48. package/src/plugins/listActions/schemas.ts +0 -55
  49. package/src/plugins/listApps/index.test.ts +0 -378
  50. package/src/plugins/listApps/index.ts +0 -159
  51. package/src/plugins/listApps/schemas.ts +0 -41
  52. package/src/plugins/listAuthentications/index.test.ts +0 -739
  53. package/src/plugins/listAuthentications/index.ts +0 -152
  54. package/src/plugins/listAuthentications/schemas.ts +0 -77
  55. package/src/plugins/listInputFieldChoices/index.test.ts +0 -653
  56. package/src/plugins/listInputFieldChoices/index.ts +0 -173
  57. package/src/plugins/listInputFieldChoices/schemas.ts +0 -125
  58. package/src/plugins/listInputFields/index.test.ts +0 -439
  59. package/src/plugins/listInputFields/index.ts +0 -294
  60. package/src/plugins/listInputFields/schemas.ts +0 -68
  61. package/src/plugins/manifest/index.test.ts +0 -776
  62. package/src/plugins/manifest/index.ts +0 -461
  63. package/src/plugins/manifest/schemas.ts +0 -60
  64. package/src/plugins/registry/index.ts +0 -160
  65. package/src/plugins/request/index.test.ts +0 -333
  66. package/src/plugins/request/index.ts +0 -105
  67. package/src/plugins/request/schemas.ts +0 -69
  68. package/src/plugins/runAction/index.test.ts +0 -388
  69. package/src/plugins/runAction/index.ts +0 -215
  70. package/src/plugins/runAction/schemas.ts +0 -60
  71. package/src/resolvers/actionKey.ts +0 -37
  72. package/src/resolvers/actionType.ts +0 -34
  73. package/src/resolvers/appKey.ts +0 -7
  74. package/src/resolvers/authenticationId.ts +0 -54
  75. package/src/resolvers/index.ts +0 -11
  76. package/src/resolvers/inputFieldKey.ts +0 -70
  77. package/src/resolvers/inputs.ts +0 -69
  78. package/src/schemas/Action.ts +0 -52
  79. package/src/schemas/App.ts +0 -45
  80. package/src/schemas/Auth.ts +0 -59
  81. package/src/schemas/Field.ts +0 -169
  82. package/src/schemas/Run.ts +0 -40
  83. package/src/schemas/UserProfile.ts +0 -60
  84. package/src/sdk.test.ts +0 -212
  85. package/src/sdk.ts +0 -178
  86. package/src/types/domain.test.ts +0 -50
  87. package/src/types/domain.ts +0 -66
  88. package/src/types/errors.ts +0 -278
  89. package/src/types/events.ts +0 -43
  90. package/src/types/functions.ts +0 -28
  91. package/src/types/optional-zapier-sdk-cli-login.d.ts +0 -37
  92. package/src/types/plugin.ts +0 -125
  93. package/src/types/properties.ts +0 -80
  94. package/src/types/sdk.ts +0 -111
  95. package/src/types/telemetry-events.ts +0 -85
  96. package/src/utils/array-utils.test.ts +0 -131
  97. package/src/utils/array-utils.ts +0 -41
  98. package/src/utils/domain-utils.test.ts +0 -433
  99. package/src/utils/domain-utils.ts +0 -267
  100. package/src/utils/file-utils.test.ts +0 -73
  101. package/src/utils/file-utils.ts +0 -94
  102. package/src/utils/function-utils.test.ts +0 -141
  103. package/src/utils/function-utils.ts +0 -245
  104. package/src/utils/pagination-utils.test.ts +0 -620
  105. package/src/utils/pagination-utils.ts +0 -242
  106. package/src/utils/schema-utils.ts +0 -207
  107. package/src/utils/string-utils.test.ts +0 -45
  108. package/src/utils/string-utils.ts +0 -54
  109. package/src/utils/validation.test.ts +0 -51
  110. package/src/utils/validation.ts +0 -44
  111. package/tsconfig.build.json +0 -18
  112. package/tsconfig.json +0 -20
  113. package/tsconfig.tsbuildinfo +0 -1
  114. package/tsup.config.ts +0 -23
@@ -1,739 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from "vitest";
2
- import {
3
- ZapierValidationError,
4
- ZapierAuthenticationError,
5
- } from "../../types/errors";
6
- import { listAuthenticationsPlugin } from "./index";
7
- import { createSdk } from "../../sdk";
8
- import type { ApiClient } from "../../api";
9
-
10
- const mockAuthenticationsResponse = {
11
- results: [
12
- {
13
- id: 123,
14
- date: "2021-01-01",
15
- account_id: 456 as any,
16
- selected_api: "SlackCLIAPI@1.21.1",
17
- is_invite_only: false,
18
- is_private: false,
19
- shared_with_all: false,
20
- is_stale: "false",
21
- marked_stale_at: null,
22
- label: "My Slack Workspace",
23
- title: "My Slack Workspace",
24
- },
25
- {
26
- id: 789,
27
- date: "2021-02-01",
28
- account_id: 456 as any,
29
- selected_api: "GitHubAPI@2.1.0",
30
- is_invite_only: false,
31
- is_private: false,
32
- shared_with_all: true,
33
- is_stale: "true",
34
- marked_stale_at: "2021-06-01",
35
- label: "GitHub Integration",
36
- title: "GitHub Integration",
37
- },
38
- ],
39
- count: 2,
40
- next: null,
41
- previous: null,
42
- };
43
-
44
- describe("listAuthentications plugin", () => {
45
- let mockApiClient: ApiClient;
46
- let mockGetVersionedImplementationId: any;
47
-
48
- beforeEach(() => {
49
- vi.clearAllMocks();
50
- mockApiClient = {
51
- get: vi.fn().mockResolvedValue(mockAuthenticationsResponse),
52
- } as Partial<ApiClient> as ApiClient;
53
-
54
- mockGetVersionedImplementationId = vi
55
- .fn()
56
- .mockResolvedValue("SlackCLIAPI@1.21.1");
57
- });
58
-
59
- const apiPlugin = () => ({
60
- context: {
61
- api: mockApiClient,
62
- },
63
- });
64
-
65
- const mockResolveAppKeys = vi.fn().mockResolvedValue([]);
66
-
67
- const manifestPlugin = () => ({
68
- context: {
69
- manifest: null,
70
- getVersionedImplementationId: mockGetVersionedImplementationId,
71
- resolveAppKeys: mockResolveAppKeys,
72
- updateManifestEntry: vi
73
- .fn()
74
- .mockResolvedValue(["test-key", {}, { apps: {} }]),
75
- },
76
- });
77
-
78
- function createTestSdk() {
79
- return createSdk()
80
- .addPlugin(apiPlugin)
81
- .addPlugin(manifestPlugin)
82
- .addPlugin(listAuthenticationsPlugin);
83
- }
84
-
85
- describe("schema validation", () => {
86
- it("should pass validation with empty options", async () => {
87
- const sdk = createTestSdk();
88
- const result = await sdk.listAuthentications({});
89
- expect(result.data).toHaveLength(2);
90
- });
91
-
92
- it("should handle undefined options", async () => {
93
- const sdk = createTestSdk();
94
- const result = await sdk.listAuthentications();
95
- expect(result.data).toHaveLength(2);
96
- expect(result.data[0]).toMatchObject({
97
- id: 123,
98
- });
99
- });
100
-
101
- it("should throw validation error for invalid appKey type", () => {
102
- const sdk = createTestSdk();
103
- expect(() => {
104
- sdk.listAuthentications({
105
- appKey: 123 as any,
106
- });
107
- }).toThrow(ZapierValidationError);
108
- });
109
-
110
- it("should throw validation error for invalid search type", () => {
111
- const sdk = createTestSdk();
112
- expect(() => {
113
- sdk.listAuthentications({
114
- search: 123 as any,
115
- });
116
- }).toThrow(ZapierValidationError);
117
- });
118
-
119
- it("should throw validation error for invalid title type", () => {
120
- const sdk = createTestSdk();
121
- expect(() => {
122
- sdk.listAuthentications({
123
- title: 123 as any,
124
- });
125
- }).toThrow(ZapierValidationError);
126
- });
127
-
128
- it("should throw validation error for invalid accountId type", () => {
129
- const sdk = createTestSdk();
130
- expect(() => {
131
- sdk.listAuthentications({
132
- accountId: 123 as any,
133
- });
134
- }).toThrow(ZapierValidationError);
135
- });
136
-
137
- it("should throw validation error for invalid owner type", () => {
138
- const sdk = createTestSdk();
139
- expect(() => {
140
- sdk.listAuthentications({
141
- owner: 123 as any,
142
- });
143
- }).toThrow(ZapierValidationError);
144
- });
145
-
146
- it("should throw validation error for invalid authenticationIds type", () => {
147
- const sdk = createTestSdk();
148
- expect(() => {
149
- sdk.listAuthentications({
150
- authenticationIds: "123" as any, // Should be array of strings
151
- });
152
- }).toThrow(ZapierValidationError);
153
-
154
- expect(() => {
155
- sdk.listAuthentications({
156
- authenticationIds: [123] as any, // Should be array of strings, not numbers
157
- });
158
- }).toThrow(ZapierValidationError);
159
- });
160
-
161
- it("should throw validation error for invalid pageSize", () => {
162
- const sdk = createTestSdk();
163
- expect(() => {
164
- sdk.listAuthentications({
165
- pageSize: 0, // Should be >= 1
166
- });
167
- }).toThrow(ZapierValidationError);
168
-
169
- expect(() => {
170
- sdk.listAuthentications({
171
- pageSize: -5, // Should be >= 1
172
- });
173
- }).toThrow(ZapierValidationError);
174
- });
175
-
176
- it("should throw validation error for invalid maxItems", () => {
177
- const sdk = createTestSdk();
178
- expect(() => {
179
- sdk.listAuthentications({
180
- maxItems: 0 as any, // Should be >= 1
181
- });
182
- }).toThrow(ZapierValidationError);
183
-
184
- expect(() => {
185
- sdk.listAuthentications({
186
- maxItems: -10 as any, // Should be >= 1
187
- });
188
- }).toThrow(ZapierValidationError);
189
- });
190
-
191
- it("should pass validation with all valid fields", async () => {
192
- const sdk = createTestSdk();
193
- const result = await sdk.listAuthentications({
194
- appKey: "slack",
195
- authenticationIds: ["123", "456"],
196
- search: "workspace",
197
- title: "My Slack Workspace",
198
- accountId: "acc_123",
199
- owner: "me",
200
- pageSize: 10,
201
- maxItems: 50,
202
- });
203
-
204
- expect(result.data).toBeDefined();
205
- });
206
- });
207
-
208
- describe("data mapping", () => {
209
- it("should map is_stale to is_expired and marked_stale_at to expired_at", async () => {
210
- const sdk = createTestSdk();
211
- const result = await sdk.listAuthentications();
212
-
213
- expect(result.data[0].is_expired).toBe("false");
214
- expect(result.data[0].expired_at).toBe(null);
215
- expect(result.data[1].is_expired).toBe("true");
216
- expect(result.data[1].expired_at).toBe("2021-06-01");
217
- });
218
-
219
- it("should coerce title from label when title is missing", async () => {
220
- const responseWithoutTitle = {
221
- ...mockAuthenticationsResponse,
222
- results: [
223
- {
224
- ...mockAuthenticationsResponse.results[0],
225
- title: undefined,
226
- label: "Label Only Auth",
227
- },
228
- ],
229
- };
230
-
231
- mockApiClient.get = vi.fn().mockResolvedValue(responseWithoutTitle);
232
-
233
- const sdk = createTestSdk();
234
- const result = await sdk.listAuthentications({});
235
-
236
- expect(result.data[0].title).toBe("Label Only Auth");
237
- });
238
-
239
- it("should handle authentications with neither title nor label", async () => {
240
- const responseWithoutTitleOrLabel = {
241
- ...mockAuthenticationsResponse,
242
- results: [
243
- {
244
- ...mockAuthenticationsResponse.results[0],
245
- title: undefined,
246
- label: undefined,
247
- },
248
- ],
249
- };
250
-
251
- mockApiClient.get = vi
252
- .fn()
253
- .mockResolvedValue(responseWithoutTitleOrLabel);
254
-
255
- const sdk = createTestSdk();
256
- const result = await sdk.listAuthentications({});
257
-
258
- expect(result.data[0].title).toBeUndefined();
259
- });
260
- });
261
-
262
- describe("filtering", () => {
263
- it("should filter by exact title match", async () => {
264
- const sdk = createTestSdk();
265
- const result = await sdk.listAuthentications({
266
- title: "My Slack Workspace",
267
- });
268
-
269
- // Should filter to exact match
270
- expect(result.data).toHaveLength(1);
271
- expect(result.data[0].title).toBe("My Slack Workspace");
272
- });
273
-
274
- it("should use search parameter when provided", async () => {
275
- const sdk = createTestSdk();
276
- await sdk.listAuthentications({ search: "workspace" });
277
-
278
- expect(mockApiClient.get).toHaveBeenCalledWith(
279
- "/api/v4/authentications/",
280
- expect.objectContaining({
281
- searchParams: expect.objectContaining({
282
- search: "workspace",
283
- }),
284
- }),
285
- );
286
- });
287
-
288
- it("should use title as search when search not provided", async () => {
289
- const sdk = createTestSdk();
290
- await sdk.listAuthentications({ title: "My Slack Workspace" });
291
-
292
- expect(mockApiClient.get).toHaveBeenCalledWith(
293
- "/api/v4/authentications/",
294
- expect.objectContaining({
295
- searchParams: expect.objectContaining({
296
- search: "My Slack Workspace",
297
- }),
298
- }),
299
- );
300
- });
301
-
302
- it("should prefer search over title when both provided", async () => {
303
- const sdk = createTestSdk();
304
- await sdk.listAuthentications({
305
- search: "explicit search",
306
- title: "My Title",
307
- });
308
-
309
- expect(mockApiClient.get).toHaveBeenCalledWith(
310
- "/api/v4/authentications/",
311
- expect.objectContaining({
312
- searchParams: expect.objectContaining({
313
- search: "explicit search",
314
- }),
315
- }),
316
- );
317
- });
318
-
319
- it("should pass accountId filter to API", async () => {
320
- const sdk = createTestSdk();
321
- await sdk.listAuthentications({ accountId: "acc_123" });
322
-
323
- expect(mockApiClient.get).toHaveBeenCalledWith(
324
- "/api/v4/authentications/",
325
- expect.objectContaining({
326
- searchParams: expect.objectContaining({
327
- account_id: "acc_123",
328
- }),
329
- }),
330
- );
331
- });
332
-
333
- it("should pass owner filter to API", async () => {
334
- const sdk = createTestSdk();
335
- await sdk.listAuthentications({ owner: "me" });
336
-
337
- expect(mockApiClient.get).toHaveBeenCalledWith(
338
- "/api/v4/authentications/",
339
- expect.objectContaining({
340
- searchParams: expect.objectContaining({
341
- owner: "me",
342
- }),
343
- }),
344
- );
345
- });
346
-
347
- it("should pass authenticationIds as ids parameter to API", async () => {
348
- const sdk = createTestSdk();
349
- await sdk.listAuthentications({
350
- authenticationIds: ["123", "456", "789"],
351
- });
352
-
353
- expect(mockApiClient.get).toHaveBeenCalledWith(
354
- "/api/v4/authentications/",
355
- expect.objectContaining({
356
- searchParams: expect.objectContaining({
357
- ids: "123,456,789",
358
- }),
359
- }),
360
- );
361
- });
362
-
363
- it("should not include ids parameter when authenticationIds is empty", async () => {
364
- const sdk = createTestSdk();
365
- await sdk.listAuthentications({
366
- authenticationIds: [],
367
- });
368
-
369
- expect(mockApiClient.get).toHaveBeenCalledWith(
370
- "/api/v4/authentications/",
371
- expect.objectContaining({
372
- searchParams: expect.not.objectContaining({
373
- ids: expect.anything(),
374
- }),
375
- }),
376
- );
377
- });
378
- });
379
-
380
- describe("pagination", () => {
381
- it("should handle pagination with maxItems by collecting all items", async () => {
382
- // Mock multiple pages - first page has 2 items, second page has 1 item
383
- mockApiClient.get = vi
384
- .fn()
385
- .mockResolvedValueOnce({
386
- results: mockAuthenticationsResponse.results,
387
- count: 3,
388
- next: "http://example.com/api/v4/authentications/?offset=2",
389
- })
390
- .mockResolvedValueOnce({
391
- results: [
392
- {
393
- id: 999,
394
- date: "2021-03-01",
395
- account_id: 456 as any,
396
- selected_api: "DropboxAPI@3.0.0",
397
- is_invite_only: false,
398
- is_private: false,
399
- shared_with_all: false,
400
- is_stale: "false",
401
- marked_stale_at: null,
402
- title: "Dropbox Integration",
403
- },
404
- ],
405
- count: 3,
406
- next: null,
407
- });
408
-
409
- const sdk = createTestSdk();
410
- // Collect all items using the items() iterator
411
- const items = [];
412
- for await (const item of sdk
413
- .listAuthentications({ maxItems: 3 })
414
- .items()) {
415
- items.push(item);
416
- }
417
-
418
- expect(items).toHaveLength(3); // Should stop at maxItems
419
- expect(mockApiClient.get).toHaveBeenCalledTimes(2); // Should fetch both pages
420
- });
421
-
422
- it("should return first page when awaited", async () => {
423
- mockApiClient.get = vi.fn().mockResolvedValue({
424
- results: mockAuthenticationsResponse.results,
425
- count: 2,
426
- next: null, // No more pages to prevent automatic fetching
427
- });
428
-
429
- const sdk = createTestSdk();
430
- const result = await sdk.listAuthentications({});
431
-
432
- // Await returns first page only
433
- expect(result.data).toHaveLength(2);
434
- expect(mockApiClient.get).toHaveBeenCalledTimes(1);
435
- });
436
-
437
- it("should support async iteration over pages", async () => {
438
- mockApiClient.get = vi
439
- .fn()
440
- .mockResolvedValueOnce({
441
- results: mockAuthenticationsResponse.results.slice(0, 1),
442
- count: 2,
443
- next: "http://example.com/api/v4/authentications/?offset=1",
444
- })
445
- .mockResolvedValueOnce({
446
- results: mockAuthenticationsResponse.results.slice(1, 2),
447
- count: 2,
448
- next: null,
449
- });
450
-
451
- const sdk = createTestSdk();
452
- const pages = [];
453
- for await (const page of sdk.listAuthentications({ pageSize: 1 })) {
454
- pages.push(page);
455
- if (pages.length >= 2) break;
456
- }
457
-
458
- expect(pages).toHaveLength(2);
459
- expect(pages[0].data).toHaveLength(1);
460
- expect(pages[1].data).toHaveLength(1);
461
- expect(pages[0].data[0].id).toBe(123);
462
- expect(pages[1].data[0].id).toBe(789);
463
- });
464
-
465
- it("should support async iteration over individual items", async () => {
466
- const sdk = createTestSdk();
467
- const items = [];
468
- for await (const item of sdk
469
- .listAuthentications({ maxItems: 2 })
470
- .items()) {
471
- items.push(item);
472
- }
473
-
474
- expect(items).toHaveLength(2);
475
- expect(items[0].id).toBe(123);
476
- expect(items[1].id).toBe(789);
477
- });
478
-
479
- it("should set appropriate pageSize for API calls", async () => {
480
- const sdk = createTestSdk();
481
- await sdk.listAuthentications({ pageSize: 1 });
482
-
483
- expect(mockApiClient.get).toHaveBeenCalledWith(
484
- "/api/v4/authentications/",
485
- expect.objectContaining({
486
- searchParams: expect.objectContaining({
487
- limit: "1",
488
- }),
489
- }),
490
- );
491
- });
492
- });
493
-
494
- describe("API integration", () => {
495
- it("should call the correct API endpoint", async () => {
496
- const sdk = createTestSdk();
497
- await sdk.listAuthentications({});
498
-
499
- expect(mockApiClient.get).toHaveBeenCalledWith(
500
- "/api/v4/authentications/",
501
- expect.any(Object),
502
- );
503
- });
504
-
505
- it("should pass pageSize as limit parameter", async () => {
506
- const sdk = createTestSdk();
507
- await sdk.listAuthentications({ pageSize: 25 });
508
-
509
- expect(mockApiClient.get).toHaveBeenCalledWith(
510
- "/api/v4/authentications/",
511
- expect.objectContaining({
512
- searchParams: expect.objectContaining({
513
- limit: "25",
514
- }),
515
- }),
516
- );
517
- });
518
-
519
- it("should handle cursor-based pagination internally", async () => {
520
- mockApiClient.get = vi
521
- .fn()
522
- .mockResolvedValueOnce({
523
- results: mockAuthenticationsResponse.results.slice(0, 1),
524
- count: 2,
525
- next: "http://example.com/api/v4/authentications/?offset=1",
526
- })
527
- .mockResolvedValueOnce({
528
- results: mockAuthenticationsResponse.results.slice(1, 2),
529
- count: 2,
530
- next: null,
531
- });
532
-
533
- const sdk = createTestSdk();
534
- // Test that the function can handle multiple pages
535
- let pageCount = 0;
536
- for await (const _page of sdk.listAuthentications({ pageSize: 1 })) {
537
- pageCount++;
538
- if (pageCount >= 2) break;
539
- }
540
-
541
- expect(pageCount).toBe(2);
542
- expect(mockApiClient.get).toHaveBeenCalledTimes(2);
543
- // The second call should include the offset from the cursor
544
- expect(mockApiClient.get).toHaveBeenNthCalledWith(
545
- 2,
546
- "/api/v4/authentications/",
547
- expect.objectContaining({
548
- searchParams: expect.objectContaining({
549
- offset: "1",
550
- }),
551
- }),
552
- );
553
- });
554
- });
555
-
556
- describe("error handling", () => {
557
- it("should throw ZapierAuthenticationError for 401 responses", async () => {
558
- const customErrorHandler = vi
559
- .fn()
560
- .mockReturnValue(
561
- new ZapierAuthenticationError(
562
- "Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP 401)",
563
- { statusCode: 401 },
564
- ),
565
- );
566
-
567
- mockApiClient.get = vi.fn().mockImplementation(() => {
568
- const error = customErrorHandler({ status: 401 });
569
- throw error;
570
- });
571
-
572
- const sdk = createTestSdk();
573
- await expect(sdk.listAuthentications({})).rejects.toThrow(
574
- ZapierAuthenticationError,
575
- );
576
- });
577
-
578
- it("should throw ZapierAuthenticationError for 403 responses", async () => {
579
- const customErrorHandler = vi
580
- .fn()
581
- .mockReturnValue(
582
- new ZapierAuthenticationError(
583
- "Access forbidden. Your token may not have the required scopes to list authentications. (HTTP 403)",
584
- { statusCode: 403 },
585
- ),
586
- );
587
-
588
- mockApiClient.get = vi.fn().mockImplementation(() => {
589
- const error = customErrorHandler({ status: 403 });
590
- throw error;
591
- });
592
-
593
- const sdk = createTestSdk();
594
- await expect(sdk.listAuthentications({})).rejects.toThrow(
595
- ZapierAuthenticationError,
596
- );
597
- });
598
-
599
- it("should handle empty results", async () => {
600
- const emptyResponse = {
601
- results: [],
602
- count: 0,
603
- next: null,
604
- };
605
-
606
- mockApiClient.get = vi.fn().mockResolvedValue(emptyResponse);
607
-
608
- const sdk = createTestSdk();
609
- const result = await sdk.listAuthentications({});
610
-
611
- expect(result.data).toHaveLength(0);
612
- expect(Array.isArray(result.data)).toBe(true);
613
- });
614
-
615
- it("should handle missing results field", async () => {
616
- const responseWithoutResults = {
617
- count: 0,
618
- next: null,
619
- };
620
-
621
- mockApiClient.get = vi.fn().mockResolvedValue(responseWithoutResults);
622
-
623
- const sdk = createTestSdk();
624
- const result = await sdk.listAuthentications({});
625
-
626
- expect(result.data).toHaveLength(0);
627
- expect(Array.isArray(result.data)).toBe(true);
628
- });
629
- });
630
-
631
- describe("app key integration", () => {
632
- it("should handle app without current_implementation_id", async () => {
633
- mockGetVersionedImplementationId.mockResolvedValue(null);
634
-
635
- const sdk = createTestSdk();
636
- await sdk.listAuthentications({ appKey: "slack" });
637
-
638
- // Should not add versionless_selected_api parameter
639
- expect(mockApiClient.get).toHaveBeenCalledWith(
640
- "/api/v4/authentications/",
641
- expect.objectContaining({
642
- searchParams: expect.not.objectContaining({
643
- versionless_selected_api: expect.any(String),
644
- }),
645
- }),
646
- );
647
- });
648
-
649
- it("should extract versionless API from versioned implementation ID", async () => {
650
- mockGetVersionedImplementationId.mockResolvedValue("SlackCLIAPI@2.1.3");
651
-
652
- const sdk = createTestSdk();
653
- await sdk.listAuthentications({ appKey: "slack" });
654
-
655
- expect(mockApiClient.get).toHaveBeenCalledWith(
656
- "/api/v4/authentications/",
657
- expect.objectContaining({
658
- searchParams: expect.objectContaining({
659
- versionless_selected_api: "SlackCLIAPI",
660
- }),
661
- }),
662
- );
663
- });
664
- });
665
-
666
- describe("response transformation", () => {
667
- it("should preserve all original authentication fields", async () => {
668
- const authWithAllFields = {
669
- results: [
670
- {
671
- id: 123,
672
- date: "2021-01-01",
673
- lastchanged: "2021-01-02",
674
- account_id: 456 as any,
675
- customuser_id: 789,
676
- selected_api: "SlackCLIAPI@1.21.1",
677
- destination_selected_api: "SlackDestAPI@1.0.0",
678
- is_invite_only: true,
679
- is_private: true,
680
- shared_with_all: false,
681
- is_stale: "true",
682
- is_shared: "false",
683
- marked_stale_at: "2021-06-01",
684
- label: "Auth Label",
685
- title: "Auth Title",
686
- identifier: "auth-identifier",
687
- url: "https://example.com",
688
- groups: "group1,group2",
689
- members: "user1,user2",
690
- permissions: { read: true, write: false },
691
- },
692
- ],
693
- count: 1,
694
- };
695
-
696
- mockApiClient.get = vi.fn().mockResolvedValue(authWithAllFields);
697
-
698
- const sdk = createTestSdk();
699
- const result = await sdk.listAuthentications({});
700
- const auth = result.data[0];
701
-
702
- // Verify original fields are preserved
703
- expect(auth.id).toBe(123);
704
- expect(auth.date).toBe("2021-01-01");
705
- expect(auth.lastchanged).toBe("2021-01-02");
706
- expect(auth.account_id).toBe(456);
707
- expect(auth.user_id).toBe(789);
708
- expect(auth.implementation_id).toBe("SlackCLIAPI@1.21.1");
709
- expect(auth.destination_selected_api).toBe("SlackDestAPI@1.0.0");
710
- expect(auth.is_invite_only).toBe(true);
711
- expect(auth.is_private).toBe(true);
712
- expect(auth.shared_with_all).toBe(false);
713
- expect(auth.is_shared).toBe("false");
714
- expect(auth.label).toBe("Auth Label");
715
- expect(auth.title).toBe("Auth Title");
716
- expect(auth.identifier).toBe("auth-identifier");
717
- expect(auth.url).toBe("https://example.com");
718
- expect(auth.groups).toBe("group1,group2");
719
- expect(auth.members).toBe("user1,user2");
720
- expect(auth.permissions).toEqual({ read: true, write: false });
721
-
722
- // Verify mapped fields
723
- expect(auth.is_expired).toBe("true");
724
- expect(auth.expired_at).toBe("2021-06-01");
725
- });
726
- });
727
-
728
- describe("context and metadata", () => {
729
- it("should provide context with meta information", () => {
730
- const sdk = createTestSdk();
731
- const context = sdk.getContext();
732
-
733
- expect((context.meta as any).listAuthentications).toBeDefined();
734
- expect(
735
- (context.meta as any).listAuthentications.inputSchema,
736
- ).toBeDefined();
737
- });
738
- });
739
- });