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
@@ -24,12 +24,12 @@ const {
24
24
  stringify
25
25
  } = JSON;
26
26
 
27
- var _lambda = _classPrivateFieldLooseKey("lambda");
27
+ var _lambda = /*#__PURE__*/_classPrivateFieldLooseKey("lambda");
28
28
 
29
- var _region = _classPrivateFieldLooseKey("region");
29
+ var _region = /*#__PURE__*/_classPrivateFieldLooseKey("region");
30
30
 
31
31
  class Schedule {
32
- constructor(lambda, region) {
32
+ constructor(lambda, region, v3Utils) {
33
33
  Object.defineProperty(this, _lambda, {
34
34
  writable: true,
35
35
  value: null
@@ -40,6 +40,13 @@ class Schedule {
40
40
  });
41
41
  _classPrivateFieldLooseBase(this, _lambda)[_lambda] = lambda;
42
42
  _classPrivateFieldLooseBase(this, _region)[_region] = region;
43
+
44
+ if (v3Utils) {
45
+ this.log = v3Utils.log;
46
+ this.progress = v3Utils.progress;
47
+ this.writeText = v3Utils.writeText;
48
+ this.v3Utils = v3Utils;
49
+ }
43
50
  }
44
51
 
45
52
  _scheduleEvent(functionKey, scheduleEvent) {
@@ -50,27 +57,54 @@ class Schedule {
50
57
  } = scheduleEvent;
51
58
 
52
59
  if (!enabled) {
53
- console.log(`Scheduling [${functionKey}] cron: disabled`);
60
+ if (this.log) {
61
+ this.log.notice(`Scheduling [${functionKey}] cron: disabled`);
62
+ } else {
63
+ console.log(`Scheduling [${functionKey}] cron: disabled`);
64
+ }
65
+
54
66
  return;
55
- }
67
+ } // Convert string rate to array to support Serverless v2.57.0 and lower.
56
68
 
57
- const cron = this._convertExpressionToCron(rate);
58
69
 
59
- console.log(`Scheduling [${functionKey}] cron: [${cron}] input: ${stringify(input)}`);
70
+ let rates = rate;
60
71
 
61
- _nodeSchedule.default.scheduleJob(cron, async () => {
62
- try {
63
- const lambdaFunction = _classPrivateFieldLooseBase(this, _lambda)[_lambda].get(functionKey);
72
+ if (typeof rate === 'string') {
73
+ rates = [rate];
74
+ }
64
75
 
65
- const event = input !== null && input !== void 0 ? input : new _ScheduleEvent.default(_classPrivateFieldLooseBase(this, _region)[_region]);
66
- lambdaFunction.setEvent(event);
67
- /* const result = */
76
+ rates.forEach(entry => {
77
+ const cron = this._convertExpressionToCron(entry);
68
78
 
69
- await lambdaFunction.runHandler();
70
- console.log(`Succesfully invoked scheduled function: [${functionKey}]`);
71
- } catch (err) {
72
- console.log(`Failed to execute scheduled function: [${functionKey}] Error: ${err}`);
79
+ if (this.log) {
80
+ this.log.notice(`Scheduling [${functionKey}] cron: [${cron}] input: ${stringify(input)}`);
81
+ } else {
82
+ console.log(`Scheduling [${functionKey}] cron: [${cron}] input: ${stringify(input)}`);
73
83
  }
84
+
85
+ _nodeSchedule.default.scheduleJob(cron, async () => {
86
+ try {
87
+ const lambdaFunction = _classPrivateFieldLooseBase(this, _lambda)[_lambda].get(functionKey);
88
+
89
+ const event = input !== null && input !== void 0 ? input : new _ScheduleEvent.default(_classPrivateFieldLooseBase(this, _region)[_region]);
90
+ lambdaFunction.setEvent(event);
91
+ /* const result = */
92
+
93
+ await lambdaFunction.runHandler();
94
+
95
+ if (this.log) {
96
+ this.log.notice(`Successfully invoked scheduled function: [${functionKey}]`);
97
+ } else {
98
+ console.log(`Successfully invoked scheduled function: [${functionKey}]`);
99
+ }
100
+ } catch (err) {
101
+ if (this.log) {
102
+ this.log.error(`Failed to execute scheduled function: [${functionKey}] Error: ${err}`);
103
+ } else {
104
+ console.log(`Failed to execute scheduled function: [${functionKey}] Error: ${err}`);
105
+ }
106
+ }
107
+ });
74
108
  });
75
109
  } // _convertCronSyntax(cronString) {
76
110
  // if (cronString.split(' ').length < CRON_LENGTH_WITH_YEAR) {
@@ -98,7 +132,12 @@ class Schedule {
98
132
  return `0 0 */${number} * *`;
99
133
 
100
134
  default:
101
- console.log(`scheduler: Invalid rate syntax '${rate}', will not schedule`);
135
+ if (this.log) {
136
+ this.log.error(`scheduler: Invalid rate syntax '${rate}', will not schedule`);
137
+ } else {
138
+ console.log(`scheduler: Invalid rate syntax '${rate}', will not schedule`);
139
+ }
140
+
102
141
  return null;
103
142
  }
104
143
  }
@@ -107,14 +146,19 @@ class Schedule {
107
146
  const params = scheduleEvent.replace('rate(', '').replace('cron(', '').replace(')', '');
108
147
 
109
148
  if (scheduleEvent.startsWith('cron(')) {
110
- console.log('schedule rate "cron" not yet supported!'); // return this._convertCronSyntax(params)
149
+ if (!this.log) console.log('schedule rate "cron" not yet supported!'); // return this._convertCronSyntax(params)
111
150
  }
112
151
 
113
152
  if (scheduleEvent.startsWith('rate(')) {
114
153
  return this._convertRateToCron(params);
115
154
  }
116
155
 
117
- console.log('scheduler: invalid, schedule syntax');
156
+ if (this.log) {
157
+ this.log.error('scheduler: invalid, schedule syntax');
158
+ } else {
159
+ console.log('scheduler: invalid, schedule syntax');
160
+ }
161
+
118
162
  return undefined;
119
163
  }
120
164
 
@@ -19,14 +19,14 @@ var id = 0;
19
19
 
20
20
  function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
21
21
 
22
- var _options = _classPrivateFieldLooseKey("options");
22
+ var _options = /*#__PURE__*/_classPrivateFieldLooseKey("options");
23
23
 
24
- var _server = _classPrivateFieldLooseKey("server");
24
+ var _server = /*#__PURE__*/_classPrivateFieldLooseKey("server");
25
25
 
26
- var _webSocketClients = _classPrivateFieldLooseKey("webSocketClients");
26
+ var _webSocketClients = /*#__PURE__*/_classPrivateFieldLooseKey("webSocketClients");
27
27
 
28
28
  class HttpServer {
29
- constructor(options, webSocketClients) {
29
+ constructor(options, webSocketClients, v3Utils) {
30
30
  Object.defineProperty(this, _options, {
31
31
  writable: true,
32
32
  value: null
@@ -41,6 +41,14 @@ class HttpServer {
41
41
  });
42
42
  _classPrivateFieldLooseBase(this, _options)[_options] = options;
43
43
  _classPrivateFieldLooseBase(this, _webSocketClients)[_webSocketClients] = webSocketClients;
44
+
45
+ if (v3Utils) {
46
+ this.log = v3Utils.log;
47
+ this.progress = v3Utils.progress;
48
+ this.writeText = v3Utils.writeText;
49
+ this.v3Utils = v3Utils;
50
+ }
51
+
44
52
  const {
45
53
  host,
46
54
  websocketPort
@@ -59,7 +67,7 @@ class HttpServer {
59
67
 
60
68
  async start() {
61
69
  // add routes
62
- const routes = [...(0, _index.connectionsRoutes)(_classPrivateFieldLooseBase(this, _webSocketClients)[_webSocketClients]), (0, _index.catchAllRoute)()];
70
+ const routes = [...(0, _index.connectionsRoutes)(_classPrivateFieldLooseBase(this, _webSocketClients)[_webSocketClients], this.v3Utils), (0, _index.catchAllRoute)(this.v3Utils)];
63
71
 
64
72
  _classPrivateFieldLooseBase(this, _server)[_server].route(routes);
65
73
 
@@ -72,11 +80,20 @@ class HttpServer {
72
80
  try {
73
81
  await _classPrivateFieldLooseBase(this, _server)[_server].start();
74
82
  } catch (err) {
75
- console.error(`Unexpected error while starting serverless-offline websocket server on port ${websocketPort}:`, err);
83
+ if (this.log) {
84
+ this.log.error(`Unexpected error while starting serverless-offline websocket server on port ${websocketPort}:`, err);
85
+ } else {
86
+ console.error(`Unexpected error while starting serverless-offline websocket server on port ${websocketPort}:`, err);
87
+ }
88
+
76
89
  process.exit(1);
77
90
  }
78
91
 
79
- (0, _serverlessLog.default)(`Offline [http for websocket] listening on http${httpsProtocol ? 's' : ''}://${host}:${websocketPort}`);
92
+ if (this.log) {
93
+ this.log.notice(`Offline [http for websocket] listening on http${httpsProtocol ? 's' : ''}://${host}:${websocketPort}`);
94
+ } else {
95
+ (0, _serverlessLog.default)(`Offline [http for websocket] listening on http${httpsProtocol ? 's' : ''}://${host}:${websocketPort}`);
96
+ }
80
97
  } // stops the server
81
98
 
82
99
 
@@ -21,12 +21,12 @@ var id = 0;
21
21
 
22
22
  function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
23
23
 
24
- var _httpServer = _classPrivateFieldLooseKey("httpServer");
24
+ var _httpServer = /*#__PURE__*/_classPrivateFieldLooseKey("httpServer");
25
25
 
26
- var _webSocketServer = _classPrivateFieldLooseKey("webSocketServer");
26
+ var _webSocketServer = /*#__PURE__*/_classPrivateFieldLooseKey("webSocketServer");
27
27
 
28
28
  class WebSocket {
29
- constructor(serverless, options, lambda) {
29
+ constructor(serverless, options, lambda, v3Utils) {
30
30
  Object.defineProperty(this, _httpServer, {
31
31
  writable: true,
32
32
  value: null
@@ -35,10 +35,18 @@ class WebSocket {
35
35
  writable: true,
36
36
  value: null
37
37
  });
38
- const webSocketClients = new _WebSocketClients.default(serverless, options, lambda);
39
- _classPrivateFieldLooseBase(this, _httpServer)[_httpServer] = new _HttpServer.default(options, webSocketClients); // share server
38
+ const webSocketClients = new _WebSocketClients.default(serverless, options, lambda, v3Utils);
40
39
 
41
- _classPrivateFieldLooseBase(this, _webSocketServer)[_webSocketServer] = new _WebSocketServer.default(options, webSocketClients, _classPrivateFieldLooseBase(this, _httpServer)[_httpServer].server);
40
+ if (v3Utils) {
41
+ this.log = v3Utils.log;
42
+ this.progress = v3Utils.progress;
43
+ this.writeText = v3Utils.writeText;
44
+ this.v3Utils = v3Utils;
45
+ }
46
+
47
+ _classPrivateFieldLooseBase(this, _httpServer)[_httpServer] = new _HttpServer.default(options, webSocketClients, this.v3Utils); // share server
48
+
49
+ _classPrivateFieldLooseBase(this, _webSocketServer)[_webSocketServer] = new _WebSocketServer.default(options, webSocketClients, _classPrivateFieldLooseBase(this, _httpServer)[_httpServer].server, v3Utils);
42
50
  }
43
51
 
44
52
  start() {
@@ -30,22 +30,22 @@ const {
30
30
  stringify
31
31
  } = JSON;
32
32
 
33
- var _clients = _classPrivateFieldLooseKey("clients");
33
+ var _clients = /*#__PURE__*/_classPrivateFieldLooseKey("clients");
34
34
 
35
- var _lambda = _classPrivateFieldLooseKey("lambda");
35
+ var _lambda = /*#__PURE__*/_classPrivateFieldLooseKey("lambda");
36
36
 
37
- var _options = _classPrivateFieldLooseKey("options");
37
+ var _options = /*#__PURE__*/_classPrivateFieldLooseKey("options");
38
38
 
39
- var _webSocketRoutes = _classPrivateFieldLooseKey("webSocketRoutes");
39
+ var _webSocketRoutes = /*#__PURE__*/_classPrivateFieldLooseKey("webSocketRoutes");
40
40
 
41
- var _websocketsApiRouteSelectionExpression = _classPrivateFieldLooseKey("websocketsApiRouteSelectionExpression");
41
+ var _websocketsApiRouteSelectionExpression = /*#__PURE__*/_classPrivateFieldLooseKey("websocketsApiRouteSelectionExpression");
42
42
 
43
- var _idleTimeouts = _classPrivateFieldLooseKey("idleTimeouts");
43
+ var _idleTimeouts = /*#__PURE__*/_classPrivateFieldLooseKey("idleTimeouts");
44
44
 
45
- var _hardTimeouts = _classPrivateFieldLooseKey("hardTimeouts");
45
+ var _hardTimeouts = /*#__PURE__*/_classPrivateFieldLooseKey("hardTimeouts");
46
46
 
47
47
  class WebSocketClients {
48
- constructor(serverless, options, lambda) {
48
+ constructor(serverless, options, lambda, v3Utils) {
49
49
  Object.defineProperty(this, _clients, {
50
50
  writable: true,
51
51
  value: new Map()
@@ -77,6 +77,13 @@ class WebSocketClients {
77
77
  _classPrivateFieldLooseBase(this, _lambda)[_lambda] = lambda;
78
78
  _classPrivateFieldLooseBase(this, _options)[_options] = options;
79
79
  _classPrivateFieldLooseBase(this, _websocketsApiRouteSelectionExpression)[_websocketsApiRouteSelectionExpression] = serverless.service.provider.websocketsApiRouteSelectionExpression || _index2.DEFAULT_WEBSOCKETS_API_ROUTE_SELECTION_EXPRESSION;
80
+
81
+ if (v3Utils) {
82
+ this.log = v3Utils.log;
83
+ this.progress = v3Utils.progress;
84
+ this.writeText = v3Utils.writeText;
85
+ this.v3Utils = v3Utils;
86
+ }
80
87
  }
81
88
 
82
89
  _addWebSocketClient(client, connectionId) {
@@ -105,7 +112,12 @@ class WebSocketClients {
105
112
 
106
113
  _addHardTimeout(client, connectionId) {
107
114
  const timeoutId = setTimeout(() => {
108
- (0, _debugLog.default)(`timeout:hard:${connectionId}`);
115
+ if (this.log) {
116
+ this.log.debug(`timeout:hard:${connectionId}`);
117
+ } else {
118
+ (0, _debugLog.default)(`timeout:hard:${connectionId}`);
119
+ }
120
+
109
121
  client.close(1001, 'Going away');
110
122
  }, _classPrivateFieldLooseBase(this, _options)[_options].webSocketHardTimeout * 1000);
111
123
 
@@ -123,9 +135,19 @@ class WebSocketClients {
123
135
 
124
136
  this._clearIdleTimeout(client);
125
137
 
126
- (0, _debugLog.default)(`timeout:idle:${connectionId}:reset`);
138
+ if (this.log) {
139
+ this.log.debug(`timeout:idle:${connectionId}:reset`);
140
+ } else {
141
+ (0, _debugLog.default)(`timeout:idle:${connectionId}:reset`);
142
+ }
143
+
127
144
  const timeoutId = setTimeout(() => {
128
- (0, _debugLog.default)(`timeout:idle:${connectionId}:trigger`);
145
+ if (this.log) {
146
+ this.log.debug(`timeout:idle:${connectionId}:trigger`);
147
+ } else {
148
+ (0, _debugLog.default)(`timeout:idle:${connectionId}:trigger`);
149
+ }
150
+
129
151
  client.close(1001, 'Going away');
130
152
  }, _classPrivateFieldLooseBase(this, _options)[_options].webSocketIdleTimeout * 1000);
131
153
 
@@ -163,7 +185,11 @@ class WebSocketClients {
163
185
  websocketClient.close();
164
186
  }
165
187
 
166
- (0, _debugLog.default)(`Error in route handler '${functionKey}'`, err);
188
+ if (this.log) {
189
+ this.log.debug(`Error in route handler '${functionKey}'`, err);
190
+ } else {
191
+ (0, _debugLog.default)(`Error in route handler '${functionKey}'`, err);
192
+ }
167
193
  };
168
194
 
169
195
  const lambdaFunction = _classPrivateFieldLooseBase(this, _lambda)[_lambda].get(functionKey);
@@ -174,7 +200,12 @@ class WebSocketClients {
174
200
  /* result = */
175
201
  await lambdaFunction.runHandler(); // TODO what to do with "result"?
176
202
  } catch (err) {
177
- console.log(err);
203
+ if (this.log) {
204
+ this.log.error(err);
205
+ } else {
206
+ console.log(err);
207
+ }
208
+
178
209
  sendError(err);
179
210
  }
180
211
  }
@@ -207,7 +238,11 @@ class WebSocketClients {
207
238
  this._processEvent(webSocketClient, connectionId, '$connect', connectEvent);
208
239
 
209
240
  webSocketClient.on('close', () => {
210
- (0, _debugLog.default)(`disconnect:${connectionId}`);
241
+ if (this.log) {
242
+ this.log.debug(`disconnect:${connectionId}`);
243
+ } else {
244
+ (0, _debugLog.default)(`disconnect:${connectionId}`);
245
+ }
211
246
 
212
247
  this._removeWebSocketClient(webSocketClient);
213
248
 
@@ -220,11 +255,20 @@ class WebSocketClients {
220
255
  this._processEvent(webSocketClient, connectionId, '$disconnect', disconnectEvent);
221
256
  });
222
257
  webSocketClient.on('message', message => {
223
- (0, _debugLog.default)(`message:${message}`);
258
+ if (this.log) {
259
+ this.log.debug(`message:${message}`);
260
+ } else {
261
+ (0, _debugLog.default)(`message:${message}`);
262
+ }
224
263
 
225
264
  const route = this._getRoute(message);
226
265
 
227
- (0, _debugLog.default)(`route:${route} on connection=${connectionId}`);
266
+ if (this.log) {
267
+ this.log.debug(`route:${route} on connection=${connectionId}`);
268
+ } else {
269
+ (0, _debugLog.default)(`route:${route} on connection=${connectionId}`);
270
+ }
271
+
228
272
  const event = new _index.WebSocketEvent(connectionId, route, message).create();
229
273
 
230
274
  this._onWebSocketUsed(connectionId);
@@ -237,7 +281,11 @@ class WebSocketClients {
237
281
  // set the route name
238
282
  _classPrivateFieldLooseBase(this, _webSocketRoutes)[_webSocketRoutes].set(route, functionKey);
239
283
 
240
- (0, _serverlessLog.default)(`route '${route}'`);
284
+ if (this.log) {
285
+ this.log.notice(`route '${route}'`);
286
+ } else {
287
+ (0, _serverlessLog.default)(`route '${route}'`);
288
+ }
241
289
  }
242
290
 
243
291
  close(connectionId) {
@@ -21,12 +21,12 @@ var id = 0;
21
21
 
22
22
  function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
23
23
 
24
- var _options = _classPrivateFieldLooseKey("options");
24
+ var _options = /*#__PURE__*/_classPrivateFieldLooseKey("options");
25
25
 
26
- var _webSocketClients = _classPrivateFieldLooseKey("webSocketClients");
26
+ var _webSocketClients = /*#__PURE__*/_classPrivateFieldLooseKey("webSocketClients");
27
27
 
28
28
  class WebSocketServer {
29
- constructor(options, webSocketClients, sharedServer) {
29
+ constructor(options, webSocketClients, sharedServer, v3Utils) {
30
30
  Object.defineProperty(this, _options, {
31
31
  writable: true,
32
32
  value: null
@@ -37,13 +37,31 @@ class WebSocketServer {
37
37
  });
38
38
  _classPrivateFieldLooseBase(this, _options)[_options] = options;
39
39
  _classPrivateFieldLooseBase(this, _webSocketClients)[_webSocketClients] = webSocketClients;
40
+
41
+ if (v3Utils) {
42
+ this.log = v3Utils.log;
43
+ this.progress = v3Utils.progress;
44
+ this.writeText = v3Utils.writeText;
45
+ this.v3Utils = v3Utils;
46
+ }
47
+
40
48
  const server = new _ws.Server({
41
49
  server: sharedServer
42
50
  });
43
51
  server.on('connection', (webSocketClient, request) => {
44
- console.log('received connection');
52
+ if (this.log) {
53
+ this.log.notice('received connection');
54
+ } else {
55
+ console.log('received connection');
56
+ }
57
+
45
58
  const connectionId = (0, _index.createUniqueId)();
46
- (0, _debugLog.default)(`connect:${connectionId}`);
59
+
60
+ if (this.log) {
61
+ this.log.debug(`connect:${connectionId}`);
62
+ } else {
63
+ (0, _debugLog.default)(`connect:${connectionId}`);
64
+ }
47
65
 
48
66
  _classPrivateFieldLooseBase(this, _webSocketClients)[_webSocketClients].addClient(webSocketClient, request, connectionId);
49
67
  });
@@ -56,7 +74,11 @@ class WebSocketServer {
56
74
  websocketPort
57
75
  } = _classPrivateFieldLooseBase(this, _options)[_options];
58
76
 
59
- (0, _serverlessLog.default)(`Offline [websocket] listening on ws${httpsProtocol ? 's' : ''}://${host}:${websocketPort}`);
77
+ if (this.log) {
78
+ this.log.notice(`Offline [websocket] listening on ws${httpsProtocol ? 's' : ''}://${host}:${websocketPort}`);
79
+ } else {
80
+ (0, _serverlessLog.default)(`Offline [websocket] listening on ws${httpsProtocol ? 's' : ''}://${host}:${websocketPort}`);
81
+ }
60
82
  } // no-op, we're re-using the http server
61
83
 
62
84
 
@@ -9,7 +9,8 @@ var _debugLog = _interopRequireDefault(require("../../../../debugLog.js"));
9
9
 
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
11
 
12
- function catchAllRoute() {
12
+ function catchAllRoute(v3Utils) {
13
+ const log = v3Utils && v3Utils.log;
13
14
  return {
14
15
  method: 'GET',
15
16
  path: '/{path*}',
@@ -18,7 +19,13 @@ function catchAllRoute() {
18
19
  const {
19
20
  url
20
21
  } = request;
21
- (0, _debugLog.default)(`got GET to ${url}`);
22
+
23
+ if (log) {
24
+ log.debug(`got GET to ${url}`);
25
+ } else {
26
+ (0, _debugLog.default)(`got GET to ${url}`);
27
+ }
28
+
22
29
  return h.response(null).code(426);
23
30
  }
24
31
 
@@ -11,7 +11,7 @@ var id = 0;
11
11
 
12
12
  function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
13
13
 
14
- var _webSocketClients = _classPrivateFieldLooseKey("webSocketClients");
14
+ var _webSocketClients = /*#__PURE__*/_classPrivateFieldLooseKey("webSocketClients");
15
15
 
16
16
  class ConnectionsController {
17
17
  constructor(webSocketClients) {
@@ -11,7 +11,8 @@ var _debugLog = _interopRequireDefault(require("../../../../debugLog.js"));
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
- function connectionsRoutes(webSocketClients) {
14
+ function connectionsRoutes(webSocketClients, v3Utils) {
15
+ const log = v3Utils && v3Utils.log;
15
16
  const connectionsController = new _ConnectionsController.default(webSocketClients);
16
17
  return [{
17
18
  method: 'POST',
@@ -30,14 +31,25 @@ function connectionsRoutes(webSocketClients) {
30
31
  payload,
31
32
  url
32
33
  } = request;
33
- (0, _debugLog.default)(`got POST to ${url}`);
34
+
35
+ if (log) {
36
+ log.debug(`got POST to ${url}`);
37
+ } else {
38
+ (0, _debugLog.default)(`got POST to ${url}`);
39
+ }
40
+
34
41
  const clientExisted = await connectionsController.send(connectionId, payload);
35
42
 
36
43
  if (!clientExisted) {
37
44
  return h.response(null).code(410);
38
45
  }
39
46
 
40
- (0, _debugLog.default)(`sent data to connection:${connectionId}`);
47
+ if (log) {
48
+ log.debug(`sent data to connection:${connectionId}`);
49
+ } else {
50
+ (0, _debugLog.default)(`sent data to connection:${connectionId}`);
51
+ }
52
+
41
53
  return null;
42
54
  }
43
55
 
@@ -57,14 +69,25 @@ function connectionsRoutes(webSocketClients) {
57
69
  },
58
70
  url
59
71
  } = request;
60
- (0, _debugLog.default)(`got DELETE to ${url}`);
72
+
73
+ if (log) {
74
+ log.debug(`got DELETE to ${url}`);
75
+ } else {
76
+ (0, _debugLog.default)(`got DELETE to ${url}`);
77
+ }
78
+
61
79
  const clientExisted = connectionsController.remove(connectionId);
62
80
 
63
81
  if (!clientExisted) {
64
82
  return h.response(null).code(410);
65
83
  }
66
84
 
67
- (0, _debugLog.default)(`closed connection:${connectionId}`);
85
+ if (log) {
86
+ log.debug(`closed connection:${connectionId}`);
87
+ } else {
88
+ (0, _debugLog.default)(`closed connection:${connectionId}`);
89
+ }
90
+
68
91
  return h.response(null).code(204);
69
92
  }
70
93
 
@@ -17,15 +17,15 @@ var id = 0;
17
17
 
18
18
  function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
19
19
 
20
- var _connectionId = _classPrivateFieldLooseKey("connectionId");
20
+ var _connectionId = /*#__PURE__*/_classPrivateFieldLooseKey("connectionId");
21
21
 
22
- var _httpsProtocol = _classPrivateFieldLooseKey("httpsProtocol");
22
+ var _httpsProtocol = /*#__PURE__*/_classPrivateFieldLooseKey("httpsProtocol");
23
23
 
24
- var _rawHeaders = _classPrivateFieldLooseKey("rawHeaders");
24
+ var _rawHeaders = /*#__PURE__*/_classPrivateFieldLooseKey("rawHeaders");
25
25
 
26
- var _url = _classPrivateFieldLooseKey("url");
26
+ var _url = /*#__PURE__*/_classPrivateFieldLooseKey("url");
27
27
 
28
- var _websocketPort = _classPrivateFieldLooseKey("websocketPort");
28
+ var _websocketPort = /*#__PURE__*/_classPrivateFieldLooseKey("websocketPort");
29
29
 
30
30
  class WebSocketConnectEvent {
31
31
  constructor(connectionId, request, options) {
@@ -17,7 +17,7 @@ var id = 0;
17
17
 
18
18
  function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
19
19
 
20
- var _connectionId = _classPrivateFieldLooseKey("connectionId");
20
+ var _connectionId = /*#__PURE__*/_classPrivateFieldLooseKey("connectionId");
21
21
 
22
22
  class WebSocketDisconnectEvent {
23
23
  constructor(connectionId) {
@@ -15,11 +15,11 @@ var id = 0;
15
15
 
16
16
  function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
17
17
 
18
- var _connectionId = _classPrivateFieldLooseKey("connectionId");
18
+ var _connectionId = /*#__PURE__*/_classPrivateFieldLooseKey("connectionId");
19
19
 
20
- var _payload = _classPrivateFieldLooseKey("payload");
20
+ var _payload = /*#__PURE__*/_classPrivateFieldLooseKey("payload");
21
21
 
22
- var _route = _classPrivateFieldLooseKey("route");
22
+ var _route = /*#__PURE__*/_classPrivateFieldLooseKey("route");
23
23
 
24
24
  class WebSocketEvent {
25
25
  constructor(connectionId, route, payload) {
@@ -18,13 +18,13 @@ const {
18
18
  } = Date;
19
19
  const connectedAt = new Map();
20
20
 
21
- var _connectionId = _classPrivateFieldLooseKey("connectionId");
21
+ var _connectionId = /*#__PURE__*/_classPrivateFieldLooseKey("connectionId");
22
22
 
23
- var _eventType = _classPrivateFieldLooseKey("eventType");
23
+ var _eventType = /*#__PURE__*/_classPrivateFieldLooseKey("eventType");
24
24
 
25
- var _route = _classPrivateFieldLooseKey("route");
25
+ var _route = /*#__PURE__*/_classPrivateFieldLooseKey("route");
26
26
 
27
- var _connectedAt = _classPrivateFieldLooseKey("connectedAt");
27
+ var _connectedAt = /*#__PURE__*/_classPrivateFieldLooseKey("connectedAt");
28
28
 
29
29
  class WebSocketRequestContext {
30
30
  constructor(eventType, route, connectionId) {