import { ManagerOptions } from 'socket.io-client'; import { Socket } from 'socket.io-client'; import { SocketOptions as SocketOptions_2 } from 'socket.io-client'; export declare const ActionIDEnum: Record; export declare type ActionKey = keyof typeof ActionNameEnum export declare type ActionName = typeof ActionNameEnum[ActionKey] export declare const ActionNameEnum: { readonly CREATE: "Create"; readonly READ: "Read"; readonly UPDATE: "Update"; readonly DELETE: "Delete"; readonly CONVERT: "Convert"; readonly DOWNLOAD: "Download"; readonly UPLOAD: "Upload"; readonly ENCRYPT: "Encrypt"; readonly DECRYPT: "Decrypt"; readonly FILTER: "Filter"; readonly INPUT: "Input"; readonly OUTPUT: "Output"; readonly PLUGIN: "Plugin"; readonly LOGIN: "Login"; readonly LOGOUT: "Logout"; readonly REFRESH: "Refresh"; readonly CHECK: "Check"; readonly WEBHOOK: "Webhook"; readonly WSCONNECT: "WSConnect"; }; declare type ActionNameEnumType = typeof ActionNameEnum; /** * Abstract base class for storage workers that provides a consistent interface * for different storage backends (localStorage, IndexedDB, Redis, remote storage, etc.). * * All storage operations are async to support both synchronous and asynchronous * storage implementations. For synchronous storage (like localStorage), the * async functions will automatically wrap return values in Promises. * * @abstract * @example * ```typescript * // Implementation for localStorage * class LocalStorageWorker extends BaseStorageWorker { * // Debug logging function, the StorageLogger will pass its function here, it can be used for debugging purposes * constructor(debugLog: DebugLogFunction) { * super(debugLog) * } * * async getItem(key: string): Promise { * // Example debug log usage * this.debugLog(`[LocalStorage] Getting item for key: ${key}`) * * return localStorage.getItem(key) // async automatically wraps in Promise * } * * async setItem(key: string, value: string): Promise { * localStorage.setItem(key, value) // no return needed for void * } * * async removeItem(key: string): Promise { * localStorage.removeItem(key) * } * * async getAllKeys(): Promise { * return Object.keys(localStorage) * } * } * ``` */ export declare abstract class BaseStorageWorker { protected debugLog: DebugLogFunction; /** * @param debugLog - Debug logging function. If not provided, debugging is disabled. */ protected constructor(debugLog: DebugLogFunction); /** * Retrieves an item from storage by its key. * * @param key - The unique identifier for the stored item * @returns A promise that resolves to the stored value as a string, or null if the key doesn't exist * * @example * ```typescript * const value = await storageWorker.getItem('user-settings') * if (value !== null) { * const settings = JSON.parse(value) * // Use settings... * } * ``` */ abstract getItem(key: string): Promise; /** * Stores an item in storage with the specified key. * If the key already exists, the value will be overwritten. * * @param key - The unique identifier for the item to store * @param value - The string value to store (use JSON.stringify for objects) * @returns A promise that resolves when the item has been successfully stored * @throws {Error} May throw if storage quota is exceeded or storage is unavailable * * @example * ```typescript * const settings = { theme: 'dark', language: 'en' } * await storageWorker.setItem('user-settings', JSON.stringify(settings)) * ``` */ abstract setItem(key: string, value: string): Promise; /** * Removes an item from storage by its key. * If the key doesn't exist, this operation should complete successfully without error. * * @param key - The unique identifier of the item to remove * @returns A promise that resolves when the item has been successfully removed * * @example * ```typescript * await storageWorker.removeItem('temporary-data') * ``` */ abstract removeItem(key: string): Promise; /** * Retrieves all keys currently stored in the storage. * This is useful for operations like cleanup, migration, or listing stored items. * * @returns A promise that resolves to an array of all keys in storage * * @example * ```typescript * const keys = await storageWorker.getAllKeys() * console.log(`Found ${keys.length} items in storage:`, keys) * * // Remove all items older than a certain date * const oldKeys = keys.filter(key => key.startsWith('log-2023-')) * for (const key of oldKeys) { * await storageWorker.removeItem(key) * } * ``` */ abstract getAllKeys(): Promise; } export declare interface ConfigOptions { /** * This defines the initialized socket socket-io connection. */ socket?: Socket /** * This defines the socket connection url. */ url?: string /** * This defines the url for https logger requests. */ requestUrl?: string /** * This defines initializing configuration options for socket-io connection. */ socketOptions?: SocketOptions /** * This defines the configuration options for logger. */ loggerOptions: LoggerOptions } export declare type ConsoleMethod = (this: Console, ...data: Array) => void /** * Type for the debug logging function that will be passed to storage workers */ export declare type DebugLogFunction = (message: string, ...data: unknown[]) => void; export declare const defaultConnectOptions: SocketOptions; export declare const defaultLoggerOptions: { logToConsole: boolean; overloadGlobalConsole: boolean; socketEmitInterval: number; }; export declare type EntityID = typeof EntityIDEnum[keyof typeof EntityIDEnum] export declare const EntityIDEnum: { readonly USER: "User ID"; readonly ACCOUNT: "Account ID"; readonly EXTENSION: "Extension ID"; readonly CAMPAIGN: "Campaign ID"; readonly QUEUE: "Queue ID"; }; export declare type EntityType = typeof EntityTypeEnum[keyof typeof EntityTypeEnum] export declare const EntityTypeEnum: { readonly USER: "User"; readonly ACCOUNT: "Account"; readonly EXTENSION: "Extension"; readonly CAMPAIGN: "Campaign"; readonly QUEUE: "Queue"; }; export declare type IdentityID = typeof IdentityIDEnum[keyof typeof IdentityIDEnum] export declare const IdentityIDEnum: { readonly USER: "UserID"; readonly ACCOUNT: "AccountID"; readonly EXTENSION: "ExtensionID"; }; export declare type IdentityName = typeof IdentityNameEnum[keyof typeof IdentityNameEnum] export declare const IdentityNameEnum: { readonly USER: "UserName"; readonly ACCOUNT: "AccountName"; readonly EXTENSION: "ExtensionName"; }; export declare type IdentityType = typeof IdentityTypeEnum[keyof typeof IdentityTypeEnum] export declare const IdentityTypeEnum: { readonly USER: "User"; readonly ACCOUNT: "Account"; }; export declare type Level = typeof LevelEnum[keyof typeof LevelEnum] export declare const LevelEnum: { readonly INFO: "info"; readonly WARNING: "warning"; readonly ERROR: "error"; readonly DEBUG: "debug"; }; export declare class LocalStorageWorker extends BaseStorageWorker { constructor(debugLog: DebugLogFunction); getItem(key: string): Promise; setItem(key: string, value: string): Promise; removeItem(key: string): Promise; getAllKeys(): Promise; } export declare interface LoggerBaseData { DateTime: Date System: string UserAgent?: string OSVersion?: string } export declare type LoggerData = Omit export declare type LoggerDataInner = LoggerBaseData & LoggerMainParameters export declare type LoggerDataPartial = Partial export declare type LoggerLevelMap = Record> export declare interface LoggerMainParameters { Subsystem: string Fingerprint?: string TopDistributorID?: string IdentityType?: IdentityType IdentityID?: IdentityID IdentityName: IdentityName EntityID?: EntityID EntityType?: EntityType Message: string ActionName?: ActionName isShowClient?: boolean Status?: string StatusCode?: number RequestID?: string LogType?: LogType Level?: Level ForwardedIP?: string DestinationIP?: string Host?: string ServerName?: string Body?: string | Record ActionID?: number Version?: string MachineName?: string SIPUser?: string Response?: string Method?: string Topic?: string } export declare interface LoggerOptions { /** * This defines if logger should contain default behavior like logging data to console. */ logToConsole: boolean /** * This defines if the global console object should be overloaded with logger functionality. */ overloadGlobalConsole: boolean /** * This defines the system namespace for the storage key. * This value should be unique across the projects. */ system: string /** * This defines the interval for sending logs using sockets in milliseconds. */ socketEmitInterval: number /** * The storage worker class that will be used to store logs. * * **REQUIRED** - You must provide a storage worker appropriate for your environment. * * @example * ```typescript * import StorageLogger, { LocalStorageWorker } from '@voicenter-team/socketio-storage-logger' * * // ✅ Browser environment with localStorage * const logger = new StorageLogger({ * loggerOptions: { * system: 'MyApp', * storageWorker: LocalStorageWorker * } * }) * * // ✅ Node.js environment with custom storage * class FileSystemStorageWorker extends BaseStorageWorker { * constructor(debugLog: DebugLogFunction) { * super(debugLog) * } * // ... implement with fs operations * } * * const logger = new StorageLogger({ * loggerOptions: { * system: 'MyApp', * storageWorker: FileSystemStorageWorker * } * }) * ``` */ storageWorker: StorageWorkerConstructor /** * The level of the logger. * If not provided, the default level is 'debug'. * Filters which logs will be sent to the server. * * - If "debug" is set, all logs will be sent. * - If "info" is set, only info, warning and error logs will be sent. * - If "warning" is set, only warning and error logs will be sent. * - If "error" is set, only error logs will be sent. */ loggerLevel?: Level /** * A static object that can optionally hold partial logger data. * The data set here will be sent in each log if not overridden by log data. */ staticObject?: LoggerDataPartial /** * A prefix to be added to local debug logs */ debugPrefix?: string } export declare type LogType = typeof LogTypeEnum[keyof typeof LogTypeEnum] export declare const LogTypeEnum: { readonly INFO: "info"; readonly WARNING: "warning"; readonly MODIFY: "modify"; readonly ERROR: "error"; readonly VIEW: "view"; }; export declare type MainParametersPartial = Partial export declare type SocketOptions = Partial declare class StorageLogger { private readonly logToConsole; private readonly overloadGlobalConsole; system: string; socketEmitInterval: number; private readonly storageId; private loggerLevel; private isActive; private readonly loggerLevelMap; private emitInProgress; private queue; private processing; private storageInitialized; private interval; private logIndex; private socket; private requestUrl; private staticObject; private localObject; private readonly storageWorker; private _logMethod; private _warnMethod; private _errorMethod; private _debugMethod; private loggerDebugEnabled; private readonly debugPrefix; /** * Initialize storage logger * @param options The configuration of the logger. */ constructor(options: ConfigOptions); /** * Migrates logs from old storage keys to the current storage key. * This prevents logs from being orphaned when the storage logger reinitialized. * @private */ private migrateOldLogs; /** * Enable or disable internal debug logging * @param enabled Boolean indicating whether debug logging should be enabled */ toggleDebugLogging(enabled: boolean): void; /** * Check if debug logging is enabled * @returns Boolean indicating whether debug logging is enabled */ isDebugLoggingEnabled(): boolean; /** * Internal method for debug logging * @param message The message to log * @param data Optional data to log */ private internalDebugLog; get currentLoggerLevelLogLevels(): Level[]; /** * The level of the logger. * If not provided, the default level is 'debug'. * Filters which logs will be sent to the server. * * - If "debug" is set, all logs will be sent. * - If "info" is set, only info, warning and error logs will be sent. * - If "warning" is set, only warning and error logs will be sent. * - If "error" is set, only error logs will be sent. */ changeLogLevel(level: Level): void; private isLogLevel; isLogLevelAllowed(level: Level): boolean; /** * Used to send http log request. * @param logs logs array which is sent in request body. * @return {Promise} */ private sendHttpRequest; /** * Used to initialize logger. Initializes storage, establishes socket connection and overloads console if needed * @param options The logger config. * @return void */ private init; /** * Used to initialize new socket connection * @param url The url used for the socket connection. * @param options The options used for the socket connection. * @return void */ private createConnection; /** * Emits stored logs to the server and clears the log storage in case the emit operation was successful * @return {Promise} */ emitLogs(): Promise; /** * Used to set additional properties for every sending log * @return LoggerDataInner */ private populateSendingLog; /** * Used to set a static object which will be send in every message * @return void */ setupStaticFields(data: LoggerDataPartial): void; /** * Used to update a static object which will be send in every message * @return void */ updateStaticFields(data: LoggerDataPartial): void; /** * Used to populate sending message object with static client parameters * @return object */ private populateMetaData; /** * Used to stop logger and interrupt socket connection * @return void */ stop(): Promise; /** * Used to start logger and reconnect socket connection * @return void */ start(): Promise; /** * Used to overload the global console object by logger methods. * @return void */ private _overloadConsole; /** * Used to initialize the storage if it wasn't created before. * Also migrates any orphaned logs from previous sessions. * @return void */ private initStorage; /** * Reset log storage * @return void */ resetStorage(): Promise; /** * Get storage name which is used to access the logs storage * @return string */ private getStorageName; /** * Does common logic for logging data. * @param args The arguments of the log where the first argument contains the log level and other * arguments are logs to be stored * @return void */ private processLog; /** * Used to process logs queue. * @return Promise */ private processQueue; /** * Logs info data into the storage * @param logData The arguments to be logged. * @return void */ log(logData: DataType): void; /** * Logs warn data into the storage * @param logData The arguments to be logged. * @return void */ warn(logData: DataType): void; /** * Logs error data into the storage * @param logData The arguments to be logged. * @return void */ error(logData: DataType): void; /** * Logs debug data into the storage * @param logData The arguments to be logged. * @return void */ debug(logData: DataType): void; /** * Used to form a key which will be used to store a log in the storage * @param level The log level. For example: Info, Warn, Error etc.. * @return string */ private formItemKey; } export default StorageLogger; /** * Alternative type if you want to be more strict about additional parameters */ export declare type StorageWorkerConstructor = new (debugLog: DebugLogFunction) => BaseStorageWorker; export { }