@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
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
|
}
|
|
@@ -280,7 +336,7 @@ var SchemaParameterResolver = class {
|
|
|
280
336
|
const inputs = {};
|
|
281
337
|
let processedFieldKeys = /* @__PURE__ */ new Set();
|
|
282
338
|
let iteration = 0;
|
|
283
|
-
const maxIterations =
|
|
339
|
+
const maxIterations = 10;
|
|
284
340
|
while (iteration < maxIterations) {
|
|
285
341
|
iteration++;
|
|
286
342
|
const updatedContext = {
|
|
@@ -295,11 +351,11 @@ var SchemaParameterResolver = class {
|
|
|
295
351
|
`Fetching input fields for ${param.name}${iteration > 1 ? ` (iteration ${iteration})` : ""}...`
|
|
296
352
|
)
|
|
297
353
|
);
|
|
298
|
-
const
|
|
354
|
+
const rootFieldItems = await typedResolver.fetch(
|
|
299
355
|
updatedContext.sdk,
|
|
300
356
|
updatedContext.resolvedParams
|
|
301
357
|
);
|
|
302
|
-
if (!
|
|
358
|
+
if (!rootFieldItems || rootFieldItems.length === 0) {
|
|
303
359
|
if (iteration === 1) {
|
|
304
360
|
console.log(
|
|
305
361
|
chalk3__default.default.yellow(`No input fields required for this action.`)
|
|
@@ -307,47 +363,125 @@ var SchemaParameterResolver = class {
|
|
|
307
363
|
}
|
|
308
364
|
break;
|
|
309
365
|
}
|
|
310
|
-
const
|
|
311
|
-
|
|
366
|
+
const fieldStats = await this.processFieldItems(
|
|
367
|
+
rootFieldItems,
|
|
368
|
+
inputs,
|
|
369
|
+
processedFieldKeys,
|
|
370
|
+
[],
|
|
371
|
+
iteration
|
|
312
372
|
);
|
|
313
|
-
if (
|
|
373
|
+
if (fieldStats.newRequired === 0 && fieldStats.newOptional === 0) {
|
|
314
374
|
break;
|
|
315
375
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
376
|
+
if (fieldStats.newRequired === 0 && fieldStats.optionalSkipped) {
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (iteration >= maxIterations) {
|
|
381
|
+
console.log(
|
|
382
|
+
chalk3__default.default.yellow(
|
|
383
|
+
`
|
|
384
|
+
\u26A0\uFE0F Maximum field resolution iterations reached. Some dynamic fields may not have been discovered.`
|
|
385
|
+
)
|
|
321
386
|
);
|
|
322
|
-
|
|
387
|
+
}
|
|
388
|
+
return inputs;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Recursively processes fieldsets and their fields, maintaining natural structure
|
|
392
|
+
* and creating nested inputs as needed (e.g., fieldset "foo" becomes inputs.foo = [{}])
|
|
393
|
+
*/
|
|
394
|
+
async processFieldItems(items, targetInputs, processedFieldKeys, fieldsetPath = [], iteration = 1) {
|
|
395
|
+
let newRequiredCount = 0;
|
|
396
|
+
let newOptionalCount = 0;
|
|
397
|
+
let optionalSkipped = false;
|
|
398
|
+
for (const item of items) {
|
|
399
|
+
const typedItem = item;
|
|
400
|
+
if (typedItem.type === "fieldset" && typedItem.fields && typedItem.key) {
|
|
401
|
+
const fieldsetTitle = typedItem.title || typedItem.key;
|
|
402
|
+
const pathDisplay = fieldsetPath.length > 0 ? ` (in ${fieldsetPath.join(" > ")})` : "";
|
|
323
403
|
console.log(
|
|
324
|
-
chalk3__default.default.
|
|
404
|
+
chalk3__default.default.cyan(
|
|
325
405
|
`
|
|
326
|
-
\u{
|
|
406
|
+
\u{1F4C1} Processing fieldset: ${fieldsetTitle}${pathDisplay}`
|
|
327
407
|
)
|
|
328
408
|
);
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
409
|
+
if (!targetInputs[typedItem.key]) {
|
|
410
|
+
targetInputs[typedItem.key] = [{}];
|
|
411
|
+
}
|
|
412
|
+
const fieldsetTarget = targetInputs[typedItem.key][0];
|
|
413
|
+
const nestedPath = [...fieldsetPath, fieldsetTitle];
|
|
414
|
+
const nestedStats = await this.processFieldItems(
|
|
415
|
+
typedItem.fields,
|
|
416
|
+
fieldsetTarget,
|
|
417
|
+
processedFieldKeys,
|
|
418
|
+
nestedPath,
|
|
419
|
+
iteration
|
|
420
|
+
);
|
|
421
|
+
newRequiredCount += nestedStats.newRequired;
|
|
422
|
+
newOptionalCount += nestedStats.newOptional;
|
|
423
|
+
if (nestedStats.optionalSkipped) {
|
|
424
|
+
optionalSkipped = true;
|
|
425
|
+
}
|
|
426
|
+
} else if (typedItem.type === "input_field" && typedItem.key) {
|
|
427
|
+
if (processedFieldKeys.has(typedItem.key)) {
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
const isRequired = typedItem.is_required || false;
|
|
431
|
+
if (isRequired) {
|
|
432
|
+
newRequiredCount++;
|
|
433
|
+
if (newRequiredCount === 1 && fieldsetPath.length === 0) {
|
|
434
|
+
console.log(
|
|
435
|
+
chalk3__default.default.blue(
|
|
436
|
+
`
|
|
437
|
+
\u{1F4DD} Please provide values for the following ${iteration === 1 ? "" : "additional "}input fields:`
|
|
438
|
+
)
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
await this.promptForField(typedItem, targetInputs);
|
|
442
|
+
processedFieldKeys.add(typedItem.key);
|
|
443
|
+
} else {
|
|
444
|
+
newOptionalCount++;
|
|
332
445
|
}
|
|
333
446
|
}
|
|
334
|
-
|
|
335
|
-
|
|
447
|
+
}
|
|
448
|
+
if (newOptionalCount > 0) {
|
|
449
|
+
const optionalFields = items.filter((item) => {
|
|
450
|
+
const typedItem = item;
|
|
451
|
+
return typedItem.type === "input_field" && typedItem.key && !typedItem.is_required && !processedFieldKeys.has(typedItem.key);
|
|
452
|
+
});
|
|
453
|
+
if (optionalFields.length > 0) {
|
|
454
|
+
const pathContext = fieldsetPath.length > 0 ? ` in ${fieldsetPath.join(" > ")}` : "";
|
|
336
455
|
console.log(
|
|
337
456
|
chalk3__default.default.gray(
|
|
338
457
|
`
|
|
339
|
-
There are ${
|
|
458
|
+
There are ${optionalFields.length} ${iteration === 1 ? "" : "additional "}optional field(s) available${pathContext}.`
|
|
340
459
|
)
|
|
341
460
|
);
|
|
342
461
|
try {
|
|
343
|
-
shouldConfigureOptional = await inquirer__default.default.prompt([
|
|
462
|
+
const shouldConfigureOptional = await inquirer__default.default.prompt([
|
|
344
463
|
{
|
|
345
464
|
type: "confirm",
|
|
346
465
|
name: "configure",
|
|
347
|
-
message: `Would you like to configure ${iteration === 1 ? "" : "these additional "}optional fields?`,
|
|
466
|
+
message: `Would you like to configure ${iteration === 1 ? "" : "these additional "}optional fields${pathContext}?`,
|
|
348
467
|
default: false
|
|
349
468
|
}
|
|
350
469
|
]);
|
|
470
|
+
if (shouldConfigureOptional.configure) {
|
|
471
|
+
console.log(chalk3__default.default.cyan(`
|
|
472
|
+
Optional fields${pathContext}:`));
|
|
473
|
+
for (const field of optionalFields) {
|
|
474
|
+
await this.promptForField(field, targetInputs);
|
|
475
|
+
const typedField = field;
|
|
476
|
+
processedFieldKeys.add(typedField.key);
|
|
477
|
+
}
|
|
478
|
+
} else {
|
|
479
|
+
optionalSkipped = true;
|
|
480
|
+
optionalFields.forEach((field) => {
|
|
481
|
+
const typedField = field;
|
|
482
|
+
processedFieldKeys.add(typedField.key);
|
|
483
|
+
});
|
|
484
|
+
}
|
|
351
485
|
} catch (error) {
|
|
352
486
|
if (this.isUserCancellation(error)) {
|
|
353
487
|
console.log(chalk3__default.default.yellow("\n\nOperation cancelled by user"));
|
|
@@ -355,32 +489,13 @@ There are ${newOptionalFields.length} ${iteration === 1 ? "" : "additional "}opt
|
|
|
355
489
|
}
|
|
356
490
|
throw error;
|
|
357
491
|
}
|
|
358
|
-
if (shouldConfigureOptional.configure) {
|
|
359
|
-
console.log(chalk3__default.default.cyan(`
|
|
360
|
-
Optional fields:`));
|
|
361
|
-
for (const field of newOptionalFields) {
|
|
362
|
-
await this.promptForField(field, inputs);
|
|
363
|
-
processedFieldKeys.add(field.key);
|
|
364
|
-
}
|
|
365
|
-
} else {
|
|
366
|
-
newOptionalFields.forEach(
|
|
367
|
-
(field) => processedFieldKeys.add(field.key)
|
|
368
|
-
);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
if (newRequiredFields.length === 0 && (!newOptionalFields.length || !shouldConfigureOptional.configure)) {
|
|
372
|
-
break;
|
|
373
492
|
}
|
|
374
493
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
)
|
|
381
|
-
);
|
|
382
|
-
}
|
|
383
|
-
return inputs;
|
|
494
|
+
return {
|
|
495
|
+
newRequired: newRequiredCount,
|
|
496
|
+
newOptional: newOptionalCount,
|
|
497
|
+
optionalSkipped
|
|
498
|
+
};
|
|
384
499
|
}
|
|
385
500
|
getNestedValue(obj, path2) {
|
|
386
501
|
return path2.reduce(
|
|
@@ -404,7 +519,7 @@ Optional fields:`));
|
|
|
404
519
|
const fieldPrompt = {
|
|
405
520
|
type: fieldObj.type === "boolean" ? "confirm" : "input",
|
|
406
521
|
name: fieldObj.key,
|
|
407
|
-
message: `${fieldObj.label || fieldObj.key}${fieldObj.
|
|
522
|
+
message: `${fieldObj.label || fieldObj.key}${fieldObj.is_required ? " (required)" : " (optional)"}:`
|
|
408
523
|
};
|
|
409
524
|
if (fieldObj.helpText) {
|
|
410
525
|
fieldPrompt.prefix = chalk3__default.default.gray(`\u2139 ${fieldObj.helpText}
|
|
@@ -429,7 +544,7 @@ Optional fields:`));
|
|
|
429
544
|
const answer = await inquirer__default.default.prompt([fieldPrompt]);
|
|
430
545
|
if (answer[fieldObj.key] !== void 0 && answer[fieldObj.key] !== "") {
|
|
431
546
|
inputs[fieldObj.key] = answer[fieldObj.key];
|
|
432
|
-
} else if (fieldObj.
|
|
547
|
+
} else if (fieldObj.is_required) {
|
|
433
548
|
throw new Error(`Required field ${fieldObj.key} cannot be empty`);
|
|
434
549
|
}
|
|
435
550
|
} catch (error) {
|
|
@@ -444,6 +559,40 @@ Optional fields:`));
|
|
|
444
559
|
const errorObj = error;
|
|
445
560
|
return errorObj?.name === "ExitPromptError" || errorObj?.message?.includes("User force closed") || errorObj?.isTTYError === true;
|
|
446
561
|
}
|
|
562
|
+
hasResolver(paramName, sdk2, functionName) {
|
|
563
|
+
if (functionName && typeof sdk2.getRegistry === "function") {
|
|
564
|
+
const registry = sdk2.getRegistry();
|
|
565
|
+
const functionInfo = registry.functions.find(
|
|
566
|
+
(f) => f.name === functionName
|
|
567
|
+
);
|
|
568
|
+
if (functionInfo && functionInfo.resolvers?.[paramName]) {
|
|
569
|
+
return true;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return false;
|
|
573
|
+
}
|
|
574
|
+
getResolver(paramName, sdk2, functionName) {
|
|
575
|
+
if (functionName && typeof sdk2.getRegistry === "function") {
|
|
576
|
+
const registry = sdk2.getRegistry();
|
|
577
|
+
const functionInfo = registry.functions.find(
|
|
578
|
+
(f) => f.name === functionName
|
|
579
|
+
);
|
|
580
|
+
if (functionInfo && functionInfo.resolvers?.[paramName]) {
|
|
581
|
+
return functionInfo.resolvers[paramName];
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
return null;
|
|
585
|
+
}
|
|
586
|
+
getLocalResolvers(sdk2, functionName) {
|
|
587
|
+
if (!functionName || typeof sdk2.getRegistry !== "function") {
|
|
588
|
+
return {};
|
|
589
|
+
}
|
|
590
|
+
const registry = sdk2.getRegistry();
|
|
591
|
+
const functionInfo = registry.functions.find(
|
|
592
|
+
(f) => f.name === functionName
|
|
593
|
+
);
|
|
594
|
+
return functionInfo?.resolvers || {};
|
|
595
|
+
}
|
|
447
596
|
};
|
|
448
597
|
function getFormatMetadata(schema) {
|
|
449
598
|
return schema?._def?.formatMeta;
|
|
@@ -451,8 +600,16 @@ function getFormatMetadata(schema) {
|
|
|
451
600
|
function getOutputSchema(schema) {
|
|
452
601
|
return schema?._def?.outputSchema;
|
|
453
602
|
}
|
|
454
|
-
function
|
|
455
|
-
|
|
603
|
+
function formatJsonOutput(data) {
|
|
604
|
+
if (data === void 0) {
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
console.log(
|
|
608
|
+
util__default.default.inspect(data, { colors: true, depth: null, breakLength: 80 })
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
function formatItemsFromSchema(functionInfo, items, startingNumber = 0) {
|
|
612
|
+
const outputSchema = functionInfo.outputSchema || getOutputSchema(functionInfo.inputSchema);
|
|
456
613
|
if (!outputSchema) {
|
|
457
614
|
formatItemsGeneric(items, startingNumber);
|
|
458
615
|
return;
|
|
@@ -463,16 +620,26 @@ function formatItemsFromSchema(inputSchema, items, startingNumber = 0) {
|
|
|
463
620
|
return;
|
|
464
621
|
}
|
|
465
622
|
items.forEach((item, index) => {
|
|
466
|
-
|
|
623
|
+
const formatted = formatMeta.format(item);
|
|
624
|
+
formatSingleItem(formatted, startingNumber + index);
|
|
467
625
|
});
|
|
468
626
|
}
|
|
469
|
-
function formatSingleItem(
|
|
470
|
-
const formatted = formatMeta.format(item);
|
|
627
|
+
function formatSingleItem(formatted, itemNumber) {
|
|
471
628
|
let titleLine = `${chalk3__default.default.gray(`${itemNumber + 1}.`)} ${chalk3__default.default.cyan(formatted.title)}`;
|
|
472
|
-
if (formatted.
|
|
473
|
-
titleLine += ` ${chalk3__default.default.gray(formatted.
|
|
629
|
+
if (formatted.id) {
|
|
630
|
+
titleLine += ` ${chalk3__default.default.gray(`(ID: ${formatted.id})`)}`;
|
|
631
|
+
} else if (formatted.key) {
|
|
632
|
+
titleLine += ` ${chalk3__default.default.gray(`(${formatted.key})`)}`;
|
|
474
633
|
}
|
|
475
634
|
console.log(titleLine);
|
|
635
|
+
if (formatted.description) {
|
|
636
|
+
console.log(` ${chalk3__default.default.dim(formatted.description)}`);
|
|
637
|
+
}
|
|
638
|
+
if (formatted.data !== void 0) {
|
|
639
|
+
formatJsonOutput(formatted.data);
|
|
640
|
+
console.log();
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
476
643
|
for (const detail of formatted.details) {
|
|
477
644
|
const styledText = applyStyle(detail.text, detail.style);
|
|
478
645
|
console.log(` ${styledText}`);
|
|
@@ -494,40 +661,36 @@ function applyStyle(value, style) {
|
|
|
494
661
|
return chalk3__default.default.blue(value);
|
|
495
662
|
}
|
|
496
663
|
}
|
|
664
|
+
function convertGenericItemToFormattedItem(item) {
|
|
665
|
+
const itemObj = item;
|
|
666
|
+
return {
|
|
667
|
+
title: itemObj.title || itemObj.name || itemObj.key || itemObj.id || "Item",
|
|
668
|
+
id: itemObj.id,
|
|
669
|
+
key: itemObj.key,
|
|
670
|
+
description: itemObj.description,
|
|
671
|
+
details: []
|
|
672
|
+
};
|
|
673
|
+
}
|
|
497
674
|
function formatItemsGeneric(items, startingNumber = 0) {
|
|
498
675
|
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();
|
|
676
|
+
const formatted = convertGenericItemToFormattedItem(item);
|
|
677
|
+
formatSingleItem(formatted, startingNumber + index);
|
|
508
678
|
});
|
|
509
679
|
}
|
|
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) {
|
|
680
|
+
function analyzeZodSchema(schema, functionInfo) {
|
|
522
681
|
const parameters = [];
|
|
523
682
|
if (schema._def && schema._def.typeName === "ZodEffects") {
|
|
524
683
|
const innerSchema = schema._def.schema;
|
|
525
|
-
return analyzeZodSchema(innerSchema);
|
|
684
|
+
return analyzeZodSchema(innerSchema, functionInfo);
|
|
526
685
|
}
|
|
527
686
|
if (schema instanceof zod.z.ZodObject) {
|
|
528
687
|
const shape = schema.shape;
|
|
529
688
|
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
530
|
-
const param = analyzeZodField(
|
|
689
|
+
const param = analyzeZodField(
|
|
690
|
+
key,
|
|
691
|
+
fieldSchema,
|
|
692
|
+
functionInfo
|
|
693
|
+
);
|
|
531
694
|
if (param) {
|
|
532
695
|
parameters.push(param);
|
|
533
696
|
}
|
|
@@ -535,7 +698,7 @@ function analyzeZodSchema(schema) {
|
|
|
535
698
|
}
|
|
536
699
|
return parameters;
|
|
537
700
|
}
|
|
538
|
-
function analyzeZodField(name, schema) {
|
|
701
|
+
function analyzeZodField(name, schema, functionInfo) {
|
|
539
702
|
let baseSchema = schema;
|
|
540
703
|
let required = true;
|
|
541
704
|
let defaultValue = void 0;
|
|
@@ -569,6 +732,10 @@ function analyzeZodField(name, schema) {
|
|
|
569
732
|
} else if (baseSchema instanceof zod.z.ZodRecord) {
|
|
570
733
|
paramType = "string";
|
|
571
734
|
}
|
|
735
|
+
let paramHasResolver = false;
|
|
736
|
+
if (functionInfo?.resolvers?.[name]) {
|
|
737
|
+
paramHasResolver = true;
|
|
738
|
+
}
|
|
572
739
|
return {
|
|
573
740
|
name,
|
|
574
741
|
type: paramType,
|
|
@@ -576,7 +743,7 @@ function analyzeZodField(name, schema) {
|
|
|
576
743
|
description: schema.description,
|
|
577
744
|
default: defaultValue,
|
|
578
745
|
choices,
|
|
579
|
-
hasResolver:
|
|
746
|
+
hasResolver: paramHasResolver,
|
|
580
747
|
isPositional: zapierSdk.isPositional(schema)
|
|
581
748
|
};
|
|
582
749
|
}
|
|
@@ -598,12 +765,7 @@ function generateCliCommands(program2, sdk2) {
|
|
|
598
765
|
return;
|
|
599
766
|
}
|
|
600
767
|
const cliCommandName = methodNameToCliCommand(fnInfo.name);
|
|
601
|
-
const config = createCommandConfig(
|
|
602
|
-
cliCommandName,
|
|
603
|
-
fnInfo.name,
|
|
604
|
-
fnInfo.inputSchema,
|
|
605
|
-
sdk2
|
|
606
|
-
);
|
|
768
|
+
const config = createCommandConfig(cliCommandName, fnInfo, sdk2);
|
|
607
769
|
addCommand(program2, cliCommandName, config);
|
|
608
770
|
});
|
|
609
771
|
program2.configureHelp({
|
|
@@ -667,14 +829,15 @@ function generateCliCommands(program2, sdk2) {
|
|
|
667
829
|
}
|
|
668
830
|
});
|
|
669
831
|
}
|
|
670
|
-
function createCommandConfig(cliCommandName,
|
|
671
|
-
const
|
|
832
|
+
function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
833
|
+
const schema = functionInfo.inputSchema;
|
|
834
|
+
const parameters = analyzeZodSchema(schema, functionInfo);
|
|
672
835
|
const description = schema.description || `${cliCommandName} command`;
|
|
673
836
|
const handler = async (...args) => {
|
|
674
837
|
try {
|
|
675
838
|
const commandObj = args[args.length - 1];
|
|
676
839
|
const options = commandObj.opts();
|
|
677
|
-
const isListCommand =
|
|
840
|
+
const isListCommand = functionInfo.type === "list";
|
|
678
841
|
const hasPaginationParams = parameters.some(
|
|
679
842
|
(p) => p.name === "maxItems" || p.name === "pageSize"
|
|
680
843
|
);
|
|
@@ -689,21 +852,22 @@ function createCommandConfig(cliCommandName, sdkMethodName, schema, sdk2) {
|
|
|
689
852
|
const resolvedParams = await resolver.resolveParameters(
|
|
690
853
|
schema,
|
|
691
854
|
rawParams,
|
|
692
|
-
sdk2
|
|
855
|
+
sdk2,
|
|
856
|
+
functionInfo.name
|
|
693
857
|
);
|
|
694
858
|
if (isListCommand && hasPaginationParams && !shouldUseJson && !hasUserSpecifiedMaxItems) {
|
|
695
859
|
const sdkObj = sdk2;
|
|
696
|
-
const sdkIterator = sdkObj[
|
|
860
|
+
const sdkIterator = sdkObj[functionInfo.name](resolvedParams);
|
|
697
861
|
await handlePaginatedListWithAsyncIteration(
|
|
698
|
-
|
|
862
|
+
functionInfo.name,
|
|
699
863
|
sdkIterator,
|
|
700
|
-
|
|
864
|
+
functionInfo
|
|
701
865
|
);
|
|
702
866
|
} else {
|
|
703
867
|
const hasOutputFile = resolvedParams.output;
|
|
704
868
|
if (hasOutputFile) {
|
|
705
869
|
const sdkObj2 = sdk2;
|
|
706
|
-
await sdkObj2[
|
|
870
|
+
await sdkObj2[functionInfo.name](resolvedParams);
|
|
707
871
|
console.log(
|
|
708
872
|
chalk3__default.default.green(`\u2705 ${cliCommandName} completed successfully!`)
|
|
709
873
|
);
|
|
@@ -711,7 +875,7 @@ function createCommandConfig(cliCommandName, sdkMethodName, schema, sdk2) {
|
|
|
711
875
|
return;
|
|
712
876
|
}
|
|
713
877
|
const sdkObj = sdk2;
|
|
714
|
-
const result = await sdkObj[
|
|
878
|
+
const result = await sdkObj[functionInfo.name](resolvedParams);
|
|
715
879
|
const items = result?.data ? result.data : result;
|
|
716
880
|
if (shouldUseJson) {
|
|
717
881
|
console.log(JSON.stringify(items, null, 2));
|
|
@@ -721,8 +885,7 @@ function createCommandConfig(cliCommandName, sdkMethodName, schema, sdk2) {
|
|
|
721
885
|
resolvedParams.maxItems,
|
|
722
886
|
hasUserSpecifiedMaxItems,
|
|
723
887
|
shouldUseJson,
|
|
724
|
-
|
|
725
|
-
sdkMethodName
|
|
888
|
+
functionInfo
|
|
726
889
|
);
|
|
727
890
|
} else {
|
|
728
891
|
formatJsonOutput(items);
|
|
@@ -843,6 +1006,9 @@ function convertCliArgsToSdkParams(parameters, positionalArgs, options) {
|
|
|
843
1006
|
return sdkParams;
|
|
844
1007
|
}
|
|
845
1008
|
function convertValue(value, type) {
|
|
1009
|
+
if (value === void 0) {
|
|
1010
|
+
return void 0;
|
|
1011
|
+
}
|
|
846
1012
|
switch (type) {
|
|
847
1013
|
case "number":
|
|
848
1014
|
return Number(value);
|
|
@@ -862,12 +1028,14 @@ function convertValue(value, type) {
|
|
|
862
1028
|
return value;
|
|
863
1029
|
}
|
|
864
1030
|
}
|
|
865
|
-
async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult,
|
|
866
|
-
const itemName = getItemNameFromMethod(
|
|
1031
|
+
async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, functionInfo) {
|
|
1032
|
+
const itemName = getItemNameFromMethod(functionInfo);
|
|
867
1033
|
let totalShown = 0;
|
|
868
1034
|
let pageCount = 0;
|
|
869
|
-
console.log(
|
|
870
|
-
|
|
1035
|
+
console.log(
|
|
1036
|
+
chalk3__default.default.blue(`\u{1F4CB} ${getListTitleFromMethod(sdkMethodName, functionInfo)}
|
|
1037
|
+
`)
|
|
1038
|
+
);
|
|
871
1039
|
try {
|
|
872
1040
|
for await (const page of sdkResult) {
|
|
873
1041
|
const items = page.data || page;
|
|
@@ -886,12 +1054,14 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, s
|
|
|
886
1054
|
if (pageCount > 1) {
|
|
887
1055
|
console.clear();
|
|
888
1056
|
console.log(
|
|
889
|
-
chalk3__default.default.blue(
|
|
890
|
-
|
|
1057
|
+
chalk3__default.default.blue(
|
|
1058
|
+
`\u{1F4CB} ${getListTitleFromMethod(sdkMethodName, functionInfo)}
|
|
1059
|
+
`
|
|
1060
|
+
)
|
|
891
1061
|
);
|
|
892
1062
|
}
|
|
893
|
-
if (
|
|
894
|
-
formatItemsFromSchema(
|
|
1063
|
+
if (functionInfo) {
|
|
1064
|
+
formatItemsFromSchema(functionInfo, items, totalShown);
|
|
895
1065
|
} else {
|
|
896
1066
|
formatItemsGeneric2(items, totalShown);
|
|
897
1067
|
}
|
|
@@ -927,8 +1097,8 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, s
|
|
|
927
1097
|
console.log(chalk3__default.default.yellow(`No ${itemName} found.`));
|
|
928
1098
|
return;
|
|
929
1099
|
}
|
|
930
|
-
if (
|
|
931
|
-
formatItemsFromSchema(
|
|
1100
|
+
if (functionInfo) {
|
|
1101
|
+
formatItemsFromSchema(functionInfo, items, 0);
|
|
932
1102
|
} else {
|
|
933
1103
|
formatItemsGeneric2(items, 0);
|
|
934
1104
|
}
|
|
@@ -939,7 +1109,7 @@ async function handlePaginatedListWithAsyncIteration(sdkMethodName, sdkResult, s
|
|
|
939
1109
|
}
|
|
940
1110
|
}
|
|
941
1111
|
}
|
|
942
|
-
function formatNonPaginatedResults(result, requestedMaxItems, userSpecifiedMaxItems, useRawJson,
|
|
1112
|
+
function formatNonPaginatedResults(result, requestedMaxItems, userSpecifiedMaxItems, useRawJson, functionInfo) {
|
|
943
1113
|
if (!Array.isArray(result)) {
|
|
944
1114
|
if (useRawJson) {
|
|
945
1115
|
console.log(JSON.stringify(result, null, 2));
|
|
@@ -952,7 +1122,7 @@ function formatNonPaginatedResults(result, requestedMaxItems, userSpecifiedMaxIt
|
|
|
952
1122
|
console.log(JSON.stringify(result, null, 2));
|
|
953
1123
|
return;
|
|
954
1124
|
}
|
|
955
|
-
const itemName =
|
|
1125
|
+
const itemName = functionInfo ? getItemNameFromMethod(functionInfo) : "items";
|
|
956
1126
|
if (result.length === 0) {
|
|
957
1127
|
console.log(chalk3__default.default.yellow(`No ${itemName} found.`));
|
|
958
1128
|
return;
|
|
@@ -960,8 +1130,8 @@ function formatNonPaginatedResults(result, requestedMaxItems, userSpecifiedMaxIt
|
|
|
960
1130
|
console.log(chalk3__default.default.green(`
|
|
961
1131
|
\u2705 Found ${result.length} ${itemName}:
|
|
962
1132
|
`));
|
|
963
|
-
if (
|
|
964
|
-
formatItemsFromSchema(
|
|
1133
|
+
if (functionInfo) {
|
|
1134
|
+
formatItemsFromSchema(functionInfo, result);
|
|
965
1135
|
} else {
|
|
966
1136
|
formatItemsGeneric2(result);
|
|
967
1137
|
}
|
|
@@ -990,18 +1160,17 @@ function formatItemsGeneric2(items, startingNumber = 0) {
|
|
|
990
1160
|
console.log();
|
|
991
1161
|
});
|
|
992
1162
|
}
|
|
993
|
-
function getItemNameFromMethod(
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
return listMatch[1].toLowerCase();
|
|
1163
|
+
function getItemNameFromMethod(functionInfo) {
|
|
1164
|
+
if (functionInfo.itemType) {
|
|
1165
|
+
return `${functionInfo.itemType} items`;
|
|
997
1166
|
}
|
|
998
1167
|
return "items";
|
|
999
1168
|
}
|
|
1000
|
-
function getListTitleFromMethod(methodName) {
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
return
|
|
1169
|
+
function getListTitleFromMethod(methodName, functionInfo) {
|
|
1170
|
+
if (functionInfo.itemType) {
|
|
1171
|
+
return `Available ${functionInfo.itemType} items`;
|
|
1172
|
+
}
|
|
1173
|
+
return `${methodName} items`;
|
|
1005
1174
|
}
|
|
1006
1175
|
|
|
1007
1176
|
// src/utils/constants.ts
|
|
@@ -2031,26 +2200,25 @@ var addPlugin = ({ sdk: sdk2, context }) => {
|
|
|
2031
2200
|
console.log(`\u{1F510} Found ${authentications.length} authentication(s)`);
|
|
2032
2201
|
}
|
|
2033
2202
|
for (const app of apps) {
|
|
2034
|
-
|
|
2203
|
+
const appSlugAndKey = app.slug ? `${app.slug} (${app.key})` : app.key;
|
|
2204
|
+
console.log(`\u{1F4E6} Adding ${appSlugAndKey}...`);
|
|
2035
2205
|
try {
|
|
2036
|
-
|
|
2037
|
-
const [implementationName, version] = currentImplementationId.split("@");
|
|
2038
|
-
if (!implementationName || !version) {
|
|
2206
|
+
if (!app.version) {
|
|
2039
2207
|
console.warn(
|
|
2040
|
-
`\u26A0\uFE0F Invalid implementation ID format for '${
|
|
2208
|
+
`\u26A0\uFE0F Invalid implementation ID format for '${appSlugAndKey}': ${app.implementation_id}. Expected format: <implementationName>@<version>. Skipping...`
|
|
2041
2209
|
);
|
|
2042
2210
|
continue;
|
|
2043
2211
|
}
|
|
2044
2212
|
const [manifestKey] = await context.updateManifestEntry(
|
|
2045
2213
|
app.key,
|
|
2046
2214
|
{
|
|
2047
|
-
implementationName,
|
|
2048
|
-
version
|
|
2215
|
+
implementationName: app.key,
|
|
2216
|
+
version: app.version
|
|
2049
2217
|
},
|
|
2050
2218
|
configPath
|
|
2051
2219
|
);
|
|
2052
2220
|
console.log(
|
|
2053
|
-
`\u{1F4DD} Locked ${
|
|
2221
|
+
`\u{1F4DD} Locked ${appSlugAndKey} to ${app.key}@${app.version} using key '${manifestKey}'`
|
|
2054
2222
|
);
|
|
2055
2223
|
let authenticationId;
|
|
2056
2224
|
if (authentications.length > 0) {
|
|
@@ -2060,10 +2228,12 @@ var addPlugin = ({ sdk: sdk2, context }) => {
|
|
|
2060
2228
|
if (matchingAuth) {
|
|
2061
2229
|
authenticationId = matchingAuth.id;
|
|
2062
2230
|
console.log(
|
|
2063
|
-
`\u{1F510} Using authentication ${authenticationId} (${matchingAuth.title}) for ${
|
|
2231
|
+
`\u{1F510} Using authentication ${authenticationId} (${matchingAuth.title}) for ${appSlugAndKey}`
|
|
2064
2232
|
);
|
|
2065
2233
|
} else {
|
|
2066
|
-
console.warn(
|
|
2234
|
+
console.warn(
|
|
2235
|
+
`\u26A0\uFE0F No matching authentication found for ${appSlugAndKey}`
|
|
2236
|
+
);
|
|
2067
2237
|
}
|
|
2068
2238
|
}
|
|
2069
2239
|
const typesPath = path.join(resolvedTypesOutput, `${manifestKey}.d.ts`);
|
|
@@ -2077,10 +2247,12 @@ var addPlugin = ({ sdk: sdk2, context }) => {
|
|
|
2077
2247
|
await promises.writeFile(typesPath, typeDefinitions, "utf8");
|
|
2078
2248
|
console.log(`\u{1F527} Generated types for ${manifestKey} at ${typesPath}`);
|
|
2079
2249
|
} catch (error) {
|
|
2080
|
-
console.warn(
|
|
2250
|
+
console.warn(
|
|
2251
|
+
`\u26A0\uFE0F Failed to generate types for ${appSlugAndKey}: ${error}`
|
|
2252
|
+
);
|
|
2081
2253
|
}
|
|
2082
2254
|
} catch (error) {
|
|
2083
|
-
console.warn(`\u26A0\uFE0F Failed to process ${
|
|
2255
|
+
console.warn(`\u26A0\uFE0F Failed to process ${appSlugAndKey}: ${error}`);
|
|
2084
2256
|
}
|
|
2085
2257
|
}
|
|
2086
2258
|
console.log(`\u2705 Added ${apps.length} app(s) to manifest`);
|
|
@@ -2115,7 +2287,7 @@ function createZapierCliSdk(options = {}) {
|
|
|
2115
2287
|
|
|
2116
2288
|
// package.json
|
|
2117
2289
|
var package_default = {
|
|
2118
|
-
version: "0.
|
|
2290
|
+
version: "0.11.0"};
|
|
2119
2291
|
|
|
2120
2292
|
// src/cli.ts
|
|
2121
2293
|
var program = new commander.Command();
|