@zapier/zapier-sdk-cli 0.6.2 → 0.6.4

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 (91) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +115 -12
  3. package/bin/{zapier-sdk.js → zapier-sdk.mjs} +1 -1
  4. package/dist/cli.cjs +1711 -0
  5. package/dist/cli.d.mts +1 -0
  6. package/dist/cli.d.ts +1 -0
  7. package/dist/{cli.js → cli.mjs} +204 -456
  8. package/dist/index.cjs +770 -0
  9. package/dist/index.d.mts +12 -0
  10. package/dist/index.d.ts +12 -0
  11. package/dist/index.mjs +739 -0
  12. package/dist/package.json +67 -0
  13. package/dist/src/cli.js +8 -14
  14. package/dist/src/index.d.ts +1 -0
  15. package/dist/src/index.js +1 -1
  16. package/dist/src/plugins/bundleCode/index.d.ts +15 -0
  17. package/dist/src/{commands/bundle-code → plugins/bundleCode}/index.js +19 -1
  18. package/dist/src/{commands/bundle-code → plugins/bundleCode}/schemas.d.ts +8 -8
  19. package/dist/src/{commands/bundle-code → plugins/bundleCode}/schemas.js +4 -4
  20. package/dist/src/plugins/generateTypes/index.d.ts +21 -0
  21. package/dist/src/{commands/generate-types → plugins/generateTypes}/index.js +18 -0
  22. package/dist/src/{commands/generate-types → plugins/generateTypes}/schemas.d.ts +0 -3
  23. package/dist/src/{commands/generate-types → plugins/generateTypes}/schemas.js +1 -2
  24. package/dist/src/plugins/getConfigPath/index.d.ts +15 -0
  25. package/dist/src/plugins/getConfigPath/index.js +19 -0
  26. package/dist/src/plugins/getConfigPath/schemas.d.ts +3 -0
  27. package/dist/src/plugins/getConfigPath/schemas.js +5 -0
  28. package/dist/src/plugins/index.d.ts +6 -0
  29. package/dist/src/plugins/index.js +6 -0
  30. package/dist/src/plugins/login/index.d.ts +15 -0
  31. package/dist/src/plugins/login/index.js +26 -0
  32. package/dist/src/plugins/login/schemas.d.ts +9 -0
  33. package/dist/src/plugins/login/schemas.js +10 -0
  34. package/dist/src/plugins/logout/index.d.ts +15 -0
  35. package/dist/src/plugins/logout/index.js +18 -0
  36. package/dist/src/plugins/logout/schemas.d.ts +3 -0
  37. package/dist/src/plugins/logout/schemas.js +5 -0
  38. package/dist/src/plugins/mcp/index.d.ts +15 -0
  39. package/dist/src/plugins/mcp/index.js +24 -0
  40. package/dist/src/plugins/mcp/schemas.d.ts +9 -0
  41. package/dist/src/plugins/mcp/schemas.js +10 -0
  42. package/dist/src/sdk.d.ts +9 -0
  43. package/dist/src/sdk.js +22 -0
  44. package/dist/src/utils/cli-generator.js +4 -0
  45. package/dist/tsconfig.tsbuildinfo +1 -1
  46. package/package.json +19 -8
  47. package/src/cli.ts +8 -21
  48. package/src/index.ts +2 -0
  49. package/src/{commands/bundle-code → plugins/bundleCode}/index.ts +39 -2
  50. package/src/{commands/bundle-code → plugins/bundleCode}/schemas.ts +4 -4
  51. package/src/{commands/generate-types → plugins/generateTypes}/index.ts +56 -3
  52. package/src/{commands/generate-types → plugins/generateTypes}/schemas.ts +0 -4
  53. package/src/plugins/getConfigPath/index.ts +42 -0
  54. package/src/plugins/getConfigPath/schemas.ts +8 -0
  55. package/src/plugins/index.ts +6 -0
  56. package/src/plugins/login/index.ts +48 -0
  57. package/src/plugins/login/schemas.ts +13 -0
  58. package/src/plugins/logout/index.ts +37 -0
  59. package/src/plugins/logout/schemas.ts +8 -0
  60. package/src/plugins/mcp/index.ts +43 -0
  61. package/src/plugins/mcp/schemas.ts +13 -0
  62. package/src/sdk.ts +43 -0
  63. package/src/utils/cli-generator.ts +5 -0
  64. package/tsconfig.build.json +15 -3
  65. package/tsconfig.json +2 -2
  66. package/tsup.config.ts +10 -4
  67. package/bin/zsdk.js +0 -4
  68. package/dist/index.js +0 -0
  69. package/dist/src/commands/bundle-code/cli.d.ts +0 -2
  70. package/dist/src/commands/bundle-code/cli.js +0 -77
  71. package/dist/src/commands/bundle-code/index.d.ts +0 -5
  72. package/dist/src/commands/configPath.d.ts +0 -2
  73. package/dist/src/commands/configPath.js +0 -9
  74. package/dist/src/commands/generate-types/cli.d.ts +0 -2
  75. package/dist/src/commands/generate-types/cli.js +0 -84
  76. package/dist/src/commands/generate-types/index.d.ts +0 -8
  77. package/dist/src/commands/index.d.ts +0 -6
  78. package/dist/src/commands/index.js +0 -6
  79. package/dist/src/commands/login.d.ts +0 -2
  80. package/dist/src/commands/login.js +0 -25
  81. package/dist/src/commands/logout.d.ts +0 -2
  82. package/dist/src/commands/logout.js +0 -16
  83. package/dist/src/commands/mcp.d.ts +0 -2
  84. package/dist/src/commands/mcp.js +0 -11
  85. package/src/commands/bundle-code/cli.ts +0 -118
  86. package/src/commands/configPath.ts +0 -10
  87. package/src/commands/generate-types/cli.ts +0 -126
  88. package/src/commands/index.ts +0 -6
  89. package/src/commands/login.ts +0 -34
  90. package/src/commands/logout.ts +0 -19
  91. package/src/commands/mcp.ts +0 -14
@@ -1,27 +1,21 @@
1
1
  #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { z } from 'zod';
4
+ import { createFunction, OutputPropertySchema, AuthenticationIdPropertySchema, AppKeyPropertySchema, createZapierSdkWithoutRegistry, registryPlugin, ZapierError, formatErrorMessage, isPositional, hasResolver, getResolutionOrderForParams, getResolver } from '@zapier/zapier-sdk';
5
+ import inquirer from 'inquirer';
6
+ import chalk3 from 'chalk';
7
+ import util from 'util';
8
+ import open from 'open';
9
+ import crypto from 'crypto';
10
+ import express from 'express';
11
+ import pkceChallenge from 'pkce-challenge';
12
+ import ora from 'ora';
13
+ import { getLoggedInUser, logout, updateLogin, getConfigPath } from '@zapier/zapier-sdk-cli-login';
14
+ import { startMcpServerAsProcess } from '@zapier/zapier-sdk-mcp';
15
+ import * as fs from 'fs';
16
+ import * as path from 'path';
17
+ import { buildSync } from 'esbuild';
2
18
 
3
- // src/cli.ts
4
- import { Command as Command7 } from "commander";
5
- import { createZapierSdk as createZapierSdk2 } from "@zapier/zapier-sdk";
6
-
7
- // src/utils/cli-generator.ts
8
- import { z as z2 } from "zod";
9
- import {
10
- hasResolver as hasResolver2,
11
- isPositional,
12
- formatErrorMessage,
13
- ZapierError
14
- } from "@zapier/zapier-sdk";
15
-
16
- // src/utils/parameter-resolver.ts
17
- import inquirer from "inquirer";
18
- import chalk from "chalk";
19
- import { z } from "zod";
20
- import {
21
- getResolver,
22
- hasResolver,
23
- getResolutionOrderForParams
24
- } from "@zapier/zapier-sdk";
25
19
  var SchemaParameterResolver = class {
26
20
  async resolveParameters(schema, providedParams, sdk2) {
27
21
  const parseResult = schema.safeParse(providedParams);
@@ -85,7 +79,7 @@ var SchemaParameterResolver = class {
85
79
  context.resolvedParams = resolvedParams;
86
80
  } catch (error) {
87
81
  if (this.isUserCancellation(error)) {
88
- console.log(chalk.yellow("\n\nOperation cancelled by user"));
82
+ console.log(chalk3.yellow("\n\nOperation cancelled by user"));
89
83
  process.exit(0);
90
84
  }
91
85
  throw error;
@@ -116,7 +110,7 @@ var SchemaParameterResolver = class {
116
110
  context.resolvedParams = resolvedParams;
117
111
  } catch (error) {
118
112
  if (this.isUserCancellation(error)) {
119
- console.log(chalk.yellow("\n\nOperation cancelled by user"));
113
+ console.log(chalk3.yellow("\n\nOperation cancelled by user"));
120
114
  process.exit(0);
121
115
  }
122
116
  throw error;
@@ -144,7 +138,7 @@ var SchemaParameterResolver = class {
144
138
  context.resolvedParams = resolvedParams;
145
139
  } catch (error) {
146
140
  if (this.isUserCancellation(error)) {
147
- console.log(chalk.yellow("\n\nOperation cancelled by user"));
141
+ console.log(chalk3.yellow("\n\nOperation cancelled by user"));
148
142
  process.exit(0);
149
143
  }
150
144
  throw error;
@@ -155,7 +149,7 @@ var SchemaParameterResolver = class {
155
149
  const finalResult = schema.safeParse(resolvedParams);
156
150
  if (!finalResult.success) {
157
151
  console.error(
158
- chalk.red("\u274C Parameter validation failed after resolution:")
152
+ chalk3.red("\u274C Parameter validation failed after resolution:")
159
153
  );
160
154
  throw finalResult.error;
161
155
  }
@@ -203,7 +197,7 @@ var SchemaParameterResolver = class {
203
197
  if (!resolver) {
204
198
  throw new Error(`No resolver found for parameter: ${param.name}`);
205
199
  }
206
- console.log(chalk.blue(`
200
+ console.log(chalk3.blue(`
207
201
  \u{1F50D} Resolving ${param.name}...`));
208
202
  const typedResolver = resolver;
209
203
  if (typedResolver.type === "static") {
@@ -220,7 +214,7 @@ var SchemaParameterResolver = class {
220
214
  } else if (typedResolver.type === "dynamic") {
221
215
  try {
222
216
  if (param.isRequired && param.name !== "authenticationId") {
223
- console.log(chalk.gray(`Fetching options for ${param.name}...`));
217
+ console.log(chalk3.gray(`Fetching options for ${param.name}...`));
224
218
  }
225
219
  const items = await typedResolver.fetch(
226
220
  context.sdk,
@@ -261,7 +255,7 @@ var SchemaParameterResolver = class {
261
255
  }
262
256
  };
263
257
  console.log(
264
- chalk.gray(
258
+ chalk3.gray(
265
259
  `Fetching input fields for ${param.name}${iteration > 1 ? ` (iteration ${iteration})` : ""}...`
266
260
  )
267
261
  );
@@ -272,7 +266,7 @@ var SchemaParameterResolver = class {
272
266
  if (!fields || fields.length === 0) {
273
267
  if (iteration === 1) {
274
268
  console.log(
275
- chalk.yellow(`No input fields required for this action.`)
269
+ chalk3.yellow(`No input fields required for this action.`)
276
270
  );
277
271
  }
278
272
  break;
@@ -291,7 +285,7 @@ var SchemaParameterResolver = class {
291
285
  );
292
286
  if (newRequiredFields.length > 0) {
293
287
  console.log(
294
- chalk.blue(
288
+ chalk3.blue(
295
289
  `
296
290
  \u{1F4DD} Please provide values for the following ${iteration === 1 ? "" : "additional "}input fields:`
297
291
  )
@@ -304,7 +298,7 @@ var SchemaParameterResolver = class {
304
298
  let shouldConfigureOptional = { configure: false };
305
299
  if (newOptionalFields.length > 0) {
306
300
  console.log(
307
- chalk.gray(
301
+ chalk3.gray(
308
302
  `
309
303
  There are ${newOptionalFields.length} ${iteration === 1 ? "" : "additional "}optional field(s) available.`
310
304
  )
@@ -320,13 +314,13 @@ There are ${newOptionalFields.length} ${iteration === 1 ? "" : "additional "}opt
320
314
  ]);
321
315
  } catch (error) {
322
316
  if (this.isUserCancellation(error)) {
323
- console.log(chalk.yellow("\n\nOperation cancelled by user"));
317
+ console.log(chalk3.yellow("\n\nOperation cancelled by user"));
324
318
  process.exit(0);
325
319
  }
326
320
  throw error;
327
321
  }
328
322
  if (shouldConfigureOptional.configure) {
329
- console.log(chalk.cyan(`
323
+ console.log(chalk3.cyan(`
330
324
  Optional fields:`));
331
325
  for (const field of newOptionalFields) {
332
326
  await this.promptForField(field, inputs);
@@ -344,7 +338,7 @@ Optional fields:`));
344
338
  }
345
339
  if (iteration >= maxIterations) {
346
340
  console.log(
347
- chalk.yellow(
341
+ chalk3.yellow(
348
342
  `
349
343
  \u26A0\uFE0F Maximum field resolution iterations reached. Some dynamic fields may not have been discovered.`
350
344
  )
@@ -377,7 +371,7 @@ Optional fields:`));
377
371
  message: `${fieldObj.label || fieldObj.key}${fieldObj.required ? " (required)" : " (optional)"}:`
378
372
  };
379
373
  if (fieldObj.helpText) {
380
- fieldPrompt.prefix = chalk.gray(`\u2139 ${fieldObj.helpText}
374
+ fieldPrompt.prefix = chalk3.gray(`\u2139 ${fieldObj.helpText}
381
375
  `);
382
376
  }
383
377
  if (fieldObj.default !== void 0) {
@@ -404,7 +398,7 @@ Optional fields:`));
404
398
  }
405
399
  } catch (error) {
406
400
  if (this.isUserCancellation(error)) {
407
- console.log(chalk.yellow("\n\nOperation cancelled by user"));
401
+ console.log(chalk3.yellow("\n\nOperation cancelled by user"));
408
402
  process.exit(0);
409
403
  }
410
404
  throw error;
@@ -415,9 +409,6 @@ Optional fields:`));
415
409
  return errorObj?.name === "ExitPromptError" || errorObj?.message?.includes("User force closed") || errorObj?.isTTYError === true;
416
410
  }
417
411
  };
418
-
419
- // src/utils/schema-formatter.ts
420
- import chalk2 from "chalk";
421
412
  function getFormatMetadata(schema) {
422
413
  return schema?._def?.formatMeta;
423
414
  }
@@ -441,9 +432,9 @@ function formatItemsFromSchema(inputSchema, items) {
441
432
  }
442
433
  function formatSingleItem(item, index, formatMeta) {
443
434
  const formatted = formatMeta.format(item);
444
- let titleLine = `${chalk2.gray(`${index + 1}.`)} ${chalk2.cyan(formatted.title)}`;
435
+ let titleLine = `${chalk3.gray(`${index + 1}.`)} ${chalk3.cyan(formatted.title)}`;
445
436
  if (formatted.subtitle) {
446
- titleLine += ` ${chalk2.gray(formatted.subtitle)}`;
437
+ titleLine += ` ${chalk3.gray(formatted.subtitle)}`;
447
438
  }
448
439
  console.log(titleLine);
449
440
  for (const detail of formatted.details) {
@@ -455,35 +446,33 @@ function formatSingleItem(item, index, formatMeta) {
455
446
  function applyStyle(value, style) {
456
447
  switch (style) {
457
448
  case "dim":
458
- return chalk2.dim(value);
449
+ return chalk3.dim(value);
459
450
  case "accent":
460
- return chalk2.magenta(value);
451
+ return chalk3.magenta(value);
461
452
  case "warning":
462
- return chalk2.red(value);
453
+ return chalk3.red(value);
463
454
  case "success":
464
- return chalk2.green(value);
455
+ return chalk3.green(value);
465
456
  case "normal":
466
457
  default:
467
- return chalk2.blue(value);
458
+ return chalk3.blue(value);
468
459
  }
469
460
  }
470
461
  function formatItemsGeneric(items) {
471
462
  items.forEach((item, index) => {
472
463
  const itemObj = item;
473
464
  const name = itemObj.title || itemObj.name || itemObj.key || itemObj.id || "Item";
474
- console.log(`${chalk2.gray(`${index + 1}.`)} ${chalk2.cyan(name)}`);
465
+ console.log(`${chalk3.gray(`${index + 1}.`)} ${chalk3.cyan(name)}`);
475
466
  if (itemObj.description) {
476
- console.log(` ${chalk2.dim(itemObj.description)}`);
467
+ console.log(` ${chalk3.dim(itemObj.description)}`);
477
468
  }
478
469
  console.log();
479
470
  });
480
471
  }
481
-
482
- // src/utils/cli-generator.ts
483
- import chalk3 from "chalk";
484
- import util from "util";
485
- import inquirer2 from "inquirer";
486
472
  function formatJsonOutput(data) {
473
+ if (data === void 0) {
474
+ return;
475
+ }
487
476
  if (data && typeof data === "object" && !Array.isArray(data) && (data.success !== void 0 || data.id || data.status)) {
488
477
  console.log(chalk3.green("\u2705 Action completed successfully!\n"));
489
478
  }
@@ -493,7 +482,7 @@ function formatJsonOutput(data) {
493
482
  }
494
483
  function analyzeZodSchema(schema) {
495
484
  const parameters = [];
496
- if (schema instanceof z2.ZodObject) {
485
+ if (schema instanceof z.ZodObject) {
497
486
  const shape = schema.shape;
498
487
  for (const [key, fieldSchema] of Object.entries(shape)) {
499
488
  const param = analyzeZodField(key, fieldSchema);
@@ -508,29 +497,29 @@ function analyzeZodField(name, schema) {
508
497
  let baseSchema = schema;
509
498
  let required = true;
510
499
  let defaultValue = void 0;
511
- if (baseSchema instanceof z2.ZodOptional) {
500
+ if (baseSchema instanceof z.ZodOptional) {
512
501
  required = false;
513
502
  baseSchema = baseSchema._def.innerType;
514
503
  }
515
- if (baseSchema instanceof z2.ZodDefault) {
504
+ if (baseSchema instanceof z.ZodDefault) {
516
505
  required = false;
517
506
  defaultValue = baseSchema._def.defaultValue();
518
507
  baseSchema = baseSchema._def.innerType;
519
508
  }
520
509
  let paramType = "string";
521
510
  let choices;
522
- if (baseSchema instanceof z2.ZodString) {
511
+ if (baseSchema instanceof z.ZodString) {
523
512
  paramType = "string";
524
- } else if (baseSchema instanceof z2.ZodNumber) {
513
+ } else if (baseSchema instanceof z.ZodNumber) {
525
514
  paramType = "number";
526
- } else if (baseSchema instanceof z2.ZodBoolean) {
515
+ } else if (baseSchema instanceof z.ZodBoolean) {
527
516
  paramType = "boolean";
528
- } else if (baseSchema instanceof z2.ZodArray) {
517
+ } else if (baseSchema instanceof z.ZodArray) {
529
518
  paramType = "array";
530
- } else if (baseSchema instanceof z2.ZodEnum) {
519
+ } else if (baseSchema instanceof z.ZodEnum) {
531
520
  paramType = "string";
532
521
  choices = baseSchema._def.values;
533
- } else if (baseSchema instanceof z2.ZodRecord) {
522
+ } else if (baseSchema instanceof z.ZodRecord) {
534
523
  paramType = "string";
535
524
  }
536
525
  return {
@@ -540,7 +529,7 @@ function analyzeZodField(name, schema) {
540
529
  description: schema.description,
541
530
  default: defaultValue,
542
531
  choices,
543
- hasResolver: hasResolver2(name),
532
+ hasResolver: hasResolver(name),
544
533
  isPositional: isPositional(schema)
545
534
  };
546
535
  }
@@ -853,7 +842,7 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, s
853
842
  )
854
843
  );
855
844
  if (page.nextCursor) {
856
- const { continueReading } = await inquirer2.prompt([
845
+ const { continueReading } = await inquirer.prompt([
857
846
  {
858
847
  type: "confirm",
859
848
  name: "continueReading",
@@ -952,24 +941,12 @@ function getListTitleFromMethod(methodName) {
952
941
  return `Available ${capitalized}`;
953
942
  }
954
943
 
955
- // src/commands/login.ts
956
- import { Command } from "commander";
957
-
958
- // src/utils/auth/login.ts
959
- import open from "open";
960
- import crypto from "crypto";
961
- import express from "express";
962
- import pkceChallenge from "pkce-challenge";
963
-
964
944
  // src/utils/constants.ts
965
945
  var ZAPIER_BASE = "https://zapier.com";
966
946
  var LOGIN_CLIENT_ID = "K5eEnRE9TTmSFATdkkWhKF8NOKwoiOnYAyIqJjae";
967
947
  var LOGIN_PORTS = [49505, 50575, 52804, 55981, 61010, 63851];
968
948
  var LOGIN_TIMEOUT_MS = 3e5;
969
949
  var AUTH_MODE_HEADER = "X-Auth";
970
-
971
- // src/utils/spinner.ts
972
- import ora from "ora";
973
950
  var spinPromise = async (promise, text) => {
974
951
  const spinner = ora(text).start();
975
952
  try {
@@ -981,21 +958,18 @@ var spinPromise = async (promise, text) => {
981
958
  throw error;
982
959
  }
983
960
  };
984
-
985
- // src/utils/log.ts
986
- import chalk4 from "chalk";
987
961
  var log = {
988
962
  info: (message, ...args) => {
989
- console.log(chalk4.blue("\u2139"), message, ...args);
963
+ console.log(chalk3.blue("\u2139"), message, ...args);
990
964
  },
991
965
  error: (message, ...args) => {
992
- console.error(chalk4.red("\u2716"), message, ...args);
966
+ console.error(chalk3.red("\u2716"), message, ...args);
993
967
  },
994
968
  success: (message, ...args) => {
995
- console.log(chalk4.green("\u2713"), message, ...args);
969
+ console.log(chalk3.green("\u2713"), message, ...args);
996
970
  },
997
971
  warn: (message, ...args) => {
998
- console.log(chalk4.yellow("\u26A0"), message, ...args);
972
+ console.log(chalk3.yellow("\u26A0"), message, ...args);
999
973
  }
1000
974
  };
1001
975
  var log_default = log;
@@ -1046,9 +1020,6 @@ var getCallablePromise = () => {
1046
1020
  };
1047
1021
  };
1048
1022
  var getCallablePromise_default = getCallablePromise;
1049
-
1050
- // src/utils/auth/login.ts
1051
- import { updateLogin, logout } from "@zapier/zapier-sdk-cli-login";
1052
1023
  var findAvailablePort = () => {
1053
1024
  return new Promise((resolve2, reject) => {
1054
1025
  let portIndex = 0;
@@ -1179,88 +1150,102 @@ var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
1179
1150
  return data.access_token;
1180
1151
  };
1181
1152
  var login_default = login;
1153
+ var LoginSchema = z.object({
1154
+ timeout: z.string().optional().describe("Login timeout in seconds (default: 300)")
1155
+ }).describe("Log in to Zapier to access your account");
1182
1156
 
1183
- // src/commands/login.ts
1184
- import { getLoggedInUser } from "@zapier/zapier-sdk-cli-login";
1185
- function createLoginCommand() {
1186
- return new Command("login").description("Log in to Zapier to access your account").option(
1187
- "--timeout <seconds>",
1188
- "Login timeout in seconds (default: 300)",
1189
- "300"
1190
- ).action(async (options) => {
1191
- try {
1192
- const timeoutSeconds = parseInt(options.timeout, 10);
1193
- if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
1194
- throw new Error("Timeout must be a positive number");
1157
+ // src/plugins/login/index.ts
1158
+ var loginWithSdk = createFunction(async function loginWithSdk2(options) {
1159
+ const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
1160
+ if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
1161
+ throw new Error("Timeout must be a positive number");
1162
+ }
1163
+ await login_default(timeoutSeconds * 1e3);
1164
+ const user = await getLoggedInUser();
1165
+ console.log(`\u2705 Successfully logged in as ${user.email}`);
1166
+ setTimeout(() => process.exit(0), 100);
1167
+ }, LoginSchema);
1168
+ var loginPlugin = () => ({
1169
+ login: loginWithSdk,
1170
+ context: {
1171
+ meta: {
1172
+ login: {
1173
+ categories: ["account"],
1174
+ inputSchema: LoginSchema
1195
1175
  }
1196
- await login_default(timeoutSeconds * 1e3);
1197
- const user = await getLoggedInUser();
1198
- console.log(`\u2705 Successfully logged in as ${user.email}`);
1199
- setTimeout(() => process.exit(0), 100);
1200
- } catch (error) {
1201
- console.error(
1202
- "\u274C Login failed:",
1203
- error instanceof Error ? error.message : "Unknown error"
1204
- );
1205
- process.exit(1);
1206
1176
  }
1207
- });
1208
- }
1177
+ }
1178
+ });
1179
+ var LogoutSchema = z.object({}).describe("Log out of your Zapier account");
1209
1180
 
1210
- // src/commands/logout.ts
1211
- import { Command as Command2 } from "commander";
1212
- import { logout as logout2 } from "@zapier/zapier-sdk-cli-login";
1213
- function createLogoutCommand() {
1214
- return new Command2("logout").description("Log out of your Zapier account").action(async () => {
1215
- try {
1216
- logout2();
1217
- console.log("\u2705 Successfully logged out");
1218
- } catch (error) {
1219
- console.error(
1220
- "\u274C Logout failed:",
1221
- error instanceof Error ? error.message : "Unknown error"
1222
- );
1223
- process.exit(1);
1181
+ // src/plugins/logout/index.ts
1182
+ var logoutWithSdk = createFunction(async function logoutWithSdk2(_options) {
1183
+ logout();
1184
+ console.log("\u2705 Successfully logged out");
1185
+ }, LogoutSchema);
1186
+ var logoutPlugin = () => ({
1187
+ logout: logoutWithSdk,
1188
+ context: {
1189
+ meta: {
1190
+ logout: {
1191
+ categories: ["account"],
1192
+ inputSchema: LogoutSchema
1193
+ }
1224
1194
  }
1225
- });
1226
- }
1227
-
1228
- // src/commands/configPath.ts
1229
- import { Command as Command3 } from "commander";
1230
- import { getConfigPath } from "@zapier/zapier-sdk-cli-login";
1231
- function createConfigPathCommand() {
1232
- return new Command3("get-config-path").description("Show the path to the configuration file").action(async () => {
1233
- console.log(`Configuration file: ${getConfigPath()}`);
1234
- });
1235
- }
1236
-
1237
- // src/commands/generate-types/cli.ts
1238
- import { Command as Command4 } from "commander";
1239
- import { createZapierSdk } from "@zapier/zapier-sdk";
1195
+ }
1196
+ });
1197
+ var McpSchema = z.object({
1198
+ port: z.string().optional().describe("Port to listen on (for future HTTP transport)")
1199
+ }).describe("Start MCP server for Zapier SDK");
1240
1200
 
1241
- // src/commands/generate-types/schemas.ts
1242
- import { z as z3 } from "zod";
1243
- import {
1244
- AppKeyPropertySchema,
1245
- AuthenticationIdPropertySchema,
1246
- OutputPropertySchema,
1247
- DebugPropertySchema
1248
- } from "@zapier/zapier-sdk";
1249
- var GenerateTypesSchema = z3.object({
1201
+ // src/plugins/mcp/index.ts
1202
+ var mcpPlugin = ({ context }) => {
1203
+ const mcpWithSdk = createFunction(async function mcpWithSdk2(options) {
1204
+ const mcpOptions = {
1205
+ ...options,
1206
+ debug: context.options.debug
1207
+ };
1208
+ return await startMcpServerAsProcess(mcpOptions);
1209
+ }, McpSchema);
1210
+ return {
1211
+ mcp: mcpWithSdk,
1212
+ context: {
1213
+ meta: {
1214
+ mcp: {
1215
+ categories: ["utility"],
1216
+ inputSchema: McpSchema
1217
+ }
1218
+ }
1219
+ }
1220
+ };
1221
+ };
1222
+ var GenerateTypesSchema = z.object({
1250
1223
  appKey: AppKeyPropertySchema.describe("App key to generate SDK code for"),
1251
1224
  authenticationId: AuthenticationIdPropertySchema.optional(),
1252
1225
  output: OutputPropertySchema.optional().describe(
1253
1226
  "Output file path (defaults to generated/<appKey>.ts)"
1254
1227
  ),
1255
- debug: DebugPropertySchema.describe(
1256
- "Enable debug logging during generation"
1257
- ),
1258
- lockFilePath: z3.string().optional().describe("Path to the .zapierrc lock file (defaults to .zapierrc)")
1228
+ lockFilePath: z.string().optional().describe("Path to the .zapierrc lock file (defaults to .zapierrc)")
1259
1229
  }).describe("Generate TypeScript SDK code for a specific app");
1260
-
1261
- // src/commands/generate-types/index.ts
1262
- import * as fs from "fs";
1263
- import * as path from "path";
1230
+ var generateTypesPlugin = ({ sdk: sdk2 }) => {
1231
+ const generateTypesWithSdk = createFunction(
1232
+ async function generateTypesWithSdk2(options) {
1233
+ return await generateTypes({ ...options, sdk: sdk2 });
1234
+ },
1235
+ GenerateTypesSchema
1236
+ );
1237
+ return {
1238
+ generateTypes: generateTypesWithSdk,
1239
+ context: {
1240
+ meta: {
1241
+ generateTypes: {
1242
+ categories: ["utility"],
1243
+ inputSchema: GenerateTypesSchema
1244
+ }
1245
+ }
1246
+ }
1247
+ };
1248
+ };
1264
1249
  function generateFetchMethodSignature() {
1265
1250
  return ` /** Make authenticated HTTP requests through Zapier's Relay service */
1266
1251
  fetch: (options: Omit<z.infer<typeof RelayFetchSchema>, 'authenticationId'>) => Promise<Response>`;
@@ -1551,216 +1536,32 @@ function mapFieldTypeToTypeScript(field) {
1551
1536
  return "string | number | boolean";
1552
1537
  }
1553
1538
  }
1554
-
1555
- // src/commands/generate-types/cli.ts
1556
- import chalk5 from "chalk";
1557
-
1558
- // src/utils/cli-generator-utils.ts
1559
- import { z as z4 } from "zod";
1560
- import { hasResolver as hasResolver3, isPositional as isPositional2 } from "@zapier/zapier-sdk";
1561
- function analyzeZodSchema2(schema) {
1562
- const parameters = [];
1563
- if (schema instanceof z4.ZodObject) {
1564
- const shape = schema.shape;
1565
- for (const [key, fieldSchema] of Object.entries(shape)) {
1566
- const param = analyzeZodField2(key, fieldSchema);
1567
- if (param) {
1568
- parameters.push(param);
1569
- }
1570
- }
1571
- }
1572
- return parameters;
1573
- }
1574
- function analyzeZodField2(name, schema) {
1575
- let baseSchema = schema;
1576
- let required = true;
1577
- let defaultValue = void 0;
1578
- if (baseSchema instanceof z4.ZodOptional) {
1579
- required = false;
1580
- baseSchema = baseSchema._def.innerType;
1581
- }
1582
- if (baseSchema instanceof z4.ZodDefault) {
1583
- required = false;
1584
- defaultValue = baseSchema._def.defaultValue();
1585
- baseSchema = baseSchema._def.innerType;
1586
- }
1587
- let paramType = "string";
1588
- let choices;
1589
- if (baseSchema instanceof z4.ZodString) {
1590
- paramType = "string";
1591
- } else if (baseSchema instanceof z4.ZodNumber) {
1592
- paramType = "number";
1593
- } else if (baseSchema instanceof z4.ZodBoolean) {
1594
- paramType = "boolean";
1595
- } else if (baseSchema instanceof z4.ZodArray) {
1596
- paramType = "array";
1597
- } else if (baseSchema instanceof z4.ZodEnum) {
1598
- paramType = "string";
1599
- choices = baseSchema._def.values;
1600
- } else if (baseSchema instanceof z4.ZodRecord) {
1601
- paramType = "string";
1602
- }
1539
+ var BundleCodeSchema = z.object({
1540
+ input: z.string().min(1).describe("Input TypeScript file path to bundle"),
1541
+ output: OutputPropertySchema.optional().describe(
1542
+ "Output file path (defaults to input with .js extension)"
1543
+ ),
1544
+ string: z.boolean().optional().describe("Return bundled code as string instead of writing to file"),
1545
+ minify: z.boolean().optional().describe("Minify the bundled output"),
1546
+ target: z.string().optional().describe("ECMAScript target version"),
1547
+ cjs: z.boolean().optional().describe("Output CommonJS format instead of ESM")
1548
+ }).describe("Bundle TypeScript code into executable JavaScript");
1549
+ var bundleCodePlugin = () => {
1550
+ const bundleCodeWithSdk = createFunction(async function bundleCodeWithSdk2(options) {
1551
+ return await bundleCode(options);
1552
+ }, BundleCodeSchema);
1603
1553
  return {
1604
- name,
1605
- type: paramType,
1606
- required,
1607
- description: schema.description,
1608
- default: defaultValue,
1609
- choices,
1610
- hasResolver: hasResolver3(name),
1611
- isPositional: isPositional2(schema)
1612
- };
1613
- }
1614
- function convertCliArgsToSdkParams2(parameters, positionalArgs, options) {
1615
- const sdkParams = {};
1616
- let argIndex = 0;
1617
- parameters.forEach((param) => {
1618
- if ((param.required || param.isPositional) && argIndex < positionalArgs.length) {
1619
- sdkParams[param.name] = convertValue2(
1620
- positionalArgs[argIndex],
1621
- param.type
1622
- );
1623
- argIndex++;
1624
- }
1625
- });
1626
- Object.entries(options).forEach(([key, value]) => {
1627
- const camelKey = key.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
1628
- const param = parameters.find((p) => p.name === camelKey);
1629
- if (param && value !== void 0) {
1630
- sdkParams[camelKey] = convertValue2(value, param.type);
1631
- }
1632
- });
1633
- return sdkParams;
1634
- }
1635
- function convertValue2(value, type) {
1636
- switch (type) {
1637
- case "number":
1638
- return Number(value);
1639
- case "boolean":
1640
- return Boolean(value);
1641
- case "array":
1642
- return Array.isArray(value) ? value : [value];
1643
- case "string":
1644
- default:
1645
- if (typeof value === "string" && (value.startsWith("{") || value.startsWith("["))) {
1646
- try {
1647
- return JSON.parse(value);
1648
- } catch {
1649
- return value;
1554
+ bundleCode: bundleCodeWithSdk,
1555
+ context: {
1556
+ meta: {
1557
+ bundleCode: {
1558
+ categories: ["utility"],
1559
+ inputSchema: BundleCodeSchema
1650
1560
  }
1651
1561
  }
1652
- return value;
1653
- }
1654
- }
1655
-
1656
- // src/commands/generate-types/cli.ts
1657
- function createGenerateTypesCommand() {
1658
- const parameters = analyzeZodSchema2(GenerateTypesSchema);
1659
- const description = GenerateTypesSchema.description || "Generate TypeScript SDK types for a specific app";
1660
- const command = new Command4("generate-types").description(description);
1661
- parameters.forEach((param) => {
1662
- const kebabName = param.name.replace(/([A-Z])/g, "-$1").toLowerCase();
1663
- if (param.hasResolver && param.required) {
1664
- command.argument(
1665
- `[${kebabName}]`,
1666
- param.description || `${kebabName} parameter`
1667
- );
1668
- } else if (param.required) {
1669
- command.argument(
1670
- `<${kebabName}>`,
1671
- param.description || `${kebabName} parameter`
1672
- );
1673
- } else if (param.isPositional) {
1674
- command.argument(
1675
- `[${kebabName}]`,
1676
- param.description || `${kebabName} parameter`
1677
- );
1678
- } else {
1679
- const flags = [`--${kebabName}`];
1680
- if (param.type === "boolean") {
1681
- command.option(flags.join(", "), param.description);
1682
- } else {
1683
- const flagSignature = flags.join(", ") + ` <${param.type}>`;
1684
- command.option(
1685
- flagSignature,
1686
- param.description || "",
1687
- param.default
1688
- );
1689
- }
1690
- }
1691
- });
1692
- command.option("--json", "Output raw JSON instead of formatted results");
1693
- command.action(async (...args) => {
1694
- try {
1695
- const commandObj = args[args.length - 1];
1696
- const options = commandObj.opts();
1697
- const rawParams = convertCliArgsToSdkParams2(
1698
- parameters,
1699
- args.slice(0, -1),
1700
- options
1701
- );
1702
- const sdk2 = createZapierSdk({
1703
- manifestPath: rawParams.lockFilePath
1704
- });
1705
- const resolver = new SchemaParameterResolver();
1706
- const resolvedParams = await resolver.resolveParameters(
1707
- GenerateTypesSchema,
1708
- rawParams,
1709
- sdk2
1710
- );
1711
- const params = resolvedParams;
1712
- console.log(
1713
- chalk5.blue(
1714
- `\u{1F527} Generating TypeScript types for ${params.appKey}...`
1715
- )
1716
- );
1717
- const generateTypesParams = {
1718
- appKey: params.appKey,
1719
- debug: params.debug ?? false,
1720
- authenticationId: params.authenticationId,
1721
- output: params.output,
1722
- sdk: sdk2
1723
- };
1724
- const result = await generateTypes(generateTypesParams);
1725
- if (options.json) {
1726
- console.log(JSON.stringify({ result }, null, 2));
1727
- } else {
1728
- const output = params.output || `./types/${params.appKey}.d.ts`;
1729
- console.log(chalk5.green("\u2705 TypeScript types generated successfully!"));
1730
- console.log(chalk5.gray(`Output written to: ${output}`));
1731
- }
1732
- } catch (error) {
1733
- console.error(
1734
- chalk5.red("Error:"),
1735
- error instanceof Error ? error.message : "Unknown error"
1736
- );
1737
- process.exit(1);
1738
1562
  }
1739
- });
1740
- return command;
1741
- }
1742
-
1743
- // src/commands/bundle-code/cli.ts
1744
- import { Command as Command5 } from "commander";
1745
-
1746
- // src/commands/bundle-code/schemas.ts
1747
- import { z as z5 } from "zod";
1748
- import { OutputPropertySchema as OutputPropertySchema2 } from "@zapier/zapier-sdk";
1749
- var BundleCodeSchema = z5.object({
1750
- input: z5.string().min(1).describe("Input TypeScript file path to bundle"),
1751
- output: OutputPropertySchema2.optional().describe(
1752
- "Output file path (defaults to input with .js extension)"
1753
- ),
1754
- string: z5.boolean().default(false).describe("Return bundled code as string instead of writing to file"),
1755
- minify: z5.boolean().default(false).describe("Minify the bundled output"),
1756
- target: z5.string().default("es2017").describe("ECMAScript target version"),
1757
- cjs: z5.boolean().default(false).describe("Output CommonJS format instead of ESM")
1758
- }).describe("Bundle TypeScript code into executable JavaScript");
1759
-
1760
- // src/commands/bundle-code/index.ts
1761
- import { buildSync } from "esbuild";
1762
- import * as fs2 from "fs";
1763
- import * as path2 from "path";
1563
+ };
1564
+ };
1764
1565
  var ZapierBundleError = class extends Error {
1765
1566
  constructor(message, details, originalError) {
1766
1567
  super(message);
@@ -1779,7 +1580,7 @@ async function bundleCode(options) {
1779
1580
  minify = false,
1780
1581
  string: returnString = false
1781
1582
  } = options;
1782
- const resolvedInput = path2.resolve(process.cwd(), input);
1583
+ const resolvedInput = path.resolve(process.cwd(), input);
1783
1584
  try {
1784
1585
  const result = buildSync({
1785
1586
  entryPoints: [resolvedInput],
@@ -1811,8 +1612,8 @@ async function bundleCode(options) {
1811
1612
  finalOutput = JSON.stringify(bundledCode);
1812
1613
  }
1813
1614
  if (output) {
1814
- fs2.mkdirSync(path2.dirname(output), { recursive: true });
1815
- fs2.writeFileSync(output, finalOutput, "utf8");
1615
+ fs.mkdirSync(path.dirname(output), { recursive: true });
1616
+ fs.writeFileSync(output, finalOutput, "utf8");
1816
1617
  }
1817
1618
  return finalOutput;
1818
1619
  } catch (error) {
@@ -1826,105 +1627,52 @@ async function bundleCode(options) {
1826
1627
  );
1827
1628
  }
1828
1629
  }
1829
-
1830
- // src/commands/bundle-code/cli.ts
1831
- import chalk6 from "chalk";
1832
- function createBundleCodeCommand() {
1833
- const parameters = analyzeZodSchema2(BundleCodeSchema);
1834
- const description = BundleCodeSchema.description || "Bundle TypeScript code into executable JavaScript";
1835
- const command = new Command5("bundle-code").description(description);
1836
- parameters.forEach((param) => {
1837
- const kebabName = param.name.replace(/([A-Z])/g, "-$1").toLowerCase();
1838
- if (param.hasResolver && param.required) {
1839
- command.argument(
1840
- `[${kebabName}]`,
1841
- param.description || `${kebabName} parameter`
1842
- );
1843
- } else if (param.required) {
1844
- command.argument(
1845
- `<${kebabName}>`,
1846
- param.description || `${kebabName} parameter`
1847
- );
1848
- } else if (param.isPositional) {
1849
- command.argument(
1850
- `[${kebabName}]`,
1851
- param.description || `${kebabName} parameter`
1852
- );
1853
- } else {
1854
- const flags = [`--${kebabName}`];
1855
- if (param.type === "boolean") {
1856
- command.option(flags.join(", "), param.description);
1857
- } else {
1858
- const flagSignature = flags.join(", ") + ` <${param.type}>`;
1859
- command.option(
1860
- flagSignature,
1861
- param.description || "",
1862
- param.default
1863
- );
1864
- }
1865
- }
1866
- });
1867
- command.option("--json", "Output raw JSON instead of formatted results");
1868
- command.action(async (...args) => {
1869
- try {
1870
- const commandObj = args[args.length - 1];
1871
- const options = commandObj.opts();
1872
- const rawParams = convertCliArgsToSdkParams2(
1873
- parameters,
1874
- args.slice(0, -1),
1875
- options
1876
- );
1877
- if (!rawParams.input) {
1878
- throw new Error("Input file path is required");
1879
- }
1880
- console.log(chalk6.blue(`\u{1F4E6} Bundling ${rawParams.input}...`));
1881
- const result = await bundleCode(
1882
- rawParams
1883
- );
1884
- if (options.json) {
1885
- console.log(JSON.stringify({ result }, null, 2));
1886
- } else if (rawParams.output && !rawParams.string) {
1887
- console.log(chalk6.green("\u2705 Bundle created successfully!"));
1888
- console.log(chalk6.gray(`Output written to: ${rawParams.output}`));
1889
- } else if (rawParams.string) {
1890
- console.log(chalk6.green("\u2705 Bundle generated as string!"));
1891
- console.log("\n" + result);
1892
- } else {
1893
- console.log(chalk6.green("\u2705 Bundle completed!"));
1894
- console.log("\n" + result);
1630
+ var GetConfigPathSchema = z.object({}).describe("Show the path to the configuration file");
1631
+ var getConfigPathPlugin = () => {
1632
+ const getConfigPathWithSdk = createFunction(
1633
+ async function getConfigPathWithSdk2(_options) {
1634
+ return getConfigPath();
1635
+ },
1636
+ GetConfigPathSchema
1637
+ );
1638
+ return {
1639
+ getConfigPath: getConfigPathWithSdk,
1640
+ context: {
1641
+ meta: {
1642
+ getConfigPath: {
1643
+ categories: ["utility"],
1644
+ inputSchema: GetConfigPathSchema
1645
+ }
1895
1646
  }
1896
- } catch (error) {
1897
- console.error(
1898
- chalk6.red("Error:"),
1899
- error instanceof Error ? error.message : "Unknown error"
1900
- );
1901
- process.exit(1);
1902
1647
  }
1648
+ };
1649
+ };
1650
+
1651
+ // src/sdk.ts
1652
+ function createZapierCliSdk(options = {}) {
1653
+ let sdk2 = createZapierSdkWithoutRegistry({
1654
+ debug: options.debug
1903
1655
  });
1904
- return command;
1656
+ sdk2 = sdk2.addPlugin(generateTypesPlugin);
1657
+ sdk2 = sdk2.addPlugin(bundleCodePlugin);
1658
+ sdk2 = sdk2.addPlugin(getConfigPathPlugin);
1659
+ sdk2 = sdk2.addPlugin(mcpPlugin);
1660
+ sdk2 = sdk2.addPlugin(loginPlugin);
1661
+ sdk2 = sdk2.addPlugin(logoutPlugin);
1662
+ const finalSdk = sdk2.addPlugin(registryPlugin);
1663
+ return finalSdk;
1905
1664
  }
1906
1665
 
1907
- // src/commands/mcp.ts
1908
- import { Command as Command6 } from "commander";
1909
- import { startMcpServerAsProcess } from "@zapier/zapier-sdk-mcp";
1910
- function createMcpCommand() {
1911
- const command = new Command6("mcp");
1912
- command.description("Start MCP server for Zapier SDK").option("--debug", "Enable debug logging").option("--port <port>", "Port to listen on (for future HTTP transport)").action(startMcpServerAsProcess);
1913
- return command;
1914
- }
1666
+ // package.json
1667
+ var package_default = {
1668
+ version: "0.6.4"};
1915
1669
 
1916
1670
  // src/cli.ts
1917
- var program = new Command7();
1918
- program.name("zapier-sdk").description("CLI for Zapier SDK").version("1.0.0").option("--debug", "Enable debug logging");
1671
+ var program = new Command();
1672
+ program.name("zapier-sdk").description("CLI for Zapier SDK").version(package_default.version, "-v, --version", "display version number").option("--debug", "Enable debug logging");
1919
1673
  var isDebugMode = process.env.DEBUG === "true" || process.argv.includes("--debug");
1920
- var sdk = createZapierSdk2({
1674
+ var sdk = createZapierCliSdk({
1921
1675
  debug: isDebugMode
1922
1676
  });
1923
- program.addCommand(createLoginCommand());
1924
- program.addCommand(createLogoutCommand());
1925
1677
  generateCliCommands(program, sdk);
1926
- program.addCommand(createGenerateTypesCommand());
1927
- program.addCommand(createBundleCodeCommand());
1928
- program.addCommand(createConfigPathCommand());
1929
- program.addCommand(createMcpCommand());
1930
1678
  program.parse();