@zapier/zapier-sdk-cli 0.34.1 → 0.34.3

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/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.3"};
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";
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, createZapierSdkWithoutRegistry, registryPlugin, getReleaseId, getCurrentTimestamp, generateEventId, ZapierValidationError, ZapierUnknownError, batch, toSnakeCase, ZapierError, isCredentialsObject } from '@zapier/zapier-sdk';
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 = ({ context }) => {
383
- const loginWithTelemetry = async (options) => {
384
- const startTime = Date.now();
385
- let success = false;
386
- let errorMessage = null;
387
- let accountId = null;
388
- let customUserId = null;
389
- try {
390
- const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
391
- if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
392
- throw new Error("Timeout must be a positive number");
393
- }
394
- const resolvedCredentials = await context.resolveCredentials();
395
- const pkceCredentials = toPkceCredentials(resolvedCredentials);
396
- await login_default({
397
- timeoutMs: timeoutSeconds * 1e3,
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: loginWithTelemetry,
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.3"};
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@zapier/zapier-sdk-cli",
3
- "version": "0.34.1",
3
+ "version": "0.34.3",
4
4
  "description": "Command line interface for Zapier SDK",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -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<{}, EventEmissionContext & CliContext, LoginPluginProvides>;
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
- // Wrap the login function to emit telemetry events
23
- const loginWithTelemetry = async (options) => {
24
- const startTime = Date.now();
25
- let success = false;
26
- let errorMessage = null;
27
- let accountId = null;
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: loginWithTelemetry,
36
+ login: loginFn,
86
37
  context: {
87
38
  meta: {
88
39
  login: {
@@ -1,3 +1,4 @@
1
1
  import type { Command } from "commander";
2
2
  import type { ZapierSdk } from "@zapier/zapier-sdk";
3
+ export declare function sanitizeCliArguments(args: string[]): string[];
3
4
  export declare function generateCliCommands(program: Command, sdk: ZapierSdk): void;
@@ -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 errorMessage = error instanceof Error ? error.message : "Unknown error";
435
- console.error(chalk.red("❌ Error:"), errorMessage);
436
- throw new ZapierCliExitError(errorMessage, 1);
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
  };