@zapier/zapier-sdk-cli 0.43.0 → 0.43.3

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 +26 -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 +2 -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 +4 -3
package/dist/index.cjs CHANGED
@@ -938,85 +938,65 @@ function toPkceCredentials(credentials) {
938
938
  }
939
939
  return void 0;
940
940
  }
941
- var loginPlugin = (sdk) => {
942
- const loginFn = async (options) => {
943
- const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
944
- if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
945
- throw new Error("Timeout must be a positive number");
946
- }
947
- const resolvedCredentials = await sdk.context.resolveCredentials();
948
- const pkceCredentials = toPkceCredentials(resolvedCredentials);
949
- await login_default({
950
- timeoutMs: timeoutSeconds * 1e3,
951
- credentials: pkceCredentials
952
- });
953
- const user = await getLoggedInUser();
954
- sdk.context.eventEmission.emit(
955
- "platform.sdk.ApplicationLifecycleEvent",
956
- zapierSdk.buildApplicationLifecycleEvent(
957
- { lifecycle_event_type: "login_success" },
958
- { customuser_id: user.customUserId, account_id: user.accountId }
959
- )
960
- );
961
- console.log(`\u2705 Successfully logged in as ${user.email}`);
962
- };
963
- return {
964
- login: loginFn,
965
- context: {
966
- meta: {
967
- login: {
968
- categories: ["account"],
969
- inputSchema: LoginSchema,
970
- supportsJsonOutput: false
971
- }
941
+ var loginPlugin = zapierSdk.definePlugin(
942
+ (sdk) => zapierSdk.createPluginMethod(sdk, {
943
+ name: "login",
944
+ categories: ["account"],
945
+ inputSchema: LoginSchema,
946
+ supportsJsonOutput: false,
947
+ handler: async ({ sdk: sdk2, options }) => {
948
+ const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
949
+ if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
950
+ throw new Error("Timeout must be a positive number");
972
951
  }
952
+ const resolvedCredentials = await sdk2.context.resolveCredentials();
953
+ const pkceCredentials = toPkceCredentials(resolvedCredentials);
954
+ await login_default({
955
+ timeoutMs: timeoutSeconds * 1e3,
956
+ credentials: pkceCredentials
957
+ });
958
+ const user = await getLoggedInUser();
959
+ sdk2.context.eventEmission.emit(
960
+ "platform.sdk.ApplicationLifecycleEvent",
961
+ zapierSdk.buildApplicationLifecycleEvent(
962
+ { lifecycle_event_type: "login_success" },
963
+ { customuser_id: user.customUserId, account_id: user.accountId }
964
+ )
965
+ );
966
+ console.log(`\u2705 Successfully logged in as ${user.email}`);
973
967
  }
974
- };
975
- };
968
+ })
969
+ );
976
970
  var LogoutSchema = zod.z.object({}).describe("Log out of your Zapier account");
977
971
 
978
972
  // src/plugins/logout/index.ts
979
- var logoutWithSdk = zapierSdk.createFunction(async function logoutWithSdk2(_options) {
980
- await logout();
981
- console.log("\u2705 Successfully logged out");
982
- }, LogoutSchema);
983
- var logoutPlugin = () => ({
984
- logout: logoutWithSdk,
985
- context: {
986
- meta: {
987
- logout: {
988
- categories: ["account"],
989
- inputSchema: LogoutSchema,
990
- supportsJsonOutput: false
991
- }
992
- }
993
- }
994
- });
973
+ var logoutPlugin = zapierSdk.definePlugin(
974
+ (sdk) => zapierSdk.createPluginMethod(sdk, {
975
+ name: "logout",
976
+ categories: ["account"],
977
+ inputSchema: LogoutSchema,
978
+ supportsJsonOutput: false,
979
+ handler: async () => {
980
+ await logout();
981
+ console.log("\u2705 Successfully logged out");
982
+ }
983
+ })
984
+ );
995
985
  var McpSchema = zod.z.object({
996
986
  port: zod.z.string().optional().describe("Port to listen on (for future HTTP transport)")
997
987
  }).describe("Start MCP server for Zapier SDK");
998
988
 
999
989
  // src/plugins/mcp/index.ts
1000
- var mcpPlugin = (sdk) => {
1001
- const mcpWithSdk = zapierSdk.createFunction(async function mcpWithSdk2(options) {
1002
- const mcpOptions = {
1003
- ...options,
1004
- debug: sdk.context.options?.debug
1005
- };
1006
- return await zapierSdkMcp.startMcpServer(mcpOptions);
1007
- }, McpSchema);
1008
- return {
1009
- mcp: mcpWithSdk,
1010
- context: {
1011
- meta: {
1012
- mcp: {
1013
- categories: ["utility"],
1014
- inputSchema: McpSchema
1015
- }
1016
- }
1017
- }
1018
- };
1019
- };
990
+ var mcpPlugin = zapierSdk.definePlugin(
991
+ (sdk) => zapierSdk.createPluginMethod(sdk, {
992
+ name: "mcp",
993
+ categories: ["utility"],
994
+ inputSchema: McpSchema,
995
+ handler: async ({ sdk: sdk2, options }) => {
996
+ await zapierSdkMcp.startMcpServer({ ...options, debug: sdk2.context.options?.debug });
997
+ }
998
+ })
999
+ );
1020
1000
  var BundleCodeSchema = zod.z.object({
1021
1001
  input: zod.z.string().min(1).describe("Input TypeScript file path to bundle"),
1022
1002
  output: zapierSdk.OutputPropertySchema.optional().describe(
@@ -1027,22 +1007,14 @@ var BundleCodeSchema = zod.z.object({
1027
1007
  target: zod.z.string().optional().describe("ECMAScript target version"),
1028
1008
  cjs: zod.z.boolean().optional().describe("Output CommonJS format instead of ESM")
1029
1009
  }).describe("Bundle TypeScript code into executable JavaScript");
1030
- var bundleCodePlugin = () => {
1031
- const bundleCodeWithSdk = zapierSdk.createFunction(async function bundleCodeWithSdk2(options) {
1032
- return await bundleCode(options);
1033
- }, BundleCodeSchema);
1034
- return {
1035
- bundleCode: bundleCodeWithSdk,
1036
- context: {
1037
- meta: {
1038
- bundleCode: {
1039
- categories: ["utility", "deprecated"],
1040
- inputSchema: BundleCodeSchema
1041
- }
1042
- }
1043
- }
1044
- };
1045
- };
1010
+ var bundleCodePlugin = zapierSdk.definePlugin(
1011
+ (sdk) => zapierSdk.createPluginMethod(sdk, {
1012
+ name: "bundleCode",
1013
+ categories: ["utility", "deprecated"],
1014
+ inputSchema: BundleCodeSchema,
1015
+ handler: async ({ options }) => bundleCode(options)
1016
+ })
1017
+ );
1046
1018
  var ZapierBundleError = class extends Error {
1047
1019
  constructor(message, details, originalError) {
1048
1020
  super(message);
@@ -1109,25 +1081,14 @@ async function bundleCode(options) {
1109
1081
  }
1110
1082
  }
1111
1083
  var GetLoginConfigPathSchema = zod.z.object({}).describe("Show the path to the login configuration file");
1112
- var getLoginConfigPathPlugin = () => {
1113
- const getLoginConfigPathWithSdk = zapierSdk.createFunction(
1114
- async function getLoginConfigPathWithSdk2(_options) {
1115
- return getConfigPath();
1116
- },
1117
- GetLoginConfigPathSchema
1118
- );
1119
- return {
1120
- getLoginConfigPath: getLoginConfigPathWithSdk,
1121
- context: {
1122
- meta: {
1123
- getLoginConfigPath: {
1124
- categories: ["utility"],
1125
- inputSchema: GetLoginConfigPathSchema
1126
- }
1127
- }
1128
- }
1129
- };
1130
- };
1084
+ var getLoginConfigPathPlugin = zapierSdk.definePlugin(
1085
+ (sdk) => zapierSdk.createPluginMethod(sdk, {
1086
+ name: "getLoginConfigPath",
1087
+ categories: ["utility"],
1088
+ inputSchema: GetLoginConfigPathSchema,
1089
+ handler: async () => getConfigPath()
1090
+ })
1091
+ );
1131
1092
  var AddSchema = zod.z.object({
1132
1093
  apps: zod.z.array(zod.z.string().min(1, "App key cannot be empty")).min(1, "At least one app key is required").describe(
1133
1094
  "One or more app keys to add (e.g., 'slack', 'github', 'trello')"
@@ -1155,111 +1116,105 @@ async function detectTypesOutputDirectory() {
1155
1116
  }
1156
1117
  return "./zapier/apps/";
1157
1118
  }
1158
- var addPlugin = (sdk) => {
1159
- const add = zapierSdk.createFunction(async function add2(options) {
1160
- const {
1161
- apps: appKeys,
1162
- connections: connectionIds,
1163
- configPath,
1164
- typesOutput = await detectTypesOutputDirectory()
1165
- } = options;
1166
- const resolvedTypesOutput = path.resolve(typesOutput);
1167
- console.log(`\u{1F4E6} Adding ${appKeys.length} app(s)...`);
1168
- const appSlugAndKeyMap = /* @__PURE__ */ new Map();
1169
- const handleManifestProgress = (event) => {
1170
- switch (event.type) {
1171
- case "apps_lookup_start":
1172
- console.log(`\u{1F4E6} Looking up ${event.count} app(s)...`);
1173
- break;
1174
- case "app_found":
1175
- const displayName = event.app.slug ? `${event.app.slug} (${event.app.key})` : event.app.key;
1176
- appSlugAndKeyMap.set(event.app.key, displayName);
1177
- break;
1178
- case "apps_lookup_complete":
1179
- if (event.count === 0) {
1180
- console.warn("\u26A0\uFE0F No apps found");
1181
- }
1182
- break;
1183
- case "app_processing_start":
1184
- const appName = event.slug ? `${event.slug} (${event.app})` : event.app;
1185
- console.log(`\u{1F4E6} Adding ${appName}...`);
1186
- break;
1187
- case "manifest_updated":
1188
- const appDisplay = appSlugAndKeyMap.get(event.app) || event.app;
1189
- console.log(
1190
- `\u{1F4DD} Locked ${appDisplay} to ${event.app}@${event.version} using key '${event.manifestKey}'`
1191
- );
1192
- break;
1193
- case "app_processing_error":
1194
- const errorApp = appSlugAndKeyMap.get(event.app) || event.app;
1195
- console.warn(`\u26A0\uFE0F ${event.error} for ${errorApp}`);
1196
- break;
1197
- }
1198
- };
1199
- const handleTypesProgress = (event) => {
1200
- switch (event.type) {
1201
- case "connections_lookup_start":
1202
- console.log(`\u{1F510} Looking up ${event.count} connection(s)...`);
1203
- break;
1204
- case "connections_lookup_complete":
1205
- console.log(`\u{1F510} Found ${event.count} connection(s)`);
1206
- break;
1207
- case "connection_matched":
1208
- const appWithConnection = appSlugAndKeyMap.get(event.app) || event.app;
1209
- console.log(
1210
- `\u{1F510} Using connection ${event.connectionId} (${event.connectionTitle}) for ${appWithConnection}`
1211
- );
1212
- break;
1213
- case "connection_not_matched":
1214
- const appWithoutConnection = appSlugAndKeyMap.get(event.app) || event.app;
1215
- console.warn(
1216
- `\u26A0\uFE0F No matching connection found for ${appWithoutConnection}`
1217
- );
1218
- break;
1219
- case "file_written":
1220
- console.log(
1221
- `\u{1F527} Generated types for ${event.manifestKey} at ${event.filePath}`
1222
- );
1223
- break;
1224
- case "app_processing_error":
1225
- const errorApp = appSlugAndKeyMap.get(event.app) || event.app;
1226
- console.warn(`\u26A0\uFE0F ${event.error} for ${errorApp}`);
1227
- break;
1228
- }
1229
- };
1230
- const manifestResult = await sdk.buildManifest({
1231
- apps: appKeys,
1232
- skipWrite: false,
1233
- configPath,
1234
- onProgress: handleManifestProgress
1235
- });
1236
- const typesResult = await sdk.generateAppTypes({
1237
- apps: appKeys,
1238
- connections: connectionIds,
1239
- skipWrite: false,
1240
- typesOutputDirectory: resolvedTypesOutput,
1241
- onProgress: handleTypesProgress
1242
- });
1243
- const results = manifestResult.manifest?.apps || {};
1244
- const successfulApps = Object.keys(results).filter(
1245
- (manifestKey) => typesResult.writtenFiles?.[manifestKey]
1246
- );
1247
- if (successfulApps.length > 0) {
1248
- console.log(`\u2705 Added ${successfulApps.length} app(s) to manifest`);
1249
- }
1250
- }, AddSchema);
1251
- return {
1252
- add,
1253
- context: {
1254
- meta: {
1255
- add: {
1256
- categories: ["utility"],
1257
- inputSchema: AddSchema
1119
+ var addPlugin = zapierSdk.definePlugin(
1120
+ (sdk) => zapierSdk.createPluginMethod(sdk, {
1121
+ name: "add",
1122
+ categories: ["utility"],
1123
+ inputSchema: AddSchema,
1124
+ handler: async ({ sdk: sdk2, options }) => {
1125
+ const {
1126
+ apps: appKeys,
1127
+ connections: connectionIds,
1128
+ configPath,
1129
+ typesOutput = await detectTypesOutputDirectory()
1130
+ } = options;
1131
+ const resolvedTypesOutput = path.resolve(typesOutput);
1132
+ console.log(`\u{1F4E6} Adding ${appKeys.length} app(s)...`);
1133
+ const appSlugAndKeyMap = /* @__PURE__ */ new Map();
1134
+ const handleManifestProgress = (event) => {
1135
+ switch (event.type) {
1136
+ case "apps_lookup_start":
1137
+ console.log(`\u{1F4E6} Looking up ${event.count} app(s)...`);
1138
+ break;
1139
+ case "app_found":
1140
+ const displayName = event.app.slug ? `${event.app.slug} (${event.app.key})` : event.app.key;
1141
+ appSlugAndKeyMap.set(event.app.key, displayName);
1142
+ break;
1143
+ case "apps_lookup_complete":
1144
+ if (event.count === 0) {
1145
+ console.warn("\u26A0\uFE0F No apps found");
1146
+ }
1147
+ break;
1148
+ case "app_processing_start":
1149
+ const appName = event.slug ? `${event.slug} (${event.app})` : event.app;
1150
+ console.log(`\u{1F4E6} Adding ${appName}...`);
1151
+ break;
1152
+ case "manifest_updated":
1153
+ const appDisplay = appSlugAndKeyMap.get(event.app) || event.app;
1154
+ console.log(
1155
+ `\u{1F4DD} Locked ${appDisplay} to ${event.app}@${event.version} using key '${event.manifestKey}'`
1156
+ );
1157
+ break;
1158
+ case "app_processing_error":
1159
+ const errorApp = appSlugAndKeyMap.get(event.app) || event.app;
1160
+ console.warn(`\u26A0\uFE0F ${event.error} for ${errorApp}`);
1161
+ break;
1162
+ }
1163
+ };
1164
+ const handleTypesProgress = (event) => {
1165
+ switch (event.type) {
1166
+ case "connections_lookup_start":
1167
+ console.log(`\u{1F510} Looking up ${event.count} connection(s)...`);
1168
+ break;
1169
+ case "connections_lookup_complete":
1170
+ console.log(`\u{1F510} Found ${event.count} connection(s)`);
1171
+ break;
1172
+ case "connection_matched":
1173
+ const appWithConnection = appSlugAndKeyMap.get(event.app) || event.app;
1174
+ console.log(
1175
+ `\u{1F510} Using connection ${event.connectionId} (${event.connectionTitle}) for ${appWithConnection}`
1176
+ );
1177
+ break;
1178
+ case "connection_not_matched":
1179
+ const appWithoutConnection = appSlugAndKeyMap.get(event.app) || event.app;
1180
+ console.warn(
1181
+ `\u26A0\uFE0F No matching connection found for ${appWithoutConnection}`
1182
+ );
1183
+ break;
1184
+ case "file_written":
1185
+ console.log(
1186
+ `\u{1F527} Generated types for ${event.manifestKey} at ${event.filePath}`
1187
+ );
1188
+ break;
1189
+ case "app_processing_error":
1190
+ const errorApp = appSlugAndKeyMap.get(event.app) || event.app;
1191
+ console.warn(`\u26A0\uFE0F ${event.error} for ${errorApp}`);
1192
+ break;
1258
1193
  }
1194
+ };
1195
+ const manifestResult = await sdk2.buildManifest({
1196
+ apps: appKeys,
1197
+ skipWrite: false,
1198
+ configPath,
1199
+ onProgress: handleManifestProgress
1200
+ });
1201
+ const typesResult = await sdk2.generateAppTypes({
1202
+ apps: appKeys,
1203
+ connections: connectionIds,
1204
+ skipWrite: false,
1205
+ typesOutputDirectory: resolvedTypesOutput,
1206
+ onProgress: handleTypesProgress
1207
+ });
1208
+ const results = manifestResult.manifest?.apps || {};
1209
+ const successfulApps = Object.keys(results).filter(
1210
+ (manifestKey) => typesResult.writtenFiles?.[manifestKey]
1211
+ );
1212
+ if (successfulApps.length > 0) {
1213
+ console.log(`\u2705 Added ${successfulApps.length} app(s) to manifest`);
1259
1214
  }
1260
1215
  }
1261
- };
1262
- };
1216
+ })
1217
+ );
1263
1218
  var GenerateAppTypesSchema = zod.z.object({
1264
1219
  apps: zod.z.array(zod.z.string().min(1, "App key cannot be empty")).min(1, "At least one app key is required").describe(
1265
1220
  "One or more app keys to generate types for (e.g., 'slack', 'github', 'trello')"
@@ -1866,150 +1821,133 @@ function createManifestEntry(app) {
1866
1821
  version: app.version
1867
1822
  };
1868
1823
  }
1869
- var generateAppTypesPlugin = (sdk) => {
1870
- const generateAppTypes = zapierSdk.createFunction(async function generateAppTypes2(options) {
1871
- const {
1872
- apps: appKeys,
1873
- connections: connectionIds,
1874
- skipWrite = false,
1875
- typesOutputDirectory = await detectTypesOutputDirectory(),
1876
- onProgress
1877
- } = options;
1878
- const resolvedTypesOutput = path.resolve(typesOutputDirectory);
1879
- const result = {
1880
- typeDefinitions: {}
1881
- };
1882
- onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
1883
- const appsIterable = sdk.listApps({ apps: appKeys }).items();
1884
- const apps = [];
1885
- for await (const app of appsIterable) {
1886
- apps.push(app);
1887
- onProgress?.({ type: "app_found", app });
1888
- }
1889
- onProgress?.({ type: "apps_lookup_complete", count: apps.length });
1890
- if (apps.length === 0) {
1891
- return result;
1892
- }
1893
- const connections = [];
1894
- if (connectionIds && connectionIds.length > 0) {
1895
- onProgress?.({
1896
- type: "connections_lookup_start",
1897
- count: connectionIds.length
1898
- });
1899
- const connectionsIterable = sdk.listConnections({ connections: connectionIds }).items();
1900
- for await (const connection of connectionsIterable) {
1901
- connections.push(connection);
1824
+ var generateAppTypesPlugin = zapierSdk.definePlugin(
1825
+ (sdk) => zapierSdk.createPluginMethod(sdk, {
1826
+ name: "generateAppTypes",
1827
+ categories: ["utility"],
1828
+ // Cast: schema validates JSON fields only; GenerateAppTypesOptions adds
1829
+ // the runtime-only `onProgress` callback (passthrough via createFunction).
1830
+ inputSchema: GenerateAppTypesSchema,
1831
+ handler: async ({ sdk: sdk2, options }) => {
1832
+ const {
1833
+ apps: appKeys,
1834
+ connections: connectionIds,
1835
+ skipWrite = false,
1836
+ typesOutputDirectory = await detectTypesOutputDirectory(),
1837
+ onProgress
1838
+ } = options;
1839
+ const resolvedTypesOutput = path.resolve(typesOutputDirectory);
1840
+ const result = { typeDefinitions: {} };
1841
+ onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
1842
+ const appsIterable = sdk2.listApps({ apps: appKeys }).items();
1843
+ const apps = [];
1844
+ for await (const app of appsIterable) {
1845
+ apps.push(app);
1846
+ onProgress?.({ type: "app_found", app });
1902
1847
  }
1903
- onProgress?.({
1904
- type: "connections_lookup_complete",
1905
- count: connections.length
1906
- });
1907
- }
1908
- if (!skipWrite && resolvedTypesOutput) {
1909
- await promises.mkdir(resolvedTypesOutput, { recursive: true });
1910
- }
1911
- if (!skipWrite) {
1912
- result.writtenFiles = {};
1913
- }
1914
- for (const app of apps) {
1915
- onProgress?.({
1916
- type: "app_processing_start",
1917
- app: app.key,
1918
- slug: app.slug
1919
- });
1920
- try {
1921
- if (!app.version) {
1922
- const errorMessage = `Invalid implementation ID format: ${app.implementation_id}. Expected format: <implementationName>@<version>`;
1923
- onProgress?.({
1924
- type: "app_processing_error",
1925
- app: app.key,
1926
- error: errorMessage
1927
- });
1928
- throw new zapierSdk.ZapierValidationError(errorMessage, {
1929
- details: {
1930
- appKey: app.key,
1931
- implementationId: app.implementation_id
1932
- }
1933
- });
1848
+ onProgress?.({ type: "apps_lookup_complete", count: apps.length });
1849
+ if (apps.length === 0) {
1850
+ return result;
1851
+ }
1852
+ const connections = [];
1853
+ if (connectionIds && connectionIds.length > 0) {
1854
+ onProgress?.({
1855
+ type: "connections_lookup_start",
1856
+ count: connectionIds.length
1857
+ });
1858
+ const connectionsIterable = sdk2.listConnections({ connections: connectionIds }).items();
1859
+ for await (const connection of connectionsIterable) {
1860
+ connections.push(connection);
1934
1861
  }
1935
- let connectionId;
1936
- if (connections.length > 0) {
1937
- const matchingConnection = connections.find((conn) => {
1938
- return conn.app_key === app.key;
1939
- });
1940
- if (matchingConnection) {
1941
- connectionId = matchingConnection.id;
1862
+ onProgress?.({
1863
+ type: "connections_lookup_complete",
1864
+ count: connections.length
1865
+ });
1866
+ }
1867
+ if (!skipWrite && resolvedTypesOutput) {
1868
+ await promises.mkdir(resolvedTypesOutput, { recursive: true });
1869
+ }
1870
+ if (!skipWrite) {
1871
+ result.writtenFiles = {};
1872
+ }
1873
+ for (const app of apps) {
1874
+ onProgress?.({
1875
+ type: "app_processing_start",
1876
+ app: app.key,
1877
+ slug: app.slug
1878
+ });
1879
+ try {
1880
+ if (!app.version) {
1881
+ const errorMessage = `Invalid implementation ID format: ${app.implementation_id}. Expected format: <implementationName>@<version>`;
1942
1882
  onProgress?.({
1943
- type: "connection_matched",
1883
+ type: "app_processing_error",
1944
1884
  app: app.key,
1945
- connectionId: matchingConnection.id,
1946
- connectionTitle: matchingConnection.title || ""
1885
+ error: errorMessage
1947
1886
  });
1948
- } else {
1949
- onProgress?.({
1950
- type: "connection_not_matched",
1951
- app: app.key
1887
+ throw new zapierSdk.ZapierValidationError(errorMessage, {
1888
+ details: {
1889
+ appKey: app.key,
1890
+ implementationId: app.implementation_id
1891
+ }
1952
1892
  });
1953
1893
  }
1954
- }
1955
- const manifestKey = getManifestKey(app);
1956
- const generator = new AstTypeGenerator();
1957
- const typeDefinitionString = await generator.generateTypes({
1958
- app,
1959
- connectionId,
1960
- sdk
1961
- });
1962
- result.typeDefinitions[manifestKey] = typeDefinitionString;
1963
- onProgress?.({
1964
- type: "type_generated",
1965
- manifestKey,
1966
- sizeBytes: typeDefinitionString.length
1967
- });
1968
- if (!skipWrite && resolvedTypesOutput && result.writtenFiles) {
1969
- const filePath = path.join(resolvedTypesOutput, `${manifestKey}.d.ts`);
1970
- await promises.writeFile(filePath, typeDefinitionString, "utf8");
1971
- result.writtenFiles[manifestKey] = filePath;
1894
+ let connectionId;
1895
+ if (connections.length > 0) {
1896
+ const matchingConnection = connections.find(
1897
+ (conn) => conn.app_key === app.key
1898
+ );
1899
+ if (matchingConnection) {
1900
+ connectionId = matchingConnection.id;
1901
+ onProgress?.({
1902
+ type: "connection_matched",
1903
+ app: app.key,
1904
+ connectionId: matchingConnection.id,
1905
+ connectionTitle: matchingConnection.title || ""
1906
+ });
1907
+ } else {
1908
+ onProgress?.({
1909
+ type: "connection_not_matched",
1910
+ app: app.key
1911
+ });
1912
+ }
1913
+ }
1914
+ const manifestKey = getManifestKey(app);
1915
+ const generator = new AstTypeGenerator();
1916
+ const typeDefinitionString = await generator.generateTypes({
1917
+ app,
1918
+ connectionId,
1919
+ sdk: sdk2
1920
+ });
1921
+ result.typeDefinitions[manifestKey] = typeDefinitionString;
1972
1922
  onProgress?.({
1973
- type: "file_written",
1923
+ type: "type_generated",
1974
1924
  manifestKey,
1975
- filePath
1925
+ sizeBytes: typeDefinitionString.length
1976
1926
  });
1977
- }
1978
- onProgress?.({
1979
- type: "app_processing_complete",
1980
- app: app.key
1981
- });
1982
- } catch (error) {
1983
- const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
1984
- onProgress?.({
1985
- type: "app_processing_error",
1986
- app: app.key,
1987
- error: errorMessage
1988
- });
1989
- if (error instanceof zapierSdk.ZapierValidationError) {
1990
- throw error;
1991
- } else {
1992
- throw new zapierSdk.ZapierUnknownError(errorMessage, {
1993
- cause: error
1994
- // Works for both Error and non-Error
1927
+ if (!skipWrite && resolvedTypesOutput && result.writtenFiles) {
1928
+ const filePath = path.join(resolvedTypesOutput, `${manifestKey}.d.ts`);
1929
+ await promises.writeFile(filePath, typeDefinitionString, "utf8");
1930
+ result.writtenFiles[manifestKey] = filePath;
1931
+ onProgress?.({ type: "file_written", manifestKey, filePath });
1932
+ }
1933
+ onProgress?.({ type: "app_processing_complete", app: app.key });
1934
+ } catch (error) {
1935
+ const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
1936
+ onProgress?.({
1937
+ type: "app_processing_error",
1938
+ app: app.key,
1939
+ error: errorMessage
1995
1940
  });
1941
+ if (error instanceof zapierSdk.ZapierValidationError) {
1942
+ throw error;
1943
+ }
1944
+ throw new zapierSdk.ZapierUnknownError(errorMessage, { cause: error });
1996
1945
  }
1997
1946
  }
1947
+ return result;
1998
1948
  }
1999
- return result;
2000
- }, GenerateAppTypesSchema);
2001
- return {
2002
- generateAppTypes,
2003
- context: {
2004
- meta: {
2005
- generateAppTypes: {
2006
- categories: ["utility"],
2007
- inputSchema: GenerateAppTypesSchema
2008
- }
2009
- }
2010
- }
2011
- };
2012
- };
1949
+ })
1950
+ );
2013
1951
  var BuildManifestSchema = zod.z.object({
2014
1952
  apps: zod.z.array(zod.z.string().min(1, "App key cannot be empty")).min(1, "At least one app key is required").describe(
2015
1953
  "One or more app keys to build manifest entries for (e.g., 'slack', 'github', 'trello')"
@@ -2025,86 +1963,80 @@ var BuildManifestSchema = zod.z.object({
2025
1963
  );
2026
1964
 
2027
1965
  // src/plugins/buildManifest/index.ts
2028
- var buildManifestPlugin = (sdk) => {
2029
- const buildManifest = zapierSdk.createFunction(async function buildManifest2(options) {
2030
- const {
2031
- apps: appKeys,
2032
- skipWrite = false,
2033
- configPath,
2034
- onProgress
2035
- } = options;
2036
- onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
2037
- const appsIterable = sdk.listApps({ apps: appKeys }).items();
2038
- const apps = [];
2039
- for await (const app of appsIterable) {
2040
- apps.push(app);
2041
- onProgress?.({ type: "app_found", app });
2042
- }
2043
- onProgress?.({ type: "apps_lookup_complete", count: apps.length });
2044
- if (apps.length === 0) {
2045
- return {};
2046
- }
2047
- let updatedManifest;
2048
- for (const app of apps) {
2049
- onProgress?.({
2050
- type: "app_processing_start",
2051
- app: app.key,
2052
- slug: app.slug
2053
- });
2054
- try {
2055
- const manifestEntry = createManifestEntry(app);
2056
- onProgress?.({
2057
- type: "manifest_entry_built",
2058
- app: app.key,
2059
- manifestKey: manifestEntry.implementationName,
2060
- version: manifestEntry.version || ""
2061
- });
2062
- const { key: updatedManifestKey, manifest } = await sdk.context.updateManifestEntry({
2063
- appKey: app.key,
2064
- entry: manifestEntry,
2065
- configPath,
2066
- skipWrite,
2067
- manifest: updatedManifest
2068
- });
2069
- updatedManifest = manifest;
2070
- onProgress?.({
2071
- type: "manifest_updated",
2072
- app: app.key,
2073
- manifestKey: updatedManifestKey,
2074
- version: manifestEntry.version || ""
2075
- });
2076
- onProgress?.({ type: "app_processing_complete", app: app.key });
2077
- } catch (error) {
2078
- const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
1966
+ var buildManifestPlugin = zapierSdk.definePlugin(
1967
+ (sdk) => zapierSdk.createPluginMethod(sdk, {
1968
+ name: "buildManifest",
1969
+ categories: ["utility"],
1970
+ // Cast: BuildManifestSchema validates JSON-serializable fields only.
1971
+ // BuildManifestOptions adds an `onProgress` callback that rides through
1972
+ // `createFunction`'s passthrough spread at runtime; this widens TInput
1973
+ // so the handler can read it.
1974
+ inputSchema: BuildManifestSchema,
1975
+ handler: async ({ sdk: sdk2, options }) => {
1976
+ const {
1977
+ apps: appKeys,
1978
+ skipWrite = false,
1979
+ configPath,
1980
+ onProgress
1981
+ } = options;
1982
+ onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
1983
+ const appsIterable = sdk2.listApps({ apps: appKeys }).items();
1984
+ const apps = [];
1985
+ for await (const app of appsIterable) {
1986
+ apps.push(app);
1987
+ onProgress?.({ type: "app_found", app });
1988
+ }
1989
+ onProgress?.({ type: "apps_lookup_complete", count: apps.length });
1990
+ if (apps.length === 0) {
1991
+ return {};
1992
+ }
1993
+ let updatedManifest;
1994
+ for (const app of apps) {
2079
1995
  onProgress?.({
2080
- type: "app_processing_error",
1996
+ type: "app_processing_start",
2081
1997
  app: app.key,
2082
- error: errorMessage
1998
+ slug: app.slug
2083
1999
  });
2084
- if (error instanceof zapierSdk.ZapierValidationError) {
2085
- throw error;
2086
- } else {
2087
- throw new zapierSdk.ZapierUnknownError(errorMessage, {
2088
- cause: error
2089
- // Works for both Error and non-Error
2000
+ try {
2001
+ const manifestEntry = createManifestEntry(app);
2002
+ onProgress?.({
2003
+ type: "manifest_entry_built",
2004
+ app: app.key,
2005
+ manifestKey: manifestEntry.implementationName,
2006
+ version: manifestEntry.version || ""
2090
2007
  });
2008
+ const { key: updatedManifestKey, manifest } = await sdk2.context.updateManifestEntry({
2009
+ appKey: app.key,
2010
+ entry: manifestEntry,
2011
+ configPath,
2012
+ skipWrite,
2013
+ manifest: updatedManifest
2014
+ });
2015
+ updatedManifest = manifest;
2016
+ onProgress?.({
2017
+ type: "manifest_updated",
2018
+ app: app.key,
2019
+ manifestKey: updatedManifestKey,
2020
+ version: manifestEntry.version || ""
2021
+ });
2022
+ onProgress?.({ type: "app_processing_complete", app: app.key });
2023
+ } catch (error) {
2024
+ const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
2025
+ onProgress?.({
2026
+ type: "app_processing_error",
2027
+ app: app.key,
2028
+ error: errorMessage
2029
+ });
2030
+ if (error instanceof zapierSdk.ZapierValidationError) {
2031
+ throw error;
2032
+ }
2033
+ throw new zapierSdk.ZapierUnknownError(errorMessage, { cause: error });
2091
2034
  }
2092
2035
  }
2036
+ return { manifest: updatedManifest };
2093
2037
  }
2094
- return { manifest: updatedManifest };
2095
- }, BuildManifestSchema);
2096
- return {
2097
- buildManifest,
2098
- context: {
2099
- meta: {
2100
- buildManifest: {
2101
- categories: ["utility"],
2102
- inputSchema: BuildManifestSchema
2103
- }
2104
- }
2105
- }
2106
- };
2107
- };
2038
+ })
2039
+ );
2108
2040
  var FeedbackSchema = zod.z.object({
2109
2041
  feedback: zod.z.string().describe(
2110
2042
  "Your feedback on the Zapier SDK. Describe what worked well, what was frustrating, or any suggestions."
@@ -2138,37 +2070,31 @@ async function postWithRetry({
2138
2070
  }
2139
2071
  return response;
2140
2072
  }
2141
- var feedbackPlugin = (sdk) => {
2142
- const debug = sdk.context.options?.debug;
2143
- const feedbackWithSdk = zapierSdk.createFunction(async function feedback(options) {
2144
- const user = await getLoggedInUser();
2145
- const body = JSON.stringify({
2146
- email: user.email,
2147
- customuser_id: user.customUserId,
2148
- feedback: options.feedback
2149
- });
2150
- const response = await postWithRetry({ body, attemptsLeft: MAX_RETRIES });
2151
- if (debug) {
2152
- const text = await response.text();
2153
- console.error("[debug] Webhook response:", text);
2154
- }
2155
- return "Thank you for your feedback!";
2156
- }, FeedbackSchema);
2157
- return {
2158
- feedback: feedbackWithSdk,
2159
- context: {
2160
- meta: {
2161
- feedback: {
2162
- categories: ["utility"],
2163
- inputSchema: FeedbackSchema,
2164
- resolvers: {
2165
- feedback: feedbackResolver
2166
- }
2167
- }
2073
+ var feedbackPlugin = zapierSdk.definePlugin(
2074
+ (sdk) => zapierSdk.createPluginMethod(sdk, {
2075
+ name: "feedback",
2076
+ categories: ["utility"],
2077
+ inputSchema: FeedbackSchema,
2078
+ resolvers: { feedback: feedbackResolver },
2079
+ handler: async ({ sdk: sdk2, options }) => {
2080
+ const user = await getLoggedInUser();
2081
+ const body = JSON.stringify({
2082
+ email: user.email,
2083
+ customuser_id: user.customUserId,
2084
+ feedback: options.feedback
2085
+ });
2086
+ const response = await postWithRetry({
2087
+ body,
2088
+ attemptsLeft: MAX_RETRIES
2089
+ });
2090
+ if (sdk2.context.options?.debug) {
2091
+ const text = await response.text();
2092
+ console.error("[debug] Webhook response:", text);
2168
2093
  }
2094
+ return "Thank you for your feedback!";
2169
2095
  }
2170
- };
2171
- };
2096
+ })
2097
+ );
2172
2098
  var CurlSchema = zod.z.object({
2173
2099
  url: zod.z.string().describe("Request URL"),
2174
2100
  request: zod.z.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]).optional().describe("HTTP method (defaults to GET, or POST if data is provided)"),
@@ -2344,7 +2270,7 @@ async function buildFormData(formArgs, formStringArgs) {
2344
2270
  }
2345
2271
 
2346
2272
  // src/plugins/curl/index.ts
2347
- var curlPlugin = (sdk) => {
2273
+ var curlPlugin = zapierSdk.definePlugin((sdk) => {
2348
2274
  async function curl(options) {
2349
2275
  const {
2350
2276
  url: rawUrl,
@@ -2587,30 +2513,25 @@ ${Array.from(
2587
2513
  }
2588
2514
  }
2589
2515
  };
2590
- };
2591
-
2592
- // src/plugins/cliOverrides/index.ts
2593
- var cliOverridesPlugin = (sdk) => {
2594
- if (!sdk.context.meta.fetch) {
2595
- return { context: { meta: {} } };
2596
- }
2597
- return {
2598
- context: {
2599
- meta: {
2600
- fetch: {
2601
- ...sdk.context.meta.fetch,
2602
- categories: [
2603
- ...sdk.context.meta.fetch.categories || [],
2604
- "deprecated"
2605
- ],
2606
- deprecation: {
2607
- message: "This command is deprecated and will be removed soon. Use `curl` instead. Learn more: https://docs.zapier.com/sdk/cli-reference#curl"
2608
- }
2516
+ });
2517
+ var cliOverridesPlugin = zapierSdk.definePlugin(
2518
+ (sdk) => {
2519
+ const meta = {};
2520
+ if (sdk.context.meta.fetch) {
2521
+ meta.fetch = {
2522
+ ...sdk.context.meta.fetch,
2523
+ categories: [
2524
+ ...sdk.context.meta.fetch.categories || [],
2525
+ "deprecated"
2526
+ ],
2527
+ deprecation: {
2528
+ message: "This command is deprecated and will be removed soon. Use `curl` instead. Learn more: https://docs.zapier.com/sdk/cli-reference#curl"
2609
2529
  }
2610
- }
2530
+ };
2611
2531
  }
2612
- };
2613
- };
2532
+ return { context: { meta } };
2533
+ }
2534
+ );
2614
2535
  var TEMPLATES = ["basic"];
2615
2536
  var InitSchema = zod.z.object({
2616
2537
  projectName: zod.z.string().min(1).describe("Name of the project directory to create"),
@@ -3022,71 +2943,65 @@ function displaySummaryAndNextSteps({
3022
2943
  }
3023
2944
 
3024
2945
  // src/plugins/init/index.ts
3025
- var initPlugin = () => {
3026
- const init = zapierSdk.createFunction(async function init2(options) {
3027
- const { projectName: rawName, skipPrompts = false } = options;
3028
- const cwd = process.cwd();
3029
- const { projectName, projectDir } = validateInitOptions({ rawName, cwd });
3030
- const displayHooks = createConsoleDisplayHooks();
3031
- const packageManagerInfo = detectPackageManager(cwd);
3032
- if (packageManagerInfo.name === "unknown") {
3033
- displayHooks.onWarn(
3034
- "Could not detect package manager, defaulting to npm."
3035
- );
3036
- }
3037
- const packageManager = packageManagerInfo.name === "unknown" ? "npm" : packageManagerInfo.name;
3038
- const steps = getInitSteps({
3039
- projectDir,
3040
- projectName,
3041
- packageManager,
3042
- displayHooks
3043
- });
3044
- const completedSetupStepIds = [];
3045
- for (let i = 0; i < steps.length; i++) {
3046
- const step = steps[i];
3047
- const succeeded = await withInterruptCleanup(
3048
- step.cleanup,
3049
- () => runStep({
3050
- step,
3051
- stepNumber: i + 1,
3052
- totalSteps: steps.length,
3053
- skipPrompts,
3054
- displayHooks
3055
- })
3056
- );
3057
- if (!succeeded) break;
3058
- completedSetupStepIds.push(step.id);
3059
- }
3060
- if (completedSetupStepIds.length === 0) {
3061
- throw new ZapierCliExitError(
3062
- "Project setup failed \u2014 no steps completed."
3063
- );
3064
- }
3065
- displaySummaryAndNextSteps({
3066
- projectName,
3067
- steps,
3068
- completedSetupStepIds,
3069
- packageManager
3070
- });
3071
- }, InitSchema);
3072
- return {
3073
- init,
3074
- context: {
3075
- meta: {
3076
- init: {
3077
- categories: ["utility"],
3078
- inputSchema: InitSchema,
3079
- supportsJsonOutput: false
3080
- }
2946
+ var initPlugin = zapierSdk.definePlugin(
2947
+ (sdk) => zapierSdk.createPluginMethod(sdk, {
2948
+ name: "init",
2949
+ categories: ["utility"],
2950
+ inputSchema: InitSchema,
2951
+ supportsJsonOutput: false,
2952
+ handler: async ({ options }) => {
2953
+ const { projectName: rawName, skipPrompts = false } = options;
2954
+ const cwd = process.cwd();
2955
+ const { projectName, projectDir } = validateInitOptions({ rawName, cwd });
2956
+ const displayHooks = createConsoleDisplayHooks();
2957
+ const packageManagerInfo = detectPackageManager(cwd);
2958
+ if (packageManagerInfo.name === "unknown") {
2959
+ displayHooks.onWarn(
2960
+ "Could not detect package manager, defaulting to npm."
2961
+ );
2962
+ }
2963
+ const packageManager = packageManagerInfo.name === "unknown" ? "npm" : packageManagerInfo.name;
2964
+ const steps = getInitSteps({
2965
+ projectDir,
2966
+ projectName,
2967
+ packageManager,
2968
+ displayHooks
2969
+ });
2970
+ const completedSetupStepIds = [];
2971
+ for (let i = 0; i < steps.length; i++) {
2972
+ const step = steps[i];
2973
+ const succeeded = await withInterruptCleanup(
2974
+ step.cleanup,
2975
+ () => runStep({
2976
+ step,
2977
+ stepNumber: i + 1,
2978
+ totalSteps: steps.length,
2979
+ skipPrompts,
2980
+ displayHooks
2981
+ })
2982
+ );
2983
+ if (!succeeded) break;
2984
+ completedSetupStepIds.push(step.id);
3081
2985
  }
2986
+ if (completedSetupStepIds.length === 0) {
2987
+ throw new ZapierCliExitError(
2988
+ "Project setup failed \u2014 no steps completed."
2989
+ );
2990
+ }
2991
+ displaySummaryAndNextSteps({
2992
+ projectName,
2993
+ steps,
2994
+ completedSetupStepIds,
2995
+ packageManager
2996
+ });
3082
2997
  }
3083
- };
3084
- };
2998
+ })
2999
+ );
3085
3000
 
3086
3001
  // package.json with { type: 'json' }
3087
3002
  var package_default = {
3088
3003
  name: "@zapier/zapier-sdk-cli",
3089
- version: "0.43.0"};
3004
+ version: "0.43.3"};
3090
3005
 
3091
3006
  // src/sdk.ts
3092
3007
  zapierSdk.injectCliLogin(login_exports);
@@ -3100,7 +3015,7 @@ function createZapierCliSdk(options = {}) {
3100
3015
 
3101
3016
  // package.json
3102
3017
  var package_default2 = {
3103
- version: "0.43.0"};
3018
+ version: "0.43.3"};
3104
3019
 
3105
3020
  // src/telemetry/builders.ts
3106
3021
  function createCliBaseEvent(context = {}) {