unleash-server
Version:
Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.
123 lines • 5.62 kB
JavaScript
import { UPDATE_FEATURE, } from '../../../types/index.js';
import { DELETE_FEATURE } from '../../../types/permissions.js';
import { emptyResponse, getStandardResponses, } from '../../../openapi/util/standard-responses.js';
import { createRequestSchema, createResponseSchema, } from '../../../openapi/index.js';
import Controller from '../../controller.js';
const PATH = '/:projectId';
const PATH_ARCHIVE = `${PATH}/archive`;
const PATH_VALIDATE_ARCHIVE = `${PATH}/archive/validate`;
const PATH_DELETE = `${PATH}/delete`;
const PATH_REVIVE = `${PATH}/revive`;
export default class ProjectArchiveController extends Controller {
constructor(config, { transactionalFeatureToggleService, featureToggleService, openApiService, }) {
super(config);
this.logger = config.getLogger('/admin-api/archive.js');
this.featureService = featureToggleService;
this.openApiService = openApiService;
this.flagResolver = config.flagResolver;
this.transactionalFeatureToggleService =
transactionalFeatureToggleService;
this.route({
method: 'post',
path: PATH_DELETE,
acceptAnyContentType: true,
handler: this.deleteFeatures,
permission: DELETE_FEATURE,
middleware: [
openApiService.validPath({
tags: ['Archive'],
operationId: 'deleteFeatures',
description: 'This endpoint deletes the specified features, that are in archive.',
summary: 'Deletes a list of features',
requestBody: createRequestSchema('batchFeaturesSchema'),
responses: {
200: emptyResponse,
...getStandardResponses(400, 401, 403),
},
}),
],
});
this.route({
method: 'post',
path: PATH_REVIVE,
acceptAnyContentType: true,
handler: this.reviveFeatures,
permission: UPDATE_FEATURE,
middleware: [
openApiService.validPath({
tags: ['Archive'],
operationId: 'reviveFeatures',
description: 'This endpoint revives the specified features.',
summary: 'Revives a list of features',
requestBody: createRequestSchema('batchFeaturesSchema'),
responses: {
200: emptyResponse,
...getStandardResponses(400, 401, 403),
},
}),
],
});
this.route({
method: 'post',
path: PATH_VALIDATE_ARCHIVE,
handler: this.validateArchiveFeatures,
permission: DELETE_FEATURE,
middleware: [
openApiService.validPath({
tags: ['Features'],
operationId: 'validateArchiveFeatures',
description: 'This endpoint return info about the archive features impact.',
summary: 'Validates archive features',
requestBody: createRequestSchema('batchFeaturesSchema'),
responses: {
200: createResponseSchema('validateArchiveFeaturesSchema'),
...getStandardResponses(400, 401, 403, 415),
},
}),
],
});
this.route({
method: 'post',
path: PATH_ARCHIVE,
handler: this.archiveFeatures,
permission: DELETE_FEATURE,
middleware: [
openApiService.validPath({
tags: ['Features'],
operationId: 'archiveFeatures',
description: "This endpoint archives the specified features. Any features that are already archived or that don't exist are ignored. All existing features (whether already archived or not) that are provided must belong to the specified project.",
summary: 'Archives a list of features',
requestBody: createRequestSchema('batchFeaturesSchema'),
responses: {
202: emptyResponse,
...getStandardResponses(400, 401, 403, 415),
},
}),
],
});
}
async deleteFeatures(req, res) {
const { projectId } = req.params;
const { features } = req.body;
await this.featureService.deleteFeatures(features, projectId, req.audit);
res.status(200).end();
}
async reviveFeatures(req, res) {
const { projectId } = req.params;
const { features } = req.body;
await this.transactionalFeatureToggleService.transactional((service) => service.reviveFeatures(features, projectId, req.audit));
res.status(200).end();
}
async archiveFeatures(req, res) {
const { features } = req.body;
const { projectId } = req.params;
await this.transactionalFeatureToggleService.transactional((service) => service.archiveToggles(features, req.user, req.audit, projectId));
res.status(202).end();
}
async validateArchiveFeatures(req, res) {
const { features } = req.body;
const { parentsWithChildFeatures, hasDeletedDependencies } = await this.featureService.validateArchiveToggles(features);
res.send({ parentsWithChildFeatures, hasDeletedDependencies });
}
}
//# sourceMappingURL=project-archive.js.map