dt-common-device
Version:
A secure and robust device management library for IoT applications
88 lines (87 loc) • 2.76 kB
TypeScript
import { CreateAlertData, AlertCategory, AlertSeverity, EntityType } from "../../../types/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): AlertBuilder;
/**
* Sets the property ID
*/
setPropertyId(propertyId: string): AlertBuilder;
/**
* Sets the alert title
*/
setTitle(title: string): AlertBuilder;
/**
* Sets the alert description
*/
setDescription(description: string): AlertBuilder;
/**
* Sets the entity ID (optional)
*/
setEntityId(entityId?: string): AlertBuilder;
/**
* Sets the entity type
*/
setEntityType(entityType: EntityType): AlertBuilder;
/**
* Sets the alert severity (optional, defaults to MEDIUM)
*/
setSeverity(severity?: AlertSeverity): AlertBuilder;
/**
* Sets the user who created the alert (optional)
*/
setCreatedBy(createdBy?: string): AlertBuilder;
/**
* Sets the snooze until date (optional)
*/
setSnoozeUntil(snoozeUntil?: Date): AlertBuilder;
/**
* 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(): AlertBuilder;
/**
* Creates a new builder instance with predefined values for common alert types
*/
static createReadinessAlert(): AlertBuilder;
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;
}