@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.
@@ -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;
@@ -1,5 +1,5 @@
1
1
  // Import shared OAuth constants from login package
2
- export { ZAPIER_BASE, LOGIN_CLIENT_ID, AUTH_MODE_HEADER, } from "@zapier/zapier-sdk-cli-login";
2
+ export { ZAPIER_AUTH_CLIENT_ID, AUTH_MODE_HEADER, } from "@zapier/zapier-sdk-cli-login";
3
3
  // CLI-specific constants
4
4
  export const LOGIN_PORTS = [49505, 50575, 52804, 55981, 61010, 63851];
5
5
  export const LOGIN_TIMEOUT_MS = 300000; // 5 minutes