2021-07-07 10:46:50 +02:00
|
|
|
import joi from 'joi';
|
2022-11-21 10:37:16 +01:00
|
|
|
import {
|
|
|
|
featureSchema,
|
|
|
|
featureTagSchema,
|
|
|
|
variantsSchema,
|
|
|
|
} from '../schema/feature-schema';
|
2021-07-07 10:46:50 +02:00
|
|
|
import strategySchema from './strategy-schema';
|
|
|
|
import { tagSchema } from './tag-schema';
|
|
|
|
import { tagTypeSchema } from './tag-type-schema';
|
2021-09-14 20:36:40 +02:00
|
|
|
import { projectSchema } from './project-schema';
|
2021-08-13 10:36:19 +02:00
|
|
|
import { nameType } from '../routes/util';
|
2022-03-29 14:59:14 +02:00
|
|
|
import { featureStrategySegmentSchema, segmentSchema } from './segment-schema';
|
2021-07-07 10:46:50 +02:00
|
|
|
|
|
|
|
export const featureStrategySchema = joi
|
|
|
|
.object()
|
|
|
|
.keys({
|
|
|
|
id: joi.string().optional(),
|
|
|
|
featureName: joi.string(),
|
2021-09-20 12:29:16 +02:00
|
|
|
projectId: joi.string(),
|
2021-07-07 10:46:50 +02:00
|
|
|
environment: joi.string(),
|
2021-09-24 13:55:00 +02:00
|
|
|
parameters: joi.object().optional().allow(null),
|
2021-07-07 10:46:50 +02:00
|
|
|
constraints: joi.array().optional(),
|
|
|
|
strategyName: joi.string(),
|
|
|
|
})
|
|
|
|
.options({ stripUnknown: true });
|
|
|
|
|
|
|
|
export const featureEnvironmentsSchema = joi.object().keys({
|
|
|
|
environment: joi.string(),
|
2021-08-12 15:04:37 +02:00
|
|
|
featureName: joi.string(),
|
2021-07-07 10:46:50 +02:00
|
|
|
enabled: joi.boolean(),
|
2022-11-21 10:37:16 +01:00
|
|
|
variants: joi.array().items(variantsSchema).optional(),
|
2021-07-07 10:46:50 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
export const environmentSchema = joi.object().keys({
|
2021-09-24 13:55:00 +02:00
|
|
|
name: nameType,
|
2021-08-12 15:04:37 +02:00
|
|
|
displayName: joi.string().optional().allow(''),
|
2021-09-13 15:57:38 +02:00
|
|
|
type: joi.string().required(),
|
2021-09-20 12:29:16 +02:00
|
|
|
sortOrder: joi.number().optional(),
|
|
|
|
enabled: joi.boolean().optional(),
|
|
|
|
protected: joi.boolean().optional(),
|
2021-07-07 10:46:50 +02:00
|
|
|
});
|
|
|
|
|
2021-09-13 15:57:38 +02:00
|
|
|
export const updateEnvironmentSchema = joi.object().keys({
|
|
|
|
displayName: joi.string().optional().allow(''),
|
|
|
|
type: joi.string().optional(),
|
|
|
|
sortOrder: joi.number().optional(),
|
|
|
|
});
|
|
|
|
|
|
|
|
export const sortOrderSchema = joi.object().pattern(/^/, joi.number());
|
|
|
|
|
2021-07-07 10:46:50 +02:00
|
|
|
export const stateSchema = joi.object().keys({
|
|
|
|
version: joi.number(),
|
2021-08-12 15:04:37 +02:00
|
|
|
features: joi.array().optional().items(featureSchema),
|
|
|
|
strategies: joi.array().optional().items(strategySchema),
|
|
|
|
tags: joi.array().optional().items(tagSchema),
|
|
|
|
tagTypes: joi.array().optional().items(tagTypeSchema),
|
|
|
|
featureTags: joi.array().optional().items(featureTagSchema),
|
|
|
|
projects: joi.array().optional().items(projectSchema),
|
|
|
|
featureStrategies: joi.array().optional().items(featureStrategySchema),
|
2021-07-07 10:46:50 +02:00
|
|
|
featureEnvironments: joi
|
|
|
|
.array()
|
|
|
|
.optional()
|
|
|
|
.items(featureEnvironmentsSchema),
|
2021-08-12 15:04:37 +02:00
|
|
|
environments: joi.array().optional().items(environmentSchema),
|
2022-03-29 14:59:14 +02:00
|
|
|
segments: joi.array().optional().items(segmentSchema),
|
|
|
|
featureStrategySegments: joi
|
|
|
|
.array()
|
|
|
|
.optional()
|
|
|
|
.items(featureStrategySegmentSchema),
|
2021-07-07 10:46:50 +02:00
|
|
|
});
|