@zapier/zapier-sdk-cli 0.0.1 → 0.0.3
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/dist/cli.js +3 -3
- package/dist/utils/cli-generator.d.ts +2 -2
- package/dist/utils/cli-generator.js +26 -26
- package/dist/utils/parameter-resolver.d.ts +2 -2
- package/dist/utils/schema-formatter.js +3 -3
- package/package.json +2 -2
- package/src/cli.ts +4 -4
- package/src/utils/cli-generator.ts +38 -39
- package/src/utils/parameter-resolver.ts +3 -3
- package/src/utils/schema-formatter.ts +1 -1
- package/test/cli.test.ts +16 -16
- package/tsconfig.json +1 -2
package/dist/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const commander_1 = require("commander");
|
|
5
|
-
const
|
|
5
|
+
const zapier_sdk_1 = require("@zapier/zapier-sdk");
|
|
6
6
|
const cli_generator_1 = require("./utils/cli-generator");
|
|
7
7
|
const program = new commander_1.Command();
|
|
8
8
|
program
|
|
@@ -14,12 +14,12 @@ program
|
|
|
14
14
|
const isDebugMode = process.env.DEBUG === "true" || process.argv.includes("--debug");
|
|
15
15
|
// Create SDK instance for CLI operations
|
|
16
16
|
// Auth will be resolved from environment variables or command options
|
|
17
|
-
const sdk = (0,
|
|
17
|
+
const sdk = (0, zapier_sdk_1.createActionsSdk)({
|
|
18
18
|
// Token will be picked up from ZAPIER_TOKEN env var or provided via options
|
|
19
19
|
debug: isDebugMode,
|
|
20
20
|
});
|
|
21
21
|
// Generate CLI commands from SDK schemas
|
|
22
|
-
(0, cli_generator_1.
|
|
22
|
+
(0, cli_generator_1.generateCliCommands)(program, sdk);
|
|
23
23
|
// Add enhanced help information
|
|
24
24
|
(0, cli_generator_1.enhanceCommandHelp)(program);
|
|
25
25
|
program.parse();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
import {
|
|
3
|
-
export declare function
|
|
2
|
+
import { ActionsSdk } from "@zapier/zapier-sdk";
|
|
3
|
+
export declare function generateCliCommands(program: Command, sdk: ActionsSdk): void;
|
|
4
4
|
export declare function enhanceCommandHelp(program: Command): void;
|
|
@@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.generateCliCommands = generateCliCommands;
|
|
7
7
|
exports.enhanceCommandHelp = enhanceCommandHelp;
|
|
8
8
|
const zod_1 = require("zod");
|
|
9
|
-
const
|
|
9
|
+
const zapier_sdk_1 = require("@zapier/zapier-sdk");
|
|
10
10
|
const parameter_resolver_1 = require("./parameter-resolver");
|
|
11
11
|
const pager_1 = require("./pager");
|
|
12
12
|
const schema_formatter_1 = require("./schema-formatter");
|
|
@@ -15,7 +15,7 @@ const util_1 = __importDefault(require("util"));
|
|
|
15
15
|
// ============================================================================
|
|
16
16
|
// JSON Formatting
|
|
17
17
|
// ============================================================================
|
|
18
|
-
function
|
|
18
|
+
function formatJsonOutput(data) {
|
|
19
19
|
// Show success message for action results
|
|
20
20
|
if (data &&
|
|
21
21
|
typeof data === "object" &&
|
|
@@ -94,14 +94,14 @@ function analyzeZodField(name, schema) {
|
|
|
94
94
|
// ============================================================================
|
|
95
95
|
// CLI Command Generation
|
|
96
96
|
// ============================================================================
|
|
97
|
-
function
|
|
98
|
-
// Check if
|
|
99
|
-
if (!
|
|
100
|
-
console.error("
|
|
97
|
+
function generateCliCommands(program, sdk) {
|
|
98
|
+
// Check if SdkSchemas is available
|
|
99
|
+
if (!zapier_sdk_1.SdkSchemas) {
|
|
100
|
+
console.error("SdkSchemas not available");
|
|
101
101
|
return;
|
|
102
102
|
}
|
|
103
103
|
// Generate namespace commands (apps, actions, auths, fields)
|
|
104
|
-
Object.entries(
|
|
104
|
+
Object.entries(zapier_sdk_1.SdkSchemas).forEach(([namespace, methods]) => {
|
|
105
105
|
if (namespace === "generate" || namespace === "bundle") {
|
|
106
106
|
// Handle root tools separately
|
|
107
107
|
return;
|
|
@@ -117,12 +117,12 @@ function generateCLICommands(program, sdk) {
|
|
|
117
117
|
}
|
|
118
118
|
});
|
|
119
119
|
// Generate root tool commands
|
|
120
|
-
if (
|
|
121
|
-
const generateConfig = createCommandConfig("", "generate",
|
|
120
|
+
if (zapier_sdk_1.SdkSchemas.generate) {
|
|
121
|
+
const generateConfig = createCommandConfig("", "generate", zapier_sdk_1.SdkSchemas.generate, sdk);
|
|
122
122
|
addSubCommand(program, "generate", generateConfig);
|
|
123
123
|
}
|
|
124
|
-
if (
|
|
125
|
-
const bundleConfig = createCommandConfig("", "bundle",
|
|
124
|
+
if (zapier_sdk_1.SdkSchemas.bundle) {
|
|
125
|
+
const bundleConfig = createCommandConfig("", "bundle", zapier_sdk_1.SdkSchemas.bundle, sdk);
|
|
126
126
|
addSubCommand(program, "bundle", bundleConfig);
|
|
127
127
|
}
|
|
128
128
|
}
|
|
@@ -139,13 +139,13 @@ function createCommandConfig(namespace, method, schema, sdk) {
|
|
|
139
139
|
const hasPaginationParams = parameters.some((p) => p.name === "limit" || p.name === "offset");
|
|
140
140
|
const hasUserSpecifiedLimit = "limit" in options && options.limit !== undefined;
|
|
141
141
|
const shouldUsePaging = isListCommand && hasPaginationParams && !hasUserSpecifiedLimit;
|
|
142
|
-
const
|
|
142
|
+
const shouldUseJson = options.json;
|
|
143
143
|
// Convert CLI args to SDK method parameters
|
|
144
|
-
const rawParams =
|
|
144
|
+
const rawParams = convertCliArgsToSdkParams(parameters, args.slice(0, -1), options);
|
|
145
145
|
// NEW: Resolve missing parameters interactively using schema metadata
|
|
146
146
|
const resolver = new parameter_resolver_1.SchemaParameterResolver();
|
|
147
147
|
const resolvedParams = await resolver.resolveParameters(schema, rawParams, sdk);
|
|
148
|
-
if (shouldUsePaging && !
|
|
148
|
+
if (shouldUsePaging && !shouldUseJson) {
|
|
149
149
|
// Use interactive paging for list commands
|
|
150
150
|
await handlePaginatedList(namespace, method, resolvedParams, sdk);
|
|
151
151
|
}
|
|
@@ -164,18 +164,18 @@ function createCommandConfig(namespace, method, schema, sdk) {
|
|
|
164
164
|
const isRootCommandWithOutput = namespace === "" && (method === "generate" || method === "bundle");
|
|
165
165
|
const hasOutputFile = isRootCommandWithOutput && resolvedParams.output;
|
|
166
166
|
// Output result (JSON or formatted)
|
|
167
|
-
if (!hasOutputFile && (
|
|
167
|
+
if (!hasOutputFile && (shouldUseJson || !isListCommand)) {
|
|
168
168
|
// Use raw JSON if --json flag is specified, otherwise use pretty formatting
|
|
169
|
-
if (
|
|
169
|
+
if (shouldUseJson) {
|
|
170
170
|
console.log(JSON.stringify(result, null, 2));
|
|
171
171
|
}
|
|
172
172
|
else {
|
|
173
|
-
|
|
173
|
+
formatJsonOutput(result);
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
else if (!hasOutputFile) {
|
|
177
177
|
// Format list results nicely (non-paginated)
|
|
178
|
-
formatNonPaginatedResults(namespace, result, resolvedParams.limit, hasUserSpecifiedLimit,
|
|
178
|
+
formatNonPaginatedResults(namespace, result, resolvedParams.limit, hasUserSpecifiedLimit, shouldUseJson);
|
|
179
179
|
}
|
|
180
180
|
else if (hasOutputFile) {
|
|
181
181
|
// Show success message for file output instead of printing generated content
|
|
@@ -228,7 +228,7 @@ function addSubCommand(parentCommand, name, config) {
|
|
|
228
228
|
// ============================================================================
|
|
229
229
|
// Parameter Conversion
|
|
230
230
|
// ============================================================================
|
|
231
|
-
function
|
|
231
|
+
function convertCliArgsToSdkParams(parameters, positionalArgs, options) {
|
|
232
232
|
const sdkParams = {};
|
|
233
233
|
// Handle positional arguments (required parameters only, whether they have resolvers or not)
|
|
234
234
|
let argIndex = 0;
|
|
@@ -294,7 +294,7 @@ async function handlePaginatedList(namespace, method, baseParams, sdk) {
|
|
|
294
294
|
return;
|
|
295
295
|
}
|
|
296
296
|
// Get the schema for this namespace/method to extract formatting info
|
|
297
|
-
const schema =
|
|
297
|
+
const schema = zapier_sdk_1.SdkSchemas[namespace];
|
|
298
298
|
const listSchema = schema && typeof schema === "object" && "list" in schema
|
|
299
299
|
? schema.list
|
|
300
300
|
: null;
|
|
@@ -315,17 +315,17 @@ async function handlePaginatedList(namespace, method, baseParams, sdk) {
|
|
|
315
315
|
...params,
|
|
316
316
|
}), {}, displayFunction);
|
|
317
317
|
}
|
|
318
|
-
function formatNonPaginatedResults(namespace, result, requestedLimit, userSpecifiedLimit,
|
|
318
|
+
function formatNonPaginatedResults(namespace, result, requestedLimit, userSpecifiedLimit, useRawJson) {
|
|
319
319
|
if (!Array.isArray(result)) {
|
|
320
|
-
if (
|
|
320
|
+
if (useRawJson) {
|
|
321
321
|
console.log(JSON.stringify(result, null, 2));
|
|
322
322
|
}
|
|
323
323
|
else {
|
|
324
|
-
|
|
324
|
+
formatJsonOutput(result);
|
|
325
325
|
}
|
|
326
326
|
return;
|
|
327
327
|
}
|
|
328
|
-
if (
|
|
328
|
+
if (useRawJson) {
|
|
329
329
|
console.log(JSON.stringify(result, null, 2));
|
|
330
330
|
return;
|
|
331
331
|
}
|
|
@@ -336,7 +336,7 @@ function formatNonPaginatedResults(namespace, result, requestedLimit, userSpecif
|
|
|
336
336
|
}
|
|
337
337
|
console.log(chalk_1.default.green(`\n✅ Found ${result.length} ${itemName}:\n`));
|
|
338
338
|
// Get the schema for this namespace/method to extract formatting info
|
|
339
|
-
const schema =
|
|
339
|
+
const schema = zapier_sdk_1.SdkSchemas[namespace];
|
|
340
340
|
const listSchema = schema && typeof schema === "object" && "list" in schema
|
|
341
341
|
? schema.list
|
|
342
342
|
: null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { ActionsSdk } from "@zapier/zapier-sdk";
|
|
3
3
|
export declare class SchemaParameterResolver {
|
|
4
|
-
resolveParameters(schema: z.ZodSchema, providedParams: any, sdk:
|
|
4
|
+
resolveParameters(schema: z.ZodSchema, providedParams: any, sdk: ActionsSdk): Promise<any>;
|
|
5
5
|
private findAllResolvableParameters;
|
|
6
6
|
private findResolvableParameters;
|
|
7
7
|
private analyzeSchema;
|
|
@@ -5,19 +5,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.formatItemsFromSchema = formatItemsFromSchema;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const
|
|
8
|
+
const zapier_sdk_1 = require("@zapier/zapier-sdk");
|
|
9
9
|
// ============================================================================
|
|
10
10
|
// Generic Schema-Driven Formatter
|
|
11
11
|
// ============================================================================
|
|
12
12
|
function formatItemsFromSchema(inputSchema, items) {
|
|
13
13
|
// Get the output schema and its format metadata
|
|
14
|
-
const outputSchema = (0,
|
|
14
|
+
const outputSchema = (0, zapier_sdk_1.getOutputSchema)(inputSchema);
|
|
15
15
|
if (!outputSchema) {
|
|
16
16
|
// Fallback to generic formatting if no output schema
|
|
17
17
|
formatItemsGeneric(items);
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
|
-
const formatMeta = (0,
|
|
20
|
+
const formatMeta = (0, zapier_sdk_1.getFormatMetadata)(outputSchema);
|
|
21
21
|
if (!formatMeta) {
|
|
22
22
|
// Fallback to generic formatting if no format metadata
|
|
23
23
|
formatItemsGeneric(items);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zapier/zapier-sdk-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Command line interface for Zapier SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"inquirer": "^12.6.3",
|
|
26
26
|
"ora": "^8.2.0",
|
|
27
27
|
"zod": "^3.25.67",
|
|
28
|
-
"@zapier/
|
|
28
|
+
"@zapier/zapier-sdk": "0.0.3"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/inquirer": "^9.0.8",
|
package/src/cli.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { Command } from "commander";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { createActionsSdk } from "@zapier/zapier-sdk";
|
|
5
|
+
import { generateCliCommands, enhanceCommandHelp } from "./utils/cli-generator";
|
|
6
6
|
|
|
7
7
|
const program = new Command();
|
|
8
8
|
|
|
@@ -18,13 +18,13 @@ const isDebugMode =
|
|
|
18
18
|
|
|
19
19
|
// Create SDK instance for CLI operations
|
|
20
20
|
// Auth will be resolved from environment variables or command options
|
|
21
|
-
const sdk =
|
|
21
|
+
const sdk = createActionsSdk({
|
|
22
22
|
// Token will be picked up from ZAPIER_TOKEN env var or provided via options
|
|
23
23
|
debug: isDebugMode,
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
// Generate CLI commands from SDK schemas
|
|
27
|
-
|
|
27
|
+
generateCliCommands(program, sdk);
|
|
28
28
|
|
|
29
29
|
// Add enhanced help information
|
|
30
30
|
enhanceCommandHelp(program);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import {
|
|
4
|
-
import { SDKSchemas } from "../../../actions-sdk/dist/schemas";
|
|
3
|
+
import { ActionsSdk, SdkSchemas } from "@zapier/zapier-sdk";
|
|
5
4
|
import { SchemaParameterResolver } from "./parameter-resolver";
|
|
6
5
|
import { createPager } from "./pager";
|
|
7
6
|
import { formatItemsFromSchema } from "./schema-formatter";
|
|
@@ -12,7 +11,7 @@ import util from "util";
|
|
|
12
11
|
// JSON Formatting
|
|
13
12
|
// ============================================================================
|
|
14
13
|
|
|
15
|
-
function
|
|
14
|
+
function formatJsonOutput(data: any): void {
|
|
16
15
|
// Show success message for action results
|
|
17
16
|
if (
|
|
18
17
|
data &&
|
|
@@ -33,13 +32,13 @@ function formatJSONOutput(data: any): void {
|
|
|
33
32
|
// Types
|
|
34
33
|
// ============================================================================
|
|
35
34
|
|
|
36
|
-
interface
|
|
35
|
+
interface CliCommandConfig {
|
|
37
36
|
description: string;
|
|
38
|
-
parameters:
|
|
37
|
+
parameters: CliParameter[];
|
|
39
38
|
handler: (...args: any[]) => Promise<void>;
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
interface
|
|
41
|
+
interface CliParameter {
|
|
43
42
|
name: string;
|
|
44
43
|
type: "string" | "number" | "boolean" | "array";
|
|
45
44
|
required: boolean;
|
|
@@ -53,8 +52,8 @@ interface CLIParameter {
|
|
|
53
52
|
// Schema Analysis
|
|
54
53
|
// ============================================================================
|
|
55
54
|
|
|
56
|
-
function analyzeZodSchema(schema: z.ZodSchema):
|
|
57
|
-
const parameters:
|
|
55
|
+
function analyzeZodSchema(schema: z.ZodSchema): CliParameter[] {
|
|
56
|
+
const parameters: CliParameter[] = [];
|
|
58
57
|
|
|
59
58
|
if (schema instanceof z.ZodObject) {
|
|
60
59
|
const shape = schema.shape;
|
|
@@ -73,7 +72,7 @@ function analyzeZodSchema(schema: z.ZodSchema): CLIParameter[] {
|
|
|
73
72
|
function analyzeZodField(
|
|
74
73
|
name: string,
|
|
75
74
|
schema: z.ZodSchema,
|
|
76
|
-
):
|
|
75
|
+
): CliParameter | null {
|
|
77
76
|
let baseSchema = schema;
|
|
78
77
|
let required = true;
|
|
79
78
|
let defaultValue: any = undefined;
|
|
@@ -91,7 +90,7 @@ function analyzeZodField(
|
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
// Determine parameter type
|
|
94
|
-
let paramType:
|
|
93
|
+
let paramType: CliParameter["type"] = "string";
|
|
95
94
|
let choices: string[] | undefined;
|
|
96
95
|
|
|
97
96
|
if (baseSchema instanceof z.ZodString) {
|
|
@@ -128,15 +127,15 @@ function analyzeZodField(
|
|
|
128
127
|
// CLI Command Generation
|
|
129
128
|
// ============================================================================
|
|
130
129
|
|
|
131
|
-
export function
|
|
132
|
-
// Check if
|
|
133
|
-
if (!
|
|
134
|
-
console.error("
|
|
130
|
+
export function generateCliCommands(program: Command, sdk: ActionsSdk): void {
|
|
131
|
+
// Check if SdkSchemas is available
|
|
132
|
+
if (!SdkSchemas) {
|
|
133
|
+
console.error("SdkSchemas not available");
|
|
135
134
|
return;
|
|
136
135
|
}
|
|
137
136
|
|
|
138
137
|
// Generate namespace commands (apps, actions, auths, fields)
|
|
139
|
-
Object.entries(
|
|
138
|
+
Object.entries(SdkSchemas).forEach(([namespace, methods]) => {
|
|
140
139
|
if (namespace === "generate" || namespace === "bundle") {
|
|
141
140
|
// Handle root tools separately
|
|
142
141
|
return;
|
|
@@ -160,21 +159,21 @@ export function generateCLICommands(program: Command, sdk: ActionsSDK): void {
|
|
|
160
159
|
});
|
|
161
160
|
|
|
162
161
|
// Generate root tool commands
|
|
163
|
-
if (
|
|
162
|
+
if (SdkSchemas.generate) {
|
|
164
163
|
const generateConfig = createCommandConfig(
|
|
165
164
|
"",
|
|
166
165
|
"generate",
|
|
167
|
-
|
|
166
|
+
SdkSchemas.generate,
|
|
168
167
|
sdk,
|
|
169
168
|
);
|
|
170
169
|
addSubCommand(program, "generate", generateConfig);
|
|
171
170
|
}
|
|
172
171
|
|
|
173
|
-
if (
|
|
172
|
+
if (SdkSchemas.bundle) {
|
|
174
173
|
const bundleConfig = createCommandConfig(
|
|
175
174
|
"",
|
|
176
175
|
"bundle",
|
|
177
|
-
|
|
176
|
+
SdkSchemas.bundle,
|
|
178
177
|
sdk,
|
|
179
178
|
);
|
|
180
179
|
addSubCommand(program, "bundle", bundleConfig);
|
|
@@ -185,8 +184,8 @@ function createCommandConfig(
|
|
|
185
184
|
namespace: string,
|
|
186
185
|
method: string,
|
|
187
186
|
schema: z.ZodSchema,
|
|
188
|
-
sdk:
|
|
189
|
-
):
|
|
187
|
+
sdk: ActionsSdk,
|
|
188
|
+
): CliCommandConfig {
|
|
190
189
|
const parameters = analyzeZodSchema(schema);
|
|
191
190
|
const description = schema.description || `${namespace} ${method} command`;
|
|
192
191
|
|
|
@@ -205,10 +204,10 @@ function createCommandConfig(
|
|
|
205
204
|
"limit" in options && options.limit !== undefined;
|
|
206
205
|
const shouldUsePaging =
|
|
207
206
|
isListCommand && hasPaginationParams && !hasUserSpecifiedLimit;
|
|
208
|
-
const
|
|
207
|
+
const shouldUseJson = options.json;
|
|
209
208
|
|
|
210
209
|
// Convert CLI args to SDK method parameters
|
|
211
|
-
const rawParams =
|
|
210
|
+
const rawParams = convertCliArgsToSdkParams(
|
|
212
211
|
parameters,
|
|
213
212
|
args.slice(0, -1),
|
|
214
213
|
options,
|
|
@@ -222,7 +221,7 @@ function createCommandConfig(
|
|
|
222
221
|
sdk,
|
|
223
222
|
);
|
|
224
223
|
|
|
225
|
-
if (shouldUsePaging && !
|
|
224
|
+
if (shouldUsePaging && !shouldUseJson) {
|
|
226
225
|
// Use interactive paging for list commands
|
|
227
226
|
await handlePaginatedList(namespace, method, resolvedParams, sdk);
|
|
228
227
|
} else {
|
|
@@ -242,12 +241,12 @@ function createCommandConfig(
|
|
|
242
241
|
const hasOutputFile = isRootCommandWithOutput && resolvedParams.output;
|
|
243
242
|
|
|
244
243
|
// Output result (JSON or formatted)
|
|
245
|
-
if (!hasOutputFile && (
|
|
244
|
+
if (!hasOutputFile && (shouldUseJson || !isListCommand)) {
|
|
246
245
|
// Use raw JSON if --json flag is specified, otherwise use pretty formatting
|
|
247
|
-
if (
|
|
246
|
+
if (shouldUseJson) {
|
|
248
247
|
console.log(JSON.stringify(result, null, 2));
|
|
249
248
|
} else {
|
|
250
|
-
|
|
249
|
+
formatJsonOutput(result);
|
|
251
250
|
}
|
|
252
251
|
} else if (!hasOutputFile) {
|
|
253
252
|
// Format list results nicely (non-paginated)
|
|
@@ -256,7 +255,7 @@ function createCommandConfig(
|
|
|
256
255
|
result,
|
|
257
256
|
resolvedParams.limit,
|
|
258
257
|
hasUserSpecifiedLimit,
|
|
259
|
-
|
|
258
|
+
shouldUseJson,
|
|
260
259
|
);
|
|
261
260
|
} else if (hasOutputFile) {
|
|
262
261
|
// Show success message for file output instead of printing generated content
|
|
@@ -285,7 +284,7 @@ function createCommandConfig(
|
|
|
285
284
|
function addSubCommand(
|
|
286
285
|
parentCommand: Command,
|
|
287
286
|
name: string,
|
|
288
|
-
config:
|
|
287
|
+
config: CliCommandConfig,
|
|
289
288
|
): void {
|
|
290
289
|
const command = parentCommand.command(name).description(config.description);
|
|
291
290
|
|
|
@@ -328,8 +327,8 @@ function addSubCommand(
|
|
|
328
327
|
// Parameter Conversion
|
|
329
328
|
// ============================================================================
|
|
330
329
|
|
|
331
|
-
function
|
|
332
|
-
parameters:
|
|
330
|
+
function convertCliArgsToSdkParams(
|
|
331
|
+
parameters: CliParameter[],
|
|
333
332
|
positionalArgs: any[],
|
|
334
333
|
options: Record<string, any>,
|
|
335
334
|
): Record<string, any> {
|
|
@@ -361,7 +360,7 @@ function convertCLIArgsToSDKParams(
|
|
|
361
360
|
return sdkParams;
|
|
362
361
|
}
|
|
363
362
|
|
|
364
|
-
function convertValue(value: any, type:
|
|
363
|
+
function convertValue(value: any, type: CliParameter["type"]): any {
|
|
365
364
|
switch (type) {
|
|
366
365
|
case "number":
|
|
367
366
|
return Number(value);
|
|
@@ -394,7 +393,7 @@ async function handlePaginatedList(
|
|
|
394
393
|
namespace: string,
|
|
395
394
|
method: string,
|
|
396
395
|
baseParams: any,
|
|
397
|
-
sdk:
|
|
396
|
+
sdk: ActionsSdk,
|
|
398
397
|
): Promise<void> {
|
|
399
398
|
const limit = baseParams.limit || 20;
|
|
400
399
|
const itemName = getItemName(namespace);
|
|
@@ -423,7 +422,7 @@ async function handlePaginatedList(
|
|
|
423
422
|
}
|
|
424
423
|
|
|
425
424
|
// Get the schema for this namespace/method to extract formatting info
|
|
426
|
-
const schema =
|
|
425
|
+
const schema = SdkSchemas[namespace as keyof typeof SdkSchemas];
|
|
427
426
|
const listSchema =
|
|
428
427
|
schema && typeof schema === "object" && "list" in schema
|
|
429
428
|
? schema.list
|
|
@@ -460,18 +459,18 @@ function formatNonPaginatedResults(
|
|
|
460
459
|
result: any[],
|
|
461
460
|
requestedLimit?: number,
|
|
462
461
|
userSpecifiedLimit?: boolean,
|
|
463
|
-
|
|
462
|
+
useRawJson?: boolean,
|
|
464
463
|
): void {
|
|
465
464
|
if (!Array.isArray(result)) {
|
|
466
|
-
if (
|
|
465
|
+
if (useRawJson) {
|
|
467
466
|
console.log(JSON.stringify(result, null, 2));
|
|
468
467
|
} else {
|
|
469
|
-
|
|
468
|
+
formatJsonOutput(result);
|
|
470
469
|
}
|
|
471
470
|
return;
|
|
472
471
|
}
|
|
473
472
|
|
|
474
|
-
if (
|
|
473
|
+
if (useRawJson) {
|
|
475
474
|
console.log(JSON.stringify(result, null, 2));
|
|
476
475
|
return;
|
|
477
476
|
}
|
|
@@ -486,7 +485,7 @@ function formatNonPaginatedResults(
|
|
|
486
485
|
console.log(chalk.green(`\n✅ Found ${result.length} ${itemName}:\n`));
|
|
487
486
|
|
|
488
487
|
// Get the schema for this namespace/method to extract formatting info
|
|
489
|
-
const schema =
|
|
488
|
+
const schema = SdkSchemas[namespace as keyof typeof SdkSchemas];
|
|
490
489
|
const listSchema =
|
|
491
490
|
schema && typeof schema === "object" && "list" in schema
|
|
492
491
|
? schema.list
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import inquirer from "inquirer";
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import {
|
|
4
|
+
import { ActionsSdk } from "@zapier/zapier-sdk";
|
|
5
5
|
|
|
6
6
|
// For editor-like prompts, we'll use a regular input prompt with multiline support
|
|
7
7
|
|
|
@@ -19,7 +19,7 @@ interface ResolvableParameter {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
interface ResolverContext {
|
|
22
|
-
sdk:
|
|
22
|
+
sdk: ActionsSdk;
|
|
23
23
|
currentParams: any;
|
|
24
24
|
resolvedParams: any;
|
|
25
25
|
}
|
|
@@ -32,7 +32,7 @@ export class SchemaParameterResolver {
|
|
|
32
32
|
async resolveParameters(
|
|
33
33
|
schema: z.ZodSchema,
|
|
34
34
|
providedParams: any,
|
|
35
|
-
sdk:
|
|
35
|
+
sdk: ActionsSdk,
|
|
36
36
|
): Promise<any> {
|
|
37
37
|
// 1. Try to parse with current parameters
|
|
38
38
|
const parseResult = schema.safeParse(providedParams);
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
getFormatMetadata,
|
|
5
5
|
getOutputSchema,
|
|
6
6
|
type FormatMetadata,
|
|
7
|
-
} from "
|
|
7
|
+
} from "@zapier/zapier-sdk";
|
|
8
8
|
|
|
9
9
|
// ============================================================================
|
|
10
10
|
// Generic Schema-Driven Formatter
|
package/test/cli.test.ts
CHANGED
|
@@ -3,44 +3,44 @@ import { execSync } from "child_process";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
|
|
5
5
|
describe("Zapier CLI", () => {
|
|
6
|
-
const cliPath = path.join(__dirname, "../bin/zapier.js");
|
|
6
|
+
const cliPath = path.join(__dirname, "../bin/zapier-sdk.js");
|
|
7
7
|
|
|
8
8
|
it("should show help when called with --help", () => {
|
|
9
9
|
const output = execSync(`node ${cliPath} --help`, { encoding: "utf8" });
|
|
10
10
|
|
|
11
11
|
expect(output).toContain("CLI for Zapier SDK");
|
|
12
12
|
expect(output).toContain("Commands:");
|
|
13
|
-
expect(output).toContain("
|
|
13
|
+
expect(output).toContain("apps");
|
|
14
|
+
expect(output).toContain("actions");
|
|
14
15
|
});
|
|
15
16
|
|
|
16
|
-
it("should show
|
|
17
|
-
const output = execSync(`node ${cliPath}
|
|
17
|
+
it("should show apps help when called with apps --help", () => {
|
|
18
|
+
const output = execSync(`node ${cliPath} apps --help`, {
|
|
18
19
|
encoding: "utf8",
|
|
19
20
|
});
|
|
20
21
|
|
|
21
|
-
expect(output).toContain("
|
|
22
|
-
expect(output).toContain("
|
|
23
|
-
expect(output).toContain("
|
|
22
|
+
expect(output).toContain("apps management commands");
|
|
23
|
+
expect(output).toContain("list");
|
|
24
|
+
expect(output).toContain("get");
|
|
24
25
|
});
|
|
25
26
|
|
|
26
|
-
it("should show
|
|
27
|
-
const output = execSync(`node ${cliPath}
|
|
27
|
+
it("should show apps list help when called with apps list --help", () => {
|
|
28
|
+
const output = execSync(`node ${cliPath} apps list --help`, {
|
|
28
29
|
encoding: "utf8",
|
|
29
30
|
});
|
|
30
31
|
|
|
31
|
-
expect(output).toContain("List all available apps");
|
|
32
32
|
expect(output).toContain("--category");
|
|
33
33
|
expect(output).toContain("--limit");
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
it("should show
|
|
37
|
-
const output = execSync(`node ${cliPath}
|
|
36
|
+
it("should show actions help when called with actions --help", () => {
|
|
37
|
+
const output = execSync(`node ${cliPath} actions --help`, {
|
|
38
38
|
encoding: "utf8",
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
expect(output).toContain("
|
|
42
|
-
expect(output).toContain("
|
|
43
|
-
expect(output).toContain("
|
|
44
|
-
expect(output).toContain("
|
|
41
|
+
expect(output).toContain("actions management commands");
|
|
42
|
+
expect(output).toContain("list");
|
|
43
|
+
expect(output).toContain("get");
|
|
44
|
+
expect(output).toContain("run");
|
|
45
45
|
});
|
|
46
46
|
});
|
package/tsconfig.json
CHANGED
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
"outDir": "./dist",
|
|
14
14
|
"rootDir": "./src",
|
|
15
15
|
"paths": {
|
|
16
|
-
"@zapier/
|
|
17
|
-
"@zapier/actions-sdk": ["../actions-sdk/src/sdk.ts"]
|
|
16
|
+
"@zapier/zapier-sdk": ["../zapier-sdk/src/index.ts"]
|
|
18
17
|
}
|
|
19
18
|
},
|
|
20
19
|
"include": ["src/**/*"],
|