@zapier/connectors-sdk 0.1.0-experimental.4 → 0.1.0-experimental.6
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 +63 -9
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +62 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -109,6 +109,7 @@ function defineConnectionResolver(resolver) {
|
|
|
109
109
|
}
|
|
110
110
|
var zapierConnectionResolver = defineConnectionResolver({
|
|
111
111
|
name: "zapier-connection-id",
|
|
112
|
+
optionalPackages: ["@zapier/zapier-sdk"],
|
|
112
113
|
resolve: async (connectionId) => {
|
|
113
114
|
const { buildZapierFetch: buildZapierFetch2 } = await Promise.resolve().then(() => (init_build_zapier_fetch(), build_zapier_fetch_exports));
|
|
114
115
|
return buildZapierFetch2(connectionId);
|
|
@@ -128,12 +129,16 @@ function defineBearerTokenResolver(opts = {}) {
|
|
|
128
129
|
});
|
|
129
130
|
}
|
|
130
131
|
|
|
132
|
+
// src/normalize-connections.ts
|
|
133
|
+
var import_node_module = require("module");
|
|
134
|
+
|
|
131
135
|
// src/connection-key.ts
|
|
132
136
|
function envFromKey(name) {
|
|
133
137
|
return name.toUpperCase().replace(/-/g, "_");
|
|
134
138
|
}
|
|
135
139
|
|
|
136
140
|
// src/normalize-connections.ts
|
|
141
|
+
var import_meta = {};
|
|
137
142
|
function* walkConnections(definition) {
|
|
138
143
|
if (typeof definition.connection === "string") {
|
|
139
144
|
yield { slotName: void 0, connectionKey: definition.connection };
|
|
@@ -267,23 +272,70 @@ function buildRunOptionsFromEnv(definition, env, connectionResolvers) {
|
|
|
267
272
|
}
|
|
268
273
|
return { connections: wrapped };
|
|
269
274
|
}
|
|
270
|
-
function
|
|
275
|
+
function isPackageInstalled(name) {
|
|
276
|
+
try {
|
|
277
|
+
(0, import_node_module.createRequire)(import_meta.url).resolve(name);
|
|
278
|
+
return true;
|
|
279
|
+
} catch {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function formatHelpForConnections(definition, connectionResolvers, env) {
|
|
271
284
|
const slots = [...walkConnections(definition)];
|
|
272
285
|
if (slots.length === 0) return [];
|
|
273
286
|
const lines = [];
|
|
274
287
|
lines.push(
|
|
275
|
-
"
|
|
288
|
+
"Auth (set as environment variables; do NOT pass via CLI argument):"
|
|
276
289
|
);
|
|
290
|
+
const notReadySlots = [];
|
|
277
291
|
for (const { slotName, connectionKey } of slots) {
|
|
278
292
|
const resolvers = resolversForKey(connectionResolvers, connectionKey);
|
|
279
|
-
|
|
280
|
-
|
|
293
|
+
if (slotName !== void 0) {
|
|
294
|
+
lines.push(` ${slotName} (${connectionKey}):`);
|
|
295
|
+
}
|
|
296
|
+
const resolverIndent = slotName !== void 0 ? " " : " ";
|
|
297
|
+
const varIndent = slotName !== void 0 ? " " : " ";
|
|
298
|
+
let slotHasReady = false;
|
|
281
299
|
for (const resolver of resolvers) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
300
|
+
const vars = envVarsFor(slotName, connectionKey, resolver);
|
|
301
|
+
let isReady = false;
|
|
302
|
+
let missingPkgs = [];
|
|
303
|
+
if (env !== void 0) {
|
|
304
|
+
const envVarsOk = vars.every(
|
|
305
|
+
(k) => typeof env[k] === "string" && env[k] !== ""
|
|
306
|
+
);
|
|
307
|
+
if (envVarsOk) isReady = true;
|
|
308
|
+
missingPkgs = (resolver.optionalPackages ?? []).filter(
|
|
309
|
+
(pkg) => !isPackageInstalled(pkg)
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
const markReady = isReady && !slotHasReady;
|
|
313
|
+
if (markReady) slotHasReady = true;
|
|
314
|
+
const resolverSuffix = env !== void 0 && markReady ? " [READY \u2014 use this]" : "";
|
|
315
|
+
lines.push(`${resolverIndent}${resolver.name}:${resolverSuffix}`);
|
|
316
|
+
for (const envVar of vars) {
|
|
317
|
+
const varSuffix = env !== void 0 ? env[envVar] !== void 0 && env[envVar] !== "" ? " [set]" : " [not set]" : "";
|
|
318
|
+
lines.push(`${varIndent}${envVar}${varSuffix}`);
|
|
319
|
+
}
|
|
320
|
+
if (env !== void 0) {
|
|
321
|
+
for (const pkg of resolver.optionalPackages ?? []) {
|
|
322
|
+
if (missingPkgs.includes(pkg)) {
|
|
323
|
+
lines.push(
|
|
324
|
+
`${varIndent}${pkg} [not installed \u2014 run \`npm install ${pkg}\` first]`
|
|
325
|
+
);
|
|
326
|
+
} else {
|
|
327
|
+
lines.push(`${varIndent}${pkg} [installed]`);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
285
330
|
}
|
|
286
331
|
}
|
|
332
|
+
if (env !== void 0 && !slotHasReady) {
|
|
333
|
+
notReadySlots.push(slotName ?? connectionKey);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (env !== void 0 && notReadySlots.length > 0) {
|
|
337
|
+
const label = notReadySlots.length === slots.length ? "No option is ready" : `No option is ready for slot${notReadySlots.length > 1 ? "s" : ""} ${notReadySlots.join(", ")}`;
|
|
338
|
+
lines.push(`${label} \u2014 set one of the env vars above.`);
|
|
287
339
|
}
|
|
288
340
|
return lines;
|
|
289
341
|
}
|
|
@@ -921,7 +973,8 @@ async function handleIfScriptMainBody(wrappedScript, connectionResolvers, io) {
|
|
|
921
973
|
if (helpRequested) {
|
|
922
974
|
io.stdout.write(
|
|
923
975
|
buildHelpText(wrappedScript, connectionResolvers, {
|
|
924
|
-
invocation: io.invocation
|
|
976
|
+
invocation: io.invocation,
|
|
977
|
+
env: io.env
|
|
925
978
|
})
|
|
926
979
|
);
|
|
927
980
|
return;
|
|
@@ -969,7 +1022,8 @@ function buildHelpText(definition, connectionResolvers, opts = {}) {
|
|
|
969
1022
|
}
|
|
970
1023
|
const connectionsBlock = formatHelpForConnections(
|
|
971
1024
|
definition,
|
|
972
|
-
connectionResolvers
|
|
1025
|
+
connectionResolvers,
|
|
1026
|
+
opts.env
|
|
973
1027
|
);
|
|
974
1028
|
if (connectionsBlock.length > 0) {
|
|
975
1029
|
lines.push(...connectionsBlock);
|
package/dist/index.d.cts
CHANGED
|
@@ -50,6 +50,12 @@ type EnvFromKey<K extends string> = Uppercase<Replace<K, "-", "_">>;
|
|
|
50
50
|
interface SingleConnectionResolver<TName extends string = string> {
|
|
51
51
|
readonly name: TName;
|
|
52
52
|
readonly keySuffixes?: undefined;
|
|
53
|
+
/**
|
|
54
|
+
* npm package names that must be installed for this resolver to function
|
|
55
|
+
* at runtime. Declared here so `--help` can check availability and tell
|
|
56
|
+
* the agent which packages to install before using this resolver.
|
|
57
|
+
*/
|
|
58
|
+
readonly optionalPackages?: readonly string[];
|
|
53
59
|
resolve: (credential: string) => typeof globalThis.fetch | Promise<typeof globalThis.fetch>;
|
|
54
60
|
}
|
|
55
61
|
/**
|
|
@@ -68,6 +74,12 @@ interface SingleConnectionResolver<TName extends string = string> {
|
|
|
68
74
|
interface MultiConnectionResolver<TName extends string = string, TSuffixes extends readonly string[] = readonly string[]> {
|
|
69
75
|
readonly name: TName;
|
|
70
76
|
readonly keySuffixes: TSuffixes;
|
|
77
|
+
/**
|
|
78
|
+
* npm package names that must be installed for this resolver to function
|
|
79
|
+
* at runtime. Declared here so `--help` can check availability and tell
|
|
80
|
+
* the agent which packages to install before using this resolver.
|
|
81
|
+
*/
|
|
82
|
+
readonly optionalPackages?: readonly string[];
|
|
71
83
|
resolve: (credentials: Record<TSuffixes[number], string>) => typeof globalThis.fetch | Promise<typeof globalThis.fetch>;
|
|
72
84
|
}
|
|
73
85
|
/** Either resolver shape. */
|
package/dist/index.d.ts
CHANGED
|
@@ -50,6 +50,12 @@ type EnvFromKey<K extends string> = Uppercase<Replace<K, "-", "_">>;
|
|
|
50
50
|
interface SingleConnectionResolver<TName extends string = string> {
|
|
51
51
|
readonly name: TName;
|
|
52
52
|
readonly keySuffixes?: undefined;
|
|
53
|
+
/**
|
|
54
|
+
* npm package names that must be installed for this resolver to function
|
|
55
|
+
* at runtime. Declared here so `--help` can check availability and tell
|
|
56
|
+
* the agent which packages to install before using this resolver.
|
|
57
|
+
*/
|
|
58
|
+
readonly optionalPackages?: readonly string[];
|
|
53
59
|
resolve: (credential: string) => typeof globalThis.fetch | Promise<typeof globalThis.fetch>;
|
|
54
60
|
}
|
|
55
61
|
/**
|
|
@@ -68,6 +74,12 @@ interface SingleConnectionResolver<TName extends string = string> {
|
|
|
68
74
|
interface MultiConnectionResolver<TName extends string = string, TSuffixes extends readonly string[] = readonly string[]> {
|
|
69
75
|
readonly name: TName;
|
|
70
76
|
readonly keySuffixes: TSuffixes;
|
|
77
|
+
/**
|
|
78
|
+
* npm package names that must be installed for this resolver to function
|
|
79
|
+
* at runtime. Declared here so `--help` can check availability and tell
|
|
80
|
+
* the agent which packages to install before using this resolver.
|
|
81
|
+
*/
|
|
82
|
+
readonly optionalPackages?: readonly string[];
|
|
71
83
|
resolve: (credentials: Record<TSuffixes[number], string>) => typeof globalThis.fetch | Promise<typeof globalThis.fetch>;
|
|
72
84
|
}
|
|
73
85
|
/** Either resolver shape. */
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ function defineConnectionResolver(resolver) {
|
|
|
4
4
|
}
|
|
5
5
|
var zapierConnectionResolver = defineConnectionResolver({
|
|
6
6
|
name: "zapier-connection-id",
|
|
7
|
+
optionalPackages: ["@zapier/zapier-sdk"],
|
|
7
8
|
resolve: async (connectionId) => {
|
|
8
9
|
const { buildZapierFetch } = await import("./build-zapier-fetch-DWCYBAF4.js");
|
|
9
10
|
return buildZapierFetch(connectionId);
|
|
@@ -23,6 +24,9 @@ function defineBearerTokenResolver(opts = {}) {
|
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
// src/normalize-connections.ts
|
|
28
|
+
import { createRequire } from "module";
|
|
29
|
+
|
|
26
30
|
// src/connection-key.ts
|
|
27
31
|
function envFromKey(name) {
|
|
28
32
|
return name.toUpperCase().replace(/-/g, "_");
|
|
@@ -162,23 +166,70 @@ function buildRunOptionsFromEnv(definition, env, connectionResolvers) {
|
|
|
162
166
|
}
|
|
163
167
|
return { connections: wrapped };
|
|
164
168
|
}
|
|
165
|
-
function
|
|
169
|
+
function isPackageInstalled(name) {
|
|
170
|
+
try {
|
|
171
|
+
createRequire(import.meta.url).resolve(name);
|
|
172
|
+
return true;
|
|
173
|
+
} catch {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function formatHelpForConnections(definition, connectionResolvers, env) {
|
|
166
178
|
const slots = [...walkConnections(definition)];
|
|
167
179
|
if (slots.length === 0) return [];
|
|
168
180
|
const lines = [];
|
|
169
181
|
lines.push(
|
|
170
|
-
"
|
|
182
|
+
"Auth (set as environment variables; do NOT pass via CLI argument):"
|
|
171
183
|
);
|
|
184
|
+
const notReadySlots = [];
|
|
172
185
|
for (const { slotName, connectionKey } of slots) {
|
|
173
186
|
const resolvers = resolversForKey(connectionResolvers, connectionKey);
|
|
174
|
-
|
|
175
|
-
|
|
187
|
+
if (slotName !== void 0) {
|
|
188
|
+
lines.push(` ${slotName} (${connectionKey}):`);
|
|
189
|
+
}
|
|
190
|
+
const resolverIndent = slotName !== void 0 ? " " : " ";
|
|
191
|
+
const varIndent = slotName !== void 0 ? " " : " ";
|
|
192
|
+
let slotHasReady = false;
|
|
176
193
|
for (const resolver of resolvers) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
194
|
+
const vars = envVarsFor(slotName, connectionKey, resolver);
|
|
195
|
+
let isReady = false;
|
|
196
|
+
let missingPkgs = [];
|
|
197
|
+
if (env !== void 0) {
|
|
198
|
+
const envVarsOk = vars.every(
|
|
199
|
+
(k) => typeof env[k] === "string" && env[k] !== ""
|
|
200
|
+
);
|
|
201
|
+
if (envVarsOk) isReady = true;
|
|
202
|
+
missingPkgs = (resolver.optionalPackages ?? []).filter(
|
|
203
|
+
(pkg) => !isPackageInstalled(pkg)
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
const markReady = isReady && !slotHasReady;
|
|
207
|
+
if (markReady) slotHasReady = true;
|
|
208
|
+
const resolverSuffix = env !== void 0 && markReady ? " [READY \u2014 use this]" : "";
|
|
209
|
+
lines.push(`${resolverIndent}${resolver.name}:${resolverSuffix}`);
|
|
210
|
+
for (const envVar of vars) {
|
|
211
|
+
const varSuffix = env !== void 0 ? env[envVar] !== void 0 && env[envVar] !== "" ? " [set]" : " [not set]" : "";
|
|
212
|
+
lines.push(`${varIndent}${envVar}${varSuffix}`);
|
|
213
|
+
}
|
|
214
|
+
if (env !== void 0) {
|
|
215
|
+
for (const pkg of resolver.optionalPackages ?? []) {
|
|
216
|
+
if (missingPkgs.includes(pkg)) {
|
|
217
|
+
lines.push(
|
|
218
|
+
`${varIndent}${pkg} [not installed \u2014 run \`npm install ${pkg}\` first]`
|
|
219
|
+
);
|
|
220
|
+
} else {
|
|
221
|
+
lines.push(`${varIndent}${pkg} [installed]`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
180
224
|
}
|
|
181
225
|
}
|
|
226
|
+
if (env !== void 0 && !slotHasReady) {
|
|
227
|
+
notReadySlots.push(slotName ?? connectionKey);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (env !== void 0 && notReadySlots.length > 0) {
|
|
231
|
+
const label = notReadySlots.length === slots.length ? "No option is ready" : `No option is ready for slot${notReadySlots.length > 1 ? "s" : ""} ${notReadySlots.join(", ")}`;
|
|
232
|
+
lines.push(`${label} \u2014 set one of the env vars above.`);
|
|
182
233
|
}
|
|
183
234
|
return lines;
|
|
184
235
|
}
|
|
@@ -816,7 +867,8 @@ async function handleIfScriptMainBody(wrappedScript, connectionResolvers, io) {
|
|
|
816
867
|
if (helpRequested) {
|
|
817
868
|
io.stdout.write(
|
|
818
869
|
buildHelpText(wrappedScript, connectionResolvers, {
|
|
819
|
-
invocation: io.invocation
|
|
870
|
+
invocation: io.invocation,
|
|
871
|
+
env: io.env
|
|
820
872
|
})
|
|
821
873
|
);
|
|
822
874
|
return;
|
|
@@ -864,7 +916,8 @@ function buildHelpText(definition, connectionResolvers, opts = {}) {
|
|
|
864
916
|
}
|
|
865
917
|
const connectionsBlock = formatHelpForConnections(
|
|
866
918
|
definition,
|
|
867
|
-
connectionResolvers
|
|
919
|
+
connectionResolvers,
|
|
920
|
+
opts.env
|
|
868
921
|
);
|
|
869
922
|
if (connectionsBlock.length > 0) {
|
|
870
923
|
lines.push(...connectionsBlock);
|
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.6",
|
|
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",
|