@zapier/zapier-sdk-cli 0.6.4 → 0.8.0
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 +30 -0
- package/README.md +61 -36
- package/dist/cli.cjs +37 -24
- package/dist/cli.mjs +37 -24
- package/dist/package.json +1 -1
- package/dist/src/utils/cli-generator.js +37 -17
- 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 +3 -3
- package/src/utils/cli-generator.test.ts +93 -0
- package/src/utils/cli-generator.ts +51 -19
- package/src/utils/schema-formatter.ts +13 -7
|
@@ -30,6 +30,15 @@ function formatJsonOutput(data) {
|
|
|
30
30
|
// ============================================================================
|
|
31
31
|
function analyzeZodSchema(schema) {
|
|
32
32
|
const parameters = [];
|
|
33
|
+
// Handle ZodEffects (schemas with .refine(), .transform(), etc.)
|
|
34
|
+
if (schema._def &&
|
|
35
|
+
schema._def.typeName ===
|
|
36
|
+
"ZodEffects") {
|
|
37
|
+
// Get the underlying schema
|
|
38
|
+
const innerSchema = schema
|
|
39
|
+
._def.schema;
|
|
40
|
+
return analyzeZodSchema(innerSchema);
|
|
41
|
+
}
|
|
33
42
|
if (schema instanceof z.ZodObject) {
|
|
34
43
|
const shape = schema.shape;
|
|
35
44
|
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
@@ -45,15 +54,26 @@ function analyzeZodField(name, schema) {
|
|
|
45
54
|
let baseSchema = schema;
|
|
46
55
|
let required = true;
|
|
47
56
|
let defaultValue = undefined;
|
|
48
|
-
// Unwrap optional and
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
// Unwrap optional, default, and nullable wrappers - keep unwrapping until we get to the base type
|
|
58
|
+
while (true) {
|
|
59
|
+
if (baseSchema instanceof z.ZodOptional) {
|
|
60
|
+
required = false;
|
|
61
|
+
baseSchema = baseSchema._def.innerType;
|
|
62
|
+
}
|
|
63
|
+
else if (baseSchema instanceof z.ZodDefault) {
|
|
64
|
+
required = false;
|
|
65
|
+
defaultValue = baseSchema._def.defaultValue();
|
|
66
|
+
baseSchema = baseSchema._def.innerType;
|
|
67
|
+
}
|
|
68
|
+
else if (baseSchema._def &&
|
|
69
|
+
baseSchema._def
|
|
70
|
+
.typeName === "ZodNullable") {
|
|
71
|
+
// nullable doesn't affect CLI required status, but we need to unwrap it to get the base type
|
|
72
|
+
baseSchema = baseSchema._def.innerType;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
break; // No more wrappers to unwrap
|
|
76
|
+
}
|
|
57
77
|
}
|
|
58
78
|
// Determine parameter type
|
|
59
79
|
let paramType = "string";
|
|
@@ -203,9 +223,9 @@ function createCommandConfig(cliCommandName, sdkMethodName, schema, sdk) {
|
|
|
203
223
|
hasPaginationParams &&
|
|
204
224
|
!shouldUseJson &&
|
|
205
225
|
!hasUserSpecifiedMaxItems) {
|
|
206
|
-
// Get the async
|
|
226
|
+
// Get the async iterable directly from the SDK method call (don't await it! that breaks the next page behavior)
|
|
207
227
|
const sdkObj = sdk;
|
|
208
|
-
const sdkIterator =
|
|
228
|
+
const sdkIterator = sdkObj[sdkMethodName](resolvedParams);
|
|
209
229
|
await handlePaginatedListWithAsyncIteration(sdkMethodName, sdkIterator, schema);
|
|
210
230
|
}
|
|
211
231
|
else {
|
|
@@ -391,10 +411,10 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, s
|
|
|
391
411
|
}
|
|
392
412
|
// Format and display items using schema
|
|
393
413
|
if (schema) {
|
|
394
|
-
formatItemsFromSchema(schema, items);
|
|
414
|
+
formatItemsFromSchema(schema, items, totalShown);
|
|
395
415
|
}
|
|
396
416
|
else {
|
|
397
|
-
formatItemsGeneric(items);
|
|
417
|
+
formatItemsGeneric(items, totalShown);
|
|
398
418
|
}
|
|
399
419
|
totalShown += items.length;
|
|
400
420
|
console.log(chalk.green(`\n✅ Showing ${totalShown} ${itemName} (page ${pageCount})`));
|
|
@@ -428,10 +448,10 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, s
|
|
|
428
448
|
return;
|
|
429
449
|
}
|
|
430
450
|
if (schema) {
|
|
431
|
-
formatItemsFromSchema(schema, items);
|
|
451
|
+
formatItemsFromSchema(schema, items, 0);
|
|
432
452
|
}
|
|
433
453
|
else {
|
|
434
|
-
formatItemsGeneric(items);
|
|
454
|
+
formatItemsGeneric(items, 0);
|
|
435
455
|
}
|
|
436
456
|
console.log(chalk.green(`\n✅ Showing ${items.length} ${itemName}`));
|
|
437
457
|
}
|
|
@@ -476,12 +496,12 @@ function formatNonPaginatedResults(result, requestedMaxItems, userSpecifiedMaxIt
|
|
|
476
496
|
console.log(chalk.gray(`\n📄 All available ${itemName} shown`));
|
|
477
497
|
}
|
|
478
498
|
}
|
|
479
|
-
function formatItemsGeneric(items) {
|
|
499
|
+
function formatItemsGeneric(items, startingNumber = 0) {
|
|
480
500
|
// Fallback formatting for items without schema metadata
|
|
481
501
|
items.forEach((item, index) => {
|
|
482
502
|
const itemObj = item;
|
|
483
503
|
const name = itemObj?.name || itemObj?.key || itemObj?.id || "Item";
|
|
484
|
-
console.log(`${chalk.gray(`${index + 1}.`)} ${chalk.cyan(String(name))}`);
|
|
504
|
+
console.log(`${chalk.gray(`${startingNumber + index + 1}.`)} ${chalk.cyan(String(name))}`);
|
|
485
505
|
if (itemObj?.description) {
|
|
486
506
|
console.log(` ${chalk.dim(String(itemObj.description))}`);
|
|
487
507
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
export declare function formatItemsFromSchema(inputSchema: z.ZodType, items: unknown[]): void;
|
|
2
|
+
export declare function formatItemsFromSchema(inputSchema: z.ZodType, items: unknown[], startingNumber?: number): void;
|
|
@@ -9,30 +9,30 @@ function getOutputSchema(schema) {
|
|
|
9
9
|
// ============================================================================
|
|
10
10
|
// Generic Schema-Driven Formatter
|
|
11
11
|
// ============================================================================
|
|
12
|
-
export function formatItemsFromSchema(inputSchema, items) {
|
|
12
|
+
export function formatItemsFromSchema(inputSchema, items, startingNumber = 0) {
|
|
13
13
|
// Get the output schema and its format metadata
|
|
14
14
|
const outputSchema = getOutputSchema(inputSchema);
|
|
15
15
|
if (!outputSchema) {
|
|
16
16
|
// Fallback to generic formatting if no output schema
|
|
17
|
-
formatItemsGeneric(items);
|
|
17
|
+
formatItemsGeneric(items, startingNumber);
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
20
|
const formatMeta = getFormatMetadata(outputSchema);
|
|
21
21
|
if (!formatMeta) {
|
|
22
22
|
// Fallback to generic formatting if no format metadata
|
|
23
|
-
formatItemsGeneric(items);
|
|
23
|
+
formatItemsGeneric(items, startingNumber);
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
26
|
// Format each item using the schema metadata
|
|
27
27
|
items.forEach((item, index) => {
|
|
28
|
-
formatSingleItem(item, index, formatMeta);
|
|
28
|
+
formatSingleItem(item, startingNumber + index, formatMeta);
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
function formatSingleItem(item,
|
|
31
|
+
function formatSingleItem(item, itemNumber, formatMeta) {
|
|
32
32
|
// Get the formatted item from the format function
|
|
33
33
|
const formatted = formatMeta.format(item);
|
|
34
34
|
// Build the main title line
|
|
35
|
-
let titleLine = `${chalk.gray(`${
|
|
35
|
+
let titleLine = `${chalk.gray(`${itemNumber + 1}.`)} ${chalk.cyan(formatted.title)}`;
|
|
36
36
|
if (formatted.subtitle) {
|
|
37
37
|
titleLine += ` ${chalk.gray(formatted.subtitle)}`;
|
|
38
38
|
}
|
|
@@ -59,12 +59,12 @@ function applyStyle(value, style) {
|
|
|
59
59
|
return chalk.blue(value);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
function formatItemsGeneric(items) {
|
|
62
|
+
function formatItemsGeneric(items, startingNumber = 0) {
|
|
63
63
|
// Fallback formatting for items without schema metadata
|
|
64
64
|
items.forEach((item, index) => {
|
|
65
65
|
const itemObj = item;
|
|
66
66
|
const name = itemObj.title || itemObj.name || itemObj.key || itemObj.id || "Item";
|
|
67
|
-
console.log(`${chalk.gray(`${index + 1}.`)} ${chalk.cyan(name)}`);
|
|
67
|
+
console.log(`${chalk.gray(`${startingNumber + index + 1}.`)} ${chalk.cyan(name)}`);
|
|
68
68
|
if (itemObj.description) {
|
|
69
69
|
console.log(` ${chalk.dim(itemObj.description)}`);
|
|
70
70
|
}
|