UNPKG

dt-common-device

Version:

A secure and robust device management library for IoT applications

97 lines (96 loc) 2.85 kB
import { EntitySubType } from "../issues"; import { CreateAlertData, AlertCategory, AlertSeverity, EntityType, AlertType } from "./alert.types"; /** * AlertBuilder - A builder pattern implementation for constructing CreateAlertData objects * * This builder provides a fluent interface for creating alert data with proper validation * and default values. It follows the Builder pattern which is a standard design pattern * in TypeScript for constructing complex objects. * * Usage example: * const alertData = new AlertBuilder() * .setCategory(AlertCategory.OPERATIONS) * .setPropertyId("prop123") * .setTitle("Device Offline") * .setDescription("Device has been offline for more than 5 minutes") * .setEntityId("device456") * .setEntityType(EntityType.DEVICE) * .setSeverity(AlertSeverity.HIGH) * .setCreatedBy("user789") * .build(); */ export declare class AlertBuilder { private data; /** * Sets the alert category */ setCategory(category: AlertCategory): this; /** * Sets the property ID */ setPropertyId(propertyId: string): this; /** * Sets the zone ID */ setZoneId(zoneId: string): this; /** * Sets the alert title */ setTitle(title: string): this; /** * Sets the alert description */ setDescription(description: string): this; /** * Sets the entity ID (optional) */ setEntityId(entityId?: string): this; /** * Sets the entity type */ setEntityType(entityType: EntityType): this; /** * Sets the entity sub type */ setEntitySubType(entitySubType: EntitySubType): this; /** * Sets the alert severity (optional, defaults to LOW) */ setSeverity(severity?: AlertSeverity): this; /** * Sets the alert type (optional) */ setType(type?: AlertType): this; /** * Sets the user who created the alert (optional) */ setCreatedBy(createdBy?: string): this; /** * Sets the snooze until date (optional) */ setSnoozeUntil(snoozeUntil?: Date): this; /** * Validates that all required fields are present */ private validate; /** * Builds and returns the CreateAlertData object * @throws Error if required fields are missing */ build(): CreateAlertData; /** * Resets the builder to its initial state */ reset(): this; static createOperationsAlert(): AlertBuilder; static createSecurityAlert(): AlertBuilder; static createEnergyAlert(): AlertBuilder; /** * Creates a device-specific alert builder */ static createDeviceAlert(deviceId: string, propertyId: string): AlertBuilder; /** * Creates a hub-specific alert builder */ static createHubAlert(hubId: string, propertyId: string): AlertBuilder; }