@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,93 +0,0 @@
1
- import util from 'util';
2
- export class EpsilonBackgroundProcessError extends Error {
3
- static EPSILON_BACKGROUND_PROCESS_ERROR_FLAG_KEY = '__epsilonBackgroundProcessErrorFlag';
4
- _errors;
5
- _detailErrorCode;
6
- _details;
7
- _requestId;
8
- _wrappedError;
9
- constructor(...errors) {
10
- super(EpsilonBackgroundProcessError.combineErrorStringsWithDefault(errors));
11
- Object.setPrototypeOf(this, EpsilonBackgroundProcessError.prototype);
12
- this._errors = errors;
13
- this[EpsilonBackgroundProcessError.EPSILON_BACKGROUND_PROCESS_ERROR_FLAG_KEY] = true;
14
- }
15
- static combineErrorStringsWithDefault(errors, defMessage = 'Internal Server Error') {
16
- return errors && errors.length > 0 ? errors.join(',') : defMessage;
17
- }
18
- setFormattedErrorMessage(format, ...input) {
19
- const msg = util.format(format, ...input);
20
- this.errors = [msg];
21
- }
22
- withFormattedErrorMessage(format, ...input) {
23
- this.setFormattedErrorMessage(format, ...input);
24
- return this;
25
- }
26
- withErrors(errors) {
27
- this.errors = errors;
28
- return this;
29
- }
30
- withDetailErrorCode(detailErrorCode) {
31
- this._detailErrorCode = detailErrorCode;
32
- return this;
33
- }
34
- withDetails(details) {
35
- this._details = details;
36
- return this;
37
- }
38
- withRequestId(requestId) {
39
- this._requestId = requestId;
40
- return this;
41
- }
42
- withWrappedError(err) {
43
- this._wrappedError = err;
44
- return this;
45
- }
46
- isWrappedError() {
47
- return !!this._wrappedError;
48
- }
49
- static wrapError(err) {
50
- let rval = null;
51
- if (EpsilonBackgroundProcessError.objectIsEpsilonBackgroundProcessError(err)) {
52
- rval = err;
53
- }
54
- else {
55
- rval = new EpsilonBackgroundProcessError(err.message).withWrappedError(err);
56
- }
57
- return rval;
58
- }
59
- static objectIsEpsilonBackgroundProcessError(obj) {
60
- return obj && obj['__epsilonHttpErrorFlag'] === true;
61
- }
62
- set errors(value) {
63
- this._errors = value || ['Internal Server Error'];
64
- this.message = EpsilonBackgroundProcessError.combineErrorStringsWithDefault(this._errors);
65
- }
66
- get errors() {
67
- return this._errors;
68
- }
69
- set detailErrorCode(value) {
70
- this._detailErrorCode = value;
71
- }
72
- get detailErrorCode() {
73
- return this._detailErrorCode;
74
- }
75
- set details(value) {
76
- this._details = value;
77
- }
78
- get details() {
79
- return this._details;
80
- }
81
- set requestId(value) {
82
- this._requestId = value || 'MISSING';
83
- }
84
- get requestId() {
85
- return this._requestId;
86
- }
87
- set wrappedError(value) {
88
- this._wrappedError = value;
89
- }
90
- get wrappedError() {
91
- return this._wrappedError;
92
- }
93
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,89 +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 { RequireRatchet } from '@bitblit/ratchet-common/lib/lang/require-ratchet.js';
4
- import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
5
- import { DateTime } from 'luxon';
6
- import { ContextUtil } from '../../util/context-util.js';
7
- export class AbstractBackgroundManager {
8
- createEntry(type, data) {
9
- const rval = {
10
- type: type,
11
- data: data,
12
- };
13
- return rval;
14
- }
15
- wrapEntryForInternal(entry, overrideTraceId, overrideTraceDepth) {
16
- const rval = Object.assign({}, entry, {
17
- createdEpochMS: new Date().getTime(),
18
- guid: AbstractBackgroundManager.generateBackgroundGuid(),
19
- traceId: overrideTraceId || ContextUtil.currentTraceId(),
20
- traceDepth: overrideTraceDepth || ContextUtil.currentTraceDepth() + 1,
21
- });
22
- return rval;
23
- }
24
- async addEntryToQueueByParts(type, data, fireStartMessage) {
25
- let rval = null;
26
- const entry = this.createEntry(type, data);
27
- if (entry) {
28
- rval = await this.addEntryToQueue(entry, fireStartMessage);
29
- }
30
- return rval;
31
- }
32
- async addEntriesToQueue(entries, fireStartMessage) {
33
- const rval = [];
34
- for (let i = 0; i < entries.length; i++) {
35
- try {
36
- const tmp = await this.addEntryToQueue(entries[i], false);
37
- rval.push(tmp);
38
- }
39
- catch (err) {
40
- Logger.error('Error processing %j : %s', entries[i], err);
41
- rval.push(err['message']);
42
- }
43
- if (fireStartMessage) {
44
- const fireResult = await this.fireStartProcessingRequest();
45
- Logger.silly('FireResult : %s', fireResult);
46
- }
47
- }
48
- return rval;
49
- }
50
- async fireImmediateProcessRequestByParts(type, data) {
51
- let rval = null;
52
- const entry = this.createEntry(type, data);
53
- if (entry) {
54
- rval = await this.fireImmediateProcessRequest(entry);
55
- }
56
- return rval;
57
- }
58
- static generateBackgroundGuid(targetEpochMS = new Date().getTime()) {
59
- const dt = DateTime.fromMillis(targetEpochMS);
60
- return dt.toFormat('yyyy-MM-dd-HH-mm-ss-') + StringRatchet.createType4Guid();
61
- }
62
- static backgroundGuidToPath(prefix, guid) {
63
- let path = StringRatchet.trimToEmpty(prefix);
64
- if (path.length && !path.endsWith('/')) {
65
- path += '/';
66
- }
67
- path += guid.substring(0, 4) + '/' + guid.substring(5, 7) + '/' + guid.substring(8, 10) + '/';
68
- path += guid + '.json';
69
- return path;
70
- }
71
- static pathToBackgroundGuid(prefix, path) {
72
- RequireRatchet.notNullOrUndefined(path, 'path');
73
- let start = 0;
74
- if (!path.endsWith('.json')) {
75
- ErrorRatchet.throwFormattedErr('Cannot extract guid, does not end with .json : %s : %s', path, prefix);
76
- }
77
- if (StringRatchet.trimToNull(prefix)) {
78
- if (!path.startsWith(prefix)) {
79
- ErrorRatchet.throwFormattedErr('Cannot extract guid, does not start with prefix : %s : %s', path, prefix);
80
- }
81
- start = prefix.length;
82
- if (!prefix.endsWith('/')) {
83
- start++;
84
- }
85
- }
86
- start += 11;
87
- return path.substring(start, path.length - 5);
88
- }
89
- }
@@ -1,153 +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 { NumberRatchet } from '@bitblit/ratchet-common/lib/lang/number-ratchet.js';
4
- import { DeleteMessageCommand, GetQueueAttributesCommand, ReceiveMessageCommand, SendMessageCommand, } from '@aws-sdk/client-sqs';
5
- import { EpsilonConstants } from '../../epsilon-constants.js';
6
- import { AbstractBackgroundManager } from './abstract-background-manager.js';
7
- import { BackgroundValidator } from '../background-validator.js';
8
- import { PublishCommand } from '@aws-sdk/client-sns';
9
- export class AwsSqsSnsBackgroundManager extends AbstractBackgroundManager {
10
- _awsConfig;
11
- _sqs;
12
- _sns;
13
- constructor(_awsConfig, _sqs, _sns) {
14
- super();
15
- this._awsConfig = _awsConfig;
16
- this._sqs = _sqs;
17
- this._sns = _sns;
18
- const cfgErrors = BackgroundValidator.validateAwsConfig(_awsConfig);
19
- if (cfgErrors.length) {
20
- ErrorRatchet.throwFormattedErr('Cannot start - invalid AWS config : %j', cfgErrors);
21
- }
22
- }
23
- get backgroundManagerName() {
24
- return 'AwsSqsSnsBackgroundManager';
25
- }
26
- get awsConfig() {
27
- return this._awsConfig;
28
- }
29
- get sqs() {
30
- return this._sqs;
31
- }
32
- get sns() {
33
- return this._sns;
34
- }
35
- async addEntryToQueue(entry, fireStartMessage) {
36
- try {
37
- const wrapped = this.wrapEntryForInternal(entry);
38
- const rval = wrapped.guid;
39
- const params = {
40
- DelaySeconds: 0,
41
- MessageBody: JSON.stringify(wrapped),
42
- MessageGroupId: entry.type,
43
- QueueUrl: this.awsConfig.queueUrl,
44
- };
45
- Logger.info('Add entry to queue (remote) : %j : Start : %s', params, fireStartMessage);
46
- const result = await this.sqs.send(new SendMessageCommand(params));
47
- if (fireStartMessage) {
48
- const fireResult = await this.fireStartProcessingRequest();
49
- Logger.silly('FireResult : %s', fireResult);
50
- }
51
- Logger.info('Background process %s using message id %s', rval, result.MessageId);
52
- return rval;
53
- }
54
- catch (error) {
55
- Logger.error('Error inserting background entry into SQS queue : %j', error);
56
- throw new Error('Error inserting background entry into SQS queue : ' + error['code'] + ' : ' + error['name']);
57
- }
58
- }
59
- async fireImmediateProcessRequest(entry) {
60
- let rval = null;
61
- const wrapped = this.wrapEntryForInternal(entry);
62
- rval = wrapped.guid;
63
- try {
64
- Logger.info('Fire immediately (remote) : %j ', entry);
65
- const toWrite = {
66
- type: EpsilonConstants.BACKGROUND_SNS_IMMEDIATE_RUN_FLAG,
67
- backgroundEntry: wrapped,
68
- };
69
- const msg = JSON.stringify(toWrite);
70
- const snsId = await this.writeMessageToSnsTopic(msg);
71
- Logger.debug('Background guid %s Wrote message : %s to SNS : %s', rval, msg, snsId);
72
- }
73
- catch (err) {
74
- Logger.error('Failed to fireImmediateProcessRequest : %s', err, err);
75
- }
76
- return rval;
77
- }
78
- async fireStartProcessingRequest() {
79
- let rval = null;
80
- try {
81
- Logger.info('Fire start processing request (remote)');
82
- rval = await this.writeMessageToSnsTopic(EpsilonConstants.BACKGROUND_SNS_START_MARKER);
83
- }
84
- catch (err) {
85
- Logger.error('Failed to fireStartProcessingRequest : %s', err, err);
86
- }
87
- return rval;
88
- }
89
- async fetchApproximateNumberOfQueueEntries() {
90
- let rval = null;
91
- const all = await this.fetchCurrentQueueAttributes();
92
- rval = NumberRatchet.safeNumber(all.Attributes['ApproximateNumberOfMessages']);
93
- return rval;
94
- }
95
- async fetchCurrentQueueAttributes() {
96
- let rval = null;
97
- const req = {
98
- AttributeNames: ['All'],
99
- QueueUrl: this.awsConfig.queueUrl,
100
- };
101
- rval = await this.sqs.send(new GetQueueAttributesCommand(req));
102
- return rval;
103
- }
104
- async writeMessageToSnsTopic(message) {
105
- let rval = null;
106
- const params = {
107
- Message: message,
108
- TopicArn: this.awsConfig.notificationArn,
109
- };
110
- Logger.debug('Writing message to SNS topic : j', params);
111
- const result = await this.sns.send(new PublishCommand(params));
112
- rval = result.MessageId;
113
- return rval;
114
- }
115
- async takeEntryFromBackgroundQueue() {
116
- const rval = [];
117
- const params = {
118
- MaxNumberOfMessages: 1,
119
- QueueUrl: this.awsConfig.queueUrl,
120
- VisibilityTimeout: 300,
121
- WaitTimeSeconds: 0,
122
- };
123
- const message = await this.sqs.send(new ReceiveMessageCommand(params));
124
- if (message && message.Messages && message.Messages.length > 0) {
125
- for (let i = 0; i < message.Messages.length; i++) {
126
- const m = message.Messages[i];
127
- try {
128
- const parsedBody = JSON.parse(m.Body);
129
- if (!parsedBody.type) {
130
- Logger.warn('Dropping invalid background entry : %j', parsedBody);
131
- }
132
- else {
133
- rval.push(parsedBody);
134
- }
135
- Logger.debug('Removing message from queue');
136
- const delParams = {
137
- QueueUrl: this.awsConfig.queueUrl,
138
- ReceiptHandle: m.ReceiptHandle,
139
- };
140
- const delResult = await this.sqs.send(new DeleteMessageCommand(delParams));
141
- Logger.silly('Delete result : %j', delResult);
142
- }
143
- catch (err) {
144
- Logger.warn('Error parsing message, dropping : %j', m);
145
- }
146
- }
147
- }
148
- else {
149
- Logger.debug('No messages found (likely end of recursion)');
150
- }
151
- return rval;
152
- }
153
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,73 +0,0 @@
1
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
2
- import { GetQueueAttributesCommand, SQSClient } from '@aws-sdk/client-sqs';
3
- import { ModelValidator } from '@bitblit/ratchet-misc/lib/model-validator/model-validator.js';
4
- import { AwsSqsSnsBackgroundManager } from './aws-sqs-sns-background-manager.js';
5
- import { EchoProcessor } from '../../built-in/background/echo-processor.js';
6
- import { NoOpProcessor } from '../../built-in/background/no-op-processor.js';
7
- import { SNSClient } from '@aws-sdk/client-sns';
8
- import { mockClient } from 'aws-sdk-client-mock';
9
- let mockSqs;
10
- let mockSns;
11
- describe('#createEntry', function () {
12
- mockSns = mockClient(SNSClient);
13
- mockSqs = mockClient(SQSClient);
14
- let backgroundMgr;
15
- const fakeAccountNumber = '123456789012';
16
- let backgroundConfig;
17
- let backgroundAwsConfig;
18
- const fakeModelValidator = new ModelValidator({ BackgroundBuiltInSampleInputValidatedProcessor: {} });
19
- const echoProcessor = new EchoProcessor();
20
- const noOpProcessor = new NoOpProcessor();
21
- beforeEach(() => {
22
- mockSqs.reset();
23
- mockSns.reset();
24
- backgroundConfig = {
25
- processors: [echoProcessor, noOpProcessor],
26
- httpSubmissionPath: '/background/',
27
- implyTypeFromPathSuffix: true,
28
- httpMetaEndpoint: '/background-meta',
29
- };
30
- backgroundAwsConfig = {
31
- queueUrl: 'https://fake-sqs.fake-availability-zone.test.com/' + fakeAccountNumber + '/fakeQueue.fifo',
32
- notificationArn: 'arn:aws:sns:fake-availability-zone:' + fakeAccountNumber + ':fakeSnsTopicName',
33
- };
34
- backgroundMgr = new AwsSqsSnsBackgroundManager(backgroundAwsConfig, mockSqs, mockSns);
35
- });
36
- it('Should return queue attributes', async () => {
37
- mockSqs.on(GetQueueAttributesCommand).resolves({
38
- Attributes: {
39
- ApproximateNumberOfMessages: 1,
40
- },
41
- });
42
- const queueAttr = await backgroundMgr.fetchCurrentQueueAttributes();
43
- const msgCount = await backgroundMgr.fetchApproximateNumberOfQueueEntries();
44
- Logger.info('Got : %j', queueAttr);
45
- Logger.info('Msg: %d', msgCount);
46
- expect(queueAttr).toBeTruthy();
47
- expect(msgCount).toEqual(1);
48
- });
49
- it('Should round-trip guids with prefix no slash', async () => {
50
- const prefix = 'test';
51
- const guid = AwsSqsSnsBackgroundManager.generateBackgroundGuid();
52
- expect(guid).toBeTruthy();
53
- const path = AwsSqsSnsBackgroundManager.backgroundGuidToPath(prefix, guid);
54
- const outGuid = AwsSqsSnsBackgroundManager.pathToBackgroundGuid(prefix, path);
55
- expect(outGuid).toEqual(guid);
56
- });
57
- it('Should round-trip guids with prefix with slash', async () => {
58
- const prefix = 'test/';
59
- const guid = AwsSqsSnsBackgroundManager.generateBackgroundGuid();
60
- expect(guid).toBeTruthy();
61
- const path = AwsSqsSnsBackgroundManager.backgroundGuidToPath(prefix, guid);
62
- const outGuid = AwsSqsSnsBackgroundManager.pathToBackgroundGuid(prefix, path);
63
- expect(outGuid).toEqual(guid);
64
- });
65
- it('Should round-trip guids with no prefix', async () => {
66
- const prefix = null;
67
- const guid = AwsSqsSnsBackgroundManager.generateBackgroundGuid();
68
- expect(guid).toBeTruthy();
69
- const path = AwsSqsSnsBackgroundManager.backgroundGuidToPath(prefix, guid);
70
- const outGuid = AwsSqsSnsBackgroundManager.pathToBackgroundGuid(prefix, path);
71
- expect(outGuid).toEqual(guid);
72
- });
73
- });
@@ -1,45 +0,0 @@
1
- import { Subject } from 'rxjs';
2
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
3
- import { AbstractBackgroundManager } from './abstract-background-manager.js';
4
- export class SingleThreadLocalBackgroundManager extends AbstractBackgroundManager {
5
- _localBus = new Subject();
6
- get backgroundManagerName() {
7
- return 'SingleThreadLocalBackgroundManager';
8
- }
9
- constructor() {
10
- super();
11
- }
12
- immediateProcessQueue() {
13
- return this._localBus;
14
- }
15
- async addEntryToQueue(entry, fireStartMessage) {
16
- const wrapped = this.wrapEntryForInternal(entry);
17
- const rval = wrapped.guid;
18
- Logger.info('Add entry to queue (local) : %j : Start : %s', entry, fireStartMessage);
19
- this._localBus.next(wrapped);
20
- return rval;
21
- }
22
- async fireImmediateProcessRequest(entry) {
23
- let rval = null;
24
- const wrapped = this.wrapEntryForInternal(entry);
25
- rval = wrapped.guid;
26
- Logger.info('Fire immediately (local) : %j ', entry);
27
- this._localBus.next(wrapped);
28
- return rval;
29
- }
30
- async fireStartProcessingRequest() {
31
- let rval = null;
32
- Logger.info('Fire start processing request (local, ignored)');
33
- rval = 'NO-OP';
34
- return rval;
35
- }
36
- async fetchApproximateNumberOfQueueEntries() {
37
- let rval = null;
38
- rval = 0;
39
- return rval;
40
- }
41
- async takeEntryFromBackgroundQueue() {
42
- Logger.info('Called takeEntryFromBackgroundQueue on SingleThreadedLocal - returning empty');
43
- return [];
44
- }
45
- }
@@ -1,52 +0,0 @@
1
- import { S3CacheRatchet } from '@bitblit/ratchet-aws/lib/s3/s3-cache-ratchet.js';
2
- import { AbstractBackgroundManager } from './manager/abstract-background-manager.js';
3
- import { ErrorRatchet } from '@bitblit/ratchet-common/lib/lang/error-ratchet.js';
4
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
5
- export class S3BackgroundTransactionLogger {
6
- cfg;
7
- s3TransactionLogCacheRatchet;
8
- constructor(cfg) {
9
- this.cfg = cfg;
10
- const err = S3BackgroundTransactionLogger.validateConfig(cfg);
11
- if (err.length) {
12
- ErrorRatchet.throwFormattedErr('Invalid S3BackgroundTransactionLogger config : %j', err);
13
- }
14
- this.s3TransactionLogCacheRatchet = new S3CacheRatchet(this.cfg.s3, this.cfg.bucket);
15
- }
16
- async logTransaction(txLog) {
17
- if (txLog) {
18
- if (txLog.request?.guid) {
19
- await this.s3TransactionLogCacheRatchet.writeObjectToCacheFile(AbstractBackgroundManager.backgroundGuidToPath(this.cfg.prefix, txLog.request.guid), txLog);
20
- }
21
- else {
22
- Logger.warn('Could not write transaction record - no guid defined : %j', txLog);
23
- }
24
- }
25
- else {
26
- Logger.silly('Skipping write of null log');
27
- }
28
- }
29
- async readTransactionLog(txGuid) {
30
- const path = AbstractBackgroundManager.backgroundGuidToPath(this.cfg.prefix, txGuid);
31
- const log = await this.s3TransactionLogCacheRatchet.fetchCacheFileAsObject(path);
32
- return log;
33
- }
34
- static validateConfig(cfg) {
35
- const rval = [];
36
- if (cfg) {
37
- if (!cfg.s3) {
38
- rval.push('You must supply an S3 object');
39
- }
40
- if (!cfg.bucket) {
41
- rval.push('You must supply a bucket');
42
- }
43
- if (!cfg.timeToLiveDays) {
44
- rval.push('You must supply a timeToLiveDays');
45
- }
46
- }
47
- else {
48
- rval.push('No config defined');
49
- }
50
- return rval;
51
- }
52
- }
@@ -1,14 +0,0 @@
1
- export class RatchetEpsilonCommonInfo {
2
- constructor() { }
3
- static buildInformation() {
4
- const val = {
5
- version: 'LOCAL-SNAPSHOT',
6
- hash: 'LOCAL-HASH',
7
- branch: 'LOCAL-BRANCH',
8
- tag: 'LOCAL-TAG',
9
- timeBuiltISO: 'LOCAL-TIME-ISO',
10
- notes: 'LOCAL-NOTES',
11
- };
12
- return val;
13
- }
14
- }
@@ -1,15 +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 { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
4
- export class EchoProcessor {
5
- static TYPE_NAME = 'EpsilonEcho';
6
- get typeName() {
7
- return EchoProcessor.TYPE_NAME;
8
- }
9
- async handleEvent(data, mgr) {
10
- Logger.info('Echo processing : %j', data);
11
- if (data && StringRatchet.trimToNull(data['error'])) {
12
- ErrorRatchet.throwFormattedErr('Forced error : %s', data['error']);
13
- }
14
- }
15
- }
@@ -1,12 +0,0 @@
1
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
2
- import { EchoProcessor } from './echo-processor.js';
3
- export class LogAndEnqueueEchoProcessor {
4
- get typeName() {
5
- return 'EpsilonLogAndEnqueueEcho';
6
- }
7
- async handleEvent(data, cfg) {
8
- Logger.info('LogAndEnqueueEchoProcessor : %j', data);
9
- await cfg.fireImmediateProcessRequestByParts(EchoProcessor.TYPE_NAME, { upstream: data });
10
- Logger.info('Completed : LogAndEnqueueEchoProcessor');
11
- }
12
- }
@@ -1,6 +0,0 @@
1
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
2
- export class LogMessageBackgroundErrorProcessor {
3
- async handleError(submission, error) {
4
- Logger.error('-------- ERROR PROCESSED : %j : %s----', submission, error);
5
- }
6
- }
@@ -1,9 +0,0 @@
1
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
2
- export class NoOpProcessor {
3
- get typeName() {
4
- return 'EpsilonNoOp';
5
- }
6
- async handleEvent(data, mgr) {
7
- Logger.silly('Hit the no-op proc');
8
- }
9
- }
@@ -1,40 +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 { DurationRatchet } from '@bitblit/ratchet-common/lib/lang/duration-ratchet.js';
4
- import { NumberRatchet } from '@bitblit/ratchet-common/lib/lang/number-ratchet.js';
5
- import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
6
- export class RetryProcessor {
7
- delegate;
8
- opts;
9
- static RETRY_FIELD_NAME = '___RetryProcessorTryNumber';
10
- constructor(delegate, opts) {
11
- this.delegate = delegate;
12
- this.opts = opts;
13
- }
14
- get typeName() {
15
- return StringRatchet.trimToEmpty(this.opts?.typePrefix) + this.delegate.typeName + StringRatchet.trimToEmpty(this.opts?.typeSuffix);
16
- }
17
- async handleEvent(data, mgr) {
18
- const tryNumber = data && data[RetryProcessor.RETRY_FIELD_NAME] ? NumberRatchet.safeNumber(data[RetryProcessor.RETRY_FIELD_NAME]) : 1;
19
- const dataCopy = data ? Object.assign({}, data) : null;
20
- delete dataCopy[RetryProcessor.RETRY_FIELD_NAME];
21
- Logger.info('RetryProcessor : %s : Try %d of %d', this.delegate.typeName, tryNumber, this.opts.retryCount);
22
- try {
23
- await this.delegate.handleEvent(dataCopy, mgr);
24
- }
25
- catch (err) {
26
- Logger.error('Failed to process : %s', err, err);
27
- if (tryNumber < this.opts.retryCount) {
28
- const waitTimeMS = tryNumber * this.opts.baseDelayMS;
29
- Logger.info('Firing automatic retry after a wait of %s', DurationRatchet.formatMsDuration(waitTimeMS));
30
- await PromiseRatchet.wait(waitTimeMS);
31
- const wrapped = dataCopy || {};
32
- wrapped[RetryProcessor.RETRY_FIELD_NAME] = tryNumber + 1;
33
- await mgr.fireImmediateProcessRequestByParts(this.typeName, wrapped);
34
- }
35
- else {
36
- Logger.error('That was the last try - giving up');
37
- }
38
- }
39
- }
40
- }
@@ -1,13 +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
- export class SampleDelayProcessor {
4
- get typeName() {
5
- return 'EpsilonSampleDelay';
6
- }
7
- async handleEvent(data, mgr) {
8
- const delayMS = Math.floor(Math.random() * 5000);
9
- Logger.info('Running sample processor for %d', delayMS);
10
- await PromiseRatchet.wait(delayMS);
11
- Logger.info('Sample processor complete');
12
- }
13
- }
@@ -1,12 +0,0 @@
1
- import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
2
- export class SampleInputValidatedProcessor {
3
- get typeName() {
4
- return 'EpsilonSampleInputValidated';
5
- }
6
- async handleEvent(data, mgr) {
7
- Logger.info('Running SampleInputValidatedProcessor, data was : %j', data);
8
- }
9
- get dataSchemaName() {
10
- return 'BackgroundSampleInputValidatedProcessorData';
11
- }
12
- }
@@ -1,21 +0,0 @@
1
- import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
2
- import { ContextUtil } from '../util/context-util.js';
3
- export class BuiltInTraceIdGenerators {
4
- static fullAwsRequestId() {
5
- let rval = ContextUtil.currentRequestId();
6
- rval = rval ?? StringRatchet.createType4Guid();
7
- return rval;
8
- }
9
- static shortAwsRequestId() {
10
- let rval = BuiltInTraceIdGenerators.fullAwsRequestId();
11
- if (rval.length > 10) {
12
- let idx = rval.lastIndexOf('-');
13
- idx = idx === -1 ? rval.length - 10 : idx;
14
- rval = rval.substring(idx);
15
- }
16
- return rval;
17
- }
18
- static fixedLengthHex(length = 10) {
19
- return StringRatchet.createRandomHexString(length);
20
- }
21
- }