@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/util/aws-util.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
export class AwsUtil {
|
|
2
|
-
static apiGatewayV2ToApiGatewayV1(srcEvt) {
|
|
3
|
-
const rval = {
|
|
4
|
-
requestContext: AwsUtil.apiGatewayV2RequestContextToApiGatewayV1RequestContext(srcEvt.requestContext),
|
|
5
|
-
httpMethod: srcEvt.requestContext.http.method,
|
|
6
|
-
path: srcEvt.requestContext.http.path,
|
|
7
|
-
queryStringParameters: srcEvt.queryStringParameters,
|
|
8
|
-
headers: srcEvt.headers,
|
|
9
|
-
body: srcEvt.body,
|
|
10
|
-
isBase64Encoded: srcEvt.isBase64Encoded,
|
|
11
|
-
multiValueHeaders: null,
|
|
12
|
-
multiValueQueryStringParameters: null,
|
|
13
|
-
pathParameters: srcEvt.pathParameters,
|
|
14
|
-
stageVariables: srcEvt.stageVariables,
|
|
15
|
-
resource: null,
|
|
16
|
-
};
|
|
17
|
-
return rval;
|
|
18
|
-
}
|
|
19
|
-
static apiGatewayV2RequestContextToApiGatewayV1RequestContext(srcEvt) {
|
|
20
|
-
const rval = {
|
|
21
|
-
accountId: srcEvt.accountId,
|
|
22
|
-
apiId: srcEvt.apiId,
|
|
23
|
-
authorizer: null,
|
|
24
|
-
domainName: srcEvt.domainName,
|
|
25
|
-
domainPrefix: srcEvt.domainPrefix,
|
|
26
|
-
requestId: srcEvt.requestId,
|
|
27
|
-
routeKey: srcEvt.routeKey,
|
|
28
|
-
stage: srcEvt.stage,
|
|
29
|
-
requestTime: srcEvt.time,
|
|
30
|
-
requestTimeEpoch: srcEvt.timeEpoch,
|
|
31
|
-
protocol: srcEvt.http.protocol,
|
|
32
|
-
httpMethod: srcEvt.http.method,
|
|
33
|
-
identity: null,
|
|
34
|
-
path: srcEvt.http.path,
|
|
35
|
-
resourceId: null,
|
|
36
|
-
resourcePath: null,
|
|
37
|
-
};
|
|
38
|
-
return rval;
|
|
39
|
-
}
|
|
40
|
-
static findInMap(toFind, map) {
|
|
41
|
-
let rval = null;
|
|
42
|
-
map.forEach((val, key) => {
|
|
43
|
-
if (AwsUtil.matchExact(key, toFind)) {
|
|
44
|
-
rval = val;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
return rval;
|
|
48
|
-
}
|
|
49
|
-
static matchExact(r, str) {
|
|
50
|
-
const match = str.match(r);
|
|
51
|
-
return match != null && str == match[0];
|
|
52
|
-
}
|
|
53
|
-
static resolvePotentialFunctionToResult(src, def) {
|
|
54
|
-
let rval = def;
|
|
55
|
-
if (src) {
|
|
56
|
-
if (typeof src === 'function') {
|
|
57
|
-
rval = src();
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
rval = src;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return rval;
|
|
64
|
-
}
|
|
65
|
-
}
|
package/lib/util/context-util.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
|
|
2
|
-
import { ErrorRatchet } from '@bitblit/ratchet-common/lib/lang/error-ratchet.js';
|
|
3
|
-
import { NumberRatchet } from '@bitblit/ratchet-common/lib/lang/number-ratchet.js';
|
|
4
|
-
import { BuiltInTraceIdGenerators } from '../built-in/built-in-trace-id-generators.js';
|
|
5
|
-
export class ContextUtil {
|
|
6
|
-
static CURRENT_EPSILON_REFERENCE;
|
|
7
|
-
static CURRENT_CONTEXT;
|
|
8
|
-
static CURRENT_EVENT;
|
|
9
|
-
static CURRENT_LOG_VARS = {};
|
|
10
|
-
static CURRENT_PROCESS_LABEL;
|
|
11
|
-
static CURRENT_OVERRIDE_TRACE_ID;
|
|
12
|
-
static CURRENT_OVERRIDE_TRACE_DEPTH;
|
|
13
|
-
constructor() { }
|
|
14
|
-
static initContext(epsilon, evt, ctx, processLabel) {
|
|
15
|
-
ContextUtil.CURRENT_EPSILON_REFERENCE = epsilon;
|
|
16
|
-
ContextUtil.CURRENT_CONTEXT = ctx;
|
|
17
|
-
ContextUtil.CURRENT_EVENT = evt;
|
|
18
|
-
ContextUtil.CURRENT_LOG_VARS = {};
|
|
19
|
-
ContextUtil.CURRENT_PROCESS_LABEL = processLabel;
|
|
20
|
-
}
|
|
21
|
-
static clearContext() {
|
|
22
|
-
ContextUtil.CURRENT_EPSILON_REFERENCE = null;
|
|
23
|
-
ContextUtil.CURRENT_CONTEXT = null;
|
|
24
|
-
ContextUtil.CURRENT_EVENT = null;
|
|
25
|
-
ContextUtil.CURRENT_LOG_VARS = {};
|
|
26
|
-
ContextUtil.CURRENT_PROCESS_LABEL = null;
|
|
27
|
-
ContextUtil.CURRENT_OVERRIDE_TRACE_ID = null;
|
|
28
|
-
ContextUtil.CURRENT_OVERRIDE_TRACE_DEPTH = null;
|
|
29
|
-
}
|
|
30
|
-
static setOverrideTrace(traceId, traceDepth) {
|
|
31
|
-
ContextUtil.CURRENT_OVERRIDE_TRACE_ID = traceId || ContextUtil.CURRENT_OVERRIDE_TRACE_ID;
|
|
32
|
-
ContextUtil.CURRENT_OVERRIDE_TRACE_DEPTH = traceDepth || ContextUtil.CURRENT_OVERRIDE_TRACE_DEPTH;
|
|
33
|
-
}
|
|
34
|
-
static setOverrideTraceFromInternalBackgroundEntry(entry) {
|
|
35
|
-
ContextUtil.setOverrideTrace(entry.traceId, entry.traceDepth);
|
|
36
|
-
}
|
|
37
|
-
static setOverrideTraceFromInterApiEntry(interApiEntry) {
|
|
38
|
-
ContextUtil.setOverrideTrace(interApiEntry.traceId, interApiEntry.traceDepth);
|
|
39
|
-
}
|
|
40
|
-
static addHeadersToRecord(input, depthOffset = 0) {
|
|
41
|
-
if (input) {
|
|
42
|
-
input[ContextUtil.traceHeaderName()] = ContextUtil.currentTraceId();
|
|
43
|
-
input[ContextUtil.traceDepthHeaderName()] = StringRatchet.safeString(ContextUtil.currentTraceDepth() + depthOffset);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
ErrorRatchet.throwFormattedErr('Cannot add headers to null/undefined input');
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
static addTraceToProxyResult(pr) {
|
|
50
|
-
pr.headers = pr.headers || {};
|
|
51
|
-
ContextUtil.addHeadersToRecord(pr.headers);
|
|
52
|
-
}
|
|
53
|
-
static addTraceToHttpRequestInit(ri) {
|
|
54
|
-
ri.headers = ri.headers || {};
|
|
55
|
-
ContextUtil.addHeadersToRecord(ri.headers, 1);
|
|
56
|
-
}
|
|
57
|
-
static setProcessLabel(processLabel) {
|
|
58
|
-
ContextUtil.CURRENT_PROCESS_LABEL = processLabel;
|
|
59
|
-
}
|
|
60
|
-
static currentRequestId() {
|
|
61
|
-
const ctx = ContextUtil.CURRENT_CONTEXT;
|
|
62
|
-
return ctx ? ctx.awsRequestId : null;
|
|
63
|
-
}
|
|
64
|
-
static remainingTimeMS() {
|
|
65
|
-
const ctx = ContextUtil.CURRENT_CONTEXT;
|
|
66
|
-
return ctx ? ctx.getRemainingTimeInMillis() : null;
|
|
67
|
-
}
|
|
68
|
-
static currentProcessLabel() {
|
|
69
|
-
return ContextUtil.CURRENT_PROCESS_LABEL || 'unset';
|
|
70
|
-
}
|
|
71
|
-
static traceHeaderName() {
|
|
72
|
-
const headerName = ContextUtil?.CURRENT_EPSILON_REFERENCE?.config?.loggerConfig?.traceHeaderName || 'X-TRACE-ID';
|
|
73
|
-
return headerName;
|
|
74
|
-
}
|
|
75
|
-
static traceDepthHeaderName() {
|
|
76
|
-
const headerName = ContextUtil?.CURRENT_EPSILON_REFERENCE?.config?.loggerConfig?.traceDepthHeaderName || 'X-TRACE-DEPTH';
|
|
77
|
-
return headerName;
|
|
78
|
-
}
|
|
79
|
-
static currentTraceId() {
|
|
80
|
-
const traceFn = ContextUtil?.CURRENT_EPSILON_REFERENCE?.config?.loggerConfig?.traceIdGenerator || BuiltInTraceIdGenerators.fullAwsRequestId;
|
|
81
|
-
const traceId = ContextUtil.CURRENT_OVERRIDE_TRACE_ID ||
|
|
82
|
-
ContextUtil.CURRENT_EVENT?.headers?.[ContextUtil.traceHeaderName()] ||
|
|
83
|
-
traceFn(ContextUtil.CURRENT_EVENT, ContextUtil.CURRENT_CONTEXT);
|
|
84
|
-
return traceId;
|
|
85
|
-
}
|
|
86
|
-
static currentTraceDepth() {
|
|
87
|
-
const caller = ContextUtil.CURRENT_OVERRIDE_TRACE_DEPTH ||
|
|
88
|
-
NumberRatchet.safeNumber(ContextUtil.CURRENT_EVENT?.headers?.[ContextUtil.traceDepthHeaderName()]) ||
|
|
89
|
-
1;
|
|
90
|
-
return caller;
|
|
91
|
-
}
|
|
92
|
-
static addLogVariable(name, val) {
|
|
93
|
-
ContextUtil.CURRENT_LOG_VARS[name] = val;
|
|
94
|
-
}
|
|
95
|
-
static fetchLogVariable(name) {
|
|
96
|
-
return ContextUtil.CURRENT_LOG_VARS?.[name];
|
|
97
|
-
}
|
|
98
|
-
static fetchLogVariables() {
|
|
99
|
-
return Object.assign({}, ContextUtil.CURRENT_LOG_VARS || {});
|
|
100
|
-
}
|
|
101
|
-
}
|
package/lib/util/cron-util.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { RequireRatchet } from '@bitblit/ratchet-common/lib/lang/require-ratchet.js';
|
|
2
|
-
import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
|
|
3
|
-
import { ErrorRatchet } from '@bitblit/ratchet-common/lib/lang/error-ratchet.js';
|
|
4
|
-
import { DateTime } from 'luxon';
|
|
5
|
-
export class CronUtil {
|
|
6
|
-
static everyNMinuteFilter(n) {
|
|
7
|
-
return CronUtil.everyNElementFilter(n, 60);
|
|
8
|
-
}
|
|
9
|
-
static everyNDaysOfYearFilter(n) {
|
|
10
|
-
return CronUtil.everyNElementFilter(n, 365);
|
|
11
|
-
}
|
|
12
|
-
static everyNElementFilter(n, m) {
|
|
13
|
-
RequireRatchet.notNullOrUndefined(n);
|
|
14
|
-
RequireRatchet.notNullOrUndefined(m);
|
|
15
|
-
const half = Math.floor(m / 2);
|
|
16
|
-
if (!n || n < 2 || n > half || m % n !== 0) {
|
|
17
|
-
ErrorRatchet.throwFormattedErr('Invalid config - this function only makes sense for 2 < N < %d and %d evenly divisible by N', half, m);
|
|
18
|
-
throw new Error('Invalid config - this function only makes sense for 2 < N < 31 and 60 evenly divisible by N');
|
|
19
|
-
}
|
|
20
|
-
const rval = [];
|
|
21
|
-
for (let i = 0; i < 60; i += n) {
|
|
22
|
-
rval.push(i);
|
|
23
|
-
}
|
|
24
|
-
return rval;
|
|
25
|
-
}
|
|
26
|
-
static numberMatchesFilter(num, filter) {
|
|
27
|
-
return !filter || filter.length === 0 || filter.includes(num);
|
|
28
|
-
}
|
|
29
|
-
static eventMatchesEntry(event, entry, cfg, testTimeEpochMS = new Date().getTime()) {
|
|
30
|
-
let rval = false;
|
|
31
|
-
if (!!event && !!entry && !!cfg.timezone) {
|
|
32
|
-
if (!!event.resources && event.resources.length > 0) {
|
|
33
|
-
const eventSourceName = event.resources[0];
|
|
34
|
-
const targetTZ = StringRatchet.trimToNull(entry.overrideTimezone) || cfg.timezone;
|
|
35
|
-
const nowInTZ = DateTime.fromMillis(testTimeEpochMS).setZone(targetTZ);
|
|
36
|
-
rval = !entry.eventFilter || entry.eventFilter.test(eventSourceName);
|
|
37
|
-
rval = rval && CronUtil.numberMatchesFilter(nowInTZ.minute, entry.minuteFilter);
|
|
38
|
-
rval = rval && CronUtil.numberMatchesFilter(nowInTZ.hour, entry.hourFilter);
|
|
39
|
-
rval = rval && CronUtil.numberMatchesFilter(nowInTZ.weekday, entry.dayOfWeekFilter);
|
|
40
|
-
rval = rval && CronUtil.numberMatchesFilter(nowInTZ.day, entry.dayOfMonthFilter);
|
|
41
|
-
rval = rval && CronUtil.numberMatchesFilter(nowInTZ.month, entry.monthOfYearFilter);
|
|
42
|
-
rval = rval && (!entry.contextMatchFilter || entry.contextMatchFilter.test(StringRatchet.trimToEmpty(cfg.context)));
|
|
43
|
-
rval = rval && (!entry.contextNoMatchFilter || !entry.contextNoMatchFilter.test(StringRatchet.trimToEmpty(cfg.context)));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return rval;
|
|
47
|
-
}
|
|
48
|
-
static cronEntryName(entry, idx = null) {
|
|
49
|
-
RequireRatchet.notNullOrUndefined(entry);
|
|
50
|
-
let rval = null;
|
|
51
|
-
if (!!entry) {
|
|
52
|
-
rval = entry.name;
|
|
53
|
-
rval = rval || entry['backgroundTaskType'];
|
|
54
|
-
if (!rval && !!entry['directHandler']) {
|
|
55
|
-
if (!!idx) {
|
|
56
|
-
rval = 'Direct Entry ' + idx;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
rval = 'Direct Entry (No idx specified)';
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
rval = 'ERROR: no entry passed';
|
|
65
|
-
}
|
|
66
|
-
return rval;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { CronUtil } from './cron-util.js';
|
|
4
|
-
import { EsmRatchet } from '@bitblit/ratchet-common/lib/lang/esm-ratchet.js';
|
|
5
|
-
describe('#cronUtil', function () {
|
|
6
|
-
it('should test matching event to entry', async () => {
|
|
7
|
-
const sEvent = JSON.parse(fs
|
|
8
|
-
.readFileSync(path.join(EsmRatchet.fetchDirName(import.meta.url), '../../../../test-data/epsilon/sample-json/sample-schedule-event-1.json'))
|
|
9
|
-
.toString());
|
|
10
|
-
const cfg = {
|
|
11
|
-
context: 'prod',
|
|
12
|
-
timezone: 'America/Los_Angeles',
|
|
13
|
-
entries: [],
|
|
14
|
-
};
|
|
15
|
-
const cron1 = {
|
|
16
|
-
contextMatchFilter: new RegExp('prod'),
|
|
17
|
-
};
|
|
18
|
-
const match1 = CronUtil.eventMatchesEntry(sEvent, cron1, cfg);
|
|
19
|
-
expect(match1).toBeTruthy();
|
|
20
|
-
const cron2 = {
|
|
21
|
-
contextMatchFilter: new RegExp('dev'),
|
|
22
|
-
};
|
|
23
|
-
const match2 = CronUtil.eventMatchesEntry(sEvent, cron2, cfg);
|
|
24
|
-
expect(match2).toBeFalsy();
|
|
25
|
-
const cron3 = {
|
|
26
|
-
eventFilter: new RegExp('.*MyScheduledRule.*'),
|
|
27
|
-
};
|
|
28
|
-
const match3 = CronUtil.eventMatchesEntry(sEvent, cron3, cfg);
|
|
29
|
-
expect(match3).toBeTruthy();
|
|
30
|
-
const cron4 = {
|
|
31
|
-
eventFilter: new RegExp('.*NotMyRule.*'),
|
|
32
|
-
};
|
|
33
|
-
const match4 = CronUtil.eventMatchesEntry(sEvent, cron4, cfg);
|
|
34
|
-
expect(match4).toBeFalsy();
|
|
35
|
-
});
|
|
36
|
-
it('should match times', async () => {
|
|
37
|
-
const sEvent = JSON.parse(fs
|
|
38
|
-
.readFileSync(path.join(EsmRatchet.fetchDirName(import.meta.url), '../../../../test-data/epsilon/sample-json/sample-schedule-event-1.json'))
|
|
39
|
-
.toString());
|
|
40
|
-
const cfg = {
|
|
41
|
-
context: 'prod',
|
|
42
|
-
timezone: 'America/Los_Angeles',
|
|
43
|
-
entries: [],
|
|
44
|
-
};
|
|
45
|
-
const entry1 = {};
|
|
46
|
-
const cron1 = {
|
|
47
|
-
contextMatchFilter: new RegExp('prod'),
|
|
48
|
-
};
|
|
49
|
-
const match1 = CronUtil.eventMatchesEntry(sEvent, cron1, cfg);
|
|
50
|
-
expect(match1).toBeTruthy();
|
|
51
|
-
const cron2 = {
|
|
52
|
-
contextMatchFilter: new RegExp('dev'),
|
|
53
|
-
};
|
|
54
|
-
const match2 = CronUtil.eventMatchesEntry(sEvent, cron2, cfg);
|
|
55
|
-
expect(match2).toBeFalsy();
|
|
56
|
-
const cron3 = {
|
|
57
|
-
eventFilter: new RegExp('.*MyScheduledRule.*'),
|
|
58
|
-
};
|
|
59
|
-
const match3 = CronUtil.eventMatchesEntry(sEvent, cron3, cfg);
|
|
60
|
-
expect(match3).toBeTruthy();
|
|
61
|
-
const cron4 = {
|
|
62
|
-
eventFilter: new RegExp('.*NotMyRule.*'),
|
|
63
|
-
};
|
|
64
|
-
const match4 = CronUtil.eventMatchesEntry(sEvent, cron4, cfg);
|
|
65
|
-
expect(match4).toBeFalsy();
|
|
66
|
-
});
|
|
67
|
-
it('should match time with override', async () => {
|
|
68
|
-
const sEvent = JSON.parse(fs
|
|
69
|
-
.readFileSync(path.join(EsmRatchet.fetchDirName(import.meta.url), '../../../../test-data/epsilon/sample-json/sample-schedule-event-1.json'))
|
|
70
|
-
.toString());
|
|
71
|
-
const cfg = {
|
|
72
|
-
context: 'prod',
|
|
73
|
-
timezone: 'America/Los_Angeles',
|
|
74
|
-
entries: [],
|
|
75
|
-
};
|
|
76
|
-
const entry1 = {};
|
|
77
|
-
const cron1 = {
|
|
78
|
-
hourFilter: [3],
|
|
79
|
-
};
|
|
80
|
-
const cron2 = {
|
|
81
|
-
overrideTimezone: 'etc/utc',
|
|
82
|
-
hourFilter: [3],
|
|
83
|
-
};
|
|
84
|
-
const testTimestampEpochMS = 1652931000000;
|
|
85
|
-
const match1 = CronUtil.eventMatchesEntry(sEvent, cron1, cfg, testTimestampEpochMS);
|
|
86
|
-
const match2 = CronUtil.eventMatchesEntry(sEvent, cron2, cfg, testTimestampEpochMS);
|
|
87
|
-
expect(match1).toBeFalsy();
|
|
88
|
-
expect(match2).toBeTruthy();
|
|
89
|
-
});
|
|
90
|
-
it('should match day of month filters', async () => {
|
|
91
|
-
const sEvent = JSON.parse(fs
|
|
92
|
-
.readFileSync(path.join(EsmRatchet.fetchDirName(import.meta.url), '../../../../test-data/epsilon/sample-json/sample-schedule-event-1.json'))
|
|
93
|
-
.toString());
|
|
94
|
-
const cfg = {
|
|
95
|
-
context: 'prod',
|
|
96
|
-
timezone: 'etc/utc',
|
|
97
|
-
entries: [],
|
|
98
|
-
};
|
|
99
|
-
const entry1 = {};
|
|
100
|
-
const testTimestampEpochMS = 1652931000000;
|
|
101
|
-
const dayOfMonth = {
|
|
102
|
-
dayOfMonthFilter: [19],
|
|
103
|
-
};
|
|
104
|
-
const matchDay = CronUtil.eventMatchesEntry(sEvent, dayOfMonth, cfg, testTimestampEpochMS);
|
|
105
|
-
expect(matchDay).toBeTruthy();
|
|
106
|
-
});
|
|
107
|
-
it('should match month of year filter', async () => {
|
|
108
|
-
const sEvent = JSON.parse(fs
|
|
109
|
-
.readFileSync(path.join(EsmRatchet.fetchDirName(import.meta.url), '../../../../test-data/epsilon/sample-json/sample-schedule-event-1.json'))
|
|
110
|
-
.toString());
|
|
111
|
-
const cfg = {
|
|
112
|
-
context: 'prod',
|
|
113
|
-
timezone: 'etc/utc',
|
|
114
|
-
entries: [],
|
|
115
|
-
};
|
|
116
|
-
const entry1 = {};
|
|
117
|
-
const testTimestampEpochMS = 1652931000000;
|
|
118
|
-
const monthOfYear = {
|
|
119
|
-
monthOfYearFilter: [5],
|
|
120
|
-
};
|
|
121
|
-
const matchMonth = CronUtil.eventMatchesEntry(sEvent, monthOfYear, cfg, testTimestampEpochMS);
|
|
122
|
-
expect(matchMonth).toBeTruthy();
|
|
123
|
-
});
|
|
124
|
-
});
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
2
|
-
import { ErrorRatchet } from '@bitblit/ratchet-common/lib/lang/error-ratchet.js';
|
|
3
|
-
import yaml from 'js-yaml';
|
|
4
|
-
import { ModelValidator } from '@bitblit/ratchet-misc/lib/model-validator/model-validator.js';
|
|
5
|
-
import { BackgroundHttpAdapterHandler } from '../background/background-http-adapter-handler.js';
|
|
6
|
-
import { BackgroundHandler } from '../background/background-handler.js';
|
|
7
|
-
import { RouterUtil } from '../http/route/router-util.js';
|
|
8
|
-
import { WebHandler } from '../http/web-handler.js';
|
|
9
|
-
import { MisconfiguredError } from '../http/error/misconfigured-error.js';
|
|
10
|
-
import { EpsilonGlobalHandler } from '../epsilon-global-handler.js';
|
|
11
|
-
export class EpsilonConfigParser {
|
|
12
|
-
constructor() { }
|
|
13
|
-
static epsilonConfigToEpsilonGlobalHandler(config, backgroundManager) {
|
|
14
|
-
return new EpsilonGlobalHandler(EpsilonConfigParser.epsilonConfigToEpsilonInstance(config, backgroundManager));
|
|
15
|
-
}
|
|
16
|
-
static epsilonConfigToEpsilonInstance(config, backgroundManager) {
|
|
17
|
-
this.validateGlobalConfig(config);
|
|
18
|
-
const label = config?.label || 'NO EPSILON CONFIG LABEL SET';
|
|
19
|
-
Logger.info('Creating epsilon : %s : BM : %j', label, backgroundManager);
|
|
20
|
-
const parsed = EpsilonConfigParser.parseOpenApiDocument(config.openApiYamlString);
|
|
21
|
-
const modelValidator = EpsilonConfigParser.openApiDocToValidator(parsed);
|
|
22
|
-
const backgroundHttpAdapter = new BackgroundHttpAdapterHandler(config.backgroundConfig, modelValidator, backgroundManager);
|
|
23
|
-
const backgroundHandler = config.backgroundConfig
|
|
24
|
-
? new BackgroundHandler(config.backgroundConfig, backgroundManager, modelValidator)
|
|
25
|
-
: null;
|
|
26
|
-
const epsilonRouter = config.httpConfig
|
|
27
|
-
? RouterUtil.openApiYamlToRouterConfig(config.httpConfig, parsed, modelValidator, backgroundHttpAdapter)
|
|
28
|
-
: null;
|
|
29
|
-
const webHandler = epsilonRouter ? new WebHandler(epsilonRouter) : null;
|
|
30
|
-
const inst = {
|
|
31
|
-
config: config,
|
|
32
|
-
parsedOpenApiDoc: parsed,
|
|
33
|
-
modelValidator: modelValidator,
|
|
34
|
-
webHandler: webHandler,
|
|
35
|
-
backgroundHandler: backgroundHandler,
|
|
36
|
-
backgroundManager: backgroundManager,
|
|
37
|
-
};
|
|
38
|
-
return inst;
|
|
39
|
-
}
|
|
40
|
-
static parseOpenApiDocument(yamlString) {
|
|
41
|
-
if (!yamlString) {
|
|
42
|
-
throw new MisconfiguredError('Cannot configure, missing either yaml or cfg');
|
|
43
|
-
}
|
|
44
|
-
const doc = yaml.load(yamlString);
|
|
45
|
-
return doc;
|
|
46
|
-
}
|
|
47
|
-
static openApiDocToValidator(doc) {
|
|
48
|
-
let rval = null;
|
|
49
|
-
if (doc?.components?.schemas) {
|
|
50
|
-
rval = ModelValidator.createFromParsedObject(doc.components.schemas);
|
|
51
|
-
}
|
|
52
|
-
return rval;
|
|
53
|
-
}
|
|
54
|
-
static validateGlobalConfig(config) {
|
|
55
|
-
if (!config) {
|
|
56
|
-
ErrorRatchet.throwFormattedErr('Config may not be null');
|
|
57
|
-
}
|
|
58
|
-
if (!config.openApiYamlString) {
|
|
59
|
-
ErrorRatchet.throwFormattedErr('Config must define an open api document');
|
|
60
|
-
}
|
|
61
|
-
if (!!config.cron && !config.cron.timezone) {
|
|
62
|
-
ErrorRatchet.throwFormattedErr('Cron is defined, but timezone is not set');
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|