@zapier/zapier-sdk-cli 0.13.16 → 0.14.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 +12 -0
- package/dist/cli.cjs +296 -20
- package/dist/cli.mjs +296 -22
- package/dist/index.cjs +29 -5
- package/dist/index.mjs +30 -6
- package/dist/package.json +4 -1
- package/dist/src/cli.js +32 -2
- package/dist/src/plugins/login/index.js +0 -2
- package/dist/src/utils/auth/login.js +3 -2
- package/dist/src/utils/cli-generator.js +10 -2
- package/dist/src/utils/errors.d.ts +16 -0
- package/dist/src/utils/errors.js +19 -0
- package/dist/src/utils/log.d.ts +1 -0
- package/dist/src/utils/log.js +5 -0
- package/dist/src/utils/package-manager-detector.d.ts +16 -0
- package/dist/src/utils/package-manager-detector.js +77 -0
- package/dist/src/utils/parameter-resolver.js +6 -5
- package/dist/src/utils/spinner.js +9 -1
- package/dist/src/utils/version-checker.d.ts +17 -0
- package/dist/src/utils/version-checker.js +154 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -1
- package/src/cli.ts +34 -2
- package/src/plugins/login/index.ts +0 -3
- package/src/utils/auth/login.ts +7 -3
- package/src/utils/cli-generator.ts +15 -2
- package/src/utils/errors.ts +26 -0
- package/src/utils/log.ts +5 -0
- package/src/utils/package-manager-detector.ts +83 -0
- package/src/utils/parameter-resolver.ts +6 -5
- package/src/utils/spinner.ts +8 -1
- package/src/utils/version-checker.test.ts +199 -0
- package/src/utils/version-checker.ts +236 -0
package/dist/cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Command } from 'commander';
|
|
2
|
+
import { Command, CommanderError } from 'commander';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { createFunction, OutputPropertySchema, DEFAULT_CONFIG_PATH, createZapierSdkWithoutRegistry, registryPlugin, ZapierValidationError, ZapierUnknownError, batch, toSnakeCase,
|
|
4
|
+
import { createFunction, OutputPropertySchema, DEFAULT_CONFIG_PATH, createZapierSdkWithoutRegistry, registryPlugin, ZapierError, ZapierValidationError, ZapierUnknownError, batch, toSnakeCase, formatErrorMessage, getOsInfo, getPlatformVersions, getCiPlatform, isCi, isPositional, getReleaseId, getCurrentTimestamp, generateEventId } from '@zapier/zapier-sdk';
|
|
5
5
|
import inquirer from 'inquirer';
|
|
6
6
|
import chalk3 from 'chalk';
|
|
7
7
|
import util from 'util';
|
|
@@ -14,11 +14,35 @@ import ora from 'ora';
|
|
|
14
14
|
import { startMcpServerAsProcess } from '@zapier/zapier-sdk-mcp';
|
|
15
15
|
import { buildSync } from 'esbuild';
|
|
16
16
|
import * as fs from 'fs';
|
|
17
|
+
import { existsSync } from 'fs';
|
|
17
18
|
import * as path from 'path';
|
|
18
19
|
import { resolve, join } from 'path';
|
|
19
20
|
import { mkdir, writeFile, access } from 'fs/promises';
|
|
20
21
|
import * as ts from 'typescript';
|
|
22
|
+
import packageJsonLib from 'package-json';
|
|
23
|
+
import Conf from 'conf';
|
|
24
|
+
import isInstalledGlobally from 'is-installed-globally';
|
|
21
25
|
|
|
26
|
+
var ZapierCliError = class extends ZapierError {
|
|
27
|
+
};
|
|
28
|
+
var ZapierCliUserCancellationError = class extends ZapierCliError {
|
|
29
|
+
constructor(message = "Operation cancelled by user") {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = "ZapierCliUserCancellationError";
|
|
32
|
+
this.code = "ZAPIER_CLI_USER_CANCELLATION";
|
|
33
|
+
this.exitCode = 0;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var ZapierCliExitError = class extends ZapierCliError {
|
|
37
|
+
constructor(message, exitCode = 1) {
|
|
38
|
+
super(message);
|
|
39
|
+
this.name = "ZapierCliExitError";
|
|
40
|
+
this.code = "ZAPIER_CLI_EXIT";
|
|
41
|
+
this.exitCode = exitCode;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/utils/parameter-resolver.ts
|
|
22
46
|
function getLocalResolutionOrder(paramName, resolvers, resolved = /* @__PURE__ */ new Set()) {
|
|
23
47
|
const resolver = resolvers[paramName];
|
|
24
48
|
if (!resolver || resolver.type === "static") {
|
|
@@ -125,7 +149,7 @@ var SchemaParameterResolver = class {
|
|
|
125
149
|
} catch (error) {
|
|
126
150
|
if (this.isUserCancellation(error)) {
|
|
127
151
|
console.log(chalk3.yellow("\n\nOperation cancelled by user"));
|
|
128
|
-
|
|
152
|
+
throw new ZapierCliUserCancellationError();
|
|
129
153
|
}
|
|
130
154
|
throw error;
|
|
131
155
|
}
|
|
@@ -163,7 +187,7 @@ var SchemaParameterResolver = class {
|
|
|
163
187
|
} catch (error) {
|
|
164
188
|
if (this.isUserCancellation(error)) {
|
|
165
189
|
console.log(chalk3.yellow("\n\nOperation cancelled by user"));
|
|
166
|
-
|
|
190
|
+
throw new ZapierCliUserCancellationError();
|
|
167
191
|
}
|
|
168
192
|
throw error;
|
|
169
193
|
}
|
|
@@ -198,7 +222,7 @@ var SchemaParameterResolver = class {
|
|
|
198
222
|
} catch (error) {
|
|
199
223
|
if (this.isUserCancellation(error)) {
|
|
200
224
|
console.log(chalk3.yellow("\n\nOperation cancelled by user"));
|
|
201
|
-
|
|
225
|
+
throw new ZapierCliUserCancellationError();
|
|
202
226
|
}
|
|
203
227
|
throw error;
|
|
204
228
|
}
|
|
@@ -452,7 +476,7 @@ Optional fields${pathContext}:`));
|
|
|
452
476
|
} catch (error) {
|
|
453
477
|
if (this.isUserCancellation(error)) {
|
|
454
478
|
console.log(chalk3.yellow("\n\nOperation cancelled by user"));
|
|
455
|
-
|
|
479
|
+
throw new ZapierCliUserCancellationError();
|
|
456
480
|
}
|
|
457
481
|
throw error;
|
|
458
482
|
}
|
|
@@ -517,7 +541,7 @@ Optional fields${pathContext}:`));
|
|
|
517
541
|
} catch (error) {
|
|
518
542
|
if (this.isUserCancellation(error)) {
|
|
519
543
|
console.log(chalk3.yellow("\n\nOperation cancelled by user"));
|
|
520
|
-
|
|
544
|
+
throw new ZapierCliUserCancellationError();
|
|
521
545
|
}
|
|
522
546
|
throw error;
|
|
523
547
|
}
|
|
@@ -740,8 +764,8 @@ function generateCliCommands(program2, sdk2) {
|
|
|
740
764
|
return;
|
|
741
765
|
}
|
|
742
766
|
const cliCommandName = methodNameToCliCommand(fnInfo.name);
|
|
743
|
-
const
|
|
744
|
-
addCommand(program2, cliCommandName,
|
|
767
|
+
const config2 = createCommandConfig(cliCommandName, fnInfo, sdk2);
|
|
768
|
+
addCommand(program2, cliCommandName, config2);
|
|
745
769
|
});
|
|
746
770
|
program2.configureHelp({
|
|
747
771
|
formatHelp: (cmd, helper) => {
|
|
@@ -883,17 +907,28 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
|
883
907
|
console.error(
|
|
884
908
|
"\n" + chalk3.dim(`Use --help to see available options`)
|
|
885
909
|
);
|
|
910
|
+
throw new ZapierCliExitError("Validation failed", 1);
|
|
886
911
|
} catch {
|
|
887
|
-
console.error(
|
|
912
|
+
console.error(
|
|
913
|
+
chalk3.red("Error:"),
|
|
914
|
+
error instanceof Error ? error.message : String(error)
|
|
915
|
+
);
|
|
916
|
+
throw new ZapierCliExitError(
|
|
917
|
+
error instanceof Error ? error.message : String(error),
|
|
918
|
+
1
|
|
919
|
+
);
|
|
888
920
|
}
|
|
921
|
+
} else if (error instanceof ZapierCliError) {
|
|
922
|
+
throw error;
|
|
889
923
|
} else if (error instanceof ZapierError) {
|
|
890
924
|
const formattedMessage = formatErrorMessage(error);
|
|
891
925
|
console.error(chalk3.red("\u274C Error:"), formattedMessage);
|
|
926
|
+
throw new ZapierCliExitError(formattedMessage, 1);
|
|
892
927
|
} else {
|
|
893
928
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
894
929
|
console.error(chalk3.red("\u274C Error:"), errorMessage);
|
|
930
|
+
throw new ZapierCliExitError(errorMessage, 1);
|
|
895
931
|
}
|
|
896
|
-
process.exit(1);
|
|
897
932
|
}
|
|
898
933
|
};
|
|
899
934
|
return {
|
|
@@ -902,10 +937,10 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
|
902
937
|
handler
|
|
903
938
|
};
|
|
904
939
|
}
|
|
905
|
-
function addCommand(program2, commandName,
|
|
906
|
-
const command = program2.command(commandName).description(
|
|
940
|
+
function addCommand(program2, commandName, config2) {
|
|
941
|
+
const command = program2.command(commandName).description(config2.description);
|
|
907
942
|
let hasPositionalArray = false;
|
|
908
|
-
|
|
943
|
+
config2.parameters.forEach((param) => {
|
|
909
944
|
const kebabName = param.name.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
910
945
|
if (param.hasResolver && param.required) {
|
|
911
946
|
command.argument(
|
|
@@ -957,7 +992,7 @@ function addCommand(program2, commandName, config) {
|
|
|
957
992
|
}
|
|
958
993
|
});
|
|
959
994
|
command.option("--json", "Output raw JSON instead of formatted results");
|
|
960
|
-
command.action(
|
|
995
|
+
command.action(config2.handler);
|
|
961
996
|
}
|
|
962
997
|
function convertCliArgsToSdkParams(parameters, positionalArgs, options) {
|
|
963
998
|
const sdkParams = {};
|
|
@@ -1167,7 +1202,11 @@ var spinPromise = async (promise, text) => {
|
|
|
1167
1202
|
spinner.succeed();
|
|
1168
1203
|
return result;
|
|
1169
1204
|
} catch (error) {
|
|
1170
|
-
|
|
1205
|
+
if (error instanceof ZapierCliUserCancellationError) {
|
|
1206
|
+
spinner.stop();
|
|
1207
|
+
} else {
|
|
1208
|
+
spinner.fail();
|
|
1209
|
+
}
|
|
1171
1210
|
throw error;
|
|
1172
1211
|
}
|
|
1173
1212
|
};
|
|
@@ -1183,6 +1222,11 @@ var log = {
|
|
|
1183
1222
|
},
|
|
1184
1223
|
warn: (message, ...args) => {
|
|
1185
1224
|
console.log(chalk3.yellow("\u26A0"), message, ...args);
|
|
1225
|
+
},
|
|
1226
|
+
debug: (message, ...args) => {
|
|
1227
|
+
if (process.env.DEBUG === "true" || process.argv.includes("--debug")) {
|
|
1228
|
+
console.log(chalk3.gray("\u{1F41B}"), message, ...args);
|
|
1229
|
+
}
|
|
1186
1230
|
}
|
|
1187
1231
|
};
|
|
1188
1232
|
var log_default = log;
|
|
@@ -1285,7 +1329,11 @@ var login = async ({
|
|
|
1285
1329
|
const availablePort = await findAvailablePort();
|
|
1286
1330
|
const redirectUri = `http://localhost:${availablePort}/oauth`;
|
|
1287
1331
|
log_default.info(`Using port ${availablePort} for OAuth callback`);
|
|
1288
|
-
const {
|
|
1332
|
+
const {
|
|
1333
|
+
promise: promisedCode,
|
|
1334
|
+
resolve: setCode,
|
|
1335
|
+
reject: rejectCode
|
|
1336
|
+
} = getCallablePromise_default();
|
|
1289
1337
|
const app = express();
|
|
1290
1338
|
app.get("/oauth", (req, res) => {
|
|
1291
1339
|
setCode(String(req.query.code));
|
|
@@ -1301,7 +1349,7 @@ var login = async ({
|
|
|
1301
1349
|
const cleanup = () => {
|
|
1302
1350
|
server.close();
|
|
1303
1351
|
log_default.info("\n\u274C Login cancelled by user");
|
|
1304
|
-
|
|
1352
|
+
rejectCode(new ZapierCliUserCancellationError());
|
|
1305
1353
|
};
|
|
1306
1354
|
process.on("SIGINT", cleanup);
|
|
1307
1355
|
process.on("SIGTERM", cleanup);
|
|
@@ -1377,7 +1425,7 @@ var LoginSchema = z.object({
|
|
|
1377
1425
|
|
|
1378
1426
|
// package.json
|
|
1379
1427
|
var package_default = {
|
|
1380
|
-
version: "0.
|
|
1428
|
+
version: "0.14.1"};
|
|
1381
1429
|
|
|
1382
1430
|
// src/telemetry/builders.ts
|
|
1383
1431
|
function createCliBaseEvent(context = {}) {
|
|
@@ -1449,7 +1497,6 @@ var loginWithSdk = createFunction(
|
|
|
1449
1497
|
});
|
|
1450
1498
|
const user = await getLoggedInUser();
|
|
1451
1499
|
console.log(`\u2705 Successfully logged in as ${user.email}`);
|
|
1452
|
-
setTimeout(() => process.exit(0), 100);
|
|
1453
1500
|
}
|
|
1454
1501
|
);
|
|
1455
1502
|
var loginPlugin = ({ context }) => {
|
|
@@ -2649,7 +2696,213 @@ function createZapierCliSdk(options = {}) {
|
|
|
2649
2696
|
|
|
2650
2697
|
// package.json with { type: 'json' }
|
|
2651
2698
|
var package_default2 = {
|
|
2652
|
-
|
|
2699
|
+
name: "@zapier/zapier-sdk-cli",
|
|
2700
|
+
version: "0.14.1"};
|
|
2701
|
+
function detectPackageManager(cwd = process.cwd()) {
|
|
2702
|
+
const ua = process.env.npm_config_user_agent;
|
|
2703
|
+
if (ua) {
|
|
2704
|
+
if (ua.includes("yarn")) return { name: "yarn", source: "runtime" };
|
|
2705
|
+
if (ua.includes("pnpm")) return { name: "pnpm", source: "runtime" };
|
|
2706
|
+
if (ua.includes("bun")) return { name: "bun", source: "runtime" };
|
|
2707
|
+
if (ua.includes("npm")) return { name: "npm", source: "runtime" };
|
|
2708
|
+
}
|
|
2709
|
+
const files = [
|
|
2710
|
+
["pnpm-lock.yaml", "pnpm"],
|
|
2711
|
+
["yarn.lock", "yarn"],
|
|
2712
|
+
["bun.lockb", "bun"],
|
|
2713
|
+
["package-lock.json", "npm"]
|
|
2714
|
+
];
|
|
2715
|
+
for (const [file, name] of files) {
|
|
2716
|
+
if (existsSync(join(cwd, file))) {
|
|
2717
|
+
return { name, source: "lockfile" };
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
return { name: "unknown", source: "fallback" };
|
|
2721
|
+
}
|
|
2722
|
+
function getUpdateCommand(packageName) {
|
|
2723
|
+
const pm = detectPackageManager();
|
|
2724
|
+
const isGlobal = isInstalledGlobally;
|
|
2725
|
+
if (isGlobal) {
|
|
2726
|
+
switch (pm.name) {
|
|
2727
|
+
case "yarn":
|
|
2728
|
+
return `yarn global upgrade ${packageName}@latest`;
|
|
2729
|
+
case "pnpm":
|
|
2730
|
+
return `pnpm update -g ${packageName}@latest`;
|
|
2731
|
+
case "bun":
|
|
2732
|
+
return `bun update -g ${packageName}@latest`;
|
|
2733
|
+
case "npm":
|
|
2734
|
+
return `npm update -g ${packageName}@latest`;
|
|
2735
|
+
case "unknown":
|
|
2736
|
+
return `npm update -g ${packageName}@latest`;
|
|
2737
|
+
}
|
|
2738
|
+
} else {
|
|
2739
|
+
switch (pm.name) {
|
|
2740
|
+
case "yarn":
|
|
2741
|
+
return `yarn upgrade ${packageName}@latest`;
|
|
2742
|
+
case "pnpm":
|
|
2743
|
+
return `pnpm update ${packageName}@latest`;
|
|
2744
|
+
case "bun":
|
|
2745
|
+
return `bun update ${packageName}@latest`;
|
|
2746
|
+
case "npm":
|
|
2747
|
+
return `npm update ${packageName}@latest`;
|
|
2748
|
+
case "unknown":
|
|
2749
|
+
return `npm update ${packageName}@latest`;
|
|
2750
|
+
}
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
|
|
2754
|
+
// src/utils/version-checker.ts
|
|
2755
|
+
var config = null;
|
|
2756
|
+
function getConfig() {
|
|
2757
|
+
if (!config) {
|
|
2758
|
+
config = new Conf({ projectName: "zapier-sdk-cli" });
|
|
2759
|
+
}
|
|
2760
|
+
return config;
|
|
2761
|
+
}
|
|
2762
|
+
var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
|
|
2763
|
+
var CACHE_RESET_INTERVAL_MS = (() => {
|
|
2764
|
+
const { ZAPIER_SDK_UPDATE_CHECK_INTERVAL_MS = `${ONE_DAY_MS}` } = process.env;
|
|
2765
|
+
const interval = parseInt(ZAPIER_SDK_UPDATE_CHECK_INTERVAL_MS);
|
|
2766
|
+
if (isNaN(interval) || interval < 0) {
|
|
2767
|
+
return -1;
|
|
2768
|
+
}
|
|
2769
|
+
return interval;
|
|
2770
|
+
})();
|
|
2771
|
+
function getVersionCache() {
|
|
2772
|
+
try {
|
|
2773
|
+
const cache = getConfig().get("version_cache");
|
|
2774
|
+
const now = Date.now();
|
|
2775
|
+
if (!cache || !cache.last_reset_timestamp || now - cache.last_reset_timestamp >= CACHE_RESET_INTERVAL_MS) {
|
|
2776
|
+
const newCache = {
|
|
2777
|
+
last_reset_timestamp: now,
|
|
2778
|
+
packages: {}
|
|
2779
|
+
};
|
|
2780
|
+
getConfig().set("version_cache", newCache);
|
|
2781
|
+
return newCache;
|
|
2782
|
+
}
|
|
2783
|
+
return cache;
|
|
2784
|
+
} catch (error) {
|
|
2785
|
+
log_default.debug(`Failed to read version cache: ${error}`);
|
|
2786
|
+
return {
|
|
2787
|
+
last_reset_timestamp: Date.now(),
|
|
2788
|
+
packages: {}
|
|
2789
|
+
};
|
|
2790
|
+
}
|
|
2791
|
+
}
|
|
2792
|
+
function setCachedPackageInfo(packageName, version, info) {
|
|
2793
|
+
try {
|
|
2794
|
+
const cache = getVersionCache();
|
|
2795
|
+
if (!cache.packages[packageName]) {
|
|
2796
|
+
cache.packages[packageName] = {};
|
|
2797
|
+
}
|
|
2798
|
+
cache.packages[packageName][version] = info;
|
|
2799
|
+
getConfig().set("version_cache", cache);
|
|
2800
|
+
} catch (error) {
|
|
2801
|
+
log_default.debug(`Failed to cache package info: ${error}`);
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
function getCachedPackageInfo(packageName, version) {
|
|
2805
|
+
try {
|
|
2806
|
+
const cache = getVersionCache();
|
|
2807
|
+
return cache.packages[packageName]?.[version];
|
|
2808
|
+
} catch (error) {
|
|
2809
|
+
log_default.debug(`Failed to get cached package info: ${error}`);
|
|
2810
|
+
return void 0;
|
|
2811
|
+
}
|
|
2812
|
+
}
|
|
2813
|
+
async function fetchCachedPackageInfo(packageName, version) {
|
|
2814
|
+
const cacheKey = version || "latest";
|
|
2815
|
+
let cachedInfo = getCachedPackageInfo(packageName, cacheKey);
|
|
2816
|
+
if (cachedInfo) {
|
|
2817
|
+
return cachedInfo;
|
|
2818
|
+
}
|
|
2819
|
+
const packageInfo = await packageJsonLib(packageName, {
|
|
2820
|
+
version,
|
|
2821
|
+
fullMetadata: true
|
|
2822
|
+
});
|
|
2823
|
+
const info = {
|
|
2824
|
+
version: packageInfo.version,
|
|
2825
|
+
deprecated: packageInfo.deprecated,
|
|
2826
|
+
fetched_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2827
|
+
};
|
|
2828
|
+
setCachedPackageInfo(packageName, cacheKey, info);
|
|
2829
|
+
return info;
|
|
2830
|
+
}
|
|
2831
|
+
async function checkForUpdates({
|
|
2832
|
+
packageName,
|
|
2833
|
+
currentVersion
|
|
2834
|
+
}) {
|
|
2835
|
+
try {
|
|
2836
|
+
const latestPackageInfo = await fetchCachedPackageInfo(packageName);
|
|
2837
|
+
const latestVersion = latestPackageInfo.version;
|
|
2838
|
+
const hasUpdate = currentVersion !== latestVersion;
|
|
2839
|
+
let currentPackageInfo;
|
|
2840
|
+
try {
|
|
2841
|
+
currentPackageInfo = await fetchCachedPackageInfo(
|
|
2842
|
+
packageName,
|
|
2843
|
+
currentVersion
|
|
2844
|
+
);
|
|
2845
|
+
} catch (error) {
|
|
2846
|
+
log_default.debug(`Failed to check deprecation for current version: ${error}`);
|
|
2847
|
+
currentPackageInfo = latestPackageInfo;
|
|
2848
|
+
}
|
|
2849
|
+
const isDeprecated = Boolean(currentPackageInfo.deprecated);
|
|
2850
|
+
const deprecationMessage = isDeprecated ? String(currentPackageInfo.deprecated) : void 0;
|
|
2851
|
+
return {
|
|
2852
|
+
hasUpdate,
|
|
2853
|
+
latestVersion,
|
|
2854
|
+
currentVersion,
|
|
2855
|
+
isDeprecated,
|
|
2856
|
+
deprecationMessage
|
|
2857
|
+
};
|
|
2858
|
+
} catch (error) {
|
|
2859
|
+
log_default.debug(`Failed to check for updates: ${error}`);
|
|
2860
|
+
return {
|
|
2861
|
+
hasUpdate: false,
|
|
2862
|
+
currentVersion,
|
|
2863
|
+
isDeprecated: false
|
|
2864
|
+
};
|
|
2865
|
+
}
|
|
2866
|
+
}
|
|
2867
|
+
function displayUpdateNotification(versionInfo, packageName) {
|
|
2868
|
+
if (versionInfo.isDeprecated) {
|
|
2869
|
+
console.error();
|
|
2870
|
+
console.error(
|
|
2871
|
+
chalk3.red.bold("\u26A0\uFE0F DEPRECATION WARNING") + chalk3.red(
|
|
2872
|
+
` - ${packageName} v${versionInfo.currentVersion} is deprecated.`
|
|
2873
|
+
)
|
|
2874
|
+
);
|
|
2875
|
+
if (versionInfo.deprecationMessage) {
|
|
2876
|
+
console.error(chalk3.red(` ${versionInfo.deprecationMessage}`));
|
|
2877
|
+
}
|
|
2878
|
+
console.error(chalk3.red(` Please update to the latest version.`));
|
|
2879
|
+
console.error();
|
|
2880
|
+
}
|
|
2881
|
+
if (versionInfo.hasUpdate) {
|
|
2882
|
+
console.log();
|
|
2883
|
+
console.log(
|
|
2884
|
+
chalk3.yellow.bold("\u{1F4E6} Update available!") + chalk3.yellow(
|
|
2885
|
+
` ${packageName} v${versionInfo.currentVersion} \u2192 v${versionInfo.latestVersion}`
|
|
2886
|
+
)
|
|
2887
|
+
);
|
|
2888
|
+
console.log(
|
|
2889
|
+
chalk3.yellow(
|
|
2890
|
+
` Run ${chalk3.bold(getUpdateCommand(packageName))} to update.`
|
|
2891
|
+
)
|
|
2892
|
+
);
|
|
2893
|
+
console.log();
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
async function checkAndNotifyUpdates({
|
|
2897
|
+
packageName,
|
|
2898
|
+
currentVersion
|
|
2899
|
+
}) {
|
|
2900
|
+
if (CACHE_RESET_INTERVAL_MS < 0) {
|
|
2901
|
+
return;
|
|
2902
|
+
}
|
|
2903
|
+
const versionInfo = await checkForUpdates({ packageName, currentVersion });
|
|
2904
|
+
displayUpdateNotification(versionInfo, packageName);
|
|
2905
|
+
}
|
|
2653
2906
|
|
|
2654
2907
|
// src/cli.ts
|
|
2655
2908
|
var program = new Command();
|
|
@@ -2677,4 +2930,25 @@ var sdk = createZapierCliSdk({
|
|
|
2677
2930
|
trackingBaseUrl
|
|
2678
2931
|
});
|
|
2679
2932
|
generateCliCommands(program, sdk);
|
|
2680
|
-
program.
|
|
2933
|
+
program.exitOverride();
|
|
2934
|
+
(async () => {
|
|
2935
|
+
let exitCode = 0;
|
|
2936
|
+
const versionCheckPromise = checkAndNotifyUpdates({
|
|
2937
|
+
packageName: package_default2.name,
|
|
2938
|
+
currentVersion: package_default2.version
|
|
2939
|
+
});
|
|
2940
|
+
try {
|
|
2941
|
+
await program.parseAsync();
|
|
2942
|
+
} catch (error) {
|
|
2943
|
+
if (error instanceof ZapierCliError) {
|
|
2944
|
+
exitCode = error.exitCode;
|
|
2945
|
+
} else if (error instanceof CommanderError) {
|
|
2946
|
+
exitCode = error.exitCode;
|
|
2947
|
+
} else {
|
|
2948
|
+
console.error("Unexpected error:", error);
|
|
2949
|
+
exitCode = 1;
|
|
2950
|
+
}
|
|
2951
|
+
}
|
|
2952
|
+
await versionCheckPromise;
|
|
2953
|
+
process.exit(exitCode);
|
|
2954
|
+
})();
|
package/dist/index.cjs
CHANGED
|
@@ -49,6 +49,18 @@ var ts__namespace = /*#__PURE__*/_interopNamespace(ts);
|
|
|
49
49
|
// src/sdk.ts
|
|
50
50
|
var LOGIN_PORTS = [49505, 50575, 52804, 55981, 61010, 63851];
|
|
51
51
|
var LOGIN_TIMEOUT_MS = 3e5;
|
|
52
|
+
var ZapierCliError = class extends zapierSdk.ZapierError {
|
|
53
|
+
};
|
|
54
|
+
var ZapierCliUserCancellationError = class extends ZapierCliError {
|
|
55
|
+
constructor(message = "Operation cancelled by user") {
|
|
56
|
+
super(message);
|
|
57
|
+
this.name = "ZapierCliUserCancellationError";
|
|
58
|
+
this.code = "ZAPIER_CLI_USER_CANCELLATION";
|
|
59
|
+
this.exitCode = 0;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/utils/spinner.ts
|
|
52
64
|
var spinPromise = async (promise, text) => {
|
|
53
65
|
const spinner = ora__default.default(text).start();
|
|
54
66
|
try {
|
|
@@ -56,7 +68,11 @@ var spinPromise = async (promise, text) => {
|
|
|
56
68
|
spinner.succeed();
|
|
57
69
|
return result;
|
|
58
70
|
} catch (error) {
|
|
59
|
-
|
|
71
|
+
if (error instanceof ZapierCliUserCancellationError) {
|
|
72
|
+
spinner.stop();
|
|
73
|
+
} else {
|
|
74
|
+
spinner.fail();
|
|
75
|
+
}
|
|
60
76
|
throw error;
|
|
61
77
|
}
|
|
62
78
|
};
|
|
@@ -72,6 +88,11 @@ var log = {
|
|
|
72
88
|
},
|
|
73
89
|
warn: (message, ...args) => {
|
|
74
90
|
console.log(chalk__default.default.yellow("\u26A0"), message, ...args);
|
|
91
|
+
},
|
|
92
|
+
debug: (message, ...args) => {
|
|
93
|
+
if (process.env.DEBUG === "true" || process.argv.includes("--debug")) {
|
|
94
|
+
console.log(chalk__default.default.gray("\u{1F41B}"), message, ...args);
|
|
95
|
+
}
|
|
75
96
|
}
|
|
76
97
|
};
|
|
77
98
|
var log_default = log;
|
|
@@ -174,7 +195,11 @@ var login = async ({
|
|
|
174
195
|
const availablePort = await findAvailablePort();
|
|
175
196
|
const redirectUri = `http://localhost:${availablePort}/oauth`;
|
|
176
197
|
log_default.info(`Using port ${availablePort} for OAuth callback`);
|
|
177
|
-
const {
|
|
198
|
+
const {
|
|
199
|
+
promise: promisedCode,
|
|
200
|
+
resolve: setCode,
|
|
201
|
+
reject: rejectCode
|
|
202
|
+
} = getCallablePromise_default();
|
|
178
203
|
const app = express__default.default();
|
|
179
204
|
app.get("/oauth", (req, res) => {
|
|
180
205
|
setCode(String(req.query.code));
|
|
@@ -190,7 +215,7 @@ var login = async ({
|
|
|
190
215
|
const cleanup = () => {
|
|
191
216
|
server.close();
|
|
192
217
|
log_default.info("\n\u274C Login cancelled by user");
|
|
193
|
-
|
|
218
|
+
rejectCode(new ZapierCliUserCancellationError());
|
|
194
219
|
};
|
|
195
220
|
process.on("SIGINT", cleanup);
|
|
196
221
|
process.on("SIGTERM", cleanup);
|
|
@@ -266,7 +291,7 @@ var LoginSchema = zod.z.object({
|
|
|
266
291
|
|
|
267
292
|
// package.json
|
|
268
293
|
var package_default = {
|
|
269
|
-
version: "0.
|
|
294
|
+
version: "0.14.1"};
|
|
270
295
|
|
|
271
296
|
// src/telemetry/builders.ts
|
|
272
297
|
function createCliBaseEvent(context = {}) {
|
|
@@ -338,7 +363,6 @@ var loginWithSdk = zapierSdk.createFunction(
|
|
|
338
363
|
});
|
|
339
364
|
const user = await zapierSdkCliLogin.getLoggedInUser();
|
|
340
365
|
console.log(`\u2705 Successfully logged in as ${user.email}`);
|
|
341
|
-
setTimeout(() => process.exit(0), 100);
|
|
342
366
|
}
|
|
343
367
|
);
|
|
344
368
|
var loginPlugin = ({ context }) => {
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createFunction, OutputPropertySchema, DEFAULT_CONFIG_PATH, getOsInfo, getPlatformVersions, getCiPlatform, isCi, createZapierSdkWithoutRegistry, registryPlugin, getReleaseId, getCurrentTimestamp, generateEventId, ZapierValidationError, ZapierUnknownError, batch, toSnakeCase } from '@zapier/zapier-sdk';
|
|
1
|
+
import { createFunction, OutputPropertySchema, DEFAULT_CONFIG_PATH, ZapierError, getOsInfo, getPlatformVersions, getCiPlatform, isCi, createZapierSdkWithoutRegistry, registryPlugin, getReleaseId, getCurrentTimestamp, generateEventId, ZapierValidationError, ZapierUnknownError, batch, toSnakeCase } from '@zapier/zapier-sdk';
|
|
2
2
|
import open from 'open';
|
|
3
3
|
import crypto from 'crypto';
|
|
4
4
|
import express from 'express';
|
|
@@ -18,6 +18,18 @@ import * as ts from 'typescript';
|
|
|
18
18
|
// src/sdk.ts
|
|
19
19
|
var LOGIN_PORTS = [49505, 50575, 52804, 55981, 61010, 63851];
|
|
20
20
|
var LOGIN_TIMEOUT_MS = 3e5;
|
|
21
|
+
var ZapierCliError = class extends ZapierError {
|
|
22
|
+
};
|
|
23
|
+
var ZapierCliUserCancellationError = class extends ZapierCliError {
|
|
24
|
+
constructor(message = "Operation cancelled by user") {
|
|
25
|
+
super(message);
|
|
26
|
+
this.name = "ZapierCliUserCancellationError";
|
|
27
|
+
this.code = "ZAPIER_CLI_USER_CANCELLATION";
|
|
28
|
+
this.exitCode = 0;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// src/utils/spinner.ts
|
|
21
33
|
var spinPromise = async (promise, text) => {
|
|
22
34
|
const spinner = ora(text).start();
|
|
23
35
|
try {
|
|
@@ -25,7 +37,11 @@ var spinPromise = async (promise, text) => {
|
|
|
25
37
|
spinner.succeed();
|
|
26
38
|
return result;
|
|
27
39
|
} catch (error) {
|
|
28
|
-
|
|
40
|
+
if (error instanceof ZapierCliUserCancellationError) {
|
|
41
|
+
spinner.stop();
|
|
42
|
+
} else {
|
|
43
|
+
spinner.fail();
|
|
44
|
+
}
|
|
29
45
|
throw error;
|
|
30
46
|
}
|
|
31
47
|
};
|
|
@@ -41,6 +57,11 @@ var log = {
|
|
|
41
57
|
},
|
|
42
58
|
warn: (message, ...args) => {
|
|
43
59
|
console.log(chalk.yellow("\u26A0"), message, ...args);
|
|
60
|
+
},
|
|
61
|
+
debug: (message, ...args) => {
|
|
62
|
+
if (process.env.DEBUG === "true" || process.argv.includes("--debug")) {
|
|
63
|
+
console.log(chalk.gray("\u{1F41B}"), message, ...args);
|
|
64
|
+
}
|
|
44
65
|
}
|
|
45
66
|
};
|
|
46
67
|
var log_default = log;
|
|
@@ -143,7 +164,11 @@ var login = async ({
|
|
|
143
164
|
const availablePort = await findAvailablePort();
|
|
144
165
|
const redirectUri = `http://localhost:${availablePort}/oauth`;
|
|
145
166
|
log_default.info(`Using port ${availablePort} for OAuth callback`);
|
|
146
|
-
const {
|
|
167
|
+
const {
|
|
168
|
+
promise: promisedCode,
|
|
169
|
+
resolve: setCode,
|
|
170
|
+
reject: rejectCode
|
|
171
|
+
} = getCallablePromise_default();
|
|
147
172
|
const app = express();
|
|
148
173
|
app.get("/oauth", (req, res) => {
|
|
149
174
|
setCode(String(req.query.code));
|
|
@@ -159,7 +184,7 @@ var login = async ({
|
|
|
159
184
|
const cleanup = () => {
|
|
160
185
|
server.close();
|
|
161
186
|
log_default.info("\n\u274C Login cancelled by user");
|
|
162
|
-
|
|
187
|
+
rejectCode(new ZapierCliUserCancellationError());
|
|
163
188
|
};
|
|
164
189
|
process.on("SIGINT", cleanup);
|
|
165
190
|
process.on("SIGTERM", cleanup);
|
|
@@ -235,7 +260,7 @@ var LoginSchema = z.object({
|
|
|
235
260
|
|
|
236
261
|
// package.json
|
|
237
262
|
var package_default = {
|
|
238
|
-
version: "0.
|
|
263
|
+
version: "0.14.1"};
|
|
239
264
|
|
|
240
265
|
// src/telemetry/builders.ts
|
|
241
266
|
function createCliBaseEvent(context = {}) {
|
|
@@ -307,7 +332,6 @@ var loginWithSdk = createFunction(
|
|
|
307
332
|
});
|
|
308
333
|
const user = await getLoggedInUser();
|
|
309
334
|
console.log(`\u2705 Successfully logged in as ${user.email}`);
|
|
310
|
-
setTimeout(() => process.exit(0), 100);
|
|
311
335
|
}
|
|
312
336
|
);
|
|
313
337
|
var loginPlugin = ({ context }) => {
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zapier/zapier-sdk-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "Command line interface for Zapier SDK",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -46,12 +46,15 @@
|
|
|
46
46
|
"chalk": "^5.3.0",
|
|
47
47
|
"cli-table3": "^0.6.5",
|
|
48
48
|
"commander": "^12.0.0",
|
|
49
|
+
"conf": "^14.0.0",
|
|
49
50
|
"esbuild": "^0.25.5",
|
|
50
51
|
"express": "^5.1.0",
|
|
51
52
|
"inquirer": "^12.6.3",
|
|
53
|
+
"is-installed-globally": "^1.0.0",
|
|
52
54
|
"jsonwebtoken": "^9.0.2",
|
|
53
55
|
"open": "^10.2.0",
|
|
54
56
|
"ora": "^8.2.0",
|
|
57
|
+
"package-json": "^10.0.1",
|
|
55
58
|
"pkce-challenge": "^5.0.0",
|
|
56
59
|
"typescript": "^5.8.3",
|
|
57
60
|
"zod": "^3.25.67"
|
package/dist/src/cli.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Command } from "commander";
|
|
2
|
+
import { Command, CommanderError } from "commander";
|
|
3
3
|
import { generateCliCommands } from "./utils/cli-generator";
|
|
4
4
|
import { createZapierCliSdk } from "./sdk";
|
|
5
5
|
import packageJson from "../package.json" with { type: "json" };
|
|
6
|
+
import { ZapierCliError } from "./utils/errors";
|
|
7
|
+
import { checkAndNotifyUpdates } from "./utils/version-checker";
|
|
6
8
|
const program = new Command();
|
|
7
9
|
program
|
|
8
10
|
.name("zapier-sdk")
|
|
@@ -39,4 +41,32 @@ const sdk = createZapierCliSdk({
|
|
|
39
41
|
// Generate CLI commands from SDK schemas (including CLI plugins)
|
|
40
42
|
generateCliCommands(program, sdk);
|
|
41
43
|
// MCP command now handled by plugin
|
|
42
|
-
|
|
44
|
+
// Override Commander's default exit behavior to handle our custom errors
|
|
45
|
+
program.exitOverride();
|
|
46
|
+
(async () => {
|
|
47
|
+
let exitCode = 0;
|
|
48
|
+
// Start version checking non-blocking
|
|
49
|
+
const versionCheckPromise = checkAndNotifyUpdates({
|
|
50
|
+
packageName: packageJson.name,
|
|
51
|
+
currentVersion: packageJson.version,
|
|
52
|
+
});
|
|
53
|
+
try {
|
|
54
|
+
await program.parseAsync();
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (error instanceof ZapierCliError) {
|
|
58
|
+
exitCode = error.exitCode;
|
|
59
|
+
}
|
|
60
|
+
else if (error instanceof CommanderError) {
|
|
61
|
+
exitCode = error.exitCode;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// For any other unexpected errors, exit with code 1
|
|
65
|
+
console.error("Unexpected error:", error);
|
|
66
|
+
exitCode = 1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Wait for version checking to complete
|
|
70
|
+
await versionCheckPromise;
|
|
71
|
+
process.exit(exitCode);
|
|
72
|
+
})();
|