@spotify-confidence/openfeature-server-provider-local 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -0,0 +1,236 @@
1
+ import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
2
+ import { EvaluationContext, JsonValue, Provider, ProviderMetadata, ProviderStatus, ResolutionDetails } from "@openfeature/server-sdk";
3
+
4
+ //#region src/proto/api.d.ts
5
+ declare enum ResolveReason {
6
+ /** RESOLVE_REASON_UNSPECIFIED - Unspecified enum. */
7
+ RESOLVE_REASON_UNSPECIFIED = 0,
8
+ /** RESOLVE_REASON_MATCH - The flag was successfully resolved because one rule matched. */
9
+ RESOLVE_REASON_MATCH = 1,
10
+ /** RESOLVE_REASON_NO_SEGMENT_MATCH - The flag could not be resolved because no rule matched. */
11
+ RESOLVE_REASON_NO_SEGMENT_MATCH = 2,
12
+ /**
13
+ * RESOLVE_REASON_NO_TREATMENT_MATCH - The flag could not be resolved because the matching rule had no variant
14
+ * that could be assigned.
15
+ *
16
+ * @deprecated
17
+ */
18
+ RESOLVE_REASON_NO_TREATMENT_MATCH = 3,
19
+ /** RESOLVE_REASON_FLAG_ARCHIVED - The flag could not be resolved because it was archived. */
20
+ RESOLVE_REASON_FLAG_ARCHIVED = 4,
21
+ /** RESOLVE_REASON_TARGETING_KEY_ERROR - The flag could not be resolved because the targeting key field was invalid */
22
+ RESOLVE_REASON_TARGETING_KEY_ERROR = 5,
23
+ /** RESOLVE_REASON_ERROR - Unknown error occurred during the resolve */
24
+ RESOLVE_REASON_ERROR = 6,
25
+ UNRECOGNIZED = -1,
26
+ }
27
+ interface ResolveFlagsRequest {
28
+ /**
29
+ * If non-empty, the specific flags are resolved, otherwise all flags
30
+ * available to the client will be resolved.
31
+ */
32
+ flags: string[];
33
+ /**
34
+ * An object that contains data used in the flag resolve. For example,
35
+ * the targeting key e.g. the id of the randomization unit, other attributes
36
+ * like country or version that are used for targeting.
37
+ */
38
+ evaluationContext?: {
39
+ [key: string]: any;
40
+ } | undefined;
41
+ /**
42
+ * Credentials for the client. It is used to identify the client and find
43
+ * the flags that are available to it.
44
+ */
45
+ clientSecret: string;
46
+ /**
47
+ * Determines whether the flags should be applied directly as part of the
48
+ * resolve, or delayed until `ApplyFlag` is called. A flag is typically
49
+ * applied when it is used, if this occurs much later than the resolve, then
50
+ * `apply` should likely be set to false.
51
+ */
52
+ apply: boolean;
53
+ }
54
+ interface ResolveFlagsResponse {
55
+ /**
56
+ * The list of all flags that could be resolved. Note: if any flag was
57
+ * archived it will not be included in this list.
58
+ */
59
+ resolvedFlags: ResolvedFlag[];
60
+ /**
61
+ * An opaque token that is used when `apply` is set to false in `ResolveFlags`.
62
+ * When `apply` is set to false, the token must be passed to `ApplyFlags`.
63
+ */
64
+ resolveToken: Uint8Array;
65
+ /** Unique identifier for this particular resolve request. */
66
+ resolveId: string;
67
+ }
68
+ interface ResolvedFlag {
69
+ /** The id of the flag that as resolved. */
70
+ flag: string;
71
+ /** The id of the resolved variant has the format `flags/abc/variants/xyz`. */
72
+ variant: string;
73
+ /**
74
+ * The value corresponding to the variant. It will always be a json object,
75
+ * for example `{ "color": "red", "size": 12 }`.
76
+ */
77
+ value?: {
78
+ [key: string]: any;
79
+ } | undefined;
80
+ /** The reason to why the flag could be resolved or not. */
81
+ reason: ResolveReason;
82
+ }
83
+ interface SetResolverStateRequest {
84
+ state: Uint8Array;
85
+ accountId: string;
86
+ }
87
+ /** Request for resolving flags with sticky (materialized) assignments */
88
+ interface ResolveWithStickyRequest {
89
+ /** The standard resolve request */
90
+ resolveRequest?: ResolveFlagsRequest | undefined;
91
+ /**
92
+ * Context about the materialization required for the resolve
93
+ * Map of targeting key (unit) to their materialization data
94
+ */
95
+ materializationsPerUnit: {
96
+ [key: string]: MaterializationMap;
97
+ };
98
+ /** If a materialization info is missing, return to the caller immediately */
99
+ failFastOnSticky: boolean;
100
+ }
101
+ /** Map of materialization IDs to their info for a specific unit */
102
+ interface MaterializationMap {
103
+ /** Map of materialization name to info */
104
+ infoMap: {
105
+ [key: string]: MaterializationInfo;
106
+ };
107
+ }
108
+ /** Information about a materialization for a specific unit */
109
+ interface MaterializationInfo {
110
+ /** Whether the unit is in this materialization/rollout */
111
+ unitInInfo: boolean;
112
+ /** Map of rule name to variant name for this unit */
113
+ ruleToVariant: {
114
+ [key: string]: string;
115
+ };
116
+ }
117
+ /** Response from resolving with sticky assignments */
118
+ interface ResolveWithStickyResponse {
119
+ success?: ResolveWithStickyResponse_Success | undefined;
120
+ missingMaterializations?: ResolveWithStickyResponse_MissingMaterializations | undefined;
121
+ }
122
+ /** Successful resolution with materialization updates */
123
+ interface ResolveWithStickyResponse_Success {
124
+ /** The resolved flags response */
125
+ response?: ResolveFlagsResponse | undefined;
126
+ /** New assignments that should be stored */
127
+ updates: ResolveWithStickyResponse_MaterializationUpdate[];
128
+ }
129
+ /** Information about missing materializations */
130
+ interface ResolveWithStickyResponse_MissingMaterializations {
131
+ items: ResolveWithStickyResponse_MissingMaterializationItem[];
132
+ }
133
+ /** A missing materialization item */
134
+ interface ResolveWithStickyResponse_MissingMaterializationItem {
135
+ unit: string;
136
+ rule: string;
137
+ readMaterialization: string;
138
+ }
139
+ /** A materialization update to be stored */
140
+ interface ResolveWithStickyResponse_MaterializationUpdate {
141
+ unit: string;
142
+ writeMaterialization: string;
143
+ rule: string;
144
+ variant: string;
145
+ }
146
+ declare const ResolveFlagsRequest: MessageFns<ResolveFlagsRequest>;
147
+ declare const ResolveFlagsResponse: MessageFns<ResolveFlagsResponse>;
148
+ declare const ResolvedFlag: MessageFns<ResolvedFlag>;
149
+ declare const SetResolverStateRequest: MessageFns<SetResolverStateRequest>;
150
+ declare const ResolveWithStickyRequest: MessageFns<ResolveWithStickyRequest>;
151
+ declare const MaterializationMap: MessageFns<MaterializationMap>;
152
+ declare const MaterializationInfo: MessageFns<MaterializationInfo>;
153
+ declare const ResolveWithStickyResponse: MessageFns<ResolveWithStickyResponse>;
154
+ declare const ResolveWithStickyResponse_Success: MessageFns<ResolveWithStickyResponse_Success>;
155
+ declare const ResolveWithStickyResponse_MissingMaterializations: MessageFns<ResolveWithStickyResponse_MissingMaterializations>;
156
+ declare const ResolveWithStickyResponse_MissingMaterializationItem: MessageFns<ResolveWithStickyResponse_MissingMaterializationItem>;
157
+ declare const ResolveWithStickyResponse_MaterializationUpdate: MessageFns<ResolveWithStickyResponse_MaterializationUpdate>;
158
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
159
+ type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> } : Partial<T>;
160
+ type KeysOfUnion<T> = T extends T ? keyof T : never;
161
+ type Exact<P, I extends P> = P extends Builtin ? P : P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
162
+ interface MessageFns<T> {
163
+ encode(message: T, writer?: BinaryWriter): BinaryWriter;
164
+ decode(input: BinaryReader | Uint8Array, length?: number): T;
165
+ fromJSON(object: any): T;
166
+ toJSON(message: T): unknown;
167
+ create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
168
+ fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
169
+ }
170
+ //#endregion
171
+ //#region src/LocalResolver.d.ts
172
+ interface LocalResolver {
173
+ resolveWithSticky(request: ResolveWithStickyRequest): ResolveWithStickyResponse;
174
+ setResolverState(request: SetResolverStateRequest): void;
175
+ flushLogs(): Uint8Array;
176
+ }
177
+ //#endregion
178
+ //#region src/ConfidenceServerProviderLocal.d.ts
179
+ interface ProviderOptions {
180
+ flagClientSecret: string;
181
+ apiClientId: string;
182
+ apiClientSecret: string;
183
+ initializeTimeout?: number;
184
+ flushInterval?: number;
185
+ fetch?: typeof fetch;
186
+ }
187
+ /**
188
+ * OpenFeature Provider for Confidence Server SDK (Local Mode)
189
+ * @public
190
+ */
191
+ declare class ConfidenceServerProviderLocal implements Provider {
192
+ private resolver;
193
+ private options;
194
+ /** Static data about the provider */
195
+ readonly metadata: ProviderMetadata;
196
+ /** Current status of the provider. Can be READY, NOT_READY, ERROR, STALE and FATAL. */
197
+ status: ProviderStatus;
198
+ private readonly main;
199
+ private readonly fetch;
200
+ private readonly flushInterval;
201
+ private stateEtag;
202
+ constructor(resolver: LocalResolver, options: ProviderOptions);
203
+ initialize(context?: EvaluationContext): Promise<void>;
204
+ onClose(): Promise<void>;
205
+ evaluate<T>(flagKey: string, defaultValue: T, context: EvaluationContext): Promise<ResolutionDetails<T>>;
206
+ /**
207
+ * Internal recursive method for resolving with sticky assignments.
208
+ *
209
+ * @private
210
+ */
211
+ private resolveWithStickyInternal;
212
+ private remoteResolve;
213
+ /**
214
+ * Extract and validate the value from a resolved flag.
215
+ */
216
+ private extractValue;
217
+ updateState(signal?: AbortSignal): Promise<void>;
218
+ flush(signal?: AbortSignal): Promise<void>;
219
+ private fetchResolveStateUri;
220
+ private fetchToken;
221
+ private static convertReason;
222
+ private static convertEvaluationContext;
223
+ /** Resolves with an evaluation of a Boolean flag */
224
+ resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: EvaluationContext): Promise<ResolutionDetails<boolean>>;
225
+ /** Resolves with an evaluation of a Numbers flag */
226
+ resolveNumberEvaluation(flagKey: string, defaultValue: number, context: EvaluationContext): Promise<ResolutionDetails<number>>;
227
+ /** Resolves with an evaluation of an Object flag */
228
+ resolveObjectEvaluation<T extends JsonValue>(flagKey: string, defaultValue: T, context: EvaluationContext): Promise<ResolutionDetails<T>>;
229
+ /** Resolves with an evaluation of a String flag */
230
+ resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext): Promise<ResolutionDetails<string>>;
231
+ }
232
+ //#endregion
233
+ //#region src/index.browser.d.ts
234
+ declare function createConfidenceServerProvider(options: ProviderOptions): ConfidenceServerProviderLocal;
235
+ //#endregion
236
+ export { createConfidenceServerProvider };