@zapier/zapier-sdk-cli 0.32.4 → 0.34.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/CHANGELOG.md +19 -0
- package/README.md +39 -2
- package/dist/cli.cjs +582 -110
- package/dist/cli.mjs +573 -102
- package/dist/index.cjs +531 -18
- package/dist/index.mjs +525 -15
- package/dist/package.json +3 -2
- 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.mjs
CHANGED
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command, CommanderError } from 'commander';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { createFunction, OutputPropertySchema, DEFAULT_CONFIG_PATH, createZapierSdkWithoutRegistry, registryPlugin, ZapierError, ZapierValidationError, ZapierUnknownError, batch, toSnakeCase, formatErrorMessage, isCredentialsObject, getOsInfo, getPlatformVersions, getCiPlatform, isCi, isPositional, getReleaseId, getCurrentTimestamp, generateEventId } from '@zapier/zapier-sdk';
|
|
4
|
+
import { createFunction, OutputPropertySchema, DEFAULT_CONFIG_PATH, injectCliLogin, createZapierSdkWithoutRegistry, registryPlugin, ZapierError, ZapierValidationError, ZapierUnknownError, batch, toSnakeCase, formatErrorMessage, isCredentialsObject, getOsInfo, getPlatformVersions, getCiPlatform, isCi, isPositional, getReleaseId, getCurrentTimestamp, generateEventId } from '@zapier/zapier-sdk';
|
|
5
5
|
import inquirer from 'inquirer';
|
|
6
|
-
import
|
|
6
|
+
import chalk6 from 'chalk';
|
|
7
7
|
import util from 'util';
|
|
8
|
+
import * as cliLogin from '@zapier/zapier-sdk-cli-login';
|
|
9
|
+
import { logout, getConfigPath, getLoggedInUser, getPkceLoginConfig, AUTH_MODE_HEADER, getLoginStorageMode, updateLogin, getConfig } from '@zapier/zapier-sdk-cli-login';
|
|
8
10
|
import open from 'open';
|
|
9
11
|
import crypto, { createHash } from 'crypto';
|
|
10
12
|
import express from 'express';
|
|
11
13
|
import pkceChallenge from 'pkce-challenge';
|
|
12
|
-
import { logout, getConfigPath, getLoggedInUser, getPkceLoginConfig, AUTH_MODE_HEADER, updateLogin } from '@zapier/zapier-sdk-cli-login';
|
|
13
14
|
import ora from 'ora';
|
|
14
15
|
import { startMcpServer } from '@zapier/zapier-sdk-mcp';
|
|
15
16
|
import { buildSync } from 'esbuild';
|
|
16
17
|
import * as fs from 'fs';
|
|
17
|
-
import { promises, createWriteStream, existsSync } from 'fs';
|
|
18
|
+
import { promises, createWriteStream, existsSync, readdirSync, rmSync, mkdirSync, writeFileSync, copyFileSync, readFileSync } from 'fs';
|
|
18
19
|
import * as path from 'path';
|
|
19
|
-
import { resolve, join, dirname, basename } from 'path';
|
|
20
|
+
import { resolve, join, dirname, basename, relative, extname } from 'path';
|
|
20
21
|
import { mkdir, writeFile, access } from 'fs/promises';
|
|
21
22
|
import * as ts from 'typescript';
|
|
22
|
-
import packageJsonLib from 'package-json';
|
|
23
|
-
import Conf from 'conf';
|
|
24
23
|
import isInstalledGlobally from 'is-installed-globally';
|
|
24
|
+
import { execSync } from 'child_process';
|
|
25
|
+
import Handlebars from 'handlebars';
|
|
26
|
+
import { fileURLToPath } from 'url';
|
|
27
|
+
import packageJsonLib from 'package-json';
|
|
25
28
|
import semver from 'semver';
|
|
26
29
|
|
|
27
30
|
var ZapierCliError = class extends ZapierError {
|
|
@@ -149,7 +152,7 @@ var SchemaParameterResolver = class {
|
|
|
149
152
|
context.resolvedParams = resolvedParams;
|
|
150
153
|
} catch (error) {
|
|
151
154
|
if (this.isUserCancellation(error)) {
|
|
152
|
-
console.log(
|
|
155
|
+
console.log(chalk6.yellow("\n\nOperation cancelled by user"));
|
|
153
156
|
throw new ZapierCliUserCancellationError();
|
|
154
157
|
}
|
|
155
158
|
throw error;
|
|
@@ -187,7 +190,7 @@ var SchemaParameterResolver = class {
|
|
|
187
190
|
context.resolvedParams = resolvedParams;
|
|
188
191
|
} catch (error) {
|
|
189
192
|
if (this.isUserCancellation(error)) {
|
|
190
|
-
console.log(
|
|
193
|
+
console.log(chalk6.yellow("\n\nOperation cancelled by user"));
|
|
191
194
|
throw new ZapierCliUserCancellationError();
|
|
192
195
|
}
|
|
193
196
|
throw error;
|
|
@@ -222,7 +225,7 @@ var SchemaParameterResolver = class {
|
|
|
222
225
|
context.resolvedParams = resolvedParams;
|
|
223
226
|
} catch (error) {
|
|
224
227
|
if (this.isUserCancellation(error)) {
|
|
225
|
-
console.log(
|
|
228
|
+
console.log(chalk6.yellow("\n\nOperation cancelled by user"));
|
|
226
229
|
throw new ZapierCliUserCancellationError();
|
|
227
230
|
}
|
|
228
231
|
throw error;
|
|
@@ -233,7 +236,7 @@ var SchemaParameterResolver = class {
|
|
|
233
236
|
const finalResult = schema.safeParse(resolvedParams);
|
|
234
237
|
if (!finalResult.success) {
|
|
235
238
|
console.error(
|
|
236
|
-
|
|
239
|
+
chalk6.red("\u274C Parameter validation failed after resolution:")
|
|
237
240
|
);
|
|
238
241
|
throw finalResult.error;
|
|
239
242
|
}
|
|
@@ -281,7 +284,7 @@ var SchemaParameterResolver = class {
|
|
|
281
284
|
if (!resolver) {
|
|
282
285
|
throw new Error(`No resolver found for parameter: ${param.name}`);
|
|
283
286
|
}
|
|
284
|
-
console.log(
|
|
287
|
+
console.log(chalk6.blue(`
|
|
285
288
|
\u{1F50D} Resolving ${param.name}...`));
|
|
286
289
|
const typedResolver = resolver;
|
|
287
290
|
if (typedResolver.type === "static") {
|
|
@@ -298,7 +301,7 @@ var SchemaParameterResolver = class {
|
|
|
298
301
|
} else if (typedResolver.type === "dynamic") {
|
|
299
302
|
try {
|
|
300
303
|
if (param.isRequired && param.name !== "connectionId") {
|
|
301
|
-
console.log(
|
|
304
|
+
console.log(chalk6.gray(`Fetching options for ${param.name}...`));
|
|
302
305
|
}
|
|
303
306
|
const items = await typedResolver.fetch(
|
|
304
307
|
context.sdk,
|
|
@@ -339,7 +342,7 @@ var SchemaParameterResolver = class {
|
|
|
339
342
|
}
|
|
340
343
|
};
|
|
341
344
|
console.log(
|
|
342
|
-
|
|
345
|
+
chalk6.gray(
|
|
343
346
|
`Fetching input fields for ${param.name}${iteration > 1 ? ` (iteration ${iteration})` : ""}...`
|
|
344
347
|
)
|
|
345
348
|
);
|
|
@@ -350,7 +353,7 @@ var SchemaParameterResolver = class {
|
|
|
350
353
|
if (!rootFieldItems || rootFieldItems.length === 0) {
|
|
351
354
|
if (iteration === 1) {
|
|
352
355
|
console.log(
|
|
353
|
-
|
|
356
|
+
chalk6.yellow(`No input fields required for this action.`)
|
|
354
357
|
);
|
|
355
358
|
}
|
|
356
359
|
break;
|
|
@@ -372,7 +375,7 @@ var SchemaParameterResolver = class {
|
|
|
372
375
|
}
|
|
373
376
|
if (iteration >= maxIterations) {
|
|
374
377
|
console.log(
|
|
375
|
-
|
|
378
|
+
chalk6.yellow(
|
|
376
379
|
`
|
|
377
380
|
\u26A0\uFE0F Maximum field resolution iterations reached. Some dynamic fields may not have been discovered.`
|
|
378
381
|
)
|
|
@@ -394,7 +397,7 @@ var SchemaParameterResolver = class {
|
|
|
394
397
|
const fieldsetTitle = typedItem.title || typedItem.key;
|
|
395
398
|
const pathDisplay = fieldsetPath.length > 0 ? ` (in ${fieldsetPath.join(" > ")})` : "";
|
|
396
399
|
console.log(
|
|
397
|
-
|
|
400
|
+
chalk6.cyan(
|
|
398
401
|
`
|
|
399
402
|
\u{1F4C1} Processing fieldset: ${fieldsetTitle}${pathDisplay}`
|
|
400
403
|
)
|
|
@@ -426,7 +429,7 @@ var SchemaParameterResolver = class {
|
|
|
426
429
|
newRequiredCount++;
|
|
427
430
|
if (newRequiredCount === 1 && fieldsetPath.length === 0) {
|
|
428
431
|
console.log(
|
|
429
|
-
|
|
432
|
+
chalk6.blue(
|
|
430
433
|
`
|
|
431
434
|
\u{1F4DD} Please provide values for the following ${iteration === 1 ? "" : "additional "}input fields:`
|
|
432
435
|
)
|
|
@@ -447,7 +450,7 @@ var SchemaParameterResolver = class {
|
|
|
447
450
|
if (optionalFields.length > 0) {
|
|
448
451
|
const pathContext = fieldsetPath.length > 0 ? ` in ${fieldsetPath.join(" > ")}` : "";
|
|
449
452
|
console.log(
|
|
450
|
-
|
|
453
|
+
chalk6.gray(
|
|
451
454
|
`
|
|
452
455
|
There are ${optionalFields.length} ${iteration === 1 ? "" : "additional "}optional field(s) available${pathContext}.`
|
|
453
456
|
)
|
|
@@ -462,7 +465,7 @@ There are ${optionalFields.length} ${iteration === 1 ? "" : "additional "}option
|
|
|
462
465
|
}
|
|
463
466
|
]);
|
|
464
467
|
if (shouldConfigureOptional.configure) {
|
|
465
|
-
console.log(
|
|
468
|
+
console.log(chalk6.cyan(`
|
|
466
469
|
Optional fields${pathContext}:`));
|
|
467
470
|
for (const field of optionalFields) {
|
|
468
471
|
await this.promptForField(field, targetInputs, context);
|
|
@@ -478,7 +481,7 @@ Optional fields${pathContext}:`));
|
|
|
478
481
|
}
|
|
479
482
|
} catch (error) {
|
|
480
483
|
if (this.isUserCancellation(error)) {
|
|
481
|
-
console.log(
|
|
484
|
+
console.log(chalk6.yellow("\n\nOperation cancelled by user"));
|
|
482
485
|
throw new ZapierCliUserCancellationError();
|
|
483
486
|
}
|
|
484
487
|
throw error;
|
|
@@ -533,7 +536,7 @@ Optional fields${pathContext}:`));
|
|
|
533
536
|
async fetchChoices(fieldMeta, inputs, context, cursor) {
|
|
534
537
|
try {
|
|
535
538
|
console.log(
|
|
536
|
-
|
|
539
|
+
chalk6.gray(
|
|
537
540
|
cursor ? ` Fetching more choices...` : ` Fetching choices for ${fieldMeta.title}...`
|
|
538
541
|
)
|
|
539
542
|
);
|
|
@@ -552,7 +555,7 @@ Optional fields${pathContext}:`));
|
|
|
552
555
|
}));
|
|
553
556
|
if (choices.length === 0 && !cursor) {
|
|
554
557
|
console.log(
|
|
555
|
-
|
|
558
|
+
chalk6.yellow(` No choices available for ${fieldMeta.title}`)
|
|
556
559
|
);
|
|
557
560
|
}
|
|
558
561
|
return {
|
|
@@ -561,7 +564,7 @@ Optional fields${pathContext}:`));
|
|
|
561
564
|
};
|
|
562
565
|
} catch (error) {
|
|
563
566
|
console.warn(
|
|
564
|
-
|
|
567
|
+
chalk6.yellow(` \u26A0\uFE0F Failed to fetch choices for ${fieldMeta.title}:`),
|
|
565
568
|
error
|
|
566
569
|
);
|
|
567
570
|
return { choices: [] };
|
|
@@ -587,7 +590,7 @@ Optional fields${pathContext}:`));
|
|
|
587
590
|
}));
|
|
588
591
|
if (nextCursor) {
|
|
589
592
|
promptChoices.push({
|
|
590
|
-
name:
|
|
593
|
+
name: chalk6.dim("(Load more...)"),
|
|
591
594
|
value: LOAD_MORE_SENTINEL
|
|
592
595
|
});
|
|
593
596
|
}
|
|
@@ -650,7 +653,7 @@ Optional fields${pathContext}:`));
|
|
|
650
653
|
};
|
|
651
654
|
}
|
|
652
655
|
if (fieldMeta.description) {
|
|
653
|
-
promptConfig.prefix =
|
|
656
|
+
promptConfig.prefix = chalk6.gray(`\u2139 ${fieldMeta.description}
|
|
654
657
|
`);
|
|
655
658
|
}
|
|
656
659
|
try {
|
|
@@ -658,7 +661,7 @@ Optional fields${pathContext}:`));
|
|
|
658
661
|
return answer[fieldMeta.key];
|
|
659
662
|
} catch (error) {
|
|
660
663
|
if (this.isUserCancellation(error)) {
|
|
661
|
-
console.log(
|
|
664
|
+
console.log(chalk6.yellow("\n\nOperation cancelled by user"));
|
|
662
665
|
throw new ZapierCliUserCancellationError();
|
|
663
666
|
}
|
|
664
667
|
throw error;
|
|
@@ -676,7 +679,7 @@ Optional fields${pathContext}:`));
|
|
|
676
679
|
}
|
|
677
680
|
} catch (error) {
|
|
678
681
|
if (this.isUserCancellation(error)) {
|
|
679
|
-
console.log(
|
|
682
|
+
console.log(chalk6.yellow("\n\nOperation cancelled by user"));
|
|
680
683
|
throw new ZapierCliUserCancellationError();
|
|
681
684
|
}
|
|
682
685
|
throw error;
|
|
@@ -780,7 +783,7 @@ function formatItemsFromSchema(functionInfo, items, startingNumber = 0) {
|
|
|
780
783
|
});
|
|
781
784
|
}
|
|
782
785
|
function formatSingleItem(formatted, itemNumber) {
|
|
783
|
-
let titleLine = `${
|
|
786
|
+
let titleLine = `${chalk6.gray(`${itemNumber + 1}.`)} ${chalk6.cyan(formatted.title)}`;
|
|
784
787
|
const subtitleParts = [];
|
|
785
788
|
if (formatted.keys) {
|
|
786
789
|
subtitleParts.push(...formatted.keys);
|
|
@@ -792,11 +795,11 @@ function formatSingleItem(formatted, itemNumber) {
|
|
|
792
795
|
}
|
|
793
796
|
const uniqueParts = [...new Set(subtitleParts)];
|
|
794
797
|
if (uniqueParts.length > 0) {
|
|
795
|
-
titleLine += ` ${
|
|
798
|
+
titleLine += ` ${chalk6.gray(`(${uniqueParts.join(", ")})`)}`;
|
|
796
799
|
}
|
|
797
800
|
console.log(titleLine);
|
|
798
801
|
if (formatted.description) {
|
|
799
|
-
console.log(` ${
|
|
802
|
+
console.log(` ${chalk6.dim(formatted.description)}`);
|
|
800
803
|
}
|
|
801
804
|
if (formatted.data !== void 0) {
|
|
802
805
|
formatJsonOutput(formatted.data);
|
|
@@ -812,16 +815,16 @@ function formatSingleItem(formatted, itemNumber) {
|
|
|
812
815
|
function applyStyle(value, style) {
|
|
813
816
|
switch (style) {
|
|
814
817
|
case "dim":
|
|
815
|
-
return
|
|
818
|
+
return chalk6.dim(value);
|
|
816
819
|
case "accent":
|
|
817
|
-
return
|
|
820
|
+
return chalk6.magenta(value);
|
|
818
821
|
case "warning":
|
|
819
|
-
return
|
|
822
|
+
return chalk6.red(value);
|
|
820
823
|
case "success":
|
|
821
|
-
return
|
|
824
|
+
return chalk6.green(value);
|
|
822
825
|
case "normal":
|
|
823
826
|
default:
|
|
824
|
-
return
|
|
827
|
+
return chalk6.blue(value);
|
|
825
828
|
}
|
|
826
829
|
}
|
|
827
830
|
function convertGenericItemToFormattedItem(item) {
|
|
@@ -884,7 +887,7 @@ async function promptConfirm(confirmType) {
|
|
|
884
887
|
return { confirmed: true };
|
|
885
888
|
}
|
|
886
889
|
const { messageBefore, messageAfter } = CONFIRM_MESSAGES[confirmType];
|
|
887
|
-
console.log(
|
|
890
|
+
console.log(chalk6.yellow(`
|
|
888
891
|
${messageBefore}
|
|
889
892
|
`));
|
|
890
893
|
const { confirmed } = await inquirer.prompt([
|
|
@@ -1054,8 +1057,8 @@ function generateCliCommands(program2, sdk2) {
|
|
|
1054
1057
|
return;
|
|
1055
1058
|
}
|
|
1056
1059
|
const cliCommandName = methodNameToCliCommand(fnInfo.name);
|
|
1057
|
-
const
|
|
1058
|
-
addCommand(program2, cliCommandName,
|
|
1060
|
+
const config = createCommandConfig(cliCommandName, fnInfo, sdk2);
|
|
1061
|
+
addCommand(program2, cliCommandName, config);
|
|
1059
1062
|
});
|
|
1060
1063
|
program2.configureHelp({
|
|
1061
1064
|
formatHelp: (cmd, helper) => {
|
|
@@ -1155,7 +1158,7 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
|
1155
1158
|
if (confirm && !shouldUseJson) {
|
|
1156
1159
|
const confirmResult = await promptConfirm(confirm);
|
|
1157
1160
|
if (!confirmResult.confirmed) {
|
|
1158
|
-
console.log(
|
|
1161
|
+
console.log(chalk6.yellow("Operation cancelled."));
|
|
1159
1162
|
return;
|
|
1160
1163
|
}
|
|
1161
1164
|
confirmMessageAfter = confirmResult.messageAfter;
|
|
@@ -1174,9 +1177,9 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
|
1174
1177
|
const sdkObj = sdk2;
|
|
1175
1178
|
await sdkObj[functionInfo.name](resolvedParams);
|
|
1176
1179
|
console.log(
|
|
1177
|
-
|
|
1180
|
+
chalk6.green(`\u2705 ${cliCommandName} completed successfully!`)
|
|
1178
1181
|
);
|
|
1179
|
-
console.log(
|
|
1182
|
+
console.log(chalk6.gray(`Output written to: ${hasOutputFile}`));
|
|
1180
1183
|
return;
|
|
1181
1184
|
}
|
|
1182
1185
|
let result;
|
|
@@ -1223,7 +1226,7 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
|
1223
1226
|
formatJsonOutput(items);
|
|
1224
1227
|
}
|
|
1225
1228
|
if (confirmMessageAfter) {
|
|
1226
|
-
console.log(
|
|
1229
|
+
console.log(chalk6.yellow(`
|
|
1227
1230
|
${confirmMessageAfter}`));
|
|
1228
1231
|
}
|
|
1229
1232
|
}
|
|
@@ -1231,23 +1234,23 @@ ${confirmMessageAfter}`));
|
|
|
1231
1234
|
if (error instanceof Error && error.message.includes('"code"')) {
|
|
1232
1235
|
try {
|
|
1233
1236
|
const validationErrors = JSON.parse(error.message);
|
|
1234
|
-
console.error(
|
|
1237
|
+
console.error(chalk6.red("\u274C Validation Error:"));
|
|
1235
1238
|
validationErrors.forEach((err) => {
|
|
1236
1239
|
const errorObj = err;
|
|
1237
1240
|
const field = errorObj?.path?.join(".") || "unknown";
|
|
1238
1241
|
console.error(
|
|
1239
|
-
|
|
1242
|
+
chalk6.yellow(
|
|
1240
1243
|
` \u2022 ${field}: ${errorObj?.message || "Unknown error"}`
|
|
1241
1244
|
)
|
|
1242
1245
|
);
|
|
1243
1246
|
});
|
|
1244
1247
|
console.error(
|
|
1245
|
-
"\n" +
|
|
1248
|
+
"\n" + chalk6.dim(`Use --help to see available options`)
|
|
1246
1249
|
);
|
|
1247
1250
|
throw new ZapierCliExitError("Validation failed", 1);
|
|
1248
1251
|
} catch {
|
|
1249
1252
|
console.error(
|
|
1250
|
-
|
|
1253
|
+
chalk6.red("Error:"),
|
|
1251
1254
|
error instanceof Error ? error.message : String(error)
|
|
1252
1255
|
);
|
|
1253
1256
|
throw new ZapierCliExitError(
|
|
@@ -1259,11 +1262,11 @@ ${confirmMessageAfter}`));
|
|
|
1259
1262
|
throw error;
|
|
1260
1263
|
} else if (error instanceof ZapierError) {
|
|
1261
1264
|
const formattedMessage = formatErrorMessage(error);
|
|
1262
|
-
console.error(
|
|
1265
|
+
console.error(chalk6.red("\u274C Error:"), formattedMessage);
|
|
1263
1266
|
throw new ZapierCliExitError(formattedMessage, 1);
|
|
1264
1267
|
} else {
|
|
1265
1268
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1266
|
-
console.error(
|
|
1269
|
+
console.error(chalk6.red("\u274C Error:"), errorMessage);
|
|
1267
1270
|
throw new ZapierCliExitError(errorMessage, 1);
|
|
1268
1271
|
}
|
|
1269
1272
|
}
|
|
@@ -1280,10 +1283,10 @@ function collect(value, previous = []) {
|
|
|
1280
1283
|
previous.push(value);
|
|
1281
1284
|
return previous;
|
|
1282
1285
|
}
|
|
1283
|
-
function addCommand(program2, commandName,
|
|
1284
|
-
const command = program2.command(commandName, { hidden:
|
|
1286
|
+
function addCommand(program2, commandName, config) {
|
|
1287
|
+
const command = program2.command(commandName, { hidden: config.hidden ?? false }).description(config.description);
|
|
1285
1288
|
let hasPositionalArray = false;
|
|
1286
|
-
|
|
1289
|
+
config.parameters.forEach((param) => {
|
|
1287
1290
|
const kebabName = param.name.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
1288
1291
|
if (param.hasResolver && param.required) {
|
|
1289
1292
|
command.argument(
|
|
@@ -1317,7 +1320,7 @@ function addCommand(program2, commandName, config2) {
|
|
|
1317
1320
|
);
|
|
1318
1321
|
} else {
|
|
1319
1322
|
const flags = [];
|
|
1320
|
-
const alias =
|
|
1323
|
+
const alias = config.aliases?.[param.name];
|
|
1321
1324
|
if (alias && alias.length === 1) {
|
|
1322
1325
|
flags.push(`-${alias}`);
|
|
1323
1326
|
}
|
|
@@ -1337,13 +1340,13 @@ function addCommand(program2, commandName, config2) {
|
|
|
1337
1340
|
}
|
|
1338
1341
|
}
|
|
1339
1342
|
});
|
|
1340
|
-
const paramNames = new Set(
|
|
1343
|
+
const paramNames = new Set(config.parameters.map((p) => p.name));
|
|
1341
1344
|
SHARED_COMMAND_CLI_OPTIONS.forEach((opt) => {
|
|
1342
1345
|
if (!paramNames.has(opt.name)) {
|
|
1343
1346
|
command.option(opt.flag, opt.description);
|
|
1344
1347
|
}
|
|
1345
1348
|
});
|
|
1346
|
-
command.action(
|
|
1349
|
+
command.action(config.handler);
|
|
1347
1350
|
}
|
|
1348
1351
|
function convertCliArgsToSdkParams(parameters, positionalArgs, options) {
|
|
1349
1352
|
const sdkParams = {};
|
|
@@ -1407,7 +1410,7 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, f
|
|
|
1407
1410
|
let totalShown = 0;
|
|
1408
1411
|
let pageCount = 0;
|
|
1409
1412
|
console.log(
|
|
1410
|
-
|
|
1413
|
+
chalk6.blue(`\u{1F4CB} ${getListTitleFromMethod(sdkMethodName, functionInfo)}
|
|
1411
1414
|
`)
|
|
1412
1415
|
);
|
|
1413
1416
|
try {
|
|
@@ -1415,11 +1418,11 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, f
|
|
|
1415
1418
|
const items = page.data || page;
|
|
1416
1419
|
pageCount++;
|
|
1417
1420
|
if (!Array.isArray(items)) {
|
|
1418
|
-
console.log(
|
|
1421
|
+
console.log(chalk6.yellow(`No ${itemName} found.`));
|
|
1419
1422
|
return;
|
|
1420
1423
|
}
|
|
1421
1424
|
if (items.length === 0 && pageCount === 1) {
|
|
1422
|
-
console.log(
|
|
1425
|
+
console.log(chalk6.yellow(`No ${itemName} found.`));
|
|
1423
1426
|
return;
|
|
1424
1427
|
}
|
|
1425
1428
|
if (items.length === 0) {
|
|
@@ -1428,7 +1431,7 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, f
|
|
|
1428
1431
|
if (pageCount > 1) {
|
|
1429
1432
|
console.clear();
|
|
1430
1433
|
console.log(
|
|
1431
|
-
|
|
1434
|
+
chalk6.blue(
|
|
1432
1435
|
`\u{1F4CB} ${getListTitleFromMethod(sdkMethodName, functionInfo)}
|
|
1433
1436
|
`
|
|
1434
1437
|
)
|
|
@@ -1445,7 +1448,7 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, f
|
|
|
1445
1448
|
}
|
|
1446
1449
|
totalShown += items.length;
|
|
1447
1450
|
console.log(
|
|
1448
|
-
|
|
1451
|
+
chalk6.green(
|
|
1449
1452
|
`
|
|
1450
1453
|
\u2705 Showing ${totalShown} ${itemName} (page ${pageCount})`
|
|
1451
1454
|
)
|
|
@@ -1466,13 +1469,13 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, f
|
|
|
1466
1469
|
break;
|
|
1467
1470
|
}
|
|
1468
1471
|
}
|
|
1469
|
-
console.log(
|
|
1472
|
+
console.log(chalk6.gray(`
|
|
1470
1473
|
\u{1F4C4} Finished browsing ${itemName}`));
|
|
1471
1474
|
} catch (error) {
|
|
1472
1475
|
const items = sdkResult?.data || sdkResult;
|
|
1473
1476
|
if (Array.isArray(items)) {
|
|
1474
1477
|
if (items.length === 0) {
|
|
1475
|
-
console.log(
|
|
1478
|
+
console.log(chalk6.yellow(`No ${itemName} found.`));
|
|
1476
1479
|
return;
|
|
1477
1480
|
}
|
|
1478
1481
|
if (functionInfo && functionInfo.inputSchema) {
|
|
@@ -1484,7 +1487,7 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, f
|
|
|
1484
1487
|
} else {
|
|
1485
1488
|
formatItemsGeneric2(items, 0);
|
|
1486
1489
|
}
|
|
1487
|
-
console.log(
|
|
1490
|
+
console.log(chalk6.green(`
|
|
1488
1491
|
\u2705 Showing ${items.length} ${itemName}`));
|
|
1489
1492
|
} else {
|
|
1490
1493
|
throw error;
|
|
@@ -1506,10 +1509,10 @@ function formatNonPaginatedResults(result, requestedMaxItems, userSpecifiedMaxIt
|
|
|
1506
1509
|
}
|
|
1507
1510
|
const itemName = functionInfo ? getItemNameFromMethod(functionInfo) : "items";
|
|
1508
1511
|
if (result.length === 0) {
|
|
1509
|
-
console.log(
|
|
1512
|
+
console.log(chalk6.yellow(`No ${itemName} found.`));
|
|
1510
1513
|
return;
|
|
1511
1514
|
}
|
|
1512
|
-
console.log(
|
|
1515
|
+
console.log(chalk6.green(`
|
|
1513
1516
|
\u2705 Found ${result.length} ${itemName}:
|
|
1514
1517
|
`));
|
|
1515
1518
|
if (functionInfo && functionInfo.inputSchema) {
|
|
@@ -1522,13 +1525,13 @@ function formatNonPaginatedResults(result, requestedMaxItems, userSpecifiedMaxIt
|
|
|
1522
1525
|
}
|
|
1523
1526
|
if (userSpecifiedMaxItems && requestedMaxItems) {
|
|
1524
1527
|
console.log(
|
|
1525
|
-
|
|
1528
|
+
chalk6.gray(
|
|
1526
1529
|
`
|
|
1527
1530
|
\u{1F4C4} Showing up to ${requestedMaxItems} ${itemName} (--max-items ${requestedMaxItems})`
|
|
1528
1531
|
)
|
|
1529
1532
|
);
|
|
1530
1533
|
} else {
|
|
1531
|
-
console.log(
|
|
1534
|
+
console.log(chalk6.gray(`
|
|
1532
1535
|
\u{1F4C4} All available ${itemName} shown`));
|
|
1533
1536
|
}
|
|
1534
1537
|
}
|
|
@@ -1537,10 +1540,10 @@ function formatItemsGeneric2(items, startingNumber = 0) {
|
|
|
1537
1540
|
const itemObj = item;
|
|
1538
1541
|
const name = itemObj?.name || itemObj?.key || itemObj?.id || "Item";
|
|
1539
1542
|
console.log(
|
|
1540
|
-
`${
|
|
1543
|
+
`${chalk6.gray(`${startingNumber + index + 1}.`)} ${chalk6.cyan(String(name))}`
|
|
1541
1544
|
);
|
|
1542
1545
|
if (itemObj?.description) {
|
|
1543
|
-
console.log(` ${
|
|
1546
|
+
console.log(` ${chalk6.dim(String(itemObj.description))}`);
|
|
1544
1547
|
}
|
|
1545
1548
|
console.log();
|
|
1546
1549
|
});
|
|
@@ -1576,20 +1579,20 @@ var spinPromise = async (promise, text) => {
|
|
|
1576
1579
|
};
|
|
1577
1580
|
var log = {
|
|
1578
1581
|
info: (message, ...args) => {
|
|
1579
|
-
console.log(
|
|
1582
|
+
console.log(chalk6.blue("\u2139"), message, ...args);
|
|
1580
1583
|
},
|
|
1581
1584
|
error: (message, ...args) => {
|
|
1582
|
-
console.error(
|
|
1585
|
+
console.error(chalk6.red("\u2716"), message, ...args);
|
|
1583
1586
|
},
|
|
1584
1587
|
success: (message, ...args) => {
|
|
1585
|
-
console.log(
|
|
1588
|
+
console.log(chalk6.green("\u2713"), message, ...args);
|
|
1586
1589
|
},
|
|
1587
1590
|
warn: (message, ...args) => {
|
|
1588
|
-
console.log(
|
|
1591
|
+
console.log(chalk6.yellow("\u26A0"), message, ...args);
|
|
1589
1592
|
},
|
|
1590
1593
|
debug: (message, ...args) => {
|
|
1591
1594
|
if (process.env.DEBUG === "true" || process.argv.includes("--debug")) {
|
|
1592
|
-
console.log(
|
|
1595
|
+
console.log(chalk6.gray("\u{1F41B}"), message, ...args);
|
|
1593
1596
|
}
|
|
1594
1597
|
}
|
|
1595
1598
|
};
|
|
@@ -1696,7 +1699,7 @@ var login = async ({
|
|
|
1696
1699
|
const scope = ensureOfflineAccess(
|
|
1697
1700
|
credentials2?.scope || "internal credentials"
|
|
1698
1701
|
);
|
|
1699
|
-
logout();
|
|
1702
|
+
await logout();
|
|
1700
1703
|
const availablePort = await findAvailablePort();
|
|
1701
1704
|
const redirectUri = `http://localhost:${availablePort}/oauth`;
|
|
1702
1705
|
log_default.info(`Using port ${availablePort} for OAuth callback`);
|
|
@@ -1789,7 +1792,32 @@ var login = async ({
|
|
|
1789
1792
|
}
|
|
1790
1793
|
}
|
|
1791
1794
|
);
|
|
1792
|
-
|
|
1795
|
+
let targetStorage;
|
|
1796
|
+
if (getLoginStorageMode() === "config") {
|
|
1797
|
+
const { upgrade } = await inquirer.prompt([
|
|
1798
|
+
{
|
|
1799
|
+
type: "confirm",
|
|
1800
|
+
name: "upgrade",
|
|
1801
|
+
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.",
|
|
1802
|
+
default: true
|
|
1803
|
+
}
|
|
1804
|
+
]);
|
|
1805
|
+
targetStorage = upgrade ? "keychain" : "config";
|
|
1806
|
+
} else {
|
|
1807
|
+
targetStorage = "keychain";
|
|
1808
|
+
}
|
|
1809
|
+
try {
|
|
1810
|
+
await updateLogin(data, { storage: targetStorage });
|
|
1811
|
+
} catch (err) {
|
|
1812
|
+
if (targetStorage === "keychain") {
|
|
1813
|
+
log_default.warn(
|
|
1814
|
+
`Could not store credentials in system keychain. Storing in plaintext at ${getConfigPath()}.`
|
|
1815
|
+
);
|
|
1816
|
+
await updateLogin(data, { storage: "config" });
|
|
1817
|
+
} else {
|
|
1818
|
+
throw err;
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1793
1821
|
log_default.info("Token exchange completed successfully");
|
|
1794
1822
|
return data.access_token;
|
|
1795
1823
|
};
|
|
@@ -1800,7 +1828,7 @@ var LoginSchema = z.object({
|
|
|
1800
1828
|
|
|
1801
1829
|
// package.json
|
|
1802
1830
|
var package_default = {
|
|
1803
|
-
version: "0.
|
|
1831
|
+
version: "0.34.0"};
|
|
1804
1832
|
|
|
1805
1833
|
// src/telemetry/builders.ts
|
|
1806
1834
|
function createCliBaseEvent(context = {}) {
|
|
@@ -1939,7 +1967,7 @@ var LogoutSchema = z.object({}).describe("Log out of your Zapier account");
|
|
|
1939
1967
|
|
|
1940
1968
|
// src/plugins/logout/index.ts
|
|
1941
1969
|
var logoutWithSdk = createFunction(async function logoutWithSdk2(_options) {
|
|
1942
|
-
logout();
|
|
1970
|
+
await logout();
|
|
1943
1971
|
console.log("\u2705 Successfully logged out");
|
|
1944
1972
|
}, LogoutSchema);
|
|
1945
1973
|
var logoutPlugin = () => ({
|
|
@@ -3568,19 +3596,13 @@ var cliOverridesPlugin = ({ context }) => {
|
|
|
3568
3596
|
}
|
|
3569
3597
|
};
|
|
3570
3598
|
};
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
}
|
|
3579
|
-
|
|
3580
|
-
// package.json with { type: 'json' }
|
|
3581
|
-
var package_default2 = {
|
|
3582
|
-
name: "@zapier/zapier-sdk-cli",
|
|
3583
|
-
version: "0.32.4"};
|
|
3599
|
+
var TEMPLATES = ["basic"];
|
|
3600
|
+
var InitSchema = z.object({
|
|
3601
|
+
projectName: z.string().min(1).describe("Name of the project directory to create"),
|
|
3602
|
+
skipPrompts: z.boolean().optional().describe("Skip all interactive prompts and accept all defaults")
|
|
3603
|
+
}).describe(
|
|
3604
|
+
"Create a new Zapier SDK project in a new directory with starter files"
|
|
3605
|
+
);
|
|
3584
3606
|
function detectPackageManager(cwd = process.cwd()) {
|
|
3585
3607
|
const ua = process.env.npm_config_user_agent;
|
|
3586
3608
|
if (ua) {
|
|
@@ -3629,13 +3651,462 @@ function getUpdateCommand(packageName) {
|
|
|
3629
3651
|
}
|
|
3630
3652
|
}
|
|
3631
3653
|
}
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3654
|
+
function getDirentParentPath(entry) {
|
|
3655
|
+
const e = entry;
|
|
3656
|
+
const parent = e.parentPath ?? e.path;
|
|
3657
|
+
if (!parent)
|
|
3658
|
+
throw new Error(
|
|
3659
|
+
"readdirSync entry missing parentPath/path \u2014 unsupported Node version"
|
|
3660
|
+
);
|
|
3661
|
+
return parent;
|
|
3662
|
+
}
|
|
3663
|
+
function toProjectName(name) {
|
|
3664
|
+
return name.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
3665
|
+
}
|
|
3666
|
+
function validateInitOptions({
|
|
3667
|
+
rawName,
|
|
3668
|
+
cwd
|
|
3669
|
+
}) {
|
|
3670
|
+
const projectName = toProjectName(rawName);
|
|
3671
|
+
if (!projectName) {
|
|
3672
|
+
throw new Error(
|
|
3673
|
+
`"${rawName}" results in an empty project name. Provide a name with at least one letter or number.`
|
|
3674
|
+
);
|
|
3675
|
+
}
|
|
3676
|
+
const projectDir = join(cwd, projectName);
|
|
3677
|
+
if (existsSync(projectDir)) {
|
|
3678
|
+
const contents = readdirSync(projectDir);
|
|
3679
|
+
if (contents.length > 0) {
|
|
3680
|
+
throw new Error(
|
|
3681
|
+
`Directory "${projectName}" already exists and is not empty. Choose a different name.`
|
|
3682
|
+
);
|
|
3683
|
+
}
|
|
3636
3684
|
}
|
|
3637
|
-
return
|
|
3685
|
+
return { projectName, projectDir };
|
|
3686
|
+
}
|
|
3687
|
+
function createExec({ cwd }) {
|
|
3688
|
+
return (cmd) => execSync(cmd, {
|
|
3689
|
+
cwd,
|
|
3690
|
+
stdio: "inherit",
|
|
3691
|
+
shell: process.platform === "win32" ? "cmd.exe" : "/bin/sh"
|
|
3692
|
+
});
|
|
3693
|
+
}
|
|
3694
|
+
async function promptYesNo({
|
|
3695
|
+
message,
|
|
3696
|
+
defaultValue,
|
|
3697
|
+
skipPrompts
|
|
3698
|
+
}) {
|
|
3699
|
+
if (skipPrompts) return defaultValue;
|
|
3700
|
+
const { answer } = await inquirer.prompt([
|
|
3701
|
+
{ type: "confirm", name: "answer", message, default: defaultValue }
|
|
3702
|
+
]);
|
|
3703
|
+
return answer;
|
|
3704
|
+
}
|
|
3705
|
+
function getPackageManagerCommands({
|
|
3706
|
+
packageManager
|
|
3707
|
+
}) {
|
|
3708
|
+
return {
|
|
3709
|
+
installCmd: `${packageManager} install`,
|
|
3710
|
+
devCmd: packageManager === "yarn" ? "yarn dev" : `${packageManager} run dev`,
|
|
3711
|
+
devScript: packageManager === "bun" ? "bun src/index.ts" : "tsx src/index.ts",
|
|
3712
|
+
execCmd: {
|
|
3713
|
+
npm: "npx",
|
|
3714
|
+
yarn: "yarn dlx",
|
|
3715
|
+
pnpm: "pnpm dlx",
|
|
3716
|
+
bun: "bunx"
|
|
3717
|
+
}[packageManager]
|
|
3718
|
+
};
|
|
3719
|
+
}
|
|
3720
|
+
function isTemplateFile(name) {
|
|
3721
|
+
return extname(name) === ".hbs";
|
|
3638
3722
|
}
|
|
3723
|
+
function getDestRelPath(relPath, isTemplate) {
|
|
3724
|
+
return isTemplate ? relPath.slice(0, -extname(relPath).length) : relPath;
|
|
3725
|
+
}
|
|
3726
|
+
function renderTemplate(srcPath, variables) {
|
|
3727
|
+
const source = readFileSync(srcPath, "utf-8");
|
|
3728
|
+
const template = Handlebars.compile(source, { noEscape: true });
|
|
3729
|
+
return template(variables);
|
|
3730
|
+
}
|
|
3731
|
+
function buildTemplateVariables({
|
|
3732
|
+
projectName,
|
|
3733
|
+
packageManager
|
|
3734
|
+
}) {
|
|
3735
|
+
const { execCmd, devScript, devCmd } = getPackageManagerCommands({
|
|
3736
|
+
packageManager
|
|
3737
|
+
});
|
|
3738
|
+
return {
|
|
3739
|
+
projectName,
|
|
3740
|
+
execCmd,
|
|
3741
|
+
devScript,
|
|
3742
|
+
devCmd,
|
|
3743
|
+
includeTsx: packageManager !== "bun"
|
|
3744
|
+
};
|
|
3745
|
+
}
|
|
3746
|
+
function cleanupProject({ projectDir }) {
|
|
3747
|
+
console.log("\n" + chalk6.yellow("!") + " Cleaning up...");
|
|
3748
|
+
rmSync(projectDir, { recursive: true, force: true });
|
|
3749
|
+
}
|
|
3750
|
+
async function withInterruptCleanup(cleanup, fn) {
|
|
3751
|
+
if (!cleanup) return fn();
|
|
3752
|
+
const handler = () => {
|
|
3753
|
+
cleanup();
|
|
3754
|
+
process.removeListener("SIGINT", handler);
|
|
3755
|
+
process.kill(process.pid, "SIGINT");
|
|
3756
|
+
};
|
|
3757
|
+
process.on("SIGINT", handler);
|
|
3758
|
+
try {
|
|
3759
|
+
return await fn();
|
|
3760
|
+
} finally {
|
|
3761
|
+
process.removeListener("SIGINT", handler);
|
|
3762
|
+
}
|
|
3763
|
+
}
|
|
3764
|
+
function createProjectDir({
|
|
3765
|
+
projectDir,
|
|
3766
|
+
projectName
|
|
3767
|
+
}) {
|
|
3768
|
+
try {
|
|
3769
|
+
mkdirSync(projectDir, { recursive: true });
|
|
3770
|
+
} catch (err) {
|
|
3771
|
+
if (err instanceof Error) {
|
|
3772
|
+
const code = err.code;
|
|
3773
|
+
if (code === "EACCES") {
|
|
3774
|
+
throw new Error(
|
|
3775
|
+
`Permission denied creating "${projectName}". Check directory permissions.`
|
|
3776
|
+
);
|
|
3777
|
+
}
|
|
3778
|
+
if (code === "ENOSPC") {
|
|
3779
|
+
throw new Error("No space left on device.");
|
|
3780
|
+
}
|
|
3781
|
+
}
|
|
3782
|
+
throw err;
|
|
3783
|
+
}
|
|
3784
|
+
}
|
|
3785
|
+
var TEMPLATES_DIR = fileURLToPath(
|
|
3786
|
+
new URL("../templates", import.meta.url)
|
|
3787
|
+
);
|
|
3788
|
+
|
|
3789
|
+
// src/plugins/init/steps.ts
|
|
3790
|
+
var DEFAULT_TEMPLATE = "basic";
|
|
3791
|
+
function getTemplateDir({
|
|
3792
|
+
template = DEFAULT_TEMPLATE
|
|
3793
|
+
} = {}) {
|
|
3794
|
+
const dirPath = join(TEMPLATES_DIR, template);
|
|
3795
|
+
if (!existsSync(dirPath)) {
|
|
3796
|
+
throw new Error(
|
|
3797
|
+
`Template "${template}" not found at ${dirPath}. Available templates: ${TEMPLATES.join(", ")}`
|
|
3798
|
+
);
|
|
3799
|
+
}
|
|
3800
|
+
return dirPath;
|
|
3801
|
+
}
|
|
3802
|
+
function scaffoldFiles({
|
|
3803
|
+
projectDir,
|
|
3804
|
+
templatesDir,
|
|
3805
|
+
variables = {},
|
|
3806
|
+
displayHooks
|
|
3807
|
+
}) {
|
|
3808
|
+
const entries = readdirSync(templatesDir, {
|
|
3809
|
+
withFileTypes: true,
|
|
3810
|
+
recursive: true
|
|
3811
|
+
});
|
|
3812
|
+
const files = entries.filter((e) => e.isFile());
|
|
3813
|
+
if (files.length === 0) {
|
|
3814
|
+
throw new Error(`Template directory "${templatesDir}" contains no files.`);
|
|
3815
|
+
}
|
|
3816
|
+
for (const entry of files) {
|
|
3817
|
+
const srcPath = join(getDirentParentPath(entry), entry.name);
|
|
3818
|
+
const relPath = relative(templatesDir, srcPath);
|
|
3819
|
+
const isTemplate = isTemplateFile(entry.name);
|
|
3820
|
+
const destRelPath = getDestRelPath(relPath, isTemplate);
|
|
3821
|
+
const destPath = join(projectDir, destRelPath);
|
|
3822
|
+
mkdirSync(dirname(destPath), { recursive: true });
|
|
3823
|
+
if (isTemplate) {
|
|
3824
|
+
writeFileSync(destPath, renderTemplate(srcPath, variables));
|
|
3825
|
+
} else {
|
|
3826
|
+
copyFileSync(srcPath, destPath);
|
|
3827
|
+
}
|
|
3828
|
+
displayHooks?.onItemComplete?.(destRelPath);
|
|
3829
|
+
}
|
|
3830
|
+
}
|
|
3831
|
+
function scaffoldProject({
|
|
3832
|
+
projectDir,
|
|
3833
|
+
projectName,
|
|
3834
|
+
packageManager,
|
|
3835
|
+
template,
|
|
3836
|
+
displayHooks
|
|
3837
|
+
}) {
|
|
3838
|
+
const variables = buildTemplateVariables({ projectName, packageManager });
|
|
3839
|
+
const templatesDir = getTemplateDir({ template });
|
|
3840
|
+
createProjectDir({ projectDir, projectName });
|
|
3841
|
+
scaffoldFiles({ projectDir, templatesDir, variables, displayHooks });
|
|
3842
|
+
}
|
|
3843
|
+
async function runStep({
|
|
3844
|
+
step,
|
|
3845
|
+
stepNumber,
|
|
3846
|
+
totalSteps,
|
|
3847
|
+
skipPrompts,
|
|
3848
|
+
displayHooks
|
|
3849
|
+
}) {
|
|
3850
|
+
if (step.askConfirmation) {
|
|
3851
|
+
const should = await promptYesNo({
|
|
3852
|
+
message: step.description,
|
|
3853
|
+
defaultValue: true,
|
|
3854
|
+
skipPrompts
|
|
3855
|
+
});
|
|
3856
|
+
if (!should) return false;
|
|
3857
|
+
}
|
|
3858
|
+
displayHooks?.onStepStart({
|
|
3859
|
+
description: step.description,
|
|
3860
|
+
stepNumber,
|
|
3861
|
+
totalSteps,
|
|
3862
|
+
command: step.command,
|
|
3863
|
+
skipPrompts
|
|
3864
|
+
});
|
|
3865
|
+
try {
|
|
3866
|
+
await step.run();
|
|
3867
|
+
displayHooks?.onStepSuccess({ stepNumber, totalSteps });
|
|
3868
|
+
return true;
|
|
3869
|
+
} catch (err) {
|
|
3870
|
+
step.cleanup?.();
|
|
3871
|
+
displayHooks?.onStepError({
|
|
3872
|
+
description: step.description,
|
|
3873
|
+
command: step.command,
|
|
3874
|
+
err
|
|
3875
|
+
});
|
|
3876
|
+
return false;
|
|
3877
|
+
}
|
|
3878
|
+
}
|
|
3879
|
+
function getInitSteps({
|
|
3880
|
+
projectDir,
|
|
3881
|
+
projectName,
|
|
3882
|
+
packageManager,
|
|
3883
|
+
template,
|
|
3884
|
+
displayHooks
|
|
3885
|
+
}) {
|
|
3886
|
+
if (template !== void 0 && !TEMPLATES.includes(template)) {
|
|
3887
|
+
throw new Error(
|
|
3888
|
+
`Unknown template "${template}". Available templates: ${TEMPLATES.join(", ")}`
|
|
3889
|
+
);
|
|
3890
|
+
}
|
|
3891
|
+
const { installCmd, execCmd, devCmd } = getPackageManagerCommands({
|
|
3892
|
+
packageManager
|
|
3893
|
+
});
|
|
3894
|
+
const exec = createExec({ cwd: projectDir });
|
|
3895
|
+
return [
|
|
3896
|
+
{
|
|
3897
|
+
id: "scaffold",
|
|
3898
|
+
description: "Scaffold project files",
|
|
3899
|
+
cleanup: () => cleanupProject({ projectDir }),
|
|
3900
|
+
run: () => scaffoldProject({
|
|
3901
|
+
projectDir,
|
|
3902
|
+
projectName,
|
|
3903
|
+
packageManager,
|
|
3904
|
+
template,
|
|
3905
|
+
displayHooks
|
|
3906
|
+
})
|
|
3907
|
+
},
|
|
3908
|
+
{
|
|
3909
|
+
id: "install-deps",
|
|
3910
|
+
description: "Install dependencies",
|
|
3911
|
+
askConfirmation: true,
|
|
3912
|
+
command: installCmd,
|
|
3913
|
+
run: () => exec(installCmd)
|
|
3914
|
+
},
|
|
3915
|
+
{
|
|
3916
|
+
id: "login",
|
|
3917
|
+
description: "Log in to Zapier",
|
|
3918
|
+
askConfirmation: true,
|
|
3919
|
+
command: `${execCmd} zapier-sdk login`,
|
|
3920
|
+
run: () => exec(`${execCmd} zapier-sdk login`)
|
|
3921
|
+
},
|
|
3922
|
+
{
|
|
3923
|
+
id: "run",
|
|
3924
|
+
description: "Run your app",
|
|
3925
|
+
askConfirmation: true,
|
|
3926
|
+
command: devCmd,
|
|
3927
|
+
run: () => exec(devCmd)
|
|
3928
|
+
}
|
|
3929
|
+
];
|
|
3930
|
+
}
|
|
3931
|
+
function buildNextSteps({
|
|
3932
|
+
projectName,
|
|
3933
|
+
leftoverSteps,
|
|
3934
|
+
execCmd
|
|
3935
|
+
}) {
|
|
3936
|
+
return [
|
|
3937
|
+
{
|
|
3938
|
+
description: "Change into your project directory",
|
|
3939
|
+
command: `cd ${projectName}`
|
|
3940
|
+
},
|
|
3941
|
+
...leftoverSteps.map(({ description, command }) => ({
|
|
3942
|
+
description,
|
|
3943
|
+
command
|
|
3944
|
+
})),
|
|
3945
|
+
{
|
|
3946
|
+
description: "Search for an app to integrate",
|
|
3947
|
+
command: `${execCmd} zapier-sdk list-apps --search "<app name>"`
|
|
3948
|
+
},
|
|
3949
|
+
{
|
|
3950
|
+
description: "Add an app and generate TypeScript types",
|
|
3951
|
+
command: `${execCmd} zapier-sdk add <app-key>`
|
|
3952
|
+
}
|
|
3953
|
+
];
|
|
3954
|
+
}
|
|
3955
|
+
function createConsoleDisplayHooks() {
|
|
3956
|
+
return {
|
|
3957
|
+
onItemComplete: (message) => console.log(" " + chalk6.green("\u2713") + " " + chalk6.dim(message)),
|
|
3958
|
+
onWarn: (message) => console.warn(chalk6.yellow("!") + " " + message),
|
|
3959
|
+
onStepStart: ({
|
|
3960
|
+
description,
|
|
3961
|
+
stepNumber,
|
|
3962
|
+
totalSteps,
|
|
3963
|
+
command,
|
|
3964
|
+
skipPrompts
|
|
3965
|
+
}) => {
|
|
3966
|
+
const progressMessage = `${description}...`;
|
|
3967
|
+
const stepCounter = chalk6.dim(`${stepNumber}/${totalSteps}`);
|
|
3968
|
+
if (skipPrompts) {
|
|
3969
|
+
console.log(
|
|
3970
|
+
"\n" + chalk6.bold(`\u276F ${progressMessage}`) + " " + stepCounter + "\n"
|
|
3971
|
+
);
|
|
3972
|
+
} else {
|
|
3973
|
+
console.log(
|
|
3974
|
+
chalk6.dim("\u2192") + " " + progressMessage + " " + stepCounter
|
|
3975
|
+
);
|
|
3976
|
+
}
|
|
3977
|
+
if (command) {
|
|
3978
|
+
console.log(" " + chalk6.cyan(`$ ${command}`));
|
|
3979
|
+
}
|
|
3980
|
+
},
|
|
3981
|
+
onStepSuccess: ({ stepNumber, totalSteps }) => console.log(
|
|
3982
|
+
"\n" + chalk6.green("\u2713") + " " + chalk6.dim(`Step ${stepNumber}/${totalSteps} complete`) + "\n"
|
|
3983
|
+
),
|
|
3984
|
+
onStepError: ({ description, command, err }) => {
|
|
3985
|
+
const detail = err instanceof Error && err.message ? `
|
|
3986
|
+
${chalk6.dim(err.message)}` : "";
|
|
3987
|
+
const hint = command ? `
|
|
3988
|
+
${chalk6.dim("run manually:")} ${chalk6.cyan(`$ ${command}`)}` : "";
|
|
3989
|
+
console.error(
|
|
3990
|
+
`
|
|
3991
|
+
${chalk6.red("\u2716")} ${chalk6.bold(description)}${chalk6.dim(" failed")}${detail}${hint}`
|
|
3992
|
+
);
|
|
3993
|
+
}
|
|
3994
|
+
};
|
|
3995
|
+
}
|
|
3996
|
+
function displaySummaryAndNextSteps({
|
|
3997
|
+
projectName,
|
|
3998
|
+
steps,
|
|
3999
|
+
completedSetupStepIds,
|
|
4000
|
+
packageManager
|
|
4001
|
+
}) {
|
|
4002
|
+
const formatStatus = (complete) => ({
|
|
4003
|
+
icon: complete ? chalk6.green("\u2713") : chalk6.yellow("!"),
|
|
4004
|
+
text: complete ? chalk6.green("Setup complete") : chalk6.yellow("Setup interrupted")
|
|
4005
|
+
});
|
|
4006
|
+
const formatNextStep = (step, i) => " " + chalk6.dim(`${i + 1}.`) + " " + chalk6.bold(step.description);
|
|
4007
|
+
const formatCommand = (cmd) => " " + chalk6.cyan(`$ ${cmd}`);
|
|
4008
|
+
const formatCompletedStep = (step) => " " + chalk6.green("\u2713") + " " + step.description;
|
|
4009
|
+
const { execCmd } = getPackageManagerCommands({ packageManager });
|
|
4010
|
+
const leftoverSteps = steps.filter(
|
|
4011
|
+
(s) => !completedSetupStepIds.includes(s.id)
|
|
4012
|
+
);
|
|
4013
|
+
const isComplete = leftoverSteps.length === 0;
|
|
4014
|
+
const status = formatStatus(isComplete);
|
|
4015
|
+
console.log("\n" + chalk6.bold("\u276F Summary") + "\n");
|
|
4016
|
+
console.log(" " + chalk6.dim("Project") + " " + chalk6.bold(projectName));
|
|
4017
|
+
console.log(
|
|
4018
|
+
" " + chalk6.dim("Status") + " " + status.icon + " " + status.text
|
|
4019
|
+
);
|
|
4020
|
+
const completedSteps = steps.filter(
|
|
4021
|
+
(s) => completedSetupStepIds.includes(s.id)
|
|
4022
|
+
);
|
|
4023
|
+
if (completedSteps.length > 0) {
|
|
4024
|
+
console.log();
|
|
4025
|
+
for (const step of completedSteps) console.log(formatCompletedStep(step));
|
|
4026
|
+
}
|
|
4027
|
+
const nextSteps = buildNextSteps({ projectName, leftoverSteps, execCmd });
|
|
4028
|
+
console.log("\n" + chalk6.bold("\u276F Next Steps") + "\n");
|
|
4029
|
+
nextSteps.forEach((step, i) => {
|
|
4030
|
+
console.log(formatNextStep(step, i));
|
|
4031
|
+
if (step.command) console.log(formatCommand(step.command));
|
|
4032
|
+
console.log();
|
|
4033
|
+
});
|
|
4034
|
+
}
|
|
4035
|
+
|
|
4036
|
+
// src/plugins/init/index.ts
|
|
4037
|
+
var initPlugin = () => {
|
|
4038
|
+
const init = createFunction(async function init2(options) {
|
|
4039
|
+
const { projectName: rawName, skipPrompts = false } = options;
|
|
4040
|
+
const cwd = process.cwd();
|
|
4041
|
+
const { projectName, projectDir } = validateInitOptions({ rawName, cwd });
|
|
4042
|
+
const displayHooks = createConsoleDisplayHooks();
|
|
4043
|
+
const packageManagerInfo = detectPackageManager(cwd);
|
|
4044
|
+
if (packageManagerInfo.name === "unknown") {
|
|
4045
|
+
displayHooks.onWarn(
|
|
4046
|
+
"Could not detect package manager, defaulting to npm."
|
|
4047
|
+
);
|
|
4048
|
+
}
|
|
4049
|
+
const packageManager = packageManagerInfo.name === "unknown" ? "npm" : packageManagerInfo.name;
|
|
4050
|
+
const steps = getInitSteps({
|
|
4051
|
+
projectDir,
|
|
4052
|
+
projectName,
|
|
4053
|
+
packageManager,
|
|
4054
|
+
displayHooks
|
|
4055
|
+
});
|
|
4056
|
+
const completedSetupStepIds = [];
|
|
4057
|
+
for (let i = 0; i < steps.length; i++) {
|
|
4058
|
+
const step = steps[i];
|
|
4059
|
+
const succeeded = await withInterruptCleanup(
|
|
4060
|
+
step.cleanup,
|
|
4061
|
+
() => runStep({
|
|
4062
|
+
step,
|
|
4063
|
+
stepNumber: i + 1,
|
|
4064
|
+
totalSteps: steps.length,
|
|
4065
|
+
skipPrompts,
|
|
4066
|
+
displayHooks
|
|
4067
|
+
})
|
|
4068
|
+
);
|
|
4069
|
+
if (!succeeded) break;
|
|
4070
|
+
completedSetupStepIds.push(step.id);
|
|
4071
|
+
}
|
|
4072
|
+
if (completedSetupStepIds.length === 0) {
|
|
4073
|
+
throw new ZapierCliExitError(
|
|
4074
|
+
"Project setup failed \u2014 no steps completed."
|
|
4075
|
+
);
|
|
4076
|
+
}
|
|
4077
|
+
displaySummaryAndNextSteps({
|
|
4078
|
+
projectName,
|
|
4079
|
+
steps,
|
|
4080
|
+
completedSetupStepIds,
|
|
4081
|
+
packageManager
|
|
4082
|
+
});
|
|
4083
|
+
}, InitSchema);
|
|
4084
|
+
return {
|
|
4085
|
+
init,
|
|
4086
|
+
context: {
|
|
4087
|
+
meta: {
|
|
4088
|
+
init: {
|
|
4089
|
+
categories: ["utility"],
|
|
4090
|
+
inputSchema: InitSchema
|
|
4091
|
+
}
|
|
4092
|
+
}
|
|
4093
|
+
}
|
|
4094
|
+
};
|
|
4095
|
+
};
|
|
4096
|
+
|
|
4097
|
+
// src/sdk.ts
|
|
4098
|
+
injectCliLogin(cliLogin);
|
|
4099
|
+
function createZapierCliSdk(options = {}) {
|
|
4100
|
+
return createZapierSdkWithoutRegistry({
|
|
4101
|
+
...options,
|
|
4102
|
+
eventEmission: { ...options.eventEmission, callContext: "cli" }
|
|
4103
|
+
}).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(registryPlugin);
|
|
4104
|
+
}
|
|
4105
|
+
|
|
4106
|
+
// package.json with { type: 'json' }
|
|
4107
|
+
var package_default2 = {
|
|
4108
|
+
name: "@zapier/zapier-sdk-cli",
|
|
4109
|
+
version: "0.34.0"};
|
|
3639
4110
|
var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
|
|
3640
4111
|
var CACHE_RESET_INTERVAL_MS = (() => {
|
|
3641
4112
|
const { ZAPIER_SDK_UPDATE_CHECK_INTERVAL_MS = `${ONE_DAY_MS}` } = process.env;
|
|
@@ -3745,26 +4216,26 @@ function displayUpdateNotification(versionInfo, packageName) {
|
|
|
3745
4216
|
if (versionInfo.isDeprecated) {
|
|
3746
4217
|
console.error();
|
|
3747
4218
|
console.error(
|
|
3748
|
-
|
|
4219
|
+
chalk6.red.bold("\u26A0\uFE0F DEPRECATION WARNING") + chalk6.red(
|
|
3749
4220
|
` - ${packageName} v${versionInfo.currentVersion} is deprecated.`
|
|
3750
4221
|
)
|
|
3751
4222
|
);
|
|
3752
4223
|
if (versionInfo.deprecationMessage) {
|
|
3753
|
-
console.error(
|
|
4224
|
+
console.error(chalk6.red(` ${versionInfo.deprecationMessage}`));
|
|
3754
4225
|
}
|
|
3755
|
-
console.error(
|
|
4226
|
+
console.error(chalk6.red(` Please update to the latest version.`));
|
|
3756
4227
|
console.error();
|
|
3757
4228
|
}
|
|
3758
4229
|
if (versionInfo.hasUpdate) {
|
|
3759
4230
|
console.error();
|
|
3760
4231
|
console.error(
|
|
3761
|
-
|
|
4232
|
+
chalk6.yellow.bold("\u{1F4E6} Update available!") + chalk6.yellow(
|
|
3762
4233
|
` ${packageName} v${versionInfo.currentVersion} \u2192 v${versionInfo.latestVersion}`
|
|
3763
4234
|
)
|
|
3764
4235
|
);
|
|
3765
4236
|
console.error(
|
|
3766
|
-
|
|
3767
|
-
` Run ${
|
|
4237
|
+
chalk6.yellow(
|
|
4238
|
+
` Run ${chalk6.bold(getUpdateCommand(packageName))} to update.`
|
|
3768
4239
|
)
|
|
3769
4240
|
);
|
|
3770
4241
|
console.error();
|