@zapier/zapier-sdk-cli 0.30.0 → 0.31.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.
- package/CHANGELOG.md +21 -0
- package/README.md +34 -13
- package/dist/cli.cjs +473 -17
- package/dist/cli.mjs +476 -20
- package/dist/index.cjs +434 -2
- package/dist/index.mjs +437 -4
- package/dist/package.json +1 -1
- package/dist/src/cli.js +3 -2
- package/dist/src/plugins/cliOverrides/index.d.ts +21 -0
- package/dist/src/plugins/cliOverrides/index.js +19 -0
- package/dist/src/plugins/curl/index.d.ts +17 -0
- package/dist/src/plugins/curl/index.js +234 -0
- package/dist/src/plugins/curl/schemas.d.ts +39 -0
- package/dist/src/plugins/curl/schemas.js +101 -0
- package/dist/src/plugins/curl/utils.d.ts +24 -0
- package/dist/src/plugins/curl/utils.js +141 -0
- package/dist/src/plugins/index.d.ts +2 -0
- package/dist/src/plugins/index.js +2 -0
- package/dist/src/sdk.js +4 -1
- package/dist/src/utils/cli-generator.js +47 -12
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
package/dist/cli.cjs
CHANGED
|
@@ -963,7 +963,7 @@ function analyzeZodField(name, schema, functionInfo) {
|
|
|
963
963
|
paramType = "string";
|
|
964
964
|
choices = baseSchema.options;
|
|
965
965
|
} else if (baseSchema instanceof zod.z.ZodRecord) {
|
|
966
|
-
paramType = "
|
|
966
|
+
paramType = "object";
|
|
967
967
|
}
|
|
968
968
|
let paramHasResolver = false;
|
|
969
969
|
if (functionInfo?.resolvers?.[name]) {
|
|
@@ -1278,9 +1278,14 @@ ${confirmMessageAfter}`));
|
|
|
1278
1278
|
description,
|
|
1279
1279
|
parameters,
|
|
1280
1280
|
handler,
|
|
1281
|
-
hidden: functionInfo.categories?.includes("deprecated") ?? false
|
|
1281
|
+
hidden: functionInfo.categories?.includes("deprecated") ?? false,
|
|
1282
|
+
aliases: functionInfo.aliases
|
|
1282
1283
|
};
|
|
1283
1284
|
}
|
|
1285
|
+
function collect(value, previous = []) {
|
|
1286
|
+
previous.push(value);
|
|
1287
|
+
return previous;
|
|
1288
|
+
}
|
|
1284
1289
|
function addCommand(program2, commandName, config2) {
|
|
1285
1290
|
const command = program2.command(commandName, { hidden: config2.hidden ?? false }).description(config2.description);
|
|
1286
1291
|
let hasPositionalArray = false;
|
|
@@ -1299,10 +1304,12 @@ function addCommand(program2, commandName, config2) {
|
|
|
1299
1304
|
);
|
|
1300
1305
|
} else if (param.required && param.type === "array") {
|
|
1301
1306
|
const flags = [`--${kebabName}`];
|
|
1302
|
-
const flagSignature = flags.join(", ") + ` <
|
|
1307
|
+
const flagSignature = flags.join(", ") + ` <value>`;
|
|
1303
1308
|
command.requiredOption(
|
|
1304
1309
|
flagSignature,
|
|
1305
|
-
param.description || `${kebabName} parameter (required)
|
|
1310
|
+
param.description || `${kebabName} parameter (required, repeatable)`,
|
|
1311
|
+
collect,
|
|
1312
|
+
[]
|
|
1306
1313
|
);
|
|
1307
1314
|
} else if (param.required) {
|
|
1308
1315
|
command.argument(
|
|
@@ -1315,16 +1322,17 @@ function addCommand(program2, commandName, config2) {
|
|
|
1315
1322
|
param.description || `${kebabName} parameter`
|
|
1316
1323
|
);
|
|
1317
1324
|
} else {
|
|
1318
|
-
const flags = [
|
|
1325
|
+
const flags = [];
|
|
1326
|
+
const alias = config2.aliases?.[param.name];
|
|
1327
|
+
if (alias && alias.length === 1) {
|
|
1328
|
+
flags.push(`-${alias}`);
|
|
1329
|
+
}
|
|
1330
|
+
flags.push(`--${kebabName}`);
|
|
1319
1331
|
if (param.type === "boolean") {
|
|
1320
1332
|
command.option(flags.join(", "), param.description);
|
|
1321
1333
|
} else if (param.type === "array") {
|
|
1322
|
-
const flagSignature = flags.join(", ") + ` <
|
|
1323
|
-
command.option(
|
|
1324
|
-
flagSignature,
|
|
1325
|
-
param.description,
|
|
1326
|
-
param.default
|
|
1327
|
-
);
|
|
1334
|
+
const flagSignature = flags.join(", ") + ` <value>`;
|
|
1335
|
+
command.option(flagSignature, param.description || "", collect, []);
|
|
1328
1336
|
} else {
|
|
1329
1337
|
const flagSignature = flags.join(", ") + ` <${param.type}>`;
|
|
1330
1338
|
command.option(
|
|
@@ -1335,7 +1343,10 @@ function addCommand(program2, commandName, config2) {
|
|
|
1335
1343
|
}
|
|
1336
1344
|
}
|
|
1337
1345
|
});
|
|
1338
|
-
|
|
1346
|
+
const hasJsonParam = config2.parameters.some((p) => p.name === "json");
|
|
1347
|
+
if (!hasJsonParam) {
|
|
1348
|
+
command.option("--json", "Output raw JSON instead of formatted results");
|
|
1349
|
+
}
|
|
1339
1350
|
command.action(config2.handler);
|
|
1340
1351
|
}
|
|
1341
1352
|
function convertCliArgsToSdkParams(parameters, positionalArgs, options) {
|
|
@@ -1354,6 +1365,9 @@ function convertCliArgsToSdkParams(parameters, positionalArgs, options) {
|
|
|
1354
1365
|
const camelKey = key.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
|
|
1355
1366
|
const param = parameters.find((p) => p.name === camelKey);
|
|
1356
1367
|
if (param && value !== void 0) {
|
|
1368
|
+
if (param.type === "array" && Array.isArray(value) && value.length === 0) {
|
|
1369
|
+
return;
|
|
1370
|
+
}
|
|
1357
1371
|
sdkParams[camelKey] = convertValue(value, param.type);
|
|
1358
1372
|
}
|
|
1359
1373
|
});
|
|
@@ -1371,6 +1385,16 @@ function convertValue(value, type) {
|
|
|
1371
1385
|
case "array":
|
|
1372
1386
|
return Array.isArray(value) ? value : [value];
|
|
1373
1387
|
case "string":
|
|
1388
|
+
return value;
|
|
1389
|
+
case "object":
|
|
1390
|
+
if (typeof value === "string") {
|
|
1391
|
+
try {
|
|
1392
|
+
return JSON.parse(value);
|
|
1393
|
+
} catch {
|
|
1394
|
+
return value;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
return value;
|
|
1374
1398
|
default:
|
|
1375
1399
|
if (typeof value === "string" && (value.startsWith("{") || value.startsWith("["))) {
|
|
1376
1400
|
try {
|
|
@@ -1780,7 +1804,7 @@ var LoginSchema = zod.z.object({
|
|
|
1780
1804
|
|
|
1781
1805
|
// package.json
|
|
1782
1806
|
var package_default = {
|
|
1783
|
-
version: "0.
|
|
1807
|
+
version: "0.31.1"};
|
|
1784
1808
|
|
|
1785
1809
|
// src/telemetry/builders.ts
|
|
1786
1810
|
function createCliBaseEvent(context = {}) {
|
|
@@ -3116,18 +3140,450 @@ var feedbackPlugin = ({
|
|
|
3116
3140
|
}
|
|
3117
3141
|
};
|
|
3118
3142
|
};
|
|
3143
|
+
var CurlSchema = zod.z.object({
|
|
3144
|
+
url: zod.z.string().describe("Request URL"),
|
|
3145
|
+
request: zod.z.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]).optional().describe("HTTP method (defaults to GET, or POST if data is provided)"),
|
|
3146
|
+
header: zod.z.array(zod.z.string()).optional().describe("HTTP headers in 'Key: Value' format (repeatable)"),
|
|
3147
|
+
data: zod.z.array(zod.z.string()).optional().describe("HTTP POST data (repeatable, joined with &)"),
|
|
3148
|
+
dataRaw: zod.z.array(zod.z.string()).optional().describe("HTTP POST data without special interpretation (repeatable)"),
|
|
3149
|
+
dataAscii: zod.z.array(zod.z.string()).optional().describe("HTTP POST ASCII data (repeatable)"),
|
|
3150
|
+
dataBinary: zod.z.array(zod.z.string()).optional().describe("HTTP POST binary data (repeatable)"),
|
|
3151
|
+
dataUrlencode: zod.z.array(zod.z.string()).optional().describe("HTTP POST data, URL-encoded (repeatable)"),
|
|
3152
|
+
json: zod.z.string().optional().describe("Send JSON body (sets Content-Type and Accept headers)"),
|
|
3153
|
+
form: zod.z.array(zod.z.string()).optional().describe("Multipart form data as 'name=value' (repeatable)"),
|
|
3154
|
+
formString: zod.z.array(zod.z.string()).optional().describe("Multipart form string field (repeatable)"),
|
|
3155
|
+
get: zod.z.boolean().optional().describe("Force GET method and append data to query string"),
|
|
3156
|
+
head: zod.z.boolean().optional().describe("Fetch headers only (HEAD request)"),
|
|
3157
|
+
location: zod.z.boolean().optional().describe("Follow redirects"),
|
|
3158
|
+
include: zod.z.boolean().optional().describe("Include response headers in output"),
|
|
3159
|
+
output: zod.z.string().optional().describe("Write output to file instead of stdout"),
|
|
3160
|
+
remoteName: zod.z.boolean().optional().describe("Write output to file named like the remote file"),
|
|
3161
|
+
verbose: zod.z.boolean().optional().describe("Verbose output (show request/response headers on stderr)"),
|
|
3162
|
+
silent: zod.z.boolean().optional().describe("Silent mode (suppress errors)"),
|
|
3163
|
+
showError: zod.z.boolean().optional().describe("Show errors even when in silent mode"),
|
|
3164
|
+
fail: zod.z.boolean().optional().describe("Fail silently on HTTP errors (exit code 22)"),
|
|
3165
|
+
failWithBody: zod.z.boolean().optional().describe("Fail on HTTP errors but still output the body"),
|
|
3166
|
+
writeOut: zod.z.string().optional().describe("Output format string after completion (e.g., '%{http_code}')"),
|
|
3167
|
+
maxTime: zod.z.number().optional().describe("Maximum time in seconds for the request"),
|
|
3168
|
+
user: zod.z.string().optional().describe("Basic auth credentials as 'user:password'"),
|
|
3169
|
+
compressed: zod.z.boolean().optional().describe("Request compressed response (sends Accept-Encoding header)"),
|
|
3170
|
+
connectionId: zod.z.union([zod.z.string(), zod.z.number()]).optional().describe("Zapier connection ID for authentication")
|
|
3171
|
+
}).describe("Make HTTP requests through Zapier Relay with curl-like options");
|
|
3172
|
+
var CurlExitError = class extends Error {
|
|
3173
|
+
constructor(message, exitCode) {
|
|
3174
|
+
super(message);
|
|
3175
|
+
this.exitCode = exitCode;
|
|
3176
|
+
this.name = "CurlExitError";
|
|
3177
|
+
}
|
|
3178
|
+
};
|
|
3179
|
+
function parseHeaderLine(input) {
|
|
3180
|
+
const idx = input.indexOf(":");
|
|
3181
|
+
if (idx === -1) {
|
|
3182
|
+
return null;
|
|
3183
|
+
}
|
|
3184
|
+
const key = input.slice(0, idx).trim();
|
|
3185
|
+
const value = input.slice(idx + 1).trim();
|
|
3186
|
+
if (!key) {
|
|
3187
|
+
return null;
|
|
3188
|
+
}
|
|
3189
|
+
return { key, value };
|
|
3190
|
+
}
|
|
3191
|
+
function basicAuthHeader(userpass) {
|
|
3192
|
+
const idx = userpass.indexOf(":");
|
|
3193
|
+
const user = idx === -1 ? userpass : userpass.slice(0, idx);
|
|
3194
|
+
const pass = idx === -1 ? "" : userpass.slice(idx + 1);
|
|
3195
|
+
const token = Buffer.from(`${user}:${pass}`, "utf8").toString("base64");
|
|
3196
|
+
return `Basic ${token}`;
|
|
3197
|
+
}
|
|
3198
|
+
function deriveRemoteFilename(url) {
|
|
3199
|
+
const path2 = url.pathname;
|
|
3200
|
+
const candidate = path2.endsWith("/") ? "index.html" : path.basename(path2);
|
|
3201
|
+
return candidate || "index.html";
|
|
3202
|
+
}
|
|
3203
|
+
function decodeWriteOutEscapes(input) {
|
|
3204
|
+
return input.replace(/\\n/g, "\n").replace(/\\r/g, "\r").replace(/\\t/g, " ");
|
|
3205
|
+
}
|
|
3206
|
+
function formatWriteOut(params) {
|
|
3207
|
+
const { template } = params;
|
|
3208
|
+
const replacements = {
|
|
3209
|
+
"%{http_code}": String(params.httpCode).padStart(3, "0"),
|
|
3210
|
+
"%{time_total}": params.timeTotalSeconds.toFixed(3),
|
|
3211
|
+
"%{size_download}": String(params.sizeDownloadBytes),
|
|
3212
|
+
"%{url_effective}": params.urlEffective,
|
|
3213
|
+
"%{content_type}": params.contentType ?? ""
|
|
3214
|
+
};
|
|
3215
|
+
let out = template;
|
|
3216
|
+
for (const [token, value] of Object.entries(replacements)) {
|
|
3217
|
+
out = out.split(token).join(value);
|
|
3218
|
+
}
|
|
3219
|
+
return decodeWriteOutEscapes(out);
|
|
3220
|
+
}
|
|
3221
|
+
function appendQueryParams(url, dataParts) {
|
|
3222
|
+
const out = new URL(url.toString());
|
|
3223
|
+
for (const part of dataParts) {
|
|
3224
|
+
const segments = part.split("&");
|
|
3225
|
+
for (const seg of segments) {
|
|
3226
|
+
if (!seg) continue;
|
|
3227
|
+
const idx = seg.indexOf("=");
|
|
3228
|
+
if (idx === -1) {
|
|
3229
|
+
out.searchParams.append(seg, "");
|
|
3230
|
+
} else {
|
|
3231
|
+
out.searchParams.append(seg.slice(0, idx), seg.slice(idx + 1));
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
}
|
|
3235
|
+
return out;
|
|
3236
|
+
}
|
|
3237
|
+
async function readAllStdin() {
|
|
3238
|
+
const chunks = [];
|
|
3239
|
+
for await (const chunk of process.stdin) {
|
|
3240
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
3241
|
+
}
|
|
3242
|
+
return Buffer.concat(chunks);
|
|
3243
|
+
}
|
|
3244
|
+
async function resolveDataArgText(raw) {
|
|
3245
|
+
if (!raw.startsWith("@")) {
|
|
3246
|
+
return raw;
|
|
3247
|
+
}
|
|
3248
|
+
const source = raw.slice(1);
|
|
3249
|
+
if (source === "-") {
|
|
3250
|
+
const buf2 = await readAllStdin();
|
|
3251
|
+
return buf2.toString("utf8");
|
|
3252
|
+
}
|
|
3253
|
+
const buf = await fs.promises.readFile(source);
|
|
3254
|
+
return buf.toString("utf8");
|
|
3255
|
+
}
|
|
3256
|
+
async function resolveDataArgBinary(raw) {
|
|
3257
|
+
if (!raw.startsWith("@")) {
|
|
3258
|
+
return Buffer.from(raw, "utf8");
|
|
3259
|
+
}
|
|
3260
|
+
const source = raw.slice(1);
|
|
3261
|
+
if (source === "-") {
|
|
3262
|
+
return await readAllStdin();
|
|
3263
|
+
}
|
|
3264
|
+
return await fs.promises.readFile(source);
|
|
3265
|
+
}
|
|
3266
|
+
async function buildFormData(formArgs, formStringArgs) {
|
|
3267
|
+
if (typeof FormData === "undefined") {
|
|
3268
|
+
throw new CurlExitError(
|
|
3269
|
+
"FormData is not available in this runtime; cannot use --form.",
|
|
3270
|
+
2
|
|
3271
|
+
);
|
|
3272
|
+
}
|
|
3273
|
+
const fd = new FormData();
|
|
3274
|
+
const addField = async (item, forceString) => {
|
|
3275
|
+
const idx = item.indexOf("=");
|
|
3276
|
+
if (idx === -1) {
|
|
3277
|
+
throw new CurlExitError(
|
|
3278
|
+
`Invalid form field: '${item}'. Expected 'name=value' or 'name=@file'.`,
|
|
3279
|
+
2
|
|
3280
|
+
);
|
|
3281
|
+
}
|
|
3282
|
+
const name = item.slice(0, idx);
|
|
3283
|
+
const value = item.slice(idx + 1);
|
|
3284
|
+
if (!name) {
|
|
3285
|
+
throw new CurlExitError(
|
|
3286
|
+
`Invalid form field: '${item}'. Field name cannot be empty.`,
|
|
3287
|
+
2
|
|
3288
|
+
);
|
|
3289
|
+
}
|
|
3290
|
+
if (!forceString && value.startsWith("@")) {
|
|
3291
|
+
const filePath = value.slice(1);
|
|
3292
|
+
const buf = filePath === "-" ? await readAllStdin() : await fs.promises.readFile(filePath);
|
|
3293
|
+
if (typeof Blob === "undefined") {
|
|
3294
|
+
fd.append(name, buf.toString("utf8"));
|
|
3295
|
+
return;
|
|
3296
|
+
}
|
|
3297
|
+
const blob = new Blob([buf]);
|
|
3298
|
+
const filename = filePath === "-" ? `stdin-${crypto.createHash("sha1").update(buf).digest("hex").slice(0, 8)}` : path.basename(filePath);
|
|
3299
|
+
fd.append(name, blob, filename);
|
|
3300
|
+
return;
|
|
3301
|
+
}
|
|
3302
|
+
fd.append(name, value);
|
|
3303
|
+
};
|
|
3304
|
+
for (const item of formArgs) {
|
|
3305
|
+
await addField(item, false);
|
|
3306
|
+
}
|
|
3307
|
+
for (const item of formStringArgs) {
|
|
3308
|
+
await addField(item, true);
|
|
3309
|
+
}
|
|
3310
|
+
return fd;
|
|
3311
|
+
}
|
|
3312
|
+
|
|
3313
|
+
// src/plugins/curl/index.ts
|
|
3314
|
+
var curlPlugin = ({
|
|
3315
|
+
sdk: sdk2
|
|
3316
|
+
}) => {
|
|
3317
|
+
async function curl(options) {
|
|
3318
|
+
const {
|
|
3319
|
+
url: rawUrl,
|
|
3320
|
+
request,
|
|
3321
|
+
header = [],
|
|
3322
|
+
data = [],
|
|
3323
|
+
dataRaw = [],
|
|
3324
|
+
dataAscii = [],
|
|
3325
|
+
dataBinary = [],
|
|
3326
|
+
dataUrlencode = [],
|
|
3327
|
+
json,
|
|
3328
|
+
form = [],
|
|
3329
|
+
formString = [],
|
|
3330
|
+
get: forceGet,
|
|
3331
|
+
head: forceHead,
|
|
3332
|
+
location,
|
|
3333
|
+
include,
|
|
3334
|
+
output,
|
|
3335
|
+
remoteName,
|
|
3336
|
+
verbose,
|
|
3337
|
+
silent,
|
|
3338
|
+
showError,
|
|
3339
|
+
fail,
|
|
3340
|
+
failWithBody,
|
|
3341
|
+
writeOut,
|
|
3342
|
+
maxTime,
|
|
3343
|
+
user,
|
|
3344
|
+
compressed,
|
|
3345
|
+
connectionId
|
|
3346
|
+
} = options;
|
|
3347
|
+
const parsedUrl = new URL(rawUrl);
|
|
3348
|
+
const headers = {};
|
|
3349
|
+
for (const h of header) {
|
|
3350
|
+
const parsed = parseHeaderLine(h);
|
|
3351
|
+
if (parsed) {
|
|
3352
|
+
headers[parsed.key] = parsed.value;
|
|
3353
|
+
}
|
|
3354
|
+
}
|
|
3355
|
+
if (user) {
|
|
3356
|
+
headers["Authorization"] = basicAuthHeader(user);
|
|
3357
|
+
}
|
|
3358
|
+
if (compressed) {
|
|
3359
|
+
headers["Accept-Encoding"] = "gzip, deflate, br";
|
|
3360
|
+
}
|
|
3361
|
+
const rawTextDataArgs = [...data, ...dataRaw, ...dataAscii];
|
|
3362
|
+
const rawBinaryDataArgs = [...dataBinary];
|
|
3363
|
+
const rawUrlencodeArgs = [...dataUrlencode];
|
|
3364
|
+
const hasForm = form.length > 0 || formString.length > 0;
|
|
3365
|
+
const hasJson = json !== void 0;
|
|
3366
|
+
const hasAnyData = hasJson || hasForm || rawTextDataArgs.length > 0 || rawBinaryDataArgs.length > 0 || rawUrlencodeArgs.length > 0;
|
|
3367
|
+
let method = "GET";
|
|
3368
|
+
if (forceHead) {
|
|
3369
|
+
method = "HEAD";
|
|
3370
|
+
} else if (request) {
|
|
3371
|
+
method = request;
|
|
3372
|
+
} else if (forceGet) {
|
|
3373
|
+
method = "GET";
|
|
3374
|
+
} else if (hasAnyData) {
|
|
3375
|
+
method = "POST";
|
|
3376
|
+
}
|
|
3377
|
+
let body;
|
|
3378
|
+
let effectiveUrl = parsedUrl;
|
|
3379
|
+
if (hasJson) {
|
|
3380
|
+
if (!headers["Content-Type"]) {
|
|
3381
|
+
headers["Content-Type"] = "application/json";
|
|
3382
|
+
}
|
|
3383
|
+
if (!headers["Accept"]) {
|
|
3384
|
+
headers["Accept"] = "application/json";
|
|
3385
|
+
}
|
|
3386
|
+
body = json;
|
|
3387
|
+
} else if (hasForm) {
|
|
3388
|
+
body = await buildFormData(form, formString);
|
|
3389
|
+
} else {
|
|
3390
|
+
const resolvedTextParts = [];
|
|
3391
|
+
for (const raw of rawTextDataArgs) {
|
|
3392
|
+
resolvedTextParts.push(await resolveDataArgText(raw));
|
|
3393
|
+
}
|
|
3394
|
+
const resolvedUrlEncodeParts = [];
|
|
3395
|
+
for (const raw of rawUrlencodeArgs) {
|
|
3396
|
+
if (raw.startsWith("@")) {
|
|
3397
|
+
const content = await resolveDataArgText(raw);
|
|
3398
|
+
resolvedUrlEncodeParts.push(encodeURIComponent(content));
|
|
3399
|
+
continue;
|
|
3400
|
+
}
|
|
3401
|
+
const atIdx = raw.indexOf("@");
|
|
3402
|
+
const eqIdx = raw.indexOf("=");
|
|
3403
|
+
if (eqIdx !== -1) {
|
|
3404
|
+
const key = raw.slice(0, eqIdx);
|
|
3405
|
+
const value = raw.slice(eqIdx + 1);
|
|
3406
|
+
resolvedUrlEncodeParts.push(
|
|
3407
|
+
`${encodeURIComponent(key)}=${encodeURIComponent(value)}`
|
|
3408
|
+
);
|
|
3409
|
+
} else if (atIdx !== -1) {
|
|
3410
|
+
const key = raw.slice(0, atIdx);
|
|
3411
|
+
const filePath = raw.slice(atIdx + 1);
|
|
3412
|
+
const buf2 = filePath === "-" ? await readAllStdin() : await fs.promises.readFile(filePath);
|
|
3413
|
+
resolvedUrlEncodeParts.push(
|
|
3414
|
+
`${encodeURIComponent(key)}=${encodeURIComponent(buf2.toString("utf8"))}`
|
|
3415
|
+
);
|
|
3416
|
+
} else {
|
|
3417
|
+
resolvedUrlEncodeParts.push(encodeURIComponent(raw));
|
|
3418
|
+
}
|
|
3419
|
+
}
|
|
3420
|
+
const resolvedBinaryParts = [];
|
|
3421
|
+
for (const raw of rawBinaryDataArgs) {
|
|
3422
|
+
resolvedBinaryParts.push(await resolveDataArgBinary(raw));
|
|
3423
|
+
}
|
|
3424
|
+
const allTextParts = [...resolvedTextParts, ...resolvedUrlEncodeParts];
|
|
3425
|
+
if (forceGet && allTextParts.length > 0) {
|
|
3426
|
+
effectiveUrl = appendQueryParams(parsedUrl, allTextParts);
|
|
3427
|
+
} else if (resolvedBinaryParts.length > 0) {
|
|
3428
|
+
body = Buffer.concat(resolvedBinaryParts);
|
|
3429
|
+
} else if (allTextParts.length > 0) {
|
|
3430
|
+
body = allTextParts.join("&");
|
|
3431
|
+
if (!headers["Content-Type"]) {
|
|
3432
|
+
headers["Content-Type"] = "application/x-www-form-urlencoded";
|
|
3433
|
+
}
|
|
3434
|
+
}
|
|
3435
|
+
}
|
|
3436
|
+
const redirect = location ? "follow" : "manual";
|
|
3437
|
+
if (verbose && !silent) {
|
|
3438
|
+
process.stderr.write(`> ${method} ${effectiveUrl.toString()}
|
|
3439
|
+
`);
|
|
3440
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
3441
|
+
process.stderr.write(`> ${k}: ${v}
|
|
3442
|
+
`);
|
|
3443
|
+
}
|
|
3444
|
+
process.stderr.write(">\n");
|
|
3445
|
+
}
|
|
3446
|
+
const signal = maxTime ? AbortSignal.timeout(maxTime * 1e3) : void 0;
|
|
3447
|
+
const start = performance.now();
|
|
3448
|
+
const response = await sdk2.fetch(effectiveUrl.toString(), {
|
|
3449
|
+
method,
|
|
3450
|
+
headers,
|
|
3451
|
+
body,
|
|
3452
|
+
redirect,
|
|
3453
|
+
signal,
|
|
3454
|
+
connectionId
|
|
3455
|
+
});
|
|
3456
|
+
const timeTotalSeconds = (performance.now() - start) / 1e3;
|
|
3457
|
+
if (verbose && !silent) {
|
|
3458
|
+
process.stderr.write(
|
|
3459
|
+
`< HTTP ${response.status} ${response.statusText}
|
|
3460
|
+
`
|
|
3461
|
+
);
|
|
3462
|
+
response.headers.forEach((value, key) => {
|
|
3463
|
+
process.stderr.write(`< ${key}: ${value}
|
|
3464
|
+
`);
|
|
3465
|
+
});
|
|
3466
|
+
process.stderr.write("<\n");
|
|
3467
|
+
}
|
|
3468
|
+
const isHttpError = response.status >= 400;
|
|
3469
|
+
const shouldFail = (fail || failWithBody) && isHttpError;
|
|
3470
|
+
const shouldOutputBody = !shouldFail || !!failWithBody;
|
|
3471
|
+
const headerText = include ? `HTTP ${response.status} ${response.statusText}
|
|
3472
|
+
${Array.from(
|
|
3473
|
+
response.headers.entries()
|
|
3474
|
+
).map(([k, v]) => `${k}: ${v}`).join("\n")}
|
|
3475
|
+
|
|
3476
|
+
` : "";
|
|
3477
|
+
let bodyBytes = 0;
|
|
3478
|
+
const buf = shouldOutputBody ? Buffer.from(await response.arrayBuffer()) : Buffer.alloc(0);
|
|
3479
|
+
bodyBytes = buf.length;
|
|
3480
|
+
const outputFile = output && output !== "-" ? output : remoteName ? deriveRemoteFilename(parsedUrl) : void 0;
|
|
3481
|
+
if (outputFile) {
|
|
3482
|
+
const dir = path.dirname(outputFile);
|
|
3483
|
+
if (dir !== ".") {
|
|
3484
|
+
await fs.promises.mkdir(dir, { recursive: true });
|
|
3485
|
+
}
|
|
3486
|
+
const ws = fs.createWriteStream(outputFile);
|
|
3487
|
+
if (headerText) {
|
|
3488
|
+
ws.write(headerText);
|
|
3489
|
+
}
|
|
3490
|
+
if (buf.length) {
|
|
3491
|
+
ws.write(buf);
|
|
3492
|
+
}
|
|
3493
|
+
await new Promise((resolve4, reject) => {
|
|
3494
|
+
ws.end(() => resolve4());
|
|
3495
|
+
ws.on("error", reject);
|
|
3496
|
+
});
|
|
3497
|
+
} else {
|
|
3498
|
+
if (headerText) {
|
|
3499
|
+
process.stdout.write(headerText);
|
|
3500
|
+
}
|
|
3501
|
+
if (buf.length) {
|
|
3502
|
+
process.stdout.write(buf);
|
|
3503
|
+
}
|
|
3504
|
+
}
|
|
3505
|
+
if (writeOut) {
|
|
3506
|
+
const formatted = formatWriteOut({
|
|
3507
|
+
template: writeOut,
|
|
3508
|
+
urlEffective: response.url || effectiveUrl.toString(),
|
|
3509
|
+
httpCode: response.status,
|
|
3510
|
+
timeTotalSeconds,
|
|
3511
|
+
sizeDownloadBytes: bodyBytes,
|
|
3512
|
+
contentType: response.headers.get("content-type")
|
|
3513
|
+
});
|
|
3514
|
+
process.stdout.write(formatted);
|
|
3515
|
+
}
|
|
3516
|
+
if (shouldFail) {
|
|
3517
|
+
if (!silent || showError) {
|
|
3518
|
+
process.stderr.write(
|
|
3519
|
+
`curl: (22) The requested URL returned error: ${response.status}
|
|
3520
|
+
`
|
|
3521
|
+
);
|
|
3522
|
+
}
|
|
3523
|
+
throw new CurlExitError("HTTP request failed", 22);
|
|
3524
|
+
}
|
|
3525
|
+
return void 0;
|
|
3526
|
+
}
|
|
3527
|
+
return {
|
|
3528
|
+
curl,
|
|
3529
|
+
context: {
|
|
3530
|
+
meta: {
|
|
3531
|
+
curl: {
|
|
3532
|
+
description: "Make authenticated HTTP requests to any API through Zapier. Pass a connection ID to automatically inject the user's stored credentials (OAuth tokens, API keys, etc.) into the outgoing request. Use it in place of the native curl command with additional Zapier-specific options.",
|
|
3533
|
+
categories: ["http"],
|
|
3534
|
+
inputSchema: CurlSchema,
|
|
3535
|
+
aliases: {
|
|
3536
|
+
request: "X",
|
|
3537
|
+
header: "H",
|
|
3538
|
+
data: "d",
|
|
3539
|
+
form: "F",
|
|
3540
|
+
get: "G",
|
|
3541
|
+
head: "I",
|
|
3542
|
+
location: "L",
|
|
3543
|
+
include: "i",
|
|
3544
|
+
output: "o",
|
|
3545
|
+
remoteName: "O",
|
|
3546
|
+
verbose: "v",
|
|
3547
|
+
silent: "s",
|
|
3548
|
+
showError: "S",
|
|
3549
|
+
writeOut: "w",
|
|
3550
|
+
maxTime: "m",
|
|
3551
|
+
user: "u"
|
|
3552
|
+
}
|
|
3553
|
+
}
|
|
3554
|
+
}
|
|
3555
|
+
}
|
|
3556
|
+
};
|
|
3557
|
+
};
|
|
3558
|
+
|
|
3559
|
+
// src/plugins/cliOverrides/index.ts
|
|
3560
|
+
var cliOverridesPlugin = ({ context }) => {
|
|
3561
|
+
if (!context.meta.fetch) {
|
|
3562
|
+
return { context: { meta: {} } };
|
|
3563
|
+
}
|
|
3564
|
+
return {
|
|
3565
|
+
context: {
|
|
3566
|
+
meta: {
|
|
3567
|
+
fetch: {
|
|
3568
|
+
...context.meta.fetch,
|
|
3569
|
+
categories: [...context.meta.fetch.categories || [], "deprecated"]
|
|
3570
|
+
}
|
|
3571
|
+
}
|
|
3572
|
+
}
|
|
3573
|
+
};
|
|
3574
|
+
};
|
|
3119
3575
|
|
|
3120
3576
|
// src/sdk.ts
|
|
3121
3577
|
function createZapierCliSdk(options = {}) {
|
|
3122
3578
|
return zapierSdk.createZapierSdkWithoutRegistry({
|
|
3123
3579
|
...options
|
|
3124
|
-
}).addPlugin(generateAppTypesPlugin).addPlugin(buildManifestPlugin).addPlugin(bundleCodePlugin).addPlugin(getLoginConfigPathPlugin).addPlugin(addPlugin).addPlugin(feedbackPlugin).addPlugin(mcpPlugin).addPlugin(loginPlugin).addPlugin(logoutPlugin).addPlugin(zapierSdk.registryPlugin);
|
|
3580
|
+
}).addPlugin(generateAppTypesPlugin).addPlugin(buildManifestPlugin).addPlugin(bundleCodePlugin).addPlugin(getLoginConfigPathPlugin).addPlugin(addPlugin).addPlugin(feedbackPlugin).addPlugin(curlPlugin).addPlugin(mcpPlugin).addPlugin(loginPlugin).addPlugin(logoutPlugin).addPlugin(cliOverridesPlugin).addPlugin(zapierSdk.registryPlugin);
|
|
3125
3581
|
}
|
|
3126
3582
|
|
|
3127
3583
|
// package.json with { type: 'json' }
|
|
3128
3584
|
var package_default2 = {
|
|
3129
3585
|
name: "@zapier/zapier-sdk-cli",
|
|
3130
|
-
version: "0.
|
|
3586
|
+
version: "0.31.1"};
|
|
3131
3587
|
function detectPackageManager(cwd = process.cwd()) {
|
|
3132
3588
|
const ua = process.env.npm_config_user_agent;
|
|
3133
3589
|
if (ua) {
|
|
@@ -3330,7 +3786,7 @@ async function checkAndNotifyUpdates({
|
|
|
3330
3786
|
|
|
3331
3787
|
// src/cli.ts
|
|
3332
3788
|
var program = new commander.Command();
|
|
3333
|
-
program.name("zapier-sdk").description("CLI for Zapier SDK").version(package_default2.version,
|
|
3789
|
+
program.name("zapier-sdk").description("CLI for Zapier SDK").version(package_default2.version, void 0, "Display version number").option("--debug", "Enable debug logging").option("--base-url <url>", "Base URL for Zapier API endpoints").option("--credentials <token>", "Authentication token").option("--credentials-client-id <id>", "OAuth client ID for authentication").option(
|
|
3334
3790
|
"--credentials-client-secret <secret>",
|
|
3335
3791
|
"OAuth client secret for authentication"
|
|
3336
3792
|
).option(
|
|
@@ -3342,7 +3798,7 @@ program.name("zapier-sdk").description("CLI for Zapier SDK").version(package_def
|
|
|
3342
3798
|
).option(
|
|
3343
3799
|
"--max-network-retry-delay-ms <ms>",
|
|
3344
3800
|
"Max delay in ms to wait for rate limit retry (default: 60000)"
|
|
3345
|
-
);
|
|
3801
|
+
).helpOption("-h, --help", "Display help for command");
|
|
3346
3802
|
var isDebugMode = process.env.DEBUG === "true" || process.argv.includes("--debug");
|
|
3347
3803
|
function getFlagValue(flagName) {
|
|
3348
3804
|
const index = process.argv.indexOf(flagName);
|