UNPKG

unleash-server

Version:

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

73 lines 3.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InstanceStatsService = void 0; const js_sha256_1 = require("js-sha256"); class InstanceStatsService { constructor({ featureToggleStore, userStore, projectStore, environmentStore, strategyStore, contextFieldStore, groupStore, segmentStore, roleStore, settingStore, }, { getLogger }, versionService) { this.strategyStore = strategyStore; this.userStore = userStore; this.featureToggleStore = featureToggleStore; this.environmentStore = environmentStore; this.projectStore = projectStore; this.groupStore = groupStore; this.contextFieldStore = contextFieldStore; this.segmentStore = segmentStore; this.roleStore = roleStore; this.versionService = versionService; this.settingStore = settingStore; this.logger = getLogger('services/stats-service.js'); } async getToggleCount() { return this.featureToggleStore.count({ archived: false, }); } async hasOIDC() { const settings = await this.settingStore.get('unleash.enterprise.auth.oidc'); return settings?.enabled || false; } async hasSAML() { const settings = await this.settingStore.get('unleash.enterprise.auth.saml'); return settings?.enabled || false; } async getStats() { const versionInfo = this.versionService.getVersionInfo(); const [featureToggles, users, projects, contextFields, groups, roles, environments, segments, strategies, SAMLenabled, OIDCenabled,] = await Promise.all([ this.getToggleCount(), this.userStore.count(), this.projectStore.count(), this.contextFieldStore.count(), this.groupStore.count(), this.roleStore.count(), this.environmentStore.count(), this.segmentStore.count(), this.strategyStore.count(), this.hasSAML(), this.hasOIDC(), ]); return { timestamp: new Date(), instanceId: versionInfo.instanceId, versionOSS: versionInfo.current.oss, versionEnterprise: versionInfo.current.enterprise, users, featureToggles, projects, contextFields, roles, groups, environments, segments, strategies, SAMLenabled, OIDCenabled, }; } async getSignedStats() { const instanceStats = await this.getStats(); const sum = (0, js_sha256_1.sha256)(`${instanceStats.instanceId}${instanceStats.users}${instanceStats.featureToggles}${instanceStats.projects}${instanceStats.roles}${instanceStats.groups}${instanceStats.environments}${instanceStats.segments}`); return { ...instanceStats, sum }; } } exports.InstanceStatsService = InstanceStatsService; //# sourceMappingURL=instance-stats-service.js.map