@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.
Files changed (180) hide show
  1. package/lib/background/background-dynamo-log-table-handler.d.ts +1 -1
  2. package/lib/background/background-handler.d.ts +1 -1
  3. package/lib/background/background-http-adapter-handler.d.ts +1 -1
  4. package/lib/background/background-validator.d.ts +1 -1
  5. package/lib/build/ratchet-epsilon-common-info.d.ts +1 -1
  6. package/lib/built-in/daemon/daemon-authorizer-function.d.ts +1 -1
  7. package/lib/built-in/daemon/daemon-handler.d.ts +2 -2
  8. package/lib/built-in/daemon/daemon-process-state-list.d.ts +1 -1
  9. package/lib/built-in/http/built-in-auth-filters.d.ts +1 -1
  10. package/lib/cli/ratchet-cli-handler.d.ts +2 -2
  11. package/lib/config/epsilon-logger-config.d.ts +2 -2
  12. package/lib/config/http/filter-chain-context.d.ts +1 -1
  13. package/lib/config/http/http-config.d.ts +1 -1
  14. package/lib/epsilon-global-handler.d.ts +1 -1
  15. package/lib/epsilon-instance.d.ts +1 -1
  16. package/lib/epsilon-logging-extension-processor.d.ts +2 -2
  17. package/lib/http/auth/auth0-web-token-manipulator.d.ts +1 -1
  18. package/lib/http/auth/google-web-token-manipulator.d.ts +1 -1
  19. package/lib/http/auth/jwt-ratchet-local-web-token-manipulator.d.ts +2 -2
  20. package/lib/http/auth/local-web-token-manipulator.d.ts +3 -3
  21. package/lib/http/auth/web-token-manipulator.d.ts +1 -1
  22. package/lib/http/event-util.d.ts +1 -1
  23. package/lib/http/response-util.d.ts +1 -1
  24. package/lib/http/route/epsilon-router.d.ts +1 -1
  25. package/lib/http/route/router-util.d.ts +2 -2
  26. package/lib/index.d.ts +132 -1
  27. package/lib/index.mjs +344 -0
  28. package/lib/index.mjs.map +1 -0
  29. package/lib/local-container-server.d.ts +1 -1
  30. package/lib/local-server.d.ts +1 -1
  31. package/lib/sample/test-error-server.d.ts +1 -1
  32. package/lib/util/epsilon-config-parser.d.ts +1 -1
  33. package/package.json +18 -19
  34. package/lib/background/background-dynamo-log-table-handler.js +0 -37
  35. package/lib/background/background-entry.js +0 -1
  36. package/lib/background/background-execution-event-type.js +0 -8
  37. package/lib/background/background-execution-event.js +0 -1
  38. package/lib/background/background-execution-listener.js +0 -1
  39. package/lib/background/background-handler.js +0 -273
  40. package/lib/background/background-http-adapter-handler.js +0 -128
  41. package/lib/background/background-meta-response-internal.js +0 -1
  42. package/lib/background/background-process-handling.js +0 -5
  43. package/lib/background/background-process-log-table-entry.js +0 -1
  44. package/lib/background/background-queue-response-internal.js +0 -1
  45. package/lib/background/background-validator.js +0 -86
  46. package/lib/background/epsilon-background-process-error.js +0 -93
  47. package/lib/background/internal-background-entry.js +0 -1
  48. package/lib/background/manager/abstract-background-manager.js +0 -89
  49. package/lib/background/manager/aws-sqs-sns-background-manager.js +0 -153
  50. package/lib/background/manager/background-manager-like.js +0 -1
  51. package/lib/background/manager/background-manager.spec.js +0 -73
  52. package/lib/background/manager/single-thread-local-background-manager.js +0 -45
  53. package/lib/background/s3-background-transaction-logger.js +0 -52
  54. package/lib/build/ratchet-epsilon-common-info.js +0 -14
  55. package/lib/built-in/background/echo-processor.js +0 -15
  56. package/lib/built-in/background/log-and-enqueue-echo-processor.js +0 -12
  57. package/lib/built-in/background/log-message-background-error-processor.js +0 -6
  58. package/lib/built-in/background/no-op-processor.js +0 -9
  59. package/lib/built-in/background/retry-processor.js +0 -40
  60. package/lib/built-in/background/sample-delay-processor.js +0 -13
  61. package/lib/built-in/background/sample-input-validated-processor-data.js +0 -1
  62. package/lib/built-in/background/sample-input-validated-processor.js +0 -12
  63. package/lib/built-in/built-in-trace-id-generators.js +0 -21
  64. package/lib/built-in/daemon/daemon-authorizer-function.js +0 -1
  65. package/lib/built-in/daemon/daemon-config.js +0 -1
  66. package/lib/built-in/daemon/daemon-group-selection-function.js +0 -1
  67. package/lib/built-in/daemon/daemon-handler.js +0 -59
  68. package/lib/built-in/daemon/daemon-process-state-list.js +0 -1
  69. package/lib/built-in/http/apollo-filter.js +0 -59
  70. package/lib/built-in/http/built-in-auth-filters.js +0 -107
  71. package/lib/built-in/http/built-in-authorizers.js +0 -39
  72. package/lib/built-in/http/built-in-filters.js +0 -208
  73. package/lib/built-in/http/built-in-handlers.js +0 -69
  74. package/lib/built-in/http/log-level-manipulation-filter.js +0 -16
  75. package/lib/built-in/http/run-handler-as-filter.js +0 -60
  76. package/lib/built-in/http/run-handler-as-filter.spec.js +0 -40
  77. package/lib/cli/ratchet-cli-handler.js +0 -20
  78. package/lib/cli/run-background-process-from-command-line.js +0 -22
  79. package/lib/config/background/background-aws-config.js +0 -1
  80. package/lib/config/background/background-config.js +0 -1
  81. package/lib/config/background/background-error-processor.js +0 -1
  82. package/lib/config/background/background-processor.js +0 -1
  83. package/lib/config/background/background-transaction-log.js +0 -1
  84. package/lib/config/background/background-transaction-logger.js +0 -1
  85. package/lib/config/cron/abstract-cron-entry.js +0 -1
  86. package/lib/config/cron/cron-background-entry.js +0 -1
  87. package/lib/config/cron/cron-config.js +0 -1
  88. package/lib/config/dynamo-db-config.js +0 -1
  89. package/lib/config/epsilon-config.js +0 -1
  90. package/lib/config/epsilon-lambda-event-handler.js +0 -1
  91. package/lib/config/epsilon-logger-config.js +0 -1
  92. package/lib/config/generic-aws-event-handler-function.js +0 -1
  93. package/lib/config/http/authorizer-function.js +0 -1
  94. package/lib/config/http/epsilon-authorization-context.js +0 -1
  95. package/lib/config/http/extended-api-gateway-event.js +0 -1
  96. package/lib/config/http/filter-chain-context.js +0 -1
  97. package/lib/config/http/filter-function.js +0 -1
  98. package/lib/config/http/handler-function.js +0 -1
  99. package/lib/config/http/http-config.js +0 -1
  100. package/lib/config/http/http-processing-config.js +0 -1
  101. package/lib/config/http/mapped-http-processing-config.js +0 -1
  102. package/lib/config/http/null-returned-object-handling.js +0 -6
  103. package/lib/config/inter-api/inter-api-aws-config.js +0 -1
  104. package/lib/config/inter-api/inter-api-config.js +0 -1
  105. package/lib/config/inter-api/inter-api-process-mapping.js +0 -1
  106. package/lib/config/logging-trace-id-generator.js +0 -1
  107. package/lib/config/open-api/open-api-document-components.js +0 -1
  108. package/lib/config/open-api/open-api-document-path.js +0 -1
  109. package/lib/config/open-api/open-api-document.js +0 -1
  110. package/lib/config/s3-config.js +0 -1
  111. package/lib/config/sns-config.js +0 -1
  112. package/lib/epsilon-build-properties.js +0 -24
  113. package/lib/epsilon-constants.js +0 -46
  114. package/lib/epsilon-global-handler.js +0 -154
  115. package/lib/epsilon-instance.js +0 -1
  116. package/lib/epsilon-logging-extension-processor.js +0 -15
  117. package/lib/http/auth/api-gateway-adapter-authentication-handler.js +0 -72
  118. package/lib/http/auth/auth0-web-token-manipulator.js +0 -61
  119. package/lib/http/auth/basic-auth-token.js +0 -1
  120. package/lib/http/auth/google-web-token-manipulator.js +0 -70
  121. package/lib/http/auth/google-web-token-manipulator.spec.js +0 -10
  122. package/lib/http/auth/jwt-ratchet-local-web-token-manipulator.js +0 -27
  123. package/lib/http/auth/local-web-token-manipulator.js +0 -74
  124. package/lib/http/auth/local-web-token-manipulator.spec.js +0 -24
  125. package/lib/http/auth/web-token-manipulator.js +0 -1
  126. package/lib/http/error/bad-gateway.js +0 -8
  127. package/lib/http/error/bad-request-error.js +0 -8
  128. package/lib/http/error/conflict-error.js +0 -8
  129. package/lib/http/error/epsilon-http-error.js +0 -133
  130. package/lib/http/error/epsilon-http-error.spec.js +0 -11
  131. package/lib/http/error/forbidden-error.js +0 -8
  132. package/lib/http/error/gateway-timeout.js +0 -8
  133. package/lib/http/error/method-not-allowed-error.js +0 -8
  134. package/lib/http/error/misconfigured-error.js +0 -8
  135. package/lib/http/error/not-found-error.js +0 -8
  136. package/lib/http/error/not-implemented.js +0 -8
  137. package/lib/http/error/request-timeout-error.js +0 -8
  138. package/lib/http/error/service-unavailable.js +0 -8
  139. package/lib/http/error/too-many-requests-error.js +0 -8
  140. package/lib/http/error/unauthorized-error.js +0 -8
  141. package/lib/http/event-util.js +0 -176
  142. package/lib/http/event-util.spec.js +0 -161
  143. package/lib/http/response-util.js +0 -141
  144. package/lib/http/response-util.spec.js +0 -92
  145. package/lib/http/route/epsilon-router.js +0 -1
  146. package/lib/http/route/extended-auth-response-context.js +0 -1
  147. package/lib/http/route/route-mapping.js +0 -1
  148. package/lib/http/route/route-validator-config.js +0 -1
  149. package/lib/http/route/router-util.js +0 -233
  150. package/lib/http/route/router-util.spec.js +0 -23
  151. package/lib/http/web-handler.js +0 -117
  152. package/lib/http/web-handler.spec.js +0 -32
  153. package/lib/http/web-v2-handler.js +0 -22
  154. package/lib/index.js +0 -1
  155. package/lib/inter-api/inter-api-entry.js +0 -1
  156. package/lib/inter-api/inter-api-util.js +0 -59
  157. package/lib/inter-api/inter-api-util.spec.js +0 -61
  158. package/lib/inter-api-manager.js +0 -65
  159. package/lib/lambda-event-handler/cron-epsilon-lambda-event-handler.js +0 -73
  160. package/lib/lambda-event-handler/cron-epsilon-lambda-event-handler.spec.js +0 -50
  161. package/lib/lambda-event-handler/dynamo-epsilon-lambda-event-handler.js +0 -33
  162. package/lib/lambda-event-handler/generic-sns-epsilon-lambda-event-handler.js +0 -29
  163. package/lib/lambda-event-handler/inter-api-epsilon-lambda-event-handler.js +0 -23
  164. package/lib/lambda-event-handler/s3-epsilon-lambda-event-handler.js +0 -41
  165. package/lib/local-container-server.js +0 -76
  166. package/lib/local-server-cert.js +0 -67
  167. package/lib/local-server.js +0 -162
  168. package/lib/open-api-util/open-api-doc-modifications.js +0 -1
  169. package/lib/open-api-util/open-api-doc-modifier.js +0 -79
  170. package/lib/open-api-util/open-api-doc-modifier.spec.js +0 -16
  171. package/lib/open-api-util/yaml-combiner.js +0 -27
  172. package/lib/open-api-util/yaml-combiner.spec.js +0 -22
  173. package/lib/sample/sample-server-components.js +0 -185
  174. package/lib/sample/sample-server-static-files.js +0 -593
  175. package/lib/sample/test-error-server.js +0 -44
  176. package/lib/util/aws-util.js +0 -65
  177. package/lib/util/context-util.js +0 -101
  178. package/lib/util/cron-util.js +0 -68
  179. package/lib/util/cron-util.spec.js +0 -124
  180. package/lib/util/epsilon-config-parser.js +0 -65
@@ -1,4 +1,4 @@
1
- /// <reference types="node" resolution-mode="require"/>
1
+ /// <reference types="node" />
2
2
  import { IncomingMessage, ServerResponse } from 'http';
3
3
  export declare class LocalContainerServer {
4
4
  private port;
@@ -1,4 +1,4 @@
1
- /// <reference types="node" resolution-mode="require"/>
1
+ /// <reference types="node" />
2
2
  import { APIGatewayEvent, Context, ProxyResult } from 'aws-lambda';
3
3
  import { IncomingMessage, ServerResponse } from 'http';
4
4
  import { EpsilonGlobalHandler } from './epsilon-global-handler.js';
@@ -1,4 +1,4 @@
1
- /// <reference types="node" resolution-mode="require"/>
1
+ /// <reference types="node" />
2
2
  import { IncomingMessage, ServerResponse } from 'http';
3
3
  export declare class TestErrorServer {
4
4
  private port;
@@ -1,4 +1,4 @@
1
- import { ModelValidator } from '@bitblit/ratchet-misc/lib/model-validator/model-validator.js';
1
+ import { ModelValidator } from '@bitblit/ratchet-misc';
2
2
  import { OpenApiDocument } from '../config/open-api/open-api-document.js';
3
3
  import { EpsilonConfig } from '../config/epsilon-config.js';
4
4
  import { EpsilonInstance } from '../epsilon-instance.js';
package/package.json CHANGED
@@ -1,17 +1,22 @@
1
1
  {
2
2
  "name": "@bitblit/ratchet-epsilon-common",
3
- "version": "4.0.115-alpha",
3
+ "version": "4.0.119-alpha",
4
4
  "description": "Tiny adapter to simplify building API gateway Lambda APIS",
5
5
  "sideEffects": false,
6
6
  "bin": {
7
7
  "epsilon-cli": "./bin/cli.js"
8
8
  },
9
9
  "type": "module",
10
- "module": "index.js",
11
10
  "files": [
12
11
  "lib/*",
13
12
  "bin/*"
14
13
  ],
14
+ "exports": {
15
+ ".": {
16
+ "types": "./lib/index.d.ts",
17
+ "import": "./lib/index.mjs"
18
+ }
19
+ },
15
20
  "contributors": [
16
21
  "Christopher Weiss <bitblit@gmail.com>",
17
22
  "Benn Linger <benn@bennlinger.com>",
@@ -35,9 +40,9 @@
35
40
  "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
36
41
  "lint": "eslint src/**/*.ts",
37
42
  "lint-fix": "eslint --fix src/**/*.ts",
38
- "__generate-barrels": "barrelsby -q --delete -d src -e .*\\.spec\\.ts",
39
- "__build": "yarn run generate-barrels && tsc",
40
- "build": "tsc",
43
+ "generate-barrels": "barrelsby -q --delete -d src -e .*\\.spec\\.ts && sed -i 's/\\x27;/.js\\x27;/' src/index.ts",
44
+ "build": "yarn clean && yarn generate-barrels && rollup -c rollup.config.js",
45
+ "force-build": "tsc --build --force",
41
46
  "run-local-container-server": "yarn build && node bin/cli.js run-local-container-server",
42
47
  "run-sample-server": "yarn build && node bin/cli.js run-sample-local-server",
43
48
  "run-test-error-server": "yarn build && node bin/cli.js run-test-error-server",
@@ -62,13 +67,13 @@
62
67
  },
63
68
  "license": "Apache-2.0",
64
69
  "dependencies": {
65
- "@aws-sdk/client-s3": "3.328.0",
66
- "@aws-sdk/client-sns": "3.328.0",
67
- "@aws-sdk/client-sqs": "3.328.0",
68
- "@bitblit/ratchet-aws": "4.0.115-alpha",
69
- "@bitblit/ratchet-common": "4.0.115-alpha",
70
- "@bitblit/ratchet-misc": "4.0.115-alpha",
71
- "@bitblit/ratchet-node-only": "4.0.115-alpha",
70
+ "@aws-sdk/client-s3": "3.332.0",
71
+ "@aws-sdk/client-sns": "3.332.0",
72
+ "@aws-sdk/client-sqs": "3.332.0",
73
+ "@bitblit/ratchet-aws": "4.0.119-alpha",
74
+ "@bitblit/ratchet-common": "4.0.119-alpha",
75
+ "@bitblit/ratchet-misc": "4.0.119-alpha",
76
+ "@bitblit/ratchet-node-only": "4.0.119-alpha",
72
77
  "clear": "0.1.0",
73
78
  "commander": "10.0.1",
74
79
  "cross-fetch": "3.1.5",
@@ -108,12 +113,6 @@
108
113
  "y18n": "^5.0.8"
109
114
  },
110
115
  "peerDependencies": {
111
- "@aws-sdk/client-sns": "^3.328.0",
112
- "@aws-sdk/client-sqs": "3.328.0",
113
- "@bitblit/ratchet-aws": "4.0.115-alpha",
114
- "@bitblit/ratchet-common": "4.0.115-alpha",
115
- "@types/aws-lambda": "^8.10.115",
116
- "graphql": "^16.6.0"
117
116
  },
118
117
  "peerDependenciesMeta": {
119
118
  "graphql": {
@@ -121,7 +120,7 @@
121
120
  }
122
121
  },
123
122
  "devDependencies": {
124
- "@bitblit/ratchet-jest": "4.0.115-alpha",
123
+ "@bitblit/ratchet-jest": "4.0.119-alpha",
125
124
  "@types/aws-lambda": "8.10.115",
126
125
  "apollo-server-lambda": "3.12.0",
127
126
  "aws-sdk-client-mock": "2.1.1",
@@ -1,37 +0,0 @@
1
- import { BackgroundExecutionEventType } from './background-execution-event-type.js';
2
- import { ContextUtil } from '../util/context-util.js';
3
- export class BackgroundDynamoLogTableHandler {
4
- dynamo;
5
- tableName;
6
- env;
7
- backgroundQueueName;
8
- constructor(dynamo, tableName, env, backgroundQueueName) {
9
- this.dynamo = dynamo;
10
- this.tableName = tableName;
11
- this.env = env;
12
- this.backgroundQueueName = backgroundQueueName;
13
- }
14
- async onEvent(event) {
15
- const entry = {
16
- env: this.env,
17
- backgroundQueueName: this.backgroundQueueName,
18
- requestId: ContextUtil.currentRequestId(),
19
- guid: event.guid,
20
- processTypeName: event.processorType,
21
- state: event.type.toString(),
22
- timestampEpochMs: new Date().getTime(),
23
- };
24
- if (event.type == BackgroundExecutionEventType.DataValidationError) {
25
- const errors = event?.errors?.length ? event.errors : ['No-Error'];
26
- entry.errors = errors;
27
- }
28
- else if (event.type == BackgroundExecutionEventType.ProcessStarting) {
29
- entry.params = event.data;
30
- }
31
- else if (event.type == BackgroundExecutionEventType.ExecutionFailedError) {
32
- const errors = event?.errors?.length ? event.errors : ['No-Error'];
33
- entry.errors = errors;
34
- }
35
- await this.dynamo.simplePut(this.tableName, entry);
36
- }
37
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
1
- export var BackgroundExecutionEventType;
2
- (function (BackgroundExecutionEventType) {
3
- BackgroundExecutionEventType["ProcessStarting"] = "ProcessStarting";
4
- BackgroundExecutionEventType["DataValidationError"] = "DataValidationError";
5
- BackgroundExecutionEventType["ExecutionSuccessfullyComplete"] = "ExecutionSuccessfullyComplete";
6
- BackgroundExecutionEventType["ExecutionFailedError"] = "ExecutionRuntimeError";
7
- BackgroundExecutionEventType["NoMatchProcessorName"] = "NoMatchProcessorName";
8
- })(BackgroundExecutionEventType || (BackgroundExecutionEventType = {}));
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,273 +0,0 @@
1
- import { ErrorRatchet } from '@bitblit/ratchet-common/lib/lang/error-ratchet.js';
2
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
3
- import { LambdaEventDetector } from '@bitblit/ratchet-aws/lib/lambda/lambda-event-detector.js';
4
- import { EpsilonConstants } from '../epsilon-constants.js';
5
- import { BackgroundValidator } from './background-validator.js';
6
- import { BackgroundExecutionEventType } from './background-execution-event-type.js';
7
- import { ContextUtil } from '../util/context-util.js';
8
- import { AbstractBackgroundManager } from './manager/abstract-background-manager.js';
9
- import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
10
- import { StopWatch } from '@bitblit/ratchet-common/lib/lang/stop-watch.js';
11
- export class BackgroundHandler {
12
- cfg;
13
- mgr;
14
- modelValidator;
15
- processors;
16
- validator;
17
- constructor(cfg, mgr, modelValidator) {
18
- this.cfg = cfg;
19
- this.mgr = mgr;
20
- this.modelValidator = modelValidator;
21
- const cfgErrors = BackgroundValidator.validateConfig(cfg);
22
- if (cfgErrors.length > 0) {
23
- ErrorRatchet.throwFormattedErr('Invalid background config : %j', cfgErrors);
24
- }
25
- Logger.silly('Starting Background processor, %d processors', cfg.processors.length);
26
- this.validator = new BackgroundValidator(cfg, modelValidator);
27
- this.processors = BackgroundValidator.validateAndMapProcessors(cfg.processors, modelValidator);
28
- if (mgr?.immediateProcessQueue && mgr.immediateProcessQueue()) {
29
- Logger.info('Attaching to immediate processing queue');
30
- mgr.immediateProcessQueue().subscribe(async (evt) => {
31
- Logger.debug('Processing local background entry : %j', evt);
32
- const rval = await this.processSingleBackgroundEntry(evt);
33
- Logger.info('Processor returned %s', rval);
34
- });
35
- }
36
- }
37
- extractLabel(evt, context) {
38
- let rval = null;
39
- if (this.isBackgroundStartSnsEvent(evt)) {
40
- rval = 'BG:START-EVT';
41
- }
42
- else if (this.isBackgroundImmediateFireEvent(evt)) {
43
- const pEvt = this.parseImmediateFireBackgroundEntry(evt);
44
- rval = 'BG:' + pEvt.type + ':' + pEvt.guid;
45
- }
46
- else {
47
- rval = 'BG:UNKNOWN';
48
- }
49
- return rval;
50
- }
51
- handlesEvent(evt) {
52
- return LambdaEventDetector.isValidSnsEvent(evt) && this.isBackgroundSNSEvent(evt);
53
- }
54
- isBackgroundSNSEvent(event) {
55
- return this.isBackgroundStartSnsEvent(event) || this.isBackgroundImmediateFireEvent(event);
56
- }
57
- isBackgroundStartSnsEvent(event) {
58
- let rval = false;
59
- if (event) {
60
- if (LambdaEventDetector.isSingleSnsEvent(event)) {
61
- const cast = event;
62
- rval = cast.Records[0].Sns.Message === EpsilonConstants.BACKGROUND_SNS_START_MARKER;
63
- }
64
- }
65
- return rval;
66
- }
67
- isBackgroundImmediateFireEvent(event) {
68
- let rval = false;
69
- if (!!event) {
70
- if (LambdaEventDetector.isSingleSnsEvent(event)) {
71
- const cast = event;
72
- const msg = cast.Records[0].Sns.Message;
73
- if (!!StringRatchet.trimToNull(msg)) {
74
- const parsed = JSON.parse(msg);
75
- rval = !!parsed && parsed['type'] === EpsilonConstants.BACKGROUND_SNS_IMMEDIATE_RUN_FLAG;
76
- }
77
- }
78
- }
79
- return rval;
80
- }
81
- parseImmediateFireBackgroundEntry(event) {
82
- let rval = null;
83
- try {
84
- if (!!event) {
85
- if (LambdaEventDetector.isSingleSnsEvent(event)) {
86
- const cast = event;
87
- const msg = cast.Records[0].Sns.Message;
88
- if (!!StringRatchet.trimToNull(msg)) {
89
- const parsed = JSON.parse(msg);
90
- if (!!parsed && parsed['type'] === EpsilonConstants.BACKGROUND_SNS_IMMEDIATE_RUN_FLAG) {
91
- rval = parsed['backgroundEntry'];
92
- }
93
- }
94
- }
95
- }
96
- }
97
- catch (err) {
98
- Logger.error('Could not parse %j as an immediate run event : %s', event, err, err);
99
- }
100
- return rval;
101
- }
102
- async processEvent(event, context) {
103
- let procd = null;
104
- if (!this.isBackgroundStartSnsEvent(event)) {
105
- const backgroundEntry = this.parseImmediateFireBackgroundEntry(event);
106
- if (!!backgroundEntry) {
107
- Logger.silly('Processing immediate fire event : %j', backgroundEntry);
108
- const result = await this.processSingleBackgroundEntry(backgroundEntry);
109
- procd = 1;
110
- }
111
- else {
112
- Logger.warn('Tried to process non-background start / immediate event : %j returning false', event);
113
- }
114
- }
115
- else {
116
- Logger.info('Reading task from background queue');
117
- procd = await this.takeAndProcessSingleBackgroundQueueEntry();
118
- if (procd > 0) {
119
- Logger.info('Processed %d elements from background queue, refiring', procd);
120
- const refire = await this.mgr.fireStartProcessingRequest();
121
- Logger.info('Refire returned %s', refire);
122
- }
123
- else {
124
- Logger.info('No items processed - stopping');
125
- }
126
- }
127
- const rval = {
128
- statusCode: 200,
129
- body: StringRatchet.safeString(procd),
130
- isBase64Encoded: false,
131
- };
132
- return rval;
133
- }
134
- async takeAndProcessSingleBackgroundQueueEntry() {
135
- let rval = null;
136
- const entries = await this.mgr.takeEntryFromBackgroundQueue();
137
- Logger.info('Found %d entries - processing', entries.length);
138
- for (let i = 0; i < entries.length; i++) {
139
- const e = entries[i];
140
- const result = await this.processSingleBackgroundEntry(e);
141
- rval += result ? 1 : 0;
142
- }
143
- Logger.debug('Returning %d', rval);
144
- return rval;
145
- }
146
- async safeWriteToLogger(entry) {
147
- if (this.cfg.transactionLogger) {
148
- try {
149
- await this.cfg.transactionLogger.logTransaction(entry);
150
- }
151
- catch (err) {
152
- Logger.error('Failed to write to transaction logger : %j : %s', entry, err, err);
153
- }
154
- }
155
- else {
156
- Logger.silly('Skipping - no logger defined');
157
- }
158
- }
159
- async conditionallyStartTransactionLog(e) {
160
- if (!StringRatchet.trimToNull(e.guid)) {
161
- Logger.warn('No guid found - creating');
162
- e.guid = AbstractBackgroundManager.generateBackgroundGuid();
163
- const log = {
164
- request: e,
165
- running: true,
166
- };
167
- await this.safeWriteToLogger(log);
168
- }
169
- Logger.debug('Starting transaction log');
170
- }
171
- async conditionallyCompleteTransactionLog(e, result, error, runtimeMS) {
172
- Logger.debug('Completing transaction log');
173
- const log = {
174
- request: e,
175
- result: result,
176
- error: error ? ErrorRatchet.safeStringifyErr(error) : null,
177
- running: false,
178
- runtimeMS: runtimeMS,
179
- };
180
- await this.safeWriteToLogger(log);
181
- }
182
- async conditionallyRunErrorProcessor(e, error) {
183
- try {
184
- if (this.cfg.errorProcessor) {
185
- Logger.info('Running error processor');
186
- await this.cfg.errorProcessor.handleError(e, error);
187
- }
188
- }
189
- catch (err) {
190
- Logger.error('Background : BAD - Failed to run error processor : %s', err, err);
191
- }
192
- }
193
- async fireListenerEvent(event) {
194
- const listeners = this.cfg.executionListeners || [];
195
- for (const listener of listeners) {
196
- try {
197
- await listener.onEvent(event);
198
- }
199
- catch (err) {
200
- Logger.error('Failure triggering handler %s : %s', StringRatchet.trimToNull(listener?.label) || 'No-name', err);
201
- }
202
- }
203
- }
204
- async processSingleBackgroundEntry(e) {
205
- ContextUtil.setOverrideTraceFromInternalBackgroundEntry(e);
206
- Logger.info('Background Process Start: %j', e);
207
- const sw = new StopWatch();
208
- await this.conditionallyStartTransactionLog(e);
209
- let rval = false;
210
- try {
211
- await this.fireListenerEvent({
212
- type: BackgroundExecutionEventType.ProcessStarting,
213
- processorType: e.type,
214
- data: e.data,
215
- guid: e.guid,
216
- });
217
- const processorInput = this.processors.get(e.type);
218
- if (!processorInput) {
219
- ErrorRatchet.throwFormattedErr('Found no processor for background entry : %j (returning false)', e);
220
- await this.fireListenerEvent({
221
- type: BackgroundExecutionEventType.NoMatchProcessorName,
222
- processorType: e.type,
223
- data: e.data,
224
- guid: e.guid,
225
- });
226
- }
227
- let dataValidationErrors = [];
228
- if (StringRatchet.trimToNull(processorInput.dataSchemaName)) {
229
- dataValidationErrors = this.modelValidator.validate(processorInput.dataSchemaName, e.data, false, false);
230
- }
231
- if (dataValidationErrors.length > 0) {
232
- await this.fireListenerEvent({
233
- type: BackgroundExecutionEventType.DataValidationError,
234
- processorType: e.type,
235
- data: e.data,
236
- errors: dataValidationErrors,
237
- guid: e.guid,
238
- });
239
- ErrorRatchet.throwFormattedErr('Not processing, data failed validation; entry was %j : errors : %j', e, dataValidationErrors);
240
- }
241
- else {
242
- let result = await processorInput.handleEvent(e.data, this.mgr);
243
- result = result || 'SUCCESSFUL COMPLETION : NO RESULT RETURNED';
244
- await this.conditionallyCompleteTransactionLog(e, result, null, sw.elapsedMS());
245
- await this.fireListenerEvent({
246
- type: BackgroundExecutionEventType.ExecutionSuccessfullyComplete,
247
- processorType: e.type,
248
- data: result,
249
- guid: e.guid,
250
- });
251
- rval = true;
252
- }
253
- }
254
- catch (err) {
255
- Logger.error('Background Process Error: %j : %s', e, err, err);
256
- await this.conditionallyRunErrorProcessor(e, err);
257
- await this.conditionallyCompleteTransactionLog(e, null, err, sw.elapsedMS());
258
- await this.fireListenerEvent({
259
- type: BackgroundExecutionEventType.ExecutionFailedError,
260
- processorType: e.type,
261
- data: e.data,
262
- errors: [ErrorRatchet.safeStringifyErr(err)],
263
- guid: e.guid,
264
- });
265
- }
266
- Logger.info('Background Process Stop: %j : %s', e, sw.dump());
267
- return rval;
268
- }
269
- getConfig() {
270
- const rval = Object.assign({}, this.cfg);
271
- return rval;
272
- }
273
- }
@@ -1,128 +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 { BackgroundProcessHandling } from './background-process-handling.js';
4
- import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
5
- import { BooleanRatchet } from '@bitblit/ratchet-common/lib/lang/boolean-ratchet.js';
6
- import { BadRequestError } from '../http/error/bad-request-error.js';
7
- import { NotFoundError } from '../http/error/not-found-error.js';
8
- import { StopWatch } from '@bitblit/ratchet-common/lib/lang/stop-watch.js';
9
- export class BackgroundHttpAdapterHandler {
10
- backgroundConfig;
11
- modelValidator;
12
- backgroundManager;
13
- maxWaitInMsForBackgroundJobToStart;
14
- constructor(backgroundConfig, modelValidator, backgroundManager, maxWaitInMsForBackgroundJobToStart = 10_000) {
15
- this.backgroundConfig = backgroundConfig;
16
- this.modelValidator = modelValidator;
17
- this.backgroundManager = backgroundManager;
18
- this.maxWaitInMsForBackgroundJobToStart = maxWaitInMsForBackgroundJobToStart;
19
- }
20
- get httpMetaEndpoint() {
21
- return this.backgroundConfig.httpMetaEndpoint;
22
- }
23
- get httpSubmissionPath() {
24
- return this.backgroundConfig.httpSubmissionPath;
25
- }
26
- get httpStatusPath() {
27
- return this.backgroundConfig.httpStatusEndpoint;
28
- }
29
- get implyTypeFromPathSuffix() {
30
- return this.backgroundConfig.implyTypeFromPathSuffix;
31
- }
32
- async handleBackgroundStatusRequest(evt, context) {
33
- Logger.info('handleBackgroundStatusRequest called');
34
- if (!this.backgroundConfig.transactionLogger) {
35
- throw new BadRequestError('Process logging not enabled');
36
- }
37
- else {
38
- const guid = StringRatchet.trimToNull(evt.pathParameters['guid']) || StringRatchet.trimToNull(evt.queryStringParameters['guid']);
39
- if (guid) {
40
- const sw = new StopWatch();
41
- let log = null;
42
- while (!log && sw.elapsedMS() < this.maxWaitInMsForBackgroundJobToStart) {
43
- log = await this.backgroundConfig.transactionLogger.readTransactionLog(guid);
44
- if (!log) {
45
- Logger.debug('No log found yet, waiting 500 ms and retrying (%s of %d waited so far)', sw.dump(), this.maxWaitInMsForBackgroundJobToStart);
46
- await PromiseRatchet.wait(500);
47
- }
48
- }
49
- if (!log) {
50
- throw new NotFoundError().withFormattedErrorMessage('No background result found for guid %s', guid);
51
- }
52
- return log;
53
- }
54
- else {
55
- throw new BadRequestError('No guid specified');
56
- }
57
- }
58
- }
59
- async handleBackgroundMetaRequest(evt, context) {
60
- Logger.info('handleBackgroundMetaRequest called');
61
- const currentCount = await this.backgroundManager.fetchApproximateNumberOfQueueEntries();
62
- const valid = this.backgroundConfig.processors.map((b) => b.typeName).filter((a) => !!a);
63
- valid.sort((a, b) => a.localeCompare(b));
64
- const rval = {
65
- currentQueueLength: currentCount,
66
- validTypes: valid,
67
- backgroundManagerName: this.backgroundManager.backgroundManagerName,
68
- };
69
- return rval;
70
- }
71
- async handleBackgroundSubmission(evt, context) {
72
- Logger.info('handleBackgroundSubmission : %j (mgr:%s)', evt.parsedBody, this.backgroundManager.backgroundManagerName);
73
- let rval = null;
74
- const startIdx = evt.path.indexOf(this.httpSubmissionPath) + this.httpSubmissionPath.length;
75
- let pathSuppliedBackgroundType = this.backgroundConfig.implyTypeFromPathSuffix
76
- ? evt.path.substring(startIdx).split('-').join('').toLowerCase()
77
- : '';
78
- if (pathSuppliedBackgroundType.includes('?')) {
79
- pathSuppliedBackgroundType = pathSuppliedBackgroundType.substring(0, pathSuppliedBackgroundType.indexOf('?'));
80
- }
81
- if (pathSuppliedBackgroundType.includes('#')) {
82
- pathSuppliedBackgroundType = pathSuppliedBackgroundType.substring(0, pathSuppliedBackgroundType.indexOf('#'));
83
- }
84
- const entry = evt.parsedBody || {};
85
- if (StringRatchet.trimToNull(pathSuppliedBackgroundType)) {
86
- if (StringRatchet.trimToNull(entry?.type) && entry.type.toLocaleLowerCase() !== pathSuppliedBackgroundType.toLocaleLowerCase()) {
87
- throw new BadRequestError('Background submission has type but does not match path supplied type');
88
- }
89
- else {
90
- entry.type = pathSuppliedBackgroundType;
91
- }
92
- }
93
- else {
94
- if (!StringRatchet.trimToNull(entry?.type)) {
95
- throw new BadRequestError('Background submission missing type and not configured in pathed mode');
96
- }
97
- }
98
- const foundProc = this.backgroundConfig.processors.find((s) => s.typeName.toLowerCase() === entry.type.toLowerCase());
99
- const immediate = BooleanRatchet.parseBool(evt.queryStringParameters['immediate']);
100
- const startProcessor = BooleanRatchet.parseBool(evt.queryStringParameters['startProcessor']);
101
- if (foundProc) {
102
- if (StringRatchet.trimToNull(foundProc.dataSchemaName)) {
103
- const errors = this.modelValidator.validate(foundProc.dataSchemaName, entry.data, false, false);
104
- if (errors.length > 0) {
105
- throw new BadRequestError().withErrors(errors);
106
- }
107
- }
108
- let result = null;
109
- if (immediate) {
110
- result = await this.backgroundManager.fireImmediateProcessRequest(entry);
111
- }
112
- else {
113
- result = await this.backgroundManager.addEntryToQueue(entry, startProcessor);
114
- }
115
- rval = {
116
- processHandling: immediate ? BackgroundProcessHandling.Immediate : BackgroundProcessHandling.Queued,
117
- startProcessorRequested: startProcessor,
118
- success: true,
119
- resultId: result,
120
- error: null,
121
- };
122
- }
123
- else {
124
- throw new BadRequestError().withFormattedErrorMessage('Could not find target background processor : %s', entry.type);
125
- }
126
- return rval;
127
- }
128
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- export var BackgroundProcessHandling;
2
- (function (BackgroundProcessHandling) {
3
- BackgroundProcessHandling["Queued"] = "Queued";
4
- BackgroundProcessHandling["Immediate"] = "Immediate";
5
- })(BackgroundProcessHandling || (BackgroundProcessHandling = {}));
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,86 +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 { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
4
- export class BackgroundValidator {
5
- cfg;
6
- modelValidator;
7
- constructor(cfg, modelValidator) {
8
- this.cfg = cfg;
9
- this.modelValidator = modelValidator;
10
- }
11
- findProcessor(typeName) {
12
- const rval = this.cfg.processors.find((s) => s.typeName === typeName);
13
- return rval;
14
- }
15
- validType(type) {
16
- return !!this.findProcessor(type);
17
- }
18
- validateEntry(entry) {
19
- const rval = [];
20
- if (!entry) {
21
- rval.push('Entry is null');
22
- }
23
- else if (!StringRatchet.trimToNull(entry.type)) {
24
- rval.push('Entry type is null or empty');
25
- const proc = this.findProcessor(entry.type);
26
- if (!proc) {
27
- rval.push('Entry type is invalid');
28
- }
29
- }
30
- return rval;
31
- }
32
- validateEntryAndThrowException(entry) {
33
- const errors = this.validateEntry(entry);
34
- if (errors.length > 0) {
35
- Logger.warn('Invalid entry %j : errors : %j', entry, errors);
36
- ErrorRatchet.throwFormattedErr('Invalid entry %j : errors : %j', entry, errors);
37
- }
38
- }
39
- static validateAndMapProcessors(processorInput, modelValidator) {
40
- const rval = new Map();
41
- processorInput.forEach((p, idx) => {
42
- if (!p) {
43
- ErrorRatchet.throwFormattedErr('Null processor provided at index %d', idx);
44
- }
45
- if (!StringRatchet.trimToNull(p.typeName)) {
46
- ErrorRatchet.throwFormattedErr('Processor at index %d defines no name', idx);
47
- }
48
- if (rval.has(p.typeName)) {
49
- ErrorRatchet.throwFormattedErr('More than one processor defined for type %s', p.typeName);
50
- }
51
- rval.set(p.typeName, p);
52
- });
53
- return rval;
54
- }
55
- static validateAwsConfig(cfg) {
56
- const rval = [];
57
- if (!cfg) {
58
- rval.push('Null config');
59
- }
60
- else {
61
- if (!cfg.notificationArn) {
62
- rval.push('AWS config missing notificationArn');
63
- }
64
- if (!cfg.queueUrl) {
65
- rval.push('AWS config missing queueUrl');
66
- }
67
- if ((cfg.sendNotificationOnBackgroundError || cfg.sendNotificationOnBackgroundValidationFailure) &&
68
- !cfg.backgroundProcessFailureSnsArn) {
69
- rval.push('At least one send notification flag set to true but no sns arn set');
70
- }
71
- }
72
- return rval;
73
- }
74
- static validateConfig(cfg) {
75
- const rval = [];
76
- if (!cfg) {
77
- rval.push('Null config');
78
- }
79
- else {
80
- if (!cfg.processors || cfg.processors.length === 0) {
81
- rval.push('No processes specified');
82
- }
83
- }
84
- return rval;
85
- }
86
- }