@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
package/lib/http/web-handler.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
2
|
-
import Route from 'route-parser';
|
|
3
|
-
import { ResponseUtil } from './response-util.js';
|
|
4
|
-
import { RequireRatchet } from '@bitblit/ratchet-common/lib/lang/require-ratchet.js';
|
|
5
|
-
import { EpsilonHttpError } from './error/epsilon-http-error.js';
|
|
6
|
-
import { BuiltInFilters } from '../built-in/http/built-in-filters.js';
|
|
7
|
-
import { RunHandlerAsFilter } from '../built-in/http/run-handler-as-filter.js';
|
|
8
|
-
import { ContextUtil } from '../util/context-util.js';
|
|
9
|
-
import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
|
|
10
|
-
import { LambdaEventDetector } from '@bitblit/ratchet-aws/lib/lambda/lambda-event-detector.js';
|
|
11
|
-
export class WebHandler {
|
|
12
|
-
routerConfig;
|
|
13
|
-
static MAXIMUM_LAMBDA_BODY_SIZE_BYTES = 1024 * 1024 * 5 - 1024 * 100;
|
|
14
|
-
constructor(routerConfig) {
|
|
15
|
-
this.routerConfig = routerConfig;
|
|
16
|
-
RequireRatchet.notNullOrUndefined(routerConfig);
|
|
17
|
-
}
|
|
18
|
-
get router() {
|
|
19
|
-
return this.routerConfig;
|
|
20
|
-
}
|
|
21
|
-
extractLabel(evt, context) {
|
|
22
|
-
return 'WEB:' + StringRatchet.trimToEmpty(evt.httpMethod).toUpperCase() + ':' + evt.path;
|
|
23
|
-
}
|
|
24
|
-
handlesEvent(evt) {
|
|
25
|
-
return LambdaEventDetector.isValidApiGatewayEvent(evt);
|
|
26
|
-
}
|
|
27
|
-
async processEvent(event, context) {
|
|
28
|
-
if (!this.routerConfig) {
|
|
29
|
-
throw new Error('Router config not found');
|
|
30
|
-
}
|
|
31
|
-
const asExtended = Object.assign({}, { parsedBody: null, authorization: null, convertedFromV2Event: false }, event);
|
|
32
|
-
const rval = await this.openApiLambdaHandler(asExtended, context);
|
|
33
|
-
ContextUtil.addTraceToProxyResult(rval);
|
|
34
|
-
Logger.updateTracePrefix(null);
|
|
35
|
-
return rval;
|
|
36
|
-
}
|
|
37
|
-
async openApiLambdaHandler(evt, context) {
|
|
38
|
-
const rm = this.findBestMatchingRoute(evt);
|
|
39
|
-
const procConfig = rm?.mapping?.metaProcessingConfig
|
|
40
|
-
? rm.mapping.metaProcessingConfig
|
|
41
|
-
: this.routerConfig.config.defaultMetaHandling;
|
|
42
|
-
const fCtx = {
|
|
43
|
-
event: evt,
|
|
44
|
-
context: context,
|
|
45
|
-
result: null,
|
|
46
|
-
rawResult: null,
|
|
47
|
-
routeAndParse: rm,
|
|
48
|
-
modelValidator: this.routerConfig.config.overrideModelValidator || this.routerConfig.openApiModelValidator,
|
|
49
|
-
authenticators: this.routerConfig.config.authorizers,
|
|
50
|
-
};
|
|
51
|
-
try {
|
|
52
|
-
let filterChain = Object.assign([], procConfig.preFilters || []);
|
|
53
|
-
RunHandlerAsFilter.addRunHandlerAsFilterToList(filterChain, rm);
|
|
54
|
-
filterChain = filterChain.concat(procConfig.postFilters || []);
|
|
55
|
-
await BuiltInFilters.combineFilters(fCtx, filterChain);
|
|
56
|
-
}
|
|
57
|
-
catch (err) {
|
|
58
|
-
const wrapper = EpsilonHttpError.wrapError(err);
|
|
59
|
-
fCtx.result = ResponseUtil.errorResponse(wrapper);
|
|
60
|
-
try {
|
|
61
|
-
await BuiltInFilters.combineFilters(fCtx, procConfig.errorFilters);
|
|
62
|
-
}
|
|
63
|
-
catch (convErr) {
|
|
64
|
-
Logger.error('REALLY BAD - FAILED WHILE PROCESSING ERROR FILTERS : %s', convErr);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return fCtx.result;
|
|
68
|
-
}
|
|
69
|
-
findBestMatchingRoute(event) {
|
|
70
|
-
let rval = null;
|
|
71
|
-
const cleanPath = this.cleanPath(event);
|
|
72
|
-
const methodLower = event.httpMethod.toLowerCase();
|
|
73
|
-
const matchRoutes = this.routerConfig.routes
|
|
74
|
-
.map((r) => {
|
|
75
|
-
let rval = null;
|
|
76
|
-
if (r.method && r.method.toLowerCase() === methodLower) {
|
|
77
|
-
const routeParser = new Route(r.path);
|
|
78
|
-
const parsed = routeParser.match(cleanPath);
|
|
79
|
-
if (parsed !== false) {
|
|
80
|
-
rval = {
|
|
81
|
-
mapping: r,
|
|
82
|
-
route: routeParser,
|
|
83
|
-
parsed: parsed,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return rval;
|
|
88
|
-
})
|
|
89
|
-
.filter((r) => r != null);
|
|
90
|
-
matchRoutes.sort((a, b) => {
|
|
91
|
-
return Object.keys(a.parsed).length - Object.keys(b.parsed).length;
|
|
92
|
-
});
|
|
93
|
-
rval = matchRoutes && matchRoutes.length > 0 ? matchRoutes[0] : null;
|
|
94
|
-
if (!rval) {
|
|
95
|
-
Logger.debug('Failed to find handler for %s (cleaned path was %s, strip prefixes were %j)', event.path, cleanPath, this.routerConfig.config.prefixesToStripBeforeRouteMatch);
|
|
96
|
-
}
|
|
97
|
-
return rval;
|
|
98
|
-
}
|
|
99
|
-
cleanPath(event) {
|
|
100
|
-
let rval = event.path;
|
|
101
|
-
while (rval.startsWith('/')) {
|
|
102
|
-
rval = rval.substring(1);
|
|
103
|
-
}
|
|
104
|
-
if (this.routerConfig.config.prefixesToStripBeforeRouteMatch) {
|
|
105
|
-
this.routerConfig.config.prefixesToStripBeforeRouteMatch.forEach((prefix) => {
|
|
106
|
-
if (rval.toLowerCase().startsWith(prefix.toLowerCase() + '/')) {
|
|
107
|
-
rval = rval.substring(prefix.length);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
while (rval.startsWith('/')) {
|
|
112
|
-
rval = rval.substring(1);
|
|
113
|
-
}
|
|
114
|
-
rval = '/' + rval;
|
|
115
|
-
return rval;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
2
|
-
import { SampleServerComponents } from '../sample/sample-server-components.js';
|
|
3
|
-
import { LoggerLevelName } from '@bitblit/ratchet-common/lib/logger/logger-level-name.js';
|
|
4
|
-
describe('#errorToProxyResult', function () {
|
|
5
|
-
it('should gzip responses correctly', async () => {
|
|
6
|
-
const inst = await SampleServerComponents.createSampleEpsilonGlobalHandler('jest-gzip');
|
|
7
|
-
expect(inst.epsilon.modelValidator).toBeTruthy();
|
|
8
|
-
const evt = {
|
|
9
|
-
httpMethod: 'get',
|
|
10
|
-
multiValueHeaders: {},
|
|
11
|
-
multiValueQueryStringParameters: {},
|
|
12
|
-
path: '/meta/server',
|
|
13
|
-
pathParameters: null,
|
|
14
|
-
queryStringParameters: null,
|
|
15
|
-
stageVariables: null,
|
|
16
|
-
requestContext: {},
|
|
17
|
-
resource: '/meta/server',
|
|
18
|
-
headers: {
|
|
19
|
-
'content-type': 'application/json; charset=UTF-8',
|
|
20
|
-
'accept-encoding': 'gzip, deflate, br',
|
|
21
|
-
},
|
|
22
|
-
isBase64Encoded: true,
|
|
23
|
-
body: null,
|
|
24
|
-
};
|
|
25
|
-
Logger.setLevel(LoggerLevelName.silly);
|
|
26
|
-
const result = await inst.epsilon.webHandler.processEvent(evt, {});
|
|
27
|
-
expect(result).toBeTruthy();
|
|
28
|
-
expect(result.isBase64Encoded).toEqual(true);
|
|
29
|
-
expect(result.headers).toBeTruthy();
|
|
30
|
-
expect(result.headers['Content-Encoding']).toEqual('gzip');
|
|
31
|
-
});
|
|
32
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { AwsUtil } from '../util/aws-util.js';
|
|
2
|
-
import { LambdaEventDetector } from '@bitblit/ratchet-aws/lib/lambda/lambda-event-detector.js';
|
|
3
|
-
export class WebV2Handler {
|
|
4
|
-
webHandler;
|
|
5
|
-
constructor(webHandler) {
|
|
6
|
-
this.webHandler = webHandler;
|
|
7
|
-
}
|
|
8
|
-
extractLabel(evt, context) {
|
|
9
|
-
let rval = this.webHandler.extractLabel(AwsUtil.apiGatewayV2ToApiGatewayV1(evt), context);
|
|
10
|
-
rval = rval.replace('WEB:', 'WEB2:');
|
|
11
|
-
return rval;
|
|
12
|
-
}
|
|
13
|
-
handlesEvent(evt) {
|
|
14
|
-
return LambdaEventDetector.isValidApiGatewayV2WithRequestContextEvent(evt);
|
|
15
|
-
}
|
|
16
|
-
async processEvent(evt, context) {
|
|
17
|
-
const conv = AwsUtil.apiGatewayV2ToApiGatewayV1(evt);
|
|
18
|
-
const asExtended = Object.assign({}, { parsedBody: null, authorization: null, convertedFromV2Event: true }, conv);
|
|
19
|
-
const rval = await this.webHandler.openApiLambdaHandler(asExtended, context);
|
|
20
|
-
return rval;
|
|
21
|
-
}
|
|
22
|
-
}
|
package/lib/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { LambdaEventDetector } from '@bitblit/ratchet-aws/lib/lambda/lambda-event-detector.js';
|
|
2
|
-
import { EpsilonConstants } from '../epsilon-constants.js';
|
|
3
|
-
import { RequireRatchet } from '@bitblit/ratchet-common/lib/lang/require-ratchet.js';
|
|
4
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
5
|
-
import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
|
|
6
|
-
import { ContextUtil } from '../util/context-util.js';
|
|
7
|
-
export class InterApiUtil {
|
|
8
|
-
static isInterApiSnsEvent(event) {
|
|
9
|
-
return !!InterApiUtil.extractEntryFromEvent(event);
|
|
10
|
-
}
|
|
11
|
-
static extractEntryFromEvent(evt) {
|
|
12
|
-
let rval = null;
|
|
13
|
-
if (!!evt) {
|
|
14
|
-
if (LambdaEventDetector.isSingleSnsEvent(evt)) {
|
|
15
|
-
const cast = evt;
|
|
16
|
-
const msg = cast.Records[0].Sns.Message;
|
|
17
|
-
if (!!StringRatchet.trimToNull(msg)) {
|
|
18
|
-
const parsed = JSON.parse(msg);
|
|
19
|
-
if (!!parsed && parsed['type'] === EpsilonConstants.INTER_API_SNS_EVENT) {
|
|
20
|
-
rval = parsed['interApiEvent'];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return rval;
|
|
26
|
-
}
|
|
27
|
-
static async processInterApiEvent(evt, cfg, mgr) {
|
|
28
|
-
let rval = [];
|
|
29
|
-
RequireRatchet.notNullOrUndefined(evt, 'InterApiEntry');
|
|
30
|
-
RequireRatchet.notNullOrUndefined(mgr, 'BackgroundManager');
|
|
31
|
-
const interApiEntry = InterApiUtil.extractEntryFromEvent(evt);
|
|
32
|
-
ContextUtil.setOverrideTraceFromInterApiEntry(interApiEntry);
|
|
33
|
-
Logger.info('Processing inter-api event : %j', evt);
|
|
34
|
-
const backgroundEntries = [];
|
|
35
|
-
cfg.processMappings.forEach((map) => {
|
|
36
|
-
if (!map.disabled && interApiEntry.source.match(map.sourceRegex) && interApiEntry.type.match(map.typeRegex)) {
|
|
37
|
-
map.backgroundProcessTypes.forEach((taskName) => {
|
|
38
|
-
const entry = mgr.createEntry(taskName, interApiEntry.data);
|
|
39
|
-
backgroundEntries.push(entry);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
if (backgroundEntries.length > 0) {
|
|
44
|
-
Logger.info('Adding %d entries to queue', backgroundEntries.length);
|
|
45
|
-
rval = await mgr.addEntriesToQueue(backgroundEntries, true);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
Logger.info('No entries mapped for this event');
|
|
49
|
-
}
|
|
50
|
-
return rval;
|
|
51
|
-
}
|
|
52
|
-
static addTraceToInterApiEntry(ent) {
|
|
53
|
-
if (ent) {
|
|
54
|
-
ent.traceId = ent.traceId || ContextUtil.currentTraceId();
|
|
55
|
-
ent.traceDepth = ent.traceDepth || ContextUtil.currentTraceDepth() + 1;
|
|
56
|
-
}
|
|
57
|
-
return ent;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { InterApiUtil } from './inter-api-util.js';
|
|
2
|
-
import { JestRatchet } from '@bitblit/ratchet-jest/lib/jest/jest-ratchet.js';
|
|
3
|
-
import { jest } from '@jest/globals';
|
|
4
|
-
describe('#interApiUtil', function () {
|
|
5
|
-
let mockSns;
|
|
6
|
-
let mockSqs;
|
|
7
|
-
let mockBgMgr;
|
|
8
|
-
const evt = {
|
|
9
|
-
Records: [
|
|
10
|
-
{
|
|
11
|
-
EventSource: 'aws:sns',
|
|
12
|
-
EventVersion: '1.0',
|
|
13
|
-
EventSubscriptionArn: 'arn:aws:sns:us-east-1:012345678901:GenericApiEventTopicDev:6efec6a5-1f02-4fc5-b0f7-fa7c013cf8bb',
|
|
14
|
-
Sns: {
|
|
15
|
-
Type: 'Notification',
|
|
16
|
-
MessageId: '205de1e8-7ba6-52f5-b706-b815f442c512',
|
|
17
|
-
TopicArn: 'arn:aws:sns:us-east-1:012345678901:GenericApiEventTopicDev',
|
|
18
|
-
Subject: null,
|
|
19
|
-
Message: '{"type":"EPSILON_INTER_API_EVENT","interApiEvent":{"source":"OriginalApi","type":"Sample","data":{"notes":"SOURCE API: OriginalApi","timestampEpochMS":1636011428200}}}',
|
|
20
|
-
Timestamp: '2021-11-04T07:37:08.241Z',
|
|
21
|
-
SignatureVersion: '1',
|
|
22
|
-
Signature: 'LyS2ybM/Epsq5sFqPJd==',
|
|
23
|
-
SigningCertUrl: 'https://sns.us-east-1.amazonaws.com/SimpleNotificationService-7ff5318490ec183fbaddaa2a969abfda.pem',
|
|
24
|
-
UnsubscribeUrl: 'https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:012345678901:GenericApiEventTopicDev:6efec6a5-1f02-4fc5-b0f7-fa7c013cf8bb',
|
|
25
|
-
MessageAttributes: {},
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
};
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
mockSns = JestRatchet.mock(jest.fn);
|
|
32
|
-
mockSqs = JestRatchet.mock(jest.fn);
|
|
33
|
-
mockBgMgr = JestRatchet.mock(jest.fn);
|
|
34
|
-
});
|
|
35
|
-
it('should translate processes', async () => {
|
|
36
|
-
mockBgMgr.createEntry.mockResolvedValue({ t: 1 });
|
|
37
|
-
mockBgMgr.addEntriesToQueue.mockResolvedValue(['a]']);
|
|
38
|
-
const cfg = {
|
|
39
|
-
aws: {
|
|
40
|
-
source: 'test',
|
|
41
|
-
snsArn: 'test',
|
|
42
|
-
localMode: true,
|
|
43
|
-
},
|
|
44
|
-
processMappings: [
|
|
45
|
-
{
|
|
46
|
-
typeRegex: '.*',
|
|
47
|
-
sourceRegex: '.*',
|
|
48
|
-
disabled: false,
|
|
49
|
-
backgroundProcessTypes: ['TESTBG'],
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
};
|
|
53
|
-
const output = await InterApiUtil.processInterApiEvent(evt, cfg, mockBgMgr);
|
|
54
|
-
expect(output).not.toBeNull();
|
|
55
|
-
expect(output.length).toEqual(1);
|
|
56
|
-
});
|
|
57
|
-
it('should verify that an event is an inter-api even', async () => {
|
|
58
|
-
const res = InterApiUtil.isInterApiSnsEvent(evt);
|
|
59
|
-
expect(res).toBeTruthy();
|
|
60
|
-
}, 500);
|
|
61
|
-
});
|
package/lib/inter-api-manager.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
2
|
-
import { EpsilonConstants } from './epsilon-constants.js';
|
|
3
|
-
import { InterApiUtil } from './inter-api/inter-api-util.js';
|
|
4
|
-
import { PublishCommand } from '@aws-sdk/client-sns';
|
|
5
|
-
export class InterApiManager {
|
|
6
|
-
_aws;
|
|
7
|
-
_sns;
|
|
8
|
-
constructor(_aws, _sns) {
|
|
9
|
-
this._aws = _aws;
|
|
10
|
-
this._sns = _sns;
|
|
11
|
-
}
|
|
12
|
-
get config() {
|
|
13
|
-
return this._aws;
|
|
14
|
-
}
|
|
15
|
-
get sns() {
|
|
16
|
-
return this._sns;
|
|
17
|
-
}
|
|
18
|
-
createEntry(type, data) {
|
|
19
|
-
const rval = {
|
|
20
|
-
source: this._aws.source,
|
|
21
|
-
type: type,
|
|
22
|
-
data: data,
|
|
23
|
-
};
|
|
24
|
-
return rval;
|
|
25
|
-
}
|
|
26
|
-
async fireInterApiEventByParts(type, data) {
|
|
27
|
-
const entry = this.createEntry(type, data);
|
|
28
|
-
const rval = await this.fireInterApiEvent(entry);
|
|
29
|
-
return rval;
|
|
30
|
-
}
|
|
31
|
-
async fireInterApiEvent(entry) {
|
|
32
|
-
let rval = null;
|
|
33
|
-
if (this.config.localMode) {
|
|
34
|
-
Logger.info('Fire inter-api event ignored because running locally (was %j)', entry);
|
|
35
|
-
rval = 'INTER-API-IGNORED';
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
try {
|
|
39
|
-
Logger.info('Firing inter-api event (remote) : %j ', entry);
|
|
40
|
-
const toWrite = {
|
|
41
|
-
type: EpsilonConstants.INTER_API_SNS_EVENT,
|
|
42
|
-
interApiEvent: InterApiUtil.addTraceToInterApiEntry(entry),
|
|
43
|
-
};
|
|
44
|
-
const msg = JSON.stringify(toWrite);
|
|
45
|
-
const snsId = await this.writeMessageToSnsTopic(msg);
|
|
46
|
-
Logger.debug('Inter-api Wrote message : %s to SNS : %s', rval, msg, snsId);
|
|
47
|
-
}
|
|
48
|
-
catch (err) {
|
|
49
|
-
Logger.error('Failed to fireImmediateProcessRequest : %s', err, err);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return rval;
|
|
53
|
-
}
|
|
54
|
-
async writeMessageToSnsTopic(message) {
|
|
55
|
-
let rval = null;
|
|
56
|
-
const params = {
|
|
57
|
-
Message: message,
|
|
58
|
-
TopicArn: this._aws.snsArn,
|
|
59
|
-
};
|
|
60
|
-
Logger.debug('Writing message to SNS topic : j', params);
|
|
61
|
-
const result = await this.sns.send(new PublishCommand(params));
|
|
62
|
-
rval = result.MessageId;
|
|
63
|
-
return rval;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
2
|
-
import { AwsUtil } from '../util/aws-util.js';
|
|
3
|
-
import { CronUtil } from '../util/cron-util.js';
|
|
4
|
-
import { LambdaEventDetector } from '@bitblit/ratchet-aws/lib/lambda/lambda-event-detector.js';
|
|
5
|
-
export class CronEpsilonLambdaEventHandler {
|
|
6
|
-
_epsilon;
|
|
7
|
-
constructor(_epsilon) {
|
|
8
|
-
this._epsilon = _epsilon;
|
|
9
|
-
}
|
|
10
|
-
extractLabel(evt, context) {
|
|
11
|
-
return 'CronEvt:' + evt.source;
|
|
12
|
-
}
|
|
13
|
-
handlesEvent(evt) {
|
|
14
|
-
return LambdaEventDetector.isValidCronEvent(evt);
|
|
15
|
-
}
|
|
16
|
-
async processEvent(evt, context) {
|
|
17
|
-
let rval = null;
|
|
18
|
-
Logger.debug('Epsilon: CRON: %j', evt);
|
|
19
|
-
if (!this._epsilon.config.cron) {
|
|
20
|
-
Logger.debug('Skipping - CRON disabled');
|
|
21
|
-
rval = {
|
|
22
|
-
statusCode: 200,
|
|
23
|
-
body: JSON.stringify({ message: 'CRON skipped - disabled' }),
|
|
24
|
-
isBase64Encoded: false,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
const output = await CronEpsilonLambdaEventHandler.processCronEvent(evt, this._epsilon.config.cron, this._epsilon.backgroundManager, this._epsilon.backgroundHandler);
|
|
29
|
-
rval = {
|
|
30
|
-
statusCode: 200,
|
|
31
|
-
body: JSON.stringify({ message: 'CRON complete' }),
|
|
32
|
-
isBase64Encoded: false,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
return rval;
|
|
36
|
-
}
|
|
37
|
-
static async processCronEvent(evt, cronConfig, backgroundManager, background) {
|
|
38
|
-
let rval = false;
|
|
39
|
-
if (cronConfig && evt && evt.resources[0]) {
|
|
40
|
-
if (!!cronConfig.entries) {
|
|
41
|
-
if (!!background) {
|
|
42
|
-
const toEnqueue = [];
|
|
43
|
-
for (let i = 0; i < cronConfig.entries.length; i++) {
|
|
44
|
-
const smCronEntry = cronConfig.entries[i];
|
|
45
|
-
if (CronUtil.eventMatchesEntry(evt, smCronEntry, cronConfig)) {
|
|
46
|
-
Logger.info('CRON Firing : %s', CronUtil.cronEntryName(smCronEntry));
|
|
47
|
-
const backgroundEntry = {
|
|
48
|
-
type: smCronEntry.backgroundTaskType,
|
|
49
|
-
data: AwsUtil.resolvePotentialFunctionToResult(smCronEntry.data, {}),
|
|
50
|
-
};
|
|
51
|
-
Logger.silly('Resolved entry : %j', backgroundEntry);
|
|
52
|
-
if (smCronEntry.fireImmediate) {
|
|
53
|
-
await backgroundManager.fireImmediateProcessRequest(backgroundEntry);
|
|
54
|
-
rval = true;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
toEnqueue.push(backgroundEntry);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (toEnqueue.length > 0) {
|
|
62
|
-
await backgroundManager.addEntriesToQueue(toEnqueue, true);
|
|
63
|
-
rval = true;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
Logger.warn('Cron defines background tasks, but no background manager provided');
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return rval;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { BackgroundHandler } from '../background/background-handler.js';
|
|
2
|
-
import { JestRatchet } from '@bitblit/ratchet-jest/lib/jest/jest-ratchet.js';
|
|
3
|
-
import { CronEpsilonLambdaEventHandler } from './cron-epsilon-lambda-event-handler.js';
|
|
4
|
-
import { SingleThreadLocalBackgroundManager } from '../background/manager/single-thread-local-background-manager.js';
|
|
5
|
-
import { jest } from '@jest/globals';
|
|
6
|
-
describe('#cronEpsilonLambdaEventHandler', function () {
|
|
7
|
-
let mockSqs;
|
|
8
|
-
let mockSns;
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
mockSqs = JestRatchet.mock(jest.fn);
|
|
11
|
-
mockSns = JestRatchet.mock(jest.fn);
|
|
12
|
-
});
|
|
13
|
-
xit('should verify that cron data functions get executed', async () => {
|
|
14
|
-
const evt = {
|
|
15
|
-
id: '1',
|
|
16
|
-
version: '1',
|
|
17
|
-
account: 'test',
|
|
18
|
-
time: 'test',
|
|
19
|
-
region: '',
|
|
20
|
-
resources: ['test'],
|
|
21
|
-
source: null,
|
|
22
|
-
detail: {},
|
|
23
|
-
'detail-type': null,
|
|
24
|
-
};
|
|
25
|
-
const cronConfig = {
|
|
26
|
-
timezone: 'America/Los_Angeles',
|
|
27
|
-
context: 'Test',
|
|
28
|
-
entries: [
|
|
29
|
-
{
|
|
30
|
-
backgroundTaskType: 'test',
|
|
31
|
-
fireImmediate: true,
|
|
32
|
-
data: () => {
|
|
33
|
-
return { curDate: new Date().toISOString(), fixed: 'abc' };
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
};
|
|
38
|
-
const smConfig = {
|
|
39
|
-
processors: [],
|
|
40
|
-
httpSubmissionPath: '/background/',
|
|
41
|
-
implyTypeFromPathSuffix: true,
|
|
42
|
-
httpMetaEndpoint: '/background-meta',
|
|
43
|
-
};
|
|
44
|
-
const background = new BackgroundHandler(null, null);
|
|
45
|
-
background.getConfig = jest.fn(() => smConfig);
|
|
46
|
-
const backgroundManager = new SingleThreadLocalBackgroundManager();
|
|
47
|
-
const res = await CronEpsilonLambdaEventHandler.processCronEvent(evt, cronConfig, backgroundManager, background);
|
|
48
|
-
expect(res).toBeTruthy();
|
|
49
|
-
}, 500);
|
|
50
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
2
|
-
import { AwsUtil } from '../util/aws-util.js';
|
|
3
|
-
import { LambdaEventDetector } from '@bitblit/ratchet-aws/lib/lambda/lambda-event-detector.js';
|
|
4
|
-
export class DynamoEpsilonLambdaEventHandler {
|
|
5
|
-
_epsilon;
|
|
6
|
-
constructor(_epsilon) {
|
|
7
|
-
this._epsilon = _epsilon;
|
|
8
|
-
}
|
|
9
|
-
extractLabel(evt, context) {
|
|
10
|
-
return 'DDBEvt:' + evt.Records[0].eventName + ':' + evt.Records[0].eventSource;
|
|
11
|
-
}
|
|
12
|
-
handlesEvent(evt) {
|
|
13
|
-
return LambdaEventDetector.isValidDynamoDBEvent(evt);
|
|
14
|
-
}
|
|
15
|
-
async processEvent(evt, context) {
|
|
16
|
-
let rval = null;
|
|
17
|
-
if (this._epsilon.config && this._epsilon.config.dynamoDb && evt && evt.Records && evt.Records.length > 0) {
|
|
18
|
-
const finder = evt.Records[0].eventSourceARN;
|
|
19
|
-
const handler = AwsUtil.findInMap(finder, this._epsilon.config.dynamoDb.handlers);
|
|
20
|
-
if (handler) {
|
|
21
|
-
rval = await handler(evt);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
Logger.info('Found no Dynamo handler for : %s', finder);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return rval;
|
|
28
|
-
}
|
|
29
|
-
async processUncaughtError(event, context, err) {
|
|
30
|
-
Logger.error('Error slipped out to outer edge (Dynamo). Logging and rethrowing : %s', err, err);
|
|
31
|
-
throw err;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
2
|
-
import { AwsUtil } from '../util/aws-util.js';
|
|
3
|
-
import { LambdaEventDetector } from '@bitblit/ratchet-aws/lib/lambda/lambda-event-detector.js';
|
|
4
|
-
export class GenericSnsEpsilonLambdaEventHandler {
|
|
5
|
-
_epsilon;
|
|
6
|
-
constructor(_epsilon) {
|
|
7
|
-
this._epsilon = _epsilon;
|
|
8
|
-
}
|
|
9
|
-
extractLabel(evt, context) {
|
|
10
|
-
return 'SNSEvt:' + evt.Records[0].EventSource;
|
|
11
|
-
}
|
|
12
|
-
handlesEvent(evt) {
|
|
13
|
-
return LambdaEventDetector.isValidSnsEvent(evt);
|
|
14
|
-
}
|
|
15
|
-
async processEvent(evt, context) {
|
|
16
|
-
let rval = null;
|
|
17
|
-
if (this._epsilon.config && this._epsilon.config.sns && evt && evt.Records.length > 0) {
|
|
18
|
-
const finder = evt.Records[0].Sns.TopicArn;
|
|
19
|
-
const handler = AwsUtil.findInMap(finder, this._epsilon.config.sns.handlers);
|
|
20
|
-
if (handler) {
|
|
21
|
-
rval = await handler(evt);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
Logger.info('Found no SNS handler for : %s', finder);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return rval;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { InterApiUtil } from '../inter-api/inter-api-util.js';
|
|
2
|
-
export class InterApiEpsilonLambdaEventHandler {
|
|
3
|
-
_epsilon;
|
|
4
|
-
constructor(_epsilon) {
|
|
5
|
-
this._epsilon = _epsilon;
|
|
6
|
-
}
|
|
7
|
-
extractLabel(evt, context) {
|
|
8
|
-
const ent = InterApiUtil.extractEntryFromEvent(evt);
|
|
9
|
-
return 'InterApi:' + ent.source + ':' + ent.type;
|
|
10
|
-
}
|
|
11
|
-
handlesEvent(evt) {
|
|
12
|
-
return this._epsilon.config.interApiConfig && InterApiUtil.isInterApiSnsEvent(evt);
|
|
13
|
-
}
|
|
14
|
-
async processEvent(evt, context) {
|
|
15
|
-
const tmp = await InterApiUtil.processInterApiEvent(evt, this._epsilon.config.interApiConfig, this._epsilon.backgroundManager);
|
|
16
|
-
const rval = {
|
|
17
|
-
statusCode: 200,
|
|
18
|
-
body: JSON.stringify(tmp),
|
|
19
|
-
isBase64Encoded: false,
|
|
20
|
-
};
|
|
21
|
-
return rval;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
2
|
-
import { AwsUtil } from '../util/aws-util.js';
|
|
3
|
-
import { LambdaEventDetector } from '@bitblit/ratchet-aws/lib/lambda/lambda-event-detector.js';
|
|
4
|
-
export class S3EpsilonLambdaEventHandler {
|
|
5
|
-
_epsilon;
|
|
6
|
-
constructor(_epsilon) {
|
|
7
|
-
this._epsilon = _epsilon;
|
|
8
|
-
}
|
|
9
|
-
extractLabel(evt, context) {
|
|
10
|
-
return 'S3Evt:' + evt.Records[0].eventSource;
|
|
11
|
-
}
|
|
12
|
-
handlesEvent(evt) {
|
|
13
|
-
return LambdaEventDetector.isValidS3Event(evt);
|
|
14
|
-
}
|
|
15
|
-
async processEvent(evt, context) {
|
|
16
|
-
let rval = null;
|
|
17
|
-
if (this._epsilon.config && this._epsilon.config.s3 && evt && evt.Records.length > 0) {
|
|
18
|
-
const finder = evt.Records[0].s3.bucket.name + '/' + evt.Records[0].s3.object.key;
|
|
19
|
-
const isRemoveEvent = evt.Records[0].eventName && evt.Records[0].eventName.startsWith('ObjectRemoved');
|
|
20
|
-
if (isRemoveEvent) {
|
|
21
|
-
const handler = AwsUtil.findInMap(finder, this._epsilon.config.s3.removeHandlers);
|
|
22
|
-
if (handler) {
|
|
23
|
-
rval = await handler(evt);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
Logger.info('Found no s3 create handler for : %s', finder);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
const handler = AwsUtil.findInMap(finder, this._epsilon.config.s3.createHandlers);
|
|
31
|
-
if (handler) {
|
|
32
|
-
rval = await handler(evt);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
Logger.info('Found no s3 remove handler for : %s', finder);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return rval;
|
|
40
|
-
}
|
|
41
|
-
}
|