UNPKG

unleash-server

Version:

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

71 lines 3.41 kB
import Controller from '../controller.js'; import { NONE } from '../../types/index.js'; import { createResponseSchema } from '../../openapi/index.js'; import { createRequestSchema } from '../../openapi/index.js'; import { validatedEdgeTokensSchema, } from '../../openapi/index.js'; import { getStandardResponses } from '../../openapi/index.js'; import { hmacSignatureVerifyTokenRequest } from '../../features/edgetokens/edge-hmac-verifier.js'; export default class EdgeController extends Controller { constructor(config, { edgeService, openApiService, }) { super(config); this.logger = config.getLogger('edge-api/index.ts'); this.edgeService = edgeService; this.openApiService = openApiService; this.route({ method: 'post', path: '/validate', handler: this.validateTokens, permission: NONE, middleware: [ this.openApiService.validPath({ tags: ['Unleash Edge'], security: [{}], summary: 'Check which tokens are valid', description: 'This operation accepts a list of tokens to validate. Unleash will validate each token you provide. For each valid token you provide, Unleash will return the token along with its type and which projects it has access to.', operationId: 'getValidTokens', requestBody: createRequestSchema('tokenStringListSchema'), responses: { 200: createResponseSchema('validatedEdgeTokensSchema'), ...getStandardResponses(400, 413, 415), }, }), ], }); this.route({ method: 'post', path: '/issue-token', handler: this.createOrReturnTokens, permission: NONE, middleware: [ this.openApiService.validPath({ tags: ['Unleash Edge'], security: [{}], release: { beta: '7.5.0', stable: '7.6.0', }, summary: 'Get or create valid tokens for the requested environment', description: 'This operation accepts a list of environments/project pairs to return tokens for. If they do not exist, Unleash will generate them', operationId: 'edgeCreateOrReturnTokens', requestBody: createRequestSchema('edgeEnvironmentProjectsListSchema'), responses: { 200: createResponseSchema('validatedEdgeTokensSchema'), ...getStandardResponses(400, 403, 413, 415), }, }), hmacSignatureVerifyTokenRequest(edgeService), ], }); } async validateTokens(req, res) { const tokens = await this.edgeService.getValidTokens(req.body.tokens); this.openApiService.respondWithValidation(200, res, validatedEdgeTokensSchema.$id, tokens); } async createOrReturnTokens(req, res) { const tokens = await this.edgeService.transactional((svc) => { return svc.getOrCreateTokens(res.locals.clientId, req.body); }); res.status(200).json(tokens); } } //# sourceMappingURL=index.js.map