@zapier/zapier-sdk 0.0.2 → 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 -76
- package/dist/api/types.js +9 -0
- package/dist/functions/bundleCode/index.d.ts +11 -0
- package/dist/functions/bundleCode/index.js +91 -0
- 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/index.d.ts +11 -0
- package/dist/functions/generateTypes/index.js +305 -0
- 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/index.d.ts +12 -0
- package/dist/functions/getAction/index.js +26 -0
- 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/index.d.ts +12 -0
- package/dist/functions/getApp/index.js +37 -0
- 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/index.d.ts +12 -0
- package/dist/functions/listActions/index.js +128 -0
- 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/index.d.ts +12 -0
- package/dist/functions/listApps/index.js +50 -0
- 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/index.d.ts +12 -0
- package/dist/functions/listAuths/index.js +118 -0
- 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/index.d.ts +12 -0
- package/dist/functions/listFields/index.js +65 -0
- 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/index.d.ts +12 -0
- package/dist/functions/runAction/index.js +157 -0
- 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 +15 -3
- package/dist/index.js +27 -4
- 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/{types.ts → api/types.ts} +51 -118
- package/src/functions/bundleCode/index.ts +78 -0
- package/src/functions/bundleCode/info.ts +9 -0
- package/src/functions/bundleCode/schemas.ts +30 -0
- package/src/functions/generateTypes/index.ts +348 -0
- package/src/functions/generateTypes/info.ts +9 -0
- package/src/functions/generateTypes/schemas.ts +38 -0
- package/src/functions/getAction/index.ts +33 -0
- package/src/functions/getAction/info.ts +9 -0
- package/src/functions/getAction/schemas.ts +35 -0
- package/src/functions/getApp/index.ts +41 -0
- package/src/functions/getApp/info.ts +9 -0
- package/src/functions/getApp/schemas.ts +31 -0
- package/src/functions/listActions/index.ts +149 -0
- package/src/functions/listActions/info.ts +9 -0
- package/src/functions/listActions/schemas.ts +40 -0
- package/src/functions/listApps/index.ts +60 -0
- package/src/functions/listApps/info.ts +9 -0
- package/src/functions/listApps/schemas.ts +43 -0
- package/src/functions/listAuths/index.ts +153 -0
- package/src/functions/listAuths/info.ts +9 -0
- package/src/functions/listAuths/schemas.ts +48 -0
- package/src/functions/listFields/index.ts +86 -0
- package/src/functions/listFields/info.ts +9 -0
- package/src/functions/listFields/schemas.ts +46 -0
- package/src/functions/runAction/index.ts +258 -0
- package/src/functions/runAction/info.ts +9 -0
- package/src/functions/runAction/schemas.ts +41 -0
- package/src/index.ts +24 -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 -51
- package/dist/actions-sdk.js +0 -1194
- 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 -1685
- package/src/output-schemas.ts +0 -196
- package/src/schemas.ts +0 -467
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BundleCodeSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const properties_1 = require("../../types/properties");
|
|
6
|
+
// Pure Zod schema - no resolver metadata!
|
|
7
|
+
exports.BundleCodeSchema = zod_1.z
|
|
8
|
+
.object({
|
|
9
|
+
input: zod_1.z.string().min(1).describe("Input TypeScript file path to bundle"),
|
|
10
|
+
output: properties_1.OutputPropertySchema.optional().describe("Output file path (defaults to input with .js extension)"),
|
|
11
|
+
string: zod_1.z
|
|
12
|
+
.boolean()
|
|
13
|
+
.default(false)
|
|
14
|
+
.describe("Return bundled code as string instead of writing to file"),
|
|
15
|
+
minify: zod_1.z.boolean().default(false).describe("Minify the bundled output"),
|
|
16
|
+
target: zod_1.z.string().default("es2017").describe("ECMAScript target version"),
|
|
17
|
+
cjs: zod_1.z
|
|
18
|
+
.boolean()
|
|
19
|
+
.default(false)
|
|
20
|
+
.describe("Output CommonJS format instead of ESM"),
|
|
21
|
+
})
|
|
22
|
+
.describe("Bundle TypeScript code into executable JavaScript");
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { GenerateTypesOptions } from "./schemas";
|
|
2
|
+
/**
|
|
3
|
+
* Generate TypeScript types for a specific app
|
|
4
|
+
*
|
|
5
|
+
* This function can be used standalone without instantiating a full SDK,
|
|
6
|
+
* which enables better tree-shaking in applications that only need this functionality.
|
|
7
|
+
*
|
|
8
|
+
* @param options - App key, authentication ID, output path, and API configuration options
|
|
9
|
+
* @returns Promise<string> - Generated TypeScript code
|
|
10
|
+
*/
|
|
11
|
+
export declare function generateTypes(options: GenerateTypesOptions): Promise<string>;
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.generateTypes = generateTypes;
|
|
37
|
+
const listActions_1 = require("../listActions");
|
|
38
|
+
const listFields_1 = require("../listFields");
|
|
39
|
+
/**
|
|
40
|
+
* Generate TypeScript types for a specific app
|
|
41
|
+
*
|
|
42
|
+
* This function can be used standalone without instantiating a full SDK,
|
|
43
|
+
* which enables better tree-shaking in applications that only need this functionality.
|
|
44
|
+
*
|
|
45
|
+
* @param options - App key, authentication ID, output path, and API configuration options
|
|
46
|
+
* @returns Promise<string> - Generated TypeScript code
|
|
47
|
+
*/
|
|
48
|
+
async function generateTypes(options) {
|
|
49
|
+
const { appKey, authenticationId, output = `./types/${appKey}.d.ts`, } = options;
|
|
50
|
+
// Parse app identifier (support app@version format)
|
|
51
|
+
const { app, version } = parseAppIdentifier(appKey);
|
|
52
|
+
// Fetch all actions for the app
|
|
53
|
+
const actions = await (0, listActions_1.listActions)({
|
|
54
|
+
...options,
|
|
55
|
+
appKey: app,
|
|
56
|
+
});
|
|
57
|
+
if (actions.length === 0) {
|
|
58
|
+
const typeDefinitions = generateEmptyTypesFile(app, version);
|
|
59
|
+
if (output) {
|
|
60
|
+
const fs = await Promise.resolve().then(() => __importStar(require("fs")));
|
|
61
|
+
const path = await Promise.resolve().then(() => __importStar(require("path")));
|
|
62
|
+
fs.mkdirSync(path.dirname(output), { recursive: true });
|
|
63
|
+
fs.writeFileSync(output, typeDefinitions, "utf8");
|
|
64
|
+
}
|
|
65
|
+
return typeDefinitions;
|
|
66
|
+
}
|
|
67
|
+
// Fetch input fields for each action
|
|
68
|
+
const actionsWithFields = [];
|
|
69
|
+
if (authenticationId) {
|
|
70
|
+
for (const action of actions) {
|
|
71
|
+
try {
|
|
72
|
+
const fields = await (0, listFields_1.listFields)({
|
|
73
|
+
...options,
|
|
74
|
+
appKey: action.appKey,
|
|
75
|
+
actionKey: action.key,
|
|
76
|
+
actionType: action.type,
|
|
77
|
+
authenticationId: authenticationId,
|
|
78
|
+
});
|
|
79
|
+
actionsWithFields.push({ ...action, inputFields: fields });
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// If we can't get fields for an action, include it without fields
|
|
83
|
+
actionsWithFields.push({ ...action, inputFields: [] });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// Convert actions to have empty input fields (will generate generic types)
|
|
89
|
+
actions.forEach((action) => {
|
|
90
|
+
actionsWithFields.push({ ...action, inputFields: [] });
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
// Generate TypeScript types
|
|
94
|
+
const typeDefinitions = generateTypeDefinitions(app, actionsWithFields, version);
|
|
95
|
+
// Write to file if output path specified
|
|
96
|
+
if (output) {
|
|
97
|
+
const fs = await Promise.resolve().then(() => __importStar(require("fs")));
|
|
98
|
+
const path = await Promise.resolve().then(() => __importStar(require("path")));
|
|
99
|
+
fs.mkdirSync(path.dirname(output), { recursive: true });
|
|
100
|
+
fs.writeFileSync(output, typeDefinitions, "utf8");
|
|
101
|
+
}
|
|
102
|
+
return typeDefinitions;
|
|
103
|
+
}
|
|
104
|
+
function parseAppIdentifier(identifier) {
|
|
105
|
+
const parts = identifier.split("@");
|
|
106
|
+
return {
|
|
107
|
+
app: parts[0],
|
|
108
|
+
version: parts[1],
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function generateTypeDefinitions(appKey, actions, version) {
|
|
112
|
+
// Handle empty actions
|
|
113
|
+
if (actions.length === 0) {
|
|
114
|
+
return generateEmptyTypesFile(appKey, version);
|
|
115
|
+
}
|
|
116
|
+
// Group actions by type
|
|
117
|
+
const actionsByType = actions.reduce((acc, action) => {
|
|
118
|
+
if (!acc[action.type]) {
|
|
119
|
+
acc[action.type] = [];
|
|
120
|
+
}
|
|
121
|
+
acc[action.type].push(action);
|
|
122
|
+
return acc;
|
|
123
|
+
}, {});
|
|
124
|
+
const appName = capitalize(appKey);
|
|
125
|
+
const versionComment = version
|
|
126
|
+
? ` * Generated for ${appKey}@${version}`
|
|
127
|
+
: ` * Generated for ${appKey}`;
|
|
128
|
+
let output = `/* eslint-disable @typescript-eslint/naming-convention */
|
|
129
|
+
/**
|
|
130
|
+
* Auto-generated TypeScript types for Zapier ${appKey} actions
|
|
131
|
+
${versionComment}
|
|
132
|
+
* Generated on: ${new Date().toISOString()}
|
|
133
|
+
*
|
|
134
|
+
* Usage:
|
|
135
|
+
* import type { ${appName}Sdk } from './path/to/this/file'
|
|
136
|
+
* const sdk = createZapierSdk() as unknown as ${appName}Sdk
|
|
137
|
+
*
|
|
138
|
+
* // Direct usage (per-call auth):
|
|
139
|
+
* await sdk.apps.${appKey}.search.user_by_email({ authenticationId: 123, inputs: { email } })
|
|
140
|
+
*
|
|
141
|
+
* // Factory usage (pinned auth):
|
|
142
|
+
* const my${appName} = sdk.apps.${appKey}({ authenticationId: 123 })
|
|
143
|
+
* await my${appName}.search.user_by_email({ inputs: { email } })
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
import type { ActionExecutionOptions, ActionExecutionResult } from '@zapier/zapier-sdk'
|
|
147
|
+
|
|
148
|
+
`;
|
|
149
|
+
// Generate input types for each action
|
|
150
|
+
actions.forEach((action) => {
|
|
151
|
+
if (action.inputFields.length > 0) {
|
|
152
|
+
const inputTypeName = `${appName}${capitalize(action.type)}${capitalize(sanitizeActionName(action.key))}Inputs`;
|
|
153
|
+
output += `interface ${inputTypeName} {\n`;
|
|
154
|
+
action.inputFields.forEach((field) => {
|
|
155
|
+
const isOptional = !field.required;
|
|
156
|
+
const fieldType = mapFieldTypeToTypeScript(field);
|
|
157
|
+
const description = field.helpText
|
|
158
|
+
? ` /** ${escapeComment(field.helpText)} */\n`
|
|
159
|
+
: "";
|
|
160
|
+
output += `${description} ${sanitizeFieldName(field.key)}${isOptional ? "?" : ""}: ${fieldType}\n`;
|
|
161
|
+
});
|
|
162
|
+
output += `}\n\n`;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
// Generate action type interfaces for each action type
|
|
166
|
+
Object.entries(actionsByType).forEach(([actionType, typeActions]) => {
|
|
167
|
+
const typeName = `${appName}${capitalize(actionType)}Actions`;
|
|
168
|
+
output += `interface ${typeName} {\n`;
|
|
169
|
+
typeActions.forEach((action) => {
|
|
170
|
+
const actionName = sanitizeActionName(action.key);
|
|
171
|
+
const description = action.description
|
|
172
|
+
? ` /** ${escapeComment(action.description)} */\n`
|
|
173
|
+
: "";
|
|
174
|
+
// Generate type-safe action method signature
|
|
175
|
+
if (action.inputFields.length > 0) {
|
|
176
|
+
const inputTypeName = `${appName}${capitalize(action.type)}${capitalize(sanitizeActionName(action.key))}Inputs`;
|
|
177
|
+
output += `${description} ${actionName}: (options: { inputs: ${inputTypeName} } & Omit<ActionExecutionOptions, 'inputs'>) => Promise<ActionExecutionResult>\n`;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
// No specific input fields available - use generic Record<string, any> for inputs
|
|
181
|
+
output += `${description} ${actionName}: (options?: { inputs?: Record<string, any> } & ActionExecutionOptions) => Promise<ActionExecutionResult>\n`;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
output += `}\n\n`;
|
|
185
|
+
});
|
|
186
|
+
// Generate the main app SDK interface with factory pattern support
|
|
187
|
+
// Generate the app proxy interface (actions grouped by type)
|
|
188
|
+
output += `interface ${appName}AppProxy {\n`;
|
|
189
|
+
Object.keys(actionsByType).forEach((actionType) => {
|
|
190
|
+
const typeName = `${appName}${capitalize(actionType)}Actions`;
|
|
191
|
+
output += ` ${actionType}: ${typeName}\n`;
|
|
192
|
+
});
|
|
193
|
+
output += `}\n\n`;
|
|
194
|
+
// Generate the factory function interface
|
|
195
|
+
output += `interface ${appName}AppFactory {\n`;
|
|
196
|
+
output += ` (options: { authenticationId: number }): ${appName}AppProxy\n`;
|
|
197
|
+
output += `}\n\n`;
|
|
198
|
+
// Combine factory and direct access
|
|
199
|
+
output += `type ${appName}AppWithFactory = ${appName}AppFactory & ${appName}AppProxy\n\n`;
|
|
200
|
+
// Generate the main SDK interface
|
|
201
|
+
output += `export interface ${appName}Sdk {\n`;
|
|
202
|
+
output += ` apps: {\n`;
|
|
203
|
+
output += ` ${appKey}: ${appName}AppWithFactory\n`;
|
|
204
|
+
output += ` }\n`;
|
|
205
|
+
output += `}\n`;
|
|
206
|
+
return output;
|
|
207
|
+
}
|
|
208
|
+
function generateEmptyTypesFile(appKey, version) {
|
|
209
|
+
const appName = capitalize(appKey);
|
|
210
|
+
const versionComment = version
|
|
211
|
+
? ` * Generated for ${appKey}@${version}`
|
|
212
|
+
: ` * Generated for ${appKey}`;
|
|
213
|
+
return `/* eslint-disable @typescript-eslint/naming-convention */
|
|
214
|
+
/**
|
|
215
|
+
* Auto-generated TypeScript types for Zapier ${appKey} actions
|
|
216
|
+
${versionComment}
|
|
217
|
+
* Generated on: ${new Date().toISOString()}
|
|
218
|
+
*
|
|
219
|
+
* No actions found for this app.
|
|
220
|
+
*/
|
|
221
|
+
|
|
222
|
+
import type { ActionExecutionOptions, ActionExecutionResult } from '@zapier/zapier-sdk'
|
|
223
|
+
|
|
224
|
+
interface ${appName}AppProxy {
|
|
225
|
+
// No actions available
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
interface ${appName}AppFactory {
|
|
229
|
+
(options: { authenticationId: number }): ${appName}AppProxy
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
type ${appName}AppWithFactory = ${appName}AppFactory & ${appName}AppProxy
|
|
233
|
+
|
|
234
|
+
export interface ${appName}Sdk {
|
|
235
|
+
apps: {
|
|
236
|
+
${appKey}: ${appName}AppWithFactory
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
`;
|
|
240
|
+
}
|
|
241
|
+
function capitalize(str) {
|
|
242
|
+
return str.charAt(0).toUpperCase() + str.slice(1).replace(/[-_]/g, "");
|
|
243
|
+
}
|
|
244
|
+
function sanitizeActionName(actionKey) {
|
|
245
|
+
// Ensure the action name is a valid TypeScript identifier
|
|
246
|
+
let sanitized = actionKey.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
247
|
+
// If it starts with a number, prepend an underscore
|
|
248
|
+
if (/^[0-9]/.test(sanitized)) {
|
|
249
|
+
sanitized = "_" + sanitized;
|
|
250
|
+
}
|
|
251
|
+
return sanitized;
|
|
252
|
+
}
|
|
253
|
+
function sanitizeFieldName(fieldKey) {
|
|
254
|
+
// Ensure the field name is a valid TypeScript identifier
|
|
255
|
+
let sanitized = fieldKey.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
256
|
+
// If it starts with a number, prepend an underscore
|
|
257
|
+
if (/^[0-9]/.test(sanitized)) {
|
|
258
|
+
sanitized = "_" + sanitized;
|
|
259
|
+
}
|
|
260
|
+
return sanitized;
|
|
261
|
+
}
|
|
262
|
+
function escapeComment(comment) {
|
|
263
|
+
// Escape comment text to prevent breaking the JSDoc comment
|
|
264
|
+
return comment.replace(/\*\//g, "*\\/").replace(/\r?\n/g, " ");
|
|
265
|
+
}
|
|
266
|
+
function mapFieldTypeToTypeScript(field) {
|
|
267
|
+
// Handle choices (enum-like fields)
|
|
268
|
+
if (field.choices && field.choices.length > 0) {
|
|
269
|
+
const choiceValues = field.choices
|
|
270
|
+
.filter((choice) => choice.value !== undefined &&
|
|
271
|
+
choice.value !== null &&
|
|
272
|
+
choice.value !== "")
|
|
273
|
+
.map((choice) => typeof choice.value === "string" ? `"${choice.value}"` : choice.value);
|
|
274
|
+
if (choiceValues.length > 0) {
|
|
275
|
+
return choiceValues.join(" | ");
|
|
276
|
+
}
|
|
277
|
+
// If all choices were filtered out, fall through to default type handling
|
|
278
|
+
}
|
|
279
|
+
// Map Zapier field types to TypeScript types
|
|
280
|
+
switch (field.type?.toLowerCase()) {
|
|
281
|
+
case "string":
|
|
282
|
+
case "text":
|
|
283
|
+
case "email":
|
|
284
|
+
case "url":
|
|
285
|
+
case "password":
|
|
286
|
+
return "string";
|
|
287
|
+
case "integer":
|
|
288
|
+
case "number":
|
|
289
|
+
return "number";
|
|
290
|
+
case "boolean":
|
|
291
|
+
return "boolean";
|
|
292
|
+
case "datetime":
|
|
293
|
+
case "date":
|
|
294
|
+
return "string"; // ISO date strings
|
|
295
|
+
case "file":
|
|
296
|
+
return "string"; // File URL or content
|
|
297
|
+
case "array":
|
|
298
|
+
return "any[]";
|
|
299
|
+
case "object":
|
|
300
|
+
return "Record<string, any>";
|
|
301
|
+
default:
|
|
302
|
+
// Default to string for unknown types, with union for common cases
|
|
303
|
+
return "string | number | boolean";
|
|
304
|
+
}
|
|
305
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { generateTypes } from "./index";
|
|
2
|
+
export declare const generateTypesInfo: {
|
|
3
|
+
name: string;
|
|
4
|
+
inputSchema: import("zod").ZodObject<{
|
|
5
|
+
appKey: import("zod").ZodString;
|
|
6
|
+
authenticationId: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
7
|
+
output: import("zod").ZodOptional<import("zod").ZodString>;
|
|
8
|
+
debug: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
9
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
10
|
+
debug: boolean;
|
|
11
|
+
appKey: string;
|
|
12
|
+
authenticationId?: number | undefined;
|
|
13
|
+
output?: string | undefined;
|
|
14
|
+
}, {
|
|
15
|
+
appKey: string;
|
|
16
|
+
debug?: boolean | undefined;
|
|
17
|
+
authenticationId?: number | undefined;
|
|
18
|
+
output?: string | undefined;
|
|
19
|
+
}>;
|
|
20
|
+
implementation: typeof generateTypes;
|
|
21
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateTypesInfo = void 0;
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
const schemas_1 = require("./schemas");
|
|
6
|
+
// Function registry info - imports both function and schema
|
|
7
|
+
exports.generateTypesInfo = {
|
|
8
|
+
name: index_1.generateTypes.name,
|
|
9
|
+
inputSchema: schemas_1.GenerateTypesSchema,
|
|
10
|
+
implementation: index_1.generateTypes,
|
|
11
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const GenerateTypesSchema: z.ZodObject<{
|
|
3
|
+
appKey: z.ZodString;
|
|
4
|
+
authenticationId: z.ZodOptional<z.ZodNumber>;
|
|
5
|
+
output: z.ZodOptional<z.ZodString>;
|
|
6
|
+
debug: z.ZodDefault<z.ZodBoolean>;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
debug: boolean;
|
|
9
|
+
appKey: string;
|
|
10
|
+
authenticationId?: number | undefined;
|
|
11
|
+
output?: string | undefined;
|
|
12
|
+
}, {
|
|
13
|
+
appKey: string;
|
|
14
|
+
debug?: boolean | undefined;
|
|
15
|
+
authenticationId?: number | undefined;
|
|
16
|
+
output?: string | undefined;
|
|
17
|
+
}>;
|
|
18
|
+
export type GenerateTypesOptions = z.infer<typeof GenerateTypesSchema> & {
|
|
19
|
+
/** Base URL for Zapier API */
|
|
20
|
+
baseUrl?: string;
|
|
21
|
+
/** Authentication token */
|
|
22
|
+
token?: string;
|
|
23
|
+
/** Optional pre-instantiated API client */
|
|
24
|
+
api?: any;
|
|
25
|
+
/** Custom fetch implementation */
|
|
26
|
+
fetch?: typeof globalThis.fetch;
|
|
27
|
+
};
|
|
28
|
+
export interface GenerateTypesSdkFunction {
|
|
29
|
+
generateTypes: (options: GenerateTypesOptions) => Promise<string>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GenerateTypesSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const properties_1 = require("../../types/properties");
|
|
6
|
+
// Pure Zod schema - no resolver metadata!
|
|
7
|
+
exports.GenerateTypesSchema = zod_1.z
|
|
8
|
+
.object({
|
|
9
|
+
appKey: properties_1.AppKeyPropertySchema.describe("App key to generate SDK code for"),
|
|
10
|
+
authenticationId: properties_1.AuthenticationIdPropertySchema.optional(),
|
|
11
|
+
output: properties_1.OutputPropertySchema.optional().describe("Output file path (defaults to generated/<appKey>.ts)"),
|
|
12
|
+
debug: properties_1.DebugPropertySchema.describe("Enable debug logging during generation"),
|
|
13
|
+
})
|
|
14
|
+
.describe("Generate TypeScript SDK code for a specific app");
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Action } from "../../types/domain";
|
|
2
|
+
import type { GetActionOptions } from "./schemas";
|
|
3
|
+
/**
|
|
4
|
+
* Get a specific action by app, action key, and type
|
|
5
|
+
*
|
|
6
|
+
* This function can be used standalone without instantiating a full SDK,
|
|
7
|
+
* which enables better tree-shaking in applications that only need this functionality.
|
|
8
|
+
*
|
|
9
|
+
* @param options - App key, action key, type, and API configuration options
|
|
10
|
+
* @returns Promise<Action>
|
|
11
|
+
*/
|
|
12
|
+
export declare function getAction(options: GetActionOptions): Promise<Action>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAction = getAction;
|
|
4
|
+
const listActions_1 = require("../listActions");
|
|
5
|
+
/**
|
|
6
|
+
* Get a specific action by app, action key, and type
|
|
7
|
+
*
|
|
8
|
+
* This function can be used standalone without instantiating a full SDK,
|
|
9
|
+
* which enables better tree-shaking in applications that only need this functionality.
|
|
10
|
+
*
|
|
11
|
+
* @param options - App key, action key, type, and API configuration options
|
|
12
|
+
* @returns Promise<Action>
|
|
13
|
+
*/
|
|
14
|
+
async function getAction(options) {
|
|
15
|
+
const { appKey, actionKey, actionType } = options;
|
|
16
|
+
const actions = await (0, listActions_1.listActions)({
|
|
17
|
+
...options,
|
|
18
|
+
appKey: appKey,
|
|
19
|
+
});
|
|
20
|
+
const action = actions.find((a) => a.key === actionKey && a.type === actionType);
|
|
21
|
+
if (!action) {
|
|
22
|
+
throw new Error(`Action not found: ${actionKey} with type ${actionType}`);
|
|
23
|
+
}
|
|
24
|
+
return action;
|
|
25
|
+
}
|
|
26
|
+
// No registry info here - moved to info.ts for proper tree-shaking
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getAction } from "./index";
|
|
2
|
+
export declare const getActionInfo: {
|
|
3
|
+
name: string;
|
|
4
|
+
inputSchema: import("zod").ZodObject<{
|
|
5
|
+
appKey: import("zod").ZodString;
|
|
6
|
+
actionType: import("zod").ZodEnum<["read", "write", "search", "create", "update", "delete"]>;
|
|
7
|
+
actionKey: import("zod").ZodString;
|
|
8
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
9
|
+
appKey: string;
|
|
10
|
+
actionType: "create" | "update" | "search" | "delete" | "read" | "write";
|
|
11
|
+
actionKey: string;
|
|
12
|
+
}, {
|
|
13
|
+
appKey: string;
|
|
14
|
+
actionType: "create" | "update" | "search" | "delete" | "read" | "write";
|
|
15
|
+
actionKey: string;
|
|
16
|
+
}>;
|
|
17
|
+
implementation: typeof getAction;
|
|
18
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getActionInfo = void 0;
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
const schemas_1 = require("./schemas");
|
|
6
|
+
// Function registry info - imports both function and schema
|
|
7
|
+
exports.getActionInfo = {
|
|
8
|
+
name: index_1.getAction.name,
|
|
9
|
+
inputSchema: schemas_1.GetActionSchema,
|
|
10
|
+
implementation: index_1.getAction,
|
|
11
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { Action } from "../../types/domain";
|
|
3
|
+
export declare const GetActionSchema: z.ZodObject<{
|
|
4
|
+
appKey: z.ZodString;
|
|
5
|
+
actionType: z.ZodEnum<["read", "write", "search", "create", "update", "delete"]>;
|
|
6
|
+
actionKey: z.ZodString;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
appKey: string;
|
|
9
|
+
actionType: "create" | "update" | "search" | "delete" | "read" | "write";
|
|
10
|
+
actionKey: string;
|
|
11
|
+
}, {
|
|
12
|
+
appKey: string;
|
|
13
|
+
actionType: "create" | "update" | "search" | "delete" | "read" | "write";
|
|
14
|
+
actionKey: string;
|
|
15
|
+
}>;
|
|
16
|
+
export type GetActionOptions = z.infer<typeof GetActionSchema> & {
|
|
17
|
+
/** Base URL for Zapier API */
|
|
18
|
+
baseUrl?: string;
|
|
19
|
+
/** Authentication token */
|
|
20
|
+
token?: string;
|
|
21
|
+
/** Optional pre-instantiated API client */
|
|
22
|
+
api?: any;
|
|
23
|
+
/** Enable debug logging */
|
|
24
|
+
debug?: boolean;
|
|
25
|
+
/** Custom fetch implementation */
|
|
26
|
+
fetch?: typeof globalThis.fetch;
|
|
27
|
+
};
|
|
28
|
+
export interface GetActionSdkFunction {
|
|
29
|
+
getAction: (options: GetActionOptions) => Promise<Action>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetActionSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const properties_1 = require("../../types/properties");
|
|
6
|
+
// Pure Zod schema - no resolver metadata!
|
|
7
|
+
exports.GetActionSchema = zod_1.z
|
|
8
|
+
.object({
|
|
9
|
+
appKey: properties_1.AppKeyPropertySchema,
|
|
10
|
+
actionType: properties_1.ActionTypePropertySchema,
|
|
11
|
+
actionKey: properties_1.ActionKeyPropertySchema,
|
|
12
|
+
})
|
|
13
|
+
.describe("Get detailed information about a specific action");
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Integration } from "../../types/domain";
|
|
2
|
+
import type { GetAppOptions } from "./schemas";
|
|
3
|
+
/**
|
|
4
|
+
* Get a specific app by key
|
|
5
|
+
*
|
|
6
|
+
* This function can be used standalone without instantiating a full SDK,
|
|
7
|
+
* which enables better tree-shaking in applications that only need this functionality.
|
|
8
|
+
*
|
|
9
|
+
* @param options - App key and API configuration options
|
|
10
|
+
* @returns Promise<Integration>
|
|
11
|
+
*/
|
|
12
|
+
export declare function getApp(options: GetAppOptions): Promise<Integration>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getApp = getApp;
|
|
4
|
+
const api_1 = require("../../api");
|
|
5
|
+
const domain_1 = require("../../types/domain");
|
|
6
|
+
/**
|
|
7
|
+
* Get a specific app by key
|
|
8
|
+
*
|
|
9
|
+
* This function can be used standalone without instantiating a full SDK,
|
|
10
|
+
* which enables better tree-shaking in applications that only need this functionality.
|
|
11
|
+
*
|
|
12
|
+
* @param options - App key and API configuration options
|
|
13
|
+
* @returns Promise<Integration>
|
|
14
|
+
*/
|
|
15
|
+
async function getApp(options) {
|
|
16
|
+
const api = (0, api_1.getOrCreateApiClient)(options);
|
|
17
|
+
const { appKey } = options;
|
|
18
|
+
const app = await api.get(`/api/v4/apps/${appKey}/`, {
|
|
19
|
+
customErrorHandler: (response) => {
|
|
20
|
+
if (response.status === 404) {
|
|
21
|
+
return new domain_1.AppNotFoundError(appKey);
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
key: app.slug,
|
|
28
|
+
name: app.name,
|
|
29
|
+
description: app.description,
|
|
30
|
+
version: "1.0.0",
|
|
31
|
+
category: app.category?.name,
|
|
32
|
+
actions: [],
|
|
33
|
+
triggers: [],
|
|
34
|
+
current_implementation_id: app.current_implementation_id,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
// No registry info here - moved to info.ts for proper tree-shaking
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getApp } from "./index";
|
|
2
|
+
export declare const getAppInfo: {
|
|
3
|
+
name: string;
|
|
4
|
+
inputSchema: import("zod").ZodObject<{
|
|
5
|
+
appKey: import("zod").ZodString;
|
|
6
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
7
|
+
appKey: string;
|
|
8
|
+
}, {
|
|
9
|
+
appKey: string;
|
|
10
|
+
}>;
|
|
11
|
+
implementation: typeof getApp;
|
|
12
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAppInfo = void 0;
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
const schemas_1 = require("./schemas");
|
|
6
|
+
// Function registry info - imports both function and schema
|
|
7
|
+
exports.getAppInfo = {
|
|
8
|
+
name: index_1.getApp.name,
|
|
9
|
+
inputSchema: schemas_1.GetAppSchema,
|
|
10
|
+
implementation: index_1.getApp,
|
|
11
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { Integration } from "../../types/domain";
|
|
3
|
+
export declare const GetAppSchema: z.ZodObject<{
|
|
4
|
+
appKey: z.ZodString;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
appKey: string;
|
|
7
|
+
}, {
|
|
8
|
+
appKey: string;
|
|
9
|
+
}>;
|
|
10
|
+
export type GetAppOptions = z.infer<typeof GetAppSchema> & {
|
|
11
|
+
/** Base URL for Zapier API */
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
/** Authentication token */
|
|
14
|
+
token?: string;
|
|
15
|
+
/** Optional pre-instantiated API client */
|
|
16
|
+
api?: any;
|
|
17
|
+
/** Enable debug logging */
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
/** Custom fetch implementation */
|
|
20
|
+
fetch?: typeof globalThis.fetch;
|
|
21
|
+
};
|
|
22
|
+
export interface GetAppSdkFunction {
|
|
23
|
+
getApp: (options: GetAppOptions) => Promise<Integration>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetAppSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const properties_1 = require("../../types/properties");
|
|
6
|
+
// Pure Zod schema - no resolver metadata!
|
|
7
|
+
exports.GetAppSchema = zod_1.z
|
|
8
|
+
.object({
|
|
9
|
+
appKey: properties_1.AppKeyPropertySchema.describe("App key or slug to fetch (e.g., google-sheets, slack, github)"),
|
|
10
|
+
})
|
|
11
|
+
.describe("Get detailed information about a specific app");
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Action } from "../../types/domain";
|
|
2
|
+
import type { ListActionsOptions } from "./schemas";
|
|
3
|
+
/**
|
|
4
|
+
* List available actions with optional filtering
|
|
5
|
+
*
|
|
6
|
+
* This function can be used standalone without instantiating a full SDK,
|
|
7
|
+
* which enables better tree-shaking in applications that only need this functionality.
|
|
8
|
+
*
|
|
9
|
+
* @param options - Filtering and API configuration options
|
|
10
|
+
* @returns Promise<Action[]> with pagination metadata
|
|
11
|
+
*/
|
|
12
|
+
export declare function listActions(options?: Partial<ListActionsOptions>): Promise<Action[]>;
|