dt-common-device 3.0.10 → 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 (113) hide show
  1. package/dist/config/config.d.ts +1 -2
  2. package/dist/config/config.js +4 -5
  3. package/dist/device/local/repository/Schedule.repository.d.ts +0 -1
  4. package/dist/device/local/repository/Schedule.repository.js +6 -6
  5. package/dist/queue/entities/HybridHttpQueue.d.ts +4 -14
  6. package/dist/queue/entities/HybridHttpQueue.js +31 -119
  7. package/dist/queue/interfaces/IHybridHttpQueue.d.ts +2 -12
  8. package/dist/queue/interfaces/IJobResult.d.ts +1 -8
  9. package/dist/queue/interfaces/index.d.ts +0 -1
  10. package/dist/queue/interfaces/index.js +0 -1
  11. package/dist/queue/services/QueueService.d.ts +2 -12
  12. package/dist/queue/types/queue.types.d.ts +10 -29
  13. package/dist/queue/utils/jobUtils.d.ts +0 -3
  14. package/dist/queue/utils/jobUtils.js +0 -48
  15. package/dist/queue/utils/queueUtils.d.ts +7 -0
  16. package/dist/queue/utils/queueUtils.js +113 -4
  17. package/package.json +6 -1
  18. package/.eslintrc.js +0 -44
  19. package/src/alerts/Alert.model.ts +0 -289
  20. package/src/alerts/Alert.repository.ts +0 -487
  21. package/src/alerts/Alert.service.ts +0 -711
  22. package/src/alerts/AlertBuilder.example.ts +0 -126
  23. package/src/alerts/AlertBuilder.ts +0 -208
  24. package/src/alerts/AlertService.example.ts +0 -232
  25. package/src/alerts/alert.types.ts +0 -64
  26. package/src/alerts/index.ts +0 -3
  27. package/src/config/config.ts +0 -202
  28. package/src/config/config.types.ts +0 -21
  29. package/src/connection/Connection.repository.ts +0 -52
  30. package/src/connection/Connection.service.ts +0 -39
  31. package/src/connection/IConnection.ts +0 -27
  32. package/src/connection/index.ts +0 -3
  33. package/src/constants/ConnectionProviders.ts +0 -11
  34. package/src/constants/Event.ts +0 -89
  35. package/src/constants/Service.ts +0 -17
  36. package/src/constants/index.ts +0 -3
  37. package/src/db/db.ts +0 -24
  38. package/src/db/index.ts +0 -2
  39. package/src/db/redis.ts +0 -20
  40. package/src/device/cloud/entities/CloudDevice.ts +0 -40
  41. package/src/device/cloud/entities/CloudDeviceService.ts +0 -8
  42. package/src/device/cloud/entities/DeviceFactory.ts +0 -27
  43. package/src/device/cloud/entities/index.ts +0 -3
  44. package/src/device/cloud/interfaces/ICloudDevice.ts +0 -14
  45. package/src/device/cloud/interfaces/ICloudDeviceService.ts +0 -6
  46. package/src/device/cloud/interfaces/IDeviceFactory.ts +0 -5
  47. package/src/device/cloud/interfaces/IRawDataTransformer.ts +0 -5
  48. package/src/device/cloud/interfaces/IRawDevice.ts +0 -19
  49. package/src/device/cloud/interfaces/index.ts +0 -5
  50. package/src/device/local/interfaces/IDevice.ts +0 -62
  51. package/src/device/local/interfaces/IDtDevice.ts +0 -16
  52. package/src/device/local/interfaces/ISchedule.ts +0 -40
  53. package/src/device/local/interfaces/index.ts +0 -3
  54. package/src/device/local/repository/Device.repository.ts +0 -368
  55. package/src/device/local/repository/Hub.repository.ts +0 -107
  56. package/src/device/local/repository/Schedule.repository.ts +0 -72
  57. package/src/device/local/services/Device.service.ts +0 -436
  58. package/src/device/local/services/Hub.service.ts +0 -57
  59. package/src/device/local/services/Schedule.service.ts +0 -26
  60. package/src/device/local/services/index.ts +0 -3
  61. package/src/docs/Alert.model.md +0 -319
  62. package/src/docs/Alerts&IssuesModel.md +0 -312
  63. package/src/docs/Issue.model.md +0 -386
  64. package/src/docs/SECURITY.md +0 -67
  65. package/src/docs/TROUBLESHOOTING.md +0 -184
  66. package/src/events/BaseEventHandler.ts +0 -145
  67. package/src/events/BaseEventTransformer.ts +0 -97
  68. package/src/events/DeviceEventHandler.ts +0 -213
  69. package/src/events/DeviceEventTransformerFactory.ts +0 -77
  70. package/src/events/EventHandler.ts +0 -124
  71. package/src/events/EventHandlerOrchestrator.ts +0 -119
  72. package/src/events/EventProcessingService.ts +0 -248
  73. package/src/events/InternalEventSubscription.ts +0 -194
  74. package/src/events/index.ts +0 -9
  75. package/src/events/interfaces/DeviceEvent.ts +0 -56
  76. package/src/events/interfaces/IEventHandler.ts +0 -28
  77. package/src/events/interfaces/IEventTransformer.ts +0 -8
  78. package/src/events/interfaces/IInternalEvent.ts +0 -33
  79. package/src/events/interfaces/index.ts +0 -4
  80. package/src/index.ts +0 -43
  81. package/src/issues/Issue.model.ts +0 -350
  82. package/src/issues/Issue.repository.ts +0 -517
  83. package/src/issues/Issue.service.ts +0 -932
  84. package/src/issues/IssueBuilder.example.ts +0 -210
  85. package/src/issues/IssueBuilder.ts +0 -263
  86. package/src/issues/IssueService.example.ts +0 -310
  87. package/src/issues/index.ts +0 -2
  88. package/src/issues/issue.types.ts +0 -98
  89. package/src/property/IProperty.ts +0 -30
  90. package/src/property/Property.repository.ts +0 -53
  91. package/src/property/Property.service.ts +0 -38
  92. package/src/property/index.ts +0 -2
  93. package/src/queue/entities/HybridHttpQueue.ts +0 -274
  94. package/src/queue/entities/index.ts +0 -1
  95. package/src/queue/index.ts +0 -6
  96. package/src/queue/interfaces/IHttpRequestJob.ts +0 -10
  97. package/src/queue/interfaces/IHybridHttpQueue.ts +0 -25
  98. package/src/queue/interfaces/IJobResult.ts +0 -15
  99. package/src/queue/interfaces/IRateLimitConfig.ts +0 -5
  100. package/src/queue/interfaces/index.ts +0 -4
  101. package/src/queue/services/QueueService.ts +0 -40
  102. package/src/queue/services/index.ts +0 -1
  103. package/src/queue/types/http.types.ts +0 -23
  104. package/src/queue/types/index.ts +0 -2
  105. package/src/queue/types/queue.types.ts +0 -21
  106. package/src/queue/utils/index.ts +0 -3
  107. package/src/queue/utils/jobUtils.ts +0 -79
  108. package/src/queue/utils/queueUtils.ts +0 -84
  109. package/src/queue/utils/rateLimit.utils.ts +0 -131
  110. package/src/utils/http.utils.ts +0 -143
  111. package/src/utils/index.ts +0 -2
  112. package/src/utils/redis.utils.ts +0 -74
  113. package/tsconfig.json +0 -20
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
- };