@zapier/zapier-sdk-cli 0.19.0 → 0.22.0
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 +8 -0
- package/dist/cli.cjs +2 -2
- package/dist/cli.mjs +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +4 -4
- package/dist/package.json +0 -78
- package/dist/src/cli.d.ts +0 -2
- package/dist/src/cli.js +0 -105
- package/dist/src/generators/ast-generator.d.ts +0 -41
- package/dist/src/generators/ast-generator.js +0 -409
- package/dist/src/index.d.ts +0 -4
- package/dist/src/index.js +0 -4
- package/dist/src/plugins/add/index.d.ts +0 -15
- package/dist/src/plugins/add/index.js +0 -103
- package/dist/src/plugins/add/schemas.d.ts +0 -8
- package/dist/src/plugins/add/schemas.js +0 -22
- package/dist/src/plugins/buildManifest/index.d.ts +0 -13
- package/dist/src/plugins/buildManifest/index.js +0 -81
- package/dist/src/plugins/buildManifest/schemas.d.ts +0 -44
- package/dist/src/plugins/buildManifest/schemas.js +0 -17
- package/dist/src/plugins/bundleCode/index.d.ts +0 -15
- package/dist/src/plugins/bundleCode/index.js +0 -80
- package/dist/src/plugins/bundleCode/schemas.d.ts +0 -10
- package/dist/src/plugins/bundleCode/schemas.js +0 -19
- package/dist/src/plugins/generateAppTypes/index.d.ts +0 -13
- package/dist/src/plugins/generateAppTypes/index.js +0 -157
- package/dist/src/plugins/generateAppTypes/schemas.d.ts +0 -58
- package/dist/src/plugins/generateAppTypes/schemas.js +0 -21
- package/dist/src/plugins/getLoginConfigPath/index.d.ts +0 -15
- package/dist/src/plugins/getLoginConfigPath/index.js +0 -19
- package/dist/src/plugins/getLoginConfigPath/schemas.d.ts +0 -3
- package/dist/src/plugins/getLoginConfigPath/schemas.js +0 -5
- package/dist/src/plugins/index.d.ts +0 -8
- package/dist/src/plugins/index.js +0 -8
- package/dist/src/plugins/login/index.d.ts +0 -23
- package/dist/src/plugins/login/index.js +0 -95
- package/dist/src/plugins/login/schemas.d.ts +0 -5
- package/dist/src/plugins/login/schemas.js +0 -10
- package/dist/src/plugins/logout/index.d.ts +0 -15
- package/dist/src/plugins/logout/index.js +0 -18
- package/dist/src/plugins/logout/schemas.d.ts +0 -3
- package/dist/src/plugins/logout/schemas.js +0 -5
- package/dist/src/plugins/mcp/index.d.ts +0 -15
- package/dist/src/plugins/mcp/index.js +0 -24
- package/dist/src/plugins/mcp/schemas.d.ts +0 -5
- package/dist/src/plugins/mcp/schemas.js +0 -10
- package/dist/src/sdk.d.ts +0 -9
- package/dist/src/sdk.js +0 -24
- package/dist/src/telemetry/builders.d.ts +0 -42
- package/dist/src/telemetry/builders.js +0 -55
- package/dist/src/telemetry/events.d.ts +0 -37
- package/dist/src/telemetry/events.js +0 -4
- package/dist/src/types/sdk.d.ts +0 -5
- package/dist/src/types/sdk.js +0 -1
- package/dist/src/utils/api/client.d.ts +0 -15
- package/dist/src/utils/api/client.js +0 -27
- package/dist/src/utils/auth/login.d.ts +0 -7
- package/dist/src/utils/auth/login.js +0 -154
- package/dist/src/utils/cli-generator-utils.d.ts +0 -14
- package/dist/src/utils/cli-generator-utils.js +0 -122
- package/dist/src/utils/cli-generator.d.ts +0 -3
- package/dist/src/utils/cli-generator.js +0 -555
- package/dist/src/utils/constants.d.ts +0 -3
- package/dist/src/utils/constants.js +0 -5
- package/dist/src/utils/directory-detection.d.ts +0 -5
- package/dist/src/utils/directory-detection.js +0 -21
- package/dist/src/utils/errors.d.ts +0 -16
- package/dist/src/utils/errors.js +0 -19
- package/dist/src/utils/getCallablePromise.d.ts +0 -6
- package/dist/src/utils/getCallablePromise.js +0 -14
- package/dist/src/utils/log.d.ts +0 -8
- package/dist/src/utils/log.js +0 -21
- package/dist/src/utils/manifest-helpers.d.ts +0 -10
- package/dist/src/utils/manifest-helpers.js +0 -19
- package/dist/src/utils/package-manager-detector.d.ts +0 -16
- package/dist/src/utils/package-manager-detector.js +0 -77
- package/dist/src/utils/parameter-resolver.d.ts +0 -42
- package/dist/src/utils/parameter-resolver.js +0 -699
- package/dist/src/utils/schema-formatter.d.ts +0 -6
- package/dist/src/utils/schema-formatter.js +0 -115
- package/dist/src/utils/serializeAsync.d.ts +0 -2
- package/dist/src/utils/serializeAsync.js +0 -16
- package/dist/src/utils/spinner.d.ts +0 -1
- package/dist/src/utils/spinner.js +0 -21
- package/dist/src/utils/version-checker.d.ts +0 -17
- package/dist/src/utils/version-checker.js +0 -156
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { createFunction } from "@zapier/zapier-sdk";
|
|
2
|
-
import { logout } from "@zapier/zapier-sdk-cli-login";
|
|
3
|
-
import { LogoutSchema } from "./schemas";
|
|
4
|
-
const logoutWithSdk = createFunction(async function logoutWithSdk(_options) {
|
|
5
|
-
logout();
|
|
6
|
-
console.log("✅ Successfully logged out");
|
|
7
|
-
}, LogoutSchema);
|
|
8
|
-
export const logoutPlugin = () => ({
|
|
9
|
-
logout: logoutWithSdk,
|
|
10
|
-
context: {
|
|
11
|
-
meta: {
|
|
12
|
-
logout: {
|
|
13
|
-
categories: ["account"],
|
|
14
|
-
inputSchema: LogoutSchema,
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from "@zapier/zapier-sdk";
|
|
2
|
-
import { McpSchema, type McpOptions } from "./schemas";
|
|
3
|
-
interface McpPluginProvides {
|
|
4
|
-
mcp: (options: McpOptions) => Promise<void>;
|
|
5
|
-
context: {
|
|
6
|
-
meta: {
|
|
7
|
-
mcp: {
|
|
8
|
-
inputSchema: typeof McpSchema;
|
|
9
|
-
categories: string[];
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
export declare const mcpPlugin: Plugin<{}, {}, McpPluginProvides>;
|
|
15
|
-
export type { McpPluginProvides };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { createFunction } from "@zapier/zapier-sdk";
|
|
2
|
-
import { startMcpServer } from "@zapier/zapier-sdk-mcp";
|
|
3
|
-
import { McpSchema } from "./schemas";
|
|
4
|
-
export const mcpPlugin = ({ context }) => {
|
|
5
|
-
const mcpWithSdk = createFunction(async function mcpWithSdk(options) {
|
|
6
|
-
// Pass through the SDK's debug option to the MCP server
|
|
7
|
-
const mcpOptions = {
|
|
8
|
-
...options,
|
|
9
|
-
debug: context.options.debug,
|
|
10
|
-
};
|
|
11
|
-
return await startMcpServer(mcpOptions);
|
|
12
|
-
}, McpSchema);
|
|
13
|
-
return {
|
|
14
|
-
mcp: mcpWithSdk,
|
|
15
|
-
context: {
|
|
16
|
-
meta: {
|
|
17
|
-
mcp: {
|
|
18
|
-
categories: ["utility"],
|
|
19
|
-
inputSchema: McpSchema,
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
};
|
package/dist/src/sdk.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type ZapierSdkOptions } from "@zapier/zapier-sdk";
|
|
2
|
-
import type { ZapierSdkCli } from "./types/sdk";
|
|
3
|
-
export interface ZapierCliSdkOptions extends ZapierSdkOptions {
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Create a Zapier SDK instance configured specifically for the CLI
|
|
7
|
-
* Includes all CLI-specific plugins in addition to the standard SDK functionality
|
|
8
|
-
*/
|
|
9
|
-
export declare function createZapierCliSdk(options?: ZapierCliSdkOptions): ZapierSdkCli;
|
package/dist/src/sdk.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { createZapierSdkWithoutRegistry, registryPlugin, } from "@zapier/zapier-sdk";
|
|
2
|
-
import { loginPlugin, logoutPlugin, mcpPlugin, bundleCodePlugin, getLoginConfigPathPlugin, addPlugin, generateAppTypesPlugin, buildManifestPlugin, } from "./plugins/index";
|
|
3
|
-
/**
|
|
4
|
-
* Create a Zapier SDK instance configured specifically for the CLI
|
|
5
|
-
* Includes all CLI-specific plugins in addition to the standard SDK functionality
|
|
6
|
-
*/
|
|
7
|
-
export function createZapierCliSdk(options = {}) {
|
|
8
|
-
// Create SDK instance and chain all plugins
|
|
9
|
-
// Chaining prevents type widening that occurs with let reassignment
|
|
10
|
-
return (createZapierSdkWithoutRegistry({
|
|
11
|
-
...options,
|
|
12
|
-
})
|
|
13
|
-
// Add CLI-specific plugins before registry
|
|
14
|
-
.addPlugin(generateAppTypesPlugin)
|
|
15
|
-
.addPlugin(buildManifestPlugin)
|
|
16
|
-
.addPlugin(bundleCodePlugin)
|
|
17
|
-
.addPlugin(getLoginConfigPathPlugin)
|
|
18
|
-
.addPlugin(addPlugin)
|
|
19
|
-
.addPlugin(mcpPlugin)
|
|
20
|
-
.addPlugin(loginPlugin)
|
|
21
|
-
.addPlugin(logoutPlugin)
|
|
22
|
-
// Add registry plugin to finalize SDK
|
|
23
|
-
.addPlugin(registryPlugin));
|
|
24
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI-specific event builders
|
|
3
|
-
*
|
|
4
|
-
* Provides builder functions for CLI command telemetry that auto-populate
|
|
5
|
-
* common CLI fields and system information.
|
|
6
|
-
*/
|
|
7
|
-
import type { CliCommandExecutedEvent } from "./events";
|
|
8
|
-
export interface CliEventContext {
|
|
9
|
-
customuser_id?: number | null;
|
|
10
|
-
account_id?: number | null;
|
|
11
|
-
identity_id?: number | null;
|
|
12
|
-
visitor_id?: string | null;
|
|
13
|
-
correlation_id?: string | null;
|
|
14
|
-
session_id?: string | null;
|
|
15
|
-
selected_api?: string | null;
|
|
16
|
-
app_id?: number | null;
|
|
17
|
-
app_version_id?: number | null;
|
|
18
|
-
}
|
|
19
|
-
export interface CliCommandExecutedEventData {
|
|
20
|
-
cli_primary_command: string;
|
|
21
|
-
success_flag: boolean;
|
|
22
|
-
execution_duration_ms?: number | null;
|
|
23
|
-
exit_code?: number | null;
|
|
24
|
-
error_message?: string | null;
|
|
25
|
-
command_category?: string | null;
|
|
26
|
-
requires_auth?: boolean | null;
|
|
27
|
-
cli_arguments?: (string | null)[] | null;
|
|
28
|
-
cli_version?: string | null;
|
|
29
|
-
made_network_requests?: boolean | null;
|
|
30
|
-
files_modified_count?: number | null;
|
|
31
|
-
files_created_count?: number | null;
|
|
32
|
-
files_processed_size_bytes?: number | null;
|
|
33
|
-
peak_memory_usage_bytes?: number | null;
|
|
34
|
-
cpu_time_ms?: number | null;
|
|
35
|
-
subprocess_count?: number | null;
|
|
36
|
-
package_manager?: string | null;
|
|
37
|
-
}
|
|
38
|
-
export declare function buildCliCommandExecutedEvent({ data, context, cliVersion, }: {
|
|
39
|
-
data: CliCommandExecutedEventData;
|
|
40
|
-
context?: CliEventContext;
|
|
41
|
-
cliVersion?: string;
|
|
42
|
-
}): CliCommandExecutedEvent;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI-specific event builders
|
|
3
|
-
*
|
|
4
|
-
* Provides builder functions for CLI command telemetry that auto-populate
|
|
5
|
-
* common CLI fields and system information.
|
|
6
|
-
*/
|
|
7
|
-
import { generateEventId, getCurrentTimestamp, getReleaseId, getOsInfo, getPlatformVersions, isCi, getCiPlatform, } from "@zapier/zapier-sdk";
|
|
8
|
-
import cliPackageJson from "../../package.json";
|
|
9
|
-
// Create base event for CLI events
|
|
10
|
-
function createCliBaseEvent(context = {}) {
|
|
11
|
-
return {
|
|
12
|
-
event_id: generateEventId(),
|
|
13
|
-
timestamp_ms: getCurrentTimestamp(),
|
|
14
|
-
release_id: getReleaseId(),
|
|
15
|
-
customuser_id: context.customuser_id ?? null,
|
|
16
|
-
account_id: context.account_id ?? null,
|
|
17
|
-
identity_id: context.identity_id ?? null,
|
|
18
|
-
visitor_id: context.visitor_id ?? null,
|
|
19
|
-
correlation_id: context.correlation_id ?? null,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export function buildCliCommandExecutedEvent({ data, context = {}, cliVersion = cliPackageJson.version, }) {
|
|
23
|
-
const osInfo = getOsInfo();
|
|
24
|
-
const platformVersions = getPlatformVersions();
|
|
25
|
-
return {
|
|
26
|
-
...createCliBaseEvent(context),
|
|
27
|
-
system_name: "zapier-sdk-cli",
|
|
28
|
-
session_id: context.session_id ?? null,
|
|
29
|
-
cli_version: data.cli_version ?? cliVersion,
|
|
30
|
-
cli_arguments: data.cli_arguments ?? null,
|
|
31
|
-
cli_primary_command: data.cli_primary_command,
|
|
32
|
-
os_platform: osInfo.platform,
|
|
33
|
-
os_release: osInfo.release,
|
|
34
|
-
os_architecture: osInfo.architecture,
|
|
35
|
-
platform_versions: platformVersions,
|
|
36
|
-
selected_api: context.selected_api ?? null,
|
|
37
|
-
app_id: context.app_id ?? null,
|
|
38
|
-
app_version_id: context.app_version_id ?? null,
|
|
39
|
-
execution_duration_ms: data.execution_duration_ms ?? null,
|
|
40
|
-
success_flag: data.success_flag,
|
|
41
|
-
exit_code: data.exit_code ?? (data.success_flag ? 0 : 1),
|
|
42
|
-
error_message: data.error_message ?? null,
|
|
43
|
-
command_category: data.command_category ?? null,
|
|
44
|
-
requires_auth: data.requires_auth ?? null,
|
|
45
|
-
is_ci_environment: isCi(),
|
|
46
|
-
ci_platform: getCiPlatform(),
|
|
47
|
-
package_manager: data.package_manager ?? "pnpm", // Default based on project setup
|
|
48
|
-
made_network_requests: data.made_network_requests ?? null,
|
|
49
|
-
files_modified_count: data.files_modified_count ?? null,
|
|
50
|
-
files_created_count: data.files_created_count ?? null,
|
|
51
|
-
files_processed_size_bytes: data.files_processed_size_bytes ?? null,
|
|
52
|
-
cpu_time_ms: data.cpu_time_ms ?? null,
|
|
53
|
-
subprocess_count: data.subprocess_count ?? null,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI-specific telemetry event definitions
|
|
3
|
-
*/
|
|
4
|
-
import type { BaseEvent } from "@zapier/zapier-sdk";
|
|
5
|
-
/**
|
|
6
|
-
* Event emitted when a CLI command is executed
|
|
7
|
-
*/
|
|
8
|
-
export interface CliCommandExecutedEvent extends BaseEvent {
|
|
9
|
-
system_name: string;
|
|
10
|
-
session_id?: string | null;
|
|
11
|
-
cli_version?: string | null;
|
|
12
|
-
cli_arguments?: (string | null)[] | null;
|
|
13
|
-
cli_primary_command?: string | null;
|
|
14
|
-
os_platform?: string | null;
|
|
15
|
-
os_release?: string | null;
|
|
16
|
-
os_architecture?: string | null;
|
|
17
|
-
platform_versions?: Record<string, string | null> | null;
|
|
18
|
-
selected_api?: string | null;
|
|
19
|
-
app_id?: number | null;
|
|
20
|
-
app_version_id?: number | null;
|
|
21
|
-
execution_duration_ms?: number | null;
|
|
22
|
-
success_flag: boolean;
|
|
23
|
-
exit_code?: number | null;
|
|
24
|
-
error_message?: string | null;
|
|
25
|
-
command_category?: string | null;
|
|
26
|
-
requires_auth?: boolean | null;
|
|
27
|
-
is_ci_environment?: boolean | null;
|
|
28
|
-
ci_platform?: string | null;
|
|
29
|
-
package_manager?: string | null;
|
|
30
|
-
made_network_requests?: boolean | null;
|
|
31
|
-
files_modified_count?: number | null;
|
|
32
|
-
files_created_count?: number | null;
|
|
33
|
-
files_processed_size_bytes?: number | null;
|
|
34
|
-
peak_memory_usage_bytes?: number | null;
|
|
35
|
-
cpu_time_ms?: number | null;
|
|
36
|
-
subprocess_count?: number | null;
|
|
37
|
-
}
|
package/dist/src/types/sdk.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { GetSdkType, ZapierSdk } from "@zapier/zapier-sdk";
|
|
2
|
-
import type { BuildManifestPluginProvides } from "../plugins/buildManifest";
|
|
3
|
-
import type { GenerateAppTypesPluginProvides } from "../plugins/generateAppTypes";
|
|
4
|
-
export interface ZapierSdkCli extends GetSdkType<ZapierSdk & BuildManifestPluginProvides & GenerateAppTypesPluginProvides> {
|
|
5
|
-
}
|
package/dist/src/types/sdk.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface ApiResponse<T = unknown> {
|
|
2
|
-
data: T;
|
|
3
|
-
status: number;
|
|
4
|
-
}
|
|
5
|
-
export declare const createApiClient: () => {
|
|
6
|
-
post: <T = unknown>(url: string, data: Record<string, string>, options?: {
|
|
7
|
-
headers?: Record<string, string>;
|
|
8
|
-
}) => Promise<ApiResponse<T>>;
|
|
9
|
-
};
|
|
10
|
-
declare const api: {
|
|
11
|
-
post: <T = unknown>(url: string, data: Record<string, string>, options?: {
|
|
12
|
-
headers?: Record<string, string>;
|
|
13
|
-
}) => Promise<ApiResponse<T>>;
|
|
14
|
-
};
|
|
15
|
-
export default api;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export const createApiClient = () => {
|
|
2
|
-
const post = async (url, data, options = {}) => {
|
|
3
|
-
const { headers = {} } = options;
|
|
4
|
-
const response = await fetch(url, {
|
|
5
|
-
method: "POST",
|
|
6
|
-
headers: {
|
|
7
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
8
|
-
Connection: "close",
|
|
9
|
-
...headers,
|
|
10
|
-
},
|
|
11
|
-
body: new URLSearchParams(data),
|
|
12
|
-
});
|
|
13
|
-
if (!response.ok) {
|
|
14
|
-
throw new Error(`${response.status} ${response.statusText}`);
|
|
15
|
-
}
|
|
16
|
-
const responseData = await response.json();
|
|
17
|
-
return {
|
|
18
|
-
data: responseData,
|
|
19
|
-
status: response.status,
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
return {
|
|
23
|
-
post,
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
const api = createApiClient();
|
|
27
|
-
export default api;
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import open from "open";
|
|
2
|
-
import crypto from "node:crypto";
|
|
3
|
-
import express from "express";
|
|
4
|
-
import pkceChallenge from "pkce-challenge";
|
|
5
|
-
import { AUTH_MODE_HEADER, LOGIN_PORTS, LOGIN_TIMEOUT_MS } from "../constants";
|
|
6
|
-
import { spinPromise } from "../spinner";
|
|
7
|
-
import log from "../log";
|
|
8
|
-
import api from "../api/client";
|
|
9
|
-
import getCallablePromise from "../getCallablePromise";
|
|
10
|
-
import { updateLogin, logout, getPkceLoginConfig, } from "@zapier/zapier-sdk-cli-login";
|
|
11
|
-
import { ZapierCliUserCancellationError } from "../errors";
|
|
12
|
-
const findAvailablePort = () => {
|
|
13
|
-
return new Promise((resolve, reject) => {
|
|
14
|
-
let portIndex = 0;
|
|
15
|
-
const tryPort = (port) => {
|
|
16
|
-
const server = express().listen(port, () => {
|
|
17
|
-
server.close();
|
|
18
|
-
resolve(port);
|
|
19
|
-
});
|
|
20
|
-
server.on("error", (err) => {
|
|
21
|
-
if (err.code === "EADDRINUSE") {
|
|
22
|
-
if (portIndex < LOGIN_PORTS.length) {
|
|
23
|
-
// Try next predefined port
|
|
24
|
-
tryPort(LOGIN_PORTS[portIndex++]);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
// All configured ports are busy
|
|
28
|
-
reject(new Error(`All configured OAuth callback ports are busy: ${LOGIN_PORTS.join(", ")}. Please try again later or close applications using these ports.`));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
reject(err);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
if (LOGIN_PORTS.length > 0) {
|
|
37
|
-
tryPort(LOGIN_PORTS[portIndex++]);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
reject(new Error("No OAuth callback ports configured"));
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
const generateRandomString = () => {
|
|
45
|
-
const array = new Uint32Array(28);
|
|
46
|
-
crypto.getRandomValues(array);
|
|
47
|
-
return Array.from(array, (dec) => ("0" + dec.toString(16)).substring(-2)).join("");
|
|
48
|
-
};
|
|
49
|
-
// Ensure offline_access is included in scope for PKCE (needed for refresh tokens)
|
|
50
|
-
function ensureOfflineAccess(scope) {
|
|
51
|
-
if (scope.includes("offline_access")) {
|
|
52
|
-
return scope;
|
|
53
|
-
}
|
|
54
|
-
return `${scope} offline_access`;
|
|
55
|
-
}
|
|
56
|
-
const login = async ({ timeoutMs = LOGIN_TIMEOUT_MS, credentials, }) => {
|
|
57
|
-
const { clientId, tokenUrl, authorizeUrl } = getPkceLoginConfig({
|
|
58
|
-
credentials,
|
|
59
|
-
});
|
|
60
|
-
const scope = ensureOfflineAccess(credentials?.scope || "internal credentials");
|
|
61
|
-
// Force logout
|
|
62
|
-
logout();
|
|
63
|
-
// Find an available port
|
|
64
|
-
const availablePort = await findAvailablePort();
|
|
65
|
-
const redirectUri = `http://localhost:${availablePort}/oauth`;
|
|
66
|
-
log.info(`Using port ${availablePort} for OAuth callback`);
|
|
67
|
-
const { promise: promisedCode, resolve: setCode, reject: rejectCode, } = getCallablePromise();
|
|
68
|
-
const app = express();
|
|
69
|
-
app.get("/oauth", (req, res) => {
|
|
70
|
-
setCode(String(req.query.code));
|
|
71
|
-
// Set headers to prevent keep-alive
|
|
72
|
-
res.setHeader("Connection", "close");
|
|
73
|
-
res.end("You can now close this tab and return to the CLI.");
|
|
74
|
-
});
|
|
75
|
-
const server = app.listen(availablePort);
|
|
76
|
-
// Track connections to force close them if needed
|
|
77
|
-
const connections = new Set();
|
|
78
|
-
server.on("connection", (conn) => {
|
|
79
|
-
connections.add(conn);
|
|
80
|
-
conn.on("close", () => connections.delete(conn));
|
|
81
|
-
});
|
|
82
|
-
// Set up signal handlers for graceful shutdown
|
|
83
|
-
const cleanup = () => {
|
|
84
|
-
server.close();
|
|
85
|
-
log.info("\n❌ Login cancelled by user");
|
|
86
|
-
rejectCode(new ZapierCliUserCancellationError());
|
|
87
|
-
};
|
|
88
|
-
process.on("SIGINT", cleanup);
|
|
89
|
-
process.on("SIGTERM", cleanup);
|
|
90
|
-
const { code_verifier: codeVerifier, code_challenge: codeChallenge } = await pkceChallenge();
|
|
91
|
-
const authUrl = `${authorizeUrl}?${new URLSearchParams({
|
|
92
|
-
response_type: "code",
|
|
93
|
-
client_id: clientId,
|
|
94
|
-
redirect_uri: redirectUri,
|
|
95
|
-
scope,
|
|
96
|
-
state: generateRandomString(),
|
|
97
|
-
code_challenge: codeChallenge,
|
|
98
|
-
code_challenge_method: "S256",
|
|
99
|
-
}).toString()}`;
|
|
100
|
-
log.info("Opening your browser to log in.");
|
|
101
|
-
log.info("If it doesn't open, visit:", authUrl);
|
|
102
|
-
open(authUrl);
|
|
103
|
-
// Track the timeout timer so we can cancel it after login succeeds
|
|
104
|
-
let timeoutTimer;
|
|
105
|
-
try {
|
|
106
|
-
await spinPromise(Promise.race([
|
|
107
|
-
promisedCode,
|
|
108
|
-
new Promise((_resolve, reject) => {
|
|
109
|
-
timeoutTimer = setTimeout(() => {
|
|
110
|
-
reject(new Error(`Login timed out after ${Math.round(timeoutMs / 1000)} seconds.`));
|
|
111
|
-
}, timeoutMs);
|
|
112
|
-
}),
|
|
113
|
-
]), "Waiting for you to login and authorize");
|
|
114
|
-
}
|
|
115
|
-
finally {
|
|
116
|
-
// Clear the timeout timer to prevent it from keeping the process alive
|
|
117
|
-
if (timeoutTimer) {
|
|
118
|
-
clearTimeout(timeoutTimer);
|
|
119
|
-
}
|
|
120
|
-
// Remove signal handlers
|
|
121
|
-
process.off("SIGINT", cleanup);
|
|
122
|
-
process.off("SIGTERM", cleanup);
|
|
123
|
-
// Close server with timeout and force-close connections if needed
|
|
124
|
-
await new Promise((resolve) => {
|
|
125
|
-
const timeout = setTimeout(() => {
|
|
126
|
-
log.info("Server close timed out, forcing connection shutdown...");
|
|
127
|
-
// Force close all connections
|
|
128
|
-
connections.forEach((conn) => conn.destroy());
|
|
129
|
-
resolve();
|
|
130
|
-
}, 1000); // 1 second timeout
|
|
131
|
-
server.close(() => {
|
|
132
|
-
clearTimeout(timeout);
|
|
133
|
-
resolve();
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
log.info("Exchanging authorization code for tokens...");
|
|
138
|
-
const { data } = await api.post(tokenUrl, {
|
|
139
|
-
grant_type: "authorization_code",
|
|
140
|
-
code: await promisedCode,
|
|
141
|
-
redirect_uri: redirectUri,
|
|
142
|
-
client_id: clientId,
|
|
143
|
-
code_verifier: codeVerifier,
|
|
144
|
-
}, {
|
|
145
|
-
headers: {
|
|
146
|
-
[AUTH_MODE_HEADER]: "no",
|
|
147
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
updateLogin(data);
|
|
151
|
-
log.info("Token exchange completed successfully");
|
|
152
|
-
return data.access_token;
|
|
153
|
-
};
|
|
154
|
-
export default login;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { type FunctionRegistryEntry } from "@zapier/zapier-sdk";
|
|
3
|
-
export interface CliParameter {
|
|
4
|
-
name: string;
|
|
5
|
-
type: "string" | "number" | "boolean" | "array";
|
|
6
|
-
required: boolean;
|
|
7
|
-
description?: string;
|
|
8
|
-
default?: unknown;
|
|
9
|
-
choices?: string[];
|
|
10
|
-
hasResolver?: boolean;
|
|
11
|
-
isPositional?: boolean;
|
|
12
|
-
}
|
|
13
|
-
export declare function analyzeZodSchema(schema: z.ZodSchema, functionInfo?: FunctionRegistryEntry): CliParameter[];
|
|
14
|
-
export declare function convertCliArgsToSdkParams(parameters: CliParameter[], positionalArgs: unknown[], options: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { isPositional } from "@zapier/zapier-sdk";
|
|
3
|
-
// ============================================================================
|
|
4
|
-
// Schema Analysis
|
|
5
|
-
// ============================================================================
|
|
6
|
-
export function analyzeZodSchema(schema, functionInfo) {
|
|
7
|
-
const parameters = [];
|
|
8
|
-
if (schema instanceof z.ZodObject) {
|
|
9
|
-
const shape = schema.shape;
|
|
10
|
-
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
11
|
-
const param = analyzeZodField(key, fieldSchema, functionInfo);
|
|
12
|
-
if (param) {
|
|
13
|
-
parameters.push(param);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return parameters;
|
|
18
|
-
}
|
|
19
|
-
function analyzeZodField(name, schema, functionInfo) {
|
|
20
|
-
let baseSchema = schema;
|
|
21
|
-
let required = true;
|
|
22
|
-
let defaultValue = undefined;
|
|
23
|
-
// Unwrap optional and default wrappers
|
|
24
|
-
if (baseSchema instanceof z.ZodOptional) {
|
|
25
|
-
required = false;
|
|
26
|
-
baseSchema = baseSchema._zod.def.innerType;
|
|
27
|
-
}
|
|
28
|
-
if (baseSchema instanceof z.ZodDefault) {
|
|
29
|
-
required = false;
|
|
30
|
-
defaultValue = baseSchema._zod.def.defaultValue();
|
|
31
|
-
baseSchema = baseSchema._zod.def.innerType;
|
|
32
|
-
}
|
|
33
|
-
// Determine parameter type
|
|
34
|
-
let paramType = "string";
|
|
35
|
-
let choices;
|
|
36
|
-
if (baseSchema instanceof z.ZodString) {
|
|
37
|
-
paramType = "string";
|
|
38
|
-
}
|
|
39
|
-
else if (baseSchema instanceof z.ZodNumber) {
|
|
40
|
-
paramType = "number";
|
|
41
|
-
}
|
|
42
|
-
else if (baseSchema instanceof z.ZodBoolean) {
|
|
43
|
-
paramType = "boolean";
|
|
44
|
-
}
|
|
45
|
-
else if (baseSchema instanceof z.ZodArray) {
|
|
46
|
-
paramType = "array";
|
|
47
|
-
}
|
|
48
|
-
else if (baseSchema instanceof z.ZodEnum) {
|
|
49
|
-
paramType = "string";
|
|
50
|
-
choices = baseSchema.options;
|
|
51
|
-
}
|
|
52
|
-
else if (baseSchema instanceof z.ZodRecord) {
|
|
53
|
-
// Handle Record<string, any> as JSON string input
|
|
54
|
-
paramType = "string";
|
|
55
|
-
}
|
|
56
|
-
// Check if this parameter has a resolver
|
|
57
|
-
let paramHasResolver = false;
|
|
58
|
-
// Check function-specific resolvers first
|
|
59
|
-
if (functionInfo?.resolvers?.[name]) {
|
|
60
|
-
paramHasResolver = true;
|
|
61
|
-
}
|
|
62
|
-
// Extract resolver metadata
|
|
63
|
-
return {
|
|
64
|
-
name,
|
|
65
|
-
type: paramType,
|
|
66
|
-
required,
|
|
67
|
-
description: schema.description,
|
|
68
|
-
default: defaultValue,
|
|
69
|
-
choices,
|
|
70
|
-
hasResolver: paramHasResolver,
|
|
71
|
-
isPositional: isPositional(schema),
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
// ============================================================================
|
|
75
|
-
// Parameter Conversion
|
|
76
|
-
// ============================================================================
|
|
77
|
-
export function convertCliArgsToSdkParams(parameters, positionalArgs, options) {
|
|
78
|
-
const sdkParams = {};
|
|
79
|
-
// Handle positional arguments (required parameters or optional positional parameters)
|
|
80
|
-
let argIndex = 0;
|
|
81
|
-
parameters.forEach((param) => {
|
|
82
|
-
if ((param.required || param.isPositional) &&
|
|
83
|
-
argIndex < positionalArgs.length) {
|
|
84
|
-
// Use the original camelCase parameter name for the SDK
|
|
85
|
-
sdkParams[param.name] = convertValue(positionalArgs[argIndex], param.type);
|
|
86
|
-
argIndex++;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
// Handle option flags
|
|
90
|
-
Object.entries(options).forEach(([key, value]) => {
|
|
91
|
-
// Convert kebab-case back to camelCase
|
|
92
|
-
const camelKey = key.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
|
|
93
|
-
const param = parameters.find((p) => p.name === camelKey);
|
|
94
|
-
if (param && value !== undefined) {
|
|
95
|
-
sdkParams[camelKey] = convertValue(value, param.type);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
return sdkParams;
|
|
99
|
-
}
|
|
100
|
-
function convertValue(value, type) {
|
|
101
|
-
switch (type) {
|
|
102
|
-
case "number":
|
|
103
|
-
return Number(value);
|
|
104
|
-
case "boolean":
|
|
105
|
-
return Boolean(value);
|
|
106
|
-
case "array":
|
|
107
|
-
return Array.isArray(value) ? value : [value];
|
|
108
|
-
case "string":
|
|
109
|
-
default:
|
|
110
|
-
// Handle JSON string for objects
|
|
111
|
-
if (typeof value === "string" &&
|
|
112
|
-
(value.startsWith("{") || value.startsWith("["))) {
|
|
113
|
-
try {
|
|
114
|
-
return JSON.parse(value);
|
|
115
|
-
}
|
|
116
|
-
catch {
|
|
117
|
-
return value;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return value;
|
|
121
|
-
}
|
|
122
|
-
}
|