2018-12-01 12:03:47 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const joi = require('joi');
|
2018-12-12 10:09:38 +01:00
|
|
|
const { nameType } = require('./util');
|
|
|
|
|
|
|
|
const nameSchema = joi.object().keys({ name: nameType });
|
2018-12-01 12:03:47 +01:00
|
|
|
|
|
|
|
const strategiesSchema = joi.object().keys({
|
2018-12-12 10:09:38 +01:00
|
|
|
name: nameType,
|
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)
|
|
|
|
.max(100)
|
|
|
|
.required(),
|
|
|
|
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()),
|
|
|
|
})
|
|
|
|
.optional()
|
|
|
|
),
|
2018-01-30 15:57:12 +01:00
|
|
|
});
|
|
|
|
|
2018-12-01 12:03:47 +01:00
|
|
|
const featureShema = joi
|
|
|
|
.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),
|
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
|
|
|
})
|
|
|
|
.options({ allowUnknown: false, stripUnknown: true });
|
|
|
|
|
2018-12-12 10:09:38 +01:00
|
|
|
module.exports = { featureShema, strategiesSchema, nameSchema };
|