/** * Feature Module Interface * * Defines the contract that all feature modules must implement. * This enables a plugin-like architecture for the SDK. * * @module types/IFeatureModule */ import type { Wallet } from '../core/Wallet'; import type { Logger } from '../utils/logger'; import { Environment } from './SDKConfig'; /** * Base configuration type that all feature configs must extend */ export interface IFeatureConfig { /** Feature name */ name: string; /** Whether the feature is enabled */ enabled: boolean; /** SDK environment (testnet or mainnet) */ environment: Environment; } /** * Feature module interface * All feature modules (Gas-Free, Watch-Tower, etc.) must implement this interface. * This allows the SDK to manage features in a uniform way. */ export interface IFeatureModule< TConfig extends IFeatureConfig = IFeatureConfig > { /** * Feature name (must match config.name) */ readonly name: string; /** * Feature configuration */ readonly config: TConfig; /** * Initialize the feature module * * Called when the SDK is initialized. The feature should perform * any necessary setup here. * * @param wallet - Optional Wallet instance for features that need RGB operations * @param logger - Logger instance for consistent logging * @returns Promise that resolves when initialization is complete */ initialize(wallet?: Wallet, logger?: Logger): Promise; /** * Cleanup and release resources * * Called when the SDK is shutting down or the feature is being disabled. * The feature should cleanup any resources, close connections, etc. * * @returns Promise that resolves when cleanup is complete */ cleanup(): Promise; /** * Check if the feature is initialized and ready to use * * @returns True if the feature is ready, false otherwise */ isReady(): boolean; /** * Get the current status of the feature * * @returns Status information (implementation-specific) */ getStatus(): { enabled: boolean; ready: boolean; [key: string]: unknown; }; } /** * Type guard to check if an object implements IFeatureModule */ export function isFeatureModule(obj: unknown): obj is IFeatureModule { if (!obj || typeof obj !== 'object') { return false; } const module = obj as Partial; return ( typeof module.name === 'string' && typeof module.config === 'object' && typeof module.initialize === 'function' && typeof module.cleanup === 'function' && typeof module.isReady === 'function' && typeof module.getStatus === 'function' ); }