@zapier/zapier-sdk-cli 0.32.4 → 0.34.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +39 -2
- package/dist/cli.cjs +589 -110
- package/dist/cli.mjs +580 -102
- package/dist/index.cjs +531 -18
- package/dist/index.mjs +525 -15
- package/dist/package.json +3 -2
- package/dist/src/cli.js +11 -1
- package/dist/src/paths.d.ts +1 -0
- package/dist/src/paths.js +6 -0
- package/dist/src/plugins/index.d.ts +1 -0
- package/dist/src/plugins/index.js +1 -0
- package/dist/src/plugins/init/display.d.ts +9 -0
- package/dist/src/plugins/init/display.js +72 -0
- package/dist/src/plugins/init/index.d.ts +16 -0
- package/dist/src/plugins/init/index.js +61 -0
- package/dist/src/plugins/init/schemas.d.ts +8 -0
- package/dist/src/plugins/init/schemas.js +14 -0
- package/dist/src/plugins/init/steps.d.ts +39 -0
- package/dist/src/plugins/init/steps.js +141 -0
- package/dist/src/plugins/init/types.d.ts +31 -0
- package/dist/src/plugins/init/types.js +1 -0
- package/dist/src/plugins/init/utils.d.ts +48 -0
- package/dist/src/plugins/init/utils.js +135 -0
- package/dist/src/plugins/logout/index.js +1 -1
- package/dist/src/sdk.js +5 -2
- package/dist/src/utils/auth/login.js +33 -4
- package/dist/src/utils/package-manager-detector.d.ts +3 -1
- package/dist/src/utils/package-manager-detector.js +1 -0
- package/dist/src/utils/version-checker.js +1 -8
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -5
- package/templates/basic/AGENTS.md.hbs +15 -0
- package/templates/basic/README.md.hbs +21 -0
- package/templates/basic/package.json.hbs +17 -0
- package/templates/basic/src/index.ts +46 -0
- package/templates/basic/tsconfig.json +12 -0
package/dist/cli.cjs
CHANGED
|
@@ -5,13 +5,13 @@ var commander = require('commander');
|
|
|
5
5
|
var zod = require('zod');
|
|
6
6
|
var zapierSdk = require('@zapier/zapier-sdk');
|
|
7
7
|
var inquirer = require('inquirer');
|
|
8
|
-
var
|
|
8
|
+
var chalk6 = require('chalk');
|
|
9
9
|
var util = require('util');
|
|
10
|
+
var cliLogin = require('@zapier/zapier-sdk-cli-login');
|
|
10
11
|
var open = require('open');
|
|
11
12
|
var crypto = require('crypto');
|
|
12
13
|
var express = require('express');
|
|
13
14
|
var pkceChallenge = require('pkce-challenge');
|
|
14
|
-
var zapierSdkCliLogin = require('@zapier/zapier-sdk-cli-login');
|
|
15
15
|
var ora = require('ora');
|
|
16
16
|
var zapierSdkMcp = require('@zapier/zapier-sdk-mcp');
|
|
17
17
|
var esbuild = require('esbuild');
|
|
@@ -19,11 +19,14 @@ var fs = require('fs');
|
|
|
19
19
|
var path = require('path');
|
|
20
20
|
var promises = require('fs/promises');
|
|
21
21
|
var ts = require('typescript');
|
|
22
|
-
var packageJsonLib = require('package-json');
|
|
23
|
-
var Conf = require('conf');
|
|
24
22
|
var isInstalledGlobally = require('is-installed-globally');
|
|
23
|
+
var child_process = require('child_process');
|
|
24
|
+
var Handlebars = require('handlebars');
|
|
25
|
+
var url = require('url');
|
|
26
|
+
var packageJsonLib = require('package-json');
|
|
25
27
|
var semver = require('semver');
|
|
26
28
|
|
|
29
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
27
30
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
28
31
|
|
|
29
32
|
function _interopNamespace(e) {
|
|
@@ -45,8 +48,9 @@ function _interopNamespace(e) {
|
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
var inquirer__default = /*#__PURE__*/_interopDefault(inquirer);
|
|
48
|
-
var
|
|
51
|
+
var chalk6__default = /*#__PURE__*/_interopDefault(chalk6);
|
|
49
52
|
var util__default = /*#__PURE__*/_interopDefault(util);
|
|
53
|
+
var cliLogin__namespace = /*#__PURE__*/_interopNamespace(cliLogin);
|
|
50
54
|
var open__default = /*#__PURE__*/_interopDefault(open);
|
|
51
55
|
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
52
56
|
var express__default = /*#__PURE__*/_interopDefault(express);
|
|
@@ -55,9 +59,9 @@ var ora__default = /*#__PURE__*/_interopDefault(ora);
|
|
|
55
59
|
var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
56
60
|
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
57
61
|
var ts__namespace = /*#__PURE__*/_interopNamespace(ts);
|
|
58
|
-
var packageJsonLib__default = /*#__PURE__*/_interopDefault(packageJsonLib);
|
|
59
|
-
var Conf__default = /*#__PURE__*/_interopDefault(Conf);
|
|
60
62
|
var isInstalledGlobally__default = /*#__PURE__*/_interopDefault(isInstalledGlobally);
|
|
63
|
+
var Handlebars__default = /*#__PURE__*/_interopDefault(Handlebars);
|
|
64
|
+
var packageJsonLib__default = /*#__PURE__*/_interopDefault(packageJsonLib);
|
|
61
65
|
var semver__default = /*#__PURE__*/_interopDefault(semver);
|
|
62
66
|
|
|
63
67
|
var ZapierCliError = class extends zapierSdk.ZapierError {
|
|
@@ -185,7 +189,7 @@ var SchemaParameterResolver = class {
|
|
|
185
189
|
context.resolvedParams = resolvedParams;
|
|
186
190
|
} catch (error) {
|
|
187
191
|
if (this.isUserCancellation(error)) {
|
|
188
|
-
console.log(
|
|
192
|
+
console.log(chalk6__default.default.yellow("\n\nOperation cancelled by user"));
|
|
189
193
|
throw new ZapierCliUserCancellationError();
|
|
190
194
|
}
|
|
191
195
|
throw error;
|
|
@@ -223,7 +227,7 @@ var SchemaParameterResolver = class {
|
|
|
223
227
|
context.resolvedParams = resolvedParams;
|
|
224
228
|
} catch (error) {
|
|
225
229
|
if (this.isUserCancellation(error)) {
|
|
226
|
-
console.log(
|
|
230
|
+
console.log(chalk6__default.default.yellow("\n\nOperation cancelled by user"));
|
|
227
231
|
throw new ZapierCliUserCancellationError();
|
|
228
232
|
}
|
|
229
233
|
throw error;
|
|
@@ -258,7 +262,7 @@ var SchemaParameterResolver = class {
|
|
|
258
262
|
context.resolvedParams = resolvedParams;
|
|
259
263
|
} catch (error) {
|
|
260
264
|
if (this.isUserCancellation(error)) {
|
|
261
|
-
console.log(
|
|
265
|
+
console.log(chalk6__default.default.yellow("\n\nOperation cancelled by user"));
|
|
262
266
|
throw new ZapierCliUserCancellationError();
|
|
263
267
|
}
|
|
264
268
|
throw error;
|
|
@@ -269,7 +273,7 @@ var SchemaParameterResolver = class {
|
|
|
269
273
|
const finalResult = schema.safeParse(resolvedParams);
|
|
270
274
|
if (!finalResult.success) {
|
|
271
275
|
console.error(
|
|
272
|
-
|
|
276
|
+
chalk6__default.default.red("\u274C Parameter validation failed after resolution:")
|
|
273
277
|
);
|
|
274
278
|
throw finalResult.error;
|
|
275
279
|
}
|
|
@@ -317,7 +321,7 @@ var SchemaParameterResolver = class {
|
|
|
317
321
|
if (!resolver) {
|
|
318
322
|
throw new Error(`No resolver found for parameter: ${param.name}`);
|
|
319
323
|
}
|
|
320
|
-
console.log(
|
|
324
|
+
console.log(chalk6__default.default.blue(`
|
|
321
325
|
\u{1F50D} Resolving ${param.name}...`));
|
|
322
326
|
const typedResolver = resolver;
|
|
323
327
|
if (typedResolver.type === "static") {
|
|
@@ -334,7 +338,7 @@ var SchemaParameterResolver = class {
|
|
|
334
338
|
} else if (typedResolver.type === "dynamic") {
|
|
335
339
|
try {
|
|
336
340
|
if (param.isRequired && param.name !== "connectionId") {
|
|
337
|
-
console.log(
|
|
341
|
+
console.log(chalk6__default.default.gray(`Fetching options for ${param.name}...`));
|
|
338
342
|
}
|
|
339
343
|
const items = await typedResolver.fetch(
|
|
340
344
|
context.sdk,
|
|
@@ -375,7 +379,7 @@ var SchemaParameterResolver = class {
|
|
|
375
379
|
}
|
|
376
380
|
};
|
|
377
381
|
console.log(
|
|
378
|
-
|
|
382
|
+
chalk6__default.default.gray(
|
|
379
383
|
`Fetching input fields for ${param.name}${iteration > 1 ? ` (iteration ${iteration})` : ""}...`
|
|
380
384
|
)
|
|
381
385
|
);
|
|
@@ -386,7 +390,7 @@ var SchemaParameterResolver = class {
|
|
|
386
390
|
if (!rootFieldItems || rootFieldItems.length === 0) {
|
|
387
391
|
if (iteration === 1) {
|
|
388
392
|
console.log(
|
|
389
|
-
|
|
393
|
+
chalk6__default.default.yellow(`No input fields required for this action.`)
|
|
390
394
|
);
|
|
391
395
|
}
|
|
392
396
|
break;
|
|
@@ -408,7 +412,7 @@ var SchemaParameterResolver = class {
|
|
|
408
412
|
}
|
|
409
413
|
if (iteration >= maxIterations) {
|
|
410
414
|
console.log(
|
|
411
|
-
|
|
415
|
+
chalk6__default.default.yellow(
|
|
412
416
|
`
|
|
413
417
|
\u26A0\uFE0F Maximum field resolution iterations reached. Some dynamic fields may not have been discovered.`
|
|
414
418
|
)
|
|
@@ -430,7 +434,7 @@ var SchemaParameterResolver = class {
|
|
|
430
434
|
const fieldsetTitle = typedItem.title || typedItem.key;
|
|
431
435
|
const pathDisplay = fieldsetPath.length > 0 ? ` (in ${fieldsetPath.join(" > ")})` : "";
|
|
432
436
|
console.log(
|
|
433
|
-
|
|
437
|
+
chalk6__default.default.cyan(
|
|
434
438
|
`
|
|
435
439
|
\u{1F4C1} Processing fieldset: ${fieldsetTitle}${pathDisplay}`
|
|
436
440
|
)
|
|
@@ -462,7 +466,7 @@ var SchemaParameterResolver = class {
|
|
|
462
466
|
newRequiredCount++;
|
|
463
467
|
if (newRequiredCount === 1 && fieldsetPath.length === 0) {
|
|
464
468
|
console.log(
|
|
465
|
-
|
|
469
|
+
chalk6__default.default.blue(
|
|
466
470
|
`
|
|
467
471
|
\u{1F4DD} Please provide values for the following ${iteration === 1 ? "" : "additional "}input fields:`
|
|
468
472
|
)
|
|
@@ -483,7 +487,7 @@ var SchemaParameterResolver = class {
|
|
|
483
487
|
if (optionalFields.length > 0) {
|
|
484
488
|
const pathContext = fieldsetPath.length > 0 ? ` in ${fieldsetPath.join(" > ")}` : "";
|
|
485
489
|
console.log(
|
|
486
|
-
|
|
490
|
+
chalk6__default.default.gray(
|
|
487
491
|
`
|
|
488
492
|
There are ${optionalFields.length} ${iteration === 1 ? "" : "additional "}optional field(s) available${pathContext}.`
|
|
489
493
|
)
|
|
@@ -498,7 +502,7 @@ There are ${optionalFields.length} ${iteration === 1 ? "" : "additional "}option
|
|
|
498
502
|
}
|
|
499
503
|
]);
|
|
500
504
|
if (shouldConfigureOptional.configure) {
|
|
501
|
-
console.log(
|
|
505
|
+
console.log(chalk6__default.default.cyan(`
|
|
502
506
|
Optional fields${pathContext}:`));
|
|
503
507
|
for (const field of optionalFields) {
|
|
504
508
|
await this.promptForField(field, targetInputs, context);
|
|
@@ -514,7 +518,7 @@ Optional fields${pathContext}:`));
|
|
|
514
518
|
}
|
|
515
519
|
} catch (error) {
|
|
516
520
|
if (this.isUserCancellation(error)) {
|
|
517
|
-
console.log(
|
|
521
|
+
console.log(chalk6__default.default.yellow("\n\nOperation cancelled by user"));
|
|
518
522
|
throw new ZapierCliUserCancellationError();
|
|
519
523
|
}
|
|
520
524
|
throw error;
|
|
@@ -569,7 +573,7 @@ Optional fields${pathContext}:`));
|
|
|
569
573
|
async fetchChoices(fieldMeta, inputs, context, cursor) {
|
|
570
574
|
try {
|
|
571
575
|
console.log(
|
|
572
|
-
|
|
576
|
+
chalk6__default.default.gray(
|
|
573
577
|
cursor ? ` Fetching more choices...` : ` Fetching choices for ${fieldMeta.title}...`
|
|
574
578
|
)
|
|
575
579
|
);
|
|
@@ -588,7 +592,7 @@ Optional fields${pathContext}:`));
|
|
|
588
592
|
}));
|
|
589
593
|
if (choices.length === 0 && !cursor) {
|
|
590
594
|
console.log(
|
|
591
|
-
|
|
595
|
+
chalk6__default.default.yellow(` No choices available for ${fieldMeta.title}`)
|
|
592
596
|
);
|
|
593
597
|
}
|
|
594
598
|
return {
|
|
@@ -597,7 +601,7 @@ Optional fields${pathContext}:`));
|
|
|
597
601
|
};
|
|
598
602
|
} catch (error) {
|
|
599
603
|
console.warn(
|
|
600
|
-
|
|
604
|
+
chalk6__default.default.yellow(` \u26A0\uFE0F Failed to fetch choices for ${fieldMeta.title}:`),
|
|
601
605
|
error
|
|
602
606
|
);
|
|
603
607
|
return { choices: [] };
|
|
@@ -623,7 +627,7 @@ Optional fields${pathContext}:`));
|
|
|
623
627
|
}));
|
|
624
628
|
if (nextCursor) {
|
|
625
629
|
promptChoices.push({
|
|
626
|
-
name:
|
|
630
|
+
name: chalk6__default.default.dim("(Load more...)"),
|
|
627
631
|
value: LOAD_MORE_SENTINEL
|
|
628
632
|
});
|
|
629
633
|
}
|
|
@@ -686,7 +690,7 @@ Optional fields${pathContext}:`));
|
|
|
686
690
|
};
|
|
687
691
|
}
|
|
688
692
|
if (fieldMeta.description) {
|
|
689
|
-
promptConfig.prefix =
|
|
693
|
+
promptConfig.prefix = chalk6__default.default.gray(`\u2139 ${fieldMeta.description}
|
|
690
694
|
`);
|
|
691
695
|
}
|
|
692
696
|
try {
|
|
@@ -694,7 +698,7 @@ Optional fields${pathContext}:`));
|
|
|
694
698
|
return answer[fieldMeta.key];
|
|
695
699
|
} catch (error) {
|
|
696
700
|
if (this.isUserCancellation(error)) {
|
|
697
|
-
console.log(
|
|
701
|
+
console.log(chalk6__default.default.yellow("\n\nOperation cancelled by user"));
|
|
698
702
|
throw new ZapierCliUserCancellationError();
|
|
699
703
|
}
|
|
700
704
|
throw error;
|
|
@@ -712,7 +716,7 @@ Optional fields${pathContext}:`));
|
|
|
712
716
|
}
|
|
713
717
|
} catch (error) {
|
|
714
718
|
if (this.isUserCancellation(error)) {
|
|
715
|
-
console.log(
|
|
719
|
+
console.log(chalk6__default.default.yellow("\n\nOperation cancelled by user"));
|
|
716
720
|
throw new ZapierCliUserCancellationError();
|
|
717
721
|
}
|
|
718
722
|
throw error;
|
|
@@ -816,7 +820,7 @@ function formatItemsFromSchema(functionInfo, items, startingNumber = 0) {
|
|
|
816
820
|
});
|
|
817
821
|
}
|
|
818
822
|
function formatSingleItem(formatted, itemNumber) {
|
|
819
|
-
let titleLine = `${
|
|
823
|
+
let titleLine = `${chalk6__default.default.gray(`${itemNumber + 1}.`)} ${chalk6__default.default.cyan(formatted.title)}`;
|
|
820
824
|
const subtitleParts = [];
|
|
821
825
|
if (formatted.keys) {
|
|
822
826
|
subtitleParts.push(...formatted.keys);
|
|
@@ -828,11 +832,11 @@ function formatSingleItem(formatted, itemNumber) {
|
|
|
828
832
|
}
|
|
829
833
|
const uniqueParts = [...new Set(subtitleParts)];
|
|
830
834
|
if (uniqueParts.length > 0) {
|
|
831
|
-
titleLine += ` ${
|
|
835
|
+
titleLine += ` ${chalk6__default.default.gray(`(${uniqueParts.join(", ")})`)}`;
|
|
832
836
|
}
|
|
833
837
|
console.log(titleLine);
|
|
834
838
|
if (formatted.description) {
|
|
835
|
-
console.log(` ${
|
|
839
|
+
console.log(` ${chalk6__default.default.dim(formatted.description)}`);
|
|
836
840
|
}
|
|
837
841
|
if (formatted.data !== void 0) {
|
|
838
842
|
formatJsonOutput(formatted.data);
|
|
@@ -848,16 +852,16 @@ function formatSingleItem(formatted, itemNumber) {
|
|
|
848
852
|
function applyStyle(value, style) {
|
|
849
853
|
switch (style) {
|
|
850
854
|
case "dim":
|
|
851
|
-
return
|
|
855
|
+
return chalk6__default.default.dim(value);
|
|
852
856
|
case "accent":
|
|
853
|
-
return
|
|
857
|
+
return chalk6__default.default.magenta(value);
|
|
854
858
|
case "warning":
|
|
855
|
-
return
|
|
859
|
+
return chalk6__default.default.red(value);
|
|
856
860
|
case "success":
|
|
857
|
-
return
|
|
861
|
+
return chalk6__default.default.green(value);
|
|
858
862
|
case "normal":
|
|
859
863
|
default:
|
|
860
|
-
return
|
|
864
|
+
return chalk6__default.default.blue(value);
|
|
861
865
|
}
|
|
862
866
|
}
|
|
863
867
|
function convertGenericItemToFormattedItem(item) {
|
|
@@ -920,7 +924,7 @@ async function promptConfirm(confirmType) {
|
|
|
920
924
|
return { confirmed: true };
|
|
921
925
|
}
|
|
922
926
|
const { messageBefore, messageAfter } = CONFIRM_MESSAGES[confirmType];
|
|
923
|
-
console.log(
|
|
927
|
+
console.log(chalk6__default.default.yellow(`
|
|
924
928
|
${messageBefore}
|
|
925
929
|
`));
|
|
926
930
|
const { confirmed } = await inquirer__default.default.prompt([
|
|
@@ -1090,8 +1094,8 @@ function generateCliCommands(program2, sdk2) {
|
|
|
1090
1094
|
return;
|
|
1091
1095
|
}
|
|
1092
1096
|
const cliCommandName = methodNameToCliCommand(fnInfo.name);
|
|
1093
|
-
const
|
|
1094
|
-
addCommand(program2, cliCommandName,
|
|
1097
|
+
const config = createCommandConfig(cliCommandName, fnInfo, sdk2);
|
|
1098
|
+
addCommand(program2, cliCommandName, config);
|
|
1095
1099
|
});
|
|
1096
1100
|
program2.configureHelp({
|
|
1097
1101
|
formatHelp: (cmd, helper) => {
|
|
@@ -1191,7 +1195,7 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
|
1191
1195
|
if (confirm && !shouldUseJson) {
|
|
1192
1196
|
const confirmResult = await promptConfirm(confirm);
|
|
1193
1197
|
if (!confirmResult.confirmed) {
|
|
1194
|
-
console.log(
|
|
1198
|
+
console.log(chalk6__default.default.yellow("Operation cancelled."));
|
|
1195
1199
|
return;
|
|
1196
1200
|
}
|
|
1197
1201
|
confirmMessageAfter = confirmResult.messageAfter;
|
|
@@ -1210,9 +1214,9 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
|
1210
1214
|
const sdkObj = sdk2;
|
|
1211
1215
|
await sdkObj[functionInfo.name](resolvedParams);
|
|
1212
1216
|
console.log(
|
|
1213
|
-
|
|
1217
|
+
chalk6__default.default.green(`\u2705 ${cliCommandName} completed successfully!`)
|
|
1214
1218
|
);
|
|
1215
|
-
console.log(
|
|
1219
|
+
console.log(chalk6__default.default.gray(`Output written to: ${hasOutputFile}`));
|
|
1216
1220
|
return;
|
|
1217
1221
|
}
|
|
1218
1222
|
let result;
|
|
@@ -1259,7 +1263,7 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
|
1259
1263
|
formatJsonOutput(items);
|
|
1260
1264
|
}
|
|
1261
1265
|
if (confirmMessageAfter) {
|
|
1262
|
-
console.log(
|
|
1266
|
+
console.log(chalk6__default.default.yellow(`
|
|
1263
1267
|
${confirmMessageAfter}`));
|
|
1264
1268
|
}
|
|
1265
1269
|
}
|
|
@@ -1267,23 +1271,23 @@ ${confirmMessageAfter}`));
|
|
|
1267
1271
|
if (error instanceof Error && error.message.includes('"code"')) {
|
|
1268
1272
|
try {
|
|
1269
1273
|
const validationErrors = JSON.parse(error.message);
|
|
1270
|
-
console.error(
|
|
1274
|
+
console.error(chalk6__default.default.red("\u274C Validation Error:"));
|
|
1271
1275
|
validationErrors.forEach((err) => {
|
|
1272
1276
|
const errorObj = err;
|
|
1273
1277
|
const field = errorObj?.path?.join(".") || "unknown";
|
|
1274
1278
|
console.error(
|
|
1275
|
-
|
|
1279
|
+
chalk6__default.default.yellow(
|
|
1276
1280
|
` \u2022 ${field}: ${errorObj?.message || "Unknown error"}`
|
|
1277
1281
|
)
|
|
1278
1282
|
);
|
|
1279
1283
|
});
|
|
1280
1284
|
console.error(
|
|
1281
|
-
"\n" +
|
|
1285
|
+
"\n" + chalk6__default.default.dim(`Use --help to see available options`)
|
|
1282
1286
|
);
|
|
1283
1287
|
throw new ZapierCliExitError("Validation failed", 1);
|
|
1284
1288
|
} catch {
|
|
1285
1289
|
console.error(
|
|
1286
|
-
|
|
1290
|
+
chalk6__default.default.red("Error:"),
|
|
1287
1291
|
error instanceof Error ? error.message : String(error)
|
|
1288
1292
|
);
|
|
1289
1293
|
throw new ZapierCliExitError(
|
|
@@ -1295,11 +1299,11 @@ ${confirmMessageAfter}`));
|
|
|
1295
1299
|
throw error;
|
|
1296
1300
|
} else if (error instanceof zapierSdk.ZapierError) {
|
|
1297
1301
|
const formattedMessage = zapierSdk.formatErrorMessage(error);
|
|
1298
|
-
console.error(
|
|
1302
|
+
console.error(chalk6__default.default.red("\u274C Error:"), formattedMessage);
|
|
1299
1303
|
throw new ZapierCliExitError(formattedMessage, 1);
|
|
1300
1304
|
} else {
|
|
1301
1305
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1302
|
-
console.error(
|
|
1306
|
+
console.error(chalk6__default.default.red("\u274C Error:"), errorMessage);
|
|
1303
1307
|
throw new ZapierCliExitError(errorMessage, 1);
|
|
1304
1308
|
}
|
|
1305
1309
|
}
|
|
@@ -1316,10 +1320,10 @@ function collect(value, previous = []) {
|
|
|
1316
1320
|
previous.push(value);
|
|
1317
1321
|
return previous;
|
|
1318
1322
|
}
|
|
1319
|
-
function addCommand(program2, commandName,
|
|
1320
|
-
const command = program2.command(commandName, { hidden:
|
|
1323
|
+
function addCommand(program2, commandName, config) {
|
|
1324
|
+
const command = program2.command(commandName, { hidden: config.hidden ?? false }).description(config.description);
|
|
1321
1325
|
let hasPositionalArray = false;
|
|
1322
|
-
|
|
1326
|
+
config.parameters.forEach((param) => {
|
|
1323
1327
|
const kebabName = param.name.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
1324
1328
|
if (param.hasResolver && param.required) {
|
|
1325
1329
|
command.argument(
|
|
@@ -1353,7 +1357,7 @@ function addCommand(program2, commandName, config2) {
|
|
|
1353
1357
|
);
|
|
1354
1358
|
} else {
|
|
1355
1359
|
const flags = [];
|
|
1356
|
-
const alias =
|
|
1360
|
+
const alias = config.aliases?.[param.name];
|
|
1357
1361
|
if (alias && alias.length === 1) {
|
|
1358
1362
|
flags.push(`-${alias}`);
|
|
1359
1363
|
}
|
|
@@ -1373,13 +1377,13 @@ function addCommand(program2, commandName, config2) {
|
|
|
1373
1377
|
}
|
|
1374
1378
|
}
|
|
1375
1379
|
});
|
|
1376
|
-
const paramNames = new Set(
|
|
1380
|
+
const paramNames = new Set(config.parameters.map((p) => p.name));
|
|
1377
1381
|
SHARED_COMMAND_CLI_OPTIONS.forEach((opt) => {
|
|
1378
1382
|
if (!paramNames.has(opt.name)) {
|
|
1379
1383
|
command.option(opt.flag, opt.description);
|
|
1380
1384
|
}
|
|
1381
1385
|
});
|
|
1382
|
-
command.action(
|
|
1386
|
+
command.action(config.handler);
|
|
1383
1387
|
}
|
|
1384
1388
|
function convertCliArgsToSdkParams(parameters, positionalArgs, options) {
|
|
1385
1389
|
const sdkParams = {};
|
|
@@ -1443,7 +1447,7 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, f
|
|
|
1443
1447
|
let totalShown = 0;
|
|
1444
1448
|
let pageCount = 0;
|
|
1445
1449
|
console.log(
|
|
1446
|
-
|
|
1450
|
+
chalk6__default.default.blue(`\u{1F4CB} ${getListTitleFromMethod(sdkMethodName, functionInfo)}
|
|
1447
1451
|
`)
|
|
1448
1452
|
);
|
|
1449
1453
|
try {
|
|
@@ -1451,11 +1455,11 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, f
|
|
|
1451
1455
|
const items = page.data || page;
|
|
1452
1456
|
pageCount++;
|
|
1453
1457
|
if (!Array.isArray(items)) {
|
|
1454
|
-
console.log(
|
|
1458
|
+
console.log(chalk6__default.default.yellow(`No ${itemName} found.`));
|
|
1455
1459
|
return;
|
|
1456
1460
|
}
|
|
1457
1461
|
if (items.length === 0 && pageCount === 1) {
|
|
1458
|
-
console.log(
|
|
1462
|
+
console.log(chalk6__default.default.yellow(`No ${itemName} found.`));
|
|
1459
1463
|
return;
|
|
1460
1464
|
}
|
|
1461
1465
|
if (items.length === 0) {
|
|
@@ -1464,7 +1468,7 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, f
|
|
|
1464
1468
|
if (pageCount > 1) {
|
|
1465
1469
|
console.clear();
|
|
1466
1470
|
console.log(
|
|
1467
|
-
|
|
1471
|
+
chalk6__default.default.blue(
|
|
1468
1472
|
`\u{1F4CB} ${getListTitleFromMethod(sdkMethodName, functionInfo)}
|
|
1469
1473
|
`
|
|
1470
1474
|
)
|
|
@@ -1481,7 +1485,7 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, f
|
|
|
1481
1485
|
}
|
|
1482
1486
|
totalShown += items.length;
|
|
1483
1487
|
console.log(
|
|
1484
|
-
|
|
1488
|
+
chalk6__default.default.green(
|
|
1485
1489
|
`
|
|
1486
1490
|
\u2705 Showing ${totalShown} ${itemName} (page ${pageCount})`
|
|
1487
1491
|
)
|
|
@@ -1502,13 +1506,13 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, f
|
|
|
1502
1506
|
break;
|
|
1503
1507
|
}
|
|
1504
1508
|
}
|
|
1505
|
-
console.log(
|
|
1509
|
+
console.log(chalk6__default.default.gray(`
|
|
1506
1510
|
\u{1F4C4} Finished browsing ${itemName}`));
|
|
1507
1511
|
} catch (error) {
|
|
1508
1512
|
const items = sdkResult?.data || sdkResult;
|
|
1509
1513
|
if (Array.isArray(items)) {
|
|
1510
1514
|
if (items.length === 0) {
|
|
1511
|
-
console.log(
|
|
1515
|
+
console.log(chalk6__default.default.yellow(`No ${itemName} found.`));
|
|
1512
1516
|
return;
|
|
1513
1517
|
}
|
|
1514
1518
|
if (functionInfo && functionInfo.inputSchema) {
|
|
@@ -1520,7 +1524,7 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, f
|
|
|
1520
1524
|
} else {
|
|
1521
1525
|
formatItemsGeneric2(items, 0);
|
|
1522
1526
|
}
|
|
1523
|
-
console.log(
|
|
1527
|
+
console.log(chalk6__default.default.green(`
|
|
1524
1528
|
\u2705 Showing ${items.length} ${itemName}`));
|
|
1525
1529
|
} else {
|
|
1526
1530
|
throw error;
|
|
@@ -1542,10 +1546,10 @@ function formatNonPaginatedResults(result, requestedMaxItems, userSpecifiedMaxIt
|
|
|
1542
1546
|
}
|
|
1543
1547
|
const itemName = functionInfo ? getItemNameFromMethod(functionInfo) : "items";
|
|
1544
1548
|
if (result.length === 0) {
|
|
1545
|
-
console.log(
|
|
1549
|
+
console.log(chalk6__default.default.yellow(`No ${itemName} found.`));
|
|
1546
1550
|
return;
|
|
1547
1551
|
}
|
|
1548
|
-
console.log(
|
|
1552
|
+
console.log(chalk6__default.default.green(`
|
|
1549
1553
|
\u2705 Found ${result.length} ${itemName}:
|
|
1550
1554
|
`));
|
|
1551
1555
|
if (functionInfo && functionInfo.inputSchema) {
|
|
@@ -1558,13 +1562,13 @@ function formatNonPaginatedResults(result, requestedMaxItems, userSpecifiedMaxIt
|
|
|
1558
1562
|
}
|
|
1559
1563
|
if (userSpecifiedMaxItems && requestedMaxItems) {
|
|
1560
1564
|
console.log(
|
|
1561
|
-
|
|
1565
|
+
chalk6__default.default.gray(
|
|
1562
1566
|
`
|
|
1563
1567
|
\u{1F4C4} Showing up to ${requestedMaxItems} ${itemName} (--max-items ${requestedMaxItems})`
|
|
1564
1568
|
)
|
|
1565
1569
|
);
|
|
1566
1570
|
} else {
|
|
1567
|
-
console.log(
|
|
1571
|
+
console.log(chalk6__default.default.gray(`
|
|
1568
1572
|
\u{1F4C4} All available ${itemName} shown`));
|
|
1569
1573
|
}
|
|
1570
1574
|
}
|
|
@@ -1573,10 +1577,10 @@ function formatItemsGeneric2(items, startingNumber = 0) {
|
|
|
1573
1577
|
const itemObj = item;
|
|
1574
1578
|
const name = itemObj?.name || itemObj?.key || itemObj?.id || "Item";
|
|
1575
1579
|
console.log(
|
|
1576
|
-
`${
|
|
1580
|
+
`${chalk6__default.default.gray(`${startingNumber + index + 1}.`)} ${chalk6__default.default.cyan(String(name))}`
|
|
1577
1581
|
);
|
|
1578
1582
|
if (itemObj?.description) {
|
|
1579
|
-
console.log(` ${
|
|
1583
|
+
console.log(` ${chalk6__default.default.dim(String(itemObj.description))}`);
|
|
1580
1584
|
}
|
|
1581
1585
|
console.log();
|
|
1582
1586
|
});
|
|
@@ -1612,20 +1616,20 @@ var spinPromise = async (promise, text) => {
|
|
|
1612
1616
|
};
|
|
1613
1617
|
var log = {
|
|
1614
1618
|
info: (message, ...args) => {
|
|
1615
|
-
console.log(
|
|
1619
|
+
console.log(chalk6__default.default.blue("\u2139"), message, ...args);
|
|
1616
1620
|
},
|
|
1617
1621
|
error: (message, ...args) => {
|
|
1618
|
-
console.error(
|
|
1622
|
+
console.error(chalk6__default.default.red("\u2716"), message, ...args);
|
|
1619
1623
|
},
|
|
1620
1624
|
success: (message, ...args) => {
|
|
1621
|
-
console.log(
|
|
1625
|
+
console.log(chalk6__default.default.green("\u2713"), message, ...args);
|
|
1622
1626
|
},
|
|
1623
1627
|
warn: (message, ...args) => {
|
|
1624
|
-
console.log(
|
|
1628
|
+
console.log(chalk6__default.default.yellow("\u26A0"), message, ...args);
|
|
1625
1629
|
},
|
|
1626
1630
|
debug: (message, ...args) => {
|
|
1627
1631
|
if (process.env.DEBUG === "true" || process.argv.includes("--debug")) {
|
|
1628
|
-
console.log(
|
|
1632
|
+
console.log(chalk6__default.default.gray("\u{1F41B}"), message, ...args);
|
|
1629
1633
|
}
|
|
1630
1634
|
}
|
|
1631
1635
|
};
|
|
@@ -1726,13 +1730,13 @@ var login = async ({
|
|
|
1726
1730
|
timeoutMs = LOGIN_TIMEOUT_MS,
|
|
1727
1731
|
credentials: credentials2
|
|
1728
1732
|
}) => {
|
|
1729
|
-
const { clientId, tokenUrl, authorizeUrl } =
|
|
1733
|
+
const { clientId, tokenUrl, authorizeUrl } = cliLogin.getPkceLoginConfig({
|
|
1730
1734
|
credentials: credentials2
|
|
1731
1735
|
});
|
|
1732
1736
|
const scope = ensureOfflineAccess(
|
|
1733
1737
|
credentials2?.scope || "internal credentials"
|
|
1734
1738
|
);
|
|
1735
|
-
|
|
1739
|
+
await cliLogin.logout();
|
|
1736
1740
|
const availablePort = await findAvailablePort();
|
|
1737
1741
|
const redirectUri = `http://localhost:${availablePort}/oauth`;
|
|
1738
1742
|
log_default.info(`Using port ${availablePort} for OAuth callback`);
|
|
@@ -1820,12 +1824,37 @@ var login = async ({
|
|
|
1820
1824
|
},
|
|
1821
1825
|
{
|
|
1822
1826
|
headers: {
|
|
1823
|
-
[
|
|
1827
|
+
[cliLogin.AUTH_MODE_HEADER]: "no",
|
|
1824
1828
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
1825
1829
|
}
|
|
1826
1830
|
}
|
|
1827
1831
|
);
|
|
1828
|
-
|
|
1832
|
+
let targetStorage;
|
|
1833
|
+
if (cliLogin.getLoginStorageMode() === "config") {
|
|
1834
|
+
const { upgrade } = await inquirer__default.default.prompt([
|
|
1835
|
+
{
|
|
1836
|
+
type: "confirm",
|
|
1837
|
+
name: "upgrade",
|
|
1838
|
+
message: "Would you like to upgrade to system keychain storage? This is recommended to securely store your credentials. However, note that older SDK/CLI versions will NOT be able to read these credentials, so you will want to upgrade them to the latest version.",
|
|
1839
|
+
default: true
|
|
1840
|
+
}
|
|
1841
|
+
]);
|
|
1842
|
+
targetStorage = upgrade ? "keychain" : "config";
|
|
1843
|
+
} else {
|
|
1844
|
+
targetStorage = "keychain";
|
|
1845
|
+
}
|
|
1846
|
+
try {
|
|
1847
|
+
await cliLogin.updateLogin(data, { storage: targetStorage });
|
|
1848
|
+
} catch (err) {
|
|
1849
|
+
if (targetStorage === "keychain") {
|
|
1850
|
+
log_default.warn(
|
|
1851
|
+
`Could not store credentials in system keychain. Storing in plaintext at ${cliLogin.getConfigPath()}.`
|
|
1852
|
+
);
|
|
1853
|
+
await cliLogin.updateLogin(data, { storage: "config" });
|
|
1854
|
+
} else {
|
|
1855
|
+
throw err;
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1829
1858
|
log_default.info("Token exchange completed successfully");
|
|
1830
1859
|
return data.access_token;
|
|
1831
1860
|
};
|
|
@@ -1836,7 +1865,7 @@ var LoginSchema = zod.z.object({
|
|
|
1836
1865
|
|
|
1837
1866
|
// package.json
|
|
1838
1867
|
var package_default = {
|
|
1839
|
-
version: "0.
|
|
1868
|
+
version: "0.34.1"};
|
|
1840
1869
|
|
|
1841
1870
|
// src/telemetry/builders.ts
|
|
1842
1871
|
function createCliBaseEvent(context = {}) {
|
|
@@ -1922,7 +1951,7 @@ var loginPlugin = ({ context }) => {
|
|
|
1922
1951
|
timeoutMs: timeoutSeconds * 1e3,
|
|
1923
1952
|
credentials: pkceCredentials
|
|
1924
1953
|
});
|
|
1925
|
-
const user = await
|
|
1954
|
+
const user = await cliLogin.getLoggedInUser();
|
|
1926
1955
|
accountId = user.accountId;
|
|
1927
1956
|
customUserId = user.customUserId;
|
|
1928
1957
|
console.log(`\u2705 Successfully logged in as ${user.email}`);
|
|
@@ -1975,7 +2004,7 @@ var LogoutSchema = zod.z.object({}).describe("Log out of your Zapier account");
|
|
|
1975
2004
|
|
|
1976
2005
|
// src/plugins/logout/index.ts
|
|
1977
2006
|
var logoutWithSdk = zapierSdk.createFunction(async function logoutWithSdk2(_options) {
|
|
1978
|
-
|
|
2007
|
+
await cliLogin.logout();
|
|
1979
2008
|
console.log("\u2705 Successfully logged out");
|
|
1980
2009
|
}, LogoutSchema);
|
|
1981
2010
|
var logoutPlugin = () => ({
|
|
@@ -2109,7 +2138,7 @@ var GetLoginConfigPathSchema = zod.z.object({}).describe("Show the path to the l
|
|
|
2109
2138
|
var getLoginConfigPathPlugin = () => {
|
|
2110
2139
|
const getLoginConfigPathWithSdk = zapierSdk.createFunction(
|
|
2111
2140
|
async function getLoginConfigPathWithSdk2(_options) {
|
|
2112
|
-
return
|
|
2141
|
+
return cliLogin.getConfigPath();
|
|
2113
2142
|
},
|
|
2114
2143
|
GetLoginConfigPathSchema
|
|
2115
2144
|
);
|
|
@@ -3144,7 +3173,7 @@ var feedbackPlugin = ({
|
|
|
3144
3173
|
}) => {
|
|
3145
3174
|
const debug = context.options.debug;
|
|
3146
3175
|
const feedbackWithSdk = zapierSdk.createFunction(async function feedback(options) {
|
|
3147
|
-
const user = await
|
|
3176
|
+
const user = await cliLogin.getLoggedInUser();
|
|
3148
3177
|
const body = JSON.stringify({
|
|
3149
3178
|
email: user.email,
|
|
3150
3179
|
customuser_id: user.customUserId,
|
|
@@ -3604,19 +3633,13 @@ var cliOverridesPlugin = ({ context }) => {
|
|
|
3604
3633
|
}
|
|
3605
3634
|
};
|
|
3606
3635
|
};
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
}
|
|
3615
|
-
|
|
3616
|
-
// package.json with { type: 'json' }
|
|
3617
|
-
var package_default2 = {
|
|
3618
|
-
name: "@zapier/zapier-sdk-cli",
|
|
3619
|
-
version: "0.32.4"};
|
|
3636
|
+
var TEMPLATES = ["basic"];
|
|
3637
|
+
var InitSchema = zod.z.object({
|
|
3638
|
+
projectName: zod.z.string().min(1).describe("Name of the project directory to create"),
|
|
3639
|
+
skipPrompts: zod.z.boolean().optional().describe("Skip all interactive prompts and accept all defaults")
|
|
3640
|
+
}).describe(
|
|
3641
|
+
"Create a new Zapier SDK project in a new directory with starter files"
|
|
3642
|
+
);
|
|
3620
3643
|
function detectPackageManager(cwd = process.cwd()) {
|
|
3621
3644
|
const ua = process.env.npm_config_user_agent;
|
|
3622
3645
|
if (ua) {
|
|
@@ -3665,13 +3688,462 @@ function getUpdateCommand(packageName) {
|
|
|
3665
3688
|
}
|
|
3666
3689
|
}
|
|
3667
3690
|
}
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3691
|
+
function getDirentParentPath(entry) {
|
|
3692
|
+
const e = entry;
|
|
3693
|
+
const parent = e.parentPath ?? e.path;
|
|
3694
|
+
if (!parent)
|
|
3695
|
+
throw new Error(
|
|
3696
|
+
"readdirSync entry missing parentPath/path \u2014 unsupported Node version"
|
|
3697
|
+
);
|
|
3698
|
+
return parent;
|
|
3699
|
+
}
|
|
3700
|
+
function toProjectName(name) {
|
|
3701
|
+
return name.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
3702
|
+
}
|
|
3703
|
+
function validateInitOptions({
|
|
3704
|
+
rawName,
|
|
3705
|
+
cwd
|
|
3706
|
+
}) {
|
|
3707
|
+
const projectName = toProjectName(rawName);
|
|
3708
|
+
if (!projectName) {
|
|
3709
|
+
throw new Error(
|
|
3710
|
+
`"${rawName}" results in an empty project name. Provide a name with at least one letter or number.`
|
|
3711
|
+
);
|
|
3712
|
+
}
|
|
3713
|
+
const projectDir = path.join(cwd, projectName);
|
|
3714
|
+
if (fs.existsSync(projectDir)) {
|
|
3715
|
+
const contents = fs.readdirSync(projectDir);
|
|
3716
|
+
if (contents.length > 0) {
|
|
3717
|
+
throw new Error(
|
|
3718
|
+
`Directory "${projectName}" already exists and is not empty. Choose a different name.`
|
|
3719
|
+
);
|
|
3720
|
+
}
|
|
3721
|
+
}
|
|
3722
|
+
return { projectName, projectDir };
|
|
3723
|
+
}
|
|
3724
|
+
function createExec({ cwd }) {
|
|
3725
|
+
return (cmd) => child_process.execSync(cmd, {
|
|
3726
|
+
cwd,
|
|
3727
|
+
stdio: "inherit",
|
|
3728
|
+
shell: process.platform === "win32" ? "cmd.exe" : "/bin/sh"
|
|
3729
|
+
});
|
|
3730
|
+
}
|
|
3731
|
+
async function promptYesNo({
|
|
3732
|
+
message,
|
|
3733
|
+
defaultValue,
|
|
3734
|
+
skipPrompts
|
|
3735
|
+
}) {
|
|
3736
|
+
if (skipPrompts) return defaultValue;
|
|
3737
|
+
const { answer } = await inquirer__default.default.prompt([
|
|
3738
|
+
{ type: "confirm", name: "answer", message, default: defaultValue }
|
|
3739
|
+
]);
|
|
3740
|
+
return answer;
|
|
3741
|
+
}
|
|
3742
|
+
function getPackageManagerCommands({
|
|
3743
|
+
packageManager
|
|
3744
|
+
}) {
|
|
3745
|
+
return {
|
|
3746
|
+
installCmd: `${packageManager} install`,
|
|
3747
|
+
devCmd: packageManager === "yarn" ? "yarn dev" : `${packageManager} run dev`,
|
|
3748
|
+
devScript: packageManager === "bun" ? "bun src/index.ts" : "tsx src/index.ts",
|
|
3749
|
+
execCmd: {
|
|
3750
|
+
npm: "npx",
|
|
3751
|
+
yarn: "yarn dlx",
|
|
3752
|
+
pnpm: "pnpm dlx",
|
|
3753
|
+
bun: "bunx"
|
|
3754
|
+
}[packageManager]
|
|
3755
|
+
};
|
|
3756
|
+
}
|
|
3757
|
+
function isTemplateFile(name) {
|
|
3758
|
+
return path.extname(name) === ".hbs";
|
|
3759
|
+
}
|
|
3760
|
+
function getDestRelPath(relPath, isTemplate) {
|
|
3761
|
+
return isTemplate ? relPath.slice(0, -path.extname(relPath).length) : relPath;
|
|
3762
|
+
}
|
|
3763
|
+
function renderTemplate(srcPath, variables) {
|
|
3764
|
+
const source = fs.readFileSync(srcPath, "utf-8");
|
|
3765
|
+
const template = Handlebars__default.default.compile(source, { noEscape: true });
|
|
3766
|
+
return template(variables);
|
|
3767
|
+
}
|
|
3768
|
+
function buildTemplateVariables({
|
|
3769
|
+
projectName,
|
|
3770
|
+
packageManager
|
|
3771
|
+
}) {
|
|
3772
|
+
const { execCmd, devScript, devCmd } = getPackageManagerCommands({
|
|
3773
|
+
packageManager
|
|
3774
|
+
});
|
|
3775
|
+
return {
|
|
3776
|
+
projectName,
|
|
3777
|
+
execCmd,
|
|
3778
|
+
devScript,
|
|
3779
|
+
devCmd,
|
|
3780
|
+
includeTsx: packageManager !== "bun"
|
|
3781
|
+
};
|
|
3782
|
+
}
|
|
3783
|
+
function cleanupProject({ projectDir }) {
|
|
3784
|
+
console.log("\n" + chalk6__default.default.yellow("!") + " Cleaning up...");
|
|
3785
|
+
fs.rmSync(projectDir, { recursive: true, force: true });
|
|
3786
|
+
}
|
|
3787
|
+
async function withInterruptCleanup(cleanup, fn) {
|
|
3788
|
+
if (!cleanup) return fn();
|
|
3789
|
+
const handler = () => {
|
|
3790
|
+
cleanup();
|
|
3791
|
+
process.removeListener("SIGINT", handler);
|
|
3792
|
+
process.kill(process.pid, "SIGINT");
|
|
3793
|
+
};
|
|
3794
|
+
process.on("SIGINT", handler);
|
|
3795
|
+
try {
|
|
3796
|
+
return await fn();
|
|
3797
|
+
} finally {
|
|
3798
|
+
process.removeListener("SIGINT", handler);
|
|
3799
|
+
}
|
|
3800
|
+
}
|
|
3801
|
+
function createProjectDir({
|
|
3802
|
+
projectDir,
|
|
3803
|
+
projectName
|
|
3804
|
+
}) {
|
|
3805
|
+
try {
|
|
3806
|
+
fs.mkdirSync(projectDir, { recursive: true });
|
|
3807
|
+
} catch (err) {
|
|
3808
|
+
if (err instanceof Error) {
|
|
3809
|
+
const code = err.code;
|
|
3810
|
+
if (code === "EACCES") {
|
|
3811
|
+
throw new Error(
|
|
3812
|
+
`Permission denied creating "${projectName}". Check directory permissions.`
|
|
3813
|
+
);
|
|
3814
|
+
}
|
|
3815
|
+
if (code === "ENOSPC") {
|
|
3816
|
+
throw new Error("No space left on device.");
|
|
3817
|
+
}
|
|
3818
|
+
}
|
|
3819
|
+
throw err;
|
|
3820
|
+
}
|
|
3821
|
+
}
|
|
3822
|
+
var TEMPLATES_DIR = url.fileURLToPath(
|
|
3823
|
+
new URL("../templates", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)))
|
|
3824
|
+
);
|
|
3825
|
+
|
|
3826
|
+
// src/plugins/init/steps.ts
|
|
3827
|
+
var DEFAULT_TEMPLATE = "basic";
|
|
3828
|
+
function getTemplateDir({
|
|
3829
|
+
template = DEFAULT_TEMPLATE
|
|
3830
|
+
} = {}) {
|
|
3831
|
+
const dirPath = path.join(TEMPLATES_DIR, template);
|
|
3832
|
+
if (!fs.existsSync(dirPath)) {
|
|
3833
|
+
throw new Error(
|
|
3834
|
+
`Template "${template}" not found at ${dirPath}. Available templates: ${TEMPLATES.join(", ")}`
|
|
3835
|
+
);
|
|
3836
|
+
}
|
|
3837
|
+
return dirPath;
|
|
3838
|
+
}
|
|
3839
|
+
function scaffoldFiles({
|
|
3840
|
+
projectDir,
|
|
3841
|
+
templatesDir,
|
|
3842
|
+
variables = {},
|
|
3843
|
+
displayHooks
|
|
3844
|
+
}) {
|
|
3845
|
+
const entries = fs.readdirSync(templatesDir, {
|
|
3846
|
+
withFileTypes: true,
|
|
3847
|
+
recursive: true
|
|
3848
|
+
});
|
|
3849
|
+
const files = entries.filter((e) => e.isFile());
|
|
3850
|
+
if (files.length === 0) {
|
|
3851
|
+
throw new Error(`Template directory "${templatesDir}" contains no files.`);
|
|
3852
|
+
}
|
|
3853
|
+
for (const entry of files) {
|
|
3854
|
+
const srcPath = path.join(getDirentParentPath(entry), entry.name);
|
|
3855
|
+
const relPath = path.relative(templatesDir, srcPath);
|
|
3856
|
+
const isTemplate = isTemplateFile(entry.name);
|
|
3857
|
+
const destRelPath = getDestRelPath(relPath, isTemplate);
|
|
3858
|
+
const destPath = path.join(projectDir, destRelPath);
|
|
3859
|
+
fs.mkdirSync(path.dirname(destPath), { recursive: true });
|
|
3860
|
+
if (isTemplate) {
|
|
3861
|
+
fs.writeFileSync(destPath, renderTemplate(srcPath, variables));
|
|
3862
|
+
} else {
|
|
3863
|
+
fs.copyFileSync(srcPath, destPath);
|
|
3864
|
+
}
|
|
3865
|
+
displayHooks?.onItemComplete?.(destRelPath);
|
|
3866
|
+
}
|
|
3867
|
+
}
|
|
3868
|
+
function scaffoldProject({
|
|
3869
|
+
projectDir,
|
|
3870
|
+
projectName,
|
|
3871
|
+
packageManager,
|
|
3872
|
+
template,
|
|
3873
|
+
displayHooks
|
|
3874
|
+
}) {
|
|
3875
|
+
const variables = buildTemplateVariables({ projectName, packageManager });
|
|
3876
|
+
const templatesDir = getTemplateDir({ template });
|
|
3877
|
+
createProjectDir({ projectDir, projectName });
|
|
3878
|
+
scaffoldFiles({ projectDir, templatesDir, variables, displayHooks });
|
|
3879
|
+
}
|
|
3880
|
+
async function runStep({
|
|
3881
|
+
step,
|
|
3882
|
+
stepNumber,
|
|
3883
|
+
totalSteps,
|
|
3884
|
+
skipPrompts,
|
|
3885
|
+
displayHooks
|
|
3886
|
+
}) {
|
|
3887
|
+
if (step.askConfirmation) {
|
|
3888
|
+
const should = await promptYesNo({
|
|
3889
|
+
message: step.description,
|
|
3890
|
+
defaultValue: true,
|
|
3891
|
+
skipPrompts
|
|
3892
|
+
});
|
|
3893
|
+
if (!should) return false;
|
|
3894
|
+
}
|
|
3895
|
+
displayHooks?.onStepStart({
|
|
3896
|
+
description: step.description,
|
|
3897
|
+
stepNumber,
|
|
3898
|
+
totalSteps,
|
|
3899
|
+
command: step.command,
|
|
3900
|
+
skipPrompts
|
|
3901
|
+
});
|
|
3902
|
+
try {
|
|
3903
|
+
await step.run();
|
|
3904
|
+
displayHooks?.onStepSuccess({ stepNumber, totalSteps });
|
|
3905
|
+
return true;
|
|
3906
|
+
} catch (err) {
|
|
3907
|
+
step.cleanup?.();
|
|
3908
|
+
displayHooks?.onStepError({
|
|
3909
|
+
description: step.description,
|
|
3910
|
+
command: step.command,
|
|
3911
|
+
err
|
|
3912
|
+
});
|
|
3913
|
+
return false;
|
|
3914
|
+
}
|
|
3915
|
+
}
|
|
3916
|
+
function getInitSteps({
|
|
3917
|
+
projectDir,
|
|
3918
|
+
projectName,
|
|
3919
|
+
packageManager,
|
|
3920
|
+
template,
|
|
3921
|
+
displayHooks
|
|
3922
|
+
}) {
|
|
3923
|
+
if (template !== void 0 && !TEMPLATES.includes(template)) {
|
|
3924
|
+
throw new Error(
|
|
3925
|
+
`Unknown template "${template}". Available templates: ${TEMPLATES.join(", ")}`
|
|
3926
|
+
);
|
|
3927
|
+
}
|
|
3928
|
+
const { installCmd, execCmd, devCmd } = getPackageManagerCommands({
|
|
3929
|
+
packageManager
|
|
3930
|
+
});
|
|
3931
|
+
const exec = createExec({ cwd: projectDir });
|
|
3932
|
+
return [
|
|
3933
|
+
{
|
|
3934
|
+
id: "scaffold",
|
|
3935
|
+
description: "Scaffold project files",
|
|
3936
|
+
cleanup: () => cleanupProject({ projectDir }),
|
|
3937
|
+
run: () => scaffoldProject({
|
|
3938
|
+
projectDir,
|
|
3939
|
+
projectName,
|
|
3940
|
+
packageManager,
|
|
3941
|
+
template,
|
|
3942
|
+
displayHooks
|
|
3943
|
+
})
|
|
3944
|
+
},
|
|
3945
|
+
{
|
|
3946
|
+
id: "install-deps",
|
|
3947
|
+
description: "Install dependencies",
|
|
3948
|
+
askConfirmation: true,
|
|
3949
|
+
command: installCmd,
|
|
3950
|
+
run: () => exec(installCmd)
|
|
3951
|
+
},
|
|
3952
|
+
{
|
|
3953
|
+
id: "login",
|
|
3954
|
+
description: "Log in to Zapier",
|
|
3955
|
+
askConfirmation: true,
|
|
3956
|
+
command: `${execCmd} zapier-sdk login`,
|
|
3957
|
+
run: () => exec(`${execCmd} zapier-sdk login`)
|
|
3958
|
+
},
|
|
3959
|
+
{
|
|
3960
|
+
id: "run",
|
|
3961
|
+
description: "Run your app",
|
|
3962
|
+
askConfirmation: true,
|
|
3963
|
+
command: devCmd,
|
|
3964
|
+
run: () => exec(devCmd)
|
|
3965
|
+
}
|
|
3966
|
+
];
|
|
3967
|
+
}
|
|
3968
|
+
function buildNextSteps({
|
|
3969
|
+
projectName,
|
|
3970
|
+
leftoverSteps,
|
|
3971
|
+
execCmd
|
|
3972
|
+
}) {
|
|
3973
|
+
return [
|
|
3974
|
+
{
|
|
3975
|
+
description: "Change into your project directory",
|
|
3976
|
+
command: `cd ${projectName}`
|
|
3977
|
+
},
|
|
3978
|
+
...leftoverSteps.map(({ description, command }) => ({
|
|
3979
|
+
description,
|
|
3980
|
+
command
|
|
3981
|
+
})),
|
|
3982
|
+
{
|
|
3983
|
+
description: "Search for an app to integrate",
|
|
3984
|
+
command: `${execCmd} zapier-sdk list-apps --search "<app name>"`
|
|
3985
|
+
},
|
|
3986
|
+
{
|
|
3987
|
+
description: "Add an app and generate TypeScript types",
|
|
3988
|
+
command: `${execCmd} zapier-sdk add <app-key>`
|
|
3989
|
+
}
|
|
3990
|
+
];
|
|
3991
|
+
}
|
|
3992
|
+
function createConsoleDisplayHooks() {
|
|
3993
|
+
return {
|
|
3994
|
+
onItemComplete: (message) => console.log(" " + chalk6__default.default.green("\u2713") + " " + chalk6__default.default.dim(message)),
|
|
3995
|
+
onWarn: (message) => console.warn(chalk6__default.default.yellow("!") + " " + message),
|
|
3996
|
+
onStepStart: ({
|
|
3997
|
+
description,
|
|
3998
|
+
stepNumber,
|
|
3999
|
+
totalSteps,
|
|
4000
|
+
command,
|
|
4001
|
+
skipPrompts
|
|
4002
|
+
}) => {
|
|
4003
|
+
const progressMessage = `${description}...`;
|
|
4004
|
+
const stepCounter = chalk6__default.default.dim(`${stepNumber}/${totalSteps}`);
|
|
4005
|
+
if (skipPrompts) {
|
|
4006
|
+
console.log(
|
|
4007
|
+
"\n" + chalk6__default.default.bold(`\u276F ${progressMessage}`) + " " + stepCounter + "\n"
|
|
4008
|
+
);
|
|
4009
|
+
} else {
|
|
4010
|
+
console.log(
|
|
4011
|
+
chalk6__default.default.dim("\u2192") + " " + progressMessage + " " + stepCounter
|
|
4012
|
+
);
|
|
4013
|
+
}
|
|
4014
|
+
if (command) {
|
|
4015
|
+
console.log(" " + chalk6__default.default.cyan(`$ ${command}`));
|
|
4016
|
+
}
|
|
4017
|
+
},
|
|
4018
|
+
onStepSuccess: ({ stepNumber, totalSteps }) => console.log(
|
|
4019
|
+
"\n" + chalk6__default.default.green("\u2713") + " " + chalk6__default.default.dim(`Step ${stepNumber}/${totalSteps} complete`) + "\n"
|
|
4020
|
+
),
|
|
4021
|
+
onStepError: ({ description, command, err }) => {
|
|
4022
|
+
const detail = err instanceof Error && err.message ? `
|
|
4023
|
+
${chalk6__default.default.dim(err.message)}` : "";
|
|
4024
|
+
const hint = command ? `
|
|
4025
|
+
${chalk6__default.default.dim("run manually:")} ${chalk6__default.default.cyan(`$ ${command}`)}` : "";
|
|
4026
|
+
console.error(
|
|
4027
|
+
`
|
|
4028
|
+
${chalk6__default.default.red("\u2716")} ${chalk6__default.default.bold(description)}${chalk6__default.default.dim(" failed")}${detail}${hint}`
|
|
4029
|
+
);
|
|
4030
|
+
}
|
|
4031
|
+
};
|
|
4032
|
+
}
|
|
4033
|
+
function displaySummaryAndNextSteps({
|
|
4034
|
+
projectName,
|
|
4035
|
+
steps,
|
|
4036
|
+
completedSetupStepIds,
|
|
4037
|
+
packageManager
|
|
4038
|
+
}) {
|
|
4039
|
+
const formatStatus = (complete) => ({
|
|
4040
|
+
icon: complete ? chalk6__default.default.green("\u2713") : chalk6__default.default.yellow("!"),
|
|
4041
|
+
text: complete ? chalk6__default.default.green("Setup complete") : chalk6__default.default.yellow("Setup interrupted")
|
|
4042
|
+
});
|
|
4043
|
+
const formatNextStep = (step, i) => " " + chalk6__default.default.dim(`${i + 1}.`) + " " + chalk6__default.default.bold(step.description);
|
|
4044
|
+
const formatCommand = (cmd) => " " + chalk6__default.default.cyan(`$ ${cmd}`);
|
|
4045
|
+
const formatCompletedStep = (step) => " " + chalk6__default.default.green("\u2713") + " " + step.description;
|
|
4046
|
+
const { execCmd } = getPackageManagerCommands({ packageManager });
|
|
4047
|
+
const leftoverSteps = steps.filter(
|
|
4048
|
+
(s) => !completedSetupStepIds.includes(s.id)
|
|
4049
|
+
);
|
|
4050
|
+
const isComplete = leftoverSteps.length === 0;
|
|
4051
|
+
const status = formatStatus(isComplete);
|
|
4052
|
+
console.log("\n" + chalk6__default.default.bold("\u276F Summary") + "\n");
|
|
4053
|
+
console.log(" " + chalk6__default.default.dim("Project") + " " + chalk6__default.default.bold(projectName));
|
|
4054
|
+
console.log(
|
|
4055
|
+
" " + chalk6__default.default.dim("Status") + " " + status.icon + " " + status.text
|
|
4056
|
+
);
|
|
4057
|
+
const completedSteps = steps.filter(
|
|
4058
|
+
(s) => completedSetupStepIds.includes(s.id)
|
|
4059
|
+
);
|
|
4060
|
+
if (completedSteps.length > 0) {
|
|
4061
|
+
console.log();
|
|
4062
|
+
for (const step of completedSteps) console.log(formatCompletedStep(step));
|
|
3672
4063
|
}
|
|
3673
|
-
|
|
4064
|
+
const nextSteps = buildNextSteps({ projectName, leftoverSteps, execCmd });
|
|
4065
|
+
console.log("\n" + chalk6__default.default.bold("\u276F Next Steps") + "\n");
|
|
4066
|
+
nextSteps.forEach((step, i) => {
|
|
4067
|
+
console.log(formatNextStep(step, i));
|
|
4068
|
+
if (step.command) console.log(formatCommand(step.command));
|
|
4069
|
+
console.log();
|
|
4070
|
+
});
|
|
3674
4071
|
}
|
|
4072
|
+
|
|
4073
|
+
// src/plugins/init/index.ts
|
|
4074
|
+
var initPlugin = () => {
|
|
4075
|
+
const init = zapierSdk.createFunction(async function init2(options) {
|
|
4076
|
+
const { projectName: rawName, skipPrompts = false } = options;
|
|
4077
|
+
const cwd = process.cwd();
|
|
4078
|
+
const { projectName, projectDir } = validateInitOptions({ rawName, cwd });
|
|
4079
|
+
const displayHooks = createConsoleDisplayHooks();
|
|
4080
|
+
const packageManagerInfo = detectPackageManager(cwd);
|
|
4081
|
+
if (packageManagerInfo.name === "unknown") {
|
|
4082
|
+
displayHooks.onWarn(
|
|
4083
|
+
"Could not detect package manager, defaulting to npm."
|
|
4084
|
+
);
|
|
4085
|
+
}
|
|
4086
|
+
const packageManager = packageManagerInfo.name === "unknown" ? "npm" : packageManagerInfo.name;
|
|
4087
|
+
const steps = getInitSteps({
|
|
4088
|
+
projectDir,
|
|
4089
|
+
projectName,
|
|
4090
|
+
packageManager,
|
|
4091
|
+
displayHooks
|
|
4092
|
+
});
|
|
4093
|
+
const completedSetupStepIds = [];
|
|
4094
|
+
for (let i = 0; i < steps.length; i++) {
|
|
4095
|
+
const step = steps[i];
|
|
4096
|
+
const succeeded = await withInterruptCleanup(
|
|
4097
|
+
step.cleanup,
|
|
4098
|
+
() => runStep({
|
|
4099
|
+
step,
|
|
4100
|
+
stepNumber: i + 1,
|
|
4101
|
+
totalSteps: steps.length,
|
|
4102
|
+
skipPrompts,
|
|
4103
|
+
displayHooks
|
|
4104
|
+
})
|
|
4105
|
+
);
|
|
4106
|
+
if (!succeeded) break;
|
|
4107
|
+
completedSetupStepIds.push(step.id);
|
|
4108
|
+
}
|
|
4109
|
+
if (completedSetupStepIds.length === 0) {
|
|
4110
|
+
throw new ZapierCliExitError(
|
|
4111
|
+
"Project setup failed \u2014 no steps completed."
|
|
4112
|
+
);
|
|
4113
|
+
}
|
|
4114
|
+
displaySummaryAndNextSteps({
|
|
4115
|
+
projectName,
|
|
4116
|
+
steps,
|
|
4117
|
+
completedSetupStepIds,
|
|
4118
|
+
packageManager
|
|
4119
|
+
});
|
|
4120
|
+
}, InitSchema);
|
|
4121
|
+
return {
|
|
4122
|
+
init,
|
|
4123
|
+
context: {
|
|
4124
|
+
meta: {
|
|
4125
|
+
init: {
|
|
4126
|
+
categories: ["utility"],
|
|
4127
|
+
inputSchema: InitSchema
|
|
4128
|
+
}
|
|
4129
|
+
}
|
|
4130
|
+
}
|
|
4131
|
+
};
|
|
4132
|
+
};
|
|
4133
|
+
|
|
4134
|
+
// src/sdk.ts
|
|
4135
|
+
zapierSdk.injectCliLogin(cliLogin__namespace);
|
|
4136
|
+
function createZapierCliSdk(options = {}) {
|
|
4137
|
+
return zapierSdk.createZapierSdkWithoutRegistry({
|
|
4138
|
+
...options,
|
|
4139
|
+
eventEmission: { ...options.eventEmission, callContext: "cli" }
|
|
4140
|
+
}).addPlugin(generateAppTypesPlugin).addPlugin(buildManifestPlugin).addPlugin(bundleCodePlugin).addPlugin(getLoginConfigPathPlugin).addPlugin(addPlugin).addPlugin(feedbackPlugin).addPlugin(curlPlugin).addPlugin(initPlugin).addPlugin(mcpPlugin).addPlugin(loginPlugin).addPlugin(logoutPlugin).addPlugin(cliOverridesPlugin).addPlugin(zapierSdk.registryPlugin);
|
|
4141
|
+
}
|
|
4142
|
+
|
|
4143
|
+
// package.json with { type: 'json' }
|
|
4144
|
+
var package_default2 = {
|
|
4145
|
+
name: "@zapier/zapier-sdk-cli",
|
|
4146
|
+
version: "0.34.1"};
|
|
3675
4147
|
var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
|
|
3676
4148
|
var CACHE_RESET_INTERVAL_MS = (() => {
|
|
3677
4149
|
const { ZAPIER_SDK_UPDATE_CHECK_INTERVAL_MS = `${ONE_DAY_MS}` } = process.env;
|
|
@@ -3683,14 +4155,14 @@ var CACHE_RESET_INTERVAL_MS = (() => {
|
|
|
3683
4155
|
})();
|
|
3684
4156
|
function getVersionCache() {
|
|
3685
4157
|
try {
|
|
3686
|
-
const cache = getConfig().get("version_cache");
|
|
4158
|
+
const cache = cliLogin.getConfig().get("version_cache");
|
|
3687
4159
|
const now = Date.now();
|
|
3688
4160
|
if (!cache || !cache.last_reset_timestamp || now - cache.last_reset_timestamp >= CACHE_RESET_INTERVAL_MS) {
|
|
3689
4161
|
const newCache = {
|
|
3690
4162
|
last_reset_timestamp: now,
|
|
3691
4163
|
packages: {}
|
|
3692
4164
|
};
|
|
3693
|
-
getConfig().set("version_cache", newCache);
|
|
4165
|
+
cliLogin.getConfig().set("version_cache", newCache);
|
|
3694
4166
|
return newCache;
|
|
3695
4167
|
}
|
|
3696
4168
|
return cache;
|
|
@@ -3709,7 +4181,7 @@ function setCachedPackageInfo(packageName, version, info) {
|
|
|
3709
4181
|
cache.packages[packageName] = {};
|
|
3710
4182
|
}
|
|
3711
4183
|
cache.packages[packageName][version] = info;
|
|
3712
|
-
getConfig().set("version_cache", cache);
|
|
4184
|
+
cliLogin.getConfig().set("version_cache", cache);
|
|
3713
4185
|
} catch (error) {
|
|
3714
4186
|
log_default.debug(`Failed to cache package info: ${error}`);
|
|
3715
4187
|
}
|
|
@@ -3781,26 +4253,26 @@ function displayUpdateNotification(versionInfo, packageName) {
|
|
|
3781
4253
|
if (versionInfo.isDeprecated) {
|
|
3782
4254
|
console.error();
|
|
3783
4255
|
console.error(
|
|
3784
|
-
|
|
4256
|
+
chalk6__default.default.red.bold("\u26A0\uFE0F DEPRECATION WARNING") + chalk6__default.default.red(
|
|
3785
4257
|
` - ${packageName} v${versionInfo.currentVersion} is deprecated.`
|
|
3786
4258
|
)
|
|
3787
4259
|
);
|
|
3788
4260
|
if (versionInfo.deprecationMessage) {
|
|
3789
|
-
console.error(
|
|
4261
|
+
console.error(chalk6__default.default.red(` ${versionInfo.deprecationMessage}`));
|
|
3790
4262
|
}
|
|
3791
|
-
console.error(
|
|
4263
|
+
console.error(chalk6__default.default.red(` Please update to the latest version.`));
|
|
3792
4264
|
console.error();
|
|
3793
4265
|
}
|
|
3794
4266
|
if (versionInfo.hasUpdate) {
|
|
3795
4267
|
console.error();
|
|
3796
4268
|
console.error(
|
|
3797
|
-
|
|
4269
|
+
chalk6__default.default.yellow.bold("\u{1F4E6} Update available!") + chalk6__default.default.yellow(
|
|
3798
4270
|
` ${packageName} v${versionInfo.currentVersion} \u2192 v${versionInfo.latestVersion}`
|
|
3799
4271
|
)
|
|
3800
4272
|
);
|
|
3801
4273
|
console.error(
|
|
3802
|
-
|
|
3803
|
-
` Run ${
|
|
4274
|
+
chalk6__default.default.yellow(
|
|
4275
|
+
` Run ${chalk6__default.default.bold(getUpdateCommand(packageName))} to update.`
|
|
3804
4276
|
)
|
|
3805
4277
|
);
|
|
3806
4278
|
console.error();
|
|
@@ -3818,6 +4290,7 @@ async function checkAndNotifyUpdates({
|
|
|
3818
4290
|
}
|
|
3819
4291
|
|
|
3820
4292
|
// src/cli.ts
|
|
4293
|
+
var EXIT_GRACE_PERIOD_MS = 500;
|
|
3821
4294
|
var program = new commander.Command();
|
|
3822
4295
|
var versionOption = getReservedCliOption("version" /* Version */);
|
|
3823
4296
|
var helpOption = getReservedCliOption("help" /* Help */);
|
|
@@ -3908,5 +4381,11 @@ program.exitOverride();
|
|
|
3908
4381
|
}
|
|
3909
4382
|
}
|
|
3910
4383
|
await versionCheckPromise;
|
|
4384
|
+
await sdk.getContext().eventEmission.close(exitCode);
|
|
4385
|
+
const exitTimeout = setTimeout(
|
|
4386
|
+
() => process.exit(exitCode),
|
|
4387
|
+
EXIT_GRACE_PERIOD_MS
|
|
4388
|
+
);
|
|
4389
|
+
exitTimeout.unref();
|
|
3911
4390
|
process.exitCode = exitCode;
|
|
3912
4391
|
})();
|