/** * @geostrategists/react-router-aws v3.0.0 * * Copyright (c) Geostrategists Consulting GmbH * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @license MIT */ import { Writable } from "node:stream"; import { RouterContextProvider, ServerBuild } from "react-router"; //#region node_modules/.pnpm/@types+aws-lambda@8.10.162/node_modules/@types/aws-lambda/common/api-gateway.d.ts // Default authorizer type, prefer using a specific type with the "...WithAuthorizer..." variant types. // Note that this doesn't have to be a context from a custom lambda outhorizer, AWS also has a cognito // authorizer type and could add more, so the property won't always be a string. type APIGatewayEventDefaultAuthorizerContext = undefined | null | { [name: string]: any; }; // The requestContext property of both request authorizer and proxy integration events. interface APIGatewayEventRequestContextWithAuthorizer { accountId: string; apiId: string; // This one is a bit confusing: it is not actually present in authorizer calls // and proxy calls without an authorizer. We model this by allowing undefined in the type, // since it ends up the same and avoids breaking users that are testing the property. // This lets us allow parameterizing the authorizer for proxy events that know what authorizer // context values they have. authorizer: TAuthorizerContext; connectedAt?: number | undefined; connectionId?: string | undefined; domainName?: string | undefined; domainPrefix?: string | undefined; eventType?: string | undefined; extendedRequestId?: string | undefined; protocol: string; httpMethod: string; identity: APIGatewayEventIdentity; messageDirection?: string | undefined; messageId?: string | null | undefined; path: string; stage: string; requestId: string; requestTime?: string | undefined; requestTimeEpoch: number; resourceId: string; resourcePath: string; routeKey?: string | undefined; } interface APIGatewayEventClientCertificate { clientCertPem: string; serialNumber: string; subjectDN: string; issuerDN: string; validity: { notAfter: string; notBefore: string; }; } interface APIGatewayEventIdentity { accessKey: string | null; accountId: string | null; apiKey: string | null; apiKeyId: string | null; caller: string | null; clientCert: APIGatewayEventClientCertificate | null; cognitoAuthenticationProvider: string | null; cognitoAuthenticationType: string | null; cognitoIdentityId: string | null; cognitoIdentityPoolId: string | null; principalOrgId: string | null; sourceIp: string; user: string | null; userAgent: string | null; userArn: string | null; vpcId?: string | undefined; vpceId?: string | undefined; } //#endregion //#region node_modules/.pnpm/@types+aws-lambda@8.10.162/node_modules/@types/aws-lambda/handler.d.ts /** * The interface that AWS Lambda will invoke your handler with. * There are more specialized types for many cases where AWS services * invoke your lambda, but you can directly use this type for when you are invoking * your lambda directly. * * See the {@link http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html AWS documentation} * for more information about the runtime behavior, and the * {@link https://aws.amazon.com/blogs/compute/node-js-8-10-runtime-now-available-in-aws-lambda/ AWS Blog post} * introducing the async handler behavior in the 8.10 runtime. * * @example Defining a custom handler type * import { Handler } from 'aws-lambda' * * interface NameEvent { * fullName: string * } * interface NameResult { * firstName: string * middleNames: string * lastName: string * } * type PersonHandler = Handler * * export const handler: PersonHandler = async (event) => { * const names = event.fullName.split(' ') * const firstName = names.shift() * const lastName = names.pop() * return { firstName, middleNames: names, lastName } * } * * @example Logs the contents of the event object and returns the location of the logs * import { Handler } from 'aws-lambda' * * export const handler: Handler = async (event, context) => { * console.log("EVENT: \n" + JSON.stringify(event, null, 2)) * return context.logStreamName * } * * @example AWS SDK with Async Function and Promises * import { Handler } from 'aws-lambda' * import AWS from 'aws-sdk' * * const s3 = new AWS.S3() * * export const handler: Handler = async (event) => { * const response = await s3.listBuckets().promise() * return response?.Buckets.map((bucket) => bucket.Name) * } * * @example HTTP Request with Callback * import { Handler } from 'aws-lambda' * import https from 'https' * * let url = "https://docs.aws.amazon.com/lambda/latest/dg/welcome.html" * * export const handler: Handler = (event, context, callback) => { * https.get(url, (res) => { * callback(null, res.statusCode) * }).on('error', (e) => { * callback(Error(e)) * }) * } * * @param event * Parsed JSON data in the lambda request payload. For an AWS service triggered * lambda this should be in the format of a type ending in Event, for example the * S3Handler receives an event of type S3Event. * @param context * Runtime contextual information of the current invocation, for example the caller * identity, available memory and time remaining, legacy completion callbacks, and * a mutable property controlling when the lambda execution completes. * @param callback * NodeJS-style completion callback that the AWS Lambda runtime will provide that can * be used to provide the lambda result payload value, or any execution error. Can * instead return a promise that resolves with the result payload value or rejects * with the execution error. * @return * A promise that resolves with the lambda result payload value, or rejects with the * execution error. Note that if you implement your handler as an async function, * you will automatically return a promise that will resolve with a returned value, * or reject with a thrown value. */ type Handler = (event: TEvent, context: Context, callback: Callback) => void | Promise // eslint-disable-next-line @typescript-eslint/no-invalid-void-type ; /** * {@link Handler} context parameter. * See {@link https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html AWS documentation}. */ interface Context { callbackWaitsForEmptyEventLoop: boolean; functionName: string; functionVersion: string; invokedFunctionArn: string; memoryLimitInMB: string; awsRequestId: string; logGroupName: string; logStreamName: string; identity?: CognitoIdentity | undefined; clientContext?: ClientContext | undefined; tenantId?: string | undefined; getRemainingTimeInMillis(): number; // Functions for compatibility with earlier Node.js Runtime v0.10.42 // No longer documented, so they are deprecated, but they still work // as of the 12.x runtime, so they are not removed from the types. /** @deprecated Use handler callback or promise result */ done(error?: Error, result?: any): void; /** @deprecated Use handler callback with first argument or reject a promise result */ fail(error: Error | string): void; /** @deprecated Use handler callback with second argument or resolve a promise result */ succeed(messageOrObject: any): void; // Unclear what behavior this is supposed to have, I couldn't find any still extant reference, // and it behaves like the above, ignoring the object parameter. /** @deprecated Use handler callback or promise result */ succeed(message: string, object: any): void; } interface CognitoIdentity { cognitoIdentityId: string; cognitoIdentityPoolId: string; } interface ClientContext { client: ClientContextClient; custom?: any; env: ClientContextEnv; } interface ClientContextClient { installationId: string; appTitle: string; appVersionName: string; appVersionCode: string; appPackageName: string; } interface ClientContextEnv { platformVersion: string; platform: string; make: string; model: string; locale: string; } /** * NodeJS-style callback parameter for the {@link Handler} type. * Can be used instead of returning a promise, see the * {@link https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html AWS documentation} * for the handler programming model. * * @param error * Parameter to use to provide the error payload for a failed lambda execution. * See {@link https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-mode-exceptions.html AWS documentation} * for error handling. * If an Error instance is passed, the error payload uses the `name` property as the `errorType`, * the `message` property as the `errorMessage`, and parses the `stack` property string into * the `trace` array. * For other values, the `errorType` is `typeof value`, the `errorMessage` is `String(value)`, and * `trace` is an empty array. * * @param result * Parameter to use to provide the result payload for a successful lambda execution. * Pass `null` or `undefined` for the `error` parameter to use this parameter. */ type Callback = (error?: Error | string | null, result?: TResult) => void; /** * Interface for using response streaming from AWS Lambda. * To indicate to the runtime that Lambda should stream your function’s responses, you must wrap your function handler with the `awslambda.streamifyResponse()` decorator. * * The `streamifyResponse` decorator accepts the following additional parameter, `responseStream`, besides the default node handler parameters, `event`, and `context`. * 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. * * {@link https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/ AWS blog post} * {@link https://docs.aws.amazon.com/lambda/latest/dg/config-rs-write-functions.html AWS documentation} * * @example Writing to the response stream * import 'aws-lambda'; * * export const handler = awslambda.streamifyResponse( * async (event, responseStream, context) => { * responseStream.setContentType("text/plain"); * responseStream.write("Hello, world!"); * responseStream.end(); * } * ); * * @example Using pipeline * import 'aws-lambda'; * import { Readable } from 'stream'; * import { pipeline } from 'stream/promises'; * import zlib from 'zlib'; * * export const handler = awslambda.streamifyResponse( * async (event, responseStream, context) => { * // As an example, convert event to a readable stream. * const requestStream = Readable.from(Buffer.from(JSON.stringify(event))); * * await pipeline(requestStream, zlib.createGzip(), responseStream); * } * ); */ type StreamifyHandler = (event: TEvent, responseStream: awslambda.HttpResponseStream, context: Context) => TResult | Promise; declare global { namespace awslambda { class HttpResponseStream extends Writable { static from(writable: Writable, metadata: Record): HttpResponseStream; setContentType: (contentType: string) => void; } /** * Decorator for using response streaming from AWS Lambda. * To indicate to the runtime that Lambda should stream your function’s responses, you must wrap your function handler with the `awslambda.streamifyResponse()` decorator. * * The `streamifyResponse` decorator accepts the following additional parameter, `responseStream`, besides the default node handler parameters, `event`, and `context`. * 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. * * {@link https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/ AWS blog post} * {@link https://docs.aws.amazon.com/lambda/latest/dg/config-rs-write-functions.html AWS documentation} * * @example Writing to the response stream * import 'aws-lambda'; * * export const handler = awslambda.streamifyResponse( * async (event, responseStream, context) => { * responseStream.setContentType("text/plain"); * responseStream.write("Hello, world!"); * responseStream.end(); * } * ); * * @example Using pipeline * import 'aws-lambda'; * import { Readable } from 'stream'; * import { pipeline } from 'stream/promises'; * import zlib from 'zlib'; * * export const handler = awslambda.streamifyResponse( * async (event, responseStream, context) => { * // As an example, convert event to a readable stream. * const requestStream = Readable.from(Buffer.from(JSON.stringify(event))); * * await pipeline(requestStream, zlib.createGzip(), responseStream); * } * ); */ function streamifyResponse(handler: StreamifyHandler): StreamifyHandler; } } //#endregion //#region node_modules/.pnpm/@types+aws-lambda@8.10.162/node_modules/@types/aws-lambda/trigger/alb.d.ts type ALBHandler = Handler; // https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html interface ALBEventRequestContext { elb: { targetGroupArn: string; }; } interface ALBEventQueryStringParameters { [name: string]: string | undefined; } interface ALBEventHeaders { [name: string]: string | undefined; } interface ALBEventMultiValueHeaders { [name: string]: string[] | undefined; } interface ALBEventMultiValueQueryStringParameters { [name: string]: string[] | undefined; } interface ALBEvent { requestContext: ALBEventRequestContext; httpMethod: string; path: string; queryStringParameters?: ALBEventQueryStringParameters | undefined; // URL encoded headers?: ALBEventHeaders | undefined; multiValueQueryStringParameters?: ALBEventMultiValueQueryStringParameters | undefined; // URL encoded multiValueHeaders?: ALBEventMultiValueHeaders | undefined; body: string | null; isBase64Encoded: boolean; } interface ALBResult { statusCode: number; statusDescription?: string | undefined; headers?: { [header: string]: boolean | number | string; } | undefined; multiValueHeaders?: { [header: string]: Array; } | undefined; body?: string | undefined; isBase64Encoded?: boolean | undefined; } //#endregion //#region node_modules/.pnpm/@types+aws-lambda@8.10.162/node_modules/@types/aws-lambda/trigger/api-gateway-proxy.d.ts /** * Works with Lambda Proxy Integration for Rest API or HTTP API integration Payload Format version 1.0 * @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html */ type APIGatewayProxyHandler = Handler; /** * Works with HTTP API integration Payload Format version 2.0 * @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html */ type APIGatewayProxyHandlerV2 = Handler>; /** * Works with Lambda Proxy Integration for Rest API or HTTP API integration Payload Format version 1.0 * @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html */ type APIGatewayProxyEvent = APIGatewayProxyEventBase; interface APIGatewayProxyEventHeaders { [name: string]: string | undefined; } interface APIGatewayProxyEventMultiValueHeaders { [name: string]: string[] | undefined; } interface APIGatewayProxyEventPathParameters { [name: string]: string | undefined; } interface APIGatewayProxyEventQueryStringParameters { [name: string]: string | undefined; } interface APIGatewayProxyEventMultiValueQueryStringParameters { [name: string]: string[] | undefined; } interface APIGatewayProxyEventStageVariables { [name: string]: string | undefined; } interface APIGatewayProxyEventBase { body: string | null; headers: APIGatewayProxyEventHeaders; multiValueHeaders: APIGatewayProxyEventMultiValueHeaders; httpMethod: string; isBase64Encoded: boolean; path: string; pathParameters: APIGatewayProxyEventPathParameters | null; queryStringParameters: APIGatewayProxyEventQueryStringParameters | null; multiValueQueryStringParameters: APIGatewayProxyEventMultiValueQueryStringParameters | null; stageVariables: APIGatewayProxyEventStageVariables | null; requestContext: APIGatewayEventRequestContextWithAuthorizer; resource: string; } /** * Works with Lambda Proxy Integration for Rest API or HTTP API integration Payload Format version 1.0 * @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html */ interface APIGatewayProxyResult { statusCode: number; headers?: { [header: string]: boolean | number | string; } | undefined; multiValueHeaders?: { [header: string]: Array; } | undefined; body: string; isBase64Encoded?: boolean | undefined; } /** * Works with HTTP API integration Payload Format version 2.0 * @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html */ interface APIGatewayEventRequestContextV2 { accountId: string; apiId: string; authentication?: { clientCert: APIGatewayEventClientCertificate; }; domainName: string; domainPrefix: string; http: { method: string; path: string; protocol: string; sourceIp: string; userAgent: string; }; requestId: string; routeKey: string; stage: string; time: string; timeEpoch: number; } /** * Proxy Event with adaptable requestContext for different authorizer scenarios */ interface APIGatewayProxyEventV2WithRequestContext { version: string; routeKey: string; rawPath: string; rawQueryString: string; cookies?: string[]; headers: APIGatewayProxyEventHeaders; queryStringParameters?: APIGatewayProxyEventQueryStringParameters; requestContext: TRequestContext; body?: string; pathParameters?: APIGatewayProxyEventPathParameters; isBase64Encoded: boolean; stageVariables?: APIGatewayProxyEventStageVariables; } /** * Default Proxy event with no Authorizer */ type APIGatewayProxyEventV2 = APIGatewayProxyEventV2WithRequestContext; /** * Works with HTTP API integration Payload Format version 2.0 * @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html */ type APIGatewayProxyResultV2 = APIGatewayProxyStructuredResultV2 | string | T; /** * Interface for structured response with `statusCode` and`headers` * Works with HTTP API integration Payload Format version 2.0 * @see - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html */ interface APIGatewayProxyStructuredResultV2 { statusCode?: number | undefined; headers?: { [header: string]: boolean | number | string; } | undefined; body?: string | undefined; isBase64Encoded?: boolean | undefined; cookies?: string[] | undefined; } //#endregion //#region node_modules/.pnpm/@types+aws-lambda@8.10.162/node_modules/@types/aws-lambda/trigger/lambda-function-url.d.ts /** * Default Lambda Function URL event with no Authorizer */ type LambdaFunctionURLEvent = APIGatewayProxyEventV2; /** * Works with Lambda Function URL format which is currently the same as HTTP API integration Payload Format version 2.0 * @see - https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html#urls-payloads */ type LambdaFunctionURLResult = APIGatewayProxyResultV2; /** * Works with Lambda Function URL format which is currently the same as HTTP API integration Payload Format version 2.0 * @see - https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html#urls-payloads */ type LambdaFunctionURLHandler = Handler>; //#endregion //#region src/adapters/index.d.ts /** * Resolves the raw host for the request URL from a Lambda event. * * Return `undefined`/`null` to fall back to the adapter default: the * request-context domain name (`event.requestContext.domainName`) for API * Gateway / Function URL events, and the `Host` header for ALB. The returned * value is sanitized via {@link resolveHost} before use. */ type GetHostFunction = (event: E) => string | null | undefined; //#endregion //#region src/server.d.ts type MaybePromise = T | Promise; /** * A function that returns the value to use as `context` in route `loader` and * `action` functions. * * You can think of this as an escape hatch that allows you to pass * environment/platform-specific values through to your loader/action. */ type GetLoadContextFunction = (event: E) => MaybePromise; type CreateRequestHandlerArgs = { build: ServerBuild; getLoadContext?: GetLoadContextFunction; mode?: string; /** * Override how the host for the request URL is derived from the Lambda event. * * React Router uses the request URL host (`new URL(request.url).host`) for its * built-in cross-origin (CSRF) check on action requests, comparing it against * the incoming `Origin` header. The returned value is sanitized (invalid * characters stripped, port validated) before use. * * Return `undefined`/`null` to fall back to the default: the AWS-provided, * non-spoofable request-context domain name (`event.requestContext.domainName`) * for API Gateway v1/v2 and Lambda Function URLs, and the `Host` header for * ALB (which has no request-context domain name). * * Use this when the default host is not the host the browser sees. Two common * cases: * * - To trust a forwarded header (e.g. `x-forwarded-host`) instead of the * request-context domain name — only safe if your proxy infrastructure sets * it and strips any incoming value: * * ```ts * createAPIGatewayV2RequestHandler({ * build, * getHost: (event) => event.headers["x-forwarded-host"], * }); * ``` * * - A Lambda Function URL behind CloudFront: `event.requestContext.domainName` * is always the internal `*.lambda-url` host, and CloudFront does not forward * the viewer host by default. Forward it yourself (e.g. a CloudFront Function * copying the viewer `Host` into a custom header) and read that header here: * * ```ts * createFunctionURLRequestHandler({ * build, * getHost: (event) => event.headers["x-viewer-host"], * }); * ``` */ getHost?: GetHostFunction; }; /** * Returns a request handler for AWS API Gateway V1 * */ /** * Returns a request handler for AWS API Gateway V1 events. * * @param options - The handler options, including the React Router server build, * optional getLoadContext function, and mode string. * @returns An AWS API Gateway V1 handler compatible with APIGatewayProxyHandler. */ declare function createAPIGatewayV1RequestHandler(options: CreateRequestHandlerArgs): APIGatewayProxyHandler; /** * Returns a request handler for AWS API Gateway V2 events. * * @param options - The handler options, including the React Router server build, * optional getLoadContext function, and mode string. * @returns An AWS API Gateway V2 handler compatible with APIGatewayProxyHandlerV2. */ declare function createAPIGatewayV2RequestHandler(options: CreateRequestHandlerArgs): APIGatewayProxyHandlerV2; /** * Returns a request handler for AWS Application Load Balancer events. * * @param options - The handler options, including the React Router server build, * optional getLoadContext function, and mode string. * @returns An AWS ALB handler compatible with ALBHandler. */ declare function createALBRequestHandler(options: CreateRequestHandlerArgs): ALBHandler; /** * Returns a request handler for AWS Lambda Function URL events (invoke mode BUFFERED). * * @param options - The handler options, including the React Router server build, * optional getLoadContext function, and mode string. * @returns An AWS Lambda Function URL handler compatible with Lambda Function URLs with InvokeMode BUFFERED. */ declare function createFunctionURLRequestHandler(options: CreateRequestHandlerArgs): LambdaFunctionURLHandler; /** * Returns a request handler for AWS Lambda Function URL events (invoke mode RESPONSE_STREAM). * * @param options - The handler options, including the React Router server build, * optional getLoadContext function, and mode string. * @returns A streaming AWS Lambda Function URL handler compatible with Lambda Function URLs with InvokeMode RESPONSE_STREAM. */ declare function createFunctionURLStreamingRequestHandler(options: CreateRequestHandlerArgs): StreamifyHandler; //#endregion export { type GetLoadContextFunction, createALBRequestHandler, createAPIGatewayV1RequestHandler, createAPIGatewayV2RequestHandler, createFunctionURLRequestHandler, createFunctionURLStreamingRequestHandler }; //# sourceMappingURL=index.d.cts.map