@zapier/zapier-sdk 0.3.0 → 0.4.0
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.
- package/dist/index.cjs +2001 -0
- package/dist/index.d.mts +840 -0
- package/dist/index.d.ts +840 -20
- package/dist/index.mjs +1955 -0
- package/package.json +19 -7
- package/src/api/client.ts +84 -16
- package/src/api/types.ts +9 -1
- package/src/auth.ts +19 -287
- package/src/functions/fetch/index.ts +180 -0
- package/src/functions/fetch/info.ts +8 -0
- package/src/functions/fetch/schemas.ts +46 -0
- package/src/functions/findFirstAuthentication/schemas.ts +3 -13
- package/src/functions/findUniqueAuthentication/schemas.ts +3 -13
- package/src/functions/generateTypes/index.ts +15 -0
- package/src/functions/generateTypes/schemas.ts +3 -10
- package/src/functions/getAction/schemas.ts +3 -13
- package/src/functions/getApp/schemas.ts +2 -13
- package/src/functions/getAuthentication/index.ts +0 -1
- package/src/functions/getAuthentication/schemas.ts +3 -17
- package/src/functions/listActions/schemas.ts +3 -13
- package/src/functions/listApps/schemas.ts +2 -13
- package/src/functions/listAuthentications/index.ts +0 -1
- package/src/functions/listAuthentications/schemas.ts +3 -15
- package/src/functions/listFields/schemas.ts +3 -13
- package/src/functions/runAction/index.ts +0 -1
- package/src/functions/runAction/schemas.ts +6 -15
- package/src/index.ts +4 -2
- package/src/plugins/apps/index.ts +35 -9
- package/src/sdk.ts +20 -22
- package/src/types/domain.ts +16 -0
- package/src/types/sdk.ts +13 -1
- package/tsconfig.json +2 -2
- package/tsup.config.ts +21 -0
- package/dist/api/auth.d.ts +0 -8
- package/dist/api/auth.js +0 -29
- package/dist/api/client.d.ts +0 -8
- package/dist/api/client.js +0 -119
- package/dist/api/debug.d.ts +0 -12
- package/dist/api/debug.js +0 -50
- package/dist/api/index.d.ts +0 -28
- package/dist/api/index.js +0 -52
- package/dist/api/polling.d.ts +0 -17
- package/dist/api/polling.js +0 -34
- package/dist/api/types.d.ts +0 -147
- package/dist/api/types.js +0 -9
- package/dist/auth.d.ts +0 -59
- package/dist/auth.js +0 -261
- package/dist/functions/bundleCode/index.d.ts +0 -11
- package/dist/functions/bundleCode/index.js +0 -91
- package/dist/functions/bundleCode/info.d.ts +0 -27
- package/dist/functions/bundleCode/info.js +0 -11
- package/dist/functions/bundleCode/schemas.d.ts +0 -27
- package/dist/functions/bundleCode/schemas.js +0 -22
- package/dist/functions/findFirstAuthentication/index.d.ts +0 -12
- package/dist/functions/findFirstAuthentication/index.js +0 -21
- package/dist/functions/findFirstAuthentication/info.d.ts +0 -30
- package/dist/functions/findFirstAuthentication/info.js +0 -11
- package/dist/functions/findFirstAuthentication/schemas.d.ts +0 -42
- package/dist/functions/findFirstAuthentication/schemas.js +0 -25
- package/dist/functions/findUniqueAuthentication/index.d.ts +0 -13
- package/dist/functions/findUniqueAuthentication/index.js +0 -28
- package/dist/functions/findUniqueAuthentication/info.d.ts +0 -30
- package/dist/functions/findUniqueAuthentication/info.js +0 -11
- package/dist/functions/findUniqueAuthentication/schemas.d.ts +0 -42
- package/dist/functions/findUniqueAuthentication/schemas.js +0 -25
- package/dist/functions/generateTypes/index.d.ts +0 -11
- package/dist/functions/generateTypes/index.js +0 -305
- package/dist/functions/generateTypes/info.d.ts +0 -21
- package/dist/functions/generateTypes/info.js +0 -11
- package/dist/functions/generateTypes/schemas.d.ts +0 -30
- package/dist/functions/generateTypes/schemas.js +0 -14
- package/dist/functions/getAction/index.d.ts +0 -12
- package/dist/functions/getAction/index.js +0 -26
- package/dist/functions/getAction/info.d.ts +0 -18
- package/dist/functions/getAction/info.js +0 -11
- package/dist/functions/getAction/schemas.d.ts +0 -30
- package/dist/functions/getAction/schemas.js +0 -13
- package/dist/functions/getApp/index.d.ts +0 -12
- package/dist/functions/getApp/index.js +0 -37
- package/dist/functions/getApp/info.d.ts +0 -12
- package/dist/functions/getApp/info.js +0 -11
- package/dist/functions/getApp/schemas.d.ts +0 -24
- package/dist/functions/getApp/schemas.js +0 -11
- package/dist/functions/getAuthentication/index.d.ts +0 -13
- package/dist/functions/getAuthentication/index.js +0 -38
- package/dist/functions/getAuthentication/info.d.ts +0 -12
- package/dist/functions/getAuthentication/info.js +0 -11
- package/dist/functions/getAuthentication/schemas.d.ts +0 -26
- package/dist/functions/getAuthentication/schemas.js +0 -16
- package/dist/functions/listActions/index.d.ts +0 -12
- package/dist/functions/listActions/index.js +0 -128
- package/dist/functions/listActions/info.d.ts +0 -15
- package/dist/functions/listActions/info.js +0 -11
- package/dist/functions/listActions/schemas.d.ts +0 -27
- package/dist/functions/listActions/schemas.js +0 -14
- package/dist/functions/listApps/index.d.ts +0 -12
- package/dist/functions/listApps/index.js +0 -50
- package/dist/functions/listApps/info.d.ts +0 -18
- package/dist/functions/listApps/info.js +0 -11
- package/dist/functions/listApps/schemas.d.ts +0 -30
- package/dist/functions/listApps/schemas.js +0 -15
- package/dist/functions/listAuthentications/index.d.ts +0 -12
- package/dist/functions/listAuthentications/index.js +0 -131
- package/dist/functions/listAuthentications/info.d.ts +0 -30
- package/dist/functions/listAuthentications/info.js +0 -11
- package/dist/functions/listAuthentications/schemas.d.ts +0 -44
- package/dist/functions/listAuthentications/schemas.js +0 -25
- package/dist/functions/listFields/index.d.ts +0 -12
- package/dist/functions/listFields/index.js +0 -65
- package/dist/functions/listFields/info.d.ts +0 -24
- package/dist/functions/listFields/info.js +0 -11
- package/dist/functions/listFields/schemas.d.ts +0 -36
- package/dist/functions/listFields/schemas.js +0 -17
- package/dist/functions/runAction/index.d.ts +0 -12
- package/dist/functions/runAction/index.js +0 -86
- package/dist/functions/runAction/info.d.ts +0 -24
- package/dist/functions/runAction/info.js +0 -11
- package/dist/functions/runAction/schemas.d.ts +0 -38
- package/dist/functions/runAction/schemas.js +0 -15
- package/dist/index.js +0 -57
- package/dist/plugins/apps/index.d.ts +0 -8
- package/dist/plugins/apps/index.js +0 -77
- package/dist/plugins/apps/info.d.ts +0 -6
- package/dist/plugins/apps/info.js +0 -13
- package/dist/plugins/apps/types.d.ts +0 -21
- package/dist/plugins/apps/types.js +0 -2
- package/dist/resolvers/actionKey.d.ts +0 -8
- package/dist/resolvers/actionKey.js +0 -20
- package/dist/resolvers/actionType.d.ts +0 -8
- package/dist/resolvers/actionType.js +0 -21
- package/dist/resolvers/appKey.d.ts +0 -6
- package/dist/resolvers/appKey.js +0 -8
- package/dist/resolvers/authenticationId.d.ts +0 -8
- package/dist/resolvers/authenticationId.js +0 -29
- package/dist/resolvers/index.d.ts +0 -39
- package/dist/resolvers/index.js +0 -105
- package/dist/resolvers/inputs.d.ts +0 -7
- package/dist/resolvers/inputs.js +0 -15
- package/dist/schema-utils.d.ts +0 -44
- package/dist/schema-utils.js +0 -76
- package/dist/schemas/Action.d.ts +0 -21
- package/dist/schemas/Action.js +0 -31
- package/dist/schemas/App.d.ts +0 -19
- package/dist/schemas/App.js +0 -32
- package/dist/schemas/Auth.d.ts +0 -27
- package/dist/schemas/Auth.js +0 -42
- package/dist/schemas/Field.d.ts +0 -15
- package/dist/schemas/Field.js +0 -25
- package/dist/sdk.d.ts +0 -6
- package/dist/sdk.js +0 -90
- package/dist/types/domain.d.ts +0 -25
- package/dist/types/domain.js +0 -21
- package/dist/types/events.d.ts +0 -37
- package/dist/types/events.js +0 -8
- package/dist/types/properties.d.ts +0 -21
- package/dist/types/properties.js +0 -52
- package/dist/types/sdk.d.ts +0 -24
- package/dist/types/sdk.js +0 -2
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { getOrCreateApiClient } from "../../api";
|
|
2
|
+
import type { FunctionOptions } from "../../types/domain";
|
|
3
|
+
|
|
4
|
+
export interface RelayFetchOptions {
|
|
5
|
+
/** HTTP method */
|
|
6
|
+
method?: string;
|
|
7
|
+
/** Request body as a string */
|
|
8
|
+
body?: string;
|
|
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
|
+
export interface RelayFetchConfig extends FunctionOptions {
|
|
20
|
+
/** Event callback function */
|
|
21
|
+
onEvent?: (event: any) => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Transforms full URLs into Relay format: /relay/{domain}/{path}
|
|
26
|
+
*
|
|
27
|
+
* @param url - The full URL to transform (e.g., "https://api.github.com/user")
|
|
28
|
+
* @returns The relay path format (e.g., "/relay/api.github.com/user")
|
|
29
|
+
*/
|
|
30
|
+
function transformUrlToRelayPath(url: string | URL): string {
|
|
31
|
+
const targetUrl = new URL(url);
|
|
32
|
+
|
|
33
|
+
// Build the Relay path: /relay/{domain}{pathname}{search}{hash}
|
|
34
|
+
const relayPath = `/relay/${targetUrl.hostname}${targetUrl.pathname}${targetUrl.search}${targetUrl.hash}`;
|
|
35
|
+
|
|
36
|
+
return relayPath;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Fetch function that can make requests to external APIs through Zapier's Relay service
|
|
41
|
+
*
|
|
42
|
+
* This function takes full URLs (like https://api.github.com/user) and transforms them
|
|
43
|
+
* into the relay format (/relay/api.github.com/user) for the API client to route
|
|
44
|
+
* to relay.zapier.com.
|
|
45
|
+
*
|
|
46
|
+
* @param url - The full URL to fetch
|
|
47
|
+
* @param options - Fetch options with additional Relay-specific parameters
|
|
48
|
+
* @param config - SDK configuration options
|
|
49
|
+
* @returns Promise<Response> - The response from the request
|
|
50
|
+
*/
|
|
51
|
+
/**
|
|
52
|
+
* Schema-compatible wrapper function for the fetch functionality
|
|
53
|
+
*/
|
|
54
|
+
export async function fetch(
|
|
55
|
+
options: {
|
|
56
|
+
url: string;
|
|
57
|
+
method?: string;
|
|
58
|
+
body?: string;
|
|
59
|
+
headers?: Record<string, string>;
|
|
60
|
+
authenticationId?: number;
|
|
61
|
+
callbackUrl?: string;
|
|
62
|
+
authenticationTemplate?: string;
|
|
63
|
+
} & FunctionOptions,
|
|
64
|
+
): Promise<Response> {
|
|
65
|
+
const {
|
|
66
|
+
url,
|
|
67
|
+
method = "GET",
|
|
68
|
+
body,
|
|
69
|
+
headers,
|
|
70
|
+
authenticationId,
|
|
71
|
+
callbackUrl,
|
|
72
|
+
authenticationTemplate,
|
|
73
|
+
...config
|
|
74
|
+
} = options;
|
|
75
|
+
|
|
76
|
+
return relayFetch(
|
|
77
|
+
url,
|
|
78
|
+
{
|
|
79
|
+
method,
|
|
80
|
+
body,
|
|
81
|
+
headers,
|
|
82
|
+
authenticationId,
|
|
83
|
+
callbackUrl,
|
|
84
|
+
authenticationTemplate,
|
|
85
|
+
},
|
|
86
|
+
config,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Internal fetch implementation
|
|
92
|
+
*/
|
|
93
|
+
export async function relayFetch(
|
|
94
|
+
url: string | URL,
|
|
95
|
+
options: RelayFetchOptions = {},
|
|
96
|
+
config: RelayFetchConfig = {},
|
|
97
|
+
): Promise<Response> {
|
|
98
|
+
const api = getOrCreateApiClient(config);
|
|
99
|
+
|
|
100
|
+
// Extract Relay-specific options
|
|
101
|
+
const {
|
|
102
|
+
authenticationId,
|
|
103
|
+
callbackUrl,
|
|
104
|
+
authenticationTemplate,
|
|
105
|
+
method = "GET",
|
|
106
|
+
body,
|
|
107
|
+
...fetchOptions
|
|
108
|
+
} = options;
|
|
109
|
+
|
|
110
|
+
// Transform full URL to relay path format
|
|
111
|
+
const relayPath = transformUrlToRelayPath(url);
|
|
112
|
+
|
|
113
|
+
// Build headers for the request
|
|
114
|
+
const headers: Record<string, string> = {};
|
|
115
|
+
|
|
116
|
+
// Copy existing headers
|
|
117
|
+
if (fetchOptions.headers) {
|
|
118
|
+
const headerEntries =
|
|
119
|
+
fetchOptions.headers instanceof Headers
|
|
120
|
+
? Array.from(fetchOptions.headers.entries())
|
|
121
|
+
: Object.entries(fetchOptions.headers);
|
|
122
|
+
|
|
123
|
+
for (const [key, value] of headerEntries) {
|
|
124
|
+
headers[key] = value;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Add Relay-specific headers
|
|
129
|
+
if (authenticationId) {
|
|
130
|
+
headers["X-Relay-Authentication-Id"] = authenticationId.toString();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (callbackUrl) {
|
|
134
|
+
headers["X-Relay-Callback-Url"] = callbackUrl;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (authenticationTemplate) {
|
|
138
|
+
headers["X-Authentication-Template"] = authenticationTemplate;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// For Relay requests, we need to disable the default authorization and add our own
|
|
142
|
+
const requestOptions = {
|
|
143
|
+
headers,
|
|
144
|
+
authRequired: false, // Disable automatic Authorization header
|
|
145
|
+
customErrorHandler: (response: Response) => {
|
|
146
|
+
if (!response.ok) {
|
|
147
|
+
return new Error(
|
|
148
|
+
`Relay request failed: ${response.status} ${response.statusText}`,
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
return undefined;
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// Add X-Relay-Authorization header manually
|
|
156
|
+
let token = config.token;
|
|
157
|
+
if (!token && config.getToken) {
|
|
158
|
+
token = await config.getToken();
|
|
159
|
+
}
|
|
160
|
+
if (!token) {
|
|
161
|
+
const { getTokenFromEnvOrConfig } = await import("../../auth");
|
|
162
|
+
token = await getTokenFromEnvOrConfig({
|
|
163
|
+
onEvent: config.onEvent,
|
|
164
|
+
fetch: config.fetch,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (token) {
|
|
168
|
+
const { getAuthorizationHeader } = await import("../../api/auth");
|
|
169
|
+
headers["X-Relay-Authorization"] = getAuthorizationHeader(token);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Use the API client's fetch method directly
|
|
173
|
+
return await api.fetch(relayPath, {
|
|
174
|
+
method,
|
|
175
|
+
body,
|
|
176
|
+
headers: requestOptions.headers,
|
|
177
|
+
authRequired: requestOptions.authRequired,
|
|
178
|
+
customErrorHandler: requestOptions.customErrorHandler,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { FunctionOptions } from "../../types/domain";
|
|
3
|
+
|
|
4
|
+
// Pure Zod schema for the fetch function
|
|
5
|
+
export const RelayFetchSchema = z
|
|
6
|
+
.object({
|
|
7
|
+
url: z
|
|
8
|
+
.string()
|
|
9
|
+
.url()
|
|
10
|
+
.describe("The URL to fetch (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 RelayFetchOptions = z.infer<typeof RelayFetchSchema> &
|
|
38
|
+
FunctionOptions & {
|
|
39
|
+
/** Base URL for Relay service */
|
|
40
|
+
relayBaseUrl?: string;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// SDK function interface
|
|
44
|
+
export interface RelayFetchSdkFunction {
|
|
45
|
+
fetch: (options: RelayFetchOptions) => Promise<Response>;
|
|
46
|
+
}
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
@@ -6,7 +6,10 @@ import {
|
|
|
6
6
|
AuthenticationIdPropertySchema,
|
|
7
7
|
InputsPropertySchema,
|
|
8
8
|
} from "../../types/properties";
|
|
9
|
-
import type {
|
|
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
|
-
|
|
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
|
@@ -27,9 +27,11 @@ export { runAction } from "./functions/runAction";
|
|
|
27
27
|
export { listFields } from "./functions/listFields";
|
|
28
28
|
export { generateTypes } from "./functions/generateTypes";
|
|
29
29
|
export { bundleCode } from "./functions/bundleCode";
|
|
30
|
+
export { fetch, relayFetch } from "./functions/fetch";
|
|
31
|
+
export { RelayFetchSchema } from "./functions/fetch/schemas";
|
|
30
32
|
|
|
31
33
|
// Export the main combined SDK
|
|
32
34
|
export { createZapierSdk, ZapierSdkOptions } from "./sdk";
|
|
33
35
|
|
|
34
|
-
// Export SDK
|
|
35
|
-
export type { ZapierSdk } from "./types/sdk";
|
|
36
|
+
// Export SDK types from types (not sdk.ts to avoid circular imports)
|
|
37
|
+
export type { BaseZapierSdk, ZapierSdk } from "./types/sdk";
|