@zapier/zapier-sdk-cli 0.13.9 → 0.13.11

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 } from 'commander';
3
3
  import { z } from 'zod';
4
- import { createFunction, OutputPropertySchema, DEFAULT_CONFIG_PATH, createZapierSdkWithoutRegistry, registryPlugin, toSnakeCase, ZapierError, formatErrorMessage, getOsInfo, getPlatformVersions, getCiPlatform, isCi, isPositional, getReleaseId, getCurrentTimestamp, generateEventId } from '@zapier/zapier-sdk';
4
+ import { createFunction, OutputPropertySchema, DEFAULT_CONFIG_PATH, createZapierSdkWithoutRegistry, registryPlugin, ZapierValidationError, ZapierUnknownError, toSnakeCase, ZapierError, formatErrorMessage, getOsInfo, getPlatformVersions, getCiPlatform, isCi, isPositional, getReleaseId, getCurrentTimestamp, generateEventId } from '@zapier/zapier-sdk';
5
5
  import inquirer from 'inquirer';
6
6
  import chalk3 from 'chalk';
7
7
  import util from 'util';
@@ -9,13 +9,13 @@ import open from 'open';
9
9
  import crypto from 'crypto';
10
10
  import express from 'express';
11
11
  import pkceChallenge from 'pkce-challenge';
12
- import { getLoggedInUser, logout, ZAPIER_BASE, LOGIN_CLIENT_ID, AUTH_MODE_HEADER, updateLogin, getConfigPath } from '@zapier/zapier-sdk-cli-login';
12
+ import { getLoggedInUser, logout, getAuthTokenUrl, getAuthAuthorizeUrl, ZAPIER_AUTH_CLIENT_ID, AUTH_MODE_HEADER, updateLogin, getConfigPath } from '@zapier/zapier-sdk-cli-login';
13
13
  import ora from 'ora';
14
14
  import { startMcpServerAsProcess } from '@zapier/zapier-sdk-mcp';
15
15
  import { buildSync } from 'esbuild';
16
16
  import * as fs from 'fs';
17
17
  import * as path from 'path';
18
- import { join, resolve } from 'path';
18
+ import { resolve, join } from 'path';
19
19
  import { mkdir, writeFile, access } from 'fs/promises';
20
20
  import * as ts from 'typescript';
21
21
 
@@ -1218,28 +1218,28 @@ var client_default = api;
1218
1218
 
1219
1219
  // src/utils/getCallablePromise.ts
1220
1220
  var getCallablePromise = () => {
1221
- let resolve3 = () => {
1221
+ let resolve4 = () => {
1222
1222
  };
1223
1223
  let reject = () => {
1224
1224
  };
1225
1225
  const promise = new Promise((_resolve, _reject) => {
1226
- resolve3 = _resolve;
1226
+ resolve4 = _resolve;
1227
1227
  reject = _reject;
1228
1228
  });
1229
1229
  return {
1230
1230
  promise,
1231
- resolve: resolve3,
1231
+ resolve: resolve4,
1232
1232
  reject
1233
1233
  };
1234
1234
  };
1235
1235
  var getCallablePromise_default = getCallablePromise;
1236
1236
  var findAvailablePort = () => {
1237
- return new Promise((resolve3, reject) => {
1237
+ return new Promise((resolve4, reject) => {
1238
1238
  let portIndex = 0;
1239
1239
  const tryPort = (port) => {
1240
1240
  const server = express().listen(port, () => {
1241
1241
  server.close();
1242
- resolve3(port);
1242
+ resolve4(port);
1243
1243
  });
1244
1244
  server.on("error", (err) => {
1245
1245
  if (err.code === "EADDRINUSE") {
@@ -1272,7 +1272,15 @@ var generateRandomString = () => {
1272
1272
  (dec) => ("0" + dec.toString(16)).substring(-2)
1273
1273
  ).join("");
1274
1274
  };
1275
- var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
1275
+ var login = async ({
1276
+ timeoutMs = LOGIN_TIMEOUT_MS,
1277
+ baseUrl: baseUrl2,
1278
+ authBaseUrl: authBaseUrl2,
1279
+ authClientId: authClientId2
1280
+ }) => {
1281
+ const authOptions = { baseUrl: baseUrl2, authBaseUrl: authBaseUrl2 };
1282
+ const tokenUrl = getAuthTokenUrl(authOptions);
1283
+ const authorizeUrl = getAuthAuthorizeUrl(authOptions);
1276
1284
  logout();
1277
1285
  const availablePort = await findAvailablePort();
1278
1286
  const redirectUri = `http://localhost:${availablePort}/oauth`;
@@ -1298,9 +1306,9 @@ var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
1298
1306
  process.on("SIGINT", cleanup);
1299
1307
  process.on("SIGTERM", cleanup);
1300
1308
  const { code_verifier: codeVerifier, code_challenge: codeChallenge } = await pkceChallenge();
1301
- const authUrl = `${ZAPIER_BASE}/oauth/authorize/?${new URLSearchParams({
1309
+ const authUrl = `${authorizeUrl}?${new URLSearchParams({
1302
1310
  response_type: "code",
1303
- client_id: LOGIN_CLIENT_ID,
1311
+ client_id: authClientId2 || ZAPIER_AUTH_CLIENT_ID,
1304
1312
  redirect_uri: redirectUri,
1305
1313
  scope: "internal offline_access",
1306
1314
  state: generateRandomString(),
@@ -1329,26 +1337,26 @@ var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
1329
1337
  } finally {
1330
1338
  process.off("SIGINT", cleanup);
1331
1339
  process.off("SIGTERM", cleanup);
1332
- await new Promise((resolve3) => {
1340
+ await new Promise((resolve4) => {
1333
1341
  const timeout = setTimeout(() => {
1334
1342
  log_default.info("Server close timed out, forcing connection shutdown...");
1335
1343
  connections.forEach((conn) => conn.destroy());
1336
- resolve3();
1344
+ resolve4();
1337
1345
  }, 1e3);
1338
1346
  server.close(() => {
1339
1347
  clearTimeout(timeout);
1340
- resolve3();
1348
+ resolve4();
1341
1349
  });
1342
1350
  });
1343
1351
  }
1344
1352
  log_default.info("Exchanging authorization code for tokens...");
1345
1353
  const { data } = await client_default.post(
1346
- `${ZAPIER_BASE}/oauth/token/`,
1354
+ tokenUrl,
1347
1355
  {
1348
1356
  grant_type: "authorization_code",
1349
1357
  code: await promisedCode,
1350
1358
  redirect_uri: redirectUri,
1351
- client_id: LOGIN_CLIENT_ID,
1359
+ client_id: authClientId2 || ZAPIER_AUTH_CLIENT_ID,
1352
1360
  code_verifier: codeVerifier
1353
1361
  },
1354
1362
  {
@@ -1369,7 +1377,7 @@ var LoginSchema = z.object({
1369
1377
 
1370
1378
  // package.json
1371
1379
  var package_default = {
1372
- version: "0.13.9"};
1380
+ version: "0.13.11"};
1373
1381
 
1374
1382
  // src/telemetry/builders.ts
1375
1383
  function createCliBaseEvent(context = {}) {
@@ -1427,23 +1435,35 @@ function buildCliCommandExecutedEvent({
1427
1435
 
1428
1436
  // src/plugins/login/index.ts
1429
1437
  var CLI_COMMAND_EXECUTED_EVENT_SUBJECT = "platform.sdk.CliCommandExecutedEvent";
1430
- var loginWithSdk = createFunction(async function loginWithSdk2(options) {
1431
- const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
1432
- if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
1433
- throw new Error("Timeout must be a positive number");
1434
- }
1435
- await login_default(timeoutSeconds * 1e3);
1436
- const user = await getLoggedInUser();
1437
- console.log(`\u2705 Successfully logged in as ${user.email}`);
1438
- setTimeout(() => process.exit(0), 100);
1439
- }, LoginSchema);
1438
+ var loginWithSdk = createFunction(
1439
+ async (options) => {
1440
+ const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
1441
+ if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
1442
+ throw new Error("Timeout must be a positive number");
1443
+ }
1444
+ await login_default({
1445
+ timeoutMs: timeoutSeconds * 1e3,
1446
+ baseUrl: options.baseUrl,
1447
+ authBaseUrl: options.authBaseUrl,
1448
+ authClientId: options.authClientId
1449
+ });
1450
+ const user = await getLoggedInUser();
1451
+ console.log(`\u2705 Successfully logged in as ${user.email}`);
1452
+ setTimeout(() => process.exit(0), 100);
1453
+ }
1454
+ );
1440
1455
  var loginPlugin = ({ context }) => {
1441
1456
  const loginWithTelemetry = async (options) => {
1442
1457
  const startTime = Date.now();
1443
1458
  let success = false;
1444
1459
  let errorMessage = null;
1445
1460
  try {
1446
- await loginWithSdk(options);
1461
+ await loginWithSdk({
1462
+ ...options,
1463
+ baseUrl: context.options?.baseUrl,
1464
+ authBaseUrl: context.options?.authBaseUrl,
1465
+ authClientId: context.options?.authClientId
1466
+ });
1447
1467
  success = true;
1448
1468
  } catch (error) {
1449
1469
  success = false;
@@ -1760,14 +1780,6 @@ var addPlugin = ({ sdk: sdk2 }) => {
1760
1780
  if (successfulApps.length > 0) {
1761
1781
  console.log(`\u2705 Added ${successfulApps.length} app(s) to manifest`);
1762
1782
  }
1763
- const allErrors = [...manifestResult.errors, ...typesResult.errors];
1764
- if (allErrors.length > 0) {
1765
- console.warn(`
1766
- \u26A0\uFE0F ${allErrors.length} error(s) occurred:`);
1767
- allErrors.forEach(({ appKey, error }) => {
1768
- console.warn(` - ${appKey}: ${error}`);
1769
- });
1770
- }
1771
1783
  }, AddSchema);
1772
1784
  return {
1773
1785
  add,
@@ -2387,17 +2399,12 @@ var generateAppTypesPlugin = ({ sdk: sdk2 }) => {
2387
2399
  appKeys,
2388
2400
  authenticationIds,
2389
2401
  skipWrite = false,
2390
- typesOutputDirectory,
2402
+ typesOutputDirectory = await detectTypesOutputDirectory(),
2391
2403
  onProgress
2392
2404
  } = options;
2393
- if (!skipWrite && !typesOutputDirectory) {
2394
- throw new Error(
2395
- "typesOutputDirectory is required when skipWrite is false"
2396
- );
2397
- }
2405
+ const resolvedTypesOutput = resolve(typesOutputDirectory);
2398
2406
  const result = {
2399
- typeDefinitions: {},
2400
- errors: []
2407
+ typeDefinitions: {}
2401
2408
  };
2402
2409
  onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
2403
2410
  const appsIterator = sdk2.listApps({ appKeys }).items();
@@ -2425,8 +2432,8 @@ var generateAppTypesPlugin = ({ sdk: sdk2 }) => {
2425
2432
  count: authentications.length
2426
2433
  });
2427
2434
  }
2428
- if (!skipWrite && typesOutputDirectory) {
2429
- await mkdir(typesOutputDirectory, { recursive: true });
2435
+ if (!skipWrite && resolvedTypesOutput) {
2436
+ await mkdir(resolvedTypesOutput, { recursive: true });
2430
2437
  }
2431
2438
  if (!skipWrite) {
2432
2439
  result.writtenFiles = {};
@@ -2439,17 +2446,18 @@ var generateAppTypesPlugin = ({ sdk: sdk2 }) => {
2439
2446
  });
2440
2447
  try {
2441
2448
  if (!app.version) {
2442
- const error = `Invalid implementation ID format: ${app.implementation_id}. Expected format: <implementationName>@<version>`;
2443
- result.errors.push({
2444
- appKey: app.key,
2445
- error
2446
- });
2449
+ const errorMessage = `Invalid implementation ID format: ${app.implementation_id}. Expected format: <implementationName>@<version>`;
2447
2450
  onProgress?.({
2448
2451
  type: "app_processing_error",
2449
2452
  appKey: app.key,
2450
- error
2453
+ error: errorMessage
2454
+ });
2455
+ throw new ZapierValidationError(errorMessage, {
2456
+ details: {
2457
+ appKey: app.key,
2458
+ implementationId: app.implementation_id
2459
+ }
2451
2460
  });
2452
- continue;
2453
2461
  }
2454
2462
  let authenticationId;
2455
2463
  if (authentications.length > 0) {
@@ -2472,56 +2480,47 @@ var generateAppTypesPlugin = ({ sdk: sdk2 }) => {
2472
2480
  }
2473
2481
  }
2474
2482
  const manifestKey = getManifestKey(app);
2475
- try {
2476
- const generator = new AstTypeGenerator();
2477
- const typeDefinitionString = await generator.generateTypes({
2478
- app,
2479
- authenticationId,
2480
- sdk: sdk2
2481
- });
2482
- result.typeDefinitions[manifestKey] = typeDefinitionString;
2483
+ const generator = new AstTypeGenerator();
2484
+ const typeDefinitionString = await generator.generateTypes({
2485
+ app,
2486
+ authenticationId,
2487
+ sdk: sdk2
2488
+ });
2489
+ result.typeDefinitions[manifestKey] = typeDefinitionString;
2490
+ onProgress?.({
2491
+ type: "type_generated",
2492
+ manifestKey,
2493
+ sizeBytes: typeDefinitionString.length
2494
+ });
2495
+ if (!skipWrite && resolvedTypesOutput && result.writtenFiles) {
2496
+ const filePath = join(resolvedTypesOutput, `${manifestKey}.d.ts`);
2497
+ await writeFile(filePath, typeDefinitionString, "utf8");
2498
+ result.writtenFiles[manifestKey] = filePath;
2483
2499
  onProgress?.({
2484
- type: "type_generated",
2500
+ type: "file_written",
2485
2501
  manifestKey,
2486
- sizeBytes: typeDefinitionString.length
2487
- });
2488
- if (!skipWrite && typesOutputDirectory && result.writtenFiles) {
2489
- const filePath = join(typesOutputDirectory, `${manifestKey}.d.ts`);
2490
- await writeFile(filePath, typeDefinitionString, "utf8");
2491
- result.writtenFiles[manifestKey] = filePath;
2492
- onProgress?.({
2493
- type: "file_written",
2494
- manifestKey,
2495
- filePath
2496
- });
2497
- }
2498
- onProgress?.({
2499
- type: "app_processing_complete",
2500
- appKey: app.key
2501
- });
2502
- } catch (error) {
2503
- const errorMessage = `Failed to generate types: ${error}`;
2504
- result.errors.push({
2505
- appKey: app.key,
2506
- error: errorMessage
2507
- });
2508
- onProgress?.({
2509
- type: "app_processing_error",
2510
- appKey: app.key,
2511
- error: errorMessage
2502
+ filePath
2512
2503
  });
2513
2504
  }
2514
- } catch (error) {
2515
- const errorMessage = `Failed to process app: ${error}`;
2516
- result.errors.push({
2517
- appKey: app.key,
2518
- error: errorMessage
2505
+ onProgress?.({
2506
+ type: "app_processing_complete",
2507
+ appKey: app.key
2519
2508
  });
2509
+ } catch (error) {
2510
+ const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
2520
2511
  onProgress?.({
2521
2512
  type: "app_processing_error",
2522
2513
  appKey: app.key,
2523
2514
  error: errorMessage
2524
2515
  });
2516
+ if (error instanceof ZapierValidationError) {
2517
+ throw error;
2518
+ } else {
2519
+ throw new ZapierUnknownError(errorMessage, {
2520
+ cause: error
2521
+ // Works for both Error and non-Error
2522
+ });
2523
+ }
2525
2524
  }
2526
2525
  }
2527
2526
  return result;
@@ -2556,9 +2555,6 @@ var BuildManifestSchema = z.object({
2556
2555
  var buildManifestPlugin = ({ sdk: sdk2, context }) => {
2557
2556
  const buildManifest = createFunction(async function buildManifest2(options) {
2558
2557
  const { appKeys, skipWrite = false, configPath, onProgress } = options;
2559
- const result = {
2560
- errors: []
2561
- };
2562
2558
  onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
2563
2559
  const appsIterator = sdk2.listApps({ appKeys }).items();
2564
2560
  const apps = [];
@@ -2568,7 +2564,7 @@ var buildManifestPlugin = ({ sdk: sdk2, context }) => {
2568
2564
  }
2569
2565
  onProgress?.({ type: "apps_lookup_complete", count: apps.length });
2570
2566
  if (apps.length === 0) {
2571
- return result;
2567
+ return {};
2572
2568
  }
2573
2569
  let updatedManifest;
2574
2570
  for (const app of apps) {
@@ -2601,20 +2597,23 @@ var buildManifestPlugin = ({ sdk: sdk2, context }) => {
2601
2597
  });
2602
2598
  onProgress?.({ type: "app_processing_complete", appKey: app.key });
2603
2599
  } catch (error) {
2604
- const errorMessage = `Failed to process app: ${error}`;
2605
- result.errors.push({
2606
- appKey: app.key,
2607
- error: errorMessage
2608
- });
2600
+ const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
2609
2601
  onProgress?.({
2610
2602
  type: "app_processing_error",
2611
2603
  appKey: app.key,
2612
2604
  error: errorMessage
2613
2605
  });
2606
+ if (error instanceof ZapierValidationError) {
2607
+ throw error;
2608
+ } else {
2609
+ throw new ZapierUnknownError(errorMessage, {
2610
+ cause: error
2611
+ // Works for both Error and non-Error
2612
+ });
2613
+ }
2614
2614
  }
2615
2615
  }
2616
- result.manifest = updatedManifest;
2617
- return result;
2616
+ return { manifest: updatedManifest };
2618
2617
  }, BuildManifestSchema);
2619
2618
  return {
2620
2619
  buildManifest,
@@ -2638,14 +2637,32 @@ function createZapierCliSdk(options = {}) {
2638
2637
 
2639
2638
  // package.json with { type: 'json' }
2640
2639
  var package_default2 = {
2641
- version: "0.13.9"};
2640
+ version: "0.13.11"};
2642
2641
 
2643
2642
  // src/cli.ts
2644
2643
  var program = new Command();
2645
- program.name("zapier-sdk").description("CLI for Zapier SDK").version(package_default2.version, "-v, --version", "display version number").option("--debug", "Enable debug logging");
2644
+ program.name("zapier-sdk").description("CLI for Zapier SDK").version(package_default2.version, "-v, --version", "display version number").option("--debug", "Enable debug logging").option("--base-url <url>", "Base URL for Zapier API endpoints").option(
2645
+ "--auth-base-url <url>",
2646
+ "Base URL for Zapier authentication endpoints"
2647
+ ).option("--auth-client-id <id>", "OAuth client ID for Zapier authentication").option(
2648
+ "--tracking-base-url <url>",
2649
+ "Base URL for Zapier tracking endpoints"
2650
+ );
2646
2651
  var isDebugMode = process.env.DEBUG === "true" || process.argv.includes("--debug");
2652
+ var baseUrlIndex = process.argv.indexOf("--base-url");
2653
+ var authBaseUrlIndex = process.argv.indexOf("--auth-base-url");
2654
+ var authClientIdIndex = process.argv.indexOf("--auth-client-id");
2655
+ var trackingBaseUrlIndex = process.argv.indexOf("--tracking-base-url");
2656
+ var baseUrl = baseUrlIndex !== -1 ? process.argv[baseUrlIndex + 1] : void 0;
2657
+ var authBaseUrl = authBaseUrlIndex !== -1 ? process.argv[authBaseUrlIndex + 1] : void 0;
2658
+ var authClientId = authClientIdIndex !== -1 ? process.argv[authClientIdIndex + 1] : void 0;
2659
+ var trackingBaseUrl = trackingBaseUrlIndex !== -1 ? process.argv[trackingBaseUrlIndex + 1] : void 0;
2647
2660
  var sdk = createZapierCliSdk({
2648
- debug: isDebugMode
2661
+ debug: isDebugMode,
2662
+ baseUrl,
2663
+ authBaseUrl,
2664
+ authClientId,
2665
+ trackingBaseUrl
2649
2666
  });
2650
2667
  generateCliCommands(program, sdk);
2651
2668
  program.parse();