@zapier/connectors-sdk 0.1.0-experimental.1 → 0.1.0-experimental.3

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 CHANGED
@@ -368,8 +368,8 @@ function ensureConnectionValue(scriptName, slotName, connectionKey, value) {
368
368
  return value;
369
369
  }
370
370
  async function buildContext(definition, opts, connectionResolvers) {
371
- const hasConnection = "connection" in opts && opts.connection !== void 0;
372
- const hasConnections = "connections" in opts && opts.connections !== void 0;
371
+ const hasConnection = opts !== void 0 && "connection" in opts && opts.connection !== void 0;
372
+ const hasConnections = opts !== void 0 && "connections" in opts && opts.connections !== void 0;
373
373
  if (definition.connection === void 0 && definition.connections === void 0) {
374
374
  if (hasConnection || hasConnections) {
375
375
  throw new Error(
@@ -378,6 +378,11 @@ async function buildContext(definition, opts, connectionResolvers) {
378
378
  }
379
379
  return {};
380
380
  }
381
+ if (opts === void 0) {
382
+ throw new Error(
383
+ `ToolDefinition "${definition.name}": \`RunOptions\` is required \u2014 pass \`{ connection: ... }\` or \`{ connections: ... }\`.`
384
+ );
385
+ }
381
386
  if (hasConnection && hasConnections) {
382
387
  throw new Error(
383
388
  `ToolDefinition "${definition.name}": \`RunOptions\` sets both \`connection\` and \`connections\`. Use one or the other.`
@@ -395,7 +400,7 @@ async function buildContext(definition, opts, connectionResolvers) {
395
400
  definition.name,
396
401
  void 0,
397
402
  connectionKey,
398
- opts.connection
403
+ "connection" in opts ? opts.connection : void 0
399
404
  );
400
405
  const fetch = await resolveSlotFetch(
401
406
  definition.name,
@@ -412,12 +417,12 @@ async function buildContext(definition, opts, connectionResolvers) {
412
417
  `ToolDefinition "${definition.name}" is multi-connection (slots: ${declaredSlots.join(", ")}) \u2014 call with \`{ connections: { ... } }\`, not \`{ connection: ... }\`.`
413
418
  );
414
419
  }
415
- if (!hasConnections) {
420
+ const provided = opts.connections;
421
+ if (provided === void 0) {
416
422
  throw new Error(
417
423
  `ToolDefinition "${definition.name}" is multi-connection \u2014 \`RunOptions.connections\` is required.`
418
424
  );
419
425
  }
420
- const provided = opts.connections;
421
426
  const unknown = Object.keys(provided).filter(
422
427
  (s) => !declaredSlots.includes(s)
423
428
  );
@@ -516,24 +521,9 @@ function toResponsesTool(definition) {
516
521
 
517
522
  // src/define-connector.ts
518
523
  function wrapScriptWithResolvers(definition, connectionResolvers) {
519
- const authorRun = definition.run;
520
524
  const wrappedRun = async (input, opts) => {
521
- const validated = definition.inputSchema.parse(input);
522
- if (definition.connection === void 0 && definition.connections === void 0) {
523
- if (opts !== void 0 && (opts.connection !== void 0 || opts.connections !== void 0)) {
524
- throw new Error(
525
- `ToolDefinition "${definition.name}" is credential-free \u2014 \`RunOptions\` must not include \`connection\` or \`connections\`.`
526
- );
527
- }
528
- return authorRun(validated);
529
- }
530
- if (opts === void 0) {
531
- throw new Error(
532
- `ToolDefinition "${definition.name}": \`RunOptions\` is required \u2014 pass \`{ connection: ... }\` or \`{ connections: ... }\`.`
533
- );
534
- }
535
525
  const ctx = await buildContext(definition, opts, connectionResolvers);
536
- return authorRun(validated, ctx);
526
+ return definition.run(input, ctx);
537
527
  };
538
528
  return { ...definition, run: wrappedRun };
539
529
  }
@@ -612,6 +602,12 @@ function defineTool(config) {
612
602
  validateConnectionKey(config.name, value);
613
603
  }
614
604
  }
605
+ const authorRun = config.run;
606
+ const wrappedRun = async (input, ctx) => {
607
+ const validated = config.inputSchema.parse(input);
608
+ const result = await authorRun(validated, ctx);
609
+ return config.outputSchema.parse(result);
610
+ };
615
611
  const base = {
616
612
  kind: "tool",
617
613
  name: config.name,
@@ -620,9 +616,8 @@ function defineTool(config) {
620
616
  inputSchema: config.inputSchema,
621
617
  outputSchema: config.outputSchema,
622
618
  annotations: config.annotations,
623
- statements: config.statements,
624
619
  inputDependencies: config.inputDependencies,
625
- run: config.run
620
+ run: wrappedRun
626
621
  };
627
622
  if (hasSingular) base.connection = config.connection;
628
623
  if (hasPlural) base.connections = config.connections;
package/dist/index.d.cts CHANGED
@@ -30,24 +30,6 @@ type Replace<S extends string, From extends string, To extends string> = S exten
30
30
  */
31
31
  type EnvFromKey<K extends string> = Uppercase<Replace<K, "-", "_">>;
32
32
 
33
- /**
34
- * A Zapier policy statement. Carried on the `ToolDefinition` for in-process
35
- * governance consumers (policy engines that wrap `script.run` before HTTP).
36
- * Not propagated to MCP `_meta` — only `inputDependencies` is published over
37
- * the wire (`_meta["zapier:inputDependencies"]`) by `toMcpTool` /
38
- * `toMcpServerTool`.
39
- */
40
- interface Statement {
41
- effect: "allow" | "ask" | "deny";
42
- permissions: ReadonlyArray<string>;
43
- resources: ReadonlyArray<string>;
44
- conditions?: ReadonlyArray<{
45
- path: ReadonlyArray<string>;
46
- operator: string;
47
- value: unknown;
48
- }>;
49
- label?: string;
50
- }
51
33
  /**
52
34
  * Single-credential resolver: the resolver's `name` IS the credential
53
35
  * descriptor. `resolve` receives the credential as a plain `string` —
@@ -160,12 +142,19 @@ interface RunOptionsMulti<TSlots extends string = string, TPerSlot extends Recor
160
142
  connections: TPerSlot;
161
143
  }
162
144
  type RunOptions<TSlots extends string = string, TValue = ConnectionValue, TPerSlot extends Record<TSlots, ConnectionValue> = Record<TSlots, ConnectionValue>> = RunOptionsNone | RunOptionsSingle<TValue> | RunOptionsMulti<TSlots, TPerSlot>;
145
+ /** Author-facing context for a credential-free script. */
146
+ interface ContextNone {
147
+ fetch?: undefined;
148
+ connections?: undefined;
149
+ }
163
150
  /** Author-facing context for a single-connection script. */
164
151
  interface ContextSingle {
165
152
  fetch: typeof globalThis.fetch;
153
+ connections?: never;
166
154
  }
167
155
  /** Author-facing context for a multi-connection script. */
168
156
  interface ContextMulti<TSlots extends string = string> {
157
+ fetch?: never;
169
158
  connections: Record<TSlots, typeof globalThis.fetch>;
170
159
  }
171
160
  type AnyInputDependencies$1 = Readonly<Record<string, unknown>>;
@@ -178,23 +167,22 @@ interface DefineToolConfigBase<TIn extends z.ZodType, TOut extends z.ZodType, TI
178
167
  inputSchema: TIn;
179
168
  outputSchema: TOut;
180
169
  annotations: _modelcontextprotocol_sdk_types_js.Tool["annotations"];
181
- statements?: ReadonlyArray<Statement>;
182
170
  inputDependencies?: TInputDependencies;
183
171
  }
184
172
  interface DefineToolConfigNone<TIn extends z.ZodType, TOut extends z.ZodType, TInputDependencies extends AnyInputDependencies$1 | undefined, TName extends string> extends DefineToolConfigBase<TIn, TOut, TInputDependencies, TName> {
185
173
  connection?: never;
186
174
  connections?: never;
187
- run: (input: z.infer<TIn>) => Promise<z.infer<TOut>>;
175
+ run: (input: z.infer<TIn>, ctx?: ContextNone) => Promise<unknown>;
188
176
  }
189
177
  interface DefineToolConfigSingle<TIn extends z.ZodType, TOut extends z.ZodType, TInputDependencies extends AnyInputDependencies$1 | undefined, TName extends string, TKey extends string> extends DefineToolConfigBase<TIn, TOut, TInputDependencies, TName> {
190
178
  connection: TKey;
191
179
  connections?: never;
192
- run: (input: z.infer<TIn>, ctx: ContextSingle) => Promise<z.infer<TOut>>;
180
+ run: (input: z.infer<TIn>, ctx: ContextSingle) => Promise<unknown>;
193
181
  }
194
182
  interface DefineToolConfigMulti<TIn extends z.ZodType, TOut extends z.ZodType, TInputDependencies extends AnyInputDependencies$1 | undefined, TName extends string, TSlots extends string, TKey extends string> extends DefineToolConfigBase<TIn, TOut, TInputDependencies, TName> {
195
183
  connection?: never;
196
184
  connections: Record<TSlots, TKey>;
197
- run: (input: z.infer<TIn>, ctx: ContextMulti<TSlots>) => Promise<z.infer<TOut>>;
185
+ run: (input: z.infer<TIn>, ctx: ContextMulti<TSlots>) => Promise<unknown>;
198
186
  }
199
187
  interface ToolDefinitionBase<TIn extends z.ZodType, TOut extends z.ZodType, TInputDependencies extends AnyInputDependencies$1 | undefined, TName extends string> {
200
188
  readonly kind: "tool";
@@ -204,14 +192,12 @@ interface ToolDefinitionBase<TIn extends z.ZodType, TOut extends z.ZodType, TInp
204
192
  inputSchema: TIn;
205
193
  outputSchema: TOut;
206
194
  readonly annotations: _modelcontextprotocol_sdk_types_js.Tool["annotations"];
207
- readonly statements: ReadonlyArray<Statement> | undefined;
208
195
  inputDependencies: InputDependenciesValue<TInputDependencies>;
209
196
  }
210
197
  interface ToolDefinitionNone<TIn extends z.ZodType = z.ZodType, TOut extends z.ZodType = z.ZodType, TInputDependencies extends AnyInputDependencies$1 | undefined = undefined, TName extends string = string> extends ToolDefinitionBase<TIn, TOut, TInputDependencies, TName> {
211
198
  readonly connection?: undefined;
212
199
  readonly connections?: undefined;
213
- /** Author's run; the wrapper passes `input` directly. */
214
- run: (input: z.infer<TIn>) => Promise<z.infer<TOut>>;
200
+ run: (input: z.infer<TIn>, ctx?: ContextNone) => Promise<z.infer<TOut>>;
215
201
  }
216
202
  interface ToolDefinitionSingle<TIn extends z.ZodType = z.ZodType, TOut extends z.ZodType = z.ZodType, TInputDependencies extends AnyInputDependencies$1 | undefined = undefined, TName extends string = string, TKey extends string = string> extends ToolDefinitionBase<TIn, TOut, TInputDependencies, TName> {
217
203
  readonly connection: TKey;
package/dist/index.d.ts CHANGED
@@ -30,24 +30,6 @@ type Replace<S extends string, From extends string, To extends string> = S exten
30
30
  */
31
31
  type EnvFromKey<K extends string> = Uppercase<Replace<K, "-", "_">>;
32
32
 
33
- /**
34
- * A Zapier policy statement. Carried on the `ToolDefinition` for in-process
35
- * governance consumers (policy engines that wrap `script.run` before HTTP).
36
- * Not propagated to MCP `_meta` — only `inputDependencies` is published over
37
- * the wire (`_meta["zapier:inputDependencies"]`) by `toMcpTool` /
38
- * `toMcpServerTool`.
39
- */
40
- interface Statement {
41
- effect: "allow" | "ask" | "deny";
42
- permissions: ReadonlyArray<string>;
43
- resources: ReadonlyArray<string>;
44
- conditions?: ReadonlyArray<{
45
- path: ReadonlyArray<string>;
46
- operator: string;
47
- value: unknown;
48
- }>;
49
- label?: string;
50
- }
51
33
  /**
52
34
  * Single-credential resolver: the resolver's `name` IS the credential
53
35
  * descriptor. `resolve` receives the credential as a plain `string` —
@@ -160,12 +142,19 @@ interface RunOptionsMulti<TSlots extends string = string, TPerSlot extends Recor
160
142
  connections: TPerSlot;
161
143
  }
162
144
  type RunOptions<TSlots extends string = string, TValue = ConnectionValue, TPerSlot extends Record<TSlots, ConnectionValue> = Record<TSlots, ConnectionValue>> = RunOptionsNone | RunOptionsSingle<TValue> | RunOptionsMulti<TSlots, TPerSlot>;
145
+ /** Author-facing context for a credential-free script. */
146
+ interface ContextNone {
147
+ fetch?: undefined;
148
+ connections?: undefined;
149
+ }
163
150
  /** Author-facing context for a single-connection script. */
164
151
  interface ContextSingle {
165
152
  fetch: typeof globalThis.fetch;
153
+ connections?: never;
166
154
  }
167
155
  /** Author-facing context for a multi-connection script. */
168
156
  interface ContextMulti<TSlots extends string = string> {
157
+ fetch?: never;
169
158
  connections: Record<TSlots, typeof globalThis.fetch>;
170
159
  }
171
160
  type AnyInputDependencies$1 = Readonly<Record<string, unknown>>;
@@ -178,23 +167,22 @@ interface DefineToolConfigBase<TIn extends z.ZodType, TOut extends z.ZodType, TI
178
167
  inputSchema: TIn;
179
168
  outputSchema: TOut;
180
169
  annotations: _modelcontextprotocol_sdk_types_js.Tool["annotations"];
181
- statements?: ReadonlyArray<Statement>;
182
170
  inputDependencies?: TInputDependencies;
183
171
  }
184
172
  interface DefineToolConfigNone<TIn extends z.ZodType, TOut extends z.ZodType, TInputDependencies extends AnyInputDependencies$1 | undefined, TName extends string> extends DefineToolConfigBase<TIn, TOut, TInputDependencies, TName> {
185
173
  connection?: never;
186
174
  connections?: never;
187
- run: (input: z.infer<TIn>) => Promise<z.infer<TOut>>;
175
+ run: (input: z.infer<TIn>, ctx?: ContextNone) => Promise<unknown>;
188
176
  }
189
177
  interface DefineToolConfigSingle<TIn extends z.ZodType, TOut extends z.ZodType, TInputDependencies extends AnyInputDependencies$1 | undefined, TName extends string, TKey extends string> extends DefineToolConfigBase<TIn, TOut, TInputDependencies, TName> {
190
178
  connection: TKey;
191
179
  connections?: never;
192
- run: (input: z.infer<TIn>, ctx: ContextSingle) => Promise<z.infer<TOut>>;
180
+ run: (input: z.infer<TIn>, ctx: ContextSingle) => Promise<unknown>;
193
181
  }
194
182
  interface DefineToolConfigMulti<TIn extends z.ZodType, TOut extends z.ZodType, TInputDependencies extends AnyInputDependencies$1 | undefined, TName extends string, TSlots extends string, TKey extends string> extends DefineToolConfigBase<TIn, TOut, TInputDependencies, TName> {
195
183
  connection?: never;
196
184
  connections: Record<TSlots, TKey>;
197
- run: (input: z.infer<TIn>, ctx: ContextMulti<TSlots>) => Promise<z.infer<TOut>>;
185
+ run: (input: z.infer<TIn>, ctx: ContextMulti<TSlots>) => Promise<unknown>;
198
186
  }
199
187
  interface ToolDefinitionBase<TIn extends z.ZodType, TOut extends z.ZodType, TInputDependencies extends AnyInputDependencies$1 | undefined, TName extends string> {
200
188
  readonly kind: "tool";
@@ -204,14 +192,12 @@ interface ToolDefinitionBase<TIn extends z.ZodType, TOut extends z.ZodType, TInp
204
192
  inputSchema: TIn;
205
193
  outputSchema: TOut;
206
194
  readonly annotations: _modelcontextprotocol_sdk_types_js.Tool["annotations"];
207
- readonly statements: ReadonlyArray<Statement> | undefined;
208
195
  inputDependencies: InputDependenciesValue<TInputDependencies>;
209
196
  }
210
197
  interface ToolDefinitionNone<TIn extends z.ZodType = z.ZodType, TOut extends z.ZodType = z.ZodType, TInputDependencies extends AnyInputDependencies$1 | undefined = undefined, TName extends string = string> extends ToolDefinitionBase<TIn, TOut, TInputDependencies, TName> {
211
198
  readonly connection?: undefined;
212
199
  readonly connections?: undefined;
213
- /** Author's run; the wrapper passes `input` directly. */
214
- run: (input: z.infer<TIn>) => Promise<z.infer<TOut>>;
200
+ run: (input: z.infer<TIn>, ctx?: ContextNone) => Promise<z.infer<TOut>>;
215
201
  }
216
202
  interface ToolDefinitionSingle<TIn extends z.ZodType = z.ZodType, TOut extends z.ZodType = z.ZodType, TInputDependencies extends AnyInputDependencies$1 | undefined = undefined, TName extends string = string, TKey extends string = string> extends ToolDefinitionBase<TIn, TOut, TInputDependencies, TName> {
217
203
  readonly connection: TKey;
package/dist/index.js CHANGED
@@ -263,8 +263,8 @@ function ensureConnectionValue(scriptName, slotName, connectionKey, value) {
263
263
  return value;
264
264
  }
265
265
  async function buildContext(definition, opts, connectionResolvers) {
266
- const hasConnection = "connection" in opts && opts.connection !== void 0;
267
- const hasConnections = "connections" in opts && opts.connections !== void 0;
266
+ const hasConnection = opts !== void 0 && "connection" in opts && opts.connection !== void 0;
267
+ const hasConnections = opts !== void 0 && "connections" in opts && opts.connections !== void 0;
268
268
  if (definition.connection === void 0 && definition.connections === void 0) {
269
269
  if (hasConnection || hasConnections) {
270
270
  throw new Error(
@@ -273,6 +273,11 @@ async function buildContext(definition, opts, connectionResolvers) {
273
273
  }
274
274
  return {};
275
275
  }
276
+ if (opts === void 0) {
277
+ throw new Error(
278
+ `ToolDefinition "${definition.name}": \`RunOptions\` is required \u2014 pass \`{ connection: ... }\` or \`{ connections: ... }\`.`
279
+ );
280
+ }
276
281
  if (hasConnection && hasConnections) {
277
282
  throw new Error(
278
283
  `ToolDefinition "${definition.name}": \`RunOptions\` sets both \`connection\` and \`connections\`. Use one or the other.`
@@ -290,7 +295,7 @@ async function buildContext(definition, opts, connectionResolvers) {
290
295
  definition.name,
291
296
  void 0,
292
297
  connectionKey,
293
- opts.connection
298
+ "connection" in opts ? opts.connection : void 0
294
299
  );
295
300
  const fetch = await resolveSlotFetch(
296
301
  definition.name,
@@ -307,12 +312,12 @@ async function buildContext(definition, opts, connectionResolvers) {
307
312
  `ToolDefinition "${definition.name}" is multi-connection (slots: ${declaredSlots.join(", ")}) \u2014 call with \`{ connections: { ... } }\`, not \`{ connection: ... }\`.`
308
313
  );
309
314
  }
310
- if (!hasConnections) {
315
+ const provided = opts.connections;
316
+ if (provided === void 0) {
311
317
  throw new Error(
312
318
  `ToolDefinition "${definition.name}" is multi-connection \u2014 \`RunOptions.connections\` is required.`
313
319
  );
314
320
  }
315
- const provided = opts.connections;
316
321
  const unknown = Object.keys(provided).filter(
317
322
  (s) => !declaredSlots.includes(s)
318
323
  );
@@ -411,24 +416,9 @@ function toResponsesTool(definition) {
411
416
 
412
417
  // src/define-connector.ts
413
418
  function wrapScriptWithResolvers(definition, connectionResolvers) {
414
- const authorRun = definition.run;
415
419
  const wrappedRun = async (input, opts) => {
416
- const validated = definition.inputSchema.parse(input);
417
- if (definition.connection === void 0 && definition.connections === void 0) {
418
- if (opts !== void 0 && (opts.connection !== void 0 || opts.connections !== void 0)) {
419
- throw new Error(
420
- `ToolDefinition "${definition.name}" is credential-free \u2014 \`RunOptions\` must not include \`connection\` or \`connections\`.`
421
- );
422
- }
423
- return authorRun(validated);
424
- }
425
- if (opts === void 0) {
426
- throw new Error(
427
- `ToolDefinition "${definition.name}": \`RunOptions\` is required \u2014 pass \`{ connection: ... }\` or \`{ connections: ... }\`.`
428
- );
429
- }
430
420
  const ctx = await buildContext(definition, opts, connectionResolvers);
431
- return authorRun(validated, ctx);
421
+ return definition.run(input, ctx);
432
422
  };
433
423
  return { ...definition, run: wrappedRun };
434
424
  }
@@ -507,6 +497,12 @@ function defineTool(config) {
507
497
  validateConnectionKey(config.name, value);
508
498
  }
509
499
  }
500
+ const authorRun = config.run;
501
+ const wrappedRun = async (input, ctx) => {
502
+ const validated = config.inputSchema.parse(input);
503
+ const result = await authorRun(validated, ctx);
504
+ return config.outputSchema.parse(result);
505
+ };
510
506
  const base = {
511
507
  kind: "tool",
512
508
  name: config.name,
@@ -515,9 +511,8 @@ function defineTool(config) {
515
511
  inputSchema: config.inputSchema,
516
512
  outputSchema: config.outputSchema,
517
513
  annotations: config.annotations,
518
- statements: config.statements,
519
514
  inputDependencies: config.inputDependencies,
520
- run: config.run
515
+ run: wrappedRun
521
516
  };
522
517
  if (hasSingular) base.connection = config.connection;
523
518
  if (hasPlural) base.connections = config.connections;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zapier/connectors-sdk",
3
- "version": "0.1.0-experimental.1",
3
+ "version": "0.1.0-experimental.3",
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,9 +24,6 @@
24
24
  "README.md",
25
25
  "LICENSE"
26
26
  ],
27
- "scripts": {
28
- "build": "tsup"
29
- },
30
27
  "peerDependencies": {
31
28
  "@modelcontextprotocol/sdk": "^1.0.0",
32
29
  "@zapier/zapier-sdk": "^0.59.0",
@@ -44,5 +41,8 @@
44
41
  "type": "git",
45
42
  "url": "https://gitlab.com/zapier/team-agents-platform/connectors.git",
46
43
  "directory": "packages/connectors-sdk"
44
+ },
45
+ "scripts": {
46
+ "build": "tsup"
47
47
  }
48
- }
48
+ }