@aws-lambda-powertools/parser
Version:
The parser package for the Powertools for AWS Lambda (TypeScript) library.
99 lines (98 loc) • 3.65 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.APIGatewayProxyWebsocketEventSchema = void 0;
const zod_1 = require("zod");
const apigw_proxy_js_1 = require("./apigw-proxy.js");
/**
* A zod schema for API Gateway Proxy WebSocket events.
*
* @example
* ```json
* {
* "type": "REQUEST",
* "methodArn": "arn:aws:execute-api:us-east-1:123456789012:abcdef123/default/$connect",
* "headers": {
* "Connection": "upgrade",
* "content-length": "0",
* "HeaderAuth1": "headerValue1",
* "Host": "abcdef123.execute-api.us-east-1.amazonaws.com",
* "Sec-WebSocket-Extensions": "permessage-deflate; client_max_window_bits",
* "Sec-WebSocket-Key": "...",
* "Sec-WebSocket-Version": "13",
* "Upgrade": "websocket",
* "X-Amzn-Trace-Id": "..."
* },
* "multiValueHeaders": {
* "Connection": [ "upgrade" ],
* "content-length": [ "0" ],
* "HeaderAuth1": [ "headerValue1" ],
* "Host": [ "abcdef123.execute-api.us-east-1.amazonaws.com" ],
* "Sec-WebSocket-Extensions": [ "permessage-deflate; client_max_window_bits" ],
* "Sec-WebSocket-Key": [ "..." ],
* "Sec-WebSocket-Version": [ "13" ],
* "Upgrade": [ "websocket" ],
* "X-Amzn-Trace-Id": [ "..." ]
* },
* "queryStringParameters": {
* "QueryString1": "queryValue1"
* },
* "multiValueQueryStringParameters": {
* "QueryString1": [ "queryValue1" ]
* },
* "stageVariables": {},
* "requestContext": {
* "routeKey": "$connect",
* "eventType": "CONNECT",
* "extendedRequestId": "...",
* "requestTime": "19/Jan/2023:21:13:26 +0000",
* "messageDirection": "IN",
* "stage": "default",
* "connectedAt": 1674162806344,
* "requestTimeEpoch": 1674162806345,
* "identity": {
* "sourceIp": "..."
* },
* "requestId": "...",
* "domainName": "abcdef123.execute-api.us-east-1.amazonaws.com",
* "connectionId": "...",
* "apiId": "abcdef123"
* },
* "isBase64Encoded": false,
* "body": null
* }
* ```
*
* @see {@link APIGatewayProxyWebsocketEvent | `APIGatewayProxyWebsocketEvent`}
* @see {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/websocket-api-develop-integrations.html}
*/
exports.APIGatewayProxyWebsocketEventSchema = zod_1.z.object({
type: zod_1.z.string(),
methodArn: zod_1.z.string(),
headers: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).nullish(),
multiValueHeaders: zod_1.z.record(zod_1.z.string(), apigw_proxy_js_1.APIGatewayStringArray),
queryStringParameters: apigw_proxy_js_1.APIGatewayRecord.nullable(),
multiValueQueryStringParameters: zod_1.z
.record(zod_1.z.string(), apigw_proxy_js_1.APIGatewayStringArray)
.nullable(),
stageVariables: apigw_proxy_js_1.APIGatewayRecord.nullable().optional(),
requestContext: zod_1.z.object({
routeKey: zod_1.z.string(),
eventType: zod_1.z.enum(['CONNECT', 'DISCONNECT', 'MESSAGE']),
extendedRequestId: zod_1.z.string(),
requestTime: zod_1.z.string(),
messageDirection: zod_1.z.enum(['IN', 'OUT']),
stage: zod_1.z.string(),
connectedAt: zod_1.z.number(),
requestTimeEpoch: zod_1.z.number(),
identity: zod_1.z.object({
sourceIp: zod_1.z.string(),
userAgent: zod_1.z.string().optional(),
}),
requestId: zod_1.z.string(),
domainName: zod_1.z.string(),
connectionId: zod_1.z.string(),
apiId: zod_1.z.string(),
}),
isBase64Encoded: zod_1.z.boolean(),
body: zod_1.z.string().optional().nullable(),
});