2018-12-01 12:03:47 +01:00
|
|
|
'use strict';
|
|
|
|
|
2020-07-31 22:15:09 +02:00
|
|
|
const joi = require('joi');
|
2021-01-18 12:32:19 +01:00
|
|
|
const { nameType } = require('../routes/admin-api/util');
|
2018-12-12 10:09:38 +01:00
|
|
|
|
2021-01-18 12:32:19 +01:00
|
|
|
const nameSchema = joi
|
|
|
|
.object()
|
|
|
|
.keys({ name: nameType })
|
|
|
|
.options({ stripUnknown: true, allowUnknown: false, abortEarly: false });
|
2018-12-01 12:03:47 +01:00
|
|
|
|
2019-11-20 22:11:30 +01:00
|
|
|
const constraintSchema = joi.object().keys({
|
|
|
|
contextName: joi.string(),
|
|
|
|
operator: joi.string(),
|
2020-10-30 16:40:29 +01:00
|
|
|
values: joi
|
|
|
|
.array()
|
|
|
|
.items(
|
|
|
|
joi
|
|
|
|
.string()
|
|
|
|
.min(1)
|
|
|
|
.max(100),
|
|
|
|
)
|
|
|
|
.min(1)
|
|
|
|
.optional(),
|
2019-11-20 22:11:30 +01:00
|
|
|
});
|
|
|
|
|
2018-12-01 12:03:47 +01:00
|
|
|
const strategiesSchema = joi.object().keys({
|
2018-12-12 10:09:38 +01:00
|
|
|
name: nameType,
|
2019-11-20 22:11:30 +01:00
|
|
|
constraints: joi
|
|
|
|
.array()
|
|
|
|
.allow(null)
|
|
|
|
.items(constraintSchema),
|
2018-12-01 12:03:47 +01:00
|
|
|
parameters: joi.object(),
|
|
|
|
});
|
|
|
|
|
2018-01-30 15:57:12 +01:00
|
|
|
const variantsSchema = joi.object().keys({
|
|
|
|
name: nameType,
|
2019-01-24 11:26:07 +01:00
|
|
|
weight: joi
|
|
|
|
.number()
|
|
|
|
.min(0)
|
2020-02-13 17:53:09 +01:00
|
|
|
.max(1000)
|
2019-01-24 11:26:07 +01:00
|
|
|
.required(),
|
2020-08-03 13:24:51 +02:00
|
|
|
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(),
|
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-01-18 12:32:19 +01:00
|
|
|
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),
|
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'),
|
2019-03-14 17:56:02 +01:00
|
|
|
description: joi
|
|
|
|
.string()
|
|
|
|
.allow('')
|
|
|
|
.allow(null)
|
|
|
|
.optional(),
|
2018-12-01 12:03:47 +01:00
|
|
|
strategies: joi
|
|
|
|
.array()
|
|
|
|
.required()
|
|
|
|
.min(1)
|
|
|
|
.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-01-22 13:39:42 +01:00
|
|
|
const querySchema = joi
|
|
|
|
.object()
|
|
|
|
.keys({
|
|
|
|
tag: joi
|
|
|
|
.array()
|
|
|
|
.allow(null)
|
|
|
|
.items(joi.string().pattern(/\w+:.+/, { name: 'tag' }))
|
|
|
|
.optional(),
|
|
|
|
project: joi
|
|
|
|
.array()
|
|
|
|
.allow(null)
|
|
|
|
.items(joi.string().alphanum())
|
|
|
|
.optional(),
|
|
|
|
namePrefix: joi
|
|
|
|
.string()
|
|
|
|
.allow(null)
|
|
|
|
.optional(),
|
|
|
|
})
|
|
|
|
.options({ allowUnknown: false, stripUnknown: true, abortEarly: false });
|
|
|
|
|
|
|
|
module.exports = { featureSchema, strategiesSchema, nameSchema, querySchema };
|