@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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @zapier/zapier-sdk-cli
2
2
 
3
+ ## 0.13.11
4
+
5
+ ### Patch Changes
6
+
7
+ - 6de89a9: Allow overriding ZAPIER_BASE_URL with env vars, and also add new ZAPIER_TRACKING_BASE_URL, ZAPIER_AUTH_BASE_URL, and ZAPIER_AUTH_CLIENT_ID env vars and parameters.
8
+ - Updated dependencies [6de89a9]
9
+ - @zapier/zapier-sdk-cli-login@0.3.4
10
+ - @zapier/zapier-sdk@0.13.8
11
+ - @zapier/zapier-sdk-mcp@0.3.21
12
+
13
+ ## 0.13.10
14
+
15
+ ### Patch Changes
16
+
17
+ - f56c6a0: Refactor buildManifest and generateAppTypes to throw proper errors, instead of returning an error property
18
+
3
19
  ## 0.13.9
4
20
 
5
21
  ### Patch Changes
package/dist/cli.cjs CHANGED
@@ -1251,28 +1251,28 @@ var client_default = api;
1251
1251
 
1252
1252
  // src/utils/getCallablePromise.ts
1253
1253
  var getCallablePromise = () => {
1254
- let resolve3 = () => {
1254
+ let resolve4 = () => {
1255
1255
  };
1256
1256
  let reject = () => {
1257
1257
  };
1258
1258
  const promise = new Promise((_resolve, _reject) => {
1259
- resolve3 = _resolve;
1259
+ resolve4 = _resolve;
1260
1260
  reject = _reject;
1261
1261
  });
1262
1262
  return {
1263
1263
  promise,
1264
- resolve: resolve3,
1264
+ resolve: resolve4,
1265
1265
  reject
1266
1266
  };
1267
1267
  };
1268
1268
  var getCallablePromise_default = getCallablePromise;
1269
1269
  var findAvailablePort = () => {
1270
- return new Promise((resolve3, reject) => {
1270
+ return new Promise((resolve4, reject) => {
1271
1271
  let portIndex = 0;
1272
1272
  const tryPort = (port) => {
1273
1273
  const server = express__default.default().listen(port, () => {
1274
1274
  server.close();
1275
- resolve3(port);
1275
+ resolve4(port);
1276
1276
  });
1277
1277
  server.on("error", (err) => {
1278
1278
  if (err.code === "EADDRINUSE") {
@@ -1305,7 +1305,15 @@ var generateRandomString = () => {
1305
1305
  (dec) => ("0" + dec.toString(16)).substring(-2)
1306
1306
  ).join("");
1307
1307
  };
1308
- var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
1308
+ var login = async ({
1309
+ timeoutMs = LOGIN_TIMEOUT_MS,
1310
+ baseUrl: baseUrl2,
1311
+ authBaseUrl: authBaseUrl2,
1312
+ authClientId: authClientId2
1313
+ }) => {
1314
+ const authOptions = { baseUrl: baseUrl2, authBaseUrl: authBaseUrl2 };
1315
+ const tokenUrl = zapierSdkCliLogin.getAuthTokenUrl(authOptions);
1316
+ const authorizeUrl = zapierSdkCliLogin.getAuthAuthorizeUrl(authOptions);
1309
1317
  zapierSdkCliLogin.logout();
1310
1318
  const availablePort = await findAvailablePort();
1311
1319
  const redirectUri = `http://localhost:${availablePort}/oauth`;
@@ -1331,9 +1339,9 @@ var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
1331
1339
  process.on("SIGINT", cleanup);
1332
1340
  process.on("SIGTERM", cleanup);
1333
1341
  const { code_verifier: codeVerifier, code_challenge: codeChallenge } = await pkceChallenge__default.default();
1334
- const authUrl = `${zapierSdkCliLogin.ZAPIER_BASE}/oauth/authorize/?${new URLSearchParams({
1342
+ const authUrl = `${authorizeUrl}?${new URLSearchParams({
1335
1343
  response_type: "code",
1336
- client_id: zapierSdkCliLogin.LOGIN_CLIENT_ID,
1344
+ client_id: authClientId2 || zapierSdkCliLogin.ZAPIER_AUTH_CLIENT_ID,
1337
1345
  redirect_uri: redirectUri,
1338
1346
  scope: "internal offline_access",
1339
1347
  state: generateRandomString(),
@@ -1362,26 +1370,26 @@ var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
1362
1370
  } finally {
1363
1371
  process.off("SIGINT", cleanup);
1364
1372
  process.off("SIGTERM", cleanup);
1365
- await new Promise((resolve3) => {
1373
+ await new Promise((resolve4) => {
1366
1374
  const timeout = setTimeout(() => {
1367
1375
  log_default.info("Server close timed out, forcing connection shutdown...");
1368
1376
  connections.forEach((conn) => conn.destroy());
1369
- resolve3();
1377
+ resolve4();
1370
1378
  }, 1e3);
1371
1379
  server.close(() => {
1372
1380
  clearTimeout(timeout);
1373
- resolve3();
1381
+ resolve4();
1374
1382
  });
1375
1383
  });
1376
1384
  }
1377
1385
  log_default.info("Exchanging authorization code for tokens...");
1378
1386
  const { data } = await client_default.post(
1379
- `${zapierSdkCliLogin.ZAPIER_BASE}/oauth/token/`,
1387
+ tokenUrl,
1380
1388
  {
1381
1389
  grant_type: "authorization_code",
1382
1390
  code: await promisedCode,
1383
1391
  redirect_uri: redirectUri,
1384
- client_id: zapierSdkCliLogin.LOGIN_CLIENT_ID,
1392
+ client_id: authClientId2 || zapierSdkCliLogin.ZAPIER_AUTH_CLIENT_ID,
1385
1393
  code_verifier: codeVerifier
1386
1394
  },
1387
1395
  {
@@ -1402,7 +1410,7 @@ var LoginSchema = zod.z.object({
1402
1410
 
1403
1411
  // package.json
1404
1412
  var package_default = {
1405
- version: "0.13.9"};
1413
+ version: "0.13.11"};
1406
1414
 
1407
1415
  // src/telemetry/builders.ts
1408
1416
  function createCliBaseEvent(context = {}) {
@@ -1460,23 +1468,35 @@ function buildCliCommandExecutedEvent({
1460
1468
 
1461
1469
  // src/plugins/login/index.ts
1462
1470
  var CLI_COMMAND_EXECUTED_EVENT_SUBJECT = "platform.sdk.CliCommandExecutedEvent";
1463
- var loginWithSdk = zapierSdk.createFunction(async function loginWithSdk2(options) {
1464
- const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
1465
- if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
1466
- throw new Error("Timeout must be a positive number");
1467
- }
1468
- await login_default(timeoutSeconds * 1e3);
1469
- const user = await zapierSdkCliLogin.getLoggedInUser();
1470
- console.log(`\u2705 Successfully logged in as ${user.email}`);
1471
- setTimeout(() => process.exit(0), 100);
1472
- }, LoginSchema);
1471
+ var loginWithSdk = zapierSdk.createFunction(
1472
+ async (options) => {
1473
+ const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
1474
+ if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
1475
+ throw new Error("Timeout must be a positive number");
1476
+ }
1477
+ await login_default({
1478
+ timeoutMs: timeoutSeconds * 1e3,
1479
+ baseUrl: options.baseUrl,
1480
+ authBaseUrl: options.authBaseUrl,
1481
+ authClientId: options.authClientId
1482
+ });
1483
+ const user = await zapierSdkCliLogin.getLoggedInUser();
1484
+ console.log(`\u2705 Successfully logged in as ${user.email}`);
1485
+ setTimeout(() => process.exit(0), 100);
1486
+ }
1487
+ );
1473
1488
  var loginPlugin = ({ context }) => {
1474
1489
  const loginWithTelemetry = async (options) => {
1475
1490
  const startTime = Date.now();
1476
1491
  let success = false;
1477
1492
  let errorMessage = null;
1478
1493
  try {
1479
- await loginWithSdk(options);
1494
+ await loginWithSdk({
1495
+ ...options,
1496
+ baseUrl: context.options?.baseUrl,
1497
+ authBaseUrl: context.options?.authBaseUrl,
1498
+ authClientId: context.options?.authClientId
1499
+ });
1480
1500
  success = true;
1481
1501
  } catch (error) {
1482
1502
  success = false;
@@ -1793,14 +1813,6 @@ var addPlugin = ({ sdk: sdk2 }) => {
1793
1813
  if (successfulApps.length > 0) {
1794
1814
  console.log(`\u2705 Added ${successfulApps.length} app(s) to manifest`);
1795
1815
  }
1796
- const allErrors = [...manifestResult.errors, ...typesResult.errors];
1797
- if (allErrors.length > 0) {
1798
- console.warn(`
1799
- \u26A0\uFE0F ${allErrors.length} error(s) occurred:`);
1800
- allErrors.forEach(({ appKey, error }) => {
1801
- console.warn(` - ${appKey}: ${error}`);
1802
- });
1803
- }
1804
1816
  }, AddSchema);
1805
1817
  return {
1806
1818
  add,
@@ -2420,17 +2432,12 @@ var generateAppTypesPlugin = ({ sdk: sdk2 }) => {
2420
2432
  appKeys,
2421
2433
  authenticationIds,
2422
2434
  skipWrite = false,
2423
- typesOutputDirectory,
2435
+ typesOutputDirectory = await detectTypesOutputDirectory(),
2424
2436
  onProgress
2425
2437
  } = options;
2426
- if (!skipWrite && !typesOutputDirectory) {
2427
- throw new Error(
2428
- "typesOutputDirectory is required when skipWrite is false"
2429
- );
2430
- }
2438
+ const resolvedTypesOutput = path.resolve(typesOutputDirectory);
2431
2439
  const result = {
2432
- typeDefinitions: {},
2433
- errors: []
2440
+ typeDefinitions: {}
2434
2441
  };
2435
2442
  onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
2436
2443
  const appsIterator = sdk2.listApps({ appKeys }).items();
@@ -2458,8 +2465,8 @@ var generateAppTypesPlugin = ({ sdk: sdk2 }) => {
2458
2465
  count: authentications.length
2459
2466
  });
2460
2467
  }
2461
- if (!skipWrite && typesOutputDirectory) {
2462
- await promises.mkdir(typesOutputDirectory, { recursive: true });
2468
+ if (!skipWrite && resolvedTypesOutput) {
2469
+ await promises.mkdir(resolvedTypesOutput, { recursive: true });
2463
2470
  }
2464
2471
  if (!skipWrite) {
2465
2472
  result.writtenFiles = {};
@@ -2472,17 +2479,18 @@ var generateAppTypesPlugin = ({ sdk: sdk2 }) => {
2472
2479
  });
2473
2480
  try {
2474
2481
  if (!app.version) {
2475
- const error = `Invalid implementation ID format: ${app.implementation_id}. Expected format: <implementationName>@<version>`;
2476
- result.errors.push({
2477
- appKey: app.key,
2478
- error
2479
- });
2482
+ const errorMessage = `Invalid implementation ID format: ${app.implementation_id}. Expected format: <implementationName>@<version>`;
2480
2483
  onProgress?.({
2481
2484
  type: "app_processing_error",
2482
2485
  appKey: app.key,
2483
- error
2486
+ error: errorMessage
2487
+ });
2488
+ throw new zapierSdk.ZapierValidationError(errorMessage, {
2489
+ details: {
2490
+ appKey: app.key,
2491
+ implementationId: app.implementation_id
2492
+ }
2484
2493
  });
2485
- continue;
2486
2494
  }
2487
2495
  let authenticationId;
2488
2496
  if (authentications.length > 0) {
@@ -2505,56 +2513,47 @@ var generateAppTypesPlugin = ({ sdk: sdk2 }) => {
2505
2513
  }
2506
2514
  }
2507
2515
  const manifestKey = getManifestKey(app);
2508
- try {
2509
- const generator = new AstTypeGenerator();
2510
- const typeDefinitionString = await generator.generateTypes({
2511
- app,
2512
- authenticationId,
2513
- sdk: sdk2
2514
- });
2515
- result.typeDefinitions[manifestKey] = typeDefinitionString;
2516
+ const generator = new AstTypeGenerator();
2517
+ const typeDefinitionString = await generator.generateTypes({
2518
+ app,
2519
+ authenticationId,
2520
+ sdk: sdk2
2521
+ });
2522
+ result.typeDefinitions[manifestKey] = typeDefinitionString;
2523
+ onProgress?.({
2524
+ type: "type_generated",
2525
+ manifestKey,
2526
+ sizeBytes: typeDefinitionString.length
2527
+ });
2528
+ if (!skipWrite && resolvedTypesOutput && result.writtenFiles) {
2529
+ const filePath = path.join(resolvedTypesOutput, `${manifestKey}.d.ts`);
2530
+ await promises.writeFile(filePath, typeDefinitionString, "utf8");
2531
+ result.writtenFiles[manifestKey] = filePath;
2516
2532
  onProgress?.({
2517
- type: "type_generated",
2533
+ type: "file_written",
2518
2534
  manifestKey,
2519
- sizeBytes: typeDefinitionString.length
2520
- });
2521
- if (!skipWrite && typesOutputDirectory && result.writtenFiles) {
2522
- const filePath = path.join(typesOutputDirectory, `${manifestKey}.d.ts`);
2523
- await promises.writeFile(filePath, typeDefinitionString, "utf8");
2524
- result.writtenFiles[manifestKey] = filePath;
2525
- onProgress?.({
2526
- type: "file_written",
2527
- manifestKey,
2528
- filePath
2529
- });
2530
- }
2531
- onProgress?.({
2532
- type: "app_processing_complete",
2533
- appKey: app.key
2534
- });
2535
- } catch (error) {
2536
- const errorMessage = `Failed to generate types: ${error}`;
2537
- result.errors.push({
2538
- appKey: app.key,
2539
- error: errorMessage
2540
- });
2541
- onProgress?.({
2542
- type: "app_processing_error",
2543
- appKey: app.key,
2544
- error: errorMessage
2535
+ filePath
2545
2536
  });
2546
2537
  }
2547
- } catch (error) {
2548
- const errorMessage = `Failed to process app: ${error}`;
2549
- result.errors.push({
2550
- appKey: app.key,
2551
- error: errorMessage
2538
+ onProgress?.({
2539
+ type: "app_processing_complete",
2540
+ appKey: app.key
2552
2541
  });
2542
+ } catch (error) {
2543
+ const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
2553
2544
  onProgress?.({
2554
2545
  type: "app_processing_error",
2555
2546
  appKey: app.key,
2556
2547
  error: errorMessage
2557
2548
  });
2549
+ if (error instanceof zapierSdk.ZapierValidationError) {
2550
+ throw error;
2551
+ } else {
2552
+ throw new zapierSdk.ZapierUnknownError(errorMessage, {
2553
+ cause: error
2554
+ // Works for both Error and non-Error
2555
+ });
2556
+ }
2558
2557
  }
2559
2558
  }
2560
2559
  return result;
@@ -2589,9 +2588,6 @@ var BuildManifestSchema = zod.z.object({
2589
2588
  var buildManifestPlugin = ({ sdk: sdk2, context }) => {
2590
2589
  const buildManifest = zapierSdk.createFunction(async function buildManifest2(options) {
2591
2590
  const { appKeys, skipWrite = false, configPath, onProgress } = options;
2592
- const result = {
2593
- errors: []
2594
- };
2595
2591
  onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
2596
2592
  const appsIterator = sdk2.listApps({ appKeys }).items();
2597
2593
  const apps = [];
@@ -2601,7 +2597,7 @@ var buildManifestPlugin = ({ sdk: sdk2, context }) => {
2601
2597
  }
2602
2598
  onProgress?.({ type: "apps_lookup_complete", count: apps.length });
2603
2599
  if (apps.length === 0) {
2604
- return result;
2600
+ return {};
2605
2601
  }
2606
2602
  let updatedManifest;
2607
2603
  for (const app of apps) {
@@ -2634,20 +2630,23 @@ var buildManifestPlugin = ({ sdk: sdk2, context }) => {
2634
2630
  });
2635
2631
  onProgress?.({ type: "app_processing_complete", appKey: app.key });
2636
2632
  } catch (error) {
2637
- const errorMessage = `Failed to process app: ${error}`;
2638
- result.errors.push({
2639
- appKey: app.key,
2640
- error: errorMessage
2641
- });
2633
+ const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
2642
2634
  onProgress?.({
2643
2635
  type: "app_processing_error",
2644
2636
  appKey: app.key,
2645
2637
  error: errorMessage
2646
2638
  });
2639
+ if (error instanceof zapierSdk.ZapierValidationError) {
2640
+ throw error;
2641
+ } else {
2642
+ throw new zapierSdk.ZapierUnknownError(errorMessage, {
2643
+ cause: error
2644
+ // Works for both Error and non-Error
2645
+ });
2646
+ }
2647
2647
  }
2648
2648
  }
2649
- result.manifest = updatedManifest;
2650
- return result;
2649
+ return { manifest: updatedManifest };
2651
2650
  }, BuildManifestSchema);
2652
2651
  return {
2653
2652
  buildManifest,
@@ -2671,14 +2670,32 @@ function createZapierCliSdk(options = {}) {
2671
2670
 
2672
2671
  // package.json with { type: 'json' }
2673
2672
  var package_default2 = {
2674
- version: "0.13.9"};
2673
+ version: "0.13.11"};
2675
2674
 
2676
2675
  // src/cli.ts
2677
2676
  var program = new commander.Command();
2678
- program.name("zapier-sdk").description("CLI for Zapier SDK").version(package_default2.version, "-v, --version", "display version number").option("--debug", "Enable debug logging");
2677
+ 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(
2678
+ "--auth-base-url <url>",
2679
+ "Base URL for Zapier authentication endpoints"
2680
+ ).option("--auth-client-id <id>", "OAuth client ID for Zapier authentication").option(
2681
+ "--tracking-base-url <url>",
2682
+ "Base URL for Zapier tracking endpoints"
2683
+ );
2679
2684
  var isDebugMode = process.env.DEBUG === "true" || process.argv.includes("--debug");
2685
+ var baseUrlIndex = process.argv.indexOf("--base-url");
2686
+ var authBaseUrlIndex = process.argv.indexOf("--auth-base-url");
2687
+ var authClientIdIndex = process.argv.indexOf("--auth-client-id");
2688
+ var trackingBaseUrlIndex = process.argv.indexOf("--tracking-base-url");
2689
+ var baseUrl = baseUrlIndex !== -1 ? process.argv[baseUrlIndex + 1] : void 0;
2690
+ var authBaseUrl = authBaseUrlIndex !== -1 ? process.argv[authBaseUrlIndex + 1] : void 0;
2691
+ var authClientId = authClientIdIndex !== -1 ? process.argv[authClientIdIndex + 1] : void 0;
2692
+ var trackingBaseUrl = trackingBaseUrlIndex !== -1 ? process.argv[trackingBaseUrlIndex + 1] : void 0;
2680
2693
  var sdk = createZapierCliSdk({
2681
- debug: isDebugMode
2694
+ debug: isDebugMode,
2695
+ baseUrl,
2696
+ authBaseUrl,
2697
+ authClientId,
2698
+ trackingBaseUrl
2682
2699
  });
2683
2700
  generateCliCommands(program, sdk);
2684
2701
  program.parse();