@zapier/zapier-sdk-cli 0.3.1 → 0.4.1

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.
Files changed (47) hide show
  1. package/dist/cli.js +1099 -16
  2. package/dist/index.js +0 -3
  3. package/package.json +5 -3
  4. package/src/cli.ts +2 -2
  5. package/src/commands/configPath.ts +1 -1
  6. package/src/commands/index.ts +4 -4
  7. package/src/commands/login.ts +2 -2
  8. package/src/commands/logout.ts +1 -1
  9. package/src/commands/whoami.ts +2 -2
  10. package/src/utils/auth/login.ts +6 -6
  11. package/src/utils/cli-generator.ts +3 -3
  12. package/tsconfig.json +3 -3
  13. package/tsup.config.ts +17 -0
  14. package/dist/cli.d.ts +0 -2
  15. package/dist/commands/configPath.d.ts +0 -2
  16. package/dist/commands/configPath.js +0 -9
  17. package/dist/commands/index.d.ts +0 -4
  18. package/dist/commands/index.js +0 -4
  19. package/dist/commands/login.d.ts +0 -2
  20. package/dist/commands/login.js +0 -25
  21. package/dist/commands/logout.d.ts +0 -2
  22. package/dist/commands/logout.js +0 -16
  23. package/dist/commands/whoami.d.ts +0 -2
  24. package/dist/commands/whoami.js +0 -17
  25. package/dist/index.d.ts +0 -1
  26. package/dist/utils/api/client.d.ts +0 -15
  27. package/dist/utils/api/client.js +0 -27
  28. package/dist/utils/auth/login.d.ts +0 -2
  29. package/dist/utils/auth/login.js +0 -134
  30. package/dist/utils/cli-generator.d.ts +0 -3
  31. package/dist/utils/cli-generator.js +0 -388
  32. package/dist/utils/constants.d.ts +0 -5
  33. package/dist/utils/constants.js +0 -6
  34. package/dist/utils/getCallablePromise.d.ts +0 -6
  35. package/dist/utils/getCallablePromise.js +0 -14
  36. package/dist/utils/log.d.ts +0 -7
  37. package/dist/utils/log.js +0 -16
  38. package/dist/utils/pager.d.ts +0 -48
  39. package/dist/utils/pager.js +0 -137
  40. package/dist/utils/parameter-resolver.d.ts +0 -13
  41. package/dist/utils/parameter-resolver.js +0 -300
  42. package/dist/utils/schema-formatter.d.ts +0 -2
  43. package/dist/utils/schema-formatter.js +0 -71
  44. package/dist/utils/serializeAsync.d.ts +0 -2
  45. package/dist/utils/serializeAsync.js +0 -16
  46. package/dist/utils/spinner.d.ts +0 -1
  47. package/dist/utils/spinner.js +0 -13
@@ -1,388 +0,0 @@
1
- import { z } from "zod";
2
- import { hasResolver, isPositional } from "@zapier/zapier-sdk";
3
- import { SchemaParameterResolver } from "./parameter-resolver.js";
4
- import { createPager } from "./pager.js";
5
- import { formatItemsFromSchema } from "./schema-formatter.js";
6
- import chalk from "chalk";
7
- import util from "util";
8
- // ============================================================================
9
- // JSON Formatting
10
- // ============================================================================
11
- function formatJsonOutput(data) {
12
- // Show success message for action results
13
- if (data &&
14
- typeof data === "object" &&
15
- !Array.isArray(data) &&
16
- (data.success !== undefined || data.id || data.status)) {
17
- console.log(chalk.green("āœ… Action completed successfully!\n"));
18
- }
19
- // Use util.inspect for colored output
20
- console.log(util.inspect(data, { colors: true, depth: null, breakLength: 80 }));
21
- }
22
- // ============================================================================
23
- // Schema Analysis
24
- // ============================================================================
25
- function analyzeZodSchema(schema) {
26
- const parameters = [];
27
- if (schema instanceof z.ZodObject) {
28
- const shape = schema.shape;
29
- for (const [key, fieldSchema] of Object.entries(shape)) {
30
- const param = analyzeZodField(key, fieldSchema);
31
- if (param) {
32
- parameters.push(param);
33
- }
34
- }
35
- }
36
- return parameters;
37
- }
38
- function analyzeZodField(name, schema) {
39
- let baseSchema = schema;
40
- let required = true;
41
- let defaultValue = undefined;
42
- // Unwrap optional and default wrappers
43
- if (baseSchema instanceof z.ZodOptional) {
44
- required = false;
45
- baseSchema = baseSchema._def.innerType;
46
- }
47
- if (baseSchema instanceof z.ZodDefault) {
48
- required = false;
49
- defaultValue = baseSchema._def.defaultValue();
50
- baseSchema = baseSchema._def.innerType;
51
- }
52
- // Determine parameter type
53
- let paramType = "string";
54
- let choices;
55
- if (baseSchema instanceof z.ZodString) {
56
- paramType = "string";
57
- }
58
- else if (baseSchema instanceof z.ZodNumber) {
59
- paramType = "number";
60
- }
61
- else if (baseSchema instanceof z.ZodBoolean) {
62
- paramType = "boolean";
63
- }
64
- else if (baseSchema instanceof z.ZodArray) {
65
- paramType = "array";
66
- }
67
- else if (baseSchema instanceof z.ZodEnum) {
68
- paramType = "string";
69
- choices = baseSchema._def.values;
70
- }
71
- else if (baseSchema instanceof z.ZodRecord) {
72
- // Handle Record<string, any> as JSON string input
73
- paramType = "string";
74
- }
75
- // Extract resolver metadata
76
- return {
77
- name,
78
- type: paramType,
79
- required,
80
- description: schema.description,
81
- default: defaultValue,
82
- choices,
83
- hasResolver: hasResolver(name),
84
- isPositional: isPositional(schema),
85
- };
86
- }
87
- // ============================================================================
88
- // CLI Structure Derivation - Purely Generic
89
- // ============================================================================
90
- /**
91
- * Convert camelCase to kebab-case
92
- * e.g., listApps -> list-apps, generateTypes -> generate-types
93
- */
94
- function toKebabCase(str) {
95
- return str.replace(/([A-Z])/g, "-$1").toLowerCase();
96
- }
97
- /**
98
- * Convert SDK method name directly to CLI command
99
- * e.g., listApps -> list-apps, getApp -> get-app, generateTypes -> generate-types
100
- */
101
- function methodNameToCliCommand(methodName) {
102
- return toKebabCase(methodName);
103
- }
104
- // ============================================================================
105
- // CLI Command Generation - Completely Generic
106
- // ============================================================================
107
- export function generateCliCommands(program, sdk) {
108
- // Check if SDK has registry
109
- if (!sdk.__registry) {
110
- console.error("SDK registry not available");
111
- return;
112
- }
113
- // Generate one flat command for each function in the registry
114
- sdk.__registry.forEach((fnInfo) => {
115
- if (!fnInfo.inputSchema) {
116
- console.warn(`Schema not found for ${fnInfo.name}`);
117
- return;
118
- }
119
- // Convert methodName to kebab-case CLI command
120
- const cliCommandName = methodNameToCliCommand(fnInfo.name);
121
- const config = createCommandConfig(cliCommandName, fnInfo.name, fnInfo.inputSchema, sdk);
122
- addCommand(program, cliCommandName, config);
123
- });
124
- }
125
- function createCommandConfig(cliCommandName, sdkMethodName, schema, sdk) {
126
- const parameters = analyzeZodSchema(schema);
127
- const description = schema.description || `${cliCommandName} command`;
128
- const handler = async (...args) => {
129
- try {
130
- // The last argument is always the command object with parsed options
131
- const commandObj = args[args.length - 1];
132
- const options = commandObj.opts();
133
- // Check if this is a list command for pagination
134
- const isListCommand = cliCommandName.startsWith("list-");
135
- const hasPaginationParams = parameters.some((p) => p.name === "limit" || p.name === "offset");
136
- const hasUserSpecifiedLimit = "limit" in options && options.limit !== undefined;
137
- const shouldUsePaging = isListCommand && hasPaginationParams && !hasUserSpecifiedLimit;
138
- const shouldUseJson = options.json;
139
- // Convert CLI args to SDK method parameters
140
- const rawParams = convertCliArgsToSdkParams(parameters, args.slice(0, -1), options);
141
- // Resolve missing parameters interactively using schema metadata
142
- const resolver = new SchemaParameterResolver();
143
- const resolvedParams = await resolver.resolveParameters(schema, rawParams, sdk);
144
- if (shouldUsePaging && !shouldUseJson) {
145
- // Use interactive paging for list commands
146
- await handlePaginatedList(sdkMethodName, resolvedParams, sdk, schema);
147
- }
148
- else {
149
- // Call the SDK method directly
150
- const result = await sdk[sdkMethodName](resolvedParams);
151
- // Special handling for commands that write to files
152
- const hasOutputFile = resolvedParams.output;
153
- // Output result (JSON or formatted)
154
- if (!hasOutputFile && (shouldUseJson || !isListCommand)) {
155
- // Use raw JSON if --json flag is specified, otherwise use pretty formatting
156
- if (shouldUseJson) {
157
- console.log(JSON.stringify(result, null, 2));
158
- }
159
- else {
160
- formatJsonOutput(result);
161
- }
162
- }
163
- else if (!hasOutputFile) {
164
- // Format list results nicely (non-paginated)
165
- formatNonPaginatedResults(result, resolvedParams.limit, hasUserSpecifiedLimit, shouldUseJson, schema, sdkMethodName);
166
- }
167
- else if (hasOutputFile) {
168
- // Show success message for file output instead of printing generated content
169
- console.log(chalk.green(`āœ… ${cliCommandName} completed successfully!`));
170
- console.log(chalk.gray(`Output written to: ${resolvedParams.output}`));
171
- }
172
- }
173
- }
174
- catch (error) {
175
- // Handle Zod validation errors more gracefully
176
- if (error instanceof Error && error.message.includes('"code"')) {
177
- try {
178
- const validationErrors = JSON.parse(error.message);
179
- console.error(chalk.red("āŒ Validation Error:"));
180
- validationErrors.forEach((err) => {
181
- const field = err.path?.join(".") || "unknown";
182
- console.error(chalk.yellow(` • ${field}: ${err.message}`));
183
- });
184
- console.error("\n" + chalk.dim(`Use --help to see available options`));
185
- }
186
- catch {
187
- console.error(chalk.red("Error:"), error.message);
188
- }
189
- }
190
- else {
191
- console.error(chalk.red("Error:"), error instanceof Error ? error.message : "Unknown error");
192
- }
193
- process.exit(1);
194
- }
195
- };
196
- return {
197
- description,
198
- parameters,
199
- handler,
200
- };
201
- }
202
- function addCommand(program, commandName, config) {
203
- const command = program.command(commandName).description(config.description);
204
- // Add parameters to command
205
- config.parameters.forEach((param) => {
206
- // Convert camelCase to kebab-case for CLI display
207
- const kebabName = param.name.replace(/([A-Z])/g, "-$1").toLowerCase();
208
- if (param.hasResolver && param.required) {
209
- // Required parameters with resolvers become optional positional arguments (resolver handles prompting)
210
- command.argument(`[${kebabName}]`, param.description || `${kebabName} parameter`);
211
- }
212
- else if (param.required) {
213
- // Required parameters without resolvers become required positional arguments
214
- command.argument(`<${kebabName}>`, param.description || `${kebabName} parameter`);
215
- }
216
- else if (param.isPositional) {
217
- // Optional parameters marked as positional become optional positional arguments
218
- command.argument(`[${kebabName}]`, param.description || `${kebabName} parameter`);
219
- }
220
- else {
221
- // Optional parameters become flags (whether they have resolvers or not)
222
- const flags = [`--${kebabName}`];
223
- if (param.type === "boolean") {
224
- command.option(flags.join(", "), param.description);
225
- }
226
- else {
227
- const flagSignature = flags.join(", ") + ` <${param.type}>`;
228
- command.option(flagSignature, param.description, param.default);
229
- }
230
- }
231
- });
232
- // Add formatting options for all commands
233
- command.option("--json", "Output raw JSON instead of formatted results");
234
- command.action(config.handler);
235
- }
236
- // ============================================================================
237
- // Parameter Conversion
238
- // ============================================================================
239
- function convertCliArgsToSdkParams(parameters, positionalArgs, options) {
240
- const sdkParams = {};
241
- // Handle positional arguments (required parameters or optional positional parameters)
242
- let argIndex = 0;
243
- parameters.forEach((param) => {
244
- if ((param.required || param.isPositional) &&
245
- argIndex < positionalArgs.length) {
246
- // Use the original camelCase parameter name for the SDK
247
- sdkParams[param.name] = convertValue(positionalArgs[argIndex], param.type);
248
- argIndex++;
249
- }
250
- });
251
- // Handle option flags
252
- Object.entries(options).forEach(([key, value]) => {
253
- // Convert kebab-case back to camelCase
254
- const camelKey = key.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
255
- const param = parameters.find((p) => p.name === camelKey);
256
- if (param && value !== undefined) {
257
- sdkParams[camelKey] = convertValue(value, param.type);
258
- }
259
- });
260
- return sdkParams;
261
- }
262
- function convertValue(value, type) {
263
- switch (type) {
264
- case "number":
265
- return Number(value);
266
- case "boolean":
267
- return Boolean(value);
268
- case "array":
269
- return Array.isArray(value) ? value : [value];
270
- case "string":
271
- default:
272
- // Handle JSON string for objects
273
- if (typeof value === "string" &&
274
- (value.startsWith("{") || value.startsWith("["))) {
275
- try {
276
- return JSON.parse(value);
277
- }
278
- catch {
279
- return value;
280
- }
281
- }
282
- return value;
283
- }
284
- }
285
- // ============================================================================
286
- // Pagination Handlers
287
- // ============================================================================
288
- async function handlePaginatedList(sdkMethodName, baseParams, sdk, schema) {
289
- const limit = baseParams.limit || 20;
290
- const itemName = getItemNameFromMethod(sdkMethodName);
291
- console.log(chalk.blue(`šŸ“‹ Fetching ${itemName}...`));
292
- const pager = createPager({
293
- pageSize: Math.min(limit, 20),
294
- itemName,
295
- });
296
- const displayFunction = (items, totalShown, totalAvailable) => {
297
- // Only clear screen if we have items to show
298
- if (items.length > 0) {
299
- console.clear();
300
- }
301
- console.log(chalk.blue(`šŸ“‹ ${getListTitleFromMethod(sdkMethodName)}\n`));
302
- if (items.length === 0) {
303
- console.log(chalk.yellow(`No ${itemName} found.`));
304
- return;
305
- }
306
- // Use schema for formatting
307
- if (schema) {
308
- formatItemsFromSchema(schema, items);
309
- }
310
- else {
311
- // Fallback to generic formatting
312
- formatItemsGeneric(items);
313
- }
314
- const totalInfo = totalAvailable
315
- ? ` of ${totalAvailable.toLocaleString()} total`
316
- : "";
317
- console.log(chalk.green(`\nāœ… Showing ${totalShown}${totalInfo} ${itemName}`));
318
- };
319
- await pager.paginate((params) => sdk[sdkMethodName]({
320
- ...baseParams,
321
- ...params,
322
- }), {}, displayFunction);
323
- }
324
- function formatNonPaginatedResults(result, requestedLimit, userSpecifiedLimit, useRawJson, schema, methodName) {
325
- if (!Array.isArray(result)) {
326
- if (useRawJson) {
327
- console.log(JSON.stringify(result, null, 2));
328
- }
329
- else {
330
- formatJsonOutput(result);
331
- }
332
- return;
333
- }
334
- if (useRawJson) {
335
- console.log(JSON.stringify(result, null, 2));
336
- return;
337
- }
338
- const itemName = methodName ? getItemNameFromMethod(methodName) : "items";
339
- if (result.length === 0) {
340
- console.log(chalk.yellow(`No ${itemName} found.`));
341
- return;
342
- }
343
- console.log(chalk.green(`\nāœ… Found ${result.length} ${itemName}:\n`));
344
- // Use schema for formatting
345
- if (schema) {
346
- formatItemsFromSchema(schema, result);
347
- }
348
- else {
349
- // Fallback to generic formatting
350
- formatItemsGeneric(result);
351
- }
352
- // Show appropriate status message
353
- if (userSpecifiedLimit && requestedLimit) {
354
- console.log(chalk.gray(`\nšŸ“„ Showing up to ${requestedLimit} ${itemName} (--limit ${requestedLimit})`));
355
- }
356
- else {
357
- console.log(chalk.gray(`\nšŸ“„ All available ${itemName} shown`));
358
- }
359
- }
360
- function formatItemsGeneric(items) {
361
- // Fallback formatting for items without schema metadata
362
- items.forEach((item, index) => {
363
- const name = item.name || item.key || item.id || "Item";
364
- console.log(`${chalk.gray(`${index + 1}.`)} ${chalk.cyan(name)}`);
365
- if (item.description) {
366
- console.log(` ${chalk.dim(item.description)}`);
367
- }
368
- console.log();
369
- });
370
- }
371
- // Generic helper functions that infer from schema description or method name
372
- function getItemNameFromMethod(methodName) {
373
- // Extract from method name: listApps -> apps, listActions -> actions
374
- const listMatch = methodName.match(/^list(.+)$/);
375
- if (listMatch) {
376
- return listMatch[1].toLowerCase();
377
- }
378
- // Fallback to generic
379
- return "items";
380
- }
381
- function getListTitleFromMethod(methodName) {
382
- const itemName = getItemNameFromMethod(methodName);
383
- if (itemName === "items")
384
- return "Available Items";
385
- // Capitalize first letter: apps -> Apps
386
- const capitalized = itemName.charAt(0).toUpperCase() + itemName.slice(1);
387
- return `Available ${capitalized}`;
388
- }
@@ -1,5 +0,0 @@
1
- export declare const ZAPIER_BASE = "https://zapier.com";
2
- export declare const LOGIN_CLIENT_ID = "K5eEnRE9TTmSFATdkkWhKF8NOKwoiOnYAyIqJjae";
3
- export declare const LOGIN_PORTS: number[];
4
- export declare const LOGIN_TIMEOUT_MS = 300000;
5
- export declare const AUTH_MODE_HEADER = "X-Auth";
@@ -1,6 +0,0 @@
1
- export const ZAPIER_BASE = "https://zapier.com";
2
- // OAuth client ID for zapier-sdk CLI
3
- export const LOGIN_CLIENT_ID = "K5eEnRE9TTmSFATdkkWhKF8NOKwoiOnYAyIqJjae";
4
- export const LOGIN_PORTS = [49505, 50575, 52804, 55981, 61010, 63851];
5
- export const LOGIN_TIMEOUT_MS = 300000; // 5 minutes
6
- export const AUTH_MODE_HEADER = "X-Auth";
@@ -1,6 +0,0 @@
1
- declare const getCallablePromise: <T>() => {
2
- promise: Promise<T>;
3
- resolve: (value: T) => void;
4
- reject: (reason: unknown) => void;
5
- };
6
- export default getCallablePromise;
@@ -1,14 +0,0 @@
1
- const getCallablePromise = () => {
2
- let resolve = () => { };
3
- let reject = () => { };
4
- const promise = new Promise((_resolve, _reject) => {
5
- resolve = _resolve;
6
- reject = _reject;
7
- });
8
- return {
9
- promise,
10
- resolve,
11
- reject,
12
- };
13
- };
14
- export default getCallablePromise;
@@ -1,7 +0,0 @@
1
- declare const log: {
2
- info: (message: string, ...args: any[]) => void;
3
- error: (message: string, ...args: any[]) => void;
4
- success: (message: string, ...args: any[]) => void;
5
- warn: (message: string, ...args: any[]) => void;
6
- };
7
- export default log;
package/dist/utils/log.js DELETED
@@ -1,16 +0,0 @@
1
- import chalk from "chalk";
2
- const log = {
3
- info: (message, ...args) => {
4
- console.log(chalk.blue("ℹ"), message, ...args);
5
- },
6
- error: (message, ...args) => {
7
- console.error(chalk.red("āœ–"), message, ...args);
8
- },
9
- success: (message, ...args) => {
10
- console.log(chalk.green("āœ“"), message, ...args);
11
- },
12
- warn: (message, ...args) => {
13
- console.log(chalk.yellow("⚠"), message, ...args);
14
- },
15
- };
16
- export default log;
@@ -1,48 +0,0 @@
1
- export interface PagerOptions {
2
- pageSize?: number;
3
- showPrompt?: boolean;
4
- itemName?: string;
5
- }
6
- export interface PaginatedResult<T> {
7
- items: T[];
8
- hasMore: boolean;
9
- totalShown: number;
10
- }
11
- /**
12
- * Generic pager that handles pagination for any data source
13
- * Supports interactive "load more" functionality
14
- */
15
- export declare class Pager<T> {
16
- private pageSize;
17
- private showPrompt;
18
- private itemName;
19
- private allItems;
20
- private currentOffset;
21
- constructor(options?: PagerOptions);
22
- /**
23
- * Fetch and display paginated results with interactive loading
24
- */
25
- paginate<TParams>(fetchFunction: (params: TParams & {
26
- limit: number;
27
- offset?: number;
28
- }) => Promise<T[]>, baseParams: TParams, displayFunction: (items: T[], totalShown: number, totalAvailable?: number) => void): Promise<PaginatedResult<T>>;
29
- /**
30
- * Reset the pager state
31
- */
32
- reset(): void;
33
- }
34
- /**
35
- * Convenience function to create a pager for a specific use case
36
- */
37
- export declare function createPager<T>(options?: PagerOptions): Pager<T>;
38
- /**
39
- * Simple pagination without interactivity - just fetches all results up to a limit
40
- */
41
- export declare function fetchAllPages<T, TParams>(fetchFunction: (params: TParams & {
42
- limit: number;
43
- offset?: number;
44
- }) => Promise<T[]>, baseParams: TParams, maxResults?: number): Promise<T[]>;
45
- /**
46
- * Display helper for showing pagination status
47
- */
48
- export declare function showPaginationStatus(currentCount: number, requestedLimit: number, itemName?: string): void;
@@ -1,137 +0,0 @@
1
- import inquirer from "inquirer";
2
- import chalk from "chalk";
3
- /**
4
- * Generic pager that handles pagination for any data source
5
- * Supports interactive "load more" functionality
6
- */
7
- export class Pager {
8
- constructor(options = {}) {
9
- this.allItems = [];
10
- this.currentOffset = 0;
11
- this.pageSize = options.pageSize || 20;
12
- this.showPrompt = options.showPrompt !== false;
13
- this.itemName = options.itemName || "items";
14
- }
15
- /**
16
- * Fetch and display paginated results with interactive loading
17
- */
18
- async paginate(fetchFunction, baseParams, displayFunction) {
19
- let hasMore = true;
20
- let totalAvailable;
21
- while (hasMore) {
22
- // Fetch next page
23
- const params = {
24
- ...baseParams,
25
- limit: this.pageSize,
26
- offset: this.currentOffset,
27
- };
28
- try {
29
- const items = await fetchFunction(params);
30
- if (items.length === 0) {
31
- // Still call display function to show "No items found" message
32
- displayFunction(this.allItems, this.allItems.length, totalAvailable);
33
- hasMore = false;
34
- break;
35
- }
36
- // Check for pagination metadata to get total count
37
- const pagination = items.__pagination;
38
- if (pagination && pagination.count) {
39
- totalAvailable = pagination.count;
40
- hasMore = pagination.hasNext;
41
- }
42
- else {
43
- // Fallback: check if we got fewer items than requested
44
- hasMore = items.length >= this.pageSize;
45
- }
46
- // Add to our collection
47
- this.allItems.push(...items);
48
- this.currentOffset += items.length;
49
- // Display current batch
50
- displayFunction(this.allItems, this.allItems.length, totalAvailable);
51
- // If prompting is disabled, continue automatically
52
- if (!this.showPrompt) {
53
- continue;
54
- }
55
- // If we have total count info, show more detailed prompt
56
- const totalInfo = totalAvailable
57
- ? ` of ${totalAvailable.toLocaleString()}`
58
- : "";
59
- const message = `Load more ${this.itemName}? (${this.allItems.length}${totalInfo} shown so far)`;
60
- // Ask user if they want to load more
61
- const { loadMore } = await inquirer.prompt([
62
- {
63
- type: "confirm",
64
- name: "loadMore",
65
- message,
66
- default: true,
67
- },
68
- ]);
69
- if (!loadMore) {
70
- hasMore = false;
71
- }
72
- }
73
- catch (error) {
74
- // Re-throw the error to be handled by the caller
75
- throw error;
76
- }
77
- }
78
- return {
79
- items: this.allItems,
80
- hasMore: this.currentOffset > 0 && hasMore,
81
- totalShown: this.allItems.length,
82
- };
83
- }
84
- /**
85
- * Reset the pager state
86
- */
87
- reset() {
88
- this.allItems = [];
89
- this.currentOffset = 0;
90
- }
91
- }
92
- /**
93
- * Convenience function to create a pager for a specific use case
94
- */
95
- export function createPager(options = {}) {
96
- return new Pager(options);
97
- }
98
- /**
99
- * Simple pagination without interactivity - just fetches all results up to a limit
100
- */
101
- export async function fetchAllPages(fetchFunction, baseParams, maxResults = 100) {
102
- const pageSize = Math.min(maxResults, 50); // Reasonable page size
103
- const allItems = [];
104
- let offset = 0;
105
- while (allItems.length < maxResults) {
106
- const remainingItems = maxResults - allItems.length;
107
- const currentPageSize = Math.min(pageSize, remainingItems);
108
- const params = {
109
- ...baseParams,
110
- limit: currentPageSize,
111
- offset,
112
- };
113
- const items = await fetchFunction(params);
114
- if (items.length === 0) {
115
- break; // No more data
116
- }
117
- allItems.push(...items);
118
- offset += items.length;
119
- // If we got fewer items than requested, we've reached the end
120
- if (items.length < currentPageSize) {
121
- break;
122
- }
123
- }
124
- return allItems;
125
- }
126
- /**
127
- * Display helper for showing pagination status
128
- */
129
- export function showPaginationStatus(currentCount, requestedLimit, itemName = "items") {
130
- if (currentCount >= requestedLimit) {
131
- console.log(chalk.yellow(`\nšŸ“„ Showing first ${currentCount} ${itemName} (limit: ${requestedLimit})`));
132
- console.log(chalk.gray(`Use --limit to increase the limit, or add paging with --page`));
133
- }
134
- else {
135
- console.log(chalk.gray(`\nšŸ“„ Showing all ${currentCount} ${itemName}`));
136
- }
137
- }
@@ -1,13 +0,0 @@
1
- import { z } from "zod";
2
- import { ZapierSdk } from "@zapier/zapier-sdk";
3
- export declare class SchemaParameterResolver {
4
- resolveParameters(schema: z.ZodSchema, providedParams: any, sdk: ZapierSdk): Promise<any>;
5
- private extractParametersFromSchema;
6
- private analyzeFieldSchema;
7
- private createResolvableParameter;
8
- private resolveParameter;
9
- private getNestedValue;
10
- private setNestedValue;
11
- private promptForField;
12
- private isUserCancellation;
13
- }