@zapier/zapier-sdk-cli 0.9.0 → 0.11.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 +32 -0
- package/dist/cli.cjs +316 -144
- package/dist/cli.mjs +317 -145
- package/dist/index.cjs +15 -12
- package/dist/index.mjs +15 -12
- package/dist/package.json +1 -1
- package/dist/src/plugins/add/index.js +11 -13
- package/dist/src/utils/cli-generator-utils.d.ts +2 -1
- package/dist/src/utils/cli-generator-utils.js +11 -5
- package/dist/src/utils/cli-generator.js +50 -65
- package/dist/src/utils/parameter-resolver.d.ts +9 -1
- package/dist/src/utils/parameter-resolver.js +192 -56
- package/dist/src/utils/schema-formatter.d.ts +5 -1
- package/dist/src/utils/schema-formatter.js +48 -18
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/plugins/add/index.ts +15 -15
- package/src/utils/cli-generator-utils.ts +17 -5
- package/src/utils/cli-generator.ts +68 -79
- package/src/utils/parameter-resolver.ts +310 -80
- package/src/utils/schema-formatter.ts +68 -33
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import type { z } from "zod";
|
|
3
|
+
import util from "util";
|
|
3
4
|
// These functions are internal to SDK, implementing basic formatting fallback
|
|
4
5
|
// TODO: Consider exposing these utilities or implementing proper CLI formatting
|
|
5
6
|
|
|
6
7
|
interface FormattedItem {
|
|
7
8
|
title: string;
|
|
8
|
-
|
|
9
|
+
id?: string;
|
|
10
|
+
key?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
data?: unknown; // Optional: if provided, use formatJsonOutput instead of details
|
|
9
13
|
details: Array<{
|
|
10
14
|
text: string;
|
|
11
15
|
style: "normal" | "dim" | "accent" | "warning" | "success";
|
|
@@ -25,17 +29,34 @@ function getOutputSchema(schema: unknown): unknown {
|
|
|
25
29
|
return (schema as { _def?: { outputSchema?: unknown } })?._def?.outputSchema;
|
|
26
30
|
}
|
|
27
31
|
|
|
32
|
+
// ============================================================================
|
|
33
|
+
// JSON Formatting
|
|
34
|
+
// ============================================================================
|
|
35
|
+
|
|
36
|
+
export function formatJsonOutput(data: unknown): void {
|
|
37
|
+
// Don't print anything for undefined results (commands that just perform actions)
|
|
38
|
+
if (data === undefined) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Use util.inspect for colored output
|
|
43
|
+
console.log(
|
|
44
|
+
util.inspect(data, { colors: true, depth: null, breakLength: 80 }),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
28
48
|
// ============================================================================
|
|
29
49
|
// Generic Schema-Driven Formatter
|
|
30
50
|
// ============================================================================
|
|
31
51
|
|
|
32
52
|
export function formatItemsFromSchema(
|
|
33
|
-
inputSchema: z.ZodType,
|
|
53
|
+
functionInfo: { inputSchema: z.ZodType; outputSchema?: z.ZodType },
|
|
34
54
|
items: unknown[],
|
|
35
55
|
startingNumber: number = 0,
|
|
36
56
|
): void {
|
|
37
|
-
// Get the output schema
|
|
38
|
-
const outputSchema =
|
|
57
|
+
// Get the output schema from function info or fall back to input schema output schema
|
|
58
|
+
const outputSchema =
|
|
59
|
+
functionInfo.outputSchema || getOutputSchema(functionInfo.inputSchema);
|
|
39
60
|
if (!outputSchema) {
|
|
40
61
|
// Fallback to generic formatting if no output schema
|
|
41
62
|
formatItemsGeneric(items, startingNumber);
|
|
@@ -51,25 +72,35 @@ export function formatItemsFromSchema(
|
|
|
51
72
|
|
|
52
73
|
// Format each item using the schema metadata
|
|
53
74
|
items.forEach((item, index) => {
|
|
54
|
-
|
|
75
|
+
const formatted = formatMeta.format(item);
|
|
76
|
+
formatSingleItem(formatted, startingNumber + index);
|
|
55
77
|
});
|
|
56
78
|
}
|
|
57
79
|
|
|
58
|
-
function formatSingleItem(
|
|
59
|
-
|
|
60
|
-
itemNumber: number,
|
|
61
|
-
formatMeta: FormatMetadata,
|
|
62
|
-
): void {
|
|
63
|
-
// Get the formatted item from the format function
|
|
64
|
-
const formatted = formatMeta.format(item);
|
|
65
|
-
|
|
66
|
-
// Build the main title line
|
|
80
|
+
function formatSingleItem(formatted: FormattedItem, itemNumber: number): void {
|
|
81
|
+
// Build the main title line with optional subtitle
|
|
67
82
|
let titleLine = `${chalk.gray(`${itemNumber + 1}.`)} ${chalk.cyan(formatted.title)}`;
|
|
68
|
-
|
|
69
|
-
|
|
83
|
+
|
|
84
|
+
// Generate subtitle from id or key
|
|
85
|
+
if (formatted.id) {
|
|
86
|
+
titleLine += ` ${chalk.gray(`(ID: ${formatted.id})`)}`;
|
|
87
|
+
} else if (formatted.key) {
|
|
88
|
+
titleLine += ` ${chalk.gray(`(${formatted.key})`)}`;
|
|
70
89
|
}
|
|
71
90
|
console.log(titleLine);
|
|
72
91
|
|
|
92
|
+
// Show description if available
|
|
93
|
+
if (formatted.description) {
|
|
94
|
+
console.log(` ${chalk.dim(formatted.description)}`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// If data is provided, use JSON formatting instead of details
|
|
98
|
+
if (formatted.data !== undefined) {
|
|
99
|
+
formatJsonOutput(formatted.data);
|
|
100
|
+
console.log(); // Empty line between items
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
73
104
|
// Format detail lines
|
|
74
105
|
for (const detail of formatted.details) {
|
|
75
106
|
const styledText = applyStyle(detail.text, detail.style);
|
|
@@ -95,27 +126,31 @@ function applyStyle(value: string, style: string): string {
|
|
|
95
126
|
}
|
|
96
127
|
}
|
|
97
128
|
|
|
129
|
+
function convertGenericItemToFormattedItem(item: unknown): FormattedItem {
|
|
130
|
+
const itemObj = item as {
|
|
131
|
+
title?: string;
|
|
132
|
+
name?: string;
|
|
133
|
+
key?: string;
|
|
134
|
+
id?: string;
|
|
135
|
+
description?: string;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
title: itemObj.title || itemObj.name || itemObj.key || itemObj.id || "Item",
|
|
140
|
+
id: itemObj.id,
|
|
141
|
+
key: itemObj.key,
|
|
142
|
+
description: itemObj.description,
|
|
143
|
+
details: [],
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
98
147
|
function formatItemsGeneric(
|
|
99
148
|
items: unknown[],
|
|
100
149
|
startingNumber: number = 0,
|
|
101
150
|
): void {
|
|
102
|
-
//
|
|
151
|
+
// Convert generic items to FormattedItem and use formatSingleItem
|
|
103
152
|
items.forEach((item, index) => {
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
name?: string;
|
|
107
|
-
key?: string;
|
|
108
|
-
id?: string;
|
|
109
|
-
description?: string;
|
|
110
|
-
};
|
|
111
|
-
const name =
|
|
112
|
-
itemObj.title || itemObj.name || itemObj.key || itemObj.id || "Item";
|
|
113
|
-
console.log(
|
|
114
|
-
`${chalk.gray(`${startingNumber + index + 1}.`)} ${chalk.cyan(name)}`,
|
|
115
|
-
);
|
|
116
|
-
if (itemObj.description) {
|
|
117
|
-
console.log(` ${chalk.dim(itemObj.description)}`);
|
|
118
|
-
}
|
|
119
|
-
console.log();
|
|
153
|
+
const formatted = convertGenericItemToFormattedItem(item);
|
|
154
|
+
formatSingleItem(formatted, startingNumber + index);
|
|
120
155
|
});
|
|
121
156
|
}
|