2021-07-07 10:46:50 +02:00
|
|
|
import joi from 'joi';
|
|
|
|
import { nameType } from '../routes/admin-api/util';
|
2018-12-01 12:03:47 +01:00
|
|
|
|
2021-07-07 10:46:50 +02:00
|
|
|
export const nameSchema = joi
|
2021-01-18 12:32:19 +01:00
|
|
|
.object()
|
|
|
|
.keys({ name: nameType })
|
|
|
|
.options({ stripUnknown: true, allowUnknown: false, abortEarly: false });
|
2018-12-01 12:03:47 +01:00
|
|
|
|
2021-07-07 10:46:50 +02:00
|
|
|
export const constraintSchema = joi.object().keys({
|
2019-11-20 22:11:30 +01:00
|
|
|
contextName: joi.string(),
|
|
|
|
operator: joi.string(),
|
2021-08-12 15:04:37 +02:00
|
|
|
values: joi.array().items(joi.string().min(1).max(100)).min(1).optional(),
|
2019-11-20 22:11:30 +01:00
|
|
|
});
|
|
|
|
|
2021-07-07 10:46:50 +02:00
|
|
|
export const strategiesSchema = joi.object().keys({
|
|
|
|
id: joi.string().optional(),
|
2018-12-12 10:09:38 +01:00
|
|
|
name: nameType,
|
2021-08-12 15:04:37 +02:00
|
|
|
constraints: joi.array().allow(null).items(constraintSchema),
|
2018-12-01 12:03:47 +01:00
|
|
|
parameters: joi.object(),
|
|
|
|
});
|
|
|
|
|
2021-07-07 10:46:50 +02:00
|
|
|
export const variantsSchema = joi.object().keys({
|
2018-01-30 15:57:12 +01:00
|
|
|
name: nameType,
|
2021-08-12 15:04:37 +02:00
|
|
|
weight: joi.number().min(0).max(1000).required(),
|
|
|
|
weightType: joi.string().valid('variable', 'fix').default('variable'),
|
2019-01-24 11:26:07 +01:00
|
|
|
payload: joi
|
|
|
|
.object()
|
|
|
|
.keys({
|
|
|
|
type: joi.string().required(),
|
|
|
|
value: joi.string().required(),
|
|
|
|
})
|
|
|
|
.optional(),
|
2021-02-11 17:59:16 +01:00
|
|
|
stickiness: joi.string().default('default'),
|
2019-01-29 09:21:54 +01:00
|
|
|
overrides: joi.array().items(
|
|
|
|
joi
|
|
|
|
.object()
|
|
|
|
.keys({
|
2019-02-04 14:04:58 +01:00
|
|
|
contextName: joi.string().required(),
|
2019-01-29 09:21:54 +01:00
|
|
|
values: joi.array().items(joi.string()),
|
|
|
|
})
|
2020-04-14 22:29:11 +02:00
|
|
|
.optional(),
|
2019-01-29 09:21:54 +01:00
|
|
|
),
|
2018-01-30 15:57:12 +01:00
|
|
|
});
|
|
|
|
|
2021-07-07 10:46:50 +02:00
|
|
|
export const featureMetadataSchema = joi
|
|
|
|
.object()
|
|
|
|
.keys({
|
|
|
|
name: nameType,
|
|
|
|
stale: joi.boolean().default(false),
|
|
|
|
archived: joi.boolean().default(false),
|
|
|
|
type: joi.string().default('release'),
|
2021-08-12 15:04:37 +02:00
|
|
|
description: joi.string().allow('').allow(null).optional(),
|
2021-07-07 10:46:50 +02:00
|
|
|
variants: joi
|
|
|
|
.array()
|
|
|
|
.allow(null)
|
|
|
|
.unique((a, b) => a.name === b.name)
|
|
|
|
.optional()
|
|
|
|
.items(variantsSchema),
|
2021-08-12 15:04:37 +02:00
|
|
|
createdAt: joi.date().optional().allow(null),
|
2021-07-07 10:46:50 +02:00
|
|
|
})
|
|
|
|
.options({ allowUnknown: false, stripUnknown: true, abortEarly: false });
|
|
|
|
|
|
|
|
export const featureSchema = joi
|
2018-12-01 12:03:47 +01:00
|
|
|
.object()
|
|
|
|
.keys({
|
2018-12-12 10:09:38 +01:00
|
|
|
name: nameType,
|
2018-12-01 12:03:47 +01:00
|
|
|
enabled: joi.boolean().default(false),
|
2020-08-07 10:46:35 +02:00
|
|
|
stale: joi.boolean().default(false),
|
2021-07-07 10:46:50 +02:00
|
|
|
archived: joi.boolean().default(false),
|
2020-08-06 11:18:52 +02:00
|
|
|
type: joi.string().default('release'),
|
2020-09-28 21:54:44 +02:00
|
|
|
project: joi.string().default('default'),
|
2021-08-12 15:04:37 +02:00
|
|
|
description: joi.string().allow('').allow(null).optional(),
|
2018-12-01 12:03:47 +01:00
|
|
|
strategies: joi
|
|
|
|
.array()
|
2021-07-07 10:46:50 +02:00
|
|
|
.min(0)
|
|
|
|
.allow(null)
|
|
|
|
.optional()
|
2018-12-01 12:03:47 +01:00
|
|
|
.items(strategiesSchema),
|
2018-01-30 15:57:12 +01:00
|
|
|
variants: joi
|
|
|
|
.array()
|
2019-03-14 17:56:02 +01:00
|
|
|
.allow(null)
|
2019-01-24 11:26:07 +01:00
|
|
|
.unique((a, b) => a.name === b.name)
|
2018-01-30 15:57:12 +01:00
|
|
|
.optional()
|
2019-03-14 17:56:02 +01:00
|
|
|
.items(variantsSchema),
|
2018-12-01 12:03:47 +01:00
|
|
|
})
|
2021-01-18 12:32:19 +01:00
|
|
|
.options({ allowUnknown: false, stripUnknown: true, abortEarly: false });
|
2018-12-01 12:03:47 +01:00
|
|
|
|
2021-07-07 10:46:50 +02:00
|
|
|
export const querySchema = joi
|
2021-01-22 13:39:42 +01:00
|
|
|
.object()
|
|
|
|
.keys({
|
|
|
|
tag: joi
|
|
|
|
.array()
|
|
|
|
.allow(null)
|
|
|
|
.items(joi.string().pattern(/\w+:.+/, { name: 'tag' }))
|
|
|
|
.optional(),
|
2021-08-12 15:04:37 +02:00
|
|
|
project: joi.array().allow(null).items(nameType).optional(),
|
|
|
|
namePrefix: joi.string().allow(null).optional(),
|
|
|
|
environment: joi.string().allow(null).optional(),
|
2021-01-22 13:39:42 +01:00
|
|
|
})
|
|
|
|
.options({ allowUnknown: false, stripUnknown: true, abortEarly: false });
|
|
|
|
|
2021-07-07 10:46:50 +02:00
|
|
|
export const featureTagSchema = joi.object().keys({
|
2021-03-12 11:08:10 +01:00
|
|
|
featureName: nameType,
|
2021-07-07 10:46:50 +02:00
|
|
|
tagType: nameType.optional(),
|
2021-03-12 11:08:10 +01:00
|
|
|
tagValue: joi.string(),
|
2021-07-07 10:46:50 +02:00
|
|
|
type: nameType.optional(),
|
|
|
|
value: joi.string().optional(),
|
2021-03-12 11:08:10 +01:00
|
|
|
});
|