@zuplo/runtime 6.70.24 → 6.70.26

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.
@@ -6106,16 +6106,24 @@ export declare const MTLSAuthInboundPolicy: InboundPolicyHandler<MTLSAuthInbound
6106
6106
  * The options for this policy.
6107
6107
  * @public
6108
6108
  */
6109
- export declare interface MTLSAuthInboundPolicyOptions {
6109
+ export declare type MTLSAuthInboundPolicyOptions = (
6110
+ | {
6111
+ [k: string]: unknown;
6112
+ }
6113
+ | {
6114
+ allowUnauthenticatedRequests: true;
6115
+ [k: string]: unknown;
6116
+ }
6117
+ ) & {
6110
6118
  /**
6111
6119
  * Allows requests to continue even when mTLS verification fails, no client certificate is presented, or the certificate metadata cannot be parsed. Defaults to false.
6112
6120
  */
6113
6121
  allowUnauthenticatedRequests?: boolean;
6114
6122
  /**
6115
- * Optional fully qualified issuer distinguished name to require on the client certificate. When set, the policy rejects certificates whose parsed issuer DN does not match this string exactly. The expected format matches the parsed metadata issuer, e.g. "CN=example-ca, O=Example, C=US".
6123
+ * Fully qualified issuer distinguished name to require on the client certificate. The policy rejects certificates whose parsed issuer DN does not match this string exactly. Required unless `allowUnauthenticatedRequests` is `true`. The expected format matches the parsed metadata issuer, e.g. "CN=example-ca, O=Example, C=US".
6116
6124
  */
6117
6125
  certIssuerDN?: string;
6118
- }
6126
+ };
6119
6127
 
6120
6128
  /**
6121
6129
  * Parsed client certificate metadata attached by the mTLS auth policy.
@@ -7410,6 +7418,7 @@ declare interface ParsedCorsPolicyConfiguration {
7410
7418
  */
7411
7419
  declare interface ParsedRouteData extends Omit<RouteData, "corsPolicies"> {
7412
7420
  corsPolicies: ParsedCorsPolicyConfiguration[];
7421
+ /* Excluded from this release type: getInboundPolicyInstance */
7413
7422
  }
7414
7423
 
7415
7424
  /**
@@ -504,52 +504,62 @@ declare type HttpStatusCodeRangeDefinition =
504
504
  | "5XX";
505
505
 
506
506
  /**
507
- * A function-based inbound policy that can modify the incoming HTTP request.
508
- * This is the simplest way to create custom policies without extending a class.
509
- *
510
- * @param request - The incoming Request
511
- * @param context - The current context of the Request
512
- * @param options - The configuration options for the policy
513
- * @param policyName - The name set on the policy in the configuration
514
- * @returns A Response to short-circuit or a Request to continue
507
+ * A policy that can modify the incoming HTTP request before it is sent to
508
+ * the handler. If a response is returned, the request is short-circuited and
509
+ * the response is returned to the client. If a Request is returned, policies
510
+ * or a handler that follow are executed.
515
511
  *
516
512
  * @public
517
513
  * @example
518
514
  * ```typescript
519
- * import { InboundPolicyHandler } from "@zuplo/runtime";
515
+ * import { InboundPolicy, ZuploContext, ZuploRequest } from "@zuplo/runtime";
520
516
  *
521
- * interface RateLimitOptions {
522
- * requests: number;
523
- * windowMs: number;
517
+ * interface MyPolicyOptions {
518
+ * headerName: string;
519
+ * headerValue: string;
524
520
  * }
525
521
  *
526
- * export const rateLimitPolicy: InboundPolicyHandler<RateLimitOptions> = async (
527
- * request,
528
- * context,
529
- * options,
530
- * policyName
531
- * ) => {
532
- * const key = request.headers.get("x-api-key") || "anonymous";
533
- * const count = await incrementCounter(key, options.windowMs);
522
+ * export class AddHeaderPolicy extends InboundPolicy<MyPolicyOptions> {
523
+ * async handler(request: ZuploRequest, context: ZuploContext) {
524
+ * // Add a custom header
525
+ * request.headers.set(this.options.headerName, this.options.headerValue);
534
526
  *
535
- * if (count > options.requests) {
536
- * return new Response("Too Many Requests", { status: 429 });
537
- * }
527
+ * // Log the action
528
+ * context.log.info(`Added header ${this.options.headerName}`);
538
529
  *
539
- * // Add rate limit headers
540
- * request.headers.set("X-RateLimit-Limit", options.requests.toString());
541
- * request.headers.set("X-RateLimit-Remaining", (options.requests - count).toString());
530
+ * // Continue to next policy/handler
531
+ * return request;
532
+ * }
533
+ * }
542
534
  *
543
- * return request;
544
- * };
535
+ * // Usage in policies.json:
536
+ * // {
537
+ * // "name": "add-custom-header",
538
+ * // "policyType": "custom-add-header-policy",
539
+ * // "handler": {
540
+ * // "export": "AddHeaderPolicy",
541
+ * // "module": "$import(./policies/add-header)",
542
+ * // "options": {
543
+ * // "headerName": "X-Custom-Header",
544
+ * // "headerValue": "My Value"
545
+ * // }
546
+ * // }
547
+ * // }
545
548
  * ```
546
549
  */
547
- declare interface InboundPolicyHandler<TOptions = any> {
548
- (
550
+ declare abstract class InboundPolicy<
551
+ TOptions = any,
552
+ > extends PolicyBase<TOptions> {
553
+ /**
554
+ * The handler that is called each time this policy is invoked
555
+ *
556
+ * @param request - The incoming Request
557
+ * @param context - The current context of the Request
558
+ * @returns A Response or Request object
559
+ */
560
+ abstract handler(
549
561
  request: ZuploRequest,
550
- context: ZuploContext,
551
- options: TOptions,
552
- policyName: string
562
+ context: ZuploContext
553
563
  ): Promise<ZuploRequest | Response>;
554
564
  }
555
565
 
@@ -937,22 +947,27 @@ declare interface Logger extends BaseLogger {
937
947
  * Authenticate MCP gateway requests using a gateway-issued OAuth access token,
938
948
  * with browser login delegated to Auth0.
939
949
  *
940
- * Auth0-friendly wrapper around `McpOAuthInboundPolicy`. Provide
941
- * `auth0Domain` and `clientId`; the wrapper derives the OIDC issuer, JWKS URL,
942
- * and Auth0 authorize/token endpoints automatically. The resolved options are
943
- * translated into the generic `McpOAuthRuntimeConfig` at gateway initialization
944
- * time (see `setupRoutes`); this request-time entry point delegates straight
945
- * to the underlying OAuth implementation.
950
+ * Auth0-friendly wrapper around `McpOAuthInboundPolicy`. Provide `auth0Domain`
951
+ * and `clientId`; the constructor derives the OIDC issuer, JWKS URL, and Auth0
952
+ * authorize/token endpoints automatically and runs the resulting shape through
953
+ * the same Zod schema as the generic policy.
954
+ *
955
+ * Validation runs lazily inside the policy constructor, which the runtime
956
+ * caches per policy name — so a misconfigured policy fails the first request
957
+ * with a `ConfigurationError` (surfaced in the 500 problem body) rather than
958
+ * crashing boot.
946
959
  *
947
960
  * @hidden
948
961
  * @title MCP Auth0 OAuth
949
- * @param request - The ZuploRequest
950
- * @param context - The ZuploContext
951
- * @param _options - The policy options set in policies.json
952
- * @param _policyName - The name of the policy as set in policies.json
953
- * @returns A Request or a Response
954
962
  */
955
- export declare const McpAuth0OAuthInboundPolicy: InboundPolicyHandler<McpAuth0OAuthInboundPolicyOptions>;
963
+ export declare class McpAuth0OAuthInboundPolicy extends InboundPolicy<McpAuth0OAuthInboundPolicyOptions> {
964
+ #private;
965
+ constructor(rawOptions: unknown, policyName: string);
966
+ handler(
967
+ request: ZuploRequest,
968
+ context: ZuploContext
969
+ ): Promise<ZuploRequest | Response>;
970
+ }
956
971
 
957
972
  /**
958
973
  * The options for this policy.
@@ -964,9 +979,9 @@ export declare interface McpAuth0OAuthInboundPolicyOptions {
964
979
  */
965
980
  auth0Domain: string;
966
981
  /**
967
- * Expected audience claim on tokens issued for the gateway. Surfaces both as the OIDC token audience and as the Auth0 authorize?audience= parameter.
982
+ * Optional Auth0 API audience. When set, the gateway sends it as the Auth0 authorize?audience= parameter and validates returned provider access tokens against it. Leave unset when Auth0 is only used for browser identity.
968
983
  */
969
- audience: string;
984
+ audience?: string;
970
985
  /**
971
986
  * The Auth0 client_id registered for the gateway's browser login flow.
972
987
  */
@@ -1042,21 +1057,22 @@ export declare class McpGatewayPlugin extends SystemRuntimePlugin {
1042
1057
  * to the OpenID Connect identity provider configured via the `oidc` and
1043
1058
  * `browserLogin` policy options.
1044
1059
  *
1045
- * The runtime resolves the policy options into a `McpOAuthRuntimeConfig` at
1046
- * gateway-initialization time and threads them into the underlying OAuth
1047
- * implementation. This policy's request-time job is to validate the bearer
1048
- * token presented by the MCP client and hydrate the principal onto the
1049
- * request context.
1060
+ * Validation runs lazily inside the policy constructor, which the runtime
1061
+ * caches per policy name so a misconfigured policy fails the first request
1062
+ * with a `ConfigurationError` (surfaced in the 500 problem body) rather than
1063
+ * crashing boot.
1050
1064
  *
1051
1065
  * @hidden
1052
1066
  * @title MCP OAuth
1053
- * @param request - The ZuploRequest
1054
- * @param context - The ZuploContext
1055
- * @param _options - The policy options set in policies.json
1056
- * @param _policyName - The name of the policy as set in policies.json
1057
- * @returns A Request or a Response
1058
1067
  */
1059
- export declare const McpOAuthInboundPolicy: InboundPolicyHandler<McpOAuthInboundPolicyOptions>;
1068
+ export declare class McpOAuthInboundPolicy extends InboundPolicy<McpOAuthInboundPolicyOptions> {
1069
+ #private;
1070
+ constructor(rawOptions: unknown, policyName: string);
1071
+ handler(
1072
+ request: ZuploRequest,
1073
+ context: ZuploContext
1074
+ ): Promise<ZuploRequest | Response>;
1075
+ }
1060
1076
 
1061
1077
  /**
1062
1078
  * The options for this policy.
@@ -1141,19 +1157,27 @@ export declare interface McpOAuthInboundPolicyOptions {
1141
1157
  }
1142
1158
 
1143
1159
  /**
1144
- * Bind a route to an upstream MCP server. Stores the resolved upstream binding
1145
- * on the request context for `McpVirtualServerHandler`, which resolves
1146
- * credentials during capability dispatch.
1160
+ * Bind a route to an upstream MCP server. Resolves the upstream connection
1161
+ * config plus per-request credential and appends a
1162
+ * `ResolvedUpstreamBindingContext` onto the request context for
1163
+ * `McpVirtualServerHandler` to pick up during capability dispatch.
1164
+ *
1165
+ * Validation runs lazily inside the policy constructor, which the runtime
1166
+ * caches per policy name — so a misconfigured policy fails the first request
1167
+ * with a `ConfigurationError` (surfaced in the 500 problem body) rather than
1168
+ * crashing boot.
1147
1169
  *
1148
1170
  * @hidden
1149
1171
  * @title MCP Upstream Connection
1150
- * @param request - The ZuploRequest
1151
- * @param context - The ZuploContext
1152
- * @param options - The policy options set in policies.json
1153
- * @param policyName - The name of the policy as set in policies.json
1154
- * @returns A Request or a Response
1155
1172
  */
1156
- export declare const McpUpstreamConnectionInboundPolicy: InboundPolicyHandler<McpUpstreamConnectionInboundPolicyOptions>;
1173
+ export declare class McpUpstreamConnectionInboundPolicy extends InboundPolicy<McpUpstreamConnectionInboundPolicyOptions> {
1174
+ #private;
1175
+ constructor(rawOptions: unknown, policyName: string);
1176
+ handler(
1177
+ request: ZuploRequest,
1178
+ context: ZuploContext
1179
+ ): Promise<ZuploRequest | Response>;
1180
+ }
1157
1181
 
1158
1182
  /**
1159
1183
  * The options for this policy.
@@ -1247,6 +1271,58 @@ export declare interface McpUpstreamConnectionInboundPolicyOptions {
1247
1271
  };
1248
1272
  }
1249
1273
 
1274
+ /**
1275
+ * Thin MCP upstream proxy. Pair this with `McpOAuthInboundPolicy` (or
1276
+ * `McpAuth0OAuthInboundPolicy`) plus `McpUpstreamConnectionInboundPolicy`:
1277
+ * the OAuth policy authenticates the request, the upstream-connection
1278
+ * policy resolves a single upstream binding onto the request context, and
1279
+ * this handler:
1280
+ *
1281
+ * 1. Reads the resolved binding off the context.
1282
+ * 2. Resolves the per-request upstream credential (handling user OAuth
1283
+ * via the connection's auth provider when configured).
1284
+ * 3. Builds a new `Request` targeting the upstream's MCP HTTP endpoint
1285
+ * with the customer's body and headers, plus the resolved credential
1286
+ * translated to `Authorization` / custom request headers.
1287
+ * 4. `fetch`-es the upstream and returns the response untouched.
1288
+ *
1289
+ * Use this for the common single-upstream pass-through case (the new
1290
+ * recommended shape). For multi-upstream aggregation or curated catalogs,
1291
+ * use `McpVirtualServerHandler` instead.
1292
+ *
1293
+ * Any customer-supplied policy attached between the upstream-connection
1294
+ * policy and this handler can observe or transform the rewritten
1295
+ * `Request` before it leaves the gateway.
1296
+ *
1297
+ * @beta
1298
+ *
1299
+ * @example
1300
+ * ```json
1301
+ * // routes.oas.json — single-upstream MCP proxy
1302
+ * {
1303
+ * "paths": {
1304
+ * "/mcp/linear": {
1305
+ * "post": {
1306
+ * "x-zuplo-route": {
1307
+ * "handler": {
1308
+ * "module": "$import(@zuplo/runtime)",
1309
+ * "export": "mcpUpstreamHandler"
1310
+ * },
1311
+ * "policies": {
1312
+ * "inbound": ["mcp-oauth", "mcp-upstream-linear"]
1313
+ * }
1314
+ * }
1315
+ * }
1316
+ * }
1317
+ * }
1318
+ * }
1319
+ * ```
1320
+ */
1321
+ export declare function mcpUpstreamHandler(
1322
+ request: ZuploRequest,
1323
+ context: ZuploContext
1324
+ ): Promise<Response>;
1325
+
1250
1326
  /**
1251
1327
  * Implements the server-side MCP request lifecycle for the gateway. Pair with
1252
1328
  * `McpOAuthInboundPolicy` (or `McpAuth0OAuthInboundPolicy`) plus an
@@ -1911,6 +1987,20 @@ declare interface ParsedCorsPolicyConfiguration {
1911
1987
  */
1912
1988
  declare interface ParsedRouteData extends Omit<RouteData, "corsPolicies"> {
1913
1989
  corsPolicies: ParsedCorsPolicyConfiguration[];
1990
+ /* Excluded from this release type: getInboundPolicyInstance */
1991
+ }
1992
+
1993
+ /**
1994
+ * The base class for inbound and outbound policies.
1995
+ * Provides common functionality for all policy types.
1996
+ *
1997
+ * @public
1998
+ */
1999
+ declare abstract class PolicyBase<TOptions = any> {
2000
+ options: TOptions;
2001
+ policyName: string;
2002
+ policyType: string;
2003
+ /* Excluded from this release type: __constructor */
1914
2004
  }
1915
2005
 
1916
2006
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zuplo/runtime",
3
3
  "type": "module",
4
- "version": "6.70.24",
4
+ "version": "6.70.26",
5
5
  "repository": "https://github.com/zuplo/zuplo",
6
6
  "author": "Zuplo, Inc.",
7
7
  "exports": {