@zapier/zapier-sdk-cli 0.13.5 → 0.13.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +39 -0
- package/dist/cli.cjs +360 -82
- package/dist/cli.mjs +356 -78
- package/dist/index.cjs +359 -81
- package/dist/index.d.mts +155 -3
- package/dist/index.d.ts +155 -3
- package/dist/index.mjs +355 -77
- package/dist/package.json +1 -1
- package/dist/src/plugins/add/index.d.ts +4 -2
- package/dist/src/plugins/add/index.js +89 -98
- package/dist/src/plugins/buildManifest/index.d.ts +13 -0
- package/dist/src/plugins/buildManifest/index.js +81 -0
- package/dist/src/plugins/buildManifest/schemas.d.ts +56 -0
- package/dist/src/plugins/buildManifest/schemas.js +17 -0
- package/dist/src/plugins/generateAppTypes/index.d.ts +13 -0
- package/dist/src/plugins/generateAppTypes/index.js +169 -0
- package/dist/src/plugins/generateAppTypes/schemas.d.ts +72 -0
- package/dist/src/plugins/generateAppTypes/schemas.js +21 -0
- package/dist/src/plugins/index.d.ts +2 -0
- package/dist/src/plugins/index.js +2 -0
- package/dist/src/sdk.d.ts +4 -3
- package/dist/src/sdk.js +16 -14
- package/dist/src/types/sdk.d.ts +5 -0
- package/dist/src/types/sdk.js +1 -0
- package/dist/src/utils/constants.d.ts +1 -3
- package/dist/src/utils/constants.js +3 -4
- package/dist/src/utils/directory-detection.d.ts +5 -0
- package/dist/src/utils/directory-detection.js +21 -0
- package/dist/src/utils/manifest-helpers.d.ts +10 -0
- package/dist/src/utils/manifest-helpers.js +19 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/plugins/add/index.ts +123 -125
- package/src/plugins/buildManifest/index.test.ts +612 -0
- package/src/plugins/buildManifest/index.ts +128 -0
- package/src/plugins/buildManifest/schemas.ts +59 -0
- package/src/plugins/generateAppTypes/index.ts +235 -0
- package/src/plugins/generateAppTypes/schemas.ts +65 -0
- package/src/plugins/index.ts +2 -0
- package/src/sdk.ts +25 -21
- package/src/types/sdk.ts +8 -0
- package/src/utils/constants.ts +7 -6
- package/src/utils/directory-detection.ts +23 -0
- package/src/utils/manifest-helpers.ts +25 -0
- /package/dist/src/{plugins/add → generators}/ast-generator.d.ts +0 -0
- /package/dist/src/{plugins/add → generators}/ast-generator.js +0 -0
- /package/src/{plugins/add → generators}/ast-generator.ts +0 -0
package/dist/index.cjs
CHANGED
|
@@ -5,16 +5,16 @@ var open = require('open');
|
|
|
5
5
|
var crypto = require('crypto');
|
|
6
6
|
var express = require('express');
|
|
7
7
|
var pkceChallenge = require('pkce-challenge');
|
|
8
|
+
var zapierSdkCliLogin = require('@zapier/zapier-sdk-cli-login');
|
|
8
9
|
var ora = require('ora');
|
|
9
10
|
var chalk = require('chalk');
|
|
10
|
-
var zapierSdkCliLogin = require('@zapier/zapier-sdk-cli-login');
|
|
11
11
|
var zod = require('zod');
|
|
12
12
|
var zapierSdkMcp = require('@zapier/zapier-sdk-mcp');
|
|
13
13
|
var esbuild = require('esbuild');
|
|
14
14
|
var fs = require('fs');
|
|
15
15
|
var path = require('path');
|
|
16
|
-
var ts = require('typescript');
|
|
17
16
|
var promises = require('fs/promises');
|
|
17
|
+
var ts = require('typescript');
|
|
18
18
|
|
|
19
19
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
20
|
|
|
@@ -47,13 +47,8 @@ var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
|
47
47
|
var ts__namespace = /*#__PURE__*/_interopNamespace(ts);
|
|
48
48
|
|
|
49
49
|
// src/sdk.ts
|
|
50
|
-
|
|
51
|
-
// src/utils/constants.ts
|
|
52
|
-
var ZAPIER_BASE = "https://zapier.com";
|
|
53
|
-
var LOGIN_CLIENT_ID = "K5eEnRE9TTmSFATdkkWhKF8NOKwoiOnYAyIqJjae";
|
|
54
50
|
var LOGIN_PORTS = [49505, 50575, 52804, 55981, 61010, 63851];
|
|
55
51
|
var LOGIN_TIMEOUT_MS = 3e5;
|
|
56
|
-
var AUTH_MODE_HEADER = "X-Auth";
|
|
57
52
|
var spinPromise = async (promise, text) => {
|
|
58
53
|
const spinner = ora__default.default(text).start();
|
|
59
54
|
try {
|
|
@@ -192,9 +187,9 @@ var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
|
|
|
192
187
|
process.on("SIGINT", cleanup);
|
|
193
188
|
process.on("SIGTERM", cleanup);
|
|
194
189
|
const { code_verifier: codeVerifier, code_challenge: codeChallenge } = await pkceChallenge__default.default();
|
|
195
|
-
const authUrl = `${ZAPIER_BASE}/oauth/authorize/?${new URLSearchParams({
|
|
190
|
+
const authUrl = `${zapierSdkCliLogin.ZAPIER_BASE}/oauth/authorize/?${new URLSearchParams({
|
|
196
191
|
response_type: "code",
|
|
197
|
-
client_id: LOGIN_CLIENT_ID,
|
|
192
|
+
client_id: zapierSdkCliLogin.LOGIN_CLIENT_ID,
|
|
198
193
|
redirect_uri: redirectUri,
|
|
199
194
|
scope: "internal offline_access",
|
|
200
195
|
state: generateRandomString(),
|
|
@@ -237,17 +232,17 @@ var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
|
|
|
237
232
|
}
|
|
238
233
|
log_default.info("Exchanging authorization code for tokens...");
|
|
239
234
|
const { data } = await client_default.post(
|
|
240
|
-
`${ZAPIER_BASE}/oauth/token/`,
|
|
235
|
+
`${zapierSdkCliLogin.ZAPIER_BASE}/oauth/token/`,
|
|
241
236
|
{
|
|
242
237
|
grant_type: "authorization_code",
|
|
243
238
|
code: await promisedCode,
|
|
244
239
|
redirect_uri: redirectUri,
|
|
245
|
-
client_id: LOGIN_CLIENT_ID,
|
|
240
|
+
client_id: zapierSdkCliLogin.LOGIN_CLIENT_ID,
|
|
246
241
|
code_verifier: codeVerifier
|
|
247
242
|
},
|
|
248
243
|
{
|
|
249
244
|
headers: {
|
|
250
|
-
[AUTH_MODE_HEADER]: "no",
|
|
245
|
+
[zapierSdkCliLogin.AUTH_MODE_HEADER]: "no",
|
|
251
246
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
252
247
|
}
|
|
253
248
|
}
|
|
@@ -263,7 +258,7 @@ var LoginSchema = zod.z.object({
|
|
|
263
258
|
|
|
264
259
|
// package.json
|
|
265
260
|
var package_default = {
|
|
266
|
-
version: "0.13.
|
|
261
|
+
version: "0.13.7"};
|
|
267
262
|
|
|
268
263
|
// src/telemetry/builders.ts
|
|
269
264
|
function createCliBaseEvent(context = {}) {
|
|
@@ -551,6 +546,146 @@ var AddSchema = zod.z.object({
|
|
|
551
546
|
}).describe(
|
|
552
547
|
"Add apps with manifest locking and TypeScript type generation - updates .zapierrc with app versions and generates TypeScript definition files"
|
|
553
548
|
);
|
|
549
|
+
async function detectTypesOutputDirectory() {
|
|
550
|
+
const candidates = ["src", "lib"];
|
|
551
|
+
for (const candidate of candidates) {
|
|
552
|
+
try {
|
|
553
|
+
await promises.access(candidate);
|
|
554
|
+
return path.join(candidate, "zapier", "apps");
|
|
555
|
+
} catch {
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
return "./zapier/apps/";
|
|
559
|
+
}
|
|
560
|
+
var addPlugin = ({ sdk }) => {
|
|
561
|
+
const add = zapierSdk.createFunction(async function add2(options) {
|
|
562
|
+
const {
|
|
563
|
+
appKeys,
|
|
564
|
+
authenticationIds,
|
|
565
|
+
configPath,
|
|
566
|
+
typesOutput = await detectTypesOutputDirectory()
|
|
567
|
+
} = options;
|
|
568
|
+
const resolvedTypesOutput = path.resolve(typesOutput);
|
|
569
|
+
console.log(`\u{1F4E6} Adding ${appKeys.length} app(s)...`);
|
|
570
|
+
const appSlugAndKeyMap = /* @__PURE__ */ new Map();
|
|
571
|
+
const handleManifestProgress = (event) => {
|
|
572
|
+
switch (event.type) {
|
|
573
|
+
case "apps_lookup_start":
|
|
574
|
+
console.log(`\u{1F4E6} Looking up ${event.count} app(s)...`);
|
|
575
|
+
break;
|
|
576
|
+
case "app_found":
|
|
577
|
+
const displayName = event.app.slug ? `${event.app.slug} (${event.app.key})` : event.app.key;
|
|
578
|
+
appSlugAndKeyMap.set(event.app.key, displayName);
|
|
579
|
+
break;
|
|
580
|
+
case "apps_lookup_complete":
|
|
581
|
+
if (event.count === 0) {
|
|
582
|
+
console.warn("\u26A0\uFE0F No apps found");
|
|
583
|
+
}
|
|
584
|
+
break;
|
|
585
|
+
case "app_processing_start":
|
|
586
|
+
const appName = event.slug ? `${event.slug} (${event.appKey})` : event.appKey;
|
|
587
|
+
console.log(`\u{1F4E6} Adding ${appName}...`);
|
|
588
|
+
break;
|
|
589
|
+
case "manifest_updated":
|
|
590
|
+
const appDisplay = appSlugAndKeyMap.get(event.appKey) || event.appKey;
|
|
591
|
+
console.log(
|
|
592
|
+
`\u{1F4DD} Locked ${appDisplay} to ${event.appKey}@${event.version} using key '${event.manifestKey}'`
|
|
593
|
+
);
|
|
594
|
+
break;
|
|
595
|
+
case "app_processing_error":
|
|
596
|
+
const errorApp = appSlugAndKeyMap.get(event.appKey) || event.appKey;
|
|
597
|
+
console.warn(`\u26A0\uFE0F ${event.error} for ${errorApp}`);
|
|
598
|
+
break;
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
const handleTypesProgress = (event) => {
|
|
602
|
+
switch (event.type) {
|
|
603
|
+
case "authentications_lookup_start":
|
|
604
|
+
console.log(`\u{1F510} Looking up ${event.count} authentication(s)...`);
|
|
605
|
+
break;
|
|
606
|
+
case "authentications_lookup_complete":
|
|
607
|
+
console.log(`\u{1F510} Found ${event.count} authentication(s)`);
|
|
608
|
+
break;
|
|
609
|
+
case "authentication_matched":
|
|
610
|
+
const appWithAuth = appSlugAndKeyMap.get(event.appKey) || event.appKey;
|
|
611
|
+
console.log(
|
|
612
|
+
`\u{1F510} Using authentication ${event.authenticationId} (${event.authenticationTitle}) for ${appWithAuth}`
|
|
613
|
+
);
|
|
614
|
+
break;
|
|
615
|
+
case "authentication_not_matched":
|
|
616
|
+
const appWithoutAuth = appSlugAndKeyMap.get(event.appKey) || event.appKey;
|
|
617
|
+
console.warn(
|
|
618
|
+
`\u26A0\uFE0F No matching authentication found for ${appWithoutAuth}`
|
|
619
|
+
);
|
|
620
|
+
break;
|
|
621
|
+
case "file_written":
|
|
622
|
+
console.log(
|
|
623
|
+
`\u{1F527} Generated types for ${event.manifestKey} at ${event.filePath}`
|
|
624
|
+
);
|
|
625
|
+
break;
|
|
626
|
+
case "app_processing_error":
|
|
627
|
+
const errorApp = appSlugAndKeyMap.get(event.appKey) || event.appKey;
|
|
628
|
+
console.warn(`\u26A0\uFE0F ${event.error} for ${errorApp}`);
|
|
629
|
+
break;
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
const manifestResult = await sdk.buildManifest({
|
|
633
|
+
appKeys,
|
|
634
|
+
skipWrite: false,
|
|
635
|
+
configPath,
|
|
636
|
+
onProgress: handleManifestProgress
|
|
637
|
+
});
|
|
638
|
+
const typesResult = await sdk.generateAppTypes({
|
|
639
|
+
appKeys,
|
|
640
|
+
authenticationIds,
|
|
641
|
+
skipWrite: false,
|
|
642
|
+
typesOutputDirectory: resolvedTypesOutput,
|
|
643
|
+
onProgress: handleTypesProgress
|
|
644
|
+
});
|
|
645
|
+
const results = manifestResult.manifest?.apps || {};
|
|
646
|
+
const successfulApps = Object.keys(results).filter(
|
|
647
|
+
(manifestKey) => typesResult.writtenFiles?.[manifestKey]
|
|
648
|
+
);
|
|
649
|
+
if (successfulApps.length > 0) {
|
|
650
|
+
console.log(`\u2705 Added ${successfulApps.length} app(s) to manifest`);
|
|
651
|
+
}
|
|
652
|
+
const allErrors = [...manifestResult.errors, ...typesResult.errors];
|
|
653
|
+
if (allErrors.length > 0) {
|
|
654
|
+
console.warn(`
|
|
655
|
+
\u26A0\uFE0F ${allErrors.length} error(s) occurred:`);
|
|
656
|
+
allErrors.forEach(({ appKey, error }) => {
|
|
657
|
+
console.warn(` - ${appKey}: ${error}`);
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
}, AddSchema);
|
|
661
|
+
return {
|
|
662
|
+
add,
|
|
663
|
+
context: {
|
|
664
|
+
meta: {
|
|
665
|
+
add: {
|
|
666
|
+
categories: ["utility"],
|
|
667
|
+
inputSchema: AddSchema
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
};
|
|
673
|
+
var GenerateAppTypesSchema = zod.z.object({
|
|
674
|
+
appKeys: zod.z.array(zod.z.string().min(1, "App key cannot be empty")).min(1, "At least one app key is required").describe(
|
|
675
|
+
"One or more app keys to generate types for (e.g., 'slack', 'github', 'trello')"
|
|
676
|
+
),
|
|
677
|
+
authenticationIds: zod.z.array(zod.z.string()).optional().describe(
|
|
678
|
+
"Authentication IDs to use for type generation (e.g., ['123', '456'])"
|
|
679
|
+
),
|
|
680
|
+
skipWrite: zod.z.boolean().optional().describe(
|
|
681
|
+
"If true, returns type definitions without writing to disk. If false or omitted, writes type files."
|
|
682
|
+
),
|
|
683
|
+
typesOutputDirectory: zod.z.string().optional().describe(
|
|
684
|
+
"Directory for TypeScript type files. Required when skipWrite is false or omitted."
|
|
685
|
+
)
|
|
686
|
+
}).describe(
|
|
687
|
+
"Generate TypeScript type definitions for apps - can optionally write to disk or just return type strings"
|
|
688
|
+
);
|
|
554
689
|
var AstTypeGenerator = class {
|
|
555
690
|
constructor() {
|
|
556
691
|
this.factory = ts__namespace.factory;
|
|
@@ -1119,69 +1254,92 @@ Usage:
|
|
|
1119
1254
|
return Array.from(allKeys);
|
|
1120
1255
|
}
|
|
1121
1256
|
};
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1257
|
+
|
|
1258
|
+
// src/utils/manifest-helpers.ts
|
|
1259
|
+
function getManifestKey(app) {
|
|
1260
|
+
return app.slug || app.key;
|
|
1261
|
+
}
|
|
1262
|
+
function createManifestEntry(app) {
|
|
1263
|
+
if (!app.version) {
|
|
1264
|
+
throw new Error(
|
|
1265
|
+
`App ${app.key} does not have a version. Implementation ID: ${app.implementation_id}`
|
|
1266
|
+
);
|
|
1130
1267
|
}
|
|
1131
|
-
return
|
|
1268
|
+
return {
|
|
1269
|
+
implementationName: app.key,
|
|
1270
|
+
version: app.version
|
|
1271
|
+
};
|
|
1132
1272
|
}
|
|
1133
|
-
var
|
|
1134
|
-
const
|
|
1273
|
+
var generateAppTypesPlugin = ({ sdk }) => {
|
|
1274
|
+
const generateAppTypes = zapierSdk.createFunction(async function generateAppTypes2(options) {
|
|
1135
1275
|
const {
|
|
1136
1276
|
appKeys,
|
|
1137
1277
|
authenticationIds,
|
|
1138
|
-
|
|
1139
|
-
|
|
1278
|
+
skipWrite = false,
|
|
1279
|
+
typesOutputDirectory,
|
|
1280
|
+
onProgress
|
|
1140
1281
|
} = options;
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1282
|
+
if (!skipWrite && !typesOutputDirectory) {
|
|
1283
|
+
throw new Error(
|
|
1284
|
+
"typesOutputDirectory is required when skipWrite is false"
|
|
1285
|
+
);
|
|
1286
|
+
}
|
|
1287
|
+
const result = {
|
|
1288
|
+
typeDefinitions: {},
|
|
1289
|
+
errors: []
|
|
1290
|
+
};
|
|
1291
|
+
onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
|
|
1144
1292
|
const appsIterator = sdk.listApps({ appKeys }).items();
|
|
1145
1293
|
const apps = [];
|
|
1146
1294
|
for await (const app of appsIterator) {
|
|
1147
1295
|
apps.push(app);
|
|
1296
|
+
onProgress?.({ type: "app_found", app });
|
|
1148
1297
|
}
|
|
1298
|
+
onProgress?.({ type: "apps_lookup_complete", count: apps.length });
|
|
1149
1299
|
if (apps.length === 0) {
|
|
1150
|
-
|
|
1151
|
-
return;
|
|
1300
|
+
return result;
|
|
1152
1301
|
}
|
|
1153
|
-
|
|
1302
|
+
const authentications = [];
|
|
1154
1303
|
if (authenticationIds && authenticationIds.length > 0) {
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1304
|
+
onProgress?.({
|
|
1305
|
+
type: "authentications_lookup_start",
|
|
1306
|
+
count: authenticationIds.length
|
|
1307
|
+
});
|
|
1158
1308
|
const authsIterator = sdk.listAuthentications({ authenticationIds }).items();
|
|
1159
1309
|
for await (const auth of authsIterator) {
|
|
1160
1310
|
authentications.push(auth);
|
|
1161
1311
|
}
|
|
1162
|
-
|
|
1312
|
+
onProgress?.({
|
|
1313
|
+
type: "authentications_lookup_complete",
|
|
1314
|
+
count: authentications.length
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
if (!skipWrite && typesOutputDirectory) {
|
|
1318
|
+
await promises.mkdir(typesOutputDirectory, { recursive: true });
|
|
1319
|
+
}
|
|
1320
|
+
if (!skipWrite) {
|
|
1321
|
+
result.writtenFiles = {};
|
|
1163
1322
|
}
|
|
1164
1323
|
for (const app of apps) {
|
|
1165
|
-
|
|
1166
|
-
|
|
1324
|
+
onProgress?.({
|
|
1325
|
+
type: "app_processing_start",
|
|
1326
|
+
appKey: app.key,
|
|
1327
|
+
slug: app.slug
|
|
1328
|
+
});
|
|
1167
1329
|
try {
|
|
1168
1330
|
if (!app.version) {
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1331
|
+
const error = `Invalid implementation ID format: ${app.implementation_id}. Expected format: <implementationName>@<version>`;
|
|
1332
|
+
result.errors.push({
|
|
1333
|
+
appKey: app.key,
|
|
1334
|
+
error
|
|
1335
|
+
});
|
|
1336
|
+
onProgress?.({
|
|
1337
|
+
type: "app_processing_error",
|
|
1338
|
+
appKey: app.key,
|
|
1339
|
+
error
|
|
1340
|
+
});
|
|
1172
1341
|
continue;
|
|
1173
1342
|
}
|
|
1174
|
-
const [manifestKey] = await context.updateManifestEntry(
|
|
1175
|
-
app.key,
|
|
1176
|
-
{
|
|
1177
|
-
implementationName: app.key,
|
|
1178
|
-
version: app.version
|
|
1179
|
-
},
|
|
1180
|
-
configPath
|
|
1181
|
-
);
|
|
1182
|
-
console.log(
|
|
1183
|
-
`\u{1F4DD} Locked ${appSlugAndKey} to ${app.key}@${app.version} using key '${manifestKey}'`
|
|
1184
|
-
);
|
|
1185
1343
|
let authenticationId;
|
|
1186
1344
|
if (authentications.length > 0) {
|
|
1187
1345
|
const matchingAuth = authentications.find((auth) => {
|
|
@@ -1189,43 +1347,171 @@ var addPlugin = ({ sdk, context }) => {
|
|
|
1189
1347
|
});
|
|
1190
1348
|
if (matchingAuth) {
|
|
1191
1349
|
authenticationId = matchingAuth.id;
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1350
|
+
onProgress?.({
|
|
1351
|
+
type: "authentication_matched",
|
|
1352
|
+
appKey: app.key,
|
|
1353
|
+
authenticationId: matchingAuth.id,
|
|
1354
|
+
authenticationTitle: matchingAuth.title || ""
|
|
1355
|
+
});
|
|
1195
1356
|
} else {
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1357
|
+
onProgress?.({
|
|
1358
|
+
type: "authentication_not_matched",
|
|
1359
|
+
appKey: app.key
|
|
1360
|
+
});
|
|
1199
1361
|
}
|
|
1200
1362
|
}
|
|
1201
|
-
const
|
|
1363
|
+
const manifestKey = getManifestKey(app);
|
|
1202
1364
|
try {
|
|
1203
1365
|
const generator = new AstTypeGenerator();
|
|
1204
|
-
const
|
|
1366
|
+
const typeDefinitionString = await generator.generateTypes({
|
|
1205
1367
|
app,
|
|
1206
1368
|
authenticationId,
|
|
1207
1369
|
sdk
|
|
1208
1370
|
});
|
|
1209
|
-
|
|
1210
|
-
|
|
1371
|
+
result.typeDefinitions[manifestKey] = typeDefinitionString;
|
|
1372
|
+
onProgress?.({
|
|
1373
|
+
type: "type_generated",
|
|
1374
|
+
manifestKey,
|
|
1375
|
+
sizeBytes: typeDefinitionString.length
|
|
1376
|
+
});
|
|
1377
|
+
if (!skipWrite && typesOutputDirectory && result.writtenFiles) {
|
|
1378
|
+
const filePath = path.join(typesOutputDirectory, `${manifestKey}.d.ts`);
|
|
1379
|
+
await promises.writeFile(filePath, typeDefinitionString, "utf8");
|
|
1380
|
+
result.writtenFiles[manifestKey] = filePath;
|
|
1381
|
+
onProgress?.({
|
|
1382
|
+
type: "file_written",
|
|
1383
|
+
manifestKey,
|
|
1384
|
+
filePath
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
onProgress?.({
|
|
1388
|
+
type: "app_processing_complete",
|
|
1389
|
+
appKey: app.key
|
|
1390
|
+
});
|
|
1211
1391
|
} catch (error) {
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1392
|
+
const errorMessage = `Failed to generate types: ${error}`;
|
|
1393
|
+
result.errors.push({
|
|
1394
|
+
appKey: app.key,
|
|
1395
|
+
error: errorMessage
|
|
1396
|
+
});
|
|
1397
|
+
onProgress?.({
|
|
1398
|
+
type: "app_processing_error",
|
|
1399
|
+
appKey: app.key,
|
|
1400
|
+
error: errorMessage
|
|
1401
|
+
});
|
|
1215
1402
|
}
|
|
1216
1403
|
} catch (error) {
|
|
1217
|
-
|
|
1404
|
+
const errorMessage = `Failed to process app: ${error}`;
|
|
1405
|
+
result.errors.push({
|
|
1406
|
+
appKey: app.key,
|
|
1407
|
+
error: errorMessage
|
|
1408
|
+
});
|
|
1409
|
+
onProgress?.({
|
|
1410
|
+
type: "app_processing_error",
|
|
1411
|
+
appKey: app.key,
|
|
1412
|
+
error: errorMessage
|
|
1413
|
+
});
|
|
1218
1414
|
}
|
|
1219
1415
|
}
|
|
1220
|
-
|
|
1221
|
-
},
|
|
1416
|
+
return result;
|
|
1417
|
+
}, GenerateAppTypesSchema);
|
|
1222
1418
|
return {
|
|
1223
|
-
|
|
1419
|
+
generateAppTypes,
|
|
1224
1420
|
context: {
|
|
1225
1421
|
meta: {
|
|
1226
|
-
|
|
1422
|
+
generateAppTypes: {
|
|
1227
1423
|
categories: ["utility"],
|
|
1228
|
-
inputSchema:
|
|
1424
|
+
inputSchema: GenerateAppTypesSchema
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
};
|
|
1429
|
+
};
|
|
1430
|
+
var BuildManifestSchema = zod.z.object({
|
|
1431
|
+
appKeys: zod.z.array(zod.z.string().min(1, "App key cannot be empty")).min(1, "At least one app key is required").describe(
|
|
1432
|
+
"One or more app keys to build manifest entries for (e.g., 'slack', 'github', 'trello')"
|
|
1433
|
+
),
|
|
1434
|
+
skipWrite: zod.z.boolean().optional().describe(
|
|
1435
|
+
"If true, returns manifest entries without writing to disk. If false or omitted, writes to the manifest file."
|
|
1436
|
+
),
|
|
1437
|
+
configPath: zod.z.string().optional().describe(
|
|
1438
|
+
"Path to the manifest file. Only used when skipWrite is false or omitted."
|
|
1439
|
+
)
|
|
1440
|
+
}).describe(
|
|
1441
|
+
"Build manifest entries for apps - can optionally write to disk or just return JSON"
|
|
1442
|
+
);
|
|
1443
|
+
|
|
1444
|
+
// src/plugins/buildManifest/index.ts
|
|
1445
|
+
var buildManifestPlugin = ({ sdk, context }) => {
|
|
1446
|
+
const buildManifest = zapierSdk.createFunction(async function buildManifest2(options) {
|
|
1447
|
+
const { appKeys, skipWrite = false, configPath, onProgress } = options;
|
|
1448
|
+
const result = {
|
|
1449
|
+
errors: []
|
|
1450
|
+
};
|
|
1451
|
+
onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
|
|
1452
|
+
const appsIterator = sdk.listApps({ appKeys }).items();
|
|
1453
|
+
const apps = [];
|
|
1454
|
+
for await (const app of appsIterator) {
|
|
1455
|
+
apps.push(app);
|
|
1456
|
+
onProgress?.({ type: "app_found", app });
|
|
1457
|
+
}
|
|
1458
|
+
onProgress?.({ type: "apps_lookup_complete", count: apps.length });
|
|
1459
|
+
if (apps.length === 0) {
|
|
1460
|
+
return result;
|
|
1461
|
+
}
|
|
1462
|
+
let updatedManifest;
|
|
1463
|
+
for (const app of apps) {
|
|
1464
|
+
onProgress?.({
|
|
1465
|
+
type: "app_processing_start",
|
|
1466
|
+
appKey: app.key,
|
|
1467
|
+
slug: app.slug
|
|
1468
|
+
});
|
|
1469
|
+
try {
|
|
1470
|
+
const manifestEntry = createManifestEntry(app);
|
|
1471
|
+
onProgress?.({
|
|
1472
|
+
type: "manifest_entry_built",
|
|
1473
|
+
appKey: app.key,
|
|
1474
|
+
manifestKey: manifestEntry.implementationName,
|
|
1475
|
+
version: manifestEntry.version || ""
|
|
1476
|
+
});
|
|
1477
|
+
const [updatedManifestKey, , manifest] = await context.updateManifestEntry({
|
|
1478
|
+
appKey: app.key,
|
|
1479
|
+
entry: manifestEntry,
|
|
1480
|
+
configPath,
|
|
1481
|
+
skipWrite,
|
|
1482
|
+
manifest: updatedManifest
|
|
1483
|
+
});
|
|
1484
|
+
updatedManifest = manifest;
|
|
1485
|
+
onProgress?.({
|
|
1486
|
+
type: "manifest_updated",
|
|
1487
|
+
appKey: app.key,
|
|
1488
|
+
manifestKey: updatedManifestKey,
|
|
1489
|
+
version: manifestEntry.version || ""
|
|
1490
|
+
});
|
|
1491
|
+
onProgress?.({ type: "app_processing_complete", appKey: app.key });
|
|
1492
|
+
} catch (error) {
|
|
1493
|
+
const errorMessage = `Failed to process app: ${error}`;
|
|
1494
|
+
result.errors.push({
|
|
1495
|
+
appKey: app.key,
|
|
1496
|
+
error: errorMessage
|
|
1497
|
+
});
|
|
1498
|
+
onProgress?.({
|
|
1499
|
+
type: "app_processing_error",
|
|
1500
|
+
appKey: app.key,
|
|
1501
|
+
error: errorMessage
|
|
1502
|
+
});
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
result.manifest = updatedManifest;
|
|
1506
|
+
return result;
|
|
1507
|
+
}, BuildManifestSchema);
|
|
1508
|
+
return {
|
|
1509
|
+
buildManifest,
|
|
1510
|
+
context: {
|
|
1511
|
+
meta: {
|
|
1512
|
+
buildManifest: {
|
|
1513
|
+
categories: ["utility"],
|
|
1514
|
+
inputSchema: BuildManifestSchema
|
|
1229
1515
|
}
|
|
1230
1516
|
}
|
|
1231
1517
|
}
|
|
@@ -1234,18 +1520,10 @@ var addPlugin = ({ sdk, context }) => {
|
|
|
1234
1520
|
|
|
1235
1521
|
// src/sdk.ts
|
|
1236
1522
|
function createZapierCliSdk(options = {}) {
|
|
1237
|
-
|
|
1523
|
+
return zapierSdk.createZapierSdkWithoutRegistry({
|
|
1238
1524
|
debug: options.debug,
|
|
1239
1525
|
eventEmission: options.eventEmission
|
|
1240
|
-
});
|
|
1241
|
-
sdk = sdk.addPlugin(bundleCodePlugin);
|
|
1242
|
-
sdk = sdk.addPlugin(getLoginConfigPathPlugin);
|
|
1243
|
-
sdk = sdk.addPlugin(addPlugin);
|
|
1244
|
-
sdk = sdk.addPlugin(mcpPlugin);
|
|
1245
|
-
sdk = sdk.addPlugin(loginPlugin);
|
|
1246
|
-
sdk = sdk.addPlugin(logoutPlugin);
|
|
1247
|
-
const finalSdk = sdk.addPlugin(zapierSdk.registryPlugin);
|
|
1248
|
-
return finalSdk;
|
|
1526
|
+
}).addPlugin(generateAppTypesPlugin).addPlugin(buildManifestPlugin).addPlugin(bundleCodePlugin).addPlugin(getLoginConfigPathPlugin).addPlugin(addPlugin).addPlugin(mcpPlugin).addPlugin(loginPlugin).addPlugin(logoutPlugin).addPlugin(zapierSdk.registryPlugin);
|
|
1249
1527
|
}
|
|
1250
1528
|
|
|
1251
1529
|
exports.buildCliCommandExecutedEvent = buildCliCommandExecutedEvent;
|