@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/cli.cjs CHANGED
@@ -1113,7 +1113,7 @@ var SHARED_COMMAND_CLI_OPTIONS = [
1113
1113
 
1114
1114
  // package.json
1115
1115
  var package_default = {
1116
- version: "0.43.0"};
1116
+ version: "0.43.1"};
1117
1117
 
1118
1118
  // src/telemetry/builders.ts
1119
1119
  function createCliBaseEvent(context = {}) {
@@ -3098,85 +3098,65 @@ function toPkceCredentials(credentials2) {
3098
3098
  }
3099
3099
  return void 0;
3100
3100
  }
3101
- var loginPlugin = (sdk2) => {
3102
- const loginFn = async (options) => {
3103
- const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
3104
- if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
3105
- throw new Error("Timeout must be a positive number");
3106
- }
3107
- const resolvedCredentials = await sdk2.context.resolveCredentials();
3108
- const pkceCredentials = toPkceCredentials(resolvedCredentials);
3109
- await login_default({
3110
- timeoutMs: timeoutSeconds * 1e3,
3111
- credentials: pkceCredentials
3112
- });
3113
- const user = await getLoggedInUser();
3114
- sdk2.context.eventEmission.emit(
3115
- "platform.sdk.ApplicationLifecycleEvent",
3116
- zapierSdk.buildApplicationLifecycleEvent(
3117
- { lifecycle_event_type: "login_success" },
3118
- { customuser_id: user.customUserId, account_id: user.accountId }
3119
- )
3120
- );
3121
- console.log(`\u2705 Successfully logged in as ${user.email}`);
3122
- };
3123
- return {
3124
- login: loginFn,
3125
- context: {
3126
- meta: {
3127
- login: {
3128
- categories: ["account"],
3129
- inputSchema: LoginSchema,
3130
- supportsJsonOutput: false
3131
- }
3101
+ var loginPlugin = zapierSdk.definePlugin(
3102
+ (sdk2) => zapierSdk.createPluginMethod(sdk2, {
3103
+ name: "login",
3104
+ categories: ["account"],
3105
+ inputSchema: LoginSchema,
3106
+ supportsJsonOutput: false,
3107
+ handler: async ({ sdk: sdk3, options }) => {
3108
+ const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
3109
+ if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
3110
+ throw new Error("Timeout must be a positive number");
3132
3111
  }
3112
+ const resolvedCredentials = await sdk3.context.resolveCredentials();
3113
+ const pkceCredentials = toPkceCredentials(resolvedCredentials);
3114
+ await login_default({
3115
+ timeoutMs: timeoutSeconds * 1e3,
3116
+ credentials: pkceCredentials
3117
+ });
3118
+ const user = await getLoggedInUser();
3119
+ sdk3.context.eventEmission.emit(
3120
+ "platform.sdk.ApplicationLifecycleEvent",
3121
+ zapierSdk.buildApplicationLifecycleEvent(
3122
+ { lifecycle_event_type: "login_success" },
3123
+ { customuser_id: user.customUserId, account_id: user.accountId }
3124
+ )
3125
+ );
3126
+ console.log(`\u2705 Successfully logged in as ${user.email}`);
3133
3127
  }
3134
- };
3135
- };
3128
+ })
3129
+ );
3136
3130
  var LogoutSchema = zod.z.object({}).describe("Log out of your Zapier account");
3137
3131
 
3138
3132
  // src/plugins/logout/index.ts
3139
- var logoutWithSdk = zapierSdk.createFunction(async function logoutWithSdk2(_options) {
3140
- await logout();
3141
- console.log("\u2705 Successfully logged out");
3142
- }, LogoutSchema);
3143
- var logoutPlugin = () => ({
3144
- logout: logoutWithSdk,
3145
- context: {
3146
- meta: {
3147
- logout: {
3148
- categories: ["account"],
3149
- inputSchema: LogoutSchema,
3150
- supportsJsonOutput: false
3151
- }
3133
+ var logoutPlugin = zapierSdk.definePlugin(
3134
+ (sdk2) => zapierSdk.createPluginMethod(sdk2, {
3135
+ name: "logout",
3136
+ categories: ["account"],
3137
+ inputSchema: LogoutSchema,
3138
+ supportsJsonOutput: false,
3139
+ handler: async () => {
3140
+ await logout();
3141
+ console.log("\u2705 Successfully logged out");
3152
3142
  }
3153
- }
3154
- });
3143
+ })
3144
+ );
3155
3145
  var McpSchema = zod.z.object({
3156
3146
  port: zod.z.string().optional().describe("Port to listen on (for future HTTP transport)")
3157
3147
  }).describe("Start MCP server for Zapier SDK");
3158
3148
 
3159
3149
  // src/plugins/mcp/index.ts
3160
- var mcpPlugin = (sdk2) => {
3161
- const mcpWithSdk = zapierSdk.createFunction(async function mcpWithSdk2(options) {
3162
- const mcpOptions = {
3163
- ...options,
3164
- debug: sdk2.context.options?.debug
3165
- };
3166
- return await zapierSdkMcp.startMcpServer(mcpOptions);
3167
- }, McpSchema);
3168
- return {
3169
- mcp: mcpWithSdk,
3170
- context: {
3171
- meta: {
3172
- mcp: {
3173
- categories: ["utility"],
3174
- inputSchema: McpSchema
3175
- }
3176
- }
3150
+ var mcpPlugin = zapierSdk.definePlugin(
3151
+ (sdk2) => zapierSdk.createPluginMethod(sdk2, {
3152
+ name: "mcp",
3153
+ categories: ["utility"],
3154
+ inputSchema: McpSchema,
3155
+ handler: async ({ sdk: sdk3, options }) => {
3156
+ await zapierSdkMcp.startMcpServer({ ...options, debug: sdk3.context.options?.debug });
3177
3157
  }
3178
- };
3179
- };
3158
+ })
3159
+ );
3180
3160
  var BundleCodeSchema = zod.z.object({
3181
3161
  input: zod.z.string().min(1).describe("Input TypeScript file path to bundle"),
3182
3162
  output: zapierSdk.OutputPropertySchema.optional().describe(
@@ -3187,22 +3167,14 @@ var BundleCodeSchema = zod.z.object({
3187
3167
  target: zod.z.string().optional().describe("ECMAScript target version"),
3188
3168
  cjs: zod.z.boolean().optional().describe("Output CommonJS format instead of ESM")
3189
3169
  }).describe("Bundle TypeScript code into executable JavaScript");
3190
- var bundleCodePlugin = () => {
3191
- const bundleCodeWithSdk = zapierSdk.createFunction(async function bundleCodeWithSdk2(options) {
3192
- return await bundleCode(options);
3193
- }, BundleCodeSchema);
3194
- return {
3195
- bundleCode: bundleCodeWithSdk,
3196
- context: {
3197
- meta: {
3198
- bundleCode: {
3199
- categories: ["utility", "deprecated"],
3200
- inputSchema: BundleCodeSchema
3201
- }
3202
- }
3203
- }
3204
- };
3205
- };
3170
+ var bundleCodePlugin = zapierSdk.definePlugin(
3171
+ (sdk2) => zapierSdk.createPluginMethod(sdk2, {
3172
+ name: "bundleCode",
3173
+ categories: ["utility", "deprecated"],
3174
+ inputSchema: BundleCodeSchema,
3175
+ handler: async ({ options }) => bundleCode(options)
3176
+ })
3177
+ );
3206
3178
  var ZapierBundleError = class extends Error {
3207
3179
  constructor(message, details, originalError) {
3208
3180
  super(message);
@@ -3269,25 +3241,14 @@ async function bundleCode(options) {
3269
3241
  }
3270
3242
  }
3271
3243
  var GetLoginConfigPathSchema = zod.z.object({}).describe("Show the path to the login configuration file");
3272
- var getLoginConfigPathPlugin = () => {
3273
- const getLoginConfigPathWithSdk = zapierSdk.createFunction(
3274
- async function getLoginConfigPathWithSdk2(_options) {
3275
- return getConfigPath();
3276
- },
3277
- GetLoginConfigPathSchema
3278
- );
3279
- return {
3280
- getLoginConfigPath: getLoginConfigPathWithSdk,
3281
- context: {
3282
- meta: {
3283
- getLoginConfigPath: {
3284
- categories: ["utility"],
3285
- inputSchema: GetLoginConfigPathSchema
3286
- }
3287
- }
3288
- }
3289
- };
3290
- };
3244
+ var getLoginConfigPathPlugin = zapierSdk.definePlugin(
3245
+ (sdk2) => zapierSdk.createPluginMethod(sdk2, {
3246
+ name: "getLoginConfigPath",
3247
+ categories: ["utility"],
3248
+ inputSchema: GetLoginConfigPathSchema,
3249
+ handler: async () => getConfigPath()
3250
+ })
3251
+ );
3291
3252
  var AddSchema = zod.z.object({
3292
3253
  apps: zod.z.array(zod.z.string().min(1, "App key cannot be empty")).min(1, "At least one app key is required").describe(
3293
3254
  "One or more app keys to add (e.g., 'slack', 'github', 'trello')"
@@ -3315,111 +3276,105 @@ async function detectTypesOutputDirectory() {
3315
3276
  }
3316
3277
  return "./zapier/apps/";
3317
3278
  }
3318
- var addPlugin = (sdk2) => {
3319
- const add = zapierSdk.createFunction(async function add2(options) {
3320
- const {
3321
- apps: appKeys,
3322
- connections: connectionIds,
3323
- configPath,
3324
- typesOutput = await detectTypesOutputDirectory()
3325
- } = options;
3326
- const resolvedTypesOutput = path.resolve(typesOutput);
3327
- console.log(`\u{1F4E6} Adding ${appKeys.length} app(s)...`);
3328
- const appSlugAndKeyMap = /* @__PURE__ */ new Map();
3329
- const handleManifestProgress = (event) => {
3330
- switch (event.type) {
3331
- case "apps_lookup_start":
3332
- console.log(`\u{1F4E6} Looking up ${event.count} app(s)...`);
3333
- break;
3334
- case "app_found":
3335
- const displayName = event.app.slug ? `${event.app.slug} (${event.app.key})` : event.app.key;
3336
- appSlugAndKeyMap.set(event.app.key, displayName);
3337
- break;
3338
- case "apps_lookup_complete":
3339
- if (event.count === 0) {
3340
- console.warn("\u26A0\uFE0F No apps found");
3341
- }
3342
- break;
3343
- case "app_processing_start":
3344
- const appName = event.slug ? `${event.slug} (${event.app})` : event.app;
3345
- console.log(`\u{1F4E6} Adding ${appName}...`);
3346
- break;
3347
- case "manifest_updated":
3348
- const appDisplay = appSlugAndKeyMap.get(event.app) || event.app;
3349
- console.log(
3350
- `\u{1F4DD} Locked ${appDisplay} to ${event.app}@${event.version} using key '${event.manifestKey}'`
3351
- );
3352
- break;
3353
- case "app_processing_error":
3354
- const errorApp = appSlugAndKeyMap.get(event.app) || event.app;
3355
- console.warn(`\u26A0\uFE0F ${event.error} for ${errorApp}`);
3356
- break;
3357
- }
3358
- };
3359
- const handleTypesProgress = (event) => {
3360
- switch (event.type) {
3361
- case "connections_lookup_start":
3362
- console.log(`\u{1F510} Looking up ${event.count} connection(s)...`);
3363
- break;
3364
- case "connections_lookup_complete":
3365
- console.log(`\u{1F510} Found ${event.count} connection(s)`);
3366
- break;
3367
- case "connection_matched":
3368
- const appWithConnection = appSlugAndKeyMap.get(event.app) || event.app;
3369
- console.log(
3370
- `\u{1F510} Using connection ${event.connectionId} (${event.connectionTitle}) for ${appWithConnection}`
3371
- );
3372
- break;
3373
- case "connection_not_matched":
3374
- const appWithoutConnection = appSlugAndKeyMap.get(event.app) || event.app;
3375
- console.warn(
3376
- `\u26A0\uFE0F No matching connection found for ${appWithoutConnection}`
3377
- );
3378
- break;
3379
- case "file_written":
3380
- console.log(
3381
- `\u{1F527} Generated types for ${event.manifestKey} at ${event.filePath}`
3382
- );
3383
- break;
3384
- case "app_processing_error":
3385
- const errorApp = appSlugAndKeyMap.get(event.app) || event.app;
3386
- console.warn(`\u26A0\uFE0F ${event.error} for ${errorApp}`);
3387
- break;
3388
- }
3389
- };
3390
- const manifestResult = await sdk2.buildManifest({
3391
- apps: appKeys,
3392
- skipWrite: false,
3393
- configPath,
3394
- onProgress: handleManifestProgress
3395
- });
3396
- const typesResult = await sdk2.generateAppTypes({
3397
- apps: appKeys,
3398
- connections: connectionIds,
3399
- skipWrite: false,
3400
- typesOutputDirectory: resolvedTypesOutput,
3401
- onProgress: handleTypesProgress
3402
- });
3403
- const results = manifestResult.manifest?.apps || {};
3404
- const successfulApps = Object.keys(results).filter(
3405
- (manifestKey) => typesResult.writtenFiles?.[manifestKey]
3406
- );
3407
- if (successfulApps.length > 0) {
3408
- console.log(`\u2705 Added ${successfulApps.length} app(s) to manifest`);
3409
- }
3410
- }, AddSchema);
3411
- return {
3412
- add,
3413
- context: {
3414
- meta: {
3415
- add: {
3416
- categories: ["utility"],
3417
- inputSchema: AddSchema
3279
+ var addPlugin = zapierSdk.definePlugin(
3280
+ (sdk2) => zapierSdk.createPluginMethod(sdk2, {
3281
+ name: "add",
3282
+ categories: ["utility"],
3283
+ inputSchema: AddSchema,
3284
+ handler: async ({ sdk: sdk3, options }) => {
3285
+ const {
3286
+ apps: appKeys,
3287
+ connections: connectionIds,
3288
+ configPath,
3289
+ typesOutput = await detectTypesOutputDirectory()
3290
+ } = options;
3291
+ const resolvedTypesOutput = path.resolve(typesOutput);
3292
+ console.log(`\u{1F4E6} Adding ${appKeys.length} app(s)...`);
3293
+ const appSlugAndKeyMap = /* @__PURE__ */ new Map();
3294
+ const handleManifestProgress = (event) => {
3295
+ switch (event.type) {
3296
+ case "apps_lookup_start":
3297
+ console.log(`\u{1F4E6} Looking up ${event.count} app(s)...`);
3298
+ break;
3299
+ case "app_found":
3300
+ const displayName = event.app.slug ? `${event.app.slug} (${event.app.key})` : event.app.key;
3301
+ appSlugAndKeyMap.set(event.app.key, displayName);
3302
+ break;
3303
+ case "apps_lookup_complete":
3304
+ if (event.count === 0) {
3305
+ console.warn("\u26A0\uFE0F No apps found");
3306
+ }
3307
+ break;
3308
+ case "app_processing_start":
3309
+ const appName = event.slug ? `${event.slug} (${event.app})` : event.app;
3310
+ console.log(`\u{1F4E6} Adding ${appName}...`);
3311
+ break;
3312
+ case "manifest_updated":
3313
+ const appDisplay = appSlugAndKeyMap.get(event.app) || event.app;
3314
+ console.log(
3315
+ `\u{1F4DD} Locked ${appDisplay} to ${event.app}@${event.version} using key '${event.manifestKey}'`
3316
+ );
3317
+ break;
3318
+ case "app_processing_error":
3319
+ const errorApp = appSlugAndKeyMap.get(event.app) || event.app;
3320
+ console.warn(`\u26A0\uFE0F ${event.error} for ${errorApp}`);
3321
+ break;
3322
+ }
3323
+ };
3324
+ const handleTypesProgress = (event) => {
3325
+ switch (event.type) {
3326
+ case "connections_lookup_start":
3327
+ console.log(`\u{1F510} Looking up ${event.count} connection(s)...`);
3328
+ break;
3329
+ case "connections_lookup_complete":
3330
+ console.log(`\u{1F510} Found ${event.count} connection(s)`);
3331
+ break;
3332
+ case "connection_matched":
3333
+ const appWithConnection = appSlugAndKeyMap.get(event.app) || event.app;
3334
+ console.log(
3335
+ `\u{1F510} Using connection ${event.connectionId} (${event.connectionTitle}) for ${appWithConnection}`
3336
+ );
3337
+ break;
3338
+ case "connection_not_matched":
3339
+ const appWithoutConnection = appSlugAndKeyMap.get(event.app) || event.app;
3340
+ console.warn(
3341
+ `\u26A0\uFE0F No matching connection found for ${appWithoutConnection}`
3342
+ );
3343
+ break;
3344
+ case "file_written":
3345
+ console.log(
3346
+ `\u{1F527} Generated types for ${event.manifestKey} at ${event.filePath}`
3347
+ );
3348
+ break;
3349
+ case "app_processing_error":
3350
+ const errorApp = appSlugAndKeyMap.get(event.app) || event.app;
3351
+ console.warn(`\u26A0\uFE0F ${event.error} for ${errorApp}`);
3352
+ break;
3418
3353
  }
3354
+ };
3355
+ const manifestResult = await sdk3.buildManifest({
3356
+ apps: appKeys,
3357
+ skipWrite: false,
3358
+ configPath,
3359
+ onProgress: handleManifestProgress
3360
+ });
3361
+ const typesResult = await sdk3.generateAppTypes({
3362
+ apps: appKeys,
3363
+ connections: connectionIds,
3364
+ skipWrite: false,
3365
+ typesOutputDirectory: resolvedTypesOutput,
3366
+ onProgress: handleTypesProgress
3367
+ });
3368
+ const results = manifestResult.manifest?.apps || {};
3369
+ const successfulApps = Object.keys(results).filter(
3370
+ (manifestKey) => typesResult.writtenFiles?.[manifestKey]
3371
+ );
3372
+ if (successfulApps.length > 0) {
3373
+ console.log(`\u2705 Added ${successfulApps.length} app(s) to manifest`);
3419
3374
  }
3420
3375
  }
3421
- };
3422
- };
3376
+ })
3377
+ );
3423
3378
  var GenerateAppTypesSchema = zod.z.object({
3424
3379
  apps: zod.z.array(zod.z.string().min(1, "App key cannot be empty")).min(1, "At least one app key is required").describe(
3425
3380
  "One or more app keys to generate types for (e.g., 'slack', 'github', 'trello')"
@@ -4026,150 +3981,133 @@ function createManifestEntry(app) {
4026
3981
  version: app.version
4027
3982
  };
4028
3983
  }
4029
- var generateAppTypesPlugin = (sdk2) => {
4030
- const generateAppTypes = zapierSdk.createFunction(async function generateAppTypes2(options) {
4031
- const {
4032
- apps: appKeys,
4033
- connections: connectionIds,
4034
- skipWrite = false,
4035
- typesOutputDirectory = await detectTypesOutputDirectory(),
4036
- onProgress
4037
- } = options;
4038
- const resolvedTypesOutput = path.resolve(typesOutputDirectory);
4039
- const result = {
4040
- typeDefinitions: {}
4041
- };
4042
- onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
4043
- const appsIterable = sdk2.listApps({ apps: appKeys }).items();
4044
- const apps = [];
4045
- for await (const app of appsIterable) {
4046
- apps.push(app);
4047
- onProgress?.({ type: "app_found", app });
4048
- }
4049
- onProgress?.({ type: "apps_lookup_complete", count: apps.length });
4050
- if (apps.length === 0) {
4051
- return result;
4052
- }
4053
- const connections = [];
4054
- if (connectionIds && connectionIds.length > 0) {
4055
- onProgress?.({
4056
- type: "connections_lookup_start",
4057
- count: connectionIds.length
4058
- });
4059
- const connectionsIterable = sdk2.listConnections({ connections: connectionIds }).items();
4060
- for await (const connection of connectionsIterable) {
4061
- connections.push(connection);
3984
+ var generateAppTypesPlugin = zapierSdk.definePlugin(
3985
+ (sdk2) => zapierSdk.createPluginMethod(sdk2, {
3986
+ name: "generateAppTypes",
3987
+ categories: ["utility"],
3988
+ // Cast: schema validates JSON fields only; GenerateAppTypesOptions adds
3989
+ // the runtime-only `onProgress` callback (passthrough via createFunction).
3990
+ inputSchema: GenerateAppTypesSchema,
3991
+ handler: async ({ sdk: sdk3, options }) => {
3992
+ const {
3993
+ apps: appKeys,
3994
+ connections: connectionIds,
3995
+ skipWrite = false,
3996
+ typesOutputDirectory = await detectTypesOutputDirectory(),
3997
+ onProgress
3998
+ } = options;
3999
+ const resolvedTypesOutput = path.resolve(typesOutputDirectory);
4000
+ const result = { typeDefinitions: {} };
4001
+ onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
4002
+ const appsIterable = sdk3.listApps({ apps: appKeys }).items();
4003
+ const apps = [];
4004
+ for await (const app of appsIterable) {
4005
+ apps.push(app);
4006
+ onProgress?.({ type: "app_found", app });
4062
4007
  }
4063
- onProgress?.({
4064
- type: "connections_lookup_complete",
4065
- count: connections.length
4066
- });
4067
- }
4068
- if (!skipWrite && resolvedTypesOutput) {
4069
- await promises.mkdir(resolvedTypesOutput, { recursive: true });
4070
- }
4071
- if (!skipWrite) {
4072
- result.writtenFiles = {};
4073
- }
4074
- for (const app of apps) {
4075
- onProgress?.({
4076
- type: "app_processing_start",
4077
- app: app.key,
4078
- slug: app.slug
4079
- });
4080
- try {
4081
- if (!app.version) {
4082
- const errorMessage = `Invalid implementation ID format: ${app.implementation_id}. Expected format: <implementationName>@<version>`;
4083
- onProgress?.({
4084
- type: "app_processing_error",
4085
- app: app.key,
4086
- error: errorMessage
4087
- });
4088
- throw new zapierSdk.ZapierValidationError(errorMessage, {
4089
- details: {
4090
- appKey: app.key,
4091
- implementationId: app.implementation_id
4092
- }
4093
- });
4008
+ onProgress?.({ type: "apps_lookup_complete", count: apps.length });
4009
+ if (apps.length === 0) {
4010
+ return result;
4011
+ }
4012
+ const connections = [];
4013
+ if (connectionIds && connectionIds.length > 0) {
4014
+ onProgress?.({
4015
+ type: "connections_lookup_start",
4016
+ count: connectionIds.length
4017
+ });
4018
+ const connectionsIterable = sdk3.listConnections({ connections: connectionIds }).items();
4019
+ for await (const connection of connectionsIterable) {
4020
+ connections.push(connection);
4094
4021
  }
4095
- let connectionId;
4096
- if (connections.length > 0) {
4097
- const matchingConnection = connections.find((conn) => {
4098
- return conn.app_key === app.key;
4099
- });
4100
- if (matchingConnection) {
4101
- connectionId = matchingConnection.id;
4022
+ onProgress?.({
4023
+ type: "connections_lookup_complete",
4024
+ count: connections.length
4025
+ });
4026
+ }
4027
+ if (!skipWrite && resolvedTypesOutput) {
4028
+ await promises.mkdir(resolvedTypesOutput, { recursive: true });
4029
+ }
4030
+ if (!skipWrite) {
4031
+ result.writtenFiles = {};
4032
+ }
4033
+ for (const app of apps) {
4034
+ onProgress?.({
4035
+ type: "app_processing_start",
4036
+ app: app.key,
4037
+ slug: app.slug
4038
+ });
4039
+ try {
4040
+ if (!app.version) {
4041
+ const errorMessage = `Invalid implementation ID format: ${app.implementation_id}. Expected format: <implementationName>@<version>`;
4102
4042
  onProgress?.({
4103
- type: "connection_matched",
4043
+ type: "app_processing_error",
4104
4044
  app: app.key,
4105
- connectionId: matchingConnection.id,
4106
- connectionTitle: matchingConnection.title || ""
4045
+ error: errorMessage
4107
4046
  });
4108
- } else {
4109
- onProgress?.({
4110
- type: "connection_not_matched",
4111
- app: app.key
4047
+ throw new zapierSdk.ZapierValidationError(errorMessage, {
4048
+ details: {
4049
+ appKey: app.key,
4050
+ implementationId: app.implementation_id
4051
+ }
4112
4052
  });
4113
4053
  }
4114
- }
4115
- const manifestKey = getManifestKey(app);
4116
- const generator = new AstTypeGenerator();
4117
- const typeDefinitionString = await generator.generateTypes({
4118
- app,
4119
- connectionId,
4120
- sdk: sdk2
4121
- });
4122
- result.typeDefinitions[manifestKey] = typeDefinitionString;
4123
- onProgress?.({
4124
- type: "type_generated",
4125
- manifestKey,
4126
- sizeBytes: typeDefinitionString.length
4127
- });
4128
- if (!skipWrite && resolvedTypesOutput && result.writtenFiles) {
4129
- const filePath = path.join(resolvedTypesOutput, `${manifestKey}.d.ts`);
4130
- await promises.writeFile(filePath, typeDefinitionString, "utf8");
4131
- result.writtenFiles[manifestKey] = filePath;
4054
+ let connectionId;
4055
+ if (connections.length > 0) {
4056
+ const matchingConnection = connections.find(
4057
+ (conn) => conn.app_key === app.key
4058
+ );
4059
+ if (matchingConnection) {
4060
+ connectionId = matchingConnection.id;
4061
+ onProgress?.({
4062
+ type: "connection_matched",
4063
+ app: app.key,
4064
+ connectionId: matchingConnection.id,
4065
+ connectionTitle: matchingConnection.title || ""
4066
+ });
4067
+ } else {
4068
+ onProgress?.({
4069
+ type: "connection_not_matched",
4070
+ app: app.key
4071
+ });
4072
+ }
4073
+ }
4074
+ const manifestKey = getManifestKey(app);
4075
+ const generator = new AstTypeGenerator();
4076
+ const typeDefinitionString = await generator.generateTypes({
4077
+ app,
4078
+ connectionId,
4079
+ sdk: sdk3
4080
+ });
4081
+ result.typeDefinitions[manifestKey] = typeDefinitionString;
4132
4082
  onProgress?.({
4133
- type: "file_written",
4083
+ type: "type_generated",
4134
4084
  manifestKey,
4135
- filePath
4085
+ sizeBytes: typeDefinitionString.length
4136
4086
  });
4137
- }
4138
- onProgress?.({
4139
- type: "app_processing_complete",
4140
- app: app.key
4141
- });
4142
- } catch (error) {
4143
- const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
4144
- onProgress?.({
4145
- type: "app_processing_error",
4146
- app: app.key,
4147
- error: errorMessage
4148
- });
4149
- if (error instanceof zapierSdk.ZapierValidationError) {
4150
- throw error;
4151
- } else {
4152
- throw new zapierSdk.ZapierUnknownError(errorMessage, {
4153
- cause: error
4154
- // Works for both Error and non-Error
4087
+ if (!skipWrite && resolvedTypesOutput && result.writtenFiles) {
4088
+ const filePath = path.join(resolvedTypesOutput, `${manifestKey}.d.ts`);
4089
+ await promises.writeFile(filePath, typeDefinitionString, "utf8");
4090
+ result.writtenFiles[manifestKey] = filePath;
4091
+ onProgress?.({ type: "file_written", manifestKey, filePath });
4092
+ }
4093
+ onProgress?.({ type: "app_processing_complete", app: app.key });
4094
+ } catch (error) {
4095
+ const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
4096
+ onProgress?.({
4097
+ type: "app_processing_error",
4098
+ app: app.key,
4099
+ error: errorMessage
4155
4100
  });
4101
+ if (error instanceof zapierSdk.ZapierValidationError) {
4102
+ throw error;
4103
+ }
4104
+ throw new zapierSdk.ZapierUnknownError(errorMessage, { cause: error });
4156
4105
  }
4157
4106
  }
4107
+ return result;
4158
4108
  }
4159
- return result;
4160
- }, GenerateAppTypesSchema);
4161
- return {
4162
- generateAppTypes,
4163
- context: {
4164
- meta: {
4165
- generateAppTypes: {
4166
- categories: ["utility"],
4167
- inputSchema: GenerateAppTypesSchema
4168
- }
4169
- }
4170
- }
4171
- };
4172
- };
4109
+ })
4110
+ );
4173
4111
  var BuildManifestSchema = zod.z.object({
4174
4112
  apps: zod.z.array(zod.z.string().min(1, "App key cannot be empty")).min(1, "At least one app key is required").describe(
4175
4113
  "One or more app keys to build manifest entries for (e.g., 'slack', 'github', 'trello')"
@@ -4185,86 +4123,80 @@ var BuildManifestSchema = zod.z.object({
4185
4123
  );
4186
4124
 
4187
4125
  // src/plugins/buildManifest/index.ts
4188
- var buildManifestPlugin = (sdk2) => {
4189
- const buildManifest = zapierSdk.createFunction(async function buildManifest2(options) {
4190
- const {
4191
- apps: appKeys,
4192
- skipWrite = false,
4193
- configPath,
4194
- onProgress
4195
- } = options;
4196
- onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
4197
- const appsIterable = sdk2.listApps({ apps: appKeys }).items();
4198
- const apps = [];
4199
- for await (const app of appsIterable) {
4200
- apps.push(app);
4201
- onProgress?.({ type: "app_found", app });
4202
- }
4203
- onProgress?.({ type: "apps_lookup_complete", count: apps.length });
4204
- if (apps.length === 0) {
4205
- return {};
4206
- }
4207
- let updatedManifest;
4208
- for (const app of apps) {
4209
- onProgress?.({
4210
- type: "app_processing_start",
4211
- app: app.key,
4212
- slug: app.slug
4213
- });
4214
- try {
4215
- const manifestEntry = createManifestEntry(app);
4216
- onProgress?.({
4217
- type: "manifest_entry_built",
4218
- app: app.key,
4219
- manifestKey: manifestEntry.implementationName,
4220
- version: manifestEntry.version || ""
4221
- });
4222
- const { key: updatedManifestKey, manifest } = await sdk2.context.updateManifestEntry({
4223
- appKey: app.key,
4224
- entry: manifestEntry,
4225
- configPath,
4226
- skipWrite,
4227
- manifest: updatedManifest
4228
- });
4229
- updatedManifest = manifest;
4230
- onProgress?.({
4231
- type: "manifest_updated",
4232
- app: app.key,
4233
- manifestKey: updatedManifestKey,
4234
- version: manifestEntry.version || ""
4235
- });
4236
- onProgress?.({ type: "app_processing_complete", app: app.key });
4237
- } catch (error) {
4238
- const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
4126
+ var buildManifestPlugin = zapierSdk.definePlugin(
4127
+ (sdk2) => zapierSdk.createPluginMethod(sdk2, {
4128
+ name: "buildManifest",
4129
+ categories: ["utility"],
4130
+ // Cast: BuildManifestSchema validates JSON-serializable fields only.
4131
+ // BuildManifestOptions adds an `onProgress` callback that rides through
4132
+ // `createFunction`'s passthrough spread at runtime; this widens TInput
4133
+ // so the handler can read it.
4134
+ inputSchema: BuildManifestSchema,
4135
+ handler: async ({ sdk: sdk3, options }) => {
4136
+ const {
4137
+ apps: appKeys,
4138
+ skipWrite = false,
4139
+ configPath,
4140
+ onProgress
4141
+ } = options;
4142
+ onProgress?.({ type: "apps_lookup_start", count: appKeys.length });
4143
+ const appsIterable = sdk3.listApps({ apps: appKeys }).items();
4144
+ const apps = [];
4145
+ for await (const app of appsIterable) {
4146
+ apps.push(app);
4147
+ onProgress?.({ type: "app_found", app });
4148
+ }
4149
+ onProgress?.({ type: "apps_lookup_complete", count: apps.length });
4150
+ if (apps.length === 0) {
4151
+ return {};
4152
+ }
4153
+ let updatedManifest;
4154
+ for (const app of apps) {
4239
4155
  onProgress?.({
4240
- type: "app_processing_error",
4156
+ type: "app_processing_start",
4241
4157
  app: app.key,
4242
- error: errorMessage
4158
+ slug: app.slug
4243
4159
  });
4244
- if (error instanceof zapierSdk.ZapierValidationError) {
4245
- throw error;
4246
- } else {
4247
- throw new zapierSdk.ZapierUnknownError(errorMessage, {
4248
- cause: error
4249
- // Works for both Error and non-Error
4160
+ try {
4161
+ const manifestEntry = createManifestEntry(app);
4162
+ onProgress?.({
4163
+ type: "manifest_entry_built",
4164
+ app: app.key,
4165
+ manifestKey: manifestEntry.implementationName,
4166
+ version: manifestEntry.version || ""
4250
4167
  });
4168
+ const { key: updatedManifestKey, manifest } = await sdk3.context.updateManifestEntry({
4169
+ appKey: app.key,
4170
+ entry: manifestEntry,
4171
+ configPath,
4172
+ skipWrite,
4173
+ manifest: updatedManifest
4174
+ });
4175
+ updatedManifest = manifest;
4176
+ onProgress?.({
4177
+ type: "manifest_updated",
4178
+ app: app.key,
4179
+ manifestKey: updatedManifestKey,
4180
+ version: manifestEntry.version || ""
4181
+ });
4182
+ onProgress?.({ type: "app_processing_complete", app: app.key });
4183
+ } catch (error) {
4184
+ const errorMessage = `Failed to process app ${app.key}: ${error instanceof Error ? error.message : String(error)}`;
4185
+ onProgress?.({
4186
+ type: "app_processing_error",
4187
+ app: app.key,
4188
+ error: errorMessage
4189
+ });
4190
+ if (error instanceof zapierSdk.ZapierValidationError) {
4191
+ throw error;
4192
+ }
4193
+ throw new zapierSdk.ZapierUnknownError(errorMessage, { cause: error });
4251
4194
  }
4252
4195
  }
4196
+ return { manifest: updatedManifest };
4253
4197
  }
4254
- return { manifest: updatedManifest };
4255
- }, BuildManifestSchema);
4256
- return {
4257
- buildManifest,
4258
- context: {
4259
- meta: {
4260
- buildManifest: {
4261
- categories: ["utility"],
4262
- inputSchema: BuildManifestSchema
4263
- }
4264
- }
4265
- }
4266
- };
4267
- };
4198
+ })
4199
+ );
4268
4200
  var FeedbackSchema = zod.z.object({
4269
4201
  feedback: zod.z.string().describe(
4270
4202
  "Your feedback on the Zapier SDK. Describe what worked well, what was frustrating, or any suggestions."
@@ -4298,37 +4230,31 @@ async function postWithRetry({
4298
4230
  }
4299
4231
  return response;
4300
4232
  }
4301
- var feedbackPlugin = (sdk2) => {
4302
- const debug = sdk2.context.options?.debug;
4303
- const feedbackWithSdk = zapierSdk.createFunction(async function feedback(options) {
4304
- const user = await getLoggedInUser();
4305
- const body = JSON.stringify({
4306
- email: user.email,
4307
- customuser_id: user.customUserId,
4308
- feedback: options.feedback
4309
- });
4310
- const response = await postWithRetry({ body, attemptsLeft: MAX_RETRIES });
4311
- if (debug) {
4312
- const text = await response.text();
4313
- console.error("[debug] Webhook response:", text);
4314
- }
4315
- return "Thank you for your feedback!";
4316
- }, FeedbackSchema);
4317
- return {
4318
- feedback: feedbackWithSdk,
4319
- context: {
4320
- meta: {
4321
- feedback: {
4322
- categories: ["utility"],
4323
- inputSchema: FeedbackSchema,
4324
- resolvers: {
4325
- feedback: feedbackResolver
4326
- }
4327
- }
4233
+ var feedbackPlugin = zapierSdk.definePlugin(
4234
+ (sdk2) => zapierSdk.createPluginMethod(sdk2, {
4235
+ name: "feedback",
4236
+ categories: ["utility"],
4237
+ inputSchema: FeedbackSchema,
4238
+ resolvers: { feedback: feedbackResolver },
4239
+ handler: async ({ sdk: sdk3, options }) => {
4240
+ const user = await getLoggedInUser();
4241
+ const body = JSON.stringify({
4242
+ email: user.email,
4243
+ customuser_id: user.customUserId,
4244
+ feedback: options.feedback
4245
+ });
4246
+ const response = await postWithRetry({
4247
+ body,
4248
+ attemptsLeft: MAX_RETRIES
4249
+ });
4250
+ if (sdk3.context.options?.debug) {
4251
+ const text = await response.text();
4252
+ console.error("[debug] Webhook response:", text);
4328
4253
  }
4254
+ return "Thank you for your feedback!";
4329
4255
  }
4330
- };
4331
- };
4256
+ })
4257
+ );
4332
4258
  var CurlSchema = zod.z.object({
4333
4259
  url: zod.z.string().describe("Request URL"),
4334
4260
  request: zod.z.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]).optional().describe("HTTP method (defaults to GET, or POST if data is provided)"),
@@ -4504,7 +4430,7 @@ async function buildFormData(formArgs, formStringArgs) {
4504
4430
  }
4505
4431
 
4506
4432
  // src/plugins/curl/index.ts
4507
- var curlPlugin = (sdk2) => {
4433
+ var curlPlugin = zapierSdk.definePlugin((sdk2) => {
4508
4434
  async function curl(options) {
4509
4435
  const {
4510
4436
  url: rawUrl,
@@ -4747,30 +4673,25 @@ ${Array.from(
4747
4673
  }
4748
4674
  }
4749
4675
  };
4750
- };
4751
-
4752
- // src/plugins/cliOverrides/index.ts
4753
- var cliOverridesPlugin = (sdk2) => {
4754
- if (!sdk2.context.meta.fetch) {
4755
- return { context: { meta: {} } };
4756
- }
4757
- return {
4758
- context: {
4759
- meta: {
4760
- fetch: {
4761
- ...sdk2.context.meta.fetch,
4762
- categories: [
4763
- ...sdk2.context.meta.fetch.categories || [],
4764
- "deprecated"
4765
- ],
4766
- deprecation: {
4767
- message: "This command is deprecated and will be removed soon. Use `curl` instead. Learn more: https://docs.zapier.com/sdk/cli-reference#curl"
4768
- }
4676
+ });
4677
+ var cliOverridesPlugin = zapierSdk.definePlugin(
4678
+ (sdk2) => {
4679
+ const meta = {};
4680
+ if (sdk2.context.meta.fetch) {
4681
+ meta.fetch = {
4682
+ ...sdk2.context.meta.fetch,
4683
+ categories: [
4684
+ ...sdk2.context.meta.fetch.categories || [],
4685
+ "deprecated"
4686
+ ],
4687
+ deprecation: {
4688
+ message: "This command is deprecated and will be removed soon. Use `curl` instead. Learn more: https://docs.zapier.com/sdk/cli-reference#curl"
4769
4689
  }
4770
- }
4690
+ };
4771
4691
  }
4772
- };
4773
- };
4692
+ return { context: { meta } };
4693
+ }
4694
+ );
4774
4695
  var TEMPLATES = ["basic"];
4775
4696
  var InitSchema = zod.z.object({
4776
4697
  projectName: zod.z.string().min(1).describe("Name of the project directory to create"),
@@ -5209,71 +5130,65 @@ function displaySummaryAndNextSteps({
5209
5130
  }
5210
5131
 
5211
5132
  // src/plugins/init/index.ts
5212
- var initPlugin = () => {
5213
- const init = zapierSdk.createFunction(async function init2(options) {
5214
- const { projectName: rawName, skipPrompts = false } = options;
5215
- const cwd = process.cwd();
5216
- const { projectName, projectDir } = validateInitOptions({ rawName, cwd });
5217
- const displayHooks = createConsoleDisplayHooks();
5218
- const packageManagerInfo = detectPackageManager(cwd);
5219
- if (packageManagerInfo.name === "unknown") {
5220
- displayHooks.onWarn(
5221
- "Could not detect package manager, defaulting to npm."
5222
- );
5223
- }
5224
- const packageManager = packageManagerInfo.name === "unknown" ? "npm" : packageManagerInfo.name;
5225
- const steps = getInitSteps({
5226
- projectDir,
5227
- projectName,
5228
- packageManager,
5229
- displayHooks
5230
- });
5231
- const completedSetupStepIds = [];
5232
- for (let i = 0; i < steps.length; i++) {
5233
- const step = steps[i];
5234
- const succeeded = await withInterruptCleanup(
5235
- step.cleanup,
5236
- () => runStep({
5237
- step,
5238
- stepNumber: i + 1,
5239
- totalSteps: steps.length,
5240
- skipPrompts,
5241
- displayHooks
5242
- })
5243
- );
5244
- if (!succeeded) break;
5245
- completedSetupStepIds.push(step.id);
5246
- }
5247
- if (completedSetupStepIds.length === 0) {
5248
- throw new ZapierCliExitError(
5249
- "Project setup failed \u2014 no steps completed."
5250
- );
5251
- }
5252
- displaySummaryAndNextSteps({
5253
- projectName,
5254
- steps,
5255
- completedSetupStepIds,
5256
- packageManager
5257
- });
5258
- }, InitSchema);
5259
- return {
5260
- init,
5261
- context: {
5262
- meta: {
5263
- init: {
5264
- categories: ["utility"],
5265
- inputSchema: InitSchema,
5266
- supportsJsonOutput: false
5267
- }
5133
+ var initPlugin = zapierSdk.definePlugin(
5134
+ (sdk2) => zapierSdk.createPluginMethod(sdk2, {
5135
+ name: "init",
5136
+ categories: ["utility"],
5137
+ inputSchema: InitSchema,
5138
+ supportsJsonOutput: false,
5139
+ handler: async ({ options }) => {
5140
+ const { projectName: rawName, skipPrompts = false } = options;
5141
+ const cwd = process.cwd();
5142
+ const { projectName, projectDir } = validateInitOptions({ rawName, cwd });
5143
+ const displayHooks = createConsoleDisplayHooks();
5144
+ const packageManagerInfo = detectPackageManager(cwd);
5145
+ if (packageManagerInfo.name === "unknown") {
5146
+ displayHooks.onWarn(
5147
+ "Could not detect package manager, defaulting to npm."
5148
+ );
5149
+ }
5150
+ const packageManager = packageManagerInfo.name === "unknown" ? "npm" : packageManagerInfo.name;
5151
+ const steps = getInitSteps({
5152
+ projectDir,
5153
+ projectName,
5154
+ packageManager,
5155
+ displayHooks
5156
+ });
5157
+ const completedSetupStepIds = [];
5158
+ for (let i = 0; i < steps.length; i++) {
5159
+ const step = steps[i];
5160
+ const succeeded = await withInterruptCleanup(
5161
+ step.cleanup,
5162
+ () => runStep({
5163
+ step,
5164
+ stepNumber: i + 1,
5165
+ totalSteps: steps.length,
5166
+ skipPrompts,
5167
+ displayHooks
5168
+ })
5169
+ );
5170
+ if (!succeeded) break;
5171
+ completedSetupStepIds.push(step.id);
5268
5172
  }
5173
+ if (completedSetupStepIds.length === 0) {
5174
+ throw new ZapierCliExitError(
5175
+ "Project setup failed \u2014 no steps completed."
5176
+ );
5177
+ }
5178
+ displaySummaryAndNextSteps({
5179
+ projectName,
5180
+ steps,
5181
+ completedSetupStepIds,
5182
+ packageManager
5183
+ });
5269
5184
  }
5270
- };
5271
- };
5185
+ })
5186
+ );
5272
5187
 
5273
5188
  // package.json with { type: 'json' }
5274
5189
  var package_default2 = {
5275
5190
  name: "@zapier/zapier-sdk-cli",
5276
- version: "0.43.0"};
5191
+ version: "0.43.1"};
5277
5192
 
5278
5193
  // src/sdk.ts
5279
5194
  zapierSdk.injectCliLogin(login_exports);