UNPKG

breathe-api

Version:

Model Context Protocol server for Breathe HR APIs with Swagger/OpenAPI support - also works with custom APIs

81 lines 3.07 kB
import { createPassword, sanitizeForLogging } from '../types/security.js'; class CredentialManager { credentials = {}; initialized = false; initialize() { if (this.initialized) { return; } const breatheUsername = process.env.BREATHE_API_USERNAME; const breathePassword = process.env.BREATHE_API_PASSWORD; if (breatheUsername && breathePassword) { this.credentials.breatheUsername = breatheUsername; this.credentials.breathePassword = createPassword(breathePassword); } const elmoUsername = process.env.ELMO_API_USERNAME || breatheUsername; const elmoPassword = process.env.ELMO_API_PASSWORD || breathePassword; if (elmoUsername && elmoPassword) { this.credentials.elmoUsername = elmoUsername; this.credentials.elmoPassword = createPassword(elmoPassword); } this.initialized = true; console.error('Credential Manager initialized:'); console.error(`- Breathe HR: ${breatheUsername ? 'configured' : 'not configured'}`); console.error(`- ELMO API: ${elmoUsername ? 'configured' : 'not configured'}`); } getBreatheCredentials() { if (!this.initialized) { this.initialize(); } if (this.credentials.breatheUsername && this.credentials.breathePassword) { return { username: this.credentials.breatheUsername, password: this.credentials.breathePassword, }; } return null; } getElmoCredentials() { if (!this.initialized) { this.initialize(); } if (this.credentials.elmoUsername && this.credentials.elmoPassword) { return { username: this.credentials.elmoUsername, password: this.credentials.elmoPassword, }; } return null; } hasCredentials(api) { if (!this.initialized) { this.initialize(); } if (api === 'breathe') { return !!(this.credentials.breatheUsername && this.credentials.breathePassword); } else { return !!(this.credentials.elmoUsername && this.credentials.elmoPassword); } } getCredentialStatus() { if (!this.initialized) { this.initialize(); } return { breathe: this.hasCredentials('breathe') ? `${this.credentials.breatheUsername} (password: ${sanitizeForLogging(this.credentials.breathePassword)})` : 'not configured', elmo: this.hasCredentials('elmo') ? `${this.credentials.elmoUsername} (password: ${sanitizeForLogging(this.credentials.elmoPassword)})` : 'not configured', }; } clearCredentials() { this.credentials = {}; this.initialized = false; } } export const credentialManager = new CredentialManager(); credentialManager.initialize(); //# sourceMappingURL=credential-manager.js.map