@zapier/zapier-sdk-cli 0.6.3 → 0.6.5
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.
- package/CHANGELOG.md +15 -0
- package/README.md +115 -12
- package/bin/{zapier-sdk.js → zapier-sdk.mjs} +1 -1
- package/dist/cli.cjs +1715 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/{cli.js → cli.mjs} +221 -469
- package/dist/index.cjs +770 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.mjs +739 -0
- package/dist/package.json +67 -0
- package/dist/src/cli.js +8 -14
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -1
- package/dist/src/plugins/bundleCode/index.d.ts +15 -0
- package/dist/src/{commands/bundle-code → plugins/bundleCode}/index.js +19 -1
- package/dist/src/{commands/bundle-code → plugins/bundleCode}/schemas.d.ts +8 -8
- package/dist/src/{commands/bundle-code → plugins/bundleCode}/schemas.js +4 -4
- package/dist/src/plugins/generateTypes/index.d.ts +21 -0
- package/dist/src/{commands/generate-types → plugins/generateTypes}/index.js +18 -0
- package/dist/src/{commands/generate-types → plugins/generateTypes}/schemas.d.ts +0 -3
- package/dist/src/{commands/generate-types → plugins/generateTypes}/schemas.js +1 -2
- package/dist/src/plugins/getConfigPath/index.d.ts +15 -0
- package/dist/src/plugins/getConfigPath/index.js +19 -0
- package/dist/src/plugins/getConfigPath/schemas.d.ts +3 -0
- package/dist/src/plugins/getConfigPath/schemas.js +5 -0
- package/dist/src/plugins/index.d.ts +6 -0
- package/dist/src/plugins/index.js +6 -0
- package/dist/src/plugins/login/index.d.ts +15 -0
- package/dist/src/plugins/login/index.js +26 -0
- package/dist/src/plugins/login/schemas.d.ts +9 -0
- package/dist/src/plugins/login/schemas.js +10 -0
- package/dist/src/plugins/logout/index.d.ts +15 -0
- package/dist/src/plugins/logout/index.js +18 -0
- package/dist/src/plugins/logout/schemas.d.ts +3 -0
- package/dist/src/plugins/logout/schemas.js +5 -0
- package/dist/src/plugins/mcp/index.d.ts +15 -0
- package/dist/src/plugins/mcp/index.js +24 -0
- package/dist/src/plugins/mcp/schemas.d.ts +9 -0
- package/dist/src/plugins/mcp/schemas.js +10 -0
- package/dist/src/sdk.d.ts +9 -0
- package/dist/src/sdk.js +22 -0
- package/dist/src/utils/cli-generator.js +12 -8
- package/dist/src/utils/schema-formatter.d.ts +1 -1
- package/dist/src/utils/schema-formatter.js +8 -8
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -8
- package/src/cli.ts +8 -21
- package/src/index.ts +2 -0
- package/src/{commands/bundle-code → plugins/bundleCode}/index.ts +39 -2
- package/src/{commands/bundle-code → plugins/bundleCode}/schemas.ts +4 -4
- package/src/{commands/generate-types → plugins/generateTypes}/index.ts +56 -3
- package/src/{commands/generate-types → plugins/generateTypes}/schemas.ts +0 -4
- package/src/plugins/getConfigPath/index.ts +42 -0
- package/src/plugins/getConfigPath/schemas.ts +8 -0
- package/src/plugins/index.ts +6 -0
- package/src/plugins/login/index.ts +48 -0
- package/src/plugins/login/schemas.ts +13 -0
- package/src/plugins/logout/index.ts +37 -0
- package/src/plugins/logout/schemas.ts +8 -0
- package/src/plugins/mcp/index.ts +43 -0
- package/src/plugins/mcp/schemas.ts +13 -0
- package/src/sdk.ts +43 -0
- package/src/utils/cli-generator.test.ts +93 -0
- package/src/utils/cli-generator.ts +19 -9
- package/src/utils/schema-formatter.ts +13 -7
- package/tsconfig.build.json +15 -3
- package/tsconfig.json +2 -2
- package/tsup.config.ts +10 -4
- package/bin/zsdk.js +0 -4
- package/dist/index.js +0 -0
- package/dist/src/commands/bundle-code/cli.d.ts +0 -2
- package/dist/src/commands/bundle-code/cli.js +0 -77
- package/dist/src/commands/bundle-code/index.d.ts +0 -5
- package/dist/src/commands/configPath.d.ts +0 -2
- package/dist/src/commands/configPath.js +0 -9
- package/dist/src/commands/generate-types/cli.d.ts +0 -2
- package/dist/src/commands/generate-types/cli.js +0 -84
- package/dist/src/commands/generate-types/index.d.ts +0 -8
- package/dist/src/commands/index.d.ts +0 -6
- package/dist/src/commands/index.js +0 -6
- package/dist/src/commands/login.d.ts +0 -2
- package/dist/src/commands/login.js +0 -25
- package/dist/src/commands/logout.d.ts +0 -2
- package/dist/src/commands/logout.js +0 -16
- package/dist/src/commands/mcp.d.ts +0 -2
- package/dist/src/commands/mcp.js +0 -11
- package/src/commands/bundle-code/cli.ts +0 -118
- package/src/commands/configPath.ts +0 -10
- package/src/commands/generate-types/cli.ts +0 -126
- package/src/commands/index.ts +0 -6
- package/src/commands/login.ts +0 -34
- package/src/commands/logout.ts +0 -19
- package/src/commands/mcp.ts +0 -14
package/dist/{cli.js → cli.mjs}
RENAMED
|
@@ -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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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 =
|
|
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(
|
|
401
|
+
console.log(chalk3.yellow("\n\nOperation cancelled by user"));
|
|
408
402
|
process.exit(0);
|
|
409
403
|
}
|
|
410
404
|
throw error;
|
|
@@ -415,35 +409,32 @@ 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
|
}
|
|
424
415
|
function getOutputSchema(schema) {
|
|
425
416
|
return schema?._def?.outputSchema;
|
|
426
417
|
}
|
|
427
|
-
function formatItemsFromSchema(inputSchema, items) {
|
|
418
|
+
function formatItemsFromSchema(inputSchema, items, startingNumber = 0) {
|
|
428
419
|
const outputSchema = getOutputSchema(inputSchema);
|
|
429
420
|
if (!outputSchema) {
|
|
430
|
-
formatItemsGeneric(items);
|
|
421
|
+
formatItemsGeneric(items, startingNumber);
|
|
431
422
|
return;
|
|
432
423
|
}
|
|
433
424
|
const formatMeta = getFormatMetadata(outputSchema);
|
|
434
425
|
if (!formatMeta) {
|
|
435
|
-
formatItemsGeneric(items);
|
|
426
|
+
formatItemsGeneric(items, startingNumber);
|
|
436
427
|
return;
|
|
437
428
|
}
|
|
438
429
|
items.forEach((item, index) => {
|
|
439
|
-
formatSingleItem(item, index, formatMeta);
|
|
430
|
+
formatSingleItem(item, startingNumber + index, formatMeta);
|
|
440
431
|
});
|
|
441
432
|
}
|
|
442
|
-
function formatSingleItem(item,
|
|
433
|
+
function formatSingleItem(item, itemNumber, formatMeta) {
|
|
443
434
|
const formatted = formatMeta.format(item);
|
|
444
|
-
let titleLine = `${
|
|
435
|
+
let titleLine = `${chalk3.gray(`${itemNumber + 1}.`)} ${chalk3.cyan(formatted.title)}`;
|
|
445
436
|
if (formatted.subtitle) {
|
|
446
|
-
titleLine += ` ${
|
|
437
|
+
titleLine += ` ${chalk3.gray(formatted.subtitle)}`;
|
|
447
438
|
}
|
|
448
439
|
console.log(titleLine);
|
|
449
440
|
for (const detail of formatted.details) {
|
|
@@ -455,35 +446,35 @@ function formatSingleItem(item, index, formatMeta) {
|
|
|
455
446
|
function applyStyle(value, style) {
|
|
456
447
|
switch (style) {
|
|
457
448
|
case "dim":
|
|
458
|
-
return
|
|
449
|
+
return chalk3.dim(value);
|
|
459
450
|
case "accent":
|
|
460
|
-
return
|
|
451
|
+
return chalk3.magenta(value);
|
|
461
452
|
case "warning":
|
|
462
|
-
return
|
|
453
|
+
return chalk3.red(value);
|
|
463
454
|
case "success":
|
|
464
|
-
return
|
|
455
|
+
return chalk3.green(value);
|
|
465
456
|
case "normal":
|
|
466
457
|
default:
|
|
467
|
-
return
|
|
458
|
+
return chalk3.blue(value);
|
|
468
459
|
}
|
|
469
460
|
}
|
|
470
|
-
function formatItemsGeneric(items) {
|
|
461
|
+
function formatItemsGeneric(items, startingNumber = 0) {
|
|
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(
|
|
465
|
+
console.log(
|
|
466
|
+
`${chalk3.gray(`${startingNumber + index + 1}.`)} ${chalk3.cyan(name)}`
|
|
467
|
+
);
|
|
475
468
|
if (itemObj.description) {
|
|
476
|
-
console.log(` ${
|
|
469
|
+
console.log(` ${chalk3.dim(itemObj.description)}`);
|
|
477
470
|
}
|
|
478
471
|
console.log();
|
|
479
472
|
});
|
|
480
473
|
}
|
|
481
|
-
|
|
482
|
-
// src/utils/cli-generator.ts
|
|
483
|
-
import chalk3 from "chalk";
|
|
484
|
-
import util from "util";
|
|
485
|
-
import inquirer2 from "inquirer";
|
|
486
474
|
function formatJsonOutput(data) {
|
|
475
|
+
if (data === void 0) {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
487
478
|
if (data && typeof data === "object" && !Array.isArray(data) && (data.success !== void 0 || data.id || data.status)) {
|
|
488
479
|
console.log(chalk3.green("\u2705 Action completed successfully!\n"));
|
|
489
480
|
}
|
|
@@ -493,7 +484,7 @@ function formatJsonOutput(data) {
|
|
|
493
484
|
}
|
|
494
485
|
function analyzeZodSchema(schema) {
|
|
495
486
|
const parameters = [];
|
|
496
|
-
if (schema instanceof
|
|
487
|
+
if (schema instanceof z.ZodObject) {
|
|
497
488
|
const shape = schema.shape;
|
|
498
489
|
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
499
490
|
const param = analyzeZodField(key, fieldSchema);
|
|
@@ -508,29 +499,29 @@ function analyzeZodField(name, schema) {
|
|
|
508
499
|
let baseSchema = schema;
|
|
509
500
|
let required = true;
|
|
510
501
|
let defaultValue = void 0;
|
|
511
|
-
if (baseSchema instanceof
|
|
502
|
+
if (baseSchema instanceof z.ZodOptional) {
|
|
512
503
|
required = false;
|
|
513
504
|
baseSchema = baseSchema._def.innerType;
|
|
514
505
|
}
|
|
515
|
-
if (baseSchema instanceof
|
|
506
|
+
if (baseSchema instanceof z.ZodDefault) {
|
|
516
507
|
required = false;
|
|
517
508
|
defaultValue = baseSchema._def.defaultValue();
|
|
518
509
|
baseSchema = baseSchema._def.innerType;
|
|
519
510
|
}
|
|
520
511
|
let paramType = "string";
|
|
521
512
|
let choices;
|
|
522
|
-
if (baseSchema instanceof
|
|
513
|
+
if (baseSchema instanceof z.ZodString) {
|
|
523
514
|
paramType = "string";
|
|
524
|
-
} else if (baseSchema instanceof
|
|
515
|
+
} else if (baseSchema instanceof z.ZodNumber) {
|
|
525
516
|
paramType = "number";
|
|
526
|
-
} else if (baseSchema instanceof
|
|
517
|
+
} else if (baseSchema instanceof z.ZodBoolean) {
|
|
527
518
|
paramType = "boolean";
|
|
528
|
-
} else if (baseSchema instanceof
|
|
519
|
+
} else if (baseSchema instanceof z.ZodArray) {
|
|
529
520
|
paramType = "array";
|
|
530
|
-
} else if (baseSchema instanceof
|
|
521
|
+
} else if (baseSchema instanceof z.ZodEnum) {
|
|
531
522
|
paramType = "string";
|
|
532
523
|
choices = baseSchema._def.values;
|
|
533
|
-
} else if (baseSchema instanceof
|
|
524
|
+
} else if (baseSchema instanceof z.ZodRecord) {
|
|
534
525
|
paramType = "string";
|
|
535
526
|
}
|
|
536
527
|
return {
|
|
@@ -540,7 +531,7 @@ function analyzeZodField(name, schema) {
|
|
|
540
531
|
description: schema.description,
|
|
541
532
|
default: defaultValue,
|
|
542
533
|
choices,
|
|
543
|
-
hasResolver:
|
|
534
|
+
hasResolver: hasResolver(name),
|
|
544
535
|
isPositional: isPositional(schema)
|
|
545
536
|
};
|
|
546
537
|
}
|
|
@@ -657,7 +648,7 @@ function createCommandConfig(cliCommandName, sdkMethodName, schema, sdk2) {
|
|
|
657
648
|
);
|
|
658
649
|
if (isListCommand && hasPaginationParams && !shouldUseJson && !hasUserSpecifiedMaxItems) {
|
|
659
650
|
const sdkObj = sdk2;
|
|
660
|
-
const sdkIterator =
|
|
651
|
+
const sdkIterator = sdkObj[sdkMethodName](resolvedParams);
|
|
661
652
|
await handlePaginatedListWithAsyncIteration(
|
|
662
653
|
sdkMethodName,
|
|
663
654
|
sdkIterator,
|
|
@@ -841,9 +832,9 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, s
|
|
|
841
832
|
);
|
|
842
833
|
}
|
|
843
834
|
if (schema) {
|
|
844
|
-
formatItemsFromSchema(schema, items);
|
|
835
|
+
formatItemsFromSchema(schema, items, totalShown);
|
|
845
836
|
} else {
|
|
846
|
-
formatItemsGeneric2(items);
|
|
837
|
+
formatItemsGeneric2(items, totalShown);
|
|
847
838
|
}
|
|
848
839
|
totalShown += items.length;
|
|
849
840
|
console.log(
|
|
@@ -853,7 +844,7 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, s
|
|
|
853
844
|
)
|
|
854
845
|
);
|
|
855
846
|
if (page.nextCursor) {
|
|
856
|
-
const { continueReading } = await
|
|
847
|
+
const { continueReading } = await inquirer.prompt([
|
|
857
848
|
{
|
|
858
849
|
type: "confirm",
|
|
859
850
|
name: "continueReading",
|
|
@@ -878,9 +869,9 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, s
|
|
|
878
869
|
return;
|
|
879
870
|
}
|
|
880
871
|
if (schema) {
|
|
881
|
-
formatItemsFromSchema(schema, items);
|
|
872
|
+
formatItemsFromSchema(schema, items, 0);
|
|
882
873
|
} else {
|
|
883
|
-
formatItemsGeneric2(items);
|
|
874
|
+
formatItemsGeneric2(items, 0);
|
|
884
875
|
}
|
|
885
876
|
console.log(chalk3.green(`
|
|
886
877
|
\u2705 Showing ${items.length} ${itemName}`));
|
|
@@ -927,11 +918,13 @@ function formatNonPaginatedResults(result, requestedMaxItems, userSpecifiedMaxIt
|
|
|
927
918
|
\u{1F4C4} All available ${itemName} shown`));
|
|
928
919
|
}
|
|
929
920
|
}
|
|
930
|
-
function formatItemsGeneric2(items) {
|
|
921
|
+
function formatItemsGeneric2(items, startingNumber = 0) {
|
|
931
922
|
items.forEach((item, index) => {
|
|
932
923
|
const itemObj = item;
|
|
933
924
|
const name = itemObj?.name || itemObj?.key || itemObj?.id || "Item";
|
|
934
|
-
console.log(
|
|
925
|
+
console.log(
|
|
926
|
+
`${chalk3.gray(`${startingNumber + index + 1}.`)} ${chalk3.cyan(String(name))}`
|
|
927
|
+
);
|
|
935
928
|
if (itemObj?.description) {
|
|
936
929
|
console.log(` ${chalk3.dim(String(itemObj.description))}`);
|
|
937
930
|
}
|
|
@@ -952,24 +945,12 @@ function getListTitleFromMethod(methodName) {
|
|
|
952
945
|
return `Available ${capitalized}`;
|
|
953
946
|
}
|
|
954
947
|
|
|
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
948
|
// src/utils/constants.ts
|
|
965
949
|
var ZAPIER_BASE = "https://zapier.com";
|
|
966
950
|
var LOGIN_CLIENT_ID = "K5eEnRE9TTmSFATdkkWhKF8NOKwoiOnYAyIqJjae";
|
|
967
951
|
var LOGIN_PORTS = [49505, 50575, 52804, 55981, 61010, 63851];
|
|
968
952
|
var LOGIN_TIMEOUT_MS = 3e5;
|
|
969
953
|
var AUTH_MODE_HEADER = "X-Auth";
|
|
970
|
-
|
|
971
|
-
// src/utils/spinner.ts
|
|
972
|
-
import ora from "ora";
|
|
973
954
|
var spinPromise = async (promise, text) => {
|
|
974
955
|
const spinner = ora(text).start();
|
|
975
956
|
try {
|
|
@@ -981,21 +962,18 @@ var spinPromise = async (promise, text) => {
|
|
|
981
962
|
throw error;
|
|
982
963
|
}
|
|
983
964
|
};
|
|
984
|
-
|
|
985
|
-
// src/utils/log.ts
|
|
986
|
-
import chalk4 from "chalk";
|
|
987
965
|
var log = {
|
|
988
966
|
info: (message, ...args) => {
|
|
989
|
-
console.log(
|
|
967
|
+
console.log(chalk3.blue("\u2139"), message, ...args);
|
|
990
968
|
},
|
|
991
969
|
error: (message, ...args) => {
|
|
992
|
-
console.error(
|
|
970
|
+
console.error(chalk3.red("\u2716"), message, ...args);
|
|
993
971
|
},
|
|
994
972
|
success: (message, ...args) => {
|
|
995
|
-
console.log(
|
|
973
|
+
console.log(chalk3.green("\u2713"), message, ...args);
|
|
996
974
|
},
|
|
997
975
|
warn: (message, ...args) => {
|
|
998
|
-
console.log(
|
|
976
|
+
console.log(chalk3.yellow("\u26A0"), message, ...args);
|
|
999
977
|
}
|
|
1000
978
|
};
|
|
1001
979
|
var log_default = log;
|
|
@@ -1046,9 +1024,6 @@ var getCallablePromise = () => {
|
|
|
1046
1024
|
};
|
|
1047
1025
|
};
|
|
1048
1026
|
var getCallablePromise_default = getCallablePromise;
|
|
1049
|
-
|
|
1050
|
-
// src/utils/auth/login.ts
|
|
1051
|
-
import { updateLogin, logout } from "@zapier/zapier-sdk-cli-login";
|
|
1052
1027
|
var findAvailablePort = () => {
|
|
1053
1028
|
return new Promise((resolve2, reject) => {
|
|
1054
1029
|
let portIndex = 0;
|
|
@@ -1179,88 +1154,102 @@ var login = async (timeoutMs = LOGIN_TIMEOUT_MS) => {
|
|
|
1179
1154
|
return data.access_token;
|
|
1180
1155
|
};
|
|
1181
1156
|
var login_default = login;
|
|
1157
|
+
var LoginSchema = z.object({
|
|
1158
|
+
timeout: z.string().optional().describe("Login timeout in seconds (default: 300)")
|
|
1159
|
+
}).describe("Log in to Zapier to access your account");
|
|
1182
1160
|
|
|
1183
|
-
// src/
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
"
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1161
|
+
// src/plugins/login/index.ts
|
|
1162
|
+
var loginWithSdk = createFunction(async function loginWithSdk2(options) {
|
|
1163
|
+
const timeoutSeconds = options.timeout ? parseInt(options.timeout, 10) : 300;
|
|
1164
|
+
if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {
|
|
1165
|
+
throw new Error("Timeout must be a positive number");
|
|
1166
|
+
}
|
|
1167
|
+
await login_default(timeoutSeconds * 1e3);
|
|
1168
|
+
const user = await getLoggedInUser();
|
|
1169
|
+
console.log(`\u2705 Successfully logged in as ${user.email}`);
|
|
1170
|
+
setTimeout(() => process.exit(0), 100);
|
|
1171
|
+
}, LoginSchema);
|
|
1172
|
+
var loginPlugin = () => ({
|
|
1173
|
+
login: loginWithSdk,
|
|
1174
|
+
context: {
|
|
1175
|
+
meta: {
|
|
1176
|
+
login: {
|
|
1177
|
+
categories: ["account"],
|
|
1178
|
+
inputSchema: LoginSchema
|
|
1195
1179
|
}
|
|
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
1180
|
}
|
|
1207
|
-
}
|
|
1208
|
-
}
|
|
1181
|
+
}
|
|
1182
|
+
});
|
|
1183
|
+
var LogoutSchema = z.object({}).describe("Log out of your Zapier account");
|
|
1209
1184
|
|
|
1210
|
-
// src/
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
process.exit(1);
|
|
1185
|
+
// src/plugins/logout/index.ts
|
|
1186
|
+
var logoutWithSdk = createFunction(async function logoutWithSdk2(_options) {
|
|
1187
|
+
logout();
|
|
1188
|
+
console.log("\u2705 Successfully logged out");
|
|
1189
|
+
}, LogoutSchema);
|
|
1190
|
+
var logoutPlugin = () => ({
|
|
1191
|
+
logout: logoutWithSdk,
|
|
1192
|
+
context: {
|
|
1193
|
+
meta: {
|
|
1194
|
+
logout: {
|
|
1195
|
+
categories: ["account"],
|
|
1196
|
+
inputSchema: LogoutSchema
|
|
1197
|
+
}
|
|
1224
1198
|
}
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
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";
|
|
1199
|
+
}
|
|
1200
|
+
});
|
|
1201
|
+
var McpSchema = z.object({
|
|
1202
|
+
port: z.string().optional().describe("Port to listen on (for future HTTP transport)")
|
|
1203
|
+
}).describe("Start MCP server for Zapier SDK");
|
|
1240
1204
|
|
|
1241
|
-
// src/
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1205
|
+
// src/plugins/mcp/index.ts
|
|
1206
|
+
var mcpPlugin = ({ context }) => {
|
|
1207
|
+
const mcpWithSdk = createFunction(async function mcpWithSdk2(options) {
|
|
1208
|
+
const mcpOptions = {
|
|
1209
|
+
...options,
|
|
1210
|
+
debug: context.options.debug
|
|
1211
|
+
};
|
|
1212
|
+
return await startMcpServerAsProcess(mcpOptions);
|
|
1213
|
+
}, McpSchema);
|
|
1214
|
+
return {
|
|
1215
|
+
mcp: mcpWithSdk,
|
|
1216
|
+
context: {
|
|
1217
|
+
meta: {
|
|
1218
|
+
mcp: {
|
|
1219
|
+
categories: ["utility"],
|
|
1220
|
+
inputSchema: McpSchema
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
};
|
|
1225
|
+
};
|
|
1226
|
+
var GenerateTypesSchema = z.object({
|
|
1250
1227
|
appKey: AppKeyPropertySchema.describe("App key to generate SDK code for"),
|
|
1251
1228
|
authenticationId: AuthenticationIdPropertySchema.optional(),
|
|
1252
1229
|
output: OutputPropertySchema.optional().describe(
|
|
1253
1230
|
"Output file path (defaults to generated/<appKey>.ts)"
|
|
1254
1231
|
),
|
|
1255
|
-
|
|
1256
|
-
"Enable debug logging during generation"
|
|
1257
|
-
),
|
|
1258
|
-
lockFilePath: z3.string().optional().describe("Path to the .zapierrc lock file (defaults to .zapierrc)")
|
|
1232
|
+
lockFilePath: z.string().optional().describe("Path to the .zapierrc lock file (defaults to .zapierrc)")
|
|
1259
1233
|
}).describe("Generate TypeScript SDK code for a specific app");
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1234
|
+
var generateTypesPlugin = ({ sdk: sdk2 }) => {
|
|
1235
|
+
const generateTypesWithSdk = createFunction(
|
|
1236
|
+
async function generateTypesWithSdk2(options) {
|
|
1237
|
+
return await generateTypes({ ...options, sdk: sdk2 });
|
|
1238
|
+
},
|
|
1239
|
+
GenerateTypesSchema
|
|
1240
|
+
);
|
|
1241
|
+
return {
|
|
1242
|
+
generateTypes: generateTypesWithSdk,
|
|
1243
|
+
context: {
|
|
1244
|
+
meta: {
|
|
1245
|
+
generateTypes: {
|
|
1246
|
+
categories: ["utility"],
|
|
1247
|
+
inputSchema: GenerateTypesSchema
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
};
|
|
1252
|
+
};
|
|
1264
1253
|
function generateFetchMethodSignature() {
|
|
1265
1254
|
return ` /** Make authenticated HTTP requests through Zapier's Relay service */
|
|
1266
1255
|
fetch: (options: Omit<z.infer<typeof RelayFetchSchema>, 'authenticationId'>) => Promise<Response>`;
|
|
@@ -1551,216 +1540,32 @@ function mapFieldTypeToTypeScript(field) {
|
|
|
1551
1540
|
return "string | number | boolean";
|
|
1552
1541
|
}
|
|
1553
1542
|
}
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
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
|
-
}
|
|
1543
|
+
var BundleCodeSchema = z.object({
|
|
1544
|
+
input: z.string().min(1).describe("Input TypeScript file path to bundle"),
|
|
1545
|
+
output: OutputPropertySchema.optional().describe(
|
|
1546
|
+
"Output file path (defaults to input with .js extension)"
|
|
1547
|
+
),
|
|
1548
|
+
string: z.boolean().optional().describe("Return bundled code as string instead of writing to file"),
|
|
1549
|
+
minify: z.boolean().optional().describe("Minify the bundled output"),
|
|
1550
|
+
target: z.string().optional().describe("ECMAScript target version"),
|
|
1551
|
+
cjs: z.boolean().optional().describe("Output CommonJS format instead of ESM")
|
|
1552
|
+
}).describe("Bundle TypeScript code into executable JavaScript");
|
|
1553
|
+
var bundleCodePlugin = () => {
|
|
1554
|
+
const bundleCodeWithSdk = createFunction(async function bundleCodeWithSdk2(options) {
|
|
1555
|
+
return await bundleCode(options);
|
|
1556
|
+
}, BundleCodeSchema);
|
|
1603
1557
|
return {
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
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;
|
|
1558
|
+
bundleCode: bundleCodeWithSdk,
|
|
1559
|
+
context: {
|
|
1560
|
+
meta: {
|
|
1561
|
+
bundleCode: {
|
|
1562
|
+
categories: ["utility"],
|
|
1563
|
+
inputSchema: BundleCodeSchema
|
|
1650
1564
|
}
|
|
1651
1565
|
}
|
|
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
1566
|
}
|
|
1739
|
-
}
|
|
1740
|
-
|
|
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";
|
|
1567
|
+
};
|
|
1568
|
+
};
|
|
1764
1569
|
var ZapierBundleError = class extends Error {
|
|
1765
1570
|
constructor(message, details, originalError) {
|
|
1766
1571
|
super(message);
|
|
@@ -1779,7 +1584,7 @@ async function bundleCode(options) {
|
|
|
1779
1584
|
minify = false,
|
|
1780
1585
|
string: returnString = false
|
|
1781
1586
|
} = options;
|
|
1782
|
-
const resolvedInput =
|
|
1587
|
+
const resolvedInput = path.resolve(process.cwd(), input);
|
|
1783
1588
|
try {
|
|
1784
1589
|
const result = buildSync({
|
|
1785
1590
|
entryPoints: [resolvedInput],
|
|
@@ -1811,8 +1616,8 @@ async function bundleCode(options) {
|
|
|
1811
1616
|
finalOutput = JSON.stringify(bundledCode);
|
|
1812
1617
|
}
|
|
1813
1618
|
if (output) {
|
|
1814
|
-
|
|
1815
|
-
|
|
1619
|
+
fs.mkdirSync(path.dirname(output), { recursive: true });
|
|
1620
|
+
fs.writeFileSync(output, finalOutput, "utf8");
|
|
1816
1621
|
}
|
|
1817
1622
|
return finalOutput;
|
|
1818
1623
|
} catch (error) {
|
|
@@ -1826,105 +1631,52 @@ async function bundleCode(options) {
|
|
|
1826
1631
|
);
|
|
1827
1632
|
}
|
|
1828
1633
|
}
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
function
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
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);
|
|
1634
|
+
var GetConfigPathSchema = z.object({}).describe("Show the path to the configuration file");
|
|
1635
|
+
var getConfigPathPlugin = () => {
|
|
1636
|
+
const getConfigPathWithSdk = createFunction(
|
|
1637
|
+
async function getConfigPathWithSdk2(_options) {
|
|
1638
|
+
return getConfigPath();
|
|
1639
|
+
},
|
|
1640
|
+
GetConfigPathSchema
|
|
1641
|
+
);
|
|
1642
|
+
return {
|
|
1643
|
+
getConfigPath: getConfigPathWithSdk,
|
|
1644
|
+
context: {
|
|
1645
|
+
meta: {
|
|
1646
|
+
getConfigPath: {
|
|
1647
|
+
categories: ["utility"],
|
|
1648
|
+
inputSchema: GetConfigPathSchema
|
|
1649
|
+
}
|
|
1895
1650
|
}
|
|
1896
|
-
} catch (error) {
|
|
1897
|
-
console.error(
|
|
1898
|
-
chalk6.red("Error:"),
|
|
1899
|
-
error instanceof Error ? error.message : "Unknown error"
|
|
1900
|
-
);
|
|
1901
|
-
process.exit(1);
|
|
1902
1651
|
}
|
|
1652
|
+
};
|
|
1653
|
+
};
|
|
1654
|
+
|
|
1655
|
+
// src/sdk.ts
|
|
1656
|
+
function createZapierCliSdk(options = {}) {
|
|
1657
|
+
let sdk2 = createZapierSdkWithoutRegistry({
|
|
1658
|
+
debug: options.debug
|
|
1903
1659
|
});
|
|
1904
|
-
|
|
1660
|
+
sdk2 = sdk2.addPlugin(generateTypesPlugin);
|
|
1661
|
+
sdk2 = sdk2.addPlugin(bundleCodePlugin);
|
|
1662
|
+
sdk2 = sdk2.addPlugin(getConfigPathPlugin);
|
|
1663
|
+
sdk2 = sdk2.addPlugin(mcpPlugin);
|
|
1664
|
+
sdk2 = sdk2.addPlugin(loginPlugin);
|
|
1665
|
+
sdk2 = sdk2.addPlugin(logoutPlugin);
|
|
1666
|
+
const finalSdk = sdk2.addPlugin(registryPlugin);
|
|
1667
|
+
return finalSdk;
|
|
1905
1668
|
}
|
|
1906
1669
|
|
|
1907
|
-
//
|
|
1908
|
-
|
|
1909
|
-
|
|
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
|
-
}
|
|
1670
|
+
// package.json
|
|
1671
|
+
var package_default = {
|
|
1672
|
+
version: "0.6.5"};
|
|
1915
1673
|
|
|
1916
1674
|
// src/cli.ts
|
|
1917
|
-
var program = new
|
|
1918
|
-
program.name("zapier-sdk").description("CLI for Zapier SDK").version(
|
|
1675
|
+
var program = new Command();
|
|
1676
|
+
program.name("zapier-sdk").description("CLI for Zapier SDK").version(package_default.version, "-v, --version", "display version number").option("--debug", "Enable debug logging");
|
|
1919
1677
|
var isDebugMode = process.env.DEBUG === "true" || process.argv.includes("--debug");
|
|
1920
|
-
var sdk =
|
|
1678
|
+
var sdk = createZapierCliSdk({
|
|
1921
1679
|
debug: isDebugMode
|
|
1922
1680
|
});
|
|
1923
|
-
program.addCommand(createLoginCommand());
|
|
1924
|
-
program.addCommand(createLogoutCommand());
|
|
1925
1681
|
generateCliCommands(program, sdk);
|
|
1926
|
-
program.addCommand(createGenerateTypesCommand());
|
|
1927
|
-
program.addCommand(createBundleCodeCommand());
|
|
1928
|
-
program.addCommand(createConfigPathCommand());
|
|
1929
|
-
program.addCommand(createMcpCommand());
|
|
1930
1682
|
program.parse();
|