@zapier/connectors-sdk 0.1.0-experimental.5 → 0.1.0-experimental.7
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 +25 -13
- package/dist/index.d.ts +25 -13
- 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. */
|
|
@@ -160,7 +172,7 @@ interface ContextMulti<TSlots extends string = string> {
|
|
|
160
172
|
type AnyInputDependencies$1 = Readonly<Record<string, unknown>>;
|
|
161
173
|
/** When authoring omits `inputDependencies`, the definition value is `undefined`. */
|
|
162
174
|
type InputDependenciesValue<T> = [T] extends [undefined] ? undefined : T;
|
|
163
|
-
interface DefineToolConfigBase<TIn extends z.
|
|
175
|
+
interface DefineToolConfigBase<TIn extends z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies$1 | undefined, TName extends string> {
|
|
164
176
|
name: TName;
|
|
165
177
|
title: string;
|
|
166
178
|
description: string;
|
|
@@ -169,22 +181,22 @@ interface DefineToolConfigBase<TIn extends z.ZodType, TOut extends z.ZodType, TI
|
|
|
169
181
|
annotations: _modelcontextprotocol_sdk_types_js.Tool["annotations"];
|
|
170
182
|
inputDependencies?: TInputDependencies;
|
|
171
183
|
}
|
|
172
|
-
interface DefineToolConfigNone<TIn extends z.
|
|
184
|
+
interface DefineToolConfigNone<TIn extends z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies$1 | undefined, TName extends string> extends DefineToolConfigBase<TIn, TOut, TInputDependencies, TName> {
|
|
173
185
|
connection?: never;
|
|
174
186
|
connections?: never;
|
|
175
187
|
run: (input: z.infer<TIn>, ctx?: ContextNone) => Promise<unknown>;
|
|
176
188
|
}
|
|
177
|
-
interface DefineToolConfigSingle<TIn extends z.
|
|
189
|
+
interface DefineToolConfigSingle<TIn extends z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies$1 | undefined, TName extends string, TKey extends string> extends DefineToolConfigBase<TIn, TOut, TInputDependencies, TName> {
|
|
178
190
|
connection: TKey;
|
|
179
191
|
connections?: never;
|
|
180
192
|
run: (input: z.infer<TIn>, ctx: ContextSingle) => Promise<unknown>;
|
|
181
193
|
}
|
|
182
|
-
interface DefineToolConfigMulti<TIn extends z.
|
|
194
|
+
interface DefineToolConfigMulti<TIn extends z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies$1 | undefined, TName extends string, TSlots extends string, TKey extends string> extends DefineToolConfigBase<TIn, TOut, TInputDependencies, TName> {
|
|
183
195
|
connection?: never;
|
|
184
196
|
connections: Record<TSlots, TKey>;
|
|
185
197
|
run: (input: z.infer<TIn>, ctx: ContextMulti<TSlots>) => Promise<unknown>;
|
|
186
198
|
}
|
|
187
|
-
interface ToolDefinitionBase<TIn extends z.
|
|
199
|
+
interface ToolDefinitionBase<TIn extends z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies$1 | undefined, TName extends string> {
|
|
188
200
|
readonly kind: "tool";
|
|
189
201
|
readonly name: TName;
|
|
190
202
|
readonly title: string;
|
|
@@ -194,25 +206,25 @@ interface ToolDefinitionBase<TIn extends z.ZodType, TOut extends z.ZodType, TInp
|
|
|
194
206
|
readonly annotations: _modelcontextprotocol_sdk_types_js.Tool["annotations"];
|
|
195
207
|
inputDependencies: InputDependenciesValue<TInputDependencies>;
|
|
196
208
|
}
|
|
197
|
-
interface ToolDefinitionNone<TIn extends z.
|
|
209
|
+
interface ToolDefinitionNone<TIn extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies$1 | undefined = undefined, TName extends string = string> extends ToolDefinitionBase<TIn, TOut, TInputDependencies, TName> {
|
|
198
210
|
readonly connection?: undefined;
|
|
199
211
|
readonly connections?: undefined;
|
|
200
212
|
run: (input: z.infer<TIn>, ctx?: ContextNone) => Promise<z.infer<TOut>>;
|
|
201
213
|
}
|
|
202
|
-
interface ToolDefinitionSingle<TIn extends z.
|
|
214
|
+
interface ToolDefinitionSingle<TIn extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies$1 | undefined = undefined, TName extends string = string, TKey extends string = string> extends ToolDefinitionBase<TIn, TOut, TInputDependencies, TName> {
|
|
203
215
|
readonly connection: TKey;
|
|
204
216
|
readonly connections?: undefined;
|
|
205
217
|
run: (input: z.infer<TIn>, ctx: ContextSingle) => Promise<z.infer<TOut>>;
|
|
206
218
|
}
|
|
207
|
-
interface ToolDefinitionMulti<TIn extends z.
|
|
219
|
+
interface ToolDefinitionMulti<TIn extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies$1 | undefined = undefined, TName extends string = string, TSlots extends string = string, TKey extends string = string> extends ToolDefinitionBase<TIn, TOut, TInputDependencies, TName> {
|
|
208
220
|
readonly connection?: undefined;
|
|
209
221
|
readonly connections: Record<TSlots, TKey>;
|
|
210
222
|
run: (input: z.infer<TIn>, ctx: ContextMulti<TSlots>) => Promise<z.infer<TOut>>;
|
|
211
223
|
}
|
|
212
|
-
type ToolDefinition<TIn extends z.
|
|
224
|
+
type ToolDefinition<TIn extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies$1 | undefined = undefined, TName extends string = string, TSlots extends string = string, TKey extends string = string> = ToolDefinitionNone<TIn, TOut, TInputDependencies, TName> | ToolDefinitionSingle<TIn, TOut, TInputDependencies, TName, TKey> | ToolDefinitionMulti<TIn, TOut, TInputDependencies, TName, TSlots, TKey>;
|
|
213
225
|
/** Wide author-side `run` signature for polymorphic walks. */
|
|
214
226
|
type AnyToolDefinitionRun = (input: any, ctx?: any) => Promise<any>;
|
|
215
|
-
type AnyToolDefinition = Omit<ToolDefinitionBase<z.
|
|
227
|
+
type AnyToolDefinition = Omit<ToolDefinitionBase<z.ZodObject<z.ZodRawShape>, z.ZodObject<z.ZodRawShape>, any, string>, "run" | "inputDependencies"> & {
|
|
216
228
|
inputDependencies: AnyInputDependencies$1 | undefined;
|
|
217
229
|
run: AnyToolDefinitionRun;
|
|
218
230
|
readonly connection?: string | undefined;
|
|
@@ -445,9 +457,9 @@ declare function defineConnector<TScripts extends Record<string, AnyDef>, const
|
|
|
445
457
|
*/
|
|
446
458
|
|
|
447
459
|
type AnyInputDependencies = Readonly<Record<string, unknown>>;
|
|
448
|
-
declare function defineTool<TIn extends z.
|
|
449
|
-
declare function defineTool<TIn extends z.
|
|
450
|
-
declare function defineTool<TIn extends z.
|
|
460
|
+
declare function defineTool<TIn extends z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies | undefined = undefined, const TName extends string = string>(config: DefineToolConfigNone<TIn, TOut, TInputDependencies, TName>): ToolDefinitionNone<TIn, TOut, TInputDependencies, TName>;
|
|
461
|
+
declare function defineTool<TIn extends z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies | undefined = undefined, const TName extends string = string, const TKey extends string = string>(config: DefineToolConfigSingle<TIn, TOut, TInputDependencies, TName, TKey>): ToolDefinitionSingle<TIn, TOut, TInputDependencies, TName, TKey>;
|
|
462
|
+
declare function defineTool<TIn extends z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies | undefined = undefined, const TName extends string = string, const TSlots extends string = string, const TKey extends string = string>(config: DefineToolConfigMulti<TIn, TOut, TInputDependencies, TName, TSlots, TKey>): ToolDefinitionMulti<TIn, TOut, TInputDependencies, TName, TSlots, TKey>;
|
|
451
463
|
|
|
452
464
|
/**
|
|
453
465
|
* `handleIfScriptMain(meta, definition, opts?)` — per-script CLI execution
|
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. */
|
|
@@ -160,7 +172,7 @@ interface ContextMulti<TSlots extends string = string> {
|
|
|
160
172
|
type AnyInputDependencies$1 = Readonly<Record<string, unknown>>;
|
|
161
173
|
/** When authoring omits `inputDependencies`, the definition value is `undefined`. */
|
|
162
174
|
type InputDependenciesValue<T> = [T] extends [undefined] ? undefined : T;
|
|
163
|
-
interface DefineToolConfigBase<TIn extends z.
|
|
175
|
+
interface DefineToolConfigBase<TIn extends z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies$1 | undefined, TName extends string> {
|
|
164
176
|
name: TName;
|
|
165
177
|
title: string;
|
|
166
178
|
description: string;
|
|
@@ -169,22 +181,22 @@ interface DefineToolConfigBase<TIn extends z.ZodType, TOut extends z.ZodType, TI
|
|
|
169
181
|
annotations: _modelcontextprotocol_sdk_types_js.Tool["annotations"];
|
|
170
182
|
inputDependencies?: TInputDependencies;
|
|
171
183
|
}
|
|
172
|
-
interface DefineToolConfigNone<TIn extends z.
|
|
184
|
+
interface DefineToolConfigNone<TIn extends z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies$1 | undefined, TName extends string> extends DefineToolConfigBase<TIn, TOut, TInputDependencies, TName> {
|
|
173
185
|
connection?: never;
|
|
174
186
|
connections?: never;
|
|
175
187
|
run: (input: z.infer<TIn>, ctx?: ContextNone) => Promise<unknown>;
|
|
176
188
|
}
|
|
177
|
-
interface DefineToolConfigSingle<TIn extends z.
|
|
189
|
+
interface DefineToolConfigSingle<TIn extends z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies$1 | undefined, TName extends string, TKey extends string> extends DefineToolConfigBase<TIn, TOut, TInputDependencies, TName> {
|
|
178
190
|
connection: TKey;
|
|
179
191
|
connections?: never;
|
|
180
192
|
run: (input: z.infer<TIn>, ctx: ContextSingle) => Promise<unknown>;
|
|
181
193
|
}
|
|
182
|
-
interface DefineToolConfigMulti<TIn extends z.
|
|
194
|
+
interface DefineToolConfigMulti<TIn extends z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies$1 | undefined, TName extends string, TSlots extends string, TKey extends string> extends DefineToolConfigBase<TIn, TOut, TInputDependencies, TName> {
|
|
183
195
|
connection?: never;
|
|
184
196
|
connections: Record<TSlots, TKey>;
|
|
185
197
|
run: (input: z.infer<TIn>, ctx: ContextMulti<TSlots>) => Promise<unknown>;
|
|
186
198
|
}
|
|
187
|
-
interface ToolDefinitionBase<TIn extends z.
|
|
199
|
+
interface ToolDefinitionBase<TIn extends z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies$1 | undefined, TName extends string> {
|
|
188
200
|
readonly kind: "tool";
|
|
189
201
|
readonly name: TName;
|
|
190
202
|
readonly title: string;
|
|
@@ -194,25 +206,25 @@ interface ToolDefinitionBase<TIn extends z.ZodType, TOut extends z.ZodType, TInp
|
|
|
194
206
|
readonly annotations: _modelcontextprotocol_sdk_types_js.Tool["annotations"];
|
|
195
207
|
inputDependencies: InputDependenciesValue<TInputDependencies>;
|
|
196
208
|
}
|
|
197
|
-
interface ToolDefinitionNone<TIn extends z.
|
|
209
|
+
interface ToolDefinitionNone<TIn extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies$1 | undefined = undefined, TName extends string = string> extends ToolDefinitionBase<TIn, TOut, TInputDependencies, TName> {
|
|
198
210
|
readonly connection?: undefined;
|
|
199
211
|
readonly connections?: undefined;
|
|
200
212
|
run: (input: z.infer<TIn>, ctx?: ContextNone) => Promise<z.infer<TOut>>;
|
|
201
213
|
}
|
|
202
|
-
interface ToolDefinitionSingle<TIn extends z.
|
|
214
|
+
interface ToolDefinitionSingle<TIn extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies$1 | undefined = undefined, TName extends string = string, TKey extends string = string> extends ToolDefinitionBase<TIn, TOut, TInputDependencies, TName> {
|
|
203
215
|
readonly connection: TKey;
|
|
204
216
|
readonly connections?: undefined;
|
|
205
217
|
run: (input: z.infer<TIn>, ctx: ContextSingle) => Promise<z.infer<TOut>>;
|
|
206
218
|
}
|
|
207
|
-
interface ToolDefinitionMulti<TIn extends z.
|
|
219
|
+
interface ToolDefinitionMulti<TIn extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies$1 | undefined = undefined, TName extends string = string, TSlots extends string = string, TKey extends string = string> extends ToolDefinitionBase<TIn, TOut, TInputDependencies, TName> {
|
|
208
220
|
readonly connection?: undefined;
|
|
209
221
|
readonly connections: Record<TSlots, TKey>;
|
|
210
222
|
run: (input: z.infer<TIn>, ctx: ContextMulti<TSlots>) => Promise<z.infer<TOut>>;
|
|
211
223
|
}
|
|
212
|
-
type ToolDefinition<TIn extends z.
|
|
224
|
+
type ToolDefinition<TIn extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies$1 | undefined = undefined, TName extends string = string, TSlots extends string = string, TKey extends string = string> = ToolDefinitionNone<TIn, TOut, TInputDependencies, TName> | ToolDefinitionSingle<TIn, TOut, TInputDependencies, TName, TKey> | ToolDefinitionMulti<TIn, TOut, TInputDependencies, TName, TSlots, TKey>;
|
|
213
225
|
/** Wide author-side `run` signature for polymorphic walks. */
|
|
214
226
|
type AnyToolDefinitionRun = (input: any, ctx?: any) => Promise<any>;
|
|
215
|
-
type AnyToolDefinition = Omit<ToolDefinitionBase<z.
|
|
227
|
+
type AnyToolDefinition = Omit<ToolDefinitionBase<z.ZodObject<z.ZodRawShape>, z.ZodObject<z.ZodRawShape>, any, string>, "run" | "inputDependencies"> & {
|
|
216
228
|
inputDependencies: AnyInputDependencies$1 | undefined;
|
|
217
229
|
run: AnyToolDefinitionRun;
|
|
218
230
|
readonly connection?: string | undefined;
|
|
@@ -445,9 +457,9 @@ declare function defineConnector<TScripts extends Record<string, AnyDef>, const
|
|
|
445
457
|
*/
|
|
446
458
|
|
|
447
459
|
type AnyInputDependencies = Readonly<Record<string, unknown>>;
|
|
448
|
-
declare function defineTool<TIn extends z.
|
|
449
|
-
declare function defineTool<TIn extends z.
|
|
450
|
-
declare function defineTool<TIn extends z.
|
|
460
|
+
declare function defineTool<TIn extends z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies | undefined = undefined, const TName extends string = string>(config: DefineToolConfigNone<TIn, TOut, TInputDependencies, TName>): ToolDefinitionNone<TIn, TOut, TInputDependencies, TName>;
|
|
461
|
+
declare function defineTool<TIn extends z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies | undefined = undefined, const TName extends string = string, const TKey extends string = string>(config: DefineToolConfigSingle<TIn, TOut, TInputDependencies, TName, TKey>): ToolDefinitionSingle<TIn, TOut, TInputDependencies, TName, TKey>;
|
|
462
|
+
declare function defineTool<TIn extends z.ZodObject<z.ZodRawShape>, TOut extends z.ZodObject<z.ZodRawShape>, TInputDependencies extends AnyInputDependencies | undefined = undefined, const TName extends string = string, const TSlots extends string = string, const TKey extends string = string>(config: DefineToolConfigMulti<TIn, TOut, TInputDependencies, TName, TSlots, TKey>): ToolDefinitionMulti<TIn, TOut, TInputDependencies, TName, TSlots, TKey>;
|
|
451
463
|
|
|
452
464
|
/**
|
|
453
465
|
* `handleIfScriptMain(meta, definition, opts?)` — per-script CLI execution
|
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.7",
|
|
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",
|