@datadog/mobile-react-native 3.5.3 → 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 (72) hide show
  1. package/android/build.gradle +8 -7
  2. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  3. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +94 -49
  4. package/ios/Sources/SdkVersion.swift +1 -1
  5. package/lib/commonjs/flags/FlagsClient.js +268 -3
  6. package/lib/commonjs/flags/FlagsClient.js.map +1 -1
  7. package/lib/commonjs/flags/configuration/context.js +70 -0
  8. package/lib/commonjs/flags/configuration/context.js.map +1 -0
  9. package/lib/commonjs/flags/configuration/index.js +39 -0
  10. package/lib/commonjs/flags/configuration/index.js.map +1 -0
  11. package/lib/commonjs/flags/configuration/precomputed.js +172 -0
  12. package/lib/commonjs/flags/configuration/precomputed.js.map +1 -0
  13. package/lib/commonjs/flags/configuration/types.js +33 -0
  14. package/lib/commonjs/flags/configuration/types.js.map +1 -0
  15. package/lib/commonjs/flags/configuration/wire.js +19 -0
  16. package/lib/commonjs/flags/configuration/wire.js.map +1 -0
  17. package/lib/commonjs/flags/internal.js +7 -3
  18. package/lib/commonjs/flags/internal.js.map +1 -1
  19. package/lib/commonjs/index.js +13 -0
  20. package/lib/commonjs/index.js.map +1 -1
  21. package/lib/commonjs/version.js +1 -1
  22. package/lib/module/flags/FlagsClient.js +268 -3
  23. package/lib/module/flags/FlagsClient.js.map +1 -1
  24. package/lib/module/flags/configuration/context.js +62 -0
  25. package/lib/module/flags/configuration/context.js.map +1 -0
  26. package/lib/module/flags/configuration/index.js +18 -0
  27. package/lib/module/flags/configuration/index.js.map +1 -0
  28. package/lib/module/flags/configuration/precomputed.js +165 -0
  29. package/lib/module/flags/configuration/precomputed.js.map +1 -0
  30. package/lib/module/flags/configuration/types.js +27 -0
  31. package/lib/module/flags/configuration/types.js.map +1 -0
  32. package/lib/module/flags/configuration/wire.js +13 -0
  33. package/lib/module/flags/configuration/wire.js.map +1 -0
  34. package/lib/module/flags/internal.js +7 -3
  35. package/lib/module/flags/internal.js.map +1 -1
  36. package/lib/module/index.js +2 -1
  37. package/lib/module/index.js.map +1 -1
  38. package/lib/module/version.js +1 -1
  39. package/lib/typescript/flags/FlagsClient.d.ts +96 -0
  40. package/lib/typescript/flags/FlagsClient.d.ts.map +1 -1
  41. package/lib/typescript/flags/configuration/context.d.ts +20 -0
  42. package/lib/typescript/flags/configuration/context.d.ts.map +1 -0
  43. package/lib/typescript/flags/configuration/index.d.ts +5 -0
  44. package/lib/typescript/flags/configuration/index.d.ts.map +1 -0
  45. package/lib/typescript/flags/configuration/precomputed.d.ts +25 -0
  46. package/lib/typescript/flags/configuration/precomputed.d.ts.map +1 -0
  47. package/lib/typescript/flags/configuration/types.d.ts +24 -0
  48. package/lib/typescript/flags/configuration/types.d.ts.map +1 -0
  49. package/lib/typescript/flags/configuration/wire.d.ts +2 -0
  50. package/lib/typescript/flags/configuration/wire.d.ts.map +1 -0
  51. package/lib/typescript/flags/internal.d.ts.map +1 -1
  52. package/lib/typescript/flags/types.d.ts +1 -1
  53. package/lib/typescript/flags/types.d.ts.map +1 -1
  54. package/lib/typescript/index.d.ts +4 -2
  55. package/lib/typescript/index.d.ts.map +1 -1
  56. package/lib/typescript/version.d.ts +1 -1
  57. package/package.json +3 -2
  58. package/src/flags/FlagsClient.ts +305 -3
  59. package/src/flags/__tests__/FlagsClient.test.ts +596 -0
  60. package/src/flags/__tests__/internal.test.ts +45 -0
  61. package/src/flags/configuration/__tests__/context.test.ts +120 -0
  62. package/src/flags/configuration/__tests__/precomputed.test.ts +301 -0
  63. package/src/flags/configuration/__tests__/wire.test.ts +127 -0
  64. package/src/flags/configuration/context.ts +76 -0
  65. package/src/flags/configuration/index.ts +27 -0
  66. package/src/flags/configuration/precomputed.ts +215 -0
  67. package/src/flags/configuration/types.ts +47 -0
  68. package/src/flags/configuration/wire.ts +15 -0
  69. package/src/flags/internal.ts +6 -3
  70. package/src/flags/types.ts +3 -1
  71. package/src/index.tsx +8 -0
  72. package/src/version.ts +1 -1
@@ -200,7 +200,7 @@ dependencies {
200
200
  // This breaks builds if the React Native target is below 0.76.0. as it relies on Gradle 8.5.0.
201
201
  // To avoid this, we enforce 1.0.0-beta01 on RN < 0.76.0
202
202
  if (reactNativeMinorVersion < 76) {
203
- implementation("com.datadoghq:dd-sdk-android-rum:3.10.0") {
203
+ implementation("com.datadoghq:dd-sdk-android-rum:3.12.1") {
204
204
  exclude group: "androidx.metrics", module: "metrics-performance"
205
205
  }
206
206
  implementation "androidx.metrics:metrics-performance:1.0.0-beta01"
@@ -220,13 +220,14 @@ dependencies {
220
220
  }
221
221
  }
222
222
  } else {
223
- implementation "com.datadoghq:dd-sdk-android-rum:3.10.0"
223
+ implementation "com.datadoghq:dd-sdk-android-rum:3.12.1"
224
224
  }
225
- implementation "com.datadoghq:dd-sdk-android-logs:3.10.0"
226
- implementation "com.datadoghq:dd-sdk-android-trace:3.10.0"
227
- implementation "com.datadoghq:dd-sdk-android-webview:3.10.0"
228
- implementation "com.datadoghq:dd-sdk-android-ndk:3.10.0"
229
- implementation "com.datadoghq:dd-sdk-android-flags:3.10.0"
225
+ implementation "com.datadoghq:dd-sdk-android-logs:3.12.1"
226
+ implementation "com.datadoghq:dd-sdk-android-trace:3.12.1"
227
+ implementation "com.datadoghq:dd-sdk-android-webview:3.12.1"
228
+ implementation "com.datadoghq:dd-sdk-android-ndk:3.12.1"
229
+ implementation "com.datadoghq:dd-sdk-android-flags:3.12.1"
230
+ implementation "com.datadoghq:dd-sdk-android-internal:3.12.1"
230
231
  implementation "com.google.code.gson:gson:2.11.0"
231
232
  testImplementation "org.junit.platform:junit-platform-launcher:1.6.2"
232
233
  testImplementation "org.junit.jupiter:junit-jupiter-api:5.6.2"
@@ -7,4 +7,4 @@
7
7
  package com.datadog.reactnative
8
8
 
9
9
  // This is automatically updated by the update-version.sh script
10
- internal const val SDK_VERSION = "3.5.3"
10
+ internal const val SDK_VERSION = "3.5.4"
@@ -1658,11 +1658,20 @@ internal class DdSdkTest {
1658
1658
  verbosity = verbosityName
1659
1659
  )
1660
1660
 
1661
- // When
1662
- testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
1661
+ val rumMock = org.mockito.Mockito.mockStatic(Rum::class.java)
1662
+ val traceMock = org.mockito.Mockito.mockStatic(Trace::class.java)
1663
+ val logsMock = org.mockito.Mockito.mockStatic(Logs::class.java)
1664
+ try {
1665
+ // When
1666
+ testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
1663
1667
 
1664
- // Then
1665
- verify(mockDatadog).setVerbosity(verbosity)
1668
+ // Then
1669
+ verify(mockDatadog).setVerbosity(verbosity)
1670
+ } finally {
1671
+ rumMock.close()
1672
+ logsMock.close()
1673
+ traceMock.close()
1674
+ }
1666
1675
  }
1667
1676
 
1668
1677
  @Test
@@ -1675,11 +1684,20 @@ internal class DdSdkTest {
1675
1684
  verbosity = verbosity
1676
1685
  )
1677
1686
 
1678
- // When
1679
- testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
1687
+ val rumMock = org.mockito.Mockito.mockStatic(Rum::class.java)
1688
+ val traceMock = org.mockito.Mockito.mockStatic(Trace::class.java)
1689
+ val logsMock = org.mockito.Mockito.mockStatic(Logs::class.java)
1690
+ try {
1691
+ // When
1692
+ testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
1680
1693
 
1681
- // Then
1682
- verify(mockDatadog, never()).setVerbosity(any())
1694
+ // Then
1695
+ verify(mockDatadog, never()).setVerbosity(any())
1696
+ } finally {
1697
+ rumMock.close()
1698
+ logsMock.close()
1699
+ traceMock.close()
1700
+ }
1683
1701
  }
1684
1702
 
1685
1703
  @Test
@@ -2493,26 +2511,35 @@ internal class DdSdkTest {
2493
2511
  )
2494
2512
  val frameDurationNs = threshold + frameDurationOverThreshold
2495
2513
 
2496
- // When
2497
- testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
2514
+ val rumMock = org.mockito.Mockito.mockStatic(Rum::class.java)
2515
+ val traceMock = org.mockito.Mockito.mockStatic(Trace::class.java)
2516
+ val logsMock = org.mockito.Mockito.mockStatic(Logs::class.java)
2517
+ try {
2518
+ // When
2519
+ testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
2498
2520
 
2499
- // Then
2500
- argumentCaptor<Choreographer.FrameCallback> {
2501
- verify(mockChoreographer).postFrameCallback(capture())
2521
+ // Then
2522
+ argumentCaptor<Choreographer.FrameCallback> {
2523
+ verify(mockChoreographer).postFrameCallback(capture())
2502
2524
 
2503
- // When
2504
- firstValue.doFrame(timestampNs)
2505
- firstValue.doFrame(timestampNs + frameDurationNs)
2525
+ // When
2526
+ firstValue.doFrame(timestampNs)
2527
+ firstValue.doFrame(timestampNs + frameDurationNs)
2506
2528
 
2507
- // then
2508
- verify(mockRumMonitor._getInternal()!!).updatePerformanceMetric(
2509
- RumPerformanceMetric.JS_FRAME_TIME,
2510
- frameDurationNs.toDouble()
2511
- )
2512
- verify(mockRumMonitor._getInternal()!!).addLongTask(
2513
- frameDurationNs,
2514
- "javascript"
2515
- )
2529
+ // then
2530
+ verify(mockRumMonitor._getInternal()!!).updatePerformanceMetric(
2531
+ RumPerformanceMetric.JS_FRAME_TIME,
2532
+ frameDurationNs.toDouble()
2533
+ )
2534
+ verify(mockRumMonitor._getInternal()!!).addLongTask(
2535
+ frameDurationNs,
2536
+ "javascript"
2537
+ )
2538
+ }
2539
+ } finally {
2540
+ rumMock.close()
2541
+ logsMock.close()
2542
+ traceMock.close()
2516
2543
  }
2517
2544
  }
2518
2545
 
@@ -2533,26 +2560,35 @@ internal class DdSdkTest {
2533
2560
  )
2534
2561
  val frameDurationNs = threshold + frameDurationOverThreshold
2535
2562
 
2536
- // When
2537
- testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
2538
-
2539
- // Then
2540
- argumentCaptor<Choreographer.FrameCallback> {
2541
- verify(mockChoreographer).postFrameCallback(capture())
2542
-
2563
+ val rumMock = org.mockito.Mockito.mockStatic(Rum::class.java)
2564
+ val traceMock = org.mockito.Mockito.mockStatic(Trace::class.java)
2565
+ val logsMock = org.mockito.Mockito.mockStatic(Logs::class.java)
2566
+ try {
2543
2567
  // When
2544
- firstValue.doFrame(timestampNs)
2545
- firstValue.doFrame(timestampNs + frameDurationNs)
2568
+ testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
2546
2569
 
2547
2570
  // Then
2548
- verify(mockRumMonitor._getInternal()!!).addLongTask(
2549
- frameDurationNs,
2550
- "javascript"
2551
- )
2552
- verify(mockRumMonitor._getInternal()!!, never()).updatePerformanceMetric(
2553
- RumPerformanceMetric.JS_FRAME_TIME,
2554
- frameDurationNs.toDouble()
2555
- )
2571
+ argumentCaptor<Choreographer.FrameCallback> {
2572
+ verify(mockChoreographer).postFrameCallback(capture())
2573
+
2574
+ // When
2575
+ firstValue.doFrame(timestampNs)
2576
+ firstValue.doFrame(timestampNs + frameDurationNs)
2577
+
2578
+ // Then
2579
+ verify(mockRumMonitor._getInternal()!!).addLongTask(
2580
+ frameDurationNs,
2581
+ "javascript"
2582
+ )
2583
+ verify(mockRumMonitor._getInternal()!!, never()).updatePerformanceMetric(
2584
+ RumPerformanceMetric.JS_FRAME_TIME,
2585
+ frameDurationNs.toDouble()
2586
+ )
2587
+ }
2588
+ } finally {
2589
+ rumMock.close()
2590
+ logsMock.close()
2591
+ traceMock.close()
2556
2592
  }
2557
2593
  }
2558
2594
 
@@ -3425,14 +3461,23 @@ internal class DdSdkTest {
3425
3461
  DdSdkSynthetics.testId = "unit-test-test-id"
3426
3462
  DdSdkSynthetics.resultId = "unit-test-result-id"
3427
3463
 
3428
- // When
3429
- testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise)
3464
+ val rumMock = org.mockito.Mockito.mockStatic(Rum::class.java)
3465
+ val traceMock = org.mockito.Mockito.mockStatic(Trace::class.java)
3466
+ val logsMock = org.mockito.Mockito.mockStatic(Logs::class.java)
3467
+ try {
3468
+ // When
3469
+ testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise)
3430
3470
 
3431
- // Then
3432
- verify(mockRumInternalProxy).setSyntheticsAttribute(
3433
- "unit-test-test-id",
3434
- "unit-test-result-id"
3435
- )
3471
+ // Then
3472
+ verify(mockRumInternalProxy).setSyntheticsAttribute(
3473
+ "unit-test-test-id",
3474
+ "unit-test-result-id"
3475
+ )
3476
+ } finally {
3477
+ rumMock.close()
3478
+ logsMock.close()
3479
+ traceMock.close()
3480
+ }
3436
3481
  }
3437
3482
 
3438
3483
  @Test
@@ -7,4 +7,4 @@
7
7
  import Foundation
8
8
 
9
9
  // This is automatically updated by the update-version.sh script
10
- let SdkVersion = "3.5.3"
10
+ let SdkVersion = "3.5.4"
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.FlagsClient = void 0;
7
7
  var _InternalLog = require("../InternalLog");
8
8
  var _SdkVerbosity = require("../config/types/SdkVerbosity");
9
+ var _context = require("./configuration/context");
10
+ var _configuration = require("./configuration");
9
11
  var _internal = require("./internal");
10
12
  /*
11
13
  * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
@@ -13,11 +15,67 @@ var _internal = require("./internal");
13
15
  * Copyright 2016-Present Datadog, Inc.
14
16
  */
15
17
 
18
+ // Imported directly (not via the module index): context matching is an internal helper,
19
+ // used here only to detect a runtime context an offline precomputed configuration cannot honor.
20
+
21
+ /**
22
+ * Error codes an offline configuration result can carry:
23
+ * - `INVALID_CONTEXT`: the active context does not match the precomputed snapshot.
24
+ * - `PROVIDER_NOT_READY`: an offline operation ran with no configuration loaded.
25
+ * - `GENERAL`: the loaded configuration is unusable (malformed/unsupported/undecodable).
26
+ */
27
+
28
+ /**
29
+ * Outcome of loading a configuration or reconciling it against the active evaluation context,
30
+ * returned by the offline APIs ({@link FlagsClient.setConfiguration},
31
+ * {@link FlagsClient.setEvaluationContextWithoutFetching},
32
+ * {@link FlagsClient.resetEvaluationContextWithoutFetching}).
33
+ *
34
+ * `'ready'` means the configuration can be served against the active context; `'error'` carries
35
+ * the precise reason so the OpenFeature provider surfaces the correct code and evaluation returns
36
+ * that code with the coded default.
37
+ *
38
+ * @internal Consumers observe OpenFeature provider events/evaluation details, not this result.
39
+ */
40
+
41
+ /**
42
+ * The decoded outcome of the last loaded offline configuration. Load validity (`kind`) is stored
43
+ * separately from context compatibility so that later context changes reconcile against a decoded
44
+ * snapshot **without re-decoding** and can never promote an invalid load to a servable state.
45
+ *
46
+ * `'none'` = no offline configuration engaged (the online/fetch path, or nothing loaded yet).
47
+ */
48
+
16
49
  class FlagsClient {
17
50
  // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
18
51
  nativeFlags = require('../specs/NativeDdFlags').default;
52
+ // The context the app explicitly set — the online fetch context, or the offline override via
53
+ // {@link setEvaluationContextWithoutFetching}. `undefined` means "no external override": an
54
+ // offline precomputed configuration is then served against its own embedded context. Tracked
55
+ // separately from {@link evaluationContext} so that adopting a configuration's embedded context
56
+ // is never mistaken for an app-set override (which would spuriously fail a later replacement).
57
+ externalContext = undefined;
58
+
59
+ // The effective context evaluation and exposure tracking run against: the external override
60
+ // when set, otherwise the loaded configuration's embedded context.
19
61
  evaluationContext = undefined;
20
- flagsCache = {};
62
+
63
+ // The servable flag cache. On the online path it holds the native-fetched flags; on the
64
+ // offline path it mirrors the decoded snapshot when the configuration is servable. A Map
65
+ // (not a plain object) so a flag keyed like an inherited property ("toString",
66
+ // "__proto__") is looked up as data via `.get()` and never resolves an `Object.prototype`
67
+ // member — important now the cache can be fed from untrusted wire data.
68
+ flagsCache = new Map();
69
+
70
+ // The decoded outcome of the last loaded offline configuration (see the type).
71
+ loadedConfiguration = {
72
+ kind: 'none'
73
+ };
74
+
75
+ // Internal serving status. `'none'` = online path (serve `flagsCache`); `'ready'` = serve
76
+ // the offline snapshot; `'error'` = serve coded defaults with `configurationError`.
77
+ configurationStatus = 'none';
78
+ configurationError = undefined;
21
79
  constructor(clientName = 'default') {
22
80
  this.clientName = clientName;
23
81
  }
@@ -48,17 +106,212 @@ class FlagsClient {
48
106
  setEvaluationContext = async context => {
49
107
  // Make sure to process the incoming context because we don't support nested object values in context.
50
108
  const processedContext = (0, _internal.processEvaluationContext)(context);
109
+
110
+ // Entering online mode drops any offline overlay *before* fetching, so a failed fetch falls
111
+ // back to coded defaults rather than continuing to serve a stale offline snapshot. Using one
112
+ // client for both online and offline is unsupported (give the offline provider its own
113
+ // `clientName`), so warn when an offline configuration is discarded here. Online-only clients
114
+ // have no overlay, so this does not touch their keep-last-known-flags-on-failure behavior.
115
+ if (this.loadedConfiguration.kind !== 'none') {
116
+ _InternalLog.InternalLog.log(`An offline configuration was loaded for '${this.clientName}' but an online fetch was requested; discarding it and serving default values on failure. Use a separate client for the offline provider.`, _SdkVerbosity.SdkVerbosity.WARN);
117
+ this.loadedConfiguration = {
118
+ kind: 'none'
119
+ };
120
+ this.configurationStatus = 'none';
121
+ this.configurationError = undefined;
122
+ this.flagsCache = new Map();
123
+ this.evaluationContext = undefined;
124
+ this.externalContext = undefined;
125
+ }
51
126
  try {
52
127
  const result = await this.nativeFlags.setEvaluationContext(this.clientName, processedContext.targetingKey, processedContext.attributes ?? {});
128
+ this.externalContext = processedContext;
53
129
  this.evaluationContext = processedContext;
54
- this.flagsCache = result;
130
+ this.flagsCache = new Map(Object.entries(result));
131
+
132
+ // A successful online fetch is authoritative: reset to the clean online state so a
133
+ // prior offline error status (e.g. PROVIDER_NOT_READY from an offline op with no
134
+ // configuration loaded) can't keep serving coded defaults over the fetched flags.
135
+ this.loadedConfiguration = {
136
+ kind: 'none'
137
+ };
138
+ this.configurationStatus = 'none';
139
+ this.configurationError = undefined;
55
140
  } catch (error) {
141
+ // A failed fetch leaves the previous online cache in place (keep-last-known); any offline
142
+ // overlay was already dropped above, so no stale offline snapshot is served.
56
143
  if (error instanceof Error) {
57
144
  _InternalLog.InternalLog.log(`Error setting flag evaluation context: ${error.message}`, _SdkVerbosity.SdkVerbosity.WARN);
58
145
  }
59
146
  throw error;
60
147
  }
61
148
  };
149
+
150
+ /**
151
+ * Set the evaluation context **without** fetching a configuration from the network, then
152
+ * reconcile the loaded configuration against it.
153
+ *
154
+ * The offline counterpart to {@link setEvaluationContext}: records the active context and
155
+ * reconciles with no native request. A precomputed configuration is single-subject, so a
156
+ * context that does not match the one it was computed for reconciles to an error
157
+ * (`INVALID_CONTEXT`) and evaluation serves defaults. With no configuration loaded the
158
+ * result is `PROVIDER_NOT_READY`. Intended for offline providers that own their
159
+ * configuration via `setConfiguration` and must not fetch on a context change.
160
+ *
161
+ * @param context The evaluation context to associate with the current client.
162
+ */
163
+ setEvaluationContextWithoutFetching = context => {
164
+ this.externalContext = (0, _internal.processEvaluationContext)(context);
165
+ return this.reconcile();
166
+ };
167
+
168
+ /**
169
+ * Clear any externally-set evaluation context and reconcile.
170
+ *
171
+ * This is the offline counterpart to clearing/omitting an OpenFeature context: it drops the
172
+ * external override so a loaded precomputed configuration is served against **its embedded
173
+ * context** again. Clearing the override (rather than skipping) matters so that a
174
+ * configuration loaded *after* a clear is not judged against a stale override. With no
175
+ * configuration loaded the result is `PROVIDER_NOT_READY`.
176
+ */
177
+ resetEvaluationContextWithoutFetching = () => {
178
+ this.externalContext = undefined;
179
+ return this.reconcile();
180
+ };
181
+
182
+ /**
183
+ * Load a configuration (parsed from a `ConfigurationWire` string via
184
+ * `configurationFromString`) into the client for offline evaluation, then reconcile it
185
+ * against the active context.
186
+ *
187
+ * For a precomputed configuration this decodes the snapshot once and adopts its embedded
188
+ * evaluation context when none is set — **no network request is made**. An unusable
189
+ * configuration reconciles to an error (`GENERAL`); a context mismatch to `INVALID_CONTEXT`.
190
+ *
191
+ * @param configuration The configuration to load.
192
+ *
193
+ * @example
194
+ * ```ts
195
+ * const configuration = configurationFromString(wire);
196
+ * flagsClient.setConfiguration(configuration);
197
+ *
198
+ * const value = flagsClient.getBooleanValue('new-feature', false);
199
+ * ```
200
+ */
201
+ setConfiguration = configuration => {
202
+ this.loadedConfiguration = this.loadConfiguration(configuration);
203
+ return this.reconcile();
204
+ };
205
+
206
+ /**
207
+ * Decode a supplied configuration into a {@link LoadedConfigurationState} **once**, capturing
208
+ * whether the load itself is valid (independent of the active context). Later context changes
209
+ * reconcile against this stored state without re-decoding, and can never turn an invalid load
210
+ * into a servable one.
211
+ *
212
+ * FORWARD-COMPAT SEAM: when a rules-based configuration is supported, it must be handled here
213
+ * BEFORE the precomputed guard — rules are context-agnostic and must NOT be classified invalid.
214
+ */
215
+ loadConfiguration = configuration => {
216
+ const precomputed = configuration?.precomputed;
217
+
218
+ // An empty configuration (a failed/lenient wire parse, or a wire with no precomputed
219
+ // branch) is unusable. `configurationFromString` collapses malformed input and
220
+ // unsupported versions to the same empty shape, so this is classified as `GENERAL`.
221
+ if (!precomputed) {
222
+ _InternalLog.InternalLog.log(`No usable precomputed configuration was provided for '${this.clientName}'.`, _SdkVerbosity.SdkVerbosity.WARN);
223
+ return {
224
+ kind: 'invalid',
225
+ errorCode: 'GENERAL'
226
+ };
227
+ }
228
+ try {
229
+ const flags = (0, _configuration.decodePrecomputedFlags)(precomputed.response);
230
+ return {
231
+ kind: 'precomputed',
232
+ configuration: precomputed,
233
+ flags
234
+ };
235
+ } catch (error) {
236
+ // Decoding rejects unsupported payloads (e.g. obfuscated) — an unsupported kind,
237
+ // classified as `GENERAL`.
238
+ if (error instanceof Error) {
239
+ _InternalLog.InternalLog.log(`Unsupported flags configuration for '${this.clientName}': ${error.message}`, _SdkVerbosity.SdkVerbosity.WARN);
240
+ }
241
+ return {
242
+ kind: 'invalid',
243
+ errorCode: 'GENERAL'
244
+ };
245
+ }
246
+ };
247
+
248
+ /**
249
+ * Reconcile the stored {@link LoadedConfigurationState} against the active evaluation context
250
+ * and (re)compute the servable flag cache and configuration status/result.
251
+ *
252
+ * The stored load validity is consulted **before** context compatibility, so a context change
253
+ * can never promote an invalid (or absent) load to `ready`.
254
+ */
255
+ reconcile = () => {
256
+ const loaded = this.loadedConfiguration;
257
+
258
+ // No offline configuration engaged: an offline operation with nothing loaded is not ready.
259
+ if (loaded.kind === 'none') {
260
+ return this.enterError('PROVIDER_NOT_READY', `The evaluation context is not usable for '${this.clientName}': no configuration is loaded. Provide a configuration via setConfiguration.`);
261
+ }
262
+
263
+ // The load itself failed (malformed/unsupported/undecodable) — independent of context.
264
+ if (loaded.kind === 'invalid') {
265
+ return this.enterError(loaded.errorCode, `The loaded configuration for '${this.clientName}' is not usable. Provide a valid precomputed configuration.`);
266
+ }
267
+ const {
268
+ configuration,
269
+ flags
270
+ } = loaded;
271
+
272
+ // A precomputed snapshot is bound to the subject it was computed for. If the app set an
273
+ // *external* context that does not match, it cannot be served (offline never fetches), so
274
+ // it is an error and evaluation serves coded defaults. Only an external override is checked
275
+ // here — the configuration's own embedded context (adopted below when no override is set)
276
+ // matches by construction, so replacing one snapshot with another for a different subject
277
+ // stays `ready`. The decoded snapshot is retained for a later matching context.
278
+ if (this.externalContext && !(0, _context.contextMatchesConfiguration)(configuration.context, this.externalContext)) {
279
+ return this.enterError('INVALID_CONTEXT', `The evaluation context does not match the precomputed configuration for '${this.clientName}'. Serving default values. Set a matching context, or use a rules-based configuration for per-context evaluation.`);
280
+ }
281
+
282
+ // Serve against the external override when set, otherwise the configuration's embedded
283
+ // context (a context-agnostic configuration falls back to an empty context).
284
+ this.evaluationContext = this.externalContext ?? this.embeddedContext(configuration);
285
+ this.flagsCache = flags;
286
+ this.configurationStatus = 'ready';
287
+ this.configurationError = undefined;
288
+ return {
289
+ status: 'ready'
290
+ };
291
+ };
292
+
293
+ /** The evaluation context a precomputed configuration was computed for (empty if agnostic). */
294
+ embeddedContext = configuration => {
295
+ return configuration.context ? (0, _configuration.normalizeWireContext)(configuration.context) : {
296
+ targetingKey: '',
297
+ attributes: {}
298
+ };
299
+ };
300
+
301
+ /** Record an error status + message, clear the servable cache, and return the result. */
302
+ enterError = (errorCode, errorMessage) => {
303
+ this.flagsCache = new Map();
304
+ this.configurationStatus = 'error';
305
+ this.configurationError = {
306
+ errorCode,
307
+ errorMessage
308
+ };
309
+ _InternalLog.InternalLog.log(errorMessage, _SdkVerbosity.SdkVerbosity.WARN);
310
+ return {
311
+ status: 'error',
312
+ errorCode
313
+ };
314
+ };
62
315
  track = (flag, context) => {
63
316
  // A non-blocking call; don't await this.
64
317
  this.nativeFlags.trackEvaluation(this.clientName, flag.key, flag, context.targetingKey, context.attributes ?? {}).catch(error => {
@@ -68,6 +321,18 @@ class FlagsClient {
68
321
  });
69
322
  };
70
323
  getDetails = (key, defaultValue, type) => {
324
+ // An offline configuration that cannot be served against the active context surfaces the
325
+ // precise error code (INVALID_CONTEXT / GENERAL / PROVIDER_NOT_READY) with the coded
326
+ // default. The OpenFeature provider maps this to a PROVIDER_ERROR / ERROR state.
327
+ if (this.configurationStatus === 'error' && this.configurationError) {
328
+ return {
329
+ key,
330
+ value: defaultValue,
331
+ reason: 'ERROR',
332
+ errorCode: this.configurationError.errorCode,
333
+ errorMessage: this.configurationError.errorMessage
334
+ };
335
+ }
71
336
  if (!this.evaluationContext) {
72
337
  return {
73
338
  key,
@@ -79,7 +344,7 @@ class FlagsClient {
79
344
  }
80
345
 
81
346
  // Retrieve the flag from the cache.
82
- const flag = this.flagsCache[key];
347
+ const flag = this.flagsCache.get(key);
83
348
  if (!flag) {
84
349
  return {
85
350
  key,
@@ -1 +1 @@
1
- {"version":3,"names":["_InternalLog","require","_SdkVerbosity","_internal","FlagsClient","nativeFlags","default","evaluationContext","undefined","flagsCache","constructor","clientName","setEvaluationContext","context","processedContext","processEvaluationContext","result","targetingKey","attributes","error","Error","InternalLog","log","message","SdkVerbosity","WARN","track","flag","trackEvaluation","key","catch","getDetails","defaultValue","type","value","reason","errorCode","errorMessage","actualType","details","variant","variationKey","allocationKey","getBooleanDetails","getStringDetails","getNumberDetails","getObjectDetails","getBooleanValue","getStringValue","getNumberValue","getObjectValue","exports"],"sourceRoot":"../../../src","sources":["flags/FlagsClient.ts"],"mappings":";;;;;;AAMA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAGA,IAAAE,SAAA,GAAAF,OAAA;AAVA;AACA;AACA;AACA;AACA;;AAUO,MAAMG,WAAW,CAAC;EACrB;EACQC,WAAW,GAAsBJ,OAAO,CAAC,wBAAwB,CAAC,CACrEK,OAAO;EAIJC,iBAAiB,GAAkCC,SAAS;EAE5DC,UAAU,GAAmC,CAAC,CAAC;EAEvDC,WAAWA,CAACC,UAAkB,GAAG,SAAS,EAAE;IACxC,IAAI,CAACA,UAAU,GAAGA,UAAU;EAChC;;EAEA;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACIC,oBAAoB,GAAG,MACnBC,OAA0B,IACV;IAChB;IACA,MAAMC,gBAAgB,GAAG,IAAAC,kCAAwB,EAACF,OAAO,CAAC;IAE1D,IAAI;MACA,MAAMG,MAAM,GAAG,MAAM,IAAI,CAACX,WAAW,CAACO,oBAAoB,CACtD,IAAI,CAACD,UAAU,EACfG,gBAAgB,CAACG,YAAY,EAC7BH,gBAAgB,CAACI,UAAU,IAAI,CAAC,CACpC,CAAC;MAED,IAAI,CAACX,iBAAiB,GAAGO,gBAAgB;MACzC,IAAI,CAACL,UAAU,GAAGO,MAAM;IAC5B,CAAC,CAAC,OAAOG,KAAK,EAAE;MACZ,IAAIA,KAAK,YAAYC,KAAK,EAAE;QACxBC,wBAAW,CAACC,GAAG,CACX,0CAA0CH,KAAK,CAACI,OAAO,EAAE,EACzDC,0BAAY,CAACC,IACjB,CAAC;MACL;MAEA,MAAMN,KAAK;IACf;EACJ,CAAC;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A;AACA;AACA;AACA;AACA;AACA;EACIc,cAAc,GAAGA,CAACnB,GAAW,EAAEG,YAAoB,KAAa;IAC5D,OAAO,IAAI,CAACY,gBAAgB,CAACf,GAAG,EAAEG,YAAY,CAAC,CAACE,KAAK;EACzD,CAAC;;EAED;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACIe,cAAc,GAAGA,CAACpB,GAAW,EAAEG,YAAoB,KAAa;IAC5D,OAAO,IAAI,CAACa,gBAAgB,CAAChB,GAAG,EAAEG,YAAY,CAAC,CAACE,KAAK;EACzD,CAAC;;EAED;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACIgB,cAAc,GAAGA,CAAsBrB,GAAW,EAAEG,YAAe,KAAQ;IACvE,OAAO,IAAI,CAACc,gBAAgB,CAACjB,GAAG,EAAEG,YAAY,CAAC,CAACE,KAAK;EACzD,CAAC;AACL;AAACiB,OAAA,CAAA/C,WAAA,GAAAA,WAAA","ignoreList":[]}
1
+ {"version":3,"names":["_InternalLog","require","_SdkVerbosity","_context","_configuration","_internal","FlagsClient","nativeFlags","default","externalContext","undefined","evaluationContext","flagsCache","Map","loadedConfiguration","kind","configurationStatus","configurationError","constructor","clientName","setEvaluationContext","context","processedContext","processEvaluationContext","InternalLog","log","SdkVerbosity","WARN","result","targetingKey","attributes","Object","entries","error","Error","message","setEvaluationContextWithoutFetching","reconcile","resetEvaluationContextWithoutFetching","setConfiguration","configuration","loadConfiguration","precomputed","errorCode","flags","decodePrecomputedFlags","response","loaded","enterError","contextMatchesConfiguration","embeddedContext","status","normalizeWireContext","errorMessage","track","flag","trackEvaluation","key","catch","getDetails","defaultValue","type","value","reason","get","actualType","details","variant","variationKey","allocationKey","getBooleanDetails","getStringDetails","getNumberDetails","getObjectDetails","getBooleanValue","getStringValue","getNumberValue","getObjectValue","exports"],"sourceRoot":"../../../src","sources":["flags/FlagsClient.ts"],"mappings":";;;;;;AAMA,IAAAA,YAAA,GAAAC,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G,YAAY,CAAC,CAACE,KAAK;EACzD,CAAC;AACL;AAACgB,OAAA,CAAAxE,WAAA,GAAAA,WAAA","ignoreList":[]}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.normalizeWireContext = exports.contextMatchesConfiguration = void 0;
7
+ var _internal = require("../internal");
8
+ /*
9
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
10
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
11
+ * Copyright 2016-Present Datadog, Inc.
12
+ */
13
+
14
+ /**
15
+ * Normalize a wire (OpenFeature-flat) evaluation context into the SDK's internal
16
+ * `{ targetingKey, attributes }` shape, applying the **same** processing the active
17
+ * context went through (`processEvaluationContext`) so the two are comparable — the
18
+ * flat wire shape and the internal shape are otherwise never equal.
19
+ */
20
+ const normalizeWireContext = wireContext => {
21
+ const {
22
+ targetingKey,
23
+ ...attributes
24
+ } = wireContext;
25
+ return (0, _internal.processEvaluationContext)({
26
+ // The wire is untrusted, so a non-string targetingKey is treated as absent.
27
+ targetingKey: typeof targetingKey === 'string' ? targetingKey : '',
28
+ // `processEvaluationContext` drops non-primitive attributes; casting here mirrors
29
+ // how the active context's attributes are typed before that same processing.
30
+ attributes: attributes
31
+ });
32
+ };
33
+
34
+ /**
35
+ * Whether a precomputed configuration's embedded context matches the active evaluation
36
+ * context.
37
+ *
38
+ * - A configuration with **no** embedded context is context-agnostic and matches any
39
+ * active context.
40
+ * - Otherwise the embedded context must match the active context exactly (after
41
+ * normalizing both through the same processing).
42
+ */
43
+ exports.normalizeWireContext = normalizeWireContext;
44
+ const contextMatchesConfiguration = (wireContext, activeContext) => {
45
+ if (!wireContext) {
46
+ return true;
47
+ }
48
+ return contextsEqual(normalizeWireContext(wireContext), activeContext);
49
+ };
50
+ exports.contextMatchesConfiguration = contextMatchesConfiguration;
51
+ const contextsEqual = (a, b) => {
52
+ if (a.targetingKey !== b.targetingKey) {
53
+ return false;
54
+ }
55
+ return attributesEqual(a.attributes ?? {}, b.attributes ?? {});
56
+ };
57
+
58
+ /**
59
+ * Compare two attribute maps. After `processEvaluationContext`, attribute values are
60
+ * primitives, so a key-set + strict-value comparison is sufficient.
61
+ */
62
+ const attributesEqual = (a, b) => {
63
+ const aKeys = Object.keys(a);
64
+ const bKeys = Object.keys(b);
65
+ if (aKeys.length !== bKeys.length) {
66
+ return false;
67
+ }
68
+ return aKeys.every(key => a[key] === b[key]);
69
+ };
70
+ //# sourceMappingURL=context.js.map