@zapier/zapier-sdk-cli 0.9.0 → 0.10.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 +20 -0
- package/dist/cli.cjs +213 -100
- package/dist/cli.mjs +214 -101
- 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 +4 -1
- package/dist/src/utils/parameter-resolver.js +92 -15
- 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 +155 -21
- package/src/utils/schema-formatter.ts +68 -33
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @zapier/zapier-sdk-cli
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3184903: No more global resolver registry, each plugin function has its own resolvers. Plugin function meta also stores output schema and some function type info to avoid some special case code for handling lists, documenting functions, etc. findFirstAuthentication throws an error to make all item functions consistent. Various other schema and output cleanup.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [3184903]
|
|
12
|
+
- @zapier/zapier-sdk@0.10.0
|
|
13
|
+
- @zapier/zapier-sdk-mcp@0.3.7
|
|
14
|
+
|
|
15
|
+
## 0.9.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [3cfed98]
|
|
20
|
+
- @zapier/zapier-sdk@0.9.1
|
|
21
|
+
- @zapier/zapier-sdk-mcp@0.3.6
|
|
22
|
+
|
|
3
23
|
## 0.9.0
|
|
4
24
|
|
|
5
25
|
### Minor Changes
|
package/dist/cli.cjs
CHANGED
|
@@ -52,12 +52,45 @@ var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
|
52
52
|
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
53
53
|
var ts__namespace = /*#__PURE__*/_interopNamespace(ts);
|
|
54
54
|
|
|
55
|
+
function getLocalResolutionOrder(paramName, resolvers, resolved = /* @__PURE__ */ new Set()) {
|
|
56
|
+
const resolver = resolvers[paramName];
|
|
57
|
+
if (!resolver || resolver.type === "static") {
|
|
58
|
+
return [paramName];
|
|
59
|
+
}
|
|
60
|
+
const order = [];
|
|
61
|
+
if ("depends" in resolver && resolver.depends) {
|
|
62
|
+
for (const dependency of resolver.depends) {
|
|
63
|
+
if (!resolved.has(dependency)) {
|
|
64
|
+
order.push(...getLocalResolutionOrder(dependency, resolvers, resolved));
|
|
65
|
+
resolved.add(dependency);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (!resolved.has(paramName)) {
|
|
70
|
+
order.push(paramName);
|
|
71
|
+
resolved.add(paramName);
|
|
72
|
+
}
|
|
73
|
+
return order;
|
|
74
|
+
}
|
|
75
|
+
function getLocalResolutionOrderForParams(paramNames, resolvers) {
|
|
76
|
+
const resolved = /* @__PURE__ */ new Set();
|
|
77
|
+
const order = [];
|
|
78
|
+
for (const paramName of paramNames) {
|
|
79
|
+
const paramOrder = getLocalResolutionOrder(paramName, resolvers, resolved);
|
|
80
|
+
for (const param of paramOrder) {
|
|
81
|
+
if (!order.includes(param)) {
|
|
82
|
+
order.push(param);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return order;
|
|
87
|
+
}
|
|
55
88
|
var SchemaParameterResolver = class {
|
|
56
|
-
async resolveParameters(schema, providedParams, sdk2) {
|
|
89
|
+
async resolveParameters(schema, providedParams, sdk2, functionName) {
|
|
57
90
|
const parseResult = schema.safeParse(providedParams);
|
|
58
91
|
const allParams = this.extractParametersFromSchema(schema);
|
|
59
92
|
const resolvableParams = allParams.filter(
|
|
60
|
-
(param) =>
|
|
93
|
+
(param) => this.hasResolver(param.name, sdk2, functionName)
|
|
61
94
|
);
|
|
62
95
|
const missingResolvable = resolvableParams.filter((param) => {
|
|
63
96
|
const hasValue = this.getNestedValue(providedParams, param.path) !== void 0;
|
|
@@ -93,11 +126,16 @@ var SchemaParameterResolver = class {
|
|
|
93
126
|
const context = {
|
|
94
127
|
sdk: sdk2,
|
|
95
128
|
currentParams: providedParams,
|
|
96
|
-
resolvedParams
|
|
129
|
+
resolvedParams,
|
|
130
|
+
functionName
|
|
97
131
|
};
|
|
132
|
+
const localResolvers = this.getLocalResolvers(sdk2, functionName);
|
|
98
133
|
if (functionallyRequired.length > 0) {
|
|
99
134
|
const requiredParamNames = functionallyRequired.map((p) => p.name);
|
|
100
|
-
const requiredResolutionOrder =
|
|
135
|
+
const requiredResolutionOrder = getLocalResolutionOrderForParams(
|
|
136
|
+
requiredParamNames,
|
|
137
|
+
localResolvers
|
|
138
|
+
);
|
|
101
139
|
const orderedRequiredParams = requiredResolutionOrder.map((paramName) => {
|
|
102
140
|
let param = functionallyRequired.find((p) => p.name === paramName);
|
|
103
141
|
if (!param) {
|
|
@@ -110,7 +148,11 @@ var SchemaParameterResolver = class {
|
|
|
110
148
|
}).filter((param) => param !== void 0);
|
|
111
149
|
for (const param of orderedRequiredParams) {
|
|
112
150
|
try {
|
|
113
|
-
const value = await this.resolveParameter(
|
|
151
|
+
const value = await this.resolveParameter(
|
|
152
|
+
param,
|
|
153
|
+
context,
|
|
154
|
+
functionName
|
|
155
|
+
);
|
|
114
156
|
this.setNestedValue(resolvedParams, param.path, value);
|
|
115
157
|
context.resolvedParams = resolvedParams;
|
|
116
158
|
} catch (error) {
|
|
@@ -137,11 +179,18 @@ var SchemaParameterResolver = class {
|
|
|
137
179
|
}
|
|
138
180
|
if (alwaysPrompt.length > 0) {
|
|
139
181
|
const alwaysPromptNames = alwaysPrompt.map((p) => p.name);
|
|
140
|
-
const alwaysPromptResolutionOrder =
|
|
182
|
+
const alwaysPromptResolutionOrder = getLocalResolutionOrderForParams(
|
|
183
|
+
alwaysPromptNames,
|
|
184
|
+
localResolvers
|
|
185
|
+
);
|
|
141
186
|
const orderedAlwaysPromptParams = alwaysPromptResolutionOrder.map((paramName) => alwaysPrompt.find((p) => p.name === paramName)).filter((param) => param !== void 0);
|
|
142
187
|
for (const param of orderedAlwaysPromptParams) {
|
|
143
188
|
try {
|
|
144
|
-
const value = await this.resolveParameter(
|
|
189
|
+
const value = await this.resolveParameter(
|
|
190
|
+
param,
|
|
191
|
+
context,
|
|
192
|
+
functionName
|
|
193
|
+
);
|
|
145
194
|
this.setNestedValue(resolvedParams, param.path, value);
|
|
146
195
|
context.resolvedParams = resolvedParams;
|
|
147
196
|
} catch (error) {
|
|
@@ -165,11 +214,18 @@ var SchemaParameterResolver = class {
|
|
|
165
214
|
]);
|
|
166
215
|
if (shouldResolveOptional.resolveOptional) {
|
|
167
216
|
const optionalParamNames = trulyOptional.map((p) => p.name);
|
|
168
|
-
const optionalResolutionOrder =
|
|
217
|
+
const optionalResolutionOrder = getLocalResolutionOrderForParams(
|
|
218
|
+
optionalParamNames,
|
|
219
|
+
localResolvers
|
|
220
|
+
);
|
|
169
221
|
const orderedOptionalParams = optionalResolutionOrder.map((paramName) => trulyOptional.find((p) => p.name === paramName)).filter((param) => param !== void 0);
|
|
170
222
|
for (const param of orderedOptionalParams) {
|
|
171
223
|
try {
|
|
172
|
-
const value = await this.resolveParameter(
|
|
224
|
+
const value = await this.resolveParameter(
|
|
225
|
+
param,
|
|
226
|
+
context,
|
|
227
|
+
functionName
|
|
228
|
+
);
|
|
173
229
|
this.setNestedValue(resolvedParams, param.path, value);
|
|
174
230
|
context.resolvedParams = resolvedParams;
|
|
175
231
|
} catch (error) {
|
|
@@ -228,8 +284,8 @@ var SchemaParameterResolver = class {
|
|
|
228
284
|
isRequired
|
|
229
285
|
};
|
|
230
286
|
}
|
|
231
|
-
async resolveParameter(param, context) {
|
|
232
|
-
const resolver =
|
|
287
|
+
async resolveParameter(param, context, functionName) {
|
|
288
|
+
const resolver = this.getResolver(param.name, context.sdk, functionName);
|
|
233
289
|
if (!resolver) {
|
|
234
290
|
throw new Error(`No resolver found for parameter: ${param.name}`);
|
|
235
291
|
}
|
|
@@ -314,10 +370,10 @@ var SchemaParameterResolver = class {
|
|
|
314
370
|
break;
|
|
315
371
|
}
|
|
316
372
|
const newRequiredFields = newFields.filter(
|
|
317
|
-
(field) => field.
|
|
373
|
+
(field) => field.is_required
|
|
318
374
|
);
|
|
319
375
|
const newOptionalFields = newFields.filter(
|
|
320
|
-
(field) => !field.
|
|
376
|
+
(field) => !field.is_required
|
|
321
377
|
);
|
|
322
378
|
if (newRequiredFields.length > 0) {
|
|
323
379
|
console.log(
|
|
@@ -404,7 +460,7 @@ Optional fields:`));
|
|
|
404
460
|
const fieldPrompt = {
|
|
405
461
|
type: fieldObj.type === "boolean" ? "confirm" : "input",
|
|
406
462
|
name: fieldObj.key,
|
|
407
|
-
message: `${fieldObj.label || fieldObj.key}${fieldObj.
|
|
463
|
+
message: `${fieldObj.label || fieldObj.key}${fieldObj.is_required ? " (required)" : " (optional)"}:`
|
|
408
464
|
};
|
|
409
465
|
if (fieldObj.helpText) {
|
|
410
466
|
fieldPrompt.prefix = chalk3__default.default.gray(`\u2139 ${fieldObj.helpText}
|
|
@@ -429,7 +485,7 @@ Optional fields:`));
|
|
|
429
485
|
const answer = await inquirer__default.default.prompt([fieldPrompt]);
|
|
430
486
|
if (answer[fieldObj.key] !== void 0 && answer[fieldObj.key] !== "") {
|
|
431
487
|
inputs[fieldObj.key] = answer[fieldObj.key];
|
|
432
|
-
} else if (fieldObj.
|
|
488
|
+
} else if (fieldObj.is_required) {
|
|
433
489
|
throw new Error(`Required field ${fieldObj.key} cannot be empty`);
|
|
434
490
|
}
|
|
435
491
|
} catch (error) {
|
|
@@ -444,6 +500,40 @@ Optional fields:`));
|
|
|
444
500
|
const errorObj = error;
|
|
445
501
|
return errorObj?.name === "ExitPromptError" || errorObj?.message?.includes("User force closed") || errorObj?.isTTYError === true;
|
|
446
502
|
}
|
|
503
|
+
hasResolver(paramName, sdk2, functionName) {
|
|
504
|
+
if (functionName && typeof sdk2.getRegistry === "function") {
|
|
505
|
+
const registry = sdk2.getRegistry();
|
|
506
|
+
const functionInfo = registry.functions.find(
|
|
507
|
+
(f) => f.name === functionName
|
|
508
|
+
);
|
|
509
|
+
if (functionInfo && functionInfo.resolvers?.[paramName]) {
|
|
510
|
+
return true;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
return false;
|
|
514
|
+
}
|
|
515
|
+
getResolver(paramName, sdk2, functionName) {
|
|
516
|
+
if (functionName && typeof sdk2.getRegistry === "function") {
|
|
517
|
+
const registry = sdk2.getRegistry();
|
|
518
|
+
const functionInfo = registry.functions.find(
|
|
519
|
+
(f) => f.name === functionName
|
|
520
|
+
);
|
|
521
|
+
if (functionInfo && functionInfo.resolvers?.[paramName]) {
|
|
522
|
+
return functionInfo.resolvers[paramName];
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return null;
|
|
526
|
+
}
|
|
527
|
+
getLocalResolvers(sdk2, functionName) {
|
|
528
|
+
if (!functionName || typeof sdk2.getRegistry !== "function") {
|
|
529
|
+
return {};
|
|
530
|
+
}
|
|
531
|
+
const registry = sdk2.getRegistry();
|
|
532
|
+
const functionInfo = registry.functions.find(
|
|
533
|
+
(f) => f.name === functionName
|
|
534
|
+
);
|
|
535
|
+
return functionInfo?.resolvers || {};
|
|
536
|
+
}
|
|
447
537
|
};
|
|
448
538
|
function getFormatMetadata(schema) {
|
|
449
539
|
return schema?._def?.formatMeta;
|
|
@@ -451,8 +541,16 @@ function getFormatMetadata(schema) {
|
|
|
451
541
|
function getOutputSchema(schema) {
|
|
452
542
|
return schema?._def?.outputSchema;
|
|
453
543
|
}
|
|
454
|
-
function
|
|
455
|
-
|
|
544
|
+
function formatJsonOutput(data) {
|
|
545
|
+
if (data === void 0) {
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
console.log(
|
|
549
|
+
util__default.default.inspect(data, { colors: true, depth: null, breakLength: 80 })
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
function formatItemsFromSchema(functionInfo, items, startingNumber = 0) {
|
|
553
|
+
const outputSchema = functionInfo.outputSchema || getOutputSchema(functionInfo.inputSchema);
|
|
456
554
|
if (!outputSchema) {
|
|
457
555
|
formatItemsGeneric(items, startingNumber);
|
|
458
556
|
return;
|
|
@@ -463,16 +561,26 @@ function formatItemsFromSchema(inputSchema, items, startingNumber = 0) {
|
|
|
463
561
|
return;
|
|
464
562
|
}
|
|
465
563
|
items.forEach((item, index) => {
|
|
466
|
-
|
|
564
|
+
const formatted = formatMeta.format(item);
|
|
565
|
+
formatSingleItem(formatted, startingNumber + index);
|
|
467
566
|
});
|
|
468
567
|
}
|
|
469
|
-
function formatSingleItem(
|
|
470
|
-
const formatted = formatMeta.format(item);
|
|
568
|
+
function formatSingleItem(formatted, itemNumber) {
|
|
471
569
|
let titleLine = `${chalk3__default.default.gray(`${itemNumber + 1}.`)} ${chalk3__default.default.cyan(formatted.title)}`;
|
|
472
|
-
if (formatted.
|
|
473
|
-
titleLine += ` ${chalk3__default.default.gray(formatted.
|
|
570
|
+
if (formatted.id) {
|
|
571
|
+
titleLine += ` ${chalk3__default.default.gray(`(ID: ${formatted.id})`)}`;
|
|
572
|
+
} else if (formatted.key) {
|
|
573
|
+
titleLine += ` ${chalk3__default.default.gray(`(${formatted.key})`)}`;
|
|
474
574
|
}
|
|
475
575
|
console.log(titleLine);
|
|
576
|
+
if (formatted.description) {
|
|
577
|
+
console.log(` ${chalk3__default.default.dim(formatted.description)}`);
|
|
578
|
+
}
|
|
579
|
+
if (formatted.data !== void 0) {
|
|
580
|
+
formatJsonOutput(formatted.data);
|
|
581
|
+
console.log();
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
476
584
|
for (const detail of formatted.details) {
|
|
477
585
|
const styledText = applyStyle(detail.text, detail.style);
|
|
478
586
|
console.log(` ${styledText}`);
|
|
@@ -494,40 +602,36 @@ function applyStyle(value, style) {
|
|
|
494
602
|
return chalk3__default.default.blue(value);
|
|
495
603
|
}
|
|
496
604
|
}
|
|
605
|
+
function convertGenericItemToFormattedItem(item) {
|
|
606
|
+
const itemObj = item;
|
|
607
|
+
return {
|
|
608
|
+
title: itemObj.title || itemObj.name || itemObj.key || itemObj.id || "Item",
|
|
609
|
+
id: itemObj.id,
|
|
610
|
+
key: itemObj.key,
|
|
611
|
+
description: itemObj.description,
|
|
612
|
+
details: []
|
|
613
|
+
};
|
|
614
|
+
}
|
|
497
615
|
function formatItemsGeneric(items, startingNumber = 0) {
|
|
498
616
|
items.forEach((item, index) => {
|
|
499
|
-
const
|
|
500
|
-
|
|
501
|
-
console.log(
|
|
502
|
-
`${chalk3__default.default.gray(`${startingNumber + index + 1}.`)} ${chalk3__default.default.cyan(name)}`
|
|
503
|
-
);
|
|
504
|
-
if (itemObj.description) {
|
|
505
|
-
console.log(` ${chalk3__default.default.dim(itemObj.description)}`);
|
|
506
|
-
}
|
|
507
|
-
console.log();
|
|
617
|
+
const formatted = convertGenericItemToFormattedItem(item);
|
|
618
|
+
formatSingleItem(formatted, startingNumber + index);
|
|
508
619
|
});
|
|
509
620
|
}
|
|
510
|
-
function
|
|
511
|
-
if (data === void 0) {
|
|
512
|
-
return;
|
|
513
|
-
}
|
|
514
|
-
if (data && typeof data === "object" && !Array.isArray(data) && (data.success !== void 0 || data.id || data.status)) {
|
|
515
|
-
console.log(chalk3__default.default.green("\u2705 Action completed successfully!\n"));
|
|
516
|
-
}
|
|
517
|
-
console.log(
|
|
518
|
-
util__default.default.inspect(data, { colors: true, depth: null, breakLength: 80 })
|
|
519
|
-
);
|
|
520
|
-
}
|
|
521
|
-
function analyzeZodSchema(schema) {
|
|
621
|
+
function analyzeZodSchema(schema, functionInfo) {
|
|
522
622
|
const parameters = [];
|
|
523
623
|
if (schema._def && schema._def.typeName === "ZodEffects") {
|
|
524
624
|
const innerSchema = schema._def.schema;
|
|
525
|
-
return analyzeZodSchema(innerSchema);
|
|
625
|
+
return analyzeZodSchema(innerSchema, functionInfo);
|
|
526
626
|
}
|
|
527
627
|
if (schema instanceof zod.z.ZodObject) {
|
|
528
628
|
const shape = schema.shape;
|
|
529
629
|
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
530
|
-
const param = analyzeZodField(
|
|
630
|
+
const param = analyzeZodField(
|
|
631
|
+
key,
|
|
632
|
+
fieldSchema,
|
|
633
|
+
functionInfo
|
|
634
|
+
);
|
|
531
635
|
if (param) {
|
|
532
636
|
parameters.push(param);
|
|
533
637
|
}
|
|
@@ -535,7 +639,7 @@ function analyzeZodSchema(schema) {
|
|
|
535
639
|
}
|
|
536
640
|
return parameters;
|
|
537
641
|
}
|
|
538
|
-
function analyzeZodField(name, schema) {
|
|
642
|
+
function analyzeZodField(name, schema, functionInfo) {
|
|
539
643
|
let baseSchema = schema;
|
|
540
644
|
let required = true;
|
|
541
645
|
let defaultValue = void 0;
|
|
@@ -569,6 +673,10 @@ function analyzeZodField(name, schema) {
|
|
|
569
673
|
} else if (baseSchema instanceof zod.z.ZodRecord) {
|
|
570
674
|
paramType = "string";
|
|
571
675
|
}
|
|
676
|
+
let paramHasResolver = false;
|
|
677
|
+
if (functionInfo?.resolvers?.[name]) {
|
|
678
|
+
paramHasResolver = true;
|
|
679
|
+
}
|
|
572
680
|
return {
|
|
573
681
|
name,
|
|
574
682
|
type: paramType,
|
|
@@ -576,7 +684,7 @@ function analyzeZodField(name, schema) {
|
|
|
576
684
|
description: schema.description,
|
|
577
685
|
default: defaultValue,
|
|
578
686
|
choices,
|
|
579
|
-
hasResolver:
|
|
687
|
+
hasResolver: paramHasResolver,
|
|
580
688
|
isPositional: zapierSdk.isPositional(schema)
|
|
581
689
|
};
|
|
582
690
|
}
|
|
@@ -598,12 +706,7 @@ function generateCliCommands(program2, sdk2) {
|
|
|
598
706
|
return;
|
|
599
707
|
}
|
|
600
708
|
const cliCommandName = methodNameToCliCommand(fnInfo.name);
|
|
601
|
-
const config = createCommandConfig(
|
|
602
|
-
cliCommandName,
|
|
603
|
-
fnInfo.name,
|
|
604
|
-
fnInfo.inputSchema,
|
|
605
|
-
sdk2
|
|
606
|
-
);
|
|
709
|
+
const config = createCommandConfig(cliCommandName, fnInfo, sdk2);
|
|
607
710
|
addCommand(program2, cliCommandName, config);
|
|
608
711
|
});
|
|
609
712
|
program2.configureHelp({
|
|
@@ -667,14 +770,15 @@ function generateCliCommands(program2, sdk2) {
|
|
|
667
770
|
}
|
|
668
771
|
});
|
|
669
772
|
}
|
|
670
|
-
function createCommandConfig(cliCommandName,
|
|
671
|
-
const
|
|
773
|
+
function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
774
|
+
const schema = functionInfo.inputSchema;
|
|
775
|
+
const parameters = analyzeZodSchema(schema, functionInfo);
|
|
672
776
|
const description = schema.description || `${cliCommandName} command`;
|
|
673
777
|
const handler = async (...args) => {
|
|
674
778
|
try {
|
|
675
779
|
const commandObj = args[args.length - 1];
|
|
676
780
|
const options = commandObj.opts();
|
|
677
|
-
const isListCommand =
|
|
781
|
+
const isListCommand = functionInfo.type === "list";
|
|
678
782
|
const hasPaginationParams = parameters.some(
|
|
679
783
|
(p) => p.name === "maxItems" || p.name === "pageSize"
|
|
680
784
|
);
|
|
@@ -689,21 +793,22 @@ function createCommandConfig(cliCommandName, sdkMethodName, schema, sdk2) {
|
|
|
689
793
|
const resolvedParams = await resolver.resolveParameters(
|
|
690
794
|
schema,
|
|
691
795
|
rawParams,
|
|
692
|
-
sdk2
|
|
796
|
+
sdk2,
|
|
797
|
+
functionInfo.name
|
|
693
798
|
);
|
|
694
799
|
if (isListCommand && hasPaginationParams && !shouldUseJson && !hasUserSpecifiedMaxItems) {
|
|
695
800
|
const sdkObj = sdk2;
|
|
696
|
-
const sdkIterator = sdkObj[
|
|
801
|
+
const sdkIterator = sdkObj[functionInfo.name](resolvedParams);
|
|
697
802
|
await handlePaginatedListWithAsyncIteration(
|
|
698
|
-
|
|
803
|
+
functionInfo.name,
|
|
699
804
|
sdkIterator,
|
|
700
|
-
|
|
805
|
+
functionInfo
|
|
701
806
|
);
|
|
702
807
|
} else {
|
|
703
808
|
const hasOutputFile = resolvedParams.output;
|
|
704
809
|
if (hasOutputFile) {
|
|
705
810
|
const sdkObj2 = sdk2;
|
|
706
|
-
await sdkObj2[
|
|
811
|
+
await sdkObj2[functionInfo.name](resolvedParams);
|
|
707
812
|
console.log(
|
|
708
813
|
chalk3__default.default.green(`\u2705 ${cliCommandName} completed successfully!`)
|
|
709
814
|
);
|
|
@@ -711,7 +816,7 @@ function createCommandConfig(cliCommandName, sdkMethodName, schema, sdk2) {
|
|
|
711
816
|
return;
|
|
712
817
|
}
|
|
713
818
|
const sdkObj = sdk2;
|
|
714
|
-
const result = await sdkObj[
|
|
819
|
+
const result = await sdkObj[functionInfo.name](resolvedParams);
|
|
715
820
|
const items = result?.data ? result.data : result;
|
|
716
821
|
if (shouldUseJson) {
|
|
717
822
|
console.log(JSON.stringify(items, null, 2));
|
|
@@ -721,8 +826,7 @@ function createCommandConfig(cliCommandName, sdkMethodName, schema, sdk2) {
|
|
|
721
826
|
resolvedParams.maxItems,
|
|
722
827
|
hasUserSpecifiedMaxItems,
|
|
723
828
|
shouldUseJson,
|
|
724
|
-
|
|
725
|
-
sdkMethodName
|
|
829
|
+
functionInfo
|
|
726
830
|
);
|
|
727
831
|
} else {
|
|
728
832
|
formatJsonOutput(items);
|
|
@@ -843,6 +947,9 @@ function convertCliArgsToSdkParams(parameters, positionalArgs, options) {
|
|
|
843
947
|
return sdkParams;
|
|
844
948
|
}
|
|
845
949
|
function convertValue(value, type) {
|
|
950
|
+
if (value === void 0) {
|
|
951
|
+
return void 0;
|
|
952
|
+
}
|
|
846
953
|
switch (type) {
|
|
847
954
|
case "number":
|
|
848
955
|
return Number(value);
|
|
@@ -862,12 +969,14 @@ function convertValue(value, type) {
|
|
|
862
969
|
return value;
|
|
863
970
|
}
|
|
864
971
|
}
|
|
865
|
-
async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult,
|
|
866
|
-
const itemName = getItemNameFromMethod(
|
|
972
|
+
async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, functionInfo) {
|
|
973
|
+
const itemName = getItemNameFromMethod(functionInfo);
|
|
867
974
|
let totalShown = 0;
|
|
868
975
|
let pageCount = 0;
|
|
869
|
-
console.log(
|
|
870
|
-
|
|
976
|
+
console.log(
|
|
977
|
+
chalk3__default.default.blue(`\u{1F4CB} ${getListTitleFromMethod(sdkMethodName, functionInfo)}
|
|
978
|
+
`)
|
|
979
|
+
);
|
|
871
980
|
try {
|
|
872
981
|
for await (const page of sdkResult) {
|
|
873
982
|
const items = page.data || page;
|
|
@@ -886,12 +995,14 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, s
|
|
|
886
995
|
if (pageCount > 1) {
|
|
887
996
|
console.clear();
|
|
888
997
|
console.log(
|
|
889
|
-
chalk3__default.default.blue(
|
|
890
|
-
|
|
998
|
+
chalk3__default.default.blue(
|
|
999
|
+
`\u{1F4CB} ${getListTitleFromMethod(sdkMethodName, functionInfo)}
|
|
1000
|
+
`
|
|
1001
|
+
)
|
|
891
1002
|
);
|
|
892
1003
|
}
|
|
893
|
-
if (
|
|
894
|
-
formatItemsFromSchema(
|
|
1004
|
+
if (functionInfo) {
|
|
1005
|
+
formatItemsFromSchema(functionInfo, items, totalShown);
|
|
895
1006
|
} else {
|
|
896
1007
|
formatItemsGeneric2(items, totalShown);
|
|
897
1008
|
}
|
|
@@ -927,8 +1038,8 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, s
|
|
|
927
1038
|
console.log(chalk3__default.default.yellow(`No ${itemName} found.`));
|
|
928
1039
|
return;
|
|
929
1040
|
}
|
|
930
|
-
if (
|
|
931
|
-
formatItemsFromSchema(
|
|
1041
|
+
if (functionInfo) {
|
|
1042
|
+
formatItemsFromSchema(functionInfo, items, 0);
|
|
932
1043
|
} else {
|
|
933
1044
|
formatItemsGeneric2(items, 0);
|
|
934
1045
|
}
|
|
@@ -939,7 +1050,7 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, s
|
|
|
939
1050
|
}
|
|
940
1051
|
}
|
|
941
1052
|
}
|
|
942
|
-
function formatNonPaginatedResults(result, requestedMaxItems, userSpecifiedMaxItems, useRawJson,
|
|
1053
|
+
function formatNonPaginatedResults(result, requestedMaxItems, userSpecifiedMaxItems, useRawJson, functionInfo) {
|
|
943
1054
|
if (!Array.isArray(result)) {
|
|
944
1055
|
if (useRawJson) {
|
|
945
1056
|
console.log(JSON.stringify(result, null, 2));
|
|
@@ -952,7 +1063,7 @@ function formatNonPaginatedResults(result, requestedMaxItems, userSpecifiedMaxIt
|
|
|
952
1063
|
console.log(JSON.stringify(result, null, 2));
|
|
953
1064
|
return;
|
|
954
1065
|
}
|
|
955
|
-
const itemName =
|
|
1066
|
+
const itemName = functionInfo ? getItemNameFromMethod(functionInfo) : "items";
|
|
956
1067
|
if (result.length === 0) {
|
|
957
1068
|
console.log(chalk3__default.default.yellow(`No ${itemName} found.`));
|
|
958
1069
|
return;
|
|
@@ -960,8 +1071,8 @@ function formatNonPaginatedResults(result, requestedMaxItems, userSpecifiedMaxIt
|
|
|
960
1071
|
console.log(chalk3__default.default.green(`
|
|
961
1072
|
\u2705 Found ${result.length} ${itemName}:
|
|
962
1073
|
`));
|
|
963
|
-
if (
|
|
964
|
-
formatItemsFromSchema(
|
|
1074
|
+
if (functionInfo) {
|
|
1075
|
+
formatItemsFromSchema(functionInfo, result);
|
|
965
1076
|
} else {
|
|
966
1077
|
formatItemsGeneric2(result);
|
|
967
1078
|
}
|
|
@@ -990,18 +1101,17 @@ function formatItemsGeneric2(items, startingNumber = 0) {
|
|
|
990
1101
|
console.log();
|
|
991
1102
|
});
|
|
992
1103
|
}
|
|
993
|
-
function getItemNameFromMethod(
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
return listMatch[1].toLowerCase();
|
|
1104
|
+
function getItemNameFromMethod(functionInfo) {
|
|
1105
|
+
if (functionInfo.itemType) {
|
|
1106
|
+
return `${functionInfo.itemType} items`;
|
|
997
1107
|
}
|
|
998
1108
|
return "items";
|
|
999
1109
|
}
|
|
1000
|
-
function getListTitleFromMethod(methodName) {
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
return
|
|
1110
|
+
function getListTitleFromMethod(methodName, functionInfo) {
|
|
1111
|
+
if (functionInfo.itemType) {
|
|
1112
|
+
return `Available ${functionInfo.itemType} items`;
|
|
1113
|
+
}
|
|
1114
|
+
return `${methodName} items`;
|
|
1005
1115
|
}
|
|
1006
1116
|
|
|
1007
1117
|
// src/utils/constants.ts
|
|
@@ -2031,26 +2141,25 @@ var addPlugin = ({ sdk: sdk2, context }) => {
|
|
|
2031
2141
|
console.log(`\u{1F510} Found ${authentications.length} authentication(s)`);
|
|
2032
2142
|
}
|
|
2033
2143
|
for (const app of apps) {
|
|
2034
|
-
|
|
2144
|
+
const appSlugAndKey = app.slug ? `${app.slug} (${app.key})` : app.key;
|
|
2145
|
+
console.log(`\u{1F4E6} Adding ${appSlugAndKey}...`);
|
|
2035
2146
|
try {
|
|
2036
|
-
|
|
2037
|
-
const [implementationName, version] = currentImplementationId.split("@");
|
|
2038
|
-
if (!implementationName || !version) {
|
|
2147
|
+
if (!app.version) {
|
|
2039
2148
|
console.warn(
|
|
2040
|
-
`\u26A0\uFE0F Invalid implementation ID format for '${
|
|
2149
|
+
`\u26A0\uFE0F Invalid implementation ID format for '${appSlugAndKey}': ${app.implementation_id}. Expected format: <implementationName>@<version>. Skipping...`
|
|
2041
2150
|
);
|
|
2042
2151
|
continue;
|
|
2043
2152
|
}
|
|
2044
2153
|
const [manifestKey] = await context.updateManifestEntry(
|
|
2045
2154
|
app.key,
|
|
2046
2155
|
{
|
|
2047
|
-
implementationName,
|
|
2048
|
-
version
|
|
2156
|
+
implementationName: app.key,
|
|
2157
|
+
version: app.version
|
|
2049
2158
|
},
|
|
2050
2159
|
configPath
|
|
2051
2160
|
);
|
|
2052
2161
|
console.log(
|
|
2053
|
-
`\u{1F4DD} Locked ${
|
|
2162
|
+
`\u{1F4DD} Locked ${appSlugAndKey} to ${app.key}@${app.version} using key '${manifestKey}'`
|
|
2054
2163
|
);
|
|
2055
2164
|
let authenticationId;
|
|
2056
2165
|
if (authentications.length > 0) {
|
|
@@ -2060,10 +2169,12 @@ var addPlugin = ({ sdk: sdk2, context }) => {
|
|
|
2060
2169
|
if (matchingAuth) {
|
|
2061
2170
|
authenticationId = matchingAuth.id;
|
|
2062
2171
|
console.log(
|
|
2063
|
-
`\u{1F510} Using authentication ${authenticationId} (${matchingAuth.title}) for ${
|
|
2172
|
+
`\u{1F510} Using authentication ${authenticationId} (${matchingAuth.title}) for ${appSlugAndKey}`
|
|
2064
2173
|
);
|
|
2065
2174
|
} else {
|
|
2066
|
-
console.warn(
|
|
2175
|
+
console.warn(
|
|
2176
|
+
`\u26A0\uFE0F No matching authentication found for ${appSlugAndKey}`
|
|
2177
|
+
);
|
|
2067
2178
|
}
|
|
2068
2179
|
}
|
|
2069
2180
|
const typesPath = path.join(resolvedTypesOutput, `${manifestKey}.d.ts`);
|
|
@@ -2077,10 +2188,12 @@ var addPlugin = ({ sdk: sdk2, context }) => {
|
|
|
2077
2188
|
await promises.writeFile(typesPath, typeDefinitions, "utf8");
|
|
2078
2189
|
console.log(`\u{1F527} Generated types for ${manifestKey} at ${typesPath}`);
|
|
2079
2190
|
} catch (error) {
|
|
2080
|
-
console.warn(
|
|
2191
|
+
console.warn(
|
|
2192
|
+
`\u26A0\uFE0F Failed to generate types for ${appSlugAndKey}: ${error}`
|
|
2193
|
+
);
|
|
2081
2194
|
}
|
|
2082
2195
|
} catch (error) {
|
|
2083
|
-
console.warn(`\u26A0\uFE0F Failed to process ${
|
|
2196
|
+
console.warn(`\u26A0\uFE0F Failed to process ${appSlugAndKey}: ${error}`);
|
|
2084
2197
|
}
|
|
2085
2198
|
}
|
|
2086
2199
|
console.log(`\u2705 Added ${apps.length} app(s) to manifest`);
|
|
@@ -2115,7 +2228,7 @@ function createZapierCliSdk(options = {}) {
|
|
|
2115
2228
|
|
|
2116
2229
|
// package.json
|
|
2117
2230
|
var package_default = {
|
|
2118
|
-
version: "0.
|
|
2231
|
+
version: "0.10.0"};
|
|
2119
2232
|
|
|
2120
2233
|
// src/cli.ts
|
|
2121
2234
|
var program = new commander.Command();
|