@zapier/zapier-sdk 0.0.3 → 0.1.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/api/auth.d.ts +8 -0
- package/dist/api/auth.js +29 -0
- package/dist/api/client.d.ts +8 -0
- package/dist/api/client.js +102 -0
- package/dist/api/debug.d.ts +12 -0
- package/dist/api/debug.js +50 -0
- package/dist/api/index.d.ts +26 -0
- package/dist/api/index.js +51 -0
- package/dist/api/polling.d.ts +17 -0
- package/dist/api/polling.js +34 -0
- package/dist/{types.d.ts → api/types.d.ts} +37 -88
- package/dist/api/types.js +9 -0
- package/dist/functions/{bundleCode.d.ts → bundleCode/index.d.ts} +1 -8
- package/dist/functions/bundleCode/info.d.ts +27 -0
- package/dist/functions/bundleCode/info.js +11 -0
- package/dist/functions/bundleCode/schemas.d.ts +27 -0
- package/dist/functions/bundleCode/schemas.js +22 -0
- package/dist/functions/{generateTypes.d.ts → generateTypes/index.d.ts} +2 -7
- package/dist/functions/{generateTypes.js → generateTypes/index.js} +58 -24
- package/dist/functions/generateTypes/info.d.ts +21 -0
- package/dist/functions/generateTypes/info.js +11 -0
- package/dist/functions/generateTypes/schemas.d.ts +30 -0
- package/dist/functions/generateTypes/schemas.js +14 -0
- package/dist/functions/{getAction.d.ts → getAction/index.d.ts} +2 -6
- package/dist/functions/{getAction.js → getAction/index.js} +6 -5
- package/dist/functions/getAction/info.d.ts +18 -0
- package/dist/functions/getAction/info.js +11 -0
- package/dist/functions/getAction/schemas.d.ts +30 -0
- package/dist/functions/getAction/schemas.js +13 -0
- package/dist/functions/{getApp.d.ts → getApp/index.d.ts} +2 -4
- package/dist/functions/{getApp.js → getApp/index.js} +6 -10
- package/dist/functions/getApp/info.d.ts +12 -0
- package/dist/functions/getApp/info.js +11 -0
- package/dist/functions/getApp/schemas.d.ts +24 -0
- package/dist/functions/getApp/schemas.js +11 -0
- package/dist/functions/{listActions.d.ts → listActions/index.d.ts} +3 -6
- package/dist/functions/{listActions.js → listActions/index.js} +4 -3
- package/dist/functions/listActions/info.d.ts +15 -0
- package/dist/functions/listActions/info.js +11 -0
- package/dist/functions/listActions/schemas.d.ts +27 -0
- package/dist/functions/listActions/schemas.js +14 -0
- package/dist/functions/{listApps.d.ts → listApps/index.d.ts} +2 -6
- package/dist/functions/{listApps.js → listApps/index.js} +1 -1
- package/dist/functions/listApps/info.d.ts +18 -0
- package/dist/functions/listApps/info.js +11 -0
- package/dist/functions/listApps/schemas.d.ts +30 -0
- package/dist/functions/listApps/schemas.js +15 -0
- package/dist/functions/{listAuths.d.ts → listAuths/index.d.ts} +3 -9
- package/dist/functions/{listAuths.js → listAuths/index.js} +5 -5
- package/dist/functions/listAuths/info.d.ts +24 -0
- package/dist/functions/listAuths/info.js +11 -0
- package/dist/functions/listAuths/schemas.d.ts +36 -0
- package/dist/functions/listAuths/schemas.js +17 -0
- package/dist/functions/{listFields.d.ts → listFields/index.d.ts} +3 -9
- package/dist/functions/{listFields.js → listFields/index.js} +8 -10
- package/dist/functions/listFields/info.d.ts +24 -0
- package/dist/functions/listFields/info.js +11 -0
- package/dist/functions/listFields/schemas.d.ts +36 -0
- package/dist/functions/listFields/schemas.js +17 -0
- package/dist/functions/{runAction.d.ts → runAction/index.d.ts} +2 -8
- package/dist/functions/{runAction.js → runAction/index.js} +15 -14
- package/dist/functions/runAction/info.d.ts +24 -0
- package/dist/functions/runAction/info.js +11 -0
- package/dist/functions/runAction/schemas.d.ts +36 -0
- package/dist/functions/runAction/schemas.js +15 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.js +7 -3
- package/dist/plugins/apps/index.d.ts +8 -0
- package/dist/plugins/apps/index.js +77 -0
- package/dist/plugins/apps/info.d.ts +6 -0
- package/dist/plugins/apps/info.js +13 -0
- package/dist/plugins/apps/types.d.ts +21 -0
- package/dist/plugins/apps/types.js +2 -0
- package/dist/resolvers/actionKey.d.ts +8 -0
- package/dist/resolvers/actionKey.js +20 -0
- package/dist/resolvers/actionType.d.ts +8 -0
- package/dist/resolvers/actionType.js +21 -0
- package/dist/resolvers/appKey.d.ts +6 -0
- package/dist/resolvers/appKey.js +8 -0
- package/dist/resolvers/authenticationId.d.ts +8 -0
- package/dist/resolvers/authenticationId.js +29 -0
- package/dist/resolvers/index.d.ts +39 -0
- package/dist/resolvers/index.js +105 -0
- package/dist/resolvers/inputs.d.ts +7 -0
- package/dist/resolvers/inputs.js +15 -0
- package/dist/schema-utils.d.ts +39 -0
- package/dist/schema-utils.js +52 -0
- package/dist/schemas/Action.d.ts +21 -0
- package/dist/schemas/Action.js +31 -0
- package/dist/schemas/App.d.ts +19 -0
- package/dist/schemas/App.js +32 -0
- package/dist/schemas/Auth.d.ts +30 -0
- package/dist/schemas/Auth.js +49 -0
- package/dist/schemas/Field.d.ts +15 -0
- package/dist/schemas/Field.js +25 -0
- package/dist/sdk.d.ts +3 -4
- package/dist/sdk.js +96 -11
- package/dist/types/domain.d.ts +22 -0
- package/dist/types/domain.js +21 -0
- package/dist/types/properties.d.ts +21 -0
- package/dist/types/properties.js +45 -0
- package/dist/types/sdk.d.ts +21 -0
- package/dist/types/sdk.js +2 -0
- package/package.json +4 -2
- package/src/api/auth.ts +28 -0
- package/src/api/client.ts +148 -0
- package/src/api/debug.ts +58 -0
- package/src/api/index.ts +83 -0
- package/src/api/polling.ts +56 -0
- package/src/api/types.ts +177 -0
- package/src/functions/{bundleCode.ts → bundleCode/index.ts} +1 -8
- package/src/functions/bundleCode/info.ts +9 -0
- package/src/functions/bundleCode/schemas.ts +30 -0
- package/src/functions/{generateTypes.ts → generateTypes/index.ts} +70 -31
- package/src/functions/generateTypes/info.ts +9 -0
- package/src/functions/generateTypes/schemas.ts +38 -0
- package/src/functions/{getAction.ts → getAction/index.ts} +11 -12
- package/src/functions/getAction/info.ts +9 -0
- package/src/functions/getAction/schemas.ts +35 -0
- package/src/functions/{getApp.ts → getApp/index.ts} +9 -15
- package/src/functions/getApp/info.ts +9 -0
- package/src/functions/getApp/schemas.ts +31 -0
- package/src/functions/{listActions.ts → listActions/index.ts} +8 -10
- package/src/functions/listActions/info.ts +9 -0
- package/src/functions/listActions/schemas.ts +40 -0
- package/src/functions/{listApps.ts → listApps/index.ts} +3 -8
- package/src/functions/listApps/info.ts +9 -0
- package/src/functions/listApps/schemas.ts +43 -0
- package/src/functions/{listAuths.ts → listAuths/index.ts} +8 -16
- package/src/functions/listAuths/info.ts +9 -0
- package/src/functions/listAuths/schemas.ts +48 -0
- package/src/functions/{listFields.ts → listFields/index.ts} +11 -20
- package/src/functions/listFields/info.ts +9 -0
- package/src/functions/listFields/schemas.ts +46 -0
- package/src/functions/{runAction.ts → runAction/index.ts} +25 -23
- package/src/functions/runAction/info.ts +9 -0
- package/src/functions/runAction/schemas.ts +41 -0
- package/src/index.ts +13 -4
- package/src/plugins/apps/index.ts +144 -0
- package/src/plugins/apps/info.ts +12 -0
- package/src/plugins/apps/types.ts +34 -0
- package/src/resolvers/actionKey.ts +33 -0
- package/src/resolvers/actionType.ts +30 -0
- package/src/resolvers/appKey.ts +11 -0
- package/src/resolvers/authenticationId.ts +38 -0
- package/src/resolvers/index.ts +117 -0
- package/src/resolvers/inputs.ts +23 -0
- package/src/schema-utils.ts +119 -0
- package/src/schemas/Action.ts +40 -0
- package/src/schemas/App.ts +43 -0
- package/src/schemas/Auth.ts +62 -0
- package/src/schemas/Field.ts +34 -0
- package/src/sdk.ts +153 -19
- package/src/types/domain.ts +54 -0
- package/src/types/properties.ts +67 -0
- package/src/types/sdk.ts +42 -0
- package/dist/actions-sdk.d.ts +0 -47
- package/dist/actions-sdk.js +0 -208
- package/dist/api.d.ts +0 -62
- package/dist/api.js +0 -227
- package/dist/output-schemas.d.ts +0 -95
- package/dist/output-schemas.js +0 -138
- package/dist/schemas.d.ts +0 -338
- package/dist/schemas.js +0 -336
- package/dist/types.js +0 -41
- package/src/actions-sdk.ts +0 -356
- package/src/api.ts +0 -361
- package/src/output-schemas.ts +0 -196
- package/src/schemas.ts +0 -467
- package/src/types.ts +0 -257
- /package/dist/functions/{bundleCode.js → bundleCode/index.js} +0 -0
package/src/api/index.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zapier API Client Module
|
|
3
|
+
*
|
|
4
|
+
* This module provides a centralized API layer for all HTTP interactions
|
|
5
|
+
* with Zapier's various APIs. It handles authentication, error handling,
|
|
6
|
+
* polling, and provides consistent patterns across all services.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Re-export all types
|
|
10
|
+
export type {
|
|
11
|
+
// API Client Infrastructure Types
|
|
12
|
+
ApiClient,
|
|
13
|
+
ApiClientOptions,
|
|
14
|
+
RequestOptions,
|
|
15
|
+
PollOptions,
|
|
16
|
+
DebugLogger,
|
|
17
|
+
// API Response Model Types
|
|
18
|
+
Integration,
|
|
19
|
+
Action,
|
|
20
|
+
Trigger,
|
|
21
|
+
Field,
|
|
22
|
+
Choice,
|
|
23
|
+
ActionExecutionResult,
|
|
24
|
+
ActionField,
|
|
25
|
+
ActionFieldChoice,
|
|
26
|
+
NeedsRequest,
|
|
27
|
+
NeedsResponse,
|
|
28
|
+
Authentication,
|
|
29
|
+
AuthenticationsResponse,
|
|
30
|
+
} from "./types";
|
|
31
|
+
|
|
32
|
+
// Re-export authentication utilities
|
|
33
|
+
export { isJwt, getAuthorizationHeader } from "./auth";
|
|
34
|
+
|
|
35
|
+
// Re-export debug utilities
|
|
36
|
+
export { createDebugLogger, createDebugFetch } from "./debug";
|
|
37
|
+
|
|
38
|
+
// Re-export polling utilities
|
|
39
|
+
export { pollUntilComplete } from "./polling";
|
|
40
|
+
|
|
41
|
+
// Re-export the main client factory
|
|
42
|
+
export { createZapierApi } from "./client";
|
|
43
|
+
|
|
44
|
+
// Utility Functions
|
|
45
|
+
export function generateRequestId(): string {
|
|
46
|
+
return Math.random().toString(36).substring(2) + Date.now().toString(36);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Utility function to get or create an API client for standalone functions
|
|
51
|
+
*
|
|
52
|
+
* @param config - Configuration that may include an existing API client
|
|
53
|
+
* @returns ApiClient instance
|
|
54
|
+
*/
|
|
55
|
+
export function getOrCreateApiClient(config: {
|
|
56
|
+
baseUrl?: string;
|
|
57
|
+
token?: string;
|
|
58
|
+
api?: import("./types").ApiClient;
|
|
59
|
+
debug?: boolean;
|
|
60
|
+
fetch?: typeof globalThis.fetch;
|
|
61
|
+
}): import("./types").ApiClient {
|
|
62
|
+
const {
|
|
63
|
+
baseUrl = "https://zapier.com",
|
|
64
|
+
token = process.env.ZAPIER_TOKEN,
|
|
65
|
+
api: providedApi,
|
|
66
|
+
debug = false,
|
|
67
|
+
fetch: customFetch,
|
|
68
|
+
} = config;
|
|
69
|
+
|
|
70
|
+
// Use provided API client or create a new one
|
|
71
|
+
if (providedApi) {
|
|
72
|
+
return providedApi;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Import createZapierApi locally to avoid circular imports
|
|
76
|
+
const { createZapierApi } = require("./client");
|
|
77
|
+
return createZapierApi({
|
|
78
|
+
baseUrl,
|
|
79
|
+
token,
|
|
80
|
+
debug,
|
|
81
|
+
fetch: customFetch,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polling Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for polling HTTP endpoints until completion,
|
|
5
|
+
* with configurable retry logic and exponential backoff.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export async function pollUntilComplete(options: {
|
|
9
|
+
fetch: typeof globalThis.fetch;
|
|
10
|
+
url: string;
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
maxAttempts?: number;
|
|
13
|
+
initialDelay?: number;
|
|
14
|
+
maxDelay?: number;
|
|
15
|
+
successStatus?: number;
|
|
16
|
+
pendingStatus?: number;
|
|
17
|
+
resultExtractor?: (response: any) => any;
|
|
18
|
+
}): Promise<any> {
|
|
19
|
+
const {
|
|
20
|
+
fetch,
|
|
21
|
+
url,
|
|
22
|
+
headers = {},
|
|
23
|
+
maxAttempts = 30,
|
|
24
|
+
initialDelay = 50,
|
|
25
|
+
maxDelay = 1000,
|
|
26
|
+
successStatus = 200,
|
|
27
|
+
pendingStatus = 202,
|
|
28
|
+
resultExtractor = (response) => response,
|
|
29
|
+
} = options;
|
|
30
|
+
|
|
31
|
+
let delay = initialDelay;
|
|
32
|
+
|
|
33
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
34
|
+
const response = await fetch(url, { headers });
|
|
35
|
+
|
|
36
|
+
if (response.status === successStatus) {
|
|
37
|
+
// Success - extract and return results
|
|
38
|
+
const result = await response.json();
|
|
39
|
+
return resultExtractor(result);
|
|
40
|
+
} else if (response.status === pendingStatus) {
|
|
41
|
+
// Still processing - wait and retry
|
|
42
|
+
if (attempt < maxAttempts - 1) {
|
|
43
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
44
|
+
delay = Math.min(delay * 2, maxDelay); // Exponential backoff
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
// Error occurred
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Request failed: GET ${url} - ${response.status} ${response.statusText}`,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
throw new Error(`Operation timed out after ${maxAttempts} attempts`);
|
|
56
|
+
}
|
package/src/api/types.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Client Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* This module contains all type definitions related to the Zapier API client,
|
|
5
|
+
* including configuration options, client interfaces, request/response types,
|
|
6
|
+
* and API response models.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// API Client Infrastructure Types
|
|
11
|
+
// ============================================================================
|
|
12
|
+
|
|
13
|
+
export interface ApiClientOptions {
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
token?: string;
|
|
16
|
+
debug?: boolean;
|
|
17
|
+
fetch?: typeof globalThis.fetch;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ApiClient {
|
|
21
|
+
get: (path: string, options?: RequestOptions) => Promise<any>;
|
|
22
|
+
post: (path: string, data?: any, options?: RequestOptions) => Promise<any>;
|
|
23
|
+
put: (path: string, data?: any, options?: RequestOptions) => Promise<any>;
|
|
24
|
+
delete: (path: string, options?: RequestOptions) => Promise<any>;
|
|
25
|
+
poll: (path: string, options?: PollOptions) => Promise<any>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface RequestOptions {
|
|
29
|
+
headers?: Record<string, string>;
|
|
30
|
+
searchParams?: Record<string, string>;
|
|
31
|
+
authRequired?: boolean;
|
|
32
|
+
customErrorHandler?: (response: Response) => Error | undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface PollOptions extends RequestOptions {
|
|
36
|
+
maxAttempts?: number;
|
|
37
|
+
initialDelay?: number;
|
|
38
|
+
maxDelay?: number;
|
|
39
|
+
successStatus?: number;
|
|
40
|
+
pendingStatus?: number;
|
|
41
|
+
resultExtractor?: (response: any) => any;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface DebugLogger {
|
|
45
|
+
(message: string, data?: any): void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ============================================================================
|
|
49
|
+
// API Response Models
|
|
50
|
+
// ============================================================================
|
|
51
|
+
|
|
52
|
+
export interface Integration {
|
|
53
|
+
key: string;
|
|
54
|
+
name: string;
|
|
55
|
+
description: string;
|
|
56
|
+
version: string;
|
|
57
|
+
category?: string;
|
|
58
|
+
actions: Action[];
|
|
59
|
+
triggers: Trigger[];
|
|
60
|
+
current_implementation_id?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface Action {
|
|
64
|
+
key: string;
|
|
65
|
+
name: string;
|
|
66
|
+
description: string;
|
|
67
|
+
appKey: string;
|
|
68
|
+
type: "create" | "update" | "search" | "delete" | "read";
|
|
69
|
+
inputFields: Field[];
|
|
70
|
+
outputFields: Field[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface Trigger {
|
|
74
|
+
key: string;
|
|
75
|
+
name: string;
|
|
76
|
+
description: string;
|
|
77
|
+
appKey: string;
|
|
78
|
+
type: "instant" | "polling" | "webhook";
|
|
79
|
+
outputFields: Field[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface Field {
|
|
83
|
+
key: string;
|
|
84
|
+
label: string;
|
|
85
|
+
type:
|
|
86
|
+
| "string"
|
|
87
|
+
| "number"
|
|
88
|
+
| "boolean"
|
|
89
|
+
| "datetime"
|
|
90
|
+
| "file"
|
|
91
|
+
| "object"
|
|
92
|
+
| "array";
|
|
93
|
+
required: boolean;
|
|
94
|
+
description?: string;
|
|
95
|
+
choices?: Choice[];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface Choice {
|
|
99
|
+
value: string | number;
|
|
100
|
+
label: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface ActionExecutionResult {
|
|
104
|
+
success: boolean;
|
|
105
|
+
data?: any;
|
|
106
|
+
error?: string;
|
|
107
|
+
metadata?: {
|
|
108
|
+
executionTime?: number;
|
|
109
|
+
requestId?: string;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface ActionField {
|
|
114
|
+
key: string;
|
|
115
|
+
label?: string;
|
|
116
|
+
required: boolean;
|
|
117
|
+
type?: string;
|
|
118
|
+
helpText?: string;
|
|
119
|
+
helpTextHtml?: string;
|
|
120
|
+
choices?: ActionFieldChoice[];
|
|
121
|
+
default?: string;
|
|
122
|
+
placeholder?: string;
|
|
123
|
+
computed?: boolean;
|
|
124
|
+
customField?: boolean;
|
|
125
|
+
dependsOn?: string[];
|
|
126
|
+
format?: string;
|
|
127
|
+
inputFormat?: string[];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface ActionFieldChoice {
|
|
131
|
+
value: string | number;
|
|
132
|
+
label: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface NeedsRequest {
|
|
136
|
+
selected_api: string;
|
|
137
|
+
action: string;
|
|
138
|
+
type_of: string;
|
|
139
|
+
authentication_id?: number;
|
|
140
|
+
params?: Record<string, any>;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface NeedsResponse {
|
|
144
|
+
success: boolean;
|
|
145
|
+
needs?: ActionField[];
|
|
146
|
+
errors?: string[];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface Authentication {
|
|
150
|
+
id: number;
|
|
151
|
+
date: string;
|
|
152
|
+
lastchanged?: string;
|
|
153
|
+
account_id: number;
|
|
154
|
+
customuser_id?: number;
|
|
155
|
+
selected_api: string;
|
|
156
|
+
destination_selected_api?: string | null;
|
|
157
|
+
is_invite_only: boolean;
|
|
158
|
+
is_private: boolean;
|
|
159
|
+
shared_with_all: boolean;
|
|
160
|
+
is_stale?: string;
|
|
161
|
+
is_shared?: string;
|
|
162
|
+
marked_stale_at?: string | null;
|
|
163
|
+
label?: string | null;
|
|
164
|
+
identifier?: string | null;
|
|
165
|
+
title?: string | null;
|
|
166
|
+
url?: string;
|
|
167
|
+
groups?: string;
|
|
168
|
+
members?: string;
|
|
169
|
+
permissions?: Record<string, boolean>;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface AuthenticationsResponse {
|
|
173
|
+
count: number;
|
|
174
|
+
next?: string | null;
|
|
175
|
+
previous?: string | null;
|
|
176
|
+
results: Authentication[];
|
|
177
|
+
}
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
input: string;
|
|
3
|
-
output?: string;
|
|
4
|
-
target?: string;
|
|
5
|
-
cjs?: boolean;
|
|
6
|
-
minify?: boolean;
|
|
7
|
-
string?: boolean;
|
|
8
|
-
}
|
|
1
|
+
import type { BundleCodeOptions } from "./schemas";
|
|
9
2
|
|
|
10
3
|
/**
|
|
11
4
|
* Bundle TypeScript code into executable JavaScript
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { bundleCode } from "./index";
|
|
2
|
+
import { BundleCodeSchema } from "./schemas";
|
|
3
|
+
|
|
4
|
+
// Function registry info - imports both function and schema
|
|
5
|
+
export const bundleCodeInfo = {
|
|
6
|
+
name: bundleCode.name,
|
|
7
|
+
inputSchema: BundleCodeSchema,
|
|
8
|
+
implementation: bundleCode,
|
|
9
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { OutputPropertySchema } from "../../types/properties";
|
|
3
|
+
|
|
4
|
+
// Pure Zod schema - no resolver metadata!
|
|
5
|
+
export const BundleCodeSchema = z
|
|
6
|
+
.object({
|
|
7
|
+
input: z.string().min(1).describe("Input TypeScript file path to bundle"),
|
|
8
|
+
output: OutputPropertySchema.optional().describe(
|
|
9
|
+
"Output file path (defaults to input with .js extension)",
|
|
10
|
+
),
|
|
11
|
+
string: z
|
|
12
|
+
.boolean()
|
|
13
|
+
.default(false)
|
|
14
|
+
.describe("Return bundled code as string instead of writing to file"),
|
|
15
|
+
minify: z.boolean().default(false).describe("Minify the bundled output"),
|
|
16
|
+
target: z.string().default("es2017").describe("ECMAScript target version"),
|
|
17
|
+
cjs: z
|
|
18
|
+
.boolean()
|
|
19
|
+
.default(false)
|
|
20
|
+
.describe("Output CommonJS format instead of ESM"),
|
|
21
|
+
})
|
|
22
|
+
.describe("Bundle TypeScript code into executable JavaScript");
|
|
23
|
+
|
|
24
|
+
// Type inferred from schema (no additional function config needed for bundleCode)
|
|
25
|
+
export type BundleCodeOptions = z.infer<typeof BundleCodeSchema>;
|
|
26
|
+
|
|
27
|
+
// SDK function interface - ready to be mixed into main SDK interface
|
|
28
|
+
export interface BundleCodeSdkFunction {
|
|
29
|
+
bundleCode: (options: BundleCodeOptions) => Promise<string>;
|
|
30
|
+
}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import type { Action, ActionField
|
|
2
|
-
import { listActions } from "
|
|
3
|
-
import { listFields } from "
|
|
4
|
-
|
|
5
|
-
export interface GenerateTypesOptions extends FunctionConfig {
|
|
6
|
-
appKey: string;
|
|
7
|
-
authId?: number;
|
|
8
|
-
output?: string;
|
|
9
|
-
}
|
|
1
|
+
import type { Action, ActionField } from "../../types/domain";
|
|
2
|
+
import { listActions } from "../listActions";
|
|
3
|
+
import { listFields } from "../listFields";
|
|
4
|
+
import type { GenerateTypesOptions } from "./schemas";
|
|
10
5
|
|
|
11
6
|
interface ActionWithActionFields extends Omit<Action, "inputFields"> {
|
|
12
7
|
inputFields: ActionField[];
|
|
@@ -18,13 +13,17 @@ interface ActionWithActionFields extends Omit<Action, "inputFields"> {
|
|
|
18
13
|
* This function can be used standalone without instantiating a full SDK,
|
|
19
14
|
* which enables better tree-shaking in applications that only need this functionality.
|
|
20
15
|
*
|
|
21
|
-
* @param options - App key,
|
|
16
|
+
* @param options - App key, authentication ID, output path, and API configuration options
|
|
22
17
|
* @returns Promise<string> - Generated TypeScript code
|
|
23
18
|
*/
|
|
24
19
|
export async function generateTypes(
|
|
25
20
|
options: GenerateTypesOptions,
|
|
26
21
|
): Promise<string> {
|
|
27
|
-
const {
|
|
22
|
+
const {
|
|
23
|
+
appKey,
|
|
24
|
+
authenticationId,
|
|
25
|
+
output = `./types/${appKey}.d.ts`,
|
|
26
|
+
} = options;
|
|
28
27
|
|
|
29
28
|
// Parse app identifier (support app@version format)
|
|
30
29
|
const { app, version } = parseAppIdentifier(appKey);
|
|
@@ -51,15 +50,15 @@ export async function generateTypes(
|
|
|
51
50
|
// Fetch input fields for each action
|
|
52
51
|
const actionsWithFields: ActionWithActionFields[] = [];
|
|
53
52
|
|
|
54
|
-
if (
|
|
53
|
+
if (authenticationId) {
|
|
55
54
|
for (const action of actions) {
|
|
56
55
|
try {
|
|
57
56
|
const fields = await listFields({
|
|
58
57
|
...options,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
appKey: action.appKey,
|
|
59
|
+
actionKey: action.key,
|
|
60
|
+
actionType: action.type,
|
|
61
|
+
authenticationId: authenticationId,
|
|
63
62
|
});
|
|
64
63
|
actionsWithFields.push({ ...action, inputFields: fields });
|
|
65
64
|
} catch {
|
|
@@ -137,8 +136,15 @@ ${versionComment}
|
|
|
137
136
|
* Generated on: ${new Date().toISOString()}
|
|
138
137
|
*
|
|
139
138
|
* Usage:
|
|
140
|
-
* import type { ${appName}
|
|
141
|
-
* const sdk
|
|
139
|
+
* import type { ${appName}Sdk } from './path/to/this/file'
|
|
140
|
+
* const sdk = createZapierSdk() as unknown as ${appName}Sdk
|
|
141
|
+
*
|
|
142
|
+
* // Direct usage (per-call auth):
|
|
143
|
+
* await sdk.apps.${appKey}.search.user_by_email({ authenticationId: 123, inputs: { email } })
|
|
144
|
+
*
|
|
145
|
+
* // Factory usage (pinned auth):
|
|
146
|
+
* const my${appName} = sdk.apps.${appKey}({ authenticationId: 123 })
|
|
147
|
+
* await my${appName}.search.user_by_email({ inputs: { email } })
|
|
142
148
|
*/
|
|
143
149
|
|
|
144
150
|
import type { ActionExecutionOptions, ActionExecutionResult } from '@zapier/zapier-sdk'
|
|
@@ -197,17 +203,28 @@ import type { ActionExecutionOptions, ActionExecutionResult } from '@zapier/zapi
|
|
|
197
203
|
output += `}\n\n`;
|
|
198
204
|
});
|
|
199
205
|
|
|
200
|
-
// Generate the main app
|
|
201
|
-
output += `export interface ${appName}Actions {\n`;
|
|
202
|
-
output += ` run: {\n`;
|
|
203
|
-
output += ` ${appKey}: {\n`;
|
|
206
|
+
// Generate the main app SDK interface with factory pattern support
|
|
204
207
|
|
|
208
|
+
// Generate the app proxy interface (actions grouped by type)
|
|
209
|
+
output += `interface ${appName}AppProxy {\n`;
|
|
205
210
|
Object.keys(actionsByType).forEach((actionType) => {
|
|
206
211
|
const typeName = `${appName}${capitalize(actionType)}Actions`;
|
|
207
|
-
output += `
|
|
212
|
+
output += ` ${actionType}: ${typeName}\n`;
|
|
208
213
|
});
|
|
214
|
+
output += `}\n\n`;
|
|
215
|
+
|
|
216
|
+
// Generate the factory function interface
|
|
217
|
+
output += `interface ${appName}AppFactory {\n`;
|
|
218
|
+
output += ` (options: { authenticationId: number }): ${appName}AppProxy\n`;
|
|
219
|
+
output += `}\n\n`;
|
|
209
220
|
|
|
210
|
-
|
|
221
|
+
// Combine factory and direct access
|
|
222
|
+
output += `type ${appName}AppWithFactory = ${appName}AppFactory & ${appName}AppProxy\n\n`;
|
|
223
|
+
|
|
224
|
+
// Generate the main SDK interface
|
|
225
|
+
output += `export interface ${appName}Sdk {\n`;
|
|
226
|
+
output += ` apps: {\n`;
|
|
227
|
+
output += ` ${appKey}: ${appName}AppWithFactory\n`;
|
|
211
228
|
output += ` }\n`;
|
|
212
229
|
output += `}\n`;
|
|
213
230
|
|
|
@@ -231,11 +248,19 @@ ${versionComment}
|
|
|
231
248
|
|
|
232
249
|
import type { ActionExecutionOptions, ActionExecutionResult } from '@zapier/zapier-sdk'
|
|
233
250
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
251
|
+
interface ${appName}AppProxy {
|
|
252
|
+
// No actions available
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
interface ${appName}AppFactory {
|
|
256
|
+
(options: { authenticationId: number }): ${appName}AppProxy
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
type ${appName}AppWithFactory = ${appName}AppFactory & ${appName}AppProxy
|
|
260
|
+
|
|
261
|
+
export interface ${appName}Sdk {
|
|
262
|
+
apps: {
|
|
263
|
+
${appKey}: ${appName}AppWithFactory
|
|
239
264
|
}
|
|
240
265
|
}
|
|
241
266
|
`;
|
|
@@ -247,12 +272,26 @@ function capitalize(str: string): string {
|
|
|
247
272
|
|
|
248
273
|
function sanitizeActionName(actionKey: string): string {
|
|
249
274
|
// Ensure the action name is a valid TypeScript identifier
|
|
250
|
-
|
|
275
|
+
let sanitized = actionKey.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
276
|
+
|
|
277
|
+
// If it starts with a number, prepend an underscore
|
|
278
|
+
if (/^[0-9]/.test(sanitized)) {
|
|
279
|
+
sanitized = "_" + sanitized;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return sanitized;
|
|
251
283
|
}
|
|
252
284
|
|
|
253
285
|
function sanitizeFieldName(fieldKey: string): string {
|
|
254
286
|
// Ensure the field name is a valid TypeScript identifier
|
|
255
|
-
|
|
287
|
+
let sanitized = fieldKey.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
288
|
+
|
|
289
|
+
// If it starts with a number, prepend an underscore
|
|
290
|
+
if (/^[0-9]/.test(sanitized)) {
|
|
291
|
+
sanitized = "_" + sanitized;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return sanitized;
|
|
256
295
|
}
|
|
257
296
|
|
|
258
297
|
function escapeComment(comment: string): string {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { generateTypes } from "./index";
|
|
2
|
+
import { GenerateTypesSchema } from "./schemas";
|
|
3
|
+
|
|
4
|
+
// Function registry info - imports both function and schema
|
|
5
|
+
export const generateTypesInfo = {
|
|
6
|
+
name: generateTypes.name,
|
|
7
|
+
inputSchema: GenerateTypesSchema,
|
|
8
|
+
implementation: generateTypes,
|
|
9
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
AppKeyPropertySchema,
|
|
4
|
+
AuthenticationIdPropertySchema,
|
|
5
|
+
OutputPropertySchema,
|
|
6
|
+
DebugPropertySchema,
|
|
7
|
+
} from "../../types/properties";
|
|
8
|
+
|
|
9
|
+
// Pure Zod schema - no resolver metadata!
|
|
10
|
+
export const GenerateTypesSchema = z
|
|
11
|
+
.object({
|
|
12
|
+
appKey: AppKeyPropertySchema.describe("App key to generate SDK code for"),
|
|
13
|
+
authenticationId: AuthenticationIdPropertySchema.optional(),
|
|
14
|
+
output: OutputPropertySchema.optional().describe(
|
|
15
|
+
"Output file path (defaults to generated/<appKey>.ts)",
|
|
16
|
+
),
|
|
17
|
+
debug: DebugPropertySchema.describe(
|
|
18
|
+
"Enable debug logging during generation",
|
|
19
|
+
),
|
|
20
|
+
})
|
|
21
|
+
.describe("Generate TypeScript SDK code for a specific app");
|
|
22
|
+
|
|
23
|
+
// 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
|
+
};
|
|
34
|
+
|
|
35
|
+
// SDK function interface - ready to be mixed into main SDK interface
|
|
36
|
+
export interface GenerateTypesSdkFunction {
|
|
37
|
+
generateTypes: (options: GenerateTypesOptions) => Promise<string>;
|
|
38
|
+
}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import type { Action
|
|
2
|
-
import { listActions } from "
|
|
3
|
-
|
|
4
|
-
export interface GetActionOptions extends FunctionConfig {
|
|
5
|
-
app: string;
|
|
6
|
-
action: string;
|
|
7
|
-
type: string;
|
|
8
|
-
}
|
|
1
|
+
import type { Action } from "../../types/domain";
|
|
2
|
+
import { listActions } from "../listActions";
|
|
3
|
+
import type { GetActionOptions } from "./schemas";
|
|
9
4
|
|
|
10
5
|
/**
|
|
11
6
|
* Get a specific action by app, action key, and type
|
|
@@ -17,18 +12,22 @@ export interface GetActionOptions extends FunctionConfig {
|
|
|
17
12
|
* @returns Promise<Action>
|
|
18
13
|
*/
|
|
19
14
|
export async function getAction(options: GetActionOptions): Promise<Action> {
|
|
20
|
-
const {
|
|
15
|
+
const { appKey, actionKey, actionType } = options;
|
|
21
16
|
|
|
22
17
|
const actions = await listActions({
|
|
23
18
|
...options,
|
|
24
|
-
appKey:
|
|
19
|
+
appKey: appKey,
|
|
25
20
|
});
|
|
26
21
|
|
|
27
|
-
const action = actions.find(
|
|
22
|
+
const action = actions.find(
|
|
23
|
+
(a) => a.key === actionKey && a.type === actionType,
|
|
24
|
+
);
|
|
28
25
|
|
|
29
26
|
if (!action) {
|
|
30
|
-
throw new Error(`Action not found: ${actionKey} with type ${
|
|
27
|
+
throw new Error(`Action not found: ${actionKey} with type ${actionType}`);
|
|
31
28
|
}
|
|
32
29
|
|
|
33
30
|
return action;
|
|
34
31
|
}
|
|
32
|
+
|
|
33
|
+
// No registry info here - moved to info.ts for proper tree-shaking
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getAction } from "./index";
|
|
2
|
+
import { GetActionSchema } from "./schemas";
|
|
3
|
+
|
|
4
|
+
// Function registry info - imports both function and schema
|
|
5
|
+
export const getActionInfo = {
|
|
6
|
+
name: getAction.name,
|
|
7
|
+
inputSchema: GetActionSchema,
|
|
8
|
+
implementation: getAction,
|
|
9
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
AppKeyPropertySchema,
|
|
4
|
+
ActionTypePropertySchema,
|
|
5
|
+
ActionKeyPropertySchema,
|
|
6
|
+
} from "../../types/properties";
|
|
7
|
+
import type { Action } from "../../types/domain";
|
|
8
|
+
|
|
9
|
+
// Pure Zod schema - no resolver metadata!
|
|
10
|
+
export const GetActionSchema = z
|
|
11
|
+
.object({
|
|
12
|
+
appKey: AppKeyPropertySchema,
|
|
13
|
+
actionType: ActionTypePropertySchema,
|
|
14
|
+
actionKey: ActionKeyPropertySchema,
|
|
15
|
+
})
|
|
16
|
+
.describe("Get detailed information about a specific action");
|
|
17
|
+
|
|
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
|
+
};
|
|
31
|
+
|
|
32
|
+
// SDK function interface - ready to be mixed into main SDK interface
|
|
33
|
+
export interface GetActionSdkFunction {
|
|
34
|
+
getAction: (options: GetActionOptions) => Promise<Action>;
|
|
35
|
+
}
|