@spotify-confidence/openfeature-server-provider-local 0.6.0 → 0.8.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.
@@ -1,5 +1,5 @@
1
1
  import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
2
- import { EvaluationContext, JsonValue, Provider, ProviderMetadata, ProviderStatus, ResolutionDetails } from "@openfeature/server-sdk";
2
+ import { EvaluationContext, JsonValue, Provider, ProviderMetadata, ProviderStatus } from "@openfeature/server-sdk";
3
3
 
4
4
  //#region src/proto/confidence/flags/types/v1/types.d.ts
5
5
  /** Schema for the value of a flag. */
@@ -173,6 +173,27 @@ interface ResolveFlagsResponse {
173
173
  /** Unique identifier for this particular resolve request. */
174
174
  resolveId: string;
175
175
  }
176
+ interface ApplyFlagsRequest {
177
+ /** The flags to apply and information about when they were applied. */
178
+ flags: AppliedFlag[];
179
+ /** Credentials for the client. */
180
+ clientSecret: string;
181
+ /** An opaque token that was returned from `ResolveFlags`; it must be set. */
182
+ resolveToken: Uint8Array;
183
+ /**
184
+ * The client time when the this request was sent, used for correcting
185
+ * clock skew from the client.
186
+ */
187
+ sendTime?: Date | undefined;
188
+ /** Information about the SDK used to initiate the request. */
189
+ sdk?: Sdk | undefined;
190
+ }
191
+ interface AppliedFlag {
192
+ /** The id of the flag that should be applied, has the format `flags/*`. */
193
+ flag: string;
194
+ /** The client time when the flag was applied. */
195
+ applyTime?: Date | undefined;
196
+ }
176
197
  interface ResolvedFlag {
177
198
  /** The id of the flag that as resolved. */
178
199
  flag: string;
@@ -189,9 +210,13 @@ interface ResolvedFlag {
189
210
  flagSchema?: FlagSchema_StructFlagSchema | undefined;
190
211
  /** The reason to why the flag could be resolved or not. */
191
212
  reason: ResolveReason;
213
+ /** Determines whether the flag should be applied in the clients */
214
+ shouldApply: boolean;
192
215
  }
193
216
  declare const ResolveFlagsRequest: MessageFns$3<ResolveFlagsRequest>;
194
217
  declare const ResolveFlagsResponse: MessageFns$3<ResolveFlagsResponse>;
218
+ declare const ApplyFlagsRequest: MessageFns$3<ApplyFlagsRequest>;
219
+ declare const AppliedFlag: MessageFns$3<AppliedFlag>;
195
220
  declare const ResolvedFlag: MessageFns$3<ResolvedFlag>;
196
221
  type Builtin$3 = Date | Function | Uint8Array | string | number | boolean | undefined;
197
222
  type DeepPartial$3<T> = T extends Builtin$3 ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial$3<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial$3<U>> : T extends {} ? { [K in keyof T]?: DeepPartial$3<T[K]> } : Partial<T>;
@@ -322,6 +347,7 @@ interface LocalResolver {
322
347
  setResolverState(request: SetResolverStateRequest): void;
323
348
  flushLogs(): Uint8Array;
324
349
  flushAssigned(): Uint8Array;
350
+ applyFlags(request: ApplyFlagsRequest): void;
325
351
  }
326
352
  //#endregion
327
353
  //#region src/materialization.d.ts
@@ -398,7 +424,40 @@ interface MaterializationStore {
398
424
  writeMaterializations?(writeOps: MaterializationStore.WriteOp[]): Promise<void>;
399
425
  }
400
426
  //#endregion
427
+ //#region src/types.d.ts
428
+ type ResolutionReason = "ERROR" | "FLAG_ARCHIVED" | "MATCH" | "NO_SEGMENT_MATCH" | "TARGETING_KEY_ERROR" | "NO_TREATMENT_MATCH" | "UNSPECIFIED";
429
+ declare enum ErrorCode {
430
+ PROVIDER_NOT_READY = "PROVIDER_NOT_READY",
431
+ PROVIDER_FATAL = "PROVIDER_FATAL",
432
+ FLAG_NOT_FOUND = "FLAG_NOT_FOUND",
433
+ TYPE_MISMATCH = "TYPE_MISMATCH",
434
+ GENERAL = "GENERAL",
435
+ }
436
+ interface ResolutionDetails<T> {
437
+ reason: ResolutionReason;
438
+ value: T;
439
+ variant?: string;
440
+ errorCode?: ErrorCode;
441
+ errorMessage?: string;
442
+ shouldApply: boolean;
443
+ }
444
+ type FlagPrimitive = null | boolean | string | number;
445
+ type FlagObject = {
446
+ [key: string]: FlagValue;
447
+ };
448
+ type FlagValue = FlagPrimitive | FlagObject;
449
+ //#endregion
450
+ //#region src/flag-bundle.d.ts
451
+ interface FlagBundle {
452
+ flags: Record<string, ResolutionDetails<FlagObject | null> | undefined>;
453
+ resolveId: string;
454
+ resolveToken: string;
455
+ errorCode?: ErrorCode;
456
+ errorMessage?: string;
457
+ }
458
+ //#endregion
401
459
  //#region src/ConfidenceServerProviderLocal.d.ts
460
+ type FlagBundle$1 = FlagBundle;
402
461
  interface ProviderOptions {
403
462
  flagClientSecret: string;
404
463
  initializeTimeout?: number;
@@ -414,7 +473,7 @@ interface ProviderOptions {
414
473
  * @public
415
474
  */
416
475
  declare class ConfidenceServerProviderLocal implements Provider {
417
- private resolver;
476
+ private resolverOrPromise;
418
477
  private options;
419
478
  /** Static data about the provider */
420
479
  readonly metadata: ProviderMetadata;
@@ -426,22 +485,19 @@ declare class ConfidenceServerProviderLocal implements Provider {
426
485
  private readonly flushInterval;
427
486
  private readonly materializationStore;
428
487
  private stateEtag;
429
- constructor(resolver: LocalResolver, options: ProviderOptions);
488
+ private get resolver();
489
+ constructor(resolverOrPromise: LocalResolver | Promise<LocalResolver>, options: ProviderOptions);
430
490
  initialize(context?: EvaluationContext): Promise<void>;
431
491
  onClose(): Promise<void>;
432
- evaluate<T>(flagKey: string, defaultValue: T, context: EvaluationContext): Promise<ResolutionDetails<T>>;
492
+ resolve(context: EvaluationContext, flagNames: string[], apply?: boolean): Promise<FlagBundle$1>;
493
+ evaluate<T extends JsonValue>(flagKey: string, defaultValue: T, context: EvaluationContext): Promise<ResolutionDetails<T>>;
433
494
  private resolveWithSticky;
434
- /**
435
- * Extract and validate the value from a resolved flag.
436
- */
437
- private extractValue;
438
495
  updateState(signal?: AbortSignal): Promise<void>;
439
496
  flush(signal?: AbortSignal): Promise<void>;
440
497
  private flushAssigned;
441
498
  private sendFlagLogs;
442
499
  private readMaterializations;
443
500
  private writeMaterializations;
444
- private static convertReason;
445
501
  private static convertEvaluationContext;
446
502
  /** Resolves with an evaluation of a Boolean flag */
447
503
  resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: EvaluationContext): Promise<ResolutionDetails<boolean>>;
@@ -451,9 +507,22 @@ declare class ConfidenceServerProviderLocal implements Provider {
451
507
  resolveObjectEvaluation<T extends JsonValue>(flagKey: string, defaultValue: T, context: EvaluationContext): Promise<ResolutionDetails<T>>;
452
508
  /** Resolves with an evaluation of a String flag */
453
509
  resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext): Promise<ResolutionDetails<string>>;
510
+ /**
511
+ * Applies a previously resolved flag, logging that it was used/exposed.
512
+ * Call this when a flag value is actually rendered or used in the client.
513
+ * @param resolveToken - Base64-encoded resolve token from the flag bundle
514
+ * @param flagName - Name of the flag to apply
515
+ */
516
+ applyFlag(resolveToken: string, flagName: string): void;
454
517
  }
455
518
  //#endregion
456
519
  //#region src/index.node.d.ts
457
- declare function createConfidenceServerProvider(options: ProviderOptions): ConfidenceServerProviderLocal;
520
+ interface ProviderOptionsExt extends ProviderOptions {
521
+ wasmPath?: string;
522
+ }
523
+ declare function createConfidenceServerProvider({
524
+ wasmPath,
525
+ ...options
526
+ }: ProviderOptionsExt): ConfidenceServerProviderLocal;
458
527
  //#endregion
459
- export { type MaterializationStore, createConfidenceServerProvider };
528
+ export { type MaterializationStore, ProviderOptionsExt, createConfidenceServerProvider };