@croct/rule-engine-experiments
Version:
A rule engine extension for A/B and multivariate testing.
67 lines (66 loc) • 1.9 kB
JavaScript
import { ArrayType, NumberType, ObjectType, StringType, UnionType } from '@croct/plug/sdk/validation';
export var propertiesSchema = new ObjectType({
required: ['testId', 'groupId'],
properties: {
testId: new StringType({ minLength: 1 }),
groupId: new StringType({ minLength: 1 }),
},
});
var abTestSchema = new ObjectType({
required: ['groups'],
properties: {
groups: new UnionType(new ArrayType({
minItems: 1,
items: new StringType({
minLength: 1,
}),
}), new ObjectType({
minProperties: 1,
additionalProperties: new ObjectType({
required: ['weight'],
properties: {
weight: new NumberType({
minimum: 0,
}),
},
}),
})),
},
});
var multivariateTestSchema = new ObjectType({
required: ['groups'],
properties: {
groups: new ArrayType({
minItems: 1,
items: new ArrayType({
minItems: 1,
items: new StringType({
minLength: 1,
}),
}),
}),
},
});
export var definitionsSchema = new ObjectType({
additionalProperties: new ObjectType({
required: ['type'],
additionalProperties: true,
properties: {
type: new StringType({
enumeration: ['ab', 'multivariate'],
}),
traffic: new NumberType({
minimum: 0,
maximum: 1,
}),
audience: new StringType({ minLength: 1 }),
},
subtypes: {
discriminator: 'type',
schemas: {
ab: abTestSchema,
multivariate: multivariateTestSchema,
},
},
}),
});