@zuplo/runtime 6.69.11 → 6.70.0
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/out/esm/chunk-5ZAQEULH.js +26 -0
- package/out/esm/chunk-5ZAQEULH.js.map +1 -0
- package/out/esm/index.js +76 -67
- package/out/esm/index.js.map +1 -1
- package/out/esm/mocks/index.js +1 -1
- package/out/types/index.d.ts +219 -0
- package/out/types/mcp-gateway/index.d.ts +2477 -0
- package/out/types/mocks/index.d.ts +38 -0
- package/package.json +6 -1
- package/out/esm/chunk-NEN7UYI6.js +0 -26
- package/out/esm/chunk-NEN7UYI6.js.map +0 -1
|
@@ -0,0 +1,2477 @@
|
|
|
1
|
+
declare interface ApiRuntimeConfig {
|
|
2
|
+
urls: UrlConfig | undefined;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Base logger interface with methods for each log level.
|
|
7
|
+
* @beta
|
|
8
|
+
*/
|
|
9
|
+
declare interface BaseLogger {
|
|
10
|
+
debug(...messages: unknown[]): void;
|
|
11
|
+
info(...messages: unknown[]): void;
|
|
12
|
+
log(...messages: unknown[]): void;
|
|
13
|
+
warn(...messages: unknown[]): void;
|
|
14
|
+
error(...messages: unknown[]): void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
declare interface BuildRouteConfiguration {
|
|
21
|
+
path: string;
|
|
22
|
+
methods: HttpMethod[];
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated This property is not used and will be removed in future versions
|
|
25
|
+
*/
|
|
26
|
+
label?: string;
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated This property is not used and will be removed in future versions
|
|
29
|
+
*/
|
|
30
|
+
key?: string;
|
|
31
|
+
handler: HandlerDefinition;
|
|
32
|
+
corsPolicy?: CorsPolicy;
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated This property is deprecated. Use route.raw() instead.
|
|
35
|
+
*/
|
|
36
|
+
custom?: any;
|
|
37
|
+
mcp?: {
|
|
38
|
+
enabled?: boolean;
|
|
39
|
+
};
|
|
40
|
+
policies?: {
|
|
41
|
+
inbound?: string[];
|
|
42
|
+
outbound?: string[];
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated This property is not used and will be removed in future versions
|
|
46
|
+
*/
|
|
47
|
+
excludeFromOpenApi?: boolean;
|
|
48
|
+
pathPattern?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Build-time metadata for this route.
|
|
51
|
+
*/
|
|
52
|
+
metadata?: {
|
|
53
|
+
/**
|
|
54
|
+
* The source file this route was generated from.
|
|
55
|
+
*/
|
|
56
|
+
filepath: string;
|
|
57
|
+
};
|
|
58
|
+
/* Excluded from this release type: raw */
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The 2-letter continent codes Cloudflare uses
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
declare type ContinentCode = "AF" | "AN" | "AS" | "EU" | "NA" | "OC" | "SA";
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
declare type CorsPolicy = string | "anything-goes" | "none";
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
declare interface CorsPolicyConfiguration {
|
|
76
|
+
name: string;
|
|
77
|
+
allowCredentials?: boolean;
|
|
78
|
+
maxAge?: number;
|
|
79
|
+
allowedOrigins: string[] | string;
|
|
80
|
+
allowedMethods?: HttpMethod[] | string;
|
|
81
|
+
allowedHeaders?: string[] | string;
|
|
82
|
+
exposeHeaders?: string[] | string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* Excluded from this release type: DevPortalRuntimeConfig */
|
|
86
|
+
|
|
87
|
+
declare type DevPortalType = "legacy" | "zudoku";
|
|
88
|
+
|
|
89
|
+
declare const EventType: {
|
|
90
|
+
readonly MCP_TOOL_USAGE: "mcp_tool_usage";
|
|
91
|
+
readonly AI_GATEWAY_COST_SUM: "ai_gateway_cost_sum";
|
|
92
|
+
readonly AI_GATEWAY_REQUEST_COUNT: "ai_gateway_request_count";
|
|
93
|
+
readonly AI_GATEWAY_TOKEN_SUM: "ai_gateway_token_sum";
|
|
94
|
+
readonly AI_GATEWAY_LATENCY_HISTOGRAM: "ai_gateway_latency_histogram";
|
|
95
|
+
readonly AI_GATEWAY_WARNING_COUNT: "ai_gateway_warning_count";
|
|
96
|
+
readonly AI_GATEWAY_BLOCKED_COUNT: "ai_gateway_blocked_count";
|
|
97
|
+
readonly MCP_GATEWAY_REQUEST_RECEIVED: "mcp_gateway_request_received";
|
|
98
|
+
readonly MCP_GATEWAY_REQUEST_COMPLETED: "mcp_gateway_request_completed";
|
|
99
|
+
readonly MCP_GATEWAY_REQUEST_REJECTED: "mcp_gateway_request_rejected";
|
|
100
|
+
readonly MCP_GATEWAY_INITIALIZE_NEGOTIATED: "mcp_gateway_initialize_negotiated";
|
|
101
|
+
readonly MCP_GATEWAY_CLIENT_UNSUPPORTED_BEHAVIOR: "mcp_gateway_client_unsupported_behavior";
|
|
102
|
+
readonly MCP_GATEWAY_CATALOG_LISTED: "mcp_gateway_catalog_listed";
|
|
103
|
+
readonly MCP_GATEWAY_CATALOG_IMPORTED: "mcp_gateway_catalog_imported";
|
|
104
|
+
readonly MCP_GATEWAY_CATALOG_DRIFT_DETECTED: "mcp_gateway_catalog_drift_detected";
|
|
105
|
+
readonly MCP_GATEWAY_CAPABILITY_LISTED: "mcp_gateway_capability_listed";
|
|
106
|
+
readonly MCP_GATEWAY_CAPABILITY_INVOKED: "mcp_gateway_capability_invoked";
|
|
107
|
+
readonly MCP_GATEWAY_CAPABILITY_COMPLETED: "mcp_gateway_capability_completed";
|
|
108
|
+
readonly MCP_GATEWAY_CAPABILITY_FAILED: "mcp_gateway_capability_failed";
|
|
109
|
+
readonly MCP_GATEWAY_CAPABILITY_CONNECT_REQUIRED: "mcp_gateway_capability_connect_required";
|
|
110
|
+
readonly MCP_GATEWAY_AUTH_DOWNSTREAM_TOKEN_VALIDATED: "mcp_gateway_auth_downstream_token_validated";
|
|
111
|
+
readonly MCP_GATEWAY_AUTH_DOWNSTREAM_TOKEN_REJECTED: "mcp_gateway_auth_downstream_token_rejected";
|
|
112
|
+
readonly MCP_GATEWAY_OAUTH_CLIENT_REGISTERED: "mcp_gateway_oauth_client_registered";
|
|
113
|
+
readonly MCP_GATEWAY_OAUTH_AUTHORIZE_STARTED: "mcp_gateway_oauth_authorize_started";
|
|
114
|
+
readonly MCP_GATEWAY_OAUTH_AUTHORIZE_AWAITING_SETUP: "mcp_gateway_oauth_authorize_awaiting_setup";
|
|
115
|
+
readonly MCP_GATEWAY_OAUTH_TOKEN_ISSUED: "mcp_gateway_oauth_token_issued";
|
|
116
|
+
readonly MCP_GATEWAY_OAUTH_TOKEN_REFRESH_ROTATED: "mcp_gateway_oauth_token_refresh_rotated";
|
|
117
|
+
readonly MCP_GATEWAY_OAUTH_TOKEN_REVOKED: "mcp_gateway_oauth_token_revoked";
|
|
118
|
+
readonly MCP_GATEWAY_AUTH_UPSTREAM_CONNECT_REQUIRED: "mcp_gateway_auth_upstream_connect_required";
|
|
119
|
+
readonly MCP_GATEWAY_AUTH_UPSTREAM_CONNECT_STARTED: "mcp_gateway_auth_upstream_connect_started";
|
|
120
|
+
readonly MCP_GATEWAY_AUTH_UPSTREAM_CALLBACK_RECEIVED: "mcp_gateway_auth_upstream_callback_received";
|
|
121
|
+
readonly MCP_GATEWAY_AUTH_UPSTREAM_TOKEN_EXCHANGE_SUCCEEDED: "mcp_gateway_auth_upstream_token_exchange_succeeded";
|
|
122
|
+
readonly MCP_GATEWAY_AUTH_UPSTREAM_TOKEN_EXCHANGE_FAILED: "mcp_gateway_auth_upstream_token_exchange_failed";
|
|
123
|
+
readonly MCP_GATEWAY_AUTH_UPSTREAM_CREDENTIAL_RESOLVED: "mcp_gateway_auth_upstream_credential_resolved";
|
|
124
|
+
readonly MCP_GATEWAY_AUTH_UPSTREAM_CREDENTIAL_MISSING: "mcp_gateway_auth_upstream_credential_missing";
|
|
125
|
+
readonly MCP_GATEWAY_AUTH_UPSTREAM_RECONSENT_REQUIRED: "mcp_gateway_auth_upstream_reconsent_required";
|
|
126
|
+
readonly MCP_GATEWAY_POLICY_DECISION: "mcp_gateway_policy_decision";
|
|
127
|
+
readonly MCP_GATEWAY_GUARDRAIL_DECISION: "mcp_gateway_guardrail_decision";
|
|
128
|
+
readonly MCP_GATEWAY_RATE_LIMIT_DECISION: "mcp_gateway_rate_limit_decision";
|
|
129
|
+
readonly MCP_GATEWAY_UPSTREAM_REQUEST_SENT: "mcp_gateway_upstream_request_sent";
|
|
130
|
+
readonly MCP_GATEWAY_UPSTREAM_REQUEST_COMPLETED: "mcp_gateway_upstream_request_completed";
|
|
131
|
+
readonly MCP_GATEWAY_UPSTREAM_REQUEST_FAILED: "mcp_gateway_upstream_request_failed";
|
|
132
|
+
readonly MCP_GATEWAY_AUDIT_VIRTUAL_SERVER_CREATED: "mcp_gateway_audit_virtual_server_created";
|
|
133
|
+
readonly MCP_GATEWAY_AUDIT_VIRTUAL_SERVER_UPDATED: "mcp_gateway_audit_virtual_server_updated";
|
|
134
|
+
readonly MCP_GATEWAY_AUDIT_VIRTUAL_SERVER_DELETED: "mcp_gateway_audit_virtual_server_deleted";
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
declare type EventType = (typeof EventType)[keyof typeof EventType];
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @public
|
|
141
|
+
*/
|
|
142
|
+
declare interface HandlerDefinition {
|
|
143
|
+
module: any;
|
|
144
|
+
export: string;
|
|
145
|
+
options?: unknown;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @public
|
|
150
|
+
*/
|
|
151
|
+
declare type HttpMethod =
|
|
152
|
+
| "GET"
|
|
153
|
+
| "HEAD"
|
|
154
|
+
| "POST"
|
|
155
|
+
| "PUT"
|
|
156
|
+
| "DELETE"
|
|
157
|
+
| "CONNECT"
|
|
158
|
+
| "OPTIONS"
|
|
159
|
+
| "TRACE"
|
|
160
|
+
| "PATCH";
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @beta
|
|
164
|
+
*/
|
|
165
|
+
declare enum HttpStatusCode {
|
|
166
|
+
/**
|
|
167
|
+
* The server has received the request headers and the client should proceed to send the request body
|
|
168
|
+
* (in the case of a request for which a body needs to be sent; for example, a POST request).
|
|
169
|
+
* Sending a large request body to a server after a request has been rejected for inappropriate headers would be inefficient.
|
|
170
|
+
* To have a server check the request's headers, a client must send Expect: 100-continue as a header in its initial request
|
|
171
|
+
* and receive a 100 Continue status code in response before sending the body. The response 417 Expectation Failed indicates the request should not be continued.
|
|
172
|
+
*/
|
|
173
|
+
CONTINUE = 100,
|
|
174
|
+
/**
|
|
175
|
+
* The requester has asked the server to switch protocols and the server has agreed to do so.
|
|
176
|
+
*/
|
|
177
|
+
SWITCHING_PROTOCOLS = 101,
|
|
178
|
+
/**
|
|
179
|
+
* A WebDAV request may contain many sub-requests involving file operations, requiring a long time to complete the request.
|
|
180
|
+
* This code indicates that the server has received and is processing the request, but no response is available yet.
|
|
181
|
+
* This prevents the client from timing out and assuming the request was lost.
|
|
182
|
+
* @deprecated This status code is deprecated and shouldn't be sent any more. Clients may still accept it, but simply ignore them.
|
|
183
|
+
*/
|
|
184
|
+
PROCESSING = 102,
|
|
185
|
+
/**
|
|
186
|
+
* This response may be sent by a server while it is still preparing a
|
|
187
|
+
* response, with hints about the resources that the server is expecting
|
|
188
|
+
* the final response will link. This allows a browser to start preloading
|
|
189
|
+
* resources even before the server has prepared and sent that final response.
|
|
190
|
+
*/
|
|
191
|
+
EARLY_HINTS = 103,
|
|
192
|
+
/**
|
|
193
|
+
* Standard response for successful HTTP requests.
|
|
194
|
+
* The actual response will depend on the request method used.
|
|
195
|
+
* In a GET request, the response will contain an entity corresponding to the requested resource.
|
|
196
|
+
* In a POST request, the response will contain an entity describing or containing the result of the action.
|
|
197
|
+
*/
|
|
198
|
+
OK = 200,
|
|
199
|
+
/**
|
|
200
|
+
* The request has been fulfilled, resulting in the creation of a new resource.
|
|
201
|
+
*/
|
|
202
|
+
CREATED = 201,
|
|
203
|
+
/**
|
|
204
|
+
* The request has been accepted for processing, but the processing has not been completed.
|
|
205
|
+
* The request might or might not be eventually acted upon, and may be disallowed when processing occurs.
|
|
206
|
+
*/
|
|
207
|
+
ACCEPTED = 202,
|
|
208
|
+
/**
|
|
209
|
+
* SINCE HTTP/1.1
|
|
210
|
+
* The server is a transforming proxy that received a 200 OK from its origin,
|
|
211
|
+
* but is returning a modified version of the origin's response.
|
|
212
|
+
*/
|
|
213
|
+
NON_AUTHORITATIVE_INFORMATION = 203,
|
|
214
|
+
/**
|
|
215
|
+
* The server successfully processed the request and is not returning any content.
|
|
216
|
+
*/
|
|
217
|
+
NO_CONTENT = 204,
|
|
218
|
+
/**
|
|
219
|
+
* The server successfully processed the request, but is not returning any content.
|
|
220
|
+
* Unlike a 204 response, this response requires that the requester reset the document view.
|
|
221
|
+
*/
|
|
222
|
+
RESET_CONTENT = 205,
|
|
223
|
+
/**
|
|
224
|
+
* The server is delivering only part of the resource (byte serving) due to a range header sent by the client.
|
|
225
|
+
* The range header is used by HTTP clients to enable resuming of interrupted downloads,
|
|
226
|
+
* or split a download into multiple simultaneous streams.
|
|
227
|
+
*/
|
|
228
|
+
PARTIAL_CONTENT = 206,
|
|
229
|
+
/**
|
|
230
|
+
* The message body that follows is an XML message and can contain a number of separate response codes,
|
|
231
|
+
* depending on how many sub-requests were made.
|
|
232
|
+
*/
|
|
233
|
+
MULTI_STATUS = 207,
|
|
234
|
+
/**
|
|
235
|
+
* The members of a DAV binding have already been enumerated in a preceding part of the (multistatus) response,
|
|
236
|
+
* and are not being included again.
|
|
237
|
+
*/
|
|
238
|
+
ALREADY_REPORTED = 208,
|
|
239
|
+
/**
|
|
240
|
+
* The server has fulfilled a request for the resource,
|
|
241
|
+
* and the response is a representation of the result of one or more instance-manipulations applied to the current instance.
|
|
242
|
+
*/
|
|
243
|
+
IM_USED = 226,
|
|
244
|
+
/**
|
|
245
|
+
* Indicates multiple options for the resource from which the client may choose (via agent-driven content negotiation).
|
|
246
|
+
* For example, this code could be used to present multiple video format options,
|
|
247
|
+
* to list files with different filename extensions, or to suggest word-sense disambiguation.
|
|
248
|
+
*/
|
|
249
|
+
MULTIPLE_CHOICES = 300,
|
|
250
|
+
/**
|
|
251
|
+
* This and all future requests should be directed to the given URI.
|
|
252
|
+
*/
|
|
253
|
+
MOVED_PERMANENTLY = 301,
|
|
254
|
+
/**
|
|
255
|
+
* This is an example of industry practice contradicting the standard.
|
|
256
|
+
* The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect
|
|
257
|
+
* (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302
|
|
258
|
+
* with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307
|
|
259
|
+
* to distinguish between the two behaviours. However, some Web applications and frameworks
|
|
260
|
+
* use the 302 status code as if it were the 303.
|
|
261
|
+
*/
|
|
262
|
+
FOUND = 302,
|
|
263
|
+
/**
|
|
264
|
+
* SINCE HTTP/1.1
|
|
265
|
+
* The response to the request can be found under another URI using a GET method.
|
|
266
|
+
* When received in response to a POST (or PUT/DELETE), the client should presume that
|
|
267
|
+
* the server has received the data and should issue a redirect with a separate GET message.
|
|
268
|
+
*/
|
|
269
|
+
SEE_OTHER = 303,
|
|
270
|
+
/**
|
|
271
|
+
* Indicates that the resource has not been modified since the version specified by the request headers If-Modified-Since or If-None-Match.
|
|
272
|
+
* In such case, there is no need to retransmit the resource since the client still has a previously-downloaded copy.
|
|
273
|
+
*/
|
|
274
|
+
NOT_MODIFIED = 304,
|
|
275
|
+
/**
|
|
276
|
+
* SINCE HTTP/1.1
|
|
277
|
+
* The requested resource is available only through a proxy, the address for which is provided in the response.
|
|
278
|
+
* Many HTTP clients (such as Mozilla and Internet Explorer) do not correctly handle responses with this status code, primarily for security reasons.
|
|
279
|
+
*/
|
|
280
|
+
USE_PROXY = 305,
|
|
281
|
+
/**
|
|
282
|
+
* No longer used. Originally meant "Subsequent requests should use the specified proxy."
|
|
283
|
+
* @deprecated No longer used
|
|
284
|
+
*/
|
|
285
|
+
SWITCH_PROXY = 306,
|
|
286
|
+
/**
|
|
287
|
+
* SINCE HTTP/1.1
|
|
288
|
+
* In this case, the request should be repeated with another URI; however, future requests should still use the original URI.
|
|
289
|
+
* In contrast to how 302 was historically implemented, the request method is not allowed to be changed when reissuing the original request.
|
|
290
|
+
* For example, a POST request should be repeated using another POST request.
|
|
291
|
+
*/
|
|
292
|
+
TEMPORARY_REDIRECT = 307,
|
|
293
|
+
/**
|
|
294
|
+
* The request and all future requests should be repeated using another URI.
|
|
295
|
+
* 307 and 308 parallel the behaviors of 302 and 301, but do not allow the HTTP method to change.
|
|
296
|
+
* So, for example, submitting a form to a permanently redirected resource may continue smoothly.
|
|
297
|
+
*/
|
|
298
|
+
PERMANENT_REDIRECT = 308,
|
|
299
|
+
/**
|
|
300
|
+
* The server cannot or will not process the request due to an apparent client error
|
|
301
|
+
* (e.g., malformed request syntax, too large size, invalid request message framing, or deceptive request routing).
|
|
302
|
+
*/
|
|
303
|
+
BAD_REQUEST = 400,
|
|
304
|
+
/**
|
|
305
|
+
* Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet
|
|
306
|
+
* been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the
|
|
307
|
+
* requested resource. See Basic access authentication and Digest access authentication. 401 semantically means
|
|
308
|
+
* "unauthenticated",i.e. the user does not have the necessary credentials.
|
|
309
|
+
*/
|
|
310
|
+
UNAUTHORIZED = 401,
|
|
311
|
+
/**
|
|
312
|
+
* Reserved for future use. The original intention was that this code might be used as part of some form of digital
|
|
313
|
+
* cash or micro payment scheme, but that has not happened, and this code is not usually used.
|
|
314
|
+
* Google Developers API uses this status if a particular developer has exceeded the daily limit on requests.
|
|
315
|
+
*/
|
|
316
|
+
PAYMENT_REQUIRED = 402,
|
|
317
|
+
/**
|
|
318
|
+
* The request was valid, but the server is refusing action.
|
|
319
|
+
* The user might not have the necessary permissions for a resource.
|
|
320
|
+
*/
|
|
321
|
+
FORBIDDEN = 403,
|
|
322
|
+
/**
|
|
323
|
+
* The requested resource could not be found but may be available in the future.
|
|
324
|
+
* Subsequent requests by the client are permissible.
|
|
325
|
+
*/
|
|
326
|
+
NOT_FOUND = 404,
|
|
327
|
+
/**
|
|
328
|
+
* A request method is not supported for the requested resource;
|
|
329
|
+
* for example, a GET request on a form that requires data to be presented via POST, or a PUT request on a read-only resource.
|
|
330
|
+
*/
|
|
331
|
+
METHOD_NOT_ALLOWED = 405,
|
|
332
|
+
/**
|
|
333
|
+
* The requested resource is capable of generating only content not acceptable according to the Accept headers sent in the request.
|
|
334
|
+
*/
|
|
335
|
+
NOT_ACCEPTABLE = 406,
|
|
336
|
+
/**
|
|
337
|
+
* The client must first authenticate itself with the proxy.
|
|
338
|
+
*/
|
|
339
|
+
PROXY_AUTHENTICATION_REQUIRED = 407,
|
|
340
|
+
/**
|
|
341
|
+
* The server timed out waiting for the request.
|
|
342
|
+
* According to HTTP specifications:
|
|
343
|
+
* "The client did not produce a request within the time that the server was prepared to wait. The client MAY repeat the request without modifications at any later time."
|
|
344
|
+
*/
|
|
345
|
+
REQUEST_TIMEOUT = 408,
|
|
346
|
+
/**
|
|
347
|
+
* Indicates that the request could not be processed because of conflict in the request,
|
|
348
|
+
* such as an edit conflict between multiple simultaneous updates.
|
|
349
|
+
*/
|
|
350
|
+
CONFLICT = 409,
|
|
351
|
+
/**
|
|
352
|
+
* Indicates that the resource requested is no longer available and will not be available again.
|
|
353
|
+
* This should be used when a resource has been intentionally removed and the resource should be purged.
|
|
354
|
+
* Upon receiving a 410 status code, the client should not request the resource in the future.
|
|
355
|
+
* Clients such as search engines should remove the resource from their indices.
|
|
356
|
+
* Most use cases do not require clients and search engines to purge the resource, and a "404 Not Found" may be used instead.
|
|
357
|
+
*/
|
|
358
|
+
GONE = 410,
|
|
359
|
+
/**
|
|
360
|
+
* The request did not specify the length of its content, which is required by the requested resource.
|
|
361
|
+
*/
|
|
362
|
+
LENGTH_REQUIRED = 411,
|
|
363
|
+
/**
|
|
364
|
+
* The server does not meet one of the preconditions that the requester put on the request.
|
|
365
|
+
*/
|
|
366
|
+
PRECONDITION_FAILED = 412,
|
|
367
|
+
/**
|
|
368
|
+
* The request is larger than the server is willing or able to process. Previously called "Request Entity Too Large".
|
|
369
|
+
*/
|
|
370
|
+
CONTENT_TOO_LARGE = 413,
|
|
371
|
+
/* Excluded from this release type: PAYLOAD_TOO_LARGE */
|
|
372
|
+
/**
|
|
373
|
+
* The URI provided was too long for the server to process. Often the result of too much data being encoded as a query-string of a GET request,
|
|
374
|
+
* in which case it should be converted to a POST request.
|
|
375
|
+
* Called "Request-URI Too Long" previously.
|
|
376
|
+
*/
|
|
377
|
+
URI_TOO_LONG = 414,
|
|
378
|
+
/**
|
|
379
|
+
* The request entity has a media type which the server or resource does not support.
|
|
380
|
+
* For example, the client uploads an image as image/svg+xml, but the server requires that images use a different format.
|
|
381
|
+
*/
|
|
382
|
+
UNSUPPORTED_MEDIA_TYPE = 415,
|
|
383
|
+
/**
|
|
384
|
+
* The client has asked for a portion of the file (byte serving), but the server cannot supply that portion.
|
|
385
|
+
* For example, if the client asked for a part of the file that lies beyond the end of the file.
|
|
386
|
+
* Called "Requested Range Not Satisfiable" previously.
|
|
387
|
+
*/
|
|
388
|
+
RANGE_NOT_SATISFIABLE = 416,
|
|
389
|
+
/**
|
|
390
|
+
* The server cannot meet the requirements of the Expect request-header field.
|
|
391
|
+
*/
|
|
392
|
+
EXPECTATION_FAILED = 417,
|
|
393
|
+
/**
|
|
394
|
+
* This code was defined in 1998 as one of the traditional IETF April Fools' jokes, in RFC 2324, Hyper Text Coffee Pot Control Protocol,
|
|
395
|
+
* and is not expected to be implemented by actual HTTP servers. The RFC specifies this code should be returned by
|
|
396
|
+
* teapots requested to brew coffee. This HTTP status is used as an Easter egg in some websites, including Google.com.
|
|
397
|
+
*/
|
|
398
|
+
I_AM_A_TEAPOT = 418,
|
|
399
|
+
/**
|
|
400
|
+
* The request was directed at a server that is not able to produce a response (for example because a connection reuse).
|
|
401
|
+
*/
|
|
402
|
+
MISDIRECTED_REQUEST = 421,
|
|
403
|
+
/* Excluded from this release type: UNPROCESSABLE_ENTITY */
|
|
404
|
+
/**
|
|
405
|
+
* The request was well-formed but was unable to be followed due to semantic errors.
|
|
406
|
+
*/
|
|
407
|
+
UNPROCESSABLE_CONTENT = 422,
|
|
408
|
+
/**
|
|
409
|
+
* The resource that is being accessed is locked.
|
|
410
|
+
*/
|
|
411
|
+
LOCKED = 423,
|
|
412
|
+
/**
|
|
413
|
+
* The request failed due to failure of a previous request (e.g., a PROPPATCH).
|
|
414
|
+
*/
|
|
415
|
+
FAILED_DEPENDENCY = 424,
|
|
416
|
+
/**
|
|
417
|
+
* The server is unwilling to risk processing a request that might be
|
|
418
|
+
* replayed, which creates the potential for a replay attack.
|
|
419
|
+
*/
|
|
420
|
+
TOO_EARLY = 425,
|
|
421
|
+
/**
|
|
422
|
+
* The client should switch to a different protocol such as TLS/1.0, given in the Upgrade header field.
|
|
423
|
+
*/
|
|
424
|
+
UPGRADE_REQUIRED = 426,
|
|
425
|
+
/**
|
|
426
|
+
* The origin server requires the request to be conditional.
|
|
427
|
+
* Intended to prevent "the 'lost update' problem, where a client
|
|
428
|
+
* GETs a resource's state, modifies it, and PUTs it back to the server,
|
|
429
|
+
* when meanwhile a third party has modified the state on the server, leading to a conflict."
|
|
430
|
+
*/
|
|
431
|
+
PRECONDITION_REQUIRED = 428,
|
|
432
|
+
/**
|
|
433
|
+
* The user has sent too many requests in a given amount of time. Intended for use with rate-limiting schemes.
|
|
434
|
+
*/
|
|
435
|
+
TOO_MANY_REQUESTS = 429,
|
|
436
|
+
/**
|
|
437
|
+
* The server is unwilling to process the request because either an individual header field,
|
|
438
|
+
* or all the header fields collectively, are too large.
|
|
439
|
+
*/
|
|
440
|
+
REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
|
|
441
|
+
/**
|
|
442
|
+
* A server operator has received a legal demand to deny access to a resource or to a set of resources
|
|
443
|
+
* that includes the requested resource. The code 451 was chosen as a reference to the novel Fahrenheit 451.
|
|
444
|
+
*/
|
|
445
|
+
UNAVAILABLE_FOR_LEGAL_REASONS = 451,
|
|
446
|
+
/**
|
|
447
|
+
* A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.
|
|
448
|
+
*/
|
|
449
|
+
INTERNAL_SERVER_ERROR = 500,
|
|
450
|
+
/**
|
|
451
|
+
* The server either does not recognize the request method, or it lacks the ability to fulfill the request.
|
|
452
|
+
* Usually this implies future availability (e.g., a new feature of a web-service API).
|
|
453
|
+
*/
|
|
454
|
+
NOT_IMPLEMENTED = 501,
|
|
455
|
+
/**
|
|
456
|
+
* The server was acting as a gateway or proxy and received an invalid response from the upstream server.
|
|
457
|
+
*/
|
|
458
|
+
BAD_GATEWAY = 502,
|
|
459
|
+
/**
|
|
460
|
+
* The server is currently unavailable (because it is overloaded or down for maintenance).
|
|
461
|
+
* Generally, this is a temporary state.
|
|
462
|
+
*/
|
|
463
|
+
SERVICE_UNAVAILABLE = 503,
|
|
464
|
+
/**
|
|
465
|
+
* The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.
|
|
466
|
+
*/
|
|
467
|
+
GATEWAY_TIMEOUT = 504,
|
|
468
|
+
/**
|
|
469
|
+
* The server does not support the HTTP protocol version used in the request
|
|
470
|
+
*/
|
|
471
|
+
HTTP_VERSION_NOT_SUPPORTED = 505,
|
|
472
|
+
/**
|
|
473
|
+
* Transparent content negotiation for the request results in a circular reference.
|
|
474
|
+
*/
|
|
475
|
+
VARIANT_ALSO_NEGOTIATES = 506,
|
|
476
|
+
/**
|
|
477
|
+
* The server is unable to store the representation needed to complete the request.
|
|
478
|
+
*/
|
|
479
|
+
INSUFFICIENT_STORAGE = 507,
|
|
480
|
+
/**
|
|
481
|
+
* The server detected an infinite loop while processing the request.
|
|
482
|
+
*/
|
|
483
|
+
LOOP_DETECTED = 508,
|
|
484
|
+
/**
|
|
485
|
+
* Further extensions to the request are required for the server to fulfill it.
|
|
486
|
+
*/
|
|
487
|
+
NOT_EXTENDED = 510,
|
|
488
|
+
/**
|
|
489
|
+
* The client needs to authenticate to gain network access.
|
|
490
|
+
* Intended for use by intercepting proxies used to control access to the network (e.g., "captive portals" used
|
|
491
|
+
* to require agreement to Terms of Service before granting full Internet access via a Wi-Fi hotspot).
|
|
492
|
+
*/
|
|
493
|
+
NETWORK_AUTHENTICATION_REQUIRED = 511,
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
declare type HttpStatusCodeRangeDefinition =
|
|
497
|
+
| "1XX"
|
|
498
|
+
| "2XX"
|
|
499
|
+
| "3XX"
|
|
500
|
+
| "4XX"
|
|
501
|
+
| "5XX";
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* A function-based inbound policy that can modify the incoming HTTP request.
|
|
505
|
+
* This is the simplest way to create custom policies without extending a class.
|
|
506
|
+
*
|
|
507
|
+
* @param request - The incoming Request
|
|
508
|
+
* @param context - The current context of the Request
|
|
509
|
+
* @param options - The configuration options for the policy
|
|
510
|
+
* @param policyName - The name set on the policy in the configuration
|
|
511
|
+
* @returns A Response to short-circuit or a Request to continue
|
|
512
|
+
*
|
|
513
|
+
* @public
|
|
514
|
+
* @example
|
|
515
|
+
* ```typescript
|
|
516
|
+
* import { InboundPolicyHandler } from "@zuplo/runtime";
|
|
517
|
+
*
|
|
518
|
+
* interface RateLimitOptions {
|
|
519
|
+
* requests: number;
|
|
520
|
+
* windowMs: number;
|
|
521
|
+
* }
|
|
522
|
+
*
|
|
523
|
+
* export const rateLimitPolicy: InboundPolicyHandler<RateLimitOptions> = async (
|
|
524
|
+
* request,
|
|
525
|
+
* context,
|
|
526
|
+
* options,
|
|
527
|
+
* policyName
|
|
528
|
+
* ) => {
|
|
529
|
+
* const key = request.headers.get("x-api-key") || "anonymous";
|
|
530
|
+
* const count = await incrementCounter(key, options.windowMs);
|
|
531
|
+
*
|
|
532
|
+
* if (count > options.requests) {
|
|
533
|
+
* return new Response("Too Many Requests", { status: 429 });
|
|
534
|
+
* }
|
|
535
|
+
*
|
|
536
|
+
* // Add rate limit headers
|
|
537
|
+
* request.headers.set("X-RateLimit-Limit", options.requests.toString());
|
|
538
|
+
* request.headers.set("X-RateLimit-Remaining", (options.requests - count).toString());
|
|
539
|
+
*
|
|
540
|
+
* return request;
|
|
541
|
+
* };
|
|
542
|
+
* ```
|
|
543
|
+
*/
|
|
544
|
+
declare interface InboundPolicyHandler<TOptions = any> {
|
|
545
|
+
(
|
|
546
|
+
request: ZuploRequest,
|
|
547
|
+
context: ZuploContext,
|
|
548
|
+
options: TOptions,
|
|
549
|
+
policyName: string
|
|
550
|
+
): Promise<ZuploRequest | Response>;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* @public
|
|
555
|
+
*/
|
|
556
|
+
declare interface IncomingRequestProperties {
|
|
557
|
+
/**
|
|
558
|
+
* ASN of the incoming request, for example, 395747.
|
|
559
|
+
*/
|
|
560
|
+
readonly asn: number | undefined;
|
|
561
|
+
/**
|
|
562
|
+
* The organization which owns the ASN of the incoming request,
|
|
563
|
+
* for example, Google Cloud.
|
|
564
|
+
*/
|
|
565
|
+
readonly asOrganization: string | undefined;
|
|
566
|
+
/**
|
|
567
|
+
* City of the incoming request, for example, "Austin".
|
|
568
|
+
*/
|
|
569
|
+
readonly city: string | undefined;
|
|
570
|
+
/**
|
|
571
|
+
* Continent of the incoming request, for example, "NA".
|
|
572
|
+
*/
|
|
573
|
+
readonly continent: ContinentCode | undefined;
|
|
574
|
+
/**
|
|
575
|
+
* The two-letter country code in the request.
|
|
576
|
+
* @see {@link https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2|ISO 3166-1 alpha-2}
|
|
577
|
+
*/
|
|
578
|
+
readonly country: Iso3166Alpha2Code | undefined;
|
|
579
|
+
/**
|
|
580
|
+
* Latitude of the incoming request, for example, "30.27130".
|
|
581
|
+
*/
|
|
582
|
+
readonly latitude: string | undefined;
|
|
583
|
+
/**
|
|
584
|
+
* Longitude of the incoming request, for example, "-97.74260".
|
|
585
|
+
*/
|
|
586
|
+
readonly longitude: string | undefined;
|
|
587
|
+
/**
|
|
588
|
+
* The three-letter IATA airport code of the data center that the request hit,
|
|
589
|
+
* for example, "DFW".
|
|
590
|
+
* @see {@link https://en.wikipedia.org/wiki/IATA_airport_code|IATA airport code}
|
|
591
|
+
*/
|
|
592
|
+
readonly colo: string | undefined;
|
|
593
|
+
/**
|
|
594
|
+
* Postal code of the incoming request, for example, "78701".
|
|
595
|
+
*/
|
|
596
|
+
readonly postalCode: string | undefined;
|
|
597
|
+
/**
|
|
598
|
+
* Metro code (DMA) of the incoming request, for example, "635".
|
|
599
|
+
*/
|
|
600
|
+
readonly metroCode: string | undefined;
|
|
601
|
+
/**
|
|
602
|
+
* If known, the ISO 3166-2 name for the first level region associated with
|
|
603
|
+
* the IP address of the incoming request, for example, "Texas".
|
|
604
|
+
* @see {@link https://en.wikipedia.org/wiki/ISO_3166-2|ISO 3166-2}
|
|
605
|
+
*/
|
|
606
|
+
readonly region: string | undefined;
|
|
607
|
+
/**
|
|
608
|
+
* If known, the ISO 3166-2 code for the first-level region associated with
|
|
609
|
+
* the IP address of the incoming request, for example, "TX".
|
|
610
|
+
* @see {@link https://en.wikipedia.org/wiki/ISO_3166-2|ISO 3166-2}
|
|
611
|
+
*/
|
|
612
|
+
readonly regionCode: string | undefined;
|
|
613
|
+
/**
|
|
614
|
+
* Timezone of the incoming request, for example, "America/Chicago".
|
|
615
|
+
*/
|
|
616
|
+
readonly timezone: string | undefined;
|
|
617
|
+
/**
|
|
618
|
+
* If available, the HTTP protocol of the incoming request, for example, "HTTP/1.1".
|
|
619
|
+
*/
|
|
620
|
+
readonly httpProtocol: string | undefined;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* ISO 3166-1 Alpha-2 codes
|
|
625
|
+
* @public
|
|
626
|
+
*/
|
|
627
|
+
declare type Iso3166Alpha2Code =
|
|
628
|
+
| "AD"
|
|
629
|
+
| "AE"
|
|
630
|
+
| "AF"
|
|
631
|
+
| "AG"
|
|
632
|
+
| "AI"
|
|
633
|
+
| "AL"
|
|
634
|
+
| "AM"
|
|
635
|
+
| "AO"
|
|
636
|
+
| "AQ"
|
|
637
|
+
| "AR"
|
|
638
|
+
| "AS"
|
|
639
|
+
| "AT"
|
|
640
|
+
| "AU"
|
|
641
|
+
| "AW"
|
|
642
|
+
| "AX"
|
|
643
|
+
| "AZ"
|
|
644
|
+
| "BA"
|
|
645
|
+
| "BB"
|
|
646
|
+
| "BD"
|
|
647
|
+
| "BE"
|
|
648
|
+
| "BF"
|
|
649
|
+
| "BG"
|
|
650
|
+
| "BH"
|
|
651
|
+
| "BI"
|
|
652
|
+
| "BJ"
|
|
653
|
+
| "BL"
|
|
654
|
+
| "BM"
|
|
655
|
+
| "BN"
|
|
656
|
+
| "BO"
|
|
657
|
+
| "BQ"
|
|
658
|
+
| "BR"
|
|
659
|
+
| "BS"
|
|
660
|
+
| "BT"
|
|
661
|
+
| "BV"
|
|
662
|
+
| "BW"
|
|
663
|
+
| "BY"
|
|
664
|
+
| "BZ"
|
|
665
|
+
| "CA"
|
|
666
|
+
| "CC"
|
|
667
|
+
| "CD"
|
|
668
|
+
| "CF"
|
|
669
|
+
| "CG"
|
|
670
|
+
| "CH"
|
|
671
|
+
| "CI"
|
|
672
|
+
| "CK"
|
|
673
|
+
| "CL"
|
|
674
|
+
| "CM"
|
|
675
|
+
| "CN"
|
|
676
|
+
| "CO"
|
|
677
|
+
| "CR"
|
|
678
|
+
| "CU"
|
|
679
|
+
| "CV"
|
|
680
|
+
| "CW"
|
|
681
|
+
| "CX"
|
|
682
|
+
| "CY"
|
|
683
|
+
| "CZ"
|
|
684
|
+
| "DE"
|
|
685
|
+
| "DJ"
|
|
686
|
+
| "DK"
|
|
687
|
+
| "DM"
|
|
688
|
+
| "DO"
|
|
689
|
+
| "DZ"
|
|
690
|
+
| "EC"
|
|
691
|
+
| "EE"
|
|
692
|
+
| "EG"
|
|
693
|
+
| "EH"
|
|
694
|
+
| "ER"
|
|
695
|
+
| "ES"
|
|
696
|
+
| "ET"
|
|
697
|
+
| "FI"
|
|
698
|
+
| "FJ"
|
|
699
|
+
| "FK"
|
|
700
|
+
| "FM"
|
|
701
|
+
| "FO"
|
|
702
|
+
| "FR"
|
|
703
|
+
| "GA"
|
|
704
|
+
| "GB"
|
|
705
|
+
| "GD"
|
|
706
|
+
| "GE"
|
|
707
|
+
| "GF"
|
|
708
|
+
| "GG"
|
|
709
|
+
| "GH"
|
|
710
|
+
| "GI"
|
|
711
|
+
| "GL"
|
|
712
|
+
| "GM"
|
|
713
|
+
| "GN"
|
|
714
|
+
| "GP"
|
|
715
|
+
| "GQ"
|
|
716
|
+
| "GR"
|
|
717
|
+
| "GS"
|
|
718
|
+
| "GT"
|
|
719
|
+
| "GU"
|
|
720
|
+
| "GW"
|
|
721
|
+
| "GY"
|
|
722
|
+
| "HK"
|
|
723
|
+
| "HM"
|
|
724
|
+
| "HN"
|
|
725
|
+
| "HR"
|
|
726
|
+
| "HT"
|
|
727
|
+
| "HU"
|
|
728
|
+
| "ID"
|
|
729
|
+
| "IE"
|
|
730
|
+
| "IL"
|
|
731
|
+
| "IM"
|
|
732
|
+
| "IN"
|
|
733
|
+
| "IO"
|
|
734
|
+
| "IQ"
|
|
735
|
+
| "IR"
|
|
736
|
+
| "IS"
|
|
737
|
+
| "IT"
|
|
738
|
+
| "JE"
|
|
739
|
+
| "JM"
|
|
740
|
+
| "JO"
|
|
741
|
+
| "JP"
|
|
742
|
+
| "KE"
|
|
743
|
+
| "KG"
|
|
744
|
+
| "KH"
|
|
745
|
+
| "KI"
|
|
746
|
+
| "KM"
|
|
747
|
+
| "KN"
|
|
748
|
+
| "KP"
|
|
749
|
+
| "KR"
|
|
750
|
+
| "KW"
|
|
751
|
+
| "KY"
|
|
752
|
+
| "KZ"
|
|
753
|
+
| "LA"
|
|
754
|
+
| "LB"
|
|
755
|
+
| "LC"
|
|
756
|
+
| "LI"
|
|
757
|
+
| "LK"
|
|
758
|
+
| "LR"
|
|
759
|
+
| "LS"
|
|
760
|
+
| "LT"
|
|
761
|
+
| "LU"
|
|
762
|
+
| "LV"
|
|
763
|
+
| "LY"
|
|
764
|
+
| "MA"
|
|
765
|
+
| "MC"
|
|
766
|
+
| "MD"
|
|
767
|
+
| "ME"
|
|
768
|
+
| "MF"
|
|
769
|
+
| "MG"
|
|
770
|
+
| "MH"
|
|
771
|
+
| "MK"
|
|
772
|
+
| "ML"
|
|
773
|
+
| "MM"
|
|
774
|
+
| "MN"
|
|
775
|
+
| "MO"
|
|
776
|
+
| "MP"
|
|
777
|
+
| "MQ"
|
|
778
|
+
| "MR"
|
|
779
|
+
| "MS"
|
|
780
|
+
| "MT"
|
|
781
|
+
| "MU"
|
|
782
|
+
| "MV"
|
|
783
|
+
| "MW"
|
|
784
|
+
| "MX"
|
|
785
|
+
| "MY"
|
|
786
|
+
| "MZ"
|
|
787
|
+
| "NA"
|
|
788
|
+
| "NC"
|
|
789
|
+
| "NE"
|
|
790
|
+
| "NF"
|
|
791
|
+
| "NG"
|
|
792
|
+
| "NI"
|
|
793
|
+
| "NL"
|
|
794
|
+
| "NO"
|
|
795
|
+
| "NP"
|
|
796
|
+
| "NR"
|
|
797
|
+
| "NU"
|
|
798
|
+
| "NZ"
|
|
799
|
+
| "OM"
|
|
800
|
+
| "PA"
|
|
801
|
+
| "PE"
|
|
802
|
+
| "PF"
|
|
803
|
+
| "PG"
|
|
804
|
+
| "PH"
|
|
805
|
+
| "PK"
|
|
806
|
+
| "PL"
|
|
807
|
+
| "PM"
|
|
808
|
+
| "PN"
|
|
809
|
+
| "PR"
|
|
810
|
+
| "PS"
|
|
811
|
+
| "PT"
|
|
812
|
+
| "PW"
|
|
813
|
+
| "PY"
|
|
814
|
+
| "QA"
|
|
815
|
+
| "RE"
|
|
816
|
+
| "RO"
|
|
817
|
+
| "RS"
|
|
818
|
+
| "RU"
|
|
819
|
+
| "RW"
|
|
820
|
+
| "SA"
|
|
821
|
+
| "SB"
|
|
822
|
+
| "SC"
|
|
823
|
+
| "SD"
|
|
824
|
+
| "SE"
|
|
825
|
+
| "SG"
|
|
826
|
+
| "SH"
|
|
827
|
+
| "SI"
|
|
828
|
+
| "SJ"
|
|
829
|
+
| "SK"
|
|
830
|
+
| "SL"
|
|
831
|
+
| "SM"
|
|
832
|
+
| "SN"
|
|
833
|
+
| "SO"
|
|
834
|
+
| "SR"
|
|
835
|
+
| "SS"
|
|
836
|
+
| "ST"
|
|
837
|
+
| "SV"
|
|
838
|
+
| "SX"
|
|
839
|
+
| "SY"
|
|
840
|
+
| "SZ"
|
|
841
|
+
| "TC"
|
|
842
|
+
| "TD"
|
|
843
|
+
| "TF"
|
|
844
|
+
| "TG"
|
|
845
|
+
| "TH"
|
|
846
|
+
| "TJ"
|
|
847
|
+
| "TK"
|
|
848
|
+
| "TL"
|
|
849
|
+
| "TM"
|
|
850
|
+
| "TN"
|
|
851
|
+
| "TO"
|
|
852
|
+
| "TR"
|
|
853
|
+
| "TT"
|
|
854
|
+
| "TV"
|
|
855
|
+
| "TW"
|
|
856
|
+
| "TZ"
|
|
857
|
+
| "UA"
|
|
858
|
+
| "UG"
|
|
859
|
+
| "UM"
|
|
860
|
+
| "US"
|
|
861
|
+
| "UY"
|
|
862
|
+
| "UZ"
|
|
863
|
+
| "VA"
|
|
864
|
+
| "VC"
|
|
865
|
+
| "VE"
|
|
866
|
+
| "VG"
|
|
867
|
+
| "VI"
|
|
868
|
+
| "VN"
|
|
869
|
+
| "VU"
|
|
870
|
+
| "WF"
|
|
871
|
+
| "WS"
|
|
872
|
+
| "YE"
|
|
873
|
+
| "YT"
|
|
874
|
+
| "ZA"
|
|
875
|
+
| "ZM"
|
|
876
|
+
| "ZW";
|
|
877
|
+
|
|
878
|
+
declare type JsonArray = JsonValue[] | readonly JsonValue[];
|
|
879
|
+
|
|
880
|
+
/**
|
|
881
|
+
Matches a JSON object.
|
|
882
|
+
This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { … }`.
|
|
883
|
+
*/
|
|
884
|
+
declare type JsonObject = {
|
|
885
|
+
[Key in string]: JsonValue;
|
|
886
|
+
} & {
|
|
887
|
+
[Key in string]?: JsonValue | undefined;
|
|
888
|
+
};
|
|
889
|
+
|
|
890
|
+
declare type JsonPrimitive = string | number | boolean | null;
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
Matches any valid JSON value.
|
|
894
|
+
@see `Jsonify` if you need to transform a type to one that is assignable to `JsonValue`.
|
|
895
|
+
*/
|
|
896
|
+
declare type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
897
|
+
|
|
898
|
+
/**
|
|
899
|
+
* Logger to be used in the runtime via context.log.
|
|
900
|
+
* You can set per-request properties that will be included in all log entries for this request.
|
|
901
|
+
* @beta
|
|
902
|
+
*/
|
|
903
|
+
declare interface Logger extends BaseLogger {
|
|
904
|
+
/**
|
|
905
|
+
* Set properties that will be included in all subsequent log entries for this request.
|
|
906
|
+
* Properties are merged with existing properties and any static fields configured in the logging plugin.
|
|
907
|
+
* Per-request properties take precedence over static fields with the same name.
|
|
908
|
+
*
|
|
909
|
+
* @param properties - Key-value pairs to include in log entries. Values must be string, number, or boolean.
|
|
910
|
+
*
|
|
911
|
+
* @example
|
|
912
|
+
* ```ts
|
|
913
|
+
* export default async function (request: ZuploRequest, context: ZuploContext) {
|
|
914
|
+
* // Set properties that will be included in all logs for this request
|
|
915
|
+
* context.log.setLogProperties({ http_status_code: 400, user_id: "123" });
|
|
916
|
+
*
|
|
917
|
+
* context.log.error("Request failed"); // Will include http_status_code and user_id
|
|
918
|
+
*
|
|
919
|
+
* return new Response("Error", { status: 400 });
|
|
920
|
+
* }
|
|
921
|
+
* ```
|
|
922
|
+
*/
|
|
923
|
+
setLogProperties?(
|
|
924
|
+
properties: Record<string, string | number | boolean>
|
|
925
|
+
): void;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
/* Excluded from this release type: LookupResult */
|
|
929
|
+
|
|
930
|
+
/**
|
|
931
|
+
* Authenticate MCP gateway requests using a gateway-issued OAuth access token,
|
|
932
|
+
* with browser login delegated to Auth0.
|
|
933
|
+
*
|
|
934
|
+
* Auth0-friendly wrapper around `McpOAuthInboundPolicy`. Provide
|
|
935
|
+
* `auth0Domain` and `clientId`; the wrapper derives the OIDC issuer, JWKS URL,
|
|
936
|
+
* and Auth0 authorize/token endpoints automatically. The resolved options are
|
|
937
|
+
* translated into the generic `McpOAuthRuntimeConfig` at gateway initialization
|
|
938
|
+
* time (see `setupRoutes`); this request-time entry point delegates straight
|
|
939
|
+
* to the underlying OAuth implementation.
|
|
940
|
+
*
|
|
941
|
+
* @beta
|
|
942
|
+
* @title MCP Auth0 OAuth Inbound
|
|
943
|
+
* @param request - The ZuploRequest
|
|
944
|
+
* @param context - The ZuploContext
|
|
945
|
+
* @param _options - The policy options set in policies.json
|
|
946
|
+
* @param _policyName - The name of the policy as set in policies.json
|
|
947
|
+
* @returns A Request or a Response
|
|
948
|
+
*/
|
|
949
|
+
export declare const McpAuth0OAuthInboundPolicy: InboundPolicyHandler<McpAuth0OAuthInboundPolicyOptions>;
|
|
950
|
+
|
|
951
|
+
/**
|
|
952
|
+
* The options for this policy.
|
|
953
|
+
* @public
|
|
954
|
+
*/
|
|
955
|
+
export declare interface McpAuth0OAuthInboundPolicyOptions {
|
|
956
|
+
/**
|
|
957
|
+
* Your Auth0 tenant domain. The OIDC issuer, JWKS URL, /authorize URL, and /oauth/token URL are derived from this.
|
|
958
|
+
*/
|
|
959
|
+
auth0Domain: string;
|
|
960
|
+
/**
|
|
961
|
+
* Expected audience claim on tokens issued for the gateway. Surfaces both as the OIDC token audience and as the Auth0 authorize?audience= parameter.
|
|
962
|
+
*/
|
|
963
|
+
audience: string;
|
|
964
|
+
/**
|
|
965
|
+
* The Auth0 client_id registered for the gateway's browser login flow.
|
|
966
|
+
*/
|
|
967
|
+
clientId: string;
|
|
968
|
+
/**
|
|
969
|
+
* The Auth0 client_secret. Use $env(...) to source from a secret environment variable.
|
|
970
|
+
*/
|
|
971
|
+
clientSecret?: string;
|
|
972
|
+
/**
|
|
973
|
+
* OIDC scopes requested during browser login.
|
|
974
|
+
*/
|
|
975
|
+
scope?: string;
|
|
976
|
+
/**
|
|
977
|
+
* Gateway-side OAuth token settings. The gateway issuer and advertised URLs are derived from the incoming request origin.
|
|
978
|
+
*/
|
|
979
|
+
gateway?: {
|
|
980
|
+
/**
|
|
981
|
+
* Lifetime of access tokens issued by /oauth/token.
|
|
982
|
+
*/
|
|
983
|
+
accessTokenTtlSeconds?: number;
|
|
984
|
+
/**
|
|
985
|
+
* Lifetime of refresh tokens issued by /oauth/token.
|
|
986
|
+
*/
|
|
987
|
+
refreshTokenTtlSeconds?: number;
|
|
988
|
+
/**
|
|
989
|
+
* Whether to advertise client_id_metadata_document_supported in AS metadata.
|
|
990
|
+
*/
|
|
991
|
+
cimdEnabled?: boolean;
|
|
992
|
+
};
|
|
993
|
+
/**
|
|
994
|
+
* Optional overrides for the derived browser-login settings.
|
|
995
|
+
*/
|
|
996
|
+
browserLoginOverrides?: {
|
|
997
|
+
remoteTimeoutMs?: number;
|
|
998
|
+
stateTtlSeconds?: number;
|
|
999
|
+
sessionTtlSeconds?: number;
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
/**
|
|
1004
|
+
* Activates the MCP Gateway internal routes (OAuth authorization server,
|
|
1005
|
+
* upstream connection management, well-known metadata) on the runtime router.
|
|
1006
|
+
* The plugin is a no-op when no MCP-related policy is present.
|
|
1007
|
+
*
|
|
1008
|
+
* Importing from `@zuplo/runtime/mcp-gateway` is the opt-in: the runtime core
|
|
1009
|
+
* does not statically reference any MCP gateway code, so unrelated projects
|
|
1010
|
+
* pay no bundle cost.
|
|
1011
|
+
*
|
|
1012
|
+
* @public
|
|
1013
|
+
* @example
|
|
1014
|
+
* ```ts
|
|
1015
|
+
* import { McpGatewayPlugin } from "@zuplo/runtime/mcp-gateway";
|
|
1016
|
+
*
|
|
1017
|
+
* export default async function (runtime: RuntimeExtensions) {
|
|
1018
|
+
* runtime.addPlugin(new McpGatewayPlugin());
|
|
1019
|
+
* }
|
|
1020
|
+
* ```
|
|
1021
|
+
*/
|
|
1022
|
+
export declare class McpGatewayPlugin extends SystemRuntimePlugin {
|
|
1023
|
+
registerRoutes(options: {
|
|
1024
|
+
router: Router;
|
|
1025
|
+
runtimeSettings: RuntimeSettings;
|
|
1026
|
+
parsedRouteData?: ParsedRouteData;
|
|
1027
|
+
}): void;
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
/**
|
|
1031
|
+
* Authenticate MCP gateway requests using a gateway-issued OAuth access token.
|
|
1032
|
+
*
|
|
1033
|
+
* The gateway hosts its own OAuth authorization server endpoints (DCR,
|
|
1034
|
+
* `/authorize`, `/token`, `/callback`) — registered automatically when this
|
|
1035
|
+
* policy is present in `policies.json`. End-user browser login is delegated
|
|
1036
|
+
* to the OpenID Connect identity provider configured via the `oidc` and
|
|
1037
|
+
* `browserLogin` policy options.
|
|
1038
|
+
*
|
|
1039
|
+
* The runtime resolves the policy options into a `McpOAuthRuntimeConfig` at
|
|
1040
|
+
* gateway-initialization time and threads them into the underlying OAuth
|
|
1041
|
+
* implementation. This policy's request-time job is to validate the bearer
|
|
1042
|
+
* token presented by the MCP client and hydrate the principal onto the
|
|
1043
|
+
* request context.
|
|
1044
|
+
*
|
|
1045
|
+
* @beta
|
|
1046
|
+
* @title MCP OAuth Inbound
|
|
1047
|
+
* @param request - The ZuploRequest
|
|
1048
|
+
* @param context - The ZuploContext
|
|
1049
|
+
* @param _options - The policy options set in policies.json
|
|
1050
|
+
* @param _policyName - The name of the policy as set in policies.json
|
|
1051
|
+
* @returns A Request or a Response
|
|
1052
|
+
*/
|
|
1053
|
+
export declare const McpOAuthInboundPolicy: InboundPolicyHandler<McpOAuthInboundPolicyOptions>;
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* The options for this policy.
|
|
1057
|
+
* @public
|
|
1058
|
+
*/
|
|
1059
|
+
export declare interface McpOAuthInboundPolicyOptions {
|
|
1060
|
+
/**
|
|
1061
|
+
* OpenID Connect identity provider that authenticates end-users before the gateway issues its own OAuth access token.
|
|
1062
|
+
*/
|
|
1063
|
+
oidc: {
|
|
1064
|
+
/**
|
|
1065
|
+
* The OIDC issuer URL of the identity provider.
|
|
1066
|
+
*/
|
|
1067
|
+
issuer: string;
|
|
1068
|
+
/**
|
|
1069
|
+
* The JWKS endpoint used to verify ID tokens issued by the identity provider.
|
|
1070
|
+
*/
|
|
1071
|
+
jwksUrl: string;
|
|
1072
|
+
/**
|
|
1073
|
+
* Expected audience claim on tokens issued for the gateway.
|
|
1074
|
+
*/
|
|
1075
|
+
audience: string;
|
|
1076
|
+
};
|
|
1077
|
+
/**
|
|
1078
|
+
* Browser-side OAuth/OIDC settings used when the gateway redirects the user to the identity provider for login.
|
|
1079
|
+
*/
|
|
1080
|
+
browserLogin: {
|
|
1081
|
+
/**
|
|
1082
|
+
* The IdP /authorize endpoint to redirect the user to. For local development on loopback, use http://127.0.0.1:9000/oauth/dev-login.
|
|
1083
|
+
*/
|
|
1084
|
+
url: string;
|
|
1085
|
+
/**
|
|
1086
|
+
* The IdP token endpoint used for the federated authorization code exchange. Required for federated_oidc browser login.
|
|
1087
|
+
*/
|
|
1088
|
+
tokenUrl?: string;
|
|
1089
|
+
/**
|
|
1090
|
+
* The OIDC client_id registered with the identity provider for the gateway's browser login flow.
|
|
1091
|
+
*/
|
|
1092
|
+
clientId?: string;
|
|
1093
|
+
/**
|
|
1094
|
+
* The OIDC client_secret. Use $env(...) to source from a secret environment variable.
|
|
1095
|
+
*/
|
|
1096
|
+
clientSecret?: string;
|
|
1097
|
+
/**
|
|
1098
|
+
* The OIDC scopes requested during browser login.
|
|
1099
|
+
*/
|
|
1100
|
+
scope?: string;
|
|
1101
|
+
/**
|
|
1102
|
+
* Optional audience parameter for the IdP authorization request (Auth0-style API audiences).
|
|
1103
|
+
*/
|
|
1104
|
+
audience?: string;
|
|
1105
|
+
/**
|
|
1106
|
+
* Timeout for outbound calls to the IdP (token exchange, JWKS fetch).
|
|
1107
|
+
*/
|
|
1108
|
+
remoteTimeoutMs?: number;
|
|
1109
|
+
/**
|
|
1110
|
+
* Lifetime of an in-flight browser-login state record.
|
|
1111
|
+
*/
|
|
1112
|
+
stateTtlSeconds?: number;
|
|
1113
|
+
/**
|
|
1114
|
+
* Lifetime of the gateway browser-login session cookie issued after a successful login.
|
|
1115
|
+
*/
|
|
1116
|
+
sessionTtlSeconds?: number;
|
|
1117
|
+
};
|
|
1118
|
+
/**
|
|
1119
|
+
* Gateway-side OAuth token settings. The gateway issuer and advertised URLs are derived from the incoming request origin.
|
|
1120
|
+
*/
|
|
1121
|
+
gateway?: {
|
|
1122
|
+
/**
|
|
1123
|
+
* Lifetime of access tokens issued by /oauth/token.
|
|
1124
|
+
*/
|
|
1125
|
+
accessTokenTtlSeconds?: number;
|
|
1126
|
+
/**
|
|
1127
|
+
* Lifetime of refresh tokens issued by /oauth/token.
|
|
1128
|
+
*/
|
|
1129
|
+
refreshTokenTtlSeconds?: number;
|
|
1130
|
+
/**
|
|
1131
|
+
* Whether to advertise client_id_metadata_document_supported in AS metadata.
|
|
1132
|
+
*/
|
|
1133
|
+
cimdEnabled?: boolean;
|
|
1134
|
+
};
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
/**
|
|
1138
|
+
* Bind a route to an upstream MCP server. Stores the resolved upstream binding
|
|
1139
|
+
* on the request context for {@link McpVirtualServerHandler}, which resolves
|
|
1140
|
+
* credentials during capability dispatch.
|
|
1141
|
+
*
|
|
1142
|
+
* @beta
|
|
1143
|
+
* @title MCP Upstream Connection Inbound
|
|
1144
|
+
* @param request - The ZuploRequest
|
|
1145
|
+
* @param context - The ZuploContext
|
|
1146
|
+
* @param options - The policy options set in policies.json
|
|
1147
|
+
* @param policyName - The name of the policy as set in policies.json
|
|
1148
|
+
* @returns A Request or a Response
|
|
1149
|
+
*/
|
|
1150
|
+
export declare const McpUpstreamConnectionInboundPolicy: InboundPolicyHandler<McpUpstreamConnectionInboundPolicyOptions>;
|
|
1151
|
+
|
|
1152
|
+
/**
|
|
1153
|
+
* The options for this policy.
|
|
1154
|
+
* @public
|
|
1155
|
+
*/
|
|
1156
|
+
export declare interface McpUpstreamConnectionInboundPolicyOptions {
|
|
1157
|
+
/**
|
|
1158
|
+
* Stable id for the upstream connection. Used to namespace per-user OAuth state and audit events. If omitted, the gateway tries to infer it from the policy name (`mcp-upstream-{id}`).
|
|
1159
|
+
*/
|
|
1160
|
+
id?: string;
|
|
1161
|
+
/**
|
|
1162
|
+
* Display name shown in connect-required responses, audit logs, and the setup UI.
|
|
1163
|
+
*/
|
|
1164
|
+
displayName: string;
|
|
1165
|
+
/**
|
|
1166
|
+
* Optional human-readable summary of the upstream, shown on the consent page.
|
|
1167
|
+
*/
|
|
1168
|
+
summary?: string;
|
|
1169
|
+
/**
|
|
1170
|
+
* The base URL of the upstream MCP server.
|
|
1171
|
+
*/
|
|
1172
|
+
mcpUrl: string;
|
|
1173
|
+
/**
|
|
1174
|
+
* Optional override for the upstream's OAuth protected-resource metadata URL.
|
|
1175
|
+
*/
|
|
1176
|
+
protectedResourceMetadataUrl?: string;
|
|
1177
|
+
/**
|
|
1178
|
+
* Additional request headers the gateway should inject when calling the upstream.
|
|
1179
|
+
*/
|
|
1180
|
+
requestHeaders?: {
|
|
1181
|
+
name: string;
|
|
1182
|
+
valueEnv: string;
|
|
1183
|
+
required?: boolean;
|
|
1184
|
+
}[];
|
|
1185
|
+
/**
|
|
1186
|
+
* Authentication mode. `user_oauth` performs per-user OAuth federation; `tenant_shared_oauth` uses a tenant-level OAuth grant; the `*_static_secret` variants use a configured secret instead of OAuth.
|
|
1187
|
+
*/
|
|
1188
|
+
authMode:
|
|
1189
|
+
| "user_oauth"
|
|
1190
|
+
| "tenant_shared_oauth"
|
|
1191
|
+
| "static_secret"
|
|
1192
|
+
| "user_static_secret"
|
|
1193
|
+
| "tenant_static_secret";
|
|
1194
|
+
/**
|
|
1195
|
+
* OAuth scopes to request from the upstream (for OAuth modes).
|
|
1196
|
+
*/
|
|
1197
|
+
scopes?: string[];
|
|
1198
|
+
/**
|
|
1199
|
+
* Delimiter used to join scopes in the OAuth authorization request. Defaults to a single space.
|
|
1200
|
+
*/
|
|
1201
|
+
scopeDelimiter?: string;
|
|
1202
|
+
/**
|
|
1203
|
+
* OAuth client id when registering manually (for OAuth modes).
|
|
1204
|
+
*/
|
|
1205
|
+
clientId?: string;
|
|
1206
|
+
/**
|
|
1207
|
+
* Environment variable holding the OAuth client secret (for OAuth modes with manual registration).
|
|
1208
|
+
*/
|
|
1209
|
+
clientSecretEnv?: string;
|
|
1210
|
+
/**
|
|
1211
|
+
* OAuth client secret reference, either an env var name or `$env(VAR_NAME)` (for OAuth modes with manual registration).
|
|
1212
|
+
*/
|
|
1213
|
+
clientSecret?: string;
|
|
1214
|
+
/**
|
|
1215
|
+
* Token endpoint authentication method (for OAuth modes with manual registration).
|
|
1216
|
+
*/
|
|
1217
|
+
tokenEndpointAuthMethod?:
|
|
1218
|
+
| "client_secret_basic"
|
|
1219
|
+
| "client_secret_post"
|
|
1220
|
+
| "none";
|
|
1221
|
+
/**
|
|
1222
|
+
* OAuth client registration mode. Defaults to `auto` (Dynamic Client Registration).
|
|
1223
|
+
*/
|
|
1224
|
+
clientRegistration?:
|
|
1225
|
+
| {
|
|
1226
|
+
mode: "auto";
|
|
1227
|
+
}
|
|
1228
|
+
| {
|
|
1229
|
+
mode: "manual";
|
|
1230
|
+
clientId: string;
|
|
1231
|
+
clientSecretEnv?: string;
|
|
1232
|
+
tokenEndpointAuthMethod?:
|
|
1233
|
+
| "client_secret_basic"
|
|
1234
|
+
| "client_secret_post"
|
|
1235
|
+
| "none";
|
|
1236
|
+
};
|
|
1237
|
+
/**
|
|
1238
|
+
* Static secret configuration (for `*_static_secret` auth modes).
|
|
1239
|
+
*/
|
|
1240
|
+
secret?: {
|
|
1241
|
+
[k: string]: unknown;
|
|
1242
|
+
};
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
/**
|
|
1246
|
+
* Implements the server-side MCP request lifecycle for the gateway. Pair with
|
|
1247
|
+
* `McpOAuthInboundPolicy` (or `McpAuth0OAuthInboundPolicy`) plus an
|
|
1248
|
+
* `McpUpstreamConnectionInboundPolicy` instance: the OAuth inbound policy
|
|
1249
|
+
* authenticates the request, the upstream-connection policy resolves which
|
|
1250
|
+
* upstream MCP server is bound to the route, and this handler accepts the
|
|
1251
|
+
* incoming JSON-RPC POST, dispatches `initialize`, `tools/list`, `tools/call`,
|
|
1252
|
+
* `prompts/list`, `prompts/get`, `resources/list`, and `resources/read` to the
|
|
1253
|
+
* upstream MCP server through the streamable HTTP transport, and returns the
|
|
1254
|
+
* JSON-RPC response.
|
|
1255
|
+
*
|
|
1256
|
+
* GET requests (for the standalone SSE channel of the streamable HTTP
|
|
1257
|
+
* transport) are intentionally rejected with JSON-RPC error code `-32000` and
|
|
1258
|
+
* `Allow: POST` because this handler runs in stateless mode.
|
|
1259
|
+
*
|
|
1260
|
+
* @beta
|
|
1261
|
+
* @param request - The ZuploRequest. The body must contain a JSON-RPC request.
|
|
1262
|
+
* @param context - The ZuploContext.
|
|
1263
|
+
* @returns The JSON-RPC response from the upstream MCP server.
|
|
1264
|
+
*
|
|
1265
|
+
* @example
|
|
1266
|
+
* ```json
|
|
1267
|
+
* // routes.oas.json - Pair with the MCP OAuth + upstream-connection policies.
|
|
1268
|
+
* {
|
|
1269
|
+
* "paths": {
|
|
1270
|
+
* "/mcp/linear": {
|
|
1271
|
+
* "post": {
|
|
1272
|
+
* "x-zuplo-route": {
|
|
1273
|
+
* "handler": {
|
|
1274
|
+
* "module": "$import(@zuplo/runtime)",
|
|
1275
|
+
* "export": "McpVirtualServerHandler"
|
|
1276
|
+
* },
|
|
1277
|
+
* "policies": {
|
|
1278
|
+
* "inbound": ["auth0-managed-oauth", "mcp-upstream-linear"]
|
|
1279
|
+
* }
|
|
1280
|
+
* }
|
|
1281
|
+
* }
|
|
1282
|
+
* }
|
|
1283
|
+
* }
|
|
1284
|
+
* }
|
|
1285
|
+
* ```
|
|
1286
|
+
*/
|
|
1287
|
+
export declare function McpVirtualServerHandler(
|
|
1288
|
+
request: ZuploRequest,
|
|
1289
|
+
context: ZuploContext
|
|
1290
|
+
): Promise<Response>;
|
|
1291
|
+
|
|
1292
|
+
declare type Modify<T, R> = Omit<T, keyof R> & R;
|
|
1293
|
+
|
|
1294
|
+
declare interface NotFoundOptions {
|
|
1295
|
+
routesMatchedByPathOnly: RouteConfiguration[];
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
/**
|
|
1299
|
+
* @public
|
|
1300
|
+
*/
|
|
1301
|
+
declare interface OnRequestHook {
|
|
1302
|
+
(
|
|
1303
|
+
request: ZuploRequest,
|
|
1304
|
+
context: ZuploContext
|
|
1305
|
+
): Promise<ZuploRequest | Response> | (ZuploRequest | Response);
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
/**
|
|
1309
|
+
* @public
|
|
1310
|
+
*/
|
|
1311
|
+
declare interface OnResponseSendingFinalHook {
|
|
1312
|
+
(
|
|
1313
|
+
response: Response,
|
|
1314
|
+
request: ZuploRequest,
|
|
1315
|
+
context: ZuploContext
|
|
1316
|
+
): Promise<void> | void;
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
/**
|
|
1320
|
+
* @public
|
|
1321
|
+
*/
|
|
1322
|
+
declare interface OnResponseSendingHook {
|
|
1323
|
+
(
|
|
1324
|
+
response: Response,
|
|
1325
|
+
request: ZuploRequest,
|
|
1326
|
+
context: ZuploContext
|
|
1327
|
+
): Promise<Response> | Response;
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
declare namespace OpenAPIV3 {
|
|
1331
|
+
interface Document<T extends {} = {}> {
|
|
1332
|
+
openapi: string;
|
|
1333
|
+
info: InfoObject;
|
|
1334
|
+
servers?: ServerObject[];
|
|
1335
|
+
paths: PathsObject<T>;
|
|
1336
|
+
components?: ComponentsObject;
|
|
1337
|
+
security?: SecurityRequirementObject[];
|
|
1338
|
+
tags?: TagObject[];
|
|
1339
|
+
externalDocs?: ExternalDocumentationObject;
|
|
1340
|
+
"x-express-openapi-additional-middleware"?: (
|
|
1341
|
+
| ((request: any, response: any, next: any) => Promise<void>)
|
|
1342
|
+
| ((request: any, response: any, next: any) => void)
|
|
1343
|
+
)[];
|
|
1344
|
+
"x-express-openapi-validation-strict"?: boolean;
|
|
1345
|
+
}
|
|
1346
|
+
interface InfoObject {
|
|
1347
|
+
title: string;
|
|
1348
|
+
description?: string;
|
|
1349
|
+
termsOfService?: string;
|
|
1350
|
+
contact?: ContactObject;
|
|
1351
|
+
license?: LicenseObject;
|
|
1352
|
+
version: string;
|
|
1353
|
+
}
|
|
1354
|
+
interface ContactObject {
|
|
1355
|
+
name?: string;
|
|
1356
|
+
url?: string;
|
|
1357
|
+
email?: string;
|
|
1358
|
+
}
|
|
1359
|
+
interface LicenseObject {
|
|
1360
|
+
name: string;
|
|
1361
|
+
url?: string;
|
|
1362
|
+
}
|
|
1363
|
+
interface ServerObject {
|
|
1364
|
+
url: string;
|
|
1365
|
+
description?: string;
|
|
1366
|
+
variables?: {
|
|
1367
|
+
[variable: string]: ServerVariableObject;
|
|
1368
|
+
};
|
|
1369
|
+
}
|
|
1370
|
+
interface ServerVariableObject {
|
|
1371
|
+
enum?: string[];
|
|
1372
|
+
default: string;
|
|
1373
|
+
description?: string;
|
|
1374
|
+
}
|
|
1375
|
+
interface PathsObject<T extends {} = {}, P extends {} = {}> {
|
|
1376
|
+
[pattern: string]: (PathItemObject<T> & P) | undefined;
|
|
1377
|
+
}
|
|
1378
|
+
enum HttpMethods {
|
|
1379
|
+
GET = "get",
|
|
1380
|
+
PUT = "put",
|
|
1381
|
+
POST = "post",
|
|
1382
|
+
DELETE = "delete",
|
|
1383
|
+
OPTIONS = "options",
|
|
1384
|
+
HEAD = "head",
|
|
1385
|
+
PATCH = "patch",
|
|
1386
|
+
TRACE = "trace",
|
|
1387
|
+
}
|
|
1388
|
+
type PathItemObject<T extends {} = {}> = {
|
|
1389
|
+
$ref?: string;
|
|
1390
|
+
summary?: string;
|
|
1391
|
+
description?: string;
|
|
1392
|
+
servers?: ServerObject[];
|
|
1393
|
+
parameters?: (ReferenceObject | ParameterObject)[];
|
|
1394
|
+
} & {
|
|
1395
|
+
[method in HttpMethods]?: OperationObject<T>;
|
|
1396
|
+
};
|
|
1397
|
+
type OperationObject<T extends {} = {}> = {
|
|
1398
|
+
tags?: string[];
|
|
1399
|
+
summary?: string;
|
|
1400
|
+
description?: string;
|
|
1401
|
+
externalDocs?: ExternalDocumentationObject;
|
|
1402
|
+
operationId?: string;
|
|
1403
|
+
parameters?: (ReferenceObject | ParameterObject)[];
|
|
1404
|
+
requestBody?: ReferenceObject | RequestBodyObject;
|
|
1405
|
+
responses: ResponsesObject;
|
|
1406
|
+
callbacks?: {
|
|
1407
|
+
[callback: string]: ReferenceObject | CallbackObject;
|
|
1408
|
+
};
|
|
1409
|
+
deprecated?: boolean;
|
|
1410
|
+
security?: SecurityRequirementObject[];
|
|
1411
|
+
servers?: ServerObject[];
|
|
1412
|
+
} & T;
|
|
1413
|
+
interface ExternalDocumentationObject {
|
|
1414
|
+
description?: string;
|
|
1415
|
+
url: string;
|
|
1416
|
+
}
|
|
1417
|
+
interface ParameterObject extends ParameterBaseObject {
|
|
1418
|
+
name: string;
|
|
1419
|
+
in: string;
|
|
1420
|
+
}
|
|
1421
|
+
interface HeaderObject extends ParameterBaseObject {}
|
|
1422
|
+
interface ParameterBaseObject {
|
|
1423
|
+
description?: string;
|
|
1424
|
+
required?: boolean;
|
|
1425
|
+
deprecated?: boolean;
|
|
1426
|
+
allowEmptyValue?: boolean;
|
|
1427
|
+
style?: string;
|
|
1428
|
+
explode?: boolean;
|
|
1429
|
+
allowReserved?: boolean;
|
|
1430
|
+
schema?: ReferenceObject | SchemaObject;
|
|
1431
|
+
example?: any;
|
|
1432
|
+
examples?: {
|
|
1433
|
+
[media: string]: ReferenceObject | ExampleObject;
|
|
1434
|
+
};
|
|
1435
|
+
content?: {
|
|
1436
|
+
[media: string]: MediaTypeObject;
|
|
1437
|
+
};
|
|
1438
|
+
}
|
|
1439
|
+
type NonArraySchemaObjectType =
|
|
1440
|
+
| "boolean"
|
|
1441
|
+
| "object"
|
|
1442
|
+
| "number"
|
|
1443
|
+
| "string"
|
|
1444
|
+
| "integer";
|
|
1445
|
+
type ArraySchemaObjectType = "array";
|
|
1446
|
+
type SchemaObject = ArraySchemaObject | NonArraySchemaObject;
|
|
1447
|
+
interface ArraySchemaObject extends BaseSchemaObject {
|
|
1448
|
+
type: ArraySchemaObjectType;
|
|
1449
|
+
items: ReferenceObject | SchemaObject;
|
|
1450
|
+
}
|
|
1451
|
+
interface NonArraySchemaObject extends BaseSchemaObject {
|
|
1452
|
+
type?: NonArraySchemaObjectType;
|
|
1453
|
+
}
|
|
1454
|
+
interface BaseSchemaObject {
|
|
1455
|
+
title?: string;
|
|
1456
|
+
description?: string;
|
|
1457
|
+
format?: string;
|
|
1458
|
+
default?: any;
|
|
1459
|
+
multipleOf?: number;
|
|
1460
|
+
maximum?: number;
|
|
1461
|
+
exclusiveMaximum?: boolean;
|
|
1462
|
+
minimum?: number;
|
|
1463
|
+
exclusiveMinimum?: boolean;
|
|
1464
|
+
maxLength?: number;
|
|
1465
|
+
minLength?: number;
|
|
1466
|
+
pattern?: string;
|
|
1467
|
+
additionalProperties?: boolean | ReferenceObject | SchemaObject;
|
|
1468
|
+
maxItems?: number;
|
|
1469
|
+
minItems?: number;
|
|
1470
|
+
uniqueItems?: boolean;
|
|
1471
|
+
maxProperties?: number;
|
|
1472
|
+
minProperties?: number;
|
|
1473
|
+
required?: string[];
|
|
1474
|
+
enum?: any[];
|
|
1475
|
+
properties?: {
|
|
1476
|
+
[name: string]: ReferenceObject | SchemaObject;
|
|
1477
|
+
};
|
|
1478
|
+
allOf?: (ReferenceObject | SchemaObject)[];
|
|
1479
|
+
oneOf?: (ReferenceObject | SchemaObject)[];
|
|
1480
|
+
anyOf?: (ReferenceObject | SchemaObject)[];
|
|
1481
|
+
not?: ReferenceObject | SchemaObject;
|
|
1482
|
+
nullable?: boolean;
|
|
1483
|
+
discriminator?: DiscriminatorObject;
|
|
1484
|
+
readOnly?: boolean;
|
|
1485
|
+
writeOnly?: boolean;
|
|
1486
|
+
xml?: XMLObject;
|
|
1487
|
+
externalDocs?: ExternalDocumentationObject;
|
|
1488
|
+
example?: any;
|
|
1489
|
+
deprecated?: boolean;
|
|
1490
|
+
}
|
|
1491
|
+
interface DiscriminatorObject {
|
|
1492
|
+
propertyName: string;
|
|
1493
|
+
mapping?: {
|
|
1494
|
+
[value: string]: string;
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
interface XMLObject {
|
|
1498
|
+
name?: string;
|
|
1499
|
+
namespace?: string;
|
|
1500
|
+
prefix?: string;
|
|
1501
|
+
attribute?: boolean;
|
|
1502
|
+
wrapped?: boolean;
|
|
1503
|
+
}
|
|
1504
|
+
interface ReferenceObject {
|
|
1505
|
+
$ref: string;
|
|
1506
|
+
}
|
|
1507
|
+
interface ExampleObject {
|
|
1508
|
+
summary?: string;
|
|
1509
|
+
description?: string;
|
|
1510
|
+
value?: any;
|
|
1511
|
+
externalValue?: string;
|
|
1512
|
+
}
|
|
1513
|
+
interface MediaTypeObject {
|
|
1514
|
+
schema?: ReferenceObject | SchemaObject;
|
|
1515
|
+
example?: any;
|
|
1516
|
+
examples?: {
|
|
1517
|
+
[media: string]: ReferenceObject | ExampleObject;
|
|
1518
|
+
};
|
|
1519
|
+
encoding?: {
|
|
1520
|
+
[media: string]: EncodingObject;
|
|
1521
|
+
};
|
|
1522
|
+
}
|
|
1523
|
+
interface EncodingObject {
|
|
1524
|
+
contentType?: string;
|
|
1525
|
+
headers?: {
|
|
1526
|
+
[header: string]: ReferenceObject | HeaderObject;
|
|
1527
|
+
};
|
|
1528
|
+
style?: string;
|
|
1529
|
+
explode?: boolean;
|
|
1530
|
+
allowReserved?: boolean;
|
|
1531
|
+
}
|
|
1532
|
+
interface RequestBodyObject {
|
|
1533
|
+
description?: string;
|
|
1534
|
+
content: {
|
|
1535
|
+
[media: string]: MediaTypeObject;
|
|
1536
|
+
};
|
|
1537
|
+
required?: boolean;
|
|
1538
|
+
}
|
|
1539
|
+
interface ResponsesObject {
|
|
1540
|
+
[code: string]: ReferenceObject | ResponseObject;
|
|
1541
|
+
}
|
|
1542
|
+
interface ResponseObject {
|
|
1543
|
+
description: string;
|
|
1544
|
+
headers?: {
|
|
1545
|
+
[header: string]: ReferenceObject | HeaderObject;
|
|
1546
|
+
};
|
|
1547
|
+
content?: {
|
|
1548
|
+
[media: string]: MediaTypeObject;
|
|
1549
|
+
};
|
|
1550
|
+
links?: {
|
|
1551
|
+
[link: string]: ReferenceObject | LinkObject;
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
interface LinkObject {
|
|
1555
|
+
operationRef?: string;
|
|
1556
|
+
operationId?: string;
|
|
1557
|
+
parameters?: {
|
|
1558
|
+
[parameter: string]: any;
|
|
1559
|
+
};
|
|
1560
|
+
requestBody?: any;
|
|
1561
|
+
description?: string;
|
|
1562
|
+
server?: ServerObject;
|
|
1563
|
+
}
|
|
1564
|
+
interface CallbackObject {
|
|
1565
|
+
[url: string]: PathItemObject;
|
|
1566
|
+
}
|
|
1567
|
+
interface SecurityRequirementObject {
|
|
1568
|
+
[name: string]: string[];
|
|
1569
|
+
}
|
|
1570
|
+
interface ComponentsObject {
|
|
1571
|
+
schemas?: {
|
|
1572
|
+
[key: string]: ReferenceObject | SchemaObject;
|
|
1573
|
+
};
|
|
1574
|
+
responses?: {
|
|
1575
|
+
[key: string]: ReferenceObject | ResponseObject;
|
|
1576
|
+
};
|
|
1577
|
+
parameters?: {
|
|
1578
|
+
[key: string]: ReferenceObject | ParameterObject;
|
|
1579
|
+
};
|
|
1580
|
+
examples?: {
|
|
1581
|
+
[key: string]: ReferenceObject | ExampleObject;
|
|
1582
|
+
};
|
|
1583
|
+
requestBodies?: {
|
|
1584
|
+
[key: string]: ReferenceObject | RequestBodyObject;
|
|
1585
|
+
};
|
|
1586
|
+
headers?: {
|
|
1587
|
+
[key: string]: ReferenceObject | HeaderObject;
|
|
1588
|
+
};
|
|
1589
|
+
securitySchemes?: {
|
|
1590
|
+
[key: string]: ReferenceObject | SecuritySchemeObject;
|
|
1591
|
+
};
|
|
1592
|
+
links?: {
|
|
1593
|
+
[key: string]: ReferenceObject | LinkObject;
|
|
1594
|
+
};
|
|
1595
|
+
callbacks?: {
|
|
1596
|
+
[key: string]: ReferenceObject | CallbackObject;
|
|
1597
|
+
};
|
|
1598
|
+
}
|
|
1599
|
+
type SecuritySchemeObject =
|
|
1600
|
+
| HttpSecurityScheme
|
|
1601
|
+
| ApiKeySecurityScheme
|
|
1602
|
+
| OAuth2SecurityScheme
|
|
1603
|
+
| OpenIdSecurityScheme;
|
|
1604
|
+
interface HttpSecurityScheme {
|
|
1605
|
+
type: "http";
|
|
1606
|
+
description?: string;
|
|
1607
|
+
scheme: string;
|
|
1608
|
+
bearerFormat?: string;
|
|
1609
|
+
}
|
|
1610
|
+
interface ApiKeySecurityScheme {
|
|
1611
|
+
type: "apiKey";
|
|
1612
|
+
description?: string;
|
|
1613
|
+
name: string;
|
|
1614
|
+
in: string;
|
|
1615
|
+
}
|
|
1616
|
+
interface OAuth2SecurityScheme {
|
|
1617
|
+
type: "oauth2";
|
|
1618
|
+
description?: string;
|
|
1619
|
+
flows: {
|
|
1620
|
+
implicit?: {
|
|
1621
|
+
authorizationUrl: string;
|
|
1622
|
+
refreshUrl?: string;
|
|
1623
|
+
scopes: {
|
|
1624
|
+
[scope: string]: string;
|
|
1625
|
+
};
|
|
1626
|
+
};
|
|
1627
|
+
password?: {
|
|
1628
|
+
tokenUrl: string;
|
|
1629
|
+
refreshUrl?: string;
|
|
1630
|
+
scopes: {
|
|
1631
|
+
[scope: string]: string;
|
|
1632
|
+
};
|
|
1633
|
+
};
|
|
1634
|
+
clientCredentials?: {
|
|
1635
|
+
tokenUrl: string;
|
|
1636
|
+
refreshUrl?: string;
|
|
1637
|
+
scopes: {
|
|
1638
|
+
[scope: string]: string;
|
|
1639
|
+
};
|
|
1640
|
+
};
|
|
1641
|
+
authorizationCode?: {
|
|
1642
|
+
authorizationUrl: string;
|
|
1643
|
+
tokenUrl: string;
|
|
1644
|
+
refreshUrl?: string;
|
|
1645
|
+
scopes: {
|
|
1646
|
+
[scope: string]: string;
|
|
1647
|
+
};
|
|
1648
|
+
};
|
|
1649
|
+
};
|
|
1650
|
+
}
|
|
1651
|
+
interface OpenIdSecurityScheme {
|
|
1652
|
+
type: "openIdConnect";
|
|
1653
|
+
description?: string;
|
|
1654
|
+
openIdConnectUrl: string;
|
|
1655
|
+
}
|
|
1656
|
+
interface TagObject {
|
|
1657
|
+
name: string;
|
|
1658
|
+
description?: string;
|
|
1659
|
+
externalDocs?: ExternalDocumentationObject;
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1663
|
+
declare namespace OpenAPIV3_1 {
|
|
1664
|
+
type Modify<T, R> = Omit<T, keyof R> & R;
|
|
1665
|
+
type PathsWebhooksComponents<T extends {} = {}> = {
|
|
1666
|
+
paths: PathsObject<T>;
|
|
1667
|
+
webhooks: Record<string, PathItemObject | ReferenceObject>;
|
|
1668
|
+
components: ComponentsObject;
|
|
1669
|
+
};
|
|
1670
|
+
type Document<T extends {} = {}> = Modify<
|
|
1671
|
+
Omit<OpenAPIV3.Document<T>, "paths" | "components">,
|
|
1672
|
+
{
|
|
1673
|
+
info: InfoObject;
|
|
1674
|
+
jsonSchemaDialect?: string;
|
|
1675
|
+
servers?: ServerObject[];
|
|
1676
|
+
} & (
|
|
1677
|
+
| (Pick<PathsWebhooksComponents<T>, "paths"> &
|
|
1678
|
+
Omit<Partial<PathsWebhooksComponents<T>>, "paths">)
|
|
1679
|
+
| (Pick<PathsWebhooksComponents<T>, "webhooks"> &
|
|
1680
|
+
Omit<Partial<PathsWebhooksComponents<T>>, "webhooks">)
|
|
1681
|
+
| (Pick<PathsWebhooksComponents<T>, "components"> &
|
|
1682
|
+
Omit<Partial<PathsWebhooksComponents<T>>, "components">)
|
|
1683
|
+
)
|
|
1684
|
+
>;
|
|
1685
|
+
type InfoObject = Modify<
|
|
1686
|
+
OpenAPIV3.InfoObject,
|
|
1687
|
+
{
|
|
1688
|
+
summary?: string;
|
|
1689
|
+
license?: LicenseObject;
|
|
1690
|
+
}
|
|
1691
|
+
>;
|
|
1692
|
+
type ContactObject = OpenAPIV3.ContactObject;
|
|
1693
|
+
type LicenseObject = Modify<
|
|
1694
|
+
OpenAPIV3.LicenseObject,
|
|
1695
|
+
{
|
|
1696
|
+
identifier?: string;
|
|
1697
|
+
}
|
|
1698
|
+
>;
|
|
1699
|
+
type ServerObject = Modify<
|
|
1700
|
+
OpenAPIV3.ServerObject,
|
|
1701
|
+
{
|
|
1702
|
+
url: string;
|
|
1703
|
+
description?: string;
|
|
1704
|
+
variables?: Record<string, ServerVariableObject>;
|
|
1705
|
+
}
|
|
1706
|
+
>;
|
|
1707
|
+
type ServerVariableObject = Modify<
|
|
1708
|
+
OpenAPIV3.ServerVariableObject,
|
|
1709
|
+
{
|
|
1710
|
+
enum?: [string, ...string[]];
|
|
1711
|
+
}
|
|
1712
|
+
>;
|
|
1713
|
+
type PathsObject<T extends {} = {}, P extends {} = {}> = Record<
|
|
1714
|
+
string,
|
|
1715
|
+
(PathItemObject<T> & P) | undefined
|
|
1716
|
+
>;
|
|
1717
|
+
type HttpMethods = OpenAPIV3.HttpMethods;
|
|
1718
|
+
type PathItemObject<T extends {} = {}> = Modify<
|
|
1719
|
+
OpenAPIV3.PathItemObject<T>,
|
|
1720
|
+
{
|
|
1721
|
+
servers?: ServerObject[];
|
|
1722
|
+
parameters?: (ReferenceObject | ParameterObject)[];
|
|
1723
|
+
}
|
|
1724
|
+
> & {
|
|
1725
|
+
[method in HttpMethods]?: OperationObject<T>;
|
|
1726
|
+
};
|
|
1727
|
+
type OperationObject<T extends {} = {}> = Modify<
|
|
1728
|
+
OpenAPIV3.OperationObject<T>,
|
|
1729
|
+
{
|
|
1730
|
+
parameters?: (ReferenceObject | ParameterObject)[];
|
|
1731
|
+
requestBody?: ReferenceObject | RequestBodyObject;
|
|
1732
|
+
responses?: ResponsesObject;
|
|
1733
|
+
callbacks?: Record<string, ReferenceObject | CallbackObject>;
|
|
1734
|
+
servers?: ServerObject[];
|
|
1735
|
+
}
|
|
1736
|
+
> &
|
|
1737
|
+
T;
|
|
1738
|
+
type ExternalDocumentationObject = OpenAPIV3.ExternalDocumentationObject;
|
|
1739
|
+
type ParameterObject = OpenAPIV3.ParameterObject;
|
|
1740
|
+
type HeaderObject = OpenAPIV3.HeaderObject;
|
|
1741
|
+
type ParameterBaseObject = OpenAPIV3.ParameterBaseObject;
|
|
1742
|
+
type NonArraySchemaObjectType = OpenAPIV3.NonArraySchemaObjectType | "null";
|
|
1743
|
+
type ArraySchemaObjectType = OpenAPIV3.ArraySchemaObjectType;
|
|
1744
|
+
/**
|
|
1745
|
+
* There is no way to tell typescript to require items when type is either 'array' or array containing 'array' type
|
|
1746
|
+
* 'items' will be always visible as optional
|
|
1747
|
+
* Casting schema object to ArraySchemaObject or NonArraySchemaObject will work fine
|
|
1748
|
+
*/
|
|
1749
|
+
type SchemaObject =
|
|
1750
|
+
| ArraySchemaObject
|
|
1751
|
+
| NonArraySchemaObject
|
|
1752
|
+
| MixedSchemaObject;
|
|
1753
|
+
interface ArraySchemaObject extends BaseSchemaObject {
|
|
1754
|
+
type: ArraySchemaObjectType;
|
|
1755
|
+
items: ReferenceObject | SchemaObject;
|
|
1756
|
+
}
|
|
1757
|
+
interface NonArraySchemaObject extends BaseSchemaObject {
|
|
1758
|
+
type?: NonArraySchemaObjectType;
|
|
1759
|
+
}
|
|
1760
|
+
interface MixedSchemaObject extends BaseSchemaObject {
|
|
1761
|
+
type?: (ArraySchemaObjectType | NonArraySchemaObjectType)[];
|
|
1762
|
+
items?: ReferenceObject | SchemaObject;
|
|
1763
|
+
}
|
|
1764
|
+
type BaseSchemaObject = Modify<
|
|
1765
|
+
Omit<OpenAPIV3.BaseSchemaObject, "nullable">,
|
|
1766
|
+
{
|
|
1767
|
+
examples?: OpenAPIV3.BaseSchemaObject["example"][];
|
|
1768
|
+
exclusiveMinimum?: boolean | number;
|
|
1769
|
+
exclusiveMaximum?: boolean | number;
|
|
1770
|
+
contentMediaType?: string;
|
|
1771
|
+
$schema?: string;
|
|
1772
|
+
additionalProperties?: boolean | ReferenceObject | SchemaObject;
|
|
1773
|
+
properties?: {
|
|
1774
|
+
[name: string]: ReferenceObject | SchemaObject;
|
|
1775
|
+
};
|
|
1776
|
+
allOf?: (ReferenceObject | SchemaObject)[];
|
|
1777
|
+
oneOf?: (ReferenceObject | SchemaObject)[];
|
|
1778
|
+
anyOf?: (ReferenceObject | SchemaObject)[];
|
|
1779
|
+
not?: ReferenceObject | SchemaObject;
|
|
1780
|
+
discriminator?: DiscriminatorObject;
|
|
1781
|
+
externalDocs?: ExternalDocumentationObject;
|
|
1782
|
+
xml?: XMLObject;
|
|
1783
|
+
const?: any;
|
|
1784
|
+
}
|
|
1785
|
+
>;
|
|
1786
|
+
type DiscriminatorObject = OpenAPIV3.DiscriminatorObject;
|
|
1787
|
+
type XMLObject = OpenAPIV3.XMLObject;
|
|
1788
|
+
type ReferenceObject = Modify<
|
|
1789
|
+
OpenAPIV3.ReferenceObject,
|
|
1790
|
+
{
|
|
1791
|
+
summary?: string;
|
|
1792
|
+
description?: string;
|
|
1793
|
+
}
|
|
1794
|
+
>;
|
|
1795
|
+
type ExampleObject = OpenAPIV3.ExampleObject;
|
|
1796
|
+
type MediaTypeObject = Modify<
|
|
1797
|
+
OpenAPIV3.MediaTypeObject,
|
|
1798
|
+
{
|
|
1799
|
+
schema?: SchemaObject | ReferenceObject;
|
|
1800
|
+
examples?: Record<string, ReferenceObject | ExampleObject>;
|
|
1801
|
+
}
|
|
1802
|
+
>;
|
|
1803
|
+
type EncodingObject = OpenAPIV3.EncodingObject;
|
|
1804
|
+
type RequestBodyObject = Modify<
|
|
1805
|
+
OpenAPIV3.RequestBodyObject,
|
|
1806
|
+
{
|
|
1807
|
+
content: {
|
|
1808
|
+
[media: string]: MediaTypeObject;
|
|
1809
|
+
};
|
|
1810
|
+
}
|
|
1811
|
+
>;
|
|
1812
|
+
type ResponsesObject = Record<string, ReferenceObject | ResponseObject>;
|
|
1813
|
+
type ResponseObject = Modify<
|
|
1814
|
+
OpenAPIV3.ResponseObject,
|
|
1815
|
+
{
|
|
1816
|
+
headers?: {
|
|
1817
|
+
[header: string]: ReferenceObject | HeaderObject;
|
|
1818
|
+
};
|
|
1819
|
+
content?: {
|
|
1820
|
+
[media: string]: MediaTypeObject;
|
|
1821
|
+
};
|
|
1822
|
+
links?: {
|
|
1823
|
+
[link: string]: ReferenceObject | LinkObject;
|
|
1824
|
+
};
|
|
1825
|
+
}
|
|
1826
|
+
>;
|
|
1827
|
+
type LinkObject = Modify<
|
|
1828
|
+
OpenAPIV3.LinkObject,
|
|
1829
|
+
{
|
|
1830
|
+
server?: ServerObject;
|
|
1831
|
+
}
|
|
1832
|
+
>;
|
|
1833
|
+
type CallbackObject = Record<string, PathItemObject | ReferenceObject>;
|
|
1834
|
+
type SecurityRequirementObject = OpenAPIV3.SecurityRequirementObject;
|
|
1835
|
+
type ComponentsObject = Modify<
|
|
1836
|
+
OpenAPIV3.ComponentsObject,
|
|
1837
|
+
{
|
|
1838
|
+
schemas?: Record<string, SchemaObject>;
|
|
1839
|
+
responses?: Record<string, ReferenceObject | ResponseObject>;
|
|
1840
|
+
parameters?: Record<string, ReferenceObject | ParameterObject>;
|
|
1841
|
+
examples?: Record<string, ReferenceObject | ExampleObject>;
|
|
1842
|
+
requestBodies?: Record<string, ReferenceObject | RequestBodyObject>;
|
|
1843
|
+
headers?: Record<string, ReferenceObject | HeaderObject>;
|
|
1844
|
+
securitySchemes?: Record<string, ReferenceObject | SecuritySchemeObject>;
|
|
1845
|
+
links?: Record<string, ReferenceObject | LinkObject>;
|
|
1846
|
+
callbacks?: Record<string, ReferenceObject | CallbackObject>;
|
|
1847
|
+
pathItems?: Record<string, ReferenceObject | PathItemObject>;
|
|
1848
|
+
}
|
|
1849
|
+
>;
|
|
1850
|
+
type SecuritySchemeObject = OpenAPIV3.SecuritySchemeObject;
|
|
1851
|
+
type HttpSecurityScheme = OpenAPIV3.HttpSecurityScheme;
|
|
1852
|
+
type ApiKeySecurityScheme = OpenAPIV3.ApiKeySecurityScheme;
|
|
1853
|
+
type OAuth2SecurityScheme = OpenAPIV3.OAuth2SecurityScheme;
|
|
1854
|
+
type OpenIdSecurityScheme = OpenAPIV3.OpenIdSecurityScheme;
|
|
1855
|
+
type TagObject = OpenAPIV3.TagObject;
|
|
1856
|
+
{
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
/**
|
|
1861
|
+
* Base object for parameter definitions
|
|
1862
|
+
* @public
|
|
1863
|
+
*/
|
|
1864
|
+
declare type ParameterBaseObject = Modify<
|
|
1865
|
+
Omit<
|
|
1866
|
+
OpenAPIV3_1.ParameterBaseObject,
|
|
1867
|
+
| "content"
|
|
1868
|
+
| "allowEmptyValue"
|
|
1869
|
+
| "style"
|
|
1870
|
+
| "allowReserved"
|
|
1871
|
+
| "explode"
|
|
1872
|
+
| "example"
|
|
1873
|
+
| "examples"
|
|
1874
|
+
>,
|
|
1875
|
+
{
|
|
1876
|
+
schema: OpenAPIV3_1.SchemaObject;
|
|
1877
|
+
}
|
|
1878
|
+
>;
|
|
1879
|
+
|
|
1880
|
+
/**
|
|
1881
|
+
* Definition of a parameter
|
|
1882
|
+
* @public
|
|
1883
|
+
*/
|
|
1884
|
+
declare interface ParameterDefinition extends ParameterBaseObject {
|
|
1885
|
+
name: string;
|
|
1886
|
+
in: string;
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1889
|
+
/**
|
|
1890
|
+
* This is the parsed values of the Cors configuration. All
|
|
1891
|
+
* values in the parsed configuration are in the format that the headers
|
|
1892
|
+
* use them (i.e. everything is converted to a string)
|
|
1893
|
+
*/
|
|
1894
|
+
declare interface ParsedCorsPolicyConfiguration {
|
|
1895
|
+
name: string;
|
|
1896
|
+
allowCredentials: string | undefined;
|
|
1897
|
+
maxAge: string | undefined;
|
|
1898
|
+
allowedOrigins: string[];
|
|
1899
|
+
allowedMethods?: string;
|
|
1900
|
+
allowedHeaders?: string;
|
|
1901
|
+
exposeHeaders?: string;
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1904
|
+
/**
|
|
1905
|
+
* @public
|
|
1906
|
+
*/
|
|
1907
|
+
declare interface ParsedRouteData extends Omit<RouteData, "corsPolicies"> {
|
|
1908
|
+
corsPolicies: ParsedCorsPolicyConfiguration[];
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
/**
|
|
1912
|
+
* @public
|
|
1913
|
+
*/
|
|
1914
|
+
declare interface PolicyConfiguration {
|
|
1915
|
+
name: string;
|
|
1916
|
+
policyType: string;
|
|
1917
|
+
handler: HandlerDefinition;
|
|
1918
|
+
options?: unknown;
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
/**
|
|
1922
|
+
* @public
|
|
1923
|
+
*/
|
|
1924
|
+
declare interface PreRoutingHook {
|
|
1925
|
+
(request: Request): Promise<Request> | Request;
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
/**
|
|
1929
|
+
* Problem Details for HTTP APIs
|
|
1930
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc7807 |RFC7807}
|
|
1931
|
+
* @public
|
|
1932
|
+
*/
|
|
1933
|
+
declare interface ProblemDetails {
|
|
1934
|
+
/**
|
|
1935
|
+
* A URI reference [RFC3986] that identifies the problem type.
|
|
1936
|
+
*
|
|
1937
|
+
* @remarks
|
|
1938
|
+
*
|
|
1939
|
+
* This specification encourages that, when dereferenced, it provide
|
|
1940
|
+
* human-readable documentation for the problem type
|
|
1941
|
+
* (e.g., using HTML [W3C.REC-html5-20141028]). When this member is not
|
|
1942
|
+
* present, its value is assumed to be "about:blank".
|
|
1943
|
+
*
|
|
1944
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc3986|RFC3986}
|
|
1945
|
+
*
|
|
1946
|
+
* @example
|
|
1947
|
+
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429
|
|
1948
|
+
*/
|
|
1949
|
+
type: string;
|
|
1950
|
+
/**
|
|
1951
|
+
* A short, human-readable summary of the problem type.
|
|
1952
|
+
*
|
|
1953
|
+
* @remarks
|
|
1954
|
+
*
|
|
1955
|
+
* It SHOULD NOT change from occurrence to occurrence of the problem, except
|
|
1956
|
+
* for purposes of localization (e.g., using proactive content negotiation;
|
|
1957
|
+
*
|
|
1958
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc7231#section-3.4|RFC7231, Section 3.4}.
|
|
1959
|
+
*
|
|
1960
|
+
* @example
|
|
1961
|
+
* Too many requests
|
|
1962
|
+
*/
|
|
1963
|
+
title: string;
|
|
1964
|
+
/**
|
|
1965
|
+
* The HTTP status code () generated by the origin server for this occurrence
|
|
1966
|
+
* of the problem.
|
|
1967
|
+
*
|
|
1968
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc7231#section-6|RFC7231, Section 6}
|
|
1969
|
+
*
|
|
1970
|
+
* @example
|
|
1971
|
+
* 429
|
|
1972
|
+
*/
|
|
1973
|
+
status: HttpStatusCode;
|
|
1974
|
+
/**
|
|
1975
|
+
* A human-readable explanation specific to this occurrence of the problem.
|
|
1976
|
+
*
|
|
1977
|
+
* @example
|
|
1978
|
+
* Rate limit exceeded, try again later
|
|
1979
|
+
*/
|
|
1980
|
+
detail?: string;
|
|
1981
|
+
/**
|
|
1982
|
+
* A URI reference that identifies the specific occurrence of the problem.
|
|
1983
|
+
* It may or may not yield further information if dereferenced.
|
|
1984
|
+
*
|
|
1985
|
+
* @example
|
|
1986
|
+
* josh-twist::test::main::prod::4edc99c/pizza/size/large/type/pepperoni
|
|
1987
|
+
*/
|
|
1988
|
+
instance?: string;
|
|
1989
|
+
/**
|
|
1990
|
+
* Identifiers useful to zuplo and the customer to locate more information in
|
|
1991
|
+
* logs. To reduce the number of properties these strings are concated
|
|
1992
|
+
*
|
|
1993
|
+
* @example
|
|
1994
|
+
* requestId:6384105d-1d34-4a7f-8ad7-5c428e97ab49/ray:lcielfnuuclvh/buildId:293908c3-e359-4037-874f-d9c71d4a7263
|
|
1995
|
+
*/
|
|
1996
|
+
trace?: Record<string, string>;
|
|
1997
|
+
/**
|
|
1998
|
+
* Problem type definitions MAY extend the problem details object with
|
|
1999
|
+
* additional members.
|
|
2000
|
+
*/
|
|
2001
|
+
[extensionMembers: string]: any;
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
/**
|
|
2005
|
+
* @public
|
|
2006
|
+
*/
|
|
2007
|
+
declare interface ProblemResponseDetails {
|
|
2008
|
+
problem: ProblemDetails;
|
|
2009
|
+
/**
|
|
2010
|
+
* statusText used in the response to accompany the
|
|
2011
|
+
*/
|
|
2012
|
+
statusText?: string;
|
|
2013
|
+
/**
|
|
2014
|
+
* Additional headers to be sent with the standard response. Used for things
|
|
2015
|
+
* like rate-limit retry-after headers (to meet other standards)
|
|
2016
|
+
*/
|
|
2017
|
+
additionalHeaders?: HeadersInit;
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
/**
|
|
2021
|
+
* @public
|
|
2022
|
+
*/
|
|
2023
|
+
declare interface ProblemResponseFormat {
|
|
2024
|
+
(
|
|
2025
|
+
problemDetails: ProblemResponseDetails,
|
|
2026
|
+
request: ZuploRequest,
|
|
2027
|
+
context: ZuploContext
|
|
2028
|
+
): Promise<Response> | Response;
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2031
|
+
/**
|
|
2032
|
+
* Generic type parameters for a request.
|
|
2033
|
+
* Extends RequestInitGeneric and adds query parameter typing.
|
|
2034
|
+
* @public
|
|
2035
|
+
*/
|
|
2036
|
+
declare interface RequestGeneric extends RequestInitGeneric {
|
|
2037
|
+
Query?: RequestQueryDefault;
|
|
2038
|
+
}
|
|
2039
|
+
|
|
2040
|
+
/**
|
|
2041
|
+
* Generic type parameters for request initialization.
|
|
2042
|
+
* Used to strongly type the user data and path parameters.
|
|
2043
|
+
* @public
|
|
2044
|
+
*/
|
|
2045
|
+
declare interface RequestInitGeneric {
|
|
2046
|
+
UserData?: UserDataDefault;
|
|
2047
|
+
Params?: RequestParamsDefault;
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2050
|
+
declare type RequestParamsDefault = Record<string, string>;
|
|
2051
|
+
|
|
2052
|
+
/* Excluded from this release type: RequestProcessor */
|
|
2053
|
+
|
|
2054
|
+
declare type RequestQueryDefault = Record<string, string>;
|
|
2055
|
+
|
|
2056
|
+
/**
|
|
2057
|
+
* Represents an authenticated user on the request.
|
|
2058
|
+
* Set by authentication policies like API key, JWT, or OAuth.
|
|
2059
|
+
*
|
|
2060
|
+
* @public
|
|
2061
|
+
* @example
|
|
2062
|
+
* ```typescript
|
|
2063
|
+
* // Access user info in a handler
|
|
2064
|
+
* export function myHandler(request: ZuploRequest, context: ZuploContext) {
|
|
2065
|
+
* if (!request.user) {
|
|
2066
|
+
* return new Response("Unauthorized", { status: 401 });
|
|
2067
|
+
* }
|
|
2068
|
+
*
|
|
2069
|
+
* const userId = request.user.sub;
|
|
2070
|
+
* const customData = request.user.data as { role: string; tenantId: string };
|
|
2071
|
+
*
|
|
2072
|
+
* context.log.info(`Request from user ${userId} with role ${customData.role}`);
|
|
2073
|
+
* }
|
|
2074
|
+
* ```
|
|
2075
|
+
*/
|
|
2076
|
+
declare interface RequestUser<TUserData> {
|
|
2077
|
+
sub: string;
|
|
2078
|
+
data: TUserData;
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
declare type ResolveRequestParams<
|
|
2082
|
+
TParams extends RequestParamsDefault | undefined,
|
|
2083
|
+
> = TParams extends RequestParamsDefault ? TParams : RequestParamsDefault;
|
|
2084
|
+
|
|
2085
|
+
declare type ResolveRequestQuery<
|
|
2086
|
+
TQuery extends RequestQueryDefault | undefined,
|
|
2087
|
+
> = TQuery extends RequestQueryDefault ? TQuery : RequestQueryDefault;
|
|
2088
|
+
|
|
2089
|
+
declare type ResolveUserData<TUserData extends UserDataDefault | undefined> =
|
|
2090
|
+
TUserData extends UserDataDefault ? TUserData : UserDataDefault;
|
|
2091
|
+
|
|
2092
|
+
/**
|
|
2093
|
+
* Definition of responses for a route
|
|
2094
|
+
* @public
|
|
2095
|
+
*/
|
|
2096
|
+
declare type ResponsesDefinition = Record<
|
|
2097
|
+
HttpStatusCode | HttpStatusCodeRangeDefinition,
|
|
2098
|
+
Modify<
|
|
2099
|
+
Omit<OpenAPIV3_1.ResponseObject, "links">,
|
|
2100
|
+
{
|
|
2101
|
+
headers?: {
|
|
2102
|
+
[header: string]: ParameterBaseObject;
|
|
2103
|
+
};
|
|
2104
|
+
}
|
|
2105
|
+
>
|
|
2106
|
+
>;
|
|
2107
|
+
|
|
2108
|
+
/**
|
|
2109
|
+
* @public
|
|
2110
|
+
*/
|
|
2111
|
+
declare interface RouteConfiguration extends Omit<
|
|
2112
|
+
BuildRouteConfiguration,
|
|
2113
|
+
"raw"
|
|
2114
|
+
> {
|
|
2115
|
+
/**
|
|
2116
|
+
* @deprecated Please switch to "raw().operationId"
|
|
2117
|
+
*/
|
|
2118
|
+
operationId?: string;
|
|
2119
|
+
/**
|
|
2120
|
+
* @deprecated Please switch to "raw().summary"
|
|
2121
|
+
*/
|
|
2122
|
+
summary?: string;
|
|
2123
|
+
/**
|
|
2124
|
+
* @deprecated Please switch to "raw().tags"
|
|
2125
|
+
*/
|
|
2126
|
+
tags?: string[];
|
|
2127
|
+
/**
|
|
2128
|
+
* @deprecated Please switch to "raw().parameters"
|
|
2129
|
+
*/
|
|
2130
|
+
parameters?: ParameterDefinition[];
|
|
2131
|
+
/**
|
|
2132
|
+
* @deprecated Please switch to "raw().responses"
|
|
2133
|
+
*/
|
|
2134
|
+
responses?: ResponsesDefinition;
|
|
2135
|
+
/**
|
|
2136
|
+
* Gets the raw route configuration object
|
|
2137
|
+
*/
|
|
2138
|
+
raw<T = any>(): T;
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
/**
|
|
2142
|
+
* @public
|
|
2143
|
+
*/
|
|
2144
|
+
declare interface RouteData {
|
|
2145
|
+
/**
|
|
2146
|
+
* @deprecated This property is not used and will be removed in future versions
|
|
2147
|
+
*/
|
|
2148
|
+
info?: OpenAPIV3_1.InfoObject;
|
|
2149
|
+
routes: RouteConfiguration[];
|
|
2150
|
+
policies: PolicyConfiguration[];
|
|
2151
|
+
corsPolicies: CorsPolicyConfiguration[];
|
|
2152
|
+
}
|
|
2153
|
+
|
|
2154
|
+
/**
|
|
2155
|
+
* @beta
|
|
2156
|
+
*/
|
|
2157
|
+
declare interface RouteHandler<T = unknown> {
|
|
2158
|
+
(request: ZuploRequest, context: ZuploContext): Promise<T>;
|
|
2159
|
+
}
|
|
2160
|
+
|
|
2161
|
+
/* Excluded from this release type: Router */
|
|
2162
|
+
|
|
2163
|
+
/**
|
|
2164
|
+
* Zuplo global runtime customization
|
|
2165
|
+
* @beta
|
|
2166
|
+
*/
|
|
2167
|
+
declare interface RuntimeExtensions {
|
|
2168
|
+
/**
|
|
2169
|
+
* Custom response formatter
|
|
2170
|
+
*/
|
|
2171
|
+
problemResponseFormat?: ProblemResponseFormat;
|
|
2172
|
+
/**
|
|
2173
|
+
* Register runtime plugins
|
|
2174
|
+
*/
|
|
2175
|
+
addPlugin: (plugin: RuntimePlugin) => void;
|
|
2176
|
+
/**
|
|
2177
|
+
* Set a custom not found handler
|
|
2178
|
+
*/
|
|
2179
|
+
notFoundHandler?: (
|
|
2180
|
+
request: ZuploRequest,
|
|
2181
|
+
context: ZuploContext,
|
|
2182
|
+
notFoundOptions: NotFoundOptions
|
|
2183
|
+
) => Promise<Response>;
|
|
2184
|
+
addRequestHook(hook: OnRequestHook): void;
|
|
2185
|
+
addResponseSendingHook(hook: OnResponseSendingHook): void;
|
|
2186
|
+
addResponseSendingFinalHook(hook: OnResponseSendingFinalHook): void;
|
|
2187
|
+
/**
|
|
2188
|
+
* Add a hook that runs before route matching occurs
|
|
2189
|
+
* @param hook - The pre-routing hook function
|
|
2190
|
+
*/
|
|
2191
|
+
addPreRoutingHook(hook: PreRoutingHook): void;
|
|
2192
|
+
}
|
|
2193
|
+
|
|
2194
|
+
/**
|
|
2195
|
+
* @public
|
|
2196
|
+
*/
|
|
2197
|
+
declare abstract class RuntimePlugin {}
|
|
2198
|
+
|
|
2199
|
+
/* Excluded from this release type: RuntimeSettings */
|
|
2200
|
+
|
|
2201
|
+
/**
|
|
2202
|
+
* Plugins for registering system capabilities
|
|
2203
|
+
* @public
|
|
2204
|
+
*/
|
|
2205
|
+
declare abstract class SystemRuntimePlugin extends RuntimePlugin {
|
|
2206
|
+
/* Excluded from this release type: initialize */
|
|
2207
|
+
/* Excluded from this release type: registerRoutes */
|
|
2208
|
+
}
|
|
2209
|
+
|
|
2210
|
+
declare interface UrlConfig {
|
|
2211
|
+
defaultUrl: string;
|
|
2212
|
+
urls: string[];
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2215
|
+
declare type UserDataDefault = any;
|
|
2216
|
+
|
|
2217
|
+
/**
|
|
2218
|
+
* @public
|
|
2219
|
+
*/
|
|
2220
|
+
declare interface WaitUntilFunc {
|
|
2221
|
+
(promise: Promise<any>): void;
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
declare interface ZuploAnalyticsContext {
|
|
2225
|
+
addAnalyticsEvent(
|
|
2226
|
+
value: number,
|
|
2227
|
+
eventType: EventType,
|
|
2228
|
+
metadata: JsonObject,
|
|
2229
|
+
unit?: string
|
|
2230
|
+
): void;
|
|
2231
|
+
flushAnalyticsEvents(): ZuploAnalyticsEvent[];
|
|
2232
|
+
getAnalyticsEvents(): ZuploAnalyticsEvent[];
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2235
|
+
declare interface ZuploAnalyticsEvent<T extends JsonObject = JsonObject> {
|
|
2236
|
+
eventId: string;
|
|
2237
|
+
requestId: string;
|
|
2238
|
+
timestamp: Date;
|
|
2239
|
+
accountName: string;
|
|
2240
|
+
projectName: string;
|
|
2241
|
+
deploymentName: string;
|
|
2242
|
+
eventType: EventType;
|
|
2243
|
+
metadata: T;
|
|
2244
|
+
unit?: string;
|
|
2245
|
+
value: number;
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2248
|
+
/**
|
|
2249
|
+
* The ZuploContext provides information about the current request and helper methods.
|
|
2250
|
+
* @public
|
|
2251
|
+
*/
|
|
2252
|
+
declare interface ZuploContext extends EventTarget {
|
|
2253
|
+
/**
|
|
2254
|
+
* The unique identifier of this context
|
|
2255
|
+
*/
|
|
2256
|
+
readonly contextId: Readonly<string>;
|
|
2257
|
+
/**
|
|
2258
|
+
* The unique identifier of the incoming request
|
|
2259
|
+
*/
|
|
2260
|
+
readonly requestId: Readonly<string>;
|
|
2261
|
+
/**
|
|
2262
|
+
* Request based logger
|
|
2263
|
+
*/
|
|
2264
|
+
readonly log: Readonly<Logger>;
|
|
2265
|
+
/**
|
|
2266
|
+
* The route that is being processed
|
|
2267
|
+
*/
|
|
2268
|
+
readonly route: Readonly<RouteConfiguration>;
|
|
2269
|
+
/**
|
|
2270
|
+
* Custom data stored on the ZuploContext
|
|
2271
|
+
*/
|
|
2272
|
+
readonly custom: Record<string, any>;
|
|
2273
|
+
readonly incomingRequestProperties: IncomingRequestProperties;
|
|
2274
|
+
/**
|
|
2275
|
+
* The parent context that spawned this context
|
|
2276
|
+
* @beta
|
|
2277
|
+
*/
|
|
2278
|
+
readonly parentContext: ZuploContext | undefined;
|
|
2279
|
+
/* Excluded from this release type: analyticsContext */
|
|
2280
|
+
readonly invokeInboundPolicy: (
|
|
2281
|
+
policyName: string,
|
|
2282
|
+
request: ZuploRequest
|
|
2283
|
+
) => Promise<Response | ZuploRequest>;
|
|
2284
|
+
readonly invokeOutboundPolicy: (
|
|
2285
|
+
policyName: string,
|
|
2286
|
+
response: Response,
|
|
2287
|
+
request: ZuploRequest
|
|
2288
|
+
) => Promise<Response>;
|
|
2289
|
+
/**
|
|
2290
|
+
* Invokes a route based on a Request without going back out to HTTP.
|
|
2291
|
+
* Can take a relative route path to invoke on the Gateway
|
|
2292
|
+
* Example: "/my/route" will invoke http://localhost/my/route on the Gateway
|
|
2293
|
+
* without having to rebuild the Request's protocol and host.
|
|
2294
|
+
* @beta
|
|
2295
|
+
*/
|
|
2296
|
+
readonly invokeRoute: <TOptions extends RequestGeneric = RequestGeneric>(
|
|
2297
|
+
input: string | URL | Request,
|
|
2298
|
+
init?: ZuploRequestInit<TOptions>
|
|
2299
|
+
) => Promise<Response>;
|
|
2300
|
+
readonly waitUntil: WaitUntilFunc;
|
|
2301
|
+
/**
|
|
2302
|
+
* Fires just before the response is sent. Response can be modified.
|
|
2303
|
+
*/
|
|
2304
|
+
readonly addResponseSendingHook: (hook: OnResponseSendingHook) => void;
|
|
2305
|
+
/**
|
|
2306
|
+
* Fires immediately after the response is sent. Response cannot be modified.
|
|
2307
|
+
*/
|
|
2308
|
+
readonly addResponseSendingFinalHook: (
|
|
2309
|
+
hook: OnResponseSendingFinalHook
|
|
2310
|
+
) => void;
|
|
2311
|
+
/**
|
|
2312
|
+
* Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
|
|
2313
|
+
*
|
|
2314
|
+
* The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.
|
|
2315
|
+
*
|
|
2316
|
+
* When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.
|
|
2317
|
+
*
|
|
2318
|
+
* When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
|
|
2319
|
+
*
|
|
2320
|
+
* When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
|
|
2321
|
+
*
|
|
2322
|
+
* If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
|
|
2323
|
+
*
|
|
2324
|
+
* The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
|
|
2325
|
+
* @deprecated This will be removed in the future. Use hooks instead. See {@link https://zuplo.com/docs/programmable-api/runtime-extensions}
|
|
2326
|
+
*/
|
|
2327
|
+
addEventListener<Type extends keyof Record<string, Event>>(
|
|
2328
|
+
type: Type,
|
|
2329
|
+
handler: EventListenerOrEventListenerObject,
|
|
2330
|
+
options?: AddEventListenerOptions | boolean
|
|
2331
|
+
): void;
|
|
2332
|
+
/**
|
|
2333
|
+
* @deprecated This will be removed in the future. See {@link https://zuplo.com/docs/programmable-api/runtime-extensions}
|
|
2334
|
+
*/
|
|
2335
|
+
removeEventListener<Type extends keyof Record<string, Event>>(
|
|
2336
|
+
type: Type,
|
|
2337
|
+
handler: EventListenerOrEventListenerObject,
|
|
2338
|
+
options?: AddEventListenerOptions | boolean
|
|
2339
|
+
): void;
|
|
2340
|
+
}
|
|
2341
|
+
|
|
2342
|
+
/**
|
|
2343
|
+
* Enhanced Request class that extends the standard Web Request API with
|
|
2344
|
+
* convenient properties for accessing path parameters, query strings, and user data.
|
|
2345
|
+
* This is the request type passed to all handlers and policies in Zuplo.
|
|
2346
|
+
*
|
|
2347
|
+
* @public
|
|
2348
|
+
* @example
|
|
2349
|
+
* ```typescript
|
|
2350
|
+
* import { ZuploRequest, ZuploContext } from "@zuplo/runtime";
|
|
2351
|
+
*
|
|
2352
|
+
* export function myHandler(request: ZuploRequest, context: ZuploContext) {
|
|
2353
|
+
* // Access query parameters
|
|
2354
|
+
* const page = request.query.page || "1";
|
|
2355
|
+
* const limit = request.query.limit || "10";
|
|
2356
|
+
*
|
|
2357
|
+
* // Access path parameters (e.g., from /users/:userId)
|
|
2358
|
+
* const userId = request.params.userId;
|
|
2359
|
+
*
|
|
2360
|
+
* // Access authenticated user
|
|
2361
|
+
* const user = request.user;
|
|
2362
|
+
*
|
|
2363
|
+
* // Standard Request properties still available
|
|
2364
|
+
* const contentType = request.headers.get("content-type");
|
|
2365
|
+
* const method = request.method;
|
|
2366
|
+
*
|
|
2367
|
+
* return Response.json({
|
|
2368
|
+
* userId,
|
|
2369
|
+
* page,
|
|
2370
|
+
* limit,
|
|
2371
|
+
* authenticated: !!user
|
|
2372
|
+
* });
|
|
2373
|
+
* }
|
|
2374
|
+
* ```
|
|
2375
|
+
*
|
|
2376
|
+
* @example
|
|
2377
|
+
* ```typescript
|
|
2378
|
+
* // Strongly typed request parameters
|
|
2379
|
+
* interface MyParams {
|
|
2380
|
+
* userId: string;
|
|
2381
|
+
* orderId: string;
|
|
2382
|
+
* }
|
|
2383
|
+
*
|
|
2384
|
+
* interface MyQuery {
|
|
2385
|
+
* include?: string;
|
|
2386
|
+
* format?: "json" | "xml";
|
|
2387
|
+
* }
|
|
2388
|
+
*
|
|
2389
|
+
* interface MyUserData {
|
|
2390
|
+
* role: "admin" | "user";
|
|
2391
|
+
* tenantId: string;
|
|
2392
|
+
* }
|
|
2393
|
+
*
|
|
2394
|
+
* type MyRequest = ZuploRequest<{
|
|
2395
|
+
* Params: MyParams;
|
|
2396
|
+
* Query: MyQuery;
|
|
2397
|
+
* UserData: MyUserData;
|
|
2398
|
+
* }>;
|
|
2399
|
+
*
|
|
2400
|
+
* export function typedHandler(request: MyRequest, context: ZuploContext) {
|
|
2401
|
+
* // All properties are now strongly typed
|
|
2402
|
+
* const userId = request.params.userId; // string
|
|
2403
|
+
* const format = request.query.format; // "json" | "xml" | undefined
|
|
2404
|
+
* const role = request.user?.data.role; // "admin" | "user" | undefined
|
|
2405
|
+
* }
|
|
2406
|
+
* ```
|
|
2407
|
+
*/
|
|
2408
|
+
declare class ZuploRequest<
|
|
2409
|
+
TOptions extends RequestGeneric = RequestGeneric,
|
|
2410
|
+
> extends Request {
|
|
2411
|
+
#private;
|
|
2412
|
+
constructor(
|
|
2413
|
+
input: string | URL | Request,
|
|
2414
|
+
init?: ZuploRequestInit<TOptions>,
|
|
2415
|
+
originalRequest?: Request
|
|
2416
|
+
);
|
|
2417
|
+
/* Excluded from this release type: originalRequest */
|
|
2418
|
+
/**
|
|
2419
|
+
* A dictionary of query-string values
|
|
2420
|
+
*
|
|
2421
|
+
* @example
|
|
2422
|
+
* The url `https://example.com?foo=bar` would return
|
|
2423
|
+
* the following query object:
|
|
2424
|
+
*
|
|
2425
|
+
* ```
|
|
2426
|
+
* const foo = request.query.foo;
|
|
2427
|
+
* ```
|
|
2428
|
+
*
|
|
2429
|
+
* @readonly
|
|
2430
|
+
*/
|
|
2431
|
+
get query(): Readonly<ResolveRequestQuery<TOptions["Query"]>>;
|
|
2432
|
+
/**
|
|
2433
|
+
* If you use tokens in your route’s URL, they are
|
|
2434
|
+
* automatically parsed into properties on the params
|
|
2435
|
+
* property of your request.
|
|
2436
|
+
*
|
|
2437
|
+
* @example
|
|
2438
|
+
* The route `/products/:productId/vendors/:vendorId`
|
|
2439
|
+
* would include two params:
|
|
2440
|
+
*
|
|
2441
|
+
* ```
|
|
2442
|
+
* const productId = request.params.productId;
|
|
2443
|
+
* const vendorId = request.params.vendorId;
|
|
2444
|
+
* ```
|
|
2445
|
+
* @readonly
|
|
2446
|
+
*/
|
|
2447
|
+
get params(): Readonly<ResolveRequestParams<TOptions["Params"]>>;
|
|
2448
|
+
/**
|
|
2449
|
+
* An optional object identifying a ‘user’.
|
|
2450
|
+
*
|
|
2451
|
+
* @remarks
|
|
2452
|
+
* If undefined this typically means the request is
|
|
2453
|
+
* anonymous. If present, the user object will have
|
|
2454
|
+
* a sub property that is a unique identifier for
|
|
2455
|
+
* that user. There is also an optional data property
|
|
2456
|
+
* that is of any type that typically contains other
|
|
2457
|
+
* information about the user. When using JWT tokens
|
|
2458
|
+
* you’ll usually find all the claims here.
|
|
2459
|
+
*
|
|
2460
|
+
* @readonly
|
|
2461
|
+
*/
|
|
2462
|
+
user?: RequestUser<ResolveUserData<TOptions["UserData"]>>;
|
|
2463
|
+
}
|
|
2464
|
+
|
|
2465
|
+
/**
|
|
2466
|
+
* Options for creating a new ZuploRequest.
|
|
2467
|
+
* Extends the standard RequestInit with Zuplo-specific properties.
|
|
2468
|
+
* @public
|
|
2469
|
+
*/
|
|
2470
|
+
declare interface ZuploRequestInit<
|
|
2471
|
+
TOptions extends RequestInitGeneric = RequestInitGeneric,
|
|
2472
|
+
> extends RequestInit {
|
|
2473
|
+
params?: ResolveRequestParams<TOptions["Params"]>;
|
|
2474
|
+
user?: ResolveUserData<TOptions["UserData"]>;
|
|
2475
|
+
}
|
|
2476
|
+
|
|
2477
|
+
export {};
|