@zapier/zapier-sdk-cli 0.24.4 → 0.25.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 +15 -0
- package/README.md +13 -14
- package/dist/cli.cjs +94 -18
- package/dist/cli.mjs +94 -18
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/package.json +1 -1
- package/dist/src/utils/cli-generator.js +100 -10
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @zapier/zapier-sdk-cli
|
|
2
2
|
|
|
3
|
+
## 0.25.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- d72cda1: Deprecates request() in favor of self-contained fetch(). The fetch plugin now handles URL-to-relay transformation, header normalization,
|
|
8
|
+
and body content-type inference directly instead of delegating to request. The request plugin is preserved as a backward-compatible
|
|
9
|
+
shim that forwards to fetch. CLI and MCP now expose a fetch command via a new inputParameters registry concept for
|
|
10
|
+
multi-positional-argument functions.
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [d72cda1]
|
|
15
|
+
- @zapier/zapier-sdk-mcp@0.8.0
|
|
16
|
+
- @zapier/zapier-sdk@0.24.0
|
|
17
|
+
|
|
3
18
|
## 0.24.4
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
- [`delete-client-credentials`](#delete-client-credentials)
|
|
31
31
|
- [`list-client-credentials`](#list-client-credentials)
|
|
32
32
|
- [HTTP Requests](#http-requests)
|
|
33
|
-
- [`
|
|
33
|
+
- [`fetch`](#fetch)
|
|
34
34
|
- [Utilities](#utilities)
|
|
35
35
|
- [`add`](#add)
|
|
36
36
|
- [`build-manifest`](#build-manifest)
|
|
@@ -423,27 +423,26 @@ npx zapier-sdk list-client-credentials [--page-size] [--max-items] [--cursor]
|
|
|
423
423
|
|
|
424
424
|
### HTTP Requests
|
|
425
425
|
|
|
426
|
-
#### `
|
|
426
|
+
#### `fetch`
|
|
427
427
|
|
|
428
|
-
Make authenticated HTTP requests through Zapier's Relay service
|
|
428
|
+
Make authenticated HTTP requests to any API through Zapier's Relay service. Pass an authenticationId to automatically inject the user's stored credentials (OAuth tokens, API keys, etc.) into the outgoing request. Mirrors the native fetch(url, init?) signature with additional Zapier-specific options.
|
|
429
429
|
|
|
430
430
|
**Options:**
|
|
431
431
|
|
|
432
|
-
| Option | Type
|
|
433
|
-
| --------------------------- |
|
|
434
|
-
| `<url>` | `string`
|
|
435
|
-
| `--method` | `string`
|
|
436
|
-
| `--
|
|
437
|
-
| `--
|
|
438
|
-
| `--
|
|
439
|
-
| `--
|
|
440
|
-
| `--
|
|
441
|
-
| `--relay-base-url` | `string` | ❌ | — | — | Base URL for Relay service |
|
|
432
|
+
| Option | Type | Required | Default | Possible Values | Description |
|
|
433
|
+
| --------------------------- | ------------------------ | -------- | ------- | ---------------------------------------------------------- | --------------------------------------------------------------------------------- |
|
|
434
|
+
| `<url>` | `string, custom` | ✅ | — | — | The full URL of the API endpoint to call (proxied through Zapier's Relay service) |
|
|
435
|
+
| `--method` | `string` | ❌ | — | `GET`, `POST`, `PUT`, `DELETE`, `PATCH`, `HEAD`, `OPTIONS` | HTTP method for the request (defaults to GET) |
|
|
436
|
+
| `--headers` | `object` | ❌ | — | — | HTTP headers to include in the request |
|
|
437
|
+
| `--body` | `string, custom, custom` | ❌ | — | — | Request body — JSON strings are auto-detected and Content-Type is set accordingly |
|
|
438
|
+
| `--authentication-id` | `string, number` | ❌ | — | — | Authentication ID to use for this action |
|
|
439
|
+
| `--callback-url` | `string` | ❌ | — | — | URL to send async response to (makes request async) |
|
|
440
|
+
| `--authentication-template` | `string` | ❌ | — | — | Optional JSON string authentication template to bypass Notary lookup |
|
|
442
441
|
|
|
443
442
|
**Usage:**
|
|
444
443
|
|
|
445
444
|
```bash
|
|
446
|
-
npx zapier-sdk
|
|
445
|
+
npx zapier-sdk fetch <url> [--method] [--headers] [--body] [--authentication-id] [--callback-url] [--authentication-template]
|
|
447
446
|
```
|
|
448
447
|
|
|
449
448
|
### Utilities
|
package/dist/cli.cjs
CHANGED
|
@@ -977,6 +977,65 @@ function analyzeZodField(name, schema, functionInfo) {
|
|
|
977
977
|
isPositional: zapierSdk.isPositional(schema)
|
|
978
978
|
};
|
|
979
979
|
}
|
|
980
|
+
function analyzeInputParameters(inputParameters, functionInfo) {
|
|
981
|
+
const cliParams = [];
|
|
982
|
+
for (const param of inputParameters) {
|
|
983
|
+
let schema = param.schema;
|
|
984
|
+
let isOptional = false;
|
|
985
|
+
if (schema instanceof zod.z.ZodOptional) {
|
|
986
|
+
isOptional = true;
|
|
987
|
+
schema = schema._zod.def.innerType;
|
|
988
|
+
}
|
|
989
|
+
if (schema instanceof zod.z.ZodObject) {
|
|
990
|
+
const shape = schema.shape;
|
|
991
|
+
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
992
|
+
const analyzed = analyzeZodField(
|
|
993
|
+
key,
|
|
994
|
+
fieldSchema,
|
|
995
|
+
functionInfo
|
|
996
|
+
);
|
|
997
|
+
if (analyzed) {
|
|
998
|
+
if (isOptional) {
|
|
999
|
+
analyzed.required = false;
|
|
1000
|
+
}
|
|
1001
|
+
cliParams.push(analyzed);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
} else {
|
|
1005
|
+
const analyzed = analyzeZodField(param.name, param.schema, functionInfo);
|
|
1006
|
+
if (analyzed) {
|
|
1007
|
+
analyzed.required = !isOptional;
|
|
1008
|
+
analyzed.isPositional = true;
|
|
1009
|
+
cliParams.push(analyzed);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
return cliParams;
|
|
1014
|
+
}
|
|
1015
|
+
function reconstructPositionalArgs(inputParameters, flatParams) {
|
|
1016
|
+
const args = [];
|
|
1017
|
+
for (const param of inputParameters) {
|
|
1018
|
+
let schema = param.schema;
|
|
1019
|
+
if (schema instanceof zod.z.ZodOptional) {
|
|
1020
|
+
schema = schema._zod.def.innerType;
|
|
1021
|
+
}
|
|
1022
|
+
if (schema instanceof zod.z.ZodObject) {
|
|
1023
|
+
const shape = schema.shape;
|
|
1024
|
+
const obj = {};
|
|
1025
|
+
let hasValues = false;
|
|
1026
|
+
for (const key of Object.keys(shape)) {
|
|
1027
|
+
if (key in flatParams && flatParams[key] !== void 0) {
|
|
1028
|
+
obj[key] = flatParams[key];
|
|
1029
|
+
hasValues = true;
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
args.push(hasValues ? obj : void 0);
|
|
1033
|
+
} else {
|
|
1034
|
+
args.push(flatParams[param.name]);
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
return args;
|
|
1038
|
+
}
|
|
980
1039
|
function toKebabCase(str) {
|
|
981
1040
|
return str.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
982
1041
|
}
|
|
@@ -990,7 +1049,7 @@ function generateCliCommands(program2, sdk2) {
|
|
|
990
1049
|
}
|
|
991
1050
|
const registry = sdk2.getRegistry({ package: "cli" });
|
|
992
1051
|
registry.functions.forEach((fnInfo) => {
|
|
993
|
-
if (!fnInfo.inputSchema) {
|
|
1052
|
+
if (!fnInfo.inputSchema && !fnInfo.inputParameters) {
|
|
994
1053
|
console.warn(`Schema not found for ${fnInfo.name}`);
|
|
995
1054
|
return;
|
|
996
1055
|
}
|
|
@@ -1060,9 +1119,10 @@ function generateCliCommands(program2, sdk2) {
|
|
|
1060
1119
|
});
|
|
1061
1120
|
}
|
|
1062
1121
|
function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
1122
|
+
const usesInputParameters = !functionInfo.inputSchema && !!functionInfo.inputParameters;
|
|
1063
1123
|
const schema = functionInfo.inputSchema;
|
|
1064
|
-
const parameters = analyzeZodSchema(schema, functionInfo);
|
|
1065
|
-
const description =
|
|
1124
|
+
const parameters = usesInputParameters ? analyzeInputParameters(functionInfo.inputParameters, functionInfo) : analyzeZodSchema(schema, functionInfo);
|
|
1125
|
+
const description = functionInfo.description || schema?.description || `${cliCommandName} command`;
|
|
1066
1126
|
const handler = async (...args) => {
|
|
1067
1127
|
try {
|
|
1068
1128
|
const commandObj = args[args.length - 1];
|
|
@@ -1078,13 +1138,18 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
|
1078
1138
|
args.slice(0, -1),
|
|
1079
1139
|
options
|
|
1080
1140
|
);
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1141
|
+
let resolvedParams;
|
|
1142
|
+
if (schema && !usesInputParameters) {
|
|
1143
|
+
const resolver = new SchemaParameterResolver();
|
|
1144
|
+
resolvedParams = await resolver.resolveParameters(
|
|
1145
|
+
schema,
|
|
1146
|
+
rawParams,
|
|
1147
|
+
sdk2,
|
|
1148
|
+
functionInfo.name
|
|
1149
|
+
);
|
|
1150
|
+
} else {
|
|
1151
|
+
resolvedParams = rawParams;
|
|
1152
|
+
}
|
|
1088
1153
|
const confirm = functionInfo.confirm;
|
|
1089
1154
|
let confirmMessageAfter;
|
|
1090
1155
|
if (confirm && !shouldUseJson) {
|
|
@@ -1106,16 +1171,26 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
|
1106
1171
|
} else {
|
|
1107
1172
|
const hasOutputFile = resolvedParams.output;
|
|
1108
1173
|
if (hasOutputFile) {
|
|
1109
|
-
const
|
|
1110
|
-
await
|
|
1174
|
+
const sdkObj = sdk2;
|
|
1175
|
+
await sdkObj[functionInfo.name](resolvedParams);
|
|
1111
1176
|
console.log(
|
|
1112
1177
|
chalk3__default.default.green(`\u2705 ${cliCommandName} completed successfully!`)
|
|
1113
1178
|
);
|
|
1114
1179
|
console.log(chalk3__default.default.gray(`Output written to: ${hasOutputFile}`));
|
|
1115
1180
|
return;
|
|
1116
1181
|
}
|
|
1117
|
-
|
|
1118
|
-
|
|
1182
|
+
let result;
|
|
1183
|
+
if (usesInputParameters) {
|
|
1184
|
+
const positionalArgs = reconstructPositionalArgs(
|
|
1185
|
+
functionInfo.inputParameters,
|
|
1186
|
+
resolvedParams
|
|
1187
|
+
);
|
|
1188
|
+
const sdkObj = sdk2;
|
|
1189
|
+
result = await sdkObj[functionInfo.name](...positionalArgs);
|
|
1190
|
+
} else {
|
|
1191
|
+
const sdkObj = sdk2;
|
|
1192
|
+
result = await sdkObj[functionInfo.name](resolvedParams);
|
|
1193
|
+
}
|
|
1119
1194
|
if (result instanceof Response) {
|
|
1120
1195
|
const response = result;
|
|
1121
1196
|
let body;
|
|
@@ -1196,11 +1271,12 @@ ${confirmMessageAfter}`));
|
|
|
1196
1271
|
return {
|
|
1197
1272
|
description,
|
|
1198
1273
|
parameters,
|
|
1199
|
-
handler
|
|
1274
|
+
handler,
|
|
1275
|
+
hidden: functionInfo.categories?.includes("deprecated") ?? false
|
|
1200
1276
|
};
|
|
1201
1277
|
}
|
|
1202
1278
|
function addCommand(program2, commandName, config2) {
|
|
1203
|
-
const command = program2.command(commandName).description(config2.description);
|
|
1279
|
+
const command = program2.command(commandName, { hidden: config2.hidden ?? false }).description(config2.description);
|
|
1204
1280
|
let hasPositionalArray = false;
|
|
1205
1281
|
config2.parameters.forEach((param) => {
|
|
1206
1282
|
const kebabName = param.name.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
@@ -1698,7 +1774,7 @@ var LoginSchema = zod.z.object({
|
|
|
1698
1774
|
|
|
1699
1775
|
// package.json
|
|
1700
1776
|
var package_default = {
|
|
1701
|
-
version: "0.
|
|
1777
|
+
version: "0.25.0"};
|
|
1702
1778
|
|
|
1703
1779
|
// src/telemetry/builders.ts
|
|
1704
1780
|
function createCliBaseEvent(context = {}) {
|
|
@@ -2979,7 +3055,7 @@ function createZapierCliSdk(options = {}) {
|
|
|
2979
3055
|
// package.json with { type: 'json' }
|
|
2980
3056
|
var package_default2 = {
|
|
2981
3057
|
name: "@zapier/zapier-sdk-cli",
|
|
2982
|
-
version: "0.
|
|
3058
|
+
version: "0.25.0"};
|
|
2983
3059
|
function detectPackageManager(cwd = process.cwd()) {
|
|
2984
3060
|
const ua = process.env.npm_config_user_agent;
|
|
2985
3061
|
if (ua) {
|
package/dist/cli.mjs
CHANGED
|
@@ -941,6 +941,65 @@ function analyzeZodField(name, schema, functionInfo) {
|
|
|
941
941
|
isPositional: isPositional(schema)
|
|
942
942
|
};
|
|
943
943
|
}
|
|
944
|
+
function analyzeInputParameters(inputParameters, functionInfo) {
|
|
945
|
+
const cliParams = [];
|
|
946
|
+
for (const param of inputParameters) {
|
|
947
|
+
let schema = param.schema;
|
|
948
|
+
let isOptional = false;
|
|
949
|
+
if (schema instanceof z.ZodOptional) {
|
|
950
|
+
isOptional = true;
|
|
951
|
+
schema = schema._zod.def.innerType;
|
|
952
|
+
}
|
|
953
|
+
if (schema instanceof z.ZodObject) {
|
|
954
|
+
const shape = schema.shape;
|
|
955
|
+
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
956
|
+
const analyzed = analyzeZodField(
|
|
957
|
+
key,
|
|
958
|
+
fieldSchema,
|
|
959
|
+
functionInfo
|
|
960
|
+
);
|
|
961
|
+
if (analyzed) {
|
|
962
|
+
if (isOptional) {
|
|
963
|
+
analyzed.required = false;
|
|
964
|
+
}
|
|
965
|
+
cliParams.push(analyzed);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
} else {
|
|
969
|
+
const analyzed = analyzeZodField(param.name, param.schema, functionInfo);
|
|
970
|
+
if (analyzed) {
|
|
971
|
+
analyzed.required = !isOptional;
|
|
972
|
+
analyzed.isPositional = true;
|
|
973
|
+
cliParams.push(analyzed);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
return cliParams;
|
|
978
|
+
}
|
|
979
|
+
function reconstructPositionalArgs(inputParameters, flatParams) {
|
|
980
|
+
const args = [];
|
|
981
|
+
for (const param of inputParameters) {
|
|
982
|
+
let schema = param.schema;
|
|
983
|
+
if (schema instanceof z.ZodOptional) {
|
|
984
|
+
schema = schema._zod.def.innerType;
|
|
985
|
+
}
|
|
986
|
+
if (schema instanceof z.ZodObject) {
|
|
987
|
+
const shape = schema.shape;
|
|
988
|
+
const obj = {};
|
|
989
|
+
let hasValues = false;
|
|
990
|
+
for (const key of Object.keys(shape)) {
|
|
991
|
+
if (key in flatParams && flatParams[key] !== void 0) {
|
|
992
|
+
obj[key] = flatParams[key];
|
|
993
|
+
hasValues = true;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
args.push(hasValues ? obj : void 0);
|
|
997
|
+
} else {
|
|
998
|
+
args.push(flatParams[param.name]);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
return args;
|
|
1002
|
+
}
|
|
944
1003
|
function toKebabCase(str) {
|
|
945
1004
|
return str.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
946
1005
|
}
|
|
@@ -954,7 +1013,7 @@ function generateCliCommands(program2, sdk2) {
|
|
|
954
1013
|
}
|
|
955
1014
|
const registry = sdk2.getRegistry({ package: "cli" });
|
|
956
1015
|
registry.functions.forEach((fnInfo) => {
|
|
957
|
-
if (!fnInfo.inputSchema) {
|
|
1016
|
+
if (!fnInfo.inputSchema && !fnInfo.inputParameters) {
|
|
958
1017
|
console.warn(`Schema not found for ${fnInfo.name}`);
|
|
959
1018
|
return;
|
|
960
1019
|
}
|
|
@@ -1024,9 +1083,10 @@ function generateCliCommands(program2, sdk2) {
|
|
|
1024
1083
|
});
|
|
1025
1084
|
}
|
|
1026
1085
|
function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
1086
|
+
const usesInputParameters = !functionInfo.inputSchema && !!functionInfo.inputParameters;
|
|
1027
1087
|
const schema = functionInfo.inputSchema;
|
|
1028
|
-
const parameters = analyzeZodSchema(schema, functionInfo);
|
|
1029
|
-
const description =
|
|
1088
|
+
const parameters = usesInputParameters ? analyzeInputParameters(functionInfo.inputParameters, functionInfo) : analyzeZodSchema(schema, functionInfo);
|
|
1089
|
+
const description = functionInfo.description || schema?.description || `${cliCommandName} command`;
|
|
1030
1090
|
const handler = async (...args) => {
|
|
1031
1091
|
try {
|
|
1032
1092
|
const commandObj = args[args.length - 1];
|
|
@@ -1042,13 +1102,18 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
|
1042
1102
|
args.slice(0, -1),
|
|
1043
1103
|
options
|
|
1044
1104
|
);
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1105
|
+
let resolvedParams;
|
|
1106
|
+
if (schema && !usesInputParameters) {
|
|
1107
|
+
const resolver = new SchemaParameterResolver();
|
|
1108
|
+
resolvedParams = await resolver.resolveParameters(
|
|
1109
|
+
schema,
|
|
1110
|
+
rawParams,
|
|
1111
|
+
sdk2,
|
|
1112
|
+
functionInfo.name
|
|
1113
|
+
);
|
|
1114
|
+
} else {
|
|
1115
|
+
resolvedParams = rawParams;
|
|
1116
|
+
}
|
|
1052
1117
|
const confirm = functionInfo.confirm;
|
|
1053
1118
|
let confirmMessageAfter;
|
|
1054
1119
|
if (confirm && !shouldUseJson) {
|
|
@@ -1070,16 +1135,26 @@ function createCommandConfig(cliCommandName, functionInfo, sdk2) {
|
|
|
1070
1135
|
} else {
|
|
1071
1136
|
const hasOutputFile = resolvedParams.output;
|
|
1072
1137
|
if (hasOutputFile) {
|
|
1073
|
-
const
|
|
1074
|
-
await
|
|
1138
|
+
const sdkObj = sdk2;
|
|
1139
|
+
await sdkObj[functionInfo.name](resolvedParams);
|
|
1075
1140
|
console.log(
|
|
1076
1141
|
chalk3.green(`\u2705 ${cliCommandName} completed successfully!`)
|
|
1077
1142
|
);
|
|
1078
1143
|
console.log(chalk3.gray(`Output written to: ${hasOutputFile}`));
|
|
1079
1144
|
return;
|
|
1080
1145
|
}
|
|
1081
|
-
|
|
1082
|
-
|
|
1146
|
+
let result;
|
|
1147
|
+
if (usesInputParameters) {
|
|
1148
|
+
const positionalArgs = reconstructPositionalArgs(
|
|
1149
|
+
functionInfo.inputParameters,
|
|
1150
|
+
resolvedParams
|
|
1151
|
+
);
|
|
1152
|
+
const sdkObj = sdk2;
|
|
1153
|
+
result = await sdkObj[functionInfo.name](...positionalArgs);
|
|
1154
|
+
} else {
|
|
1155
|
+
const sdkObj = sdk2;
|
|
1156
|
+
result = await sdkObj[functionInfo.name](resolvedParams);
|
|
1157
|
+
}
|
|
1083
1158
|
if (result instanceof Response) {
|
|
1084
1159
|
const response = result;
|
|
1085
1160
|
let body;
|
|
@@ -1160,11 +1235,12 @@ ${confirmMessageAfter}`));
|
|
|
1160
1235
|
return {
|
|
1161
1236
|
description,
|
|
1162
1237
|
parameters,
|
|
1163
|
-
handler
|
|
1238
|
+
handler,
|
|
1239
|
+
hidden: functionInfo.categories?.includes("deprecated") ?? false
|
|
1164
1240
|
};
|
|
1165
1241
|
}
|
|
1166
1242
|
function addCommand(program2, commandName, config2) {
|
|
1167
|
-
const command = program2.command(commandName).description(config2.description);
|
|
1243
|
+
const command = program2.command(commandName, { hidden: config2.hidden ?? false }).description(config2.description);
|
|
1168
1244
|
let hasPositionalArray = false;
|
|
1169
1245
|
config2.parameters.forEach((param) => {
|
|
1170
1246
|
const kebabName = param.name.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
@@ -1662,7 +1738,7 @@ var LoginSchema = z.object({
|
|
|
1662
1738
|
|
|
1663
1739
|
// package.json
|
|
1664
1740
|
var package_default = {
|
|
1665
|
-
version: "0.
|
|
1741
|
+
version: "0.25.0"};
|
|
1666
1742
|
|
|
1667
1743
|
// src/telemetry/builders.ts
|
|
1668
1744
|
function createCliBaseEvent(context = {}) {
|
|
@@ -2943,7 +3019,7 @@ function createZapierCliSdk(options = {}) {
|
|
|
2943
3019
|
// package.json with { type: 'json' }
|
|
2944
3020
|
var package_default2 = {
|
|
2945
3021
|
name: "@zapier/zapier-sdk-cli",
|
|
2946
|
-
version: "0.
|
|
3022
|
+
version: "0.25.0"};
|
|
2947
3023
|
function detectPackageManager(cwd = process.cwd()) {
|
|
2948
3024
|
const ua = process.env.npm_config_user_agent;
|
|
2949
3025
|
if (ua) {
|
package/dist/index.cjs
CHANGED
package/dist/index.mjs
CHANGED
package/dist/package.json
CHANGED
|
@@ -122,6 +122,74 @@ function analyzeZodField(name, schema, functionInfo) {
|
|
|
122
122
|
isPositional: isPositional(schema),
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Analyze inputParameters (used by multi-parameter functions like fetch) into flat CLI parameters.
|
|
127
|
+
* Simple-type params become positional args; object-type params have their properties flattened into flags.
|
|
128
|
+
*/
|
|
129
|
+
function analyzeInputParameters(inputParameters, functionInfo) {
|
|
130
|
+
const cliParams = [];
|
|
131
|
+
for (const param of inputParameters) {
|
|
132
|
+
let schema = param.schema;
|
|
133
|
+
let isOptional = false;
|
|
134
|
+
// Unwrap optional wrapper
|
|
135
|
+
if (schema instanceof z.ZodOptional) {
|
|
136
|
+
isOptional = true;
|
|
137
|
+
schema = schema._zod.def.innerType;
|
|
138
|
+
}
|
|
139
|
+
if (schema instanceof z.ZodObject) {
|
|
140
|
+
// Flatten object properties into individual CLI flags
|
|
141
|
+
const shape = schema.shape;
|
|
142
|
+
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
143
|
+
const analyzed = analyzeZodField(key, fieldSchema, functionInfo);
|
|
144
|
+
if (analyzed) {
|
|
145
|
+
if (isOptional) {
|
|
146
|
+
analyzed.required = false;
|
|
147
|
+
}
|
|
148
|
+
cliParams.push(analyzed);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
// Simple type — treat as positional argument
|
|
154
|
+
const analyzed = analyzeZodField(param.name, param.schema, functionInfo);
|
|
155
|
+
if (analyzed) {
|
|
156
|
+
analyzed.required = !isOptional;
|
|
157
|
+
analyzed.isPositional = true;
|
|
158
|
+
cliParams.push(analyzed);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return cliParams;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Reconstruct positional arguments for SDK invocation from a flat params record.
|
|
166
|
+
* Used when calling multi-parameter SDK functions (inputParameters) from the CLI.
|
|
167
|
+
*/
|
|
168
|
+
function reconstructPositionalArgs(inputParameters, flatParams) {
|
|
169
|
+
const args = [];
|
|
170
|
+
for (const param of inputParameters) {
|
|
171
|
+
let schema = param.schema;
|
|
172
|
+
if (schema instanceof z.ZodOptional) {
|
|
173
|
+
schema = schema._zod.def.innerType;
|
|
174
|
+
}
|
|
175
|
+
if (schema instanceof z.ZodObject) {
|
|
176
|
+
const shape = schema.shape;
|
|
177
|
+
const obj = {};
|
|
178
|
+
let hasValues = false;
|
|
179
|
+
for (const key of Object.keys(shape)) {
|
|
180
|
+
if (key in flatParams && flatParams[key] !== undefined) {
|
|
181
|
+
obj[key] = flatParams[key];
|
|
182
|
+
hasValues = true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
args.push(hasValues ? obj : undefined);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
args.push(flatParams[param.name]);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return args;
|
|
192
|
+
}
|
|
125
193
|
// ============================================================================
|
|
126
194
|
// CLI Structure Derivation - Purely Generic
|
|
127
195
|
// ============================================================================
|
|
@@ -151,7 +219,7 @@ export function generateCliCommands(program, sdk) {
|
|
|
151
219
|
const registry = sdk.getRegistry({ package: "cli" });
|
|
152
220
|
// Create all commands first
|
|
153
221
|
registry.functions.forEach((fnInfo) => {
|
|
154
|
-
if (!fnInfo.inputSchema) {
|
|
222
|
+
if (!fnInfo.inputSchema && !fnInfo.inputParameters) {
|
|
155
223
|
console.warn(`Schema not found for ${fnInfo.name}`);
|
|
156
224
|
return;
|
|
157
225
|
}
|
|
@@ -213,9 +281,14 @@ export function generateCliCommands(program, sdk) {
|
|
|
213
281
|
});
|
|
214
282
|
}
|
|
215
283
|
function createCommandConfig(cliCommandName, functionInfo, sdk) {
|
|
284
|
+
const usesInputParameters = !functionInfo.inputSchema && !!functionInfo.inputParameters;
|
|
216
285
|
const schema = functionInfo.inputSchema;
|
|
217
|
-
const parameters =
|
|
218
|
-
|
|
286
|
+
const parameters = usesInputParameters
|
|
287
|
+
? analyzeInputParameters(functionInfo.inputParameters, functionInfo)
|
|
288
|
+
: analyzeZodSchema(schema, functionInfo);
|
|
289
|
+
const description = functionInfo.description ||
|
|
290
|
+
schema?.description ||
|
|
291
|
+
`${cliCommandName} command`;
|
|
219
292
|
const handler = async (...args) => {
|
|
220
293
|
try {
|
|
221
294
|
// The last argument is always the command object with parsed options
|
|
@@ -229,8 +302,15 @@ function createCommandConfig(cliCommandName, functionInfo, sdk) {
|
|
|
229
302
|
// Convert CLI args to SDK method parameters
|
|
230
303
|
const rawParams = convertCliArgsToSdkParams(parameters, args.slice(0, -1), options);
|
|
231
304
|
// Resolve missing parameters interactively using schema metadata
|
|
232
|
-
|
|
233
|
-
|
|
305
|
+
// (only available for inputSchema-based functions)
|
|
306
|
+
let resolvedParams;
|
|
307
|
+
if (schema && !usesInputParameters) {
|
|
308
|
+
const resolver = new SchemaParameterResolver();
|
|
309
|
+
resolvedParams = (await resolver.resolveParameters(schema, rawParams, sdk, functionInfo.name));
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
resolvedParams = rawParams;
|
|
313
|
+
}
|
|
234
314
|
// Check for confirmation before executing (skip for --json mode)
|
|
235
315
|
const confirm = functionInfo.confirm;
|
|
236
316
|
let confirmMessageAfter;
|
|
@@ -256,16 +336,23 @@ function createCommandConfig(cliCommandName, functionInfo, sdk) {
|
|
|
256
336
|
// Special handling for commands that write to files
|
|
257
337
|
const hasOutputFile = resolvedParams.output;
|
|
258
338
|
if (hasOutputFile) {
|
|
259
|
-
// Call the SDK method for file output commands
|
|
260
339
|
const sdkObj = sdk;
|
|
261
340
|
await sdkObj[functionInfo.name](resolvedParams);
|
|
262
341
|
console.log(chalk.green(`✅ ${cliCommandName} completed successfully!`));
|
|
263
342
|
console.log(chalk.gray(`Output written to: ${hasOutputFile}`));
|
|
264
343
|
return;
|
|
265
344
|
}
|
|
266
|
-
//
|
|
267
|
-
|
|
268
|
-
|
|
345
|
+
// Invoke SDK method — reconstruct positional args for inputParameters functions
|
|
346
|
+
let result;
|
|
347
|
+
if (usesInputParameters) {
|
|
348
|
+
const positionalArgs = reconstructPositionalArgs(functionInfo.inputParameters, resolvedParams);
|
|
349
|
+
const sdkObj = sdk;
|
|
350
|
+
result = await sdkObj[functionInfo.name](...positionalArgs);
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
const sdkObj = sdk;
|
|
354
|
+
result = await sdkObj[functionInfo.name](resolvedParams);
|
|
355
|
+
}
|
|
269
356
|
// Handle Response objects by wrapping in a structured envelope
|
|
270
357
|
if (result instanceof Response) {
|
|
271
358
|
const response = result;
|
|
@@ -345,10 +432,13 @@ function createCommandConfig(cliCommandName, functionInfo, sdk) {
|
|
|
345
432
|
description,
|
|
346
433
|
parameters,
|
|
347
434
|
handler,
|
|
435
|
+
hidden: functionInfo.categories?.includes("deprecated") ?? false,
|
|
348
436
|
};
|
|
349
437
|
}
|
|
350
438
|
function addCommand(program, commandName, config) {
|
|
351
|
-
const command = program
|
|
439
|
+
const command = program
|
|
440
|
+
.command(commandName, { hidden: config.hidden ?? false })
|
|
441
|
+
.description(config.description);
|
|
352
442
|
// Track whether we've already used a positional array parameter
|
|
353
443
|
let hasPositionalArray = false;
|
|
354
444
|
// Add parameters to command
|