@zapier/connectors-sdk 0.1.0-experimental.10 → 0.1.0-experimental.11
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 +49 -0
- package/dist/index.js +49 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -280,6 +280,39 @@ function isPackageInstalled(name) {
|
|
|
280
280
|
return false;
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
|
+
function buildMissingConnectionError(scriptName, missingSlots) {
|
|
284
|
+
const lines = [];
|
|
285
|
+
if (missingSlots.length === 1 && missingSlots[0].slotName === void 0) {
|
|
286
|
+
const { connectionKey, resolvers } = missingSlots[0];
|
|
287
|
+
lines.push(
|
|
288
|
+
`"${scriptName}" requires the "${connectionKey}" connection but no credentials were found in the environment.`
|
|
289
|
+
);
|
|
290
|
+
lines.push("");
|
|
291
|
+
lines.push(
|
|
292
|
+
"Set one of the following environment variables before running:"
|
|
293
|
+
);
|
|
294
|
+
lines.push("");
|
|
295
|
+
for (const resolver of resolvers) {
|
|
296
|
+
const vars = envVarsFor(void 0, connectionKey, resolver);
|
|
297
|
+
lines.push(` ${vars.join(" ")} (${resolver.name})`);
|
|
298
|
+
}
|
|
299
|
+
} else {
|
|
300
|
+
lines.push(
|
|
301
|
+
`"${scriptName}" is missing credentials for connection slot(s):`
|
|
302
|
+
);
|
|
303
|
+
for (const { slotName, connectionKey, resolvers } of missingSlots) {
|
|
304
|
+
lines.push("");
|
|
305
|
+
lines.push(` ${slotName} (${connectionKey}):`);
|
|
306
|
+
for (const resolver of resolvers) {
|
|
307
|
+
const vars = envVarsFor(slotName, connectionKey, resolver);
|
|
308
|
+
lines.push(` ${vars.join(" ")} (${resolver.name})`);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
lines.push("");
|
|
313
|
+
lines.push("Run with --help for the full auth guide.");
|
|
314
|
+
return new Error(lines.join("\n"));
|
|
315
|
+
}
|
|
283
316
|
function formatHelpForConnections(definition, connectionResolvers, env) {
|
|
284
317
|
const slots = [...walkConnections(definition)];
|
|
285
318
|
if (slots.length === 0) return [];
|
|
@@ -1057,6 +1090,22 @@ async function handleIfScriptMainBody(wrappedScript, connectionResolvers, io) {
|
|
|
1057
1090
|
const input = wrappedScript.inputSchema.parse(JSON.parse(raw));
|
|
1058
1091
|
const hasConnections = [...walkConnections(wrappedScript)].length > 0;
|
|
1059
1092
|
const runOpts = hasConnections ? buildRunOptionsFromEnv(wrappedScript, io.env, connectionResolvers) : void 0;
|
|
1093
|
+
if (runOpts !== void 0) {
|
|
1094
|
+
const missing = [];
|
|
1095
|
+
for (const { slotName, connectionKey } of walkConnections(wrappedScript)) {
|
|
1096
|
+
const value = slotName === void 0 ? "connection" in runOpts ? runOpts.connection : void 0 : "connections" in runOpts ? runOpts.connections[slotName] : void 0;
|
|
1097
|
+
if (value === void 0) {
|
|
1098
|
+
missing.push({
|
|
1099
|
+
slotName,
|
|
1100
|
+
connectionKey,
|
|
1101
|
+
resolvers: resolversForKey(connectionResolvers, connectionKey)
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
if (missing.length > 0) {
|
|
1106
|
+
throw buildMissingConnectionError(wrappedScript.name, missing);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1060
1109
|
const result = await wrappedScript.run(input, runOpts);
|
|
1061
1110
|
io.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
|
1062
1111
|
}
|
package/dist/index.js
CHANGED
|
@@ -174,6 +174,39 @@ function isPackageInstalled(name) {
|
|
|
174
174
|
return false;
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
|
+
function buildMissingConnectionError(scriptName, missingSlots) {
|
|
178
|
+
const lines = [];
|
|
179
|
+
if (missingSlots.length === 1 && missingSlots[0].slotName === void 0) {
|
|
180
|
+
const { connectionKey, resolvers } = missingSlots[0];
|
|
181
|
+
lines.push(
|
|
182
|
+
`"${scriptName}" requires the "${connectionKey}" connection but no credentials were found in the environment.`
|
|
183
|
+
);
|
|
184
|
+
lines.push("");
|
|
185
|
+
lines.push(
|
|
186
|
+
"Set one of the following environment variables before running:"
|
|
187
|
+
);
|
|
188
|
+
lines.push("");
|
|
189
|
+
for (const resolver of resolvers) {
|
|
190
|
+
const vars = envVarsFor(void 0, connectionKey, resolver);
|
|
191
|
+
lines.push(` ${vars.join(" ")} (${resolver.name})`);
|
|
192
|
+
}
|
|
193
|
+
} else {
|
|
194
|
+
lines.push(
|
|
195
|
+
`"${scriptName}" is missing credentials for connection slot(s):`
|
|
196
|
+
);
|
|
197
|
+
for (const { slotName, connectionKey, resolvers } of missingSlots) {
|
|
198
|
+
lines.push("");
|
|
199
|
+
lines.push(` ${slotName} (${connectionKey}):`);
|
|
200
|
+
for (const resolver of resolvers) {
|
|
201
|
+
const vars = envVarsFor(slotName, connectionKey, resolver);
|
|
202
|
+
lines.push(` ${vars.join(" ")} (${resolver.name})`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
lines.push("");
|
|
207
|
+
lines.push("Run with --help for the full auth guide.");
|
|
208
|
+
return new Error(lines.join("\n"));
|
|
209
|
+
}
|
|
177
210
|
function formatHelpForConnections(definition, connectionResolvers, env) {
|
|
178
211
|
const slots = [...walkConnections(definition)];
|
|
179
212
|
if (slots.length === 0) return [];
|
|
@@ -951,6 +984,22 @@ async function handleIfScriptMainBody(wrappedScript, connectionResolvers, io) {
|
|
|
951
984
|
const input = wrappedScript.inputSchema.parse(JSON.parse(raw));
|
|
952
985
|
const hasConnections = [...walkConnections(wrappedScript)].length > 0;
|
|
953
986
|
const runOpts = hasConnections ? buildRunOptionsFromEnv(wrappedScript, io.env, connectionResolvers) : void 0;
|
|
987
|
+
if (runOpts !== void 0) {
|
|
988
|
+
const missing = [];
|
|
989
|
+
for (const { slotName, connectionKey } of walkConnections(wrappedScript)) {
|
|
990
|
+
const value = slotName === void 0 ? "connection" in runOpts ? runOpts.connection : void 0 : "connections" in runOpts ? runOpts.connections[slotName] : void 0;
|
|
991
|
+
if (value === void 0) {
|
|
992
|
+
missing.push({
|
|
993
|
+
slotName,
|
|
994
|
+
connectionKey,
|
|
995
|
+
resolvers: resolversForKey(connectionResolvers, connectionKey)
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
if (missing.length > 0) {
|
|
1000
|
+
throw buildMissingConnectionError(wrappedScript.name, missing);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
954
1003
|
const result = await wrappedScript.run(input, runOpts);
|
|
955
1004
|
io.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
|
956
1005
|
}
|
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.11",
|
|
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",
|