@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
@@ -6,12 +6,70 @@
6
6
 
7
7
  import { InternalLog } from '../InternalLog';
8
8
  import { SdkVerbosity } from '../config/types/SdkVerbosity';
9
+ // Imported directly (not via the module index): context matching is an internal helper,
10
+ // used here only to detect a runtime context an offline precomputed configuration cannot honor.
11
+ import { contextMatchesConfiguration } from './configuration/context';
12
+ import { decodePrecomputedFlags, normalizeWireContext } from './configuration';
9
13
  import { processEvaluationContext } from './internal';
14
+
15
+ /**
16
+ * Error codes an offline configuration result can carry:
17
+ * - `INVALID_CONTEXT`: the active context does not match the precomputed snapshot.
18
+ * - `PROVIDER_NOT_READY`: an offline operation ran with no configuration loaded.
19
+ * - `GENERAL`: the loaded configuration is unusable (malformed/unsupported/undecodable).
20
+ */
21
+
22
+ /**
23
+ * Outcome of loading a configuration or reconciling it against the active evaluation context,
24
+ * returned by the offline APIs ({@link FlagsClient.setConfiguration},
25
+ * {@link FlagsClient.setEvaluationContextWithoutFetching},
26
+ * {@link FlagsClient.resetEvaluationContextWithoutFetching}).
27
+ *
28
+ * `'ready'` means the configuration can be served against the active context; `'error'` carries
29
+ * the precise reason so the OpenFeature provider surfaces the correct code and evaluation returns
30
+ * that code with the coded default.
31
+ *
32
+ * @internal Consumers observe OpenFeature provider events/evaluation details, not this result.
33
+ */
34
+
35
+ /**
36
+ * The decoded outcome of the last loaded offline configuration. Load validity (`kind`) is stored
37
+ * separately from context compatibility so that later context changes reconcile against a decoded
38
+ * snapshot **without re-decoding** and can never promote an invalid load to a servable state.
39
+ *
40
+ * `'none'` = no offline configuration engaged (the online/fetch path, or nothing loaded yet).
41
+ */
42
+
10
43
  export class FlagsClient {
11
44
  // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
12
45
  nativeFlags = require('../specs/NativeDdFlags').default;
46
+ // The context the app explicitly set — the online fetch context, or the offline override via
47
+ // {@link setEvaluationContextWithoutFetching}. `undefined` means "no external override": an
48
+ // offline precomputed configuration is then served against its own embedded context. Tracked
49
+ // separately from {@link evaluationContext} so that adopting a configuration's embedded context
50
+ // is never mistaken for an app-set override (which would spuriously fail a later replacement).
51
+ externalContext = undefined;
52
+
53
+ // The effective context evaluation and exposure tracking run against: the external override
54
+ // when set, otherwise the loaded configuration's embedded context.
13
55
  evaluationContext = undefined;
14
- flagsCache = {};
56
+
57
+ // The servable flag cache. On the online path it holds the native-fetched flags; on the
58
+ // offline path it mirrors the decoded snapshot when the configuration is servable. A Map
59
+ // (not a plain object) so a flag keyed like an inherited property ("toString",
60
+ // "__proto__") is looked up as data via `.get()` and never resolves an `Object.prototype`
61
+ // member — important now the cache can be fed from untrusted wire data.
62
+ flagsCache = new Map();
63
+
64
+ // The decoded outcome of the last loaded offline configuration (see the type).
65
+ loadedConfiguration = {
66
+ kind: 'none'
67
+ };
68
+
69
+ // Internal serving status. `'none'` = online path (serve `flagsCache`); `'ready'` = serve
70
+ // the offline snapshot; `'error'` = serve coded defaults with `configurationError`.
71
+ configurationStatus = 'none';
72
+ configurationError = undefined;
15
73
  constructor(clientName = 'default') {
16
74
  this.clientName = clientName;
17
75
  }
@@ -42,17 +100,212 @@ export class FlagsClient {
42
100
  setEvaluationContext = async context => {
43
101
  // Make sure to process the incoming context because we don't support nested object values in context.
44
102
  const processedContext = processEvaluationContext(context);
103
+
104
+ // Entering online mode drops any offline overlay *before* fetching, so a failed fetch falls
105
+ // back to coded defaults rather than continuing to serve a stale offline snapshot. Using one
106
+ // client for both online and offline is unsupported (give the offline provider its own
107
+ // `clientName`), so warn when an offline configuration is discarded here. Online-only clients
108
+ // have no overlay, so this does not touch their keep-last-known-flags-on-failure behavior.
109
+ if (this.loadedConfiguration.kind !== 'none') {
110
+ 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.WARN);
111
+ this.loadedConfiguration = {
112
+ kind: 'none'
113
+ };
114
+ this.configurationStatus = 'none';
115
+ this.configurationError = undefined;
116
+ this.flagsCache = new Map();
117
+ this.evaluationContext = undefined;
118
+ this.externalContext = undefined;
119
+ }
45
120
  try {
46
121
  const result = await this.nativeFlags.setEvaluationContext(this.clientName, processedContext.targetingKey, processedContext.attributes ?? {});
122
+ this.externalContext = processedContext;
47
123
  this.evaluationContext = processedContext;
48
- this.flagsCache = result;
124
+ this.flagsCache = new Map(Object.entries(result));
125
+
126
+ // A successful online fetch is authoritative: reset to the clean online state so a
127
+ // prior offline error status (e.g. PROVIDER_NOT_READY from an offline op with no
128
+ // configuration loaded) can't keep serving coded defaults over the fetched flags.
129
+ this.loadedConfiguration = {
130
+ kind: 'none'
131
+ };
132
+ this.configurationStatus = 'none';
133
+ this.configurationError = undefined;
49
134
  } catch (error) {
135
+ // A failed fetch leaves the previous online cache in place (keep-last-known); any offline
136
+ // overlay was already dropped above, so no stale offline snapshot is served.
50
137
  if (error instanceof Error) {
51
138
  InternalLog.log(`Error setting flag evaluation context: ${error.message}`, SdkVerbosity.WARN);
52
139
  }
53
140
  throw error;
54
141
  }
55
142
  };
143
+
144
+ /**
145
+ * Set the evaluation context **without** fetching a configuration from the network, then
146
+ * reconcile the loaded configuration against it.
147
+ *
148
+ * The offline counterpart to {@link setEvaluationContext}: records the active context and
149
+ * reconciles with no native request. A precomputed configuration is single-subject, so a
150
+ * context that does not match the one it was computed for reconciles to an error
151
+ * (`INVALID_CONTEXT`) and evaluation serves defaults. With no configuration loaded the
152
+ * result is `PROVIDER_NOT_READY`. Intended for offline providers that own their
153
+ * configuration via `setConfiguration` and must not fetch on a context change.
154
+ *
155
+ * @param context The evaluation context to associate with the current client.
156
+ */
157
+ setEvaluationContextWithoutFetching = context => {
158
+ this.externalContext = processEvaluationContext(context);
159
+ return this.reconcile();
160
+ };
161
+
162
+ /**
163
+ * Clear any externally-set evaluation context and reconcile.
164
+ *
165
+ * This is the offline counterpart to clearing/omitting an OpenFeature context: it drops the
166
+ * external override so a loaded precomputed configuration is served against **its embedded
167
+ * context** again. Clearing the override (rather than skipping) matters so that a
168
+ * configuration loaded *after* a clear is not judged against a stale override. With no
169
+ * configuration loaded the result is `PROVIDER_NOT_READY`.
170
+ */
171
+ resetEvaluationContextWithoutFetching = () => {
172
+ this.externalContext = undefined;
173
+ return this.reconcile();
174
+ };
175
+
176
+ /**
177
+ * Load a configuration (parsed from a `ConfigurationWire` string via
178
+ * `configurationFromString`) into the client for offline evaluation, then reconcile it
179
+ * against the active context.
180
+ *
181
+ * For a precomputed configuration this decodes the snapshot once and adopts its embedded
182
+ * evaluation context when none is set — **no network request is made**. An unusable
183
+ * configuration reconciles to an error (`GENERAL`); a context mismatch to `INVALID_CONTEXT`.
184
+ *
185
+ * @param configuration The configuration to load.
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * const configuration = configurationFromString(wire);
190
+ * flagsClient.setConfiguration(configuration);
191
+ *
192
+ * const value = flagsClient.getBooleanValue('new-feature', false);
193
+ * ```
194
+ */
195
+ setConfiguration = configuration => {
196
+ this.loadedConfiguration = this.loadConfiguration(configuration);
197
+ return this.reconcile();
198
+ };
199
+
200
+ /**
201
+ * Decode a supplied configuration into a {@link LoadedConfigurationState} **once**, capturing
202
+ * whether the load itself is valid (independent of the active context). Later context changes
203
+ * reconcile against this stored state without re-decoding, and can never turn an invalid load
204
+ * into a servable one.
205
+ *
206
+ * FORWARD-COMPAT SEAM: when a rules-based configuration is supported, it must be handled here
207
+ * BEFORE the precomputed guard — rules are context-agnostic and must NOT be classified invalid.
208
+ */
209
+ loadConfiguration = configuration => {
210
+ const precomputed = configuration?.precomputed;
211
+
212
+ // An empty configuration (a failed/lenient wire parse, or a wire with no precomputed
213
+ // branch) is unusable. `configurationFromString` collapses malformed input and
214
+ // unsupported versions to the same empty shape, so this is classified as `GENERAL`.
215
+ if (!precomputed) {
216
+ InternalLog.log(`No usable precomputed configuration was provided for '${this.clientName}'.`, SdkVerbosity.WARN);
217
+ return {
218
+ kind: 'invalid',
219
+ errorCode: 'GENERAL'
220
+ };
221
+ }
222
+ try {
223
+ const flags = decodePrecomputedFlags(precomputed.response);
224
+ return {
225
+ kind: 'precomputed',
226
+ configuration: precomputed,
227
+ flags
228
+ };
229
+ } catch (error) {
230
+ // Decoding rejects unsupported payloads (e.g. obfuscated) — an unsupported kind,
231
+ // classified as `GENERAL`.
232
+ if (error instanceof Error) {
233
+ InternalLog.log(`Unsupported flags configuration for '${this.clientName}': ${error.message}`, SdkVerbosity.WARN);
234
+ }
235
+ return {
236
+ kind: 'invalid',
237
+ errorCode: 'GENERAL'
238
+ };
239
+ }
240
+ };
241
+
242
+ /**
243
+ * Reconcile the stored {@link LoadedConfigurationState} against the active evaluation context
244
+ * and (re)compute the servable flag cache and configuration status/result.
245
+ *
246
+ * The stored load validity is consulted **before** context compatibility, so a context change
247
+ * can never promote an invalid (or absent) load to `ready`.
248
+ */
249
+ reconcile = () => {
250
+ const loaded = this.loadedConfiguration;
251
+
252
+ // No offline configuration engaged: an offline operation with nothing loaded is not ready.
253
+ if (loaded.kind === 'none') {
254
+ return this.enterError('PROVIDER_NOT_READY', `The evaluation context is not usable for '${this.clientName}': no configuration is loaded. Provide a configuration via setConfiguration.`);
255
+ }
256
+
257
+ // The load itself failed (malformed/unsupported/undecodable) — independent of context.
258
+ if (loaded.kind === 'invalid') {
259
+ return this.enterError(loaded.errorCode, `The loaded configuration for '${this.clientName}' is not usable. Provide a valid precomputed configuration.`);
260
+ }
261
+ const {
262
+ configuration,
263
+ flags
264
+ } = loaded;
265
+
266
+ // A precomputed snapshot is bound to the subject it was computed for. If the app set an
267
+ // *external* context that does not match, it cannot be served (offline never fetches), so
268
+ // it is an error and evaluation serves coded defaults. Only an external override is checked
269
+ // here — the configuration's own embedded context (adopted below when no override is set)
270
+ // matches by construction, so replacing one snapshot with another for a different subject
271
+ // stays `ready`. The decoded snapshot is retained for a later matching context.
272
+ if (this.externalContext && !contextMatchesConfiguration(configuration.context, this.externalContext)) {
273
+ 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.`);
274
+ }
275
+
276
+ // Serve against the external override when set, otherwise the configuration's embedded
277
+ // context (a context-agnostic configuration falls back to an empty context).
278
+ this.evaluationContext = this.externalContext ?? this.embeddedContext(configuration);
279
+ this.flagsCache = flags;
280
+ this.configurationStatus = 'ready';
281
+ this.configurationError = undefined;
282
+ return {
283
+ status: 'ready'
284
+ };
285
+ };
286
+
287
+ /** The evaluation context a precomputed configuration was computed for (empty if agnostic). */
288
+ embeddedContext = configuration => {
289
+ return configuration.context ? normalizeWireContext(configuration.context) : {
290
+ targetingKey: '',
291
+ attributes: {}
292
+ };
293
+ };
294
+
295
+ /** Record an error status + message, clear the servable cache, and return the result. */
296
+ enterError = (errorCode, errorMessage) => {
297
+ this.flagsCache = new Map();
298
+ this.configurationStatus = 'error';
299
+ this.configurationError = {
300
+ errorCode,
301
+ errorMessage
302
+ };
303
+ InternalLog.log(errorMessage, SdkVerbosity.WARN);
304
+ return {
305
+ status: 'error',
306
+ errorCode
307
+ };
308
+ };
56
309
  track = (flag, context) => {
57
310
  // A non-blocking call; don't await this.
58
311
  this.nativeFlags.trackEvaluation(this.clientName, flag.key, flag, context.targetingKey, context.attributes ?? {}).catch(error => {
@@ -62,6 +315,18 @@ export class FlagsClient {
62
315
  });
63
316
  };
64
317
  getDetails = (key, defaultValue, type) => {
318
+ // An offline configuration that cannot be served against the active context surfaces the
319
+ // precise error code (INVALID_CONTEXT / GENERAL / PROVIDER_NOT_READY) with the coded
320
+ // default. The OpenFeature provider maps this to a PROVIDER_ERROR / ERROR state.
321
+ if (this.configurationStatus === 'error' && this.configurationError) {
322
+ return {
323
+ key,
324
+ value: defaultValue,
325
+ reason: 'ERROR',
326
+ errorCode: this.configurationError.errorCode,
327
+ errorMessage: this.configurationError.errorMessage
328
+ };
329
+ }
65
330
  if (!this.evaluationContext) {
66
331
  return {
67
332
  key,
@@ -73,7 +338,7 @@ export class FlagsClient {
73
338
  }
74
339
 
75
340
  // Retrieve the flag from the cache.
76
- const flag = this.flagsCache[key];
341
+ const flag = this.flagsCache.get(key);
77
342
  if (!flag) {
78
343
  return {
79
344
  key,
@@ -1 +1 @@
1
- {"version":3,"names":["InternalLog","SdkVerbosity","processEvaluationContext","FlagsClient","nativeFlags","require","default","evaluationContext","undefined","flagsCache","constructor","clientName","setEvaluationContext","context","processedContext","result","targetingKey","attributes","error","Error","log","message","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"],"sourceRoot":"../../../src","sources":["flags/FlagsClient.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,SAASA,WAAW,QAAQ,gBAAgB;AAC5C,SAASC,YAAY,QAAQ,8BAA8B;AAG3D,SAASC,wBAAwB,QAAQ,YAAY;AAIrD,OAAO,MAAMC,WAAW,CAAC;EACrB;EACQC,WAAW,GAAsBC,OAAO,CAAC,wBAAwB,CAAC,CACrEC,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,GAAGZ,wBAAwB,CAACW,OAAO,CAAC;IAE1D,IAAI;MACA,MAAME,MAAM,GAAG,MAAM,IAAI,CAACX,WAAW,CAACQ,oBAAoB,CACtD,IAAI,CAACD,UAAU,EACfG,gBAAgB,CAAC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,GAAGA,CACfjB,GAAW,EACXG,YAAe,KACE;IACjB,OAAO,IAAI,CAACD,UAAU,CAACF,GAAG,EAAEG,YAAY,EAAE,QAAQ,CAAC;EACvD,CAAC;;EAED;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACIe,eAAe,GAAGA,CAAClB,GAAW,EAAEG,YAAqB,KAAc;IAC/D,OAAO,IAAI,CAACW,iBAAiB,CAACd,GAAG,EAAEG,YAAY,CAAC,CAACE,KAAK;EAC1D,CAAC;;EAED;AACJ;AACA;AACA;AACA;AACA;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","ignoreList":[]}
1
+ {"version":3,"names":["InternalLog","SdkVerbosity","contextMatchesConfiguration","decodePrecomputedFlags","normalizeWireContext","processEvaluationContext","FlagsClient","nativeFlags","require","default","externalContext","undefined","evaluationContext","flagsCache","Map","loadedConfiguration","kind","configurationStatus","configurationError","constructor","clientName","setEvaluationContext","context","processedContext","log","WARN","result","targetingKey","attributes","Object","entries","error","Error","message","setEvaluationContextWithoutFetching","reconcile","resetEvaluationContextWithoutFetching","setConfiguration","configuration","loadConfiguration","precomputed","errorCode","flags","response","loaded","enterError","embeddedContext","status","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"],"sourceRoot":"../../../src","sources":["flags/FlagsClient.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,SAASA,WAAW,QAAQ,gBAAgB;AAC5C,SAASC,YAAY,QAAQ,8BAA8B;AAG3D;AACA;AACA,SAASC,2BAA2B,QAAQ,yBAAyB;AACrE,SAASC,sBAAsB,EAAEC,oBAAoB,QAAQ,iBAAiB;AAK9E,SAASC,wBAAwB,QAAQ,YAAY;;AAIrD;AACA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA,OAAO,MAAMC,WAAW,CAAC;EACrB;EACQC,WAAW,GAAsBC,OAAO,CAAC,wBAAwB,CAAC,CACrEC,OAAO;EAIZ;EACA;EACA;EACA;EACA;EACQC,eAAe,GAAkCC,SAAS;;EAElE;EACA;EACQC,iBAAiB,GAAkCD,SAAS;;EAEpE;EACA;EACA;EACA;EACA;EACQE,UAAU,GAAgC,IAAIC,GAAG,CAAC,CAAC;;EAE3D;EACQC,mBAAmB,GAA6B;IAAEC,IAAI,EAAE;EAAO,CAAC;;EAExE;EACA;EACQC,mBAAmB,GAA+B,MAAM;EAExDC,kBAAkB,GAERP,SAAS;EAE3BQ,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,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B,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,CAAsBpB,GAAW,EAAEG,YAAe,KAAQ;IACvE,OAAO,IAAI,CAACa,gBAAgB,CAAChB,GAAG,EAAEG,YAAY,CAAC,CAACE,KAAK;EACzD,CAAC;AACL","ignoreList":[]}
@@ -0,0 +1,62 @@
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
+ import { processEvaluationContext } from '../internal';
8
+ /**
9
+ * Normalize a wire (OpenFeature-flat) evaluation context into the SDK's internal
10
+ * `{ targetingKey, attributes }` shape, applying the **same** processing the active
11
+ * context went through (`processEvaluationContext`) so the two are comparable — the
12
+ * flat wire shape and the internal shape are otherwise never equal.
13
+ */
14
+ export const normalizeWireContext = wireContext => {
15
+ const {
16
+ targetingKey,
17
+ ...attributes
18
+ } = wireContext;
19
+ return processEvaluationContext({
20
+ // The wire is untrusted, so a non-string targetingKey is treated as absent.
21
+ targetingKey: typeof targetingKey === 'string' ? targetingKey : '',
22
+ // `processEvaluationContext` drops non-primitive attributes; casting here mirrors
23
+ // how the active context's attributes are typed before that same processing.
24
+ attributes: attributes
25
+ });
26
+ };
27
+
28
+ /**
29
+ * Whether a precomputed configuration's embedded context matches the active evaluation
30
+ * context.
31
+ *
32
+ * - A configuration with **no** embedded context is context-agnostic and matches any
33
+ * active context.
34
+ * - Otherwise the embedded context must match the active context exactly (after
35
+ * normalizing both through the same processing).
36
+ */
37
+ export const contextMatchesConfiguration = (wireContext, activeContext) => {
38
+ if (!wireContext) {
39
+ return true;
40
+ }
41
+ return contextsEqual(normalizeWireContext(wireContext), activeContext);
42
+ };
43
+ const contextsEqual = (a, b) => {
44
+ if (a.targetingKey !== b.targetingKey) {
45
+ return false;
46
+ }
47
+ return attributesEqual(a.attributes ?? {}, b.attributes ?? {});
48
+ };
49
+
50
+ /**
51
+ * Compare two attribute maps. After `processEvaluationContext`, attribute values are
52
+ * primitives, so a key-set + strict-value comparison is sufficient.
53
+ */
54
+ const attributesEqual = (a, b) => {
55
+ const aKeys = Object.keys(a);
56
+ const bKeys = Object.keys(b);
57
+ if (aKeys.length !== bKeys.length) {
58
+ return false;
59
+ }
60
+ return aKeys.every(key => a[key] === b[key]);
61
+ };
62
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["processEvaluationContext","normalizeWireContext","wireContext","targetingKey","attributes","contextMatchesConfiguration","activeContext","contextsEqual","a","b","attributesEqual","aKeys","Object","keys","bKeys","length","every","key"],"sourceRoot":"../../../../src","sources":["flags/configuration/context.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,SAASA,wBAAwB,QAAQ,aAAa;AAKtD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,oBAAoB,GAC7BC,WAAkC,IACd;EACpB,MAAM;IAAEC,YAAY;IAAE,GAAGC;EAAW,CAAC,GAAGF,WAAW;EAEnD,OAAOF,wBAAwB,CAAC;IAC5B;IACAG,YAAY,EAAE,OAAOA,YAAY,KAAK,QAAQ,GAAGA,YAAY,GAAG,EAAE;IAClE;IACA;IACAC,UAAU,EAAEA;EAChB,CAAC,CAAC;AACN,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,2BAA2B,GAAGA,CACvCH,WAA8C,EAC9CI,aAAgC,KACtB;EACV,IAAI,CAACJ,WAAW,EAAE;IACd,OAAO,IAAI;EACf;EAEA,OAAOK,aAAa,CAACN,oBAAoB,CAACC,WAAW,CAAC,EAAEI,aAAa,CAAC;AAC1E,CAAC;AAED,MAAMC,aAAa,GAAGA,CAACC,CAAoB,EAAEC,CAAoB,KAAc;EAC3E,IAAID,CAAC,CAACL,YAAY,KAAKM,CAAC,CAACN,YAAY,EAAE;IACnC,OAAO,KAAK;EAChB;EAEA,OAAOO,eAAe,CAACF,CAAC,CAACJ,UAAU,IAAI,CAAC,CAAC,EAAEK,CAAC,CAACL,UAAU,IAAI,CAAC,CAAC,CAAC;AAClE,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAMM,eAAe,GAAGA,CACpBF,CAAiC,EACjCC,CAAiC,KACvB;EACV,MAAME,KAAK,GAAGC,MAAM,CAACC,IAAI,CAACL,CAAC,CAAC;EAC5B,MAAMM,KAAK,GAAGF,MAAM,CAACC,IAAI,CAACJ,CAAC,CAAC;EAE5B,IAAIE,KAAK,CAACI,MAAM,KAAKD,KAAK,CAACC,MAAM,EAAE;IAC/B,OAAO,KAAK;EAChB;EAEA,OAAOJ,KAAK,CAACK,KAAK,CAACC,GAAG,IAAIT,CAAC,CAACS,GAAG,CAAC,KAAKR,CAAC,CAACQ,GAAG,CAAC,CAAC;AAChD,CAAC","ignoreList":[]}
@@ -0,0 +1,18 @@
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
+ // Module boundary for portable-configuration handling. The public entry point
8
+ // (`packages/core/src/index.tsx`) re-exports only the customer-facing surface —
9
+ // `configurationFromString`/`configurationToString` and the `ParsedFlagsConfiguration` type;
10
+ // the decoder and other helpers stay internal to this boundary. Keeping the surface contained
11
+ // here makes a future "port -> depend on a shared core" swap easier.
12
+
13
+ export { configurationFromString, configurationToString } from './wire';
14
+ export { decodePrecomputedFlags, UnsupportedConfigurationError } from './precomputed';
15
+ // `contextMatchesConfiguration` is intentionally NOT re-exported — it is an internal
16
+ // helper consumed directly by `FlagsClient` (see its import from `./configuration/context`).
17
+ export { normalizeWireContext } from './context';
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["configurationFromString","configurationToString","decodePrecomputedFlags","UnsupportedConfigurationError","normalizeWireContext"],"sourceRoot":"../../../../src","sources":["flags/configuration/index.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA,SAASA,uBAAuB,EAAEC,qBAAqB,QAAQ,QAAQ;AACvE,SACIC,sBAAsB,EACtBC,6BAA6B,QAC1B,eAAe;AACtB;AACA;AACA,SAASC,oBAAoB,QAAQ,WAAW","ignoreList":[]}
@@ -0,0 +1,165 @@
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
+ import { InternalLog } from '../../InternalLog';
8
+ import { SdkVerbosity } from '../../config/types/SdkVerbosity';
9
+ import { SUPPORTED_VARIATION_TYPES } from './types';
10
+
11
+ /**
12
+ * Thrown when a configuration cannot be supported by this SDK (e.g. an obfuscated
13
+ * precomputed payload). Callers translate this into a provider error state rather
14
+ * than silently serving wrong data.
15
+ */
16
+ export class UnsupportedConfigurationError extends Error {
17
+ constructor(message) {
18
+ super(message);
19
+ this.name = 'UnsupportedConfigurationError';
20
+ }
21
+ }
22
+
23
+ /**
24
+ * Decode a precomputed CDN response into the `FlagCacheEntry` map that `FlagsClient`
25
+ * caches and evaluates against — the same shape the native CDN fetch returns today.
26
+ *
27
+ * The mapping is ~1:1. Two transforms are applied per flag:
28
+ * - `value` is the typed `variationValue` as-is (`integer`/`float` are JS `number`s);
29
+ * - a string `variationValue` is derived (JSON for objects, `"true"/"false"` for
30
+ * booleans, `String(...)` otherwise) because native Android exposure tracking
31
+ * rebuilds the flag from the string form.
32
+ *
33
+ * @throws {UnsupportedConfigurationError} if the response is obfuscated, or its envelope is
34
+ * structurally malformed (missing/non-object `data.attributes.flags`).
35
+ */
36
+ export const decodePrecomputedFlags = response => {
37
+ const attributes = response?.data?.attributes;
38
+
39
+ // `obfuscated` is not part of flagging-core's response type, but the CDN payload
40
+ // carries it. Read it defensively so obfuscated payloads are still rejected:
41
+ // de-hashing keys / decoding values is not implemented here, so fail predictably
42
+ // instead of mis-mapping hashed keys.
43
+ if (attributes?.obfuscated) {
44
+ throw new UnsupportedConfigurationError('Obfuscated precomputed configurations are not supported.');
45
+ }
46
+
47
+ // Validate the response envelope before trusting it. An untrusted wire can be JSON-valid yet
48
+ // structurally malformed (a null/non-object envelope, or a `flags` that is null or an array).
49
+ // Fail predictably so the caller classifies it as an error instead of silently decoding it to
50
+ // an empty — but "ready" — configuration. A genuinely empty `flags: {}` is still accepted.
51
+ const flags = attributes?.flags;
52
+ if (!isFlagsMap(flags)) {
53
+ throw new UnsupportedConfigurationError("Malformed precomputed configuration: 'data.attributes.flags' must be an object.");
54
+ }
55
+
56
+ // A Map (returned as-is) so a pathological flag keyed "__proto__" is stored as data
57
+ // and later looked up via `.get()` — never hitting the `Object.prototype` "__proto__"
58
+ // setter (on write) or the prototype chain (on read) the way a plain object would.
59
+ const cache = new Map();
60
+ for (const [key, flag] of Object.entries(flags)) {
61
+ const entry = toFlagCacheEntry(key, flag);
62
+ if (entry) {
63
+ cache.set(key, entry);
64
+ }
65
+ }
66
+ return cache;
67
+ };
68
+
69
+ // A well-formed flags container is a plain object (a possibly-empty map of flag key -> flag).
70
+ // `null`, arrays, and primitives are malformed envelopes.
71
+ const isFlagsMap = value => typeof value === 'object' && value !== null && !Array.isArray(value);
72
+ const toFlagCacheEntry = (key, flag) => {
73
+ // A malformed payload can carry a non-object flag (e.g. `flags: { "k": null }`).
74
+ // Skip the bad entry with a warning instead of throwing and aborting decoding of
75
+ // the whole configuration.
76
+ if (typeof flag !== 'object' || flag === null) {
77
+ InternalLog.log(`Flag "${key}" is not an object. Omitting it from the configuration.`, SdkVerbosity.WARN);
78
+ return null;
79
+ }
80
+ const {
81
+ variationType,
82
+ variationValue,
83
+ variationKey,
84
+ allocationKey,
85
+ reason,
86
+ doLog,
87
+ extraLogging
88
+ } = flag;
89
+ if (typeof variationType !== 'string' || !SUPPORTED_VARIATION_TYPES.has(variationType)) {
90
+ InternalLog.log(`Flag "${key}" has an unsupported variation type "${String(variationType)}". Omitting it from the configuration.`, SdkVerbosity.WARN);
91
+ return null;
92
+ }
93
+ if (!valueMatchesVariationType(variationValue, variationType)) {
94
+ InternalLog.log(`Flag "${key}" value does not match its variation type "${variationType}". Omitting it from the configuration.`, SdkVerbosity.WARN);
95
+ return null;
96
+ }
97
+
98
+ // The remaining fields feed evaluation and native exposure tracking. A corrupt
99
+ // payload could carry wrong types here, so validate before forwarding them.
100
+ if (typeof allocationKey !== 'string' || typeof variationKey !== 'string' || typeof reason !== 'string' || typeof doLog !== 'boolean' ||
101
+ // `extraLogging` must be a key/value map; an array (also `typeof === 'object'`) would
102
+ // break native exposure tracking that expects an object, so treat it as malformed.
103
+ extraLogging !== undefined && (typeof extraLogging !== 'object' || extraLogging === null || Array.isArray(extraLogging))) {
104
+ InternalLog.log(`Flag "${key}" has malformed metadata. Omitting it from the configuration.`, SdkVerbosity.WARN);
105
+ return null;
106
+ }
107
+
108
+ // `serialId` is intentionally not propagated: `FlagCacheEntry` has no slot for it
109
+ // and the native CDN-fetched snapshot omits it too, so dropping it keeps
110
+ // offline/online parity.
111
+ return {
112
+ key,
113
+ value: variationValue,
114
+ allocationKey,
115
+ variationKey,
116
+ variationType,
117
+ variationValue: stringifyValue(variationValue),
118
+ reason,
119
+ doLog,
120
+ extraLogging: extraLogging ?? {}
121
+ };
122
+ };
123
+ const valueMatchesVariationType = (value, variationType) => {
124
+ switch (variationType) {
125
+ case 'boolean':
126
+ return typeof value === 'boolean';
127
+ case 'string':
128
+ return typeof value === 'string';
129
+ case 'number':
130
+ case 'float':
131
+ // Reject NaN/Infinity: native parsers can't round-trip them.
132
+ return typeof value === 'number' && Number.isFinite(value);
133
+ case 'integer':
134
+ // A fractional value under an integer flag would be truncated/mis-parsed
135
+ // natively, so require a whole number.
136
+ return Number.isInteger(value);
137
+ case 'object':
138
+ // The `object` variation type carries JSON. ffe-service enforces a top-level object at
139
+ // the API layer, so in practice the value is an object; that is not a storage
140
+ // constraint, so a malformed or hand-crafted payload could still carry any JSON value
141
+ // here. Accept it at decode (and stringify it for native tracking); a non-object value
142
+ // is then served the coded default with TYPE_MISMATCH at evaluation — see
143
+ // `FlagsClient.getObjectDetails`. So this only affects malformed wires, never the
144
+ // guaranteed-object values from a real Datadog config.
145
+ return true;
146
+ default:
147
+ return false;
148
+ }
149
+ };
150
+
151
+ /**
152
+ * Derive the string form of a flag value expected by native Android exposure tracking.
153
+ * Objects/arrays are JSON-encoded; everything else uses `String(...)`, which yields
154
+ * lowercase `"true"/"false"` for booleans.
155
+ */
156
+ const stringifyValue = value => {
157
+ if (value === null) {
158
+ return 'null';
159
+ }
160
+ if (typeof value === 'object') {
161
+ return JSON.stringify(value);
162
+ }
163
+ return String(value);
164
+ };
165
+ //# sourceMappingURL=precomputed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["InternalLog","SdkVerbosity","SUPPORTED_VARIATION_TYPES","UnsupportedConfigurationError","Error","constructor","message","name","decodePrecomputedFlags","response","attributes","data","obfuscated","flags","isFlagsMap","cache","Map","key","flag","Object","entries","entry","toFlagCacheEntry","set","value","Array","isArray","log","WARN","variationType","variationValue","variationKey","allocationKey","reason","doLog","extraLogging","has","String","valueMatchesVariationType","undefined","stringifyValue","Number","isFinite","isInteger","JSON","stringify"],"sourceRoot":"../../../../src","sources":["flags/configuration/precomputed.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,SAASA,WAAW,QAAQ,mBAAmB;AAC/C,SAASC,YAAY,QAAQ,iCAAiC;AAO9D,SAASC,yBAAyB,QAAQ,SAAS;;AAEnD;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,6BAA6B,SAASC,KAAK,CAAC;EACrDC,WAAW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Y,EAAEA,YAAY,IAAI,CAAC;EACnC,CAAC;AACL,CAAC;AAED,MAAMG,yBAAyB,GAAGA,CAC9Bd,KAAc,EACdK,aAAqB,KACX;EACV,QAAQA,aAAa;IACjB,KAAK,SAAS;MACV,OAAO,OAAOL,KAAK,KAAK,SAAS;IACrC,KAAK,QAAQ;MACT,OAAO,OAAOA,KAAK,KAAK,QAAQ;IACpC,KAAK,QAAQ;IACb,KAAK,OAAO;MACR;MACA,OAAO,OAAOA,KAAK,KAAK,QAAQ,IAAIiB,MAAM,CAACC,QAAQ,CAAClB,KAAK,CAAC;IAC9D,KAAK,SAAS;MACV;MACA;MACA,OAAOiB,MAAM,CAACE,SAAS,CAACnB,KAAK,CAAC;IAClC,KAAK,QAAQ;MACT;MACA;MACA;MACA;MACA;MACA;MACA;MACA,OAAO,IAAI;IACf;MACI,OAAO,KAAK;EACpB;AACJ,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,MAAMgB,cAAc,GAAIhB,KAAc,IAAa;EAC/C,IAAIA,KAAK,KAAK,IAAI,EAAE;IAChB,OAAO,MAAM;EACjB;EACA,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAC3B,OAAOoB,IAAI,CAACC,SAAS,CAACrB,KAAK,CAAC;EAChC;EACA,OAAOa,MAAM,CAACb,KAAK,CAAC;AACxB,CAAC","ignoreList":[]}
@@ -0,0 +1,27 @@
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
+ /**
8
+ * The flag `variationType`s the decoder accepts. `@datadog/flagging-core` models the
9
+ * type as OpenFeature's `boolean | string | number | object`, and the CDN confirms only
10
+ * those are emitted. `integer`/`float` are kept here defensively — the decoder validates
11
+ * untrusted payloads and treats both as JavaScript `number`s.
12
+ */
13
+ export const SUPPORTED_VARIATION_TYPES = new Set(['boolean', 'string', 'number', 'integer', 'float', 'object']);
14
+
15
+ /**
16
+ * The context an evaluation is performed against, as it appears **on the wire**.
17
+ *
18
+ * This is the OpenFeature-shaped context: a flat object with an optional
19
+ * `targetingKey` and arbitrary sibling attributes. It is intentionally different
20
+ * from the SDK's internal `EvaluationContext` (`{ targetingKey, attributes }`);
21
+ * callers must normalize before comparing the two.
22
+ */
23
+
24
+ // The wire/precomputed types are re-exported from `@datadog/flagging-core` so this SDK
25
+ // shares the canonical shapes instead of maintaining its own copies. Local names are
26
+ // kept so the rest of the SDK is insulated from the upstream naming.
27
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["SUPPORTED_VARIATION_TYPES","Set"],"sourceRoot":"../../../../src","sources":["flags/configuration/types.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,yBAA8C,GAAG,IAAIC,GAAG,CAAC,CAClE,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,OAAO,EACP,QAAQ,CACX,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA","ignoreList":[]}