@bitblit/ratchet-epsilon-common 4.0.115-alpha → 4.0.119-alpha
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/lib/background/background-dynamo-log-table-handler.d.ts +1 -1
- package/lib/background/background-handler.d.ts +1 -1
- package/lib/background/background-http-adapter-handler.d.ts +1 -1
- package/lib/background/background-validator.d.ts +1 -1
- package/lib/build/ratchet-epsilon-common-info.d.ts +1 -1
- package/lib/built-in/daemon/daemon-authorizer-function.d.ts +1 -1
- package/lib/built-in/daemon/daemon-handler.d.ts +2 -2
- package/lib/built-in/daemon/daemon-process-state-list.d.ts +1 -1
- package/lib/built-in/http/built-in-auth-filters.d.ts +1 -1
- package/lib/cli/ratchet-cli-handler.d.ts +2 -2
- package/lib/config/epsilon-logger-config.d.ts +2 -2
- package/lib/config/http/filter-chain-context.d.ts +1 -1
- package/lib/config/http/http-config.d.ts +1 -1
- package/lib/epsilon-global-handler.d.ts +1 -1
- package/lib/epsilon-instance.d.ts +1 -1
- package/lib/epsilon-logging-extension-processor.d.ts +2 -2
- package/lib/http/auth/auth0-web-token-manipulator.d.ts +1 -1
- package/lib/http/auth/google-web-token-manipulator.d.ts +1 -1
- package/lib/http/auth/jwt-ratchet-local-web-token-manipulator.d.ts +2 -2
- package/lib/http/auth/local-web-token-manipulator.d.ts +3 -3
- package/lib/http/auth/web-token-manipulator.d.ts +1 -1
- package/lib/http/event-util.d.ts +1 -1
- package/lib/http/response-util.d.ts +1 -1
- package/lib/http/route/epsilon-router.d.ts +1 -1
- package/lib/http/route/router-util.d.ts +2 -2
- package/lib/index.d.ts +132 -1
- package/lib/index.mjs +344 -0
- package/lib/index.mjs.map +1 -0
- package/lib/local-container-server.d.ts +1 -1
- package/lib/local-server.d.ts +1 -1
- package/lib/sample/test-error-server.d.ts +1 -1
- package/lib/util/epsilon-config-parser.d.ts +1 -1
- package/package.json +18 -19
- package/lib/background/background-dynamo-log-table-handler.js +0 -37
- package/lib/background/background-entry.js +0 -1
- package/lib/background/background-execution-event-type.js +0 -8
- package/lib/background/background-execution-event.js +0 -1
- package/lib/background/background-execution-listener.js +0 -1
- package/lib/background/background-handler.js +0 -273
- package/lib/background/background-http-adapter-handler.js +0 -128
- package/lib/background/background-meta-response-internal.js +0 -1
- package/lib/background/background-process-handling.js +0 -5
- package/lib/background/background-process-log-table-entry.js +0 -1
- package/lib/background/background-queue-response-internal.js +0 -1
- package/lib/background/background-validator.js +0 -86
- package/lib/background/epsilon-background-process-error.js +0 -93
- package/lib/background/internal-background-entry.js +0 -1
- package/lib/background/manager/abstract-background-manager.js +0 -89
- package/lib/background/manager/aws-sqs-sns-background-manager.js +0 -153
- package/lib/background/manager/background-manager-like.js +0 -1
- package/lib/background/manager/background-manager.spec.js +0 -73
- package/lib/background/manager/single-thread-local-background-manager.js +0 -45
- package/lib/background/s3-background-transaction-logger.js +0 -52
- package/lib/build/ratchet-epsilon-common-info.js +0 -14
- package/lib/built-in/background/echo-processor.js +0 -15
- package/lib/built-in/background/log-and-enqueue-echo-processor.js +0 -12
- package/lib/built-in/background/log-message-background-error-processor.js +0 -6
- package/lib/built-in/background/no-op-processor.js +0 -9
- package/lib/built-in/background/retry-processor.js +0 -40
- package/lib/built-in/background/sample-delay-processor.js +0 -13
- package/lib/built-in/background/sample-input-validated-processor-data.js +0 -1
- package/lib/built-in/background/sample-input-validated-processor.js +0 -12
- package/lib/built-in/built-in-trace-id-generators.js +0 -21
- package/lib/built-in/daemon/daemon-authorizer-function.js +0 -1
- package/lib/built-in/daemon/daemon-config.js +0 -1
- package/lib/built-in/daemon/daemon-group-selection-function.js +0 -1
- package/lib/built-in/daemon/daemon-handler.js +0 -59
- package/lib/built-in/daemon/daemon-process-state-list.js +0 -1
- package/lib/built-in/http/apollo-filter.js +0 -59
- package/lib/built-in/http/built-in-auth-filters.js +0 -107
- package/lib/built-in/http/built-in-authorizers.js +0 -39
- package/lib/built-in/http/built-in-filters.js +0 -208
- package/lib/built-in/http/built-in-handlers.js +0 -69
- package/lib/built-in/http/log-level-manipulation-filter.js +0 -16
- package/lib/built-in/http/run-handler-as-filter.js +0 -60
- package/lib/built-in/http/run-handler-as-filter.spec.js +0 -40
- package/lib/cli/ratchet-cli-handler.js +0 -20
- package/lib/cli/run-background-process-from-command-line.js +0 -22
- package/lib/config/background/background-aws-config.js +0 -1
- package/lib/config/background/background-config.js +0 -1
- package/lib/config/background/background-error-processor.js +0 -1
- package/lib/config/background/background-processor.js +0 -1
- package/lib/config/background/background-transaction-log.js +0 -1
- package/lib/config/background/background-transaction-logger.js +0 -1
- package/lib/config/cron/abstract-cron-entry.js +0 -1
- package/lib/config/cron/cron-background-entry.js +0 -1
- package/lib/config/cron/cron-config.js +0 -1
- package/lib/config/dynamo-db-config.js +0 -1
- package/lib/config/epsilon-config.js +0 -1
- package/lib/config/epsilon-lambda-event-handler.js +0 -1
- package/lib/config/epsilon-logger-config.js +0 -1
- package/lib/config/generic-aws-event-handler-function.js +0 -1
- package/lib/config/http/authorizer-function.js +0 -1
- package/lib/config/http/epsilon-authorization-context.js +0 -1
- package/lib/config/http/extended-api-gateway-event.js +0 -1
- package/lib/config/http/filter-chain-context.js +0 -1
- package/lib/config/http/filter-function.js +0 -1
- package/lib/config/http/handler-function.js +0 -1
- package/lib/config/http/http-config.js +0 -1
- package/lib/config/http/http-processing-config.js +0 -1
- package/lib/config/http/mapped-http-processing-config.js +0 -1
- package/lib/config/http/null-returned-object-handling.js +0 -6
- package/lib/config/inter-api/inter-api-aws-config.js +0 -1
- package/lib/config/inter-api/inter-api-config.js +0 -1
- package/lib/config/inter-api/inter-api-process-mapping.js +0 -1
- package/lib/config/logging-trace-id-generator.js +0 -1
- package/lib/config/open-api/open-api-document-components.js +0 -1
- package/lib/config/open-api/open-api-document-path.js +0 -1
- package/lib/config/open-api/open-api-document.js +0 -1
- package/lib/config/s3-config.js +0 -1
- package/lib/config/sns-config.js +0 -1
- package/lib/epsilon-build-properties.js +0 -24
- package/lib/epsilon-constants.js +0 -46
- package/lib/epsilon-global-handler.js +0 -154
- package/lib/epsilon-instance.js +0 -1
- package/lib/epsilon-logging-extension-processor.js +0 -15
- package/lib/http/auth/api-gateway-adapter-authentication-handler.js +0 -72
- package/lib/http/auth/auth0-web-token-manipulator.js +0 -61
- package/lib/http/auth/basic-auth-token.js +0 -1
- package/lib/http/auth/google-web-token-manipulator.js +0 -70
- package/lib/http/auth/google-web-token-manipulator.spec.js +0 -10
- package/lib/http/auth/jwt-ratchet-local-web-token-manipulator.js +0 -27
- package/lib/http/auth/local-web-token-manipulator.js +0 -74
- package/lib/http/auth/local-web-token-manipulator.spec.js +0 -24
- package/lib/http/auth/web-token-manipulator.js +0 -1
- package/lib/http/error/bad-gateway.js +0 -8
- package/lib/http/error/bad-request-error.js +0 -8
- package/lib/http/error/conflict-error.js +0 -8
- package/lib/http/error/epsilon-http-error.js +0 -133
- package/lib/http/error/epsilon-http-error.spec.js +0 -11
- package/lib/http/error/forbidden-error.js +0 -8
- package/lib/http/error/gateway-timeout.js +0 -8
- package/lib/http/error/method-not-allowed-error.js +0 -8
- package/lib/http/error/misconfigured-error.js +0 -8
- package/lib/http/error/not-found-error.js +0 -8
- package/lib/http/error/not-implemented.js +0 -8
- package/lib/http/error/request-timeout-error.js +0 -8
- package/lib/http/error/service-unavailable.js +0 -8
- package/lib/http/error/too-many-requests-error.js +0 -8
- package/lib/http/error/unauthorized-error.js +0 -8
- package/lib/http/event-util.js +0 -176
- package/lib/http/event-util.spec.js +0 -161
- package/lib/http/response-util.js +0 -141
- package/lib/http/response-util.spec.js +0 -92
- package/lib/http/route/epsilon-router.js +0 -1
- package/lib/http/route/extended-auth-response-context.js +0 -1
- package/lib/http/route/route-mapping.js +0 -1
- package/lib/http/route/route-validator-config.js +0 -1
- package/lib/http/route/router-util.js +0 -233
- package/lib/http/route/router-util.spec.js +0 -23
- package/lib/http/web-handler.js +0 -117
- package/lib/http/web-handler.spec.js +0 -32
- package/lib/http/web-v2-handler.js +0 -22
- package/lib/index.js +0 -1
- package/lib/inter-api/inter-api-entry.js +0 -1
- package/lib/inter-api/inter-api-util.js +0 -59
- package/lib/inter-api/inter-api-util.spec.js +0 -61
- package/lib/inter-api-manager.js +0 -65
- package/lib/lambda-event-handler/cron-epsilon-lambda-event-handler.js +0 -73
- package/lib/lambda-event-handler/cron-epsilon-lambda-event-handler.spec.js +0 -50
- package/lib/lambda-event-handler/dynamo-epsilon-lambda-event-handler.js +0 -33
- package/lib/lambda-event-handler/generic-sns-epsilon-lambda-event-handler.js +0 -29
- package/lib/lambda-event-handler/inter-api-epsilon-lambda-event-handler.js +0 -23
- package/lib/lambda-event-handler/s3-epsilon-lambda-event-handler.js +0 -41
- package/lib/local-container-server.js +0 -76
- package/lib/local-server-cert.js +0 -67
- package/lib/local-server.js +0 -162
- package/lib/open-api-util/open-api-doc-modifications.js +0 -1
- package/lib/open-api-util/open-api-doc-modifier.js +0 -79
- package/lib/open-api-util/open-api-doc-modifier.spec.js +0 -16
- package/lib/open-api-util/yaml-combiner.js +0 -27
- package/lib/open-api-util/yaml-combiner.spec.js +0 -22
- package/lib/sample/sample-server-components.js +0 -185
- package/lib/sample/sample-server-static-files.js +0 -593
- package/lib/sample/test-error-server.js +0 -44
- package/lib/util/aws-util.js +0 -65
- package/lib/util/context-util.js +0 -101
- package/lib/util/cron-util.js +0 -68
- package/lib/util/cron-util.spec.js +0 -124
- package/lib/util/epsilon-config-parser.js +0 -65
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
2
|
-
import { NotFoundError } from '../../http/error/not-found-error.js';
|
|
3
|
-
import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
|
|
4
|
-
export class DaemonHandler {
|
|
5
|
-
daemon;
|
|
6
|
-
inConfig;
|
|
7
|
-
static ALLOW_EVERYTHING_AUTHORIZER = async (evt, proc) => {
|
|
8
|
-
return true;
|
|
9
|
-
};
|
|
10
|
-
config;
|
|
11
|
-
constructor(daemon, inConfig) {
|
|
12
|
-
this.daemon = daemon;
|
|
13
|
-
this.inConfig = inConfig;
|
|
14
|
-
this.config = inConfig || {};
|
|
15
|
-
this.config.authorizer = this.config.authorizer || DaemonHandler.ALLOW_EVERYTHING_AUTHORIZER;
|
|
16
|
-
this.config.groupSelector = this.config.groupSelector || ((evt) => Promise.resolve(daemon.defaultGroup));
|
|
17
|
-
this.config.fetchDaemonStatusByPublicTokenPathParameter =
|
|
18
|
-
StringRatchet.trimToNull(this.config.fetchDaemonStatusByPublicTokenPathParameter) || 'publicToken';
|
|
19
|
-
this.config.fetchDaemonStatusPathParameter = StringRatchet.trimToNull(this.config.fetchDaemonStatusPathParameter) || 'key';
|
|
20
|
-
}
|
|
21
|
-
async fetchDaemonStatusByPublicToken(evt) {
|
|
22
|
-
const publicToken = evt.pathParameters[this.config.fetchDaemonStatusByPublicTokenPathParameter];
|
|
23
|
-
Logger.info('Fetching daemon status for token: %s', publicToken);
|
|
24
|
-
let rval = await this.daemon.statFromPublicToken(publicToken);
|
|
25
|
-
const canRead = rval ? await this.config.authorizer(evt, rval) : false;
|
|
26
|
-
rval = canRead ? rval : null;
|
|
27
|
-
if (rval === null) {
|
|
28
|
-
throw new NotFoundError('No such token : ' + publicToken);
|
|
29
|
-
}
|
|
30
|
-
return rval;
|
|
31
|
-
}
|
|
32
|
-
async fetchDaemonStatus(evt) {
|
|
33
|
-
const daemonKey = evt.pathParameters[this.config.fetchDaemonStatusPathParameter];
|
|
34
|
-
Logger.info('Fetching daemon status for : %s', daemonKey);
|
|
35
|
-
let rval = await this.daemon.stat(daemonKey);
|
|
36
|
-
const canRead = rval ? await this.config.authorizer(evt, rval) : false;
|
|
37
|
-
rval = canRead ? rval : null;
|
|
38
|
-
if (rval === null) {
|
|
39
|
-
throw new NotFoundError('No such key : ' + daemonKey);
|
|
40
|
-
}
|
|
41
|
-
return rval;
|
|
42
|
-
}
|
|
43
|
-
async listDaemonStatus(evt) {
|
|
44
|
-
const group = await this.config.groupSelector(evt);
|
|
45
|
-
const keys = await this.daemon.list(group);
|
|
46
|
-
const allowed = [];
|
|
47
|
-
for (let i = 0; i < keys.length; i++) {
|
|
48
|
-
const canRead = await this.config.authorizer(evt, keys[i]);
|
|
49
|
-
if (canRead) {
|
|
50
|
-
allowed.push(keys[i]);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const rval = {
|
|
54
|
-
results: allowed,
|
|
55
|
-
nextToken: null,
|
|
56
|
-
};
|
|
57
|
-
return rval;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
2
|
-
import { PromiseRatchet } from '@bitblit/ratchet-common/lib/lang/promise-ratchet.js';
|
|
3
|
-
import { TimeoutToken } from '@bitblit/ratchet-common/lib/lang/timeout-token.js';
|
|
4
|
-
import { RequestTimeoutError } from '../../http/error/request-timeout-error.js';
|
|
5
|
-
import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
|
|
6
|
-
export class ApolloFilter {
|
|
7
|
-
static CACHE_APOLLO_HANDLER;
|
|
8
|
-
static async handlePathWithApollo(fCtx, apolloPathRegex, apolloServer, createHandlerOptions) {
|
|
9
|
-
if (fCtx.event?.path && apolloPathRegex && apolloPathRegex.test(fCtx.event.path)) {
|
|
10
|
-
fCtx.result = await ApolloFilter.processApolloRequest(fCtx.event, fCtx.context, apolloServer, createHandlerOptions);
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
static async processApolloRequest(event, context, apolloServer, createHandlerOptions) {
|
|
18
|
-
Logger.silly('Processing event with apollo: %j', event);
|
|
19
|
-
let rval = null;
|
|
20
|
-
if (!ApolloFilter.CACHE_APOLLO_HANDLER) {
|
|
21
|
-
ApolloFilter.CACHE_APOLLO_HANDLER = apolloServer.createHandler(createHandlerOptions);
|
|
22
|
-
}
|
|
23
|
-
event.multiValueHeaders = event.multiValueHeaders || {};
|
|
24
|
-
Object.keys(event.headers).forEach((k) => {
|
|
25
|
-
event.multiValueHeaders[k] = [event.headers[k]];
|
|
26
|
-
});
|
|
27
|
-
event.httpMethod = event.httpMethod.toUpperCase();
|
|
28
|
-
if (event.isBase64Encoded && !!event.body) {
|
|
29
|
-
event.body = Buffer.from(event.body, 'base64').toString();
|
|
30
|
-
event.isBase64Encoded = false;
|
|
31
|
-
}
|
|
32
|
-
const apolloPromise = ApolloFilter.CACHE_APOLLO_HANDLER(event, context, null) || Promise.resolve(null);
|
|
33
|
-
const timeoutMS = context.getRemainingTimeInMillis() - 500;
|
|
34
|
-
let result = null;
|
|
35
|
-
if (timeoutMS) {
|
|
36
|
-
result = await PromiseRatchet.timeout(apolloPromise, 'Apollo timed out after ' + timeoutMS + ' ms.', timeoutMS);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
Logger.warn('No timeout set even after defaulting for Apollo');
|
|
40
|
-
result = await apolloPromise;
|
|
41
|
-
}
|
|
42
|
-
if (TimeoutToken.isTimeoutToken(result)) {
|
|
43
|
-
result.writeToLog();
|
|
44
|
-
throw new RequestTimeoutError('Timed out');
|
|
45
|
-
}
|
|
46
|
-
rval = result;
|
|
47
|
-
if (StringRatchet.trimToEmpty(rval?.body).startsWith('<!DOCTYPE html>')) {
|
|
48
|
-
Logger.info('Forcing content type to html');
|
|
49
|
-
rval.headers = rval.headers || {};
|
|
50
|
-
rval.headers['content-type'] = 'text/html';
|
|
51
|
-
}
|
|
52
|
-
return rval;
|
|
53
|
-
}
|
|
54
|
-
static addApolloFilterToList(filters, apolloPathRegex, apolloServer, createHandlerOptions) {
|
|
55
|
-
if (filters) {
|
|
56
|
-
filters.push((fCtx) => ApolloFilter.handlePathWithApollo(fCtx, apolloPathRegex, apolloServer, createHandlerOptions));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
|
|
2
|
-
import { UnauthorizedError } from '../../http/error/unauthorized-error.js';
|
|
3
|
-
import { MisconfiguredError } from '../../http/error/misconfigured-error.js';
|
|
4
|
-
import { ForbiddenError } from '../../http/error/forbidden-error.js';
|
|
5
|
-
import { EventUtil } from '../../http/event-util.js';
|
|
6
|
-
export class BuiltInAuthFilters {
|
|
7
|
-
static async requireAllRolesInCommonJwt(fCtx, requiredRoleAllOf) {
|
|
8
|
-
if (!requiredRoleAllOf || requiredRoleAllOf.length === 0) {
|
|
9
|
-
throw new MisconfiguredError('You must require at least 1 role');
|
|
10
|
-
}
|
|
11
|
-
if (!fCtx.event?.authorization?.auth) {
|
|
12
|
-
throw new UnauthorizedError('May not proceed, not authenticated');
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
const asJwt = fCtx.event.authorization.auth;
|
|
16
|
-
if (!asJwt.roles || asJwt.roles.length === 0) {
|
|
17
|
-
throw new UnauthorizedError('Required role not found');
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
requiredRoleAllOf.forEach((r) => {
|
|
21
|
-
if (!asJwt.roles.includes(r)) {
|
|
22
|
-
throw new UnauthorizedError('Required role not found');
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
static async requireAnyRoleInCommonJwt(fCtx, requiredRoleOneOf) {
|
|
30
|
-
if (!requiredRoleOneOf || requiredRoleOneOf.length === 0) {
|
|
31
|
-
throw new MisconfiguredError('You must require at least 1 role');
|
|
32
|
-
}
|
|
33
|
-
if (!fCtx.event?.authorization?.auth) {
|
|
34
|
-
throw new UnauthorizedError('May not proceed, not authenticated');
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
const asJwt = fCtx.event.authorization.auth;
|
|
38
|
-
if (!asJwt.roles || asJwt.roles.length === 0) {
|
|
39
|
-
throw new UnauthorizedError('Required role not found');
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
let found = false;
|
|
43
|
-
requiredRoleOneOf.forEach((r) => {
|
|
44
|
-
if (!found && asJwt.roles.includes(r)) {
|
|
45
|
-
found = true;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
if (!found) {
|
|
49
|
-
throw new UnauthorizedError('Required role not found');
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
static async parseAuthorizationHeader(fCtx, webTokenManipulators) {
|
|
56
|
-
if (!fCtx?.event || !webTokenManipulators || (Array.isArray(webTokenManipulators) && !webTokenManipulators.length)) {
|
|
57
|
-
throw new MisconfiguredError('Cannot continue - missing event or encryption');
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
const tokenString = EventUtil.extractBearerTokenFromEvent(fCtx?.event);
|
|
61
|
-
if (!Array.isArray(webTokenManipulators)) {
|
|
62
|
-
webTokenManipulators = [webTokenManipulators];
|
|
63
|
-
}
|
|
64
|
-
for (let i = 0; i < webTokenManipulators.length && !fCtx?.event?.authorization?.auth; i++) {
|
|
65
|
-
const manipulator = webTokenManipulators[i];
|
|
66
|
-
try {
|
|
67
|
-
const token = await manipulator.extractTokenFromAuthorizationHeader(tokenString);
|
|
68
|
-
fCtx.event.authorization = {
|
|
69
|
-
raw: tokenString,
|
|
70
|
-
auth: token,
|
|
71
|
-
error: null,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
catch (err) {
|
|
75
|
-
fCtx.event.authorization = {
|
|
76
|
-
raw: tokenString,
|
|
77
|
-
auth: null,
|
|
78
|
-
error: err['message'],
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
static async applyOpenApiAuthorization(fCtx) {
|
|
86
|
-
if (StringRatchet.trimToNull(fCtx?.routeAndParse?.mapping?.authorizerName)) {
|
|
87
|
-
const authorizer = fCtx?.authenticators?.get(fCtx.routeAndParse.mapping.authorizerName);
|
|
88
|
-
if (authorizer) {
|
|
89
|
-
if (fCtx?.event?.authorization?.auth) {
|
|
90
|
-
const allowed = await authorizer(fCtx.event.authorization, fCtx.event, fCtx.routeAndParse.mapping);
|
|
91
|
-
if (!allowed) {
|
|
92
|
-
throw new ForbiddenError('You lack privileges to see this endpoint');
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
throw new UnauthorizedError('You need to supply credentials for this endpoint');
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
throw new MisconfiguredError().withFormattedErrorMessage('Authorizer %s requested but not found', fCtx.routeAndParse.mapping.authorizerName);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
}
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
2
|
-
export class BuiltInAuthorizers {
|
|
3
|
-
static async simpleNoAuthenticationLogAccess(authorizationContext, evt) {
|
|
4
|
-
Logger.debug('Auth requested for %s : %j', evt.path, authorizationContext?.auth);
|
|
5
|
-
return true;
|
|
6
|
-
}
|
|
7
|
-
static async simpleLoggedInAuth(authorizationContext, evt) {
|
|
8
|
-
const rval = !!authorizationContext?.auth;
|
|
9
|
-
Logger.silly('SimpleLoggedInAuth returning %s for %s', rval, evt.path);
|
|
10
|
-
return rval;
|
|
11
|
-
}
|
|
12
|
-
static async simpleRoleRouteAuth(authorizationContext, event, route, requiredRoleOneOf = null, requiredRoleAllOf = null) {
|
|
13
|
-
let rval = true;
|
|
14
|
-
const token = authorizationContext?.auth;
|
|
15
|
-
if (token) {
|
|
16
|
-
if (requiredRoleOneOf) {
|
|
17
|
-
requiredRoleOneOf.forEach((r) => {
|
|
18
|
-
rval = rval || token.roles.indexOf(r) > -1;
|
|
19
|
-
});
|
|
20
|
-
if (!rval) {
|
|
21
|
-
Logger.warn('Request to %s failed to find at least one of %j', route.path, requiredRoleOneOf);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
if (rval && requiredRoleAllOf) {
|
|
25
|
-
requiredRoleAllOf.forEach((r) => {
|
|
26
|
-
rval = rval && token.roles.indexOf(r) > -1;
|
|
27
|
-
});
|
|
28
|
-
if (!rval) {
|
|
29
|
-
Logger.warn('Request to %s failed to find all of %j', route.path, requiredRoleAllOf);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
Logger.warn('Cannot authenticate - no parsed auth found');
|
|
35
|
-
rval = false;
|
|
36
|
-
}
|
|
37
|
-
return rval;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
2
|
-
import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
|
|
3
|
-
import { MapRatchet } from '@bitblit/ratchet-common/lib/lang/map-ratchet.js';
|
|
4
|
-
import { EventUtil } from '../../http/event-util.js';
|
|
5
|
-
import { BadRequestError } from '../../http/error/bad-request-error.js';
|
|
6
|
-
import { ResponseUtil } from '../../http/response-util.js';
|
|
7
|
-
import { EpsilonHttpError } from '../../http/error/epsilon-http-error.js';
|
|
8
|
-
import { MisconfiguredError } from '../../http/error/misconfigured-error.js';
|
|
9
|
-
export class BuiltInFilters {
|
|
10
|
-
static MAXIMUM_LAMBDA_BODY_SIZE_BYTES = 1024 * 1024 * 5 - 1024 * 100;
|
|
11
|
-
static async combineFilters(fCtx, filters) {
|
|
12
|
-
let cont = true;
|
|
13
|
-
if (filters && filters.length > 0) {
|
|
14
|
-
for (let i = 0; i < filters.length && cont; i++) {
|
|
15
|
-
cont = await filters[i](fCtx);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return cont;
|
|
19
|
-
}
|
|
20
|
-
static async applyGzipIfPossible(fCtx) {
|
|
21
|
-
if (fCtx.event?.headers && fCtx.result) {
|
|
22
|
-
const encodingHeader = fCtx.event && fCtx.event.headers ? MapRatchet.extractValueFromMapIgnoreCase(fCtx.event.headers, 'accept-encoding') : null;
|
|
23
|
-
fCtx.result = await ResponseUtil.applyGzipIfPossible(encodingHeader, fCtx.result);
|
|
24
|
-
}
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
static async addConstantHeaders(fCtx, headers) {
|
|
28
|
-
if (headers && fCtx.result) {
|
|
29
|
-
fCtx.result.headers = Object.assign({}, headers, fCtx.result.headers);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
Logger.warn('Could not add headers - either result or headers were missing');
|
|
33
|
-
}
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
static async addAWSRequestIdHeader(fCtx, headerName = 'X-REQUEST-ID') {
|
|
37
|
-
if (fCtx.result && StringRatchet.trimToNull(headerName) && headerName.startsWith('X-')) {
|
|
38
|
-
fCtx.result.headers = fCtx.result.headers || {};
|
|
39
|
-
fCtx.result.headers[headerName] = fCtx.context?.awsRequestId || 'Request-Id-Missing';
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
Logger.warn('Could not add request id header - either result or context were missing or name was invalid');
|
|
43
|
-
}
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
static async addAllowEverythingCORSHeaders(fCtx) {
|
|
47
|
-
return BuiltInFilters.addConstantHeaders(fCtx, {
|
|
48
|
-
'Access-Control-Allow-Origin': '*',
|
|
49
|
-
'Access-Control-Allow-Methods': '*',
|
|
50
|
-
'Access-Control-Allow-Headers': '*',
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
static async addAllowReflectionCORSHeaders(fCtx) {
|
|
54
|
-
return BuiltInFilters.addConstantHeaders(fCtx, {
|
|
55
|
-
'Access-Control-Allow-Origin': MapRatchet.caseInsensitiveAccess(fCtx.event.headers, 'Origin') || '*',
|
|
56
|
-
'Access-Control-Allow-Methods': MapRatchet.caseInsensitiveAccess(fCtx.event.headers, 'Access-Control-Request-Method') || '*',
|
|
57
|
-
'Access-Control-Allow-Headers': MapRatchet.caseInsensitiveAccess(fCtx.event.headers, 'Access-Control-Request-Headers') || '*',
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
static async uriDecodeQueryParams(fCtx) {
|
|
61
|
-
if (fCtx?.event?.queryStringParameters) {
|
|
62
|
-
Object.keys(fCtx.event.queryStringParameters).forEach((k) => {
|
|
63
|
-
const val = fCtx.event.queryStringParameters[k];
|
|
64
|
-
if (val) {
|
|
65
|
-
fCtx.event.queryStringParameters[k] = decodeURIComponent(val);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
if (fCtx?.event?.multiValueQueryStringParameters) {
|
|
70
|
-
Object.keys(fCtx.event.multiValueQueryStringParameters).forEach((k) => {
|
|
71
|
-
const val = fCtx.event.multiValueQueryStringParameters[k];
|
|
72
|
-
if (val && val.length) {
|
|
73
|
-
const cleaned = val.map((v) => decodeURIComponent(v));
|
|
74
|
-
fCtx.event.multiValueQueryStringParameters[k] = cleaned;
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
static async fixStillEncodedQueryParams(fCtx) {
|
|
81
|
-
EventUtil.fixStillEncodedQueryParams(fCtx.event);
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
static async disallowStringNullAsPathParameter(fCtx) {
|
|
85
|
-
if (fCtx?.event?.pathParameters) {
|
|
86
|
-
Object.keys(fCtx.event.pathParameters).forEach((k) => {
|
|
87
|
-
if ('null' === StringRatchet.trimToEmpty(fCtx.event.pathParameters[k]).toLowerCase()) {
|
|
88
|
-
throw new BadRequestError().withFormattedErrorMessage('Path parameter %s was string -null-', k);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
static async disallowStringNullAsQueryStringParameter(fCtx) {
|
|
95
|
-
if (fCtx?.event?.queryStringParameters) {
|
|
96
|
-
Object.keys(fCtx.event.queryStringParameters).forEach((k) => {
|
|
97
|
-
if ('null' === StringRatchet.trimToEmpty(fCtx.event.queryStringParameters[k]).toLowerCase()) {
|
|
98
|
-
throw new BadRequestError().withFormattedErrorMessage('Query parameter %s was string -null-', k);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
static async ensureEventMaps(fCtx) {
|
|
105
|
-
fCtx.event.queryStringParameters = fCtx.event.queryStringParameters || {};
|
|
106
|
-
fCtx.event.headers = fCtx.event.headers || {};
|
|
107
|
-
fCtx.event.pathParameters = fCtx.event.pathParameters || {};
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
static async parseJsonBodyToObject(fCtx) {
|
|
111
|
-
if (fCtx.event?.body) {
|
|
112
|
-
try {
|
|
113
|
-
fCtx.event.parsedBody = EventUtil.jsonBodyToObject(fCtx.event);
|
|
114
|
-
}
|
|
115
|
-
catch (err) {
|
|
116
|
-
throw new EpsilonHttpError('Supplied body was not parsable as valid JSON').withHttpStatusCode(400);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return true;
|
|
120
|
-
}
|
|
121
|
-
static async checkMaximumLambdaBodySize(fCtx) {
|
|
122
|
-
if (fCtx.result?.body && fCtx.result.body.length > BuiltInFilters.MAXIMUM_LAMBDA_BODY_SIZE_BYTES) {
|
|
123
|
-
const delta = fCtx.result.body.length - BuiltInFilters.MAXIMUM_LAMBDA_BODY_SIZE_BYTES;
|
|
124
|
-
throw new EpsilonHttpError('Response size is ' + fCtx.result.body.length + ' bytes, which is ' + delta + ' bytes too large for this handler').withHttpStatusCode(500);
|
|
125
|
-
}
|
|
126
|
-
return true;
|
|
127
|
-
}
|
|
128
|
-
static async validateInboundBody(fCtx) {
|
|
129
|
-
if (fCtx?.event?.parsedBody && fCtx.routeAndParse) {
|
|
130
|
-
if (fCtx.routeAndParse.mapping.validation) {
|
|
131
|
-
if (!fCtx.modelValidator) {
|
|
132
|
-
throw new MisconfiguredError('Requested body validation but supplied no validator');
|
|
133
|
-
}
|
|
134
|
-
const errors = fCtx.modelValidator.validate(fCtx.routeAndParse.mapping.validation.modelName, fCtx.event.parsedBody, fCtx.routeAndParse.mapping.validation.emptyAllowed, fCtx.routeAndParse.mapping.validation.extraPropertiesAllowed);
|
|
135
|
-
if (errors.length > 0) {
|
|
136
|
-
Logger.info('Found errors while validating %s object %j', fCtx.routeAndParse.mapping.validation.modelName, errors);
|
|
137
|
-
const newError = new BadRequestError(...errors);
|
|
138
|
-
throw newError;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
Logger.debug('No validation since no route specified or no parsed body');
|
|
144
|
-
}
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
static async validateInboundQueryParams(fCtx) {
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
static async validateInboundPathParams(fCtx) {
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
153
|
-
static async validateOutboundResponse(fCtx) {
|
|
154
|
-
if (fCtx?.rawResult) {
|
|
155
|
-
if (fCtx.routeAndParse.mapping.outboundValidation) {
|
|
156
|
-
Logger.debug('Applying outbound check to %j', fCtx.rawResult);
|
|
157
|
-
const errors = fCtx.modelValidator.validate(fCtx.routeAndParse.mapping.outboundValidation.modelName, fCtx.rawResult, fCtx.routeAndParse.mapping.outboundValidation.emptyAllowed, fCtx.routeAndParse.mapping.outboundValidation.extraPropertiesAllowed);
|
|
158
|
-
if (errors.length > 0) {
|
|
159
|
-
Logger.error('Found outbound errors while validating %s object %j', fCtx.routeAndParse.mapping.outboundValidation.modelName, errors);
|
|
160
|
-
errors.unshift('Server sent object invalid according to spec');
|
|
161
|
-
throw new EpsilonHttpError().withErrors(errors).withHttpStatusCode(500).withDetails(fCtx.rawResult);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
Logger.debug('Applied no outbound validation because none set');
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
Logger.debug('No validation since no outbound body or disabled');
|
|
170
|
-
}
|
|
171
|
-
return true;
|
|
172
|
-
}
|
|
173
|
-
static async autoRespondToOptionsRequestWithCors(fCtx) {
|
|
174
|
-
if (StringRatchet.trimToEmpty(fCtx?.event?.httpMethod).toLowerCase() === 'options') {
|
|
175
|
-
fCtx.result = {
|
|
176
|
-
statusCode: 200,
|
|
177
|
-
body: '{"cors":true, "m":2}',
|
|
178
|
-
};
|
|
179
|
-
await BuiltInFilters.addAllowReflectionCORSHeaders(fCtx);
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
return true;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
static async autoRespond(fCtx, inBody) {
|
|
187
|
-
const body = inBody || {
|
|
188
|
-
message: 'Not Implemented',
|
|
189
|
-
};
|
|
190
|
-
fCtx.result = {
|
|
191
|
-
statusCode: 200,
|
|
192
|
-
body: JSON.stringify(body),
|
|
193
|
-
};
|
|
194
|
-
return false;
|
|
195
|
-
}
|
|
196
|
-
static async secureOutboundServerErrorForProduction(fCtx, errorMessage, errCode) {
|
|
197
|
-
if (fCtx?.result?.statusCode) {
|
|
198
|
-
if (errCode === null || fCtx.result.statusCode === errCode) {
|
|
199
|
-
Logger.warn('Securing outbound error info (was : %j)', fCtx.result.body);
|
|
200
|
-
fCtx.rawResult = new EpsilonHttpError(errorMessage).withHttpStatusCode(fCtx.result.statusCode);
|
|
201
|
-
const oldResult = fCtx.result;
|
|
202
|
-
fCtx.result = ResponseUtil.errorResponse(fCtx.rawResult);
|
|
203
|
-
fCtx.result.headers = Object.assign({}, oldResult.headers || {}, fCtx.result.headers || {});
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return true;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
|
|
2
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
3
|
-
import { NumberRatchet } from '@bitblit/ratchet-common/lib/lang/number-ratchet.js';
|
|
4
|
-
import { BadRequestError } from '../../http/error/bad-request-error.js';
|
|
5
|
-
import { EpsilonHttpError } from '../../http/error/epsilon-http-error.js';
|
|
6
|
-
import { UnauthorizedError } from '../../http/error/unauthorized-error.js';
|
|
7
|
-
import { NotFoundError } from '../../http/error/not-found-error.js';
|
|
8
|
-
import { ForbiddenError } from '../../http/error/forbidden-error.js';
|
|
9
|
-
import { NotImplemented } from '../../http/error/not-implemented.js';
|
|
10
|
-
import { MisconfiguredError } from '../../http/error/misconfigured-error.js';
|
|
11
|
-
export class BuiltInHandlers {
|
|
12
|
-
static async expectedHandledByFilter(evt, flag) {
|
|
13
|
-
throw new MisconfiguredError().withFormattedErrorMessage('Should not happen - it was expected that route %s would be handled by a filter', evt.path);
|
|
14
|
-
}
|
|
15
|
-
static async handleNotImplemented(evt, flag) {
|
|
16
|
-
Logger.info('A request was made to %s with body %j - not yet implemented', evt.path, evt.body);
|
|
17
|
-
const rval = {
|
|
18
|
-
time: new Date().toLocaleString(),
|
|
19
|
-
path: evt.path,
|
|
20
|
-
message: 'NOT IMPLEMENTED YET',
|
|
21
|
-
};
|
|
22
|
-
return rval;
|
|
23
|
-
}
|
|
24
|
-
static async sample(evt, flag, context) {
|
|
25
|
-
const rval = {
|
|
26
|
-
time: new Date().toLocaleString(),
|
|
27
|
-
evt: evt,
|
|
28
|
-
pad: StringRatchet.createRandomHexString(2000),
|
|
29
|
-
flag: flag,
|
|
30
|
-
};
|
|
31
|
-
if (context) {
|
|
32
|
-
rval['context'] = context;
|
|
33
|
-
}
|
|
34
|
-
const errNumber = NumberRatchet.safeNumber(evt.queryStringParameters['error']);
|
|
35
|
-
if (errNumber) {
|
|
36
|
-
switch (errNumber) {
|
|
37
|
-
case -1:
|
|
38
|
-
throw new Error('Test random failure');
|
|
39
|
-
case 400:
|
|
40
|
-
throw new BadRequestError('Bad request error');
|
|
41
|
-
case 401:
|
|
42
|
-
throw new UnauthorizedError('Unauthorized error');
|
|
43
|
-
case 403:
|
|
44
|
-
throw new ForbiddenError('Forbidden error');
|
|
45
|
-
case 404:
|
|
46
|
-
throw new NotFoundError('Not Found error');
|
|
47
|
-
case 501:
|
|
48
|
-
throw new NotImplemented('Not Implemented');
|
|
49
|
-
default:
|
|
50
|
-
throw new EpsilonHttpError()
|
|
51
|
-
.withFormattedErrorMessage('Default error - %s', errNumber)
|
|
52
|
-
.withHttpStatusCode(500)
|
|
53
|
-
.withDetails({ src: errNumber })
|
|
54
|
-
.withEndUserErrors(['msg1', 'msg2']);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
let test = StringRatchet.trimToNull(evt.queryStringParameters['test']);
|
|
58
|
-
if (test) {
|
|
59
|
-
test = test.toLowerCase();
|
|
60
|
-
if (test === 'null') {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return rval;
|
|
65
|
-
}
|
|
66
|
-
static async defaultErrorProcessor(event, err, cfg) {
|
|
67
|
-
Logger.warn('Unhandled error (in promise catch) : %s \nStack was: %s\nEvt was: %j\nConfig was: %j', err.message, err.stack, event, cfg);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
2
|
-
export class LogLevelManipulationFilter {
|
|
3
|
-
static LOG_LEVEL_BEFORE_CHANGE = null;
|
|
4
|
-
static async setLogLevelForTransaction(fCtx) {
|
|
5
|
-
LogLevelManipulationFilter.LOG_LEVEL_BEFORE_CHANGE = Logger.getLevel();
|
|
6
|
-
return true;
|
|
7
|
-
}
|
|
8
|
-
static async clearLogLevelForTransaction(fCtx) {
|
|
9
|
-
if (LogLevelManipulationFilter.LOG_LEVEL_BEFORE_CHANGE) {
|
|
10
|
-
Logger.setLevel(LogLevelManipulationFilter.LOG_LEVEL_BEFORE_CHANGE);
|
|
11
|
-
LogLevelManipulationFilter.LOG_LEVEL_BEFORE_CHANGE = null;
|
|
12
|
-
Logger.updateTracePrefix(null);
|
|
13
|
-
}
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
2
|
-
import { PromiseRatchet } from '@bitblit/ratchet-common/lib/lang/promise-ratchet.js';
|
|
3
|
-
import { TimeoutToken } from '@bitblit/ratchet-common/lib/lang/timeout-token.js';
|
|
4
|
-
import { RequestTimeoutError } from '../../http/error/request-timeout-error.js';
|
|
5
|
-
import { ResponseUtil } from '../../http/response-util.js';
|
|
6
|
-
import { NotFoundError } from '../../http/error/not-found-error.js';
|
|
7
|
-
import { NullReturnedObjectHandling } from '../../config/http/null-returned-object-handling.js';
|
|
8
|
-
import { EpsilonHttpError } from '../../http/error/epsilon-http-error.js';
|
|
9
|
-
export class RunHandlerAsFilter {
|
|
10
|
-
static async runHandler(fCtx, rm) {
|
|
11
|
-
const handler = RunHandlerAsFilter.findHandler(rm, fCtx.event, fCtx.context);
|
|
12
|
-
Logger.debug('Processing event with epsilon: %j', fCtx.event);
|
|
13
|
-
let tmp = await handler;
|
|
14
|
-
if (TimeoutToken.isTimeoutToken(tmp)) {
|
|
15
|
-
tmp.writeToLog();
|
|
16
|
-
throw new RequestTimeoutError('Timed out');
|
|
17
|
-
}
|
|
18
|
-
Logger.debug('Initial return value : %j', tmp);
|
|
19
|
-
tmp = RunHandlerAsFilter.applyNullReturnedObjectHandling(tmp, rm.mapping.metaProcessingConfig.nullReturnedObjectHandling);
|
|
20
|
-
fCtx.rawResult = tmp;
|
|
21
|
-
fCtx.result = ResponseUtil.coerceToProxyResult(tmp);
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
static applyNullReturnedObjectHandling(result, handling) {
|
|
25
|
-
let rval = result;
|
|
26
|
-
if (result === null || result === undefined) {
|
|
27
|
-
if (handling === NullReturnedObjectHandling.Error) {
|
|
28
|
-
Logger.error('Null object returned and Error specified, throwing 500');
|
|
29
|
-
throw new EpsilonHttpError('Null object').withHttpStatusCode(500);
|
|
30
|
-
}
|
|
31
|
-
else if (handling === NullReturnedObjectHandling.Return404NotFoundResponse) {
|
|
32
|
-
throw new NotFoundError('Resource not found');
|
|
33
|
-
}
|
|
34
|
-
else if (handling === NullReturnedObjectHandling.ConvertToEmptyString) {
|
|
35
|
-
Logger.warn('Null object returned from handler and convert not specified, converting to empty string');
|
|
36
|
-
rval = '';
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
throw new EpsilonHttpError('Cant happen - failed enum check').withHttpStatusCode(500);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return rval;
|
|
43
|
-
}
|
|
44
|
-
static async findHandler(rm, event, context, add404OnMissing = true) {
|
|
45
|
-
let rval = null;
|
|
46
|
-
if (rm) {
|
|
47
|
-
event.pathParameters = Object.assign({}, event.pathParameters, rm.parsed);
|
|
48
|
-
rval = PromiseRatchet.timeout(rm.mapping.function(event, context), 'Timed out after ' + rm.mapping.metaProcessingConfig.timeoutMS + ' ms. Request was ' + JSON.stringify(event), rm.mapping.metaProcessingConfig.timeoutMS);
|
|
49
|
-
}
|
|
50
|
-
else if (add404OnMissing) {
|
|
51
|
-
throw new NotFoundError('No such endpoint');
|
|
52
|
-
}
|
|
53
|
-
return rval;
|
|
54
|
-
}
|
|
55
|
-
static addRunHandlerAsFilterToList(filters, rm) {
|
|
56
|
-
if (filters) {
|
|
57
|
-
filters.push((fCtx) => RunHandlerAsFilter.runHandler(fCtx, rm));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|