1+ import { z } from 'zod' ;
2+
3+ /**
4+ * A zod schema for API Gateway Proxy WebSocket events.
5+ *
6+ * @example
7+ * ```json
8+ * {
9+ * "type": "REQUEST",
10+ * "methodArn": "arn:aws:execute-api:us-east-1:123456789012:abcdef123/default/$connect",
11+ * "headers": {
12+ * "Connection": "upgrade",
13+ * "content-length": "0",
14+ * "HeaderAuth1": "headerValue1",
15+ * "Host": "abcdef123.execute-api.us-east-1.amazonaws.com",
16+ * "Sec-WebSocket-Extensions": "permessage-deflate; client_max_window_bits",
17+ * "Sec-WebSocket-Key": "...",
18+ * "Sec-WebSocket-Version": "13",
19+ * "Upgrade": "websocket",
20+ * "X-Amzn-Trace-Id": "..."
21+ * },
22+ * "multiValueHeaders": {
23+ * "Connection": [ "upgrade" ],
24+ * "content-length": [ "0" ],
25+ * "HeaderAuth1": [ "headerValue1" ],
26+ * "Host": [ "abcdef123.execute-api.us-east-1.amazonaws.com" ],
27+ * "Sec-WebSocket-Extensions": [ "permessage-deflate; client_max_window_bits" ],
28+ * "Sec-WebSocket-Key": [ "..." ],
29+ * "Sec-WebSocket-Version": [ "13" ],
30+ * "Upgrade": [ "websocket" ],
31+ * "X-Amzn-Trace-Id": [ "..." ]
32+ * },
33+ * "queryStringParameters": {
34+ * "QueryString1": "queryValue1"
35+ * },
36+ * "multiValueQueryStringParameters": {
37+ * "QueryString1": [ "queryValue1" ]
38+ * },
39+ * "stageVariables": {},
40+ * "requestContext": {
41+ * "routeKey": "$connect",
42+ * "eventType": "CONNECT",
43+ * "extendedRequestId": "...",
44+ * "requestTime": "19/Jan/2023:21:13:26 +0000",
45+ * "messageDirection": "IN",
46+ * "stage": "default",
47+ * "connectedAt": 1674162806344,
48+ * "requestTimeEpoch": 1674162806345,
49+ * "identity": {
50+ * "sourceIp": "..."
51+ * },
52+ * "requestId": "...",
53+ * "domainName": "abcdef123.execute-api.us-east-1.amazonaws.com",
54+ * "connectionId": "...",
55+ * "apiId": "abcdef123"
56+ * },
57+ * "isBase64Encoded": false,
58+ * "body": null
59+ * }
60+ * ```
61+ *
62+ * @see {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/websocket-api-develop-integrations.html }
63+ */
64+ export const APIGatewayProxyWebsocketEventSchema = z . object ( {
65+ type : z . string ( ) ,
66+ methodArn : z . string ( ) ,
67+ headers : z . record ( z . string ( ) ) ,
68+ multiValueHeaders : z . record ( z . array ( z . string ( ) ) ) ,
69+ queryStringParameters : z . record ( z . string ( ) ) . nullable ( ) . optional ( ) ,
70+ multiValueQueryStringParameters : z . record ( z . array ( z . string ( ) ) ) . nullable ( ) . optional ( ) ,
71+ stageVariables : z . record ( z . string ( ) ) . nullable ( ) . optional ( ) ,
72+ requestContext : z . object ( {
73+ routeKey : z . string ( ) ,
74+ eventType : z . enum ( [ "CONNECT" , "DISCONNECT" , "MESSAGE" ] ) ,
75+ extendedRequestId : z . string ( ) ,
76+ requestTime : z . string ( ) ,
77+ messageDirection : z . enum ( [ "IN" , "OUT" ] ) ,
78+ stage : z . string ( ) ,
79+ connectedAt : z . number ( ) ,
80+ requestTimeEpoch : z . number ( ) ,
81+ identity : z . object ( {
82+ sourceIp : z . string ( ) ,
83+ userAgent : z . string ( ) . optional ( ) ,
84+ } ) ,
85+ requestId : z . string ( ) ,
86+ domainName : z . string ( ) ,
87+ connectionId : z . string ( ) ,
88+ apiId : z . string ( ) ,
89+ } ) ,
90+ isBase64Encoded : z . boolean ( ) ,
91+ body : z . string ( ) . optional ( ) . nullable ( ) ,
92+ } ) ;
0 commit comments