-
-
Notifications
You must be signed in to change notification settings - Fork 793
/
WebSocketRequestContext.js
47 lines (42 loc) · 1.27 KB
/
WebSocketRequestContext.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { createUniqueId, formatToClfTime } from '../../../utils/index.js'
const { now } = Date
export default class WebSocketRequestContext {
constructor(eventType, route, connectionId) {
this._connectionId = connectionId
this._eventType = eventType
this._route = route
}
create() {
const timeEpoch = now()
const requestContext = {
apiId: 'private',
connectedAt: now(), // TODO this is probably not correct, and should be the initial connection time?
connectionId: this._connectionId,
domainName: 'localhost',
eventType: this._eventType,
extendedRequestId: createUniqueId(),
identity: {
accessKey: null,
accountId: null,
caller: null,
cognitoAuthenticationProvider: null,
cognitoAuthenticationType: null,
cognitoIdentityId: null,
cognitoIdentityPoolId: null,
principalOrgId: null,
sourceIp: '127.0.0.1',
user: null,
userAgent: null,
userArn: null,
},
messageDirection: 'IN',
messageId: createUniqueId(),
requestId: createUniqueId(),
requestTime: formatToClfTime(timeEpoch),
requestTimeEpoch: timeEpoch,
routeKey: this._route,
stage: 'local',
}
return requestContext
}
}