@zapier/zapier-sdk-cli 0.4.4 → 0.5.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 +13 -0
- package/dist/cli.js +96 -46
- package/dist/src/commands/bundle-code/cli.js +1 -1
- package/dist/src/commands/generate-types/cli.js +13 -4
- package/dist/src/utils/api/client.d.ts +3 -3
- package/dist/src/utils/cli-generator-utils.d.ts +2 -2
- package/dist/src/utils/cli-generator.js +29 -20
- package/dist/src/utils/log.d.ts +4 -4
- package/dist/src/utils/parameter-resolver.d.ts +1 -1
- package/dist/src/utils/parameter-resolver.js +33 -22
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/commands/bundle-code/cli.ts +19 -4
- package/src/commands/generate-types/cli.ts +21 -6
- package/src/utils/api/client.ts +3 -3
- package/src/utils/cli-generator-utils.ts +7 -7
- package/src/utils/cli-generator.ts +80 -45
- package/src/utils/log.ts +4 -4
- package/src/utils/parameter-resolver.ts +79 -42
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @zapier/zapier-sdk-cli
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 218a3ca: reducing 'any' usage with minimal changes to runtime
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [218a3ca]
|
|
12
|
+
- @zapier/zapier-sdk-cli-login@0.3.2
|
|
13
|
+
- @zapier/zapier-sdk-mcp@0.1.4
|
|
14
|
+
- @zapier/zapier-sdk@0.5.2
|
|
15
|
+
|
|
3
16
|
## 0.4.4
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/cli.js
CHANGED
|
@@ -268,7 +268,7 @@ var SchemaParameterResolver = class {
|
|
|
268
268
|
break;
|
|
269
269
|
}
|
|
270
270
|
const newFields = fields.filter(
|
|
271
|
-
(field) => !processedFieldKeys.has(field.key)
|
|
271
|
+
(field) => !(field.key && processedFieldKeys.has(field.key))
|
|
272
272
|
);
|
|
273
273
|
if (newFields.length === 0) {
|
|
274
274
|
break;
|
|
@@ -343,40 +343,54 @@ Optional fields:`));
|
|
|
343
343
|
return inputs;
|
|
344
344
|
}
|
|
345
345
|
getNestedValue(obj, path3) {
|
|
346
|
-
return path3.reduce(
|
|
346
|
+
return path3.reduce(
|
|
347
|
+
(current, key) => current?.[key],
|
|
348
|
+
obj
|
|
349
|
+
);
|
|
347
350
|
}
|
|
348
351
|
setNestedValue(obj, path3, value) {
|
|
349
352
|
const lastKey = path3[path3.length - 1];
|
|
350
353
|
const parent = path3.slice(0, -1).reduce((current, key) => {
|
|
351
|
-
|
|
352
|
-
|
|
354
|
+
const currentObj = current;
|
|
355
|
+
if (!(key in currentObj)) {
|
|
356
|
+
currentObj[key] = {};
|
|
353
357
|
}
|
|
354
|
-
return
|
|
358
|
+
return currentObj[key];
|
|
355
359
|
}, obj);
|
|
356
360
|
parent[lastKey] = value;
|
|
357
361
|
}
|
|
358
362
|
async promptForField(field, inputs) {
|
|
363
|
+
const fieldObj = field;
|
|
359
364
|
const fieldPrompt = {
|
|
360
|
-
type:
|
|
361
|
-
name:
|
|
362
|
-
message: `${
|
|
363
|
-
...field.helpText && { prefix: chalk.gray(`\u2139 ${field.helpText}
|
|
364
|
-
`) },
|
|
365
|
-
...field.default && { default: field.default }
|
|
365
|
+
type: fieldObj.type === "boolean" ? "confirm" : "input",
|
|
366
|
+
name: fieldObj.key,
|
|
367
|
+
message: `${fieldObj.label || fieldObj.key}${fieldObj.required ? " (required)" : " (optional)"}:`
|
|
366
368
|
};
|
|
367
|
-
if (
|
|
369
|
+
if (fieldObj.helpText) {
|
|
370
|
+
fieldPrompt.prefix = chalk.gray(`\u2139 ${fieldObj.helpText}
|
|
371
|
+
`);
|
|
372
|
+
}
|
|
373
|
+
if (fieldObj.default !== void 0) {
|
|
374
|
+
fieldPrompt.default = fieldObj.default;
|
|
375
|
+
}
|
|
376
|
+
if (fieldObj.choices && fieldObj.choices.length > 0) {
|
|
368
377
|
fieldPrompt.type = "list";
|
|
369
|
-
fieldPrompt.choices =
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
378
|
+
fieldPrompt.choices = fieldObj.choices.map(
|
|
379
|
+
(choice) => {
|
|
380
|
+
const choiceObj = choice;
|
|
381
|
+
return {
|
|
382
|
+
name: choiceObj.label || choiceObj.value,
|
|
383
|
+
value: choiceObj.value
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
);
|
|
373
387
|
}
|
|
374
388
|
try {
|
|
375
389
|
const answer = await inquirer.prompt([fieldPrompt]);
|
|
376
|
-
if (answer[
|
|
377
|
-
inputs[
|
|
378
|
-
} else if (
|
|
379
|
-
throw new Error(`Required field ${
|
|
390
|
+
if (answer[fieldObj.key] !== void 0 && answer[fieldObj.key] !== "") {
|
|
391
|
+
inputs[fieldObj.key] = answer[fieldObj.key];
|
|
392
|
+
} else if (fieldObj.required) {
|
|
393
|
+
throw new Error(`Required field ${fieldObj.key} cannot be empty`);
|
|
380
394
|
}
|
|
381
395
|
} catch (error) {
|
|
382
396
|
if (this.isUserCancellation(error)) {
|
|
@@ -387,7 +401,8 @@ Optional fields:`));
|
|
|
387
401
|
}
|
|
388
402
|
}
|
|
389
403
|
isUserCancellation(error) {
|
|
390
|
-
|
|
404
|
+
const errorObj = error;
|
|
405
|
+
return errorObj?.name === "ExitPromptError" || errorObj?.message?.includes("User force closed") || errorObj?.isTTYError === true;
|
|
391
406
|
}
|
|
392
407
|
};
|
|
393
408
|
|
|
@@ -568,24 +583,27 @@ function createCommandConfig(cliCommandName, sdkMethodName, schema, sdk2) {
|
|
|
568
583
|
rawParams,
|
|
569
584
|
sdk2
|
|
570
585
|
);
|
|
571
|
-
const hasOutputFile = resolvedParams.output;
|
|
572
|
-
if (hasOutputFile) {
|
|
573
|
-
await sdk2[sdkMethodName](resolvedParams);
|
|
574
|
-
console.log(
|
|
575
|
-
chalk3.green(`\u2705 ${cliCommandName} completed successfully!`)
|
|
576
|
-
);
|
|
577
|
-
console.log(chalk3.gray(`Output written to: ${resolvedParams.output}`));
|
|
578
|
-
return;
|
|
579
|
-
}
|
|
580
586
|
if (isListCommand && hasPaginationParams && !shouldUseJson && !hasUserSpecifiedMaxItems) {
|
|
581
|
-
const
|
|
587
|
+
const sdkObj = sdk2;
|
|
588
|
+
const sdkIterator = await sdkObj[sdkMethodName](resolvedParams);
|
|
582
589
|
await handlePaginatedListWithAsyncIteration(
|
|
583
590
|
sdkMethodName,
|
|
584
591
|
sdkIterator,
|
|
585
592
|
schema
|
|
586
593
|
);
|
|
587
594
|
} else {
|
|
588
|
-
const
|
|
595
|
+
const hasOutputFile = resolvedParams.output;
|
|
596
|
+
if (hasOutputFile) {
|
|
597
|
+
const sdkObj2 = sdk2;
|
|
598
|
+
await sdkObj2[sdkMethodName](resolvedParams);
|
|
599
|
+
console.log(
|
|
600
|
+
chalk3.green(`\u2705 ${cliCommandName} completed successfully!`)
|
|
601
|
+
);
|
|
602
|
+
console.log(chalk3.gray(`Output written to: ${hasOutputFile}`));
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
const sdkObj = sdk2;
|
|
606
|
+
const result = await sdkObj[sdkMethodName](resolvedParams);
|
|
589
607
|
const items = result?.data ? result.data : result;
|
|
590
608
|
if (shouldUseJson) {
|
|
591
609
|
console.log(JSON.stringify(items, null, 2));
|
|
@@ -608,8 +626,13 @@ function createCommandConfig(cliCommandName, sdkMethodName, schema, sdk2) {
|
|
|
608
626
|
const validationErrors = JSON.parse(error.message);
|
|
609
627
|
console.error(chalk3.red("\u274C Validation Error:"));
|
|
610
628
|
validationErrors.forEach((err) => {
|
|
611
|
-
const
|
|
612
|
-
|
|
629
|
+
const errorObj = err;
|
|
630
|
+
const field = errorObj?.path?.join(".") || "unknown";
|
|
631
|
+
console.error(
|
|
632
|
+
chalk3.yellow(
|
|
633
|
+
` \u2022 ${field}: ${errorObj?.message || "Unknown error"}`
|
|
634
|
+
)
|
|
635
|
+
);
|
|
613
636
|
});
|
|
614
637
|
console.error(
|
|
615
638
|
"\n" + chalk3.dim(`Use --help to see available options`)
|
|
@@ -658,10 +681,18 @@ function addCommand(program2, commandName, config) {
|
|
|
658
681
|
command.option(flags.join(", "), param.description);
|
|
659
682
|
} else if (param.type === "array") {
|
|
660
683
|
const flagSignature = flags.join(", ") + ` <values...>`;
|
|
661
|
-
command.option(
|
|
684
|
+
command.option(
|
|
685
|
+
flagSignature,
|
|
686
|
+
param.description,
|
|
687
|
+
param.default
|
|
688
|
+
);
|
|
662
689
|
} else {
|
|
663
690
|
const flagSignature = flags.join(", ") + ` <${param.type}>`;
|
|
664
|
-
command.option(
|
|
691
|
+
command.option(
|
|
692
|
+
flagSignature,
|
|
693
|
+
param.description || "",
|
|
694
|
+
param.default
|
|
695
|
+
);
|
|
665
696
|
}
|
|
666
697
|
}
|
|
667
698
|
});
|
|
@@ -826,10 +857,11 @@ function formatNonPaginatedResults(result, requestedMaxItems, userSpecifiedMaxIt
|
|
|
826
857
|
}
|
|
827
858
|
function formatItemsGeneric2(items) {
|
|
828
859
|
items.forEach((item, index) => {
|
|
829
|
-
const
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
860
|
+
const itemObj = item;
|
|
861
|
+
const name = itemObj?.name || itemObj?.key || itemObj?.id || "Item";
|
|
862
|
+
console.log(`${chalk3.gray(`${index + 1}.`)} ${chalk3.cyan(String(name))}`);
|
|
863
|
+
if (itemObj?.description) {
|
|
864
|
+
console.log(` ${chalk3.dim(String(itemObj.description))}`);
|
|
833
865
|
}
|
|
834
866
|
console.log();
|
|
835
867
|
});
|
|
@@ -1556,7 +1588,11 @@ function createGenerateTypesCommand() {
|
|
|
1556
1588
|
command.option(flags.join(", "), param.description);
|
|
1557
1589
|
} else {
|
|
1558
1590
|
const flagSignature = flags.join(", ") + ` <${param.type}>`;
|
|
1559
|
-
command.option(
|
|
1591
|
+
command.option(
|
|
1592
|
+
flagSignature,
|
|
1593
|
+
param.description || "",
|
|
1594
|
+
param.default
|
|
1595
|
+
);
|
|
1560
1596
|
}
|
|
1561
1597
|
}
|
|
1562
1598
|
});
|
|
@@ -1577,16 +1613,24 @@ function createGenerateTypesCommand() {
|
|
|
1577
1613
|
rawParams,
|
|
1578
1614
|
sdk2
|
|
1579
1615
|
);
|
|
1616
|
+
const params = resolvedParams;
|
|
1580
1617
|
console.log(
|
|
1581
1618
|
chalk5.blue(
|
|
1582
|
-
`\u{1F527} Generating TypeScript types for ${
|
|
1619
|
+
`\u{1F527} Generating TypeScript types for ${params.appKey}...`
|
|
1583
1620
|
)
|
|
1584
1621
|
);
|
|
1585
|
-
const
|
|
1622
|
+
const generateTypesParams = {
|
|
1623
|
+
appKey: params.appKey,
|
|
1624
|
+
debug: params.debug ?? false,
|
|
1625
|
+
authenticationId: params.authenticationId,
|
|
1626
|
+
output: params.output,
|
|
1627
|
+
sdk: sdk2
|
|
1628
|
+
};
|
|
1629
|
+
const result = await generateTypes(generateTypesParams);
|
|
1586
1630
|
if (options.json) {
|
|
1587
1631
|
console.log(JSON.stringify({ result }, null, 2));
|
|
1588
1632
|
} else {
|
|
1589
|
-
const output =
|
|
1633
|
+
const output = params.output || `./types/${params.appKey}.d.ts`;
|
|
1590
1634
|
console.log(chalk5.green("\u2705 TypeScript types generated successfully!"));
|
|
1591
1635
|
console.log(chalk5.gray(`Output written to: ${output}`));
|
|
1592
1636
|
}
|
|
@@ -1717,7 +1761,11 @@ function createBundleCodeCommand() {
|
|
|
1717
1761
|
command.option(flags.join(", "), param.description);
|
|
1718
1762
|
} else {
|
|
1719
1763
|
const flagSignature = flags.join(", ") + ` <${param.type}>`;
|
|
1720
|
-
command.option(
|
|
1764
|
+
command.option(
|
|
1765
|
+
flagSignature,
|
|
1766
|
+
param.description || "",
|
|
1767
|
+
param.default
|
|
1768
|
+
);
|
|
1721
1769
|
}
|
|
1722
1770
|
}
|
|
1723
1771
|
});
|
|
@@ -1735,7 +1783,9 @@ function createBundleCodeCommand() {
|
|
|
1735
1783
|
throw new Error("Input file path is required");
|
|
1736
1784
|
}
|
|
1737
1785
|
console.log(chalk6.blue(`\u{1F4E6} Bundling ${rawParams.input}...`));
|
|
1738
|
-
const result = await bundleCode(
|
|
1786
|
+
const result = await bundleCode(
|
|
1787
|
+
rawParams
|
|
1788
|
+
);
|
|
1739
1789
|
if (options.json) {
|
|
1740
1790
|
console.log(JSON.stringify({ result }, null, 2));
|
|
1741
1791
|
} else if (rawParams.output && !rawParams.string) {
|
|
@@ -32,7 +32,7 @@ export function createBundleCodeCommand() {
|
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
34
|
const flagSignature = flags.join(", ") + ` <${param.type}>`;
|
|
35
|
-
command.option(flagSignature, param.description, param.default);
|
|
35
|
+
command.option(flagSignature, param.description || "", param.default);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
});
|
|
@@ -34,7 +34,7 @@ export function createGenerateTypesCommand() {
|
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
36
|
const flagSignature = flags.join(", ") + ` <${param.type}>`;
|
|
37
|
-
command.option(flagSignature, param.description, param.default);
|
|
37
|
+
command.option(flagSignature, param.description || "", param.default);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
});
|
|
@@ -52,14 +52,23 @@ export function createGenerateTypesCommand() {
|
|
|
52
52
|
// Resolve missing parameters interactively using schema metadata
|
|
53
53
|
const resolver = new SchemaParameterResolver();
|
|
54
54
|
const resolvedParams = await resolver.resolveParameters(GenerateTypesSchema, rawParams, sdk);
|
|
55
|
-
|
|
55
|
+
const params = resolvedParams;
|
|
56
|
+
console.log(chalk.blue(`🔧 Generating TypeScript types for ${params.appKey}...`));
|
|
56
57
|
// Call our implementation
|
|
57
|
-
const
|
|
58
|
+
const generateTypesParams = {
|
|
59
|
+
appKey: params.appKey,
|
|
60
|
+
debug: params.debug ?? false,
|
|
61
|
+
authenticationId: params.authenticationId,
|
|
62
|
+
output: params.output,
|
|
63
|
+
sdk,
|
|
64
|
+
};
|
|
65
|
+
const result = await generateTypes(generateTypesParams);
|
|
58
66
|
if (options.json) {
|
|
59
67
|
console.log(JSON.stringify({ result }, null, 2));
|
|
60
68
|
}
|
|
61
69
|
else {
|
|
62
|
-
const output =
|
|
70
|
+
const output = params.output ||
|
|
71
|
+
`./types/${params.appKey}.d.ts`;
|
|
63
72
|
console.log(chalk.green("✅ TypeScript types generated successfully!"));
|
|
64
73
|
console.log(chalk.gray(`Output written to: ${output}`));
|
|
65
74
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export interface ApiResponse<T =
|
|
1
|
+
export interface ApiResponse<T = unknown> {
|
|
2
2
|
data: T;
|
|
3
3
|
status: number;
|
|
4
4
|
}
|
|
5
5
|
export declare const createApiClient: () => {
|
|
6
|
-
post: <T =
|
|
6
|
+
post: <T = unknown>(url: string, data: Record<string, string>, options?: {
|
|
7
7
|
headers?: Record<string, string>;
|
|
8
8
|
}) => Promise<ApiResponse<T>>;
|
|
9
9
|
};
|
|
10
10
|
declare const api: {
|
|
11
|
-
post: <T =
|
|
11
|
+
post: <T = unknown>(url: string, data: Record<string, string>, options?: {
|
|
12
12
|
headers?: Record<string, string>;
|
|
13
13
|
}) => Promise<ApiResponse<T>>;
|
|
14
14
|
};
|
|
@@ -4,10 +4,10 @@ export interface CliParameter {
|
|
|
4
4
|
type: "string" | "number" | "boolean" | "array";
|
|
5
5
|
required: boolean;
|
|
6
6
|
description?: string;
|
|
7
|
-
default?:
|
|
7
|
+
default?: unknown;
|
|
8
8
|
choices?: string[];
|
|
9
9
|
hasResolver?: boolean;
|
|
10
10
|
isPositional?: boolean;
|
|
11
11
|
}
|
|
12
12
|
export declare function analyzeZodSchema(schema: z.ZodSchema): CliParameter[];
|
|
13
|
-
export declare function convertCliArgsToSdkParams(parameters: CliParameter[], positionalArgs:
|
|
13
|
+
export declare function convertCliArgsToSdkParams(parameters: CliParameter[], positionalArgs: unknown[], options: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -13,7 +13,9 @@ function formatJsonOutput(data) {
|
|
|
13
13
|
if (data &&
|
|
14
14
|
typeof data === "object" &&
|
|
15
15
|
!Array.isArray(data) &&
|
|
16
|
-
(data.success !== undefined ||
|
|
16
|
+
(data.success !== undefined ||
|
|
17
|
+
data.id ||
|
|
18
|
+
data.status)) {
|
|
17
19
|
console.log(chalk.green("✅ Action completed successfully!\n"));
|
|
18
20
|
}
|
|
19
21
|
// Use util.inspect for colored output
|
|
@@ -140,28 +142,33 @@ function createCommandConfig(cliCommandName, sdkMethodName, schema, sdk) {
|
|
|
140
142
|
// Resolve missing parameters interactively using schema metadata
|
|
141
143
|
const resolver = new SchemaParameterResolver();
|
|
142
144
|
const resolvedParams = await resolver.resolveParameters(schema, rawParams, sdk);
|
|
143
|
-
// Special handling for commands that write to files
|
|
144
|
-
const hasOutputFile = resolvedParams.output;
|
|
145
|
-
if (hasOutputFile) {
|
|
146
|
-
// Call the SDK method for file output commands
|
|
147
|
-
await sdk[sdkMethodName](resolvedParams);
|
|
148
|
-
console.log(chalk.green(`✅ ${cliCommandName} completed successfully!`));
|
|
149
|
-
console.log(chalk.gray(`Output written to: ${resolvedParams.output}`));
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
145
|
// Handle paginated list commands with async iteration
|
|
153
146
|
if (isListCommand &&
|
|
154
147
|
hasPaginationParams &&
|
|
155
148
|
!shouldUseJson &&
|
|
156
149
|
!hasUserSpecifiedMaxItems) {
|
|
157
150
|
// Get the async iterator directly from the SDK method call
|
|
158
|
-
const
|
|
151
|
+
const sdkObj = sdk;
|
|
152
|
+
const sdkIterator = await sdkObj[sdkMethodName](resolvedParams);
|
|
159
153
|
await handlePaginatedListWithAsyncIteration(sdkMethodName, sdkIterator, schema);
|
|
160
154
|
}
|
|
161
155
|
else {
|
|
156
|
+
// Special handling for commands that write to files
|
|
157
|
+
const hasOutputFile = resolvedParams.output;
|
|
158
|
+
if (hasOutputFile) {
|
|
159
|
+
// Call the SDK method for file output commands
|
|
160
|
+
const sdkObj = sdk;
|
|
161
|
+
await sdkObj[sdkMethodName](resolvedParams);
|
|
162
|
+
console.log(chalk.green(`✅ ${cliCommandName} completed successfully!`));
|
|
163
|
+
console.log(chalk.gray(`Output written to: ${hasOutputFile}`));
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
162
166
|
// Call the SDK method and handle non-paginated results
|
|
163
|
-
const
|
|
164
|
-
const
|
|
167
|
+
const sdkObj = sdk;
|
|
168
|
+
const result = await sdkObj[sdkMethodName](resolvedParams);
|
|
169
|
+
const items = result?.data
|
|
170
|
+
? result.data
|
|
171
|
+
: result;
|
|
165
172
|
if (shouldUseJson) {
|
|
166
173
|
console.log(JSON.stringify(items, null, 2));
|
|
167
174
|
}
|
|
@@ -180,8 +187,9 @@ function createCommandConfig(cliCommandName, sdkMethodName, schema, sdk) {
|
|
|
180
187
|
const validationErrors = JSON.parse(error.message);
|
|
181
188
|
console.error(chalk.red("❌ Validation Error:"));
|
|
182
189
|
validationErrors.forEach((err) => {
|
|
183
|
-
const
|
|
184
|
-
|
|
190
|
+
const errorObj = err;
|
|
191
|
+
const field = errorObj?.path?.join(".") || "unknown";
|
|
192
|
+
console.error(chalk.yellow(` • ${field}: ${errorObj?.message || "Unknown error"}`));
|
|
185
193
|
});
|
|
186
194
|
console.error("\n" + chalk.dim(`Use --help to see available options`));
|
|
187
195
|
}
|
|
@@ -239,7 +247,7 @@ function addCommand(program, commandName, config) {
|
|
|
239
247
|
}
|
|
240
248
|
else {
|
|
241
249
|
const flagSignature = flags.join(", ") + ` <${param.type}>`;
|
|
242
|
-
command.option(flagSignature, param.description, param.default);
|
|
250
|
+
command.option(flagSignature, param.description || "", param.default);
|
|
243
251
|
}
|
|
244
252
|
}
|
|
245
253
|
});
|
|
@@ -415,10 +423,11 @@ function formatNonPaginatedResults(result, requestedMaxItems, userSpecifiedMaxIt
|
|
|
415
423
|
function formatItemsGeneric(items) {
|
|
416
424
|
// Fallback formatting for items without schema metadata
|
|
417
425
|
items.forEach((item, index) => {
|
|
418
|
-
const
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
426
|
+
const itemObj = item;
|
|
427
|
+
const name = itemObj?.name || itemObj?.key || itemObj?.id || "Item";
|
|
428
|
+
console.log(`${chalk.gray(`${index + 1}.`)} ${chalk.cyan(String(name))}`);
|
|
429
|
+
if (itemObj?.description) {
|
|
430
|
+
console.log(` ${chalk.dim(String(itemObj.description))}`);
|
|
422
431
|
}
|
|
423
432
|
console.log();
|
|
424
433
|
});
|
package/dist/src/utils/log.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare const log: {
|
|
2
|
-
info: (message: string, ...args:
|
|
3
|
-
error: (message: string, ...args:
|
|
4
|
-
success: (message: string, ...args:
|
|
5
|
-
warn: (message: string, ...args:
|
|
2
|
+
info: (message: string, ...args: unknown[]) => void;
|
|
3
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
4
|
+
success: (message: string, ...args: unknown[]) => void;
|
|
5
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
6
6
|
};
|
|
7
7
|
export default log;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { ZapierSdk } from "@zapier/zapier-sdk";
|
|
3
3
|
export declare class SchemaParameterResolver {
|
|
4
|
-
resolveParameters(schema: z.ZodSchema, providedParams:
|
|
4
|
+
resolveParameters(schema: z.ZodSchema, providedParams: unknown, sdk: ZapierSdk): Promise<unknown>;
|
|
5
5
|
private extractParametersFromSchema;
|
|
6
6
|
private analyzeFieldSchema;
|
|
7
7
|
private createResolvableParameter;
|
|
@@ -55,7 +55,7 @@ export class SchemaParameterResolver {
|
|
|
55
55
|
}
|
|
56
56
|
return parseResult.data;
|
|
57
57
|
}
|
|
58
|
-
// 2. Resolve functionally required parameters
|
|
58
|
+
// 2. Resolve functionally required parameters first
|
|
59
59
|
const resolvedParams = { ...providedParams };
|
|
60
60
|
const context = {
|
|
61
61
|
sdk,
|
|
@@ -274,7 +274,8 @@ export class SchemaParameterResolver {
|
|
|
274
274
|
break;
|
|
275
275
|
}
|
|
276
276
|
// Find new fields that we haven't processed yet
|
|
277
|
-
const newFields = fields.filter((field) => !
|
|
277
|
+
const newFields = fields.filter((field) => !(field.key &&
|
|
278
|
+
processedFieldKeys.has(field.key)));
|
|
278
279
|
if (newFields.length === 0) {
|
|
279
280
|
// No new fields, we're done
|
|
280
281
|
break;
|
|
@@ -340,35 +341,44 @@ export class SchemaParameterResolver {
|
|
|
340
341
|
setNestedValue(obj, path, value) {
|
|
341
342
|
const lastKey = path[path.length - 1];
|
|
342
343
|
const parent = path.slice(0, -1).reduce((current, key) => {
|
|
343
|
-
|
|
344
|
-
|
|
344
|
+
const currentObj = current;
|
|
345
|
+
if (!(key in currentObj)) {
|
|
346
|
+
currentObj[key] = {};
|
|
345
347
|
}
|
|
346
|
-
return
|
|
348
|
+
return currentObj[key];
|
|
347
349
|
}, obj);
|
|
348
350
|
parent[lastKey] = value;
|
|
349
351
|
}
|
|
350
352
|
async promptForField(field, inputs) {
|
|
353
|
+
const fieldObj = field;
|
|
351
354
|
const fieldPrompt = {
|
|
352
|
-
type:
|
|
353
|
-
name:
|
|
354
|
-
message: `${
|
|
355
|
-
...(field.helpText && { prefix: chalk.gray(`ℹ ${field.helpText}\n`) }),
|
|
356
|
-
...(field.default && { default: field.default }),
|
|
355
|
+
type: fieldObj.type === "boolean" ? "confirm" : "input",
|
|
356
|
+
name: fieldObj.key,
|
|
357
|
+
message: `${fieldObj.label || fieldObj.key}${fieldObj.required ? " (required)" : " (optional)"}:`,
|
|
357
358
|
};
|
|
358
|
-
if (
|
|
359
|
+
if (fieldObj.helpText) {
|
|
360
|
+
fieldPrompt.prefix = chalk.gray(`ℹ ${fieldObj.helpText}\n`);
|
|
361
|
+
}
|
|
362
|
+
if (fieldObj.default !== undefined) {
|
|
363
|
+
fieldPrompt.default = fieldObj.default;
|
|
364
|
+
}
|
|
365
|
+
if (fieldObj.choices && fieldObj.choices.length > 0) {
|
|
359
366
|
fieldPrompt.type = "list";
|
|
360
|
-
fieldPrompt.choices =
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
367
|
+
fieldPrompt.choices = fieldObj.choices.map((choice) => {
|
|
368
|
+
const choiceObj = choice;
|
|
369
|
+
return {
|
|
370
|
+
name: choiceObj.label || choiceObj.value,
|
|
371
|
+
value: choiceObj.value,
|
|
372
|
+
};
|
|
373
|
+
});
|
|
364
374
|
}
|
|
365
375
|
try {
|
|
366
376
|
const answer = await inquirer.prompt([fieldPrompt]);
|
|
367
|
-
if (answer[
|
|
368
|
-
inputs[
|
|
377
|
+
if (answer[fieldObj.key] !== undefined && answer[fieldObj.key] !== "") {
|
|
378
|
+
inputs[fieldObj.key] = answer[fieldObj.key];
|
|
369
379
|
}
|
|
370
|
-
else if (
|
|
371
|
-
throw new Error(`Required field ${
|
|
380
|
+
else if (fieldObj.required) {
|
|
381
|
+
throw new Error(`Required field ${fieldObj.key} cannot be empty`);
|
|
372
382
|
}
|
|
373
383
|
}
|
|
374
384
|
catch (error) {
|
|
@@ -380,8 +390,9 @@ export class SchemaParameterResolver {
|
|
|
380
390
|
}
|
|
381
391
|
}
|
|
382
392
|
isUserCancellation(error) {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
393
|
+
const errorObj = error;
|
|
394
|
+
return (errorObj?.name === "ExitPromptError" ||
|
|
395
|
+
errorObj?.message?.includes("User force closed") ||
|
|
396
|
+
errorObj?.isTTYError === true);
|
|
386
397
|
}
|
|
387
398
|
}
|