serverless-offline 8.6.0 → 8.8.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 (43) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/README.md +89 -93
  3. package/dist/ServerlessOffline.js +14 -13
  4. package/dist/config/supportedRuntimes.js +1 -1
  5. package/dist/debugLog.js +3 -1
  6. package/dist/events/authValidateContext.js +53 -0
  7. package/dist/events/http/Endpoint.js +3 -1
  8. package/dist/events/http/HttpServer.js +27 -20
  9. package/dist/events/http/OfflineEndpoint.js +23 -25
  10. package/dist/events/http/createAuthScheme.js +22 -11
  11. package/dist/events/http/createJWTAuthScheme.js +6 -2
  12. package/dist/events/http/lambda-events/LambdaIntegrationEvent.js +26 -0
  13. package/dist/events/http/lambda-events/LambdaProxyIntegrationEvent.js +16 -14
  14. package/dist/events/http/lambda-events/LambdaProxyIntegrationEventV2.js +17 -13
  15. package/dist/events/http/lambda-events/VelocityContext.js +3 -1
  16. package/dist/events/http/lambda-events/renderVelocityTemplateObject.js +4 -1
  17. package/dist/events/schedule/Schedule.js +10 -9
  18. package/dist/events/websocket/HttpServer.js +3 -1
  19. package/dist/events/websocket/WebSocketClients.js +38 -11
  20. package/dist/events/websocket/WebSocketServer.js +5 -6
  21. package/dist/index.js +0 -4
  22. package/dist/lambda/HttpServer.js +3 -1
  23. package/dist/lambda/Lambda.js +5 -1
  24. package/dist/lambda/LambdaFunction.js +1 -2
  25. package/dist/lambda/handler-runner/HandlerRunner.js +1 -29
  26. package/dist/lambda/handler-runner/child-process-runner/ChildProcessRunner.js +1 -9
  27. package/dist/lambda/handler-runner/child-process-runner/childProcessHelper.js +15 -6
  28. package/dist/lambda/handler-runner/docker-runner/DockerContainer.js +2 -4
  29. package/dist/lambda/handler-runner/go-runner/GoRunner.js +34 -15
  30. package/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js +24 -30
  31. package/dist/lambda/handler-runner/java-runner/JavaRunner.js +3 -1
  32. package/dist/lambda/handler-runner/python-runner/PythonRunner.js +15 -10
  33. package/dist/lambda/handler-runner/ruby-runner/RubyRunner.js +3 -4
  34. package/dist/lambda/handler-runner/worker-thread-runner/WorkerThreadRunner.js +0 -2
  35. package/dist/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js +4 -3
  36. package/dist/utils/generateHapiPath.js +1 -1
  37. package/dist/utils/getHttpApiCorsConfig.js +4 -8
  38. package/dist/utils/index.js +11 -4
  39. package/dist/utils/lowerCaseKeys.js +14 -0
  40. package/dist/utils/resolveJoins.js +4 -2
  41. package/dist/utils/splitHandlerPathAndName.js +9 -13
  42. package/package.json +23 -27
  43. package/dist/checkEngine.js +0 -21
@@ -5,18 +5,22 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ var _child_process = require("child_process");
9
+
8
10
  var _os = require("os");
9
11
 
10
12
  var _path = require("path");
11
13
 
12
- var _child_process = require("child_process");
13
-
14
- var _extend = _interopRequireDefault(require("extend"));
14
+ var _process = _interopRequireWildcard(require("process"));
15
15
 
16
16
  var _readline = _interopRequireDefault(require("readline"));
17
17
 
18
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
19
 
20
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
+
22
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
+
20
24
  function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
21
25
 
22
26
  var id = 0;
@@ -28,8 +32,8 @@ const {
28
32
  stringify
29
33
  } = JSON;
30
34
  const {
31
- cwd
32
- } = process;
35
+ assign
36
+ } = Object;
33
37
  const {
34
38
  has
35
39
  } = Reflect;
@@ -84,15 +88,15 @@ class PythonRunner {
84
88
  this.v3Utils = v3Utils;
85
89
  }
86
90
 
87
- if (process.env.VIRTUAL_ENV) {
91
+ if (_process.default.env.VIRTUAL_ENV) {
88
92
  const runtimeDir = (0, _os.platform)() === 'win32' ? 'Scripts' : 'bin';
89
- process.env.PATH = [(0, _path.join)(process.env.VIRTUAL_ENV, runtimeDir), _path.delimiter, process.env.PATH].join('');
93
+ _process.default.env.PATH = [(0, _path.join)(_process.default.env.VIRTUAL_ENV, runtimeDir), _path.delimiter, _process.default.env.PATH].join('');
90
94
  }
91
95
 
92
96
  const [pythonExecutable] = _classPrivateFieldLooseBase(this, _runtime)[_runtime].split('.');
93
97
 
94
- this.handlerProcess = (0, _child_process.spawn)(pythonExecutable, ['-u', (0, _path.resolve)(__dirname, 'invoke.py'), (0, _path.relative)(cwd(), _classPrivateFieldLooseBase(this, _handlerPath)[_handlerPath]), _classPrivateFieldLooseBase(this, _handlerName)[_handlerName]], {
95
- env: (0, _extend.default)(process.env, _classPrivateFieldLooseBase(this, _env)[_env]),
98
+ this.handlerProcess = (0, _child_process.spawn)(pythonExecutable, ['-u', (0, _path.resolve)(__dirname, 'invoke.py'), (0, _path.relative)((0, _process.cwd)(), _classPrivateFieldLooseBase(this, _handlerPath)[_handlerPath]), _classPrivateFieldLooseBase(this, _handlerName)[_handlerName]], {
99
+ env: assign(_process.default.env, _classPrivateFieldLooseBase(this, _env)[_env]),
96
100
  shell: true
97
101
  });
98
102
  this.handlerProcess.stdout.readline = _readline.default.createInterface({
@@ -168,7 +172,8 @@ class PythonRunner {
168
172
 
169
173
  this.handlerProcess.stdout.readline.on('line', onLine);
170
174
  this.handlerProcess.stderr.on('data', onErr);
171
- process.nextTick(() => {
175
+
176
+ _process.default.nextTick(() => {
172
177
  this.handlerProcess.stdin.write(input);
173
178
  this.handlerProcess.stdin.write('\n');
174
179
  });
@@ -9,6 +9,8 @@ var _os = require("os");
9
9
 
10
10
  var _path = require("path");
11
11
 
12
+ var _process = require("process");
13
+
12
14
  var _execa = _interopRequireDefault(require("execa"));
13
15
 
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -23,9 +25,6 @@ const {
23
25
  parse,
24
26
  stringify
25
27
  } = JSON;
26
- const {
27
- cwd
28
- } = process;
29
28
  const {
30
29
  has
31
30
  } = Reflect;
@@ -120,7 +119,7 @@ class RubyRunner {
120
119
  allowCache: _classPrivateFieldLooseBase(this, _allowCache)[_allowCache]
121
120
  }); // console.log(input)
122
121
 
123
- const ruby = (0, _execa.default)(runtime, [(0, _path.resolve)(__dirname, 'invoke.rb'), (0, _path.relative)(cwd(), _classPrivateFieldLooseBase(this, _handlerPath)[_handlerPath]), _classPrivateFieldLooseBase(this, _handlerName)[_handlerName]], {
122
+ const ruby = (0, _execa.default)(runtime, [(0, _path.resolve)(__dirname, 'invoke.rb'), (0, _path.relative)((0, _process.cwd)(), _classPrivateFieldLooseBase(this, _handlerPath)[_handlerPath]), _classPrivateFieldLooseBase(this, _handlerName)[_handlerName]], {
124
123
  env: _classPrivateFieldLooseBase(this, _env)[_env],
125
124
  input // shell: true,
126
125
 
@@ -39,7 +39,6 @@ class WorkerThreadRunner {
39
39
  functionKey,
40
40
  handlerName,
41
41
  handlerPath,
42
- handlerModuleNesting,
43
42
  timeout
44
43
  } = funOptions;
45
44
  _classPrivateFieldLooseBase(this, _allowCache)[_allowCache] = allowCache;
@@ -50,7 +49,6 @@ class WorkerThreadRunner {
50
49
  functionKey,
51
50
  handlerName,
52
51
  handlerPath,
53
- handlerModuleNesting,
54
52
  timeout
55
53
  }
56
54
  });
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ var _process = require("process");
4
+
3
5
  var _worker_threads = require("worker_threads");
4
6
 
5
7
  var _index = _interopRequireDefault(require("../in-process-runner/index.js"));
@@ -10,8 +12,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
10
12
  const {
11
13
  functionKey,
12
14
  handlerName,
13
- handlerPath,
14
- handlerModuleNesting
15
+ handlerPath
15
16
  } = _worker_threads.workerData;
16
17
 
17
18
  _worker_threads.parentPort.on('message', async messageData => {
@@ -23,7 +24,7 @@ _worker_threads.parentPort.on('message', async messageData => {
23
24
  allowCache
24
25
  } = messageData; // TODO we could probably cache this in the module scope?
25
26
 
26
- const inProcessRunner = new _index.default(functionKey, handlerPath, handlerName, handlerModuleNesting, process.env, timeout, allowCache);
27
+ const inProcessRunner = new _index.default(functionKey, handlerPath, handlerName, _process.env, timeout, allowCache);
27
28
  const result = await inProcessRunner.run(event, context); // TODO check serializeability (contains function, symbol etc)
28
29
 
29
30
  port.postMessage(result);
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = generateHapiPath;
7
7
 
8
- function generateHapiPath(path = '', options, serverless) {
8
+ function generateHapiPath(path, options, serverless) {
9
9
  // path must start with '/'
10
10
  let hapiPath = path.startsWith('/') ? path : `/${path}`;
11
11
 
@@ -7,8 +7,6 @@ exports.default = getHttpApiCorsConfig;
7
7
 
8
8
  var _debugLog = _interopRequireDefault(require("../debugLog.js"));
9
9
 
10
- var _serverlessLog = require("../serverlessLog.js");
11
-
12
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
11
 
14
12
  function getHttpApiCorsConfig(httpApiCors, {
@@ -24,20 +22,18 @@ function getHttpApiCorsConfig(httpApiCors, {
24
22
  };
25
23
 
26
24
  if (log) {
27
- log.warning(c);
25
+ log.debug('Using CORS policy', c);
28
26
  } else {
29
- (0, _debugLog.default)(c);
30
- (0, _serverlessLog.logWarning)(c);
27
+ (0, _debugLog.default)('Using CORS policy', c);
31
28
  }
32
29
 
33
30
  return c;
34
31
  }
35
32
 
36
33
  if (log) {
37
- log.warning(httpApiCors);
34
+ log.debug('Using CORS policy', httpApiCors);
38
35
  } else {
39
- (0, _debugLog.default)(httpApiCors);
40
- (0, _serverlessLog.logWarning)(httpApiCors);
36
+ (0, _debugLog.default)('Using CORS policy', httpApiCors);
41
37
  }
42
38
 
43
39
  return httpApiCors;
@@ -59,6 +59,12 @@ Object.defineProperty(exports, "jsonPath", {
59
59
  return _jsonPath.default;
60
60
  }
61
61
  });
62
+ Object.defineProperty(exports, "lowerCaseKeys", {
63
+ enumerable: true,
64
+ get: function () {
65
+ return _lowerCaseKeys.default;
66
+ }
67
+ });
62
68
  exports.nullIfEmpty = nullIfEmpty;
63
69
  Object.defineProperty(exports, "parseHeaders", {
64
70
  enumerable: true,
@@ -110,6 +116,8 @@ var _getHttpApiCorsConfig = _interopRequireDefault(require("./getHttpApiCorsConf
110
116
 
111
117
  var _jsonPath = _interopRequireDefault(require("./jsonPath.js"));
112
118
 
119
+ var _lowerCaseKeys = _interopRequireDefault(require("./lowerCaseKeys.js"));
120
+
113
121
  var _parseHeaders = _interopRequireDefault(require("./parseHeaders.js"));
114
122
 
115
123
  var _parseMultiValueHeaders = _interopRequireDefault(require("./parseMultiValueHeaders.js"));
@@ -130,16 +138,15 @@ var _generateHapiPath = _interopRequireDefault(require("./generateHapiPath.js"))
130
138
 
131
139
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
132
140
 
141
+ // export { default as baseImage } from './baseImage.js'
133
142
  const {
134
143
  isArray
135
144
  } = Array;
136
145
  const {
137
146
  keys
138
- } = Object;
139
-
140
- // export { default as baseImage } from './baseImage.js'
141
- // Detect the toString encoding from the request headers content-type
147
+ } = Object; // Detect the toString encoding from the request headers content-type
142
148
  // enhance if further content types need to be non utf8 encoded.
149
+
143
150
  function detectEncoding(request) {
144
151
  const contentType = request.headers['content-type'];
145
152
  return typeof contentType === 'string' && contentType.includes('multipart/form-data') ? 'binary' : 'utf8';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = parseHeaders;
7
+ const {
8
+ entries,
9
+ fromEntries
10
+ } = Object; // (obj: { [string]: string }): { [Lowercase<string>]: string }
11
+
12
+ function parseHeaders(obj) {
13
+ return fromEntries(entries(obj).map(([k, v]) => [k.toLowerCase(), v]));
14
+ }
@@ -4,15 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = resolveJoins;
7
+ const {
8
+ keys
9
+ } = Object; // Used to resolve Fn::Join in environment variables
7
10
 
8
- // Used to resolve Fn::Join in environment variables
9
11
  function resolveJoins(environment) {
10
12
  if (!environment) {
11
13
  return undefined;
12
14
  }
13
15
 
14
16
  const newEnv = {};
15
- Object.keys(environment).forEach(key => {
17
+ keys(environment).forEach(key => {
16
18
  const value = environment[key];
17
19
 
18
20
  if (!value) {
@@ -8,18 +8,18 @@ exports.default = splitHandlerPathAndName;
8
8
  // some-folder/src.index => some-folder/src
9
9
  function splitHandlerPathAndName(handler) {
10
10
  // Split handler into method name and path i.e. handler.run
11
- const prepathDelimiter = handler.lastIndexOf('/');
12
- const prepath = handler.substr(0, prepathDelimiter + 1); // include '/' for path
13
-
14
- const postpath = handler.substr(prepathDelimiter + 1); // Support Ruby paths with namespace resolution operators e.g.
11
+ // Support Ruby paths with namespace resolution operators e.g.
15
12
  // ./src/somefolder/source.LambdaFunctions::Handler.process
16
13
  // prepath: ./src/somefolder/
17
14
  // postpath: source.LambdaFunctions::Handler.process
18
15
  // filename: source
19
16
  // path: ./src/somefolder/source
20
17
  // name: LambdaFunctions::Handler.process
21
-
22
18
  if (handler.match(/::/)) {
19
+ const prepathDelimiter = handler.lastIndexOf('/');
20
+ const prepath = handler.substr(0, prepathDelimiter + 1); // include '/' for path
21
+
22
+ const postpath = handler.substr(prepathDelimiter + 1);
23
23
  const nameDelimiter = postpath.indexOf('.');
24
24
  const filename = postpath.substr(0, nameDelimiter);
25
25
  const path = prepath + filename;
@@ -30,12 +30,8 @@ function splitHandlerPathAndName(handler) {
30
30
  // name: run
31
31
 
32
32
 
33
- const [filename, ...moduleNesting] = postpath.split('.');
34
- const [name] = moduleNesting.slice(-1);
35
- const path = prepath + filename; // module nesting has been added to support when the
36
- // handler function is buried deep inside of a module
37
- // e.g /src/somefoler/handlers/index.layer1.layer2.handler
38
- // AWS supports this feature
39
-
40
- return [path, name, moduleNesting];
33
+ const delimiter = handler.lastIndexOf('.');
34
+ const path = handler.substr(0, delimiter);
35
+ const name = handler.substr(delimiter + 1);
36
+ return [path, name];
41
37
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "dedicatedTo": "Blue, a great migrating bird.",
3
3
  "name": "serverless-offline",
4
- "version": "8.6.0",
4
+ "version": "8.8.1",
5
5
  "description": "Emulate AWS λ and API Gateway locally when developing your Serverless project",
6
6
  "license": "MIT",
7
7
  "main": "dist/main.js",
@@ -118,6 +118,7 @@
118
118
  "kobanyan (https://github.com/kobanyan)",
119
119
  "Leonardo Alifraco (https://github.com/lalifraco-devspark)",
120
120
  "Leonardo Medici (https://github.com/doclm)",
121
+ "Luciano Jesus Lima (https://github.com/brazilianbytes)",
121
122
  "Luke Chavers (https://github.com/vmadman)",
122
123
  "Manuel Böhm (https://github.com/boehmers)",
123
124
  "Marc Campbell (https://github.com/marccampbell)",
@@ -204,59 +205,54 @@
204
205
  "dependencies": {
205
206
  "@hapi/boom": "^9.1.4",
206
207
  "@hapi/h2o2": "^9.1.0",
207
- "@hapi/hapi": "^20.2.1",
208
- "aws-sdk": "^2.1097.0",
208
+ "@hapi/hapi": "^20.2.2",
209
+ "aws-sdk": "^2.1136.0",
209
210
  "boxen": "^5.1.2",
210
211
  "chalk": "^4.1.2",
211
212
  "cuid": "^2.1.8",
212
213
  "execa": "^5.1.1",
213
- "extend": "^3.0.2",
214
- "fs-extra": "^9.1.0",
214
+ "fs-extra": "^10.1.0",
215
215
  "java-invoke-local": "0.0.6",
216
216
  "js-string-escape": "^1.0.1",
217
217
  "jsonpath-plus": "^5.1.0",
218
218
  "jsonschema": "^1.4.0",
219
219
  "jsonwebtoken": "^8.5.1",
220
- "jszip": "^3.7.1",
221
- "luxon": "^1.28.0",
220
+ "jszip": "^3.9.1",
221
+ "luxon": "^2.4.0",
222
222
  "node-fetch": "^2.6.7",
223
- "node-schedule": "^1.3.3",
224
- "object.fromentries": "^2.0.5",
223
+ "node-schedule": "^2.1.0",
225
224
  "p-memoize": "^4.0.4",
226
225
  "p-queue": "^6.6.2",
227
- "p-retry": "^4.6.1",
228
- "please-upgrade-node": "^3.2.0",
229
- "semver": "^7.3.5",
230
- "update-notifier": "^5.1.0",
226
+ "p-retry": "^4.6.2",
227
+ "semver": "^7.3.7",
231
228
  "velocityjs": "^2.0.6",
232
229
  "ws": "^7.5.7"
233
230
  },
234
231
  "devDependencies": {
235
- "@babel/cli": "^7.17.6",
236
- "@babel/core": "^7.17.8",
237
- "@babel/plugin-proposal-class-properties": "^7.16.7",
232
+ "@babel/cli": "^7.17.10",
233
+ "@babel/core": "^7.17.12",
234
+ "@babel/plugin-proposal-class-properties": "^7.17.12",
238
235
  "@babel/plugin-proposal-dynamic-import": "^7.16.7",
239
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.7",
240
- "@babel/plugin-proposal-optional-chaining": "^7.16.7",
241
- "@babel/plugin-transform-modules-commonjs": "^7.17.7",
236
+ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.17.12",
237
+ "@babel/plugin-proposal-optional-chaining": "^7.17.12",
238
+ "@babel/plugin-transform-modules-commonjs": "^7.17.12",
242
239
  "@babel/register": "^7.17.7",
243
- "archiver": "^5.3.0",
244
- "babel-eslint": "^10.1.0",
240
+ "archiver": "^5.3.1",
245
241
  "copyfiles": "^2.4.1",
246
- "eslint": "^7.32.0",
247
- "eslint-config-airbnb-base": "^14.2.1",
248
- "eslint-config-prettier": "^7.2.0",
242
+ "eslint": "^8.15.0",
243
+ "eslint-config-airbnb-base": "^15.0.0",
244
+ "eslint-config-prettier": "^8.5.0",
249
245
  "eslint-plugin-import": "^2.25.4",
250
- "eslint-plugin-prettier": "^3.4.1",
246
+ "eslint-plugin-prettier": "^4.0.0",
251
247
  "git-list-updated": "^1.2.1",
252
248
  "husky": "^4.3.8",
253
249
  "jest": "^26.6.3",
254
250
  "lint-staged": "^11.2.6",
255
251
  "p-map": "^4.0.0",
256
- "prettier": "^2.6.0",
252
+ "prettier": "^2.6.2",
257
253
  "rimraf": "^3.0.2",
258
254
  "serverless": "^2.72.3",
259
- "standard-version": "^9.3.2"
255
+ "standard-version": "^9.5.0"
260
256
  },
261
257
  "peerDependencies": {
262
258
  "serverless": "^1.60.0 || 2 || 3"
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- var _pleaseUpgradeNode = _interopRequireDefault(require("please-upgrade-node"));
4
-
5
- var _package = _interopRequireDefault(require("../package.json"));
6
-
7
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
-
9
- // NOTE: important, don't use any new javascript language features in this file!
10
- // (other than es6 modules, which are transpiled)
11
- const currentNodeVersion = process.versions.node;
12
-
13
- const requiredNodeVersion = _package.default.engines.node.replace('>=', '');
14
-
15
- (0, _pleaseUpgradeNode.default)(_package.default, {
16
- message: function message() {
17
- return (// eslint-disable-next-line prefer-template
18
- 'serverless-offline requires node.js version ' + requiredNodeVersion + ' or higher, but found version ' + currentNodeVersion + '. Please upgrade!'
19
- );
20
- }
21
- });