UNPKG

@nexle-soft/quick-desk-client

Version:

Typescript Client for Quick desk's APIs

58 lines 1.97 kB
export class Configuration { constructor({ host, secretKey, }) { this.host = host; this.secretKey = secretKey; } // Singleton pattern with improved initialization check static getInstance(config) { // If instance does not exist and config is provided, create a new instance if (!Configuration.instance && config) { Configuration.instance = new Configuration(config); } // If instance does not exist and no config is provided, throw an error if (!Configuration.instance) { throw new Error("Configuration is not initialized. Please provide host and secretKey."); } return Configuration.instance; } // Method to check if configuration has been properly initialized static isInitialized() { return (Configuration.instance !== null && !!Configuration.instance.host && !!Configuration.instance.secretKey); } getHost() { this.ensureInitialized(); return this.host; } setHost(value) { this.ensureInitialized(); this.host = value; } getSecretKey() { this.ensureInitialized(); return this.secretKey; } setSecretKey(value) { this.ensureInitialized(); this.secretKey = value; } // Reinitialize the configuration with new values (optional) static reinitialize(config) { if (Configuration.instance) { Configuration.instance.host = config.host; Configuration.instance.secretKey = config.secretKey; } else { Configuration.instance = new Configuration(config); } } // Ensure that the instance has been initialized ensureInitialized() { if (!this.host || !this.secretKey) { throw new Error("Configuration is not properly initialized."); } } } Configuration.instance = null; //# sourceMappingURL=configuration.js.map