-
Notifications
You must be signed in to change notification settings - Fork 31
/
evaluation.ts
129 lines (105 loc) · 3.23 KB
/
evaluation.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
export type FlagValueType = 'boolean' | 'string' | 'number' | 'object';
export type PrimitiveValue = null | boolean | string | number;
export type JsonObject = { [key: string]: JsonValue };
export type JsonArray = JsonValue[];
/**
* Represents a JSON node value.
*/
export type JsonValue = PrimitiveValue | JsonObject | JsonArray;
/**
* Represents a JSON node value, or Date.
*/
export type FlagValue = boolean | string | number | JsonValue;
export type ResolutionReason = keyof typeof StandardResolutionReasons | (string & Record<never, never>);
/**
* A structure which supports definition of arbitrary properties, with keys of type string, and values of type boolean, string, or number.
*
* This structure is populated by a provider for use by an Application Author (via the Evaluation API) or an Application Integrator (via hooks).
*/
export type FlagMetadata = Record<string, string | number | boolean>;
export type ResolutionDetails<U> = {
value: U;
variant?: string;
flagMetadata?: FlagMetadata;
reason?: ResolutionReason;
errorCode?: ErrorCode;
errorMessage?: string;
};
export type EvaluationDetails<T extends FlagValue> = {
flagKey: string;
flagMetadata: Readonly<FlagMetadata>;
} & ResolutionDetails<T>;
export const StandardResolutionReasons = {
/**
* The resolved value is static (no dynamic evaluation).
*/
STATIC: 'STATIC',
/**
* The resolved value was configured statically, or otherwise fell back to a pre-configured value.
*/
DEFAULT: 'DEFAULT',
/**
* The resolved value was the result of a dynamic evaluation, such as a rule or specific user-targeting.
*/
TARGETING_MATCH: 'TARGETING_MATCH',
/**
* The resolved value was the result of pseudorandom assignment.
*/
SPLIT: 'SPLIT',
/**
* The resolved value was retrieved from cache.
*/
CACHED: 'CACHED',
/**
* The resolved value was the result of the flag being disabled in the management system.
*/
DISABLED: 'DISABLED',
/**
* The reason for the resolved value could not be determined.
*/
UNKNOWN: 'UNKNOWN',
/**
* The resolved value is non-authoritative or possibly out of date.
*/
STALE: 'STALE',
/**
* The resolved value was the result of an error.
*
* Note: The `errorCode` and `errorMessage` fields may contain additional details of this error.
*/
ERROR: 'ERROR',
} as const;
export enum ErrorCode {
/**
* The value was resolved before the provider was ready.
*/
PROVIDER_NOT_READY = 'PROVIDER_NOT_READY',
/**
* The provider has entered an irrecoverable error state.
*/
PROVIDER_FATAL = 'PROVIDER_FATAL',
/**
* The flag could not be found.
*/
FLAG_NOT_FOUND = 'FLAG_NOT_FOUND',
/**
* An error was encountered parsing data, such as a flag configuration.
*/
PARSE_ERROR = 'PARSE_ERROR',
/**
* The type of the flag value does not match the expected type.
*/
TYPE_MISMATCH = 'TYPE_MISMATCH',
/**
* The provider requires a targeting key and one was not provided in the evaluation context.
*/
TARGETING_KEY_MISSING = 'TARGETING_KEY_MISSING',
/**
* The evaluation context does not meet provider requirements.
*/
INVALID_CONTEXT = 'INVALID_CONTEXT',
/**
* An error with an unspecified code.
*/
GENERAL = 'GENERAL',
}