@datadog/mobile-react-native-openfeature 3.5.2 → 3.5.4

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.
Files changed (58) hide show
  1. package/README.md +77 -0
  2. package/lib/commonjs/coreProvider.js +79 -0
  3. package/lib/commonjs/coreProvider.js.map +1 -0
  4. package/lib/commonjs/index.js +14 -0
  5. package/lib/commonjs/index.js.map +1 -1
  6. package/lib/commonjs/mappers.js +50 -0
  7. package/lib/commonjs/mappers.js.map +1 -0
  8. package/lib/commonjs/offlineProvider.js +149 -0
  9. package/lib/commonjs/offlineProvider.js.map +1 -0
  10. package/lib/commonjs/provider.js +9 -73
  11. package/lib/commonjs/provider.js.map +1 -1
  12. package/lib/module/coreProvider.js +72 -0
  13. package/lib/module/coreProvider.js.map +1 -0
  14. package/lib/module/index.js +3 -1
  15. package/lib/module/index.js.map +1 -1
  16. package/lib/module/mappers.js +42 -0
  17. package/lib/module/mappers.js.map +1 -0
  18. package/lib/module/offlineProvider.js +143 -0
  19. package/lib/module/offlineProvider.js.map +1 -0
  20. package/lib/module/provider.js +7 -71
  21. package/lib/module/provider.js.map +1 -1
  22. package/lib/typescript/core/src/flags/FlagsClient.d.ts +96 -0
  23. package/lib/typescript/core/src/flags/FlagsClient.d.ts.map +1 -1
  24. package/lib/typescript/core/src/flags/configuration/context.d.ts +20 -0
  25. package/lib/typescript/core/src/flags/configuration/context.d.ts.map +1 -0
  26. package/lib/typescript/core/src/flags/configuration/index.d.ts +5 -0
  27. package/lib/typescript/core/src/flags/configuration/index.d.ts.map +1 -0
  28. package/lib/typescript/core/src/flags/configuration/precomputed.d.ts +25 -0
  29. package/lib/typescript/core/src/flags/configuration/precomputed.d.ts.map +1 -0
  30. package/lib/typescript/core/src/flags/configuration/types.d.ts +24 -0
  31. package/lib/typescript/core/src/flags/configuration/types.d.ts.map +1 -0
  32. package/lib/typescript/core/src/flags/configuration/wire.d.ts +2 -0
  33. package/lib/typescript/core/src/flags/configuration/wire.d.ts.map +1 -0
  34. package/lib/typescript/core/src/flags/internal.d.ts.map +1 -1
  35. package/lib/typescript/core/src/flags/types.d.ts +1 -1
  36. package/lib/typescript/core/src/flags/types.d.ts.map +1 -1
  37. package/lib/typescript/core/src/index.d.ts +4 -2
  38. package/lib/typescript/core/src/index.d.ts.map +1 -1
  39. package/lib/typescript/core/src/version.d.ts +1 -1
  40. package/lib/typescript/react-native-openfeature/src/coreProvider.d.ts +34 -0
  41. package/lib/typescript/react-native-openfeature/src/coreProvider.d.ts.map +1 -0
  42. package/lib/typescript/react-native-openfeature/src/index.d.ts +3 -1
  43. package/lib/typescript/react-native-openfeature/src/index.d.ts.map +1 -1
  44. package/lib/typescript/react-native-openfeature/src/mappers.d.ts +20 -0
  45. package/lib/typescript/react-native-openfeature/src/mappers.d.ts.map +1 -0
  46. package/lib/typescript/react-native-openfeature/src/offlineProvider.d.ts +59 -0
  47. package/lib/typescript/react-native-openfeature/src/offlineProvider.d.ts.map +1 -0
  48. package/lib/typescript/react-native-openfeature/src/provider.d.ts +8 -21
  49. package/lib/typescript/react-native-openfeature/src/provider.d.ts.map +1 -1
  50. package/package.json +5 -5
  51. package/src/__tests__/offlineProvider.integration.test.ts +271 -0
  52. package/src/__tests__/offlineProvider.test.ts +252 -0
  53. package/src/__tests__/provider.test.ts +74 -0
  54. package/src/coreProvider.ts +142 -0
  55. package/src/index.ts +8 -1
  56. package/src/mappers.ts +47 -0
  57. package/src/offlineProvider.ts +185 -0
  58. package/src/provider.ts +10 -139
@@ -0,0 +1,34 @@
1
+ import type { FlagsClient } from '@datadog/mobile-react-native';
2
+ import type { EvaluationContext as OFEvaluationContext, JsonValue, Logger, Paradigm, Provider, ProviderMetadata, ResolutionDetails, ProviderEventEmitter, ProviderEvents } from '@openfeature/web-sdk';
3
+ export interface DatadogOpenFeatureProviderOptions {
4
+ /**
5
+ * The name of the Datadog Flags client to use.
6
+ *
7
+ * Provide this parameter in order to use different Datadog Flags clients for different OpenFeature domains.
8
+ *
9
+ * @default 'default'
10
+ */
11
+ clientName?: string;
12
+ }
13
+ /**
14
+ * Shared base for the Datadog OpenFeature providers. It owns the `FlagsClient`, the event
15
+ * emitter, and evaluation (`resolveX`) — everything the online and offline providers have in
16
+ * common. It does not decide how the evaluation context is sourced (fetch vs. offline load);
17
+ * concrete providers implement `initialize`/`onContextChange`.
18
+ *
19
+ * Internal: not exported from the package entry point. Customers use
20
+ * `DatadogOpenFeatureProvider` (online) or `DatadogOfflineOpenFeatureProvider` (offline).
21
+ */
22
+ export declare abstract class DatadogCoreOpenFeatureProvider implements Provider {
23
+ readonly runsOn: Paradigm;
24
+ abstract readonly metadata: ProviderMetadata;
25
+ private options;
26
+ protected flagsClient: FlagsClient;
27
+ readonly events: ProviderEventEmitter<ProviderEvents>;
28
+ constructor(options?: DatadogOpenFeatureProviderOptions);
29
+ resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, _context: OFEvaluationContext, _logger: Logger): ResolutionDetails<boolean>;
30
+ resolveStringEvaluation(flagKey: string, defaultValue: string, _context: OFEvaluationContext, _logger: Logger): ResolutionDetails<string>;
31
+ resolveNumberEvaluation(flagKey: string, defaultValue: number, _context: OFEvaluationContext, _logger: Logger): ResolutionDetails<number>;
32
+ resolveObjectEvaluation<T extends JsonValue>(flagKey: string, defaultValue: T, _context: OFEvaluationContext, _logger: Logger): ResolutionDetails<T>;
33
+ }
34
+ //# sourceMappingURL=coreProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coreProvider.d.ts","sourceRoot":"","sources":["../../../../src/coreProvider.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE7E,OAAO,KAAK,EACR,iBAAiB,IAAI,mBAAmB,EACxC,SAAS,EACT,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACjB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,WAAW,iCAAiC;IAC9C;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;GAQG;AACH,8BAAsB,8BAA+B,YAAW,QAAQ;IACpE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAY;IACrC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IAE7C,OAAO,CAAC,OAAO,CAAoC;IACnD,SAAS,CAAC,WAAW,EAAE,WAAW,CAAC;IAEnC,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC,cAAc,CAAC,CAAiC;gBAE1E,OAAO,GAAE,iCAAsC;IAU3D,wBAAwB,CACpB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,OAAO,EACrB,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,EAAE,MAAM,GAChB,iBAAiB,CAAC,OAAO,CAAC;IAQ7B,uBAAuB,CACnB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,EAAE,MAAM,GAChB,iBAAiB,CAAC,MAAM,CAAC;IAQ5B,uBAAuB,CACnB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,EAAE,MAAM,GAChB,iBAAiB,CAAC,MAAM,CAAC;IAQ5B,uBAAuB,CAAC,CAAC,SAAS,SAAS,EACvC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,CAAC,EACf,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,EAAE,MAAM,GAChB,iBAAiB,CAAC,CAAC,CAAC;CAY1B"}
@@ -1,5 +1,7 @@
1
+ import { configurationFromString } from '@datadog/mobile-react-native';
2
+ import { DatadogOfflineOpenFeatureProvider } from './offlineProvider';
1
3
  import { DatadogOpenFeatureProvider } from './provider';
2
4
  import type { DatadogOpenFeatureProviderOptions } from './provider';
3
- export { DatadogOpenFeatureProvider };
5
+ export { DatadogOpenFeatureProvider, DatadogOfflineOpenFeatureProvider, configurationFromString };
4
6
  export type { DatadogOpenFeatureProviderOptions };
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,YAAY,CAAC;AAEpE,OAAO,EAAE,0BAA0B,EAAE,CAAC;AACtC,YAAY,EAAE,iCAAiC,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,OAAO,EAAE,iCAAiC,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,YAAY,CAAC;AAEpE,OAAO,EACH,0BAA0B,EAC1B,iCAAiC,EACjC,uBAAuB,EAC1B,CAAC;AACF,YAAY,EAAE,iCAAiC,EAAE,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { EvaluationContext as DdEvaluationContext } from '@datadog/mobile-react-native';
2
+ import type { EvaluationContext as OFEvaluationContext } from '@openfeature/web-sdk';
3
+ /**
4
+ * Convert an OpenFeature evaluation context into the Datadog Flags shape.
5
+ */
6
+ export declare const toDdContext: (context: OFEvaluationContext) => DdEvaluationContext;
7
+ /**
8
+ * Whether an OpenFeature evaluation context carries no information — no targeting key and no
9
+ * attributes with a defined value (so `{}` and `{ targetingKey: undefined }` are both empty).
10
+ * Used by the offline provider to avoid overwriting a configuration's embedded context with an
11
+ * empty context stamped by the OpenFeature lifecycle.
12
+ *
13
+ * Note: an explicit `targetingKey: ''` is **not** empty. An empty string is a real (anonymous)
14
+ * targeting key — a distinct subject — not the absence of a context. Only a genuinely absent
15
+ * context (`{}` / `clearContext()`) re-adopts the configuration's embedded context; `{ targetingKey:
16
+ * '' }` is reconciled as a real context, so it must match the precomputed snapshot or the provider
17
+ * enters `ERROR` (serving coded defaults) rather than silently serving another subject's flags.
18
+ */
19
+ export declare const isEmptyContext: (context: OFEvaluationContext) => boolean;
20
+ //# sourceMappingURL=mappers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mappers.d.ts","sourceRoot":"","sources":["../../../../src/mappers.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACR,iBAAiB,IAAI,mBAAmB,EAE3C,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,iBAAiB,IAAI,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAErF;;GAEG;AACH,eAAO,MAAM,WAAW,YACX,mBAAmB,KAC7B,mBAaF,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,YAAa,mBAAmB,KAAG,OAE7D,CAAC"}
@@ -0,0 +1,59 @@
1
+ import type { ParsedFlagsConfiguration } from '@datadog/mobile-react-native';
2
+ import type { EvaluationContext as OFEvaluationContext, ProviderMetadata } from '@openfeature/web-sdk';
3
+ import { DatadogCoreOpenFeatureProvider } from './coreProvider';
4
+ /**
5
+ * An offline Datadog OpenFeature provider.
6
+ *
7
+ * It behaves like the online `DatadogOpenFeatureProvider` — same flag evaluation and
8
+ * exposure/RUM tracking — **except it never fetches configuration from the network**.
9
+ * Instead of fetching on `initialize`/`onContextChange`, it evaluates against a configuration
10
+ * supplied via {@link DatadogOfflineOpenFeatureProvider.setConfiguration}. A precomputed
11
+ * configuration carries the evaluation context it was computed for, so you should **not** call
12
+ * `OpenFeature.setContext` for the offline precomputed flow — see the class remarks.
13
+ *
14
+ * A runtime context that does not match the configuration's embedded context (compared after
15
+ * normalization) cannot be served (offline never fetches), so it puts the provider into the
16
+ * OpenFeature `ERROR` state and evaluations fall back to your coded defaults (`INVALID_CONTEXT`).
17
+ * An empty *effective* context re-adopts the embedded context and recovers — but note that
18
+ * `clearContext(domain)` falls back to the global context, which may itself be non-empty and
19
+ * mismatching (and would keep the provider in `ERROR`). Load the configuration before setting the
20
+ * provider so it is ready with real flag values from the start:
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { OpenFeature } from '@openfeature/web-sdk';
25
+ * import {
26
+ * DatadogOfflineOpenFeatureProvider,
27
+ * configurationFromString
28
+ * } from '@datadog/mobile-react-native-openfeature';
29
+ *
30
+ * const provider = new DatadogOfflineOpenFeatureProvider();
31
+ * provider.setConfiguration(configurationFromString(wire)); // no network
32
+ * await OpenFeature.setProviderAndWait(provider);
33
+ *
34
+ * const client = OpenFeature.getClient();
35
+ * const enabled = client.getBooleanValue('new-feature', false);
36
+ * ```
37
+ */
38
+ export declare class DatadogOfflineOpenFeatureProvider extends DatadogCoreOpenFeatureProvider {
39
+ readonly metadata: ProviderMetadata;
40
+ private configurationInError;
41
+ initialize(context?: OFEvaluationContext): Promise<void>;
42
+ onContextChange(_oldContext: OFEvaluationContext, newContext: OFEvaluationContext): void;
43
+ /**
44
+ * Load a configuration into the provider for offline evaluation.
45
+ *
46
+ * @param configuration A configuration parsed from a `ConfigurationWire` string via
47
+ * `configurationFromString`.
48
+ */
49
+ setConfiguration(configuration: ParsedFlagsConfiguration): void;
50
+ private applyContext;
51
+ /**
52
+ * Map a reconcile error code to the precise OpenFeature error type, so direct callers of
53
+ * `initialize`/`onContextChange` (and `setProviderAndWait`) receive the correct typed error.
54
+ * (Web SDK 1.8.0 drops the code from the lifecycle-generated error *event*, but the thrown
55
+ * error type is still accurate for callers.)
56
+ */
57
+ private toError;
58
+ }
59
+ //# sourceMappingURL=offlineProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"offlineProvider.d.ts","sourceRoot":"","sources":["../../../../src/offlineProvider.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAER,wBAAwB,EAC3B,MAAM,8BAA8B,CAAC;AAQtC,OAAO,KAAK,EACR,iBAAiB,IAAI,mBAAmB,EAExC,gBAAgB,EACnB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAC;AAsBhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,iCAAkC,SAAQ,8BAA8B;IACjF,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAEjC;IAMF,OAAO,CAAC,oBAAoB,CAAS;IAE/B,UAAU,CAAC,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;IAYlE,eAAe,CACX,WAAW,EAAE,mBAAmB,EAChC,UAAU,EAAE,mBAAmB,GAChC,IAAI;IAYP;;;;;OAKG;IACH,gBAAgB,CAAC,aAAa,EAAE,wBAAwB,GAAG,IAAI;IAuB/D,OAAO,CAAC,YAAY;IAgBpB;;;;;OAKG;IACH,OAAO,CAAC,OAAO;CAgBlB"}
@@ -1,27 +1,14 @@
1
- import type { EvaluationContext as OFEvaluationContext, JsonValue, Logger, Paradigm, Provider, ProviderMetadata, ResolutionDetails, ProviderEventEmitter, ProviderEvents } from '@openfeature/web-sdk';
2
- export interface DatadogOpenFeatureProviderOptions {
3
- /**
4
- * The name of the Datadog Flags client to use.
5
- *
6
- * Provide this parameter in order to use different Datadog Flags clients for different OpenFeature domains.
7
- *
8
- * @default 'default'
9
- */
10
- clientName?: string;
11
- }
12
- export declare class DatadogOpenFeatureProvider implements Provider {
13
- readonly runsOn: Paradigm;
1
+ import type { EvaluationContext as OFEvaluationContext, ProviderMetadata } from '@openfeature/web-sdk';
2
+ import { DatadogCoreOpenFeatureProvider } from './coreProvider';
3
+ export type { DatadogOpenFeatureProviderOptions } from './coreProvider';
4
+ /**
5
+ * The online Datadog OpenFeature provider. Fetches precomputed flag assignments from Datadog
6
+ * whenever the evaluation context is set or changed.
7
+ */
8
+ export declare class DatadogOpenFeatureProvider extends DatadogCoreOpenFeatureProvider {
14
9
  readonly metadata: ProviderMetadata;
15
- private options;
16
- private flagsClient;
17
- readonly events: ProviderEventEmitter<ProviderEvents>;
18
10
  private contextChangePromise;
19
- constructor(options?: DatadogOpenFeatureProviderOptions);
20
11
  initialize(context?: OFEvaluationContext): Promise<void>;
21
12
  onContextChange(_oldContext: OFEvaluationContext, newContext: OFEvaluationContext): Promise<void>;
22
- resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, _context: OFEvaluationContext, _logger: Logger): ResolutionDetails<boolean>;
23
- resolveStringEvaluation(flagKey: string, defaultValue: string, _context: OFEvaluationContext, _logger: Logger): ResolutionDetails<string>;
24
- resolveNumberEvaluation(flagKey: string, defaultValue: number, _context: OFEvaluationContext, _logger: Logger): ResolutionDetails<number>;
25
- resolveObjectEvaluation<T extends JsonValue>(flagKey: string, defaultValue: T, _context: OFEvaluationContext, _logger: Logger): ResolutionDetails<T>;
26
13
  }
27
14
  //# sourceMappingURL=provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../../src/provider.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACR,iBAAiB,IAAI,mBAAmB,EACxC,SAAS,EACT,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,EAEjB,oBAAoB,EACpB,cAAc,EACjB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,WAAW,iCAAiC;IAC9C;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qBAAa,0BAA2B,YAAW,QAAQ;IACvD,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAY;IACrC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAEjC;IAEF,OAAO,CAAC,OAAO,CAAoC;IACnD,OAAO,CAAC,WAAW,CAAc;IAEjC,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC,cAAc,CAAC,CAAiC;IACtF,OAAO,CAAC,oBAAoB,CAAqB;gBAErC,OAAO,GAAE,iCAAsC;IAUrD,UAAU,CAAC,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;IAS5D,eAAe,CACjB,WAAW,EAAE,mBAAmB,EAChC,UAAU,EAAE,mBAAmB,GAChC,OAAO,CAAC,IAAI,CAAC;IAYhB,wBAAwB,CACpB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,OAAO,EACrB,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,EAAE,MAAM,GAChB,iBAAiB,CAAC,OAAO,CAAC;IAQ7B,uBAAuB,CACnB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,EAAE,MAAM,GAChB,iBAAiB,CAAC,MAAM,CAAC;IAQ5B,uBAAuB,CACnB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,EAAE,MAAM,GAChB,iBAAiB,CAAC,MAAM,CAAC;IAQ5B,uBAAuB,CAAC,CAAC,SAAS,SAAS,EACvC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,CAAC,EACf,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,EAAE,MAAM,GAChB,iBAAiB,CAAC,CAAC,CAAC;CAY1B"}
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../../src/provider.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACR,iBAAiB,IAAI,mBAAmB,EACxC,gBAAgB,EACnB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAC;AAGhE,YAAY,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AAExE;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,8BAA8B;IAC1E,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAEjC;IAEF,OAAO,CAAC,oBAAoB,CAAqB;IAE3C,UAAU,CAAC,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;IAS5D,eAAe,CACjB,WAAW,EAAE,mBAAmB,EAChC,UAAU,EAAE,mBAAmB,GAChC,OAAO,CAAC,IAAI,CAAC;CAWnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datadog/mobile-react-native-openfeature",
3
- "version": "3.5.2",
3
+ "version": "3.5.4",
4
4
  "description": "A client-side React Native module to provide OpenFeature integration with Datadog Feature Flags",
5
5
  "keywords": [
6
6
  "datadog",
@@ -38,16 +38,16 @@
38
38
  "prepare": "rm -rf lib && yarn bob build"
39
39
  },
40
40
  "devDependencies": {
41
- "@datadog/mobile-react-native": "^3.5.2",
41
+ "@datadog/mobile-react-native": "^3.5.4",
42
42
  "@openfeature/core": "^1.9.2",
43
- "@openfeature/web-sdk": "^1.7.3",
43
+ "@openfeature/web-sdk": "^1.8.0",
44
44
  "@testing-library/react-native": "7.0.2",
45
45
  "react-native-builder-bob": "0.26.0",
46
46
  "react-native-gesture-handler": "1.10.3"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "@datadog/mobile-react-native": "^3.1.0",
50
- "@openfeature/web-sdk": "^1.7.3",
50
+ "@openfeature/web-sdk": "^1.8.0",
51
51
  "react": ">=16.13.1",
52
52
  "react-native": ">=0.63.4 <1.0"
53
53
  },
@@ -83,5 +83,5 @@
83
83
  ]
84
84
  ]
85
85
  },
86
- "gitHead": "92462dccefd689815d87dabbad0d41572cd06cca"
86
+ "gitHead": "c0afe3bf819756eab3dd9a32553ec49fae513105"
87
87
  }
@@ -0,0 +1,271 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+
7
+ // Integration test: exercises the offline provider against the REAL core FlagsClient (no mock of
8
+ // @datadog/mobile-react-native) AND through the REAL OpenFeature Web SDK lifecycle, so the actual
9
+ // configuration parse, context reconcile, provider-status transitions, and evaluation-detail
10
+ // mapping run. Assertions read the SDK's provider status (the status-overwrite bug is only visible
11
+ // end to end), the evaluation error code, and served values. Only the native TurboModule is stubbed
12
+ // (it is unavailable under jest) so ready-state evaluation can track exposures without throwing.
13
+
14
+ import { configurationFromString } from '@datadog/mobile-react-native';
15
+ import { ErrorCode, OpenFeature, ProviderStatus } from '@openfeature/web-sdk';
16
+
17
+ import { DatadogOfflineOpenFeatureProvider } from '../offlineProvider';
18
+
19
+ // Stub the native flags TurboModule (TurboModuleRegistry.get returns null under jest), so
20
+ // ready-state evaluation can call trackEvaluation without throwing.
21
+ jest.mock('../../../core/src/specs/NativeDdFlags', () => ({
22
+ __esModule: true,
23
+ default: {
24
+ enable: jest.fn(() => Promise.resolve()),
25
+ setEvaluationContext: jest.fn(() => Promise.resolve({})),
26
+ trackEvaluation: jest.fn(() => Promise.resolve())
27
+ }
28
+ }));
29
+
30
+ const wireFor = (targetingKey: string): string =>
31
+ JSON.stringify({
32
+ version: 1,
33
+ precomputed: {
34
+ response: JSON.stringify({
35
+ data: {
36
+ attributes: {
37
+ obfuscated: false,
38
+ flags: {
39
+ 'new-feature': {
40
+ variationType: 'boolean',
41
+ variationValue: true,
42
+ variationKey: 'true',
43
+ allocationKey: 'alloc-1',
44
+ reason: 'STATIC',
45
+ doLog: false,
46
+ extraLogging: {}
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }),
52
+ context: { targetingKey }
53
+ }
54
+ });
55
+
56
+ // A unique OpenFeature domain + Datadog clientName per test keeps providers isolated (separate
57
+ // domains otherwise share the same underlying FlagsClient).
58
+ let seq = 0;
59
+ const freshNames = () => {
60
+ seq += 1;
61
+ return { domain: `offline-int-${seq}`, clientName: `offline-int-${seq}` };
62
+ };
63
+
64
+ describe('DatadogOfflineOpenFeatureProvider (integration, real FlagsClient + OpenFeature)', () => {
65
+ afterEach(async () => {
66
+ await OpenFeature.clearProviders();
67
+ // Reset the global context so a context set by one test does not leak into the next.
68
+ await OpenFeature.clearContext();
69
+ });
70
+
71
+ it('is READY when a matching configuration is loaded before registration', async () => {
72
+ const { domain, clientName } = freshNames();
73
+ const provider = new DatadogOfflineOpenFeatureProvider({ clientName });
74
+ provider.setConfiguration(configurationFromString(wireFor('user-123')));
75
+
76
+ await OpenFeature.setProviderAndWait(domain, provider);
77
+
78
+ const client = OpenFeature.getClient(domain);
79
+ expect(client.providerStatus).toBe(ProviderStatus.READY);
80
+ expect(client.getBooleanValue('new-feature', false)).toBe(true);
81
+ });
82
+
83
+ it('enters ERROR and serves defaults on a mismatching setContext, then recovers on a matching one', async () => {
84
+ const { domain, clientName } = freshNames();
85
+ const provider = new DatadogOfflineOpenFeatureProvider({ clientName });
86
+ provider.setConfiguration(configurationFromString(wireFor('user-123')));
87
+ await OpenFeature.setProviderAndWait(domain, provider);
88
+
89
+ // A runtime context that does not match the snapshot cannot be served.
90
+ await OpenFeature.setContext(domain, { targetingKey: 'someone-else' });
91
+
92
+ const client = OpenFeature.getClient(domain);
93
+ expect(client.providerStatus).toBe(ProviderStatus.ERROR);
94
+ // Serving the coded default, with the precise error code.
95
+ const details = client.getBooleanDetails('new-feature', false);
96
+ expect(details.value).toBe(false);
97
+ expect(details.errorCode).toBe(ErrorCode.INVALID_CONTEXT);
98
+
99
+ // Setting the matching context again recovers automatically and serves the retained value.
100
+ await OpenFeature.setContext(domain, { targetingKey: 'user-123' });
101
+ expect(client.providerStatus).toBe(ProviderStatus.READY);
102
+ expect(client.getBooleanValue('new-feature', false)).toBe(true);
103
+ });
104
+
105
+ it('errors on an explicit empty-string targeting key (a real anonymous subject, not "cleared")', async () => {
106
+ const { domain, clientName } = freshNames();
107
+ const provider = new DatadogOfflineOpenFeatureProvider({ clientName });
108
+ provider.setConfiguration(configurationFromString(wireFor('user-123')));
109
+ await OpenFeature.setProviderAndWait(domain, provider);
110
+
111
+ // `{ targetingKey: '' }` is an anonymous subject, distinct from the user-123 snapshot — not
112
+ // the same as clearing context. It must error rather than silently serve user-123's flags.
113
+ await OpenFeature.setContext(domain, { targetingKey: '' });
114
+
115
+ const client = OpenFeature.getClient(domain);
116
+ expect(client.providerStatus).toBe(ProviderStatus.ERROR);
117
+ expect(client.getBooleanDetails('new-feature', false).errorCode).toBe(
118
+ ErrorCode.INVALID_CONTEXT
119
+ );
120
+ });
121
+
122
+ it('stays READY when the context is cleared (empty = re-adopt embedded)', async () => {
123
+ const { domain, clientName } = freshNames();
124
+ const provider = new DatadogOfflineOpenFeatureProvider({ clientName });
125
+ provider.setConfiguration(configurationFromString(wireFor('user-123')));
126
+ await OpenFeature.setProviderAndWait(domain, provider);
127
+
128
+ await OpenFeature.setContext(domain, { targetingKey: 'user-123' });
129
+ expect(OpenFeature.getClient(domain).providerStatus).toBe(
130
+ ProviderStatus.READY
131
+ );
132
+
133
+ // clearContext(domain) falls back to the empty global context; empty means "no override", so
134
+ // the embedded context is re-adopted and the provider stays READY.
135
+ await OpenFeature.clearContext(domain);
136
+ expect(OpenFeature.getClient(domain).providerStatus).toBe(
137
+ ProviderStatus.READY
138
+ );
139
+ });
140
+
141
+ it('starts in ERROR when registered before any configuration, then recovers via setConfiguration', async () => {
142
+ const { domain, clientName } = freshNames();
143
+ const provider = new DatadogOfflineOpenFeatureProvider({ clientName });
144
+
145
+ // Provider-first: initialize rejects (no usable configuration), so registration surfaces
146
+ // an error and the provider is ERROR rather than a misleading READY.
147
+ await expect(
148
+ OpenFeature.setProviderAndWait(domain, provider)
149
+ ).rejects.toThrow();
150
+ const client = OpenFeature.getClient(domain);
151
+ expect(client.providerStatus).toBe(ProviderStatus.ERROR);
152
+
153
+ // Loading a valid configuration recovers via the emitted PROVIDER_READY.
154
+ provider.setConfiguration(configurationFromString(wireFor('user-123')));
155
+ expect(client.providerStatus).toBe(ProviderStatus.READY);
156
+ expect(client.getBooleanValue('new-feature', false)).toBe(true);
157
+ });
158
+
159
+ it('recovers via setConfiguration when a config matching the current context is loaded', async () => {
160
+ const { domain, clientName } = freshNames();
161
+ const provider = new DatadogOfflineOpenFeatureProvider({ clientName });
162
+ provider.setConfiguration(configurationFromString(wireFor('user-123')));
163
+ await OpenFeature.setProviderAndWait(domain, provider);
164
+
165
+ await OpenFeature.setContext(domain, { targetingKey: 'someone-else' });
166
+ const client = OpenFeature.getClient(domain);
167
+ expect(client.providerStatus).toBe(ProviderStatus.ERROR);
168
+
169
+ // Load a configuration computed for the now-current context: it reconciles to ready and
170
+ // setConfiguration emits PROVIDER_READY.
171
+ provider.setConfiguration(
172
+ configurationFromString(wireFor('someone-else'))
173
+ );
174
+ expect(client.providerStatus).toBe(ProviderStatus.READY);
175
+ });
176
+
177
+ describe('domain / global-context isolation', () => {
178
+ it('stays READY with the documented setup: global mismatch set, explicit empty domain context, then register', async () => {
179
+ const { domain, clientName } = freshNames();
180
+ const provider = new DatadogOfflineOpenFeatureProvider({
181
+ clientName
182
+ });
183
+ provider.setConfiguration(
184
+ configurationFromString(wireFor('user-123'))
185
+ );
186
+
187
+ // The documented order: a mismatching GLOBAL context is already in place, the dedicated
188
+ // domain is given an explicit empty context (isolating it), and only then is the provider
189
+ // registered. It initializes against the empty domain context → embedded → READY.
190
+ await OpenFeature.setContext({ targetingKey: 'global-user' });
191
+ await OpenFeature.setContext(domain, {});
192
+ await OpenFeature.setProviderAndWait(domain, provider);
193
+
194
+ expect(OpenFeature.getClient(domain).providerStatus).toBe(
195
+ ProviderStatus.READY
196
+ );
197
+ });
198
+
199
+ it('inherits a mismatching global context when the domain has none, entering ERROR', async () => {
200
+ const { domain, clientName } = freshNames();
201
+ const provider = new DatadogOfflineOpenFeatureProvider({
202
+ clientName
203
+ });
204
+ provider.setConfiguration(
205
+ configurationFromString(wireFor('user-123'))
206
+ );
207
+
208
+ // A global (non-domain) context is set; the domain has no context of its own, so it
209
+ // inherits the global one at registration → mismatch → ERROR.
210
+ await OpenFeature.setContext({ targetingKey: 'global-user' });
211
+ await expect(
212
+ OpenFeature.setProviderAndWait(domain, provider)
213
+ ).rejects.toThrow();
214
+
215
+ expect(OpenFeature.getClient(domain).providerStatus).toBe(
216
+ ProviderStatus.ERROR
217
+ );
218
+ });
219
+
220
+ it('ignores later global context changes once the domain has an explicit empty context', async () => {
221
+ const { domain, clientName } = freshNames();
222
+ const provider = new DatadogOfflineOpenFeatureProvider({
223
+ clientName
224
+ });
225
+ provider.setConfiguration(
226
+ configurationFromString(wireFor('user-123'))
227
+ );
228
+ await OpenFeature.setProviderAndWait(domain, provider);
229
+
230
+ // Give the domain its own (empty) context: this provider reads it as "no override".
231
+ await OpenFeature.setContext(domain, {});
232
+ expect(OpenFeature.getClient(domain).providerStatus).toBe(
233
+ ProviderStatus.READY
234
+ );
235
+
236
+ // A later mismatching GLOBAL context does not reach a domain that has its own context.
237
+ await OpenFeature.setContext({ targetingKey: 'global-mismatch' });
238
+ expect(OpenFeature.getClient(domain).providerStatus).toBe(
239
+ ProviderStatus.READY
240
+ );
241
+ });
242
+
243
+ it('falls back to a mismatching global context when the domain context is cleared', async () => {
244
+ const { domain, clientName } = freshNames();
245
+ const provider = new DatadogOfflineOpenFeatureProvider({
246
+ clientName
247
+ });
248
+ provider.setConfiguration(
249
+ configurationFromString(wireFor('user-123'))
250
+ );
251
+ await OpenFeature.setProviderAndWait(domain, provider);
252
+
253
+ await OpenFeature.setContext(domain, { targetingKey: 'user-123' });
254
+ expect(OpenFeature.getClient(domain).providerStatus).toBe(
255
+ ProviderStatus.READY
256
+ );
257
+
258
+ // A mismatching global context does not reach the domain while it has its own context.
259
+ await OpenFeature.setContext({ targetingKey: 'global-mismatch' });
260
+ expect(OpenFeature.getClient(domain).providerStatus).toBe(
261
+ ProviderStatus.READY
262
+ );
263
+
264
+ // Clearing the domain context falls back to the (mismatching) global context → ERROR.
265
+ await OpenFeature.clearContext(domain);
266
+ expect(OpenFeature.getClient(domain).providerStatus).toBe(
267
+ ProviderStatus.ERROR
268
+ );
269
+ });
270
+ });
271
+ });