@zapier/zapier-sdk-cli 0.34.1 → 0.34.4
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 +23 -0
- package/dist/cli.cjs +172 -143
- package/dist/cli.mjs +173 -144
- package/dist/index.cjs +74 -113
- package/dist/index.mjs +75 -114
- package/dist/package.json +1 -1
- package/dist/src/plugins/login/index.d.ts +1 -2
- package/dist/src/plugins/login/index.js +16 -65
- package/dist/src/utils/cli-generator.d.ts +1 -0
- package/dist/src/utils/cli-generator.js +69 -4
- package/dist/src/utils/parameter-resolver.js +27 -25
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as cliLogin from '@zapier/zapier-sdk-cli-login';
|
|
2
2
|
import { logout, getConfigPath, getLoggedInUser, getPkceLoginConfig, AUTH_MODE_HEADER, getLoginStorageMode, updateLogin } from '@zapier/zapier-sdk-cli-login';
|
|
3
|
-
import { createFunction, OutputPropertySchema, DEFAULT_CONFIG_PATH, injectCliLogin, getOsInfo, getPlatformVersions, getCiPlatform, isCi,
|
|
3
|
+
import { createFunction, OutputPropertySchema, DEFAULT_CONFIG_PATH, injectCliLogin, createZapierSdkWithoutRegistry, registryPlugin, getOsInfo, getPlatformVersions, getCiPlatform, isCi, ZapierValidationError, ZapierUnknownError, getReleaseId, getCurrentTimestamp, generateEventId, batch, toSnakeCase, ZapierError, isCredentialsObject } from '@zapier/zapier-sdk';
|
|
4
4
|
import open from 'open';
|
|
5
5
|
import crypto, { createHash } from 'crypto';
|
|
6
6
|
import express from 'express';
|
|
@@ -309,65 +309,7 @@ var LoginSchema = z.object({
|
|
|
309
309
|
timeout: z.string().optional().describe("Login timeout in seconds (default: 300)")
|
|
310
310
|
}).describe("Log in to Zapier to access your account");
|
|
311
311
|
|
|
312
|
-
// package.json
|
|
313
|
-
var package_default = {
|
|
314
|
-
version: "0.34.1"};
|
|
315
|
-
|
|
316
|
-
// src/telemetry/builders.ts
|
|
317
|
-
function createCliBaseEvent(context = {}) {
|
|
318
|
-
return {
|
|
319
|
-
event_id: generateEventId(),
|
|
320
|
-
timestamp_ms: getCurrentTimestamp(),
|
|
321
|
-
release_id: getReleaseId(),
|
|
322
|
-
customuser_id: context.customuser_id ?? null,
|
|
323
|
-
account_id: context.account_id ?? null,
|
|
324
|
-
identity_id: context.identity_id ?? null,
|
|
325
|
-
visitor_id: context.visitor_id ?? null,
|
|
326
|
-
correlation_id: context.correlation_id ?? null
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
function buildCliCommandExecutedEvent({
|
|
330
|
-
data,
|
|
331
|
-
context = {},
|
|
332
|
-
cliVersion = package_default.version
|
|
333
|
-
}) {
|
|
334
|
-
const osInfo = getOsInfo();
|
|
335
|
-
const platformVersions = getPlatformVersions();
|
|
336
|
-
return {
|
|
337
|
-
...createCliBaseEvent(context),
|
|
338
|
-
system_name: "zapier-sdk-cli",
|
|
339
|
-
session_id: context.session_id ?? null,
|
|
340
|
-
cli_version: data.cli_version ?? cliVersion,
|
|
341
|
-
cli_arguments: data.cli_arguments ?? null,
|
|
342
|
-
cli_primary_command: data.cli_primary_command,
|
|
343
|
-
os_platform: osInfo.platform,
|
|
344
|
-
os_release: osInfo.release,
|
|
345
|
-
os_architecture: osInfo.architecture,
|
|
346
|
-
platform_versions: platformVersions,
|
|
347
|
-
selected_api: context.selected_api ?? null,
|
|
348
|
-
app_id: context.app_id ?? null,
|
|
349
|
-
app_version_id: context.app_version_id ?? null,
|
|
350
|
-
execution_duration_ms: data.execution_duration_ms ?? null,
|
|
351
|
-
success_flag: data.success_flag,
|
|
352
|
-
exit_code: data.exit_code ?? (data.success_flag ? 0 : 1),
|
|
353
|
-
error_message: data.error_message ?? null,
|
|
354
|
-
command_category: data.command_category ?? null,
|
|
355
|
-
requires_auth: data.requires_auth ?? null,
|
|
356
|
-
is_ci_environment: isCi(),
|
|
357
|
-
ci_platform: getCiPlatform(),
|
|
358
|
-
package_manager: data.package_manager ?? "pnpm",
|
|
359
|
-
// Default based on project setup
|
|
360
|
-
made_network_requests: data.made_network_requests ?? null,
|
|
361
|
-
files_modified_count: data.files_modified_count ?? null,
|
|
362
|
-
files_created_count: data.files_created_count ?? null,
|
|
363
|
-
files_processed_size_bytes: data.files_processed_size_bytes ?? null,
|
|
364
|
-
cpu_time_ms: data.cpu_time_ms ?? null,
|
|
365
|
-
subprocess_count: data.subprocess_count ?? null
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
|
|
369
312
|
// src/plugins/login/index.ts
|
|
370
|
-
var CLI_COMMAND_EXECUTED_EVENT_SUBJECT = "platform.sdk.CliCommandExecutedEvent";
|
|
371
313
|
function toPkceCredentials(credentials) {
|
|
372
314
|
if (credentials && isCredentialsObject(credentials) && !("clientSecret" in credentials)) {
|
|
373
315
|
return {
|
|
@@ -379,63 +321,25 @@ function toPkceCredentials(credentials) {
|
|
|
379
321
|
}
|
|
380
322
|
return void 0;
|
|
381
323
|
}
|
|
382
|
-
var loginPlugin = ({
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
credentials: pkceCredentials
|
|
399
|
-
});
|
|
400
|
-
const user = await getLoggedInUser();
|
|
401
|
-
accountId = user.accountId;
|
|
402
|
-
customUserId = user.customUserId;
|
|
403
|
-
console.log(`\u2705 Successfully logged in as ${user.email}`);
|
|
404
|
-
success = true;
|
|
405
|
-
} catch (error) {
|
|
406
|
-
success = false;
|
|
407
|
-
errorMessage = error instanceof Error ? error.message : "Login failed";
|
|
408
|
-
throw error;
|
|
409
|
-
} finally {
|
|
410
|
-
const event = buildCliCommandExecutedEvent({
|
|
411
|
-
data: {
|
|
412
|
-
cli_primary_command: "login",
|
|
413
|
-
success_flag: success,
|
|
414
|
-
execution_duration_ms: Date.now() - startTime,
|
|
415
|
-
exit_code: success ? 0 : 1,
|
|
416
|
-
error_message: errorMessage,
|
|
417
|
-
command_category: "authentication",
|
|
418
|
-
requires_auth: false,
|
|
419
|
-
cli_arguments: [
|
|
420
|
-
"login",
|
|
421
|
-
options.timeout ? `--timeout=${options.timeout}` : null
|
|
422
|
-
].filter(Boolean)
|
|
423
|
-
},
|
|
424
|
-
context: {
|
|
425
|
-
session_id: context.session_id,
|
|
426
|
-
selected_api: context.selected_api,
|
|
427
|
-
app_id: context.app_id,
|
|
428
|
-
app_version_id: context.app_version_id,
|
|
429
|
-
customuser_id: customUserId,
|
|
430
|
-
account_id: accountId
|
|
431
|
-
},
|
|
432
|
-
cliVersion: package_default.version
|
|
433
|
-
});
|
|
434
|
-
context.eventEmission.emit(CLI_COMMAND_EXECUTED_EVENT_SUBJECT, event);
|
|
435
|
-
}
|
|
324
|
+
var loginPlugin = ({
|
|
325
|
+
context
|
|
326
|
+
}) => {
|
|
327
|
+
const loginFn = async (options) => {
|
|
328
|
+
const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
|
|
329
|
+
if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
|
|
330
|
+
throw new Error("Timeout must be a positive number");
|
|
331
|
+
}
|
|
332
|
+
const resolvedCredentials = await context.resolveCredentials();
|
|
333
|
+
const pkceCredentials = toPkceCredentials(resolvedCredentials);
|
|
334
|
+
await login_default({
|
|
335
|
+
timeoutMs: timeoutSeconds * 1e3,
|
|
336
|
+
credentials: pkceCredentials
|
|
337
|
+
});
|
|
338
|
+
const user = await getLoggedInUser();
|
|
339
|
+
console.log(`\u2705 Successfully logged in as ${user.email}`);
|
|
436
340
|
};
|
|
437
341
|
return {
|
|
438
|
-
login:
|
|
342
|
+
login: loginFn,
|
|
439
343
|
context: {
|
|
440
344
|
meta: {
|
|
441
345
|
login: {
|
|
@@ -2559,6 +2463,63 @@ function createZapierCliSdk(options = {}) {
|
|
|
2559
2463
|
}).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);
|
|
2560
2464
|
}
|
|
2561
2465
|
|
|
2466
|
+
// package.json
|
|
2467
|
+
var package_default = {
|
|
2468
|
+
version: "0.34.4"};
|
|
2469
|
+
|
|
2470
|
+
// src/telemetry/builders.ts
|
|
2471
|
+
function createCliBaseEvent(context = {}) {
|
|
2472
|
+
return {
|
|
2473
|
+
event_id: generateEventId(),
|
|
2474
|
+
timestamp_ms: getCurrentTimestamp(),
|
|
2475
|
+
release_id: getReleaseId(),
|
|
2476
|
+
customuser_id: context.customuser_id ?? null,
|
|
2477
|
+
account_id: context.account_id ?? null,
|
|
2478
|
+
identity_id: context.identity_id ?? null,
|
|
2479
|
+
visitor_id: context.visitor_id ?? null,
|
|
2480
|
+
correlation_id: context.correlation_id ?? null
|
|
2481
|
+
};
|
|
2482
|
+
}
|
|
2483
|
+
function buildCliCommandExecutedEvent({
|
|
2484
|
+
data,
|
|
2485
|
+
context = {},
|
|
2486
|
+
cliVersion = package_default.version
|
|
2487
|
+
}) {
|
|
2488
|
+
const osInfo = getOsInfo();
|
|
2489
|
+
const platformVersions = getPlatformVersions();
|
|
2490
|
+
return {
|
|
2491
|
+
...createCliBaseEvent(context),
|
|
2492
|
+
system_name: "zapier-sdk-cli",
|
|
2493
|
+
session_id: context.session_id ?? null,
|
|
2494
|
+
cli_version: data.cli_version ?? cliVersion,
|
|
2495
|
+
cli_arguments: data.cli_arguments ?? null,
|
|
2496
|
+
cli_primary_command: data.cli_primary_command,
|
|
2497
|
+
os_platform: osInfo.platform,
|
|
2498
|
+
os_release: osInfo.release,
|
|
2499
|
+
os_architecture: osInfo.architecture,
|
|
2500
|
+
platform_versions: platformVersions,
|
|
2501
|
+
selected_api: context.selected_api ?? null,
|
|
2502
|
+
app_id: context.app_id ?? null,
|
|
2503
|
+
app_version_id: context.app_version_id ?? null,
|
|
2504
|
+
execution_duration_ms: data.execution_duration_ms ?? null,
|
|
2505
|
+
success_flag: data.success_flag,
|
|
2506
|
+
exit_code: data.exit_code ?? (data.success_flag ? 0 : 1),
|
|
2507
|
+
error_message: data.error_message ?? null,
|
|
2508
|
+
command_category: data.command_category ?? null,
|
|
2509
|
+
requires_auth: data.requires_auth ?? null,
|
|
2510
|
+
is_ci_environment: isCi(),
|
|
2511
|
+
ci_platform: getCiPlatform(),
|
|
2512
|
+
package_manager: data.package_manager ?? "pnpm",
|
|
2513
|
+
// Default based on project setup
|
|
2514
|
+
made_network_requests: data.made_network_requests ?? null,
|
|
2515
|
+
files_modified_count: data.files_modified_count ?? null,
|
|
2516
|
+
files_created_count: data.files_created_count ?? null,
|
|
2517
|
+
files_processed_size_bytes: data.files_processed_size_bytes ?? null,
|
|
2518
|
+
cpu_time_ms: data.cpu_time_ms ?? null,
|
|
2519
|
+
subprocess_count: data.subprocess_count ?? null
|
|
2520
|
+
};
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2562
2523
|
// src/utils/cli-options.ts
|
|
2563
2524
|
var ReservedCliParameter = /* @__PURE__ */ ((ReservedCliParameter2) => {
|
|
2564
2525
|
ReservedCliParameter2["Version"] = "version";
|
package/dist/package.json
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Plugin, ResolvedCredentials } from "@zapier/zapier-sdk";
|
|
2
|
-
import type { EventEmissionContext } from "@zapier/zapier-sdk";
|
|
3
2
|
import { LoginSchema, type LoginOptions } from "./schemas";
|
|
4
3
|
interface CliContext {
|
|
5
4
|
session_id?: string | null;
|
|
@@ -19,5 +18,5 @@ interface LoginPluginProvides {
|
|
|
19
18
|
};
|
|
20
19
|
};
|
|
21
20
|
}
|
|
22
|
-
export declare const loginPlugin: Plugin<{},
|
|
21
|
+
export declare const loginPlugin: Plugin<{}, CliContext, LoginPluginProvides>;
|
|
23
22
|
export type { LoginPluginProvides };
|
|
@@ -2,9 +2,6 @@ import { isCredentialsObject } from "@zapier/zapier-sdk";
|
|
|
2
2
|
import login from "../../utils/auth/login";
|
|
3
3
|
import { getLoggedInUser, } from "@zapier/zapier-sdk-cli-login";
|
|
4
4
|
import { LoginSchema } from "./schemas";
|
|
5
|
-
import { buildCliCommandExecutedEvent } from "../../telemetry/builders";
|
|
6
|
-
import cliPackageJson from "../../../package.json";
|
|
7
|
-
const CLI_COMMAND_EXECUTED_EVENT_SUBJECT = "platform.sdk.CliCommandExecutedEvent";
|
|
8
5
|
function toPkceCredentials(credentials) {
|
|
9
6
|
if (credentials &&
|
|
10
7
|
isCredentialsObject(credentials) &&
|
|
@@ -18,71 +15,25 @@ function toPkceCredentials(credentials) {
|
|
|
18
15
|
}
|
|
19
16
|
return undefined;
|
|
20
17
|
}
|
|
21
|
-
export const loginPlugin = ({ context }) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
let customUserId = null;
|
|
29
|
-
try {
|
|
30
|
-
const timeoutSeconds = options.timeout
|
|
31
|
-
? parseInt(options.timeout, 10)
|
|
32
|
-
: 300;
|
|
33
|
-
if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
|
|
34
|
-
throw new Error("Timeout must be a positive number");
|
|
35
|
-
}
|
|
36
|
-
// Resolve credentials from options and env vars
|
|
37
|
-
const resolvedCredentials = await context.resolveCredentials();
|
|
38
|
-
const pkceCredentials = toPkceCredentials(resolvedCredentials);
|
|
39
|
-
await login({
|
|
40
|
-
timeoutMs: timeoutSeconds * 1000,
|
|
41
|
-
credentials: pkceCredentials,
|
|
42
|
-
});
|
|
43
|
-
// Get user info after successful login
|
|
44
|
-
const user = await getLoggedInUser();
|
|
45
|
-
accountId = user.accountId;
|
|
46
|
-
customUserId = user.customUserId;
|
|
47
|
-
console.log(`✅ Successfully logged in as ${user.email}`);
|
|
48
|
-
success = true;
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
success = false;
|
|
52
|
-
errorMessage = error instanceof Error ? error.message : "Login failed";
|
|
53
|
-
throw error;
|
|
54
|
-
}
|
|
55
|
-
finally {
|
|
56
|
-
// Emit CLI command executed event if event emission is available
|
|
57
|
-
const event = buildCliCommandExecutedEvent({
|
|
58
|
-
data: {
|
|
59
|
-
cli_primary_command: "login",
|
|
60
|
-
success_flag: success,
|
|
61
|
-
execution_duration_ms: Date.now() - startTime,
|
|
62
|
-
exit_code: success ? 0 : 1,
|
|
63
|
-
error_message: errorMessage,
|
|
64
|
-
command_category: "authentication",
|
|
65
|
-
requires_auth: false,
|
|
66
|
-
cli_arguments: [
|
|
67
|
-
"login",
|
|
68
|
-
options.timeout ? `--timeout=${options.timeout}` : null,
|
|
69
|
-
].filter(Boolean),
|
|
70
|
-
},
|
|
71
|
-
context: {
|
|
72
|
-
session_id: context.session_id,
|
|
73
|
-
selected_api: context.selected_api,
|
|
74
|
-
app_id: context.app_id,
|
|
75
|
-
app_version_id: context.app_version_id,
|
|
76
|
-
customuser_id: customUserId,
|
|
77
|
-
account_id: accountId,
|
|
78
|
-
},
|
|
79
|
-
cliVersion: cliPackageJson.version,
|
|
80
|
-
});
|
|
81
|
-
context.eventEmission.emit(CLI_COMMAND_EXECUTED_EVENT_SUBJECT, event);
|
|
18
|
+
export const loginPlugin = ({ context, }) => {
|
|
19
|
+
const loginFn = async (options) => {
|
|
20
|
+
const timeoutSeconds = options.timeout
|
|
21
|
+
? parseInt(options.timeout, 10)
|
|
22
|
+
: 300;
|
|
23
|
+
if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
|
|
24
|
+
throw new Error("Timeout must be a positive number");
|
|
82
25
|
}
|
|
26
|
+
const resolvedCredentials = await context.resolveCredentials();
|
|
27
|
+
const pkceCredentials = toPkceCredentials(resolvedCredentials);
|
|
28
|
+
await login({
|
|
29
|
+
timeoutMs: timeoutSeconds * 1000,
|
|
30
|
+
credentials: pkceCredentials,
|
|
31
|
+
});
|
|
32
|
+
const user = await getLoggedInUser();
|
|
33
|
+
console.log(`✅ Successfully logged in as ${user.email}`);
|
|
83
34
|
};
|
|
84
35
|
return {
|
|
85
|
-
login:
|
|
36
|
+
login: loginFn,
|
|
86
37
|
context: {
|
|
87
38
|
meta: {
|
|
88
39
|
login: {
|
|
@@ -6,6 +6,41 @@ import chalk from "chalk";
|
|
|
6
6
|
import inquirer from "inquirer";
|
|
7
7
|
import { ZapierCliError, ZapierCliExitError } from "./errors";
|
|
8
8
|
import { SHARED_COMMAND_CLI_OPTIONS } from "./cli-options";
|
|
9
|
+
import { buildCliCommandExecutedEvent } from "../telemetry/builders";
|
|
10
|
+
const CLI_COMMAND_EXECUTED_EVENT_SUBJECT = "platform.sdk.CliCommandExecutedEvent";
|
|
11
|
+
// Flags whose values may contain secrets and must not appear in telemetry
|
|
12
|
+
const SENSITIVE_FLAGS = [
|
|
13
|
+
"--credentials",
|
|
14
|
+
"--credentials-client-secret",
|
|
15
|
+
"--credentials-client-id",
|
|
16
|
+
"--credentials-base-url",
|
|
17
|
+
"--user",
|
|
18
|
+
"--header",
|
|
19
|
+
"-H",
|
|
20
|
+
"-u",
|
|
21
|
+
];
|
|
22
|
+
export function sanitizeCliArguments(args) {
|
|
23
|
+
const sanitized = [];
|
|
24
|
+
let skipNext = false;
|
|
25
|
+
for (const arg of args) {
|
|
26
|
+
if (skipNext) {
|
|
27
|
+
skipNext = false;
|
|
28
|
+
sanitized.push("[REDACTED]");
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (SENSITIVE_FLAGS.some((flag) => arg.startsWith(flag + "="))) {
|
|
32
|
+
sanitized.push(arg.split("=")[0] + "=[REDACTED]");
|
|
33
|
+
}
|
|
34
|
+
else if (SENSITIVE_FLAGS.includes(arg)) {
|
|
35
|
+
sanitized.push(arg);
|
|
36
|
+
skipNext = true;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
sanitized.push(arg);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return sanitized;
|
|
43
|
+
}
|
|
9
44
|
const CONFIRM_MESSAGES = {
|
|
10
45
|
"create-secret": {
|
|
11
46
|
messageBefore: "You are about to create a sensitive secret that will be displayed as plain text.\n" +
|
|
@@ -299,6 +334,10 @@ function createCommandConfig(cliCommandName, functionInfo, sdk) {
|
|
|
299
334
|
schema?.description ||
|
|
300
335
|
`${cliCommandName} command`;
|
|
301
336
|
const handler = async (...args) => {
|
|
337
|
+
const startTime = Date.now();
|
|
338
|
+
let success = true;
|
|
339
|
+
let errorMessage = null;
|
|
340
|
+
let resolvedParams = {};
|
|
302
341
|
try {
|
|
303
342
|
// The last argument is always the command object with parsed options
|
|
304
343
|
const commandObj = args[args.length - 1];
|
|
@@ -312,7 +351,6 @@ function createCommandConfig(cliCommandName, functionInfo, sdk) {
|
|
|
312
351
|
const rawParams = convertCliArgsToSdkParams(parameters, args.slice(0, -1), options);
|
|
313
352
|
// Resolve missing parameters interactively using schema metadata
|
|
314
353
|
// (only available for inputSchema-based functions)
|
|
315
|
-
let resolvedParams;
|
|
316
354
|
if (schema && !usesInputParameters) {
|
|
317
355
|
const resolver = new SchemaParameterResolver();
|
|
318
356
|
resolvedParams = (await resolver.resolveParameters(schema, rawParams, sdk, functionInfo.name));
|
|
@@ -401,6 +439,8 @@ function createCommandConfig(cliCommandName, functionInfo, sdk) {
|
|
|
401
439
|
}
|
|
402
440
|
}
|
|
403
441
|
catch (error) {
|
|
442
|
+
success = false;
|
|
443
|
+
errorMessage = error instanceof Error ? error.message : String(error);
|
|
404
444
|
// Handle Zod validation errors more gracefully
|
|
405
445
|
if (error instanceof Error && error.message.includes('"code"')) {
|
|
406
446
|
try {
|
|
@@ -431,9 +471,34 @@ function createCommandConfig(cliCommandName, functionInfo, sdk) {
|
|
|
431
471
|
}
|
|
432
472
|
else {
|
|
433
473
|
// Handle other errors
|
|
434
|
-
const
|
|
435
|
-
console.error(chalk.red("❌ Error:"),
|
|
436
|
-
throw new ZapierCliExitError(
|
|
474
|
+
const msg = error instanceof Error ? error.message : "Unknown error";
|
|
475
|
+
console.error(chalk.red("❌ Error:"), msg);
|
|
476
|
+
throw new ZapierCliExitError(msg, 1);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
finally {
|
|
480
|
+
try {
|
|
481
|
+
const event = buildCliCommandExecutedEvent({
|
|
482
|
+
data: {
|
|
483
|
+
cli_primary_command: cliCommandName,
|
|
484
|
+
success_flag: success,
|
|
485
|
+
execution_duration_ms: Date.now() - startTime,
|
|
486
|
+
exit_code: success ? 0 : 1,
|
|
487
|
+
error_message: errorMessage,
|
|
488
|
+
command_category: functionInfo.categories?.[0] ?? null,
|
|
489
|
+
requires_auth: null,
|
|
490
|
+
cli_arguments: sanitizeCliArguments(process.argv.slice(2)),
|
|
491
|
+
},
|
|
492
|
+
context: {
|
|
493
|
+
selected_api: resolvedParams.appKey ?? null,
|
|
494
|
+
},
|
|
495
|
+
});
|
|
496
|
+
sdk
|
|
497
|
+
.getContext()
|
|
498
|
+
.eventEmission.emit(CLI_COMMAND_EXECUTED_EVENT_SUBJECT, event);
|
|
499
|
+
}
|
|
500
|
+
catch {
|
|
501
|
+
// Never let telemetry failures affect command execution
|
|
437
502
|
}
|
|
438
503
|
}
|
|
439
504
|
};
|
|
@@ -260,47 +260,49 @@ export class SchemaParameterResolver {
|
|
|
260
260
|
throw new Error(`No resolver found for parameter: ${param.name}`);
|
|
261
261
|
}
|
|
262
262
|
console.log(chalk.blue(`\n🔍 Resolving ${param.name}...`));
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
// Static resolver - just prompt for input
|
|
263
|
+
if (resolver.type === "static") {
|
|
264
|
+
const staticResolver = resolver;
|
|
266
265
|
const promptConfig = {
|
|
267
|
-
type:
|
|
266
|
+
type: staticResolver.inputType === "password" ? "password" : "input",
|
|
268
267
|
name: param.name,
|
|
269
268
|
message: `Enter ${param.name}:`,
|
|
270
|
-
...(
|
|
271
|
-
default:
|
|
269
|
+
...(staticResolver.placeholder && {
|
|
270
|
+
default: staticResolver.placeholder,
|
|
272
271
|
}),
|
|
273
272
|
};
|
|
274
273
|
const answers = await inquirer.prompt([promptConfig]);
|
|
275
274
|
return answers[param.name];
|
|
276
275
|
}
|
|
277
|
-
else if (
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
276
|
+
else if (resolver.type === "dynamic") {
|
|
277
|
+
const dynamicResolver = resolver;
|
|
278
|
+
if (dynamicResolver.tryResolveWithoutPrompt) {
|
|
279
|
+
try {
|
|
280
|
+
const preResolvedValue = await dynamicResolver.tryResolveWithoutPrompt(context.sdk, context.resolvedParams);
|
|
281
|
+
if (preResolvedValue != null) {
|
|
282
|
+
return preResolvedValue.resolvedValue;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
// Fall through to fetch/prompt if pre-resolution fails
|
|
283
287
|
}
|
|
284
|
-
const items = await typedResolver.fetch(context.sdk, context.resolvedParams);
|
|
285
|
-
// Let the resolver's prompt handle empty lists (e.g., connectionId can show "skip connection")
|
|
286
|
-
const safeItems = items || [];
|
|
287
|
-
const promptConfig = typedResolver.prompt(safeItems, context.resolvedParams);
|
|
288
|
-
const answers = await inquirer.prompt([promptConfig]);
|
|
289
|
-
return answers[param.name];
|
|
290
288
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
289
|
+
// Only show "Fetching..." for required parameters that typically have many options
|
|
290
|
+
if (param.isRequired && param.name !== "connectionId") {
|
|
291
|
+
console.log(chalk.gray(`Fetching options for ${param.name}...`));
|
|
294
292
|
}
|
|
293
|
+
const items = await dynamicResolver.fetch(context.sdk, context.resolvedParams);
|
|
294
|
+
// Let the resolver's prompt handle empty lists (e.g., connectionId can show "skip connection")
|
|
295
|
+
const safeItems = items || [];
|
|
296
|
+
const promptConfig = dynamicResolver.prompt(safeItems, context.resolvedParams);
|
|
297
|
+
const answers = await inquirer.prompt([promptConfig]);
|
|
298
|
+
return answers[param.name];
|
|
295
299
|
}
|
|
296
|
-
else if (
|
|
297
|
-
// Fields resolver - fetch field definitions and prompt for each input with recursive field resolution
|
|
300
|
+
else if (resolver.type === "fields") {
|
|
298
301
|
return await this.resolveFieldsRecursively(resolver, context, param);
|
|
299
302
|
}
|
|
300
303
|
throw new Error(`Unknown resolver type for ${param.name}`);
|
|
301
304
|
}
|
|
302
305
|
async resolveFieldsRecursively(resolver, context, param) {
|
|
303
|
-
const typedResolver = resolver;
|
|
304
306
|
const inputs = {};
|
|
305
307
|
let processedFieldKeys = new Set();
|
|
306
308
|
let iteration = 0;
|
|
@@ -316,7 +318,7 @@ export class SchemaParameterResolver {
|
|
|
316
318
|
},
|
|
317
319
|
};
|
|
318
320
|
console.log(chalk.gray(`Fetching input fields for ${param.name}${iteration > 1 ? ` (iteration ${iteration})` : ""}...`));
|
|
319
|
-
const rootFieldItems = await
|
|
321
|
+
const rootFieldItems = await resolver.fetch(updatedContext.sdk, updatedContext.resolvedParams);
|
|
320
322
|
if (!rootFieldItems || rootFieldItems.length === 0) {
|
|
321
323
|
if (iteration === 1) {
|
|
322
324
|
console.log(chalk.yellow(`No input fields required for this action.`));
|