serverless-offline 8.0.0 → 8.3.1

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 (53) hide show
  1. package/README.md +125 -112
  2. package/dist/ServerlessOffline.js +91 -24
  3. package/dist/config/constants.js +1 -1
  4. package/dist/config/supportedRuntimes.js +1 -1
  5. package/dist/events/http/Endpoint.js +27 -9
  6. package/dist/events/http/Http.js +3 -3
  7. package/dist/events/http/HttpServer.js +311 -76
  8. package/dist/events/http/authFunctionNameExtractor.js +14 -8
  9. package/dist/events/http/authJWTSettingsExtractor.js +14 -7
  10. package/dist/events/http/createAuthScheme.js +42 -8
  11. package/dist/events/http/createJWTAuthScheme.js +52 -13
  12. package/dist/events/http/lambda-events/LambdaIntegrationEvent.js +7 -6
  13. package/dist/events/http/lambda-events/LambdaProxyIntegrationEvent.js +18 -7
  14. package/dist/events/http/lambda-events/LambdaProxyIntegrationEventV2.js +17 -6
  15. package/dist/events/http/lambda-events/VelocityContext.js +4 -4
  16. package/dist/events/http/lambda-events/index.js +4 -4
  17. package/dist/events/http/lambda-events/renderVelocityTemplateObject.js +19 -7
  18. package/dist/events/schedule/Schedule.js +64 -20
  19. package/dist/events/websocket/HttpServer.js +24 -7
  20. package/dist/events/websocket/WebSocket.js +14 -6
  21. package/dist/events/websocket/WebSocketClients.js +65 -17
  22. package/dist/events/websocket/WebSocketServer.js +28 -6
  23. package/dist/events/websocket/http-routes/_catchAll/catchAllRoute.js +9 -2
  24. package/dist/events/websocket/http-routes/connections/ConnectionsController.js +1 -1
  25. package/dist/events/websocket/http-routes/connections/connectionsRoutes.js +28 -5
  26. package/dist/events/websocket/lambda-events/WebSocketConnectEvent.js +5 -5
  27. package/dist/events/websocket/lambda-events/WebSocketDisconnectEvent.js +1 -1
  28. package/dist/events/websocket/lambda-events/WebSocketEvent.js +3 -3
  29. package/dist/events/websocket/lambda-events/WebSocketRequestContext.js +4 -4
  30. package/dist/lambda/HttpServer.js +34 -10
  31. package/dist/lambda/Lambda.js +15 -7
  32. package/dist/lambda/LambdaContext.js +1 -1
  33. package/dist/lambda/LambdaFunction.js +40 -23
  34. package/dist/lambda/LambdaFunctionPool.js +9 -8
  35. package/dist/lambda/handler-runner/HandlerRunner.js +48 -15
  36. package/dist/lambda/handler-runner/child-process-runner/ChildProcessRunner.js +21 -8
  37. package/dist/lambda/handler-runner/child-process-runner/childProcessHelper.js +1 -10
  38. package/dist/lambda/handler-runner/docker-runner/DockerContainer.js +168 -69
  39. package/dist/lambda/handler-runner/docker-runner/DockerImage.js +21 -5
  40. package/dist/lambda/handler-runner/docker-runner/DockerRunner.js +4 -4
  41. package/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js +9 -21
  42. package/dist/lambda/handler-runner/java-runner/JavaRunner.js +26 -14
  43. package/dist/lambda/handler-runner/python-runner/PythonRunner.js +20 -7
  44. package/dist/lambda/handler-runner/ruby-runner/RubyRunner.js +22 -24
  45. package/dist/lambda/handler-runner/worker-thread-runner/WorkerThreadRunner.js +2 -2
  46. package/dist/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js +1 -11
  47. package/dist/lambda/routes/invocations/InvocationsController.js +37 -11
  48. package/dist/lambda/routes/invocations/invocationsRoute.js +2 -2
  49. package/dist/lambda/routes/invoke-async/InvokeAsyncController.js +2 -6
  50. package/dist/serverlessLog.js +1 -1
  51. package/dist/utils/getHttpApiCorsConfig.js +18 -5
  52. package/dist/utils/index.js +16 -16
  53. package/package.json +58 -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'
@@ -103,16 +117,31 @@ function createAuthScheme(authorizerOptions, provider, lambda) {
103
117
  const policy = result; // Validate that the policy document has the principalId set
104
118
 
105
119
  if (!policy.principalId) {
106
- (0, _serverlessLog.default)(`Authorization response did not include a principalId: (λ: ${authFunName})`);
120
+ if (log) {
121
+ log.notice(`Authorization response did not include a principalId: (λ: ${authFunName})`);
122
+ } else {
123
+ (0, _serverlessLog.default)(`Authorization response did not include a principalId: (λ: ${authFunName})`);
124
+ }
125
+
107
126
  return _boom.default.forbidden('No principalId set on the Response');
108
127
  }
109
128
 
110
129
  if (!(0, _authCanExecuteResource.default)(policy.policyDocument, event.methodArn)) {
111
- (0, _serverlessLog.default)(`Authorization response didn't authorize user to access resource: (λ: ${authFunName})`);
130
+ if (log) {
131
+ log.notice(`Authorization response didn't authorize user to access resource: (λ: ${authFunName})`);
132
+ } else {
133
+ (0, _serverlessLog.default)(`Authorization response didn't authorize user to access resource: (λ: ${authFunName})`);
134
+ }
135
+
112
136
  return _boom.default.forbidden('User is not authorized to access this resource');
113
137
  }
114
138
 
115
- (0, _serverlessLog.default)(`Authorization function returned a successful response: (λ: ${authFunName})`);
139
+ if (log) {
140
+ log.notice(`Authorization function returned a successful response: (λ: ${authFunName})`);
141
+ } else {
142
+ (0, _serverlessLog.default)(`Authorization function returned a successful response: (λ: ${authFunName})`);
143
+ }
144
+
116
145
  const authorizer = {
117
146
  integrationLatency: '42',
118
147
  principalId: policy.principalId,
@@ -129,7 +158,12 @@ function createAuthScheme(authorizerOptions, provider, lambda) {
129
158
  }
130
159
  });
131
160
  } catch (err) {
132
- (0, _serverlessLog.default)(`Authorization function returned an error response: (λ: ${authFunName})`);
161
+ if (log) {
162
+ log.notice(`Authorization function returned an error response: (λ: ${authFunName})`);
163
+ } else {
164
+ (0, _serverlessLog.default)(`Authorization function returned an error response: (λ: ${authFunName})`);
165
+ }
166
+
133
167
  return _boom.default.unauthorized('Unauthorized');
134
168
  }
135
169
  }
@@ -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,18 @@ 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
41
 
42
42
  class LambdaProxyIntegrationEvent {
43
- constructor(request, stage, path, stageVariables, routeKey = null) {
43
+ constructor(request, stage, path, stageVariables, routeKey = null, v3Utils) {
44
44
  Object.defineProperty(this, _path, {
45
45
  writable: true,
46
46
  value: null
@@ -66,6 +66,13 @@ class LambdaProxyIntegrationEvent {
66
66
  _classPrivateFieldLooseBase(this, _request)[_request] = request;
67
67
  _classPrivateFieldLooseBase(this, _stage)[_stage] = stage;
68
68
  _classPrivateFieldLooseBase(this, _stageVariables)[_stageVariables] = stageVariables;
69
+
70
+ if (v3Utils) {
71
+ this.log = v3Utils.log;
72
+ this.progress = v3Utils.progress;
73
+ this.writeText = v3Utils.writeText;
74
+ this.v3Utils = v3Utils;
75
+ }
69
76
  }
70
77
 
71
78
  create() {
@@ -78,7 +85,11 @@ class LambdaProxyIntegrationEvent {
78
85
  try {
79
86
  authAuthorizer = parse(process.env.AUTHORIZER);
80
87
  } catch (error) {
81
- console.error('Serverless-offline: Could not parse process.env.AUTHORIZER, make sure it is correct JSON.');
88
+ if (this.log) {
89
+ this.log.error('Could not parse process.env.AUTHORIZER, make sure it is correct JSON');
90
+ } else {
91
+ console.error('Serverless-offline: Could not parse process.env.AUTHORIZER, make sure it is correct JSON.');
92
+ }
82
93
  }
83
94
  }
84
95
 
@@ -28,16 +28,16 @@ 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
38
 
39
39
  class LambdaProxyIntegrationEventV2 {
40
- constructor(request, stage, routeKey, stageVariables) {
40
+ constructor(request, stage, routeKey, stageVariables, v3Utils) {
41
41
  Object.defineProperty(this, _routeKey, {
42
42
  writable: true,
43
43
  value: null
@@ -58,6 +58,13 @@ class LambdaProxyIntegrationEventV2 {
58
58
  _classPrivateFieldLooseBase(this, _request)[_request] = request;
59
59
  _classPrivateFieldLooseBase(this, _stage)[_stage] = stage;
60
60
  _classPrivateFieldLooseBase(this, _stageVariables)[_stageVariables] = stageVariables;
61
+
62
+ if (v3Utils) {
63
+ this.log = v3Utils.log;
64
+ this.progress = v3Utils.progress;
65
+ this.writeText = v3Utils.writeText;
66
+ this.v3Utils = v3Utils;
67
+ }
61
68
  }
62
69
 
63
70
  create() {
@@ -68,7 +75,11 @@ class LambdaProxyIntegrationEventV2 {
68
75
  try {
69
76
  authAuthorizer = parse(process.env.AUTHORIZER);
70
77
  } catch (error) {
71
- console.error('Serverless-offline: Could not parse process.env.AUTHORIZER, make sure it is correct JSON.');
78
+ if (this.log) {
79
+ this.log.error('Could not parse process.env.AUTHORIZER, make sure it is correct JSON');
80
+ } else {
81
+ console.error('Serverless-offline: Could not parse process.env.AUTHORIZER, make sure it is correct JSON.');
82
+ }
72
83
  }
73
84
  }
74
85
 
@@ -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