serverless-offline 8.8.1 → 9.0.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 +3 -3
- package/package.json +33 -57
- package/src/ServerlessOffline.js +412 -0
- package/src/config/commandOptions.js +155 -0
- package/src/config/constants.js +22 -0
- package/{dist → src}/config/defaultOptions.js +8 -17
- package/src/config/index.js +4 -0
- package/src/config/supportedRuntimes.js +47 -0
- package/src/events/authCanExecuteResource.js +35 -0
- package/src/events/authFunctionNameExtractor.js +75 -0
- package/src/events/authMatchPolicyResource.js +71 -0
- package/src/events/authValidateContext.js +51 -0
- package/src/events/http/Endpoint.js +135 -0
- package/src/events/http/Http.js +50 -0
- package/src/events/http/HttpEventDefinition.js +20 -0
- package/src/events/http/HttpServer.js +1277 -0
- package/src/events/http/OfflineEndpoint.js +33 -0
- package/src/events/http/authJWTSettingsExtractor.js +70 -0
- package/src/events/http/createAuthScheme.js +176 -0
- package/src/events/http/createJWTAuthScheme.js +106 -0
- package/src/events/http/index.js +1 -0
- package/src/events/http/javaHelpers.js +102 -0
- package/src/events/http/lambda-events/LambdaIntegrationEvent.js +57 -0
- package/src/events/http/lambda-events/LambdaProxyIntegrationEvent.js +233 -0
- package/src/events/http/lambda-events/LambdaProxyIntegrationEventV2.js +190 -0
- package/src/events/http/lambda-events/VelocityContext.js +147 -0
- package/src/events/http/lambda-events/index.js +4 -0
- package/src/events/http/lambda-events/renderVelocityTemplateObject.js +93 -0
- package/{dist → src}/events/http/parseResources.js +73 -78
- package/src/events/http/payloadSchemaValidator.js +13 -0
- package/{dist → src}/events/http/templates/offline-default.req.vm +0 -0
- package/{dist → src}/events/http/templates/offline-default.res.vm +0 -0
- package/src/events/schedule/Schedule.js +131 -0
- package/src/events/schedule/ScheduleEvent.js +18 -0
- package/src/events/schedule/ScheduleEventDefinition.js +21 -0
- package/src/events/schedule/index.js +1 -0
- package/src/events/websocket/HttpServer.js +69 -0
- package/src/events/websocket/WebSocket.js +52 -0
- package/src/events/websocket/WebSocketClients.js +462 -0
- package/src/events/websocket/WebSocketEventDefinition.js +18 -0
- package/src/events/websocket/WebSocketServer.js +73 -0
- package/src/events/websocket/http-routes/_catchAll/catchAllRoute.js +16 -0
- package/src/events/websocket/http-routes/_catchAll/index.js +1 -0
- package/src/events/websocket/http-routes/connections/ConnectionsController.js +28 -0
- package/src/events/websocket/http-routes/connections/connectionsRoutes.js +70 -0
- package/src/events/websocket/http-routes/connections/index.js +1 -0
- package/src/events/websocket/http-routes/index.js +2 -0
- package/src/events/websocket/index.js +1 -0
- package/src/events/websocket/lambda-events/WebSocketAuthorizerEvent.js +65 -0
- package/src/events/websocket/lambda-events/WebSocketConnectEvent.js +68 -0
- package/src/events/websocket/lambda-events/WebSocketDisconnectEvent.js +31 -0
- package/src/events/websocket/lambda-events/WebSocketEvent.js +29 -0
- package/src/events/websocket/lambda-events/WebSocketRequestContext.js +67 -0
- package/src/events/websocket/lambda-events/index.js +4 -0
- package/src/index.js +12 -0
- package/src/lambda/HttpServer.js +108 -0
- package/src/lambda/Lambda.js +68 -0
- package/src/lambda/LambdaContext.js +33 -0
- package/src/lambda/LambdaFunction.js +308 -0
- package/src/lambda/LambdaFunctionPool.js +109 -0
- package/src/lambda/__tests__/LambdaContext.test.js +30 -0
- package/src/lambda/__tests__/LambdaFunction.test.js +196 -0
- package/src/lambda/__tests__/fixtures/Lambda/LambdaFunctionThatReturnsJSONObject.fixture.js +47 -0
- package/src/lambda/__tests__/fixtures/Lambda/LambdaFunctionThatReturnsNativeString.fixture.js +46 -0
- package/src/lambda/__tests__/fixtures/Lambda/package.json +3 -0
- package/src/lambda/__tests__/fixtures/lambdaFunction.fixture.js +145 -0
- package/src/lambda/__tests__/fixtures/package.json +3 -0
- package/src/lambda/__tests__/routes/invocations/InvocationsController.test.js +42 -0
- package/src/lambda/handler-runner/HandlerRunner.js +136 -0
- package/src/lambda/handler-runner/child-process-runner/ChildProcessRunner.js +72 -0
- package/src/lambda/handler-runner/child-process-runner/childProcessHelper.js +42 -0
- package/src/lambda/handler-runner/child-process-runner/index.js +1 -0
- package/src/lambda/handler-runner/docker-runner/DockerContainer.js +417 -0
- package/src/lambda/handler-runner/docker-runner/DockerImage.js +35 -0
- package/src/lambda/handler-runner/docker-runner/DockerRunner.js +63 -0
- package/src/lambda/handler-runner/docker-runner/index.js +1 -0
- package/src/lambda/handler-runner/go-runner/GoRunner.js +166 -0
- package/src/lambda/handler-runner/go-runner/index.js +1 -0
- package/src/lambda/handler-runner/in-process-runner/InProcessRunner.js +125 -0
- package/src/lambda/handler-runner/in-process-runner/index.js +1 -0
- package/src/lambda/handler-runner/index.js +1 -0
- package/src/lambda/handler-runner/java-runner/JavaRunner.js +114 -0
- package/src/lambda/handler-runner/java-runner/index.js +1 -0
- package/src/lambda/handler-runner/python-runner/PythonRunner.js +138 -0
- package/src/lambda/handler-runner/python-runner/index.js +1 -0
- package/{dist → src}/lambda/handler-runner/python-runner/invoke.py +0 -0
- package/src/lambda/handler-runner/ruby-runner/RubyRunner.js +107 -0
- package/src/lambda/handler-runner/ruby-runner/index.js +1 -0
- package/{dist → src}/lambda/handler-runner/ruby-runner/invoke.rb +0 -0
- package/src/lambda/handler-runner/worker-thread-runner/WorkerThreadRunner.js +70 -0
- package/src/lambda/handler-runner/worker-thread-runner/index.js +1 -0
- package/src/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js +29 -0
- package/src/lambda/index.js +1 -0
- package/src/lambda/routes/index.js +2 -0
- package/src/lambda/routes/invocations/InvocationsController.js +102 -0
- package/src/lambda/routes/invocations/index.js +1 -0
- package/src/lambda/routes/invocations/invocationsRoute.js +77 -0
- package/src/lambda/routes/invoke-async/InvokeAsyncController.js +20 -0
- package/src/lambda/routes/invoke-async/index.js +1 -0
- package/src/lambda/routes/invoke-async/invokeAsyncRoute.js +33 -0
- package/src/utils/__tests__/createUniqueId.test.js +18 -0
- package/src/utils/__tests__/formatToClfTime.test.js +14 -0
- package/src/utils/__tests__/generateHapiPath.test.js +46 -0
- package/src/utils/__tests__/lowerCaseKeys.test.js +30 -0
- package/src/utils/__tests__/parseHeaders.test.js +13 -0
- package/src/utils/__tests__/parseMultiValueHeaders.test.js +24 -0
- package/src/utils/__tests__/parseMultiValueQueryStringParameters.test.js +159 -0
- package/src/utils/__tests__/parseQueryStringParameters.test.js +15 -0
- package/src/utils/__tests__/splitHandlerPathAndName.test.js +54 -0
- package/src/utils/__tests__/unflatten.test.js +32 -0
- package/src/utils/checkDockerDaemon.js +19 -0
- package/src/utils/checkGoVersion.js +16 -0
- package/src/utils/createApiKey.js +5 -0
- package/src/utils/createUniqueId.js +5 -0
- package/src/utils/detectExecutable.js +11 -0
- package/{dist → src}/utils/formatToClfTime.js +6 -14
- package/src/utils/generateHapiPath.js +26 -0
- package/src/utils/getHttpApiCorsConfig.js +28 -0
- package/src/utils/index.js +42 -0
- package/src/utils/jsonPath.js +13 -0
- package/src/utils/logRoutes.js +64 -0
- package/src/utils/lowerCaseKeys.js +6 -0
- package/src/utils/parseHeaders.js +14 -0
- package/src/utils/parseMultiValueHeaders.js +27 -0
- package/src/utils/parseMultiValueQueryStringParameters.js +31 -0
- package/src/utils/parseQueryStringParameters.js +15 -0
- package/src/utils/resolveJoins.js +29 -0
- package/src/utils/splitHandlerPathAndName.js +31 -0
- package/src/utils/unflatten.js +11 -0
- package/CHANGELOG.md +0 -78
- package/dist/ServerlessOffline.js +0 -508
- package/dist/config/commandOptions.js +0 -149
- package/dist/config/constants.js +0 -30
- package/dist/config/index.js +0 -55
- package/dist/config/supportedRuntimes.js +0 -40
- package/dist/debugLog.js +0 -12
- package/dist/events/authCanExecuteResource.js +0 -35
- package/dist/events/authFunctionNameExtractor.js +0 -87
- package/dist/events/authMatchPolicyResource.js +0 -62
- package/dist/events/authValidateContext.js +0 -53
- package/dist/events/http/Endpoint.js +0 -173
- package/dist/events/http/Http.js +0 -77
- package/dist/events/http/HttpEventDefinition.js +0 -36
- package/dist/events/http/HttpServer.js +0 -1370
- package/dist/events/http/OfflineEndpoint.js +0 -38
- package/dist/events/http/authJWTSettingsExtractor.js +0 -76
- package/dist/events/http/createAuthScheme.js +0 -184
- package/dist/events/http/createJWTAuthScheme.js +0 -159
- package/dist/events/http/index.js +0 -15
- package/dist/events/http/javaHelpers.js +0 -99
- package/dist/events/http/lambda-events/LambdaIntegrationEvent.js +0 -87
- package/dist/events/http/lambda-events/LambdaProxyIntegrationEvent.js +0 -246
- package/dist/events/http/lambda-events/LambdaProxyIntegrationEventV2.js +0 -225
- package/dist/events/http/lambda-events/VelocityContext.js +0 -170
- package/dist/events/http/lambda-events/index.js +0 -39
- package/dist/events/http/lambda-events/renderVelocityTemplateObject.js +0 -111
- package/dist/events/http/payloadSchemaValidator.js +0 -13
- package/dist/events/schedule/Schedule.js +0 -183
- package/dist/events/schedule/ScheduleEvent.js +0 -27
- package/dist/events/schedule/ScheduleEventDefinition.js +0 -36
- package/dist/events/schedule/index.js +0 -15
- package/dist/events/websocket/HttpServer.js +0 -114
- package/dist/events/websocket/WebSocket.js +0 -78
- package/dist/events/websocket/WebSocketClients.js +0 -577
- package/dist/events/websocket/WebSocketEventDefinition.js +0 -32
- package/dist/events/websocket/WebSocketServer.js +0 -139
- package/dist/events/websocket/http-routes/_catchAll/catchAllRoute.js +0 -33
- package/dist/events/websocket/http-routes/_catchAll/index.js +0 -15
- package/dist/events/websocket/http-routes/connections/ConnectionsController.js +0 -45
- package/dist/events/websocket/http-routes/connections/connectionsRoutes.js +0 -95
- package/dist/events/websocket/http-routes/connections/index.js +0 -15
- package/dist/events/websocket/http-routes/index.js +0 -23
- package/dist/events/websocket/index.js +0 -15
- package/dist/events/websocket/lambda-events/WebSocketAuthorizerEvent.js +0 -99
- package/dist/events/websocket/lambda-events/WebSocketConnectEvent.js +0 -101
- package/dist/events/websocket/lambda-events/WebSocketDisconnectEvent.js +0 -47
- package/dist/events/websocket/lambda-events/WebSocketEvent.js +0 -54
- package/dist/events/websocket/lambda-events/WebSocketRequestContext.js +0 -98
- package/dist/events/websocket/lambda-events/index.js +0 -39
- package/dist/index.js +0 -15
- package/dist/lambda/HttpServer.js +0 -124
- package/dist/lambda/Lambda.js +0 -117
- package/dist/lambda/LambdaContext.js +0 -53
- package/dist/lambda/LambdaFunction.js +0 -390
- package/dist/lambda/LambdaFunctionPool.js +0 -127
- package/dist/lambda/handler-runner/HandlerRunner.js +0 -195
- package/dist/lambda/handler-runner/child-process-runner/ChildProcessRunner.js +0 -124
- package/dist/lambda/handler-runner/child-process-runner/childProcessHelper.js +0 -49
- package/dist/lambda/handler-runner/child-process-runner/index.js +0 -15
- package/dist/lambda/handler-runner/docker-runner/DockerContainer.js +0 -515
- package/dist/lambda/handler-runner/docker-runner/DockerImage.js +0 -67
- package/dist/lambda/handler-runner/docker-runner/DockerRunner.js +0 -74
- package/dist/lambda/handler-runner/docker-runner/index.js +0 -15
- package/dist/lambda/handler-runner/go-runner/GoRunner.js +0 -230
- package/dist/lambda/handler-runner/go-runner/index.js +0 -15
- package/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js +0 -228
- package/dist/lambda/handler-runner/in-process-runner/index.js +0 -15
- package/dist/lambda/handler-runner/index.js +0 -15
- package/dist/lambda/handler-runner/java-runner/JavaRunner.js +0 -153
- package/dist/lambda/handler-runner/java-runner/index.js +0 -15
- package/dist/lambda/handler-runner/python-runner/PythonRunner.js +0 -185
- package/dist/lambda/handler-runner/python-runner/index.js +0 -15
- package/dist/lambda/handler-runner/ruby-runner/RubyRunner.js +0 -147
- package/dist/lambda/handler-runner/ruby-runner/index.js +0 -15
- package/dist/lambda/handler-runner/worker-thread-runner/WorkerThreadRunner.js +0 -92
- package/dist/lambda/handler-runner/worker-thread-runner/index.js +0 -15
- package/dist/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js +0 -31
- package/dist/lambda/index.js +0 -15
- package/dist/lambda/routes/index.js +0 -23
- package/dist/lambda/routes/invocations/InvocationsController.js +0 -142
- package/dist/lambda/routes/invocations/index.js +0 -15
- package/dist/lambda/routes/invocations/invocationsRoute.js +0 -90
- package/dist/lambda/routes/invoke-async/InvokeAsyncController.js +0 -38
- package/dist/lambda/routes/invoke-async/index.js +0 -15
- package/dist/lambda/routes/invoke-async/invokeAsyncRoute.js +0 -43
- package/dist/main.js +0 -11
- package/dist/serverlessLog.js +0 -91
- package/dist/utils/checkDockerDaemon.js +0 -27
- package/dist/utils/checkGoVersion.js +0 -27
- package/dist/utils/createApiKey.js +0 -12
- package/dist/utils/createUniqueId.js +0 -14
- package/dist/utils/detectExecutable.js +0 -21
- package/dist/utils/generateHapiPath.js +0 -28
- package/dist/utils/getHttpApiCorsConfig.js +0 -40
- package/dist/utils/index.js +0 -165
- package/dist/utils/jsonPath.js +0 -21
- package/dist/utils/lowerCaseKeys.js +0 -14
- package/dist/utils/parseHeaders.js +0 -23
- package/dist/utils/parseMultiValueHeaders.js +0 -36
- package/dist/utils/parseMultiValueQueryStringParameters.js +0 -40
- package/dist/utils/parseQueryStringParameters.js +0 -26
- package/dist/utils/resolveJoins.js +0 -36
- package/dist/utils/satisfiesVersionRange.js +0 -20
- package/dist/utils/splitHandlerPathAndName.js +0 -37
- package/dist/utils/unflatten.js +0 -18
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { execa } from 'execa'
|
|
2
|
+
|
|
3
|
+
export default async function checkGoVersion() {
|
|
4
|
+
let goVersion
|
|
5
|
+
|
|
6
|
+
try {
|
|
7
|
+
const { stdout } = await execa('go', ['version'])
|
|
8
|
+
if (stdout.match(/go1.\d+/g)) {
|
|
9
|
+
goVersion = '1.x'
|
|
10
|
+
}
|
|
11
|
+
} catch {
|
|
12
|
+
// @ignore
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return goVersion
|
|
16
|
+
}
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { DateTime } from 'luxon'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = formatToClfTime;
|
|
3
|
+
const { fromMillis } = DateTime
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
fromMillis
|
|
12
|
-
} = _luxon.DateTime; // CLF -> Common Log Format
|
|
5
|
+
// CLF -> Common Log Format
|
|
13
6
|
// https://httpd.apache.org/docs/1.3/logs.html#common
|
|
14
7
|
// [day/month/year:hour:minute:second zone]
|
|
15
8
|
// day = 2*digit
|
|
@@ -19,7 +12,6 @@ const {
|
|
|
19
12
|
// minute = 2*digit
|
|
20
13
|
// second = 2*digit
|
|
21
14
|
// zone = (`+' | `-') 4*digit
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
15
|
+
export default function formatToClfTime(millis) {
|
|
16
|
+
return fromMillis(millis).toFormat('dd/MMM/yyyy:HH:mm:ss ZZZ')
|
|
17
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export default function generateHapiPath(path, options, serverless) {
|
|
2
|
+
// path must start with '/'
|
|
3
|
+
let hapiPath = path.startsWith('/') ? path : `/${path}`
|
|
4
|
+
|
|
5
|
+
if (!options.noPrependStageInUrl) {
|
|
6
|
+
const stage = options.stage || serverless.service.provider.stage
|
|
7
|
+
// prepend the stage to path
|
|
8
|
+
hapiPath = `/${stage}${hapiPath}`
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (options.prefix) {
|
|
12
|
+
hapiPath = `/${options.prefix}${hapiPath}`
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (
|
|
16
|
+
hapiPath !== '/' &&
|
|
17
|
+
hapiPath.endsWith('/') &&
|
|
18
|
+
(!options.noStripTrailingSlashInUrl || hapiPath.endsWith('+}/'))
|
|
19
|
+
) {
|
|
20
|
+
hapiPath = hapiPath.slice(0, -1)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
hapiPath = hapiPath.replace(/\+}/g, '*}')
|
|
24
|
+
|
|
25
|
+
return hapiPath
|
|
26
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { log } from '@serverless/utils/log.js'
|
|
2
|
+
|
|
3
|
+
export default function getHttpApiCorsConfig(httpApiCors) {
|
|
4
|
+
if (httpApiCors === true) {
|
|
5
|
+
// default values that should be set by serverless
|
|
6
|
+
// https://www.serverless.com/framework/docs/providers/aws/events/http-api/
|
|
7
|
+
const c = {
|
|
8
|
+
allowedHeaders: [
|
|
9
|
+
'Authorization',
|
|
10
|
+
'Content-Type',
|
|
11
|
+
'X-Amz-Date',
|
|
12
|
+
'X-Amz-Security-Token',
|
|
13
|
+
'X-Amz-User-Agent',
|
|
14
|
+
'X-Api-Key',
|
|
15
|
+
],
|
|
16
|
+
allowedMethods: ['DELETE', 'GET', 'OPTIONS', 'PATCH', 'POST', 'PUT'],
|
|
17
|
+
allowedOrigins: ['*'],
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
log.debug('Using CORS policy', c)
|
|
21
|
+
|
|
22
|
+
return c
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
log.debug('Using CORS policy', httpApiCors)
|
|
26
|
+
|
|
27
|
+
return httpApiCors
|
|
28
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export { default as createApiKey } from './createApiKey.js'
|
|
2
|
+
export { default as createUniqueId } from './createUniqueId.js'
|
|
3
|
+
export { default as detectExecutable } from './detectExecutable.js'
|
|
4
|
+
export { default as formatToClfTime } from './formatToClfTime.js'
|
|
5
|
+
export { default as getHttpApiCorsConfig } from './getHttpApiCorsConfig.js'
|
|
6
|
+
export { default as jsonPath } from './jsonPath.js'
|
|
7
|
+
export { default as lowerCaseKeys } from './lowerCaseKeys.js'
|
|
8
|
+
export { default as parseHeaders } from './parseHeaders.js'
|
|
9
|
+
export { default as parseMultiValueHeaders } from './parseMultiValueHeaders.js'
|
|
10
|
+
export { default as parseMultiValueQueryStringParameters } from './parseMultiValueQueryStringParameters.js'
|
|
11
|
+
export { default as parseQueryStringParameters } from './parseQueryStringParameters.js'
|
|
12
|
+
export { default as splitHandlerPathAndName } from './splitHandlerPathAndName.js'
|
|
13
|
+
export { default as checkDockerDaemon } from './checkDockerDaemon.js'
|
|
14
|
+
export { default as checkGoVersion } from './checkGoVersion.js'
|
|
15
|
+
export { default as generateHapiPath } from './generateHapiPath.js'
|
|
16
|
+
// export { default as baseImage } from './baseImage.js'
|
|
17
|
+
|
|
18
|
+
const { isArray } = Array
|
|
19
|
+
const { keys } = Object
|
|
20
|
+
|
|
21
|
+
// Detect the toString encoding from the request headers content-type
|
|
22
|
+
// enhance if further content types need to be non utf8 encoded.
|
|
23
|
+
export function detectEncoding(request) {
|
|
24
|
+
const contentType = request.headers['content-type']
|
|
25
|
+
|
|
26
|
+
return typeof contentType === 'string' &&
|
|
27
|
+
contentType.includes('multipart/form-data')
|
|
28
|
+
? 'binary'
|
|
29
|
+
: 'utf8'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function nullIfEmpty(obj) {
|
|
33
|
+
return obj && (keys(obj).length > 0 ? obj : null)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function isPlainObject(obj) {
|
|
37
|
+
return typeof obj === 'object' && !isArray(obj) && obj != null
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function toPlainOrEmptyObject(obj) {
|
|
41
|
+
return typeof obj === 'object' && !isArray(obj) ? obj : {}
|
|
42
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { JSONPath } from 'jsonpath-plus'
|
|
2
|
+
|
|
3
|
+
export default function jsonPath(json, path) {
|
|
4
|
+
// NOTE: JSONPath returns undefined if 'json' is e.g. null, undefined, string,
|
|
5
|
+
// number (anything other than JSON)
|
|
6
|
+
const [result] =
|
|
7
|
+
JSONPath({
|
|
8
|
+
json,
|
|
9
|
+
path,
|
|
10
|
+
}) || []
|
|
11
|
+
|
|
12
|
+
return result
|
|
13
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import boxen from 'boxen'
|
|
2
|
+
import chalk from 'chalk'
|
|
3
|
+
|
|
4
|
+
const { max } = Math
|
|
5
|
+
|
|
6
|
+
const dodgerblue = chalk.hex('#1e90ff')
|
|
7
|
+
const grey = chalk.hex('#808080')
|
|
8
|
+
const lime = chalk.hex('#00ff00')
|
|
9
|
+
const orange = chalk.hex('#ffa500')
|
|
10
|
+
const peachpuff = chalk.hex('#ffdab9')
|
|
11
|
+
const plum = chalk.hex('#dda0dd')
|
|
12
|
+
const red = chalk.hex('#ff0000')
|
|
13
|
+
const yellow = chalk.hex('#ffff00')
|
|
14
|
+
|
|
15
|
+
const colorMethodMapping = new Map([
|
|
16
|
+
['DELETE', red],
|
|
17
|
+
['GET', dodgerblue],
|
|
18
|
+
// ['HEAD', ...],
|
|
19
|
+
['PATCH', orange],
|
|
20
|
+
['POST', plum],
|
|
21
|
+
['PUT', dodgerblue],
|
|
22
|
+
])
|
|
23
|
+
|
|
24
|
+
// logs based on:
|
|
25
|
+
// https://github.com/serverless/serverless/blob/master/lib/classes/CLI.js
|
|
26
|
+
|
|
27
|
+
function logRoute(method, server, path, maxLength, dimPath = false) {
|
|
28
|
+
const methodColor = colorMethodMapping.get(method) ?? peachpuff
|
|
29
|
+
const methodFormatted = method.padEnd(maxLength, ' ')
|
|
30
|
+
|
|
31
|
+
return `${methodColor(methodFormatted)} ${yellow.dim('|')} ${grey.dim(
|
|
32
|
+
server,
|
|
33
|
+
)}${dimPath ? grey.dim(path) : lime(path)}`
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getMaxHttpMethodNameLength(routeInfo) {
|
|
37
|
+
return max(...routeInfo.map(({ method }) => method.length))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default function logRoutes(routeInfo) {
|
|
41
|
+
const boxenOptions = {
|
|
42
|
+
borderColor: 'yellow',
|
|
43
|
+
dimBorder: true,
|
|
44
|
+
margin: 1,
|
|
45
|
+
padding: 1,
|
|
46
|
+
}
|
|
47
|
+
const maxLength = getMaxHttpMethodNameLength(routeInfo)
|
|
48
|
+
|
|
49
|
+
// eslint-disable-next-line no-console
|
|
50
|
+
console.log(
|
|
51
|
+
boxen(
|
|
52
|
+
routeInfo
|
|
53
|
+
.map(
|
|
54
|
+
({ method, path, server, invokePath }) =>
|
|
55
|
+
// eslint-disable-next-line prefer-template
|
|
56
|
+
logRoute(method, server, path, maxLength) +
|
|
57
|
+
'\n' +
|
|
58
|
+
logRoute('POST', server, invokePath, maxLength, true),
|
|
59
|
+
)
|
|
60
|
+
.join('\n'),
|
|
61
|
+
boxenOptions,
|
|
62
|
+
),
|
|
63
|
+
)
|
|
64
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import unflatten from './unflatten.js'
|
|
2
|
+
|
|
3
|
+
const { fromEntries } = Object
|
|
4
|
+
|
|
5
|
+
// (rawHeaders: Array<string>): { [string]: string }
|
|
6
|
+
export default function parseHeaders(rawHeaders) {
|
|
7
|
+
if (rawHeaders.length === 0) {
|
|
8
|
+
return null
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const unflattened = unflatten(rawHeaders, 2)
|
|
12
|
+
|
|
13
|
+
return fromEntries(unflattened)
|
|
14
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import unflatten from './unflatten.js'
|
|
2
|
+
|
|
3
|
+
const { fromEntries } = Object
|
|
4
|
+
|
|
5
|
+
// https://aws.amazon.com/blogs/compute/support-for-multi-value-parameters-in-amazon-api-gateway/
|
|
6
|
+
// (rawHeaders: Array<string>): { [string]: Array<string> }
|
|
7
|
+
export default function parseMultiValueHeaders(rawHeaders) {
|
|
8
|
+
if (rawHeaders.length === 0) {
|
|
9
|
+
return null
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const map = new Map()
|
|
13
|
+
const unflattened = unflatten(rawHeaders, 2)
|
|
14
|
+
|
|
15
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
16
|
+
for (const [key, value] of unflattened) {
|
|
17
|
+
const item = map.get(key)
|
|
18
|
+
|
|
19
|
+
if (item) {
|
|
20
|
+
item.push(value)
|
|
21
|
+
} else {
|
|
22
|
+
map.set(key, [value])
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return fromEntries(map)
|
|
27
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BASE_URL_PLACEHOLDER } from '../config/index.js'
|
|
2
|
+
|
|
3
|
+
const { fromEntries } = Object
|
|
4
|
+
|
|
5
|
+
// https://aws.amazon.com/blogs/compute/support-for-multi-value-parameters-in-amazon-api-gateway/
|
|
6
|
+
// [ [ 'petType', 'dog' ], [ 'petType', 'fish' ] ]
|
|
7
|
+
// => { petType: [ 'dog', 'fish' ] },
|
|
8
|
+
export default function parseMultiValueQueryStringParameters(url) {
|
|
9
|
+
// dummy placeholder url for the WHATWG URL constructor
|
|
10
|
+
// https://github.com/nodejs/node/issues/12682
|
|
11
|
+
const { searchParams } = new URL(url, BASE_URL_PLACEHOLDER)
|
|
12
|
+
|
|
13
|
+
if (Array.from(searchParams).length === 0) {
|
|
14
|
+
return null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const map = new Map()
|
|
18
|
+
|
|
19
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
20
|
+
for (const [key, value] of searchParams) {
|
|
21
|
+
const item = map.get(key)
|
|
22
|
+
|
|
23
|
+
if (item) {
|
|
24
|
+
item.push(value)
|
|
25
|
+
} else {
|
|
26
|
+
map.set(key, [value])
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return fromEntries(map)
|
|
31
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BASE_URL_PLACEHOLDER } from '../config/index.js'
|
|
2
|
+
|
|
3
|
+
const { fromEntries } = Object
|
|
4
|
+
|
|
5
|
+
export default function parseQueryStringParameters(url) {
|
|
6
|
+
// dummy placeholder url for the WHATWG URL constructor
|
|
7
|
+
// https://github.com/nodejs/node/issues/12682
|
|
8
|
+
const { searchParams } = new URL(url, BASE_URL_PLACEHOLDER)
|
|
9
|
+
|
|
10
|
+
if (Array.from(searchParams).length === 0) {
|
|
11
|
+
return null
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return fromEntries(searchParams)
|
|
15
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const { entries } = Object
|
|
2
|
+
|
|
3
|
+
// Used to resolve Fn::Join in environment variables
|
|
4
|
+
export default function resolveJoins(environment) {
|
|
5
|
+
if (!environment) {
|
|
6
|
+
return undefined
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const newEnv = {}
|
|
10
|
+
|
|
11
|
+
entries(environment).forEach(([key, value]) => {
|
|
12
|
+
if (!value) {
|
|
13
|
+
return
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const joinArray = value['Fn::Join']
|
|
17
|
+
const isJoin = Boolean(joinArray)
|
|
18
|
+
|
|
19
|
+
if (isJoin) {
|
|
20
|
+
const separator = joinArray[0]
|
|
21
|
+
const joined = joinArray[1].join(separator)
|
|
22
|
+
newEnv[key] = joined
|
|
23
|
+
} else {
|
|
24
|
+
newEnv[key] = value
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
return newEnv
|
|
29
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// some-folder/src.index => some-folder/src
|
|
2
|
+
export default function splitHandlerPathAndName(handler) {
|
|
3
|
+
// Split handler into method name and path i.e. handler.run
|
|
4
|
+
// Support Ruby paths with namespace resolution operators e.g.
|
|
5
|
+
// ./src/somefolder/source.LambdaFunctions::Handler.process
|
|
6
|
+
// prepath: ./src/somefolder/
|
|
7
|
+
// postpath: source.LambdaFunctions::Handler.process
|
|
8
|
+
// filename: source
|
|
9
|
+
// path: ./src/somefolder/source
|
|
10
|
+
// name: LambdaFunctions::Handler.process
|
|
11
|
+
if (handler.match(/::/)) {
|
|
12
|
+
const prepathDelimiter = handler.lastIndexOf('/')
|
|
13
|
+
const prepath = handler.substr(0, prepathDelimiter + 1) // include '/' for path
|
|
14
|
+
const postpath = handler.substr(prepathDelimiter + 1)
|
|
15
|
+
const nameDelimiter = postpath.indexOf('.')
|
|
16
|
+
const filename = postpath.substr(0, nameDelimiter)
|
|
17
|
+
const path = prepath + filename
|
|
18
|
+
const name = postpath.substr(nameDelimiter + 1)
|
|
19
|
+
|
|
20
|
+
return [path, name]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Support nested paths i.e. ./src/somefolder/.handlers/handler.run
|
|
24
|
+
// path: ./src/somefoler/.handlers/handler
|
|
25
|
+
// name: run
|
|
26
|
+
const delimiter = handler.lastIndexOf('.')
|
|
27
|
+
const path = handler.substr(0, delimiter)
|
|
28
|
+
const name = handler.substr(delimiter + 1)
|
|
29
|
+
|
|
30
|
+
return [path, name]
|
|
31
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// [0, 1, 2, 3, 4 ,5] => [[0, 1], [2, 3], [4, 5]]
|
|
2
|
+
export default function unflatten(value, size) {
|
|
3
|
+
const unflattened = []
|
|
4
|
+
|
|
5
|
+
for (let i = 0; i < value.length; i += size) {
|
|
6
|
+
const slice = value.slice(i, i + size)
|
|
7
|
+
unflattened.push(slice)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return unflattened
|
|
11
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
-
|
|
5
|
-
### [8.8.1](https://github.com/dherault/serverless-offline/compare/v8.8.0...v8.8.1) (2022-07-09)
|
|
6
|
-
|
|
7
|
-
### Maintenance Improvements
|
|
8
|
-
|
|
9
|
-
- remove update-notifier ([fbcd41e](https://github.com/dherault/serverless-offline/commit/fbcd41eb29fd5aa60d3ce52a734b89ed4113d893))
|
|
10
|
-
|
|
11
|
-
## [8.8.0](https://github.com/dherault/serverless-offline/compare/v8.7.0...v8.8.0) (2022-05-17)
|
|
12
|
-
|
|
13
|
-
### Features
|
|
14
|
-
|
|
15
|
-
- Support using go build ([#1334](https://github.com/dherault/serverless-offline/issues/1334)) ([#1356](https://github.com/dherault/serverless-offline/issues/1356)) ([a79b15c](https://github.com/dherault/serverless-offline/commit/a79b15c529b60ac0d037716cf6e475bcda8f822e))
|
|
16
|
-
|
|
17
|
-
### Bug Fixes
|
|
18
|
-
|
|
19
|
-
- lowercase API gateway V2 event headers ([#1288](https://github.com/dherault/serverless-offline/issues/1288)) ([9ff4cf3](https://github.com/dherault/serverless-offline/commit/9ff4cf38c4f620545d95d815d0b420d134be5cb1))
|
|
20
|
-
- remove (now) useless worker thread support check ([#1406](https://github.com/dherault/serverless-offline/issues/1406)) ([1b2ae00](https://github.com/dherault/serverless-offline/commit/1b2ae0016cec385416c240b55669df038ddc5d1e))
|
|
21
|
-
- remove babel-eslint ([17adeb5](https://github.com/dherault/serverless-offline/commit/17adeb5b923d990f64e96e234297999baaca30a0))
|
|
22
|
-
- remove engine check ([#1407](https://github.com/dherault/serverless-offline/issues/1407)) ([58b2199](https://github.com/dherault/serverless-offline/commit/58b21998e2ced5eeab3ebf0a30fd1849e974befe))
|
|
23
|
-
- remove unneeded deps ([95e1fe5](https://github.com/dherault/serverless-offline/commit/95e1fe5bbc4aceb83bd8135503c3c4123006d61b))
|
|
24
|
-
- solve merge issues ([99a2578](https://github.com/dherault/serverless-offline/commit/99a25789ce6d4be718dcae470e99bde5f3ab8b86))
|
|
25
|
-
- temporary revert nested modules ([#1419](https://github.com/dherault/serverless-offline/issues/1419)) ([f4317e4](https://github.com/dherault/serverless-offline/commit/f4317e4f6bd818ed6d243b440cab9d7030b1c30d))
|
|
26
|
-
|
|
27
|
-
### Maintenance Improvements
|
|
28
|
-
|
|
29
|
-
- import from namespace ([#1405](https://github.com/dherault/serverless-offline/issues/1405)) ([ed9d6cd](https://github.com/dherault/serverless-offline/commit/ed9d6cd48fbdba26cf7a4b5aa096464fba94193e))
|
|
30
|
-
- import process explicit ([#1418](https://github.com/dherault/serverless-offline/issues/1418)) ([8893c67](https://github.com/dherault/serverless-offline/commit/8893c67718259b7d760194c74f31ee56fcd7e789))
|
|
31
|
-
- prettify docs ([2ee5b1e](https://github.com/dherault/serverless-offline/commit/2ee5b1ef56133aecbc120f2d20858411b30956d3))
|
|
32
|
-
- remove extend module, replace with Object.assign ([#1417](https://github.com/dherault/serverless-offline/issues/1417)) ([90d5169](https://github.com/dherault/serverless-offline/commit/90d516909c3c41e907d728afd47cf436f078bf97))
|
|
33
|
-
|
|
34
|
-
## [8.7.0](https://github.com/dherault/serverless-offline/compare/v8.6.0...v8.7.0) (2022-04-13)
|
|
35
|
-
|
|
36
|
-
- [Validate authorizer context response to better mimic API Gateway](https://github.com/dherault/serverless-offline/pull/1376)
|
|
37
|
-
- [Add support for the AUTHORIZER env variable for LambdaIntegration](https://github.com/dherault/serverless-offline/pull/1308)
|
|
38
|
-
|
|
39
|
-
## [8.6.0](https://github.com/dherault/serverless-offline/compare/v8.5.0...v8.6.0) (2022-04-13)
|
|
40
|
-
|
|
41
|
-
- [POC for externally triggering cleanup of lambda functions](https://github.com/dherault/serverless-offline/pull/1093)
|
|
42
|
-
- [Fixing AWS env vars](https://github.com/dherault/serverless-offline/pull/1108)
|
|
43
|
-
- [Ensure gateway IP is truthy before adding to docker args](https://github.com/dherault/serverless-offline/pull/1174)
|
|
44
|
-
- [update debugging instructions](https://github.com/dherault/serverless-offline/pull/1221)
|
|
45
|
-
- [Never remove cached node_modules or binary modules](https://github.com/dherault/serverless-offline/pull/1230)
|
|
46
|
-
- [Handle multiple cookies with the same name in the same way API Gateway does.](https://github.com/dherault/serverless-offline/pull/1249)
|
|
47
|
-
|
|
48
|
-
## [8.5.0](https://github.com/dherault/serverless-offline/compare/v8.4.0...v8.5.0) (2022-02-18)
|
|
49
|
-
|
|
50
|
-
### Features
|
|
51
|
-
|
|
52
|
-
- Add `httpEvent.operationId` to the request context ([#1325](https://github.com/dherault/serverless-offline/issues/1325)) ([e217fcb](https://github.com/dherault/serverless-offline/commit/e217fcba61fe3eae110f506268c71b350e1937da)) ([Quenby Mitchell](https://github.com/qswinson))
|
|
53
|
-
- Ensure `websocket` parity with API Gateway ([#1301](https://github.com/dherault/serverless-offline/issues/1301)) ([8f02226](https://github.com/dherault/serverless-offline/commit/8f0222644e5946c2bba8853c7ee6c224e7a33b41)) ([Christian Nuss](https://github.com/cnuss))
|
|
54
|
-
- Introduce header to override authorizer response ([#1328](https://github.com/dherault/serverless-offline/issues/1328)) ([a5158a4](https://github.com/dherault/serverless-offline/commit/a5158a489048ceee007cefa41441f841b51db59c)) ([ericctsf](https://github.com/ericctsf))
|
|
55
|
-
- Support injection of custom authentication strategy ([#1314](https://github.com/dherault/serverless-offline/issues/1314)) ([febfe77](https://github.com/dherault/serverless-offline/commit/febfe77d470b2e5e4fbfe5243b265d6a27fb84f3)) ([tom-stclair](https://github.com/tom-stclair))
|
|
56
|
-
|
|
57
|
-
### Bug Fixes
|
|
58
|
-
|
|
59
|
-
- Fix payload normalization ([#1332](https://github.com/dherault/serverless-offline/issues/1332)) ([e9e8169](https://github.com/dherault/serverless-offline/commit/e9e816996e8da9605a4a9856a60ddfbbe885e1b1)) ([Taras Romaniv](https://github.com/trsrm))
|
|
60
|
-
- Skip clearing undefined modules in `InProcessRunner` ([#1339](https://github.com/dherault/serverless-offline/issues/1339)) ([5026e43](https://github.com/dherault/serverless-offline/commit/5026e43974dd73de66bf2c82b742cc7341f7c55b)) ([Kevin Rueter](https://github.com/kerueter))
|
|
61
|
-
|
|
62
|
-
## [8.4.0](https://github.com/dherault/serverless-offline/compare/v8.3.1...v8.4.0) (2022-01-28)
|
|
63
|
-
|
|
64
|
-
### Features
|
|
65
|
-
|
|
66
|
-
- `go-runner` implementation ([#1320](https://github.com/dherault/serverless-offline/issues/1320)) ([6bb54fd](https://github.com/dherault/serverless-offline/commit/6bb54fdccebd3db61221a9b8f709414876086324))
|
|
67
|
-
- `--disableScheduledEvents` CLI param support ([#1185](https://github.com/dherault/serverless-offline/issues/1185)) ([4503567](https://github.com/dherault/serverless-offline/commit/4503567cdb8fa31ac9df98b667a403b0408f8444))
|
|
68
|
-
|
|
69
|
-
### Bug Fixes
|
|
70
|
-
|
|
71
|
-
- Handle custom authorizer 401 in non in-process runners ([#1319](https://github.com/dherault/serverless-offline/issues/1319)) ([8d61bde](https://github.com/dherault/serverless-offline/commit/8d61bde74cdfb37410a5c1952ca608e815eeb1cf))
|
|
72
|
-
- Support `httpApi` payload override on function level ([#1312](https://github.com/dherault/serverless-offline/issues/1312)) ([8db63dd](https://github.com/dherault/serverless-offline/commit/8db63dda6054198775ed3b567dc3c1dbf73eb574))
|
|
73
|
-
|
|
74
|
-
### [8.3.1](https://github.com/dherault/serverless-offline/compare/v8.3.0...v8.3.1) (2021-11-25)
|
|
75
|
-
|
|
76
|
-
### Bug Fixes
|
|
77
|
-
|
|
78
|
-
- Fix handling of modern logs (`Cannot read properties of undefined (reading 'notice')` error)
|