dt-common-device 13.1.5 → 13.1.7

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 (167) hide show
  1. package/dist/events/BaseEventTransformer.d.ts +1 -0
  2. package/dist/events/DeviceEventTransformerFactory.d.ts +1 -1
  3. package/dist/events/DeviceEventTransformerFactory.js +13 -1
  4. package/dist/events/interfaces/IEventTransformer.d.ts +1 -0
  5. package/package.json +1 -1
  6. package/dist/admin/Admin.repository.d.ts +0 -7
  7. package/dist/admin/Admin.service.d.ts +0 -5
  8. package/dist/admin/index.d.ts +0 -1
  9. package/dist/alerts/AlertBuilder.example.d.ts +0 -11
  10. package/dist/alerts/AlertService.example.d.ts +0 -55
  11. package/dist/audit/AuditProperties.d.ts +0 -16
  12. package/dist/chronicle/Cronicle.service.d.ts +0 -9
  13. package/dist/chronicle/IChronicle.interface.d.ts +0 -14
  14. package/dist/chronicle/ICronicle.interface.d.ts +0 -15
  15. package/dist/chronicle/chronicle.service.d.ts +0 -4
  16. package/dist/chronicle/index.d.ts +0 -2
  17. package/dist/connection/Connection.repository.d.ts +0 -8
  18. package/dist/connection/Connection.service.d.ts +0 -8
  19. package/dist/connection/IConnection.d.ts +0 -28
  20. package/dist/connection/index.d.ts +0 -2
  21. package/dist/copilotQueue/examples/CopilotQueue.example.d.ts +0 -37
  22. package/dist/copilotQueue/examples/index.d.ts +0 -1
  23. package/dist/device/cloud/entities/CloudConnection.d.ts +0 -6
  24. package/dist/device/cloud/entities/CloudDevice.d.ts +0 -16
  25. package/dist/device/cloud/entities/CloudDeviceService.d.ts +0 -5
  26. package/dist/device/cloud/entities/DeviceFactory.d.ts +0 -7
  27. package/dist/device/cloud/entities/index.d.ts +0 -3
  28. package/dist/device/cloud/interface.d.ts +0 -101
  29. package/dist/device/cloud/interfaces/ICloudConnection.d.ts +0 -5
  30. package/dist/device/cloud/interfaces/ICloudDevice.d.ts +0 -9
  31. package/dist/device/cloud/interfaces/ICloudDeviceService.d.ts +0 -4
  32. package/dist/device/cloud/interfaces/IConnectionService.d.ts +0 -7
  33. package/dist/device/cloud/interfaces/IDeviceConnectionService.d.ts +0 -7
  34. package/dist/device/cloud/interfaces/IDeviceFactory.d.ts +0 -4
  35. package/dist/device/cloud/interfaces/IDeviceService.d.ts +0 -8
  36. package/dist/device/cloud/interfaces/IDevicesService.d.ts +0 -9
  37. package/dist/device/cloud/interfaces/IHubService.d.ts +0 -5
  38. package/dist/device/cloud/interfaces/IRawDataTransformer.d.ts +0 -4
  39. package/dist/device/cloud/interfaces/IRawDevice.d.ts +0 -17
  40. package/dist/device/cloud/interfaces/index.d.ts +0 -5
  41. package/dist/device/cloud/services/CloudDevice.service.d.ts +0 -5
  42. package/dist/device/cloud/services/Connection.service.d.ts +0 -8
  43. package/dist/device/cloud/services/Device.service.d.ts +0 -39
  44. package/dist/device/cloud/services/DeviceCloudService.d.ts +0 -42
  45. package/dist/device/cloud/services/DeviceHub.service.d.ts +0 -3
  46. package/dist/device/cloud/services/Hub.service.d.ts +0 -25
  47. package/dist/device/cloud/services/SmartThingsDeviceService.d.ts +0 -38
  48. package/dist/device/cloud/services/SmartThingsDeviceService.js +0 -52
  49. package/dist/device/cloud/services/index.d.ts +0 -2
  50. package/dist/device/cloud/types.d.ts +0 -52
  51. package/dist/device/cloud/types.js +0 -15
  52. package/dist/device/index.d.ts +0 -4
  53. package/dist/device/local/entities/AlertBuilder.d.ts +0 -87
  54. package/dist/device/local/entities/AlertBuilder.example.d.ts +0 -11
  55. package/dist/device/local/entities/IssueBuilder.d.ts +0 -109
  56. package/dist/device/local/entities/IssueBuilder.example.d.ts +0 -16
  57. package/dist/device/local/entities/IssueBuilder.example.js +0 -196
  58. package/dist/device/local/entities/IssueBuilder.js +0 -237
  59. package/dist/device/local/entities/index.d.ts +0 -2
  60. package/dist/device/local/events/EventHandler.d.ts +0 -11
  61. package/dist/device/local/events/Events.d.ts +0 -54
  62. package/dist/device/local/events/index.d.ts +0 -2
  63. package/dist/device/local/handler/EventHandler.d.ts +0 -7
  64. package/dist/device/local/interface.d.ts +0 -0
  65. package/dist/device/local/interfaces/IConnection.d.ts +0 -26
  66. package/dist/device/local/interfaces/IDevice.d.ts +0 -68
  67. package/dist/device/local/interfaces/IDtDevice.d.ts +0 -16
  68. package/dist/device/local/interfaces/IHub.d.ts +0 -46
  69. package/dist/device/local/interfaces/IProperty.d.ts +0 -29
  70. package/dist/device/local/interfaces/ISchedule.d.ts +0 -25
  71. package/dist/device/local/interfaces/index.d.ts +0 -3
  72. package/dist/device/local/models/Alert.model.d.ts +0 -28
  73. package/dist/device/local/models/Issue.model.d.ts +0 -28
  74. package/dist/device/local/repository/Alert.repository.d.ts +0 -106
  75. package/dist/device/local/repository/Connection.repository.d.ts +0 -8
  76. package/dist/device/local/repository/Device.repository.d.ts +0 -30
  77. package/dist/device/local/repository/Hub.repository.d.ts +0 -13
  78. package/dist/device/local/repository/Issue.repository.d.ts +0 -113
  79. package/dist/device/local/repository/Property.repository.d.ts +0 -8
  80. package/dist/device/local/repository/Property.repository.js +0 -95
  81. package/dist/device/local/repository/Schedule.repository.d.ts +0 -9
  82. package/dist/device/local/repository/Schedule.repository.js +0 -109
  83. package/dist/device/local/services/Alert.service.d.ts +0 -137
  84. package/dist/device/local/services/AlertService.example.d.ts +0 -55
  85. package/dist/device/local/services/Connection.service.d.ts +0 -8
  86. package/dist/device/local/services/Device.service.d.ts +0 -40
  87. package/dist/device/local/services/DeviceHub.service.d.ts +0 -11
  88. package/dist/device/local/services/Hub.service.d.ts +0 -12
  89. package/dist/device/local/services/Issue.service.d.ts +0 -168
  90. package/dist/device/local/services/Issue.service.js +0 -642
  91. package/dist/device/local/services/IssueService.example.d.ts +0 -68
  92. package/dist/device/local/services/IssueService.example.js +0 -177
  93. package/dist/device/local/services/Property.service.d.ts +0 -8
  94. package/dist/device/local/services/Property.service.js +0 -36
  95. package/dist/device/local/services/Schedule.service.d.ts +0 -9
  96. package/dist/device/local/services/Schedule.service.js +0 -26
  97. package/dist/device/local/services/index.d.ts +0 -3
  98. package/dist/entities/accessGroup/AccessGroup.repository.d.ts +0 -5
  99. package/dist/entities/accessGroup/AccessGroup.service.d.ts +0 -5
  100. package/dist/entities/accessGroup/IAccessGroup.d.ts +0 -14
  101. package/dist/entities/accessGroup/index.d.ts +0 -2
  102. package/dist/entities/device/local/repository/DeviceProfile.repository.d.ts +0 -5
  103. package/dist/entities/guest/Guest.repository.d.ts +0 -6
  104. package/dist/entities/guest/Guest.service.d.ts +0 -6
  105. package/dist/entities/guest/IGuest.d.ts +0 -12
  106. package/dist/entities/guest/index.d.ts +0 -2
  107. package/dist/entities/schedules/ISchedule.d.ts +0 -14
  108. package/dist/entities/schedules/Schedule.repository.d.ts +0 -6
  109. package/dist/entities/schedules/Schedule.repository.js +0 -74
  110. package/dist/entities/schedules/Schedule.service.d.ts +0 -6
  111. package/dist/entities/schedules/Schedule.service.js +0 -104
  112. package/dist/entities/schedules/index.d.ts +0 -2
  113. package/dist/entities/user/IUser.d.ts +0 -15
  114. package/dist/entities/user/IUser.js +0 -2
  115. package/dist/entities/user/User.repository.d.ts +0 -5
  116. package/dist/entities/user/User.repository.js +0 -68
  117. package/dist/entities/user/User.service.d.ts +0 -6
  118. package/dist/entities/user/User.service.js +0 -103
  119. package/dist/entities/zone/IZone.d.ts +0 -10
  120. package/dist/entities/zone/IZone.js +0 -2
  121. package/dist/entities/zone/Zone.repository.d.ts +0 -6
  122. package/dist/entities/zone/Zone.repository.js +0 -77
  123. package/dist/entities/zone/Zone.service.d.ts +0 -6
  124. package/dist/entities/zone/Zone.service.js +0 -104
  125. package/dist/entities/zone/index.d.ts +0 -2
  126. package/dist/issues/IssueBuilder.example.d.ts +0 -16
  127. package/dist/issues/IssueBuilder.example.js +0 -196
  128. package/dist/issues/IssueService.example.d.ts +0 -68
  129. package/dist/issues/IssueService.example.js +0 -292
  130. package/dist/pms/IPms.d.ts +0 -6
  131. package/dist/pms/index.d.ts +0 -1
  132. package/dist/pms/webhookQueue/examples/index.d.ts +0 -2
  133. package/dist/pms/webhookQueue/examples/pms-integration.d.ts +0 -65
  134. package/dist/pms/webhookQueue/examples/pms-integration.js +0 -254
  135. package/dist/pms/webhookQueue/examples/usage.d.ts +0 -7
  136. package/dist/pms/webhookQueue/examples/usage.js +0 -175
  137. package/dist/pms/webhookQueue/index.d.ts +0 -3
  138. package/dist/pms/webhookQueue/interfaces/IWebhookQueue.d.ts +0 -33
  139. package/dist/pms/webhookQueue/interfaces/IWebhookQueue.js +0 -2
  140. package/dist/pms/webhookQueue/interfaces/IWebhookWorker.d.ts +0 -38
  141. package/dist/pms/webhookQueue/interfaces/IWebhookWorker.js +0 -2
  142. package/dist/pms/webhookQueue/interfaces/index.d.ts +0 -1
  143. package/dist/pms/webhookQueue/services/WebhookQueueFactory.d.ts +0 -38
  144. package/dist/pms/webhookQueue/services/WebhookQueueFactory.js +0 -131
  145. package/dist/pms/webhookQueue/services/WebhookQueueIntegration.d.ts +0 -70
  146. package/dist/pms/webhookQueue/services/WebhookQueueIntegration.js +0 -207
  147. package/dist/pms/webhookQueue/services/WebhookQueueService.d.ts +0 -45
  148. package/dist/pms/webhookQueue/services/WebhookQueueService.js +0 -270
  149. package/dist/pms/webhookQueue/services/WebhookWorker.d.ts +0 -37
  150. package/dist/pms/webhookQueue/services/WebhookWorker.js +0 -201
  151. package/dist/pms/webhookQueue/services/index.d.ts +0 -1
  152. package/dist/pms/webhookQueue/types/index.d.ts +0 -1
  153. package/dist/pms/webhookQueue/types/webhook.types.d.ts +0 -39
  154. package/dist/pms/webhookQueue/types/webhook.types.js +0 -2
  155. package/dist/property/IProperty.d.ts +0 -29
  156. package/dist/property/Property.repository.d.ts +0 -8
  157. package/dist/property/Property.repository.js +0 -109
  158. package/dist/property/Property.service.d.ts +0 -8
  159. package/dist/property/Property.service.js +0 -124
  160. package/dist/property/index.d.ts +0 -2
  161. package/dist/queue/interfaces/IHttpRequestJob.d.ts +0 -9
  162. package/dist/types/alert.types.d.ts +0 -57
  163. package/dist/types/config.types.d.ts +0 -19
  164. package/dist/types/index.d.ts +0 -3
  165. package/dist/types/issue.types.d.ts +0 -90
  166. package/dist/types/issue.types.js +0 -40
  167. package/dist/utils/http-utils.d.ts +0 -13
@@ -1,254 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExamplePmsController = exports.ExamplePmsServiceWithQueue = void 0;
4
- exports.exampleUsage = exampleUsage;
5
- const WebhookQueueIntegration_1 = require("../services/WebhookQueueIntegration");
6
- /**
7
- * Example: How to integrate webhook queue with existing PMS service
8
- *
9
- * This example shows how to modify your existing PMS service to use
10
- * the webhook queue system without major refactoring.
11
- */
12
- // Configuration for the webhook queue
13
- const webhookQueueConfig = {
14
- redisHost: process.env.REDIS_HOST || "localhost",
15
- redisPort: parseInt(process.env.REDIS_PORT || "6379"),
16
- maxRetries: 3,
17
- backoffDelay: 2000,
18
- jobTimeout: 300000, // 5 minutes
19
- removeOnComplete: { age: 3600000, count: 100 }, // 1 hour, max 100
20
- removeOnFail: { age: 7200000, count: 50 }, // 2 hours, max 50
21
- };
22
- // Example: Modified PMS Service with webhook queue integration
23
- class ExamplePmsServiceWithQueue {
24
- constructor() {
25
- this.webhookQueueIntegration = new WebhookQueueIntegration_1.WebhookQueueIntegration();
26
- }
27
- /**
28
- * Initialize the webhook queue system
29
- */
30
- async initializeWebhookQueue() {
31
- try {
32
- // Initialize with your existing webhook processing logic
33
- await this.webhookQueueIntegration.initialize(webhookQueueConfig, this.processWebhook.bind(this) // Bind to existing method
34
- );
35
- console.log("Webhook queue initialized in PMS service");
36
- }
37
- catch (error) {
38
- console.error("Failed to initialize webhook queue:", error);
39
- throw error;
40
- }
41
- }
42
- /**
43
- * Your existing webhook processing method
44
- * This will be called by the queue worker
45
- */
46
- async processWebhook(webhookData, pmsType) {
47
- console.log(`[PMS Service] Processing webhook for PMS: ${pmsType}`);
48
- try {
49
- // Your existing webhook processing logic here
50
- // This could include:
51
- // - Calling handleWebhookEvents
52
- // - Database operations
53
- // - Business logic
54
- // - etc.
55
- // Simulate processing
56
- await this.simulateWebhookProcessing(webhookData, pmsType);
57
- console.log(`[PMS Service] Webhook processed successfully for PMS: ${pmsType}`);
58
- return { success: true, processedAt: new Date().toISOString() };
59
- }
60
- catch (error) {
61
- console.error(`[PMS Service] Error processing webhook for PMS: ${pmsType}:`, error);
62
- throw error;
63
- }
64
- }
65
- /**
66
- * Modified webhook handler that queues webhooks instead of processing directly
67
- */
68
- async handleWebhookWithQueue(webhookData, pmsType, propertyId) {
69
- try {
70
- // Extract propertyId from webhook if not provided
71
- const extractedPropertyId = propertyId || this.extractPropertyIdFromWebhook(webhookData);
72
- if (!extractedPropertyId) {
73
- // Fallback to direct processing if propertyId cannot be extracted
74
- console.warn("Could not extract propertyId, processing webhook directly");
75
- return await this.processWebhook(webhookData, pmsType);
76
- }
77
- // Queue the webhook for processing
78
- const jobId = await this.webhookQueueIntegration.queueWebhook(extractedPropertyId, pmsType, webhookData);
79
- console.log(`Webhook queued successfully with job ID: ${jobId}`);
80
- return jobId;
81
- }
82
- catch (error) {
83
- console.error("Failed to queue webhook:", error);
84
- // Fallback to direct processing
85
- console.log("Falling back to direct webhook processing");
86
- return await this.processWebhook(webhookData, pmsType);
87
- }
88
- }
89
- /**
90
- * Get webhook queue status for monitoring
91
- */
92
- async getWebhookQueueStatus(propertyId, pmsType) {
93
- if (!this.webhookQueueIntegration.isReady()) {
94
- throw new Error("Webhook queue not initialized");
95
- }
96
- return await this.webhookQueueIntegration.getQueueStatus(propertyId, pmsType);
97
- }
98
- /**
99
- * Get all webhook queue statuses for a property
100
- */
101
- async getAllWebhookQueueStatuses(propertyId) {
102
- if (!this.webhookQueueIntegration.isReady()) {
103
- throw new Error("Webhook queue not initialized");
104
- }
105
- return await this.webhookQueueIntegration.getAllQueueStatuses(propertyId);
106
- }
107
- /**
108
- * Clean up old webhook jobs
109
- */
110
- async cleanupWebhookQueues(propertyId) {
111
- if (!this.webhookQueueIntegration.isReady()) {
112
- return;
113
- }
114
- const pmsTypes = ["CLOUDBEDS", "HOTELKEY", "STAYNTOUCH"];
115
- for (const pmsType of pmsTypes) {
116
- try {
117
- await this.webhookQueueIntegration.cleanupQueue(propertyId, pmsType);
118
- console.log(`Cleaned up webhook queue for ${propertyId}_${pmsType}`);
119
- }
120
- catch (error) {
121
- console.error(`Failed to cleanup queue for ${propertyId}_${pmsType}:`, error);
122
- }
123
- }
124
- }
125
- /**
126
- * Shutdown webhook queue system
127
- */
128
- async shutdownWebhookQueue() {
129
- if (this.webhookQueueIntegration.isReady()) {
130
- await this.webhookQueueIntegration.shutdown();
131
- }
132
- }
133
- // Helper methods
134
- extractPropertyIdFromWebhook(webhookData) {
135
- // Implement your logic to extract propertyId from webhook data
136
- // This will depend on how each PMS sends the propertyId
137
- return webhookData.propertyId || webhookData.property_id || null;
138
- }
139
- async simulateWebhookProcessing(webhookData, pmsType) {
140
- // Simulate some processing time
141
- await new Promise((resolve) => setTimeout(resolve, 100));
142
- // Simulate different processing logic based on PMS type
143
- switch (pmsType) {
144
- case "CLOUDBEDS":
145
- console.log("Processing Cloudbeds webhook...");
146
- break;
147
- case "HOTELKEY":
148
- console.log("Processing HotelKey webhook...");
149
- break;
150
- case "STAYNTOUCH":
151
- console.log("Processing StayNTouch webhook...");
152
- break;
153
- default:
154
- console.log("Processing unknown PMS webhook...");
155
- }
156
- }
157
- }
158
- exports.ExamplePmsServiceWithQueue = ExamplePmsServiceWithQueue;
159
- // Example: How to use in your existing controller
160
- class ExamplePmsController {
161
- constructor() {
162
- this.pmsService = new ExamplePmsServiceWithQueue();
163
- }
164
- /**
165
- * Initialize the service (call this when your app starts)
166
- */
167
- async initialize() {
168
- await this.pmsService.initializeWebhookQueue();
169
- }
170
- /**
171
- * Modified webhook endpoint that uses the queue
172
- */
173
- async handleWebhook(payload, pmsType) {
174
- try {
175
- // Try to extract propertyId from the webhook payload
176
- const propertyId = this.extractPropertyIdFromPayload(payload);
177
- if (propertyId) {
178
- // Use the queue system
179
- const jobId = await this.pmsService.handleWebhookWithQueue(payload, pmsType, propertyId);
180
- return {
181
- message: "Webhook queued successfully",
182
- jobId,
183
- propertyId,
184
- pmsType,
185
- };
186
- }
187
- else {
188
- // Fallback to direct processing
189
- console.warn("PropertyId not found, processing webhook directly");
190
- return await this.pmsService.processWebhook(payload, pmsType);
191
- }
192
- }
193
- catch (error) {
194
- console.error("Error handling webhook:", error);
195
- throw error;
196
- }
197
- }
198
- /**
199
- * Get webhook queue status
200
- */
201
- async getWebhookQueueStatus(propertyId, pmsType) {
202
- return await this.pmsService.getWebhookQueueStatus(propertyId, pmsType);
203
- }
204
- /**
205
- * Get all webhook queue statuses for a property
206
- */
207
- async getAllWebhookQueueStatuses(propertyId) {
208
- return await this.pmsService.getAllWebhookQueueStatuses(propertyId);
209
- }
210
- /**
211
- * Cleanup webhook queues
212
- */
213
- async cleanupWebhookQueues(propertyId) {
214
- await this.pmsService.cleanupWebhookQueues(propertyId);
215
- }
216
- /**
217
- * Shutdown the service
218
- */
219
- async shutdown() {
220
- await this.pmsService.shutdownWebhookQueue();
221
- }
222
- extractPropertyIdFromPayload(payload) {
223
- // Implement your logic to extract propertyId
224
- return payload.propertyId || payload.property_id || null;
225
- }
226
- }
227
- exports.ExamplePmsController = ExamplePmsController;
228
- // Example: Usage in your application
229
- async function exampleUsage() {
230
- try {
231
- // 1. Create controller
232
- const controller = new ExamplePmsController();
233
- // 2. Initialize
234
- await controller.initialize();
235
- // 3. Handle webhooks (they will be queued)
236
- const webhookPayload = {
237
- eventType: "reservation.created",
238
- propertyId: "hotel123",
239
- reservationId: "res_001",
240
- };
241
- const result = await controller.handleWebhook(webhookPayload, "CLOUDBEDS");
242
- console.log("Webhook result:", result);
243
- // 4. Check queue status
244
- const status = await controller.getWebhookQueueStatus("hotel123", "CLOUDBEDS");
245
- console.log("Queue status:", status);
246
- // 5. Cleanup when done
247
- await controller.cleanupWebhookQueues("hotel123");
248
- // 6. Shutdown
249
- await controller.shutdown();
250
- }
251
- catch (error) {
252
- console.error("Example usage failed:", error);
253
- }
254
- }
@@ -1,7 +0,0 @@
1
- export declare function initializeWebhookQueue(): Promise<import("..").WebhookQueueService>;
2
- export declare function addWebhookToQueue(propertyId: string, pmsType: string, webhookData: any): Promise<string>;
3
- export declare function checkQueueStatus(propertyId: string, pmsType: string): Promise<import("../types/webhook.types").IWebhookQueueStatus>;
4
- export declare function getAllQueueStatuses(propertyId: string): Promise<Record<string, import("../types/webhook.types").IWebhookQueueStatus>>;
5
- export declare function cleanupWebhookQueue(): Promise<void>;
6
- export declare function completeWebhookWorkflow(): Promise<void>;
7
- export declare function demonstrateErrorHandling(): Promise<string>;
@@ -1,175 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initializeWebhookQueue = initializeWebhookQueue;
4
- exports.addWebhookToQueue = addWebhookToQueue;
5
- exports.checkQueueStatus = checkQueueStatus;
6
- exports.getAllQueueStatuses = getAllQueueStatuses;
7
- exports.cleanupWebhookQueue = cleanupWebhookQueue;
8
- exports.completeWebhookWorkflow = completeWebhookWorkflow;
9
- exports.demonstrateErrorHandling = demonstrateErrorHandling;
10
- const WebhookQueueFactory_1 = require("../services/WebhookQueueFactory");
11
- /**
12
- * Example usage of the Webhook Queue System
13
- */
14
- // Configuration for the webhook queue
15
- const webhookQueueConfig = {
16
- redisHost: process.env.REDIS_HOST || "localhost",
17
- redisPort: parseInt(process.env.REDIS_PORT || "6379"),
18
- maxRetries: 3,
19
- backoffDelay: 2000,
20
- jobTimeout: 300000, // 5 minutes
21
- removeOnComplete: { age: 3600000, count: 100 }, // 1 hour, max 100
22
- removeOnFail: { age: 7200000, count: 50 }, // 2 hours, max 50
23
- };
24
- // Example webhook processor function
25
- async function processWebhook(webhookData, pmsType) {
26
- console.log(`Processing webhook for PMS: ${pmsType}`);
27
- console.log("Webhook data:", webhookData);
28
- // Your webhook processing logic here
29
- // This could include:
30
- // - Updating database records
31
- // - Sending notifications
32
- // - Triggering other services
33
- // - etc.
34
- // Simulate some processing time
35
- await new Promise((resolve) => setTimeout(resolve, 1000));
36
- console.log(`Webhook processed successfully for PMS: ${pmsType}`);
37
- return { success: true, processedAt: new Date().toISOString() };
38
- }
39
- // Example: Initialize webhook queue
40
- async function initializeWebhookQueue() {
41
- try {
42
- // Create webhook queue service
43
- const webhookQueue = WebhookQueueFactory_1.WebhookQueueFactory.createWebhookQueue(webhookQueueConfig);
44
- // Set webhook processor for different PMS types
45
- await webhookQueue.setWebhookProcessor("property123", "CLOUDBEDS", processWebhook);
46
- await webhookQueue.setWebhookProcessor("property123", "HOTELKEY", processWebhook);
47
- await webhookQueue.setWebhookProcessor("property123", "STAYNTOUCH", processWebhook);
48
- console.log("Webhook queue initialized successfully");
49
- return webhookQueue;
50
- }
51
- catch (error) {
52
- console.error("Failed to initialize webhook queue:", error);
53
- throw error;
54
- }
55
- }
56
- // Example: Add webhook to queue
57
- async function addWebhookToQueue(propertyId, pmsType, webhookData) {
58
- try {
59
- const webhookQueue = WebhookQueueFactory_1.WebhookQueueFactory.getWebhookQueue();
60
- if (!webhookQueue) {
61
- throw new Error("Webhook queue not initialized");
62
- }
63
- const jobId = await webhookQueue.addWebhookToQueue(propertyId, pmsType, webhookData);
64
- console.log(`Webhook added to queue with job ID: ${jobId}`);
65
- return jobId;
66
- }
67
- catch (error) {
68
- console.error("Failed to add webhook to queue:", error);
69
- throw error;
70
- }
71
- }
72
- // Example: Check queue status
73
- async function checkQueueStatus(propertyId, pmsType) {
74
- try {
75
- const webhookQueue = WebhookQueueFactory_1.WebhookQueueFactory.getWebhookQueue();
76
- if (!webhookQueue) {
77
- throw new Error("Webhook queue not initialized");
78
- }
79
- const status = await webhookQueue.getQueueStatus(propertyId, pmsType);
80
- console.log(`Queue status for ${propertyId}_${pmsType}_webhook:`, status);
81
- return status;
82
- }
83
- catch (error) {
84
- console.error("Failed to check queue status:", error);
85
- throw error;
86
- }
87
- }
88
- // Example: Get all queue statuses for a property
89
- async function getAllQueueStatuses(propertyId) {
90
- try {
91
- const webhookQueue = WebhookQueueFactory_1.WebhookQueueFactory.getWebhookQueue();
92
- if (!webhookQueue) {
93
- throw new Error("Webhook queue not initialized");
94
- }
95
- const statuses = await webhookQueue.getAllPropertyQueueStatuses(propertyId);
96
- console.log(`All queue statuses for property ${propertyId}:`, statuses);
97
- return statuses;
98
- }
99
- catch (error) {
100
- console.error("Failed to get queue statuses:", error);
101
- throw error;
102
- }
103
- }
104
- // Example: Cleanup and shutdown
105
- async function cleanupWebhookQueue() {
106
- try {
107
- await WebhookQueueFactory_1.WebhookQueueFactory.shutdownAll();
108
- console.log("Webhook queue shutdown successfully");
109
- }
110
- catch (error) {
111
- console.error("Failed to shutdown webhook queue:", error);
112
- throw error;
113
- }
114
- }
115
- // Example: Complete workflow
116
- async function completeWebhookWorkflow() {
117
- try {
118
- // 1. Initialize the queue
119
- const webhookQueue = await initializeWebhookQueue();
120
- // 2. Add some webhooks
121
- const webhookData1 = {
122
- eventType: "reservation.created",
123
- reservationId: "res_001",
124
- guestName: "John Doe",
125
- checkIn: "2024-01-15",
126
- checkOut: "2024-01-17",
127
- };
128
- const webhookData2 = {
129
- eventType: "reservation.updated",
130
- reservationId: "res_002",
131
- guestName: "Jane Smith",
132
- checkIn: "2024-01-16",
133
- checkOut: "2024-01-18",
134
- };
135
- // Add webhooks to different queues
136
- await addWebhookToQueue("property123", "CLOUDBEDS", webhookData1);
137
- await addWebhookToQueue("property123", "HOTELKEY", webhookData2);
138
- // 3. Check queue statuses
139
- await checkQueueStatus("property123", "CLOUDBEDS");
140
- await getAllQueueStatuses("property123");
141
- // 4. Wait for processing (in real scenario, this would be handled by workers)
142
- console.log("Waiting for webhooks to be processed...");
143
- await new Promise((resolve) => setTimeout(resolve, 5000));
144
- // 5. Check final statuses
145
- await checkQueueStatus("property123", "CLOUDBEDS");
146
- console.log("Webhook workflow completed successfully");
147
- }
148
- catch (error) {
149
- console.error("Webhook workflow failed:", error);
150
- throw error;
151
- }
152
- }
153
- // Example: Error handling and retries
154
- async function demonstrateErrorHandling() {
155
- try {
156
- const webhookQueue = WebhookQueueFactory_1.WebhookQueueFactory.getWebhookQueue();
157
- if (!webhookQueue) {
158
- throw new Error("Webhook queue not initialized");
159
- }
160
- // Add webhook with custom retry options
161
- const jobId = await webhookQueue.addWebhookToQueue("property123", "CLOUDBEDS", { test: "error-handling" }, {
162
- attempts: 5,
163
- backoff: {
164
- type: "exponential",
165
- delay: 1000,
166
- },
167
- });
168
- console.log(`Webhook added with custom retry options, job ID: ${jobId}`);
169
- return jobId;
170
- }
171
- catch (error) {
172
- console.error("Failed to demonstrate error handling:", error);
173
- throw error;
174
- }
175
- }
@@ -1,3 +0,0 @@
1
- export * from "./interfaces";
2
- export * from "./services";
3
- export * from "./types";
@@ -1,33 +0,0 @@
1
- import { IWebhookQueueOptions } from "../types/webhook.types";
2
- export interface IWebhookQueue {
3
- /**
4
- * Add a webhook to the appropriate queue based on propertyId and pmsType
5
- */
6
- addWebhookToQueue(propertyId: string, pmsType: string, webhookData: any, options?: IWebhookQueueOptions): Promise<string>;
7
- /**
8
- * Mark a webhook job as completed (processed successfully)
9
- */
10
- markWebhookCompleted(propertyId: string, pmsType: string, jobId: string): Promise<void>;
11
- /**
12
- * Mark a webhook job as failed
13
- */
14
- markWebhookFailed(propertyId: string, pmsType: string, jobId: string, error?: string): Promise<void>;
15
- /**
16
- * Poll available webhook from ANY available webhook queue in Redis
17
- */
18
- pollWebhookFromQueues(): Promise<{
19
- jobId: string;
20
- data: any;
21
- propertyId: string;
22
- pmsType: string;
23
- queueName: string;
24
- } | null>;
25
- /**
26
- * Get all available webhook queue names from Redis
27
- */
28
- getAllQueueNames(): Promise<string[]>;
29
- /**
30
- * Get total waiting count across all webhook queues
31
- */
32
- getTotalWaitingCount(): Promise<number>;
33
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,38 +0,0 @@
1
- import { IWebhookJobData, IWebhookProcessingResult } from "../types/webhook.types";
2
- export interface IWebhookWorker {
3
- /**
4
- * Start processing webhook jobs from the queue
5
- */
6
- startProcessing(queueName: string): Promise<void>;
7
- /**
8
- * Stop processing webhook jobs
9
- */
10
- stopProcessing(): Promise<void>;
11
- /**
12
- * Process a single webhook job
13
- */
14
- processWebhookJob(jobData: IWebhookJobData): Promise<IWebhookProcessingResult>;
15
- /**
16
- * Handle webhook processing errors
17
- */
18
- handleError(error: Error, jobData: IWebhookJobData): Promise<void>;
19
- /**
20
- * Get worker status
21
- */
22
- getWorkerStatus(): Promise<{
23
- isRunning: boolean;
24
- processedJobs: number;
25
- failedJobs: number;
26
- lastProcessedAt?: string;
27
- }>;
28
- /**
29
- * Set webhook processor function
30
- */
31
- setWebhookProcessor(processor: (webhookData: any, pmsType: string) => Promise<any>): void;
32
- }
33
- export interface IWebhookProcessor {
34
- /**
35
- * Process webhook data
36
- */
37
- process(webhookData: any, pmsType: string): Promise<any>;
38
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +0,0 @@
1
- export * from "./IWebhookQueue";
@@ -1,38 +0,0 @@
1
- import { IWebhookQueueConfig } from "../types/webhook.types";
2
- import { WebhookQueueService } from "./WebhookQueueService";
3
- export declare class WebhookQueueFactory {
4
- private static instances;
5
- /**
6
- * Create or get a webhook queue service instance
7
- * @param config Configuration for the webhook queue
8
- * @param instanceKey Optional key to identify different instances
9
- * @returns WebhookQueueService instance
10
- */
11
- static createWebhookQueue(config: IWebhookQueueConfig, instanceKey?: string): WebhookQueueService;
12
- /**
13
- * Get an existing webhook queue service instance
14
- * @param instanceKey Key to identify the instance
15
- * @returns WebhookQueueService instance or null if not found
16
- */
17
- static getWebhookQueue(instanceKey?: string): WebhookQueueService | null;
18
- /**
19
- * Get all webhook queue service instances
20
- * @returns Array of all WebhookQueueService instances
21
- */
22
- static getAllWebhookQueues(): WebhookQueueService[];
23
- /**
24
- * Shutdown all webhook queue service instances
25
- */
26
- static shutdownAll(): Promise<void>;
27
- /**
28
- * Check if a webhook queue service instance exists
29
- * @param instanceKey Key to identify the instance
30
- * @returns True if instance exists, false otherwise
31
- */
32
- static hasWebhookQueue(instanceKey?: string): boolean;
33
- /**
34
- * Remove a webhook queue service instance
35
- * @param instanceKey Key to identify the instance
36
- */
37
- static removeWebhookQueue(instanceKey?: string): Promise<void>;
38
- }