@zapier/connectors-sdk 0.1.0-experimental.12 → 0.1.0-experimental.14
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 +56 -8
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +56 -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,27 @@ 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(`\`--filter\` requires a jq expression argument.`);
|
|
1168
|
+
}
|
|
1169
|
+
filter = value;
|
|
1170
|
+
i++;
|
|
1171
|
+
} else if (arg.startsWith("--filter=")) {
|
|
1172
|
+
const value = arg.slice("--filter=".length);
|
|
1173
|
+
if (value.length === 0) {
|
|
1174
|
+
throw new Error(`\`--filter\` requires a jq expression argument.`);
|
|
1175
|
+
}
|
|
1176
|
+
filter = value;
|
|
1162
1177
|
} else if (arg.startsWith("--")) {
|
|
1163
1178
|
throw new Error(
|
|
1164
|
-
`Unknown flag "${arg}". The per-script CLI accepts
|
|
1179
|
+
`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
1180
|
);
|
|
1166
1181
|
} else if (positional === void 0) {
|
|
1167
1182
|
positional = arg;
|
|
@@ -1206,7 +1221,12 @@ async function handleIfScriptMainBody(wrappedScript, connectionResolvers, io) {
|
|
|
1206
1221
|
}
|
|
1207
1222
|
}
|
|
1208
1223
|
const result = await wrappedScript.run(input, runOpts);
|
|
1209
|
-
|
|
1224
|
+
const output = filter === void 0 ? result : await applyJqFilter(result, filter);
|
|
1225
|
+
io.stdout.write(JSON.stringify(output, null, 2) + "\n");
|
|
1226
|
+
}
|
|
1227
|
+
async function applyJqFilter(value, filter) {
|
|
1228
|
+
const { json: runJq } = await import("jq-wasm");
|
|
1229
|
+
return runJq(value, filter);
|
|
1210
1230
|
}
|
|
1211
1231
|
async function readStdinInput(stdin, scriptName) {
|
|
1212
1232
|
if (stdin.isTTY) {
|
|
@@ -1225,11 +1245,20 @@ function buildHelpText(definition, connectionResolvers, opts = {}) {
|
|
|
1225
1245
|
lines.push("");
|
|
1226
1246
|
lines.push("Usage:");
|
|
1227
1247
|
if (opts.invocation) {
|
|
1228
|
-
lines.push(
|
|
1248
|
+
lines.push(
|
|
1249
|
+
` <bin> run ${opts.invocation.scriptName} '<json-input>' [--filter <jq>]`
|
|
1250
|
+
);
|
|
1229
1251
|
} else {
|
|
1230
|
-
lines.push(` <bin> '<json-input>'`);
|
|
1252
|
+
lines.push(` <bin> '<json-input>' [--filter <jq>]`);
|
|
1231
1253
|
}
|
|
1232
1254
|
lines.push("");
|
|
1255
|
+
lines.push(
|
|
1256
|
+
" --filter <jq> Transform the JSON output through a jq expression,"
|
|
1257
|
+
);
|
|
1258
|
+
lines.push(
|
|
1259
|
+
" e.g. to trim large results. See the output schema below."
|
|
1260
|
+
);
|
|
1261
|
+
lines.push("");
|
|
1233
1262
|
if (opts.invocation) {
|
|
1234
1263
|
lines.push("Example:");
|
|
1235
1264
|
lines.push(
|
|
@@ -1254,6 +1283,11 @@ function buildHelpText(definition, connectionResolvers, opts = {}) {
|
|
|
1254
1283
|
lines.push(...inputBlock);
|
|
1255
1284
|
lines.push("");
|
|
1256
1285
|
}
|
|
1286
|
+
const outputBlock = formatHelpForOutput(definition);
|
|
1287
|
+
if (outputBlock.length > 0) {
|
|
1288
|
+
lines.push(...outputBlock);
|
|
1289
|
+
lines.push("");
|
|
1290
|
+
}
|
|
1257
1291
|
return lines.join("\n");
|
|
1258
1292
|
}
|
|
1259
1293
|
function formatExampleCommand(definition, connectionResolvers, invocation) {
|
|
@@ -1290,6 +1324,20 @@ function formatHelpForInput(definition) {
|
|
|
1290
1324
|
}
|
|
1291
1325
|
return lines;
|
|
1292
1326
|
}
|
|
1327
|
+
function formatHelpForOutput(definition) {
|
|
1328
|
+
let schema;
|
|
1329
|
+
try {
|
|
1330
|
+
schema = import_zod3.z.toJSONSchema(definition.outputSchema);
|
|
1331
|
+
} catch {
|
|
1332
|
+
return [];
|
|
1333
|
+
}
|
|
1334
|
+
const lines = ["Output (JSON Schema):"];
|
|
1335
|
+
const json = JSON.stringify(schema, null, 2);
|
|
1336
|
+
for (const line of json.split("\n")) {
|
|
1337
|
+
lines.push(` ${line}`);
|
|
1338
|
+
}
|
|
1339
|
+
return lines;
|
|
1340
|
+
}
|
|
1293
1341
|
|
|
1294
1342
|
// src/surfaces/to-functions.ts
|
|
1295
1343
|
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,27 @@ 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(`\`--filter\` requires a jq expression argument.`);
|
|
1062
|
+
}
|
|
1063
|
+
filter = value;
|
|
1064
|
+
i++;
|
|
1065
|
+
} else if (arg.startsWith("--filter=")) {
|
|
1066
|
+
const value = arg.slice("--filter=".length);
|
|
1067
|
+
if (value.length === 0) {
|
|
1068
|
+
throw new Error(`\`--filter\` requires a jq expression argument.`);
|
|
1069
|
+
}
|
|
1070
|
+
filter = value;
|
|
1056
1071
|
} else if (arg.startsWith("--")) {
|
|
1057
1072
|
throw new Error(
|
|
1058
|
-
`Unknown flag "${arg}". The per-script CLI accepts
|
|
1073
|
+
`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
1074
|
);
|
|
1060
1075
|
} else if (positional === void 0) {
|
|
1061
1076
|
positional = arg;
|
|
@@ -1100,7 +1115,12 @@ async function handleIfScriptMainBody(wrappedScript, connectionResolvers, io) {
|
|
|
1100
1115
|
}
|
|
1101
1116
|
}
|
|
1102
1117
|
const result = await wrappedScript.run(input, runOpts);
|
|
1103
|
-
|
|
1118
|
+
const output = filter === void 0 ? result : await applyJqFilter(result, filter);
|
|
1119
|
+
io.stdout.write(JSON.stringify(output, null, 2) + "\n");
|
|
1120
|
+
}
|
|
1121
|
+
async function applyJqFilter(value, filter) {
|
|
1122
|
+
const { json: runJq } = await import("jq-wasm");
|
|
1123
|
+
return runJq(value, filter);
|
|
1104
1124
|
}
|
|
1105
1125
|
async function readStdinInput(stdin, scriptName) {
|
|
1106
1126
|
if (stdin.isTTY) {
|
|
@@ -1119,11 +1139,20 @@ function buildHelpText(definition, connectionResolvers, opts = {}) {
|
|
|
1119
1139
|
lines.push("");
|
|
1120
1140
|
lines.push("Usage:");
|
|
1121
1141
|
if (opts.invocation) {
|
|
1122
|
-
lines.push(
|
|
1142
|
+
lines.push(
|
|
1143
|
+
` <bin> run ${opts.invocation.scriptName} '<json-input>' [--filter <jq>]`
|
|
1144
|
+
);
|
|
1123
1145
|
} else {
|
|
1124
|
-
lines.push(` <bin> '<json-input>'`);
|
|
1146
|
+
lines.push(` <bin> '<json-input>' [--filter <jq>]`);
|
|
1125
1147
|
}
|
|
1126
1148
|
lines.push("");
|
|
1149
|
+
lines.push(
|
|
1150
|
+
" --filter <jq> Transform the JSON output through a jq expression,"
|
|
1151
|
+
);
|
|
1152
|
+
lines.push(
|
|
1153
|
+
" e.g. to trim large results. See the output schema below."
|
|
1154
|
+
);
|
|
1155
|
+
lines.push("");
|
|
1127
1156
|
if (opts.invocation) {
|
|
1128
1157
|
lines.push("Example:");
|
|
1129
1158
|
lines.push(
|
|
@@ -1148,6 +1177,11 @@ function buildHelpText(definition, connectionResolvers, opts = {}) {
|
|
|
1148
1177
|
lines.push(...inputBlock);
|
|
1149
1178
|
lines.push("");
|
|
1150
1179
|
}
|
|
1180
|
+
const outputBlock = formatHelpForOutput(definition);
|
|
1181
|
+
if (outputBlock.length > 0) {
|
|
1182
|
+
lines.push(...outputBlock);
|
|
1183
|
+
lines.push("");
|
|
1184
|
+
}
|
|
1151
1185
|
return lines.join("\n");
|
|
1152
1186
|
}
|
|
1153
1187
|
function formatExampleCommand(definition, connectionResolvers, invocation) {
|
|
@@ -1184,6 +1218,20 @@ function formatHelpForInput(definition) {
|
|
|
1184
1218
|
}
|
|
1185
1219
|
return lines;
|
|
1186
1220
|
}
|
|
1221
|
+
function formatHelpForOutput(definition) {
|
|
1222
|
+
let schema;
|
|
1223
|
+
try {
|
|
1224
|
+
schema = z3.toJSONSchema(definition.outputSchema);
|
|
1225
|
+
} catch {
|
|
1226
|
+
return [];
|
|
1227
|
+
}
|
|
1228
|
+
const lines = ["Output (JSON Schema):"];
|
|
1229
|
+
const json = JSON.stringify(schema, null, 2);
|
|
1230
|
+
for (const line of json.split("\n")) {
|
|
1231
|
+
lines.push(` ${line}`);
|
|
1232
|
+
}
|
|
1233
|
+
return lines;
|
|
1234
|
+
}
|
|
1187
1235
|
|
|
1188
1236
|
// src/surfaces/to-functions.ts
|
|
1189
1237
|
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.14",
|
|
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",
|