@datadog/mobile-react-native-openfeature 3.9.0 → 3.11.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.
Files changed (71) hide show
  1. package/README.md +118 -10
  2. package/lib/commonjs/datadogCoreProvider.js +129 -0
  3. package/lib/commonjs/datadogCoreProvider.js.map +1 -0
  4. package/lib/commonjs/offlineEvaluation.js +198 -0
  5. package/lib/commonjs/offlineEvaluation.js.map +1 -0
  6. package/lib/commonjs/offlineProvider.js +44 -8
  7. package/lib/commonjs/offlineProvider.js.map +1 -1
  8. package/lib/commonjs/rules-based.js +62 -0
  9. package/lib/commonjs/rules-based.js.map +1 -0
  10. package/lib/module/datadogCoreProvider.js +122 -0
  11. package/lib/module/datadogCoreProvider.js.map +1 -0
  12. package/lib/module/offlineEvaluation.js +192 -0
  13. package/lib/module/offlineEvaluation.js.map +1 -0
  14. package/lib/module/offlineProvider.js +45 -9
  15. package/lib/module/offlineProvider.js.map +1 -1
  16. package/lib/module/rules-based.js +50 -0
  17. package/lib/module/rules-based.js.map +1 -0
  18. package/lib/typescript/core/src/config/FileBasedConfiguration.d.ts.map +1 -1
  19. package/lib/typescript/core/src/config/FileBasedConfiguration.type.d.ts +2 -0
  20. package/lib/typescript/core/src/config/FileBasedConfiguration.type.d.ts.map +1 -1
  21. package/lib/typescript/core/src/config/async/AutoInstrumentationConfiguration.d.ts +4 -0
  22. package/lib/typescript/core/src/config/async/AutoInstrumentationConfiguration.d.ts.map +1 -1
  23. package/lib/typescript/core/src/config/async/PartialInitializationConfiguration.d.ts +2 -0
  24. package/lib/typescript/core/src/config/async/PartialInitializationConfiguration.d.ts.map +1 -1
  25. package/lib/typescript/core/src/config/features/RumConfiguration.d.ts +4 -0
  26. package/lib/typescript/core/src/config/features/RumConfiguration.d.ts.map +1 -1
  27. package/lib/typescript/core/src/config/features/RumConfiguration.type.d.ts +21 -0
  28. package/lib/typescript/core/src/config/features/RumConfiguration.type.d.ts.map +1 -1
  29. package/lib/typescript/core/src/config/features/RumConfigurationNative.d.ts +2 -0
  30. package/lib/typescript/core/src/config/features/RumConfigurationNative.d.ts.map +1 -1
  31. package/lib/typescript/core/src/flags/FlagsClient.d.ts +38 -1
  32. package/lib/typescript/core/src/flags/FlagsClient.d.ts.map +1 -1
  33. package/lib/typescript/core/src/flags/internal.d.ts +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/rum/DdRum.d.ts +1 -0
  38. package/lib/typescript/core/src/rum/DdRum.d.ts.map +1 -1
  39. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts +2 -0
  40. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts.map +1 -1
  41. package/lib/typescript/core/src/rum/types.d.ts +6 -0
  42. package/lib/typescript/core/src/rum/types.d.ts.map +1 -1
  43. package/lib/typescript/core/src/sdk/AccountInfoSingleton/AccountInfoSingleton.d.ts.map +1 -1
  44. package/lib/typescript/core/src/sdk/UserInfoSingleton/UserInfoSingleton.d.ts.map +1 -1
  45. package/lib/typescript/core/src/specs/NativeDdRum.d.ts +6 -0
  46. package/lib/typescript/core/src/specs/NativeDdRum.d.ts.map +1 -1
  47. package/lib/typescript/core/src/version.d.ts +1 -1
  48. package/lib/typescript/core/src/version.d.ts.map +1 -1
  49. package/lib/typescript/react-native-openfeature/src/datadogCoreProvider.d.ts +31 -0
  50. package/lib/typescript/react-native-openfeature/src/datadogCoreProvider.d.ts.map +1 -0
  51. package/lib/typescript/react-native-openfeature/src/index.d.ts +1 -0
  52. package/lib/typescript/react-native-openfeature/src/index.d.ts.map +1 -1
  53. package/lib/typescript/react-native-openfeature/src/offlineEvaluation.d.ts +33 -0
  54. package/lib/typescript/react-native-openfeature/src/offlineEvaluation.d.ts.map +1 -0
  55. package/lib/typescript/react-native-openfeature/src/offlineProvider.d.ts +14 -8
  56. package/lib/typescript/react-native-openfeature/src/offlineProvider.d.ts.map +1 -1
  57. package/lib/typescript/react-native-openfeature/src/rules-based.d.ts +17 -0
  58. package/lib/typescript/react-native-openfeature/src/rules-based.d.ts.map +1 -0
  59. package/package.json +8 -4
  60. package/rules-based/package.json +7 -0
  61. package/src/__tests__/__utils__/coreConfiguration.ts +84 -0
  62. package/src/__tests__/datadogCoreProvider.integration.test.ts +230 -0
  63. package/src/__tests__/datadogCoreProvider.test.ts +587 -0
  64. package/src/__tests__/entrypoints.test.ts +35 -0
  65. package/src/__tests__/offlineProvider.delegation.test.ts +795 -0
  66. package/src/__tests__/offlineProvider.test.ts +74 -10
  67. package/src/datadogCoreProvider.ts +223 -0
  68. package/src/index.ts +1 -0
  69. package/src/offlineEvaluation.ts +295 -0
  70. package/src/offlineProvider.ts +64 -13
  71. package/src/rules-based.ts +58 -0
package/README.md CHANGED
@@ -4,11 +4,16 @@ Use [OpenFeature][1] with [Datadog Feature Flags][2] to evaluate feature flags a
4
4
 
5
5
  OpenFeature is a vendor-neutral, community-driven specification and SDK for feature flagging. It provides a unified API for feature flag evaluation that works across different providers. This enables you to switch vendors or integrate multiple feature flag systems.
6
6
 
7
- This package provides an OpenFeature-compatible provider that wraps Datadog's Feature Flags SDK.
7
+ This package provides an online provider backed by Datadog's Feature Flags SDK, a
8
+ `DatadogCoreProvider` for manually supplied JavaScript-evaluated configurations, and an offline
9
+ compatibility provider that delegates to `DatadogCoreProvider` while retaining native tracking.
10
+ `DatadogCoreProvider` and the rules-based parser are exported from the
11
+ `@datadog/mobile-react-native-openfeature/rules-based` entry point, which keeps the protobuf rules
12
+ parser out of apps that do not use it.
8
13
 
9
14
  ## Setup
10
15
 
11
- **Note**: This package is an integration for the [OpenFeature React SDK][1]. Install and set up the core [`@datadog/mobile-react-native`][3] SDK to start using Datadog Feature Flags.
16
+ **Note**: This package is an integration for the [OpenFeature React SDK][1]. Install and set up the core [`@datadog/mobile-react-native`][3] SDK to use the native-backed providers. `DatadogCoreProvider` uses the same package dependencies but does not require Datadog SDK initialization or `DdFlags.enable()`.
12
17
 
13
18
  To install with NPM, run:
14
19
 
@@ -70,7 +75,7 @@ After completing this setup, your app is ready for flag evaluation with OpenFeat
70
75
  ### RUM user context
71
76
 
72
77
  Use `enrichWithRumUser()` when you explicitly want to use the current RUM user as part of an
73
- OpenFeature evaluation context. Neither Datadog OpenFeature provider enriches context automatically.
78
+ OpenFeature evaluation context. None of the Datadog OpenFeature providers enrich context automatically.
74
79
  This keeps context changes visible through OpenFeature and avoids changing flag assignments unless
75
80
  your application opts in.
76
81
 
@@ -284,13 +289,114 @@ function App() {
284
289
  export default AppWithProviders;
285
290
  ```
286
291
 
292
+ ### JavaScript evaluation with manual configuration
293
+
294
+ Use `DatadogCoreProvider` to evaluate manually supplied precomputed or rules-based configurations in
295
+ JavaScript. The provider does not fetch configuration or send exposure or RUM events. Your
296
+ application manages configuration delivery, storage, and updates.
297
+
298
+ ```tsx
299
+ import {
300
+ DatadogCoreProvider,
301
+ coreConfigurationFromString
302
+ } from '@datadog/mobile-react-native-openfeature/rules-based';
303
+ import { OpenFeature } from '@openfeature/react-sdk';
304
+
305
+ const provider = new DatadogCoreProvider();
306
+ // `wire` is a ConfigurationWire string delivered by your application.
307
+ // This parser supports both precomputed and rules-based configurations.
308
+ provider.setConfiguration(coreConfigurationFromString(wire));
309
+
310
+ // For precomputed data, supply the exact context the configuration was computed for.
311
+ // For rules, supply the context you want to evaluate locally.
312
+ const context = { targetingKey: 'user-123', country: 'US' };
313
+ await OpenFeature.setProviderAndWait('datadog-core', provider, context);
314
+
315
+ const client = OpenFeature.getClient('datadog-core');
316
+ const enabled = client.getBooleanValue('new-feature', false);
317
+
318
+ // Replace configuration whenever your application receives an update.
319
+ provider.setConfiguration(coreConfigurationFromString(updatedWire));
320
+ ```
321
+
322
+ You can also supply a parsed `FlagsConfiguration` directly. Both entry points export this type.
323
+ `getConfiguration()` returns the supplied configuration, or `undefined` if no configuration is set.
324
+ Use `coreConfigurationFromString` for this provider, rather than the native offline provider's
325
+ precomputed-only `configurationFromString` helper.
326
+
327
+ - Matching precomputed data takes precedence over rules. If the context does not match, the
328
+ evaluator uses rules when available. Otherwise, evaluation returns your coded default with
329
+ `INVALID_CONTEXT`, or `PARSE_ERROR` if the rules could not be parsed.
330
+ - **Unlike `DatadogOfflineOpenFeatureProvider`, an empty OpenFeature context is literal.** It does
331
+ not adopt the precomputed configuration's embedded context. Clearing a context can therefore
332
+ make a precomputed-only provider enter `ERROR`. Use the same domain for registration,
333
+ evaluations, and subsequent `OpenFeature.setContext('datadog-core', context)` calls.
334
+ - Load configuration before registering the provider. Missing configuration causes initialization to
335
+ fail with `PROVIDER_NOT_READY`. Unusable configuration produces `PARSE_ERROR`. If initialization
336
+ fails, wait for it to finish before loading a valid configuration.
337
+ - Replacing a usable configuration emits `ConfigurationChanged`. An unusable replacement emits
338
+ `Error`. Loading a usable configuration after an error emits `Ready`, followed by
339
+ `ConfigurationChanged`.
340
+
287
341
  ### Offline initialization
288
342
 
289
- If you fetch a flag configuration yourself (for example a precomputed-assignments payload
290
- cached on disk, delivered via your own service, or bundled with the app), use
291
- `DatadogOfflineOpenFeatureProvider` instead of `DatadogOpenFeatureProvider`. It evaluates flags
292
- and reports exposures exactly like the online provider, but **never fetches configuration from
293
- the network** — you supply it with `setConfiguration`.
343
+ Use `DatadogOfflineOpenFeatureProvider` to evaluate manually supplied precomputed or rules-based
344
+ configurations with native exposure or RUM tracking. The provider does not fetch configuration;
345
+ supply it with `setConfiguration`. For evaluation without tracking, use `DatadogCoreProvider`.
346
+
347
+ Rules-based evaluation requires `@datadog/mobile-react-native` and
348
+ `@datadog/mobile-react-native-openfeature` 3.10.0 or later. Update both packages together to use the
349
+ native tracking/evaluator bridge. With an older core SDK that lacks the bridge, precomputed
350
+ configurations retain their previous behavior, but rules configurations produce a warning and
351
+ `GENERAL` error rather than being silently ignored. A configuration that cannot be parsed reports
352
+ `PARSE_ERROR`, as `DatadogCoreProvider` does.
353
+
354
+ #### Rules-based configuration
355
+
356
+ Use `coreConfigurationFromString` from the `/rules-based` entry point to parse rules-based
357
+ configurations or configurations containing both precomputed data and rules.
358
+ `configurationFromString` supports only precomputed configurations. Rules are evaluated locally for
359
+ the current context, so you can change users or targeting attributes without fetching another
360
+ configuration:
361
+
362
+ ```tsx
363
+ import { DdFlags } from '@datadog/mobile-react-native';
364
+ import { DatadogOfflineOpenFeatureProvider } from '@datadog/mobile-react-native-openfeature';
365
+ import { coreConfigurationFromString } from '@datadog/mobile-react-native-openfeature/rules-based';
366
+ import { OpenFeature } from '@openfeature/react-sdk';
367
+
368
+ await DdFlags.enable();
369
+ const domain = 'offline-rules';
370
+ const provider = new DatadogOfflineOpenFeatureProvider({ clientName: domain });
371
+ provider.setConfiguration(coreConfigurationFromString(rulesWire));
372
+ await OpenFeature.setProviderAndWait(domain, provider, {
373
+ targetingKey: 'user-123',
374
+ country: 'CA'
375
+ });
376
+ const client = OpenFeature.getClient(domain);
377
+ const initialValue = client.getBooleanValue('new-feature', false);
378
+
379
+ await OpenFeature.setContext(domain, { targetingKey: 'user-123', country: 'US' });
380
+ const updatedValue = client.getBooleanValue('new-feature', false);
381
+ ```
382
+
383
+ Changing context can select a different rule and value. Successful evaluations are sent to the
384
+ native tracking path once, with the evaluated value, variant, allocation, and effective context.
385
+ The native SDK deduplicates exposures by subject, flag, allocation, and variant (and split serial ID
386
+ on Android). Replacing a configuration does not reset this deduplication.
387
+ Native `trackExposures` and `rumIntegrationEnabled` settings still apply. The named `FlagsClient`
388
+ shares the same evaluator, including when accessed directly with `DdFlags.getClient(domain)`.
389
+
390
+ For configurations containing both precomputed data and rules, matching precomputed data takes
391
+ precedence. The provider uses rules when the precomputed context does not match. If either part is
392
+ malformed, the provider can still use the valid part.
393
+ An empty effective context adopts the precomputed context when present. Without a context, rules have
394
+ no targeting key: an evaluation that reaches a shard on the targeting key returns
395
+ `TARGETING_KEY_MISSING`. Pass `targetingKey: ''` for an anonymous subject.
396
+
397
+ #### Precomputed configuration
398
+
399
+ The released precomputed-only setup remains supported:
294
400
 
295
401
  ```tsx
296
402
  import { DdFlags } from '@datadog/mobile-react-native';
@@ -317,7 +423,8 @@ const isNewFeatureEnabled = client.getBooleanValue('new-feature-enabled', false)
317
423
 
318
424
  The configuration carries the evaluation context it was computed for, and the provider adopts it
319
425
  automatically. A precomputed configuration is a **single-subject snapshot**: it can only be served
320
- against the context it was computed for. Per-context evaluation is a future (rules-based) capability.
426
+ against the context it was computed for. Use rules-based configuration, as shown above, for
427
+ per-context evaluation.
321
428
 
322
429
  > **Warning:** Do **not** call `OpenFeature.setContext` with a _different_ context for the offline
323
430
  > precomputed flow. A runtime context that does not match the configuration's embedded context
@@ -329,7 +436,8 @@ against the context it was computed for. Per-context evaluation is a future (rul
329
436
  > distinct subject that must match the snapshot; use `clearContext()` (or omit context) to fall back
330
437
  > to the embedded context.
331
438
 
332
- Recommended setup for a hybrid app that also uses other OpenFeature providers, hooks, or domains:
439
+ Recommended precomputed-only setup for a hybrid app that also uses other OpenFeature providers,
440
+ hooks, or domains:
333
441
 
334
442
  - **Bind the offline provider to a dedicated OpenFeature domain, and give that domain an explicit
335
443
  empty context** at registration (`OpenFeature.setContext(domain, {})`) — which this provider reads
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DatadogCoreEvaluationProvider = void 0;
7
+ var _flaggingCore = require("@datadog/flagging-core");
8
+ var _webSdk = require("@openfeature/web-sdk");
9
+ /*
10
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
11
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
12
+ * Copyright 2016-Present Datadog, Inc.
13
+ */
14
+
15
+ /**
16
+ * Evaluates manually supplied configurations in JavaScript using @datadog/flagging-core.
17
+ * Ported from openfeature-js-client's browser DatadogCoreProvider.
18
+ *
19
+ * Unlike the native-backed providers, this provider does not use DdFlags, fetch configuration,
20
+ * or send exposure/RUM events. Load a configuration before registering it with OpenFeature.
21
+ * Precomputed configurations require a matching OpenFeature context, including when it is empty.
22
+ */
23
+ class DatadogCoreEvaluationProvider {
24
+ metadata = {
25
+ name: 'datadog-core'
26
+ };
27
+ runsOn = 'client';
28
+ events = new _webSdk.OpenFeatureEventEmitter();
29
+ getConfiguration() {
30
+ return this.flagsConfiguration;
31
+ }
32
+ setConfiguration(configuration) {
33
+ const hadEvaluatableConfiguration = this.canEvaluateCurrentContext();
34
+ // Untyped callers can pass a non-object (e.g. `null`), which flagging-core cannot read.
35
+ // Like any other unusable configuration, it replaces the previous one and surfaces
36
+ // PARSE_ERROR until a valid configuration is set.
37
+ if (typeof configuration !== 'object' || configuration === null) {
38
+ this.flagsConfiguration = {
39
+ configurationError: 'Flags configuration must be an object'
40
+ };
41
+ this.flagsConfigurationId = undefined;
42
+ } else {
43
+ this.flagsConfiguration = configuration;
44
+ this.flagsConfigurationId = this.computeConfigurationId(configuration);
45
+ }
46
+ if (this.context === undefined) {
47
+ return;
48
+ }
49
+ const error = toOpenFeatureError((0, _flaggingCore.getFlagsConfigurationError)(this.flagsConfiguration, this.context));
50
+ if (error) {
51
+ // The web-sdk's ErrorEvent type omits errorCode, but its provider wrapper reads it.
52
+ const details = {
53
+ error,
54
+ message: error.message,
55
+ errorCode: error.code
56
+ };
57
+ this.events.emit(_webSdk.ProviderEvents.Error, details);
58
+ return;
59
+ }
60
+ if (!hadEvaluatableConfiguration) {
61
+ this.events.emit(_webSdk.ProviderEvents.Ready);
62
+ }
63
+ this.events.emit(_webSdk.ProviderEvents.ConfigurationChanged);
64
+ }
65
+ initialize(context = {}) {
66
+ this.context = context;
67
+ const error = toOpenFeatureError((0, _flaggingCore.getFlagsConfigurationError)(this.flagsConfiguration, context));
68
+ return error ? Promise.reject(error) : Promise.resolve();
69
+ }
70
+ onContextChange(_oldContext, newContext) {
71
+ this.context = newContext;
72
+ const error = toOpenFeatureError((0, _flaggingCore.getFlagsConfigurationError)(this.flagsConfiguration, this.context));
73
+ if (error) {
74
+ throw error;
75
+ }
76
+ }
77
+ resolveBooleanEvaluation(flagKey, defaultValue, context, logger) {
78
+ return this.resolve('boolean', flagKey, defaultValue, context, logger);
79
+ }
80
+ resolveStringEvaluation(flagKey, defaultValue, context, logger) {
81
+ return this.resolve('string', flagKey, defaultValue, context, logger);
82
+ }
83
+ resolveNumberEvaluation(flagKey, defaultValue, context, logger) {
84
+ return this.resolve('number', flagKey, defaultValue, context, logger);
85
+ }
86
+ resolveObjectEvaluation(flagKey, defaultValue, context, logger) {
87
+ // OpenFeature requires a specific JsonValue subtype without runtime type information.
88
+ // Callers must provide a default value with the expected shape.
89
+ return this.resolve('object', flagKey, defaultValue, context, logger);
90
+ }
91
+ resolve(type, flagKey, defaultValue, context, logger) {
92
+ const details = (0, _flaggingCore.evaluate)(this.flagsConfiguration, type, flagKey, defaultValue, context, logger);
93
+ if (this.flagsConfigurationId === undefined || details.flagMetadata?.doLog !== true || typeof details.flagMetadata?.allocationKey !== 'string' || details.variant == null) {
94
+ return details;
95
+ }
96
+
97
+ // Preserve the browser provider's configuration identity for consumers of evaluation metadata.
98
+ return {
99
+ ...details,
100
+ flagMetadata: {
101
+ ...details.flagMetadata,
102
+ __dd_core_configuration_id: this.flagsConfigurationId
103
+ }
104
+ };
105
+ }
106
+ canEvaluateCurrentContext() {
107
+ return this.context !== undefined && !(0, _flaggingCore.getFlagsConfigurationError)(this.flagsConfiguration, this.context);
108
+ }
109
+
110
+ // The `/rules-based` entry adds the browser's configuration identity. Hashing a rules
111
+ // configuration needs the protobuf encoder, which the main entry must not load.
112
+ computeConfigurationId(_configuration) {
113
+ return undefined;
114
+ }
115
+ }
116
+ exports.DatadogCoreEvaluationProvider = DatadogCoreEvaluationProvider;
117
+ function toOpenFeatureError(error) {
118
+ if (!error) {
119
+ return undefined;
120
+ }
121
+ if (error.errorCode === 'PARSE_ERROR') {
122
+ return new _webSdk.ParseError(error.errorMessage);
123
+ }
124
+ if (error.errorCode === 'INVALID_CONTEXT') {
125
+ return new _webSdk.InvalidContextError(error.errorMessage);
126
+ }
127
+ return new _webSdk.ProviderNotReadyError(error.errorMessage);
128
+ }
129
+ //# sourceMappingURL=datadogCoreProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_flaggingCore","require","_webSdk","DatadogCoreEvaluationProvider","metadata","name","runsOn","events","OpenFeatureEventEmitter","getConfiguration","flagsConfiguration","setConfiguration","configuration","hadEvaluatableConfiguration","canEvaluateCurrentContext","configurationError","flagsConfigurationId","undefined","computeConfigurationId","context","error","toOpenFeatureError","getFlagsConfigurationError","details","message","errorCode","code","emit","ProviderEvents","Error","Ready","ConfigurationChanged","initialize","Promise","reject","resolve","onContextChange","_oldContext","newContext","resolveBooleanEvaluation","flagKey","defaultValue","logger","resolveStringEvaluation","resolveNumberEvaluation","resolveObjectEvaluation","type","evaluate","flagMetadata","doLog","allocationKey","variant","__dd_core_configuration_id","_configuration","exports","ParseError","errorMessage","InvalidContextError","ProviderNotReadyError"],"sourceRoot":"../../src","sources":["datadogCoreProvider.ts"],"mappings":";;;;;;AAWA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAZA;AACA;AACA;AACA;AACA;;AA4BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAME,6BAA6B,CAAqB;EAClDC,QAAQ,GAAqB;IAAEC,IAAI,EAAE;EAAe,CAAC;EACrDC,MAAM,GAAa,QAAQ;EAC3BC,MAAM,GAAyC,IAAIC,+BAAuB,CAAC,CAAC;EAMrFC,gBAAgBA,CAAA,EAAmC;IAC/C,OAAO,IAAI,CAACC,kBAAkB;EAClC;EAEAC,gBAAgBA,CAACC,aAAiC,EAAQ;IACtD,MAAMC,2BAA2B,GAAG,IAAI,CAACC,yBAAyB,CAAC,CAAC;IACpE;IACA;IACA;IACA,IAAI,OAAOF,aAAa,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ACD,IACI,IAAI,CAAC1B,oBAAoB,KAAKC,SAAS,IACvCM,OAAO,CAACyB,YAAY,EAAEC,KAAK,KAAK,IAAI,IACpC,OAAO1B,OAAO,CAACyB,YAAY,EAAEE,aAAa,KAAK,QAAQ,IACvD3B,OAAO,CAAC4B,OAAO,IAAI,IAAI,EACzB;MACE,OAAO5B,OAAO;IAClB;;IAEA;IACA,OAAO;MACH,GAAGA,OAAO;MACVyB,YAAY,EAAE;QACV,GAAGzB,OAAO,CAACyB,YAAY;QACvBI,0BAA0B,EAAE,IAAI,CAACpC;MACrC;IACJ,CAAC;EACL;EAEQF,yBAAyBA,CAAA,EAAY;IACzC,OACI,IAAI,CAACK,OAAO,KAAKF,SAAS,IAC1B,CAAC,IAAAK,wCAA0B,EAAC,IAAI,CAACZ,kBAAkB,EAAE,IAAI,CAACS,OAAO,CAAC;EAE1E;;EAEA;EACA;EACUD,sBAAsBA,CAC5BmC,cAAkC,EAChB;IAClB,OAAOpC,SAAS;EACpB;AACJ;AAACqC,OAAA,CAAAnD,6BAAA,GAAAA,6BAAA;AAED,SAASkB,kBAAkBA,CACvBD,KAA0C,EACd;EAC5B,IAAI,CAACA,KAAK,EAAE;IACR,OAAOH,SAAS;EACpB;EACA,IAAIG,KAAK,CAACK,SAAS,KAAK,aAAa,EAAE;IACnC,OAAO,IAAI8B,kBAAU,CAACnC,KAAK,CAACoC,YAAY,CAAC;EAC7C;EACA,IAAIpC,KAAK,CAACK,SAAS,KAAK,iBAAiB,EAAE;IACvC,OAAO,IAAIgC,2BAAmB,CAACrC,KAAK,CAACoC,YAAY,CAAC;EACtD;EACA,OAAO,IAAIE,6BAAqB,CAACtC,KAAK,CAACoC,YAAY,CAAC;AACxD","ignoreList":[]}
@@ -0,0 +1,198 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.OfflineEvaluation = void 0;
7
+ var _flaggingCore = require("@datadog/flagging-core");
8
+ var _mobileReactNative = require("@datadog/mobile-react-native");
9
+ var _webSdk = require("@openfeature/web-sdk");
10
+ var _datadogCoreProvider = require("./datadogCoreProvider");
11
+ /*
12
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
13
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
14
+ * Copyright 2016-Present Datadog, Inc.
15
+ */
16
+
17
+ // Keep the bridge contract owned by FlagsClient; no OpenFeature dependency enters the core SDK.
18
+
19
+ const logger = {
20
+ debug: message => _mobileReactNative.InternalLog.log(String(message), _mobileReactNative.SdkVerbosity.DEBUG),
21
+ info: message => _mobileReactNative.InternalLog.log(String(message), _mobileReactNative.SdkVerbosity.INFO),
22
+ warn: message => _mobileReactNative.InternalLog.log(String(message), _mobileReactNative.SdkVerbosity.WARN),
23
+ error: message => _mobileReactNative.InternalLog.log(String(message), _mobileReactNative.SdkVerbosity.ERROR)
24
+ };
25
+
26
+ /**
27
+ * Compatibility adapter for the released offline provider. DatadogCoreProvider owns evaluation;
28
+ * the named FlagsClient owns this adapter and native exposure/RUM delivery. Only the legacy
29
+ * precomputed input/context normalization and native tracking representation are adapted here.
30
+ */
31
+ class OfflineEvaluation {
32
+ core = new _datadogCoreProvider.DatadogCoreEvaluationProvider();
33
+ precomputedFlags = new Map();
34
+ context = {
35
+ targetingKey: '',
36
+ attributes: {}
37
+ };
38
+ coreContext = {};
39
+ // Whether the active context selects the precomputed snapshot. Fixed until the next reconcile.
40
+ servesPrecomputed = false;
41
+ constructor(configuration, helpers) {
42
+ this.configuration = {
43
+ ...configuration
44
+ };
45
+ const precomputed = configuration?.precomputed;
46
+ if (!precomputed && !this.configuration.rules && this.configuration.configurationError === undefined && this.configuration.precomputedError === undefined && this.configuration.rulesError === undefined) {
47
+ // A bare {} has no capability. The precomputed-only parser returns it for a rules-only wire.
48
+ _mobileReactNative.InternalLog.log('DatadogOfflineOpenFeatureProvider received no precomputed or rules configuration. configurationFromString is precomputed-only; parse rules-based wires with coreConfigurationFromString from the /rules-based entry point.', _mobileReactNative.SdkVerbosity.WARN);
49
+ }
50
+ if (precomputed) {
51
+ try {
52
+ this.precomputedFlags = helpers.decodePrecomputedFlags(precomputed.response);
53
+ const flags = Object.fromEntries(Array.from(this.precomputedFlags, ([key, flag]) => [key, {
54
+ allocationKey: flag.allocationKey,
55
+ variationKey: flag.variationKey,
56
+ // The released client checks the value's runtime type, including integer/float
57
+ // aliases and object-typed payloads containing primitives. Keep that behavior.
58
+ variationType: typeof flag.value,
59
+ variationValue: flag.value,
60
+ reason: flag.reason,
61
+ doLog: flag.doLog,
62
+ // The native decoder does not keep the split serial ID; read it from the wire.
63
+ serialId: precomputed.response.data.attributes.flags[key]?.serialId
64
+ }]));
65
+ this.configuration.precomputed = {
66
+ ...precomputed,
67
+ context: precomputed.context ? toOpenFeatureContext(helpers.normalizeWireContext(precomputed.context)) : undefined,
68
+ // The native decoder omits malformed entries; flagging-core's parser reports them.
69
+ flagErrors: precomputed.flagErrors,
70
+ response: {
71
+ data: {
72
+ attributes: {
73
+ createdAt: precomputed.response.data.attributes.createdAt,
74
+ flags
75
+ }
76
+ }
77
+ }
78
+ };
79
+ } catch (error) {
80
+ // A malformed precomputed branch must not hide a usable rules branch.
81
+ this.configuration.precomputed = undefined;
82
+ this.configuration.precomputedError = error instanceof Error ? error.message : String(error);
83
+ }
84
+ }
85
+ this.core.setConfiguration(this.configuration);
86
+ }
87
+ reconcile(context, hasTargetingKey = typeof context?.targetingKey === 'string') {
88
+ // An omitted override adopts the normalized embedded context. Rules-only configurations
89
+ // must not invent an anonymous subject: missing and explicitly empty keys differ.
90
+ const embedded = this.configuration.precomputed?.context;
91
+ this.context = context ?? (embedded ? {
92
+ targetingKey: embedded.targetingKey ?? '',
93
+ attributes: withoutTargetingKey(embedded)
94
+ } : {
95
+ targetingKey: '',
96
+ attributes: {}
97
+ });
98
+ const normalizedContext = toOpenFeatureContext(this.context);
99
+ // Snapshot matching retains released normalization/adoption. Only rules fallback uses the
100
+ // original subject presence; native tracking still receives the normalized context.
101
+ this.coreContext = (0, _flaggingCore.configMatchesContext)(this.configuration, normalizedContext) || hasTargetingKey === true ? normalizedContext : withoutTargetingKey(normalizedContext);
102
+ this.servesPrecomputed = (0, _flaggingCore.configMatchesContext)(this.configuration, this.coreContext);
103
+ try {
104
+ // Synchronous validation preserves the offline provider's context-change lifecycle.
105
+ this.core.onContextChange({}, this.coreContext);
106
+ return {
107
+ status: 'ready'
108
+ };
109
+ } catch (error) {
110
+ const code = error instanceof _webSdk.OpenFeatureError ? error.code : _webSdk.ErrorCode.GENERAL;
111
+ return {
112
+ status: 'error',
113
+ errorCode: code === _webSdk.ErrorCode.INVALID_CONTEXT || code === _webSdk.ErrorCode.PROVIDER_NOT_READY || code === _webSdk.ErrorCode.PARSE_ERROR ? code : _webSdk.ErrorCode.GENERAL
114
+ };
115
+ }
116
+ }
117
+ evaluate(key, defaultValue, type) {
118
+ const context = this.coreContext;
119
+ const result = this.resolve(key, defaultValue, type, context);
120
+ const allocationKey = result.flagMetadata?.allocationKey;
121
+ const details = {
122
+ key,
123
+ value: result.value,
124
+ reason: result.reason ?? 'UNKNOWN',
125
+ variant: result.variant,
126
+ allocationKey: typeof allocationKey === 'string' ? allocationKey : undefined,
127
+ errorCode: result.errorCode,
128
+ errorMessage: result.errorMessage
129
+ };
130
+ if (result.errorCode || typeof allocationKey !== 'string' || result.variant === undefined) {
131
+ return {
132
+ details
133
+ };
134
+ }
135
+
136
+ // Reuse original precomputed tracking metadata (including extraLogging and variationType).
137
+ // A rules result has no native cache entry, so build the same native tracking shape from
138
+ // the actual evaluated result, never from the fallback/default value.
139
+ const precomputed = this.servesPrecomputed ? this.precomputedFlags.get(key) : undefined;
140
+ const serialId = result.flagMetadata?.__dd_split_serial_id;
141
+ const serial = typeof serialId === 'number' ? {
142
+ serialId: String(serialId)
143
+ } : {};
144
+ const flag = precomputed ? {
145
+ ...precomputed,
146
+ ...serial
147
+ } : {
148
+ key,
149
+ value: result.value,
150
+ allocationKey,
151
+ variationKey: result.variant,
152
+ variationType: type,
153
+ variationValue: typeof result.value === 'object' ? JSON.stringify(result.value) : String(result.value),
154
+ reason: result.reason ?? 'UNKNOWN',
155
+ doLog: result.flagMetadata?.doLog === true,
156
+ extraLogging: {},
157
+ ...serial
158
+ };
159
+ // Even doLog=false evaluations reach native code: RUM tracking is independent of exposures.
160
+ return {
161
+ details,
162
+ exposure: {
163
+ flag,
164
+ context: this.context
165
+ }
166
+ };
167
+ }
168
+ resolve(key, defaultValue, type, context) {
169
+ // FlagsClient's typed getters guarantee the default's type. OpenFeature's object method
170
+ // additionally relies on the caller's JSON shape, just as DatadogCoreProvider does.
171
+ switch (type) {
172
+ case 'boolean':
173
+ return this.core.resolveBooleanEvaluation(key, defaultValue, context, logger);
174
+ case 'string':
175
+ return this.core.resolveStringEvaluation(key, defaultValue, context, logger);
176
+ case 'number':
177
+ return this.core.resolveNumberEvaluation(key, defaultValue, context, logger);
178
+ case 'object':
179
+ return this.core.resolveObjectEvaluation(key, defaultValue, context, logger);
180
+ }
181
+ }
182
+ }
183
+ exports.OfflineEvaluation = OfflineEvaluation;
184
+ function toOpenFeatureContext(context) {
185
+ return {
186
+ ...context.attributes,
187
+ targetingKey: context.targetingKey
188
+ };
189
+ }
190
+ function withoutTargetingKey(context) {
191
+ const {
192
+ targetingKey,
193
+ ...attributes
194
+ } = context;
195
+ // This context has already passed through FlagsClient's primitive-only normalization.
196
+ return attributes;
197
+ }
198
+ //# sourceMappingURL=offlineEvaluation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_flaggingCore","require","_mobileReactNative","_webSdk","_datadogCoreProvider","logger","debug","message","InternalLog","log","String","SdkVerbosity","DEBUG","info","INFO","warn","WARN","error","ERROR","OfflineEvaluation","core","DatadogCoreEvaluationProvider","precomputedFlags","Map","context","targetingKey","attributes","coreContext","servesPrecomputed","constructor","configuration","helpers","precomputed","rules","configurationError","undefined","precomputedError","rulesError","decodePrecomputedFlags","response","flags","Object","fromEntries","Array","from","key","flag","allocationKey","variationKey","variationType","value","variationValue","reason","doLog","serialId","data","toOpenFeatureContext","normalizeWireContext","flagErrors","createdAt","Error","setConfiguration","reconcile","hasTargetingKey","embedded","withoutTargetingKey","normalizedContext","configMatchesContext","onContextChange","status","code","OpenFeatureError","ErrorCode","GENERAL","errorCode","INVALID_CONTEXT","PROVIDER_NOT_READY","PARSE_ERROR","evaluate","defaultValue","type","result","resolve","flagMetadata","details","variant","errorMessage","get","__dd_split_serial_id","serial","JSON","stringify","extraLogging","exposure","resolveBooleanEvaluation","resolveStringEvaluation","resolveNumberEvaluation","resolveObjectEvaluation","exports"],"sourceRoot":"../../src","sources":["offlineEvaluation.ts"],"mappings":";;;;;;AAMA,IAAAA,aAAA,GAAAC,OAAA;AAKA,IAAAC,kBAAA,GAAAD,OAAA;AAMA,IAAAE,OAAA,GAAAF,OAAA;AASA,IAAAG,oBAAA,GAAAH,OAAA;AA1BA;AACA;AACA;AACA;AACA;;AAwBA;;AASA,MAAMI,MAAc,GAAG;EACnBC,KAAK,EAAEC,OAAO,IAAIC,8BAAW,CAACC,GAAG,CAACC,MAAM,CAACH,OAAO,CAAC,EAAEI,+BAAY,CAACC,KAAK,CAAC;EACtEC,IAAI,EAAEN,OAAO,IAAIC,8BAAW,CAACC,GAAG,CAACC,MAAM,CAACH,OAAO,CAAC,EAAEI,+BAAY,CAACG,IAAI,CAAC;EACpEC,IAAI,EAAER,OAAO,IAAIC,8BAAW,CAACC,GAAG,CAACC,MAAM,CAACH,OAAO,CAAC,EAAEI,+BAAY,CAACK,IAAI,CAAC;EACpEC,KAAK,EAAEV,OAAO,IAAIC,8BAAW,CAACC,GAAG,CAACC,MAAM,CAACH,OAAO,CAAC,EAAEI,+BAAY,CAACO,KAAK;AACzE,CAAC;;AAED;AACA;AACA;AACA;AACA;AACO,MAAMC,iBAAiB,CAA6B;EACtCC,IAAI,GAAG,IAAIC,kDAA6B,CAAC,CAAC;EAEnDC,gBAAgB,GAAc,IAAIC,GAAG,CAAC,C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AK,IAAI;MAC1CuC,YAAY,EAAE,CAAC,CAAC;MAChB,GAAGH;IACP,CAAC;IACP;IACA,OAAO;MAAEL,OAAO;MAAES,QAAQ,EAAE;QAAE/C,IAAI;QAAEtB,OAAO,EAAE,IAAI,CAACA;MAAQ;IAAE,CAAC;EACjE;EAEQ0D,OAAOA,CACXrC,GAAW,EACXkC,YAAe,EACfC,IAAmB,EACnBxD,OAA4B,EACR;IACpB;IACA;IACA,QAAQwD,IAAI;MACR,KAAK,SAAS;QACV,OAAO,IAAI,CAAC5D,IAAI,CAAC0E,wBAAwB,CACrCjD,GAAG,EACHkC,YAAY,EACZvD,OAAO,EACPnB,MACJ,CAAC;MACL,KAAK,QAAQ;QACT,OAAO,IAAI,CAACe,IAAI,CAAC2E,uBAAuB,CACpClD,GAAG,EACHkC,YAAY,EACZvD,OAAO,EACPnB,MACJ,CAAC;MACL,KAAK,QAAQ;QACT,OAAO,IAAI,CAACe,IAAI,CAAC4E,uBAAuB,CACpCnD,GAAG,EACHkC,YAAY,EACZvD,OAAO,EACPnB,MACJ,CAAC;MACL,KAAK,QAAQ;QACT,OAAO,IAAI,CAACe,IAAI,CAAC6E,uBAAuB,CACpCpD,GAAG,EACHkC,YAAY,EACZvD,OAAO,EACPnB,MACJ,CAAC;IACT;EACJ;AACJ;AAAC6F,OAAA,CAAA/E,iBAAA,GAAAA,iBAAA;AAED,SAASqC,oBAAoBA,CAAChC,OAA0B,EAAuB;EAC3E,OAAO;IAAE,GAAGA,OAAO,CAACE,UAAU;IAAED,YAAY,EAAED,OAAO,CAACC;EAAa,CAAC;AACxE;AAEA,SAASwC,mBAAmBA,CACxBzC,OAA4B,EACgB;EAC5C,MAAM;IAAEC,YAAY;IAAE,GAAGC;EAAW,CAAC,GAAGF,OAAO;EAC/C;EACA,OAAOE,UAAU;AACrB","ignoreList":[]}
@@ -4,9 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DatadogOfflineOpenFeatureProvider = void 0;
7
+ var _mobileReactNative = require("@datadog/mobile-react-native");
7
8
  var _webSdk = require("@openfeature/web-sdk");
8
9
  var _coreProvider = require("./coreProvider");
9
10
  var _mappers = require("./mappers");
11
+ var _offlineEvaluation = require("./offlineEvaluation");
10
12
  /*
11
13
  * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
12
14
  * This product includes software developed at Datadog (https://www.datadoghq.com/).
@@ -23,21 +25,26 @@ var _mappers = require("./mappers");
23
25
  const OF_ERROR_CODE = {
24
26
  INVALID_CONTEXT: _webSdk.ErrorCode.INVALID_CONTEXT,
25
27
  PROVIDER_NOT_READY: _webSdk.ErrorCode.PROVIDER_NOT_READY,
28
+ PARSE_ERROR: _webSdk.ErrorCode.PARSE_ERROR,
26
29
  GENERAL: _webSdk.ErrorCode.GENERAL
27
30
  };
28
31
 
29
32
  /**
30
33
  * An offline Datadog OpenFeature provider.
31
34
  *
32
- * It behaves like the online `DatadogOpenFeatureProvider` — same flag evaluation and
33
- * exposure/RUM tracking — **except it never fetches configuration from the network**.
35
+ * Delegates precomputed and rules-based evaluation to `DatadogCoreProvider`, while preserving
36
+ * named native clients and exposure/RUM tracking. It never fetches configuration from the network.
34
37
  * Instead of fetching on `initialize`/`onContextChange`, it evaluates against a configuration
35
38
  * supplied via {@link DatadogOfflineOpenFeatureProvider.setConfiguration}. A precomputed
36
39
  * configuration carries the evaluation context it was computed for, so you should **not** call
37
40
  * `OpenFeature.setContext` for the offline precomputed flow — see the class remarks.
38
41
  *
39
- * A runtime context that does not match the configuration's embedded context (compared after
40
- * normalization) cannot be served (offline never fetches), so it puts the provider into the
42
+ * Rules are evaluated locally for the supplied context. A missing/null targeting key is not an
43
+ * anonymous subject: an evaluation that reaches a shard on the targeting key returns
44
+ * TARGETING_KEY_MISSING, while an explicit empty string remains a valid targeting key.
45
+ * Precomputed context normalization/adoption is unchanged.
46
+ * Without usable rules, a runtime context that does not match the precomputed configuration's embedded context (after normalization)
47
+ * cannot be served (offline never fetches), so it puts the provider into the
41
48
  * OpenFeature `ERROR` state and evaluations fall back to your coded defaults (`INVALID_CONTEXT`).
42
49
  * An empty *effective* context re-adopts the embedded context and recovers — but note that
43
50
  * `clearContext(domain)` falls back to the global context, which may itself be non-empty and
@@ -95,11 +102,12 @@ class DatadogOfflineOpenFeatureProvider extends _coreProvider.DatadogCoreOpenFea
95
102
  /**
96
103
  * Load a configuration into the provider for offline evaluation.
97
104
  *
98
- * @param configuration A configuration parsed from a `ConfigurationWire` string via
99
- * `configurationFromString`.
105
+ * @param configuration A precomputed or rules-based configuration parsed with
106
+ * `coreConfigurationFromString` from the `/rules-based` entry point. The existing precomputed-only `configurationFromString`
107
+ * output remains supported.
100
108
  */
101
109
  setConfiguration(configuration) {
102
- const result = this.flagsClient.setConfiguration(configuration);
110
+ const result = this.installConfiguration(configuration);
103
111
  if (result.status === 'ready') {
104
112
  if (this.configurationInError) {
105
113
  // Recover from a prior error: PROVIDER_READY clears the ERROR status (a bare
@@ -118,12 +126,38 @@ class DatadogOfflineOpenFeatureProvider extends _coreProvider.DatadogCoreOpenFea
118
126
  this.events.emit(_webSdk.ProviderEvents.Error, details);
119
127
  }
120
128
  }
129
+ installConfiguration(configuration) {
130
+ if (typeof this.flagsClient.__ddSetOfflineEvaluator === 'function') {
131
+ return this.flagsClient.__ddSetOfflineEvaluator(helpers => new _offlineEvaluation.OfflineEvaluation(configuration, helpers));
132
+ }
133
+
134
+ // Older core SDKs predate the evaluator bridge. Keep their released precomputed behavior,
135
+ // but never silently ignore usable rules or keep serving a stale configuration when they
136
+ // are supplied. A rules parse error has no rules to ignore, so precomputed data still loads.
137
+ if (configuration?.rules) {
138
+ _mobileReactNative.InternalLog.log('DatadogOfflineOpenFeatureProvider rules-based evaluation requires an updated @datadog/mobile-react-native SDK. Update both Datadog packages together.', _mobileReactNative.SdkVerbosity.WARN);
139
+ this.flagsClient.setConfiguration({});
140
+ return {
141
+ status: 'error',
142
+ errorCode: 'GENERAL'
143
+ };
144
+ }
145
+ return this.flagsClient.setConfiguration(configuration);
146
+ }
121
147
  applyContext(context) {
122
148
  // An empty context means "no external override": clear it so a loaded precomputed
123
149
  // configuration is served against its embedded context. Order-independent — the synthetic
124
150
  // `initialize({})`, `setContext({})`, and `clearContext()` all re-adopt the embedded
125
151
  // context rather than being treated as a mismatch.
126
- const result = (0, _mappers.isEmptyContext)(context) ? this.flagsClient.resetEvaluationContextWithoutFetching() : this.flagsClient.setEvaluationContextWithoutFetching((0, _mappers.toDdContext)(context));
152
+ let result;
153
+ if ((0, _mappers.isEmptyContext)(context)) {
154
+ result = this.flagsClient.resetEvaluationContextWithoutFetching();
155
+ } else if (typeof this.flagsClient.__ddSetOfflineEvaluationContext === 'function') {
156
+ result = this.flagsClient.__ddSetOfflineEvaluationContext((0, _mappers.toDdContext)(context), typeof context.targetingKey === 'string');
157
+ } else {
158
+ // Older core SDKs retain their precomputed-only context behavior.
159
+ result = this.flagsClient.setEvaluationContextWithoutFetching((0, _mappers.toDdContext)(context));
160
+ }
127
161
  this.configurationInError = result.status === 'error';
128
162
  return result;
129
163
  }
@@ -140,6 +174,8 @@ class DatadogOfflineOpenFeatureProvider extends _coreProvider.DatadogCoreOpenFea
140
174
  return new _webSdk.InvalidContextError('The evaluation context does not match the offline precomputed configuration. Serving default values.');
141
175
  case 'PROVIDER_NOT_READY':
142
176
  return new _webSdk.ProviderNotReadyError('The Datadog offline provider has no configuration loaded. Provide one via setConfiguration.');
177
+ case 'PARSE_ERROR':
178
+ return new _webSdk.ParseError('The Datadog offline provider cannot parse the loaded configuration.');
143
179
  default:
144
180
  return new _webSdk.GeneralError('The Datadog offline provider cannot serve the loaded configuration.');
145
181
  }