@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,333 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from "vitest";
2
- import { ZapierValidationError } from "../../types/errors";
3
- import { requestPlugin } from "./index";
4
- import { createSdk } from "../../sdk";
5
- import type { RelayRequestOptions } from "./schemas";
6
- import type { ApiClient } from "../../api";
7
-
8
- describe("request plugin", () => {
9
- let mockApiClient: ApiClient;
10
- let mockFetch: any;
11
-
12
- beforeEach(() => {
13
- vi.clearAllMocks();
14
- mockFetch = vi.fn().mockResolvedValue(
15
- new Response('{"success": true}', {
16
- status: 200,
17
- headers: { "Content-Type": "application/json" },
18
- }),
19
- );
20
-
21
- mockApiClient = {
22
- fetch: mockFetch,
23
- } as Partial<ApiClient> as ApiClient;
24
- });
25
-
26
- const apiPlugin = () => ({
27
- context: {
28
- api: mockApiClient,
29
- },
30
- });
31
-
32
- function createTestSdk() {
33
- return createSdk().addPlugin(apiPlugin).addPlugin(requestPlugin);
34
- }
35
-
36
- describe("schema validation", () => {
37
- it("should throw validation error for missing url", async () => {
38
- const sdk = createTestSdk();
39
- await expect(sdk.request({} as RelayRequestOptions)).rejects.toThrow(
40
- ZapierValidationError,
41
- );
42
- });
43
-
44
- it("should throw validation error for invalid url", async () => {
45
- const sdk = createTestSdk();
46
- await expect(sdk.request({ url: "not-a-url" })).rejects.toThrow(
47
- ZapierValidationError,
48
- );
49
- });
50
-
51
- it("should throw validation error for invalid method", async () => {
52
- const sdk = createTestSdk();
53
- await expect(
54
- sdk.request({
55
- url: "https://api.example.com/data",
56
- method: "INVALID" as any,
57
- }),
58
- ).rejects.toThrow(ZapierValidationError);
59
- });
60
-
61
- it("should throw validation error for invalid authenticationId type", async () => {
62
- const sdk = createTestSdk();
63
- await expect(
64
- sdk.request({
65
- url: "https://api.example.com/data",
66
- authenticationId: "not-a-number" as any,
67
- }),
68
- ).rejects.toThrow(ZapierValidationError);
69
- });
70
-
71
- it("should throw validation error for invalid callbackUrl", async () => {
72
- const sdk = createTestSdk();
73
- await expect(
74
- sdk.request({
75
- url: "https://api.example.com/data",
76
- callbackUrl: "not-a-url",
77
- }),
78
- ).rejects.toThrow(ZapierValidationError);
79
- });
80
-
81
- it("should pass validation with valid minimal options", async () => {
82
- const sdk = createTestSdk();
83
- await sdk.request({ url: "https://api.example.com/data" });
84
-
85
- expect(mockFetch).toHaveBeenCalled();
86
- });
87
-
88
- it("should pass validation with all valid options", async () => {
89
- const sdk = createTestSdk();
90
- await sdk.request({
91
- url: "https://api.example.com/data",
92
- method: "POST",
93
- body: '{"test": true}',
94
- headers: { "Content-Type": "application/json" },
95
- authenticationId: 123,
96
- callbackUrl: "https://webhook.example.com/callback",
97
- authenticationTemplate: '{"token": "{{auth.token}}"}',
98
- });
99
-
100
- expect(mockFetch).toHaveBeenCalled();
101
- });
102
- });
103
-
104
- describe("URL transformation", () => {
105
- it("should transform full URLs to relay path format", async () => {
106
- const sdk = createTestSdk();
107
- await sdk.request({
108
- url: "https://api.github.com/user",
109
- method: "GET",
110
- });
111
-
112
- expect(mockFetch).toHaveBeenCalledWith(
113
- "/relay/api.github.com/user",
114
- expect.any(Object),
115
- );
116
- });
117
-
118
- it("should preserve query parameters and fragments", async () => {
119
- const sdk = createTestSdk();
120
- await sdk.request({
121
- url: "https://api.example.com/search?q=test&limit=10#section",
122
- method: "GET",
123
- });
124
-
125
- expect(mockFetch).toHaveBeenCalledWith(
126
- "/relay/api.example.com/search?q=test&limit=10#section",
127
- expect.any(Object),
128
- );
129
- });
130
-
131
- it("should handle URLs with ports", async () => {
132
- const sdk = createTestSdk();
133
- await sdk.request({
134
- url: "https://api.example.com:8443/data",
135
- method: "GET",
136
- });
137
-
138
- expect(mockFetch).toHaveBeenCalledWith(
139
- "/relay/api.example.com:8443/data",
140
- expect.any(Object),
141
- );
142
- });
143
- });
144
-
145
- describe("headers handling", () => {
146
- it("should pass through regular headers", async () => {
147
- const sdk = createTestSdk();
148
- const headers = {
149
- "Content-Type": "application/json",
150
- "X-Custom-Header": "test-value",
151
- };
152
-
153
- await sdk.request({
154
- url: "https://api.example.com/data",
155
- method: "POST",
156
- headers,
157
- });
158
-
159
- expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
160
- method: "POST",
161
- body: undefined,
162
- headers: {
163
- "Content-Type": "application/json",
164
- "X-Custom-Header": "test-value",
165
- },
166
- });
167
- });
168
-
169
- it("should add relay-specific headers when provided", async () => {
170
- const sdk = createTestSdk();
171
- await sdk.request({
172
- url: "https://api.example.com/data",
173
- method: "POST",
174
- authenticationId: 123,
175
- callbackUrl: "https://webhook.example.com/callback",
176
- authenticationTemplate: '{"token": "{{auth.token}}"}',
177
- });
178
-
179
- expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
180
- method: "POST",
181
- body: undefined,
182
- headers: {
183
- "X-Relay-Authentication-Id": "123",
184
- "X-Relay-Callback-Url": "https://webhook.example.com/callback",
185
- "X-Authentication-Template": '{"token": "{{auth.token}}"}',
186
- },
187
- });
188
- });
189
-
190
- it("should handle Headers object", async () => {
191
- const sdk = createTestSdk();
192
- const headers = new Headers();
193
- headers.set("Content-Type", "application/json");
194
- headers.set("Authorization", "Bearer token");
195
-
196
- await sdk.request({
197
- url: "https://api.example.com/data",
198
- headers,
199
- });
200
-
201
- expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
202
- method: "GET",
203
- body: undefined,
204
- headers: {
205
- "content-type": "application/json", // Headers constructor lowercases names
206
- authorization: "Bearer token", // Headers constructor lowercases names
207
- },
208
- });
209
- });
210
-
211
- it("should handle headers as array of tuples", async () => {
212
- const sdk = createTestSdk();
213
- const headers: [string, string][] = [
214
- ["Content-Type", "application/json"],
215
- ["X-Api-Key", "secret"],
216
- ];
217
-
218
- await sdk.request({
219
- url: "https://api.example.com/data",
220
- headers,
221
- });
222
-
223
- expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
224
- method: "GET",
225
- body: undefined,
226
- headers: {
227
- "Content-Type": "application/json",
228
- "X-Api-Key": "secret",
229
- },
230
- });
231
- });
232
- });
233
-
234
- describe("HTTP methods", () => {
235
- const methods = [
236
- "GET",
237
- "POST",
238
- "PUT",
239
- "DELETE",
240
- "PATCH",
241
- "HEAD",
242
- "OPTIONS",
243
- ] as const;
244
-
245
- methods.forEach((method) => {
246
- it(`should support ${method} method`, async () => {
247
- const sdk = createTestSdk();
248
- await sdk.request({
249
- url: "https://api.example.com/data",
250
- method,
251
- });
252
-
253
- expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
254
- method,
255
- body: undefined,
256
- headers: {},
257
- });
258
- });
259
- });
260
-
261
- it("should default to GET method", async () => {
262
- const sdk = createTestSdk();
263
- await sdk.request({
264
- url: "https://api.example.com/data",
265
- });
266
-
267
- expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
268
- method: "GET",
269
- body: undefined,
270
- headers: {},
271
- });
272
- });
273
- });
274
-
275
- describe("request body", () => {
276
- it("should pass through request body", async () => {
277
- const sdk = createTestSdk();
278
- const body = '{"name": "test", "value": 42}';
279
-
280
- await sdk.request({
281
- url: "https://api.example.com/data",
282
- method: "POST",
283
- body,
284
- });
285
-
286
- expect(mockFetch).toHaveBeenCalledWith("/relay/api.example.com/data", {
287
- method: "POST",
288
- body,
289
- headers: {},
290
- });
291
- });
292
- });
293
-
294
- describe("response handling", () => {
295
- it("should return the response from api.fetch", async () => {
296
- const mockResponse = new Response('{"result": "success"}', {
297
- status: 200,
298
- statusText: "OK",
299
- headers: { "Content-Type": "application/json" },
300
- });
301
-
302
- mockFetch.mockResolvedValue(mockResponse);
303
-
304
- const sdk = createTestSdk();
305
- const response = await sdk.request({
306
- url: "https://api.example.com/data",
307
- });
308
-
309
- expect(response).toBe(mockResponse);
310
- expect(response.status).toBe(200);
311
- });
312
-
313
- it("should handle API errors", async () => {
314
- const error = new Error("Network error");
315
- mockFetch.mockRejectedValue(error);
316
-
317
- const sdk = createTestSdk();
318
- await expect(
319
- sdk.request({ url: "https://api.example.com/data" }),
320
- ).rejects.toThrow("Network error");
321
- });
322
- });
323
-
324
- describe("context and metadata", () => {
325
- it("should provide context with meta information", () => {
326
- const sdk = createTestSdk();
327
- const context = sdk.getContext();
328
-
329
- expect((context.meta as any).request).toBeDefined();
330
- expect((context.meta as any).request.inputSchema).toBeDefined();
331
- });
332
- });
333
- });
@@ -1,105 +0,0 @@
1
- import type { Plugin } from "../../types/plugin";
2
- import type { ApiClient } from "../../api";
3
- import { RelayRequestSchema, type RelayRequestOptions } from "./schemas";
4
- import { createFunction } from "../../utils/function-utils";
5
-
6
- /**
7
- * Transforms full URLs into Relay format: /relay/{domain}/{path}
8
- *
9
- * @param url - The full URL to transform (e.g., "https://api.github.com/user")
10
- * @returns The relay path format (e.g., "/relay/api.github.com/user")
11
- */
12
- function transformUrlToRelayPath(url: string | URL): string {
13
- const targetUrl = new URL(url);
14
-
15
- // Build the Relay path: /relay/{host}{pathname}{search}{hash}
16
- // Use host instead of hostname to include port if present
17
- const relayPath = `/relay/${targetUrl.host}${targetUrl.pathname}${targetUrl.search}${targetUrl.hash}`;
18
-
19
- return relayPath;
20
- }
21
-
22
- export interface RequestPluginProvides {
23
- request: (options: RelayRequestOptions) => Promise<Response>;
24
- context: {
25
- meta: {
26
- request: {
27
- inputSchema: typeof RelayRequestSchema;
28
- };
29
- };
30
- };
31
- }
32
-
33
- export const requestPlugin: Plugin<
34
- {}, // no SDK dependencies
35
- { api: ApiClient }, // requires api in context
36
- RequestPluginProvides
37
- > = ({ context }) => {
38
- const request = createFunction(async function request(
39
- options: RelayRequestOptions,
40
- ): Promise<Response> {
41
- const { api } = context;
42
- const {
43
- url,
44
- method = "GET",
45
- body,
46
- headers: optionsHeaders,
47
- authenticationId,
48
- callbackUrl,
49
- authenticationTemplate,
50
- } = options;
51
-
52
- // Transform full URL to relay path format
53
- const relayPath = transformUrlToRelayPath(url);
54
-
55
- // Build headers for the request
56
- const headers: Record<string, string> = {};
57
-
58
- // Copy existing headers
59
- if (optionsHeaders) {
60
- const headerEntries =
61
- optionsHeaders instanceof Headers
62
- ? Array.from(optionsHeaders.entries())
63
- : Array.isArray(optionsHeaders)
64
- ? optionsHeaders
65
- : Object.entries(optionsHeaders);
66
-
67
- for (const [key, value] of headerEntries) {
68
- headers[key] = value;
69
- }
70
- }
71
-
72
- // Add Relay-specific headers
73
- if (authenticationId) {
74
- headers["X-Relay-Authentication-Id"] = authenticationId.toString();
75
- }
76
-
77
- if (callbackUrl) {
78
- headers["X-Relay-Callback-Url"] = callbackUrl;
79
- }
80
-
81
- if (authenticationTemplate) {
82
- headers["X-Authentication-Template"] = authenticationTemplate;
83
- }
84
-
85
- // Use the API client's fetch method directly - let it handle auth automatically
86
- return await api.fetch(relayPath, {
87
- method,
88
- body,
89
- headers,
90
- });
91
- }, RelayRequestSchema);
92
-
93
- return {
94
- request,
95
- context: {
96
- meta: {
97
- request: {
98
- categories: ["http"],
99
- returnType: "Response",
100
- inputSchema: RelayRequestSchema,
101
- },
102
- },
103
- },
104
- };
105
- };
@@ -1,69 +0,0 @@
1
- import { z } from "zod";
2
- import type {
3
- ZapierApiError,
4
- ZapierValidationError,
5
- ZapierUnknownError,
6
- } from "../../types/errors";
7
-
8
- // Pure Zod schema for the request function
9
- export const RelayRequestSchema = z
10
- .object({
11
- url: z
12
- .string()
13
- .url()
14
- .describe("The URL to request (will be proxied through Relay)"),
15
- method: z
16
- .enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"])
17
- .optional()
18
- .describe("HTTP method"),
19
- body: z.any().optional().describe("Request body as a string"),
20
- authenticationId: z
21
- .number()
22
- .int()
23
- .optional()
24
- .describe("Zapier authentication ID to use for the request"),
25
- callbackUrl: z
26
- .string()
27
- .url()
28
- .optional()
29
- .describe("URL to send async response to (makes request async)"),
30
- authenticationTemplate: z
31
- .string()
32
- .optional()
33
- .describe(
34
- "Optional JSON string authentication template to bypass Notary lookup",
35
- ),
36
- headers: z
37
- .union([
38
- z.record(z.string()),
39
- z.instanceof(Headers),
40
- z.array(z.tuple([z.string(), z.string()])),
41
- ])
42
- .optional()
43
- .describe("Request headers"),
44
- })
45
- .extend({
46
- relayBaseUrl: z.string().optional().describe("Base URL for Relay service"),
47
- })
48
- .describe("Make authenticated HTTP requests through Zapier's Relay service");
49
-
50
- // Type inferred from schema
51
- export type RelayRequestOptions = z.infer<typeof RelayRequestSchema>;
52
-
53
- // Error union for this function
54
- export type RelayRequestError =
55
- | ZapierApiError
56
- | ZapierValidationError
57
- | ZapierUnknownError;
58
-
59
- // SDK function interface
60
- export interface RelayRequestSdkFunction {
61
- request: (options: RelayRequestOptions) => Promise<Response>;
62
- }
63
-
64
- // Legacy exports for compatibility
65
- export const RelayFetchSchema = RelayRequestSchema;
66
- export type RelayFetchOptions = RelayRequestOptions;
67
- export interface RelayFetchSdkFunction {
68
- fetch: (options: RelayFetchOptions) => Promise<Response>;
69
- }