@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/dist/cli.mjs CHANGED
@@ -1,7 +1,7 @@
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, injectCliLogin, 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, isPositional, getOsInfo, getPlatformVersions, getCiPlatform, isCi, getReleaseId, getCurrentTimestamp, generateEventId } from '@zapier/zapier-sdk';
5
5
  import inquirer from 'inquirer';
6
6
  import chalk6 from 'chalk';
7
7
  import util from 'util';
@@ -280,44 +280,57 @@ var SchemaParameterResolver = class {
280
280
  };
281
281
  }
282
282
  async resolveParameter(param, context, functionName) {
283
- const resolver = this.getResolver(param.name, context.sdk, functionName);
283
+ const resolver = this.getResolver(
284
+ param.name,
285
+ context.sdk,
286
+ functionName
287
+ );
284
288
  if (!resolver) {
285
289
  throw new Error(`No resolver found for parameter: ${param.name}`);
286
290
  }
287
291
  console.log(chalk6.blue(`
288
292
  \u{1F50D} Resolving ${param.name}...`));
289
- const typedResolver = resolver;
290
- if (typedResolver.type === "static") {
293
+ if (resolver.type === "static") {
294
+ const staticResolver = resolver;
291
295
  const promptConfig = {
292
- type: typedResolver.inputType === "password" ? "password" : "input",
296
+ type: staticResolver.inputType === "password" ? "password" : "input",
293
297
  name: param.name,
294
298
  message: `Enter ${param.name}:`,
295
- ...typedResolver.placeholder && {
296
- default: typedResolver.placeholder
299
+ ...staticResolver.placeholder && {
300
+ default: staticResolver.placeholder
297
301
  }
298
302
  };
299
303
  const answers = await inquirer.prompt([promptConfig]);
300
304
  return answers[param.name];
301
- } else if (typedResolver.type === "dynamic") {
302
- try {
303
- if (param.isRequired && param.name !== "connectionId") {
304
- console.log(chalk6.gray(`Fetching options for ${param.name}...`));
305
+ } else if (resolver.type === "dynamic") {
306
+ const dynamicResolver = resolver;
307
+ if (dynamicResolver.tryResolveWithoutPrompt) {
308
+ try {
309
+ const preResolvedValue = await dynamicResolver.tryResolveWithoutPrompt(
310
+ context.sdk,
311
+ context.resolvedParams
312
+ );
313
+ if (preResolvedValue != null) {
314
+ return preResolvedValue.resolvedValue;
315
+ }
316
+ } catch {
305
317
  }
306
- const items = await typedResolver.fetch(
307
- context.sdk,
308
- context.resolvedParams
309
- );
310
- const safeItems = items || [];
311
- const promptConfig = typedResolver.prompt(
312
- safeItems,
313
- context.resolvedParams
314
- );
315
- const answers = await inquirer.prompt([promptConfig]);
316
- return answers[param.name];
317
- } catch (error) {
318
- throw error;
319
318
  }
320
- } else if (typedResolver.type === "fields") {
319
+ if (param.isRequired && param.name !== "connectionId") {
320
+ console.log(chalk6.gray(`Fetching options for ${param.name}...`));
321
+ }
322
+ const items = await dynamicResolver.fetch(
323
+ context.sdk,
324
+ context.resolvedParams
325
+ );
326
+ const safeItems = items || [];
327
+ const promptConfig = dynamicResolver.prompt(
328
+ safeItems,
329
+ context.resolvedParams
330
+ );
331
+ const answers = await inquirer.prompt([promptConfig]);
332
+ return answers[param.name];
333
+ } else if (resolver.type === "fields") {
321
334
  return await this.resolveFieldsRecursively(
322
335
  resolver,
323
336
  context,
@@ -327,7 +340,6 @@ var SchemaParameterResolver = class {
327
340
  throw new Error(`Unknown resolver type for ${param.name}`);
328
341
  }
329
342
  async resolveFieldsRecursively(resolver, context, param) {
330
- const typedResolver = resolver;
331
343
  const inputs = {};
332
344
  let processedFieldKeys = /* @__PURE__ */ new Set();
333
345
  let iteration = 0;
@@ -346,7 +358,7 @@ var SchemaParameterResolver = class {
346
358
  `Fetching input fields for ${param.name}${iteration > 1 ? ` (iteration ${iteration})` : ""}...`
347
359
  )
348
360
  );
349
- const rootFieldItems = await typedResolver.fetch(
361
+ const rootFieldItems = await resolver.fetch(
350
362
  updatedContext.sdk,
351
363
  updatedContext.resolvedParams
352
364
  );
@@ -872,7 +884,95 @@ var SHARED_COMMAND_CLI_OPTIONS = [
872
884
  }
873
885
  ];
874
886
 
887
+ // package.json
888
+ var package_default = {
889
+ version: "0.34.4"};
890
+
891
+ // src/telemetry/builders.ts
892
+ function createCliBaseEvent(context = {}) {
893
+ return {
894
+ event_id: generateEventId(),
895
+ timestamp_ms: getCurrentTimestamp(),
896
+ release_id: getReleaseId(),
897
+ customuser_id: context.customuser_id ?? null,
898
+ account_id: context.account_id ?? null,
899
+ identity_id: context.identity_id ?? null,
900
+ visitor_id: context.visitor_id ?? null,
901
+ correlation_id: context.correlation_id ?? null
902
+ };
903
+ }
904
+ function buildCliCommandExecutedEvent({
905
+ data,
906
+ context = {},
907
+ cliVersion = package_default.version
908
+ }) {
909
+ const osInfo = getOsInfo();
910
+ const platformVersions = getPlatformVersions();
911
+ return {
912
+ ...createCliBaseEvent(context),
913
+ system_name: "zapier-sdk-cli",
914
+ session_id: context.session_id ?? null,
915
+ cli_version: data.cli_version ?? cliVersion,
916
+ cli_arguments: data.cli_arguments ?? null,
917
+ cli_primary_command: data.cli_primary_command,
918
+ os_platform: osInfo.platform,
919
+ os_release: osInfo.release,
920
+ os_architecture: osInfo.architecture,
921
+ platform_versions: platformVersions,
922
+ selected_api: context.selected_api ?? null,
923
+ app_id: context.app_id ?? null,
924
+ app_version_id: context.app_version_id ?? null,
925
+ execution_duration_ms: data.execution_duration_ms ?? null,
926
+ success_flag: data.success_flag,
927
+ exit_code: data.exit_code ?? (data.success_flag ? 0 : 1),
928
+ error_message: data.error_message ?? null,
929
+ command_category: data.command_category ?? null,
930
+ requires_auth: null,
931
+ is_ci_environment: isCi(),
932
+ ci_platform: getCiPlatform(),
933
+ package_manager: data.package_manager ?? "pnpm",
934
+ // Default based on project setup
935
+ made_network_requests: data.made_network_requests ?? null,
936
+ files_modified_count: data.files_modified_count ?? null,
937
+ files_created_count: data.files_created_count ?? null,
938
+ files_processed_size_bytes: data.files_processed_size_bytes ?? null,
939
+ cpu_time_ms: data.cpu_time_ms ?? null,
940
+ subprocess_count: data.subprocess_count ?? null
941
+ };
942
+ }
943
+
875
944
  // src/utils/cli-generator.ts
945
+ var CLI_COMMAND_EXECUTED_EVENT_SUBJECT = "platform.sdk.CliCommandExecutedEvent";
946
+ var SENSITIVE_FLAGS = [
947
+ "--credentials",
948
+ "--credentials-client-secret",
949
+ "--credentials-client-id",
950
+ "--credentials-base-url",
951
+ "--user",
952
+ "--header",
953
+ "-H",
954
+ "-u"
955
+ ];
956
+ function sanitizeCliArguments(args) {
957
+ const sanitized = [];
958
+ let skipNext = false;
959
+ for (const arg of args) {
960
+ if (skipNext) {
961
+ skipNext = false;
962
+ sanitized.push("[REDACTED]");
963
+ continue;
964
+ }
965
+ if (SENSITIVE_FLAGS.some((flag) => arg.startsWith(flag + "="))) {
966
+ sanitized.push(arg.split("=")[0] + "=[REDACTED]");
967
+ } else if (SENSITIVE_FLAGS.includes(arg)) {
968
+ sanitized.push(arg);
969
+ skipNext = true;
970
+ } else {
971
+ sanitized.push(arg);
972
+ }
973
+ }
974
+ return sanitized;
975
+ }
876
976
  var CONFIRM_MESSAGES = {
877
977
  "create-secret": {
878
978
  messageBefore: "You are about to create a sensitive secret that will be displayed as plain text.\nOnce created, you cannot retrieve it again.",
@@ -1127,6 +1227,10 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
1127
1227
  const parameters = usesInputParameters ? analyzeInputParameters(functionInfo.inputParameters, functionInfo) : analyzeZodSchema(schema, functionInfo);
1128
1228
  const description = functionInfo.description || schema?.description || `${cliCommandName} command`;
1129
1229
  const handler = async (...args) => {
1230
+ const startTime = Date.now();
1231
+ let success = true;
1232
+ let errorMessage = null;
1233
+ let resolvedParams = {};
1130
1234
  try {
1131
1235
  const commandObj = args[args.length - 1];
1132
1236
  const options = commandObj.opts();
@@ -1141,7 +1245,6 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
1141
1245
  args.slice(0, -1),
1142
1246
  options
1143
1247
  );
1144
- let resolvedParams;
1145
1248
  if (schema && !usesInputParameters) {
1146
1249
  const resolver = new SchemaParameterResolver();
1147
1250
  resolvedParams = await resolver.resolveParameters(
@@ -1231,6 +1334,8 @@ ${confirmMessageAfter}`));
1231
1334
  }
1232
1335
  }
1233
1336
  } catch (error) {
1337
+ success = false;
1338
+ errorMessage = error instanceof Error ? error.message : String(error);
1234
1339
  if (error instanceof Error && error.message.includes('"code"')) {
1235
1340
  try {
1236
1341
  const validationErrors = JSON.parse(error.message);
@@ -1265,9 +1370,29 @@ ${confirmMessageAfter}`));
1265
1370
  console.error(chalk6.red("\u274C Error:"), formattedMessage);
1266
1371
  throw new ZapierCliExitError(formattedMessage, 1);
1267
1372
  } else {
1268
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
1269
- console.error(chalk6.red("\u274C Error:"), errorMessage);
1270
- throw new ZapierCliExitError(errorMessage, 1);
1373
+ const msg = error instanceof Error ? error.message : "Unknown error";
1374
+ console.error(chalk6.red("\u274C Error:"), msg);
1375
+ throw new ZapierCliExitError(msg, 1);
1376
+ }
1377
+ } finally {
1378
+ try {
1379
+ const event = buildCliCommandExecutedEvent({
1380
+ data: {
1381
+ cli_primary_command: cliCommandName,
1382
+ success_flag: success,
1383
+ execution_duration_ms: Date.now() - startTime,
1384
+ exit_code: success ? 0 : 1,
1385
+ error_message: errorMessage,
1386
+ command_category: functionInfo.categories?.[0] ?? null,
1387
+ requires_auth: null,
1388
+ cli_arguments: sanitizeCliArguments(process.argv.slice(2))
1389
+ },
1390
+ context: {
1391
+ selected_api: resolvedParams.appKey ?? null
1392
+ }
1393
+ });
1394
+ sdk2.getContext().eventEmission.emit(CLI_COMMAND_EXECUTED_EVENT_SUBJECT, event);
1395
+ } catch {
1271
1396
  }
1272
1397
  }
1273
1398
  };
@@ -1826,65 +1951,7 @@ var LoginSchema = z.object({
1826
1951
  timeout: z.string().optional().describe("Login timeout in seconds (default: 300)")
1827
1952
  }).describe("Log in to Zapier to access your account");
1828
1953
 
1829
- // package.json
1830
- var package_default = {
1831
- version: "0.34.1"};
1832
-
1833
- // src/telemetry/builders.ts
1834
- function createCliBaseEvent(context = {}) {
1835
- return {
1836
- event_id: generateEventId(),
1837
- timestamp_ms: getCurrentTimestamp(),
1838
- release_id: getReleaseId(),
1839
- customuser_id: context.customuser_id ?? null,
1840
- account_id: context.account_id ?? null,
1841
- identity_id: context.identity_id ?? null,
1842
- visitor_id: context.visitor_id ?? null,
1843
- correlation_id: context.correlation_id ?? null
1844
- };
1845
- }
1846
- function buildCliCommandExecutedEvent({
1847
- data,
1848
- context = {},
1849
- cliVersion = package_default.version
1850
- }) {
1851
- const osInfo = getOsInfo();
1852
- const platformVersions = getPlatformVersions();
1853
- return {
1854
- ...createCliBaseEvent(context),
1855
- system_name: "zapier-sdk-cli",
1856
- session_id: context.session_id ?? null,
1857
- cli_version: data.cli_version ?? cliVersion,
1858
- cli_arguments: data.cli_arguments ?? null,
1859
- cli_primary_command: data.cli_primary_command,
1860
- os_platform: osInfo.platform,
1861
- os_release: osInfo.release,
1862
- os_architecture: osInfo.architecture,
1863
- platform_versions: platformVersions,
1864
- selected_api: context.selected_api ?? null,
1865
- app_id: context.app_id ?? null,
1866
- app_version_id: context.app_version_id ?? null,
1867
- execution_duration_ms: data.execution_duration_ms ?? null,
1868
- success_flag: data.success_flag,
1869
- exit_code: data.exit_code ?? (data.success_flag ? 0 : 1),
1870
- error_message: data.error_message ?? null,
1871
- command_category: data.command_category ?? null,
1872
- requires_auth: data.requires_auth ?? null,
1873
- is_ci_environment: isCi(),
1874
- ci_platform: getCiPlatform(),
1875
- package_manager: data.package_manager ?? "pnpm",
1876
- // Default based on project setup
1877
- made_network_requests: data.made_network_requests ?? null,
1878
- files_modified_count: data.files_modified_count ?? null,
1879
- files_created_count: data.files_created_count ?? null,
1880
- files_processed_size_bytes: data.files_processed_size_bytes ?? null,
1881
- cpu_time_ms: data.cpu_time_ms ?? null,
1882
- subprocess_count: data.subprocess_count ?? null
1883
- };
1884
- }
1885
-
1886
1954
  // src/plugins/login/index.ts
1887
- var CLI_COMMAND_EXECUTED_EVENT_SUBJECT = "platform.sdk.CliCommandExecutedEvent";
1888
1955
  function toPkceCredentials(credentials2) {
1889
1956
  if (credentials2 && isCredentialsObject(credentials2) && !("clientSecret" in credentials2)) {
1890
1957
  return {
@@ -1896,63 +1963,25 @@ function toPkceCredentials(credentials2) {
1896
1963
  }
1897
1964
  return void 0;
1898
1965
  }
1899
- var loginPlugin = ({ context }) => {
1900
- const loginWithTelemetry = async (options) => {
1901
- const startTime = Date.now();
1902
- let success = false;
1903
- let errorMessage = null;
1904
- let accountId = null;
1905
- let customUserId = null;
1906
- try {
1907
- const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
1908
- if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
1909
- throw new Error("Timeout must be a positive number");
1910
- }
1911
- const resolvedCredentials = await context.resolveCredentials();
1912
- const pkceCredentials = toPkceCredentials(resolvedCredentials);
1913
- await login_default({
1914
- timeoutMs: timeoutSeconds * 1e3,
1915
- credentials: pkceCredentials
1916
- });
1917
- const user = await getLoggedInUser();
1918
- accountId = user.accountId;
1919
- customUserId = user.customUserId;
1920
- console.log(`\u2705 Successfully logged in as ${user.email}`);
1921
- success = true;
1922
- } catch (error) {
1923
- success = false;
1924
- errorMessage = error instanceof Error ? error.message : "Login failed";
1925
- throw error;
1926
- } finally {
1927
- const event = buildCliCommandExecutedEvent({
1928
- data: {
1929
- cli_primary_command: "login",
1930
- success_flag: success,
1931
- execution_duration_ms: Date.now() - startTime,
1932
- exit_code: success ? 0 : 1,
1933
- error_message: errorMessage,
1934
- command_category: "authentication",
1935
- requires_auth: false,
1936
- cli_arguments: [
1937
- "login",
1938
- options.timeout ? `--timeout=${options.timeout}` : null
1939
- ].filter(Boolean)
1940
- },
1941
- context: {
1942
- session_id: context.session_id,
1943
- selected_api: context.selected_api,
1944
- app_id: context.app_id,
1945
- app_version_id: context.app_version_id,
1946
- customuser_id: customUserId,
1947
- account_id: accountId
1948
- },
1949
- cliVersion: package_default.version
1950
- });
1951
- context.eventEmission.emit(CLI_COMMAND_EXECUTED_EVENT_SUBJECT, event);
1966
+ var loginPlugin = ({
1967
+ context
1968
+ }) => {
1969
+ const loginFn = async (options) => {
1970
+ const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
1971
+ if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
1972
+ throw new Error("Timeout must be a positive number");
1952
1973
  }
1974
+ const resolvedCredentials = await context.resolveCredentials();
1975
+ const pkceCredentials = toPkceCredentials(resolvedCredentials);
1976
+ await login_default({
1977
+ timeoutMs: timeoutSeconds * 1e3,
1978
+ credentials: pkceCredentials
1979
+ });
1980
+ const user = await getLoggedInUser();
1981
+ console.log(`\u2705 Successfully logged in as ${user.email}`);
1953
1982
  };
1954
1983
  return {
1955
- login: loginWithTelemetry,
1984
+ login: loginFn,
1956
1985
  context: {
1957
1986
  meta: {
1958
1987
  login: {
@@ -4106,7 +4135,7 @@ function createZapierCliSdk(options = {}) {
4106
4135
  // package.json with { type: 'json' }
4107
4136
  var package_default2 = {
4108
4137
  name: "@zapier/zapier-sdk-cli",
4109
- version: "0.34.1"};
4138
+ version: "0.34.4"};
4110
4139
  var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
4111
4140
  var CACHE_RESET_INTERVAL_MS = (() => {
4112
4141
  const { ZAPIER_SDK_UPDATE_CHECK_INTERVAL_MS = `${ONE_DAY_MS}` } = process.env;
package/dist/index.cjs CHANGED
@@ -342,65 +342,7 @@ var LoginSchema = zod.z.object({
342
342
  timeout: zod.z.string().optional().describe("Login timeout in seconds (default: 300)")
343
343
  }).describe("Log in to Zapier to access your account");
344
344
 
345
- // package.json
346
- var package_default = {
347
- version: "0.34.1"};
348
-
349
- // src/telemetry/builders.ts
350
- function createCliBaseEvent(context = {}) {
351
- return {
352
- event_id: zapierSdk.generateEventId(),
353
- timestamp_ms: zapierSdk.getCurrentTimestamp(),
354
- release_id: zapierSdk.getReleaseId(),
355
- customuser_id: context.customuser_id ?? null,
356
- account_id: context.account_id ?? null,
357
- identity_id: context.identity_id ?? null,
358
- visitor_id: context.visitor_id ?? null,
359
- correlation_id: context.correlation_id ?? null
360
- };
361
- }
362
- function buildCliCommandExecutedEvent({
363
- data,
364
- context = {},
365
- cliVersion = package_default.version
366
- }) {
367
- const osInfo = zapierSdk.getOsInfo();
368
- const platformVersions = zapierSdk.getPlatformVersions();
369
- return {
370
- ...createCliBaseEvent(context),
371
- system_name: "zapier-sdk-cli",
372
- session_id: context.session_id ?? null,
373
- cli_version: data.cli_version ?? cliVersion,
374
- cli_arguments: data.cli_arguments ?? null,
375
- cli_primary_command: data.cli_primary_command,
376
- os_platform: osInfo.platform,
377
- os_release: osInfo.release,
378
- os_architecture: osInfo.architecture,
379
- platform_versions: platformVersions,
380
- selected_api: context.selected_api ?? null,
381
- app_id: context.app_id ?? null,
382
- app_version_id: context.app_version_id ?? null,
383
- execution_duration_ms: data.execution_duration_ms ?? null,
384
- success_flag: data.success_flag,
385
- exit_code: data.exit_code ?? (data.success_flag ? 0 : 1),
386
- error_message: data.error_message ?? null,
387
- command_category: data.command_category ?? null,
388
- requires_auth: data.requires_auth ?? null,
389
- is_ci_environment: zapierSdk.isCi(),
390
- ci_platform: zapierSdk.getCiPlatform(),
391
- package_manager: data.package_manager ?? "pnpm",
392
- // Default based on project setup
393
- made_network_requests: data.made_network_requests ?? null,
394
- files_modified_count: data.files_modified_count ?? null,
395
- files_created_count: data.files_created_count ?? null,
396
- files_processed_size_bytes: data.files_processed_size_bytes ?? null,
397
- cpu_time_ms: data.cpu_time_ms ?? null,
398
- subprocess_count: data.subprocess_count ?? null
399
- };
400
- }
401
-
402
345
  // src/plugins/login/index.ts
403
- var CLI_COMMAND_EXECUTED_EVENT_SUBJECT = "platform.sdk.CliCommandExecutedEvent";
404
346
  function toPkceCredentials(credentials) {
405
347
  if (credentials && zapierSdk.isCredentialsObject(credentials) && !("clientSecret" in credentials)) {
406
348
  return {
@@ -412,63 +354,25 @@ function toPkceCredentials(credentials) {
412
354
  }
413
355
  return void 0;
414
356
  }
415
- var loginPlugin = ({ context }) => {
416
- const loginWithTelemetry = async (options) => {
417
- const startTime = Date.now();
418
- let success = false;
419
- let errorMessage = null;
420
- let accountId = null;
421
- let customUserId = null;
422
- try {
423
- const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
424
- if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
425
- throw new Error("Timeout must be a positive number");
426
- }
427
- const resolvedCredentials = await context.resolveCredentials();
428
- const pkceCredentials = toPkceCredentials(resolvedCredentials);
429
- await login_default({
430
- timeoutMs: timeoutSeconds * 1e3,
431
- credentials: pkceCredentials
432
- });
433
- const user = await cliLogin.getLoggedInUser();
434
- accountId = user.accountId;
435
- customUserId = user.customUserId;
436
- console.log(`\u2705 Successfully logged in as ${user.email}`);
437
- success = true;
438
- } catch (error) {
439
- success = false;
440
- errorMessage = error instanceof Error ? error.message : "Login failed";
441
- throw error;
442
- } finally {
443
- const event = buildCliCommandExecutedEvent({
444
- data: {
445
- cli_primary_command: "login",
446
- success_flag: success,
447
- execution_duration_ms: Date.now() - startTime,
448
- exit_code: success ? 0 : 1,
449
- error_message: errorMessage,
450
- command_category: "authentication",
451
- requires_auth: false,
452
- cli_arguments: [
453
- "login",
454
- options.timeout ? `--timeout=${options.timeout}` : null
455
- ].filter(Boolean)
456
- },
457
- context: {
458
- session_id: context.session_id,
459
- selected_api: context.selected_api,
460
- app_id: context.app_id,
461
- app_version_id: context.app_version_id,
462
- customuser_id: customUserId,
463
- account_id: accountId
464
- },
465
- cliVersion: package_default.version
466
- });
467
- context.eventEmission.emit(CLI_COMMAND_EXECUTED_EVENT_SUBJECT, event);
468
- }
357
+ var loginPlugin = ({
358
+ context
359
+ }) => {
360
+ const loginFn = async (options) => {
361
+ const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
362
+ if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
363
+ throw new Error("Timeout must be a positive number");
364
+ }
365
+ const resolvedCredentials = await context.resolveCredentials();
366
+ const pkceCredentials = toPkceCredentials(resolvedCredentials);
367
+ await login_default({
368
+ timeoutMs: timeoutSeconds * 1e3,
369
+ credentials: pkceCredentials
370
+ });
371
+ const user = await cliLogin.getLoggedInUser();
372
+ console.log(`\u2705 Successfully logged in as ${user.email}`);
469
373
  };
470
374
  return {
471
- login: loginWithTelemetry,
375
+ login: loginFn,
472
376
  context: {
473
377
  meta: {
474
378
  login: {
@@ -2592,6 +2496,63 @@ function createZapierCliSdk(options = {}) {
2592
2496
  }).addPlugin(generateAppTypesPlugin).addPlugin(buildManifestPlugin).addPlugin(bundleCodePlugin).addPlugin(getLoginConfigPathPlugin).addPlugin(addPlugin).addPlugin(feedbackPlugin).addPlugin(curlPlugin).addPlugin(initPlugin).addPlugin(mcpPlugin).addPlugin(loginPlugin).addPlugin(logoutPlugin).addPlugin(cliOverridesPlugin).addPlugin(zapierSdk.registryPlugin);
2593
2497
  }
2594
2498
 
2499
+ // package.json
2500
+ var package_default = {
2501
+ version: "0.34.4"};
2502
+
2503
+ // src/telemetry/builders.ts
2504
+ function createCliBaseEvent(context = {}) {
2505
+ return {
2506
+ event_id: zapierSdk.generateEventId(),
2507
+ timestamp_ms: zapierSdk.getCurrentTimestamp(),
2508
+ release_id: zapierSdk.getReleaseId(),
2509
+ customuser_id: context.customuser_id ?? null,
2510
+ account_id: context.account_id ?? null,
2511
+ identity_id: context.identity_id ?? null,
2512
+ visitor_id: context.visitor_id ?? null,
2513
+ correlation_id: context.correlation_id ?? null
2514
+ };
2515
+ }
2516
+ function buildCliCommandExecutedEvent({
2517
+ data,
2518
+ context = {},
2519
+ cliVersion = package_default.version
2520
+ }) {
2521
+ const osInfo = zapierSdk.getOsInfo();
2522
+ const platformVersions = zapierSdk.getPlatformVersions();
2523
+ return {
2524
+ ...createCliBaseEvent(context),
2525
+ system_name: "zapier-sdk-cli",
2526
+ session_id: context.session_id ?? null,
2527
+ cli_version: data.cli_version ?? cliVersion,
2528
+ cli_arguments: data.cli_arguments ?? null,
2529
+ cli_primary_command: data.cli_primary_command,
2530
+ os_platform: osInfo.platform,
2531
+ os_release: osInfo.release,
2532
+ os_architecture: osInfo.architecture,
2533
+ platform_versions: platformVersions,
2534
+ selected_api: context.selected_api ?? null,
2535
+ app_id: context.app_id ?? null,
2536
+ app_version_id: context.app_version_id ?? null,
2537
+ execution_duration_ms: data.execution_duration_ms ?? null,
2538
+ success_flag: data.success_flag,
2539
+ exit_code: data.exit_code ?? (data.success_flag ? 0 : 1),
2540
+ error_message: data.error_message ?? null,
2541
+ command_category: data.command_category ?? null,
2542
+ requires_auth: data.requires_auth ?? null,
2543
+ is_ci_environment: zapierSdk.isCi(),
2544
+ ci_platform: zapierSdk.getCiPlatform(),
2545
+ package_manager: data.package_manager ?? "pnpm",
2546
+ // Default based on project setup
2547
+ made_network_requests: data.made_network_requests ?? null,
2548
+ files_modified_count: data.files_modified_count ?? null,
2549
+ files_created_count: data.files_created_count ?? null,
2550
+ files_processed_size_bytes: data.files_processed_size_bytes ?? null,
2551
+ cpu_time_ms: data.cpu_time_ms ?? null,
2552
+ subprocess_count: data.subprocess_count ?? null
2553
+ };
2554
+ }
2555
+
2595
2556
  // src/utils/cli-options.ts
2596
2557
  var ReservedCliParameter = /* @__PURE__ */ ((ReservedCliParameter2) => {
2597
2558
  ReservedCliParameter2["Version"] = "version";