@zapier/zapier-sdk-cli 0.52.10 → 0.53.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.
Files changed (71) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +39 -1
  3. package/dist/cli.cjs +972 -473
  4. package/dist/cli.mjs +973 -474
  5. package/dist/experimental.cjs +914 -424
  6. package/dist/experimental.d.mts +1 -1
  7. package/dist/experimental.d.ts +1 -1
  8. package/dist/experimental.mjs +910 -420
  9. package/dist/index.cjs +914 -424
  10. package/dist/index.d.mts +1 -1
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.mjs +910 -420
  13. package/dist/login.cjs +8 -10
  14. package/dist/login.d.mts +2 -10
  15. package/dist/login.d.ts +2 -10
  16. package/dist/login.mjs +5 -9
  17. package/dist/package.json +1 -1
  18. package/dist/{sdk-B3nKAZdN.d.mts → sdk-SOLizjno.d.mts} +54 -16
  19. package/dist/{sdk-B3nKAZdN.d.ts → sdk-SOLizjno.d.ts} +54 -16
  20. package/dist/src/experimental.js +30 -27
  21. package/dist/src/login/index.d.ts +1 -9
  22. package/dist/src/login/index.js +12 -14
  23. package/dist/src/plugins/add/index.d.ts +15 -15
  24. package/dist/src/plugins/add/index.js +1 -1
  25. package/dist/src/plugins/buildManifest/index.d.ts +2 -2
  26. package/dist/src/plugins/bundleCode/index.d.ts +1 -1
  27. package/dist/src/plugins/bundleCode/index.js +2 -1
  28. package/dist/src/plugins/cliOverrides/index.d.ts +5 -10
  29. package/dist/src/plugins/cliOverrides/index.js +2 -6
  30. package/dist/src/plugins/curl/index.d.ts +2 -2
  31. package/dist/src/plugins/curl/schemas.d.ts +2 -2
  32. package/dist/src/plugins/feedback/index.d.ts +1 -1
  33. package/dist/src/plugins/generateAppTypes/index.d.ts +11 -11
  34. package/dist/src/plugins/getLoginConfigPath/index.d.ts +1 -1
  35. package/dist/src/plugins/index.d.ts +2 -1
  36. package/dist/src/plugins/index.js +2 -1
  37. package/dist/src/plugins/init/index.d.ts +1 -1
  38. package/dist/src/plugins/login/index.d.ts +3 -16
  39. package/dist/src/plugins/login/index.js +3 -191
  40. package/dist/src/plugins/logout/index.d.ts +1 -1
  41. package/dist/src/plugins/mcp/index.d.ts +1 -1
  42. package/dist/src/plugins/signup/index.d.ts +25 -0
  43. package/dist/src/plugins/signup/index.js +12 -0
  44. package/dist/src/plugins/signup/schemas.d.ts +9 -0
  45. package/dist/src/plugins/signup/schemas.js +26 -0
  46. package/dist/src/plugins/signup/test-harness.d.ts +34 -0
  47. package/dist/src/plugins/signup/test-harness.js +74 -0
  48. package/dist/src/sdk.js +32 -20
  49. package/dist/src/types/sdk.d.ts +2 -1
  50. package/dist/src/utils/auth/account-auth.d.ts +32 -0
  51. package/dist/src/utils/auth/account-auth.js +265 -0
  52. package/dist/src/utils/auth/oauth-callback.d.ts +6 -0
  53. package/dist/src/utils/auth/oauth-callback.js +28 -0
  54. package/dist/src/utils/auth/oauth-errors.d.ts +2 -0
  55. package/dist/src/utils/auth/oauth-errors.js +39 -0
  56. package/dist/src/utils/auth/oauth-flow.d.ts +31 -6
  57. package/dist/src/utils/auth/oauth-flow.js +258 -106
  58. package/dist/src/utils/auth/oauth-transaction.d.ts +35 -0
  59. package/dist/src/utils/auth/oauth-transaction.js +69 -0
  60. package/dist/src/utils/cli-generator.js +14 -7
  61. package/dist/src/utils/cli-renderer.d.ts +13 -3
  62. package/dist/src/utils/cli-renderer.js +27 -20
  63. package/dist/src/utils/log.js +9 -4
  64. package/dist/src/utils/non-interactive.d.ts +5 -4
  65. package/dist/src/utils/non-interactive.js +6 -5
  66. package/dist/src/utils/parameter-resolver.js +3 -1
  67. package/dist/src/utils/schema-formatter.d.ts +2 -2
  68. package/dist/src/utils/schema-formatter.js +4 -30
  69. package/dist/src/utils/version-checker.js +8 -3
  70. package/dist/tsconfig.tsbuildinfo +1 -1
  71. package/package.json +3 -3
@@ -1,4 +1,4 @@
1
- export declare const addPlugin: (sdk: {
1
+ export declare const addAppsPlugin: (sdk: {
2
2
  listApps: (options?: ({
3
3
  search?: string | undefined;
4
4
  apps?: string[] | undefined;
@@ -66,19 +66,19 @@ export declare const addPlugin: (sdk: {
66
66
  } & {
67
67
  context: {
68
68
  meta: {
69
- listApps: import("@zapier/zapier-sdk").PluginMeta;
69
+ listApps: import("@zapier/zapier-sdk").PluginMeta<unknown>;
70
70
  };
71
71
  };
72
72
  } & {
73
73
  listActions: (options?: (({
74
74
  app: string;
75
- actionType?: "filter" | "read" | "read_bulk" | "run" | "search" | "search_and_write" | "search_or_write" | "write" | undefined;
75
+ actionType?: "read" | "read_bulk" | "write" | "search" | "search_or_write" | "search_and_write" | "filter" | "run" | undefined;
76
76
  pageSize?: number | undefined;
77
77
  maxItems?: number | undefined;
78
78
  cursor?: string | undefined;
79
79
  } | {
80
80
  appKey: string;
81
- actionType?: "filter" | "read" | "read_bulk" | "run" | "search" | "search_and_write" | "search_or_write" | "write" | undefined;
81
+ actionType?: "read" | "read_bulk" | "write" | "search" | "search_or_write" | "search_and_write" | "filter" | "run" | undefined;
82
82
  pageSize?: number | undefined;
83
83
  maxItems?: number | undefined;
84
84
  cursor?: string | undefined;
@@ -90,24 +90,24 @@ export declare const addPlugin: (sdk: {
90
90
  description: string;
91
91
  key: string;
92
92
  app_key: string;
93
- action_type: "filter" | "read" | "read_bulk" | "run" | "search" | "search_and_write" | "search_or_write" | "write";
93
+ action_type: "read" | "read_bulk" | "write" | "search" | "search_or_write" | "search_and_write" | "filter" | "run";
94
94
  title: string;
95
95
  type: "action";
96
+ is_hidden?: boolean | undefined;
96
97
  id?: string | undefined;
97
98
  is_important?: boolean | undefined;
98
- is_hidden?: boolean | undefined;
99
99
  app_version?: string | undefined;
100
100
  }>;
101
101
  } & {
102
102
  context: {
103
103
  meta: {
104
- listActions: import("@zapier/zapier-sdk").PluginMeta;
104
+ listActions: import("@zapier/zapier-sdk").PluginMeta<unknown>;
105
105
  };
106
106
  };
107
107
  } & {
108
108
  listActionInputFields: (options?: (({
109
109
  app: string;
110
- actionType: "filter" | "read" | "read_bulk" | "run" | "search" | "search_and_write" | "search_or_write" | "write";
110
+ actionType: "read" | "read_bulk" | "write" | "search" | "search_or_write" | "search_and_write" | "filter" | "run";
111
111
  action: string;
112
112
  connection?: string | number | undefined;
113
113
  connectionId?: string | number | null | undefined;
@@ -118,7 +118,7 @@ export declare const addPlugin: (sdk: {
118
118
  cursor?: string | undefined;
119
119
  } | {
120
120
  appKey: string;
121
- actionType: "filter" | "read" | "read_bulk" | "run" | "search" | "search_and_write" | "search_or_write" | "write";
121
+ actionType: "read" | "read_bulk" | "write" | "search" | "search_or_write" | "search_and_write" | "filter" | "run";
122
122
  actionKey: string;
123
123
  connection?: string | number | undefined;
124
124
  connectionId?: string | number | null | undefined;
@@ -155,7 +155,7 @@ export declare const addPlugin: (sdk: {
155
155
  } & {
156
156
  context: {
157
157
  meta: {
158
- listActionInputFields: import("@zapier/zapier-sdk").PluginMeta;
158
+ listActionInputFields: import("@zapier/zapier-sdk").PluginMeta<unknown>;
159
159
  };
160
160
  };
161
161
  } & {
@@ -212,7 +212,7 @@ export declare const addPlugin: (sdk: {
212
212
  } & {
213
213
  context: {
214
214
  meta: {
215
- listConnections: import("@zapier/zapier-sdk").PluginMeta;
215
+ listConnections: import("@zapier/zapier-sdk").PluginMeta<unknown>;
216
216
  };
217
217
  };
218
218
  } & {
@@ -220,7 +220,7 @@ export declare const addPlugin: (sdk: {
220
220
  } & {
221
221
  context: {
222
222
  meta: {
223
- buildManifest: import("@zapier/zapier-sdk").PluginMeta;
223
+ buildManifest: import("@zapier/zapier-sdk").PluginMeta<unknown>;
224
224
  };
225
225
  };
226
226
  } & {
@@ -228,7 +228,7 @@ export declare const addPlugin: (sdk: {
228
228
  } & {
229
229
  context: {
230
230
  meta: {
231
- generateAppTypes: import("@zapier/zapier-sdk").PluginMeta;
231
+ generateAppTypes: import("@zapier/zapier-sdk").PluginMeta<unknown>;
232
232
  };
233
233
  };
234
234
  } & {
@@ -247,8 +247,8 @@ export declare const addPlugin: (sdk: {
247
247
  } & {
248
248
  context: {
249
249
  meta: {
250
- add: import("@zapier/zapier-sdk").PluginMeta;
250
+ add: import("@zapier/zapier-sdk").PluginMeta<unknown>;
251
251
  };
252
252
  };
253
253
  };
254
- export type AddPluginProvides = ReturnType<typeof addPlugin>;
254
+ export type AddAppsPluginProvides = ReturnType<typeof addAppsPlugin>;
@@ -2,7 +2,7 @@ import { createPluginMethod, definePlugin } from "@zapier/zapier-sdk";
2
2
  import { AddSchema } from "./schemas";
3
3
  import { detectTypesOutputDirectory } from "../../utils/directory-detection";
4
4
  import { resolve } from "path";
5
- export const addPlugin = definePlugin((sdk) => createPluginMethod(sdk, {
5
+ export const addAppsPlugin = definePlugin((sdk) => createPluginMethod(sdk, {
6
6
  name: "add",
7
7
  categories: ["utility"],
8
8
  inputSchema: AddSchema,
@@ -68,7 +68,7 @@ export declare const buildManifestPlugin: (sdk: {
68
68
  } & {
69
69
  context: {
70
70
  meta: {
71
- listApps: import("@zapier/zapier-sdk").PluginMeta;
71
+ listApps: import("@zapier/zapier-sdk").PluginMeta<unknown>;
72
72
  };
73
73
  };
74
74
  } & {
@@ -113,7 +113,7 @@ export declare const buildManifestPlugin: (sdk: {
113
113
  } & {
114
114
  context: {
115
115
  meta: {
116
- buildManifest: import("@zapier/zapier-sdk").PluginMeta;
116
+ buildManifest: import("@zapier/zapier-sdk").PluginMeta<unknown>;
117
117
  };
118
118
  };
119
119
  };
@@ -16,7 +16,7 @@ export declare const bundleCodePlugin: (sdk: {
16
16
  } & {
17
17
  context: {
18
18
  meta: {
19
- bundleCode: import("@zapier/zapier-sdk").PluginMeta;
19
+ bundleCode: import("@zapier/zapier-sdk").PluginMeta<unknown>;
20
20
  };
21
21
  };
22
22
  };
@@ -5,7 +5,8 @@ import * as fs from "fs";
5
5
  import * as path from "path";
6
6
  export const bundleCodePlugin = definePlugin((sdk) => createPluginMethod(sdk, {
7
7
  name: "bundleCode",
8
- categories: ["utility", "deprecated"],
8
+ categories: ["utility"],
9
+ deprecation: { message: "bundleCode is no longer maintained." },
9
10
  inputSchema: BundleCodeSchema,
10
11
  handler: async ({ options }) => bundleCode(options),
11
12
  }));
@@ -1,16 +1,12 @@
1
- import type { FunctionDeprecation, PluginMeta } from "@zapier/zapier-sdk";
2
- interface FetchMeta {
3
- categories?: string[];
4
- deprecation?: FunctionDeprecation;
5
- }
1
+ import type { PluginMeta } from "@zapier/zapier-sdk";
6
2
  /**
7
- * CLI-specific metadata overrides.
8
- * Adds "deprecated" category to fetch so it's hidden from CLI help.
3
+ * CLI-specific metadata overrides. Tags `fetch` with a deprecation so the
4
+ * CLI help hides it and a deprecation warning fires when it's invoked.
9
5
  */
10
6
  export declare const cliOverridesPlugin: (sdk: {
11
7
  context: {
12
8
  meta: {
13
- fetch?: FetchMeta;
9
+ fetch?: PluginMeta;
14
10
  };
15
11
  };
16
12
  } & {
@@ -19,8 +15,7 @@ export declare const cliOverridesPlugin: (sdk: {
19
15
  };
20
16
  }) => {
21
17
  context: {
22
- meta: Record<string, PluginMeta>;
18
+ meta: Record<string, PluginMeta<unknown>>;
23
19
  };
24
20
  };
25
21
  export type CliOverridesProvides = ReturnType<typeof cliOverridesPlugin>;
26
- export {};
@@ -1,17 +1,13 @@
1
1
  import { definePlugin } from "@zapier/zapier-sdk";
2
2
  /**
3
- * CLI-specific metadata overrides.
4
- * Adds "deprecated" category to fetch so it's hidden from CLI help.
3
+ * CLI-specific metadata overrides. Tags `fetch` with a deprecation so the
4
+ * CLI help hides it and a deprecation warning fires when it's invoked.
5
5
  */
6
6
  export const cliOverridesPlugin = definePlugin((sdk) => {
7
7
  const meta = {};
8
8
  if (sdk.context.meta.fetch) {
9
9
  meta.fetch = {
10
10
  ...sdk.context.meta.fetch,
11
- categories: [
12
- ...(sdk.context.meta.fetch.categories || []),
13
- "deprecated",
14
- ],
15
11
  deprecation: {
16
12
  message: "This command is deprecated and will be removed soon. Use `curl` instead. Learn more: https://docs.zapier.com/sdk/cli-reference#curl",
17
13
  },
@@ -15,10 +15,10 @@ export declare const curlPlugin: (sdk: {
15
15
  inputSchema: import("zod").ZodObject<{
16
16
  url: import("zod").ZodString;
17
17
  request: import("zod").ZodOptional<import("zod").ZodEnum<{
18
- POST: "POST";
19
18
  GET: "GET";
20
- PUT: "PUT";
19
+ POST: "POST";
21
20
  DELETE: "DELETE";
21
+ PUT: "PUT";
22
22
  PATCH: "PATCH";
23
23
  HEAD: "HEAD";
24
24
  OPTIONS: "OPTIONS";
@@ -2,10 +2,10 @@ import { z } from "zod";
2
2
  export declare const CurlSchema: z.ZodObject<{
3
3
  url: z.ZodString;
4
4
  request: z.ZodOptional<z.ZodEnum<{
5
- POST: "POST";
6
5
  GET: "GET";
7
- PUT: "PUT";
6
+ POST: "POST";
8
7
  DELETE: "DELETE";
8
+ PUT: "PUT";
9
9
  PATCH: "PATCH";
10
10
  HEAD: "HEAD";
11
11
  OPTIONS: "OPTIONS";
@@ -17,7 +17,7 @@ export declare const feedbackPlugin: (sdk: {
17
17
  } & {
18
18
  context: {
19
19
  meta: {
20
- feedback: import("@zapier/zapier-sdk").PluginMeta;
20
+ feedback: import("@zapier/zapier-sdk").PluginMeta<unknown>;
21
21
  };
22
22
  };
23
23
  };
@@ -67,19 +67,19 @@ export declare const generateAppTypesPlugin: (sdk: {
67
67
  } & {
68
68
  context: {
69
69
  meta: {
70
- listApps: import("@zapier/zapier-sdk").PluginMeta;
70
+ listApps: import("@zapier/zapier-sdk").PluginMeta<unknown>;
71
71
  };
72
72
  };
73
73
  } & {
74
74
  listActions: (options?: (({
75
75
  app: string;
76
- actionType?: "filter" | "read" | "read_bulk" | "run" | "search" | "search_and_write" | "search_or_write" | "write" | undefined;
76
+ actionType?: "read" | "read_bulk" | "write" | "search" | "search_or_write" | "search_and_write" | "filter" | "run" | undefined;
77
77
  pageSize?: number | undefined;
78
78
  maxItems?: number | undefined;
79
79
  cursor?: string | undefined;
80
80
  } | {
81
81
  appKey: string;
82
- actionType?: "filter" | "read" | "read_bulk" | "run" | "search" | "search_and_write" | "search_or_write" | "write" | undefined;
82
+ actionType?: "read" | "read_bulk" | "write" | "search" | "search_or_write" | "search_and_write" | "filter" | "run" | undefined;
83
83
  pageSize?: number | undefined;
84
84
  maxItems?: number | undefined;
85
85
  cursor?: string | undefined;
@@ -91,24 +91,24 @@ export declare const generateAppTypesPlugin: (sdk: {
91
91
  description: string;
92
92
  key: string;
93
93
  app_key: string;
94
- action_type: "filter" | "read" | "read_bulk" | "run" | "search" | "search_and_write" | "search_or_write" | "write";
94
+ action_type: "read" | "read_bulk" | "write" | "search" | "search_or_write" | "search_and_write" | "filter" | "run";
95
95
  title: string;
96
96
  type: "action";
97
+ is_hidden?: boolean | undefined;
97
98
  id?: string | undefined;
98
99
  is_important?: boolean | undefined;
99
- is_hidden?: boolean | undefined;
100
100
  app_version?: string | undefined;
101
101
  }>;
102
102
  } & {
103
103
  context: {
104
104
  meta: {
105
- listActions: import("@zapier/zapier-sdk").PluginMeta;
105
+ listActions: import("@zapier/zapier-sdk").PluginMeta<unknown>;
106
106
  };
107
107
  };
108
108
  } & {
109
109
  listActionInputFields: (options?: (({
110
110
  app: string;
111
- actionType: "filter" | "read" | "read_bulk" | "run" | "search" | "search_and_write" | "search_or_write" | "write";
111
+ actionType: "read" | "read_bulk" | "write" | "search" | "search_or_write" | "search_and_write" | "filter" | "run";
112
112
  action: string;
113
113
  connection?: string | number | undefined;
114
114
  connectionId?: string | number | null | undefined;
@@ -119,7 +119,7 @@ export declare const generateAppTypesPlugin: (sdk: {
119
119
  cursor?: string | undefined;
120
120
  } | {
121
121
  appKey: string;
122
- actionType: "filter" | "read" | "read_bulk" | "run" | "search" | "search_and_write" | "search_or_write" | "write";
122
+ actionType: "read" | "read_bulk" | "write" | "search" | "search_or_write" | "search_and_write" | "filter" | "run";
123
123
  actionKey: string;
124
124
  connection?: string | number | undefined;
125
125
  connectionId?: string | number | null | undefined;
@@ -156,7 +156,7 @@ export declare const generateAppTypesPlugin: (sdk: {
156
156
  } & {
157
157
  context: {
158
158
  meta: {
159
- listActionInputFields: import("@zapier/zapier-sdk").PluginMeta;
159
+ listActionInputFields: import("@zapier/zapier-sdk").PluginMeta<unknown>;
160
160
  };
161
161
  };
162
162
  } & {
@@ -213,7 +213,7 @@ export declare const generateAppTypesPlugin: (sdk: {
213
213
  } & {
214
214
  context: {
215
215
  meta: {
216
- listConnections: import("@zapier/zapier-sdk").PluginMeta;
216
+ listConnections: import("@zapier/zapier-sdk").PluginMeta<unknown>;
217
217
  };
218
218
  };
219
219
  } & {
@@ -258,7 +258,7 @@ export declare const generateAppTypesPlugin: (sdk: {
258
258
  } & {
259
259
  context: {
260
260
  meta: {
261
- generateAppTypes: import("@zapier/zapier-sdk").PluginMeta;
261
+ generateAppTypes: import("@zapier/zapier-sdk").PluginMeta<unknown>;
262
262
  };
263
263
  };
264
264
  };
@@ -9,7 +9,7 @@ export declare const getLoginConfigPathPlugin: (sdk: {
9
9
  } & {
10
10
  context: {
11
11
  meta: {
12
- getLoginConfigPath: import("@zapier/zapier-sdk").PluginMeta;
12
+ getLoginConfigPath: import("@zapier/zapier-sdk").PluginMeta<unknown>;
13
13
  };
14
14
  };
15
15
  };
@@ -1,9 +1,10 @@
1
1
  export { loginPlugin } from "./login";
2
+ export { signupPlugin } from "./signup";
2
3
  export { logoutPlugin } from "./logout";
3
4
  export { mcpPlugin } from "./mcp";
4
5
  export { bundleCodePlugin } from "./bundleCode";
5
6
  export { getLoginConfigPathPlugin } from "./getLoginConfigPath";
6
- export { addPlugin } from "./add";
7
+ export { addAppsPlugin } from "./add";
7
8
  export { generateAppTypesPlugin } from "./generateAppTypes";
8
9
  export { buildManifestPlugin } from "./buildManifest";
9
10
  export { feedbackPlugin } from "./feedback";
@@ -1,9 +1,10 @@
1
1
  export { loginPlugin } from "./login";
2
+ export { signupPlugin } from "./signup";
2
3
  export { logoutPlugin } from "./logout";
3
4
  export { mcpPlugin } from "./mcp";
4
5
  export { bundleCodePlugin } from "./bundleCode";
5
6
  export { getLoginConfigPathPlugin } from "./getLoginConfigPath";
6
- export { addPlugin } from "./add";
7
+ export { addAppsPlugin } from "./add";
7
8
  export { generateAppTypesPlugin } from "./generateAppTypes";
8
9
  export { buildManifestPlugin } from "./buildManifest";
9
10
  export { feedbackPlugin } from "./feedback";
@@ -14,7 +14,7 @@ export declare const initPlugin: (sdk: {
14
14
  } & {
15
15
  context: {
16
16
  meta: {
17
- init: import("@zapier/zapier-sdk").PluginMeta;
17
+ init: import("@zapier/zapier-sdk").PluginMeta<unknown>;
18
18
  };
19
19
  };
20
20
  };
@@ -1,20 +1,8 @@
1
- import { type ApiClient, type ResolvedCredentials } from "@zapier/zapier-sdk";
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: CliContext;
5
+ context: AccountAuthCliContext;
18
6
  } & {
19
7
  context: {
20
8
  meta: Record<string, import("@zapier/zapier-sdk").PluginMeta>;
@@ -29,9 +17,8 @@ export declare const loginPlugin: (sdk: {
29
17
  } & {
30
18
  context: {
31
19
  meta: {
32
- login: import("@zapier/zapier-sdk").PluginMeta;
20
+ login: import("@zapier/zapier-sdk").PluginMeta<unknown>;
33
21
  };
34
22
  };
35
23
  };
36
24
  export type LoginPluginProvides = ReturnType<typeof loginPlugin>;
37
- export {};
@@ -1,200 +1,12 @@
1
- import { hostname } from "os";
2
- import { createPluginMethod, definePlugin, getOrCreateApiClient, isCredentialsObject, buildApplicationLifecycleEvent, } from "@zapier/zapier-sdk";
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
- const timeoutSeconds = parseTimeoutSeconds(options.timeout);
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
  }));
@@ -22,7 +22,7 @@ export declare const logoutPlugin: (sdk: {
22
22
  } & {
23
23
  context: {
24
24
  meta: {
25
- logout: import("@zapier/zapier-sdk").PluginMeta;
25
+ logout: import("@zapier/zapier-sdk").PluginMeta<unknown>;
26
26
  };
27
27
  };
28
28
  };
@@ -21,7 +21,7 @@ export declare const mcpPlugin: (sdk: {
21
21
  } & {
22
22
  context: {
23
23
  meta: {
24
- mcp: import("@zapier/zapier-sdk").PluginMeta;
24
+ mcp: import("@zapier/zapier-sdk").PluginMeta<unknown>;
25
25
  };
26
26
  };
27
27
  };