@zapier/zapier-sdk 0.13.6 → 0.13.8

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 (155) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/api/client.d.ts.map +1 -1
  3. package/dist/api/client.js +5 -5
  4. package/dist/api/client.test.d.ts +2 -0
  5. package/dist/api/client.test.d.ts.map +1 -0
  6. package/dist/api/client.test.js +80 -0
  7. package/dist/api/index.d.ts +1 -0
  8. package/dist/api/index.d.ts.map +1 -1
  9. package/dist/api/index.js +3 -1
  10. package/dist/api/schemas.d.ts +20 -20
  11. package/dist/api/types.d.ts +2 -0
  12. package/dist/api/types.d.ts.map +1 -1
  13. package/dist/auth.d.ts +3 -0
  14. package/dist/auth.d.ts.map +1 -1
  15. package/dist/auth.test.d.ts +2 -0
  16. package/dist/auth.test.d.ts.map +1 -0
  17. package/dist/auth.test.js +102 -0
  18. package/dist/constants.d.ts +4 -4
  19. package/dist/constants.d.ts.map +1 -1
  20. package/dist/constants.js +4 -4
  21. package/dist/index.cjs +89 -21
  22. package/dist/index.d.mts +21 -1
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +2 -0
  26. package/dist/index.mjs +88 -22
  27. package/dist/plugins/api/index.d.ts.map +1 -1
  28. package/dist/plugins/api/index.js +4 -1
  29. package/dist/plugins/eventEmission/index.d.ts +2 -0
  30. package/dist/plugins/eventEmission/index.d.ts.map +1 -1
  31. package/dist/plugins/eventEmission/index.js +35 -9
  32. package/dist/plugins/eventEmission/index.test.js +100 -0
  33. package/dist/schemas/Action.d.ts +2 -2
  34. package/dist/schemas/Auth.d.ts +4 -4
  35. package/dist/schemas/Field.d.ts +10 -10
  36. package/dist/sdk.test.js +121 -1
  37. package/dist/types/sdk.d.ts +3 -0
  38. package/dist/types/sdk.d.ts.map +1 -1
  39. package/dist/utils/url-utils.d.ts +19 -0
  40. package/dist/utils/url-utils.d.ts.map +1 -0
  41. package/dist/utils/url-utils.js +62 -0
  42. package/dist/utils/url-utils.test.d.ts +2 -0
  43. package/dist/utils/url-utils.test.d.ts.map +1 -0
  44. package/dist/utils/url-utils.test.js +103 -0
  45. package/package.json +8 -3
  46. package/src/api/auth.ts +0 -28
  47. package/src/api/client.ts +0 -491
  48. package/src/api/debug.test.ts +0 -76
  49. package/src/api/debug.ts +0 -154
  50. package/src/api/index.ts +0 -90
  51. package/src/api/polling.test.ts +0 -405
  52. package/src/api/polling.ts +0 -253
  53. package/src/api/schemas.ts +0 -465
  54. package/src/api/types.ts +0 -152
  55. package/src/auth.ts +0 -72
  56. package/src/constants.ts +0 -16
  57. package/src/index.ts +0 -111
  58. package/src/plugins/api/index.ts +0 -43
  59. package/src/plugins/apps/index.ts +0 -203
  60. package/src/plugins/apps/schemas.ts +0 -64
  61. package/src/plugins/eventEmission/builders.ts +0 -115
  62. package/src/plugins/eventEmission/index.test.ts +0 -169
  63. package/src/plugins/eventEmission/index.ts +0 -294
  64. package/src/plugins/eventEmission/transport.test.ts +0 -214
  65. package/src/plugins/eventEmission/transport.ts +0 -135
  66. package/src/plugins/eventEmission/types.ts +0 -58
  67. package/src/plugins/eventEmission/utils.ts +0 -121
  68. package/src/plugins/fetch/index.ts +0 -83
  69. package/src/plugins/fetch/schemas.ts +0 -37
  70. package/src/plugins/findFirstAuthentication/index.test.ts +0 -209
  71. package/src/plugins/findFirstAuthentication/index.ts +0 -68
  72. package/src/plugins/findFirstAuthentication/schemas.ts +0 -47
  73. package/src/plugins/findUniqueAuthentication/index.test.ts +0 -197
  74. package/src/plugins/findUniqueAuthentication/index.ts +0 -77
  75. package/src/plugins/findUniqueAuthentication/schemas.ts +0 -49
  76. package/src/plugins/getAction/index.test.ts +0 -239
  77. package/src/plugins/getAction/index.ts +0 -75
  78. package/src/plugins/getAction/schemas.ts +0 -41
  79. package/src/plugins/getApp/index.test.ts +0 -181
  80. package/src/plugins/getApp/index.ts +0 -60
  81. package/src/plugins/getApp/schemas.ts +0 -33
  82. package/src/plugins/getAuthentication/index.test.ts +0 -294
  83. package/src/plugins/getAuthentication/index.ts +0 -95
  84. package/src/plugins/getAuthentication/schemas.ts +0 -38
  85. package/src/plugins/getProfile/index.ts +0 -60
  86. package/src/plugins/getProfile/schemas.ts +0 -24
  87. package/src/plugins/listActions/index.test.ts +0 -526
  88. package/src/plugins/listActions/index.ts +0 -132
  89. package/src/plugins/listActions/schemas.ts +0 -55
  90. package/src/plugins/listApps/index.test.ts +0 -378
  91. package/src/plugins/listApps/index.ts +0 -159
  92. package/src/plugins/listApps/schemas.ts +0 -41
  93. package/src/plugins/listAuthentications/index.test.ts +0 -739
  94. package/src/plugins/listAuthentications/index.ts +0 -152
  95. package/src/plugins/listAuthentications/schemas.ts +0 -77
  96. package/src/plugins/listInputFieldChoices/index.test.ts +0 -653
  97. package/src/plugins/listInputFieldChoices/index.ts +0 -173
  98. package/src/plugins/listInputFieldChoices/schemas.ts +0 -125
  99. package/src/plugins/listInputFields/index.test.ts +0 -439
  100. package/src/plugins/listInputFields/index.ts +0 -294
  101. package/src/plugins/listInputFields/schemas.ts +0 -68
  102. package/src/plugins/manifest/index.test.ts +0 -776
  103. package/src/plugins/manifest/index.ts +0 -461
  104. package/src/plugins/manifest/schemas.ts +0 -60
  105. package/src/plugins/registry/index.ts +0 -160
  106. package/src/plugins/request/index.test.ts +0 -333
  107. package/src/plugins/request/index.ts +0 -105
  108. package/src/plugins/request/schemas.ts +0 -69
  109. package/src/plugins/runAction/index.test.ts +0 -388
  110. package/src/plugins/runAction/index.ts +0 -215
  111. package/src/plugins/runAction/schemas.ts +0 -60
  112. package/src/resolvers/actionKey.ts +0 -37
  113. package/src/resolvers/actionType.ts +0 -34
  114. package/src/resolvers/appKey.ts +0 -7
  115. package/src/resolvers/authenticationId.ts +0 -54
  116. package/src/resolvers/index.ts +0 -11
  117. package/src/resolvers/inputFieldKey.ts +0 -70
  118. package/src/resolvers/inputs.ts +0 -69
  119. package/src/schemas/Action.ts +0 -52
  120. package/src/schemas/App.ts +0 -45
  121. package/src/schemas/Auth.ts +0 -59
  122. package/src/schemas/Field.ts +0 -169
  123. package/src/schemas/Run.ts +0 -40
  124. package/src/schemas/UserProfile.ts +0 -60
  125. package/src/sdk.test.ts +0 -212
  126. package/src/sdk.ts +0 -178
  127. package/src/types/domain.test.ts +0 -50
  128. package/src/types/domain.ts +0 -66
  129. package/src/types/errors.ts +0 -278
  130. package/src/types/events.ts +0 -43
  131. package/src/types/functions.ts +0 -28
  132. package/src/types/optional-zapier-sdk-cli-login.d.ts +0 -37
  133. package/src/types/plugin.ts +0 -125
  134. package/src/types/properties.ts +0 -80
  135. package/src/types/sdk.ts +0 -111
  136. package/src/types/telemetry-events.ts +0 -85
  137. package/src/utils/array-utils.test.ts +0 -131
  138. package/src/utils/array-utils.ts +0 -41
  139. package/src/utils/domain-utils.test.ts +0 -433
  140. package/src/utils/domain-utils.ts +0 -267
  141. package/src/utils/file-utils.test.ts +0 -73
  142. package/src/utils/file-utils.ts +0 -94
  143. package/src/utils/function-utils.test.ts +0 -141
  144. package/src/utils/function-utils.ts +0 -245
  145. package/src/utils/pagination-utils.test.ts +0 -620
  146. package/src/utils/pagination-utils.ts +0 -242
  147. package/src/utils/schema-utils.ts +0 -207
  148. package/src/utils/string-utils.test.ts +0 -45
  149. package/src/utils/string-utils.ts +0 -54
  150. package/src/utils/validation.test.ts +0 -51
  151. package/src/utils/validation.ts +0 -44
  152. package/tsconfig.build.json +0 -18
  153. package/tsconfig.json +0 -20
  154. package/tsconfig.tsbuildinfo +0 -1
  155. package/tsup.config.ts +0 -23
@@ -1,439 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from "vitest";
2
- import {
3
- ZapierValidationError,
4
- ZapierConfigurationError,
5
- ZapierApiError,
6
- } from "../../types/errors";
7
- import { listInputFieldsPlugin } from "./index";
8
- import { getActionPlugin } from "../getAction";
9
- import { getAppPlugin } from "../getApp";
10
- import { listActionsPlugin } from "../listActions";
11
- import { listAppsPlugin } from "../listApps";
12
- import { createSdk } from "../../sdk";
13
- import type { ApiClient } from "../../api";
14
- import type { ListInputFieldsOptions } from "./schemas";
15
- import type { NeedsResponse, Need } from "../../api/types";
16
-
17
- const mockNeeds: Need[] = [
18
- {
19
- key: "message",
20
- label: "Message",
21
- help_text: "The message to send",
22
- required: true,
23
- type: "string",
24
- placeholder: "Enter your message",
25
- default: "",
26
- },
27
- {
28
- key: "channel",
29
- label: "Channel",
30
- help_text: "The channel to send to",
31
- required: true,
32
- type: "string",
33
- choices: [
34
- { value: "#general", label: "General", sample: "#general" },
35
- { value: "#random", label: "Random", sample: "#random" },
36
- ],
37
- },
38
- {
39
- key: "tags",
40
- label: "Tags",
41
- help_text: "List of tags",
42
- type: "string",
43
- list: true,
44
- },
45
- ];
46
-
47
- const mockNeedsResponse: NeedsResponse = {
48
- success: true,
49
- needs: mockNeeds,
50
- };
51
-
52
- const mockActionsResponse = {
53
- results: [
54
- {
55
- slug: "slack",
56
- selected_api: "slack",
57
- actions: [
58
- {
59
- key: "send_message",
60
- name: "Send Message",
61
- description: "Send a message to a channel",
62
- type_of: "write",
63
- type: "write",
64
- id: "core:12345",
65
- },
66
- ],
67
- },
68
- ],
69
- meta: {
70
- next_cursor: null,
71
- },
72
- };
73
-
74
- describe("listInputFields plugin", () => {
75
- let mockApiClient: ApiClient;
76
- let mockGetVersionedImplementationId: any;
77
-
78
- beforeEach(() => {
79
- vi.clearAllMocks();
80
- mockApiClient = {
81
- get: vi.fn().mockResolvedValue(mockActionsResponse),
82
- post: vi.fn().mockResolvedValue(mockNeedsResponse),
83
- } as Partial<ApiClient> as ApiClient;
84
-
85
- mockGetVersionedImplementationId = vi
86
- .fn()
87
- .mockResolvedValue("SlackCLIAPI@1.21.1");
88
- });
89
-
90
- function createTestSdk() {
91
- return createSdk(
92
- {},
93
- {},
94
- {
95
- api: mockApiClient,
96
- meta: {},
97
- getVersionedImplementationId: mockGetVersionedImplementationId,
98
- },
99
- )
100
- .addPlugin(listAppsPlugin as any)
101
- .addPlugin(listActionsPlugin as any)
102
- .addPlugin(getAppPlugin as any)
103
- .addPlugin(getActionPlugin as any)
104
- .addPlugin(listInputFieldsPlugin as any);
105
- }
106
-
107
- describe("schema validation", () => {
108
- it("should throw validation error for missing required fields", () => {
109
- const sdk = createTestSdk();
110
- expect(() => {
111
- sdk.listInputFields({
112
- // Missing required fields
113
- } as ListInputFieldsOptions);
114
- }).toThrow(ZapierValidationError);
115
- });
116
-
117
- it("should throw validation error for invalid field types", () => {
118
- const sdk = createTestSdk();
119
- expect(() => {
120
- sdk.listInputFields({
121
- appKey: 123 as any,
122
- actionType: "write",
123
- actionKey: "send_message",
124
- });
125
- }).toThrow(ZapierValidationError);
126
- });
127
-
128
- it("should pass validation with all required fields", async () => {
129
- const sdk = createTestSdk();
130
- const result = await sdk.listInputFields({
131
- appKey: "slack",
132
- actionType: "write",
133
- actionKey: "send_message",
134
- });
135
-
136
- expect(result.data).toBeDefined();
137
- });
138
-
139
- it("should pass validation with optional fields", async () => {
140
- const sdk = createTestSdk();
141
- const result = await sdk.listInputFields({
142
- appKey: "slack",
143
- actionType: "write",
144
- actionKey: "send_message",
145
- authenticationId: 123,
146
- inputs: { channel: "#general" },
147
- });
148
-
149
- expect(result.data).toBeDefined();
150
- });
151
- });
152
-
153
- describe("API integration", () => {
154
- it("should call the correct API endpoint", async () => {
155
- const sdk = createTestSdk();
156
- await sdk.listInputFields({
157
- appKey: "slack",
158
- actionType: "write",
159
- actionKey: "send_message",
160
- });
161
-
162
- expect(mockApiClient.post).toHaveBeenCalledWith(
163
- "/api/v4/implementations/needs/",
164
- {
165
- selected_api: "SlackCLIAPI@1.21.1",
166
- action: "send_message",
167
- type_of: "write",
168
- params: {},
169
- },
170
- );
171
- });
172
-
173
- it("should include authentication_id when provided", async () => {
174
- const sdk = createTestSdk();
175
- await sdk.listInputFields({
176
- appKey: "slack",
177
- actionType: "write",
178
- actionKey: "send_message",
179
- authenticationId: 123,
180
- });
181
-
182
- expect(mockApiClient.post).toHaveBeenCalledWith(
183
- "/api/v4/implementations/needs/",
184
- {
185
- selected_api: "SlackCLIAPI@1.21.1",
186
- action: "send_message",
187
- type_of: "write",
188
- params: {},
189
- authentication_id: 123,
190
- },
191
- );
192
- });
193
-
194
- it("should exclude authentication_id when null", async () => {
195
- const sdk = createTestSdk();
196
- await sdk.listInputFields({
197
- appKey: "slack",
198
- actionType: "write",
199
- actionKey: "send_message",
200
- authenticationId: null,
201
- });
202
-
203
- expect(mockApiClient.post).toHaveBeenCalledWith(
204
- "/api/v4/implementations/needs/",
205
- {
206
- selected_api: "SlackCLIAPI@1.21.1",
207
- action: "send_message",
208
- type_of: "write",
209
- params: {},
210
- // No authentication_id
211
- },
212
- );
213
- });
214
-
215
- it("should include inputs when provided", async () => {
216
- const sdk = createTestSdk();
217
- const inputs = { channel: "#general", message: "test" };
218
-
219
- await sdk.listInputFields({
220
- appKey: "slack",
221
- actionType: "write",
222
- actionKey: "send_message",
223
- inputs,
224
- });
225
-
226
- expect(mockApiClient.post).toHaveBeenCalledWith(
227
- "/api/v4/implementations/needs/",
228
- {
229
- selected_api: "SlackCLIAPI@1.21.1",
230
- action: "send_message",
231
- type_of: "write",
232
- params: inputs,
233
- },
234
- );
235
- });
236
- });
237
-
238
- describe("data transformation", () => {
239
- it("should transform needs to input field items correctly", async () => {
240
- const sdk = createTestSdk();
241
- const result = await sdk.listInputFields({
242
- appKey: "slack",
243
- actionType: "write",
244
- actionKey: "send_message",
245
- });
246
-
247
- expect(result.data).toHaveLength(3);
248
-
249
- // Check message field transformation
250
- expect(result.data[0]).toEqual(
251
- expect.objectContaining({
252
- key: "message",
253
- title: "Message",
254
- description: "The message to send",
255
- is_required: true,
256
- value_type: "STRING",
257
- placeholder: "Enter your message",
258
- default_value: "",
259
- }),
260
- );
261
-
262
- // Check channel field with SELECT format
263
- expect(result.data[1]).toEqual(
264
- expect.objectContaining({
265
- key: "channel",
266
- title: "Channel",
267
- description: "The channel to send to",
268
- is_required: true,
269
- value_type: "STRING",
270
- format: "SELECT",
271
- }),
272
- );
273
-
274
- // Check array field
275
- expect(result.data[2]).toEqual(
276
- expect.objectContaining({
277
- key: "tags",
278
- title: "Tags",
279
- description: "List of tags",
280
- value_type: "ARRAY",
281
- items: { type: "STRING" },
282
- }),
283
- );
284
- });
285
-
286
- it("should handle different field types correctly", async () => {
287
- const complexNeeds: Need[] = [
288
- {
289
- key: "count",
290
- type: "integer",
291
- label: "Count",
292
- required: false,
293
- },
294
- {
295
- key: "price",
296
- type: "decimal",
297
- label: "Price",
298
- },
299
- {
300
- key: "enabled",
301
- type: "boolean",
302
- label: "Enabled",
303
- },
304
- {
305
- key: "config",
306
- type: "dict",
307
- label: "Configuration",
308
- },
309
- {
310
- key: "description",
311
- type: "text",
312
- label: "Description",
313
- },
314
- ];
315
-
316
- mockApiClient.post = vi.fn().mockResolvedValue({
317
- success: true,
318
- needs: complexNeeds,
319
- });
320
-
321
- const sdk = createTestSdk();
322
- const result = await sdk.listInputFields({
323
- appKey: "slack",
324
- actionType: "write",
325
- actionKey: "send_message",
326
- });
327
-
328
- expect(result.data[0].value_type).toBe("INTEGER");
329
- expect(result.data[1].value_type).toBe("NUMBER");
330
- expect(result.data[2].value_type).toBe("BOOLEAN");
331
- expect(result.data[3].value_type).toBe("OBJECT");
332
- expect(result.data[4].value_type).toBe("STRING");
333
- expect(result.data[4].format).toBe("MULTILINE");
334
- });
335
- });
336
-
337
- describe("error handling", () => {
338
- it("should throw ZapierConfigurationError when app has no current_implementation_id", async () => {
339
- mockGetVersionedImplementationId.mockResolvedValue(null);
340
-
341
- const sdk = createTestSdk();
342
- await expect(
343
- sdk.listInputFields({
344
- appKey: "invalid",
345
- actionType: "write",
346
- actionKey: "send_message",
347
- }),
348
- ).rejects.toThrow(ZapierConfigurationError);
349
- });
350
-
351
- it("should throw ZapierApiError when API response indicates failure", async () => {
352
- mockApiClient.post = vi.fn().mockResolvedValue({
353
- success: false,
354
- errors: ["Authentication failed", "Invalid credentials"],
355
- });
356
-
357
- const sdk = createTestSdk();
358
- await expect(
359
- sdk.listInputFields({
360
- appKey: "slack",
361
- actionType: "write",
362
- actionKey: "send_message", // Use valid action so we get to the POST call
363
- }),
364
- ).rejects.toThrow(ZapierApiError);
365
-
366
- await expect(
367
- sdk.listInputFields({
368
- appKey: "slack",
369
- actionType: "write",
370
- actionKey: "send_message", // Use valid action so we get to the POST call
371
- }),
372
- ).rejects.toThrow(
373
- "Failed to get action fields: Authentication failed, Invalid credentials",
374
- );
375
- });
376
-
377
- it("should handle API errors gracefully", async () => {
378
- mockApiClient.post = vi
379
- .fn()
380
- .mockRejectedValue(new Error("Network error"));
381
-
382
- const sdk = createTestSdk();
383
- await expect(
384
- sdk.listInputFields({
385
- appKey: "slack",
386
- actionType: "write",
387
- actionKey: "send_message",
388
- }),
389
- ).rejects.toThrow("Network error");
390
- });
391
- });
392
-
393
- describe("context and metadata", () => {
394
- it("should provide context with meta information", () => {
395
- const sdk = createTestSdk();
396
- const context = sdk.getContext();
397
-
398
- expect((context.meta as any).listInputFields).toBeDefined();
399
- expect((context.meta as any).listInputFields.inputSchema).toBeDefined();
400
- });
401
- });
402
-
403
- describe("pagination", () => {
404
- it("should support async iteration over pages", async () => {
405
- const sdk = createTestSdk();
406
- const listInputFieldsResult = sdk.listInputFields({
407
- appKey: "slack",
408
- actionType: "write",
409
- actionKey: "send_message",
410
- });
411
-
412
- const pages = [];
413
- for await (const page of listInputFieldsResult) {
414
- pages.push(page);
415
- break; // Just get first page for testing
416
- }
417
-
418
- expect(pages).toHaveLength(1);
419
- expect(pages[0].data).toHaveLength(3);
420
- });
421
-
422
- it("should support async iteration over individual items", async () => {
423
- const sdk = createTestSdk();
424
- const listInputFieldsResult = sdk.listInputFields({
425
- appKey: "slack",
426
- actionType: "write",
427
- actionKey: "send_message",
428
- });
429
-
430
- const items = [];
431
- for await (const item of listInputFieldsResult.items()) {
432
- items.push(item);
433
- }
434
-
435
- expect(items).toHaveLength(3);
436
- expect(items[0].key).toBe("message");
437
- });
438
- });
439
- });