dt-common-device 13.0.22 → 13.0.23

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 (166) hide show
  1. package/dist/admin/Admin.repository.d.ts +7 -0
  2. package/dist/admin/Admin.service.d.ts +5 -0
  3. package/dist/admin/index.d.ts +1 -0
  4. package/dist/alerts/AlertBuilder.example.d.ts +11 -0
  5. package/dist/alerts/AlertService.example.d.ts +55 -0
  6. package/dist/audit/AuditProperties.d.ts +16 -0
  7. package/dist/chronicle/Cronicle.service.d.ts +9 -0
  8. package/dist/chronicle/IChronicle.interface.d.ts +14 -0
  9. package/dist/chronicle/ICronicle.interface.d.ts +15 -0
  10. package/dist/chronicle/chronicle.service.d.ts +4 -0
  11. package/dist/chronicle/index.d.ts +2 -0
  12. package/dist/connection/Connection.repository.d.ts +8 -0
  13. package/dist/connection/Connection.service.d.ts +8 -0
  14. package/dist/connection/IConnection.d.ts +28 -0
  15. package/dist/connection/index.d.ts +2 -0
  16. package/dist/constants/ConnectionProviders.d.ts +1 -0
  17. package/dist/constants/ConnectionProviders.js +1 -0
  18. package/dist/copilotQueue/examples/CopilotQueue.example.d.ts +37 -0
  19. package/dist/copilotQueue/examples/index.d.ts +1 -0
  20. package/dist/device/cloud/entities/CloudConnection.d.ts +6 -0
  21. package/dist/device/cloud/entities/CloudDevice.d.ts +16 -0
  22. package/dist/device/cloud/entities/CloudDeviceService.d.ts +5 -0
  23. package/dist/device/cloud/entities/DeviceFactory.d.ts +7 -0
  24. package/dist/device/cloud/entities/index.d.ts +3 -0
  25. package/dist/device/cloud/interface.d.ts +101 -0
  26. package/dist/device/cloud/interfaces/ICloudConnection.d.ts +5 -0
  27. package/dist/device/cloud/interfaces/ICloudDevice.d.ts +9 -0
  28. package/dist/device/cloud/interfaces/ICloudDeviceService.d.ts +4 -0
  29. package/dist/device/cloud/interfaces/IConnectionService.d.ts +7 -0
  30. package/dist/device/cloud/interfaces/IDeviceConnectionService.d.ts +7 -0
  31. package/dist/device/cloud/interfaces/IDeviceFactory.d.ts +4 -0
  32. package/dist/device/cloud/interfaces/IDeviceService.d.ts +8 -0
  33. package/dist/device/cloud/interfaces/IDevicesService.d.ts +9 -0
  34. package/dist/device/cloud/interfaces/IHubService.d.ts +5 -0
  35. package/dist/device/cloud/interfaces/IRawDataTransformer.d.ts +4 -0
  36. package/dist/device/cloud/interfaces/IRawDevice.d.ts +17 -0
  37. package/dist/device/cloud/interfaces/index.d.ts +5 -0
  38. package/dist/device/cloud/services/CloudDevice.service.d.ts +5 -0
  39. package/dist/device/cloud/services/Connection.service.d.ts +8 -0
  40. package/dist/device/cloud/services/Device.service.d.ts +39 -0
  41. package/dist/device/cloud/services/DeviceCloudService.d.ts +42 -0
  42. package/dist/device/cloud/services/DeviceHub.service.d.ts +3 -0
  43. package/dist/device/cloud/services/Hub.service.d.ts +25 -0
  44. package/dist/device/cloud/services/SmartThingsDeviceService.d.ts +38 -0
  45. package/dist/device/cloud/services/SmartThingsDeviceService.js +52 -0
  46. package/dist/device/cloud/services/index.d.ts +2 -0
  47. package/dist/device/cloud/types.d.ts +52 -0
  48. package/dist/device/cloud/types.js +15 -0
  49. package/dist/device/index.d.ts +4 -0
  50. package/dist/device/local/entities/AlertBuilder.d.ts +87 -0
  51. package/dist/device/local/entities/AlertBuilder.example.d.ts +11 -0
  52. package/dist/device/local/entities/IssueBuilder.d.ts +109 -0
  53. package/dist/device/local/entities/IssueBuilder.example.d.ts +16 -0
  54. package/dist/device/local/entities/IssueBuilder.example.js +196 -0
  55. package/dist/device/local/entities/IssueBuilder.js +237 -0
  56. package/dist/device/local/entities/index.d.ts +2 -0
  57. package/dist/device/local/events/EventHandler.d.ts +11 -0
  58. package/dist/device/local/events/Events.d.ts +54 -0
  59. package/dist/device/local/events/index.d.ts +2 -0
  60. package/dist/device/local/handler/EventHandler.d.ts +7 -0
  61. package/dist/device/local/interface.d.ts +0 -0
  62. package/dist/device/local/interfaces/IConnection.d.ts +26 -0
  63. package/dist/device/local/interfaces/IDevice.d.ts +68 -0
  64. package/dist/device/local/interfaces/IDtDevice.d.ts +16 -0
  65. package/dist/device/local/interfaces/IHub.d.ts +46 -0
  66. package/dist/device/local/interfaces/IProperty.d.ts +29 -0
  67. package/dist/device/local/interfaces/ISchedule.d.ts +25 -0
  68. package/dist/device/local/interfaces/index.d.ts +3 -0
  69. package/dist/device/local/models/Alert.model.d.ts +28 -0
  70. package/dist/device/local/models/Issue.model.d.ts +28 -0
  71. package/dist/device/local/repository/Alert.repository.d.ts +106 -0
  72. package/dist/device/local/repository/Connection.repository.d.ts +8 -0
  73. package/dist/device/local/repository/Device.repository.d.ts +30 -0
  74. package/dist/device/local/repository/Hub.repository.d.ts +13 -0
  75. package/dist/device/local/repository/Issue.repository.d.ts +113 -0
  76. package/dist/device/local/repository/Property.repository.d.ts +8 -0
  77. package/dist/device/local/repository/Property.repository.js +95 -0
  78. package/dist/device/local/repository/Schedule.repository.d.ts +9 -0
  79. package/dist/device/local/repository/Schedule.repository.js +109 -0
  80. package/dist/device/local/services/Alert.service.d.ts +137 -0
  81. package/dist/device/local/services/AlertService.example.d.ts +55 -0
  82. package/dist/device/local/services/Connection.service.d.ts +8 -0
  83. package/dist/device/local/services/Device.service.d.ts +40 -0
  84. package/dist/device/local/services/DeviceHub.service.d.ts +11 -0
  85. package/dist/device/local/services/Hub.service.d.ts +12 -0
  86. package/dist/device/local/services/Issue.service.d.ts +168 -0
  87. package/dist/device/local/services/Issue.service.js +642 -0
  88. package/dist/device/local/services/IssueService.example.d.ts +68 -0
  89. package/dist/device/local/services/IssueService.example.js +177 -0
  90. package/dist/device/local/services/Property.service.d.ts +8 -0
  91. package/dist/device/local/services/Property.service.js +36 -0
  92. package/dist/device/local/services/Schedule.service.d.ts +9 -0
  93. package/dist/device/local/services/Schedule.service.js +26 -0
  94. package/dist/device/local/services/index.d.ts +3 -0
  95. package/dist/entities/accessGroup/AccessGroup.repository.d.ts +5 -0
  96. package/dist/entities/accessGroup/AccessGroup.service.d.ts +5 -0
  97. package/dist/entities/accessGroup/IAccessGroup.d.ts +14 -0
  98. package/dist/entities/accessGroup/index.d.ts +2 -0
  99. package/dist/entities/device/local/repository/DeviceProfile.repository.d.ts +5 -0
  100. package/dist/entities/guest/Guest.repository.d.ts +6 -0
  101. package/dist/entities/guest/Guest.service.d.ts +6 -0
  102. package/dist/entities/guest/IGuest.d.ts +12 -0
  103. package/dist/entities/guest/index.d.ts +2 -0
  104. package/dist/entities/schedules/ISchedule.d.ts +14 -0
  105. package/dist/entities/schedules/Schedule.repository.d.ts +6 -0
  106. package/dist/entities/schedules/Schedule.repository.js +74 -0
  107. package/dist/entities/schedules/Schedule.service.d.ts +6 -0
  108. package/dist/entities/schedules/Schedule.service.js +104 -0
  109. package/dist/entities/schedules/index.d.ts +2 -0
  110. package/dist/entities/user/IUser.d.ts +15 -0
  111. package/dist/entities/user/IUser.js +2 -0
  112. package/dist/entities/user/User.repository.d.ts +5 -0
  113. package/dist/entities/user/User.repository.js +68 -0
  114. package/dist/entities/user/User.service.d.ts +6 -0
  115. package/dist/entities/user/User.service.js +103 -0
  116. package/dist/entities/zone/IZone.d.ts +10 -0
  117. package/dist/entities/zone/IZone.js +2 -0
  118. package/dist/entities/zone/Zone.repository.d.ts +6 -0
  119. package/dist/entities/zone/Zone.repository.js +77 -0
  120. package/dist/entities/zone/Zone.service.d.ts +6 -0
  121. package/dist/entities/zone/Zone.service.js +104 -0
  122. package/dist/entities/zone/index.d.ts +2 -0
  123. package/dist/issues/IssueBuilder.example.d.ts +16 -0
  124. package/dist/issues/IssueBuilder.example.js +196 -0
  125. package/dist/issues/IssueService.example.d.ts +68 -0
  126. package/dist/issues/IssueService.example.js +292 -0
  127. package/dist/pms/IPms.d.ts +6 -0
  128. package/dist/pms/index.d.ts +1 -0
  129. package/dist/pms/webhookQueue/examples/index.d.ts +2 -0
  130. package/dist/pms/webhookQueue/examples/pms-integration.d.ts +65 -0
  131. package/dist/pms/webhookQueue/examples/pms-integration.js +254 -0
  132. package/dist/pms/webhookQueue/examples/usage.d.ts +7 -0
  133. package/dist/pms/webhookQueue/examples/usage.js +175 -0
  134. package/dist/pms/webhookQueue/index.d.ts +3 -0
  135. package/dist/pms/webhookQueue/interfaces/IWebhookQueue.d.ts +33 -0
  136. package/dist/pms/webhookQueue/interfaces/IWebhookQueue.js +2 -0
  137. package/dist/pms/webhookQueue/interfaces/IWebhookWorker.d.ts +38 -0
  138. package/dist/pms/webhookQueue/interfaces/IWebhookWorker.js +2 -0
  139. package/dist/pms/webhookQueue/interfaces/index.d.ts +1 -0
  140. package/dist/pms/webhookQueue/services/WebhookQueueFactory.d.ts +38 -0
  141. package/dist/pms/webhookQueue/services/WebhookQueueFactory.js +131 -0
  142. package/dist/pms/webhookQueue/services/WebhookQueueIntegration.d.ts +70 -0
  143. package/dist/pms/webhookQueue/services/WebhookQueueIntegration.js +207 -0
  144. package/dist/pms/webhookQueue/services/WebhookQueueService.d.ts +45 -0
  145. package/dist/pms/webhookQueue/services/WebhookQueueService.js +270 -0
  146. package/dist/pms/webhookQueue/services/WebhookWorker.d.ts +37 -0
  147. package/dist/pms/webhookQueue/services/WebhookWorker.js +201 -0
  148. package/dist/pms/webhookQueue/services/index.d.ts +1 -0
  149. package/dist/pms/webhookQueue/types/index.d.ts +1 -0
  150. package/dist/pms/webhookQueue/types/webhook.types.d.ts +39 -0
  151. package/dist/pms/webhookQueue/types/webhook.types.js +2 -0
  152. package/dist/property/IProperty.d.ts +29 -0
  153. package/dist/property/Property.repository.d.ts +8 -0
  154. package/dist/property/Property.repository.js +109 -0
  155. package/dist/property/Property.service.d.ts +8 -0
  156. package/dist/property/Property.service.js +124 -0
  157. package/dist/property/index.d.ts +2 -0
  158. package/dist/queue/interfaces/IHttpRequestJob.d.ts +9 -0
  159. package/dist/queue/utils/rateLimit.utils.js +7 -1
  160. package/dist/types/alert.types.d.ts +57 -0
  161. package/dist/types/config.types.d.ts +19 -0
  162. package/dist/types/index.d.ts +3 -0
  163. package/dist/types/issue.types.d.ts +90 -0
  164. package/dist/types/issue.types.js +40 -0
  165. package/dist/utils/http-utils.d.ts +13 -0
  166. package/package.json +1 -1
@@ -0,0 +1,131 @@
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.WebhookQueueFactory = void 0;
42
+ const typedi_1 = require("typedi");
43
+ const WebhookQueueService_1 = require("./WebhookQueueService");
44
+ let WebhookQueueFactory = (() => {
45
+ let _classDecorators = [(0, typedi_1.Service)()];
46
+ let _classDescriptor;
47
+ let _classExtraInitializers = [];
48
+ let _classThis;
49
+ var WebhookQueueFactory = _classThis = class {
50
+ /**
51
+ * Create or get a webhook queue service instance
52
+ * @param config Configuration for the webhook queue
53
+ * @param instanceKey Optional key to identify different instances
54
+ * @returns WebhookQueueService instance
55
+ */
56
+ static createWebhookQueue(config, instanceKey = "default") {
57
+ const key = `${config.redisHost}:${config.redisPort}:${instanceKey}`;
58
+ if (!this.instances.has(key)) {
59
+ const instance = new WebhookQueueService_1.WebhookQueueService(config);
60
+ this.instances.set(key, instance);
61
+ }
62
+ return this.instances.get(key);
63
+ }
64
+ /**
65
+ * Get an existing webhook queue service instance
66
+ * @param instanceKey Key to identify the instance
67
+ * @returns WebhookQueueService instance or null if not found
68
+ */
69
+ static getWebhookQueue(instanceKey = "default") {
70
+ for (const [key, instance] of this.instances) {
71
+ if (key.includes(instanceKey)) {
72
+ return instance;
73
+ }
74
+ }
75
+ return null;
76
+ }
77
+ /**
78
+ * Get all webhook queue service instances
79
+ * @returns Array of all WebhookQueueService instances
80
+ */
81
+ static getAllWebhookQueues() {
82
+ return Array.from(this.instances.values());
83
+ }
84
+ /**
85
+ * Shutdown all webhook queue service instances
86
+ */
87
+ static async shutdownAll() {
88
+ const shutdownPromises = Array.from(this.instances.values()).map((instance) => instance.shutdown());
89
+ await Promise.all(shutdownPromises);
90
+ this.instances.clear();
91
+ }
92
+ /**
93
+ * Check if a webhook queue service instance exists
94
+ * @param instanceKey Key to identify the instance
95
+ * @returns True if instance exists, false otherwise
96
+ */
97
+ static hasWebhookQueue(instanceKey = "default") {
98
+ return this.getWebhookQueue(instanceKey) !== null;
99
+ }
100
+ /**
101
+ * Remove a webhook queue service instance
102
+ * @param instanceKey Key to identify the instance
103
+ */
104
+ static async removeWebhookQueue(instanceKey = "default") {
105
+ const instance = this.getWebhookQueue(instanceKey);
106
+ if (instance) {
107
+ await instance.shutdown();
108
+ // Remove from instances map
109
+ for (const [key, inst] of this.instances) {
110
+ if (key.includes(instanceKey)) {
111
+ this.instances.delete(key);
112
+ break;
113
+ }
114
+ }
115
+ }
116
+ }
117
+ };
118
+ __setFunctionName(_classThis, "WebhookQueueFactory");
119
+ (() => {
120
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
121
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
122
+ WebhookQueueFactory = _classThis = _classDescriptor.value;
123
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
124
+ })();
125
+ _classThis.instances = new Map();
126
+ (() => {
127
+ __runInitializers(_classThis, _classExtraInitializers);
128
+ })();
129
+ return WebhookQueueFactory = _classThis;
130
+ })();
131
+ exports.WebhookQueueFactory = WebhookQueueFactory;
@@ -0,0 +1,70 @@
1
+ import { IWebhookQueue } from "../interfaces";
2
+ import { IWebhookQueueConfig } from "../types/webhook.types";
3
+ /**
4
+ * Integration service that provides a simple interface for using webhook queues
5
+ * in existing PMS services without major refactoring
6
+ */
7
+ export declare class WebhookQueueIntegration {
8
+ private webhookQueue;
9
+ private isInitialized;
10
+ /**
11
+ * Initialize the webhook queue system
12
+ * @param config Configuration for the webhook queue
13
+ * @param webhookProcessor Function to process webhooks
14
+ */
15
+ initialize(config: IWebhookQueueConfig, webhookProcessor: (webhookData: any, pmsType: string) => Promise<any>): Promise<void>;
16
+ /**
17
+ * Queue a webhook for processing
18
+ * @param propertyId Property ID
19
+ * @param pmsType PMS type
20
+ * @param webhookData Webhook payload
21
+ * @returns Job ID
22
+ */
23
+ queueWebhook(propertyId: string, pmsType: string, webhookData: any): Promise<string>;
24
+ /**
25
+ * Get queue status for monitoring
26
+ * @param propertyId Property ID
27
+ * @param pmsType PMS type
28
+ */
29
+ getQueueStatus(propertyId: string, pmsType: string): Promise<import("../types/webhook.types").IWebhookQueueStatus>;
30
+ /**
31
+ * Get all queue statuses for a property
32
+ * @param propertyId Property ID
33
+ */
34
+ getAllQueueStatuses(propertyId: string): Promise<Record<string, import("../types/webhook.types").IWebhookQueueStatus>>;
35
+ /**
36
+ * Check if webhook queue integration is initialized
37
+ */
38
+ isReady(): boolean;
39
+ /**
40
+ * Shutdown the webhook queue system
41
+ */
42
+ shutdown(): Promise<void>;
43
+ /**
44
+ * Get the underlying webhook queue service
45
+ */
46
+ getWebhookQueue(): IWebhookQueue | null;
47
+ /**
48
+ * Default webhook processor that can be overridden
49
+ */
50
+ private getDefaultWebhookProcessor;
51
+ /**
52
+ * Set a custom webhook processor for a specific queue
53
+ * @param propertyId Property ID
54
+ * @param pmsType PMS type
55
+ * @param processor Custom processor function
56
+ */
57
+ setCustomProcessor(propertyId: string, pmsType: string, processor: (webhookData: any, pmsType: string) => Promise<any>): Promise<void>;
58
+ /**
59
+ * Clean up old jobs from a queue
60
+ * @param propertyId Property ID
61
+ * @param pmsType PMS type
62
+ */
63
+ cleanupQueue(propertyId: string, pmsType: string): Promise<void>;
64
+ /**
65
+ * Get queue metrics for monitoring
66
+ * @param propertyId Property ID
67
+ * @param pmsType PMS type
68
+ */
69
+ getQueueMetrics(propertyId: string, pmsType: string): Promise<import("../types/webhook.types").IWebhookQueueMetrics>;
70
+ }
@@ -0,0 +1,207 @@
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.WebhookQueueIntegration = void 0;
42
+ const typedi_1 = require("typedi");
43
+ const WebhookQueueFactory_1 = require("../services/WebhookQueueFactory");
44
+ /**
45
+ * Integration service that provides a simple interface for using webhook queues
46
+ * in existing PMS services without major refactoring
47
+ */
48
+ let WebhookQueueIntegration = (() => {
49
+ let _classDecorators = [(0, typedi_1.Service)()];
50
+ let _classDescriptor;
51
+ let _classExtraInitializers = [];
52
+ let _classThis;
53
+ var WebhookQueueIntegration = _classThis = class {
54
+ constructor() {
55
+ this.webhookQueue = null;
56
+ this.isInitialized = false;
57
+ }
58
+ /**
59
+ * Initialize the webhook queue system
60
+ * @param config Configuration for the webhook queue
61
+ * @param webhookProcessor Function to process webhooks
62
+ */
63
+ async initialize(config, webhookProcessor) {
64
+ if (this.isInitialized) {
65
+ return;
66
+ }
67
+ try {
68
+ // Create webhook queue service
69
+ this.webhookQueue = WebhookQueueFactory_1.WebhookQueueFactory.createWebhookQueue(config);
70
+ // Set webhook processor for all PMS types
71
+ const pmsTypes = ["CLOUDBEDS", "HOTELKEY", "STAYNTOUCH"];
72
+ // Note: We'll set processors when specific queues are created
73
+ // This is a placeholder for now
74
+ this.isInitialized = true;
75
+ console.log("Webhook queue integration initialized successfully");
76
+ }
77
+ catch (error) {
78
+ console.error("Failed to initialize webhook queue integration:", error);
79
+ throw error;
80
+ }
81
+ }
82
+ /**
83
+ * Queue a webhook for processing
84
+ * @param propertyId Property ID
85
+ * @param pmsType PMS type
86
+ * @param webhookData Webhook payload
87
+ * @returns Job ID
88
+ */
89
+ async queueWebhook(propertyId, pmsType, webhookData) {
90
+ if (!this.isInitialized || !this.webhookQueue) {
91
+ throw new Error("Webhook queue integration not initialized");
92
+ }
93
+ try {
94
+ // Set webhook processor for this specific queue if not already set
95
+ await this.webhookQueue.setWebhookProcessor(propertyId, pmsType, this.getDefaultWebhookProcessor());
96
+ // Add webhook to queue
97
+ const jobId = await this.webhookQueue.addWebhookToQueue(propertyId, pmsType, webhookData);
98
+ console.log(`Webhook queued successfully for property: ${propertyId}, PMS: ${pmsType}, Job ID: ${jobId}`);
99
+ return jobId;
100
+ }
101
+ catch (error) {
102
+ console.error(`Failed to queue webhook for property: ${propertyId}, PMS: ${pmsType}:`, error);
103
+ throw error;
104
+ }
105
+ }
106
+ /**
107
+ * Get queue status for monitoring
108
+ * @param propertyId Property ID
109
+ * @param pmsType PMS type
110
+ */
111
+ async getQueueStatus(propertyId, pmsType) {
112
+ if (!this.isInitialized || !this.webhookQueue) {
113
+ throw new Error("Webhook queue integration not initialized");
114
+ }
115
+ return await this.webhookQueue.getQueueStatus(propertyId, pmsType);
116
+ }
117
+ /**
118
+ * Get all queue statuses for a property
119
+ * @param propertyId Property ID
120
+ */
121
+ async getAllQueueStatuses(propertyId) {
122
+ if (!this.isInitialized || !this.webhookQueue) {
123
+ throw new Error("Webhook queue integration not initialized");
124
+ }
125
+ return await this.webhookQueue.getAllPropertyQueueStatuses(propertyId);
126
+ }
127
+ /**
128
+ * Check if webhook queue integration is initialized
129
+ */
130
+ isReady() {
131
+ return this.isInitialized && this.webhookQueue !== null;
132
+ }
133
+ /**
134
+ * Shutdown the webhook queue system
135
+ */
136
+ async shutdown() {
137
+ if (this.isInitialized) {
138
+ await WebhookQueueFactory_1.WebhookQueueFactory.shutdownAll();
139
+ this.isInitialized = false;
140
+ this.webhookQueue = null;
141
+ console.log("Webhook queue integration shutdown successfully");
142
+ }
143
+ }
144
+ /**
145
+ * Get the underlying webhook queue service
146
+ */
147
+ getWebhookQueue() {
148
+ return this.webhookQueue;
149
+ }
150
+ /**
151
+ * Default webhook processor that can be overridden
152
+ */
153
+ getDefaultWebhookProcessor() {
154
+ return async (webhookData, pmsType) => {
155
+ console.log(`[Default Processor] Processing webhook for PMS: ${pmsType}`);
156
+ console.log("Webhook data:", webhookData);
157
+ // This should be overridden with actual processing logic
158
+ // For now, just return success
159
+ return { success: true, processedAt: new Date().toISOString() };
160
+ };
161
+ }
162
+ /**
163
+ * Set a custom webhook processor for a specific queue
164
+ * @param propertyId Property ID
165
+ * @param pmsType PMS type
166
+ * @param processor Custom processor function
167
+ */
168
+ async setCustomProcessor(propertyId, pmsType, processor) {
169
+ if (!this.isInitialized || !this.webhookQueue) {
170
+ throw new Error("Webhook queue integration not initialized");
171
+ }
172
+ await this.webhookQueue.setWebhookProcessor(propertyId, pmsType, processor);
173
+ }
174
+ /**
175
+ * Clean up old jobs from a queue
176
+ * @param propertyId Property ID
177
+ * @param pmsType PMS type
178
+ */
179
+ async cleanupQueue(propertyId, pmsType) {
180
+ if (!this.isInitialized || !this.webhookQueue) {
181
+ throw new Error("Webhook queue integration not initialized");
182
+ }
183
+ await this.webhookQueue.cleanupQueue(propertyId, pmsType);
184
+ }
185
+ /**
186
+ * Get queue metrics for monitoring
187
+ * @param propertyId Property ID
188
+ * @param pmsType PMS type
189
+ */
190
+ async getQueueMetrics(propertyId, pmsType) {
191
+ if (!this.isInitialized || !this.webhookQueue) {
192
+ throw new Error("Webhook queue integration not initialized");
193
+ }
194
+ return await this.webhookQueue.getQueueMetrics(propertyId, pmsType);
195
+ }
196
+ };
197
+ __setFunctionName(_classThis, "WebhookQueueIntegration");
198
+ (() => {
199
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
200
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
201
+ WebhookQueueIntegration = _classThis = _classDescriptor.value;
202
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
203
+ __runInitializers(_classThis, _classExtraInitializers);
204
+ })();
205
+ return WebhookQueueIntegration = _classThis;
206
+ })();
207
+ exports.WebhookQueueIntegration = WebhookQueueIntegration;
@@ -0,0 +1,45 @@
1
+ import { IWebhookQueue } from "../interfaces/IWebhookQueue";
2
+ import { IWebhookQueueOptions } from "../types/webhook.types";
3
+ export declare class WebhookQueueService implements IWebhookQueue {
4
+ private readonly webhookQueues;
5
+ /**
6
+ * Generate queue name based on propertyId and pmsType
7
+ * Format: propertyId_pmsType_webhook
8
+ */
9
+ private generateQueueName;
10
+ /**
11
+ * Add a webhook to the appropriate queue based on propertyId and pmsType
12
+ * Creates queue if it doesn't exist
13
+ */
14
+ addWebhookToQueue(propertyId: string, pmsType: string, webhookData: any, options?: IWebhookQueueOptions): Promise<string>;
15
+ /**
16
+ * Mark a webhook job as completed (processed successfully)
17
+ * Note: Jobs are now removed immediately when polled, so this method is for logging purposes
18
+ */
19
+ markWebhookCompleted(propertyId: string, pmsType: string, jobId: string): Promise<void>;
20
+ /**
21
+ * Mark a webhook job as failed
22
+ * Note: Jobs are now removed immediately when polled, so this method is for logging purposes
23
+ */
24
+ markWebhookFailed(propertyId: string, pmsType: string, jobId: string, error?: string): Promise<void>;
25
+ /**
26
+ * Poll available webhook from ANY available webhook queue in Redis
27
+ * This method will discover all queues in Redis and filter only webhook queues
28
+ */
29
+ pollWebhookFromQueues(): Promise<{
30
+ jobId: string;
31
+ data: any;
32
+ propertyId: string;
33
+ pmsType: string;
34
+ queueName: string;
35
+ } | null>;
36
+ /**
37
+ * Get all available webhook queue names from Redis
38
+ */
39
+ getAllQueueNames(): Promise<string[]>;
40
+ /**
41
+ * Get total waiting count across all webhook queues
42
+ */
43
+ getTotalWaitingCount(): Promise<number>;
44
+ static getOrCreateQueue(queueKey: string, queues: Map<string, any>): Promise<any>;
45
+ }