@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/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",
@@ -43,9 +43,9 @@
43
43
  "pkce-challenge": "^5.0.0",
44
44
  "typescript": "^5.8.3",
45
45
  "zod": "^3.25.67",
46
- "@zapier/zapier-sdk": "0.13.7",
47
- "@zapier/zapier-sdk-cli-login": "0.3.3",
48
- "@zapier/zapier-sdk-mcp": "0.3.20"
46
+ "@zapier/zapier-sdk-cli-login": "0.3.4",
47
+ "@zapier/zapier-sdk-mcp": "0.3.21",
48
+ "@zapier/zapier-sdk": "0.13.8"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/express": "^5.0.3",
package/src/cli.test.ts CHANGED
@@ -11,4 +11,14 @@ describe("CLI", () => {
11
11
  expect(result).toContain("Options:");
12
12
  expect(result).toContain("Commands:");
13
13
  });
14
+
15
+ it("should include authClientId option in help", () => {
16
+ const result = execSync("npx tsx src/cli.ts --help", {
17
+ encoding: "utf-8",
18
+ cwd: __dirname + "/..",
19
+ });
20
+
21
+ expect(result).toContain("--auth-client-id <id>");
22
+ expect(result).toContain("OAuth client ID for Zapier authentication");
23
+ });
14
24
  });
package/src/cli.ts CHANGED
@@ -11,15 +11,47 @@ program
11
11
  .name("zapier-sdk")
12
12
  .description("CLI for Zapier SDK")
13
13
  .version(packageJson.version, "-v, --version", "display version number")
14
- .option("--debug", "Enable debug logging");
14
+ .option("--debug", "Enable debug logging")
15
+ .option("--base-url <url>", "Base URL for Zapier API endpoints")
16
+ .option(
17
+ "--auth-base-url <url>",
18
+ "Base URL for Zapier authentication endpoints",
19
+ )
20
+ .option("--auth-client-id <id>", "OAuth client ID for Zapier authentication")
21
+ .option(
22
+ "--tracking-base-url <url>",
23
+ "Base URL for Zapier tracking endpoints",
24
+ );
15
25
 
16
- // Check for debug flag early
26
+ // Check for debug flag early (support both flag and env var)
17
27
  const isDebugMode =
18
28
  process.env.DEBUG === "true" || process.argv.includes("--debug");
19
29
 
20
- // Create CLI SDK instance with all plugins
30
+ // Extract URL options from process.argv for early SDK creation
31
+ // We need to create the SDK before parsing to generate commands from schemas
32
+ const baseUrlIndex = process.argv.indexOf("--base-url");
33
+ const authBaseUrlIndex = process.argv.indexOf("--auth-base-url");
34
+ const authClientIdIndex = process.argv.indexOf("--auth-client-id");
35
+ const trackingBaseUrlIndex = process.argv.indexOf("--tracking-base-url");
36
+
37
+ const baseUrl =
38
+ baseUrlIndex !== -1 ? process.argv[baseUrlIndex + 1] : undefined;
39
+ const authBaseUrl =
40
+ authBaseUrlIndex !== -1 ? process.argv[authBaseUrlIndex + 1] : undefined;
41
+ const authClientId =
42
+ authClientIdIndex !== -1 ? process.argv[authClientIdIndex + 1] : undefined;
43
+ const trackingBaseUrl =
44
+ trackingBaseUrlIndex !== -1
45
+ ? process.argv[trackingBaseUrlIndex + 1]
46
+ : undefined;
47
+
48
+ // Create CLI SDK instance with all plugins and URL options
21
49
  const sdk = createZapierCliSdk({
22
50
  debug: isDebugMode,
51
+ baseUrl,
52
+ authBaseUrl,
53
+ authClientId,
54
+ trackingBaseUrl,
23
55
  });
24
56
 
25
57
  // Auth commands now handled by plugins
@@ -29,22 +29,36 @@ interface LoginPluginProvides {
29
29
  const CLI_COMMAND_EXECUTED_EVENT_SUBJECT =
30
30
  "platform.sdk.CliCommandExecutedEvent";
31
31
 
32
- const loginWithSdk = createFunction(async function loginWithSdk(
33
- options: LoginOptions,
34
- ): Promise<void> {
35
- const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
36
- if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
37
- throw new Error("Timeout must be a positive number");
38
- }
32
+ // Internal type for loginWithSdk that includes SDK URL options
33
+ interface LoginWithSdkOptions extends LoginOptions {
34
+ baseUrl?: string;
35
+ authBaseUrl?: string;
36
+ authClientId?: string;
37
+ }
38
+
39
+ const loginWithSdk = createFunction(
40
+ async (options: LoginWithSdkOptions): Promise<void> => {
41
+ const timeoutSeconds = options.timeout
42
+ ? parseInt(options.timeout, 10)
43
+ : 300;
44
+ if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
45
+ throw new Error("Timeout must be a positive number");
46
+ }
39
47
 
40
- await login(timeoutSeconds * 1000); // Convert to milliseconds
41
- const user = await getLoggedInUser();
48
+ await login({
49
+ timeoutMs: timeoutSeconds * 1000,
50
+ baseUrl: options.baseUrl,
51
+ authBaseUrl: options.authBaseUrl,
52
+ authClientId: options.authClientId,
53
+ });
54
+ const user = await getLoggedInUser();
42
55
 
43
- console.log(`✅ Successfully logged in as ${user.email}`);
56
+ console.log(`✅ Successfully logged in as ${user.email}`);
44
57
 
45
- // Force immediate exit to prevent hanging (especially in development with tsx)
46
- setTimeout(() => process.exit(0), 100);
47
- }, LoginSchema);
58
+ // Force immediate exit to prevent hanging (especially in development with tsx)
59
+ setTimeout(() => process.exit(0), 100);
60
+ },
61
+ );
48
62
 
49
63
  export const loginPlugin: Plugin<
50
64
  {},
@@ -58,7 +72,12 @@ export const loginPlugin: Plugin<
58
72
  let errorMessage: string | null = null;
59
73
 
60
74
  try {
61
- await loginWithSdk(options);
75
+ await loginWithSdk({
76
+ ...options,
77
+ baseUrl: context.options?.baseUrl,
78
+ authBaseUrl: context.options?.authBaseUrl,
79
+ authClientId: context.options?.authClientId,
80
+ });
62
81
  success = true;
63
82
  } catch (error) {
64
83
  success = false;
@@ -6,16 +6,20 @@ import type { Socket } from "net";
6
6
 
7
7
  import {
8
8
  AUTH_MODE_HEADER,
9
- LOGIN_CLIENT_ID,
9
+ ZAPIER_AUTH_CLIENT_ID,
10
10
  LOGIN_PORTS,
11
11
  LOGIN_TIMEOUT_MS,
12
- ZAPIER_BASE,
13
12
  } from "../constants";
14
13
  import { spinPromise } from "../spinner";
15
14
  import log from "../log";
16
15
  import api from "../api/client";
17
16
  import getCallablePromise from "../getCallablePromise";
18
- import { updateLogin, logout } from "@zapier/zapier-sdk-cli-login";
17
+ import {
18
+ updateLogin,
19
+ logout,
20
+ getAuthTokenUrl,
21
+ getAuthAuthorizeUrl,
22
+ } from "@zapier/zapier-sdk-cli-login";
19
23
 
20
24
  const findAvailablePort = (): Promise<number> => {
21
25
  return new Promise((resolve, reject) => {
@@ -62,7 +66,22 @@ const generateRandomString = () => {
62
66
  ).join("");
63
67
  };
64
68
 
65
- const login = async (timeoutMs: number = LOGIN_TIMEOUT_MS): Promise<string> => {
69
+ interface LoginOptions {
70
+ timeoutMs?: number;
71
+ baseUrl?: string;
72
+ authBaseUrl?: string;
73
+ authClientId?: string;
74
+ }
75
+
76
+ const login = async ({
77
+ timeoutMs = LOGIN_TIMEOUT_MS,
78
+ baseUrl,
79
+ authBaseUrl,
80
+ authClientId,
81
+ }: LoginOptions): Promise<string> => {
82
+ const authOptions = { baseUrl, authBaseUrl };
83
+ const tokenUrl = getAuthTokenUrl(authOptions);
84
+ const authorizeUrl = getAuthAuthorizeUrl(authOptions);
66
85
  // Force logout
67
86
  logout();
68
87
 
@@ -106,9 +125,9 @@ const login = async (timeoutMs: number = LOGIN_TIMEOUT_MS): Promise<string> => {
106
125
  const { code_verifier: codeVerifier, code_challenge: codeChallenge } =
107
126
  await pkceChallenge();
108
127
 
109
- const authUrl = `${ZAPIER_BASE}/oauth/authorize/?${new URLSearchParams({
128
+ const authUrl = `${authorizeUrl}?${new URLSearchParams({
110
129
  response_type: "code",
111
- client_id: LOGIN_CLIENT_ID,
130
+ client_id: authClientId || ZAPIER_AUTH_CLIENT_ID,
112
131
  redirect_uri: redirectUri,
113
132
  scope: "internal offline_access",
114
133
  state: generateRandomString(),
@@ -165,12 +184,12 @@ const login = async (timeoutMs: number = LOGIN_TIMEOUT_MS): Promise<string> => {
165
184
  refresh_token: string;
166
185
  expires_in: number;
167
186
  }>(
168
- `${ZAPIER_BASE}/oauth/token/`,
187
+ tokenUrl,
169
188
  {
170
189
  grant_type: "authorization_code",
171
190
  code: await promisedCode,
172
191
  redirect_uri: redirectUri,
173
- client_id: LOGIN_CLIENT_ID,
192
+ client_id: authClientId || ZAPIER_AUTH_CLIENT_ID,
174
193
  code_verifier: codeVerifier,
175
194
  },
176
195
  {
@@ -1,7 +1,6 @@
1
1
  // Import shared OAuth constants from login package
2
2
  export {
3
- ZAPIER_BASE,
4
- LOGIN_CLIENT_ID,
3
+ ZAPIER_AUTH_CLIENT_ID,
5
4
  AUTH_MODE_HEADER,
6
5
  } from "@zapier/zapier-sdk-cli-login";
7
6