@zuplo/runtime 6.59.7 → 6.59.9

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.
@@ -22,4 +22,4 @@
22
22
  * DEALINGS IN THE SOFTWARE.
23
23
  *--------------------------------------------------------------------------------------------*/
24
24
 
25
- import{b as e,c as t,e as a,f as o,g as r,h as i,i as n}from"../chunk-ABYPZMH4.js";import"../chunk-SSAQ7DDU.js";export{o as getIdForParameterSchema,i as getIdForRefSchema,r as getIdForRequestBodySchema,a as getRawOperationDataIdentifierName,e as isRestrictedEnvVariableName,t as isZuploReadableEnvVariableName,n as sanitizedIdentifierName};
25
+ import{b as e,c as t,e as a,f as o,g as r,h as i,i as n}from"../chunk-V5YKH6RW.js";import"../chunk-B77APQ6Y.js";export{o as getIdForParameterSchema,i as getIdForRefSchema,r as getIdForRequestBodySchema,a as getRawOperationDataIdentifierName,e as isRestrictedEnvVariableName,t as isZuploReadableEnvVariableName,n as sanitizedIdentifierName};
@@ -22,4 +22,4 @@
22
22
  * DEALINGS IN THE SOFTWARE.
23
23
  *--------------------------------------------------------------------------------------------*/
24
24
 
25
- import{a as p}from"../chunk-7X7Y6YCS.js";import{Z as n,a as t}from"../chunk-SSAQ7DDU.js";function g(u={request:new Request("https://api.example.com")}){let e=[];function o(i){e.push(Promise.resolve(i))}return t(o,"waitUntil"),{context:new s({event:{waitUntil:o},route:u.route}),invokeResponse:t(async()=>{await Promise.all(e)},"invokeResponse")}}t(g,"createMockContext");var a={path:"/",methods:["GET"],handler:{module:{},export:"default"},raw:t(()=>({}),"raw")},s=class extends EventTarget{static{t(this,"MockZuploContext")}#e;contextId;requestId;log;route;custom;incomingRequestProperties;parentContext;analyticsContext;constructor({event:e,route:o=a,parentContext:r}){super(),this.requestId=crypto.randomUUID(),this.contextId=crypto.randomUUID(),this.log={info:n.console.info,log:n.console.log,debug:n.console.debug,warn:n.console.warn,error:n.console.error},this.custom={},this.route=o,this.incomingRequestProperties={asn:1234,asOrganization:"ORGANIZATION",city:"Seattle",region:"Washington",regionCode:"WA",colo:"SEA",continent:"NA",country:"US",postalCode:"98004",metroCode:"SEA",latitude:void 0,longitude:void 0,timezone:void 0,httpProtocol:void 0},this.parentContext=r,this.#e=e,this.analyticsContext=new p(this.requestId)}waitUntil(e){this.#e.waitUntil(e)}invokeInboundPolicy(e,o){throw new Error("Not implemented")}invokeOutboundPolicy(e,o,r){throw new Error("Not implemented")}invokeRoute(e,o){throw new Error("Not implemented")}addResponseSendingHook(e){throw new Error("Not implemented")}addResponseSendingFinalHook(e){throw new Error("Not implemented")}addEventListener(e,o,r){let l=t(i=>{try{typeof o=="function"?o(i):o.handleEvent(i)}catch(d){throw this.log.error(`Error invoking event ${e}. See following logs for details.`),d}},"wrapped");super.addEventListener(e,l,r)}};export{s as MockZuploContext,g as createMockContext};
25
+ import{a as p}from"../chunk-QROYR45R.js";import{Z as n,a as t}from"../chunk-B77APQ6Y.js";function g(u={request:new Request("https://api.example.com")}){let e=[];function o(i){e.push(Promise.resolve(i))}return t(o,"waitUntil"),{context:new s({event:{waitUntil:o},route:u.route}),invokeResponse:t(async()=>{await Promise.all(e)},"invokeResponse")}}t(g,"createMockContext");var a={path:"/",methods:["GET"],handler:{module:{},export:"default"},raw:t(()=>({}),"raw")},s=class extends EventTarget{static{t(this,"MockZuploContext")}#e;contextId;requestId;log;route;custom;incomingRequestProperties;parentContext;analyticsContext;constructor({event:e,route:o=a,parentContext:r}){super(),this.requestId=crypto.randomUUID(),this.contextId=crypto.randomUUID(),this.log={info:n.console.info,log:n.console.log,debug:n.console.debug,warn:n.console.warn,error:n.console.error},this.custom={},this.route=o,this.incomingRequestProperties={asn:1234,asOrganization:"ORGANIZATION",city:"Seattle",region:"Washington",regionCode:"WA",colo:"SEA",continent:"NA",country:"US",postalCode:"98004",metroCode:"SEA",latitude:void 0,longitude:void 0,timezone:void 0,httpProtocol:void 0},this.parentContext=r,this.#e=e,this.analyticsContext=new p(this.requestId)}waitUntil(e){this.#e.waitUntil(e)}invokeInboundPolicy(e,o){throw new Error("Not implemented")}invokeOutboundPolicy(e,o,r){throw new Error("Not implemented")}invokeRoute(e,o){throw new Error("Not implemented")}addResponseSendingHook(e){throw new Error("Not implemented")}addResponseSendingFinalHook(e){throw new Error("Not implemented")}addEventListener(e,o,r){let l=t(i=>{try{typeof o=="function"?o(i):o.handleEvent(i)}catch(d){throw this.log.error(`Error invoking event ${e}. See following logs for details.`),d}},"wrapped");super.addEventListener(e,l,r)}};export{s as MockZuploContext,g as createMockContext};
@@ -4,6 +4,100 @@ import { RequestGeneric as RequestGeneric_2 } from "../../request.js";
4
4
  import type { ValidateFunction } from "ajv";
5
5
  import { z } from "zod/v4";
6
6
 
7
+ /**
8
+ * Authenticates an AI Gateway Application requests based on Application API Keys
9
+ * using Zuplo's Gateway service.
10
+ * This policy validates API keys against the Api keys bucket, fetches configuration data,
11
+ * caches results for performance, and automatically adds user information to
12
+ * authenticated requests.
13
+ * @hidden
14
+ * @title AI Gateway Authentication
15
+ * @public
16
+ *
17
+ * @param request - The incoming ZuploRequest
18
+ * @param context - The ZuploContext
19
+ * @param unparsedOptions - The policy configuration options
20
+ * @param policyName - The name of the policy instance
21
+ * @returns The authenticated request with user info, or a 401 response if unauthorized
22
+ *
23
+ * @example
24
+ * ```json
25
+ * // policies.json - Basic AI Gateway authentication
26
+ * {
27
+ * "name": "ai-gateway-auth",
28
+ * "policyType": "ai-gateway-auth-inbound",
29
+ * "handler": {
30
+ * "export": "AIGatewayAuthInboundPolicy",
31
+ * "module": "$import(@zuplo/runtime)",
32
+ * "options": {
33
+ * "cacheTtlSeconds": 300
34
+ * }
35
+ * }
36
+ * }
37
+ * ```
38
+ *
39
+ * @example
40
+ * ```json
41
+ * // Custom header and auth scheme
42
+ * {
43
+ * "handler": {
44
+ * "export": "AIGatewayAuthInboundPolicy",
45
+ * "module": "$import(@zuplo/runtime)",
46
+ * "options": {
47
+ * "authHeader": "x-api-key",
48
+ * "authScheme": ""
49
+ * }
50
+ * }
51
+ * }
52
+ * ```
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * // Access authenticated user data in handler
57
+ * export function myHandler(request: ZuploRequest, context: ZuploContext) {
58
+ * // User is automatically added by AI Gateway policy
59
+ * const user = request.user;
60
+ * context.log.info(`Request from API key: ${user.sub}`);
61
+ *
62
+ * // Access AI Gateway configuration and metadata
63
+ * const userData = user.data as {
64
+ * metadata: Record<string, unknown>;
65
+ * configuration: Record<string, unknown>;
66
+ * };
67
+ *
68
+ * return Response.json({
69
+ * message: `Hello ${user.sub}`,
70
+ * config: userData.configuration
71
+ * });
72
+ * }
73
+ * ```
74
+ */
75
+ export declare function AIGatewayAuthInboundPolicy(
76
+ request: ZuploRequest,
77
+ context: ZuploContext,
78
+ unparsedOptions: AIGatewayAuthInboundPolicyOptions,
79
+ policyName: string
80
+ ): Promise<Response | ZuploRequest<RequestGeneric_2>>;
81
+
82
+ /**
83
+ * The options for this policy.
84
+ * @public
85
+ */
86
+ export declare interface AIGatewayAuthInboundPolicyOptions {
87
+ /**
88
+ * The name of the header with the key.
89
+ */
90
+ authHeader?: string;
91
+ /**
92
+ * The scheme used on the header.
93
+ */
94
+ authScheme?: string;
95
+ /**
96
+ * The time to cache authentication results for a particular key. Higher values will decrease latency. Cached results will be valid until the cache expires even in the event the key is deleted, etc.
97
+ */
98
+ cacheTtlSeconds?: number;
99
+ }
100
+
7
101
  /**
8
102
  * Handler that routes AI/LLM requests through Zuplo's LLM Translation Layer.
9
103
  * This handler forwards requests to the translation layer that handles provider-specific
@@ -30,6 +124,57 @@ export declare function aiGatewayHandler(
30
124
  context: ZuploContext
31
125
  ): Promise<Response>;
32
126
 
127
+ /* Excluded from this release type: AIGatewayMeterIncrements */
128
+
129
+ /**
130
+ * AI Gateway Metering policy for quota enforcement
131
+ *
132
+ * @title AI Gateway Metering
133
+ * @hidden
134
+ * @param request - The ZuploRequest
135
+ * @param context - The ZuploContext
136
+ * @param options - The policy options set in policies.json
137
+ * @param policyName - The name of the policy as set in policies.json
138
+ * @returns A Request or a Response
139
+ */
140
+ export declare class AIGatewayMeteringInboundPolicy extends InboundPolicy<AIGatewayMeteringInboundPolicyOptions> {
141
+ /**
142
+ * Set the meter increments for the current request.
143
+ *
144
+ * @param context - The ZuploContext
145
+ * @param increments - The increments to set.
146
+ */
147
+ static setIncrements(
148
+ context: ZuploContext,
149
+ increments: AIGatewayMeterIncrements
150
+ ): void;
151
+ static getIncrements(context: ZuploContext): AIGatewayMeterIncrements;
152
+ constructor(
153
+ options: AIGatewayMeteringInboundPolicyOptions,
154
+ policyName: string
155
+ );
156
+ handler(
157
+ request: ZuploRequest,
158
+ context: ZuploContext
159
+ ): Promise<Response | ZuploRequest<RequestGeneric_2>>;
160
+ private fetchCurrentMeters;
161
+ private incrementMeters;
162
+ private checkQuotas;
163
+ private checkQuotaLimit;
164
+ private createQuotaExceededResponse;
165
+ }
166
+
167
+ /**
168
+ * The options for this policy.
169
+ * @public
170
+ */
171
+ export declare interface AIGatewayMeteringInboundPolicyOptions {
172
+ /**
173
+ * If true, the policy will throw an error in the event there is a problem connecting to the metering service.
174
+ */
175
+ throwOnFailure?: boolean;
176
+ }
177
+
33
178
  /**
34
179
  * Entry format for Akamai API Security logger
35
180
  * @public
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zuplo/runtime",
3
3
  "type": "module",
4
- "version": "6.59.7",
4
+ "version": "6.59.9",
5
5
  "repository": "https://github.com/zuplo/zuplo",
6
6
  "author": "Zuplo, Inc.",
7
7
  "exports": {