dt-common-device 3.0.9 → 3.0.11

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 (144) hide show
  1. package/dist/config/config.d.ts +1 -2
  2. package/dist/config/config.js +4 -5
  3. package/dist/device/cloud/interface.d.ts +101 -0
  4. package/dist/device/cloud/interface.js +3 -0
  5. package/dist/device/cloud/interfaces/IDeviceConnectionService.d.ts +7 -0
  6. package/dist/device/cloud/interfaces/IDeviceConnectionService.js +3 -0
  7. package/dist/device/cloud/interfaces/IDevicesService.d.ts +9 -0
  8. package/dist/device/cloud/services/Device.service.d.ts +39 -0
  9. package/dist/device/cloud/services/Device.service.js +9 -0
  10. package/dist/device/cloud/services/DeviceCloudService.d.ts +42 -0
  11. package/dist/device/cloud/services/DeviceCloudService.js +59 -0
  12. package/dist/device/cloud/services/DeviceHub.service.d.ts +3 -0
  13. package/dist/device/cloud/services/DeviceHub.service.js +6 -0
  14. package/dist/device/cloud/services/Hub.service.d.ts +25 -0
  15. package/dist/device/cloud/services/Hub.service.js +9 -0
  16. package/dist/device/cloud/services/SmartThingsDeviceService.d.ts +38 -0
  17. package/dist/device/cloud/services/SmartThingsDeviceService.js +52 -0
  18. package/dist/device/index.d.ts +4 -0
  19. package/dist/device/index.js +20 -0
  20. package/dist/device/local/events/EventHandler.js +6 -6
  21. package/dist/device/local/events/Events.d.ts +12 -33
  22. package/dist/device/local/events/Events.js +12 -33
  23. package/dist/device/local/interface.d.ts +0 -0
  24. package/dist/device/local/interface.js +1 -0
  25. package/dist/device/local/interfaces/IDevice.d.ts +1 -0
  26. package/dist/device/local/repository/Schedule.repository.d.ts +0 -1
  27. package/dist/device/local/repository/Schedule.repository.js +6 -6
  28. package/dist/device/local/services/DeviceHub.service.d.ts +11 -0
  29. package/dist/device/local/services/DeviceHub.service.js +40 -0
  30. package/dist/queue/entities/HybridHttpQueue.d.ts +4 -14
  31. package/dist/queue/entities/HybridHttpQueue.js +31 -119
  32. package/dist/queue/interfaces/IHybridHttpQueue.d.ts +2 -12
  33. package/dist/queue/interfaces/IJobResult.d.ts +1 -8
  34. package/dist/queue/interfaces/index.d.ts +0 -1
  35. package/dist/queue/interfaces/index.js +0 -1
  36. package/dist/queue/services/QueueService.d.ts +2 -12
  37. package/dist/queue/types/queue.types.d.ts +10 -29
  38. package/dist/queue/utils/jobUtils.d.ts +0 -3
  39. package/dist/queue/utils/jobUtils.js +0 -48
  40. package/dist/queue/utils/queueUtils.d.ts +7 -0
  41. package/dist/queue/utils/queueUtils.js +113 -4
  42. package/package.json +6 -1
  43. package/.eslintrc.js +0 -44
  44. package/dist/audit/AuditProperties.d.ts +0 -16
  45. package/dist/audit/AuditUtils.d.ts +0 -2
  46. package/dist/audit/AuditUtils.js +0 -36
  47. package/src/alerts/Alert.model.ts +0 -289
  48. package/src/alerts/Alert.repository.ts +0 -487
  49. package/src/alerts/Alert.service.ts +0 -711
  50. package/src/alerts/AlertBuilder.example.ts +0 -126
  51. package/src/alerts/AlertBuilder.ts +0 -208
  52. package/src/alerts/AlertService.example.ts +0 -232
  53. package/src/alerts/alert.types.ts +0 -64
  54. package/src/alerts/index.ts +0 -3
  55. package/src/audit/AuditProperties.ts +0 -16
  56. package/src/audit/AuditUtils.ts +0 -38
  57. package/src/config/config.ts +0 -202
  58. package/src/config/config.types.ts +0 -21
  59. package/src/connection/Connection.repository.ts +0 -52
  60. package/src/connection/Connection.service.ts +0 -39
  61. package/src/connection/IConnection.ts +0 -27
  62. package/src/connection/index.ts +0 -3
  63. package/src/constants/ConnectionProviders.ts +0 -11
  64. package/src/constants/Event.ts +0 -89
  65. package/src/constants/Service.ts +0 -17
  66. package/src/constants/index.ts +0 -3
  67. package/src/db/db.ts +0 -24
  68. package/src/db/index.ts +0 -2
  69. package/src/db/redis.ts +0 -20
  70. package/src/device/cloud/entities/CloudDevice.ts +0 -40
  71. package/src/device/cloud/entities/CloudDeviceService.ts +0 -8
  72. package/src/device/cloud/entities/DeviceFactory.ts +0 -27
  73. package/src/device/cloud/entities/index.ts +0 -3
  74. package/src/device/cloud/interfaces/ICloudDevice.ts +0 -14
  75. package/src/device/cloud/interfaces/ICloudDeviceService.ts +0 -6
  76. package/src/device/cloud/interfaces/IDeviceFactory.ts +0 -5
  77. package/src/device/cloud/interfaces/IRawDataTransformer.ts +0 -5
  78. package/src/device/cloud/interfaces/IRawDevice.ts +0 -19
  79. package/src/device/cloud/interfaces/index.ts +0 -5
  80. package/src/device/local/interfaces/IDevice.ts +0 -61
  81. package/src/device/local/interfaces/IDtDevice.ts +0 -16
  82. package/src/device/local/interfaces/ISchedule.ts +0 -40
  83. package/src/device/local/interfaces/index.ts +0 -3
  84. package/src/device/local/repository/Device.repository.ts +0 -368
  85. package/src/device/local/repository/Hub.repository.ts +0 -107
  86. package/src/device/local/repository/Schedule.repository.ts +0 -72
  87. package/src/device/local/services/Device.service.ts +0 -436
  88. package/src/device/local/services/Hub.service.ts +0 -57
  89. package/src/device/local/services/Schedule.service.ts +0 -26
  90. package/src/device/local/services/index.ts +0 -3
  91. package/src/docs/Alert.model.md +0 -319
  92. package/src/docs/Alerts&IssuesModel.md +0 -312
  93. package/src/docs/Issue.model.md +0 -386
  94. package/src/docs/SECURITY.md +0 -67
  95. package/src/docs/TROUBLESHOOTING.md +0 -184
  96. package/src/events/BaseEventHandler.ts +0 -145
  97. package/src/events/BaseEventTransformer.ts +0 -97
  98. package/src/events/DeviceEventHandler.ts +0 -213
  99. package/src/events/DeviceEventTransformerFactory.ts +0 -77
  100. package/src/events/EventHandler.ts +0 -124
  101. package/src/events/EventHandlerOrchestrator.ts +0 -119
  102. package/src/events/EventProcessingService.ts +0 -248
  103. package/src/events/InternalEventSubscription.ts +0 -194
  104. package/src/events/index.ts +0 -9
  105. package/src/events/interfaces/DeviceEvent.ts +0 -56
  106. package/src/events/interfaces/IEventHandler.ts +0 -28
  107. package/src/events/interfaces/IEventTransformer.ts +0 -8
  108. package/src/events/interfaces/IInternalEvent.ts +0 -33
  109. package/src/events/interfaces/index.ts +0 -4
  110. package/src/index.ts +0 -43
  111. package/src/issues/Issue.model.ts +0 -350
  112. package/src/issues/Issue.repository.ts +0 -517
  113. package/src/issues/Issue.service.ts +0 -932
  114. package/src/issues/IssueBuilder.example.ts +0 -210
  115. package/src/issues/IssueBuilder.ts +0 -263
  116. package/src/issues/IssueService.example.ts +0 -310
  117. package/src/issues/index.ts +0 -2
  118. package/src/issues/issue.types.ts +0 -98
  119. package/src/property/IProperty.ts +0 -30
  120. package/src/property/Property.repository.ts +0 -53
  121. package/src/property/Property.service.ts +0 -38
  122. package/src/property/index.ts +0 -2
  123. package/src/queue/entities/HybridHttpQueue.ts +0 -274
  124. package/src/queue/entities/index.ts +0 -1
  125. package/src/queue/index.ts +0 -6
  126. package/src/queue/interfaces/IHttpRequestJob.ts +0 -10
  127. package/src/queue/interfaces/IHybridHttpQueue.ts +0 -25
  128. package/src/queue/interfaces/IJobResult.ts +0 -15
  129. package/src/queue/interfaces/IRateLimitConfig.ts +0 -5
  130. package/src/queue/interfaces/index.ts +0 -4
  131. package/src/queue/services/QueueService.ts +0 -40
  132. package/src/queue/services/index.ts +0 -1
  133. package/src/queue/types/http.types.ts +0 -23
  134. package/src/queue/types/index.ts +0 -2
  135. package/src/queue/types/queue.types.ts +0 -21
  136. package/src/queue/utils/index.ts +0 -3
  137. package/src/queue/utils/jobUtils.ts +0 -79
  138. package/src/queue/utils/queueUtils.ts +0 -84
  139. package/src/queue/utils/rateLimit.utils.ts +0 -131
  140. package/src/utils/http.utils.ts +0 -143
  141. package/src/utils/index.ts +0 -2
  142. package/src/utils/redis.utils.ts +0 -74
  143. package/tsconfig.json +0 -20
  144. /package/dist/{audit/AuditProperties.js → device/cloud/interfaces/IDevicesService.js} +0 -0
package/src/index.ts DELETED
@@ -1,43 +0,0 @@
1
- // Main entry point for dt-common-device
2
-
3
- // CONSTANTS EXPORTS
4
- export * from "./constants";
5
-
6
- // DEVICE EXPORTS
7
- export {
8
- CloudDevice,
9
- CloudDeviceService,
10
- DeviceFactory,
11
- } from "./device/cloud/entities";
12
- export {
13
- LocalDeviceService,
14
- LocalHubService,
15
- LocalScheduleService,
16
- } from "./device/local/services";
17
- export * from "./device/local/interfaces";
18
- export * from "./device/cloud/interfaces";
19
-
20
- // CONNECTION EXPORTS
21
- export * from "./connection";
22
-
23
- // PROPERTY EXPORTS
24
- export * from "./property";
25
-
26
- // EVENTS EXPORTS
27
- export * from "./events";
28
- export * from "./events/interfaces";
29
-
30
- // ALERTS EXPORTS
31
- export * from "./alerts";
32
-
33
- // ISSUES EXPORTS
34
- export * from "./issues";
35
-
36
- // REDIS EXPORTS
37
- export * from "./utils";
38
-
39
- // QUEUE EXPORTS
40
- export * from "./queue";
41
-
42
- // CONFIG EXPORTS
43
- export { initialize, getConfig, shutdown } from "./config/config";
@@ -1,350 +0,0 @@
1
- import mongoose, { Schema, Model } from "mongoose";
2
- import {
3
- IssuesCategory,
4
- EntityType,
5
- IssueStatus,
6
- IssuePriority,
7
- IssueComment,
8
- IssueDocument as IIssueDocument,
9
- CreateIssueData,
10
- UpdateIssueData,
11
- AddCommentData,
12
- } from "./issue.types";
13
-
14
- // Comment sub-schema
15
- const CommentSchema = new Schema<IssueComment>(
16
- {
17
- id: { type: String, required: true },
18
- userId: { type: String, required: true },
19
- content: { type: String, required: true },
20
- createdAt: { type: Date, default: Date.now },
21
- updatedAt: { type: Date },
22
- },
23
- { _id: false }
24
- );
25
-
26
- // Interface for instance methods
27
- interface IIssueMethods {
28
- addComment(commentData: AddCommentData): void;
29
- updateComment(commentId: string, content: string, userId: string): boolean;
30
- removeComment(commentId: string): boolean;
31
- resolve(resolvedBy: string): void;
32
- reopen(updatedBy: string): void;
33
- assign(userId: string, assignedBy: string): void;
34
- unassign(unassignedBy: string): void;
35
- }
36
-
37
- // Interface for static methods
38
- interface IIssueModel extends Model<IIssueDocument, {}, IIssueMethods> {
39
- findByProperty(
40
- propertyId: string,
41
- includeDeleted?: boolean
42
- ): Promise<IIssueDocument[]>;
43
- findByAssignee(
44
- assignedTo: string,
45
- includeDeleted?: boolean
46
- ): Promise<IIssueDocument[]>;
47
- findByEntity(
48
- entityId: string,
49
- entityType: EntityType,
50
- includeDeleted?: boolean
51
- ): Promise<IIssueDocument[]>;
52
- findByStatus(
53
- status: IssueStatus,
54
- includeDeleted?: boolean
55
- ): Promise<IIssueDocument[]>;
56
- findByPriority(
57
- priority: IssuePriority,
58
- includeDeleted?: boolean
59
- ): Promise<IIssueDocument[]>;
60
- findOverdue(includeDeleted?: boolean): Promise<IIssueDocument[]>;
61
- findUpcoming(
62
- days?: number,
63
- includeDeleted?: boolean
64
- ): Promise<IIssueDocument[]>;
65
- }
66
-
67
- // Main Issue schema
68
- const IssueSchema = new Schema<IIssueDocument, IIssueModel, IIssueMethods>(
69
- {
70
- category: {
71
- type: String,
72
- enum: Object.values(IssuesCategory),
73
- required: true,
74
- },
75
- propertyId: {
76
- type: String,
77
- required: true,
78
- index: true,
79
- },
80
- title: {
81
- type: String,
82
- required: true,
83
- trim: true,
84
- },
85
- description: {
86
- type: String,
87
- required: true,
88
- trim: true,
89
- },
90
- entityId: {
91
- type: String,
92
- index: true,
93
- },
94
- entityType: {
95
- type: String,
96
- enum: Object.values(EntityType),
97
- required: true,
98
- index: true,
99
- },
100
- status: {
101
- type: String,
102
- enum: Object.values(IssueStatus),
103
- default: IssueStatus.PENDING,
104
- index: true,
105
- },
106
- priority: {
107
- type: String,
108
- enum: Object.values(IssuePriority),
109
- default: IssuePriority.MEDIUM,
110
- },
111
- assignedTo: {
112
- type: String,
113
- index: true,
114
- },
115
- createdBy: {
116
- type: String,
117
- required: true,
118
- },
119
- updatedBy: {
120
- type: String,
121
- },
122
- isDeleted: {
123
- type: Boolean,
124
- default: false,
125
- },
126
- createdAt: {
127
- type: Date,
128
- default: Date.now,
129
- },
130
- updatedAt: {
131
- type: Date,
132
- default: Date.now,
133
- },
134
- resolvedAt: {
135
- type: Date,
136
- },
137
- dueDate: {
138
- type: Date,
139
- },
140
- comments: {
141
- type: [CommentSchema],
142
- default: [],
143
- },
144
- },
145
- {
146
- timestamps: true,
147
- collection: "dt_issues",
148
- }
149
- );
150
-
151
- IssueSchema.index({ propertyId: 1, status: 1 });
152
- IssueSchema.index({ assignedTo: 1, status: 1 });
153
- IssueSchema.index({ entityId: 1, entityType: 1 });
154
-
155
- // Pre-save middleware to update the updatedAt field
156
- IssueSchema.pre("save", function (next) {
157
- this.updatedAt = new Date();
158
- next();
159
- });
160
-
161
- // Pre-update middleware to update the updatedAt field
162
- IssueSchema.pre(
163
- ["updateOne", "findOneAndUpdate", "updateMany"],
164
- function (next) {
165
- this.set({ updatedAt: new Date() });
166
- next();
167
- }
168
- );
169
-
170
- // Instance methods
171
- IssueSchema.methods.addComment = function (commentData: AddCommentData): void {
172
- const comment: IssueComment = {
173
- id: new mongoose.Types.ObjectId().toString(),
174
- userId: commentData.userId,
175
- content: commentData.content,
176
- createdAt: new Date(),
177
- };
178
-
179
- if (!this.comments) {
180
- this.comments = [];
181
- }
182
-
183
- this.comments.push(comment);
184
- };
185
-
186
- IssueSchema.methods.updateComment = function (
187
- commentId: string,
188
- content: string,
189
- userId: string
190
- ): boolean {
191
- if (!this.comments) return false;
192
-
193
- const comment = this.comments.find((c: IssueComment) => c.id === commentId);
194
- if (comment) {
195
- comment.content = content;
196
- comment.updatedAt = new Date();
197
- return true;
198
- }
199
- return false;
200
- };
201
-
202
- IssueSchema.methods.removeComment = function (commentId: string): boolean {
203
- if (!this.comments) return false;
204
-
205
- const initialLength = this.comments.length;
206
- this.comments = this.comments.filter((c: IssueComment) => c.id !== commentId);
207
- return this.comments.length < initialLength;
208
- };
209
-
210
- IssueSchema.methods.resolve = function (resolvedBy: string): void {
211
- this.status = IssueStatus.RESOLVED;
212
- this.resolvedAt = new Date();
213
- this.updatedBy = resolvedBy;
214
- };
215
-
216
- IssueSchema.methods.reopen = function (updatedBy: string): void {
217
- this.status = IssueStatus.PENDING;
218
- this.resolvedAt = undefined;
219
- this.updatedBy = updatedBy;
220
- };
221
-
222
- IssueSchema.methods.assign = function (
223
- userId: string,
224
- assignedBy: string
225
- ): void {
226
- this.assignedTo = userId;
227
- this.updatedBy = assignedBy;
228
- };
229
-
230
- IssueSchema.methods.unassign = function (unassignedBy: string): void {
231
- this.assignedTo = undefined;
232
- this.updatedBy = unassignedBy;
233
- };
234
-
235
- // Static methods
236
- IssueSchema.statics.findByProperty = function (
237
- propertyId: string,
238
- includeDeleted = false
239
- ) {
240
- const query: any = { propertyId };
241
- if (!includeDeleted) {
242
- query.isDeleted = false;
243
- }
244
- return this.find(query).sort({ createdAt: -1 });
245
- };
246
-
247
- IssueSchema.statics.findByAssignee = function (
248
- assignedTo: string,
249
- includeDeleted = false
250
- ) {
251
- const query: any = { assignedTo };
252
- if (!includeDeleted) {
253
- query.isDeleted = false;
254
- }
255
- return this.find(query).sort({ priority: -1, createdAt: -1 });
256
- };
257
-
258
- IssueSchema.statics.findByEntity = function (
259
- entityId: string,
260
- entityType: EntityType,
261
- includeDeleted = false
262
- ) {
263
- const query: any = { entityId, entityType };
264
- if (!includeDeleted) {
265
- query.isDeleted = false;
266
- }
267
- return this.find(query).sort({ createdAt: -1 });
268
- };
269
-
270
- IssueSchema.statics.findByStatus = function (
271
- status: IssueStatus,
272
- includeDeleted = false
273
- ) {
274
- const query: any = { status };
275
- if (!includeDeleted) {
276
- query.isDeleted = false;
277
- }
278
- return this.find(query).sort({ priority: -1, createdAt: -1 });
279
- };
280
-
281
- IssueSchema.statics.findByPriority = function (
282
- priority: IssuePriority,
283
- includeDeleted = false
284
- ) {
285
- const query: any = { priority };
286
- if (!includeDeleted) {
287
- query.isDeleted = false;
288
- }
289
- return this.find(query).sort({ createdAt: -1 });
290
- };
291
-
292
- IssueSchema.statics.findOverdue = function (includeDeleted = false) {
293
- const query: any = {
294
- dueDate: { $lt: new Date() },
295
- status: {
296
- $nin: [IssueStatus.RESOLVED, IssueStatus.CLOSED, IssueStatus.CANCELLED],
297
- },
298
- };
299
- if (!includeDeleted) {
300
- query.isDeleted = false;
301
- }
302
- return this.find(query).sort({ dueDate: 1 });
303
- };
304
-
305
- IssueSchema.statics.findUpcoming = function (
306
- days: number = 7,
307
- includeDeleted = false
308
- ) {
309
- const futureDate = new Date();
310
- futureDate.setDate(futureDate.getDate() + days);
311
-
312
- const query: any = {
313
- dueDate: { $gte: new Date(), $lte: futureDate },
314
- status: {
315
- $nin: [IssueStatus.RESOLVED, IssueStatus.CLOSED, IssueStatus.CANCELLED],
316
- },
317
- };
318
- if (!includeDeleted) {
319
- query.isDeleted = false;
320
- }
321
- return this.find(query).sort({ dueDate: 1 });
322
- };
323
-
324
- // Virtual for soft delete
325
- IssueSchema.virtual("isActive").get(function () {
326
- return !this.isDeleted;
327
- });
328
-
329
- // Ensure virtuals are serialized
330
- IssueSchema.set("toJSON", { virtuals: true });
331
- IssueSchema.set("toObject", { virtuals: true });
332
-
333
- // Create and export the model
334
- export const IssueModel = mongoose.model<IIssueDocument, IIssueModel>(
335
- "Issue",
336
- IssueSchema
337
- );
338
-
339
- // Export the schema for potential reuse
340
- export { IssueSchema };
341
-
342
- // Export types for external use
343
- export type {
344
- IIssueDocument,
345
- CreateIssueData,
346
- UpdateIssueData,
347
- AddCommentData,
348
- IIssueMethods,
349
- IIssueModel,
350
- };