serverless-offline 8.2.0 → 8.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +157 -116
  2. package/dist/ServerlessOffline.js +98 -26
  3. package/dist/config/commandOptions.js +4 -0
  4. package/dist/config/constants.js +1 -1
  5. package/dist/config/defaultOptions.js +1 -0
  6. package/dist/events/http/Endpoint.js +27 -9
  7. package/dist/events/http/Http.js +3 -3
  8. package/dist/events/http/HttpServer.js +355 -82
  9. package/dist/events/http/authFunctionNameExtractor.js +14 -8
  10. package/dist/events/http/authJWTSettingsExtractor.js +14 -7
  11. package/dist/events/http/createAuthScheme.js +44 -9
  12. package/dist/events/http/createJWTAuthScheme.js +52 -13
  13. package/dist/events/http/lambda-events/LambdaIntegrationEvent.js +7 -6
  14. package/dist/events/http/lambda-events/LambdaProxyIntegrationEvent.js +38 -7
  15. package/dist/events/http/lambda-events/LambdaProxyIntegrationEventV2.js +37 -6
  16. package/dist/events/http/lambda-events/VelocityContext.js +4 -4
  17. package/dist/events/http/lambda-events/index.js +4 -4
  18. package/dist/events/http/lambda-events/renderVelocityTemplateObject.js +19 -7
  19. package/dist/events/schedule/Schedule.js +45 -10
  20. package/dist/events/websocket/HttpServer.js +24 -7
  21. package/dist/events/websocket/WebSocket.js +14 -6
  22. package/dist/events/websocket/WebSocketClients.js +127 -38
  23. package/dist/events/websocket/WebSocketServer.js +79 -11
  24. package/dist/events/websocket/http-routes/_catchAll/catchAllRoute.js +9 -2
  25. package/dist/events/websocket/http-routes/connections/ConnectionsController.js +1 -1
  26. package/dist/events/websocket/http-routes/connections/connectionsRoutes.js +28 -5
  27. package/dist/events/websocket/lambda-events/WebSocketConnectEvent.js +5 -5
  28. package/dist/events/websocket/lambda-events/WebSocketDisconnectEvent.js +1 -1
  29. package/dist/events/websocket/lambda-events/WebSocketEvent.js +3 -3
  30. package/dist/events/websocket/lambda-events/WebSocketRequestContext.js +4 -4
  31. package/dist/lambda/HttpServer.js +34 -10
  32. package/dist/lambda/Lambda.js +15 -7
  33. package/dist/lambda/LambdaContext.js +1 -1
  34. package/dist/lambda/LambdaFunction.js +40 -23
  35. package/dist/lambda/LambdaFunctionPool.js +9 -8
  36. package/dist/lambda/handler-runner/HandlerRunner.js +51 -16
  37. package/dist/lambda/handler-runner/child-process-runner/ChildProcessRunner.js +21 -8
  38. package/dist/lambda/handler-runner/child-process-runner/childProcessHelper.js +1 -10
  39. package/dist/lambda/handler-runner/docker-runner/DockerContainer.js +168 -69
  40. package/dist/lambda/handler-runner/docker-runner/DockerImage.js +21 -5
  41. package/dist/lambda/handler-runner/docker-runner/DockerRunner.js +4 -4
  42. package/dist/lambda/handler-runner/go-runner/GoRunner.js +211 -0
  43. package/dist/lambda/handler-runner/go-runner/index.js +15 -0
  44. package/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js +16 -22
  45. package/dist/lambda/handler-runner/java-runner/JavaRunner.js +26 -14
  46. package/dist/lambda/handler-runner/python-runner/PythonRunner.js +20 -7
  47. package/dist/lambda/handler-runner/ruby-runner/RubyRunner.js +22 -24
  48. package/dist/lambda/handler-runner/worker-thread-runner/WorkerThreadRunner.js +2 -2
  49. package/dist/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js +1 -11
  50. package/dist/lambda/routes/invocations/InvocationsController.js +30 -11
  51. package/dist/lambda/routes/invocations/invocationsRoute.js +4 -3
  52. package/dist/lambda/routes/invoke-async/InvokeAsyncController.js +2 -6
  53. package/dist/serverlessLog.js +1 -1
  54. package/dist/utils/checkGoVersion.js +27 -0
  55. package/dist/utils/getHttpApiCorsConfig.js +18 -5
  56. package/dist/utils/index.js +24 -16
  57. package/package.json +86 -37
@@ -10,12 +10,18 @@ var _serverlessLog2 = _interopRequireDefault(require("../../serverlessLog.js"));
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
11
 
12
12
  // FIXME "slessLog" param is only remaining for tests, should be removed
13
- function authFunctionNameExtractor(endpoint, slessLog) {
13
+ function authFunctionNameExtractor(endpoint, slessLog, v3Utils) {
14
14
  const buildFailureResult = warningMessage => {
15
+ const log = v3Utils && v3Utils.log;
16
+
15
17
  const _serverlessLog = slessLog || _serverlessLog2.default; // FIXME remove
16
18
 
17
19
 
18
- _serverlessLog(warningMessage);
20
+ if (log) {
21
+ log.warning(warningMessage);
22
+ } else {
23
+ _serverlessLog(`WARNING: ${warningMessage}`);
24
+ }
19
25
 
20
26
  return {
21
27
  unsupportedAuth: true
@@ -28,7 +34,7 @@ function authFunctionNameExtractor(endpoint, slessLog) {
28
34
 
29
35
  const handleStringAuthorizer = authorizerString => {
30
36
  if (authorizerString.toUpperCase() === 'AWS_IAM') {
31
- return buildFailureResult('WARNING: Serverless Offline does not support the AWS_IAM authorization type');
37
+ return buildFailureResult('Serverless Offline does not support the AWS_IAM authorization type');
32
38
  }
33
39
 
34
40
  return buildSuccessResult(authorizerString);
@@ -43,19 +49,19 @@ function authFunctionNameExtractor(endpoint, slessLog) {
43
49
  } = authorizerObject;
44
50
 
45
51
  if (type && type.toUpperCase() === 'AWS_IAM') {
46
- return buildFailureResult('WARNING: Serverless Offline does not support the AWS_IAM authorization type');
52
+ return buildFailureResult('Serverless Offline does not support the AWS_IAM authorization type');
47
53
  }
48
54
 
49
55
  if (arn) {
50
- return buildFailureResult(`WARNING: Serverless Offline does not support non local authorizers (arn): ${arn}`);
56
+ return buildFailureResult(`Serverless Offline does not support non local authorizers (arn): ${arn}`);
51
57
  }
52
58
 
53
59
  if (authorizerId) {
54
- return buildFailureResult(`WARNING: Serverless Offline does not support non local authorizers (authorizerId): ${authorizerId}`);
60
+ return buildFailureResult(`Serverless Offline does not support non local authorizers (authorizerId): ${authorizerId}`);
55
61
  }
56
62
 
57
63
  if (!name) {
58
- return buildFailureResult('WARNING: Serverless Offline supports local authorizers but authorizer name is missing');
64
+ return buildFailureResult('Serverless Offline supports local authorizers but authorizer name is missing');
59
65
  }
60
66
 
61
67
  return buildSuccessResult(name);
@@ -77,5 +83,5 @@ function authFunctionNameExtractor(endpoint, slessLog) {
77
83
  return handleObjectAuthorizer(authorizer);
78
84
  }
79
85
 
80
- return buildFailureResult('WARNING: Serverless Offline supports only local authorizers defined as string or object');
86
+ return buildFailureResult('Serverless Offline supports only local authorizers defined as string or object');
81
87
  }
@@ -9,9 +9,16 @@ var _serverlessLog = _interopRequireDefault(require("../../serverlessLog.js"));
9
9
 
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
11
 
12
- function authJWTSettingsExtractor(endpoint, provider, ignoreJWTSignature) {
12
+ function authJWTSettingsExtractor(endpoint, provider, ignoreJWTSignature, {
13
+ log
14
+ }) {
13
15
  const buildFailureResult = warningMessage => {
14
- (0, _serverlessLog.default)(warningMessage);
16
+ if (log) {
17
+ log.warning(warningMessage);
18
+ } else {
19
+ (0, _serverlessLog.default)(`WARNING: ${warningMessage}`);
20
+ }
21
+
15
22
  return {
16
23
  unsupportedAuth: true
17
24
  };
@@ -39,25 +46,25 @@ function authJWTSettingsExtractor(endpoint, provider, ignoreJWTSignature) {
39
46
  }
40
47
 
41
48
  if (!authorizer.name) {
42
- return buildFailureResult('WARNING: Serverless Offline supports only JWT authorizers referenced by name');
49
+ return buildFailureResult('Serverless Offline supports only JWT authorizers referenced by name');
43
50
  }
44
51
 
45
52
  const httpApiAuthorizer = provider.httpApi.authorizers[authorizer.name];
46
53
 
47
54
  if (!httpApiAuthorizer) {
48
- return buildFailureResult(`WARNING: JWT authorizer ${authorizer.name} not found`);
55
+ return buildFailureResult(`JWT authorizer ${authorizer.name} not found`);
49
56
  }
50
57
 
51
58
  if (!httpApiAuthorizer.identitySource) {
52
- return buildFailureResult(`WARNING: JWT authorizer ${authorizer.name} missing identity source`);
59
+ return buildFailureResult(`JWT authorizer ${authorizer.name} missing identity source`);
53
60
  }
54
61
 
55
62
  if (!httpApiAuthorizer.issuerUrl) {
56
- return buildFailureResult(`WARNING: JWT authorizer ${authorizer.name} missing issuer url`);
63
+ return buildFailureResult(`JWT authorizer ${authorizer.name} missing issuer url`);
57
64
  }
58
65
 
59
66
  if (!httpApiAuthorizer.audience || httpApiAuthorizer.audience.length === 0) {
60
- return buildFailureResult(`WARNING: JWT authorizer ${authorizer.name} missing audience`);
67
+ return buildFailureResult(`JWT authorizer ${authorizer.name} missing audience`);
61
68
  }
62
69
 
63
70
  const result = {
@@ -17,7 +17,9 @@ var _index = require("../../utils/index.js");
17
17
 
18
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
19
 
20
- function createAuthScheme(authorizerOptions, provider, lambda) {
20
+ function createAuthScheme(authorizerOptions, provider, lambda, {
21
+ log
22
+ }) {
21
23
  const authFunName = authorizerOptions.name;
22
24
  let identityHeader = 'authorization';
23
25
 
@@ -34,9 +36,15 @@ function createAuthScheme(authorizerOptions, provider, lambda) {
34
36
 
35
37
  return () => ({
36
38
  async authenticate(request, h) {
37
- console.log(''); // Just to make things a little pretty
39
+ if (log) {
40
+ log.notice();
41
+ log.notice(`Running Authorization function for ${request.method} ${request.path} (λ: ${authFunName})`);
42
+ } else {
43
+ console.log(''); // Just to make things a little pretty
44
+
45
+ (0, _serverlessLog.default)(`Running Authorization function for ${request.method} ${request.path} (λ: ${authFunName})`);
46
+ } // Get Authorization header
38
47
 
39
- (0, _serverlessLog.default)(`Running Authorization function for ${request.method} ${request.path} (λ: ${authFunName})`); // Get Authorization header
40
48
 
41
49
  const {
42
50
  req
@@ -87,7 +95,13 @@ function createAuthScheme(authorizerOptions, provider, lambda) {
87
95
  const identityValidationExpression = new RegExp(authorizerOptions.identityValidationExpression);
88
96
  const matchedAuthorization = identityValidationExpression.test(authorization);
89
97
  const finalAuthorization = matchedAuthorization ? authorization : '';
90
- (0, _debugLog.default)(`Retrieved ${identityHeader} header "${finalAuthorization}"`);
98
+
99
+ if (log) {
100
+ log.debug(`Retrieved ${identityHeader} header "${finalAuthorization}"`);
101
+ } else {
102
+ (0, _debugLog.default)(`Retrieved ${identityHeader} header "${finalAuthorization}"`);
103
+ }
104
+
91
105
  event = { ...event,
92
106
  authorizationToken: finalAuthorization,
93
107
  type: 'TOKEN'
@@ -98,21 +112,37 @@ function createAuthScheme(authorizerOptions, provider, lambda) {
98
112
  lambdaFunction.setEvent(event);
99
113
 
100
114
  try {
101
- const result = await lambdaFunction.runHandler(); // return processResponse(null, result)
115
+ const result = await lambdaFunction.runHandler();
116
+ if (result === 'Unauthorized') return _boom.default.unauthorized('Unauthorized'); // return processResponse(null, result)
102
117
 
103
118
  const policy = result; // Validate that the policy document has the principalId set
104
119
 
105
120
  if (!policy.principalId) {
106
- (0, _serverlessLog.default)(`Authorization response did not include a principalId: (λ: ${authFunName})`);
121
+ if (log) {
122
+ log.notice(`Authorization response did not include a principalId: (λ: ${authFunName})`);
123
+ } else {
124
+ (0, _serverlessLog.default)(`Authorization response did not include a principalId: (λ: ${authFunName})`);
125
+ }
126
+
107
127
  return _boom.default.forbidden('No principalId set on the Response');
108
128
  }
109
129
 
110
130
  if (!(0, _authCanExecuteResource.default)(policy.policyDocument, event.methodArn)) {
111
- (0, _serverlessLog.default)(`Authorization response didn't authorize user to access resource: (λ: ${authFunName})`);
131
+ if (log) {
132
+ log.notice(`Authorization response didn't authorize user to access resource: (λ: ${authFunName})`);
133
+ } else {
134
+ (0, _serverlessLog.default)(`Authorization response didn't authorize user to access resource: (λ: ${authFunName})`);
135
+ }
136
+
112
137
  return _boom.default.forbidden('User is not authorized to access this resource');
113
138
  }
114
139
 
115
- (0, _serverlessLog.default)(`Authorization function returned a successful response: (λ: ${authFunName})`);
140
+ if (log) {
141
+ log.notice(`Authorization function returned a successful response: (λ: ${authFunName})`);
142
+ } else {
143
+ (0, _serverlessLog.default)(`Authorization function returned a successful response: (λ: ${authFunName})`);
144
+ }
145
+
116
146
  const authorizer = {
117
147
  integrationLatency: '42',
118
148
  principalId: policy.principalId,
@@ -129,7 +159,12 @@ function createAuthScheme(authorizerOptions, provider, lambda) {
129
159
  }
130
160
  });
131
161
  } catch (err) {
132
- (0, _serverlessLog.default)(`Authorization function returned an error response: (λ: ${authFunName})`);
162
+ if (log) {
163
+ log.notice(`Authorization function returned an error response: (λ: ${authFunName})`);
164
+ } else {
165
+ (0, _serverlessLog.default)(`Authorization function returned an error response: (λ: ${authFunName})`);
166
+ }
167
+
133
168
  return _boom.default.unauthorized('Unauthorized');
134
169
  }
135
170
  }
@@ -13,7 +13,9 @@ var _serverlessLog = _interopRequireDefault(require("../../serverlessLog.js"));
13
13
 
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
- function createAuthScheme(jwtOptions) {
16
+ function createAuthScheme(jwtOptions, {
17
+ log
18
+ }) {
17
19
  const authorizerName = jwtOptions.name;
18
20
  const identitySourceMatch = /^\$request.header.((?:\w+-?)+\w+)$/.exec(jwtOptions.identitySource);
19
21
 
@@ -25,12 +27,18 @@ function createAuthScheme(jwtOptions) {
25
27
 
26
28
  return () => ({
27
29
  async authenticate(request, h) {
28
- console.log(''); // Just to make things a little pretty
29
- // TODO: this only validates specific properties of the JWT
30
- // it does not verify the JWT is correctly signed. That would
31
- // be a great feature to add under an optional flag :)
30
+ if (log) {
31
+ log.notice();
32
+ log.notice(`Running JWT Authorization function for ${request.method} ${request.path} (${authorizerName})`);
33
+ } else {
34
+ console.log(''); // Just to make things a little pretty
35
+ // TODO: this only validates specific properties of the JWT
36
+ // it does not verify the JWT is correctly signed. That would
37
+ // be a great feature to add under an optional flag :)
38
+
39
+ (0, _serverlessLog.default)(`Running JWT Authorization function for ${request.method} ${request.path} (${authorizerName})`);
40
+ } // Get Authorization header
32
41
 
33
- (0, _serverlessLog.default)(`Running JWT Authorization function for ${request.method} ${request.path} (${authorizerName})`); // Get Authorization header
34
42
 
35
43
  const {
36
44
  req
@@ -65,7 +73,12 @@ function createAuthScheme(jwtOptions) {
65
73
  const clientId = decoded.payload.client_id;
66
74
 
67
75
  if (iss !== jwtOptions.issuerUrl) {
68
- (0, _serverlessLog.default)(`JWT Token not from correct issuer url`);
76
+ if (log) {
77
+ log.notice(`JWT Token not from correct issuer url`);
78
+ } else {
79
+ (0, _serverlessLog.default)(`JWT Token not from correct issuer url`);
80
+ }
81
+
69
82
  return _boom.default.unauthorized('JWT Token not from correct issuer url');
70
83
  }
71
84
 
@@ -74,7 +87,12 @@ function createAuthScheme(jwtOptions) {
74
87
  const validAudienceProvided = providedAudiences.some(a => validAudiences.includes(a));
75
88
 
76
89
  if (!validAudienceProvided && !validAudiences.includes(clientId)) {
77
- (0, _serverlessLog.default)(`JWT Token does not contain correct audience`);
90
+ if (log) {
91
+ log.notice(`JWT Token does not contain correct audience`);
92
+ } else {
93
+ (0, _serverlessLog.default)(`JWT Token does not contain correct audience`);
94
+ }
95
+
78
96
  return _boom.default.unauthorized('JWT Token does not contain correct audience');
79
97
  }
80
98
 
@@ -82,7 +100,12 @@ function createAuthScheme(jwtOptions) {
82
100
 
83
101
  if (jwtOptions.scopes && jwtOptions.scopes.length) {
84
102
  if (!scope) {
85
- (0, _serverlessLog.default)(`JWT Token missing valid scope`);
103
+ if (log) {
104
+ log.notice(`JWT Token missing valid scope`);
105
+ } else {
106
+ (0, _serverlessLog.default)(`JWT Token missing valid scope`);
107
+ }
108
+
86
109
  return _boom.default.forbidden('JWT Token missing valid scope');
87
110
  }
88
111
 
@@ -91,14 +114,24 @@ function createAuthScheme(jwtOptions) {
91
114
  if (scopes.every(s => {
92
115
  return !jwtOptions.scopes.includes(s);
93
116
  })) {
94
- (0, _serverlessLog.default)(`JWT Token missing valid scope`);
117
+ if (log) {
118
+ log.notice(`JWT Token missing valid scope`);
119
+ } else {
120
+ (0, _serverlessLog.default)(`JWT Token missing valid scope`);
121
+ }
122
+
95
123
  return _boom.default.forbidden('JWT Token missing valid scope');
96
124
  }
97
125
  }
98
126
 
99
- (0, _serverlessLog.default)(`JWT Token validated`); // Set the credentials for the rest of the pipeline
127
+ if (log) {
128
+ log.notice(`JWT Token validated`);
129
+ } else {
130
+ (0, _serverlessLog.default)(`JWT Token validated`);
131
+ } // Set the credentials for the rest of the pipeline
100
132
  // return resolve(
101
133
 
134
+
102
135
  return h.authenticated({
103
136
  credentials: {
104
137
  claims: decoded.payload,
@@ -106,8 +139,14 @@ function createAuthScheme(jwtOptions) {
106
139
  }
107
140
  });
108
141
  } catch (err) {
109
- (0, _serverlessLog.default)(`JWT could not be decoded`);
110
- (0, _serverlessLog.default)(err);
142
+ if (log) {
143
+ log.notice(`JWT could not be decoded`);
144
+ log.error(err);
145
+ } else {
146
+ (0, _serverlessLog.default)(`JWT could not be decoded`);
147
+ (0, _serverlessLog.default)(err);
148
+ }
149
+
111
150
  return _boom.default.unauthorized('Unauthorized');
112
151
  }
113
152
  }
@@ -17,16 +17,16 @@ var id = 0;
17
17
 
18
18
  function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
19
19
 
20
- var _path = _classPrivateFieldLooseKey("path");
20
+ var _path = /*#__PURE__*/_classPrivateFieldLooseKey("path");
21
21
 
22
- var _request = _classPrivateFieldLooseKey("request");
22
+ var _request = /*#__PURE__*/_classPrivateFieldLooseKey("request");
23
23
 
24
- var _requestTemplate = _classPrivateFieldLooseKey("requestTemplate");
24
+ var _requestTemplate = /*#__PURE__*/_classPrivateFieldLooseKey("requestTemplate");
25
25
 
26
- var _stage = _classPrivateFieldLooseKey("stage");
26
+ var _stage = /*#__PURE__*/_classPrivateFieldLooseKey("stage");
27
27
 
28
28
  class LambdaIntegrationEvent {
29
- constructor(request, stage, requestTemplate, path) {
29
+ constructor(request, stage, requestTemplate, path, v3Utils) {
30
30
  Object.defineProperty(this, _path, {
31
31
  writable: true,
32
32
  value: null
@@ -47,11 +47,12 @@ class LambdaIntegrationEvent {
47
47
  _classPrivateFieldLooseBase(this, _request)[_request] = request;
48
48
  _classPrivateFieldLooseBase(this, _requestTemplate)[_requestTemplate] = requestTemplate;
49
49
  _classPrivateFieldLooseBase(this, _stage)[_stage] = stage;
50
+ this.v3Utils = v3Utils;
50
51
  }
51
52
 
52
53
  create() {
53
54
  const velocityContext = new _VelocityContext.default(_classPrivateFieldLooseBase(this, _request)[_request], _classPrivateFieldLooseBase(this, _stage)[_stage], _classPrivateFieldLooseBase(this, _request)[_request].payload || {}, _classPrivateFieldLooseBase(this, _path)[_path]).getContext();
54
- const event = (0, _renderVelocityTemplateObject.default)(_classPrivateFieldLooseBase(this, _requestTemplate)[_requestTemplate], velocityContext);
55
+ const event = (0, _renderVelocityTemplateObject.default)(_classPrivateFieldLooseBase(this, _requestTemplate)[_requestTemplate], velocityContext, this.v3Utils);
55
56
  return event;
56
57
  }
57
58
 
@@ -29,18 +29,20 @@ const {
29
29
  // https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
30
30
  // http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy-for-lambda.html
31
31
 
32
- var _path = _classPrivateFieldLooseKey("path");
32
+ var _path = /*#__PURE__*/_classPrivateFieldLooseKey("path");
33
33
 
34
- var _routeKey = _classPrivateFieldLooseKey("routeKey");
34
+ var _routeKey = /*#__PURE__*/_classPrivateFieldLooseKey("routeKey");
35
35
 
36
- var _request = _classPrivateFieldLooseKey("request");
36
+ var _request = /*#__PURE__*/_classPrivateFieldLooseKey("request");
37
37
 
38
- var _stage = _classPrivateFieldLooseKey("stage");
38
+ var _stage = /*#__PURE__*/_classPrivateFieldLooseKey("stage");
39
39
 
40
- var _stageVariables = _classPrivateFieldLooseKey("stageVariables");
40
+ var _stageVariables = /*#__PURE__*/_classPrivateFieldLooseKey("stageVariables");
41
+
42
+ var _additionalRequestContext = /*#__PURE__*/_classPrivateFieldLooseKey("additionalRequestContext");
41
43
 
42
44
  class LambdaProxyIntegrationEvent {
43
- constructor(request, stage, path, stageVariables, routeKey = null) {
45
+ constructor(request, stage, path, stageVariables, routeKey = null, additionalRequestContext = null, v3Utils) {
44
46
  Object.defineProperty(this, _path, {
45
47
  writable: true,
46
48
  value: null
@@ -61,11 +63,23 @@ class LambdaProxyIntegrationEvent {
61
63
  writable: true,
62
64
  value: null
63
65
  });
66
+ Object.defineProperty(this, _additionalRequestContext, {
67
+ writable: true,
68
+ value: null
69
+ });
64
70
  _classPrivateFieldLooseBase(this, _path)[_path] = path;
65
71
  _classPrivateFieldLooseBase(this, _routeKey)[_routeKey] = routeKey;
66
72
  _classPrivateFieldLooseBase(this, _request)[_request] = request;
67
73
  _classPrivateFieldLooseBase(this, _stage)[_stage] = stage;
68
74
  _classPrivateFieldLooseBase(this, _stageVariables)[_stageVariables] = stageVariables;
75
+ _classPrivateFieldLooseBase(this, _additionalRequestContext)[_additionalRequestContext] = additionalRequestContext || {};
76
+
77
+ if (v3Utils) {
78
+ this.log = v3Utils.log;
79
+ this.progress = v3Utils.progress;
80
+ this.writeText = v3Utils.writeText;
81
+ this.v3Utils = v3Utils;
82
+ }
69
83
  }
70
84
 
71
85
  create() {
@@ -78,7 +92,11 @@ class LambdaProxyIntegrationEvent {
78
92
  try {
79
93
  authAuthorizer = parse(process.env.AUTHORIZER);
80
94
  } catch (error) {
81
- console.error('Serverless-offline: Could not parse process.env.AUTHORIZER, make sure it is correct JSON.');
95
+ if (this.log) {
96
+ this.log.error('Could not parse process.env.AUTHORIZER, make sure it is correct JSON');
97
+ } else {
98
+ console.error('Serverless-offline: Could not parse process.env.AUTHORIZER, make sure it is correct JSON.');
99
+ }
82
100
  }
83
101
  }
84
102
 
@@ -92,6 +110,18 @@ class LambdaProxyIntegrationEvent {
92
110
 
93
111
  const headers = (0, _index.parseHeaders)(rawHeaders || []) || {};
94
112
 
113
+ if (headers['sls-offline-authorizer-override']) {
114
+ try {
115
+ authAuthorizer = parse(headers['sls-offline-authorizer-override']);
116
+ } catch (error) {
117
+ if (this.log) {
118
+ this.log.error('Could not parse header sls-offline-authorizer-override, make sure it is correct JSON');
119
+ } else {
120
+ console.error('Serverless-offline: Could not parse header sls-offline-authorizer-override make sure it is correct JSON.');
121
+ }
122
+ }
123
+ }
124
+
95
125
  if (body) {
96
126
  if (typeof body !== 'string') {
97
127
  // this.#request.payload is NOT the same as the rawPayload
@@ -194,6 +224,7 @@ class LambdaProxyIntegrationEvent {
194
224
  userAgent: _headers['user-agent'] || '',
195
225
  userArn: 'offlineContext_userArn'
196
226
  },
227
+ operationName: _classPrivateFieldLooseBase(this, _additionalRequestContext)[_additionalRequestContext].operationName,
197
228
  path: _classPrivateFieldLooseBase(this, _path)[_path],
198
229
  protocol: 'HTTP/1.1',
199
230
  requestId: (0, _index.createUniqueId)(),
@@ -28,16 +28,18 @@ const {
28
28
  } = Object; // https://www.serverless.com/framework/docs/providers/aws/events/http-api/
29
29
  // https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
30
30
 
31
- var _routeKey = _classPrivateFieldLooseKey("routeKey");
31
+ var _routeKey = /*#__PURE__*/_classPrivateFieldLooseKey("routeKey");
32
32
 
33
- var _request = _classPrivateFieldLooseKey("request");
33
+ var _request = /*#__PURE__*/_classPrivateFieldLooseKey("request");
34
34
 
35
- var _stage = _classPrivateFieldLooseKey("stage");
35
+ var _stage = /*#__PURE__*/_classPrivateFieldLooseKey("stage");
36
36
 
37
- var _stageVariables = _classPrivateFieldLooseKey("stageVariables");
37
+ var _stageVariables = /*#__PURE__*/_classPrivateFieldLooseKey("stageVariables");
38
+
39
+ var _additionalRequestContext = /*#__PURE__*/_classPrivateFieldLooseKey("additionalRequestContext");
38
40
 
39
41
  class LambdaProxyIntegrationEventV2 {
40
- constructor(request, stage, routeKey, stageVariables) {
42
+ constructor(request, stage, routeKey, stageVariables, additionalRequestContext, v3Utils) {
41
43
  Object.defineProperty(this, _routeKey, {
42
44
  writable: true,
43
45
  value: null
@@ -54,10 +56,22 @@ class LambdaProxyIntegrationEventV2 {
54
56
  writable: true,
55
57
  value: null
56
58
  });
59
+ Object.defineProperty(this, _additionalRequestContext, {
60
+ writable: true,
61
+ value: null
62
+ });
57
63
  _classPrivateFieldLooseBase(this, _routeKey)[_routeKey] = routeKey;
58
64
  _classPrivateFieldLooseBase(this, _request)[_request] = request;
59
65
  _classPrivateFieldLooseBase(this, _stage)[_stage] = stage;
60
66
  _classPrivateFieldLooseBase(this, _stageVariables)[_stageVariables] = stageVariables;
67
+ _classPrivateFieldLooseBase(this, _additionalRequestContext)[_additionalRequestContext] = additionalRequestContext || {};
68
+
69
+ if (v3Utils) {
70
+ this.log = v3Utils.log;
71
+ this.progress = v3Utils.progress;
72
+ this.writeText = v3Utils.writeText;
73
+ this.v3Utils = v3Utils;
74
+ }
61
75
  }
62
76
 
63
77
  create() {
@@ -68,7 +82,11 @@ class LambdaProxyIntegrationEventV2 {
68
82
  try {
69
83
  authAuthorizer = parse(process.env.AUTHORIZER);
70
84
  } catch (error) {
71
- console.error('Serverless-offline: Could not parse process.env.AUTHORIZER, make sure it is correct JSON.');
85
+ if (this.log) {
86
+ this.log.error('Could not parse process.env.AUTHORIZER, make sure it is correct JSON');
87
+ } else {
88
+ console.error('Serverless-offline: Could not parse process.env.AUTHORIZER, make sure it is correct JSON.');
89
+ }
72
90
  }
73
91
  }
74
92
 
@@ -81,6 +99,18 @@ class LambdaProxyIntegrationEventV2 {
81
99
 
82
100
  const headers = (0, _index.parseHeaders)(rawHeaders || []) || {};
83
101
 
102
+ if (headers['sls-offline-authorizer-override']) {
103
+ try {
104
+ authAuthorizer = parse(headers['sls-offline-authorizer-override']);
105
+ } catch (error) {
106
+ if (this.log) {
107
+ this.log.error('Could not parse header sls-offline-authorizer-override, make sure it is correct JSON');
108
+ } else {
109
+ console.error('Serverless-offline: Could not parse header sls-offline-authorizer-override make sure it is correct JSON.');
110
+ }
111
+ }
112
+ }
113
+
84
114
  if (body) {
85
115
  if (typeof body !== 'string') {
86
116
  // this.#request.payload is NOT the same as the rawPayload
@@ -166,6 +196,7 @@ class LambdaProxyIntegrationEventV2 {
166
196
  sourceIp: remoteAddress,
167
197
  userAgent: _headers['user-agent'] || ''
168
198
  },
199
+ operationName: _classPrivateFieldLooseBase(this, _additionalRequestContext)[_additionalRequestContext].operationName,
169
200
  requestId: 'offlineContext_resourceId',
170
201
  routeKey: _classPrivateFieldLooseBase(this, _routeKey)[_routeKey],
171
202
  stage: _classPrivateFieldLooseBase(this, _stage)[_stage],
@@ -53,13 +53,13 @@ function escapeJavaScript(x) {
53
53
  */
54
54
 
55
55
 
56
- var _path = _classPrivateFieldLooseKey("path");
56
+ var _path = /*#__PURE__*/_classPrivateFieldLooseKey("path");
57
57
 
58
- var _payload = _classPrivateFieldLooseKey("payload");
58
+ var _payload = /*#__PURE__*/_classPrivateFieldLooseKey("payload");
59
59
 
60
- var _request = _classPrivateFieldLooseKey("request");
60
+ var _request = /*#__PURE__*/_classPrivateFieldLooseKey("request");
61
61
 
62
- var _stage = _classPrivateFieldLooseKey("stage");
62
+ var _stage = /*#__PURE__*/_classPrivateFieldLooseKey("stage");
63
63
 
64
64
  class VelocityContext {
65
65
  constructor(request, stage, payload, path) {
@@ -15,16 +15,16 @@ Object.defineProperty(exports, "LambdaProxyIntegrationEvent", {
15
15
  return _LambdaProxyIntegrationEvent.default;
16
16
  }
17
17
  });
18
- Object.defineProperty(exports, "renderVelocityTemplateObject", {
18
+ Object.defineProperty(exports, "VelocityContext", {
19
19
  enumerable: true,
20
20
  get: function () {
21
- return _renderVelocityTemplateObject.default;
21
+ return _VelocityContext.default;
22
22
  }
23
23
  });
24
- Object.defineProperty(exports, "VelocityContext", {
24
+ Object.defineProperty(exports, "renderVelocityTemplateObject", {
25
25
  enumerable: true,
26
26
  get: function () {
27
- return _VelocityContext.default;
27
+ return _renderVelocityTemplateObject.default;
28
28
  }
29
29
  });
30
30
 
@@ -30,8 +30,9 @@ function tryToParseJSON(string) {
30
30
  return parsed || string;
31
31
  }
32
32
 
33
- function renderVelocityString(velocityString, context) {
34
- // runs in a "polluted" (extended) String.prototype replacement scope
33
+ function renderVelocityString(velocityString, context, v3Utils) {
34
+ const log = v3Utils && v3Utils.log; // runs in a "polluted" (extended) String.prototype replacement scope
35
+
35
36
  const renderResult = (0, _javaHelpers.default)(() => // This line can throw, but this function does not handle errors
36
37
  // Quick args explanation:
37
38
  // { escape: false } --> otherwise would escape &, < and > chars with html (&amp;, &lt; and &gt;)
@@ -39,7 +40,13 @@ function renderVelocityString(velocityString, context) {
39
40
  new _velocityjs.Compile((0, _velocityjs.parse)(velocityString), {
40
41
  escape: false
41
42
  }).render(context, null, true));
42
- (0, _debugLog.default)('Velocity rendered:', renderResult || 'undefined'); // Haaaa Velocity... this language sure loves strings a lot
43
+
44
+ if (log) {
45
+ log.debug('Velocity rendered:', renderResult || 'undefined');
46
+ } else {
47
+ (0, _debugLog.default)('Velocity rendered:', renderResult || 'undefined');
48
+ } // Haaaa Velocity... this language sure loves strings a lot
49
+
43
50
 
44
51
  switch (renderResult) {
45
52
  case 'undefined':
@@ -65,8 +72,9 @@ function renderVelocityString(velocityString, context) {
65
72
  */
66
73
 
67
74
 
68
- function renderVelocityTemplateObject(templateObject, context) {
75
+ function renderVelocityTemplateObject(templateObject, context, v3Utils) {
69
76
  const result = {};
77
+ const log = v3Utils && v3Utils.log;
70
78
  let toProcess = templateObject; // In some projects, the template object is a string, let us see if it's JSON
71
79
 
72
80
  if (typeof toProcess === 'string') {
@@ -76,10 +84,14 @@ function renderVelocityTemplateObject(templateObject, context) {
76
84
 
77
85
  if ((0, _index.isPlainObject)(toProcess)) {
78
86
  entries(toProcess).forEach(([key, value]) => {
79
- (0, _debugLog.default)('Processing key:', key, '- value:', value);
87
+ if (log) {
88
+ log.debug('Processing key:', key, '- value:', value);
89
+ } else {
90
+ (0, _debugLog.default)('Processing key:', key, '- value:', value);
91
+ }
80
92
 
81
93
  if (typeof value === 'string') {
82
- result[key] = renderVelocityString(value, context); // Go deeper
94
+ result[key] = renderVelocityString(value, context, v3Utils); // Go deeper
83
95
  } else if ((0, _index.isPlainObject)(value)) {
84
96
  result[key] = renderVelocityTemplateObject(value, context); // This should never happen: value should either be a string or a plain object
85
97
  } else {
@@ -88,7 +100,7 @@ function renderVelocityTemplateObject(templateObject, context) {
88
100
  }); // Still a string? Maybe it's some complex Velocity stuff
89
101
  } else if (typeof toProcess === 'string') {
90
102
  // If the plugin threw here then you should consider reviewing your template or posting an issue.
91
- const alternativeResult = tryToParseJSON(renderVelocityString(toProcess, context));
103
+ const alternativeResult = tryToParseJSON(renderVelocityString(toProcess, context, v3Utils));
92
104
  return (0, _index.isPlainObject)(alternativeResult) ? alternativeResult : result;
93
105
  }
94
106