1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00
unleash.unleash/src/lib/schema/api-token-schema.ts

34 lines
1.1 KiB
TypeScript
Raw Normal View History

import joi from 'joi';
import { ALL, ApiTokenType } from '../types/models/api-token';
import { DEFAULT_ENV } from '../util/constants';
export const createApiToken = joi
.object()
.keys({
username: joi.string().optional(),
tokenName: joi.string().optional(),
type: joi
.string()
.lowercase()
.required()
.valid(
ApiTokenType.ADMIN,
ApiTokenType.CLIENT,
ApiTokenType.FRONTEND,
),
expiresAt: joi.date().optional(),
project: joi.when('projects', {
not: joi.required(),
then: joi.string().optional().default(ALL),
}),
projects: joi.array().min(0).optional(),
environment: joi.when('type', {
is: joi.string().valid(ApiTokenType.CLIENT, ApiTokenType.FRONTEND),
then: joi.string().optional().default(DEFAULT_ENV),
otherwise: joi.string().optional().default(ALL),
}),
})
.nand('username', 'tokenName')
.nand('project', 'projects')
.options({ stripUnknown: true, allowUnknown: false, abortEarly: false });