unleash-server
Version:
Unleash is an enterprise ready feature toggles service. It provides different strategies for handling feature toggles.
46 lines • 2.29 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const permissions_1 = require("../../types/permissions");
const controller_1 = __importDefault(require("../controller"));
const create_response_schema_1 = require("../../openapi/util/create-response-schema");
const endpoint_descriptions_1 = require("../../openapi/endpoint-descriptions");
const standard_responses_1 = require("../../../lib/openapi/util/standard-responses");
const create_request_schema_1 = require("../../../lib/openapi/util/create-request-schema");
const playground_response_schema_1 = require("../../../lib/openapi/spec/playground-response-schema");
class PlaygroundController extends controller_1.default {
constructor(config, { openApiService, playgroundService, }) {
super(config);
this.openApiService = openApiService;
this.playgroundService = playgroundService;
this.route({
method: 'post',
path: '',
handler: this.evaluateContext,
permission: permissions_1.NONE,
middleware: [
openApiService.validPath({
operationId: 'getPlayground',
tags: ['Playground'],
responses: {
...(0, standard_responses_1.getStandardResponses)(400, 401),
200: (0, create_response_schema_1.createResponseSchema)('playgroundResponseSchema'),
},
requestBody: (0, create_request_schema_1.createRequestSchema)('playgroundRequestSchema'),
...endpoint_descriptions_1.endpointDescriptions.admin.playground,
}),
],
});
}
async evaluateContext(req, res) {
const response = {
input: req.body,
features: await this.playgroundService.evaluateQuery(req.body.projects, req.body.environment, req.body.context),
};
this.openApiService.respondWithValidation(200, res, playground_response_schema_1.playgroundResponseSchema.$id, response);
}
}
exports.default = PlaygroundController;
//# sourceMappingURL=playground.js.map