@geostrategists/react-router-aws 2.2.1 → 2.3.0-rc.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/README.md +67 -0
- package/dist/index.cjs +352 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +661 -0
- package/dist/index.d.mts +583 -24
- package/dist/index.mjs +302 -305
- package/dist/index.mjs.map +1 -0
- package/package.json +43 -82
- package/biome.json +0 -47
- package/dist/index.d.ts +0 -102
- package/dist/index.js +0 -378
- package/test/alb.test.ts +0 -95
- package/test/apigw-v1.test.ts +0 -101
- package/test/apigw-v2.test.ts +0 -107
- package/test/function-url-streaming.test.ts +0 -107
- package/test/function-url.test.ts +0 -107
- package/test/lambda-stream/HttpResponseStream.ts +0 -34
- package/test/lambda-stream/ResponseStream.ts +0 -44
- package/test/lambda-stream/index.ts +0 -56
- package/test/setup.ts +0 -7
- package/test/utils.ts +0 -69
- package/vitest.config.ts +0 -12
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,529 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @geostrategists/react-router-aws v2.3.0-rc.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Geostrategists Consulting GmbH
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
import { AppLoadContext, RouterContextProvider, ServerBuild, UNSAFE_MiddlewareEnabled } from "react-router";
|
|
12
|
+
import { Writable } from "node:stream";
|
|
4
13
|
|
|
14
|
+
//#region node_modules/.pnpm/@types+aws-lambda@8.10.162/node_modules/@types/aws-lambda/common/api-gateway.d.ts
|
|
15
|
+
// Default authorizer type, prefer using a specific type with the "...WithAuthorizer..." variant types.
|
|
16
|
+
// Note that this doesn't have to be a context from a custom lambda outhorizer, AWS also has a cognito
|
|
17
|
+
// authorizer type and could add more, so the property won't always be a string.
|
|
18
|
+
type APIGatewayEventDefaultAuthorizerContext = undefined | null | {
|
|
19
|
+
[name: string]: any;
|
|
20
|
+
};
|
|
21
|
+
// The requestContext property of both request authorizer and proxy integration events.
|
|
22
|
+
interface APIGatewayEventRequestContextWithAuthorizer<TAuthorizerContext> {
|
|
23
|
+
accountId: string;
|
|
24
|
+
apiId: string; // This one is a bit confusing: it is not actually present in authorizer calls
|
|
25
|
+
// and proxy calls without an authorizer. We model this by allowing undefined in the type,
|
|
26
|
+
// since it ends up the same and avoids breaking users that are testing the property.
|
|
27
|
+
// This lets us allow parameterizing the authorizer for proxy events that know what authorizer
|
|
28
|
+
// context values they have.
|
|
29
|
+
authorizer: TAuthorizerContext;
|
|
30
|
+
connectedAt?: number | undefined;
|
|
31
|
+
connectionId?: string | undefined;
|
|
32
|
+
domainName?: string | undefined;
|
|
33
|
+
domainPrefix?: string | undefined;
|
|
34
|
+
eventType?: string | undefined;
|
|
35
|
+
extendedRequestId?: string | undefined;
|
|
36
|
+
protocol: string;
|
|
37
|
+
httpMethod: string;
|
|
38
|
+
identity: APIGatewayEventIdentity;
|
|
39
|
+
messageDirection?: string | undefined;
|
|
40
|
+
messageId?: string | null | undefined;
|
|
41
|
+
path: string;
|
|
42
|
+
stage: string;
|
|
43
|
+
requestId: string;
|
|
44
|
+
requestTime?: string | undefined;
|
|
45
|
+
requestTimeEpoch: number;
|
|
46
|
+
resourceId: string;
|
|
47
|
+
resourcePath: string;
|
|
48
|
+
routeKey?: string | undefined;
|
|
49
|
+
}
|
|
50
|
+
interface APIGatewayEventClientCertificate {
|
|
51
|
+
clientCertPem: string;
|
|
52
|
+
serialNumber: string;
|
|
53
|
+
subjectDN: string;
|
|
54
|
+
issuerDN: string;
|
|
55
|
+
validity: {
|
|
56
|
+
notAfter: string;
|
|
57
|
+
notBefore: string;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
interface APIGatewayEventIdentity {
|
|
61
|
+
accessKey: string | null;
|
|
62
|
+
accountId: string | null;
|
|
63
|
+
apiKey: string | null;
|
|
64
|
+
apiKeyId: string | null;
|
|
65
|
+
caller: string | null;
|
|
66
|
+
clientCert: APIGatewayEventClientCertificate | null;
|
|
67
|
+
cognitoAuthenticationProvider: string | null;
|
|
68
|
+
cognitoAuthenticationType: string | null;
|
|
69
|
+
cognitoIdentityId: string | null;
|
|
70
|
+
cognitoIdentityPoolId: string | null;
|
|
71
|
+
principalOrgId: string | null;
|
|
72
|
+
sourceIp: string;
|
|
73
|
+
user: string | null;
|
|
74
|
+
userAgent: string | null;
|
|
75
|
+
userArn: string | null;
|
|
76
|
+
vpcId?: string | undefined;
|
|
77
|
+
vpceId?: string | undefined;
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region node_modules/.pnpm/@types+aws-lambda@8.10.162/node_modules/@types/aws-lambda/handler.d.ts
|
|
81
|
+
/**
|
|
82
|
+
* The interface that AWS Lambda will invoke your handler with.
|
|
83
|
+
* There are more specialized types for many cases where AWS services
|
|
84
|
+
* invoke your lambda, but you can directly use this type for when you are invoking
|
|
85
|
+
* your lambda directly.
|
|
86
|
+
*
|
|
87
|
+
* See the {@link http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html AWS documentation}
|
|
88
|
+
* for more information about the runtime behavior, and the
|
|
89
|
+
* {@link https://aws.amazon.com/blogs/compute/node-js-8-10-runtime-now-available-in-aws-lambda/ AWS Blog post}
|
|
90
|
+
* introducing the async handler behavior in the 8.10 runtime.
|
|
91
|
+
*
|
|
92
|
+
* @example <caption>Defining a custom handler type</caption>
|
|
93
|
+
* import { Handler } from 'aws-lambda'
|
|
94
|
+
*
|
|
95
|
+
* interface NameEvent {
|
|
96
|
+
* fullName: string
|
|
97
|
+
* }
|
|
98
|
+
* interface NameResult {
|
|
99
|
+
* firstName: string
|
|
100
|
+
* middleNames: string
|
|
101
|
+
* lastName: string
|
|
102
|
+
* }
|
|
103
|
+
* type PersonHandler = Handler<NameEvent, NameResult>
|
|
104
|
+
*
|
|
105
|
+
* export const handler: PersonHandler = async (event) => {
|
|
106
|
+
* const names = event.fullName.split(' ')
|
|
107
|
+
* const firstName = names.shift()
|
|
108
|
+
* const lastName = names.pop()
|
|
109
|
+
* return { firstName, middleNames: names, lastName }
|
|
110
|
+
* }
|
|
111
|
+
*
|
|
112
|
+
* @example <caption>Logs the contents of the event object and returns the location of the logs</caption>
|
|
113
|
+
* import { Handler } from 'aws-lambda'
|
|
114
|
+
*
|
|
115
|
+
* export const handler: Handler = async (event, context) => {
|
|
116
|
+
* console.log("EVENT: \n" + JSON.stringify(event, null, 2))
|
|
117
|
+
* return context.logStreamName
|
|
118
|
+
* }
|
|
119
|
+
*
|
|
120
|
+
* @example <caption>AWS SDK with Async Function and Promises</caption>
|
|
121
|
+
* import { Handler } from 'aws-lambda'
|
|
122
|
+
* import AWS from 'aws-sdk'
|
|
123
|
+
*
|
|
124
|
+
* const s3 = new AWS.S3()
|
|
125
|
+
*
|
|
126
|
+
* export const handler: Handler = async (event) => {
|
|
127
|
+
* const response = await s3.listBuckets().promise()
|
|
128
|
+
* return response?.Buckets.map((bucket) => bucket.Name)
|
|
129
|
+
* }
|
|
130
|
+
*
|
|
131
|
+
* @example <caption>HTTP Request with Callback</caption>
|
|
132
|
+
* import { Handler } from 'aws-lambda'
|
|
133
|
+
* import https from 'https'
|
|
134
|
+
*
|
|
135
|
+
* let url = "https://docs.aws.amazon.com/lambda/latest/dg/welcome.html"
|
|
136
|
+
*
|
|
137
|
+
* export const handler: Handler<void, number> = (event, context, callback) => {
|
|
138
|
+
* https.get(url, (res) => {
|
|
139
|
+
* callback(null, res.statusCode)
|
|
140
|
+
* }).on('error', (e) => {
|
|
141
|
+
* callback(Error(e))
|
|
142
|
+
* })
|
|
143
|
+
* }
|
|
144
|
+
*
|
|
145
|
+
* @param event
|
|
146
|
+
* Parsed JSON data in the lambda request payload. For an AWS service triggered
|
|
147
|
+
* lambda this should be in the format of a type ending in Event, for example the
|
|
148
|
+
* S3Handler receives an event of type S3Event.
|
|
149
|
+
* @param context
|
|
150
|
+
* Runtime contextual information of the current invocation, for example the caller
|
|
151
|
+
* identity, available memory and time remaining, legacy completion callbacks, and
|
|
152
|
+
* a mutable property controlling when the lambda execution completes.
|
|
153
|
+
* @param callback
|
|
154
|
+
* NodeJS-style completion callback that the AWS Lambda runtime will provide that can
|
|
155
|
+
* be used to provide the lambda result payload value, or any execution error. Can
|
|
156
|
+
* instead return a promise that resolves with the result payload value or rejects
|
|
157
|
+
* with the execution error.
|
|
158
|
+
* @return
|
|
159
|
+
* A promise that resolves with the lambda result payload value, or rejects with the
|
|
160
|
+
* execution error. Note that if you implement your handler as an async function,
|
|
161
|
+
* you will automatically return a promise that will resolve with a returned value,
|
|
162
|
+
* or reject with a thrown value.
|
|
163
|
+
*/
|
|
164
|
+
type Handler<TEvent = any, TResult = any> = (event: TEvent, context: Context, callback: Callback<TResult>) => void | Promise<TResult> // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
165
|
+
;
|
|
166
|
+
/**
|
|
167
|
+
* {@link Handler} context parameter.
|
|
168
|
+
* See {@link https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html AWS documentation}.
|
|
169
|
+
*/
|
|
170
|
+
interface Context {
|
|
171
|
+
callbackWaitsForEmptyEventLoop: boolean;
|
|
172
|
+
functionName: string;
|
|
173
|
+
functionVersion: string;
|
|
174
|
+
invokedFunctionArn: string;
|
|
175
|
+
memoryLimitInMB: string;
|
|
176
|
+
awsRequestId: string;
|
|
177
|
+
logGroupName: string;
|
|
178
|
+
logStreamName: string;
|
|
179
|
+
identity?: CognitoIdentity | undefined;
|
|
180
|
+
clientContext?: ClientContext | undefined;
|
|
181
|
+
tenantId?: string | undefined;
|
|
182
|
+
getRemainingTimeInMillis(): number; // Functions for compatibility with earlier Node.js Runtime v0.10.42
|
|
183
|
+
// No longer documented, so they are deprecated, but they still work
|
|
184
|
+
// as of the 12.x runtime, so they are not removed from the types.
|
|
185
|
+
/** @deprecated Use handler callback or promise result */
|
|
186
|
+
done(error?: Error, result?: any): void;
|
|
187
|
+
/** @deprecated Use handler callback with first argument or reject a promise result */
|
|
188
|
+
fail(error: Error | string): void;
|
|
189
|
+
/** @deprecated Use handler callback with second argument or resolve a promise result */
|
|
190
|
+
succeed(messageOrObject: any): void; // Unclear what behavior this is supposed to have, I couldn't find any still extant reference,
|
|
191
|
+
// and it behaves like the above, ignoring the object parameter.
|
|
192
|
+
/** @deprecated Use handler callback or promise result */
|
|
193
|
+
succeed(message: string, object: any): void;
|
|
194
|
+
}
|
|
195
|
+
interface CognitoIdentity {
|
|
196
|
+
cognitoIdentityId: string;
|
|
197
|
+
cognitoIdentityPoolId: string;
|
|
198
|
+
}
|
|
199
|
+
interface ClientContext {
|
|
200
|
+
client: ClientContextClient;
|
|
201
|
+
custom?: any;
|
|
202
|
+
env: ClientContextEnv;
|
|
203
|
+
}
|
|
204
|
+
interface ClientContextClient {
|
|
205
|
+
installationId: string;
|
|
206
|
+
appTitle: string;
|
|
207
|
+
appVersionName: string;
|
|
208
|
+
appVersionCode: string;
|
|
209
|
+
appPackageName: string;
|
|
210
|
+
}
|
|
211
|
+
interface ClientContextEnv {
|
|
212
|
+
platformVersion: string;
|
|
213
|
+
platform: string;
|
|
214
|
+
make: string;
|
|
215
|
+
model: string;
|
|
216
|
+
locale: string;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* NodeJS-style callback parameter for the {@link Handler} type.
|
|
220
|
+
* Can be used instead of returning a promise, see the
|
|
221
|
+
* {@link https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html AWS documentation}
|
|
222
|
+
* for the handler programming model.
|
|
223
|
+
*
|
|
224
|
+
* @param error
|
|
225
|
+
* Parameter to use to provide the error payload for a failed lambda execution.
|
|
226
|
+
* See {@link https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-mode-exceptions.html AWS documentation}
|
|
227
|
+
* for error handling.
|
|
228
|
+
* If an Error instance is passed, the error payload uses the `name` property as the `errorType`,
|
|
229
|
+
* the `message` property as the `errorMessage`, and parses the `stack` property string into
|
|
230
|
+
* the `trace` array.
|
|
231
|
+
* For other values, the `errorType` is `typeof value`, the `errorMessage` is `String(value)`, and
|
|
232
|
+
* `trace` is an empty array.
|
|
233
|
+
*
|
|
234
|
+
* @param result
|
|
235
|
+
* Parameter to use to provide the result payload for a successful lambda execution.
|
|
236
|
+
* Pass `null` or `undefined` for the `error` parameter to use this parameter.
|
|
237
|
+
*/
|
|
238
|
+
type Callback<TResult = any> = (error?: Error | string | null, result?: TResult) => void;
|
|
239
|
+
/**
|
|
240
|
+
* Interface for using response streaming from AWS Lambda.
|
|
241
|
+
* To indicate to the runtime that Lambda should stream your function’s responses, you must wrap your function handler with the `awslambda.streamifyResponse()` decorator.
|
|
242
|
+
*
|
|
243
|
+
* The `streamifyResponse` decorator accepts the following additional parameter, `responseStream`, besides the default node handler parameters, `event`, and `context`.
|
|
244
|
+
* The new `responseStream` object provides a stream object that your function can write data to. Data written to this stream is sent immediately to the client. You can optionally set the Content-Type header of the response to pass additional metadata to your client about the contents of the stream.
|
|
245
|
+
*
|
|
246
|
+
* {@link https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/ AWS blog post}
|
|
247
|
+
* {@link https://docs.aws.amazon.com/lambda/latest/dg/config-rs-write-functions.html AWS documentation}
|
|
248
|
+
*
|
|
249
|
+
* @example <caption>Writing to the response stream</caption>
|
|
250
|
+
* import 'aws-lambda';
|
|
251
|
+
*
|
|
252
|
+
* export const handler = awslambda.streamifyResponse(
|
|
253
|
+
* async (event, responseStream, context) => {
|
|
254
|
+
* responseStream.setContentType("text/plain");
|
|
255
|
+
* responseStream.write("Hello, world!");
|
|
256
|
+
* responseStream.end();
|
|
257
|
+
* }
|
|
258
|
+
* );
|
|
259
|
+
*
|
|
260
|
+
* @example <caption>Using pipeline</caption>
|
|
261
|
+
* import 'aws-lambda';
|
|
262
|
+
* import { Readable } from 'stream';
|
|
263
|
+
* import { pipeline } from 'stream/promises';
|
|
264
|
+
* import zlib from 'zlib';
|
|
265
|
+
*
|
|
266
|
+
* export const handler = awslambda.streamifyResponse(
|
|
267
|
+
* async (event, responseStream, context) => {
|
|
268
|
+
* // As an example, convert event to a readable stream.
|
|
269
|
+
* const requestStream = Readable.from(Buffer.from(JSON.stringify(event)));
|
|
270
|
+
*
|
|
271
|
+
* await pipeline(requestStream, zlib.createGzip(), responseStream);
|
|
272
|
+
* }
|
|
273
|
+
* );
|
|
274
|
+
*/
|
|
275
|
+
type StreamifyHandler<TEvent = any, TResult = any> = (event: TEvent, responseStream: awslambda.HttpResponseStream, context: Context) => TResult | Promise<TResult>;
|
|
276
|
+
declare global {
|
|
277
|
+
namespace awslambda {
|
|
278
|
+
class HttpResponseStream extends Writable {
|
|
279
|
+
static from(writable: Writable, metadata: Record<string, unknown>): HttpResponseStream;
|
|
280
|
+
setContentType: (contentType: string) => void;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Decorator for using response streaming from AWS Lambda.
|
|
284
|
+
* To indicate to the runtime that Lambda should stream your function’s responses, you must wrap your function handler with the `awslambda.streamifyResponse()` decorator.
|
|
285
|
+
*
|
|
286
|
+
* The `streamifyResponse` decorator accepts the following additional parameter, `responseStream`, besides the default node handler parameters, `event`, and `context`.
|
|
287
|
+
* The new `responseStream` object provides a stream object that your function can write data to. Data written to this stream is sent immediately to the client. You can optionally set the Content-Type header of the response to pass additional metadata to your client about the contents of the stream.
|
|
288
|
+
*
|
|
289
|
+
* {@link https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/ AWS blog post}
|
|
290
|
+
* {@link https://docs.aws.amazon.com/lambda/latest/dg/config-rs-write-functions.html AWS documentation}
|
|
291
|
+
*
|
|
292
|
+
* @example <caption>Writing to the response stream</caption>
|
|
293
|
+
* import 'aws-lambda';
|
|
294
|
+
*
|
|
295
|
+
* export const handler = awslambda.streamifyResponse(
|
|
296
|
+
* async (event, responseStream, context) => {
|
|
297
|
+
* responseStream.setContentType("text/plain");
|
|
298
|
+
* responseStream.write("Hello, world!");
|
|
299
|
+
* responseStream.end();
|
|
300
|
+
* }
|
|
301
|
+
* );
|
|
302
|
+
*
|
|
303
|
+
* @example <caption>Using pipeline</caption>
|
|
304
|
+
* import 'aws-lambda';
|
|
305
|
+
* import { Readable } from 'stream';
|
|
306
|
+
* import { pipeline } from 'stream/promises';
|
|
307
|
+
* import zlib from 'zlib';
|
|
308
|
+
*
|
|
309
|
+
* export const handler = awslambda.streamifyResponse(
|
|
310
|
+
* async (event, responseStream, context) => {
|
|
311
|
+
* // As an example, convert event to a readable stream.
|
|
312
|
+
* const requestStream = Readable.from(Buffer.from(JSON.stringify(event)));
|
|
313
|
+
*
|
|
314
|
+
* await pipeline(requestStream, zlib.createGzip(), responseStream);
|
|
315
|
+
* }
|
|
316
|
+
* );
|
|
317
|
+
*/
|
|
318
|
+
function streamifyResponse<TEvent = any, TResult = void>(handler: StreamifyHandler<TEvent, TResult>): StreamifyHandler<TEvent, TResult>;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
//#endregion
|
|
322
|
+
//#region node_modules/.pnpm/@types+aws-lambda@8.10.162/node_modules/@types/aws-lambda/trigger/alb.d.ts
|
|
323
|
+
type ALBHandler = Handler<ALBEvent, ALBResult>;
|
|
324
|
+
// https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html
|
|
325
|
+
interface ALBEventRequestContext {
|
|
326
|
+
elb: {
|
|
327
|
+
targetGroupArn: string;
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
interface ALBEventQueryStringParameters {
|
|
331
|
+
[name: string]: string | undefined;
|
|
332
|
+
}
|
|
333
|
+
interface ALBEventHeaders {
|
|
334
|
+
[name: string]: string | undefined;
|
|
335
|
+
}
|
|
336
|
+
interface ALBEventMultiValueHeaders {
|
|
337
|
+
[name: string]: string[] | undefined;
|
|
338
|
+
}
|
|
339
|
+
interface ALBEventMultiValueQueryStringParameters {
|
|
340
|
+
[name: string]: string[] | undefined;
|
|
341
|
+
}
|
|
342
|
+
interface ALBEvent {
|
|
343
|
+
requestContext: ALBEventRequestContext;
|
|
344
|
+
httpMethod: string;
|
|
345
|
+
path: string;
|
|
346
|
+
queryStringParameters?: ALBEventQueryStringParameters | undefined; // URL encoded
|
|
347
|
+
headers?: ALBEventHeaders | undefined;
|
|
348
|
+
multiValueQueryStringParameters?: ALBEventMultiValueQueryStringParameters | undefined; // URL encoded
|
|
349
|
+
multiValueHeaders?: ALBEventMultiValueHeaders | undefined;
|
|
350
|
+
body: string | null;
|
|
351
|
+
isBase64Encoded: boolean;
|
|
352
|
+
}
|
|
353
|
+
interface ALBResult {
|
|
354
|
+
statusCode: number;
|
|
355
|
+
statusDescription?: string | undefined;
|
|
356
|
+
headers?: {
|
|
357
|
+
[header: string]: boolean | number | string;
|
|
358
|
+
} | undefined;
|
|
359
|
+
multiValueHeaders?: {
|
|
360
|
+
[header: string]: Array<boolean | number | string>;
|
|
361
|
+
} | undefined;
|
|
362
|
+
body?: string | undefined;
|
|
363
|
+
isBase64Encoded?: boolean | undefined;
|
|
364
|
+
}
|
|
365
|
+
//#endregion
|
|
366
|
+
//#region node_modules/.pnpm/@types+aws-lambda@8.10.162/node_modules/@types/aws-lambda/trigger/api-gateway-proxy.d.ts
|
|
367
|
+
/**
|
|
368
|
+
* Works with Lambda Proxy Integration for Rest API or HTTP API integration Payload Format version 1.0
|
|
369
|
+
* @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
370
|
+
*/
|
|
371
|
+
type APIGatewayProxyHandler = Handler<APIGatewayProxyEvent, APIGatewayProxyResult>;
|
|
372
|
+
/**
|
|
373
|
+
* Works with HTTP API integration Payload Format version 2.0
|
|
374
|
+
* @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
375
|
+
*/
|
|
376
|
+
type APIGatewayProxyHandlerV2<T = never> = Handler<APIGatewayProxyEventV2, APIGatewayProxyResultV2<T>>;
|
|
377
|
+
/**
|
|
378
|
+
* Works with Lambda Proxy Integration for Rest API or HTTP API integration Payload Format version 1.0
|
|
379
|
+
* @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
380
|
+
*/
|
|
381
|
+
type APIGatewayProxyEvent = APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
|
|
382
|
+
interface APIGatewayProxyEventHeaders {
|
|
383
|
+
[name: string]: string | undefined;
|
|
384
|
+
}
|
|
385
|
+
interface APIGatewayProxyEventMultiValueHeaders {
|
|
386
|
+
[name: string]: string[] | undefined;
|
|
387
|
+
}
|
|
388
|
+
interface APIGatewayProxyEventPathParameters {
|
|
389
|
+
[name: string]: string | undefined;
|
|
390
|
+
}
|
|
391
|
+
interface APIGatewayProxyEventQueryStringParameters {
|
|
392
|
+
[name: string]: string | undefined;
|
|
393
|
+
}
|
|
394
|
+
interface APIGatewayProxyEventMultiValueQueryStringParameters {
|
|
395
|
+
[name: string]: string[] | undefined;
|
|
396
|
+
}
|
|
397
|
+
interface APIGatewayProxyEventStageVariables {
|
|
398
|
+
[name: string]: string | undefined;
|
|
399
|
+
}
|
|
400
|
+
interface APIGatewayProxyEventBase<TAuthorizerContext> {
|
|
401
|
+
body: string | null;
|
|
402
|
+
headers: APIGatewayProxyEventHeaders;
|
|
403
|
+
multiValueHeaders: APIGatewayProxyEventMultiValueHeaders;
|
|
404
|
+
httpMethod: string;
|
|
405
|
+
isBase64Encoded: boolean;
|
|
406
|
+
path: string;
|
|
407
|
+
pathParameters: APIGatewayProxyEventPathParameters | null;
|
|
408
|
+
queryStringParameters: APIGatewayProxyEventQueryStringParameters | null;
|
|
409
|
+
multiValueQueryStringParameters: APIGatewayProxyEventMultiValueQueryStringParameters | null;
|
|
410
|
+
stageVariables: APIGatewayProxyEventStageVariables | null;
|
|
411
|
+
requestContext: APIGatewayEventRequestContextWithAuthorizer<TAuthorizerContext>;
|
|
412
|
+
resource: string;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Works with Lambda Proxy Integration for Rest API or HTTP API integration Payload Format version 1.0
|
|
416
|
+
* @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
417
|
+
*/
|
|
418
|
+
interface APIGatewayProxyResult {
|
|
419
|
+
statusCode: number;
|
|
420
|
+
headers?: {
|
|
421
|
+
[header: string]: boolean | number | string;
|
|
422
|
+
} | undefined;
|
|
423
|
+
multiValueHeaders?: {
|
|
424
|
+
[header: string]: Array<boolean | number | string>;
|
|
425
|
+
} | undefined;
|
|
426
|
+
body: string;
|
|
427
|
+
isBase64Encoded?: boolean | undefined;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Works with HTTP API integration Payload Format version 2.0
|
|
431
|
+
* @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
432
|
+
*/
|
|
433
|
+
interface APIGatewayEventRequestContextV2 {
|
|
434
|
+
accountId: string;
|
|
435
|
+
apiId: string;
|
|
436
|
+
authentication?: {
|
|
437
|
+
clientCert: APIGatewayEventClientCertificate;
|
|
438
|
+
};
|
|
439
|
+
domainName: string;
|
|
440
|
+
domainPrefix: string;
|
|
441
|
+
http: {
|
|
442
|
+
method: string;
|
|
443
|
+
path: string;
|
|
444
|
+
protocol: string;
|
|
445
|
+
sourceIp: string;
|
|
446
|
+
userAgent: string;
|
|
447
|
+
};
|
|
448
|
+
requestId: string;
|
|
449
|
+
routeKey: string;
|
|
450
|
+
stage: string;
|
|
451
|
+
time: string;
|
|
452
|
+
timeEpoch: number;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Proxy Event with adaptable requestContext for different authorizer scenarios
|
|
456
|
+
*/
|
|
457
|
+
interface APIGatewayProxyEventV2WithRequestContext<TRequestContext> {
|
|
458
|
+
version: string;
|
|
459
|
+
routeKey: string;
|
|
460
|
+
rawPath: string;
|
|
461
|
+
rawQueryString: string;
|
|
462
|
+
cookies?: string[];
|
|
463
|
+
headers: APIGatewayProxyEventHeaders;
|
|
464
|
+
queryStringParameters?: APIGatewayProxyEventQueryStringParameters;
|
|
465
|
+
requestContext: TRequestContext;
|
|
466
|
+
body?: string;
|
|
467
|
+
pathParameters?: APIGatewayProxyEventPathParameters;
|
|
468
|
+
isBase64Encoded: boolean;
|
|
469
|
+
stageVariables?: APIGatewayProxyEventStageVariables;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Default Proxy event with no Authorizer
|
|
473
|
+
*/
|
|
474
|
+
type APIGatewayProxyEventV2 = APIGatewayProxyEventV2WithRequestContext<APIGatewayEventRequestContextV2>;
|
|
475
|
+
/**
|
|
476
|
+
* Works with HTTP API integration Payload Format version 2.0
|
|
477
|
+
* @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
478
|
+
*/
|
|
479
|
+
type APIGatewayProxyResultV2<T = never> = APIGatewayProxyStructuredResultV2 | string | T;
|
|
480
|
+
/**
|
|
481
|
+
* Interface for structured response with `statusCode` and`headers`
|
|
482
|
+
* Works with HTTP API integration Payload Format version 2.0
|
|
483
|
+
* @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
484
|
+
*/
|
|
485
|
+
interface APIGatewayProxyStructuredResultV2 {
|
|
486
|
+
statusCode?: number | undefined;
|
|
487
|
+
headers?: {
|
|
488
|
+
[header: string]: boolean | number | string;
|
|
489
|
+
} | undefined;
|
|
490
|
+
body?: string | undefined;
|
|
491
|
+
isBase64Encoded?: boolean | undefined;
|
|
492
|
+
cookies?: string[] | undefined;
|
|
493
|
+
}
|
|
494
|
+
//#endregion
|
|
495
|
+
//#region node_modules/.pnpm/@types+aws-lambda@8.10.162/node_modules/@types/aws-lambda/trigger/lambda-function-url.d.ts
|
|
496
|
+
/**
|
|
497
|
+
* Default Lambda Function URL event with no Authorizer
|
|
498
|
+
*/
|
|
499
|
+
type LambdaFunctionURLEvent = APIGatewayProxyEventV2;
|
|
500
|
+
/**
|
|
501
|
+
* Works with Lambda Function URL format which is currently the same as HTTP API integration Payload Format version 2.0
|
|
502
|
+
* @see - https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html#urls-payloads
|
|
503
|
+
*/
|
|
504
|
+
type LambdaFunctionURLResult<T = never> = APIGatewayProxyResultV2<T>;
|
|
505
|
+
/**
|
|
506
|
+
* Works with Lambda Function URL format which is currently the same as HTTP API integration Payload Format version 2.0
|
|
507
|
+
* @see - https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html#urls-payloads
|
|
508
|
+
*/
|
|
509
|
+
type LambdaFunctionURLHandler<T = never> = Handler<LambdaFunctionURLEvent, LambdaFunctionURLResult<T>>;
|
|
510
|
+
//#endregion
|
|
511
|
+
//#region src/adapters/index.d.ts
|
|
512
|
+
/**
|
|
513
|
+
* Resolves the raw host for the request URL from a Lambda event.
|
|
514
|
+
*
|
|
515
|
+
* Return `undefined`/`null` to fall back to the adapter default (the
|
|
516
|
+
* `x-forwarded-host` header, falling back to the `host`/`Host` header). The
|
|
517
|
+
* returned value is sanitized via {@link resolveHost} before use.
|
|
518
|
+
*/
|
|
519
|
+
type GetHostFunction<E> = (event: E) => string | null | undefined;
|
|
520
|
+
interface ReactRouterAdapter<E, Ret, Res = void, H = Handler<E, Ret>> {
|
|
521
|
+
wrapHandler: (handler: (event: E, res: Res) => Promise<Ret>) => H;
|
|
522
|
+
createReactRouterRequest: (event: E, getHost?: GetHostFunction<E>) => Request;
|
|
523
|
+
sendReactRouterResponse: (nodeResponse: Response, response: Res) => Promise<Ret>;
|
|
524
|
+
}
|
|
525
|
+
//#endregion
|
|
526
|
+
//#region src/server.d.ts
|
|
5
527
|
type MaybePromise<T> = T | Promise<T>;
|
|
6
528
|
/**
|
|
7
529
|
* A function that returns the value to use as `context` in route `loader` and
|
|
@@ -12,9 +534,46 @@ type MaybePromise<T> = T | Promise<T>;
|
|
|
12
534
|
*/
|
|
13
535
|
type GetLoadContextFunction<E> = (event: E) => UNSAFE_MiddlewareEnabled extends true ? MaybePromise<RouterContextProvider> : MaybePromise<AppLoadContext>;
|
|
14
536
|
type CreateRequestHandlerArgs<T> = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
537
|
+
build: ServerBuild;
|
|
538
|
+
getLoadContext?: GetLoadContextFunction<T>;
|
|
539
|
+
mode?: string;
|
|
540
|
+
/**
|
|
541
|
+
* Override how the host for the request URL is derived from the Lambda event.
|
|
542
|
+
*
|
|
543
|
+
* React Router uses the request URL host (`new URL(request.url).host`) for its
|
|
544
|
+
* built-in cross-origin (CSRF) check on action requests, comparing it against
|
|
545
|
+
* the incoming `Origin` header. The returned value is sanitized (invalid
|
|
546
|
+
* characters stripped, port validated) before use.
|
|
547
|
+
*
|
|
548
|
+
* Return `undefined`/`null` to fall back to the default: the
|
|
549
|
+
* `x-forwarded-host` header (falling back to the `host`/`Host` header).
|
|
550
|
+
*
|
|
551
|
+
* Use this when the default forwarded host is not the host the browser sees.
|
|
552
|
+
* For example, a Lambda Function URL behind CloudFront cannot use its
|
|
553
|
+
* request-context domain name (always the internal `*.lambda-url` host), and
|
|
554
|
+
* CloudFront does not forward the viewer host by default. Forward it yourself
|
|
555
|
+
* (e.g. a CloudFront Function copying the viewer `Host` into a custom header)
|
|
556
|
+
* and read that header here:
|
|
557
|
+
*
|
|
558
|
+
* ```ts
|
|
559
|
+
* createFunctionURLRequestHandler({
|
|
560
|
+
* build,
|
|
561
|
+
* getHost: (event) => event.headers["x-viewer-host"],
|
|
562
|
+
* });
|
|
563
|
+
* ```
|
|
564
|
+
*
|
|
565
|
+
* @remarks
|
|
566
|
+
* The default currently uses the `x-forwarded-host` header, which is
|
|
567
|
+
* client-controlled and can be spoofed. Because that host drives the CSRF
|
|
568
|
+
* check, trusting it should be deliberate: the default will change to the
|
|
569
|
+
* AWS-provided, non-spoofable request-context domain name
|
|
570
|
+
* (`event.requestContext.domainName`) in the next major version (aligning with
|
|
571
|
+
* the upstream `@react-router/architect` adapter), after which relying on a
|
|
572
|
+
* forwarded header becomes an explicit opt-in via `getHost`. Setups where the
|
|
573
|
+
* request-context host is not the browser-facing host (e.g. Function URLs
|
|
574
|
+
* behind CloudFront) must set `getHost`.
|
|
575
|
+
*/
|
|
576
|
+
getHost?: GetHostFunction<T>;
|
|
18
577
|
};
|
|
19
578
|
/**
|
|
20
579
|
* Returns a request handler for AWS API Gateway V1
|
|
@@ -60,27 +619,26 @@ declare function createFunctionURLRequestHandler(options: CreateRequestHandlerAr
|
|
|
60
619
|
* @returns A streaming AWS Lambda Function URL handler compatible with Lambda Function URLs with InvokeMode RESPONSE_STREAM.
|
|
61
620
|
*/
|
|
62
621
|
declare function createFunctionURLStreamingRequestHandler(options: CreateRequestHandlerArgs<LambdaFunctionURLEvent>): StreamifyHandler<LambdaFunctionURLEvent, void>;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
wrapHandler: (handler: (event: E, res: Res) => Promise<Ret>) => H;
|
|
66
|
-
createReactRouterRequest: (event: E) => Request;
|
|
67
|
-
sendReactRouterResponse: (nodeResponse: Response, response: Res) => Promise<Ret>;
|
|
68
|
-
}
|
|
69
|
-
|
|
622
|
+
//#endregion
|
|
623
|
+
//#region src/adapters/api-gateway-v1.d.ts
|
|
70
624
|
type ApiGatewayV1Adapter = ReactRouterAdapter<APIGatewayProxyEvent, APIGatewayProxyResult>;
|
|
71
|
-
|
|
625
|
+
//#endregion
|
|
626
|
+
//#region src/adapters/api-gateway-v2.d.ts
|
|
72
627
|
type ApiGatewayV2Adapter = ReactRouterAdapter<APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2>;
|
|
73
|
-
|
|
628
|
+
//#endregion
|
|
629
|
+
//#region src/adapters/application-load-balancer.d.ts
|
|
74
630
|
type ApplicationLoadBalancerAdapter = ReactRouterAdapter<ALBEvent, ALBResult>;
|
|
75
|
-
|
|
631
|
+
//#endregion
|
|
632
|
+
//#region src/adapters/function-url-streaming.d.ts
|
|
76
633
|
type FunctionUrlStreamingAdapter = ReactRouterAdapter<LambdaFunctionURLEvent, void, awslambda.HttpResponseStream, StreamifyHandler<LambdaFunctionURLEvent, void>>;
|
|
77
|
-
|
|
634
|
+
//#endregion
|
|
635
|
+
//#region src/legacy.d.ts
|
|
78
636
|
declare enum AWSProxy {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
637
|
+
APIGatewayV1 = "APIGatewayV1",
|
|
638
|
+
APIGatewayV2 = "APIGatewayV2",
|
|
639
|
+
ALB = "ALB",
|
|
640
|
+
FunctionURL = "FunctionURL",
|
|
641
|
+
FunctionURLStreaming = "FunctionURLStreaming"
|
|
84
642
|
}
|
|
85
643
|
type InferAdapter<T extends AWSProxy> = T extends AWSProxy.APIGatewayV1 ? ApiGatewayV1Adapter : T extends AWSProxy.APIGatewayV2 | AWSProxy.FunctionURL ? ApiGatewayV2Adapter : T extends AWSProxy.ALB ? ApplicationLoadBalancerAdapter : T extends AWSProxy.FunctionURLStreaming ? FunctionUrlStreamingAdapter : never;
|
|
86
644
|
type InferEventType<T extends AWSProxy> = InferAdapter<T> extends ReactRouterAdapter<infer E, any, any, any> ? E : never;
|
|
@@ -96,7 +654,8 @@ type InferHandlerType<T extends AWSProxy> = InferAdapter<T> extends ReactRouterA
|
|
|
96
654
|
* - `createFunctionURLStreamingRequestHandler`
|
|
97
655
|
*/
|
|
98
656
|
declare function createRequestHandler<T extends AWSProxy>(options: CreateRequestHandlerArgs<InferEventType<T>> & {
|
|
99
|
-
|
|
657
|
+
awsProxy?: T;
|
|
100
658
|
}): InferHandlerType<T>;
|
|
101
|
-
|
|
659
|
+
//#endregion
|
|
102
660
|
export { AWSProxy, type GetLoadContextFunction, createALBRequestHandler, createAPIGatewayV1RequestHandler, createAPIGatewayV2RequestHandler, createFunctionURLRequestHandler, createFunctionURLStreamingRequestHandler, createRequestHandler };
|
|
661
|
+
//# sourceMappingURL=index.d.mts.map
|