mirror of
https://github.com/Unleash/unleash.git
synced 2025-10-13 11:17:26 +02:00
<!-- Thanks for creating a PR! To make it easier for reviewers and everyone else to understand what your changes relate to, please add some relevant content to the headings below. Feel free to ignore or delete sections that you don't think are relevant. Thank you! ❤️ --> Adds enabled field to feature strategies Filter out disabled strategies when returning/evaluating ## About the changes <!-- Describe the changes introduced. What are they and why are they being introduced? Feel free to also add screenshots or steps to view the changes if they're visual. --> <!-- Does it close an issue? Multiple? --> Closes # [1-865](https://linear.app/unleash/issue/1-865/allow-for-enablingdisabling-strategies-in-place-backend) <!-- (For internal contributors): Does it relate to an issue on public roadmap? --> <!-- Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item: # --> ### Important files <!-- PRs can contain a lot of changes, but not all changes are equally important. Where should a reviewer start looking to get an overview of the changes? Are any files particularly important? --> ## Discussion points <!-- Anything about the PR you'd like to discuss before it gets merged? Got any questions or doubts? --> --------- Signed-off-by: andreas-unleash <andreas@getunleash.ai>
134 lines
4.5 KiB
TypeScript
134 lines
4.5 KiB
TypeScript
import { FromSchema } from 'json-schema-to-ts';
|
|
import { parametersSchema } from './parameters-schema';
|
|
import { playgroundConstraintSchema } from './playground-constraint-schema';
|
|
import { playgroundSegmentSchema } from './playground-segment-schema';
|
|
|
|
export const playgroundStrategyEvaluation = {
|
|
evaluationComplete: 'complete',
|
|
evaluationIncomplete: 'incomplete',
|
|
unknownResult: 'unknown',
|
|
} as const;
|
|
|
|
export const strategyEvaluationResults = {
|
|
anyOf: [
|
|
{
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
required: ['evaluationStatus', 'enabled'],
|
|
properties: {
|
|
evaluationStatus: {
|
|
type: 'string',
|
|
description:
|
|
"Signals that this strategy could not be evaluated. This is most likely because you're using a custom strategy that Unleash doesn't know about.",
|
|
enum: [playgroundStrategyEvaluation.evaluationIncomplete],
|
|
},
|
|
enabled: {
|
|
description:
|
|
"Whether this strategy resolves to `false` or if it might resolve to `true`. Because Unleash can't evaluate the strategy, it can't say for certain whether it will be `true`, but if you have failing constraints or segments, it _can_ determine that your strategy would be `false`.",
|
|
anyOf: [
|
|
{ type: 'boolean', enum: [false] },
|
|
{
|
|
type: 'string',
|
|
enum: [playgroundStrategyEvaluation.unknownResult],
|
|
},
|
|
],
|
|
},
|
|
},
|
|
},
|
|
{
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
required: ['evaluationStatus', 'enabled'],
|
|
properties: {
|
|
evaluationStatus: {
|
|
description:
|
|
'Signals that this strategy was evaluated successfully.',
|
|
type: 'string',
|
|
enum: ['complete'],
|
|
},
|
|
enabled: {
|
|
type: 'boolean',
|
|
description:
|
|
'Whether this strategy evaluates to true or not.',
|
|
},
|
|
},
|
|
},
|
|
],
|
|
} as const;
|
|
|
|
export const playgroundStrategySchema = {
|
|
$id: '#/components/schemas/playgroundStrategySchema',
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
required: [
|
|
'id',
|
|
'name',
|
|
'result',
|
|
'segments',
|
|
'constraints',
|
|
'parameters',
|
|
'disabled',
|
|
],
|
|
properties: {
|
|
name: {
|
|
description: "The strategy's name.",
|
|
type: 'string',
|
|
},
|
|
title: {
|
|
type: 'string',
|
|
example: 'Beta rollout',
|
|
description: "Description of the feature's purpose.",
|
|
},
|
|
id: {
|
|
description: "The strategy's id.",
|
|
type: 'string',
|
|
},
|
|
result: {
|
|
description: `The strategy's evaluation result. If the strategy is a custom strategy that Unleash can't evaluate, \`evaluationStatus\` will be \`${playgroundStrategyEvaluation.unknownResult}\`. Otherwise, it will be \`true\` or \`false\``,
|
|
...strategyEvaluationResults,
|
|
},
|
|
disabled: {
|
|
type: 'boolean',
|
|
description:
|
|
"The strategy's status. Disabled strategies are not evaluated",
|
|
example: false,
|
|
nullable: true,
|
|
},
|
|
segments: {
|
|
type: 'array',
|
|
description:
|
|
"The strategy's segments and their evaluation results.",
|
|
items: {
|
|
$ref: playgroundSegmentSchema.$id,
|
|
},
|
|
},
|
|
constraints: {
|
|
type: 'array',
|
|
description:
|
|
"The strategy's constraints and their evaluation results.",
|
|
items: {
|
|
$ref: playgroundConstraintSchema.$id,
|
|
},
|
|
},
|
|
parameters: {
|
|
description:
|
|
"The strategy's constraints and their evaluation results.",
|
|
example: {
|
|
myParam1: 'param value',
|
|
},
|
|
$ref: parametersSchema.$id,
|
|
},
|
|
},
|
|
components: {
|
|
schemas: {
|
|
playgroundConstraintSchema,
|
|
playgroundSegmentSchema,
|
|
parametersSchema,
|
|
},
|
|
},
|
|
} as const;
|
|
|
|
export type PlaygroundStrategySchema = FromSchema<
|
|
typeof playgroundStrategySchema
|
|
>;
|