forked from dherault/serverless-offline
/
LambdaIntegrationEvent.js
58 lines (51 loc) · 1.41 KB
/
LambdaIntegrationEvent.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
48
49
50
51
52
53
54
55
56
57
58
import renderVelocityTemplateObject from './renderVelocityTemplateObject.js'
import VelocityContext from './VelocityContext.js'
const { parse } = JSON
export default class LambdaIntegrationEvent {
#path = null
#request = null
#requestTemplate = null
#stage = null
constructor(request, stage, requestTemplate, path, v3Utils) {
this.#path = path
this.#request = request
this.#requestTemplate = requestTemplate
this.#stage = stage
this.v3Utils = v3Utils
}
create() {
if (process.env.AUTHORIZER) {
try {
const authorizerContext = parse(process.env.AUTHORIZER)
if (authorizerContext) {
this.#request.auth = {
...this.#request.auth,
authorizer: authorizerContext,
}
}
} catch (error) {
if (this.log) {
this.log.error(
'Could not parse process.env.AUTHORIZER, make sure it is correct JSON',
)
} else {
console.error(
'Serverless-offline: Could not parse process.env.AUTHORIZER, make sure it is correct JSON.',
)
}
}
}
const velocityContext = new VelocityContext(
this.#request,
this.#stage,
this.#request.payload || {},
this.#path,
).getContext()
const event = renderVelocityTemplateObject(
this.#requestTemplate,
velocityContext,
this.v3Utils,
)
return event
}
}