UNPKG

unleash-server

Version:

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

36 lines 1.45 kB
import BadDataError from '../../error/bad-data-error.js'; import { ApiTokenType } from '../model.js'; export const ALL = '*'; export const isAllProjects = (projects) => { return projects && projects.length === 1 && projects[0] === ALL; }; export const resolveValidProjects = (projects) => { if (projects.includes('*')) { return ['*']; } return projects; }; export const validateApiToken = ({ type, projects, environment, }) => { if (type === ApiTokenType.ADMIN && !isAllProjects(projects)) { throw new BadDataError('Admin token cannot be scoped to single project'); } if (type === ApiTokenType.ADMIN && environment !== ALL) { throw new BadDataError('Admin token cannot be scoped to single environment'); } if (type === ApiTokenType.CLIENT && environment === ALL) { throw new BadDataError('Client token cannot be scoped to all environments'); } if (type === ApiTokenType.FRONTEND && environment === ALL) { throw new BadDataError('Frontend token cannot be scoped to all environments'); } }; export const validateApiTokenEnvironment = ({ environment }, environments) => { if (environment === ALL) { return; } const selectedEnvironment = environments.find((env) => env.name === environment); if (!selectedEnvironment) { throw new BadDataError(`Environment=${environment} does not exist`); } }; //# sourceMappingURL=api-token.js.map