UNPKG

unleash-server

Version:

Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.

64 lines 2.77 kB
import { IAuthType, } from '../server-impl.js'; import { simpleAuthSettingsKey, } from '../types/settings/simple-auth-settings.js'; import version from '../util/version.js'; export class UiConfigService { constructor(config, { versionService, settingService, emailService, frontendApiService, maintenanceService, sessionService, resourceLimitsService, }) { this.config = config; this.flagResolver = config.flagResolver; this.versionService = versionService; this.settingService = settingService; this.emailService = emailService; this.frontendApiService = frontendApiService; this.maintenanceService = maintenanceService; this.sessionService = sessionService; this.resourceLimitsService = resourceLimitsService; } async getMaxSessionsCount() { if (this.flagResolver.isEnabled('showUserDeviceCount')) { return this.sessionService.getMaxSessionsCount(); } return 0; } async getUiConfig(user) { const [frontendSettings, simpleAuthSettings, maintenanceMode, maxSessionsCount,] = await Promise.all([ this.frontendApiService.getFrontendSettings(false), this.settingService.get(simpleAuthSettingsKey), this.maintenanceService.isMaintenanceMode(), this.getMaxSessionsCount(), ]); const disablePasswordAuth = simpleAuthSettings?.disabled || this.config.authentication.type === IAuthType.NONE; const expFlags = this.config.flagResolver.getAll({ email: user.email, }); const flags = { ...this.config.ui.flags, ...expFlags, }; const unleashContext = { ...this.flagResolver.getStaticContext(), email: user.email, userId: user.id, }; const uiConfig = { ...this.config.ui, flags, version, emailEnabled: this.emailService.isEnabled(), unleashUrl: this.config.server.unleashUrl, baseUriPath: this.config.server.baseUriPath, authenticationType: this.config.authentication?.type, frontendApiOrigins: frontendSettings.frontendApiOrigins, versionInfo: await this.versionService.getVersionInfo(), prometheusAPIAvailable: this.config.prometheusApi !== undefined, resourceLimits: await this.resourceLimitsService.getResourceLimits(), disablePasswordAuth, maintenanceMode, feedbackUriPath: this.config.feedbackUriPath, maxSessionsCount, unleashContext: unleashContext, }; return uiConfig; } } //# sourceMappingURL=ui-config-service.js.map