@zapier/zapier-sdk-cli 0.13.10 → 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,15 @@
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
+
3
13
  ## 0.13.10
4
14
 
5
15
  ### Patch Changes
package/dist/cli.cjs CHANGED
@@ -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(),
@@ -1376,12 +1384,12 @@ var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
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.10"};
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;
@@ -2650,14 +2670,32 @@ function createZapierCliSdk(options = {}) {
2650
2670
 
2651
2671
  // package.json with { type: 'json' }
2652
2672
  var package_default2 = {
2653
- version: "0.13.10"};
2673
+ version: "0.13.11"};
2654
2674
 
2655
2675
  // src/cli.ts
2656
2676
  var program = new commander.Command();
2657
- 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
+ );
2658
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;
2659
2693
  var sdk = createZapierCliSdk({
2660
- debug: isDebugMode
2694
+ debug: isDebugMode,
2695
+ baseUrl,
2696
+ authBaseUrl,
2697
+ authClientId,
2698
+ trackingBaseUrl
2661
2699
  });
2662
2700
  generateCliCommands(program, sdk);
2663
2701
  program.parse();
package/dist/cli.mjs CHANGED
@@ -9,7 +9,7 @@ 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';
@@ -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(),
@@ -1343,12 +1351,12 @@ var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
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.10"};
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;
@@ -2617,14 +2637,32 @@ function createZapierCliSdk(options = {}) {
2617
2637
 
2618
2638
  // package.json with { type: 'json' }
2619
2639
  var package_default2 = {
2620
- version: "0.13.10"};
2640
+ version: "0.13.11"};
2621
2641
 
2622
2642
  // src/cli.ts
2623
2643
  var program = new Command();
2624
- 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
+ );
2625
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;
2626
2660
  var sdk = createZapierCliSdk({
2627
- debug: isDebugMode
2661
+ debug: isDebugMode,
2662
+ baseUrl,
2663
+ authBaseUrl,
2664
+ authClientId,
2665
+ trackingBaseUrl
2628
2666
  });
2629
2667
  generateCliCommands(program, sdk);
2630
2668
  program.parse();
package/dist/index.cjs CHANGED
@@ -161,7 +161,15 @@ var generateRandomString = () => {
161
161
  (dec) => ("0" + dec.toString(16)).substring(-2)
162
162
  ).join("");
163
163
  };
164
- var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
164
+ var login = async ({
165
+ timeoutMs = LOGIN_TIMEOUT_MS,
166
+ baseUrl,
167
+ authBaseUrl,
168
+ authClientId
169
+ }) => {
170
+ const authOptions = { baseUrl, authBaseUrl };
171
+ const tokenUrl = zapierSdkCliLogin.getAuthTokenUrl(authOptions);
172
+ const authorizeUrl = zapierSdkCliLogin.getAuthAuthorizeUrl(authOptions);
165
173
  zapierSdkCliLogin.logout();
166
174
  const availablePort = await findAvailablePort();
167
175
  const redirectUri = `http://localhost:${availablePort}/oauth`;
@@ -187,9 +195,9 @@ var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
187
195
  process.on("SIGINT", cleanup);
188
196
  process.on("SIGTERM", cleanup);
189
197
  const { code_verifier: codeVerifier, code_challenge: codeChallenge } = await pkceChallenge__default.default();
190
- const authUrl = `${zapierSdkCliLogin.ZAPIER_BASE}/oauth/authorize/?${new URLSearchParams({
198
+ const authUrl = `${authorizeUrl}?${new URLSearchParams({
191
199
  response_type: "code",
192
- client_id: zapierSdkCliLogin.LOGIN_CLIENT_ID,
200
+ client_id: authClientId || zapierSdkCliLogin.ZAPIER_AUTH_CLIENT_ID,
193
201
  redirect_uri: redirectUri,
194
202
  scope: "internal offline_access",
195
203
  state: generateRandomString(),
@@ -232,12 +240,12 @@ var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
232
240
  }
233
241
  log_default.info("Exchanging authorization code for tokens...");
234
242
  const { data } = await client_default.post(
235
- `${zapierSdkCliLogin.ZAPIER_BASE}/oauth/token/`,
243
+ tokenUrl,
236
244
  {
237
245
  grant_type: "authorization_code",
238
246
  code: await promisedCode,
239
247
  redirect_uri: redirectUri,
240
- client_id: zapierSdkCliLogin.LOGIN_CLIENT_ID,
248
+ client_id: authClientId || zapierSdkCliLogin.ZAPIER_AUTH_CLIENT_ID,
241
249
  code_verifier: codeVerifier
242
250
  },
243
251
  {
@@ -258,7 +266,7 @@ var LoginSchema = zod.z.object({
258
266
 
259
267
  // package.json
260
268
  var package_default = {
261
- version: "0.13.10"};
269
+ version: "0.13.11"};
262
270
 
263
271
  // src/telemetry/builders.ts
264
272
  function createCliBaseEvent(context = {}) {
@@ -316,23 +324,35 @@ function buildCliCommandExecutedEvent({
316
324
 
317
325
  // src/plugins/login/index.ts
318
326
  var CLI_COMMAND_EXECUTED_EVENT_SUBJECT = "platform.sdk.CliCommandExecutedEvent";
319
- var loginWithSdk = zapierSdk.createFunction(async function loginWithSdk2(options) {
320
- const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
321
- if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
322
- throw new Error("Timeout must be a positive number");
327
+ var loginWithSdk = zapierSdk.createFunction(
328
+ async (options) => {
329
+ const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
330
+ if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
331
+ throw new Error("Timeout must be a positive number");
332
+ }
333
+ await login_default({
334
+ timeoutMs: timeoutSeconds * 1e3,
335
+ baseUrl: options.baseUrl,
336
+ authBaseUrl: options.authBaseUrl,
337
+ authClientId: options.authClientId
338
+ });
339
+ const user = await zapierSdkCliLogin.getLoggedInUser();
340
+ console.log(`\u2705 Successfully logged in as ${user.email}`);
341
+ setTimeout(() => process.exit(0), 100);
323
342
  }
324
- await login_default(timeoutSeconds * 1e3);
325
- const user = await zapierSdkCliLogin.getLoggedInUser();
326
- console.log(`\u2705 Successfully logged in as ${user.email}`);
327
- setTimeout(() => process.exit(0), 100);
328
- }, LoginSchema);
343
+ );
329
344
  var loginPlugin = ({ context }) => {
330
345
  const loginWithTelemetry = async (options) => {
331
346
  const startTime = Date.now();
332
347
  let success = false;
333
348
  let errorMessage = null;
334
349
  try {
335
- await loginWithSdk(options);
350
+ await loginWithSdk({
351
+ ...options,
352
+ baseUrl: context.options?.baseUrl,
353
+ authBaseUrl: context.options?.authBaseUrl,
354
+ authClientId: context.options?.authClientId
355
+ });
336
356
  success = true;
337
357
  } catch (error) {
338
358
  success = false;
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import open from 'open';
3
3
  import crypto from 'crypto';
4
4
  import express from 'express';
5
5
  import pkceChallenge from 'pkce-challenge';
6
- import { getLoggedInUser, logout, ZAPIER_BASE, LOGIN_CLIENT_ID, AUTH_MODE_HEADER, updateLogin, getConfigPath } from '@zapier/zapier-sdk-cli-login';
6
+ import { getLoggedInUser, logout, getAuthTokenUrl, getAuthAuthorizeUrl, ZAPIER_AUTH_CLIENT_ID, AUTH_MODE_HEADER, updateLogin, getConfigPath } from '@zapier/zapier-sdk-cli-login';
7
7
  import ora from 'ora';
8
8
  import chalk from 'chalk';
9
9
  import { z } from 'zod';
@@ -130,7 +130,15 @@ var generateRandomString = () => {
130
130
  (dec) => ("0" + dec.toString(16)).substring(-2)
131
131
  ).join("");
132
132
  };
133
- var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
133
+ var login = async ({
134
+ timeoutMs = LOGIN_TIMEOUT_MS,
135
+ baseUrl,
136
+ authBaseUrl,
137
+ authClientId
138
+ }) => {
139
+ const authOptions = { baseUrl, authBaseUrl };
140
+ const tokenUrl = getAuthTokenUrl(authOptions);
141
+ const authorizeUrl = getAuthAuthorizeUrl(authOptions);
134
142
  logout();
135
143
  const availablePort = await findAvailablePort();
136
144
  const redirectUri = `http://localhost:${availablePort}/oauth`;
@@ -156,9 +164,9 @@ var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
156
164
  process.on("SIGINT", cleanup);
157
165
  process.on("SIGTERM", cleanup);
158
166
  const { code_verifier: codeVerifier, code_challenge: codeChallenge } = await pkceChallenge();
159
- const authUrl = `${ZAPIER_BASE}/oauth/authorize/?${new URLSearchParams({
167
+ const authUrl = `${authorizeUrl}?${new URLSearchParams({
160
168
  response_type: "code",
161
- client_id: LOGIN_CLIENT_ID,
169
+ client_id: authClientId || ZAPIER_AUTH_CLIENT_ID,
162
170
  redirect_uri: redirectUri,
163
171
  scope: "internal offline_access",
164
172
  state: generateRandomString(),
@@ -201,12 +209,12 @@ var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
201
209
  }
202
210
  log_default.info("Exchanging authorization code for tokens...");
203
211
  const { data } = await client_default.post(
204
- `${ZAPIER_BASE}/oauth/token/`,
212
+ tokenUrl,
205
213
  {
206
214
  grant_type: "authorization_code",
207
215
  code: await promisedCode,
208
216
  redirect_uri: redirectUri,
209
- client_id: LOGIN_CLIENT_ID,
217
+ client_id: authClientId || ZAPIER_AUTH_CLIENT_ID,
210
218
  code_verifier: codeVerifier
211
219
  },
212
220
  {
@@ -227,7 +235,7 @@ var LoginSchema = z.object({
227
235
 
228
236
  // package.json
229
237
  var package_default = {
230
- version: "0.13.10"};
238
+ version: "0.13.11"};
231
239
 
232
240
  // src/telemetry/builders.ts
233
241
  function createCliBaseEvent(context = {}) {
@@ -285,23 +293,35 @@ function buildCliCommandExecutedEvent({
285
293
 
286
294
  // src/plugins/login/index.ts
287
295
  var CLI_COMMAND_EXECUTED_EVENT_SUBJECT = "platform.sdk.CliCommandExecutedEvent";
288
- var loginWithSdk = createFunction(async function loginWithSdk2(options) {
289
- const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
290
- if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
291
- throw new Error("Timeout must be a positive number");
296
+ var loginWithSdk = createFunction(
297
+ async (options) => {
298
+ const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
299
+ if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
300
+ throw new Error("Timeout must be a positive number");
301
+ }
302
+ await login_default({
303
+ timeoutMs: timeoutSeconds * 1e3,
304
+ baseUrl: options.baseUrl,
305
+ authBaseUrl: options.authBaseUrl,
306
+ authClientId: options.authClientId
307
+ });
308
+ const user = await getLoggedInUser();
309
+ console.log(`\u2705 Successfully logged in as ${user.email}`);
310
+ setTimeout(() => process.exit(0), 100);
292
311
  }
293
- await login_default(timeoutSeconds * 1e3);
294
- const user = await getLoggedInUser();
295
- console.log(`\u2705 Successfully logged in as ${user.email}`);
296
- setTimeout(() => process.exit(0), 100);
297
- }, LoginSchema);
312
+ );
298
313
  var loginPlugin = ({ context }) => {
299
314
  const loginWithTelemetry = async (options) => {
300
315
  const startTime = Date.now();
301
316
  let success = false;
302
317
  let errorMessage = null;
303
318
  try {
304
- await loginWithSdk(options);
319
+ await loginWithSdk({
320
+ ...options,
321
+ baseUrl: context.options?.baseUrl,
322
+ authBaseUrl: context.options?.authBaseUrl,
323
+ authClientId: context.options?.authClientId
324
+ });
305
325
  success = true;
306
326
  } catch (error) {
307
327
  success = false;
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zapier/zapier-sdk-cli",
3
- "version": "0.13.10",
3
+ "version": "0.13.11",
4
4
  "description": "Command line interface for Zapier SDK",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
package/dist/src/cli.js CHANGED
@@ -8,12 +8,32 @@ program
8
8
  .name("zapier-sdk")
9
9
  .description("CLI for Zapier SDK")
10
10
  .version(packageJson.version, "-v, --version", "display version number")
11
- .option("--debug", "Enable debug logging");
12
- // Check for debug flag early
11
+ .option("--debug", "Enable debug logging")
12
+ .option("--base-url <url>", "Base URL for Zapier API endpoints")
13
+ .option("--auth-base-url <url>", "Base URL for Zapier authentication endpoints")
14
+ .option("--auth-client-id <id>", "OAuth client ID for Zapier authentication")
15
+ .option("--tracking-base-url <url>", "Base URL for Zapier tracking endpoints");
16
+ // Check for debug flag early (support both flag and env var)
13
17
  const isDebugMode = process.env.DEBUG === "true" || process.argv.includes("--debug");
14
- // Create CLI SDK instance with all plugins
18
+ // Extract URL options from process.argv for early SDK creation
19
+ // We need to create the SDK before parsing to generate commands from schemas
20
+ const baseUrlIndex = process.argv.indexOf("--base-url");
21
+ const authBaseUrlIndex = process.argv.indexOf("--auth-base-url");
22
+ const authClientIdIndex = process.argv.indexOf("--auth-client-id");
23
+ const trackingBaseUrlIndex = process.argv.indexOf("--tracking-base-url");
24
+ const baseUrl = baseUrlIndex !== -1 ? process.argv[baseUrlIndex + 1] : undefined;
25
+ const authBaseUrl = authBaseUrlIndex !== -1 ? process.argv[authBaseUrlIndex + 1] : undefined;
26
+ const authClientId = authClientIdIndex !== -1 ? process.argv[authClientIdIndex + 1] : undefined;
27
+ const trackingBaseUrl = trackingBaseUrlIndex !== -1
28
+ ? process.argv[trackingBaseUrlIndex + 1]
29
+ : undefined;
30
+ // Create CLI SDK instance with all plugins and URL options
15
31
  const sdk = createZapierCliSdk({
16
32
  debug: isDebugMode,
33
+ baseUrl,
34
+ authBaseUrl,
35
+ authClientId,
36
+ trackingBaseUrl,
17
37
  });
18
38
  // Auth commands now handled by plugins
19
39
  // Generate CLI commands from SDK schemas (including CLI plugins)
@@ -5,17 +5,24 @@ import { LoginSchema } from "./schemas";
5
5
  import { buildCliCommandExecutedEvent } from "../../telemetry/builders";
6
6
  import cliPackageJson from "../../../package.json";
7
7
  const CLI_COMMAND_EXECUTED_EVENT_SUBJECT = "platform.sdk.CliCommandExecutedEvent";
8
- const loginWithSdk = createFunction(async function loginWithSdk(options) {
9
- const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
8
+ const loginWithSdk = createFunction(async (options) => {
9
+ const timeoutSeconds = options.timeout
10
+ ? parseInt(options.timeout, 10)
11
+ : 300;
10
12
  if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
11
13
  throw new Error("Timeout must be a positive number");
12
14
  }
13
- await login(timeoutSeconds * 1000); // Convert to milliseconds
15
+ await login({
16
+ timeoutMs: timeoutSeconds * 1000,
17
+ baseUrl: options.baseUrl,
18
+ authBaseUrl: options.authBaseUrl,
19
+ authClientId: options.authClientId,
20
+ });
14
21
  const user = await getLoggedInUser();
15
22
  console.log(`✅ Successfully logged in as ${user.email}`);
16
23
  // Force immediate exit to prevent hanging (especially in development with tsx)
17
24
  setTimeout(() => process.exit(0), 100);
18
- }, LoginSchema);
25
+ });
19
26
  export const loginPlugin = ({ context }) => {
20
27
  // Wrap the login function to emit telemetry events
21
28
  const loginWithTelemetry = async (options) => {
@@ -23,7 +30,12 @@ export const loginPlugin = ({ context }) => {
23
30
  let success = false;
24
31
  let errorMessage = null;
25
32
  try {
26
- await loginWithSdk(options);
33
+ await loginWithSdk({
34
+ ...options,
35
+ baseUrl: context.options?.baseUrl,
36
+ authBaseUrl: context.options?.authBaseUrl,
37
+ authClientId: context.options?.authClientId,
38
+ });
27
39
  success = true;
28
40
  }
29
41
  catch (error) {
@@ -1,2 +1,8 @@
1
- declare const login: (timeoutMs?: number) => Promise<string>;
1
+ interface LoginOptions {
2
+ timeoutMs?: number;
3
+ baseUrl?: string;
4
+ authBaseUrl?: string;
5
+ authClientId?: string;
6
+ }
7
+ declare const login: ({ timeoutMs, baseUrl, authBaseUrl, authClientId, }: LoginOptions) => Promise<string>;
2
8
  export default login;
@@ -2,12 +2,12 @@ import open from "open";
2
2
  import crypto from "node:crypto";
3
3
  import express from "express";
4
4
  import pkceChallenge from "pkce-challenge";
5
- import { AUTH_MODE_HEADER, LOGIN_CLIENT_ID, LOGIN_PORTS, LOGIN_TIMEOUT_MS, ZAPIER_BASE, } from "../constants";
5
+ import { AUTH_MODE_HEADER, ZAPIER_AUTH_CLIENT_ID, LOGIN_PORTS, LOGIN_TIMEOUT_MS, } from "../constants";
6
6
  import { spinPromise } from "../spinner";
7
7
  import log from "../log";
8
8
  import api from "../api/client";
9
9
  import getCallablePromise from "../getCallablePromise";
10
- import { updateLogin, logout } from "@zapier/zapier-sdk-cli-login";
10
+ import { updateLogin, logout, getAuthTokenUrl, getAuthAuthorizeUrl, } from "@zapier/zapier-sdk-cli-login";
11
11
  const findAvailablePort = () => {
12
12
  return new Promise((resolve, reject) => {
13
13
  let portIndex = 0;
@@ -45,7 +45,10 @@ const generateRandomString = () => {
45
45
  crypto.getRandomValues(array);
46
46
  return Array.from(array, (dec) => ("0" + dec.toString(16)).substring(-2)).join("");
47
47
  };
48
- const login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
48
+ const login = async ({ timeoutMs = LOGIN_TIMEOUT_MS, baseUrl, authBaseUrl, authClientId, }) => {
49
+ const authOptions = { baseUrl, authBaseUrl };
50
+ const tokenUrl = getAuthTokenUrl(authOptions);
51
+ const authorizeUrl = getAuthAuthorizeUrl(authOptions);
49
52
  // Force logout
50
53
  logout();
51
54
  // Find an available port
@@ -76,9 +79,9 @@ const login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
76
79
  process.on("SIGINT", cleanup);
77
80
  process.on("SIGTERM", cleanup);
78
81
  const { code_verifier: codeVerifier, code_challenge: codeChallenge } = await pkceChallenge();
79
- const authUrl = `${ZAPIER_BASE}/oauth/authorize/?${new URLSearchParams({
82
+ const authUrl = `${authorizeUrl}?${new URLSearchParams({
80
83
  response_type: "code",
81
- client_id: LOGIN_CLIENT_ID,
84
+ client_id: authClientId || ZAPIER_AUTH_CLIENT_ID,
82
85
  redirect_uri: redirectUri,
83
86
  scope: "internal offline_access",
84
87
  state: generateRandomString(),
@@ -115,11 +118,11 @@ const login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
115
118
  });
116
119
  }
117
120
  log.info("Exchanging authorization code for tokens...");
118
- const { data } = await api.post(`${ZAPIER_BASE}/oauth/token/`, {
121
+ const { data } = await api.post(tokenUrl, {
119
122
  grant_type: "authorization_code",
120
123
  code: await promisedCode,
121
124
  redirect_uri: redirectUri,
122
- client_id: LOGIN_CLIENT_ID,
125
+ client_id: authClientId || ZAPIER_AUTH_CLIENT_ID,
123
126
  code_verifier: codeVerifier,
124
127
  }, {
125
128
  headers: {
@@ -1,3 +1,3 @@
1
- export { ZAPIER_BASE, LOGIN_CLIENT_ID, AUTH_MODE_HEADER, } from "@zapier/zapier-sdk-cli-login";
1
+ export { ZAPIER_AUTH_CLIENT_ID, AUTH_MODE_HEADER, } from "@zapier/zapier-sdk-cli-login";
2
2
  export declare const LOGIN_PORTS: number[];
3
3
  export declare const LOGIN_TIMEOUT_MS = 300000;