UNPKG

unleash-server

Version:

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

64 lines (63 loc) 3.29 kB
import { ADMIN, NONE } from '../../types/permissions.js'; import { featureTypesSchema, } from '../../openapi/spec/feature-types-schema.js'; import { createResponseSchema } from '../../openapi/util/create-response-schema.js'; import Controller from '../controller.js'; import { createRequestSchema, featureTypeSchema, getStandardResponses, } from '../../openapi/index.js'; const version = 1; export class FeatureTypeController extends Controller { constructor(config, { featureTypeService, openApiService, }) { super(config); this.featureTypeService = featureTypeService; this.openApiService = openApiService; this.flagResolver = config.flagResolver; this.route({ method: 'get', path: '', handler: this.getAllFeatureTypes, permission: NONE, middleware: [ openApiService.validPath({ tags: ['Feature Types'], operationId: 'getAllFeatureTypes', summary: 'Get all feature types', description: 'Retrieves all feature types that exist in this Unleash instance, along with their descriptions and lifetimes.', responses: { 200: createResponseSchema('featureTypesSchema'), ...getStandardResponses(401), }, }), ], }); this.route({ method: 'put', path: '/:id/lifetime', handler: this.updateLifetime, permission: ADMIN, middleware: [ openApiService.validPath({ tags: ['Feature Types'], operationId: 'updateFeatureTypeLifetime', summary: 'Update feature type lifetime', description: `Updates the lifetime configuration for the specified [feature flag type](https://docs.getunleash.io/concepts/feature-flags#feature-flag-types). The expected lifetime is an integer representing the number of days before Unleash marks a feature flag of that type as potentially stale. If set to \`null\` or \`0\`, then feature flags of that particular type will never be marked as potentially stale. When a feature flag type's expected lifetime is changed, this will also cause any feature flags of this type to be reevaluated for potential staleness.`, responses: { 200: createResponseSchema('featureTypeSchema'), ...getStandardResponses(400, 401, 403, 404, 409, 415), }, requestBody: createRequestSchema('updateFeatureTypeLifetimeSchema'), }), ], }); } async getAllFeatureTypes(_req, res) { this.openApiService.respondWithValidation(200, res, featureTypesSchema.$id, { version, types: await this.featureTypeService.getAll(), }); } async updateLifetime(req, res) { const result = await this.featureTypeService.updateLifetime(req.params.id.toLowerCase(), req.body.lifetimeDays, req.audit); this.openApiService.respondWithValidation(200, res, featureTypeSchema.$id, result); } } //# sourceMappingURL=feature-type.js.map