serverless-offline 8.7.0 → 8.8.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.
- package/README.md +89 -93
- package/dist/ServerlessOffline.js +15 -8
- package/dist/config/supportedRuntimes.js +1 -1
- package/dist/debugLog.js +3 -1
- package/dist/events/{http/authValidateContext.js → authValidateContext.js} +8 -3
- package/dist/events/http/Endpoint.js +3 -1
- package/dist/events/http/HttpServer.js +27 -20
- package/dist/events/http/OfflineEndpoint.js +23 -25
- package/dist/events/http/createAuthScheme.js +1 -1
- package/dist/events/http/createJWTAuthScheme.js +6 -2
- package/dist/events/http/lambda-events/LambdaIntegrationEvent.js +4 -2
- package/dist/events/http/lambda-events/LambdaProxyIntegrationEvent.js +16 -14
- package/dist/events/http/lambda-events/LambdaProxyIntegrationEventV2.js +17 -13
- package/dist/events/http/lambda-events/VelocityContext.js +3 -1
- package/dist/events/http/lambda-events/renderVelocityTemplateObject.js +4 -1
- package/dist/events/schedule/Schedule.js +10 -9
- package/dist/events/websocket/HttpServer.js +3 -1
- package/dist/events/websocket/WebSocketClients.js +38 -11
- package/dist/events/websocket/WebSocketServer.js +5 -6
- package/dist/index.js +0 -4
- package/dist/lambda/HttpServer.js +3 -1
- package/dist/lambda/Lambda.js +5 -1
- package/dist/lambda/LambdaFunction.js +1 -2
- package/dist/lambda/handler-runner/HandlerRunner.js +1 -29
- package/dist/lambda/handler-runner/child-process-runner/ChildProcessRunner.js +1 -9
- package/dist/lambda/handler-runner/child-process-runner/childProcessHelper.js +15 -6
- package/dist/lambda/handler-runner/docker-runner/DockerContainer.js +2 -4
- package/dist/lambda/handler-runner/go-runner/GoRunner.js +34 -15
- package/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js +24 -30
- package/dist/lambda/handler-runner/java-runner/JavaRunner.js +3 -1
- package/dist/lambda/handler-runner/python-runner/PythonRunner.js +15 -10
- package/dist/lambda/handler-runner/ruby-runner/RubyRunner.js +3 -4
- package/dist/lambda/handler-runner/worker-thread-runner/WorkerThreadRunner.js +0 -2
- package/dist/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js +4 -3
- package/dist/utils/generateHapiPath.js +1 -1
- package/dist/utils/getHttpApiCorsConfig.js +4 -8
- package/dist/utils/index.js +11 -4
- package/dist/utils/lowerCaseKeys.js +14 -0
- package/dist/utils/resolveJoins.js +4 -2
- package/dist/utils/splitHandlerPathAndName.js +9 -13
- package/package.json +23 -26
- package/dist/checkEngine.js +0 -21
|
@@ -7,32 +7,30 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
class OfflineEndpoint {
|
|
9
9
|
constructor() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
'application/json': ''
|
|
18
|
-
},
|
|
19
|
-
responses: {
|
|
20
|
-
default: {
|
|
21
|
-
400: {
|
|
22
|
-
statusCode: '400'
|
|
23
|
-
},
|
|
24
|
-
responseModels: {
|
|
25
|
-
'application/json;charset=UTF-8': 'Empty'
|
|
26
|
-
},
|
|
27
|
-
responseParameters: {},
|
|
28
|
-
responseTemplates: {
|
|
29
|
-
'application/json;charset=UTF-8': ''
|
|
30
|
-
},
|
|
31
|
-
statusCode: 200
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
type: 'AWS'
|
|
10
|
+
this.apiKeyRequired = false;
|
|
11
|
+
this.authorizationType = 'none';
|
|
12
|
+
this.authorizerFunction = false;
|
|
13
|
+
this.path = '';
|
|
14
|
+
this.requestParameters = {};
|
|
15
|
+
this.requestTemplates = {
|
|
16
|
+
'application/json': ''
|
|
35
17
|
};
|
|
18
|
+
this.responses = {
|
|
19
|
+
default: {
|
|
20
|
+
400: {
|
|
21
|
+
statusCode: '400'
|
|
22
|
+
},
|
|
23
|
+
responseModels: {
|
|
24
|
+
'application/json;charset=UTF-8': 'Empty'
|
|
25
|
+
},
|
|
26
|
+
responseParameters: {},
|
|
27
|
+
responseTemplates: {
|
|
28
|
+
'application/json;charset=UTF-8': ''
|
|
29
|
+
},
|
|
30
|
+
statusCode: 200
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
this.type = 'AWS';
|
|
36
34
|
}
|
|
37
35
|
|
|
38
36
|
}
|
|
@@ -9,7 +9,7 @@ var _boom = _interopRequireDefault(require("@hapi/boom"));
|
|
|
9
9
|
|
|
10
10
|
var _authCanExecuteResource = _interopRequireDefault(require("../authCanExecuteResource.js"));
|
|
11
11
|
|
|
12
|
-
var _authValidateContext = _interopRequireDefault(require("
|
|
12
|
+
var _authValidateContext = _interopRequireDefault(require("../authValidateContext.js"));
|
|
13
13
|
|
|
14
14
|
var _debugLog = _interopRequireDefault(require("../../debugLog.js"));
|
|
15
15
|
|
|
@@ -13,6 +13,10 @@ var _serverlessLog = _interopRequireDefault(require("../../serverlessLog.js"));
|
|
|
13
13
|
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
15
|
|
|
16
|
+
const {
|
|
17
|
+
isArray
|
|
18
|
+
} = Array;
|
|
19
|
+
|
|
16
20
|
function createAuthScheme(jwtOptions, {
|
|
17
21
|
log
|
|
18
22
|
}) {
|
|
@@ -82,8 +86,8 @@ function createAuthScheme(jwtOptions, {
|
|
|
82
86
|
return _boom.default.unauthorized('JWT Token not from correct issuer url');
|
|
83
87
|
}
|
|
84
88
|
|
|
85
|
-
const validAudiences =
|
|
86
|
-
const providedAudiences =
|
|
89
|
+
const validAudiences = isArray(jwtOptions.audience) ? jwtOptions.audience : [jwtOptions.audience];
|
|
90
|
+
const providedAudiences = isArray(aud) ? aud : [aud];
|
|
87
91
|
const validAudienceProvided = providedAudiences.some(a => validAudiences.includes(a));
|
|
88
92
|
|
|
89
93
|
if (!validAudienceProvided && !validAudiences.includes(clientId)) {
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _process = require("process");
|
|
9
|
+
|
|
8
10
|
var _renderVelocityTemplateObject = _interopRequireDefault(require("./renderVelocityTemplateObject.js"));
|
|
9
11
|
|
|
10
12
|
var _VelocityContext = _interopRequireDefault(require("./VelocityContext.js"));
|
|
@@ -55,9 +57,9 @@ class LambdaIntegrationEvent {
|
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
create() {
|
|
58
|
-
if (
|
|
60
|
+
if (_process.env.AUTHORIZER) {
|
|
59
61
|
try {
|
|
60
|
-
const authorizerContext = parse(
|
|
62
|
+
const authorizerContext = parse(_process.env.AUTHORIZER);
|
|
61
63
|
|
|
62
64
|
if (authorizerContext) {
|
|
63
65
|
_classPrivateFieldLooseBase(this, _request)[_request].auth = { ..._classPrivateFieldLooseBase(this, _request)[_request].auth,
|
|
@@ -7,6 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _buffer = require("buffer");
|
|
9
9
|
|
|
10
|
+
var _process = require("process");
|
|
11
|
+
|
|
10
12
|
var _jsonwebtoken = require("jsonwebtoken");
|
|
11
13
|
|
|
12
14
|
var _index = require("../../../utils/index.js");
|
|
@@ -42,7 +44,7 @@ var _stageVariables = /*#__PURE__*/_classPrivateFieldLooseKey("stageVariables");
|
|
|
42
44
|
var _additionalRequestContext = /*#__PURE__*/_classPrivateFieldLooseKey("additionalRequestContext");
|
|
43
45
|
|
|
44
46
|
class LambdaProxyIntegrationEvent {
|
|
45
|
-
constructor(request, stage, path, stageVariables, routeKey
|
|
47
|
+
constructor(request, stage, path, stageVariables, routeKey, additionalRequestContext, v3Utils) {
|
|
46
48
|
Object.defineProperty(this, _path, {
|
|
47
49
|
writable: true,
|
|
48
50
|
value: null
|
|
@@ -88,14 +90,14 @@ class LambdaProxyIntegrationEvent {
|
|
|
88
90
|
const authContext = _classPrivateFieldLooseBase(this, _request)[_request].auth && _classPrivateFieldLooseBase(this, _request)[_request].auth.credentials && _classPrivateFieldLooseBase(this, _request)[_request].auth.credentials.context || {};
|
|
89
91
|
let authAuthorizer;
|
|
90
92
|
|
|
91
|
-
if (
|
|
93
|
+
if (_process.env.AUTHORIZER) {
|
|
92
94
|
try {
|
|
93
|
-
authAuthorizer = parse(
|
|
95
|
+
authAuthorizer = parse(_process.env.AUTHORIZER);
|
|
94
96
|
} catch (error) {
|
|
95
97
|
if (this.log) {
|
|
96
|
-
this.log.error('Could not parse
|
|
98
|
+
this.log.error('Could not parse env.AUTHORIZER, make sure it is correct JSON');
|
|
97
99
|
} else {
|
|
98
|
-
console.error('Serverless-offline: Could not parse
|
|
100
|
+
console.error('Serverless-offline: Could not parse env.AUTHORIZER, make sure it is correct JSON.');
|
|
99
101
|
}
|
|
100
102
|
}
|
|
101
103
|
}
|
|
@@ -201,7 +203,7 @@ class LambdaProxyIntegrationEvent {
|
|
|
201
203
|
claims,
|
|
202
204
|
scopes,
|
|
203
205
|
// 'principalId' should have higher priority
|
|
204
|
-
principalId: authPrincipalId ||
|
|
206
|
+
principalId: authPrincipalId || _process.env.PRINCIPAL_ID || 'offlineContext_authorizer_principalId' // See #24
|
|
205
207
|
|
|
206
208
|
}),
|
|
207
209
|
domainName: 'offlineContext_domainName',
|
|
@@ -210,14 +212,14 @@ class LambdaProxyIntegrationEvent {
|
|
|
210
212
|
httpMethod,
|
|
211
213
|
identity: {
|
|
212
214
|
accessKey: null,
|
|
213
|
-
accountId:
|
|
214
|
-
apiKey:
|
|
215
|
-
apiKeyId:
|
|
216
|
-
caller:
|
|
217
|
-
cognitoAuthenticationProvider: _headers['cognito-authentication-provider'] ||
|
|
218
|
-
cognitoAuthenticationType:
|
|
219
|
-
cognitoIdentityId: _headers['cognito-identity-id'] ||
|
|
220
|
-
cognitoIdentityPoolId:
|
|
215
|
+
accountId: _process.env.SLS_ACCOUNT_ID || 'offlineContext_accountId',
|
|
216
|
+
apiKey: _process.env.SLS_API_KEY || 'offlineContext_apiKey',
|
|
217
|
+
apiKeyId: _process.env.SLS_API_KEY_ID || 'offlineContext_apiKeyId',
|
|
218
|
+
caller: _process.env.SLS_CALLER || 'offlineContext_caller',
|
|
219
|
+
cognitoAuthenticationProvider: _headers['cognito-authentication-provider'] || _process.env.SLS_COGNITO_AUTHENTICATION_PROVIDER || 'offlineContext_cognitoAuthenticationProvider',
|
|
220
|
+
cognitoAuthenticationType: _process.env.SLS_COGNITO_AUTHENTICATION_TYPE || 'offlineContext_cognitoAuthenticationType',
|
|
221
|
+
cognitoIdentityId: _headers['cognito-identity-id'] || _process.env.SLS_COGNITO_IDENTITY_ID || 'offlineContext_cognitoIdentityId',
|
|
222
|
+
cognitoIdentityPoolId: _process.env.SLS_COGNITO_IDENTITY_POOL_ID || 'offlineContext_cognitoIdentityPoolId',
|
|
221
223
|
principalOrgId: null,
|
|
222
224
|
sourceIp: remoteAddress,
|
|
223
225
|
user: 'offlineContext_user',
|
|
@@ -7,6 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _buffer = require("buffer");
|
|
9
9
|
|
|
10
|
+
var _process = require("process");
|
|
11
|
+
|
|
10
12
|
var _jsonwebtoken = require("jsonwebtoken");
|
|
11
13
|
|
|
12
14
|
var _index = require("../../../utils/index.js");
|
|
@@ -18,13 +20,15 @@ var id = 0;
|
|
|
18
20
|
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
19
21
|
|
|
20
22
|
const {
|
|
21
|
-
|
|
22
|
-
} =
|
|
23
|
+
isArray
|
|
24
|
+
} = Array;
|
|
23
25
|
const {
|
|
24
26
|
parse
|
|
25
27
|
} = JSON;
|
|
26
28
|
const {
|
|
27
|
-
assign
|
|
29
|
+
assign,
|
|
30
|
+
entries,
|
|
31
|
+
fromEntries
|
|
28
32
|
} = Object; // https://www.serverless.com/framework/docs/providers/aws/events/http-api/
|
|
29
33
|
// https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
30
34
|
|
|
@@ -78,9 +82,9 @@ class LambdaProxyIntegrationEventV2 {
|
|
|
78
82
|
const authContext = _classPrivateFieldLooseBase(this, _request)[_request].auth && _classPrivateFieldLooseBase(this, _request)[_request].auth.credentials && _classPrivateFieldLooseBase(this, _request)[_request].auth.credentials.context || {};
|
|
79
83
|
let authAuthorizer;
|
|
80
84
|
|
|
81
|
-
if (
|
|
85
|
+
if (_process.env.AUTHORIZER) {
|
|
82
86
|
try {
|
|
83
|
-
authAuthorizer = parse(
|
|
87
|
+
authAuthorizer = parse(_process.env.AUTHORIZER);
|
|
84
88
|
} catch (error) {
|
|
85
89
|
if (this.log) {
|
|
86
90
|
this.log.error('Could not parse process.env.AUTHORIZER, make sure it is correct JSON');
|
|
@@ -97,7 +101,7 @@ class LambdaProxyIntegrationEventV2 {
|
|
|
97
101
|
} = _classPrivateFieldLooseBase(this, _request)[_request].raw.req; // NOTE FIXME request.raw.req.rawHeaders can only be null for testing (hapi shot inject())
|
|
98
102
|
|
|
99
103
|
|
|
100
|
-
const headers = (0, _index.parseHeaders)(rawHeaders || []) || {};
|
|
104
|
+
const headers = (0, _index.lowerCaseKeys)((0, _index.parseHeaders)(rawHeaders || [])) || {};
|
|
101
105
|
|
|
102
106
|
if (headers['sls-offline-authorizer-override']) {
|
|
103
107
|
try {
|
|
@@ -117,13 +121,13 @@ class LambdaProxyIntegrationEventV2 {
|
|
|
117
121
|
body = _classPrivateFieldLooseBase(this, _request)[_request].rawPayload;
|
|
118
122
|
}
|
|
119
123
|
|
|
120
|
-
if (!headers['
|
|
121
|
-
headers['
|
|
124
|
+
if (!headers['content-length'] && (typeof body === 'string' || body instanceof _buffer.Buffer || body instanceof ArrayBuffer)) {
|
|
125
|
+
headers['content-length'] = String(_buffer.Buffer.byteLength(body));
|
|
122
126
|
} // Set a default Content-Type if not provided.
|
|
123
127
|
|
|
124
128
|
|
|
125
|
-
if (!headers['
|
|
126
|
-
headers['
|
|
129
|
+
if (!headers['content-type']) {
|
|
130
|
+
headers['content-type'] = 'application/json';
|
|
127
131
|
}
|
|
128
132
|
} else if (typeof body === 'undefined' || body === '') {
|
|
129
133
|
body = null;
|
|
@@ -169,8 +173,8 @@ class LambdaProxyIntegrationEventV2 {
|
|
|
169
173
|
const httpMethod = method.toUpperCase();
|
|
170
174
|
const requestTime = (0, _index.formatToClfTime)(received);
|
|
171
175
|
const requestTimeEpoch = received;
|
|
172
|
-
const cookies =
|
|
173
|
-
if (
|
|
176
|
+
const cookies = entries(_classPrivateFieldLooseBase(this, _request)[_request].state).flatMap(([key, value]) => {
|
|
177
|
+
if (isArray(value)) {
|
|
174
178
|
return value.map(v => `${key}=${v}`);
|
|
175
179
|
}
|
|
176
180
|
|
|
@@ -183,7 +187,7 @@ class LambdaProxyIntegrationEventV2 {
|
|
|
183
187
|
rawQueryString: _classPrivateFieldLooseBase(this, _request)[_request].url.searchParams.toString(),
|
|
184
188
|
cookies,
|
|
185
189
|
headers,
|
|
186
|
-
queryStringParameters: _classPrivateFieldLooseBase(this, _request)[_request].url.search ?
|
|
190
|
+
queryStringParameters: _classPrivateFieldLooseBase(this, _request)[_request].url.search ? fromEntries(Array.from(_classPrivateFieldLooseBase(this, _request)[_request].url.searchParams)) : null,
|
|
187
191
|
requestContext: {
|
|
188
192
|
accountId: 'offlineContext_accountId',
|
|
189
193
|
apiId: 'offlineContext_apiId',
|
|
@@ -7,6 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _buffer = require("buffer");
|
|
9
9
|
|
|
10
|
+
var _process = require("process");
|
|
11
|
+
|
|
10
12
|
var _jsStringEscape = _interopRequireDefault(require("js-string-escape"));
|
|
11
13
|
|
|
12
14
|
var _jsonwebtoken = require("jsonwebtoken");
|
|
@@ -102,7 +104,7 @@ class VelocityContext {
|
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
if (!authorizer) authorizer = {};
|
|
105
|
-
authorizer.principalId = authPrincipalId ||
|
|
107
|
+
authorizer.principalId = authPrincipalId || _process.env.PRINCIPAL_ID || 'offlineContext_authorizer_principalId'; // See #24
|
|
106
108
|
|
|
107
109
|
if (token) {
|
|
108
110
|
try {
|
|
@@ -15,6 +15,9 @@ var _index = require("../../../utils/index.js");
|
|
|
15
15
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
|
|
18
|
+
const {
|
|
19
|
+
parse
|
|
20
|
+
} = JSON;
|
|
18
21
|
const {
|
|
19
22
|
entries
|
|
20
23
|
} = Object;
|
|
@@ -23,7 +26,7 @@ function tryToParseJSON(string) {
|
|
|
23
26
|
let parsed;
|
|
24
27
|
|
|
25
28
|
try {
|
|
26
|
-
parsed =
|
|
29
|
+
parsed = parse(string);
|
|
27
30
|
} catch (err) {// nothing! Some things are not meant to be parsed.
|
|
28
31
|
}
|
|
29
32
|
|
|
@@ -19,7 +19,7 @@ var id = 0;
|
|
|
19
19
|
|
|
20
20
|
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
const CRON_LENGTH_WITH_YEAR = 6;
|
|
23
23
|
const {
|
|
24
24
|
stringify
|
|
25
25
|
} = JSON;
|
|
@@ -106,14 +106,15 @@ class Schedule {
|
|
|
106
106
|
}
|
|
107
107
|
});
|
|
108
108
|
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
// }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
_convertCronSyntax(cronString) {
|
|
112
|
+
if (cronString.split(' ').length < CRON_LENGTH_WITH_YEAR) {
|
|
113
|
+
return cronString;
|
|
114
|
+
}
|
|
116
115
|
|
|
116
|
+
return cronString.replace(/\s\S+$/, '');
|
|
117
|
+
}
|
|
117
118
|
|
|
118
119
|
_convertRateToCron(rate) {
|
|
119
120
|
const [number, unit] = rate.split(' ');
|
|
@@ -146,7 +147,7 @@ class Schedule {
|
|
|
146
147
|
const params = scheduleEvent.replace('rate(', '').replace('cron(', '').replace(')', '');
|
|
147
148
|
|
|
148
149
|
if (scheduleEvent.startsWith('cron(')) {
|
|
149
|
-
|
|
150
|
+
return this._convertCronSyntax(params);
|
|
150
151
|
}
|
|
151
152
|
|
|
152
153
|
if (scheduleEvent.startsWith('rate(')) {
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _process = require("process");
|
|
9
|
+
|
|
8
10
|
var _hapi = require("@hapi/hapi");
|
|
9
11
|
|
|
10
12
|
var _index = require("./http-routes/index.js");
|
|
@@ -86,7 +88,7 @@ class HttpServer {
|
|
|
86
88
|
console.error(`Unexpected error while starting serverless-offline websocket server on port ${websocketPort}:`, err);
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
|
|
91
|
+
(0, _process.exit)(1);
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
if (this.log) {
|
|
@@ -7,6 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _ws = require("ws");
|
|
9
9
|
|
|
10
|
+
var _boom = require("@hapi/boom");
|
|
11
|
+
|
|
10
12
|
var _index = require("./lambda-events/index.js");
|
|
11
13
|
|
|
12
14
|
var _debugLog = _interopRequireDefault(require("../../debugLog.js"));
|
|
@@ -21,6 +23,8 @@ var _authFunctionNameExtractor = _interopRequireDefault(require("../authFunction
|
|
|
21
23
|
|
|
22
24
|
var _authCanExecuteResource = _interopRequireDefault(require("../authCanExecuteResource.js"));
|
|
23
25
|
|
|
26
|
+
var _authValidateContext = _interopRequireDefault(require("../authValidateContext.js"));
|
|
27
|
+
|
|
24
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
29
|
|
|
26
30
|
function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
|
|
@@ -254,6 +258,9 @@ class WebSocketClients {
|
|
|
254
258
|
(0, _serverlessLog.default)(`Authorization function returned a successful response: (λ: ${authFunName})`);
|
|
255
259
|
}
|
|
256
260
|
|
|
261
|
+
const validatedContext = (0, _authValidateContext.default)(policy.context, authorizerFunction);
|
|
262
|
+
if (validatedContext instanceof Error) throw validatedContext;
|
|
263
|
+
|
|
257
264
|
_classPrivateFieldLooseBase(this, _webSocketAuthorizersCache)[_webSocketAuthorizersCache].set(connectionId, {
|
|
258
265
|
identity: {
|
|
259
266
|
apiKey: policy.usageIdentifierKey,
|
|
@@ -263,7 +270,7 @@ class WebSocketClients {
|
|
|
263
270
|
authorizer: {
|
|
264
271
|
integrationLatency: '42',
|
|
265
272
|
principalId: policy.principalId,
|
|
266
|
-
...
|
|
273
|
+
...validatedContext
|
|
267
274
|
}
|
|
268
275
|
});
|
|
269
276
|
} catch (err) {
|
|
@@ -273,9 +280,19 @@ class WebSocketClients {
|
|
|
273
280
|
(0, _debugLog.default)(`Error in route handler '${routeName}' authorizer`, err);
|
|
274
281
|
}
|
|
275
282
|
|
|
283
|
+
let headers = [];
|
|
284
|
+
let message;
|
|
285
|
+
|
|
286
|
+
if ((0, _boom.isBoom)(err)) {
|
|
287
|
+
headers = err.output.headers;
|
|
288
|
+
message = err.output.payload.message;
|
|
289
|
+
}
|
|
290
|
+
|
|
276
291
|
return {
|
|
277
292
|
verified: false,
|
|
278
|
-
statusCode: 500
|
|
293
|
+
statusCode: 500,
|
|
294
|
+
headers,
|
|
295
|
+
message
|
|
279
296
|
};
|
|
280
297
|
}
|
|
281
298
|
}
|
|
@@ -283,8 +300,8 @@ class WebSocketClients {
|
|
|
283
300
|
const authorizerData = _classPrivateFieldLooseBase(this, _webSocketAuthorizersCache)[_webSocketAuthorizersCache].get(connectionId);
|
|
284
301
|
|
|
285
302
|
if (authorizerData) {
|
|
286
|
-
connectEvent.identity = authorizerData.identity;
|
|
287
|
-
connectEvent.authorizer = authorizerData.authorizer;
|
|
303
|
+
connectEvent.requestContext.identity = authorizerData.identity;
|
|
304
|
+
connectEvent.requestContext.authorizer = authorizerData.authorizer;
|
|
288
305
|
}
|
|
289
306
|
|
|
290
307
|
const lambdaFunction = _classPrivateFieldLooseBase(this, _lambda)[_lambda].get(route.functionKey);
|
|
@@ -343,9 +360,19 @@ class WebSocketClients {
|
|
|
343
360
|
}
|
|
344
361
|
};
|
|
345
362
|
|
|
363
|
+
const authorizerData = _classPrivateFieldLooseBase(this, _webSocketAuthorizersCache)[_webSocketAuthorizersCache].get(connectionId);
|
|
364
|
+
|
|
365
|
+
let authorizedEvent;
|
|
366
|
+
|
|
367
|
+
if (authorizerData) {
|
|
368
|
+
authorizedEvent = event;
|
|
369
|
+
authorizedEvent.requestContext.identity = authorizerData.identity;
|
|
370
|
+
authorizedEvent.requestContext.authorizer = authorizerData.authorizer;
|
|
371
|
+
}
|
|
372
|
+
|
|
346
373
|
const lambdaFunction = _classPrivateFieldLooseBase(this, _lambda)[_lambda].get(route.functionKey);
|
|
347
374
|
|
|
348
|
-
lambdaFunction.setEvent(event);
|
|
375
|
+
lambdaFunction.setEvent(authorizedEvent || event);
|
|
349
376
|
|
|
350
377
|
try {
|
|
351
378
|
const {
|
|
@@ -410,8 +437,8 @@ class WebSocketClients {
|
|
|
410
437
|
const authorizerData = _classPrivateFieldLooseBase(this, _webSocketAuthorizersCache)[_webSocketAuthorizersCache].get(connectionId);
|
|
411
438
|
|
|
412
439
|
if (authorizerData) {
|
|
413
|
-
disconnectEvent.identity = authorizerData.identity;
|
|
414
|
-
disconnectEvent.authorizer = authorizerData.authorizer;
|
|
440
|
+
disconnectEvent.requestContext.identity = authorizerData.identity;
|
|
441
|
+
disconnectEvent.requestContext.authorizer = authorizerData.authorizer;
|
|
415
442
|
}
|
|
416
443
|
|
|
417
444
|
this._processEvent(webSocketClient, connectionId, '$disconnect', disconnectEvent).finally(() => _classPrivateFieldLooseBase(this, _webSocketAuthorizersCache)[_webSocketAuthorizersCache].delete(connectionId));
|
|
@@ -436,8 +463,8 @@ class WebSocketClients {
|
|
|
436
463
|
const authorizerData = _classPrivateFieldLooseBase(this, _webSocketAuthorizersCache)[_webSocketAuthorizersCache].get(connectionId);
|
|
437
464
|
|
|
438
465
|
if (authorizerData) {
|
|
439
|
-
event.identity = authorizerData.identity;
|
|
440
|
-
event.authorizer = authorizerData.authorizer;
|
|
466
|
+
event.requestContext.identity = authorizerData.identity;
|
|
467
|
+
event.requestContext.authorizer = authorizerData.authorizer;
|
|
441
468
|
}
|
|
442
469
|
|
|
443
470
|
this._onWebSocketUsed(connectionId);
|
|
@@ -515,9 +542,9 @@ class WebSocketClients {
|
|
|
515
542
|
}
|
|
516
543
|
|
|
517
544
|
if (this.log) {
|
|
518
|
-
this.log.notice(`route '${definition}'`);
|
|
545
|
+
this.log.notice(`route '${definition.route} (λ: ${functionKey})'`);
|
|
519
546
|
} else {
|
|
520
|
-
(0, _serverlessLog.default)(`route '${definition}'`);
|
|
547
|
+
(0, _serverlessLog.default)(`route '${definition.route} (λ: ${functionKey})'`);
|
|
521
548
|
}
|
|
522
549
|
}
|
|
523
550
|
|
|
@@ -57,10 +57,7 @@ class WebSocketServer {
|
|
|
57
57
|
req
|
|
58
58
|
}, cb) => {
|
|
59
59
|
const connectionId = (0, _index.createUniqueId)();
|
|
60
|
-
const
|
|
61
|
-
headers
|
|
62
|
-
} = req;
|
|
63
|
-
const key = headers['sec-websocket-key'];
|
|
60
|
+
const key = req.headers['sec-websocket-key'];
|
|
64
61
|
|
|
65
62
|
if (this.log) {
|
|
66
63
|
this.log.debug(`verifyClient:${key} ${connectionId}`);
|
|
@@ -73,11 +70,13 @@ class WebSocketServer {
|
|
|
73
70
|
|
|
74
71
|
_classPrivateFieldLooseBase(this, _webSocketClients)[_webSocketClients].verifyClient(connectionId, req).then(({
|
|
75
72
|
verified,
|
|
76
|
-
statusCode
|
|
73
|
+
statusCode,
|
|
74
|
+
message,
|
|
75
|
+
headers
|
|
77
76
|
}) => {
|
|
78
77
|
try {
|
|
79
78
|
if (!verified) {
|
|
80
|
-
cb(false, statusCode);
|
|
79
|
+
cb(false, statusCode, message, headers);
|
|
81
80
|
return;
|
|
82
81
|
}
|
|
83
82
|
|
package/dist/index.js
CHANGED
|
@@ -10,10 +10,6 @@ Object.defineProperty(exports, "default", {
|
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
require("./checkEngine.js");
|
|
14
|
-
|
|
15
|
-
require("object.fromentries/auto.js");
|
|
16
|
-
|
|
17
13
|
var _ServerlessOffline = _interopRequireDefault(require("./ServerlessOffline.js"));
|
|
18
14
|
|
|
19
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -7,6 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _hapi = require("@hapi/hapi");
|
|
9
9
|
|
|
10
|
+
var _process = require("process");
|
|
11
|
+
|
|
10
12
|
var _index = require("./routes/index.js");
|
|
11
13
|
|
|
12
14
|
var _serverlessLog = _interopRequireDefault(require("../serverlessLog.js"));
|
|
@@ -85,7 +87,7 @@ class HttpServer {
|
|
|
85
87
|
console.error(`Unexpected error while starting serverless-offline lambda server on port ${lambdaPort}:`, err);
|
|
86
88
|
}
|
|
87
89
|
|
|
88
|
-
|
|
90
|
+
(0, _process.exit)(1);
|
|
89
91
|
}
|
|
90
92
|
|
|
91
93
|
if (this.log) {
|
package/dist/lambda/Lambda.js
CHANGED
|
@@ -17,6 +17,10 @@ var id = 0;
|
|
|
17
17
|
|
|
18
18
|
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
|
|
19
19
|
|
|
20
|
+
const {
|
|
21
|
+
assign
|
|
22
|
+
} = Object;
|
|
23
|
+
|
|
20
24
|
var _httpServer = /*#__PURE__*/_classPrivateFieldLooseKey("httpServer");
|
|
21
25
|
|
|
22
26
|
var _lambdas = /*#__PURE__*/_classPrivateFieldLooseKey("lambdas");
|
|
@@ -88,7 +92,7 @@ class Lambda {
|
|
|
88
92
|
}
|
|
89
93
|
|
|
90
94
|
listFunctionNamePairs() {
|
|
91
|
-
const funcNamePairs = Array.from(_classPrivateFieldLooseBase(this, _lambdaFunctionNamesKeys)[_lambdaFunctionNamesKeys]).reduce((obj, [key, value]) =>
|
|
95
|
+
const funcNamePairs = Array.from(_classPrivateFieldLooseBase(this, _lambdaFunctionNamesKeys)[_lambdaFunctionNamesKeys]).reduce((obj, [key, value]) => assign(obj, {
|
|
92
96
|
[key]: value
|
|
93
97
|
}), // Be careful! Maps can have non-String keys; object literals can't.
|
|
94
98
|
{});
|
|
@@ -177,7 +177,7 @@ class LambdaFunction {
|
|
|
177
177
|
name,
|
|
178
178
|
package: functionPackage = {}
|
|
179
179
|
} = functionDefinition;
|
|
180
|
-
const [handlerPath, handlerName
|
|
180
|
+
const [handlerPath, handlerName] = (0, _index3.splitHandlerPathAndName)(handler);
|
|
181
181
|
const memorySize = functionDefinition.memorySize || provider.memorySize || _index2.DEFAULT_LAMBDA_MEMORY_SIZE;
|
|
182
182
|
const runtime = functionDefinition.runtime || provider.runtime || _index2.DEFAULT_LAMBDA_RUNTIME;
|
|
183
183
|
const timeout = (functionDefinition.timeout || provider.timeout || _index2.DEFAULT_LAMBDA_TIMEOUT) * 1000; // this._executionTimeout = null
|
|
@@ -212,7 +212,6 @@ class LambdaFunction {
|
|
|
212
212
|
functionKey,
|
|
213
213
|
handler,
|
|
214
214
|
handlerName,
|
|
215
|
-
handlerModuleNesting,
|
|
216
215
|
codeDir: _classPrivateFieldLooseBase(this, _codeDir)[_codeDir],
|
|
217
216
|
handlerPath: (0, _path.resolve)(_classPrivateFieldLooseBase(this, _codeDir)[_codeDir], handlerPath),
|
|
218
217
|
runtime,
|
|
@@ -11,8 +11,6 @@ var _serverlessLog = require("../../serverlessLog.js");
|
|
|
11
11
|
|
|
12
12
|
var _index = require("../../config/index.js");
|
|
13
13
|
|
|
14
|
-
var _index2 = require("../../utils/index.js");
|
|
15
|
-
|
|
16
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
15
|
|
|
18
16
|
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); }
|
|
@@ -75,7 +73,6 @@ class HandlerRunner {
|
|
|
75
73
|
functionKey,
|
|
76
74
|
handlerName,
|
|
77
75
|
handlerPath,
|
|
78
|
-
handlerModuleNesting,
|
|
79
76
|
runtime,
|
|
80
77
|
timeout
|
|
81
78
|
} = _classPrivateFieldLooseBase(this, _funOptions)[_funOptions];
|
|
@@ -130,9 +127,6 @@ class HandlerRunner {
|
|
|
130
127
|
}
|
|
131
128
|
|
|
132
129
|
if (useWorkerThreads) {
|
|
133
|
-
// worker threads
|
|
134
|
-
this._verifyWorkerThreadCompatibility();
|
|
135
|
-
|
|
136
130
|
const {
|
|
137
131
|
default: WorkerThreadRunner
|
|
138
132
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./worker-thread-runner/index.js')));
|
|
@@ -142,7 +136,7 @@ class HandlerRunner {
|
|
|
142
136
|
const {
|
|
143
137
|
default: InProcessRunner
|
|
144
138
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./in-process-runner/index.js')));
|
|
145
|
-
return new InProcessRunner(functionKey, handlerPath, handlerName,
|
|
139
|
+
return new InProcessRunner(functionKey, handlerPath, handlerName, _classPrivateFieldLooseBase(this, _env)[_env], timeout, allowCache);
|
|
146
140
|
}
|
|
147
141
|
|
|
148
142
|
if (_index.supportedGo.has(runtime)) {
|
|
@@ -175,28 +169,6 @@ class HandlerRunner {
|
|
|
175
169
|
|
|
176
170
|
|
|
177
171
|
throw new Error('Unsupported runtime');
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
_verifyWorkerThreadCompatibility() {
|
|
181
|
-
const {
|
|
182
|
-
node: currentVersion
|
|
183
|
-
} = process.versions;
|
|
184
|
-
const requiredVersionRange = '>=11.7.0';
|
|
185
|
-
const versionIsSatisfied = (0, _index2.satisfiesVersionRange)(currentVersion, requiredVersionRange); // we're happy
|
|
186
|
-
|
|
187
|
-
if (!versionIsSatisfied) {
|
|
188
|
-
if (this.log) {
|
|
189
|
-
this.log.warning(`"worker threads" require node.js version ${requiredVersionRange}, but found version ${currentVersion}.
|
|
190
|
-
To use this feature you have to update node.js to a later version.
|
|
191
|
-
`);
|
|
192
|
-
} else {
|
|
193
|
-
(0, _serverlessLog.logWarning)(`"worker threads" require node.js version ${requiredVersionRange}, but found version ${currentVersion}.
|
|
194
|
-
To use this feature you have to update node.js to a later version.
|
|
195
|
-
`);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
throw new Error('"worker threads" are not supported with this node.js version');
|
|
199
|
-
}
|
|
200
172
|
} // TEMP TODO FIXME
|
|
201
173
|
|
|
202
174
|
|