@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,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
- });