/** * ExplodingMessageService — self-destructing message logic for BrightChain. * * Provides time-based and read-count-based message expiration with * secure deletion. Messages can be configured to auto-destruct after * a specified time or after being read a certain number of times. * * All methods are stateless and operate on message objects directly. * Persistence and scheduling are handled by the caller. * * Requirements: 8.1, 8.2, 8.3, 8.4, 8.7 */ import { CommunicationEventType } from '../../enumerations/communication'; import { ICommunicationMessage } from '../../interfaces/communication'; export declare class ExplodingMessageError extends Error { constructor(message: string); } export declare class MessageAlreadyExplodedError extends ExplodingMessageError { constructor(messageId: string); } export declare class InvalidExpirationError extends ExplodingMessageError { constructor(reason: string); } /** * Event emitted when a message explodes (is permanently deleted). */ export interface IExplodingMessageEvent { type: CommunicationEventType; messageId: string; contextId: string; contextType: 'conversation' | 'group' | 'channel'; reason: 'time_expired' | 'read_count_exceeded'; explodedAt: Date; } /** * Result of checking expired messages. */ export interface IExpiredMessagesResult { /** Messages that have expired and should be deleted */ expired: ICommunicationMessage[]; /** Events to emit for each expired message */ events: IExplodingMessageEvent[]; } /** * Service for managing self-destructing (exploding) messages. * * Supports two expiration modes: * - Time-based: message expires after a specified duration * - Read-count: message expires after being read N times * * Both modes can be combined on a single message. * * @example * ```typescript * // Set a 5-minute expiration * ExplodingMessageService.setExpiration(message, { * expiresInMs: 5 * 60 * 1000, * }); * * // Set a read-count limit * ExplodingMessageService.setExpiration(message, { * maxReads: 3, * }); * * // Mark as read by a member * ExplodingMessageService.markRead(message, 'member-123'); * * // Check if expired * const shouldExplode = ExplodingMessageService.checkExpiration(message); * ``` */ export declare class ExplodingMessageService { /** * Configure expiration settings on a message. * * @param message - The message to configure * @param options - Expiration options * @param options.expiresAt - Absolute expiration time * @param options.expiresInMs - Relative expiration (milliseconds from now) * @param options.maxReads - Maximum read count before expiration * @throws {MessageAlreadyExplodedError} If the message has already exploded * @throws {InvalidExpirationError} If no expiration option is provided * * Requirements: 8.1, 8.2 */ static setExpiration(message: ICommunicationMessage, options: { expiresAt?: Date; expiresInMs?: number; maxReads?: number; }): void; /** * Record that a member has read a message. * * Increments the read count and records the member's read timestamp. * If the member has already read the message, this is a no-op for * the read count but updates the timestamp. * * @param message - The message to mark as read * @param memberId - The ID of the member who read the message * @returns `true` if the message should now be exploded (read count exceeded) * @throws {MessageAlreadyExplodedError} If the message has already exploded * * Requirements: 8.2, 8.3 */ static markRead(message: ICommunicationMessage, memberId: string): boolean; /** * Check whether a message has expired based on its expiration settings. * * Checks both time-based and read-count-based expiration. * * @param message - The message to check * @param now - Optional current time (defaults to Date.now()) * @returns The reason for expiration, or `null` if not expired * * Requirements: 8.1, 8.2, 8.4 */ static checkExpiration(message: ICommunicationMessage, now?: Date): 'time_expired' | 'read_count_exceeded' | null; /** * Explode (permanently delete) a message. * * Clears the encrypted content and marks the message as exploded. * The message metadata is preserved for audit purposes. * * @param message - The message to explode * @returns The explosion event * @throws {MessageAlreadyExplodedError} If the message has already exploded * * Requirements: 8.4, 8.7 */ static explode(message: ICommunicationMessage): IExplodingMessageEvent; /** * Scan a collection of messages and find all that have expired. * * Returns the expired messages and the events to emit for each. * Does NOT modify the messages — call {@link explode} on each * returned message to actually delete them. * * @param messages - The messages to scan * @param now - Optional current time (defaults to Date.now()) * @returns The expired messages and their events * * Requirements: 8.4 */ static deleteExpired(messages: ReadonlyArray, now?: Date): IExpiredMessagesResult; /** * Check if a message is an exploding message (has any expiration configured). * * @param message - The message to check * @returns `true` if the message has expiration settings */ static isExplodingMessage(message: ICommunicationMessage): boolean; /** * Get the remaining time until a message expires (in milliseconds). * * @param message - The message to check * @param now - Optional current time * @returns Remaining time in ms, or `null` if no time-based expiration */ static getRemainingTime(message: ICommunicationMessage, now?: Date): number | null; /** * Get the remaining reads before a message expires. * * @param message - The message to check * @returns Remaining reads, or `null` if no read-count expiration */ static getRemainingReads(message: ICommunicationMessage): number | null; } //# sourceMappingURL=explodingMessageService.d.ts.map