dt-common-device 2.0.7 → 3.0.0

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 (186) hide show
  1. package/README.md +321 -99
  2. package/dist/alerts/Alert.model.d.ts +28 -0
  3. package/dist/alerts/Alert.model.js +222 -0
  4. package/dist/alerts/Alert.repository.d.ts +106 -0
  5. package/dist/alerts/Alert.repository.js +374 -0
  6. package/dist/alerts/Alert.service.d.ts +137 -0
  7. package/dist/alerts/Alert.service.js +476 -0
  8. package/dist/alerts/AlertBuilder.d.ts +87 -0
  9. package/dist/alerts/AlertBuilder.example.d.ts +11 -0
  10. package/dist/alerts/AlertBuilder.example.js +117 -0
  11. package/dist/alerts/AlertBuilder.js +185 -0
  12. package/dist/alerts/AlertService.example.d.ts +55 -0
  13. package/dist/alerts/AlertService.example.js +148 -0
  14. package/dist/alerts/alert.types.d.ts +57 -0
  15. package/dist/alerts/alert.types.js +22 -0
  16. package/dist/alerts/index.d.ts +3 -0
  17. package/dist/alerts/index.js +19 -0
  18. package/dist/config/config.d.ts +4 -4
  19. package/dist/config/config.js +3 -3
  20. package/dist/config/config.types.d.ts +19 -0
  21. package/dist/config/config.types.js +2 -0
  22. package/dist/connection/Connection.repository.d.ts +8 -0
  23. package/dist/connection/Connection.repository.js +92 -0
  24. package/dist/connection/Connection.service.d.ts +8 -0
  25. package/dist/connection/Connection.service.js +32 -0
  26. package/dist/connection/IConnection.d.ts +26 -0
  27. package/dist/connection/IConnection.js +14 -0
  28. package/dist/connection/index.d.ts +2 -0
  29. package/dist/connection/index.js +18 -0
  30. package/dist/device/cloud/entities/CloudDevice.d.ts +2 -2
  31. package/dist/device/cloud/entities/CloudDeviceService.d.ts +1 -1
  32. package/dist/device/cloud/entities/DeviceFactory.d.ts +1 -1
  33. package/dist/device/cloud/entities/DeviceFactory.js +1 -1
  34. package/dist/device/cloud/interfaces/ICloudDeviceService.d.ts +1 -1
  35. package/dist/device/cloud/interfaces/IRawDevice.d.ts +1 -1
  36. package/dist/device/local/interfaces/index.d.ts +2 -3
  37. package/dist/device/local/interfaces/index.js +2 -3
  38. package/dist/device/local/repository/Device.repository.js +3 -3
  39. package/dist/device/local/repository/Hub.repository.js +4 -4
  40. package/dist/device/local/repository/Schedule.repository.js +2 -2
  41. package/dist/device/local/services/Device.service.d.ts +2 -2
  42. package/dist/device/local/services/Device.service.js +1 -1
  43. package/dist/device/local/services/index.d.ts +0 -4
  44. package/dist/device/local/services/index.js +0 -4
  45. package/dist/events/BaseEventHandler.d.ts +2 -2
  46. package/dist/events/BaseEventHandler.js +2 -2
  47. package/dist/events/BaseEventTransformer.d.ts +1 -1
  48. package/dist/events/BaseEventTransformer.js +1 -1
  49. package/dist/events/DeviceEventHandler.d.ts +1 -1
  50. package/dist/events/DeviceEventHandler.js +2 -2
  51. package/dist/events/EventHandler.js +1 -1
  52. package/dist/events/EventHandlerOrchestrator.js +1 -1
  53. package/dist/events/EventProcessingService.js +1 -1
  54. package/dist/events/InternalEventSubscription.js +1 -1
  55. package/dist/index.d.ts +7 -5
  56. package/dist/index.js +16 -13
  57. package/dist/issues/Issue.model.d.ts +28 -0
  58. package/dist/issues/Issue.model.js +260 -0
  59. package/dist/issues/Issue.repository.d.ts +113 -0
  60. package/dist/issues/Issue.repository.js +401 -0
  61. package/dist/issues/Issue.service.d.ts +168 -0
  62. package/dist/issues/Issue.service.js +642 -0
  63. package/dist/issues/IssueBuilder.d.ts +109 -0
  64. package/dist/issues/IssueBuilder.example.d.ts +16 -0
  65. package/dist/issues/IssueBuilder.example.js +196 -0
  66. package/dist/issues/IssueBuilder.js +237 -0
  67. package/dist/issues/IssueService.example.d.ts +68 -0
  68. package/dist/issues/IssueService.example.js +177 -0
  69. package/dist/issues/index.d.ts +2 -0
  70. package/dist/issues/index.js +18 -0
  71. package/dist/issues/issue.types.d.ts +90 -0
  72. package/dist/issues/issue.types.js +40 -0
  73. package/dist/property/IProperty.d.ts +29 -0
  74. package/dist/property/IProperty.js +2 -0
  75. package/dist/property/Property.repository.d.ts +8 -0
  76. package/dist/property/Property.repository.js +95 -0
  77. package/dist/property/Property.service.d.ts +8 -0
  78. package/dist/property/Property.service.js +36 -0
  79. package/dist/property/index.d.ts +2 -0
  80. package/dist/property/index.js +18 -0
  81. package/dist/queue/entities/HybridHttpQueue.d.ts +23 -0
  82. package/dist/queue/entities/HybridHttpQueue.js +189 -0
  83. package/dist/queue/entities/index.d.ts +1 -0
  84. package/dist/queue/entities/index.js +17 -0
  85. package/dist/queue/index.d.ts +5 -0
  86. package/dist/queue/index.js +22 -0
  87. package/dist/queue/interfaces/IHttpRequestJob.d.ts +9 -0
  88. package/dist/queue/interfaces/IHttpRequestJob.js +2 -0
  89. package/dist/queue/interfaces/IHybridHttpQueue.d.ts +16 -0
  90. package/dist/queue/interfaces/IHybridHttpQueue.js +2 -0
  91. package/dist/queue/interfaces/IJobResult.d.ts +6 -0
  92. package/dist/queue/interfaces/IJobResult.js +2 -0
  93. package/dist/queue/interfaces/IRateLimitConfig.d.ts +5 -0
  94. package/dist/queue/interfaces/IRateLimitConfig.js +2 -0
  95. package/dist/queue/interfaces/index.d.ts +4 -0
  96. package/dist/queue/interfaces/index.js +20 -0
  97. package/dist/queue/services/QueueService.d.ts +19 -0
  98. package/dist/queue/services/QueueService.js +73 -0
  99. package/dist/queue/services/index.d.ts +1 -0
  100. package/dist/queue/services/index.js +17 -0
  101. package/dist/queue/types/http.types.d.ts +21 -0
  102. package/dist/queue/types/http.types.js +2 -0
  103. package/dist/queue/types/index.d.ts +2 -0
  104. package/dist/queue/types/index.js +18 -0
  105. package/dist/queue/types/queue.types.d.ts +35 -0
  106. package/dist/queue/types/queue.types.js +2 -0
  107. package/dist/queue/utils/index.d.ts +3 -0
  108. package/dist/queue/utils/index.js +19 -0
  109. package/dist/queue/utils/jobUtils.d.ts +10 -0
  110. package/dist/queue/utils/jobUtils.js +64 -0
  111. package/dist/queue/utils/queueUtils.d.ts +5 -0
  112. package/dist/queue/utils/queueUtils.js +59 -0
  113. package/dist/queue/utils/rateLimit.utils.d.ts +6 -0
  114. package/dist/queue/utils/rateLimit.utils.js +44 -0
  115. package/package.json +2 -1
  116. package/src/{device/local/models → alerts}/Alert.model.ts +1 -1
  117. package/src/{device/local/repository → alerts}/Alert.repository.ts +2 -2
  118. package/src/{device/local/services → alerts}/Alert.service.ts +14 -7
  119. package/src/{device/local/entities → alerts}/AlertBuilder.example.ts +2 -2
  120. package/src/{device/local/entities → alerts}/AlertBuilder.ts +14 -8
  121. package/src/{device/local/services → alerts}/AlertService.example.ts +6 -5
  122. package/src/{types → alerts}/alert.types.ts +2 -2
  123. package/src/alerts/index.ts +3 -0
  124. package/src/config/config.ts +7 -7
  125. package/src/{types → config}/config.types.ts +1 -1
  126. package/src/{device/local/repository → connection}/Connection.repository.ts +2 -2
  127. package/src/{device/local/services → connection}/Connection.service.ts +2 -2
  128. package/src/connection/index.ts +3 -0
  129. package/src/device/cloud/entities/CloudDevice.ts +2 -2
  130. package/src/device/cloud/entities/CloudDeviceService.ts +1 -1
  131. package/src/device/cloud/entities/DeviceFactory.ts +2 -2
  132. package/src/device/cloud/interfaces/ICloudDeviceService.ts +1 -1
  133. package/src/device/cloud/interfaces/IRawDevice.ts +1 -1
  134. package/src/device/local/interfaces/index.ts +2 -3
  135. package/src/device/local/repository/Device.repository.ts +3 -3
  136. package/src/device/local/repository/Hub.repository.ts +4 -4
  137. package/src/device/local/repository/Schedule.repository.ts +2 -2
  138. package/src/device/local/services/Device.service.ts +1 -1
  139. package/src/device/local/services/index.ts +0 -4
  140. package/{TROUBLESHOOTING.md → src/docs/TROUBLESHOOTING.md} +2 -2
  141. package/src/events/BaseEventHandler.ts +3 -3
  142. package/src/events/BaseEventTransformer.ts +2 -2
  143. package/src/events/DeviceEventHandler.ts +3 -3
  144. package/src/events/EventHandler.ts +1 -1
  145. package/src/events/EventHandlerOrchestrator.ts +2 -2
  146. package/src/events/EventProcessingService.ts +2 -2
  147. package/src/events/InternalEventSubscription.ts +2 -2
  148. package/src/index.ts +19 -13
  149. package/src/{device/local/models → issues}/Issue.model.ts +1 -1
  150. package/src/{device/local/repository → issues}/Issue.repository.ts +2 -2
  151. package/src/{device/local/services → issues}/Issue.service.ts +4 -4
  152. package/src/{device/local/entities → issues}/IssueBuilder.example.ts +1 -1
  153. package/src/{device/local/entities → issues}/IssueBuilder.ts +1 -1
  154. package/src/{device/local/services → issues}/IssueService.example.ts +6 -5
  155. package/src/issues/index.ts +2 -0
  156. package/src/{device/local/repository → property}/Property.repository.ts +2 -2
  157. package/src/{device/local/services → property}/Property.service.ts +1 -1
  158. package/src/property/index.ts +2 -0
  159. package/src/queue/entities/HybridHttpQueue.ts +196 -0
  160. package/src/queue/entities/index.ts +1 -0
  161. package/src/queue/index.ts +6 -0
  162. package/src/queue/interfaces/IHttpRequestJob.ts +10 -0
  163. package/src/queue/interfaces/IHybridHttpQueue.ts +23 -0
  164. package/src/queue/interfaces/IJobResult.ts +6 -0
  165. package/src/queue/interfaces/IRateLimitConfig.ts +5 -0
  166. package/src/queue/interfaces/index.ts +4 -0
  167. package/src/queue/services/QueueService.ts +39 -0
  168. package/src/queue/services/index.ts +1 -0
  169. package/src/queue/types/http.types.ts +22 -0
  170. package/src/queue/types/index.ts +2 -0
  171. package/src/queue/types/queue.types.ts +22 -0
  172. package/src/queue/utils/index.ts +3 -0
  173. package/src/queue/utils/jobUtils.ts +80 -0
  174. package/src/queue/utils/queueUtils.ts +90 -0
  175. package/src/queue/utils/rateLimit.utils.ts +58 -0
  176. package/tsconfig.json +4 -0
  177. package/src/device/local/entities/README.md +0 -173
  178. package/src/device/local/entities/index.ts +0 -2
  179. package/src/types/index.ts +0 -3
  180. /package/src/{device/local/interfaces → connection}/IConnection.ts +0 -0
  181. /package/src/{device/local/models → docs}/Alert.model.md +0 -0
  182. /package/src/{device/local/models/README.md → docs/Alerts&IssuesModel.md} +0 -0
  183. /package/src/{device/local/models → docs}/Issue.model.md +0 -0
  184. /package/{SECURITY.md → src/docs/SECURITY.md} +0 -0
  185. /package/src/{types → issues}/issue.types.ts +0 -0
  186. /package/src/{device/local/interfaces → property}/IProperty.ts +0 -0
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
36
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
37
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
38
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
39
+ };
40
+ var __importDefault = (this && this.__importDefault) || function (mod) {
41
+ return (mod && mod.__esModule) ? mod : { "default": mod };
42
+ };
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.HybridHttpQueue = void 0;
45
+ const config_1 = require("../../config/config");
46
+ const axios_1 = __importDefault(require("axios"));
47
+ const dt_audit_library_1 = require("dt-audit-library");
48
+ const typedi_1 = require("typedi");
49
+ const rateLimit_utils_1 = require("../utils/rateLimit.utils");
50
+ const jobUtils_1 = require("../utils/jobUtils");
51
+ const queueUtils_1 = require("../utils/queueUtils");
52
+ let HybridHttpQueue = (() => {
53
+ let _classDecorators = [(0, typedi_1.Service)()];
54
+ let _classDescriptor;
55
+ let _classExtraInitializers = [];
56
+ let _classThis;
57
+ var HybridHttpQueue = _classThis = class {
58
+ constructor() {
59
+ this.queues = new Map();
60
+ this.workers = new Map();
61
+ this.jobResults = new Map();
62
+ this.rateLimitConfigs = rateLimit_utils_1.RateLimitUtils.initializeRateLimitConfigs();
63
+ }
64
+ async handleRateLimit(job) {
65
+ const { connectionId, provider, url, method, options } = job.data;
66
+ const microservice = options.queueOptions?.microservice || "default";
67
+ const isMaxRetries = job.attemptsMade >= 2;
68
+ await (0, dt_audit_library_1.publishAudit)({
69
+ eventType: isMaxRetries
70
+ ? "http.request.failed"
71
+ : "http.request.rateLimitExceeded",
72
+ properties: {
73
+ connectionId,
74
+ provider,
75
+ endpoint: url,
76
+ method,
77
+ timestamp: Date.now(),
78
+ queueId: job.id,
79
+ reason: isMaxRetries ? "max_retries_exceeded" : "rate_limit_exceeded",
80
+ ...(!isMaxRetries && {
81
+ retryCount: job.attemptsMade + 1,
82
+ maxRetries: 3,
83
+ }),
84
+ },
85
+ });
86
+ if (isMaxRetries) {
87
+ await this.queues
88
+ .get(queueUtils_1.QueueUtils.getQueueKey(microservice, connectionId, provider))
89
+ ?.obliterate({ force: true });
90
+ // Don't throw error for max retries - just return
91
+ return;
92
+ }
93
+ throw new Error("Rate limit exceeded");
94
+ }
95
+ async processHttpRequest(job) {
96
+ const { connectionId, provider, url, method, options } = job.data;
97
+ // Check rate limit
98
+ if (!(await rateLimit_utils_1.RateLimitUtils.checkRateLimit(connectionId, provider, this.rateLimitConfigs))) {
99
+ await this.handleRateLimit(job);
100
+ return;
101
+ }
102
+ try {
103
+ (0, config_1.getConfig)().LOGGER.info(`Executing HTTP request: ${method} ${url} for ${provider}`);
104
+ const response = await (0, axios_1.default)({
105
+ method: method.toLowerCase(),
106
+ url: url,
107
+ headers: options.headers || {},
108
+ timeout: 30000,
109
+ ...(options.body && { data: options.body }),
110
+ ...(options.params && { params: options.params }),
111
+ });
112
+ (0, config_1.getConfig)().LOGGER.info(`HTTP request successful: ${method} ${url} for ${provider}`);
113
+ return response.data;
114
+ }
115
+ catch (error) {
116
+ (0, config_1.getConfig)().LOGGER.error(`HTTP request failed ${job.id}: ${error.message}`);
117
+ await (0, dt_audit_library_1.publishAudit)({
118
+ eventType: "http.request.error",
119
+ properties: {
120
+ connectionId,
121
+ provider,
122
+ endpoint: url,
123
+ method,
124
+ timestamp: Date.now(),
125
+ queueId: job.id,
126
+ reason: "execution_error",
127
+ errorMessage: error.message,
128
+ },
129
+ });
130
+ throw new Error(`HTTP request failed: ${error.message}`);
131
+ }
132
+ }
133
+ async request(options) {
134
+ const { method, url, body, headers, queueOptions } = options;
135
+ // Create HttpCallOption object
136
+ const httpCallOption = {
137
+ headers,
138
+ body,
139
+ queueOptions,
140
+ };
141
+ // Call handleRequest with the constructed parameters
142
+ return this.handleRequest(url, method, httpCallOption);
143
+ }
144
+ async handleRequest(url, method, options) {
145
+ const { connectionId, provider, microservice } = jobUtils_1.JobUtils.extractConnectionDetails(options);
146
+ const queueKey = queueUtils_1.QueueUtils.getQueueKey(microservice, connectionId, provider);
147
+ (0, config_1.getConfig)().LOGGER.info(`Queueing: ${method} ${url} -> ${provider} [${connectionId}]`);
148
+ queueUtils_1.QueueUtils.getOrCreateWorker(queueKey, this.workers, this.processHttpRequest.bind(this), this.jobResults);
149
+ const queue = queueUtils_1.QueueUtils.getOrCreateQueue(queueKey, this.queues);
150
+ const job = await queue.add("http-request", {
151
+ microservice,
152
+ connectionId,
153
+ provider,
154
+ url,
155
+ method,
156
+ options,
157
+ timestamp: Date.now(),
158
+ }, {
159
+ attempts: 3,
160
+ backoff: { type: "exponential", delay: 5000 },
161
+ removeOnComplete: { age: 300, count: 1 },
162
+ removeOnFail: { age: 300, count: 1 },
163
+ });
164
+ (0, config_1.getConfig)().LOGGER.info(`Job ${job.id} queued, waiting for completion...`);
165
+ return jobUtils_1.JobUtils.waitForJobCompletion(job, queueKey, this.jobResults);
166
+ }
167
+ async shutdown() {
168
+ (0, config_1.getConfig)().LOGGER.info("Shutting down HTTP queues...");
169
+ await Promise.all([
170
+ ...Array.from(this.workers.values()).map((worker) => worker.close()),
171
+ ...Array.from(this.queues.values()).map((queue) => queue.close()),
172
+ ]);
173
+ this.workers.clear();
174
+ this.queues.clear();
175
+ this.jobResults.clear();
176
+ (0, config_1.getConfig)().LOGGER.info("HTTP queues shutdown complete");
177
+ }
178
+ };
179
+ __setFunctionName(_classThis, "HybridHttpQueue");
180
+ (() => {
181
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
182
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
183
+ HybridHttpQueue = _classThis = _classDescriptor.value;
184
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
185
+ __runInitializers(_classThis, _classExtraInitializers);
186
+ })();
187
+ return HybridHttpQueue = _classThis;
188
+ })();
189
+ exports.HybridHttpQueue = HybridHttpQueue;
@@ -0,0 +1 @@
1
+ export * from "./HybridHttpQueue";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./HybridHttpQueue"), exports);
@@ -0,0 +1,5 @@
1
+ export * from "./entities";
2
+ export * from "./interfaces";
3
+ export * from "./services";
4
+ export * from "./types";
5
+ export * from "./utils";
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // Main queue exports
18
+ __exportStar(require("./entities"), exports);
19
+ __exportStar(require("./interfaces"), exports);
20
+ __exportStar(require("./services"), exports);
21
+ __exportStar(require("./types"), exports);
22
+ __exportStar(require("./utils"), exports);
@@ -0,0 +1,9 @@
1
+ import { HttpCallOption } from "../types/http.types";
2
+ export interface IHttpRequestJob {
3
+ connectionId: string;
4
+ provider: string;
5
+ url: string;
6
+ method: string;
7
+ options: HttpCallOption;
8
+ timestamp: number;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,16 @@
1
+ import { HttpCallOption } from "../types/http.types";
2
+ export interface IHybridHttpQueue {
3
+ request(options: {
4
+ method: string;
5
+ url: string;
6
+ body?: any;
7
+ headers?: Record<string, string>;
8
+ queueOptions?: {
9
+ connectionId: string;
10
+ connectionProvider: string;
11
+ microservice: string;
12
+ };
13
+ }): Promise<any>;
14
+ handleRequest(url: string, method: string, options: HttpCallOption): Promise<any>;
15
+ shutdown(): Promise<void>;
16
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export interface IJobResult {
2
+ result?: any;
3
+ error?: string;
4
+ resolved: boolean;
5
+ timestamp: number;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export interface IRateLimitConfig {
2
+ maxRequests: number;
3
+ windowMs: number;
4
+ provider: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export * from "./IHybridHttpQueue";
2
+ export * from "./IHttpRequestJob";
3
+ export * from "./IJobResult";
4
+ export * from "./IRateLimitConfig";
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./IHybridHttpQueue"), exports);
18
+ __exportStar(require("./IHttpRequestJob"), exports);
19
+ __exportStar(require("./IJobResult"), exports);
20
+ __exportStar(require("./IRateLimitConfig"), exports);
@@ -0,0 +1,19 @@
1
+ import { IHybridHttpQueue } from "../interfaces";
2
+ import { HttpCallOption } from "../types/http.types";
3
+ export declare class QueueService implements IHybridHttpQueue {
4
+ private readonly hybridQueue;
5
+ constructor();
6
+ request(options: {
7
+ method: string;
8
+ url: string;
9
+ body?: any;
10
+ headers?: Record<string, string>;
11
+ queueOptions?: {
12
+ connectionId: string;
13
+ connectionProvider: string;
14
+ microservice: string;
15
+ };
16
+ }): Promise<any>;
17
+ handleRequest(url: string, method: string, options: HttpCallOption): Promise<any>;
18
+ shutdown(): Promise<void>;
19
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
36
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
37
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
38
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
39
+ };
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.QueueService = void 0;
42
+ const typedi_1 = require("typedi");
43
+ const HybridHttpQueue_1 = require("../entities/HybridHttpQueue");
44
+ let QueueService = (() => {
45
+ let _classDecorators = [(0, typedi_1.Service)()];
46
+ let _classDescriptor;
47
+ let _classExtraInitializers = [];
48
+ let _classThis;
49
+ var QueueService = _classThis = class {
50
+ constructor() {
51
+ this.hybridQueue = new HybridHttpQueue_1.HybridHttpQueue();
52
+ }
53
+ async request(options) {
54
+ return this.hybridQueue.request(options);
55
+ }
56
+ async handleRequest(url, method, options) {
57
+ return this.hybridQueue.handleRequest(url, method, options);
58
+ }
59
+ async shutdown() {
60
+ return this.hybridQueue.shutdown();
61
+ }
62
+ };
63
+ __setFunctionName(_classThis, "QueueService");
64
+ (() => {
65
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
66
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
67
+ QueueService = _classThis = _classDescriptor.value;
68
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
69
+ __runInitializers(_classThis, _classExtraInitializers);
70
+ })();
71
+ return QueueService = _classThis;
72
+ })();
73
+ exports.QueueService = QueueService;
@@ -0,0 +1 @@
1
+ export * from "./QueueService";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./QueueService"), exports);
@@ -0,0 +1,21 @@
1
+ export interface HttpCallOption {
2
+ headers?: Record<string, string>;
3
+ body?: any;
4
+ params?: Record<string, any>;
5
+ queueOptions?: {
6
+ connectionId: string;
7
+ connectionProvider: string;
8
+ microservice: string;
9
+ };
10
+ }
11
+ export interface HttpRequestOptions {
12
+ method: string;
13
+ url: string;
14
+ body?: any;
15
+ headers?: Record<string, string>;
16
+ queueOptions?: {
17
+ connectionId: string;
18
+ connectionProvider: string;
19
+ microservice: string;
20
+ };
21
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export * from "./http.types";
2
+ export * from "./queue.types";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./http.types"), exports);
18
+ __exportStar(require("./queue.types"), exports);
@@ -0,0 +1,35 @@
1
+ export interface QueueConfig {
2
+ concurrency: number;
3
+ removeOnComplete: {
4
+ age: number;
5
+ count: number;
6
+ };
7
+ removeOnFail: {
8
+ age: number;
9
+ count: number;
10
+ };
11
+ lockDuration: number;
12
+ stalledInterval: number;
13
+ }
14
+ export interface JobOptions {
15
+ attempts: number;
16
+ backoff: {
17
+ type: string;
18
+ delay: number;
19
+ };
20
+ removeOnComplete: {
21
+ age: number;
22
+ count: number;
23
+ };
24
+ removeOnFail: {
25
+ age: number;
26
+ count: number;
27
+ };
28
+ }
29
+ export interface QueueMetrics {
30
+ totalJobs: number;
31
+ completedJobs: number;
32
+ failedJobs: number;
33
+ pendingJobs: number;
34
+ activeJobs: number;
35
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export * from "./rateLimit.utils";
2
+ export * from "./jobUtils";
3
+ export * from "./queueUtils";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./rateLimit.utils"), exports);
18
+ __exportStar(require("./jobUtils"), exports);
19
+ __exportStar(require("./queueUtils"), exports);
@@ -0,0 +1,10 @@
1
+ import { Job } from "bullmq";
2
+ import { IJobResult } from "../interfaces";
3
+ export declare class JobUtils {
4
+ static waitForJobCompletion(job: Job, queueKey: string, jobResults: Map<string, IJobResult>): Promise<any>;
5
+ static extractConnectionDetails(options: any): {
6
+ connectionId: string;
7
+ provider: string;
8
+ microservice: string;
9
+ };
10
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JobUtils = void 0;
4
+ class JobUtils {
5
+ static async waitForJobCompletion(job, queueKey, jobResults) {
6
+ return new Promise((resolve, reject) => {
7
+ let timeoutId;
8
+ let checkCount = 0;
9
+ const maxChecks = 600;
10
+ const checkJob = async () => {
11
+ if (++checkCount >= maxChecks) {
12
+ clearTimeout(timeoutId);
13
+ return reject(new Error("Job timeout: Request took too long"));
14
+ }
15
+ try {
16
+ const state = await job.getState();
17
+ if (state === "completed") {
18
+ clearTimeout(timeoutId);
19
+ const memoryResult = jobResults.get(job.id);
20
+ if (memoryResult?.resolved) {
21
+ return memoryResult.result !== undefined
22
+ ? resolve(memoryResult.result)
23
+ : reject(new Error(memoryResult.error || "Unknown error"));
24
+ }
25
+ // Fallback to job result
26
+ resolve(await job.returnvalue);
27
+ }
28
+ else if (state === "failed") {
29
+ clearTimeout(timeoutId);
30
+ const memoryResult = jobResults.get(job.id);
31
+ const errorMsg = memoryResult?.error ||
32
+ (await job.failedReason) ||
33
+ "Unknown error";
34
+ reject(new Error(`Job failed: ${errorMsg}`));
35
+ }
36
+ else {
37
+ timeoutId = setTimeout(checkJob, checkCount < 10 ? 50 : 100);
38
+ }
39
+ }
40
+ catch (error) {
41
+ clearTimeout(timeoutId);
42
+ reject(new Error(`Error checking job: ${error.message}`));
43
+ }
44
+ };
45
+ checkJob();
46
+ // Backup timeout
47
+ setTimeout(() => {
48
+ clearTimeout(timeoutId);
49
+ reject(new Error("Request timeout: Maximum wait time exceeded"));
50
+ }, 60000);
51
+ });
52
+ }
53
+ static extractConnectionDetails(options) {
54
+ const { connectionId, connectionProvider: provider, microservice, } = options?.queueOptions ?? {};
55
+ if (!connectionId)
56
+ throw new Error("Connection ID not found in options");
57
+ if (!provider)
58
+ throw new Error("Connection provider not found in options");
59
+ if (!microservice)
60
+ throw new Error("Microservice not found in options");
61
+ return { connectionId, provider, microservice };
62
+ }
63
+ }
64
+ exports.JobUtils = JobUtils;
@@ -0,0 +1,5 @@
1
+ export declare class QueueUtils {
2
+ static getQueueKey(microservice: string, connectionId: string, provider: string): string;
3
+ static getOrCreateQueue(queueKey: string, queues: Map<string, any>): any;
4
+ static getOrCreateWorker(queueKey: string, workers: Map<string, any>, processFunction: (job: any) => Promise<any>, jobResults: Map<string, any>): void;
5
+ }