@zapier/zapier-sdk 0.3.1 → 0.4.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 (162) hide show
  1. package/dist/index.cjs +1962 -0
  2. package/dist/index.d.mts +892 -0
  3. package/dist/index.d.ts +892 -20
  4. package/dist/index.mjs +1914 -0
  5. package/package.json +19 -7
  6. package/src/api/client.ts +106 -25
  7. package/src/api/polling.ts +4 -8
  8. package/src/api/types.ts +8 -1
  9. package/src/auth.ts +19 -287
  10. package/src/functions/findFirstAuthentication/schemas.ts +3 -13
  11. package/src/functions/findUniqueAuthentication/schemas.ts +3 -13
  12. package/src/functions/generateTypes/index.ts +15 -0
  13. package/src/functions/generateTypes/schemas.ts +3 -10
  14. package/src/functions/getAction/schemas.ts +3 -13
  15. package/src/functions/getApp/schemas.ts +2 -13
  16. package/src/functions/getAuthentication/index.ts +0 -1
  17. package/src/functions/getAuthentication/schemas.ts +3 -17
  18. package/src/functions/listActions/schemas.ts +3 -13
  19. package/src/functions/listApps/schemas.ts +2 -13
  20. package/src/functions/listAuthentications/index.ts +0 -1
  21. package/src/functions/listAuthentications/schemas.ts +3 -15
  22. package/src/functions/listFields/schemas.ts +3 -13
  23. package/src/functions/request/index.ts +150 -0
  24. package/src/functions/request/info.ts +11 -0
  25. package/src/functions/request/schemas.ts +53 -0
  26. package/src/functions/runAction/index.ts +0 -1
  27. package/src/functions/runAction/schemas.ts +6 -15
  28. package/src/index.ts +8 -2
  29. package/src/plugins/apps/index.ts +34 -9
  30. package/src/plugins/apps/types.ts +17 -1
  31. package/src/plugins/fetch/index.ts +50 -0
  32. package/src/plugins/fetch/types.ts +2 -0
  33. package/src/sdk.ts +19 -23
  34. package/src/types/domain.ts +16 -0
  35. package/src/types/sdk.ts +17 -2
  36. package/tsconfig.json +2 -2
  37. package/tsup.config.ts +21 -0
  38. package/dist/api/auth.d.ts +0 -8
  39. package/dist/api/auth.js +0 -29
  40. package/dist/api/client.d.ts +0 -8
  41. package/dist/api/client.js +0 -119
  42. package/dist/api/debug.d.ts +0 -12
  43. package/dist/api/debug.js +0 -50
  44. package/dist/api/index.d.ts +0 -28
  45. package/dist/api/index.js +0 -52
  46. package/dist/api/polling.d.ts +0 -17
  47. package/dist/api/polling.js +0 -34
  48. package/dist/api/types.d.ts +0 -147
  49. package/dist/api/types.js +0 -9
  50. package/dist/auth.d.ts +0 -59
  51. package/dist/auth.js +0 -261
  52. package/dist/functions/bundleCode/index.d.ts +0 -11
  53. package/dist/functions/bundleCode/index.js +0 -91
  54. package/dist/functions/bundleCode/info.d.ts +0 -27
  55. package/dist/functions/bundleCode/info.js +0 -11
  56. package/dist/functions/bundleCode/schemas.d.ts +0 -27
  57. package/dist/functions/bundleCode/schemas.js +0 -22
  58. package/dist/functions/findFirstAuthentication/index.d.ts +0 -12
  59. package/dist/functions/findFirstAuthentication/index.js +0 -21
  60. package/dist/functions/findFirstAuthentication/info.d.ts +0 -30
  61. package/dist/functions/findFirstAuthentication/info.js +0 -11
  62. package/dist/functions/findFirstAuthentication/schemas.d.ts +0 -42
  63. package/dist/functions/findFirstAuthentication/schemas.js +0 -25
  64. package/dist/functions/findUniqueAuthentication/index.d.ts +0 -13
  65. package/dist/functions/findUniqueAuthentication/index.js +0 -28
  66. package/dist/functions/findUniqueAuthentication/info.d.ts +0 -30
  67. package/dist/functions/findUniqueAuthentication/info.js +0 -11
  68. package/dist/functions/findUniqueAuthentication/schemas.d.ts +0 -42
  69. package/dist/functions/findUniqueAuthentication/schemas.js +0 -25
  70. package/dist/functions/generateTypes/index.d.ts +0 -11
  71. package/dist/functions/generateTypes/index.js +0 -305
  72. package/dist/functions/generateTypes/info.d.ts +0 -21
  73. package/dist/functions/generateTypes/info.js +0 -11
  74. package/dist/functions/generateTypes/schemas.d.ts +0 -30
  75. package/dist/functions/generateTypes/schemas.js +0 -14
  76. package/dist/functions/getAction/index.d.ts +0 -12
  77. package/dist/functions/getAction/index.js +0 -26
  78. package/dist/functions/getAction/info.d.ts +0 -18
  79. package/dist/functions/getAction/info.js +0 -11
  80. package/dist/functions/getAction/schemas.d.ts +0 -30
  81. package/dist/functions/getAction/schemas.js +0 -13
  82. package/dist/functions/getApp/index.d.ts +0 -12
  83. package/dist/functions/getApp/index.js +0 -37
  84. package/dist/functions/getApp/info.d.ts +0 -12
  85. package/dist/functions/getApp/info.js +0 -11
  86. package/dist/functions/getApp/schemas.d.ts +0 -24
  87. package/dist/functions/getApp/schemas.js +0 -11
  88. package/dist/functions/getAuthentication/index.d.ts +0 -13
  89. package/dist/functions/getAuthentication/index.js +0 -38
  90. package/dist/functions/getAuthentication/info.d.ts +0 -12
  91. package/dist/functions/getAuthentication/info.js +0 -11
  92. package/dist/functions/getAuthentication/schemas.d.ts +0 -26
  93. package/dist/functions/getAuthentication/schemas.js +0 -16
  94. package/dist/functions/listActions/index.d.ts +0 -12
  95. package/dist/functions/listActions/index.js +0 -128
  96. package/dist/functions/listActions/info.d.ts +0 -15
  97. package/dist/functions/listActions/info.js +0 -11
  98. package/dist/functions/listActions/schemas.d.ts +0 -27
  99. package/dist/functions/listActions/schemas.js +0 -14
  100. package/dist/functions/listApps/index.d.ts +0 -12
  101. package/dist/functions/listApps/index.js +0 -50
  102. package/dist/functions/listApps/info.d.ts +0 -18
  103. package/dist/functions/listApps/info.js +0 -11
  104. package/dist/functions/listApps/schemas.d.ts +0 -30
  105. package/dist/functions/listApps/schemas.js +0 -15
  106. package/dist/functions/listAuthentications/index.d.ts +0 -12
  107. package/dist/functions/listAuthentications/index.js +0 -131
  108. package/dist/functions/listAuthentications/info.d.ts +0 -30
  109. package/dist/functions/listAuthentications/info.js +0 -11
  110. package/dist/functions/listAuthentications/schemas.d.ts +0 -44
  111. package/dist/functions/listAuthentications/schemas.js +0 -25
  112. package/dist/functions/listFields/index.d.ts +0 -12
  113. package/dist/functions/listFields/index.js +0 -65
  114. package/dist/functions/listFields/info.d.ts +0 -24
  115. package/dist/functions/listFields/info.js +0 -11
  116. package/dist/functions/listFields/schemas.d.ts +0 -36
  117. package/dist/functions/listFields/schemas.js +0 -17
  118. package/dist/functions/runAction/index.d.ts +0 -12
  119. package/dist/functions/runAction/index.js +0 -86
  120. package/dist/functions/runAction/info.d.ts +0 -24
  121. package/dist/functions/runAction/info.js +0 -11
  122. package/dist/functions/runAction/schemas.d.ts +0 -38
  123. package/dist/functions/runAction/schemas.js +0 -15
  124. package/dist/index.js +0 -57
  125. package/dist/plugins/apps/index.d.ts +0 -8
  126. package/dist/plugins/apps/index.js +0 -77
  127. package/dist/plugins/apps/info.d.ts +0 -6
  128. package/dist/plugins/apps/info.js +0 -13
  129. package/dist/plugins/apps/types.d.ts +0 -21
  130. package/dist/plugins/apps/types.js +0 -2
  131. package/dist/resolvers/actionKey.d.ts +0 -8
  132. package/dist/resolvers/actionKey.js +0 -20
  133. package/dist/resolvers/actionType.d.ts +0 -8
  134. package/dist/resolvers/actionType.js +0 -21
  135. package/dist/resolvers/appKey.d.ts +0 -6
  136. package/dist/resolvers/appKey.js +0 -8
  137. package/dist/resolvers/authenticationId.d.ts +0 -8
  138. package/dist/resolvers/authenticationId.js +0 -29
  139. package/dist/resolvers/index.d.ts +0 -39
  140. package/dist/resolvers/index.js +0 -105
  141. package/dist/resolvers/inputs.d.ts +0 -7
  142. package/dist/resolvers/inputs.js +0 -15
  143. package/dist/schema-utils.d.ts +0 -44
  144. package/dist/schema-utils.js +0 -76
  145. package/dist/schemas/Action.d.ts +0 -21
  146. package/dist/schemas/Action.js +0 -31
  147. package/dist/schemas/App.d.ts +0 -19
  148. package/dist/schemas/App.js +0 -32
  149. package/dist/schemas/Auth.d.ts +0 -27
  150. package/dist/schemas/Auth.js +0 -42
  151. package/dist/schemas/Field.d.ts +0 -15
  152. package/dist/schemas/Field.js +0 -25
  153. package/dist/sdk.d.ts +0 -6
  154. package/dist/sdk.js +0 -90
  155. package/dist/types/domain.d.ts +0 -25
  156. package/dist/types/domain.js +0 -21
  157. package/dist/types/events.d.ts +0 -37
  158. package/dist/types/events.js +0 -8
  159. package/dist/types/properties.d.ts +0 -21
  160. package/dist/types/properties.js +0 -52
  161. package/dist/types/sdk.d.ts +0 -24
  162. package/dist/types/sdk.js +0 -2
@@ -6,7 +6,7 @@ import {
6
6
  } from "../../types/properties";
7
7
  import { withOutputSchema } from "../../schema-utils";
8
8
  import { AuthItemSchema } from "../../schemas/Auth";
9
- import type { Authentication } from "../../types/domain";
9
+ import type { Authentication, FunctionOptions } from "../../types/domain";
10
10
 
11
11
  // Pure Zod schema - no resolver metadata!
12
12
  export const FindFirstAuthenticationSchema = withOutputSchema(
@@ -39,18 +39,8 @@ export const FindFirstAuthenticationSchema = withOutputSchema(
39
39
  // Type inferred from schema + function config
40
40
  export type FindFirstAuthenticationOptions = z.infer<
41
41
  typeof FindFirstAuthenticationSchema
42
- > & {
43
- /** Base URL for Zapier API */
44
- baseUrl?: string;
45
- /** Authentication token */
46
- token?: string;
47
- /** Optional pre-instantiated API client */
48
- api?: any;
49
- /** Enable debug logging */
50
- debug?: boolean;
51
- /** Custom fetch implementation */
52
- fetch?: typeof globalThis.fetch;
53
- };
42
+ > &
43
+ FunctionOptions;
54
44
 
55
45
  // SDK function interface - ready to be mixed into main SDK interface
56
46
  export interface FindFirstAuthenticationSdkFunction {
@@ -6,7 +6,7 @@ import {
6
6
  } from "../../types/properties";
7
7
  import { withOutputSchema } from "../../schema-utils";
8
8
  import { AuthItemSchema } from "../../schemas/Auth";
9
- import type { Authentication } from "../../types/domain";
9
+ import type { Authentication, FunctionOptions } from "../../types/domain";
10
10
 
11
11
  // Pure Zod schema - no resolver metadata!
12
12
  export const FindUniqueAuthenticationSchema = withOutputSchema(
@@ -39,18 +39,8 @@ export const FindUniqueAuthenticationSchema = withOutputSchema(
39
39
  // Type inferred from schema + function config
40
40
  export type FindUniqueAuthenticationOptions = z.infer<
41
41
  typeof FindUniqueAuthenticationSchema
42
- > & {
43
- /** Base URL for Zapier API */
44
- baseUrl?: string;
45
- /** Authentication token */
46
- token?: string;
47
- /** Optional pre-instantiated API client */
48
- api?: any;
49
- /** Enable debug logging */
50
- debug?: boolean;
51
- /** Custom fetch implementation */
52
- fetch?: typeof globalThis.fetch;
53
- };
42
+ > &
43
+ FunctionOptions;
54
44
 
55
45
  // SDK function interface - ready to be mixed into main SDK interface
56
46
  export interface FindUniqueAuthenticationSdkFunction {
@@ -7,6 +7,14 @@ interface ActionWithActionFields extends Omit<Action, "inputFields"> {
7
7
  inputFields: ActionField[];
8
8
  }
9
9
 
10
+ /**
11
+ * Generate the fetch method signature for app proxies
12
+ */
13
+ function generateFetchMethodSignature(): string {
14
+ return ` /** Make authenticated HTTP requests through Zapier's Relay service */
15
+ fetch: (options: Omit<z.infer<typeof RelayFetchSchema>, 'authenticationId'>) => Promise<Response>`;
16
+ }
17
+
10
18
  /**
11
19
  * Generate TypeScript types for a specific app
12
20
  *
@@ -148,6 +156,8 @@ ${versionComment}
148
156
  */
149
157
 
150
158
  import type { ActionExecutionOptions, ActionExecutionResult } from '@zapier/zapier-sdk'
159
+ import { z } from 'zod'
160
+ import { RelayFetchSchema } from '@zapier/zapier-sdk'
151
161
 
152
162
  `;
153
163
 
@@ -211,6 +221,8 @@ import type { ActionExecutionOptions, ActionExecutionResult } from '@zapier/zapi
211
221
  const typeName = `${appName}${capitalize(actionType)}Actions`;
212
222
  output += ` ${actionType}: ${typeName}\n`;
213
223
  });
224
+ // Always include fetch method for authenticated HTTP requests
225
+ output += generateFetchMethodSignature() + "\n";
214
226
  output += `}\n\n`;
215
227
 
216
228
  // Generate the factory function interface
@@ -247,9 +259,12 @@ ${versionComment}
247
259
  */
248
260
 
249
261
  import type { ActionExecutionOptions, ActionExecutionResult } from '@zapier/zapier-sdk'
262
+ import { z } from 'zod'
263
+ import { RelayFetchSchema } from '@zapier/zapier-sdk'
250
264
 
251
265
  interface ${appName}AppProxy {
252
266
  // No actions available
267
+ ${generateFetchMethodSignature()}
253
268
  }
254
269
 
255
270
  interface ${appName}AppFactory {
@@ -5,6 +5,7 @@ import {
5
5
  OutputPropertySchema,
6
6
  DebugPropertySchema,
7
7
  } from "../../types/properties";
8
+ import type { FunctionOptions } from "../../types/domain";
8
9
 
9
10
  // Pure Zod schema - no resolver metadata!
10
11
  export const GenerateTypesSchema = z
@@ -21,16 +22,8 @@ export const GenerateTypesSchema = z
21
22
  .describe("Generate TypeScript SDK code for a specific app");
22
23
 
23
24
  // Type inferred from schema + function config
24
- export type GenerateTypesOptions = z.infer<typeof GenerateTypesSchema> & {
25
- /** Base URL for Zapier API */
26
- baseUrl?: string;
27
- /** Authentication token */
28
- token?: string;
29
- /** Optional pre-instantiated API client */
30
- api?: any;
31
- /** Custom fetch implementation */
32
- fetch?: typeof globalThis.fetch;
33
- };
25
+ export type GenerateTypesOptions = z.infer<typeof GenerateTypesSchema> &
26
+ FunctionOptions;
34
27
 
35
28
  // SDK function interface - ready to be mixed into main SDK interface
36
29
  export interface GenerateTypesSdkFunction {
@@ -4,7 +4,7 @@ import {
4
4
  ActionTypePropertySchema,
5
5
  ActionKeyPropertySchema,
6
6
  } from "../../types/properties";
7
- import type { Action } from "../../types/domain";
7
+ import type { Action, FunctionOptions } from "../../types/domain";
8
8
 
9
9
  // Pure Zod schema - no resolver metadata!
10
10
  export const GetActionSchema = z
@@ -16,18 +16,8 @@ export const GetActionSchema = z
16
16
  .describe("Get detailed information about a specific action");
17
17
 
18
18
  // Type inferred from schema + function config
19
- export type GetActionOptions = z.infer<typeof GetActionSchema> & {
20
- /** Base URL for Zapier API */
21
- baseUrl?: string;
22
- /** Authentication token */
23
- token?: string;
24
- /** Optional pre-instantiated API client */
25
- api?: any;
26
- /** Enable debug logging */
27
- debug?: boolean;
28
- /** Custom fetch implementation */
29
- fetch?: typeof globalThis.fetch;
30
- };
19
+ export type GetActionOptions = z.infer<typeof GetActionSchema> &
20
+ FunctionOptions;
31
21
 
32
22
  // SDK function interface - ready to be mixed into main SDK interface
33
23
  export interface GetActionSdkFunction {
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { AppKeyPropertySchema } from "../../types/properties";
3
- import type { Integration } from "../../types/domain";
3
+ import type { Integration, FunctionOptions } from "../../types/domain";
4
4
 
5
5
  // Pure Zod schema - no resolver metadata!
6
6
  export const GetAppSchema = z
@@ -12,18 +12,7 @@ export const GetAppSchema = z
12
12
  .describe("Get detailed information about a specific app");
13
13
 
14
14
  // Type inferred from schema + function config
15
- export type GetAppOptions = z.infer<typeof GetAppSchema> & {
16
- /** Base URL for Zapier API */
17
- baseUrl?: string;
18
- /** Authentication token */
19
- token?: string;
20
- /** Optional pre-instantiated API client */
21
- api?: any;
22
- /** Enable debug logging */
23
- debug?: boolean;
24
- /** Custom fetch implementation */
25
- fetch?: typeof globalThis.fetch;
26
- };
15
+ export type GetAppOptions = z.infer<typeof GetAppSchema> & FunctionOptions;
27
16
 
28
17
  // SDK function interface - ready to be mixed into main SDK interface
29
18
  export interface GetAppSdkFunction {
@@ -17,7 +17,6 @@ export async function getAuthentication(
17
17
  ): Promise<Authentication> {
18
18
  const { authenticationId } = options;
19
19
  const api = getOrCreateApiClient(options);
20
- api.requireAuthTo("get authentication");
21
20
 
22
21
  const data: Authentication = await api.get(
23
22
  `/api/v4/authentications/${authenticationId}/`,
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { withOutputSchema } from "../../schema-utils";
3
3
  import { AuthItemSchema } from "../../schemas/Auth";
4
- import type { Authentication } from "../../types/domain";
4
+ import type { Authentication, FunctionOptions } from "../../types/domain";
5
5
 
6
6
  // Pure Zod schema - no resolver metadata!
7
7
  export const GetAuthenticationSchema = withOutputSchema(
@@ -18,22 +18,8 @@ export const GetAuthenticationSchema = withOutputSchema(
18
18
  );
19
19
 
20
20
  // Type inferred from schema + function config
21
- export type GetAuthenticationOptions = z.infer<
22
- typeof GetAuthenticationSchema
23
- > & {
24
- /** Base URL for Zapier API */
25
- baseUrl?: string;
26
- /** Authentication token */
27
- token?: string;
28
- /** Function to dynamically resolve authentication token */
29
- getToken?: () => Promise<string | undefined>;
30
- /** Optional pre-instantiated API client */
31
- api?: any;
32
- /** Enable debug logging */
33
- debug?: boolean;
34
- /** Custom fetch implementation */
35
- fetch?: typeof globalThis.fetch;
36
- };
21
+ export type GetAuthenticationOptions = z.infer<typeof GetAuthenticationSchema> &
22
+ FunctionOptions;
37
23
 
38
24
  // SDK function interface - ready to be mixed into main SDK interface
39
25
  export interface GetAuthenticationSdkFunction {
@@ -5,7 +5,7 @@ import {
5
5
  } from "../../types/properties";
6
6
  import { withOutputSchema } from "../../schema-utils";
7
7
  import { ActionItemSchema } from "../../schemas/Action";
8
- import type { Action } from "../../types/domain";
8
+ import type { Action, FunctionOptions } from "../../types/domain";
9
9
 
10
10
  // Pure Zod schema - no resolver metadata!
11
11
  export const ListActionsSchema = withOutputSchema(
@@ -21,18 +21,8 @@ export const ListActionsSchema = withOutputSchema(
21
21
  );
22
22
 
23
23
  // Type inferred from schema + function config
24
- export type ListActionsOptions = z.infer<typeof ListActionsSchema> & {
25
- /** Base URL for Zapier API */
26
- baseUrl?: string;
27
- /** Authentication token */
28
- token?: string;
29
- /** Optional pre-instantiated API client */
30
- api?: any;
31
- /** Enable debug logging */
32
- debug?: boolean;
33
- /** Custom fetch implementation */
34
- fetch?: typeof globalThis.fetch;
35
- };
24
+ export type ListActionsOptions = z.infer<typeof ListActionsSchema> &
25
+ FunctionOptions;
36
26
 
37
27
  // SDK function interface - ready to be mixed into main SDK interface
38
28
  export interface ListActionsSdkFunction {
@@ -5,7 +5,7 @@ import {
5
5
  } from "../../types/properties";
6
6
  import { withOutputSchema } from "../../schema-utils";
7
7
  import { AppItemSchema } from "../../schemas/App";
8
- import type { Integration } from "../../types/domain";
8
+ import type { Integration, FunctionOptions } from "../../types/domain";
9
9
 
10
10
  // Pure Zod schema - no resolver metadata!
11
11
  export const ListAppsSchema = withOutputSchema(
@@ -24,18 +24,7 @@ export const ListAppsSchema = withOutputSchema(
24
24
  );
25
25
 
26
26
  // Type inferred from schema + function config
27
- export type ListAppsOptions = z.infer<typeof ListAppsSchema> & {
28
- /** Base URL for Zapier API */
29
- baseUrl?: string;
30
- /** Authentication token */
31
- token?: string;
32
- /** Optional pre-instantiated API client */
33
- api?: any;
34
- /** Enable debug logging */
35
- debug?: boolean;
36
- /** Custom fetch implementation */
37
- fetch?: typeof globalThis.fetch;
38
- };
27
+ export type ListAppsOptions = z.infer<typeof ListAppsSchema> & FunctionOptions;
39
28
 
40
29
  // SDK function interface - ready to be mixed into main SDK interface
41
30
  export interface ListAppsSdkFunction {
@@ -19,7 +19,6 @@ export async function listAuthentications(
19
19
  options: Partial<ListAuthenticationsOptions> = {},
20
20
  ): Promise<Authentication[]> {
21
21
  const api = getOrCreateApiClient(options);
22
- api.requireAuthTo("list authentications");
23
22
 
24
23
  // Local function to handle the actual API fetching
25
24
  const listAuthenticationsInternal = async (
@@ -6,7 +6,7 @@ import {
6
6
  } from "../../types/properties";
7
7
  import { withOutputSchema } from "../../schema-utils";
8
8
  import { AuthItemSchema } from "../../schemas/Auth";
9
- import type { Authentication } from "../../types/domain";
9
+ import type { Authentication, FunctionOptions } from "../../types/domain";
10
10
 
11
11
  // Pure Zod schema - no resolver metadata!
12
12
  export const ListAuthenticationsSchema = withOutputSchema(
@@ -39,20 +39,8 @@ export const ListAuthenticationsSchema = withOutputSchema(
39
39
  // Type inferred from schema + function config
40
40
  export type ListAuthenticationsOptions = z.infer<
41
41
  typeof ListAuthenticationsSchema
42
- > & {
43
- /** Base URL for Zapier API */
44
- baseUrl?: string;
45
- /** Authentication token */
46
- token?: string;
47
- /** Function to dynamically resolve authentication token */
48
- getToken?: () => Promise<string | undefined>;
49
- /** Optional pre-instantiated API client */
50
- api?: any;
51
- /** Enable debug logging */
52
- debug?: boolean;
53
- /** Custom fetch implementation */
54
- fetch?: typeof globalThis.fetch;
55
- };
42
+ > &
43
+ FunctionOptions;
56
44
 
57
45
  // SDK function interface - ready to be mixed into main SDK interface
58
46
  export interface ListAuthenticationsSdkFunction {
@@ -8,7 +8,7 @@ import {
8
8
  } from "../../types/properties";
9
9
  import { withOutputSchema } from "../../schema-utils";
10
10
  import { FieldItemSchema } from "../../schemas/Field";
11
- import type { ActionField } from "../../types/domain";
11
+ import type { ActionField, FunctionOptions } from "../../types/domain";
12
12
 
13
13
  // Pure Zod schema - no resolver metadata!
14
14
  export const ListFieldsSchema = withOutputSchema(
@@ -27,18 +27,8 @@ export const ListFieldsSchema = withOutputSchema(
27
27
  );
28
28
 
29
29
  // Type inferred from schema + function config
30
- export type ListFieldsOptions = z.infer<typeof ListFieldsSchema> & {
31
- /** Base URL for Zapier API */
32
- baseUrl?: string;
33
- /** Authentication token */
34
- token?: string;
35
- /** Optional pre-instantiated API client */
36
- api?: any;
37
- /** Enable debug logging */
38
- debug?: boolean;
39
- /** Custom fetch implementation */
40
- fetch?: typeof globalThis.fetch;
41
- };
30
+ export type ListFieldsOptions = z.infer<typeof ListFieldsSchema> &
31
+ FunctionOptions;
42
32
 
43
33
  // SDK function interface - ready to be mixed into main SDK interface
44
34
  export interface ListFieldsSdkFunction {
@@ -0,0 +1,150 @@
1
+ import { getOrCreateApiClient } from "../../api";
2
+ import type { FunctionOptions } from "../../types/domain";
3
+
4
+ export interface RelayRequestOptions {
5
+ /** HTTP method */
6
+ method?: string;
7
+ /** Request body (can be string, FormData, Blob, etc.) */
8
+ body?: BodyInit | null;
9
+ /** Request headers */
10
+ headers?: HeadersInit;
11
+ /** Zapier authentication ID to use for the request */
12
+ authenticationId?: number;
13
+ /** URL to send async response to (makes request async) */
14
+ callbackUrl?: string;
15
+ /** Optional JSON string authentication template to bypass Notary lookup */
16
+ authenticationTemplate?: string;
17
+ }
18
+
19
+ // Legacy type alias
20
+ export type RelayFetchOptions = RelayRequestOptions;
21
+
22
+ export interface RelayFetchConfig extends FunctionOptions {
23
+ /** Event callback function */
24
+ onEvent?: (event: any) => void;
25
+ }
26
+
27
+ /**
28
+ * Transforms full URLs into Relay format: /relay/{domain}/{path}
29
+ *
30
+ * @param url - The full URL to transform (e.g., "https://api.github.com/user")
31
+ * @returns The relay path format (e.g., "/relay/api.github.com/user")
32
+ */
33
+ function transformUrlToRelayPath(url: string | URL): string {
34
+ const targetUrl = new URL(url);
35
+
36
+ // Build the Relay path: /relay/{domain}{pathname}{search}{hash}
37
+ const relayPath = `/relay/${targetUrl.hostname}${targetUrl.pathname}${targetUrl.search}${targetUrl.hash}`;
38
+
39
+ return relayPath;
40
+ }
41
+
42
+ /**
43
+ * Fetch function that can make requests to external APIs through Zapier's Relay service
44
+ *
45
+ * This function takes full URLs (like https://api.github.com/user) and transforms them
46
+ * into the relay format (/relay/api.github.com/user) for the API client to route
47
+ * to relay.zapier.com.
48
+ *
49
+ * @param url - The full URL to fetch
50
+ * @param options - Fetch options with additional Relay-specific parameters
51
+ * @param config - SDK configuration options
52
+ * @returns Promise<Response> - The response from the request
53
+ */
54
+ /**
55
+ * Schema-compatible wrapper function for the request functionality
56
+ */
57
+ export async function request(
58
+ options: {
59
+ url: string;
60
+ method?: string;
61
+ body?: BodyInit | null;
62
+ headers?: HeadersInit;
63
+ authenticationId?: number;
64
+ callbackUrl?: string;
65
+ authenticationTemplate?: string;
66
+ } & FunctionOptions,
67
+ ): Promise<Response> {
68
+ const {
69
+ url,
70
+ method = "GET",
71
+ body,
72
+ headers,
73
+ authenticationId,
74
+ callbackUrl,
75
+ authenticationTemplate,
76
+ ...config
77
+ } = options;
78
+
79
+ return relayFetch(
80
+ url,
81
+ {
82
+ method,
83
+ body,
84
+ headers,
85
+ authenticationId,
86
+ callbackUrl,
87
+ authenticationTemplate,
88
+ },
89
+ config,
90
+ );
91
+ }
92
+
93
+ /**
94
+ * Internal fetch implementation
95
+ */
96
+ export async function relayFetch(
97
+ url: string | URL,
98
+ options: RelayRequestOptions = {},
99
+ config: RelayFetchConfig = {},
100
+ ): Promise<Response> {
101
+ const api = getOrCreateApiClient(config);
102
+
103
+ // Extract Relay-specific options
104
+ const {
105
+ authenticationId,
106
+ callbackUrl,
107
+ authenticationTemplate,
108
+ method = "GET",
109
+ body,
110
+ ...fetchOptions
111
+ } = options;
112
+
113
+ // Transform full URL to relay path format
114
+ const relayPath = transformUrlToRelayPath(url);
115
+
116
+ // Build headers for the request
117
+ const headers: Record<string, string> = {};
118
+
119
+ // Copy existing headers
120
+ if (fetchOptions.headers) {
121
+ const headerEntries =
122
+ fetchOptions.headers instanceof Headers
123
+ ? Array.from(fetchOptions.headers.entries())
124
+ : Object.entries(fetchOptions.headers);
125
+
126
+ for (const [key, value] of headerEntries) {
127
+ headers[key] = value;
128
+ }
129
+ }
130
+
131
+ // Add Relay-specific headers
132
+ if (authenticationId) {
133
+ headers["X-Relay-Authentication-Id"] = authenticationId.toString();
134
+ }
135
+
136
+ if (callbackUrl) {
137
+ headers["X-Relay-Callback-Url"] = callbackUrl;
138
+ }
139
+
140
+ if (authenticationTemplate) {
141
+ headers["X-Authentication-Template"] = authenticationTemplate;
142
+ }
143
+
144
+ // Use the API client's fetch method directly - let it handle auth automatically
145
+ return await api.fetch(relayPath, {
146
+ method,
147
+ body,
148
+ headers,
149
+ });
150
+ }
@@ -0,0 +1,11 @@
1
+ import { request } from "./index";
2
+ import { RelayRequestSchema } from "./schemas";
3
+
4
+ export const requestInfo = {
5
+ name: "request",
6
+ inputSchema: RelayRequestSchema,
7
+ implementation: request,
8
+ };
9
+
10
+ // Legacy export for compatibility
11
+ export const fetchInfo = requestInfo;
@@ -0,0 +1,53 @@
1
+ import { z } from "zod";
2
+ import type { FunctionOptions } from "../../types/domain";
3
+
4
+ // Pure Zod schema for the request function
5
+ export const RelayRequestSchema = z
6
+ .object({
7
+ url: z
8
+ .string()
9
+ .url()
10
+ .describe("The URL to request (will be proxied through Relay)"),
11
+ method: z
12
+ .enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"])
13
+ .optional()
14
+ .describe("HTTP method"),
15
+ body: z.string().optional().describe("Request body as a string"),
16
+ authenticationId: z
17
+ .number()
18
+ .int()
19
+ .optional()
20
+ .describe("Zapier authentication ID to use for the request"),
21
+ callbackUrl: z
22
+ .string()
23
+ .url()
24
+ .optional()
25
+ .describe("URL to send async response to (makes request async)"),
26
+ authenticationTemplate: z
27
+ .string()
28
+ .optional()
29
+ .describe(
30
+ "Optional JSON string authentication template to bypass Notary lookup",
31
+ ),
32
+ headers: z.record(z.string()).optional().describe("Request headers"),
33
+ })
34
+ .describe("Make authenticated HTTP requests through Zapier's Relay service");
35
+
36
+ // Type inferred from schema + function config
37
+ export type RelayRequestOptions = z.infer<typeof RelayRequestSchema> &
38
+ FunctionOptions & {
39
+ /** Base URL for Relay service */
40
+ relayBaseUrl?: string;
41
+ };
42
+
43
+ // SDK function interface
44
+ export interface RelayRequestSdkFunction {
45
+ request: (options: RelayRequestOptions) => Promise<Response>;
46
+ }
47
+
48
+ // Legacy exports for compatibility
49
+ export const RelayFetchSchema = RelayRequestSchema;
50
+ export type RelayFetchOptions = RelayRequestOptions;
51
+ export interface RelayFetchSdkFunction {
52
+ fetch: (options: RelayFetchOptions) => Promise<Response>;
53
+ }
@@ -25,7 +25,6 @@ export async function runAction(
25
25
  } = options;
26
26
 
27
27
  const api = getOrCreateApiClient(options);
28
- api.requireAuthTo("run actions");
29
28
 
30
29
  // Validate that the action exists
31
30
  const actionData = await getAction({
@@ -6,7 +6,10 @@ import {
6
6
  AuthenticationIdPropertySchema,
7
7
  InputsPropertySchema,
8
8
  } from "../../types/properties";
9
- import type { ActionExecutionResult } from "../../types/domain";
9
+ import type {
10
+ ActionExecutionResult,
11
+ FunctionOptions,
12
+ } from "../../types/domain";
10
13
 
11
14
  // Pure Zod schema - no resolver metadata!
12
15
  export const RunActionSchema = z
@@ -22,20 +25,8 @@ export const RunActionSchema = z
22
25
  .describe("Execute an action with the given inputs");
23
26
 
24
27
  // Type inferred from schema + function config
25
- export type RunActionOptions = z.infer<typeof RunActionSchema> & {
26
- /** Base URL for Zapier API */
27
- baseUrl?: string;
28
- /** Authentication token */
29
- token?: string;
30
- /** Function to dynamically resolve authentication token */
31
- getToken?: () => Promise<string | undefined>;
32
- /** Optional pre-instantiated API client */
33
- api?: any;
34
- /** Enable debug logging */
35
- debug?: boolean;
36
- /** Custom fetch implementation */
37
- fetch?: typeof globalThis.fetch;
38
- };
28
+ export type RunActionOptions = z.infer<typeof RunActionSchema> &
29
+ FunctionOptions;
39
30
 
40
31
  // SDK function interface - ready to be mixed into main SDK interface
41
32
  export interface RunActionSdkFunction {
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  export * from "./types/domain";
3
3
  export * from "./types/properties";
4
4
  export * from "./plugins/apps";
5
+ export * from "./plugins/fetch";
5
6
 
6
7
  // Export schema utilities for CLI
7
8
  export { isPositional } from "./schema-utils";
@@ -27,9 +28,14 @@ export { runAction } from "./functions/runAction";
27
28
  export { listFields } from "./functions/listFields";
28
29
  export { generateTypes } from "./functions/generateTypes";
29
30
  export { bundleCode } from "./functions/bundleCode";
31
+ export { request, relayFetch } from "./functions/request";
32
+ export {
33
+ RelayRequestSchema,
34
+ RelayFetchSchema,
35
+ } from "./functions/request/schemas";
30
36
 
31
37
  // Export the main combined SDK
32
38
  export { createZapierSdk, ZapierSdkOptions } from "./sdk";
33
39
 
34
- // Export SDK type from types (not sdk.ts to avoid circular imports)
35
- export type { ZapierSdk } from "./types/sdk";
40
+ // Export SDK types from types (not sdk.ts to avoid circular imports)
41
+ export type { BaseZapierSdk, ZapierSdk } from "./types/sdk";