@zapier/connectors-sdk 0.1.0-experimental.12 → 0.1.0-experimental.13
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/index.cjs +59 -8
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +59 -8
- package/package.json +4 -1
package/dist/index.cjs
CHANGED
|
@@ -1050,8 +1050,8 @@ async function resolvePackageName(meta) {
|
|
|
1050
1050
|
function printUsage(scripts, out, packageName) {
|
|
1051
1051
|
const names = Object.keys(scripts);
|
|
1052
1052
|
out.write(
|
|
1053
|
-
`Usage: <bin> run <script> [<json-input>]
|
|
1054
|
-
<bin> run <script> --help (per-script input
|
|
1053
|
+
`Usage: <bin> run <script> [<json-input>] [--filter <jq>]
|
|
1054
|
+
<bin> run <script> --help (per-script input/output schema, env vars, --filter)
|
|
1055
1055
|
<bin> mcp (run as a local MCP server over stdio)
|
|
1056
1056
|
<bin> skill (print SKILL.md to stdout)
|
|
1057
1057
|
<bin> reference [<name>] (print references/<name>.md, or list all)
|
|
@@ -1080,7 +1080,7 @@ function printUsage(scripts, out, packageName) {
|
|
|
1080
1080
|
}
|
|
1081
1081
|
out.write(
|
|
1082
1082
|
`
|
|
1083
|
-
|
|
1083
|
+
Run \`<bin> run <script> --help\` for a script's input/output schema, its required env vars (credentials are environment-variable only), and the \`--filter <jq>\` flag for trimming output.
|
|
1084
1084
|
`
|
|
1085
1085
|
);
|
|
1086
1086
|
}
|
|
@@ -1156,12 +1156,31 @@ async function handleIfScriptMainBody(wrappedScript, connectionResolvers, io) {
|
|
|
1156
1156
|
const args = io.argv.slice(2);
|
|
1157
1157
|
let positional;
|
|
1158
1158
|
let helpRequested = false;
|
|
1159
|
-
|
|
1159
|
+
let filter;
|
|
1160
|
+
for (let i = 0; i < args.length; i++) {
|
|
1161
|
+
const arg = args[i];
|
|
1160
1162
|
if (arg === "--help" || arg === "-h") {
|
|
1161
1163
|
helpRequested = true;
|
|
1164
|
+
} else if (arg === "--filter") {
|
|
1165
|
+
const value = args[i + 1];
|
|
1166
|
+
if (value === void 0 || value.length === 0) {
|
|
1167
|
+
throw new Error(
|
|
1168
|
+
`\`--filter\` requires a jq expression, e.g. \`--filter '.results | length'\`.`
|
|
1169
|
+
);
|
|
1170
|
+
}
|
|
1171
|
+
filter = value;
|
|
1172
|
+
i++;
|
|
1173
|
+
} else if (arg.startsWith("--filter=")) {
|
|
1174
|
+
const value = arg.slice("--filter=".length);
|
|
1175
|
+
if (value.length === 0) {
|
|
1176
|
+
throw new Error(
|
|
1177
|
+
`\`--filter\` requires a jq expression, e.g. \`--filter '.results | length'\`.`
|
|
1178
|
+
);
|
|
1179
|
+
}
|
|
1180
|
+
filter = value;
|
|
1162
1181
|
} else if (arg.startsWith("--")) {
|
|
1163
1182
|
throw new Error(
|
|
1164
|
-
`Unknown flag "${arg}". The per-script CLI accepts
|
|
1183
|
+
`Unknown flag "${arg}". The per-script CLI accepts \`--help\`, \`--filter <jq>\`, and a positional JSON-encoded input. Credentials are env-only \u2014 set the resolver's required env vars (run with \`--help\` to list them).`
|
|
1165
1184
|
);
|
|
1166
1185
|
} else if (positional === void 0) {
|
|
1167
1186
|
positional = arg;
|
|
@@ -1206,7 +1225,12 @@ async function handleIfScriptMainBody(wrappedScript, connectionResolvers, io) {
|
|
|
1206
1225
|
}
|
|
1207
1226
|
}
|
|
1208
1227
|
const result = await wrappedScript.run(input, runOpts);
|
|
1209
|
-
|
|
1228
|
+
const output = filter === void 0 ? result : await applyJqFilter(result, filter);
|
|
1229
|
+
io.stdout.write(JSON.stringify(output, null, 2) + "\n");
|
|
1230
|
+
}
|
|
1231
|
+
async function applyJqFilter(value, filter) {
|
|
1232
|
+
const { json: runJq } = await import("jq-wasm");
|
|
1233
|
+
return runJq(value, filter);
|
|
1210
1234
|
}
|
|
1211
1235
|
async function readStdinInput(stdin, scriptName) {
|
|
1212
1236
|
if (stdin.isTTY) {
|
|
@@ -1225,11 +1249,19 @@ function buildHelpText(definition, connectionResolvers, opts = {}) {
|
|
|
1225
1249
|
lines.push("");
|
|
1226
1250
|
lines.push("Usage:");
|
|
1227
1251
|
if (opts.invocation) {
|
|
1228
|
-
lines.push(
|
|
1252
|
+
lines.push(
|
|
1253
|
+
` <bin> run ${opts.invocation.scriptName} '<json-input>' [--filter <jq>]`
|
|
1254
|
+
);
|
|
1229
1255
|
} else {
|
|
1230
|
-
lines.push(` <bin> '<json-input>'`);
|
|
1256
|
+
lines.push(` <bin> '<json-input>' [--filter <jq>]`);
|
|
1231
1257
|
}
|
|
1232
1258
|
lines.push("");
|
|
1259
|
+
lines.push(
|
|
1260
|
+
" --filter <jq> Transform the JSON output through a jq expression."
|
|
1261
|
+
);
|
|
1262
|
+
lines.push(" Useful for trimming large outputs, e.g.");
|
|
1263
|
+
lines.push(" --filter '.results | length'.");
|
|
1264
|
+
lines.push("");
|
|
1233
1265
|
if (opts.invocation) {
|
|
1234
1266
|
lines.push("Example:");
|
|
1235
1267
|
lines.push(
|
|
@@ -1254,6 +1286,11 @@ function buildHelpText(definition, connectionResolvers, opts = {}) {
|
|
|
1254
1286
|
lines.push(...inputBlock);
|
|
1255
1287
|
lines.push("");
|
|
1256
1288
|
}
|
|
1289
|
+
const outputBlock = formatHelpForOutput(definition);
|
|
1290
|
+
if (outputBlock.length > 0) {
|
|
1291
|
+
lines.push(...outputBlock);
|
|
1292
|
+
lines.push("");
|
|
1293
|
+
}
|
|
1257
1294
|
return lines.join("\n");
|
|
1258
1295
|
}
|
|
1259
1296
|
function formatExampleCommand(definition, connectionResolvers, invocation) {
|
|
@@ -1290,6 +1327,20 @@ function formatHelpForInput(definition) {
|
|
|
1290
1327
|
}
|
|
1291
1328
|
return lines;
|
|
1292
1329
|
}
|
|
1330
|
+
function formatHelpForOutput(definition) {
|
|
1331
|
+
let schema;
|
|
1332
|
+
try {
|
|
1333
|
+
schema = import_zod3.z.toJSONSchema(definition.outputSchema);
|
|
1334
|
+
} catch {
|
|
1335
|
+
return [];
|
|
1336
|
+
}
|
|
1337
|
+
const lines = ["Output (JSON Schema):"];
|
|
1338
|
+
const json = JSON.stringify(schema, null, 2);
|
|
1339
|
+
for (const line of json.split("\n")) {
|
|
1340
|
+
lines.push(` ${line}`);
|
|
1341
|
+
}
|
|
1342
|
+
return lines;
|
|
1343
|
+
}
|
|
1293
1344
|
|
|
1294
1345
|
// src/surfaces/to-functions.ts
|
|
1295
1346
|
function toFunctions(connector) {
|
package/dist/index.d.cts
CHANGED
|
@@ -463,8 +463,9 @@ declare function defineTool<TIn extends z.ZodObject<z.ZodRawShape>, TOut extends
|
|
|
463
463
|
* from `process.env` via `buildRunOptionsFromEnv`, calls the wrapped
|
|
464
464
|
* script, writes JSON.
|
|
465
465
|
*
|
|
466
|
-
* **Credentials are env-only by design.** The CLI takes
|
|
467
|
-
* JSON (the script's `inputSchema`) and `--
|
|
466
|
+
* **Credentials are env-only by design.** The CLI takes positional
|
|
467
|
+
* JSON (the script's `inputSchema`), `--help`, and `--filter <jq>` (a jq
|
|
468
|
+
* expression that post-processes the JSON output). Passing secrets via
|
|
468
469
|
* argv would leak them through shell history, `ps`, audit logs, and CI
|
|
469
470
|
* runner echo.
|
|
470
471
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -463,8 +463,9 @@ declare function defineTool<TIn extends z.ZodObject<z.ZodRawShape>, TOut extends
|
|
|
463
463
|
* from `process.env` via `buildRunOptionsFromEnv`, calls the wrapped
|
|
464
464
|
* script, writes JSON.
|
|
465
465
|
*
|
|
466
|
-
* **Credentials are env-only by design.** The CLI takes
|
|
467
|
-
* JSON (the script's `inputSchema`) and `--
|
|
466
|
+
* **Credentials are env-only by design.** The CLI takes positional
|
|
467
|
+
* JSON (the script's `inputSchema`), `--help`, and `--filter <jq>` (a jq
|
|
468
|
+
* expression that post-processes the JSON output). Passing secrets via
|
|
468
469
|
* argv would leak them through shell history, `ps`, audit logs, and CI
|
|
469
470
|
* runner echo.
|
|
470
471
|
*
|
package/dist/index.js
CHANGED
|
@@ -944,8 +944,8 @@ async function resolvePackageName(meta) {
|
|
|
944
944
|
function printUsage(scripts, out, packageName) {
|
|
945
945
|
const names = Object.keys(scripts);
|
|
946
946
|
out.write(
|
|
947
|
-
`Usage: <bin> run <script> [<json-input>]
|
|
948
|
-
<bin> run <script> --help (per-script input
|
|
947
|
+
`Usage: <bin> run <script> [<json-input>] [--filter <jq>]
|
|
948
|
+
<bin> run <script> --help (per-script input/output schema, env vars, --filter)
|
|
949
949
|
<bin> mcp (run as a local MCP server over stdio)
|
|
950
950
|
<bin> skill (print SKILL.md to stdout)
|
|
951
951
|
<bin> reference [<name>] (print references/<name>.md, or list all)
|
|
@@ -974,7 +974,7 @@ function printUsage(scripts, out, packageName) {
|
|
|
974
974
|
}
|
|
975
975
|
out.write(
|
|
976
976
|
`
|
|
977
|
-
|
|
977
|
+
Run \`<bin> run <script> --help\` for a script's input/output schema, its required env vars (credentials are environment-variable only), and the \`--filter <jq>\` flag for trimming output.
|
|
978
978
|
`
|
|
979
979
|
);
|
|
980
980
|
}
|
|
@@ -1050,12 +1050,31 @@ async function handleIfScriptMainBody(wrappedScript, connectionResolvers, io) {
|
|
|
1050
1050
|
const args = io.argv.slice(2);
|
|
1051
1051
|
let positional;
|
|
1052
1052
|
let helpRequested = false;
|
|
1053
|
-
|
|
1053
|
+
let filter;
|
|
1054
|
+
for (let i = 0; i < args.length; i++) {
|
|
1055
|
+
const arg = args[i];
|
|
1054
1056
|
if (arg === "--help" || arg === "-h") {
|
|
1055
1057
|
helpRequested = true;
|
|
1058
|
+
} else if (arg === "--filter") {
|
|
1059
|
+
const value = args[i + 1];
|
|
1060
|
+
if (value === void 0 || value.length === 0) {
|
|
1061
|
+
throw new Error(
|
|
1062
|
+
`\`--filter\` requires a jq expression, e.g. \`--filter '.results | length'\`.`
|
|
1063
|
+
);
|
|
1064
|
+
}
|
|
1065
|
+
filter = value;
|
|
1066
|
+
i++;
|
|
1067
|
+
} else if (arg.startsWith("--filter=")) {
|
|
1068
|
+
const value = arg.slice("--filter=".length);
|
|
1069
|
+
if (value.length === 0) {
|
|
1070
|
+
throw new Error(
|
|
1071
|
+
`\`--filter\` requires a jq expression, e.g. \`--filter '.results | length'\`.`
|
|
1072
|
+
);
|
|
1073
|
+
}
|
|
1074
|
+
filter = value;
|
|
1056
1075
|
} else if (arg.startsWith("--")) {
|
|
1057
1076
|
throw new Error(
|
|
1058
|
-
`Unknown flag "${arg}". The per-script CLI accepts
|
|
1077
|
+
`Unknown flag "${arg}". The per-script CLI accepts \`--help\`, \`--filter <jq>\`, and a positional JSON-encoded input. Credentials are env-only \u2014 set the resolver's required env vars (run with \`--help\` to list them).`
|
|
1059
1078
|
);
|
|
1060
1079
|
} else if (positional === void 0) {
|
|
1061
1080
|
positional = arg;
|
|
@@ -1100,7 +1119,12 @@ async function handleIfScriptMainBody(wrappedScript, connectionResolvers, io) {
|
|
|
1100
1119
|
}
|
|
1101
1120
|
}
|
|
1102
1121
|
const result = await wrappedScript.run(input, runOpts);
|
|
1103
|
-
|
|
1122
|
+
const output = filter === void 0 ? result : await applyJqFilter(result, filter);
|
|
1123
|
+
io.stdout.write(JSON.stringify(output, null, 2) + "\n");
|
|
1124
|
+
}
|
|
1125
|
+
async function applyJqFilter(value, filter) {
|
|
1126
|
+
const { json: runJq } = await import("jq-wasm");
|
|
1127
|
+
return runJq(value, filter);
|
|
1104
1128
|
}
|
|
1105
1129
|
async function readStdinInput(stdin, scriptName) {
|
|
1106
1130
|
if (stdin.isTTY) {
|
|
@@ -1119,11 +1143,19 @@ function buildHelpText(definition, connectionResolvers, opts = {}) {
|
|
|
1119
1143
|
lines.push("");
|
|
1120
1144
|
lines.push("Usage:");
|
|
1121
1145
|
if (opts.invocation) {
|
|
1122
|
-
lines.push(
|
|
1146
|
+
lines.push(
|
|
1147
|
+
` <bin> run ${opts.invocation.scriptName} '<json-input>' [--filter <jq>]`
|
|
1148
|
+
);
|
|
1123
1149
|
} else {
|
|
1124
|
-
lines.push(` <bin> '<json-input>'`);
|
|
1150
|
+
lines.push(` <bin> '<json-input>' [--filter <jq>]`);
|
|
1125
1151
|
}
|
|
1126
1152
|
lines.push("");
|
|
1153
|
+
lines.push(
|
|
1154
|
+
" --filter <jq> Transform the JSON output through a jq expression."
|
|
1155
|
+
);
|
|
1156
|
+
lines.push(" Useful for trimming large outputs, e.g.");
|
|
1157
|
+
lines.push(" --filter '.results | length'.");
|
|
1158
|
+
lines.push("");
|
|
1127
1159
|
if (opts.invocation) {
|
|
1128
1160
|
lines.push("Example:");
|
|
1129
1161
|
lines.push(
|
|
@@ -1148,6 +1180,11 @@ function buildHelpText(definition, connectionResolvers, opts = {}) {
|
|
|
1148
1180
|
lines.push(...inputBlock);
|
|
1149
1181
|
lines.push("");
|
|
1150
1182
|
}
|
|
1183
|
+
const outputBlock = formatHelpForOutput(definition);
|
|
1184
|
+
if (outputBlock.length > 0) {
|
|
1185
|
+
lines.push(...outputBlock);
|
|
1186
|
+
lines.push("");
|
|
1187
|
+
}
|
|
1151
1188
|
return lines.join("\n");
|
|
1152
1189
|
}
|
|
1153
1190
|
function formatExampleCommand(definition, connectionResolvers, invocation) {
|
|
@@ -1184,6 +1221,20 @@ function formatHelpForInput(definition) {
|
|
|
1184
1221
|
}
|
|
1185
1222
|
return lines;
|
|
1186
1223
|
}
|
|
1224
|
+
function formatHelpForOutput(definition) {
|
|
1225
|
+
let schema;
|
|
1226
|
+
try {
|
|
1227
|
+
schema = z3.toJSONSchema(definition.outputSchema);
|
|
1228
|
+
} catch {
|
|
1229
|
+
return [];
|
|
1230
|
+
}
|
|
1231
|
+
const lines = ["Output (JSON Schema):"];
|
|
1232
|
+
const json = JSON.stringify(schema, null, 2);
|
|
1233
|
+
for (const line of json.split("\n")) {
|
|
1234
|
+
lines.push(` ${line}`);
|
|
1235
|
+
}
|
|
1236
|
+
return lines;
|
|
1237
|
+
}
|
|
1187
1238
|
|
|
1188
1239
|
// src/surfaces/to-functions.ts
|
|
1189
1240
|
function toFunctions(connector) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zapier/connectors-sdk",
|
|
3
|
-
"version": "0.1.0-experimental.
|
|
3
|
+
"version": "0.1.0-experimental.13",
|
|
4
4
|
"description": "SDK for building Zapier connectors. Provides the authoring primitives and execution surfaces for connector scripts.",
|
|
5
5
|
"license": "Elastic-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
"README.md",
|
|
25
25
|
"LICENSE"
|
|
26
26
|
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"jq-wasm": "1.1.0-jq-1.8.1"
|
|
29
|
+
},
|
|
27
30
|
"peerDependencies": {
|
|
28
31
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
29
32
|
"@zapier/zapier-sdk": "^0.59.0",
|