@zapier/zapier-sdk 0.32.5 → 0.33.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/auth.d.ts.map +1 -1
  3. package/dist/auth.js +1 -0
  4. package/dist/constants.d.ts +0 -14
  5. package/dist/constants.d.ts.map +1 -1
  6. package/dist/constants.js +0 -14
  7. package/dist/credentials.d.ts.map +1 -1
  8. package/dist/credentials.js +19 -20
  9. package/dist/index.cjs +22 -37
  10. package/dist/index.d.mts +1 -15
  11. package/dist/index.mjs +23 -30
  12. package/package.json +2 -2
  13. package/dist/api/auth.test.d.ts +0 -2
  14. package/dist/api/auth.test.d.ts.map +0 -1
  15. package/dist/api/auth.test.js +0 -220
  16. package/dist/api/client.test.d.ts +0 -2
  17. package/dist/api/client.test.d.ts.map +0 -1
  18. package/dist/api/client.test.js +0 -611
  19. package/dist/api/debug.test.d.ts +0 -2
  20. package/dist/api/debug.test.d.ts.map +0 -1
  21. package/dist/api/debug.test.js +0 -59
  22. package/dist/api/polling.test.d.ts +0 -2
  23. package/dist/api/polling.test.d.ts.map +0 -1
  24. package/dist/api/polling.test.js +0 -360
  25. package/dist/auth.test.d.ts +0 -2
  26. package/dist/auth.test.d.ts.map +0 -1
  27. package/dist/auth.test.js +0 -480
  28. package/dist/plugins/eventEmission/builders.test.d.ts +0 -2
  29. package/dist/plugins/eventEmission/builders.test.d.ts.map +0 -1
  30. package/dist/plugins/eventEmission/builders.test.js +0 -138
  31. package/dist/plugins/eventEmission/index.test.d.ts +0 -5
  32. package/dist/plugins/eventEmission/index.test.d.ts.map +0 -1
  33. package/dist/plugins/eventEmission/index.test.js +0 -704
  34. package/dist/plugins/eventEmission/transport.test.d.ts +0 -5
  35. package/dist/plugins/eventEmission/transport.test.d.ts.map +0 -1
  36. package/dist/plugins/eventEmission/transport.test.js +0 -164
  37. package/dist/plugins/fetch/index.test.d.ts +0 -2
  38. package/dist/plugins/fetch/index.test.d.ts.map +0 -1
  39. package/dist/plugins/fetch/index.test.js +0 -428
  40. package/dist/plugins/findFirstConnection/index.test.d.ts +0 -2
  41. package/dist/plugins/findFirstConnection/index.test.d.ts.map +0 -1
  42. package/dist/plugins/findFirstConnection/index.test.js +0 -177
  43. package/dist/plugins/findUniqueConnection/index.test.d.ts +0 -2
  44. package/dist/plugins/findUniqueConnection/index.test.d.ts.map +0 -1
  45. package/dist/plugins/findUniqueConnection/index.test.js +0 -159
  46. package/dist/plugins/getAction/index.test.d.ts +0 -2
  47. package/dist/plugins/getAction/index.test.d.ts.map +0 -1
  48. package/dist/plugins/getAction/index.test.js +0 -211
  49. package/dist/plugins/getApp/index.test.d.ts +0 -2
  50. package/dist/plugins/getApp/index.test.d.ts.map +0 -1
  51. package/dist/plugins/getApp/index.test.js +0 -157
  52. package/dist/plugins/getConnection/index.test.d.ts +0 -2
  53. package/dist/plugins/getConnection/index.test.d.ts.map +0 -1
  54. package/dist/plugins/getConnection/index.test.js +0 -124
  55. package/dist/plugins/getInputFieldsSchema/index.test.d.ts +0 -2
  56. package/dist/plugins/getInputFieldsSchema/index.test.d.ts.map +0 -1
  57. package/dist/plugins/getInputFieldsSchema/index.test.js +0 -291
  58. package/dist/plugins/listActions/index.test.d.ts +0 -2
  59. package/dist/plugins/listActions/index.test.d.ts.map +0 -1
  60. package/dist/plugins/listActions/index.test.js +0 -454
  61. package/dist/plugins/listApps/index.test.d.ts +0 -2
  62. package/dist/plugins/listApps/index.test.d.ts.map +0 -1
  63. package/dist/plugins/listApps/index.test.js +0 -124
  64. package/dist/plugins/listConnections/index.test.d.ts +0 -2
  65. package/dist/plugins/listConnections/index.test.d.ts.map +0 -1
  66. package/dist/plugins/listConnections/index.test.js +0 -920
  67. package/dist/plugins/listInputFieldChoices/index.test.d.ts +0 -2
  68. package/dist/plugins/listInputFieldChoices/index.test.d.ts.map +0 -1
  69. package/dist/plugins/listInputFieldChoices/index.test.js +0 -717
  70. package/dist/plugins/listInputFields/index.test.d.ts +0 -2
  71. package/dist/plugins/listInputFields/index.test.d.ts.map +0 -1
  72. package/dist/plugins/listInputFields/index.test.js +0 -359
  73. package/dist/plugins/manifest/index.test.d.ts +0 -2
  74. package/dist/plugins/manifest/index.test.d.ts.map +0 -1
  75. package/dist/plugins/manifest/index.test.js +0 -1179
  76. package/dist/plugins/request/index.test.d.ts +0 -2
  77. package/dist/plugins/request/index.test.d.ts.map +0 -1
  78. package/dist/plugins/request/index.test.js +0 -458
  79. package/dist/plugins/runAction/index.test.d.ts +0 -2
  80. package/dist/plugins/runAction/index.test.d.ts.map +0 -1
  81. package/dist/plugins/runAction/index.test.js +0 -350
  82. package/dist/resolvers/connectionId.test.d.ts +0 -2
  83. package/dist/resolvers/connectionId.test.d.ts.map +0 -1
  84. package/dist/resolvers/connectionId.test.js +0 -61
  85. package/dist/sdk.test.d.ts +0 -2
  86. package/dist/sdk.test.d.ts.map +0 -1
  87. package/dist/sdk.test.js +0 -260
  88. package/dist/types/domain.test.d.ts +0 -2
  89. package/dist/types/domain.test.d.ts.map +0 -1
  90. package/dist/types/domain.test.js +0 -39
  91. package/dist/utils/array-utils.test.d.ts +0 -2
  92. package/dist/utils/array-utils.test.d.ts.map +0 -1
  93. package/dist/utils/array-utils.test.js +0 -107
  94. package/dist/utils/batch-utils.test.d.ts +0 -2
  95. package/dist/utils/batch-utils.test.d.ts.map +0 -1
  96. package/dist/utils/batch-utils.test.js +0 -476
  97. package/dist/utils/domain-utils.test.d.ts +0 -2
  98. package/dist/utils/domain-utils.test.d.ts.map +0 -1
  99. package/dist/utils/domain-utils.test.js +0 -346
  100. package/dist/utils/file-utils.test.d.ts +0 -2
  101. package/dist/utils/file-utils.test.d.ts.map +0 -1
  102. package/dist/utils/file-utils.test.js +0 -51
  103. package/dist/utils/function-utils.test.d.ts +0 -2
  104. package/dist/utils/function-utils.test.d.ts.map +0 -1
  105. package/dist/utils/function-utils.test.js +0 -188
  106. package/dist/utils/id-utils.test.d.ts +0 -2
  107. package/dist/utils/id-utils.test.d.ts.map +0 -1
  108. package/dist/utils/id-utils.test.js +0 -22
  109. package/dist/utils/pagination-utils.test.d.ts +0 -17
  110. package/dist/utils/pagination-utils.test.d.ts.map +0 -1
  111. package/dist/utils/pagination-utils.test.js +0 -461
  112. package/dist/utils/retry-utils.test.d.ts +0 -2
  113. package/dist/utils/retry-utils.test.d.ts.map +0 -1
  114. package/dist/utils/retry-utils.test.js +0 -90
  115. package/dist/utils/string-utils.test.d.ts +0 -2
  116. package/dist/utils/string-utils.test.d.ts.map +0 -1
  117. package/dist/utils/string-utils.test.js +0 -59
  118. package/dist/utils/telemetry-context.test.d.ts +0 -2
  119. package/dist/utils/telemetry-context.test.d.ts.map +0 -1
  120. package/dist/utils/telemetry-context.test.js +0 -154
  121. package/dist/utils/telemetry-utils.test.d.ts +0 -2
  122. package/dist/utils/telemetry-utils.test.d.ts.map +0 -1
  123. package/dist/utils/telemetry-utils.test.js +0 -155
  124. package/dist/utils/url-utils.test.d.ts +0 -2
  125. package/dist/utils/url-utils.test.d.ts.map +0 -1
  126. package/dist/utils/url-utils.test.js +0 -103
  127. package/dist/utils/validation.test.d.ts +0 -2
  128. package/dist/utils/validation.test.d.ts.map +0 -1
  129. package/dist/utils/validation.test.js +0 -44
@@ -1,454 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from "vitest";
2
- import { ZapierValidationError, ZapierAuthenticationError, ZapierConfigurationError, } from "../../types/errors";
3
- import { listActionsPlugin } from "./index";
4
- import { createSdk } from "../../sdk";
5
- import { listAppsPlugin } from "../listApps";
6
- import { eventEmissionPlugin } from "../eventEmission";
7
- const mockImplementationsResponse = {
8
- results: [
9
- {
10
- slug: "slack",
11
- selected_api: "slack",
12
- actions: [
13
- {
14
- key: "user_by_email",
15
- name: "Search User by Email",
16
- description: "Find a user by email address",
17
- type_of: "search",
18
- type: "search",
19
- },
20
- {
21
- key: "send_message",
22
- name: "Send Message",
23
- description: "Send a message to a channel",
24
- type_of: "write",
25
- type: "write",
26
- },
27
- {
28
- key: "create_channel",
29
- name: "Create Channel",
30
- description: "Create a new channel",
31
- type_of: "write",
32
- type: "write",
33
- },
34
- ],
35
- },
36
- ],
37
- meta: {
38
- next_cursor: null,
39
- },
40
- };
41
- const mockEmptyImplementationsResponse = {
42
- results: [],
43
- meta: {
44
- next_cursor: null,
45
- },
46
- };
47
- describe("listActions plugin", () => {
48
- let mockApiClient;
49
- let mockGetVersionedImplementationId;
50
- beforeEach(() => {
51
- vi.clearAllMocks();
52
- mockApiClient = {
53
- get: vi.fn().mockResolvedValue(mockImplementationsResponse),
54
- };
55
- mockGetVersionedImplementationId = vi
56
- .fn()
57
- .mockResolvedValue("SlackCLIAPI@1.21.1");
58
- });
59
- const mockResolveAppKeys = vi.fn().mockResolvedValue([]);
60
- function createTestSdk() {
61
- // Create a proper plugin chain with context dependencies
62
- // Build SDK with proper plugin composition, providing API in initial context
63
- return createSdk()
64
- .addPlugin(() => ({
65
- context: {
66
- options: {},
67
- },
68
- }))
69
- .addPlugin(() => ({
70
- context: {
71
- api: mockApiClient,
72
- resolveCredentials: vi.fn().mockResolvedValue(undefined),
73
- },
74
- }))
75
- .addPlugin(eventEmissionPlugin)
76
- .addPlugin(() => ({
77
- context: {
78
- manifest: null,
79
- getVersionedImplementationId: mockGetVersionedImplementationId,
80
- resolveAppKeys: mockResolveAppKeys,
81
- updateManifestEntry: vi
82
- .fn()
83
- .mockResolvedValue(["test-key", {}, { apps: {} }]),
84
- addActionEntry: vi
85
- .fn()
86
- .mockResolvedValue(["test-key", {}, { apps: {} }]),
87
- findActionEntry: vi.fn().mockResolvedValue({
88
- key: "test-key",
89
- entry: {},
90
- manifest: { apps: {} },
91
- }),
92
- hasActionEntry: vi.fn().mockResolvedValue(true),
93
- listActionEntries: vi
94
- .fn()
95
- .mockResolvedValue([
96
- [
97
- "test-key",
98
- { key: "test-key", entry: {}, manifest: { apps: {} } },
99
- ],
100
- ]),
101
- deleteActionEntry: vi.fn().mockResolvedValue({ apps: {} }),
102
- findManifestEntry: vi
103
- .fn()
104
- .mockResolvedValue([
105
- "test-key",
106
- { key: "test-key", entry: {}, manifest: { apps: {} } },
107
- ]),
108
- readManifestFromFile: vi.fn().mockResolvedValue({ apps: {} }),
109
- },
110
- }))
111
- .addPlugin(listAppsPlugin)
112
- .addPlugin(listActionsPlugin);
113
- }
114
- describe("schema validation", () => {
115
- it("should pass validation with valid appKey", async () => {
116
- const sdk = createTestSdk();
117
- const result = await sdk.listActions({ appKey: "slack" });
118
- expect(result.data).toHaveLength(3);
119
- });
120
- it("should throw validation error for missing appKey", () => {
121
- const sdk = createTestSdk();
122
- expect(() => {
123
- sdk.listActions({});
124
- }).toThrow(ZapierValidationError);
125
- });
126
- it("should throw validation error for invalid appKey type", () => {
127
- const sdk = createTestSdk();
128
- expect(() => {
129
- sdk.listActions({
130
- appKey: 123,
131
- });
132
- }).toThrow(ZapierValidationError);
133
- });
134
- it("should throw validation error for empty appKey", () => {
135
- const sdk = createTestSdk();
136
- expect(() => {
137
- sdk.listActions({ appKey: "" });
138
- }).toThrow(ZapierValidationError);
139
- });
140
- it("should throw validation error for invalid pageSize", () => {
141
- const sdk = createTestSdk();
142
- expect(() => {
143
- sdk.listActions({ appKey: "slack", pageSize: 0 });
144
- }).toThrow(ZapierValidationError);
145
- expect(() => {
146
- sdk.listActions({ appKey: "slack", pageSize: -5 });
147
- }).toThrow(ZapierValidationError);
148
- });
149
- it("should throw validation error for invalid maxItems", () => {
150
- const sdk = createTestSdk();
151
- expect(() => {
152
- sdk.listActions({ appKey: "slack", maxItems: 0 });
153
- }).toThrow(ZapierValidationError);
154
- expect(() => {
155
- sdk.listActions({ appKey: "slack", maxItems: -10 });
156
- }).toThrow(ZapierValidationError);
157
- });
158
- it("should throw validation error for invalid actionType", () => {
159
- const sdk = createTestSdk();
160
- expect(() => {
161
- sdk.listActions({
162
- appKey: "slack",
163
- actionType: "invalid-type",
164
- });
165
- }).toThrow(ZapierValidationError);
166
- });
167
- it("should pass validation with all valid fields", async () => {
168
- const sdk = createTestSdk();
169
- const result = await sdk.listActions({
170
- appKey: "slack",
171
- actionType: "write",
172
- pageSize: 10,
173
- maxItems: 50,
174
- });
175
- expect(result.data).toHaveLength(2); // Only write actions
176
- expect(result.data.every((action) => action.action_type === "write")).toBe(true);
177
- });
178
- });
179
- describe("actionType enum validation", () => {
180
- const validActionTypes = [
181
- "read",
182
- "read_bulk",
183
- "write",
184
- "run",
185
- "search",
186
- "search_or_write",
187
- "search_and_write",
188
- "filter",
189
- ];
190
- validActionTypes.forEach((actionType) => {
191
- it(`should accept valid actionType: ${actionType}`, async () => {
192
- const mockResponse = {
193
- results: [
194
- {
195
- slug: "slack",
196
- actions: [
197
- {
198
- key: "test_action",
199
- name: "Test Action",
200
- description: "Test description",
201
- type_of: actionType,
202
- type: actionType,
203
- },
204
- ],
205
- },
206
- ],
207
- meta: { next_cursor: null },
208
- };
209
- mockApiClient.get = vi.fn().mockResolvedValue(mockResponse);
210
- const sdk = createTestSdk();
211
- const result = await sdk.listActions({
212
- appKey: "slack",
213
- actionType: actionType,
214
- });
215
- expect(result.data).toHaveLength(1);
216
- expect(result.data[0].action_type).toBe(actionType);
217
- });
218
- });
219
- });
220
- describe("data transformation", () => {
221
- it("should transform implementation actions to ActionItem format", async () => {
222
- const sdk = createTestSdk();
223
- const result = await sdk.listActions({ appKey: "slack" });
224
- const firstAction = result.data[0];
225
- // Check all required ActionItem fields are present
226
- expect(firstAction).toHaveProperty("key");
227
- expect(firstAction).toHaveProperty("type", "action");
228
- expect(firstAction).toHaveProperty("action_type");
229
- expect(firstAction).toHaveProperty("title");
230
- expect(firstAction).toHaveProperty("app_key", "slack");
231
- expect(firstAction).toHaveProperty("description");
232
- // Check that title is mapped from API name field
233
- expect(firstAction.title).toBe("Search User by Email");
234
- expect(firstAction.app_key).toBe("slack");
235
- expect(firstAction.type).toBe("action");
236
- });
237
- it("should map type_of to action_type", async () => {
238
- const sdk = createTestSdk();
239
- const result = await sdk.listActions({ appKey: "slack" });
240
- expect(result.data[0].action_type).toBe("search"); // From type_of field
241
- expect(result.data[1].action_type).toBe("write"); // From type_of field
242
- });
243
- it("should fall back to type field if type_of is missing", async () => {
244
- const mockResponseWithoutTypeOf = {
245
- results: [
246
- {
247
- slug: "slack",
248
- actions: [
249
- {
250
- key: "test_action",
251
- name: "Test Action",
252
- description: "Test description",
253
- type: "read", // Only type field, no type_of
254
- },
255
- ],
256
- },
257
- ],
258
- meta: { next_cursor: null },
259
- };
260
- mockApiClient.get = vi.fn().mockResolvedValue(mockResponseWithoutTypeOf);
261
- const sdk = createTestSdk();
262
- const result = await sdk.listActions({ appKey: "slack" });
263
- expect(result.data[0].action_type).toBe("read"); // Falls back to type field
264
- });
265
- it("should handle actions with read type", async () => {
266
- const mockResponseWithoutType = {
267
- results: [
268
- {
269
- slug: "slack",
270
- actions: [
271
- {
272
- key: "test_action",
273
- name: "Test Action",
274
- description: "Test description",
275
- type: "read", // Provide the required type field
276
- },
277
- ],
278
- },
279
- ],
280
- meta: { next_cursor: null },
281
- };
282
- mockApiClient.get = vi.fn().mockResolvedValue(mockResponseWithoutType);
283
- const sdk = createTestSdk();
284
- const result = await sdk.listActions({ appKey: "slack" });
285
- expect(result.data[0].action_type).toBe("read"); // Should match provided type
286
- });
287
- });
288
- describe("filtering", () => {
289
- it("should filter actions by actionType", async () => {
290
- const sdk = createTestSdk();
291
- const result = await sdk.listActions({
292
- appKey: "slack",
293
- actionType: "write",
294
- });
295
- expect(result.data).toHaveLength(2);
296
- expect(result.data.every((action) => action.action_type === "write")).toBe(true);
297
- expect(result.data.map((action) => action.key)).toEqual([
298
- "send_message",
299
- "create_channel",
300
- ]);
301
- });
302
- it("should return empty array when no actions match filter", async () => {
303
- const sdk = createTestSdk();
304
- const result = await sdk.listActions({
305
- appKey: "slack",
306
- actionType: "filter", // No actions of this type in mock data
307
- });
308
- expect(result.data).toHaveLength(0);
309
- });
310
- it("should return all actions when no actionType filter provided", async () => {
311
- const sdk = createTestSdk();
312
- const result = await sdk.listActions({ appKey: "slack" });
313
- expect(result.data).toHaveLength(3); // All actions
314
- });
315
- });
316
- describe("pagination", () => {
317
- it("should handle maxItems limit", async () => {
318
- const sdk = createTestSdk();
319
- const result = await sdk.listActions({
320
- appKey: "slack",
321
- maxItems: 2,
322
- });
323
- expect(result.data).toHaveLength(2); // Limited to maxItems
324
- });
325
- it("should support async iteration over pages", async () => {
326
- const sdk = createTestSdk();
327
- const listActions = sdk.listActions({ appKey: "slack" });
328
- const pages = [];
329
- for await (const page of listActions) {
330
- pages.push(page);
331
- break; // Just get first page for testing
332
- }
333
- expect(pages).toHaveLength(1);
334
- expect(pages[0].data).toHaveLength(3);
335
- expect(pages[0].data[0].key).toBe("user_by_email");
336
- });
337
- it("should support async iteration over individual items", async () => {
338
- const sdk = createTestSdk();
339
- const listActions = sdk.listActions({
340
- appKey: "slack",
341
- maxItems: 2,
342
- });
343
- const items = [];
344
- for await (const item of listActions.items()) {
345
- items.push(item);
346
- }
347
- expect(items).toHaveLength(2);
348
- expect(items[0].key).toBe("user_by_email");
349
- expect(items[1].key).toBe("send_message");
350
- });
351
- it("should respect pageSize parameter", async () => {
352
- const sdk = createTestSdk();
353
- await sdk.listActions({
354
- appKey: "slack",
355
- pageSize: 10,
356
- });
357
- // Note: Since listActions doesn't actually use pagination internally,
358
- // we just verify it accepts the parameter without error
359
- expect(mockApiClient.get).toHaveBeenCalled();
360
- });
361
- });
362
- describe("API integration", () => {
363
- it("should call getApp to get implementation ID", async () => {
364
- const sdk = createTestSdk();
365
- await sdk.listActions({ appKey: "slack" });
366
- expect(mockGetVersionedImplementationId).toHaveBeenCalledWith("slack");
367
- });
368
- it("should pass correct search parameters to implementations API", async () => {
369
- const sdk = createTestSdk();
370
- await sdk.listActions({ appKey: "slack" });
371
- expect(mockApiClient.get).toHaveBeenCalledWith("/zapier/api/v4/implementations/", expect.objectContaining({
372
- searchParams: expect.objectContaining({
373
- global: "true",
374
- public_only: "true",
375
- selected_apis: "SlackCLIAPI@1.21.1",
376
- }),
377
- }));
378
- });
379
- });
380
- describe("error handling", () => {
381
- it("should throw ZapierConfigurationError when app has no current_implementation_id", async () => {
382
- mockGetVersionedImplementationId.mockResolvedValue(null);
383
- const sdk = createTestSdk();
384
- await expect(sdk.listActions({ appKey: "slack" })).rejects.toThrow(ZapierConfigurationError);
385
- });
386
- it("should throw ZapierConfigurationError when current_implementation_id is empty", async () => {
387
- mockGetVersionedImplementationId.mockResolvedValue("");
388
- const sdk = createTestSdk();
389
- await expect(sdk.listActions({ appKey: "slack" })).rejects.toThrow(ZapierConfigurationError);
390
- });
391
- it("should handle authentication error (401)", async () => {
392
- mockApiClient.get = vi.fn().mockImplementation((_url, options) => {
393
- if (options.customErrorHandler) {
394
- const error = options.customErrorHandler({ status: 401 });
395
- if (error) {
396
- throw error;
397
- }
398
- }
399
- throw new Error("Unauthorized");
400
- });
401
- const sdk = createTestSdk();
402
- await expect(sdk.listActions({ appKey: "slack" })).rejects.toThrow(ZapierAuthenticationError);
403
- });
404
- it("should handle forbidden error (403)", async () => {
405
- mockApiClient.get = vi.fn().mockImplementation((_url, options) => {
406
- if (options.customErrorHandler) {
407
- const error = options.customErrorHandler({ status: 403 });
408
- if (error) {
409
- throw error;
410
- }
411
- }
412
- throw new Error("Forbidden");
413
- });
414
- const sdk = createTestSdk();
415
- await expect(sdk.listActions({ appKey: "slack" })).rejects.toThrow(ZapierAuthenticationError);
416
- });
417
- it("should return empty array when implementations API returns no results", async () => {
418
- mockApiClient.get = vi
419
- .fn()
420
- .mockResolvedValue(mockEmptyImplementationsResponse);
421
- const sdk = createTestSdk();
422
- const result = await sdk.listActions({ appKey: "slack" });
423
- expect(result.data).toHaveLength(0);
424
- });
425
- it("should handle implementation without actions", async () => {
426
- const mockResponseWithoutActions = {
427
- results: [
428
- {
429
- slug: "slack",
430
- // No actions property
431
- },
432
- ],
433
- meta: { next_cursor: null },
434
- };
435
- mockApiClient.get = vi.fn().mockResolvedValue(mockResponseWithoutActions);
436
- const sdk = createTestSdk();
437
- const result = await sdk.listActions({ appKey: "slack" });
438
- expect(result.data).toHaveLength(0);
439
- });
440
- it("should propagate getVersionedImplementationId errors", async () => {
441
- mockGetVersionedImplementationId.mockRejectedValue(new Error("App not found"));
442
- const sdk = createTestSdk();
443
- await expect(sdk.listActions({ appKey: "nonexistent" })).rejects.toThrow("App not found");
444
- });
445
- });
446
- describe("context and metadata", () => {
447
- it("should provide context with meta information", () => {
448
- const sdk = createTestSdk();
449
- const context = sdk.getContext();
450
- expect(context.meta.listActions).toBeDefined();
451
- expect(context.meta.listActions.inputSchema).toBeDefined();
452
- });
453
- });
454
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/listApps/index.test.ts"],"names":[],"mappings":""}
@@ -1,124 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from "vitest";
2
- import { ZapierValidationError } from "../../types/errors";
3
- import { listAppsPlugin } from "./index";
4
- import { createSdk } from "../../sdk";
5
- import { eventEmissionPlugin } from "../eventEmission";
6
- // Mock transport for testing - prevents real HTTP telemetry requests
7
- const mockTransport = {
8
- emit: vi.fn().mockResolvedValue(undefined),
9
- close: vi.fn().mockResolvedValue(undefined),
10
- };
11
- vi.mock("../eventEmission/transport", () => ({
12
- createTransport: vi.fn(() => mockTransport),
13
- }));
14
- // Mock CLI login packages - prevents real token resolution requests
15
- vi.mock("@zapier/zapier-sdk-cli/login", () => ({
16
- getToken: vi.fn().mockResolvedValue(undefined),
17
- }));
18
- vi.mock("@zapier/zapier-sdk-cli-login", () => ({
19
- getToken: vi.fn().mockResolvedValue(undefined),
20
- }));
21
- const mockResolveAppKeys = vi
22
- .fn()
23
- .mockImplementation(async ({ appKeys }) => {
24
- return appKeys.map((appKey) => ({
25
- lookupAppKey: appKey,
26
- implementationName: appKey,
27
- slug: appKey.toLowerCase(),
28
- version: undefined,
29
- }));
30
- });
31
- describe("listApps plugin", () => {
32
- let mockApiClient;
33
- beforeEach(() => {
34
- vi.clearAllMocks();
35
- mockApiClient = {
36
- get: vi.fn().mockResolvedValue({
37
- data: [
38
- {
39
- title: "Slack",
40
- key: "SlackCLIAPI",
41
- implementation_id: "SlackCLIAPI@1.0.0",
42
- version: "1.0.0",
43
- slug: "slack",
44
- description: "Team communication",
45
- primary_color: "#4A154B",
46
- },
47
- {
48
- title: "Google Sheets",
49
- key: "GoogleSheetsCLIAPI",
50
- implementation_id: "GoogleSheetsCLIAPI@1.0.0",
51
- version: "1.0.0",
52
- slug: "google-sheets",
53
- description: "Online spreadsheets",
54
- primary_color: "#34A853",
55
- },
56
- ],
57
- links: { next: null },
58
- meta: { count: 2, limit: 100, offset: 0 },
59
- }),
60
- };
61
- });
62
- const apiPlugin = () => ({
63
- context: {
64
- api: mockApiClient,
65
- },
66
- });
67
- function createTestSdk() {
68
- return createSdk()
69
- .addPlugin(() => ({
70
- context: {
71
- options: {},
72
- },
73
- }))
74
- .addPlugin(apiPlugin)
75
- .addPlugin(eventEmissionPlugin)
76
- .addPlugin(() => ({
77
- context: {
78
- resolveAppKeys: mockResolveAppKeys,
79
- },
80
- }))
81
- .addPlugin(listAppsPlugin);
82
- }
83
- describe("basic functionality", () => {
84
- it("should provide listApps method that returns apps", async () => {
85
- const sdk = createTestSdk();
86
- const result = await sdk.listApps({ pageSize: 2 });
87
- // Just verify the structure - handler tests verify correct data
88
- expect(result.data.length).toBeGreaterThan(0);
89
- expect(result.data[0]).toHaveProperty("title");
90
- expect(result.data[0]).toHaveProperty("key");
91
- expect(result.data[0]).toHaveProperty("implementation_id");
92
- expect(result.data[0]).toHaveProperty("version");
93
- });
94
- });
95
- describe("plugin integration", () => {
96
- it("should provide metadata in context for CLI introspection", () => {
97
- const sdk = createTestSdk();
98
- const context = sdk.getContext();
99
- expect(context.meta.listApps).toBeDefined();
100
- expect(context.meta.listApps.inputSchema).toBeDefined();
101
- });
102
- it("should integrate with resolveAppKeys", async () => {
103
- const sdk = createTestSdk();
104
- await sdk.listApps({ appKeys: ["SlackCLIAPI"] });
105
- // Verify resolveAppKeys was called with the provided appKeys
106
- expect(mockResolveAppKeys).toHaveBeenCalledWith(expect.objectContaining({
107
- appKeys: ["SlackCLIAPI"],
108
- }));
109
- });
110
- });
111
- describe("validation", () => {
112
- it("should throw validation error for invalid input", () => {
113
- const sdk = createTestSdk();
114
- // Invalid pageSize
115
- expect(() => {
116
- sdk.listApps({ pageSize: 0 });
117
- }).toThrow(ZapierValidationError);
118
- // Invalid appKeys type
119
- expect(() => {
120
- sdk.listApps({ appKeys: 123 });
121
- }).toThrow(ZapierValidationError);
122
- });
123
- });
124
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/plugins/listConnections/index.test.ts"],"names":[],"mappings":""}