@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 CHANGED
@@ -1,5 +1,28 @@
1
1
  # @zapier/zapier-sdk-cli
2
2
 
3
+ ## 0.34.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 04000f6: Skip connection selection for apps that do not require auth
8
+ - Updated dependencies [04000f6]
9
+ - @zapier/zapier-sdk@0.32.3
10
+ - @zapier/zapier-sdk-mcp@0.9.14
11
+
12
+ ## 0.34.3
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [a6dec83]
17
+ - @zapier/zapier-sdk@0.32.2
18
+ - @zapier/zapier-sdk-mcp@0.9.13
19
+
20
+ ## 0.34.2
21
+
22
+ ### Patch Changes
23
+
24
+ - 2860435: Emit telemetry events for all CLI commands
25
+
3
26
  ## 0.34.1
4
27
 
5
28
  ### Patch Changes
package/dist/cli.cjs CHANGED
@@ -317,44 +317,57 @@ var SchemaParameterResolver = class {
317
317
  };
318
318
  }
319
319
  async resolveParameter(param, context, functionName) {
320
- const resolver = this.getResolver(param.name, context.sdk, functionName);
320
+ const resolver = this.getResolver(
321
+ param.name,
322
+ context.sdk,
323
+ functionName
324
+ );
321
325
  if (!resolver) {
322
326
  throw new Error(`No resolver found for parameter: ${param.name}`);
323
327
  }
324
328
  console.log(chalk6__default.default.blue(`
325
329
  \u{1F50D} Resolving ${param.name}...`));
326
- const typedResolver = resolver;
327
- if (typedResolver.type === "static") {
330
+ if (resolver.type === "static") {
331
+ const staticResolver = resolver;
328
332
  const promptConfig = {
329
- type: typedResolver.inputType === "password" ? "password" : "input",
333
+ type: staticResolver.inputType === "password" ? "password" : "input",
330
334
  name: param.name,
331
335
  message: `Enter ${param.name}:`,
332
- ...typedResolver.placeholder && {
333
- default: typedResolver.placeholder
336
+ ...staticResolver.placeholder && {
337
+ default: staticResolver.placeholder
334
338
  }
335
339
  };
336
340
  const answers = await inquirer__default.default.prompt([promptConfig]);
337
341
  return answers[param.name];
338
- } else if (typedResolver.type === "dynamic") {
339
- try {
340
- if (param.isRequired && param.name !== "connectionId") {
341
- console.log(chalk6__default.default.gray(`Fetching options for ${param.name}...`));
342
+ } else if (resolver.type === "dynamic") {
343
+ const dynamicResolver = resolver;
344
+ if (dynamicResolver.tryResolveWithoutPrompt) {
345
+ try {
346
+ const preResolvedValue = await dynamicResolver.tryResolveWithoutPrompt(
347
+ context.sdk,
348
+ context.resolvedParams
349
+ );
350
+ if (preResolvedValue != null) {
351
+ return preResolvedValue.resolvedValue;
352
+ }
353
+ } catch {
342
354
  }
343
- const items = await typedResolver.fetch(
344
- context.sdk,
345
- context.resolvedParams
346
- );
347
- const safeItems = items || [];
348
- const promptConfig = typedResolver.prompt(
349
- safeItems,
350
- context.resolvedParams
351
- );
352
- const answers = await inquirer__default.default.prompt([promptConfig]);
353
- return answers[param.name];
354
- } catch (error) {
355
- throw error;
356
355
  }
357
- } else if (typedResolver.type === "fields") {
356
+ if (param.isRequired && param.name !== "connectionId") {
357
+ console.log(chalk6__default.default.gray(`Fetching options for ${param.name}...`));
358
+ }
359
+ const items = await dynamicResolver.fetch(
360
+ context.sdk,
361
+ context.resolvedParams
362
+ );
363
+ const safeItems = items || [];
364
+ const promptConfig = dynamicResolver.prompt(
365
+ safeItems,
366
+ context.resolvedParams
367
+ );
368
+ const answers = await inquirer__default.default.prompt([promptConfig]);
369
+ return answers[param.name];
370
+ } else if (resolver.type === "fields") {
358
371
  return await this.resolveFieldsRecursively(
359
372
  resolver,
360
373
  context,
@@ -364,7 +377,6 @@ var SchemaParameterResolver = class {
364
377
  throw new Error(`Unknown resolver type for ${param.name}`);
365
378
  }
366
379
  async resolveFieldsRecursively(resolver, context, param) {
367
- const typedResolver = resolver;
368
380
  const inputs = {};
369
381
  let processedFieldKeys = /* @__PURE__ */ new Set();
370
382
  let iteration = 0;
@@ -383,7 +395,7 @@ var SchemaParameterResolver = class {
383
395
  `Fetching input fields for ${param.name}${iteration > 1 ? ` (iteration ${iteration})` : ""}...`
384
396
  )
385
397
  );
386
- const rootFieldItems = await typedResolver.fetch(
398
+ const rootFieldItems = await resolver.fetch(
387
399
  updatedContext.sdk,
388
400
  updatedContext.resolvedParams
389
401
  );
@@ -909,7 +921,95 @@ var SHARED_COMMAND_CLI_OPTIONS = [
909
921
  }
910
922
  ];
911
923
 
924
+ // package.json
925
+ var package_default = {
926
+ version: "0.34.4"};
927
+
928
+ // src/telemetry/builders.ts
929
+ function createCliBaseEvent(context = {}) {
930
+ return {
931
+ event_id: zapierSdk.generateEventId(),
932
+ timestamp_ms: zapierSdk.getCurrentTimestamp(),
933
+ release_id: zapierSdk.getReleaseId(),
934
+ customuser_id: context.customuser_id ?? null,
935
+ account_id: context.account_id ?? null,
936
+ identity_id: context.identity_id ?? null,
937
+ visitor_id: context.visitor_id ?? null,
938
+ correlation_id: context.correlation_id ?? null
939
+ };
940
+ }
941
+ function buildCliCommandExecutedEvent({
942
+ data,
943
+ context = {},
944
+ cliVersion = package_default.version
945
+ }) {
946
+ const osInfo = zapierSdk.getOsInfo();
947
+ const platformVersions = zapierSdk.getPlatformVersions();
948
+ return {
949
+ ...createCliBaseEvent(context),
950
+ system_name: "zapier-sdk-cli",
951
+ session_id: context.session_id ?? null,
952
+ cli_version: data.cli_version ?? cliVersion,
953
+ cli_arguments: data.cli_arguments ?? null,
954
+ cli_primary_command: data.cli_primary_command,
955
+ os_platform: osInfo.platform,
956
+ os_release: osInfo.release,
957
+ os_architecture: osInfo.architecture,
958
+ platform_versions: platformVersions,
959
+ selected_api: context.selected_api ?? null,
960
+ app_id: context.app_id ?? null,
961
+ app_version_id: context.app_version_id ?? null,
962
+ execution_duration_ms: data.execution_duration_ms ?? null,
963
+ success_flag: data.success_flag,
964
+ exit_code: data.exit_code ?? (data.success_flag ? 0 : 1),
965
+ error_message: data.error_message ?? null,
966
+ command_category: data.command_category ?? null,
967
+ requires_auth: null,
968
+ is_ci_environment: zapierSdk.isCi(),
969
+ ci_platform: zapierSdk.getCiPlatform(),
970
+ package_manager: data.package_manager ?? "pnpm",
971
+ // Default based on project setup
972
+ made_network_requests: data.made_network_requests ?? null,
973
+ files_modified_count: data.files_modified_count ?? null,
974
+ files_created_count: data.files_created_count ?? null,
975
+ files_processed_size_bytes: data.files_processed_size_bytes ?? null,
976
+ cpu_time_ms: data.cpu_time_ms ?? null,
977
+ subprocess_count: data.subprocess_count ?? null
978
+ };
979
+ }
980
+
912
981
  // src/utils/cli-generator.ts
982
+ var CLI_COMMAND_EXECUTED_EVENT_SUBJECT = "platform.sdk.CliCommandExecutedEvent";
983
+ var SENSITIVE_FLAGS = [
984
+ "--credentials",
985
+ "--credentials-client-secret",
986
+ "--credentials-client-id",
987
+ "--credentials-base-url",
988
+ "--user",
989
+ "--header",
990
+ "-H",
991
+ "-u"
992
+ ];
993
+ function sanitizeCliArguments(args) {
994
+ const sanitized = [];
995
+ let skipNext = false;
996
+ for (const arg of args) {
997
+ if (skipNext) {
998
+ skipNext = false;
999
+ sanitized.push("[REDACTED]");
1000
+ continue;
1001
+ }
1002
+ if (SENSITIVE_FLAGS.some((flag) => arg.startsWith(flag + "="))) {
1003
+ sanitized.push(arg.split("=")[0] + "=[REDACTED]");
1004
+ } else if (SENSITIVE_FLAGS.includes(arg)) {
1005
+ sanitized.push(arg);
1006
+ skipNext = true;
1007
+ } else {
1008
+ sanitized.push(arg);
1009
+ }
1010
+ }
1011
+ return sanitized;
1012
+ }
913
1013
  var CONFIRM_MESSAGES = {
914
1014
  "create-secret": {
915
1015
  messageBefore: "You are about to create a sensitive secret that will be displayed as plain text.\nOnce created, you cannot retrieve it again.",
@@ -1164,6 +1264,10 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
1164
1264
  const parameters = usesInputParameters ? analyzeInputParameters(functionInfo.inputParameters, functionInfo) : analyzeZodSchema(schema, functionInfo);
1165
1265
  const description = functionInfo.description || schema?.description || `${cliCommandName} command`;
1166
1266
  const handler = async (...args) => {
1267
+ const startTime = Date.now();
1268
+ let success = true;
1269
+ let errorMessage = null;
1270
+ let resolvedParams = {};
1167
1271
  try {
1168
1272
  const commandObj = args[args.length - 1];
1169
1273
  const options = commandObj.opts();
@@ -1178,7 +1282,6 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
1178
1282
  args.slice(0, -1),
1179
1283
  options
1180
1284
  );
1181
- let resolvedParams;
1182
1285
  if (schema && !usesInputParameters) {
1183
1286
  const resolver = new SchemaParameterResolver();
1184
1287
  resolvedParams = await resolver.resolveParameters(
@@ -1268,6 +1371,8 @@ ${confirmMessageAfter}`));
1268
1371
  }
1269
1372
  }
1270
1373
  } catch (error) {
1374
+ success = false;
1375
+ errorMessage = error instanceof Error ? error.message : String(error);
1271
1376
  if (error instanceof Error && error.message.includes('"code"')) {
1272
1377
  try {
1273
1378
  const validationErrors = JSON.parse(error.message);
@@ -1302,9 +1407,29 @@ ${confirmMessageAfter}`));
1302
1407
  console.error(chalk6__default.default.red("\u274C Error:"), formattedMessage);
1303
1408
  throw new ZapierCliExitError(formattedMessage, 1);
1304
1409
  } else {
1305
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
1306
- console.error(chalk6__default.default.red("\u274C Error:"), errorMessage);
1307
- throw new ZapierCliExitError(errorMessage, 1);
1410
+ const msg = error instanceof Error ? error.message : "Unknown error";
1411
+ console.error(chalk6__default.default.red("\u274C Error:"), msg);
1412
+ throw new ZapierCliExitError(msg, 1);
1413
+ }
1414
+ } finally {
1415
+ try {
1416
+ const event = buildCliCommandExecutedEvent({
1417
+ data: {
1418
+ cli_primary_command: cliCommandName,
1419
+ success_flag: success,
1420
+ execution_duration_ms: Date.now() - startTime,
1421
+ exit_code: success ? 0 : 1,
1422
+ error_message: errorMessage,
1423
+ command_category: functionInfo.categories?.[0] ?? null,
1424
+ requires_auth: null,
1425
+ cli_arguments: sanitizeCliArguments(process.argv.slice(2))
1426
+ },
1427
+ context: {
1428
+ selected_api: resolvedParams.appKey ?? null
1429
+ }
1430
+ });
1431
+ sdk2.getContext().eventEmission.emit(CLI_COMMAND_EXECUTED_EVENT_SUBJECT, event);
1432
+ } catch {
1308
1433
  }
1309
1434
  }
1310
1435
  };
@@ -1863,65 +1988,7 @@ var LoginSchema = zod.z.object({
1863
1988
  timeout: zod.z.string().optional().describe("Login timeout in seconds (default: 300)")
1864
1989
  }).describe("Log in to Zapier to access your account");
1865
1990
 
1866
- // package.json
1867
- var package_default = {
1868
- version: "0.34.1"};
1869
-
1870
- // src/telemetry/builders.ts
1871
- function createCliBaseEvent(context = {}) {
1872
- return {
1873
- event_id: zapierSdk.generateEventId(),
1874
- timestamp_ms: zapierSdk.getCurrentTimestamp(),
1875
- release_id: zapierSdk.getReleaseId(),
1876
- customuser_id: context.customuser_id ?? null,
1877
- account_id: context.account_id ?? null,
1878
- identity_id: context.identity_id ?? null,
1879
- visitor_id: context.visitor_id ?? null,
1880
- correlation_id: context.correlation_id ?? null
1881
- };
1882
- }
1883
- function buildCliCommandExecutedEvent({
1884
- data,
1885
- context = {},
1886
- cliVersion = package_default.version
1887
- }) {
1888
- const osInfo = zapierSdk.getOsInfo();
1889
- const platformVersions = zapierSdk.getPlatformVersions();
1890
- return {
1891
- ...createCliBaseEvent(context),
1892
- system_name: "zapier-sdk-cli",
1893
- session_id: context.session_id ?? null,
1894
- cli_version: data.cli_version ?? cliVersion,
1895
- cli_arguments: data.cli_arguments ?? null,
1896
- cli_primary_command: data.cli_primary_command,
1897
- os_platform: osInfo.platform,
1898
- os_release: osInfo.release,
1899
- os_architecture: osInfo.architecture,
1900
- platform_versions: platformVersions,
1901
- selected_api: context.selected_api ?? null,
1902
- app_id: context.app_id ?? null,
1903
- app_version_id: context.app_version_id ?? null,
1904
- execution_duration_ms: data.execution_duration_ms ?? null,
1905
- success_flag: data.success_flag,
1906
- exit_code: data.exit_code ?? (data.success_flag ? 0 : 1),
1907
- error_message: data.error_message ?? null,
1908
- command_category: data.command_category ?? null,
1909
- requires_auth: data.requires_auth ?? null,
1910
- is_ci_environment: zapierSdk.isCi(),
1911
- ci_platform: zapierSdk.getCiPlatform(),
1912
- package_manager: data.package_manager ?? "pnpm",
1913
- // Default based on project setup
1914
- made_network_requests: data.made_network_requests ?? null,
1915
- files_modified_count: data.files_modified_count ?? null,
1916
- files_created_count: data.files_created_count ?? null,
1917
- files_processed_size_bytes: data.files_processed_size_bytes ?? null,
1918
- cpu_time_ms: data.cpu_time_ms ?? null,
1919
- subprocess_count: data.subprocess_count ?? null
1920
- };
1921
- }
1922
-
1923
1991
  // src/plugins/login/index.ts
1924
- var CLI_COMMAND_EXECUTED_EVENT_SUBJECT = "platform.sdk.CliCommandExecutedEvent";
1925
1992
  function toPkceCredentials(credentials2) {
1926
1993
  if (credentials2 && zapierSdk.isCredentialsObject(credentials2) && !("clientSecret" in credentials2)) {
1927
1994
  return {
@@ -1933,63 +2000,25 @@ function toPkceCredentials(credentials2) {
1933
2000
  }
1934
2001
  return void 0;
1935
2002
  }
1936
- var loginPlugin = ({ context }) => {
1937
- const loginWithTelemetry = async (options) => {
1938
- const startTime = Date.now();
1939
- let success = false;
1940
- let errorMessage = null;
1941
- let accountId = null;
1942
- let customUserId = null;
1943
- try {
1944
- const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
1945
- if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
1946
- throw new Error("Timeout must be a positive number");
1947
- }
1948
- const resolvedCredentials = await context.resolveCredentials();
1949
- const pkceCredentials = toPkceCredentials(resolvedCredentials);
1950
- await login_default({
1951
- timeoutMs: timeoutSeconds * 1e3,
1952
- credentials: pkceCredentials
1953
- });
1954
- const user = await cliLogin.getLoggedInUser();
1955
- accountId = user.accountId;
1956
- customUserId = user.customUserId;
1957
- console.log(`\u2705 Successfully logged in as ${user.email}`);
1958
- success = true;
1959
- } catch (error) {
1960
- success = false;
1961
- errorMessage = error instanceof Error ? error.message : "Login failed";
1962
- throw error;
1963
- } finally {
1964
- const event = buildCliCommandExecutedEvent({
1965
- data: {
1966
- cli_primary_command: "login",
1967
- success_flag: success,
1968
- execution_duration_ms: Date.now() - startTime,
1969
- exit_code: success ? 0 : 1,
1970
- error_message: errorMessage,
1971
- command_category: "authentication",
1972
- requires_auth: false,
1973
- cli_arguments: [
1974
- "login",
1975
- options.timeout ? `--timeout=${options.timeout}` : null
1976
- ].filter(Boolean)
1977
- },
1978
- context: {
1979
- session_id: context.session_id,
1980
- selected_api: context.selected_api,
1981
- app_id: context.app_id,
1982
- app_version_id: context.app_version_id,
1983
- customuser_id: customUserId,
1984
- account_id: accountId
1985
- },
1986
- cliVersion: package_default.version
1987
- });
1988
- context.eventEmission.emit(CLI_COMMAND_EXECUTED_EVENT_SUBJECT, event);
2003
+ var loginPlugin = ({
2004
+ context
2005
+ }) => {
2006
+ const loginFn = async (options) => {
2007
+ const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
2008
+ if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
2009
+ throw new Error("Timeout must be a positive number");
1989
2010
  }
2011
+ const resolvedCredentials = await context.resolveCredentials();
2012
+ const pkceCredentials = toPkceCredentials(resolvedCredentials);
2013
+ await login_default({
2014
+ timeoutMs: timeoutSeconds * 1e3,
2015
+ credentials: pkceCredentials
2016
+ });
2017
+ const user = await cliLogin.getLoggedInUser();
2018
+ console.log(`\u2705 Successfully logged in as ${user.email}`);
1990
2019
  };
1991
2020
  return {
1992
- login: loginWithTelemetry,
2021
+ login: loginFn,
1993
2022
  context: {
1994
2023
  meta: {
1995
2024
  login: {
@@ -4143,7 +4172,7 @@ function createZapierCliSdk(options = {}) {
4143
4172
  // package.json with { type: 'json' }
4144
4173
  var package_default2 = {
4145
4174
  name: "@zapier/zapier-sdk-cli",
4146
- version: "0.34.1"};
4175
+ version: "0.34.4"};
4147
4176
  var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
4148
4177
  var CACHE_RESET_INTERVAL_MS = (() => {
4149
4178
  const { ZAPIER_SDK_UPDATE_CHECK_INTERVAL_MS = `${ONE_DAY_MS}` } = process.env;