@zapier/zapier-sdk-cli 0.52.12 → 0.53.1
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/AGENTS.md +326 -0
- package/CHANGELOG.md +22 -0
- package/CLAUDE.md +3 -324
- package/README.md +20 -0
- package/dist/cli.cjs +896 -395
- package/dist/cli.mjs +897 -396
- package/dist/experimental.cjs +897 -398
- package/dist/experimental.d.mts +1 -1
- package/dist/experimental.d.ts +1 -1
- package/dist/experimental.mjs +896 -397
- package/dist/index.cjs +898 -399
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +897 -398
- package/dist/package.json +2 -1
- package/dist/{sdk-Sa1HjzUj.d.mts → sdk-SOLizjno.d.mts} +40 -2
- package/dist/{sdk-Sa1HjzUj.d.ts → sdk-SOLizjno.d.ts} +40 -2
- package/dist/src/experimental.js +2 -1
- package/dist/src/plugins/index.d.ts +1 -0
- package/dist/src/plugins/index.js +1 -0
- package/dist/src/plugins/login/index.d.ts +2 -15
- package/dist/src/plugins/login/index.js +3 -191
- package/dist/src/plugins/signup/index.d.ts +25 -0
- package/dist/src/plugins/signup/index.js +12 -0
- package/dist/src/plugins/signup/schemas.d.ts +9 -0
- package/dist/src/plugins/signup/schemas.js +26 -0
- package/dist/src/plugins/signup/test-harness.d.ts +34 -0
- package/dist/src/plugins/signup/test-harness.js +74 -0
- package/dist/src/sdk.js +2 -1
- package/dist/src/types/sdk.d.ts +2 -1
- package/dist/src/utils/auth/account-auth.d.ts +32 -0
- package/dist/src/utils/auth/account-auth.js +265 -0
- package/dist/src/utils/auth/oauth-callback.d.ts +6 -0
- package/dist/src/utils/auth/oauth-callback.js +28 -0
- package/dist/src/utils/auth/oauth-errors.d.ts +2 -0
- package/dist/src/utils/auth/oauth-errors.js +39 -0
- package/dist/src/utils/auth/oauth-flow.d.ts +31 -6
- package/dist/src/utils/auth/oauth-flow.js +258 -106
- package/dist/src/utils/auth/oauth-transaction.d.ts +35 -0
- package/dist/src/utils/auth/oauth-transaction.js +69 -0
- package/dist/src/utils/non-interactive.d.ts +5 -4
- package/dist/src/utils/non-interactive.js +6 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -3
- package/templates/basic/AGENTS.md.hbs +2 -2
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zapier/zapier-sdk-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.1",
|
|
4
4
|
"description": "Command line interface for Zapier SDK",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -67,6 +67,7 @@
|
|
|
67
67
|
"templates",
|
|
68
68
|
"README.md",
|
|
69
69
|
"CHANGELOG.md",
|
|
70
|
+
"AGENTS.md",
|
|
70
71
|
"CLAUDE.md"
|
|
71
72
|
],
|
|
72
73
|
"repository": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _zapier_zapier_sdk from '@zapier/zapier-sdk';
|
|
2
|
-
import { AppItem, Manifest, ZapierSdk } from '@zapier/zapier-sdk';
|
|
2
|
+
import { AppItem, Manifest, ResolvedCredentials, ApiClient, ZapierSdk } from '@zapier/zapier-sdk';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
declare const BuildManifestSchema: z.ZodObject<{
|
|
@@ -511,6 +511,44 @@ declare const generateAppTypesPlugin: (sdk: {
|
|
|
511
511
|
};
|
|
512
512
|
type GenerateAppTypesPluginProvides = ReturnType<typeof generateAppTypesPlugin>;
|
|
513
513
|
|
|
514
|
-
|
|
514
|
+
interface AccountAuthCliContext {
|
|
515
|
+
session_id?: string | null;
|
|
516
|
+
selected_api?: string | null;
|
|
517
|
+
app_id?: number | null;
|
|
518
|
+
app_version_id?: number | null;
|
|
519
|
+
resolveCredentials: () => Promise<ResolvedCredentials | undefined>;
|
|
520
|
+
api: ApiClient;
|
|
521
|
+
options?: {
|
|
522
|
+
baseUrl?: string;
|
|
523
|
+
credentials?: unknown;
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
declare const signupPlugin: (sdk: {
|
|
528
|
+
context: _zapier_zapier_sdk.EventEmissionContext;
|
|
529
|
+
} & {
|
|
530
|
+
context: AccountAuthCliContext;
|
|
531
|
+
} & {
|
|
532
|
+
context: {
|
|
533
|
+
meta: Record<string, _zapier_zapier_sdk.PluginMeta>;
|
|
534
|
+
};
|
|
535
|
+
}) => {
|
|
536
|
+
signup: (options?: {
|
|
537
|
+
timeout?: string | undefined;
|
|
538
|
+
useApprovals?: boolean | undefined;
|
|
539
|
+
nonInteractive?: boolean | undefined;
|
|
540
|
+
skipPrompts?: boolean | undefined;
|
|
541
|
+
headless?: boolean | undefined;
|
|
542
|
+
} | undefined) => Promise<void>;
|
|
543
|
+
} & {
|
|
544
|
+
context: {
|
|
545
|
+
meta: {
|
|
546
|
+
signup: _zapier_zapier_sdk.PluginMeta<unknown>;
|
|
547
|
+
};
|
|
548
|
+
};
|
|
549
|
+
};
|
|
550
|
+
type SignupPluginProvides = ReturnType<typeof signupPlugin>;
|
|
551
|
+
|
|
552
|
+
type ZapierSdkCli = ZapierSdk & BuildManifestPluginProvides & FeedbackPluginProvides & GenerateAppTypesPluginProvides & SignupPluginProvides;
|
|
515
553
|
|
|
516
554
|
export type { ZapierSdkCli as Z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _zapier_zapier_sdk from '@zapier/zapier-sdk';
|
|
2
|
-
import { AppItem, Manifest, ZapierSdk } from '@zapier/zapier-sdk';
|
|
2
|
+
import { AppItem, Manifest, ResolvedCredentials, ApiClient, ZapierSdk } from '@zapier/zapier-sdk';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
declare const BuildManifestSchema: z.ZodObject<{
|
|
@@ -511,6 +511,44 @@ declare const generateAppTypesPlugin: (sdk: {
|
|
|
511
511
|
};
|
|
512
512
|
type GenerateAppTypesPluginProvides = ReturnType<typeof generateAppTypesPlugin>;
|
|
513
513
|
|
|
514
|
-
|
|
514
|
+
interface AccountAuthCliContext {
|
|
515
|
+
session_id?: string | null;
|
|
516
|
+
selected_api?: string | null;
|
|
517
|
+
app_id?: number | null;
|
|
518
|
+
app_version_id?: number | null;
|
|
519
|
+
resolveCredentials: () => Promise<ResolvedCredentials | undefined>;
|
|
520
|
+
api: ApiClient;
|
|
521
|
+
options?: {
|
|
522
|
+
baseUrl?: string;
|
|
523
|
+
credentials?: unknown;
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
declare const signupPlugin: (sdk: {
|
|
528
|
+
context: _zapier_zapier_sdk.EventEmissionContext;
|
|
529
|
+
} & {
|
|
530
|
+
context: AccountAuthCliContext;
|
|
531
|
+
} & {
|
|
532
|
+
context: {
|
|
533
|
+
meta: Record<string, _zapier_zapier_sdk.PluginMeta>;
|
|
534
|
+
};
|
|
535
|
+
}) => {
|
|
536
|
+
signup: (options?: {
|
|
537
|
+
timeout?: string | undefined;
|
|
538
|
+
useApprovals?: boolean | undefined;
|
|
539
|
+
nonInteractive?: boolean | undefined;
|
|
540
|
+
skipPrompts?: boolean | undefined;
|
|
541
|
+
headless?: boolean | undefined;
|
|
542
|
+
} | undefined) => Promise<void>;
|
|
543
|
+
} & {
|
|
544
|
+
context: {
|
|
545
|
+
meta: {
|
|
546
|
+
signup: _zapier_zapier_sdk.PluginMeta<unknown>;
|
|
547
|
+
};
|
|
548
|
+
};
|
|
549
|
+
};
|
|
550
|
+
type SignupPluginProvides = ReturnType<typeof signupPlugin>;
|
|
551
|
+
|
|
552
|
+
type ZapierSdkCli = ZapierSdk & BuildManifestPluginProvides & FeedbackPluginProvides & GenerateAppTypesPluginProvides & SignupPluginProvides;
|
|
515
553
|
|
|
516
554
|
export type { ZapierSdkCli as Z };
|
package/dist/src/experimental.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import * as cliLogin from "./login";
|
|
17
17
|
import { addPlugin, createZapierSdkStack, injectCliLogin, } from "@zapier/zapier-sdk/experimental";
|
|
18
|
-
import { loginPlugin, logoutPlugin, mcpPlugin, bundleCodePlugin, getLoginConfigPathPlugin, addAppsPlugin, generateAppTypesPlugin, buildManifestPlugin, feedbackPlugin, curlPlugin, cliOverridesPlugin, initPlugin, drainTriggerInboxCliPlugin, watchTriggerInboxCliPlugin, } from "./plugins/index";
|
|
18
|
+
import { loginPlugin, signupPlugin, logoutPlugin, mcpPlugin, bundleCodePlugin, getLoginConfigPathPlugin, addAppsPlugin, generateAppTypesPlugin, buildManifestPlugin, feedbackPlugin, curlPlugin, cliOverridesPlugin, initPlugin, drainTriggerInboxCliPlugin, watchTriggerInboxCliPlugin, } from "./plugins/index";
|
|
19
19
|
import packageJson from "../package.json" with { type: "json" };
|
|
20
20
|
injectCliLogin(cliLogin);
|
|
21
21
|
/**
|
|
@@ -63,6 +63,7 @@ export function createZapierCliSdk(options = {}) {
|
|
|
63
63
|
.use(watchTriggerInboxCliPlugin, { override: true })
|
|
64
64
|
.use(mcpPlugin)
|
|
65
65
|
.use(loginPlugin)
|
|
66
|
+
.use(signupPlugin)
|
|
66
67
|
.use(logoutPlugin)
|
|
67
68
|
// cliOverridesPlugin patches existing meta entries (e.g. flags `fetch`
|
|
68
69
|
// as deprecated) without re-registering the method. `.use` throws on
|
|
@@ -1,20 +1,8 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
interface CliContext {
|
|
3
|
-
session_id?: string | null;
|
|
4
|
-
selected_api?: string | null;
|
|
5
|
-
app_id?: number | null;
|
|
6
|
-
app_version_id?: number | null;
|
|
7
|
-
resolveCredentials: () => Promise<ResolvedCredentials | undefined>;
|
|
8
|
-
api: ApiClient;
|
|
9
|
-
options?: {
|
|
10
|
-
baseUrl?: string;
|
|
11
|
-
credentials?: unknown;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
1
|
+
import { type AccountAuthCliContext } from "../../utils/auth/account-auth";
|
|
14
2
|
export declare const loginPlugin: (sdk: {
|
|
15
3
|
context: import("@zapier/zapier-sdk").EventEmissionContext;
|
|
16
4
|
} & {
|
|
17
|
-
context:
|
|
5
|
+
context: AccountAuthCliContext;
|
|
18
6
|
} & {
|
|
19
7
|
context: {
|
|
20
8
|
meta: Record<string, import("@zapier/zapier-sdk").PluginMeta>;
|
|
@@ -34,4 +22,3 @@ export declare const loginPlugin: (sdk: {
|
|
|
34
22
|
};
|
|
35
23
|
};
|
|
36
24
|
export type LoginPluginProvides = ReturnType<typeof loginPlugin>;
|
|
37
|
-
export {};
|
|
@@ -1,200 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import inquirer from "inquirer";
|
|
4
|
-
import { clearLegacyJwtState, hasLegacyJwtConfig, } from "../../login/legacy-jwt";
|
|
5
|
-
import { getActiveCredentials, deleteStoredClientCredentials, } from "../../login/credentials-store";
|
|
6
|
-
import { revokeCredentials } from "../../login/credentials-revoke";
|
|
7
|
-
import { runOauthFlow } from "../../utils/auth/oauth-flow";
|
|
8
|
-
import { EMPTY_POLICY, setupClientCredentials, } from "../../utils/auth/client-credentials";
|
|
9
|
-
import { resolveCredentialsBaseUrl } from "../auth/credentials-base-url";
|
|
10
|
-
import { ZapierCliValidationError } from "../../utils/errors";
|
|
11
|
-
import { resolveNonInteractive } from "../../utils/non-interactive";
|
|
1
|
+
import { createPluginMethod, definePlugin, } from "@zapier/zapier-sdk";
|
|
2
|
+
import { runAccountAuth, } from "../../utils/auth/account-auth";
|
|
12
3
|
import { LoginSchema } from "./schemas";
|
|
13
|
-
function toPkceCredentials(credentials) {
|
|
14
|
-
if (credentials &&
|
|
15
|
-
isCredentialsObject(credentials) &&
|
|
16
|
-
!("clientSecret" in credentials)) {
|
|
17
|
-
return {
|
|
18
|
-
type: "pkce",
|
|
19
|
-
clientId: credentials.clientId,
|
|
20
|
-
baseUrl: credentials.baseUrl,
|
|
21
|
-
scope: credentials.scope,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
async function confirmRevokeAndRelogin(activeCredentials, nonInteractive) {
|
|
27
|
-
if (nonInteractive) {
|
|
28
|
-
throw new ZapierCliValidationError(`Already logged in as "${activeCredentials.name}". Run \`logout\` first or use an interactive terminal to re-authenticate.`);
|
|
29
|
-
}
|
|
30
|
-
const { confirmed } = await inquirer.prompt([
|
|
31
|
-
{
|
|
32
|
-
type: "confirm",
|
|
33
|
-
name: "confirmed",
|
|
34
|
-
message: `You are already logged in as "${activeCredentials.name}".\n` +
|
|
35
|
-
"Logging out will delete these credentials and may interrupt other Zapier SDK or CLI sessions using them.\n" +
|
|
36
|
-
"Log out and log in again?",
|
|
37
|
-
default: false,
|
|
38
|
-
},
|
|
39
|
-
]);
|
|
40
|
-
if (!confirmed) {
|
|
41
|
-
console.log("Login cancelled.");
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
async function confirmJwtMigration(nonInteractive) {
|
|
47
|
-
if (nonInteractive) {
|
|
48
|
-
throw new ZapierCliValidationError("Legacy JWT login detected. Run `logout` first or use an interactive terminal to migrate to client credentials.");
|
|
49
|
-
}
|
|
50
|
-
const { confirmed } = await inquirer.prompt([
|
|
51
|
-
{
|
|
52
|
-
type: "confirm",
|
|
53
|
-
name: "confirmed",
|
|
54
|
-
message: "We're upgrading your login to client credentials for a simpler, more reliable experience " +
|
|
55
|
-
"and to support future security controls. " +
|
|
56
|
-
"Older Zapier SDK/CLI versions on this machine may stop working after the upgrade. " +
|
|
57
|
-
"Continue?",
|
|
58
|
-
default: true,
|
|
59
|
-
},
|
|
60
|
-
]);
|
|
61
|
-
if (!confirmed) {
|
|
62
|
-
console.log("Login cancelled.");
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
async function confirmLocalLoginReset(nonInteractive) {
|
|
68
|
-
if (nonInteractive) {
|
|
69
|
-
throw new ZapierCliValidationError("Login cleanup failed and cannot be reset without confirmation. Re-run with an interactive terminal.");
|
|
70
|
-
}
|
|
71
|
-
const { confirmed } = await inquirer.prompt([
|
|
72
|
-
{
|
|
73
|
-
type: "confirm",
|
|
74
|
-
name: "confirmed",
|
|
75
|
-
message: "Login cleanup failed. Reset local session state and continue?",
|
|
76
|
-
default: false,
|
|
77
|
-
},
|
|
78
|
-
]);
|
|
79
|
-
if (!confirmed) {
|
|
80
|
-
console.log("Login cancelled.");
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
function parseTimeoutSeconds(timeout) {
|
|
86
|
-
const timeoutSeconds = timeout ? parseInt(timeout, 10) : 300;
|
|
87
|
-
if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
|
|
88
|
-
throw new Error("Timeout must be a positive number");
|
|
89
|
-
}
|
|
90
|
-
return timeoutSeconds;
|
|
91
|
-
}
|
|
92
|
-
async function promptCredentialsName(email, nonInteractive) {
|
|
93
|
-
const fallback = `${email}@${hostname()}`;
|
|
94
|
-
if (nonInteractive) {
|
|
95
|
-
return fallback;
|
|
96
|
-
}
|
|
97
|
-
const { credentialName } = await inquirer.prompt([
|
|
98
|
-
{
|
|
99
|
-
type: "input",
|
|
100
|
-
name: "credentialName",
|
|
101
|
-
message: "Enter a name to identify them:",
|
|
102
|
-
default: fallback,
|
|
103
|
-
validate: (input) => {
|
|
104
|
-
if (!input.trim())
|
|
105
|
-
return "Name cannot be empty";
|
|
106
|
-
return true;
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
]);
|
|
110
|
-
return credentialName;
|
|
111
|
-
}
|
|
112
|
-
function emitLoginSuccess({ sdk, profile, }) {
|
|
113
|
-
sdk.context.eventEmission.emit("platform.sdk.ApplicationLifecycleEvent", buildApplicationLifecycleEvent({
|
|
114
|
-
lifecycle_event_type: "login_success",
|
|
115
|
-
}, {
|
|
116
|
-
customuser_id: profile.user_id,
|
|
117
|
-
account_id: profile.roles[0]?.account_id ?? null,
|
|
118
|
-
}));
|
|
119
|
-
}
|
|
120
|
-
async function getProfile(api) {
|
|
121
|
-
return api.get("/zapier/api/v4/profile/", {
|
|
122
|
-
authRequired: true,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
async function bestEffortClearLegacyJwtState() {
|
|
126
|
-
// Don't fail the whole login over a transient keychain hiccup during cleanup.
|
|
127
|
-
try {
|
|
128
|
-
await clearLegacyJwtState();
|
|
129
|
-
}
|
|
130
|
-
catch (err) {
|
|
131
|
-
console.error("[login] Best-effort legacy JWT cleanup failed:", err);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
4
|
export const loginPlugin = definePlugin((sdk) => createPluginMethod(sdk, {
|
|
135
5
|
name: "login",
|
|
136
6
|
categories: ["account"],
|
|
137
7
|
inputSchema: LoginSchema,
|
|
138
8
|
supportsJsonOutput: false,
|
|
139
9
|
handler: async ({ sdk, options }) => {
|
|
140
|
-
|
|
141
|
-
const nonInteractive = resolveNonInteractive(options);
|
|
142
|
-
const resolvedCredentials = await sdk.context.resolveCredentials();
|
|
143
|
-
const pkceCredentials = toPkceCredentials(resolvedCredentials);
|
|
144
|
-
const credentialsBaseUrl = await resolveCredentialsBaseUrl({
|
|
145
|
-
...sdk.context,
|
|
146
|
-
resolvedCredentials,
|
|
147
|
-
});
|
|
148
|
-
const activeCredentials = getActiveCredentials({
|
|
149
|
-
baseUrl: credentialsBaseUrl,
|
|
150
|
-
});
|
|
151
|
-
if (activeCredentials) {
|
|
152
|
-
if (!(await confirmRevokeAndRelogin(activeCredentials, nonInteractive)))
|
|
153
|
-
return;
|
|
154
|
-
try {
|
|
155
|
-
await revokeCredentials({
|
|
156
|
-
api: sdk.context.api,
|
|
157
|
-
credentials: activeCredentials,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
catch {
|
|
161
|
-
if (!(await confirmLocalLoginReset(nonInteractive)))
|
|
162
|
-
return;
|
|
163
|
-
await deleteStoredClientCredentials({
|
|
164
|
-
name: activeCredentials.name,
|
|
165
|
-
baseUrl: activeCredentials.baseUrl,
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
else if (hasLegacyJwtConfig()) {
|
|
170
|
-
if (!(await confirmJwtMigration(nonInteractive)))
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
const { accessToken } = await runOauthFlow({
|
|
174
|
-
timeoutMs: timeoutSeconds * 1000,
|
|
175
|
-
pkceCredentials,
|
|
176
|
-
baseUrl: credentialsBaseUrl,
|
|
177
|
-
});
|
|
178
|
-
const scopedApi = getOrCreateApiClient({
|
|
179
|
-
credentials: accessToken,
|
|
180
|
-
baseUrl: credentialsBaseUrl,
|
|
181
|
-
});
|
|
182
|
-
const profile = await getProfile(scopedApi);
|
|
183
|
-
console.log(`👤 Logged in as ${profile.email}`);
|
|
184
|
-
console.log("\nGenerating credentials so this machine can make authenticated requests on your behalf.");
|
|
185
|
-
const credentialName = await promptCredentialsName(profile.email, nonInteractive);
|
|
186
|
-
const useApprovals = options.useApprovals === true;
|
|
187
|
-
await setupClientCredentials({
|
|
188
|
-
api: scopedApi,
|
|
189
|
-
name: credentialName,
|
|
190
|
-
credentialsBaseUrl,
|
|
191
|
-
...(useApprovals && { policy: EMPTY_POLICY }),
|
|
192
|
-
});
|
|
193
|
-
await bestEffortClearLegacyJwtState();
|
|
194
|
-
console.log(`✅ Credentials "${credentialName}" created and set as default. You are ready to use the Zapier SDK.`);
|
|
195
|
-
if (useApprovals) {
|
|
196
|
-
console.log("🔐 Approvals are enabled for these credentials.");
|
|
197
|
-
}
|
|
198
|
-
emitLoginSuccess({ sdk, profile });
|
|
10
|
+
await runAccountAuth({ sdk, options, entryPoint: "login" });
|
|
199
11
|
},
|
|
200
12
|
}));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type AccountAuthCliContext } from "../../utils/auth/account-auth";
|
|
2
|
+
export declare const signupPlugin: (sdk: {
|
|
3
|
+
context: import("@zapier/zapier-sdk").EventEmissionContext;
|
|
4
|
+
} & {
|
|
5
|
+
context: AccountAuthCliContext;
|
|
6
|
+
} & {
|
|
7
|
+
context: {
|
|
8
|
+
meta: Record<string, import("@zapier/zapier-sdk").PluginMeta>;
|
|
9
|
+
};
|
|
10
|
+
}) => {
|
|
11
|
+
signup: (options?: {
|
|
12
|
+
timeout?: string | undefined;
|
|
13
|
+
useApprovals?: boolean | undefined;
|
|
14
|
+
nonInteractive?: boolean | undefined;
|
|
15
|
+
skipPrompts?: boolean | undefined;
|
|
16
|
+
headless?: boolean | undefined;
|
|
17
|
+
} | undefined) => Promise<void>;
|
|
18
|
+
} & {
|
|
19
|
+
context: {
|
|
20
|
+
meta: {
|
|
21
|
+
signup: import("@zapier/zapier-sdk").PluginMeta<unknown>;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export type SignupPluginProvides = ReturnType<typeof signupPlugin>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createPluginMethod, definePlugin, } from "@zapier/zapier-sdk";
|
|
2
|
+
import { runAccountAuth, } from "../../utils/auth/account-auth";
|
|
3
|
+
import { SignupSchema } from "./schemas";
|
|
4
|
+
export const signupPlugin = definePlugin((sdk) => createPluginMethod(sdk, {
|
|
5
|
+
name: "signup",
|
|
6
|
+
categories: ["account"],
|
|
7
|
+
inputSchema: SignupSchema,
|
|
8
|
+
supportsJsonOutput: false,
|
|
9
|
+
handler: async ({ sdk, options }) => {
|
|
10
|
+
await runAccountAuth({ sdk, options, entryPoint: "signup" });
|
|
11
|
+
},
|
|
12
|
+
}));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const SignupSchema: z.ZodObject<{
|
|
3
|
+
timeout: z.ZodOptional<z.ZodString>;
|
|
4
|
+
useApprovals: z.ZodOptional<z.ZodBoolean>;
|
|
5
|
+
nonInteractive: z.ZodOptional<z.ZodBoolean>;
|
|
6
|
+
skipPrompts: z.ZodOptional<z.ZodBoolean>;
|
|
7
|
+
headless: z.ZodOptional<z.ZodBoolean>;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
export type SignupOptions = z.infer<typeof SignupSchema>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const SignupSchema = z
|
|
3
|
+
.object({
|
|
4
|
+
timeout: z
|
|
5
|
+
.string()
|
|
6
|
+
.optional()
|
|
7
|
+
.describe("Signup timeout in seconds (default: 300)"),
|
|
8
|
+
useApprovals: z
|
|
9
|
+
.boolean()
|
|
10
|
+
.optional()
|
|
11
|
+
.describe("Require approvals for actions performed with these credentials"),
|
|
12
|
+
nonInteractive: z
|
|
13
|
+
.boolean()
|
|
14
|
+
.optional()
|
|
15
|
+
.describe("Skip interactive prompts. Uses defaults where possible; errors instead of prompting when input is required. Useful in CI, piped output, or environments where TTY detection is unreliable."),
|
|
16
|
+
/** @deprecated Use `nonInteractive` instead. */
|
|
17
|
+
skipPrompts: z.boolean().optional().meta({
|
|
18
|
+
deprecated: true,
|
|
19
|
+
deprecationMessage: "Use --non-interactive instead.",
|
|
20
|
+
}),
|
|
21
|
+
headless: z
|
|
22
|
+
.boolean()
|
|
23
|
+
.optional()
|
|
24
|
+
.describe("Use when signing up from a machine that has no browser. Prints a signup link to open elsewhere, then accepts the pasted loopback callback URL."),
|
|
25
|
+
})
|
|
26
|
+
.describe("Set up Zapier account access and SDK credentials");
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type EventEmissionContext, type EventEmissionProvides } from "@zapier/zapier-sdk";
|
|
2
|
+
import type { vi } from "vitest";
|
|
3
|
+
import type { CliContext } from "../../utils/auth/account-auth";
|
|
4
|
+
import { type SignupPluginProvides } from "./index";
|
|
5
|
+
type Vi = typeof vi;
|
|
6
|
+
type EventEmit = EventEmissionProvides["context"]["eventEmission"]["emit"];
|
|
7
|
+
type SignupTestContext = CliContext & EventEmissionContext;
|
|
8
|
+
interface SpyWithCalls {
|
|
9
|
+
mock: {
|
|
10
|
+
calls: unknown[][];
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface SignupTestTtyState {
|
|
14
|
+
stdinIsTty: boolean | undefined;
|
|
15
|
+
stdoutIsTty: boolean | undefined;
|
|
16
|
+
}
|
|
17
|
+
export declare function getSignupTestTty(): SignupTestTtyState;
|
|
18
|
+
export declare function setSignupTestTty(value: boolean): void;
|
|
19
|
+
export declare function restoreSignupTestTty(state: SignupTestTtyState): void;
|
|
20
|
+
export declare function getSignupTestOutput(spy: SpyWithCalls): string;
|
|
21
|
+
export declare function getSignupTestLogs(spy: SpyWithCalls): string;
|
|
22
|
+
export declare function existingSignupCredentials(): {
|
|
23
|
+
name: string;
|
|
24
|
+
clientId: string;
|
|
25
|
+
createdAt: number;
|
|
26
|
+
scopes: string[];
|
|
27
|
+
baseUrl: string;
|
|
28
|
+
};
|
|
29
|
+
export declare function buildSignupTestContext(vi: Vi, mockEmit?: EventEmit): SignupTestContext;
|
|
30
|
+
export declare function createSignupTestSdk({ vi, context, }: {
|
|
31
|
+
vi: Vi;
|
|
32
|
+
context?: SignupTestContext;
|
|
33
|
+
}): SignupPluginProvides;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createSdk, } from "@zapier/zapier-sdk";
|
|
2
|
+
import { signupPlugin } from "./index";
|
|
3
|
+
export function getSignupTestTty() {
|
|
4
|
+
return {
|
|
5
|
+
stdinIsTty: process.stdin.isTTY,
|
|
6
|
+
stdoutIsTty: process.stdout.isTTY,
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export function setSignupTestTty(value) {
|
|
10
|
+
const descriptor = { value, configurable: true, writable: true };
|
|
11
|
+
Object.defineProperty(process.stdin, "isTTY", descriptor);
|
|
12
|
+
Object.defineProperty(process.stdout, "isTTY", descriptor);
|
|
13
|
+
}
|
|
14
|
+
export function restoreSignupTestTty(state) {
|
|
15
|
+
Object.defineProperty(process.stdin, "isTTY", {
|
|
16
|
+
value: state.stdinIsTty,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(process.stdout, "isTTY", {
|
|
21
|
+
value: state.stdoutIsTty,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export function getSignupTestOutput(spy) {
|
|
27
|
+
return spy.mock.calls.map((call) => String(call[0])).join("");
|
|
28
|
+
}
|
|
29
|
+
export function getSignupTestLogs(spy) {
|
|
30
|
+
return spy.mock.calls.map((call) => call.map(String).join(" ")).join("\n");
|
|
31
|
+
}
|
|
32
|
+
export function existingSignupCredentials() {
|
|
33
|
+
return {
|
|
34
|
+
name: "existing",
|
|
35
|
+
clientId: "old-id",
|
|
36
|
+
createdAt: 1,
|
|
37
|
+
scopes: ["external"],
|
|
38
|
+
baseUrl: "https://zapier.com",
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async function emptyApiResult() {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
function createSignupTestApi() {
|
|
45
|
+
return {
|
|
46
|
+
get: emptyApiResult,
|
|
47
|
+
post: emptyApiResult,
|
|
48
|
+
put: emptyApiResult,
|
|
49
|
+
patch: emptyApiResult,
|
|
50
|
+
delete: emptyApiResult,
|
|
51
|
+
poll: emptyApiResult,
|
|
52
|
+
fetch: () => Promise.resolve(new Response()),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export function buildSignupTestContext(vi, mockEmit = () => undefined) {
|
|
56
|
+
return {
|
|
57
|
+
resolveCredentials: vi.fn().mockResolvedValue(undefined),
|
|
58
|
+
api: createSignupTestApi(),
|
|
59
|
+
eventEmission: {
|
|
60
|
+
transport: { emit: vi.fn(), close: vi.fn() },
|
|
61
|
+
config: { enabled: true },
|
|
62
|
+
emit: mockEmit,
|
|
63
|
+
createBaseEvent: vi.fn().mockResolvedValue({}),
|
|
64
|
+
flush: vi.fn().mockResolvedValue(undefined),
|
|
65
|
+
close: vi.fn().mockResolvedValue(undefined),
|
|
66
|
+
},
|
|
67
|
+
hooks: { onMethodEnd: vi.fn() },
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export function createSignupTestSdk({ vi, context = buildSignupTestContext(vi), }) {
|
|
71
|
+
return createSdk()
|
|
72
|
+
.addPlugin(() => ({ context }))
|
|
73
|
+
.addPlugin(signupPlugin);
|
|
74
|
+
}
|
package/dist/src/sdk.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as cliLogin from "./login";
|
|
2
2
|
import { addPlugin, createZapierSdkStack, injectCliLogin, } from "@zapier/zapier-sdk";
|
|
3
|
-
import { loginPlugin, logoutPlugin, mcpPlugin, bundleCodePlugin, getLoginConfigPathPlugin, addAppsPlugin, generateAppTypesPlugin, buildManifestPlugin, feedbackPlugin, curlPlugin, cliOverridesPlugin, initPlugin,
|
|
3
|
+
import { loginPlugin, signupPlugin, logoutPlugin, mcpPlugin, bundleCodePlugin, getLoginConfigPathPlugin, addAppsPlugin, generateAppTypesPlugin, buildManifestPlugin, feedbackPlugin, curlPlugin, cliOverridesPlugin, initPlugin,
|
|
4
4
|
// drainTriggerInboxForeverCliPlugin is experimental — registered only
|
|
5
5
|
// in `./experimental.ts`. See the "Experimental gating" section in
|
|
6
6
|
// `docs/design/2026-05-01-triggers-in-sdk.md`.
|
|
@@ -35,6 +35,7 @@ export function createZapierCliSdk(options = {}) {
|
|
|
35
35
|
.use(initPlugin)
|
|
36
36
|
.use(mcpPlugin)
|
|
37
37
|
.use(loginPlugin)
|
|
38
|
+
.use(signupPlugin)
|
|
38
39
|
.use(logoutPlugin)
|
|
39
40
|
// cliOverridesPlugin patches existing meta entries (e.g. flags `fetch`
|
|
40
41
|
// as deprecated) without re-registering the method. `.use` throws on
|
package/dist/src/types/sdk.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ import type { ZapierSdk } from "@zapier/zapier-sdk";
|
|
|
2
2
|
import type { BuildManifestPluginProvides } from "../plugins/buildManifest";
|
|
3
3
|
import type { FeedbackPluginProvides } from "../plugins/feedback";
|
|
4
4
|
import type { GenerateAppTypesPluginProvides } from "../plugins/generateAppTypes";
|
|
5
|
-
|
|
5
|
+
import type { SignupPluginProvides } from "../plugins/signup";
|
|
6
|
+
export type ZapierSdkCli = ZapierSdk & BuildManifestPluginProvides & FeedbackPluginProvides & GenerateAppTypesPluginProvides & SignupPluginProvides;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type ApiClient, type EventEmissionProvides, type ResolvedCredentials } from "@zapier/zapier-sdk";
|
|
2
|
+
export type AccountAuthEntryPoint = "login" | "signup";
|
|
3
|
+
export interface AccountAuthOptions {
|
|
4
|
+
timeout?: string;
|
|
5
|
+
useApprovals?: boolean;
|
|
6
|
+
nonInteractive?: boolean;
|
|
7
|
+
/** @deprecated Use `nonInteractive` instead. */
|
|
8
|
+
skipPrompts?: boolean;
|
|
9
|
+
headless?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface AccountAuthCliContext {
|
|
12
|
+
session_id?: string | null;
|
|
13
|
+
selected_api?: string | null;
|
|
14
|
+
app_id?: number | null;
|
|
15
|
+
app_version_id?: number | null;
|
|
16
|
+
resolveCredentials: () => Promise<ResolvedCredentials | undefined>;
|
|
17
|
+
api: ApiClient;
|
|
18
|
+
options?: {
|
|
19
|
+
baseUrl?: string;
|
|
20
|
+
credentials?: unknown;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export type CliContext = AccountAuthCliContext;
|
|
24
|
+
interface RunAccountAuthOptions<TOptions extends AccountAuthOptions> {
|
|
25
|
+
sdk: EventEmissionProvides & {
|
|
26
|
+
context: AccountAuthCliContext;
|
|
27
|
+
};
|
|
28
|
+
options: TOptions;
|
|
29
|
+
entryPoint: AccountAuthEntryPoint;
|
|
30
|
+
}
|
|
31
|
+
export declare function runAccountAuth<TOptions extends AccountAuthOptions>({ sdk, options, entryPoint, }: RunAccountAuthOptions<TOptions>): Promise<void>;
|
|
32
|
+
export {};
|