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.
- package/dist/config/config.d.ts +1 -2
- package/dist/config/config.js +4 -5
- package/dist/device/local/repository/Schedule.repository.d.ts +0 -1
- package/dist/device/local/repository/Schedule.repository.js +6 -6
- package/dist/queue/entities/HybridHttpQueue.d.ts +4 -14
- package/dist/queue/entities/HybridHttpQueue.js +31 -119
- package/dist/queue/interfaces/IHybridHttpQueue.d.ts +2 -12
- package/dist/queue/interfaces/IJobResult.d.ts +1 -8
- package/dist/queue/interfaces/index.d.ts +0 -1
- package/dist/queue/interfaces/index.js +0 -1
- package/dist/queue/services/QueueService.d.ts +2 -12
- package/dist/queue/types/queue.types.d.ts +10 -29
- package/dist/queue/utils/jobUtils.d.ts +0 -3
- package/dist/queue/utils/jobUtils.js +0 -48
- package/dist/queue/utils/queueUtils.d.ts +7 -0
- package/dist/queue/utils/queueUtils.js +113 -4
- package/package.json +6 -1
- package/.eslintrc.js +0 -44
- package/src/alerts/Alert.model.ts +0 -289
- package/src/alerts/Alert.repository.ts +0 -487
- package/src/alerts/Alert.service.ts +0 -711
- package/src/alerts/AlertBuilder.example.ts +0 -126
- package/src/alerts/AlertBuilder.ts +0 -208
- package/src/alerts/AlertService.example.ts +0 -232
- package/src/alerts/alert.types.ts +0 -64
- package/src/alerts/index.ts +0 -3
- package/src/config/config.ts +0 -202
- package/src/config/config.types.ts +0 -21
- package/src/connection/Connection.repository.ts +0 -52
- package/src/connection/Connection.service.ts +0 -39
- package/src/connection/IConnection.ts +0 -27
- package/src/connection/index.ts +0 -3
- package/src/constants/ConnectionProviders.ts +0 -11
- package/src/constants/Event.ts +0 -89
- package/src/constants/Service.ts +0 -17
- package/src/constants/index.ts +0 -3
- package/src/db/db.ts +0 -24
- package/src/db/index.ts +0 -2
- package/src/db/redis.ts +0 -20
- package/src/device/cloud/entities/CloudDevice.ts +0 -40
- package/src/device/cloud/entities/CloudDeviceService.ts +0 -8
- package/src/device/cloud/entities/DeviceFactory.ts +0 -27
- package/src/device/cloud/entities/index.ts +0 -3
- package/src/device/cloud/interfaces/ICloudDevice.ts +0 -14
- package/src/device/cloud/interfaces/ICloudDeviceService.ts +0 -6
- package/src/device/cloud/interfaces/IDeviceFactory.ts +0 -5
- package/src/device/cloud/interfaces/IRawDataTransformer.ts +0 -5
- package/src/device/cloud/interfaces/IRawDevice.ts +0 -19
- package/src/device/cloud/interfaces/index.ts +0 -5
- package/src/device/local/interfaces/IDevice.ts +0 -62
- package/src/device/local/interfaces/IDtDevice.ts +0 -16
- package/src/device/local/interfaces/ISchedule.ts +0 -40
- package/src/device/local/interfaces/index.ts +0 -3
- package/src/device/local/repository/Device.repository.ts +0 -368
- package/src/device/local/repository/Hub.repository.ts +0 -107
- package/src/device/local/repository/Schedule.repository.ts +0 -72
- package/src/device/local/services/Device.service.ts +0 -436
- package/src/device/local/services/Hub.service.ts +0 -57
- package/src/device/local/services/Schedule.service.ts +0 -26
- package/src/device/local/services/index.ts +0 -3
- package/src/docs/Alert.model.md +0 -319
- package/src/docs/Alerts&IssuesModel.md +0 -312
- package/src/docs/Issue.model.md +0 -386
- package/src/docs/SECURITY.md +0 -67
- package/src/docs/TROUBLESHOOTING.md +0 -184
- package/src/events/BaseEventHandler.ts +0 -145
- package/src/events/BaseEventTransformer.ts +0 -97
- package/src/events/DeviceEventHandler.ts +0 -213
- package/src/events/DeviceEventTransformerFactory.ts +0 -77
- package/src/events/EventHandler.ts +0 -124
- package/src/events/EventHandlerOrchestrator.ts +0 -119
- package/src/events/EventProcessingService.ts +0 -248
- package/src/events/InternalEventSubscription.ts +0 -194
- package/src/events/index.ts +0 -9
- package/src/events/interfaces/DeviceEvent.ts +0 -56
- package/src/events/interfaces/IEventHandler.ts +0 -28
- package/src/events/interfaces/IEventTransformer.ts +0 -8
- package/src/events/interfaces/IInternalEvent.ts +0 -33
- package/src/events/interfaces/index.ts +0 -4
- package/src/index.ts +0 -43
- package/src/issues/Issue.model.ts +0 -350
- package/src/issues/Issue.repository.ts +0 -517
- package/src/issues/Issue.service.ts +0 -932
- package/src/issues/IssueBuilder.example.ts +0 -210
- package/src/issues/IssueBuilder.ts +0 -263
- package/src/issues/IssueService.example.ts +0 -310
- package/src/issues/index.ts +0 -2
- package/src/issues/issue.types.ts +0 -98
- package/src/property/IProperty.ts +0 -30
- package/src/property/Property.repository.ts +0 -53
- package/src/property/Property.service.ts +0 -38
- package/src/property/index.ts +0 -2
- package/src/queue/entities/HybridHttpQueue.ts +0 -274
- package/src/queue/entities/index.ts +0 -1
- package/src/queue/index.ts +0 -6
- package/src/queue/interfaces/IHttpRequestJob.ts +0 -10
- package/src/queue/interfaces/IHybridHttpQueue.ts +0 -25
- package/src/queue/interfaces/IJobResult.ts +0 -15
- package/src/queue/interfaces/IRateLimitConfig.ts +0 -5
- package/src/queue/interfaces/index.ts +0 -4
- package/src/queue/services/QueueService.ts +0 -40
- package/src/queue/services/index.ts +0 -1
- package/src/queue/types/http.types.ts +0 -23
- package/src/queue/types/index.ts +0 -2
- package/src/queue/types/queue.types.ts +0 -21
- package/src/queue/utils/index.ts +0 -3
- package/src/queue/utils/jobUtils.ts +0 -79
- package/src/queue/utils/queueUtils.ts +0 -84
- package/src/queue/utils/rateLimit.utils.ts +0 -131
- package/src/utils/http.utils.ts +0 -143
- package/src/utils/index.ts +0 -2
- package/src/utils/redis.utils.ts +0 -74
- package/tsconfig.json +0 -20
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { AlertBuilder } from "./AlertBuilder";
|
|
2
|
-
import { AlertCategory, AlertSeverity, EntityType } from "./alert.types";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Example usage of AlertBuilder
|
|
6
|
-
* This file demonstrates various ways to use the AlertBuilder pattern
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// Example 1: Basic alert creation
|
|
10
|
-
export function createBasicAlert() {
|
|
11
|
-
const alertData = new AlertBuilder()
|
|
12
|
-
.setCategory(AlertCategory.OPERATIONS)
|
|
13
|
-
.setPropertyId("prop123")
|
|
14
|
-
.setTitle("Device Offline")
|
|
15
|
-
.setDescription("Device has been offline for more than 5 minutes")
|
|
16
|
-
.setEntityId("device456")
|
|
17
|
-
.setEntityType(EntityType.DEVICE)
|
|
18
|
-
.setSeverity(AlertSeverity.HIGH)
|
|
19
|
-
.setCreatedBy("user789")
|
|
20
|
-
.build();
|
|
21
|
-
|
|
22
|
-
return alertData;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Example 2: Using static factory methods
|
|
26
|
-
export function createDeviceAlert() {
|
|
27
|
-
const alertData = AlertBuilder.createDeviceAlert("device123", "prop456")
|
|
28
|
-
.setCategory(AlertCategory.READINESS)
|
|
29
|
-
.setTitle("Device Maintenance Required")
|
|
30
|
-
.setDescription("Device firmware update is available")
|
|
31
|
-
.setSeverity(AlertSeverity.MEDIUM)
|
|
32
|
-
.setCreatedBy("system")
|
|
33
|
-
.build();
|
|
34
|
-
|
|
35
|
-
return alertData;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Example 3: Using predefined alert types
|
|
39
|
-
export function createSecurityAlert() {
|
|
40
|
-
const alertData = AlertBuilder.createSecurityAlert()
|
|
41
|
-
.setPropertyId("prop789")
|
|
42
|
-
.setTitle("Unauthorized Access Attempt")
|
|
43
|
-
.setDescription("Multiple failed login attempts detected")
|
|
44
|
-
.setEntityId("user123")
|
|
45
|
-
.setEntityType(EntityType.USER)
|
|
46
|
-
.setCreatedBy("security-system")
|
|
47
|
-
.build();
|
|
48
|
-
|
|
49
|
-
return alertData;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Example 4: Creating energy alert
|
|
53
|
-
export function createEnergyAlert() {
|
|
54
|
-
const alertData = AlertBuilder.createEnergyAlert()
|
|
55
|
-
.setPropertyId("prop101")
|
|
56
|
-
.setTitle("High Energy Consumption")
|
|
57
|
-
.setDescription("Energy usage is 20% above normal levels")
|
|
58
|
-
.setEntityId("zone456")
|
|
59
|
-
.setEntityType(EntityType.COLLECTION)
|
|
60
|
-
.setCreatedBy("energy-monitor")
|
|
61
|
-
.build();
|
|
62
|
-
|
|
63
|
-
return alertData;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Example 5: Creating hub alert
|
|
67
|
-
export function createHubAlert() {
|
|
68
|
-
const alertData = AlertBuilder.createHubAlert("hub789", "prop202")
|
|
69
|
-
.setCategory(AlertCategory.OPERATIONS)
|
|
70
|
-
.setTitle("Hub Connection Lost")
|
|
71
|
-
.setDescription("Hub has lost connection to the network")
|
|
72
|
-
.setSeverity(AlertSeverity.CRITICAL)
|
|
73
|
-
.setCreatedBy("network-monitor")
|
|
74
|
-
.build();
|
|
75
|
-
|
|
76
|
-
return alertData;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Example 6: Alert with snooze
|
|
80
|
-
export function createSnoozedAlert() {
|
|
81
|
-
const snoozeUntil = new Date();
|
|
82
|
-
snoozeUntil.setHours(snoozeUntil.getHours() + 2); // Snooze for 2 hours
|
|
83
|
-
|
|
84
|
-
const alertData = new AlertBuilder()
|
|
85
|
-
.setCategory(AlertCategory.OTHER)
|
|
86
|
-
.setPropertyId("prop303")
|
|
87
|
-
.setTitle("Scheduled Maintenance")
|
|
88
|
-
.setDescription("System maintenance scheduled for tonight")
|
|
89
|
-
.setEntityType(EntityType.PROPERTY)
|
|
90
|
-
.setSeverity(AlertSeverity.INFO)
|
|
91
|
-
.setCreatedBy("admin")
|
|
92
|
-
.setSnoozeUntil(snoozeUntil)
|
|
93
|
-
.build();
|
|
94
|
-
|
|
95
|
-
return alertData;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Example 7: Reusing builder instance
|
|
99
|
-
export function createMultipleAlerts() {
|
|
100
|
-
const builder = new AlertBuilder()
|
|
101
|
-
.setPropertyId("prop404")
|
|
102
|
-
.setCreatedBy("system");
|
|
103
|
-
|
|
104
|
-
const alert1 = builder
|
|
105
|
-
.setCategory(AlertCategory.OPERATIONS)
|
|
106
|
-
.setTitle("Device Temperature High")
|
|
107
|
-
.setDescription("Device temperature exceeds normal operating range")
|
|
108
|
-
.setEntityId("device789")
|
|
109
|
-
.setEntityType(EntityType.DEVICE)
|
|
110
|
-
.setSeverity(AlertSeverity.HIGH)
|
|
111
|
-
.build();
|
|
112
|
-
|
|
113
|
-
const alert2 = builder
|
|
114
|
-
.reset()
|
|
115
|
-
.setPropertyId("prop404")
|
|
116
|
-
.setCategory(AlertCategory.ENERGY)
|
|
117
|
-
.setTitle("Low Battery Warning")
|
|
118
|
-
.setDescription("Device battery level is below 20%")
|
|
119
|
-
.setEntityId("device789")
|
|
120
|
-
.setEntityType(EntityType.DEVICE)
|
|
121
|
-
.setSeverity(AlertSeverity.MEDIUM)
|
|
122
|
-
.setCreatedBy("system")
|
|
123
|
-
.build();
|
|
124
|
-
|
|
125
|
-
return [alert1, alert2];
|
|
126
|
-
}
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CreateAlertData,
|
|
3
|
-
AlertCategory,
|
|
4
|
-
AlertSeverity,
|
|
5
|
-
EntityType,
|
|
6
|
-
} from "./alert.types";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* AlertBuilder - A builder pattern implementation for constructing CreateAlertData objects
|
|
10
|
-
*
|
|
11
|
-
* This builder provides a fluent interface for creating alert data with proper validation
|
|
12
|
-
* and default values. It follows the Builder pattern which is a standard design pattern
|
|
13
|
-
* in TypeScript for constructing complex objects.
|
|
14
|
-
*
|
|
15
|
-
* Usage example:
|
|
16
|
-
* const alertData = new AlertBuilder()
|
|
17
|
-
* .setCategory(AlertCategory.OPERATIONS)
|
|
18
|
-
* .setPropertyId("prop123")
|
|
19
|
-
* .setTitle("Device Offline")
|
|
20
|
-
* .setDescription("Device has been offline for more than 5 minutes")
|
|
21
|
-
* .setEntityId("device456")
|
|
22
|
-
* .setEntityType(EntityType.DEVICE)
|
|
23
|
-
* .setSeverity(AlertSeverity.HIGH)
|
|
24
|
-
* .setCreatedBy("user789")
|
|
25
|
-
* .build();
|
|
26
|
-
*/
|
|
27
|
-
export class AlertBuilder {
|
|
28
|
-
private data: Partial<CreateAlertData> = {};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Sets the alert category
|
|
32
|
-
*/
|
|
33
|
-
setCategory(category: AlertCategory | AlertCategory[]): AlertBuilder {
|
|
34
|
-
this.data.category = Array.isArray(category) ? category : [category];
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Sets the property ID
|
|
40
|
-
*/
|
|
41
|
-
setPropertyId(propertyId: string): AlertBuilder {
|
|
42
|
-
if (!propertyId || propertyId.trim() === "") {
|
|
43
|
-
throw new Error("Property ID is required and cannot be empty");
|
|
44
|
-
}
|
|
45
|
-
this.data.propertyId = propertyId;
|
|
46
|
-
return this;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Sets the alert title
|
|
51
|
-
*/
|
|
52
|
-
setTitle(title: string): AlertBuilder {
|
|
53
|
-
if (!title || title.trim() === "") {
|
|
54
|
-
throw new Error("Title is required and cannot be empty");
|
|
55
|
-
}
|
|
56
|
-
this.data.title = title.trim();
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Sets the alert description
|
|
62
|
-
*/
|
|
63
|
-
setDescription(description: string): AlertBuilder {
|
|
64
|
-
if (!description || description.trim() === "") {
|
|
65
|
-
throw new Error("Description is required and cannot be empty");
|
|
66
|
-
}
|
|
67
|
-
this.data.description = description.trim();
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Sets the entity ID (optional)
|
|
73
|
-
*/
|
|
74
|
-
setEntityId(entityId?: string): AlertBuilder {
|
|
75
|
-
if (entityId !== undefined) {
|
|
76
|
-
this.data.entityId = entityId.trim() || undefined;
|
|
77
|
-
}
|
|
78
|
-
return this;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Sets the entity type
|
|
83
|
-
*/
|
|
84
|
-
setEntityType(entityType: EntityType): AlertBuilder {
|
|
85
|
-
this.data.entityType = entityType;
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Sets the alert severity (optional, defaults to MEDIUM)
|
|
91
|
-
*/
|
|
92
|
-
setSeverity(severity?: AlertSeverity): AlertBuilder {
|
|
93
|
-
if (severity !== undefined) {
|
|
94
|
-
this.data.severity = severity;
|
|
95
|
-
}
|
|
96
|
-
return this;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Sets the user who created the alert (optional)
|
|
101
|
-
*/
|
|
102
|
-
setCreatedBy(createdBy?: string): AlertBuilder {
|
|
103
|
-
if (createdBy !== undefined) {
|
|
104
|
-
this.data.createdBy = createdBy.trim() || undefined;
|
|
105
|
-
}
|
|
106
|
-
return this;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Sets the snooze until date (optional)
|
|
111
|
-
*/
|
|
112
|
-
setSnoozeUntil(snoozeUntil?: Date): AlertBuilder {
|
|
113
|
-
if (snoozeUntil !== undefined) {
|
|
114
|
-
this.data.snoozeUntil = snoozeUntil;
|
|
115
|
-
}
|
|
116
|
-
return this;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Validates that all required fields are present
|
|
121
|
-
*/
|
|
122
|
-
private validate(): void {
|
|
123
|
-
const requiredFields = [
|
|
124
|
-
"category",
|
|
125
|
-
"propertyId",
|
|
126
|
-
"title",
|
|
127
|
-
"description",
|
|
128
|
-
"entityType",
|
|
129
|
-
];
|
|
130
|
-
const missingFields = requiredFields.filter(
|
|
131
|
-
(field) => !this.data[field as keyof CreateAlertData]
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
if (missingFields.length > 0) {
|
|
135
|
-
throw new Error(`Missing required fields: ${missingFields.join(", ")}`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Builds and returns the CreateAlertData object
|
|
141
|
-
* @throws Error if required fields are missing
|
|
142
|
-
*/
|
|
143
|
-
build(): CreateAlertData {
|
|
144
|
-
this.validate();
|
|
145
|
-
|
|
146
|
-
// Set default severity if not provided
|
|
147
|
-
if (!this.data.severity) {
|
|
148
|
-
this.data.severity = AlertSeverity.MEDIUM;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return this.data as CreateAlertData;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Resets the builder to its initial state
|
|
156
|
-
*/
|
|
157
|
-
reset(): AlertBuilder {
|
|
158
|
-
this.data = {};
|
|
159
|
-
return this;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Creates a new builder instance with predefined values for common alert types
|
|
164
|
-
*/
|
|
165
|
-
static createReadinessAlert(): AlertBuilder {
|
|
166
|
-
return new AlertBuilder()
|
|
167
|
-
.setCategory(AlertCategory.READINESS)
|
|
168
|
-
.setSeverity(AlertSeverity.MEDIUM);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
static createOperationsAlert(): AlertBuilder {
|
|
172
|
-
return new AlertBuilder()
|
|
173
|
-
.setCategory(AlertCategory.OPERATIONS)
|
|
174
|
-
.setSeverity(AlertSeverity.HIGH);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
static createSecurityAlert(): AlertBuilder {
|
|
178
|
-
return new AlertBuilder()
|
|
179
|
-
.setCategory(AlertCategory.SECURITY)
|
|
180
|
-
.setSeverity(AlertSeverity.CRITICAL);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
static createEnergyAlert(): AlertBuilder {
|
|
184
|
-
return new AlertBuilder()
|
|
185
|
-
.setCategory(AlertCategory.ENERGY)
|
|
186
|
-
.setSeverity(AlertSeverity.LOW);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Creates a device-specific alert builder
|
|
191
|
-
*/
|
|
192
|
-
static createDeviceAlert(deviceId: string, propertyId: string): AlertBuilder {
|
|
193
|
-
return new AlertBuilder()
|
|
194
|
-
.setEntityType(EntityType.DEVICE)
|
|
195
|
-
.setEntityId(deviceId)
|
|
196
|
-
.setPropertyId(propertyId);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Creates a hub-specific alert builder
|
|
201
|
-
*/
|
|
202
|
-
static createHubAlert(hubId: string, propertyId: string): AlertBuilder {
|
|
203
|
-
return new AlertBuilder()
|
|
204
|
-
.setEntityType(EntityType.HUB)
|
|
205
|
-
.setEntityId(hubId)
|
|
206
|
-
.setPropertyId(propertyId);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { Source } from "../constants/Service";
|
|
2
|
-
import { AlertService } from "./Alert.service";
|
|
3
|
-
import { AlertBuilder } from "./AlertBuilder";
|
|
4
|
-
import { AlertCategory, AlertSeverity, EntityType } from "./alert.types";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Example usage of the updated AlertService with AlertBuilder integration
|
|
8
|
-
* This file demonstrates various ways to use the AlertService with the new AlertBuilder
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export class AlertServiceExample {
|
|
12
|
-
constructor(private readonly alertService: AlertService) {}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Example 1: Using the updated createAlert method with AlertBuilder
|
|
16
|
-
*/
|
|
17
|
-
async createAlertWithBuilder() {
|
|
18
|
-
const alertBuilder = new AlertBuilder()
|
|
19
|
-
.setCategory(AlertCategory.OPERATIONS)
|
|
20
|
-
.setPropertyId("prop123")
|
|
21
|
-
.setTitle("Device Offline")
|
|
22
|
-
.setDescription("Device has been offline for more than 5 minutes")
|
|
23
|
-
.setEntityId("device456")
|
|
24
|
-
.setEntityType(EntityType.DEVICE)
|
|
25
|
-
.setSeverity(AlertSeverity.HIGH)
|
|
26
|
-
.setCreatedBy("user789");
|
|
27
|
-
|
|
28
|
-
// Pass the AlertBuilder directly to createAlert
|
|
29
|
-
const alert = await this.alertService.createAlert(alertBuilder);
|
|
30
|
-
return alert;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Example 2: Using convenience methods for specific alert types
|
|
35
|
-
*/
|
|
36
|
-
async createSpecificAlerts() {
|
|
37
|
-
// Create a readiness alert
|
|
38
|
-
const readinessAlert = await this.alertService.raiseReadinessAlert(
|
|
39
|
-
"prop123",
|
|
40
|
-
"System Maintenance Required",
|
|
41
|
-
"System maintenance is scheduled for tonight",
|
|
42
|
-
"system456",
|
|
43
|
-
EntityType.PROPERTY,
|
|
44
|
-
"admin"
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
// Create an operations alert
|
|
48
|
-
const operationsAlert = await this.alertService.raiseOperationsAlert(
|
|
49
|
-
"prop123",
|
|
50
|
-
"Device Temperature High",
|
|
51
|
-
"Device temperature exceeds normal operating range",
|
|
52
|
-
"device789",
|
|
53
|
-
EntityType.DEVICE,
|
|
54
|
-
"monitor"
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
// Create a security alert
|
|
58
|
-
const securityAlert = await this.alertService.raiseSecurityAlert(
|
|
59
|
-
"prop123",
|
|
60
|
-
"Unauthorized Access Attempt",
|
|
61
|
-
"Multiple failed login attempts detected",
|
|
62
|
-
"user123",
|
|
63
|
-
EntityType.USER,
|
|
64
|
-
"security-system"
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
// Create an energy alert
|
|
68
|
-
const energyAlert = await this.alertService.raiseEnergyAlert(
|
|
69
|
-
"prop123",
|
|
70
|
-
"High Energy Consumption",
|
|
71
|
-
"Energy usage is 20% above normal levels",
|
|
72
|
-
"zone456",
|
|
73
|
-
EntityType.COLLECTION,
|
|
74
|
-
"energy-monitor"
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
return { readinessAlert, operationsAlert, securityAlert, energyAlert };
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Example 3: Using device-specific alert methods
|
|
82
|
-
*/
|
|
83
|
-
async createDeviceAlerts() {
|
|
84
|
-
// Create a device alert with default category and severity
|
|
85
|
-
const deviceAlert1 = await this.alertService.raiseDeviceAlert(
|
|
86
|
-
"device123",
|
|
87
|
-
"prop456",
|
|
88
|
-
"Device Battery Low",
|
|
89
|
-
"Device battery level is below 20%",
|
|
90
|
-
undefined, // Use default category
|
|
91
|
-
undefined, // Use default severity
|
|
92
|
-
Source.CLOUD_EVENT
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
// Create a device alert with custom category and severity
|
|
96
|
-
const deviceAlert2 = await this.alertService.raiseDeviceAlert(
|
|
97
|
-
"device789",
|
|
98
|
-
"prop456",
|
|
99
|
-
"Device Firmware Update Available",
|
|
100
|
-
"New firmware version is available for installation",
|
|
101
|
-
AlertCategory.READINESS,
|
|
102
|
-
AlertSeverity.MEDIUM,
|
|
103
|
-
Source.CLOUD_EVENT
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
return { deviceAlert1, deviceAlert2 };
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Example 4: Using hub-specific alert methods
|
|
111
|
-
*/
|
|
112
|
-
async createHubAlerts() {
|
|
113
|
-
// Create a hub alert with default settings
|
|
114
|
-
const hubAlert1 = await this.alertService.raiseHubAlert(
|
|
115
|
-
"hub123",
|
|
116
|
-
"prop456",
|
|
117
|
-
"Hub Connection Lost",
|
|
118
|
-
"Hub has lost connection to the network",
|
|
119
|
-
undefined, // Use default category
|
|
120
|
-
undefined, // Use default severity
|
|
121
|
-
"network-monitor"
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
// Create a hub alert with custom settings
|
|
125
|
-
const hubAlert2 = await this.alertService.raiseHubAlert(
|
|
126
|
-
"hub789",
|
|
127
|
-
"prop456",
|
|
128
|
-
"Hub Maintenance Required",
|
|
129
|
-
"Hub requires scheduled maintenance",
|
|
130
|
-
AlertCategory.READINESS,
|
|
131
|
-
AlertSeverity.LOW,
|
|
132
|
-
"maintenance-system"
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
return { hubAlert1, hubAlert2 };
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Example 5: Using static factory methods with AlertBuilder
|
|
140
|
-
*/
|
|
141
|
-
async createAlertsWithStaticMethods() {
|
|
142
|
-
// Create a device alert using static factory method
|
|
143
|
-
const deviceAlert = AlertBuilder.createDeviceAlert("device123", "prop456")
|
|
144
|
-
.setCategory(AlertCategory.OPERATIONS)
|
|
145
|
-
.setTitle("Device Offline")
|
|
146
|
-
.setDescription("Device has been offline for more than 5 minutes")
|
|
147
|
-
.setSeverity(AlertSeverity.HIGH)
|
|
148
|
-
.setCreatedBy("monitor");
|
|
149
|
-
|
|
150
|
-
const alert1 = await this.alertService.createAlert(deviceAlert);
|
|
151
|
-
|
|
152
|
-
// Create a hub alert using static factory method
|
|
153
|
-
const hubAlert = AlertBuilder.createHubAlert("hub789", "prop202")
|
|
154
|
-
.setCategory(AlertCategory.SECURITY)
|
|
155
|
-
.setTitle("Hub Security Breach")
|
|
156
|
-
.setDescription("Unauthorized access attempt detected on hub")
|
|
157
|
-
.setSeverity(AlertSeverity.CRITICAL)
|
|
158
|
-
.setCreatedBy("security-system");
|
|
159
|
-
|
|
160
|
-
const alert2 = await this.alertService.createAlert(hubAlert);
|
|
161
|
-
|
|
162
|
-
return { alert1, alert2 };
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Example 6: Creating multiple alerts efficiently
|
|
167
|
-
*/
|
|
168
|
-
async createMultipleAlerts() {
|
|
169
|
-
const alerts = [];
|
|
170
|
-
|
|
171
|
-
// Create multiple device alerts efficiently
|
|
172
|
-
const deviceIds = ["device1", "device2", "device3"];
|
|
173
|
-
const propertyId = "prop123";
|
|
174
|
-
|
|
175
|
-
for (const deviceId of deviceIds) {
|
|
176
|
-
const alertBuilder = AlertBuilder.createDeviceAlert(deviceId, propertyId)
|
|
177
|
-
.setCategory(AlertCategory.OPERATIONS)
|
|
178
|
-
.setTitle(`Device ${deviceId} Status`)
|
|
179
|
-
.setDescription(`Status check for device ${deviceId}`)
|
|
180
|
-
.setSeverity(AlertSeverity.MEDIUM)
|
|
181
|
-
.setCreatedBy("batch-processor");
|
|
182
|
-
|
|
183
|
-
const alert = await this.alertService.createAlert(alertBuilder);
|
|
184
|
-
alerts.push(alert);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return alerts;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Example 7: Creating alerts with snooze functionality
|
|
192
|
-
*/
|
|
193
|
-
async createSnoozedAlert() {
|
|
194
|
-
const snoozeUntil = new Date();
|
|
195
|
-
snoozeUntil.setHours(snoozeUntil.getHours() + 2); // Snooze for 2 hours
|
|
196
|
-
|
|
197
|
-
const alertBuilder = new AlertBuilder()
|
|
198
|
-
.setCategory(AlertCategory.OTHER)
|
|
199
|
-
.setPropertyId("prop303")
|
|
200
|
-
.setTitle("Scheduled Maintenance")
|
|
201
|
-
.setDescription("System maintenance scheduled for tonight")
|
|
202
|
-
.setEntityType(EntityType.PROPERTY)
|
|
203
|
-
.setSeverity(AlertSeverity.INFO)
|
|
204
|
-
.setCreatedBy("admin")
|
|
205
|
-
.setSnoozeUntil(snoozeUntil);
|
|
206
|
-
|
|
207
|
-
const alert = await this.alertService.createAlert(alertBuilder);
|
|
208
|
-
return alert;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Example 8: Backward compatibility - still works with CreateAlertData
|
|
213
|
-
*/
|
|
214
|
-
async createAlertWithLegacyData() {
|
|
215
|
-
const alertData = {
|
|
216
|
-
category: [AlertCategory.OPERATIONS],
|
|
217
|
-
propertyId: "prop123",
|
|
218
|
-
title: "Legacy Alert",
|
|
219
|
-
description:
|
|
220
|
-
"This alert was created using the old CreateAlertData format",
|
|
221
|
-
entityId: "device456",
|
|
222
|
-
entityType: EntityType.DEVICE,
|
|
223
|
-
severity: AlertSeverity.MEDIUM,
|
|
224
|
-
createdBy: "legacy-system",
|
|
225
|
-
source: Source.CLOUD_EVENT,
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
// This still works with the updated createAlert method
|
|
229
|
-
const alert = await this.alertService.createAlert(alertData);
|
|
230
|
-
return alert;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { EntityType } from "../issues/issue.types";
|
|
2
|
-
|
|
3
|
-
export enum AlertCategory {
|
|
4
|
-
READINESS = "READINESS",
|
|
5
|
-
OPERATIONS = "OPERATIONS",
|
|
6
|
-
SECURITY = "SECURITY",
|
|
7
|
-
ENERGY = "ENERGY",
|
|
8
|
-
OTHER = "OTHER",
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export enum AlertSeverity {
|
|
12
|
-
INFO = "INFO",
|
|
13
|
-
LOW = "LOW",
|
|
14
|
-
MEDIUM = "MEDIUM",
|
|
15
|
-
HIGH = "HIGH",
|
|
16
|
-
CRITICAL = "CRITICAL",
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface AlertDocument {
|
|
20
|
-
_id: string;
|
|
21
|
-
category: AlertCategory[];
|
|
22
|
-
propertyId: string;
|
|
23
|
-
title: string;
|
|
24
|
-
description: string;
|
|
25
|
-
entityId?: string;
|
|
26
|
-
entityType: EntityType;
|
|
27
|
-
severity: AlertSeverity;
|
|
28
|
-
isRead: boolean;
|
|
29
|
-
isActive: boolean;
|
|
30
|
-
isDeleted: boolean;
|
|
31
|
-
snoozeUntil?: Date;
|
|
32
|
-
createdBy?: string;
|
|
33
|
-
updatedBy?: string;
|
|
34
|
-
createdAt: Date;
|
|
35
|
-
updatedAt: Date;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface CreateAlertData {
|
|
39
|
-
category: AlertCategory[];
|
|
40
|
-
propertyId: string;
|
|
41
|
-
title: string;
|
|
42
|
-
description: string;
|
|
43
|
-
entityId?: string;
|
|
44
|
-
entityType: EntityType;
|
|
45
|
-
severity?: AlertSeverity;
|
|
46
|
-
createdBy?: string;
|
|
47
|
-
snoozeUntil?: Date;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface UpdateAlertData {
|
|
51
|
-
category?: AlertCategory[];
|
|
52
|
-
title?: string;
|
|
53
|
-
description?: string;
|
|
54
|
-
entityId?: string;
|
|
55
|
-
entityType?: EntityType;
|
|
56
|
-
severity?: AlertSeverity;
|
|
57
|
-
isRead?: boolean;
|
|
58
|
-
isActive?: boolean;
|
|
59
|
-
snoozeUntil?: Date;
|
|
60
|
-
updatedBy?: string;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Re-export EntityType from issue.types.ts to avoid duplication
|
|
64
|
-
export { EntityType } from "../issues/issue.types";
|
package/src/alerts/index.ts
DELETED