UNPKG

unleash-server

Version:

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

38 lines 2.08 kB
import { PermissionError, SKIP_CHANGE_REQUEST, } from '../../server-impl.js'; export class ReleasePlanMilestoneStrategyService { constructor({ releasePlanMilestoneStrategyStore: milestoneStrategyStore, }, { featureToggleService, }, changeRequestAccessReadModel, { getLogger }) { this.logger = getLogger('services/release-plan-milestone-strategy-service.ts'); this.milestoneStrategyStore = milestoneStrategyStore; this.featureToggleService = featureToggleService; this.changeRequestAccessReadModel = changeRequestAccessReadModel; } async updateStrategy(id, strategy, context, auditUser, user) { await this.stopWhenChangeRequestsEnabled(context.projectId, context.environment, user); return this.unprotectedUpdateStrategy(id, strategy, context, auditUser, user); } async stopWhenChangeRequestsEnabled(project, environment, user) { const canBypass = await this.changeRequestAccessReadModel.canBypassChangeRequest(project, environment, user); if (!canBypass) { throw new PermissionError(SKIP_CHANGE_REQUEST); } } async unprotectedUpdateStrategy(id, strategy, context, auditUser, user) { const { projectId, environment, featureName } = context; await this.milestoneStrategyStore.get(id); // Validate milestone strategy exists let isActive; try { isActive = Boolean(await this.featureToggleService.getStrategy(id)); } catch { isActive = false; } const shouldSyncStrategies = isActive; if (shouldSyncStrategies) { await this.featureToggleService.unprotectedUpdateStrategy(id, strategy, { projectId, environment, featureName }, auditUser, user); } const updatedStrategy = await this.milestoneStrategyStore.upsert(id, strategy); this.logger.info(`${auditUser.username} updates milestone strategy ${id} for feature ${context.featureName}`); return updatedStrategy; } } //# sourceMappingURL=release-plan-milestone-strategy-service.js.map