@zapier/zapier-sdk-cli 0.43.0 → 0.43.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cli.cjs +434 -519
  3. package/dist/cli.mjs +437 -522
  4. package/dist/index.cjs +436 -521
  5. package/dist/index.d.mts +395 -23
  6. package/dist/index.d.ts +395 -23
  7. package/dist/index.mjs +440 -525
  8. package/dist/package.json +1 -1
  9. package/dist/src/plugins/add/index.d.ts +250 -11
  10. package/dist/src/plugins/add/index.js +8 -16
  11. package/dist/src/plugins/buildManifest/index.d.ts +116 -9
  12. package/dist/src/plugins/buildManifest/index.js +14 -23
  13. package/dist/src/plugins/bundleCode/index.d.ts +19 -10
  14. package/dist/src/plugins/bundleCode/index.js +7 -17
  15. package/dist/src/plugins/cliOverrides/index.d.ts +12 -10
  16. package/dist/src/plugins/cliOverrides/index.js +16 -20
  17. package/dist/src/plugins/curl/index.d.ts +69 -10
  18. package/dist/src/plugins/curl/index.js +3 -2
  19. package/dist/src/plugins/feedback/index.d.ts +18 -13
  20. package/dist/src/plugins/feedback/index.js +17 -25
  21. package/dist/src/plugins/generateAppTypes/index.d.ts +261 -9
  22. package/dist/src/plugins/generateAppTypes/index.js +17 -45
  23. package/dist/src/plugins/getLoginConfigPath/index.d.ts +12 -10
  24. package/dist/src/plugins/getLoginConfigPath/index.js +8 -18
  25. package/dist/src/plugins/init/index.d.ts +15 -11
  26. package/dist/src/plugins/init/index.js +9 -17
  27. package/dist/src/plugins/login/index.d.ts +18 -13
  28. package/dist/src/plugins/login/index.js +9 -17
  29. package/dist/src/plugins/logout/index.d.ts +12 -11
  30. package/dist/src/plugins/logout/index.js +10 -16
  31. package/dist/src/plugins/mcp/index.d.ts +18 -15
  32. package/dist/src/plugins/mcp/index.js +9 -21
  33. package/dist/tsconfig.tsbuildinfo +1 -1
  34. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import Conf from 'conf';
2
2
  import * as fs from 'fs';
3
- import { existsSync, mkdirSync, writeFileSync, promises, createWriteStream, readdirSync, rmSync, copyFileSync, readFileSync } from 'fs';
3
+ import { promises, createWriteStream, existsSync, readdirSync, rmSync, mkdirSync, writeFileSync, copyFileSync, readFileSync } from 'fs';
4
4
  import * as jwt from 'jsonwebtoken';
5
- import { deletePassword, setPassword, getPassword, getKeyring } from 'cross-keychain';
5
+ import { getPassword, getKeyring, setPassword, deletePassword } from 'cross-keychain';
6
6
  import crypto, { createHash } from 'crypto';
7
7
  import * as path from 'path';
8
- import { dirname, resolve, join, basename, relative, extname } from 'path';
8
+ import { resolve, join, dirname, basename, relative, extname } from 'path';
9
9
  import * as lockfile from 'proper-lockfile';
10
- import { createFunction, OutputPropertySchema, DEFAULT_CONFIG_PATH, injectCliLogin, createZapierSdk, getOsInfo, getPlatformVersions, getCiPlatform, isCi, ZapierValidationError, ZapierUnknownError, getReleaseId, getCurrentTimestamp, generateEventId, batch, toSnakeCase, buildApplicationLifecycleEvent, ZapierError, isCredentialsObject } from '@zapier/zapier-sdk';
10
+ import { definePlugin, createPluginMethod, buildApplicationLifecycleEvent, OutputPropertySchema, DEFAULT_CONFIG_PATH, ZapierValidationError, ZapierUnknownError, injectCliLogin, isCredentialsObject, batch, toSnakeCase, ZapierError, createZapierSdk, getOsInfo, getPlatformVersions, getCiPlatform, isCi, getReleaseId, getCurrentTimestamp, generateEventId } from '@zapier/zapier-sdk';
11
11
  import open from 'open';
12
12
  import express from 'express';
13
13
  import pkceChallenge from 'pkce-challenge';
@@ -902,85 +902,65 @@ function toPkceCredentials(credentials) {
902
902
  }
903
903
  return void 0;
904
904
  }
905
- var loginPlugin = (sdk) => {
906
- const loginFn = async (options) => {
907
- const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
908
- if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
909
- throw new Error("Timeout must be a positive number");
910
- }
911
- const resolvedCredentials = await sdk.context.resolveCredentials();
912
- const pkceCredentials = toPkceCredentials(resolvedCredentials);
913
- await login_default({
914
- timeoutMs: timeoutSeconds * 1e3,
915
- credentials: pkceCredentials
916
- });
917
- const user = await getLoggedInUser();
918
- sdk.context.eventEmission.emit(
919
- "platform.sdk.ApplicationLifecycleEvent",
920
- buildApplicationLifecycleEvent(
921
- { lifecycle_event_type: "login_success" },
922
- { customuser_id: user.customUserId, account_id: user.accountId }
923
- )
924
- );
925
- console.log(`\u2705 Successfully logged in as ${user.email}`);
926
- };
927
- return {
928
- login: loginFn,
929
- context: {
930
- meta: {
931
- login: {
932
- categories: ["account"],
933
- inputSchema: LoginSchema,
934
- supportsJsonOutput: false
935
- }
905
+ var loginPlugin = definePlugin(
906
+ (sdk) => createPluginMethod(sdk, {
907
+ name: "login",
908
+ categories: ["account"],
909
+ inputSchema: LoginSchema,
910
+ supportsJsonOutput: false,
911
+ handler: async ({ sdk: sdk2, options }) => {
912
+ const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
913
+ if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
914
+ throw new Error("Timeout must be a positive number");
936
915
  }
916
+ const resolvedCredentials = await sdk2.context.resolveCredentials();
917
+ const pkceCredentials = toPkceCredentials(resolvedCredentials);
918
+ await login_default({
919
+ timeoutMs: timeoutSeconds * 1e3,
920
+ credentials: pkceCredentials
921
+ });
922
+ const user = await getLoggedInUser();
923
+ sdk2.context.eventEmission.emit(
924
+ "platform.sdk.ApplicationLifecycleEvent",
925
+ buildApplicationLifecycleEvent(
926
+ { lifecycle_event_type: "login_success" },
927
+ { customuser_id: user.customUserId, account_id: user.accountId }
928
+ )
929
+ );
930
+ console.log(`\u2705 Successfully logged in as ${user.email}`);
937
931
  }
938
- };
939
- };
932
+ })
933
+ );
940
934
  var LogoutSchema = z.object({}).describe("Log out of your Zapier account");
941
935
 
942
936
  // src/plugins/logout/index.ts
943
- var logoutWithSdk = createFunction(async function logoutWithSdk2(_options) {
944
- await logout();
945
- console.log("\u2705 Successfully logged out");
946
- }, LogoutSchema);
947
- var logoutPlugin = () => ({
948
- logout: logoutWithSdk,
949
- context: {
950
- meta: {
951
- logout: {
952
- categories: ["account"],
953
- inputSchema: LogoutSchema,
954
- supportsJsonOutput: false
955
- }
956
- }
957
- }
958
- });
937
+ var logoutPlugin = definePlugin(
938
+ (sdk) => createPluginMethod(sdk, {
939
+ name: "logout",
940
+ categories: ["account"],
941
+ inputSchema: LogoutSchema,
942
+ supportsJsonOutput: false,
943
+ handler: async () => {
944
+ await logout();
945
+ console.log("\u2705 Successfully logged out");
946
+ }
947
+ })
948
+ );
959
949
  var McpSchema = z.object({
960
950
  port: z.string().optional().describe("Port to listen on (for future HTTP transport)")
961
951
  }).describe("Start MCP server for Zapier SDK");
962
952
 
963
953
  // src/plugins/mcp/index.ts
964
- var mcpPlugin = (sdk) => {
965
- const mcpWithSdk = createFunction(async function mcpWithSdk2(options) {
966
- const mcpOptions = {
967
- ...options,
968
- debug: sdk.context.options?.debug
969
- };
970
- return await startMcpServer(mcpOptions);
971
- }, McpSchema);
972
- return {
973
- mcp: mcpWithSdk,
974
- context: {
975
- meta: {
976
- mcp: {
977
- categories: ["utility"],
978
- inputSchema: McpSchema
979
- }
980
- }
981
- }
982
- };
983
- };
954
+ var mcpPlugin = definePlugin(
955
+ (sdk) => createPluginMethod(sdk, {
956
+ name: "mcp",
957
+ categories: ["utility"],
958
+ inputSchema: McpSchema,
959
+ handler: async ({ sdk: sdk2, options }) => {
960
+ await startMcpServer({ ...options, debug: sdk2.context.options?.debug });
961
+ }
962
+ })
963
+ );
984
964
  var BundleCodeSchema = z.object({
985
965
  input: z.string().min(1).describe("Input TypeScript file path to bundle"),
986
966
  output: OutputPropertySchema.optional().describe(
@@ -991,22 +971,14 @@ var BundleCodeSchema = z.object({
991
971
  target: z.string().optional().describe("ECMAScript target version"),
992
972
  cjs: z.boolean().optional().describe("Output CommonJS format instead of ESM")
993
973
  }).describe("Bundle TypeScript code into executable JavaScript");
994
- var bundleCodePlugin = () => {
995
- const bundleCodeWithSdk = createFunction(async function bundleCodeWithSdk2(options) {
996
- return await bundleCode(options);
997
- }, BundleCodeSchema);
998
- return {
999
- bundleCode: bundleCodeWithSdk,
1000
- context: {
1001
- meta: {
1002
- bundleCode: {
1003
- categories: ["utility", "deprecated"],
1004
- inputSchema: BundleCodeSchema
1005
- }
1006
- }
1007
- }
1008
- };
1009
- };
974
+ var bundleCodePlugin = definePlugin(
975
+ (sdk) => createPluginMethod(sdk, {
976
+ name: "bundleCode",
977
+ categories: ["utility", "deprecated"],
978
+ inputSchema: BundleCodeSchema,
979
+ handler: async ({ options }) => bundleCode(options)
980
+ })
981
+ );
1010
982
  var ZapierBundleError = class extends Error {
1011
983
  constructor(message, details, originalError) {
1012
984
  super(message);
@@ -1073,25 +1045,14 @@ async function bundleCode(options) {
1073
1045
  }
1074
1046
  }
1075
1047
  var GetLoginConfigPathSchema = z.object({}).describe("Show the path to the login configuration file");
1076
- var getLoginConfigPathPlugin = () => {
1077
- const getLoginConfigPathWithSdk = createFunction(
1078
- async function getLoginConfigPathWithSdk2(_options) {
1079
- return getConfigPath();
1080
- },
1081
- GetLoginConfigPathSchema
1082
- );
1083
- return {
1084
- getLoginConfigPath: getLoginConfigPathWithSdk,
1085
- context: {
1086
- meta: {
1087
- getLoginConfigPath: {
1088
- categories: ["utility"],
1089
- inputSchema: GetLoginConfigPathSchema
1090
- }
1091
- }
1092
- }
1093
- };
1094
- };
1048
+ var getLoginConfigPathPlugin = definePlugin(
1049
+ (sdk) => createPluginMethod(sdk, {
1050
+ name: "getLoginConfigPath",
1051
+ categories: ["utility"],
1052
+ inputSchema: GetLoginConfigPathSchema,
1053
+ handler: async () => getConfigPath()
1054
+ })
1055
+ );
1095
1056
  var AddSchema = z.object({
1096
1057
  apps: z.array(z.string().min(1, "App key cannot be empty")).min(1, "At least one app key is required").describe(
1097
1058
  "One or more app keys to add (e.g., 'slack', 'github', 'trello')"
@@ -1119,111 +1080,105 @@ async function detectTypesOutputDirectory() {
1119
1080
  }
1120
1081
  return "./zapier/apps/";
1121
1082
  }
1122
- var addPlugin = (sdk) => {
1123
- const add = createFunction(async function add2(options) {
1124
- const {
1125
- apps: appKeys,
1126
- connections: connectionIds,
1127
- configPath,
1128
- typesOutput = await detectTypesOutputDirectory()
1129
- } = options;
1130
- const resolvedTypesOutput = resolve(typesOutput);
1131
- console.log(`\u{1F4E6} Adding ${appKeys.length} app(s)...`);
1132
- const appSlugAndKeyMap = /* @__PURE__ */ new Map();
1133
- const handleManifestProgress = (event) => {
1134
- switch (event.type) {
1135
- case "apps_lookup_start":
1136
- console.log(`\u{1F4E6} Looking up ${event.count} app(s)...`);
1137
- break;
1138
- case "app_found":
1139
- const displayName = event.app.slug ? `${event.app.slug} (${event.app.key})` : event.app.key;
1140
- appSlugAndKeyMap.set(event.app.key, displayName);
1141
- break;
1142
- case "apps_lookup_complete":
1143
- if (event.count === 0) {
1144
- console.warn("\u26A0\uFE0F No apps found");
1145
- }
1146
- break;
1147
- case "app_processing_start":
1148
- const appName = event.slug ? `${event.slug} (${event.app})` : event.app;
1149
- console.log(`\u{1F4E6} Adding ${appName}...`);
1150
- break;
1151
- case "manifest_updated":
1152
- const appDisplay = appSlugAndKeyMap.get(event.app) || event.app;
1153
- console.log(
1154
- `\u{1F4DD} Locked ${appDisplay} to ${event.app}@${event.version} using key '${event.manifestKey}'`
1155
- );
1156
- break;
1157
- case "app_processing_error":
1158
- const errorApp = appSlugAndKeyMap.get(event.app) || event.app;
1159
- console.warn(`\u26A0\uFE0F ${event.error} for ${errorApp}`);
1160
- break;
1161
- }
1162
- };
1163
- const handleTypesProgress = (event) => {
1164
- switch (event.type) {
1165
- case "connections_lookup_start":
1166
- console.log(`\u{1F510} Looking up ${event.count} connection(s)...`);
1167
- break;
1168
- case "connections_lookup_complete":
1169
- console.log(`\u{1F510} Found ${event.count} connection(s)`);
1170
- break;
1171
- case "connection_matched":
1172
- const appWithConnection = appSlugAndKeyMap.get(event.app) || event.app;
1173
- console.log(
1174
- `\u{1F510} Using connection ${event.connectionId} (${event.connectionTitle}) for ${appWithConnection}`
1175
- );
1176
- break;
1177
- case "connection_not_matched":
1178
- const appWithoutConnection = appSlugAndKeyMap.get(event.app) || event.app;
1179
- console.warn(
1180
- `\u26A0\uFE0F No matching connection found for ${appWithoutConnection}`
1181
- );
1182
- break;
1183
- case "file_written":
1184
- console.log(
1185
- `\u{1F527} Generated types for ${event.manifestKey} at ${event.filePath}`
1186
- );
1187
- break;
1188
- case "app_processing_error":
1189
- const errorApp = appSlugAndKeyMap.get(event.app) || event.app;
1190
- console.warn(`\u26A0\uFE0F ${event.error} for ${errorApp}`);
1191
- break;
1192
- }
1193
- };
1194
- const manifestResult = await sdk.buildManifest({
1195
- apps: appKeys,
1196
- skipWrite: false,
1197
- configPath,
1198
- onProgress: handleManifestProgress
1199
- });
1200
- const typesResult = await sdk.generateAppTypes({
1201
- apps: appKeys,
1202
- connections: connectionIds,
1203
- skipWrite: false,
1204
- typesOutputDirectory: resolvedTypesOutput,
1205
- onProgress: handleTypesProgress
1206
- });
1207
- const results = manifestResult.manifest?.apps || {};
1208
- const successfulApps = Object.keys(results).filter(
1209
- (manifestKey) => typesResult.writtenFiles?.[manifestKey]
1210
- );
1211
- if (successfulApps.length > 0) {
1212
- console.log(`\u2705 Added ${successfulApps.length} app(s) to manifest`);
1213
- }
1214
- }, AddSchema);
1215
- return {
1216
- add,
1217
- context: {
1218
- meta: {
1219
- add: {
1220
- categories: ["utility"],
1221
- inputSchema: AddSchema
1083
+ var addPlugin = definePlugin(
1084
+ (sdk) => createPluginMethod(sdk, {
1085
+ name: "add",
1086
+ categories: ["utility"],
1087
+ inputSchema: AddSchema,
1088
+ handler: async ({ sdk: sdk2, options }) => {
1089
+ const {
1090
+ apps: appKeys,
1091
+ connections: connectionIds,
1092
+ configPath,
1093
+ typesOutput = await detectTypesOutputDirectory()
1094
+ } = options;
1095
+ const resolvedTypesOutput = resolve(typesOutput);
1096
+ console.log(`\u{1F4E6} Adding ${appKeys.length} app(s)...`);
1097
+ const appSlugAndKeyMap = /* @__PURE__ */ new Map();
1098
+ const handleManifestProgress = (event) => {
1099
+ switch (event.type) {
1100
+ case "apps_lookup_start":
1101
+ console.log(`\u{1F4E6} Looking up ${event.count} app(s)...`);
1102
+ break;
1103
+ case "app_found":
1104
+ const displayName = event.app.slug ? `${event.app.slug} (${event.app.key})` : event.app.key;
1105
+ appSlugAndKeyMap.set(event.app.key, displayName);
1106
+ break;
1107
+ case "apps_lookup_complete":
1108
+ if (event.count === 0) {
1109
+ console.warn("\u26A0\uFE0F No apps found");
1110
+ }
1111
+ break;
1112
+ case "app_processing_start":
1113
+ const appName = event.slug ? `${event.slug} (${event.app})` : event.app;
1114
+ console.log(`\u{1F4E6} Adding ${appName}...`);
1115
+ break;
1116
+ case "manifest_updated":
1117
+ const appDisplay = appSlugAndKeyMap.get(event.app) || event.app;
1118
+ console.log(
1119
+ `\u{1F4DD} Locked ${appDisplay} to ${event.app}@${event.version} using key '${event.manifestKey}'`
1120
+ );
1121
+ break;
1122
+ case "app_processing_error":
1123
+ const errorApp = appSlugAndKeyMap.get(event.app) || event.app;
1124
+ console.warn(`\u26A0\uFE0F ${event.error} for ${errorApp}`);
1125
+ break;
1126
+ }
1127
+ };
1128
+ const handleTypesProgress = (event) => {
1129
+ switch (event.type) {
1130
+ case "connections_lookup_start":
1131
+ console.log(`\u{1F510} Looking up ${event.count} connection(s)...`);
1132
+ break;
1133
+ case "connections_lookup_complete":
1134
+ console.log(`\u{1F510} Found ${event.count} connection(s)`);
1135
+ break;
1136
+ case "connection_matched":
1137
+ const appWithConnection = appSlugAndKeyMap.get(event.app) || event.app;
1138
+ console.log(
1139
+ `\u{1F510} Using connection ${event.connectionId} (${event.connectionTitle}) for ${appWithConnection}`
1140
+ );
1141
+ break;
1142
+ case "connection_not_matched":
1143
+ const appWithoutConnection = appSlugAndKeyMap.get(event.app) || event.app;
1144
+ console.warn(
1145
+ `\u26A0\uFE0F No matching connection found for ${appWithoutConnection}`
1146
+ );
1147
+ break;
1148
+ case "file_written":
1149
+ console.log(
1150
+ `\u{1F527} Generated types for ${event.manifestKey} at ${event.filePath}`
1151
+ );
1152
+ break;
1153
+ case "app_processing_error":
1154
+ const errorApp = appSlugAndKeyMap.get(event.app) || event.app;
1155
+ console.warn(`\u26A0\uFE0F ${event.error} for ${errorApp}`);
1156
+ break;
1222
1157
  }
1158
+ };
1159
+ const manifestResult = await sdk2.buildManifest({
1160
+ apps: appKeys,
1161
+ skipWrite: false,
1162
+ configPath,
1163
+ onProgress: handleManifestProgress
1164
+ });
1165
+ const typesResult = await sdk2.generateAppTypes({
1166
+ apps: appKeys,
1167
+ connections: connectionIds,
1168
+ skipWrite: false,
1169
+ typesOutputDirectory: resolvedTypesOutput,
1170
+ onProgress: handleTypesProgress
1171
+ });
1172
+ const results = manifestResult.manifest?.apps || {};
1173
+ const successfulApps = Object.keys(results).filter(
1174
+ (manifestKey) => typesResult.writtenFiles?.[manifestKey]
1175
+ );
1176
+ if (successfulApps.length > 0) {
1177
+ console.log(`\u2705 Added ${successfulApps.length} app(s) to manifest`);
1223
1178
  }
1224
1179
  }
1225
- };
1226
- };
1180
+ })
1181
+ );
1227
1182
  var GenerateAppTypesSchema = z.object({
1228
1183
  apps: z.array(z.string().min(1, "App key cannot be empty")).min(1, "At least one app key is required").describe(
1229
1184
  "One or more app keys to generate types for (e.g., 'slack', 'github', 'trello')"
@@ -1830,150 +1785,133 @@ function createManifestEntry(app) {
1830
1785
  version: app.version
1831
1786
  };
1832
1787
  }
1833
- var generateAppTypesPlugin = (sdk) => {
1834
- const generateAppTypes = createFunction(async function generateAppTypes2(options) {
1835
- const {
1836
- apps: appKeys,
1837
- connections: connectionIds,
1838
- skipWrite = false,
1839
- typesOutputDirectory = await detectTypesOutputDirectory(),
1840
- onProgress
1841
- } = options;
1842
- const resolvedTypesOutput = resolve(typesOutputDirectory);
1843
- const result = {
1844
- typeDefinitions: {}
1845
- };
1846
- onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
1847
- const appsIterable = sdk.listApps({ apps: appKeys }).items();
1848
- const apps = [];
1849
- for await (const app of appsIterable) {
1850
- apps.push(app);
1851
- onProgress?.({ type: "app_found", app });
1852
- }
1853
- onProgress?.({ type: "apps_lookup_complete", count: apps.length });
1854
- if (apps.length === 0) {
1855
- return result;
1856
- }
1857
- const connections = [];
1858
- if (connectionIds && connectionIds.length > 0) {
1859
- onProgress?.({
1860
- type: "connections_lookup_start",
1861
- count: connectionIds.length
1862
- });
1863
- const connectionsIterable = sdk.listConnections({ connections: connectionIds }).items();
1864
- for await (const connection of connectionsIterable) {
1865
- connections.push(connection);
1788
+ var generateAppTypesPlugin = definePlugin(
1789
+ (sdk) => createPluginMethod(sdk, {
1790
+ name: "generateAppTypes",
1791
+ categories: ["utility"],
1792
+ // Cast: schema validates JSON fields only; GenerateAppTypesOptions adds
1793
+ // the runtime-only `onProgress` callback (passthrough via createFunction).
1794
+ inputSchema: GenerateAppTypesSchema,
1795
+ handler: async ({ sdk: sdk2, options }) => {
1796
+ const {
1797
+ apps: appKeys,
1798
+ connections: connectionIds,
1799
+ skipWrite = false,
1800
+ typesOutputDirectory = await detectTypesOutputDirectory(),
1801
+ onProgress
1802
+ } = options;
1803
+ const resolvedTypesOutput = resolve(typesOutputDirectory);
1804
+ const result = { typeDefinitions: {} };
1805
+ onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
1806
+ const appsIterable = sdk2.listApps({ apps: appKeys }).items();
1807
+ const apps = [];
1808
+ for await (const app of appsIterable) {
1809
+ apps.push(app);
1810
+ onProgress?.({ type: "app_found", app });
1866
1811
  }
1867
- onProgress?.({
1868
- type: "connections_lookup_complete",
1869
- count: connections.length
1870
- });
1871
- }
1872
- if (!skipWrite && resolvedTypesOutput) {
1873
- await mkdir(resolvedTypesOutput, { recursive: true });
1874
- }
1875
- if (!skipWrite) {
1876
- result.writtenFiles = {};
1877
- }
1878
- for (const app of apps) {
1879
- onProgress?.({
1880
- type: "app_processing_start",
1881
- app: app.key,
1882
- slug: app.slug
1883
- });
1884
- try {
1885
- if (!app.version) {
1886
- const errorMessage = `Invalid implementation ID format: ${app.implementation_id}. Expected format: <implementationName>@<version>`;
1887
- onProgress?.({
1888
- type: "app_processing_error",
1889
- app: app.key,
1890
- error: errorMessage
1891
- });
1892
- throw new ZapierValidationError(errorMessage, {
1893
- details: {
1894
- appKey: app.key,
1895
- implementationId: app.implementation_id
1896
- }
1897
- });
1812
+ onProgress?.({ type: "apps_lookup_complete", count: apps.length });
1813
+ if (apps.length === 0) {
1814
+ return result;
1815
+ }
1816
+ const connections = [];
1817
+ if (connectionIds && connectionIds.length > 0) {
1818
+ onProgress?.({
1819
+ type: "connections_lookup_start",
1820
+ count: connectionIds.length
1821
+ });
1822
+ const connectionsIterable = sdk2.listConnections({ connections: connectionIds }).items();
1823
+ for await (const connection of connectionsIterable) {
1824
+ connections.push(connection);
1898
1825
  }
1899
- let connectionId;
1900
- if (connections.length > 0) {
1901
- const matchingConnection = connections.find((conn) => {
1902
- return conn.app_key === app.key;
1903
- });
1904
- if (matchingConnection) {
1905
- connectionId = matchingConnection.id;
1826
+ onProgress?.({
1827
+ type: "connections_lookup_complete",
1828
+ count: connections.length
1829
+ });
1830
+ }
1831
+ if (!skipWrite && resolvedTypesOutput) {
1832
+ await mkdir(resolvedTypesOutput, { recursive: true });
1833
+ }
1834
+ if (!skipWrite) {
1835
+ result.writtenFiles = {};
1836
+ }
1837
+ for (const app of apps) {
1838
+ onProgress?.({
1839
+ type: "app_processing_start",
1840
+ app: app.key,
1841
+ slug: app.slug
1842
+ });
1843
+ try {
1844
+ if (!app.version) {
1845
+ const errorMessage = `Invalid implementation ID format: ${app.implementation_id}. Expected format: <implementationName>@<version>`;
1906
1846
  onProgress?.({
1907
- type: "connection_matched",
1847
+ type: "app_processing_error",
1908
1848
  app: app.key,
1909
- connectionId: matchingConnection.id,
1910
- connectionTitle: matchingConnection.title || ""
1849
+ error: errorMessage
1911
1850
  });
1912
- } else {
1913
- onProgress?.({
1914
- type: "connection_not_matched",
1915
- app: app.key
1851
+ throw new ZapierValidationError(errorMessage, {
1852
+ details: {
1853
+ appKey: app.key,
1854
+ implementationId: app.implementation_id
1855
+ }
1916
1856
  });
1917
1857
  }
1918
- }
1919
- const manifestKey = getManifestKey(app);
1920
- const generator = new AstTypeGenerator();
1921
- const typeDefinitionString = await generator.generateTypes({
1922
- app,
1923
- connectionId,
1924
- sdk
1925
- });
1926
- result.typeDefinitions[manifestKey] = typeDefinitionString;
1927
- onProgress?.({
1928
- type: "type_generated",
1929
- manifestKey,
1930
- sizeBytes: typeDefinitionString.length
1931
- });
1932
- if (!skipWrite && resolvedTypesOutput && result.writtenFiles) {
1933
- const filePath = join(resolvedTypesOutput, `${manifestKey}.d.ts`);
1934
- await writeFile(filePath, typeDefinitionString, "utf8");
1935
- result.writtenFiles[manifestKey] = filePath;
1858
+ let connectionId;
1859
+ if (connections.length > 0) {
1860
+ const matchingConnection = connections.find(
1861
+ (conn) => conn.app_key === app.key
1862
+ );
1863
+ if (matchingConnection) {
1864
+ connectionId = matchingConnection.id;
1865
+ onProgress?.({
1866
+ type: "connection_matched",
1867
+ app: app.key,
1868
+ connectionId: matchingConnection.id,
1869
+ connectionTitle: matchingConnection.title || ""
1870
+ });
1871
+ } else {
1872
+ onProgress?.({
1873
+ type: "connection_not_matched",
1874
+ app: app.key
1875
+ });
1876
+ }
1877
+ }
1878
+ const manifestKey = getManifestKey(app);
1879
+ const generator = new AstTypeGenerator();
1880
+ const typeDefinitionString = await generator.generateTypes({
1881
+ app,
1882
+ connectionId,
1883
+ sdk: sdk2
1884
+ });
1885
+ result.typeDefinitions[manifestKey] = typeDefinitionString;
1936
1886
  onProgress?.({
1937
- type: "file_written",
1887
+ type: "type_generated",
1938
1888
  manifestKey,
1939
- filePath
1889
+ sizeBytes: typeDefinitionString.length
1940
1890
  });
1941
- }
1942
- onProgress?.({
1943
- type: "app_processing_complete",
1944
- app: app.key
1945
- });
1946
- } catch (error) {
1947
- const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
1948
- onProgress?.({
1949
- type: "app_processing_error",
1950
- app: app.key,
1951
- error: errorMessage
1952
- });
1953
- if (error instanceof ZapierValidationError) {
1954
- throw error;
1955
- } else {
1956
- throw new ZapierUnknownError(errorMessage, {
1957
- cause: error
1958
- // Works for both Error and non-Error
1891
+ if (!skipWrite && resolvedTypesOutput && result.writtenFiles) {
1892
+ const filePath = join(resolvedTypesOutput, `${manifestKey}.d.ts`);
1893
+ await writeFile(filePath, typeDefinitionString, "utf8");
1894
+ result.writtenFiles[manifestKey] = filePath;
1895
+ onProgress?.({ type: "file_written", manifestKey, filePath });
1896
+ }
1897
+ onProgress?.({ type: "app_processing_complete", app: app.key });
1898
+ } catch (error) {
1899
+ const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
1900
+ onProgress?.({
1901
+ type: "app_processing_error",
1902
+ app: app.key,
1903
+ error: errorMessage
1959
1904
  });
1905
+ if (error instanceof ZapierValidationError) {
1906
+ throw error;
1907
+ }
1908
+ throw new ZapierUnknownError(errorMessage, { cause: error });
1960
1909
  }
1961
1910
  }
1911
+ return result;
1962
1912
  }
1963
- return result;
1964
- }, GenerateAppTypesSchema);
1965
- return {
1966
- generateAppTypes,
1967
- context: {
1968
- meta: {
1969
- generateAppTypes: {
1970
- categories: ["utility"],
1971
- inputSchema: GenerateAppTypesSchema
1972
- }
1973
- }
1974
- }
1975
- };
1976
- };
1913
+ })
1914
+ );
1977
1915
  var BuildManifestSchema = z.object({
1978
1916
  apps: z.array(z.string().min(1, "App key cannot be empty")).min(1, "At least one app key is required").describe(
1979
1917
  "One or more app keys to build manifest entries for (e.g., 'slack', 'github', 'trello')"
@@ -1989,86 +1927,80 @@ var BuildManifestSchema = z.object({
1989
1927
  );
1990
1928
 
1991
1929
  // src/plugins/buildManifest/index.ts
1992
- var buildManifestPlugin = (sdk) => {
1993
- const buildManifest = createFunction(async function buildManifest2(options) {
1994
- const {
1995
- apps: appKeys,
1996
- skipWrite = false,
1997
- configPath,
1998
- onProgress
1999
- } = options;
2000
- onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
2001
- const appsIterable = sdk.listApps({ apps: appKeys }).items();
2002
- const apps = [];
2003
- for await (const app of appsIterable) {
2004
- apps.push(app);
2005
- onProgress?.({ type: "app_found", app });
2006
- }
2007
- onProgress?.({ type: "apps_lookup_complete", count: apps.length });
2008
- if (apps.length === 0) {
2009
- return {};
2010
- }
2011
- let updatedManifest;
2012
- for (const app of apps) {
2013
- onProgress?.({
2014
- type: "app_processing_start",
2015
- app: app.key,
2016
- slug: app.slug
2017
- });
2018
- try {
2019
- const manifestEntry = createManifestEntry(app);
2020
- onProgress?.({
2021
- type: "manifest_entry_built",
2022
- app: app.key,
2023
- manifestKey: manifestEntry.implementationName,
2024
- version: manifestEntry.version || ""
2025
- });
2026
- const { key: updatedManifestKey, manifest } = await sdk.context.updateManifestEntry({
2027
- appKey: app.key,
2028
- entry: manifestEntry,
2029
- configPath,
2030
- skipWrite,
2031
- manifest: updatedManifest
2032
- });
2033
- updatedManifest = manifest;
2034
- onProgress?.({
2035
- type: "manifest_updated",
2036
- app: app.key,
2037
- manifestKey: updatedManifestKey,
2038
- version: manifestEntry.version || ""
2039
- });
2040
- onProgress?.({ type: "app_processing_complete", app: app.key });
2041
- } catch (error) {
2042
- const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
1930
+ var buildManifestPlugin = definePlugin(
1931
+ (sdk) => createPluginMethod(sdk, {
1932
+ name: "buildManifest",
1933
+ categories: ["utility"],
1934
+ // Cast: BuildManifestSchema validates JSON-serializable fields only.
1935
+ // BuildManifestOptions adds an `onProgress` callback that rides through
1936
+ // `createFunction`'s passthrough spread at runtime; this widens TInput
1937
+ // so the handler can read it.
1938
+ inputSchema: BuildManifestSchema,
1939
+ handler: async ({ sdk: sdk2, options }) => {
1940
+ const {
1941
+ apps: appKeys,
1942
+ skipWrite = false,
1943
+ configPath,
1944
+ onProgress
1945
+ } = options;
1946
+ onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
1947
+ const appsIterable = sdk2.listApps({ apps: appKeys }).items();
1948
+ const apps = [];
1949
+ for await (const app of appsIterable) {
1950
+ apps.push(app);
1951
+ onProgress?.({ type: "app_found", app });
1952
+ }
1953
+ onProgress?.({ type: "apps_lookup_complete", count: apps.length });
1954
+ if (apps.length === 0) {
1955
+ return {};
1956
+ }
1957
+ let updatedManifest;
1958
+ for (const app of apps) {
2043
1959
  onProgress?.({
2044
- type: "app_processing_error",
1960
+ type: "app_processing_start",
2045
1961
  app: app.key,
2046
- error: errorMessage
1962
+ slug: app.slug
2047
1963
  });
2048
- if (error instanceof ZapierValidationError) {
2049
- throw error;
2050
- } else {
2051
- throw new ZapierUnknownError(errorMessage, {
2052
- cause: error
2053
- // Works for both Error and non-Error
1964
+ try {
1965
+ const manifestEntry = createManifestEntry(app);
1966
+ onProgress?.({
1967
+ type: "manifest_entry_built",
1968
+ app: app.key,
1969
+ manifestKey: manifestEntry.implementationName,
1970
+ version: manifestEntry.version || ""
2054
1971
  });
1972
+ const { key: updatedManifestKey, manifest } = await sdk2.context.updateManifestEntry({
1973
+ appKey: app.key,
1974
+ entry: manifestEntry,
1975
+ configPath,
1976
+ skipWrite,
1977
+ manifest: updatedManifest
1978
+ });
1979
+ updatedManifest = manifest;
1980
+ onProgress?.({
1981
+ type: "manifest_updated",
1982
+ app: app.key,
1983
+ manifestKey: updatedManifestKey,
1984
+ version: manifestEntry.version || ""
1985
+ });
1986
+ onProgress?.({ type: "app_processing_complete", app: app.key });
1987
+ } catch (error) {
1988
+ const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
1989
+ onProgress?.({
1990
+ type: "app_processing_error",
1991
+ app: app.key,
1992
+ error: errorMessage
1993
+ });
1994
+ if (error instanceof ZapierValidationError) {
1995
+ throw error;
1996
+ }
1997
+ throw new ZapierUnknownError(errorMessage, { cause: error });
2055
1998
  }
2056
1999
  }
2000
+ return { manifest: updatedManifest };
2057
2001
  }
2058
- return { manifest: updatedManifest };
2059
- }, BuildManifestSchema);
2060
- return {
2061
- buildManifest,
2062
- context: {
2063
- meta: {
2064
- buildManifest: {
2065
- categories: ["utility"],
2066
- inputSchema: BuildManifestSchema
2067
- }
2068
- }
2069
- }
2070
- };
2071
- };
2002
+ })
2003
+ );
2072
2004
  var FeedbackSchema = z.object({
2073
2005
  feedback: z.string().describe(
2074
2006
  "Your feedback on the Zapier SDK. Describe what worked well, what was frustrating, or any suggestions."
@@ -2102,37 +2034,31 @@ async function postWithRetry({
2102
2034
  }
2103
2035
  return response;
2104
2036
  }
2105
- var feedbackPlugin = (sdk) => {
2106
- const debug = sdk.context.options?.debug;
2107
- const feedbackWithSdk = createFunction(async function feedback(options) {
2108
- const user = await getLoggedInUser();
2109
- const body = JSON.stringify({
2110
- email: user.email,
2111
- customuser_id: user.customUserId,
2112
- feedback: options.feedback
2113
- });
2114
- const response = await postWithRetry({ body, attemptsLeft: MAX_RETRIES });
2115
- if (debug) {
2116
- const text = await response.text();
2117
- console.error("[debug] Webhook response:", text);
2118
- }
2119
- return "Thank you for your feedback!";
2120
- }, FeedbackSchema);
2121
- return {
2122
- feedback: feedbackWithSdk,
2123
- context: {
2124
- meta: {
2125
- feedback: {
2126
- categories: ["utility"],
2127
- inputSchema: FeedbackSchema,
2128
- resolvers: {
2129
- feedback: feedbackResolver
2130
- }
2131
- }
2037
+ var feedbackPlugin = definePlugin(
2038
+ (sdk) => createPluginMethod(sdk, {
2039
+ name: "feedback",
2040
+ categories: ["utility"],
2041
+ inputSchema: FeedbackSchema,
2042
+ resolvers: { feedback: feedbackResolver },
2043
+ handler: async ({ sdk: sdk2, options }) => {
2044
+ const user = await getLoggedInUser();
2045
+ const body = JSON.stringify({
2046
+ email: user.email,
2047
+ customuser_id: user.customUserId,
2048
+ feedback: options.feedback
2049
+ });
2050
+ const response = await postWithRetry({
2051
+ body,
2052
+ attemptsLeft: MAX_RETRIES
2053
+ });
2054
+ if (sdk2.context.options?.debug) {
2055
+ const text = await response.text();
2056
+ console.error("[debug] Webhook response:", text);
2132
2057
  }
2058
+ return "Thank you for your feedback!";
2133
2059
  }
2134
- };
2135
- };
2060
+ })
2061
+ );
2136
2062
  var CurlSchema = z.object({
2137
2063
  url: z.string().describe("Request URL"),
2138
2064
  request: z.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]).optional().describe("HTTP method (defaults to GET, or POST if data is provided)"),
@@ -2308,7 +2234,7 @@ async function buildFormData(formArgs, formStringArgs) {
2308
2234
  }
2309
2235
 
2310
2236
  // src/plugins/curl/index.ts
2311
- var curlPlugin = (sdk) => {
2237
+ var curlPlugin = definePlugin((sdk) => {
2312
2238
  async function curl(options) {
2313
2239
  const {
2314
2240
  url: rawUrl,
@@ -2551,30 +2477,25 @@ ${Array.from(
2551
2477
  }
2552
2478
  }
2553
2479
  };
2554
- };
2555
-
2556
- // src/plugins/cliOverrides/index.ts
2557
- var cliOverridesPlugin = (sdk) => {
2558
- if (!sdk.context.meta.fetch) {
2559
- return { context: { meta: {} } };
2560
- }
2561
- return {
2562
- context: {
2563
- meta: {
2564
- fetch: {
2565
- ...sdk.context.meta.fetch,
2566
- categories: [
2567
- ...sdk.context.meta.fetch.categories || [],
2568
- "deprecated"
2569
- ],
2570
- deprecation: {
2571
- message: "This command is deprecated and will be removed soon. Use `curl` instead. Learn more: https://docs.zapier.com/sdk/cli-reference#curl"
2572
- }
2480
+ });
2481
+ var cliOverridesPlugin = definePlugin(
2482
+ (sdk) => {
2483
+ const meta = {};
2484
+ if (sdk.context.meta.fetch) {
2485
+ meta.fetch = {
2486
+ ...sdk.context.meta.fetch,
2487
+ categories: [
2488
+ ...sdk.context.meta.fetch.categories || [],
2489
+ "deprecated"
2490
+ ],
2491
+ deprecation: {
2492
+ message: "This command is deprecated and will be removed soon. Use `curl` instead. Learn more: https://docs.zapier.com/sdk/cli-reference#curl"
2573
2493
  }
2574
- }
2494
+ };
2575
2495
  }
2576
- };
2577
- };
2496
+ return { context: { meta } };
2497
+ }
2498
+ );
2578
2499
  var TEMPLATES = ["basic"];
2579
2500
  var InitSchema = z.object({
2580
2501
  projectName: z.string().min(1).describe("Name of the project directory to create"),
@@ -2986,71 +2907,65 @@ function displaySummaryAndNextSteps({
2986
2907
  }
2987
2908
 
2988
2909
  // src/plugins/init/index.ts
2989
- var initPlugin = () => {
2990
- const init = createFunction(async function init2(options) {
2991
- const { projectName: rawName, skipPrompts = false } = options;
2992
- const cwd = process.cwd();
2993
- const { projectName, projectDir } = validateInitOptions({ rawName, cwd });
2994
- const displayHooks = createConsoleDisplayHooks();
2995
- const packageManagerInfo = detectPackageManager(cwd);
2996
- if (packageManagerInfo.name === "unknown") {
2997
- displayHooks.onWarn(
2998
- "Could not detect package manager, defaulting to npm."
2999
- );
3000
- }
3001
- const packageManager = packageManagerInfo.name === "unknown" ? "npm" : packageManagerInfo.name;
3002
- const steps = getInitSteps({
3003
- projectDir,
3004
- projectName,
3005
- packageManager,
3006
- displayHooks
3007
- });
3008
- const completedSetupStepIds = [];
3009
- for (let i = 0; i < steps.length; i++) {
3010
- const step = steps[i];
3011
- const succeeded = await withInterruptCleanup(
3012
- step.cleanup,
3013
- () => runStep({
3014
- step,
3015
- stepNumber: i + 1,
3016
- totalSteps: steps.length,
3017
- skipPrompts,
3018
- displayHooks
3019
- })
3020
- );
3021
- if (!succeeded) break;
3022
- completedSetupStepIds.push(step.id);
3023
- }
3024
- if (completedSetupStepIds.length === 0) {
3025
- throw new ZapierCliExitError(
3026
- "Project setup failed \u2014 no steps completed."
3027
- );
3028
- }
3029
- displaySummaryAndNextSteps({
3030
- projectName,
3031
- steps,
3032
- completedSetupStepIds,
3033
- packageManager
3034
- });
3035
- }, InitSchema);
3036
- return {
3037
- init,
3038
- context: {
3039
- meta: {
3040
- init: {
3041
- categories: ["utility"],
3042
- inputSchema: InitSchema,
3043
- supportsJsonOutput: false
3044
- }
2910
+ var initPlugin = definePlugin(
2911
+ (sdk) => createPluginMethod(sdk, {
2912
+ name: "init",
2913
+ categories: ["utility"],
2914
+ inputSchema: InitSchema,
2915
+ supportsJsonOutput: false,
2916
+ handler: async ({ options }) => {
2917
+ const { projectName: rawName, skipPrompts = false } = options;
2918
+ const cwd = process.cwd();
2919
+ const { projectName, projectDir } = validateInitOptions({ rawName, cwd });
2920
+ const displayHooks = createConsoleDisplayHooks();
2921
+ const packageManagerInfo = detectPackageManager(cwd);
2922
+ if (packageManagerInfo.name === "unknown") {
2923
+ displayHooks.onWarn(
2924
+ "Could not detect package manager, defaulting to npm."
2925
+ );
2926
+ }
2927
+ const packageManager = packageManagerInfo.name === "unknown" ? "npm" : packageManagerInfo.name;
2928
+ const steps = getInitSteps({
2929
+ projectDir,
2930
+ projectName,
2931
+ packageManager,
2932
+ displayHooks
2933
+ });
2934
+ const completedSetupStepIds = [];
2935
+ for (let i = 0; i < steps.length; i++) {
2936
+ const step = steps[i];
2937
+ const succeeded = await withInterruptCleanup(
2938
+ step.cleanup,
2939
+ () => runStep({
2940
+ step,
2941
+ stepNumber: i + 1,
2942
+ totalSteps: steps.length,
2943
+ skipPrompts,
2944
+ displayHooks
2945
+ })
2946
+ );
2947
+ if (!succeeded) break;
2948
+ completedSetupStepIds.push(step.id);
3045
2949
  }
2950
+ if (completedSetupStepIds.length === 0) {
2951
+ throw new ZapierCliExitError(
2952
+ "Project setup failed \u2014 no steps completed."
2953
+ );
2954
+ }
2955
+ displaySummaryAndNextSteps({
2956
+ projectName,
2957
+ steps,
2958
+ completedSetupStepIds,
2959
+ packageManager
2960
+ });
3046
2961
  }
3047
- };
3048
- };
2962
+ })
2963
+ );
3049
2964
 
3050
2965
  // package.json with { type: 'json' }
3051
2966
  var package_default = {
3052
2967
  name: "@zapier/zapier-sdk-cli",
3053
- version: "0.43.0"};
2968
+ version: "0.43.1"};
3054
2969
 
3055
2970
  // src/sdk.ts
3056
2971
  injectCliLogin(login_exports);
@@ -3064,7 +2979,7 @@ function createZapierCliSdk(options = {}) {
3064
2979
 
3065
2980
  // package.json
3066
2981
  var package_default2 = {
3067
- version: "0.43.0"};
2982
+ version: "0.43.1"};
3068
2983
 
3069
2984
  // src/telemetry/builders.ts
3070
2985
  function createCliBaseEvent(context = {}) {