@datadog/mobile-react-native 3.5.3 → 3.6.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 (206) hide show
  1. package/README.md +10 -0
  2. package/android/build.gradle +22 -8
  3. package/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt +23 -4
  4. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +3 -2
  5. package/android/src/main/kotlin/com/datadog/reactnative/HeatmapActionHandler.kt +121 -0
  6. package/android/src/main/kotlin/com/datadog/reactnative/HeatmapTouchResolver.kt +108 -0
  7. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  8. package/android/src/newarch/kotlin/com/datadog/reactnative/DdRum.kt +19 -2
  9. package/android/src/newarch/kotlin/com/datadog/reactnative/DdSdk.kt +1 -1
  10. package/android/src/oldarch/kotlin/com/datadog/reactnative/HeatmapViewResolverFactory.kt +38 -0
  11. package/android/src/oldarch65/kotlin/com/datadog/reactnative/HeatmapViewResolverFactory.kt +20 -0
  12. package/android/src/{oldarch → oldarchCommon}/kotlin/com/datadog/reactnative/DdRum.kt +15 -2
  13. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +482 -0
  14. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +94 -49
  15. package/android/src/test/kotlin/com/datadog/reactnative/HeatmapTouchResolverTest.kt +529 -0
  16. package/datadog-configuration.schema.json +4 -0
  17. package/ios/Sources/DdSdk.mm +2 -0
  18. package/ios/Sources/DdSdkImplementation.swift +0 -1
  19. package/ios/Sources/SdkVersion.swift +1 -1
  20. package/lib/commonjs/DdSdkReactNative.js +3 -1
  21. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  22. package/lib/commonjs/config/FileBasedConfiguration.js +1 -0
  23. package/lib/commonjs/config/FileBasedConfiguration.js.map +1 -1
  24. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js +1 -0
  25. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  26. package/lib/commonjs/config/features/RumConfiguration.js +4 -0
  27. package/lib/commonjs/config/features/RumConfiguration.js.map +1 -1
  28. package/lib/commonjs/flags/FlagsClient.js +268 -3
  29. package/lib/commonjs/flags/FlagsClient.js.map +1 -1
  30. package/lib/commonjs/flags/configuration/context.js +70 -0
  31. package/lib/commonjs/flags/configuration/context.js.map +1 -0
  32. package/lib/commonjs/flags/configuration/index.js +39 -0
  33. package/lib/commonjs/flags/configuration/index.js.map +1 -0
  34. package/lib/commonjs/flags/configuration/precomputed.js +172 -0
  35. package/lib/commonjs/flags/configuration/precomputed.js.map +1 -0
  36. package/lib/commonjs/flags/configuration/types.js +33 -0
  37. package/lib/commonjs/flags/configuration/types.js.map +1 -0
  38. package/lib/commonjs/flags/configuration/wire.js +19 -0
  39. package/lib/commonjs/flags/configuration/wire.js.map +1 -0
  40. package/lib/commonjs/flags/internal.js +7 -3
  41. package/lib/commonjs/flags/internal.js.map +1 -1
  42. package/lib/commonjs/index.js +13 -0
  43. package/lib/commonjs/index.js.map +1 -1
  44. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +27 -13
  45. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  46. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +270 -0
  47. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -0
  48. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +38 -72
  49. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  50. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.js +33 -0
  51. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.js.map +1 -0
  52. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +39 -0
  53. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -0
  54. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/ResourceReporter.js +4 -4
  55. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -0
  56. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/internalDevResourceBlocklist.js +0 -18
  57. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/internalDevResourceBlocklist.js.map +1 -0
  58. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.js +109 -0
  59. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.js.map +1 -0
  60. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/resourceTiming.js +0 -9
  61. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/resourceTiming.js.map +1 -0
  62. package/lib/commonjs/version.js +1 -1
  63. package/lib/module/DdSdkReactNative.js +3 -1
  64. package/lib/module/DdSdkReactNative.js.map +1 -1
  65. package/lib/module/config/FileBasedConfiguration.js +1 -0
  66. package/lib/module/config/FileBasedConfiguration.js.map +1 -1
  67. package/lib/module/config/async/AutoInstrumentationConfiguration.js +1 -0
  68. package/lib/module/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  69. package/lib/module/config/features/RumConfiguration.js +4 -0
  70. package/lib/module/config/features/RumConfiguration.js.map +1 -1
  71. package/lib/module/flags/FlagsClient.js +268 -3
  72. package/lib/module/flags/FlagsClient.js.map +1 -1
  73. package/lib/module/flags/configuration/context.js +62 -0
  74. package/lib/module/flags/configuration/context.js.map +1 -0
  75. package/lib/module/flags/configuration/index.js +18 -0
  76. package/lib/module/flags/configuration/index.js.map +1 -0
  77. package/lib/module/flags/configuration/precomputed.js +165 -0
  78. package/lib/module/flags/configuration/precomputed.js.map +1 -0
  79. package/lib/module/flags/configuration/types.js +27 -0
  80. package/lib/module/flags/configuration/types.js.map +1 -0
  81. package/lib/module/flags/configuration/wire.js +13 -0
  82. package/lib/module/flags/configuration/wire.js.map +1 -0
  83. package/lib/module/flags/internal.js +7 -3
  84. package/lib/module/flags/internal.js.map +1 -1
  85. package/lib/module/index.js +2 -1
  86. package/lib/module/index.js.map +1 -1
  87. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +27 -13
  88. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  89. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +263 -0
  90. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -0
  91. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +38 -72
  92. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  93. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.js +25 -0
  94. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.js.map +1 -0
  95. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +32 -0
  96. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -0
  97. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/ResourceReporter.js +4 -4
  98. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -0
  99. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/internalDevResourceBlocklist.js +0 -18
  100. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/internalDevResourceBlocklist.js.map +1 -0
  101. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.js +101 -0
  102. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.js.map +1 -0
  103. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/resourceTiming.js +0 -9
  104. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/resourceTiming.js.map +1 -0
  105. package/lib/module/version.js +1 -1
  106. package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
  107. package/lib/typescript/config/FileBasedConfiguration.d.ts.map +1 -1
  108. package/lib/typescript/config/FileBasedConfiguration.type.d.ts +1 -0
  109. package/lib/typescript/config/FileBasedConfiguration.type.d.ts.map +1 -1
  110. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts +2 -0
  111. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts.map +1 -1
  112. package/lib/typescript/config/features/RumConfiguration.d.ts +2 -0
  113. package/lib/typescript/config/features/RumConfiguration.d.ts.map +1 -1
  114. package/lib/typescript/config/features/RumConfiguration.type.d.ts +7 -0
  115. package/lib/typescript/config/features/RumConfiguration.type.d.ts.map +1 -1
  116. package/lib/typescript/flags/FlagsClient.d.ts +96 -0
  117. package/lib/typescript/flags/FlagsClient.d.ts.map +1 -1
  118. package/lib/typescript/flags/configuration/context.d.ts +20 -0
  119. package/lib/typescript/flags/configuration/context.d.ts.map +1 -0
  120. package/lib/typescript/flags/configuration/index.d.ts +5 -0
  121. package/lib/typescript/flags/configuration/index.d.ts.map +1 -0
  122. package/lib/typescript/flags/configuration/precomputed.d.ts +25 -0
  123. package/lib/typescript/flags/configuration/precomputed.d.ts.map +1 -0
  124. package/lib/typescript/flags/configuration/types.d.ts +24 -0
  125. package/lib/typescript/flags/configuration/types.d.ts.map +1 -0
  126. package/lib/typescript/flags/configuration/wire.d.ts +2 -0
  127. package/lib/typescript/flags/configuration/wire.d.ts.map +1 -0
  128. package/lib/typescript/flags/internal.d.ts.map +1 -1
  129. package/lib/typescript/flags/types.d.ts +1 -1
  130. package/lib/typescript/flags/types.d.ts.map +1 -1
  131. package/lib/typescript/index.d.ts +4 -2
  132. package/lib/typescript/index.d.ts.map +1 -1
  133. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +3 -2
  134. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts.map +1 -1
  135. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.d.ts +29 -0
  136. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.d.ts.map +1 -0
  137. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts +1 -1
  138. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
  139. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.d.ts +8 -0
  140. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.d.ts.map +1 -0
  141. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts +20 -0
  142. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts.map +1 -0
  143. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/ResourceReporter.d.ts +2 -2
  144. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.d.ts.map +1 -0
  145. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/internalDevResourceBlocklist.d.ts +3 -0
  146. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/internalDevResourceBlocklist.d.ts.map +1 -0
  147. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.d.ts +18 -0
  148. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.d.ts.map +1 -0
  149. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/resourceTiming.d.ts +0 -6
  150. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/resourceTiming.d.ts.map +1 -0
  151. package/lib/typescript/version.d.ts +1 -1
  152. package/package.json +12 -2
  153. package/src/DdSdkReactNative.tsx +5 -1
  154. package/src/__tests__/DdSdkReactNative.test.tsx +5 -2
  155. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +3 -0
  156. package/src/config/FileBasedConfiguration.ts +2 -0
  157. package/src/config/FileBasedConfiguration.type.ts +1 -0
  158. package/src/config/__tests__/FileBasedConfiguration.test.ts +3 -0
  159. package/src/config/__tests__/__fixtures__/configuration-all-fields.json +1 -0
  160. package/src/config/async/AutoInstrumentationConfiguration.ts +5 -0
  161. package/src/config/features/RumConfiguration.ts +4 -0
  162. package/src/config/features/RumConfiguration.type.ts +8 -0
  163. package/src/flags/FlagsClient.ts +305 -3
  164. package/src/flags/__tests__/FlagsClient.test.ts +596 -0
  165. package/src/flags/__tests__/internal.test.ts +45 -0
  166. package/src/flags/configuration/__tests__/context.test.ts +120 -0
  167. package/src/flags/configuration/__tests__/precomputed.test.ts +301 -0
  168. package/src/flags/configuration/__tests__/wire.test.ts +127 -0
  169. package/src/flags/configuration/context.ts +76 -0
  170. package/src/flags/configuration/index.ts +27 -0
  171. package/src/flags/configuration/precomputed.ts +215 -0
  172. package/src/flags/configuration/types.ts +47 -0
  173. package/src/flags/configuration/wire.ts +15 -0
  174. package/src/flags/internal.ts +6 -3
  175. package/src/flags/types.ts +3 -1
  176. package/src/index.tsx +8 -0
  177. package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +38 -13
  178. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +101 -0
  179. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.ts +316 -0
  180. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/__tests__/FetchProxy.test.ts +393 -0
  181. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/__tests__/ResourceReporter.test.ts +1 -1
  182. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/__tests__/internalDevResourceBlocklist.test.ts +1 -1
  183. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +49 -115
  184. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +1 -1
  185. package/src/rum/instrumentation/resourceTracking/requestProxy/common/FetchProxyState.ts +25 -0
  186. package/src/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.ts +54 -0
  187. package/src/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/ResourceReporter.ts +5 -5
  188. package/src/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/internalDevResourceBlocklist.ts +1 -17
  189. package/src/rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders.ts +106 -0
  190. package/src/rum/instrumentation/resourceTracking/requestProxy/{XHRProxy/DatadogRumResource → common}/resourceTiming.ts +0 -18
  191. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +1 -0
  192. package/src/version.ts +1 -1
  193. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +0 -1
  194. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/internalDevResourceBlocklist.js.map +0 -1
  195. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/resourceTiming.js.map +0 -1
  196. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +0 -1
  197. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/internalDevResourceBlocklist.js.map +0 -1
  198. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/resourceTiming.js.map +0 -1
  199. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.d.ts.map +0 -1
  200. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/internalDevResourceBlocklist.d.ts +0 -7
  201. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/internalDevResourceBlocklist.d.ts.map +0 -1
  202. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/resourceTiming.d.ts.map +0 -1
  203. /package/android/src/{oldarch → oldarchCommon}/kotlin/com/datadog/reactnative/DdFlags.kt +0 -0
  204. /package/android/src/{oldarch → oldarchCommon}/kotlin/com/datadog/reactnative/DdLogs.kt +0 -0
  205. /package/android/src/{oldarch → oldarchCommon}/kotlin/com/datadog/reactnative/DdSdk.kt +0 -0
  206. /package/android/src/{oldarch → oldarchCommon}/kotlin/com/datadog/reactnative/DdTrace.kt +0 -0
@@ -0,0 +1,215 @@
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 type { FlagCacheEntry } from '../internal';
10
+
11
+ import type {
12
+ PrecomputedConfigurationResponse,
13
+ PrecomputedFlag
14
+ } from './types';
15
+ import { SUPPORTED_VARIATION_TYPES } from './types';
16
+
17
+ /**
18
+ * Thrown when a configuration cannot be supported by this SDK (e.g. an obfuscated
19
+ * precomputed payload). Callers translate this into a provider error state rather
20
+ * than silently serving wrong data.
21
+ */
22
+ export class UnsupportedConfigurationError extends Error {
23
+ constructor(message: string) {
24
+ super(message);
25
+ this.name = 'UnsupportedConfigurationError';
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Decode a precomputed CDN response into the `FlagCacheEntry` map that `FlagsClient`
31
+ * caches and evaluates against — the same shape the native CDN fetch returns today.
32
+ *
33
+ * The mapping is ~1:1. Two transforms are applied per flag:
34
+ * - `value` is the typed `variationValue` as-is (`integer`/`float` are JS `number`s);
35
+ * - a string `variationValue` is derived (JSON for objects, `"true"/"false"` for
36
+ * booleans, `String(...)` otherwise) because native Android exposure tracking
37
+ * rebuilds the flag from the string form.
38
+ *
39
+ * @throws {UnsupportedConfigurationError} if the response is obfuscated, or its envelope is
40
+ * structurally malformed (missing/non-object `data.attributes.flags`).
41
+ */
42
+ export const decodePrecomputedFlags = (
43
+ response: PrecomputedConfigurationResponse
44
+ ): Map<string, FlagCacheEntry> => {
45
+ const attributes = response?.data?.attributes;
46
+
47
+ // `obfuscated` is not part of flagging-core's response type, but the CDN payload
48
+ // carries it. Read it defensively so obfuscated payloads are still rejected:
49
+ // de-hashing keys / decoding values is not implemented here, so fail predictably
50
+ // instead of mis-mapping hashed keys.
51
+ if ((attributes as { obfuscated?: boolean } | undefined)?.obfuscated) {
52
+ throw new UnsupportedConfigurationError(
53
+ 'Obfuscated precomputed configurations are not supported.'
54
+ );
55
+ }
56
+
57
+ // Validate the response envelope before trusting it. An untrusted wire can be JSON-valid yet
58
+ // structurally malformed (a null/non-object envelope, or a `flags` that is null or an array).
59
+ // Fail predictably so the caller classifies it as an error instead of silently decoding it to
60
+ // an empty — but "ready" — configuration. A genuinely empty `flags: {}` is still accepted.
61
+ const flags = attributes?.flags;
62
+ if (!isFlagsMap(flags)) {
63
+ throw new UnsupportedConfigurationError(
64
+ "Malformed precomputed configuration: 'data.attributes.flags' must be an object."
65
+ );
66
+ }
67
+
68
+ // A Map (returned as-is) so a pathological flag keyed "__proto__" is stored as data
69
+ // and later looked up via `.get()` — never hitting the `Object.prototype` "__proto__"
70
+ // setter (on write) or the prototype chain (on read) the way a plain object would.
71
+ const cache = new Map<string, FlagCacheEntry>();
72
+
73
+ for (const [key, flag] of Object.entries(flags)) {
74
+ const entry = toFlagCacheEntry(key, flag);
75
+ if (entry) {
76
+ cache.set(key, entry);
77
+ }
78
+ }
79
+
80
+ return cache;
81
+ };
82
+
83
+ // A well-formed flags container is a plain object (a possibly-empty map of flag key -> flag).
84
+ // `null`, arrays, and primitives are malformed envelopes.
85
+ const isFlagsMap = (value: unknown): value is Record<string, unknown> =>
86
+ typeof value === 'object' && value !== null && !Array.isArray(value);
87
+
88
+ const toFlagCacheEntry = (
89
+ key: string,
90
+ flag: unknown
91
+ ): FlagCacheEntry | null => {
92
+ // A malformed payload can carry a non-object flag (e.g. `flags: { "k": null }`).
93
+ // Skip the bad entry with a warning instead of throwing and aborting decoding of
94
+ // the whole configuration.
95
+ if (typeof flag !== 'object' || flag === null) {
96
+ InternalLog.log(
97
+ `Flag "${key}" is not an object. Omitting it from the configuration.`,
98
+ SdkVerbosity.WARN
99
+ );
100
+ return null;
101
+ }
102
+
103
+ const {
104
+ variationType,
105
+ variationValue,
106
+ variationKey,
107
+ allocationKey,
108
+ reason,
109
+ doLog,
110
+ extraLogging
111
+ } = flag as Partial<PrecomputedFlag>;
112
+
113
+ if (
114
+ typeof variationType !== 'string' ||
115
+ !SUPPORTED_VARIATION_TYPES.has(variationType)
116
+ ) {
117
+ InternalLog.log(
118
+ `Flag "${key}" has an unsupported variation type "${String(
119
+ variationType
120
+ )}". Omitting it from the configuration.`,
121
+ SdkVerbosity.WARN
122
+ );
123
+ return null;
124
+ }
125
+
126
+ if (!valueMatchesVariationType(variationValue, variationType)) {
127
+ InternalLog.log(
128
+ `Flag "${key}" value does not match its variation type "${variationType}". Omitting it from the configuration.`,
129
+ SdkVerbosity.WARN
130
+ );
131
+ return null;
132
+ }
133
+
134
+ // The remaining fields feed evaluation and native exposure tracking. A corrupt
135
+ // payload could carry wrong types here, so validate before forwarding them.
136
+ if (
137
+ typeof allocationKey !== 'string' ||
138
+ typeof variationKey !== 'string' ||
139
+ typeof reason !== 'string' ||
140
+ typeof doLog !== 'boolean' ||
141
+ // `extraLogging` must be a key/value map; an array (also `typeof === 'object'`) would
142
+ // break native exposure tracking that expects an object, so treat it as malformed.
143
+ (extraLogging !== undefined &&
144
+ (typeof extraLogging !== 'object' ||
145
+ extraLogging === null ||
146
+ Array.isArray(extraLogging)))
147
+ ) {
148
+ InternalLog.log(
149
+ `Flag "${key}" has malformed metadata. Omitting it from the configuration.`,
150
+ SdkVerbosity.WARN
151
+ );
152
+ return null;
153
+ }
154
+
155
+ // `serialId` is intentionally not propagated: `FlagCacheEntry` has no slot for it
156
+ // and the native CDN-fetched snapshot omits it too, so dropping it keeps
157
+ // offline/online parity.
158
+ return {
159
+ key,
160
+ value: variationValue,
161
+ allocationKey,
162
+ variationKey,
163
+ variationType,
164
+ variationValue: stringifyValue(variationValue),
165
+ reason,
166
+ doLog,
167
+ extraLogging: extraLogging ?? {}
168
+ };
169
+ };
170
+
171
+ const valueMatchesVariationType = (
172
+ value: unknown,
173
+ variationType: string
174
+ ): boolean => {
175
+ switch (variationType) {
176
+ case 'boolean':
177
+ return typeof value === 'boolean';
178
+ case 'string':
179
+ return typeof value === 'string';
180
+ case 'number':
181
+ case 'float':
182
+ // Reject NaN/Infinity: native parsers can't round-trip them.
183
+ return typeof value === 'number' && Number.isFinite(value);
184
+ case 'integer':
185
+ // A fractional value under an integer flag would be truncated/mis-parsed
186
+ // natively, so require a whole number.
187
+ return Number.isInteger(value);
188
+ case 'object':
189
+ // The `object` variation type carries JSON. ffe-service enforces a top-level object at
190
+ // the API layer, so in practice the value is an object; that is not a storage
191
+ // constraint, so a malformed or hand-crafted payload could still carry any JSON value
192
+ // here. Accept it at decode (and stringify it for native tracking); a non-object value
193
+ // is then served the coded default with TYPE_MISMATCH at evaluation — see
194
+ // `FlagsClient.getObjectDetails`. So this only affects malformed wires, never the
195
+ // guaranteed-object values from a real Datadog config.
196
+ return true;
197
+ default:
198
+ return false;
199
+ }
200
+ };
201
+
202
+ /**
203
+ * Derive the string form of a flag value expected by native Android exposure tracking.
204
+ * Objects/arrays are JSON-encoded; everything else uses `String(...)`, which yields
205
+ * lowercase `"true"/"false"` for booleans.
206
+ */
207
+ const stringifyValue = (value: unknown): string => {
208
+ if (value === null) {
209
+ return 'null';
210
+ }
211
+ if (typeof value === 'object') {
212
+ return JSON.stringify(value);
213
+ }
214
+ return String(value);
215
+ };
@@ -0,0 +1,47 @@
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 type {
8
+ FlagsConfiguration,
9
+ PrecomputedConfiguration,
10
+ PrecomputedConfigurationResponse as FlaggingCorePrecomputedConfigurationResponse,
11
+ PrecomputedFlag as FlaggingCorePrecomputedFlag
12
+ } from '@datadog/flagging-core';
13
+
14
+ /**
15
+ * The flag `variationType`s the decoder accepts. `@datadog/flagging-core` models the
16
+ * type as OpenFeature's `boolean | string | number | object`, and the CDN confirms only
17
+ * those are emitted. `integer`/`float` are kept here defensively — the decoder validates
18
+ * untrusted payloads and treats both as JavaScript `number`s.
19
+ */
20
+ export const SUPPORTED_VARIATION_TYPES: ReadonlySet<string> = new Set([
21
+ 'boolean',
22
+ 'string',
23
+ 'number',
24
+ 'integer',
25
+ 'float',
26
+ 'object'
27
+ ]);
28
+
29
+ /**
30
+ * The context an evaluation is performed against, as it appears **on the wire**.
31
+ *
32
+ * This is the OpenFeature-shaped context: a flat object with an optional
33
+ * `targetingKey` and arbitrary sibling attributes. It is intentionally different
34
+ * from the SDK's internal `EvaluationContext` (`{ targetingKey, attributes }`);
35
+ * callers must normalize before comparing the two.
36
+ */
37
+ export type WireEvaluationContext = {
38
+ targetingKey?: string;
39
+ } & Record<string, unknown>;
40
+
41
+ // The wire/precomputed types are re-exported from `@datadog/flagging-core` so this SDK
42
+ // shares the canonical shapes instead of maintaining its own copies. Local names are
43
+ // kept so the rest of the SDK is insulated from the upstream naming.
44
+ export type PrecomputedFlag = FlaggingCorePrecomputedFlag;
45
+ export type PrecomputedConfigurationResponse = FlaggingCorePrecomputedConfigurationResponse;
46
+ export type ParsedPrecomputedConfiguration = PrecomputedConfiguration;
47
+ export type ParsedFlagsConfiguration = FlagsConfiguration;
@@ -0,0 +1,15 @@
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
+ // Wire (de)serialization is reused from `@datadog/flagging-core` (the canonical
8
+ // implementation) rather than reimplemented here. `configurationFromString` is lenient:
9
+ // it returns an empty configuration (`{}`) for malformed input or an unsupported wire
10
+ // version rather than throwing. `configurationToString` is the inverse (its fix from
11
+ // https://github.com/DataDog/openfeature-js-client/pull/331 shipped in flagging-core 2.0.0).
12
+ export {
13
+ configurationFromString,
14
+ configurationToString
15
+ } from '@datadog/flagging-core';
@@ -30,7 +30,10 @@ export const processEvaluationContext = (
30
30
  const providedAttributes: Record<string, unknown> =
31
31
  context.attributes ?? {};
32
32
 
33
- const attributes: Record<string, PrimitiveValue> = {};
33
+ // Accumulate in a Map so reserved keys such as "__proto__" are handled as data
34
+ // instead of hitting the Object.prototype setter (which would silently drop them or
35
+ // pollute the prototype). Object.fromEntries then materializes own properties safely.
36
+ const attributes = new Map<string, PrimitiveValue>();
34
37
 
35
38
  for (const [key, value] of Object.entries(providedAttributes)) {
36
39
  const isPrimitiveValue =
@@ -53,11 +56,11 @@ export const processEvaluationContext = (
53
56
  continue;
54
57
  }
55
58
 
56
- attributes[key] = value;
59
+ attributes.set(key, value as PrimitiveValue);
57
60
  }
58
61
 
59
62
  return {
60
63
  targetingKey,
61
- attributes
64
+ attributes: Object.fromEntries(attributes)
62
65
  };
63
66
  };
@@ -169,7 +169,9 @@ type FlagErrorCode =
169
169
  | 'PROVIDER_NOT_READY'
170
170
  | 'FLAG_NOT_FOUND'
171
171
  | 'PARSE_ERROR'
172
- | 'TYPE_MISMATCH';
172
+ | 'TYPE_MISMATCH'
173
+ | 'INVALID_CONTEXT'
174
+ | 'GENERAL';
173
175
 
174
176
  /**
175
177
  * Detailed information about a feature flag evaluation.
package/src/index.tsx CHANGED
@@ -32,6 +32,11 @@ import {
32
32
  } from './config/types';
33
33
  import { DdFlags } from './flags/DdFlags';
34
34
  import type { FlagsClient } from './flags/FlagsClient';
35
+ import {
36
+ configurationFromString,
37
+ configurationToString
38
+ } from './flags/configuration';
39
+ import type { ParsedFlagsConfiguration } from './flags/configuration';
35
40
  import type {
36
41
  FlagsConfiguration,
37
42
  FlagDetails,
@@ -72,6 +77,8 @@ export {
72
77
  InitializationMode,
73
78
  DdLogs,
74
79
  DdFlags,
80
+ configurationFromString,
81
+ configurationToString,
75
82
  DdTrace,
76
83
  DdRum,
77
84
  RumActionType,
@@ -118,6 +125,7 @@ export type {
118
125
  TraceConfigurationOptions,
119
126
  FlagsConfiguration,
120
127
  FlagsClient,
128
+ ParsedFlagsConfiguration,
121
129
  EvaluationContext,
122
130
  PrimitiveValue,
123
131
  FlagDetails
@@ -13,6 +13,7 @@ import type { FirstPartyHost } from '../../types';
13
13
 
14
14
  import { DistributedTracingSampling } from './distributedTracing/distributedTracingSampling';
15
15
  import { firstPartyHostsRegexMapBuilder } from './distributedTracing/firstPartyHosts';
16
+ import { FetchProxy } from './requestProxy/FetchProxy/FetchProxy';
16
17
  import { XHRProxy } from './requestProxy/XHRProxy/XHRProxy';
17
18
  import type { RequestProxy } from './requestProxy/interfaces/RequestProxy';
18
19
 
@@ -24,7 +25,7 @@ const RUM_RESOURCE_TRACKING_MODULE =
24
25
  */
25
26
  class RumResourceTracking {
26
27
  private _isTracking = false;
27
- private _requestProxy: RequestProxy | null = null;
28
+ private _requestProxies: RequestProxy[] = [];
28
29
  private _maxSampledTraceId: BigInt.BigInteger | null = null;
29
30
 
30
31
  get isTracking(): boolean {
@@ -40,33 +41,55 @@ class RumResourceTracking {
40
41
  */
41
42
  startTracking({
42
43
  resourceTraceSampleRate,
43
- firstPartyHosts
44
+ firstPartyHosts,
45
+ trackFetchResources = false
44
46
  }: {
45
47
  resourceTraceSampleRate: number;
46
48
  firstPartyHosts: FirstPartyHost[];
49
+ trackFetchResources?: boolean;
47
50
  }): void {
48
51
  // extra safety to avoid proxying the XHR class twice
49
52
  if (this._isTracking) {
50
53
  InternalLog.log(
51
- 'Datadog SDK is already tracking XHR resources',
54
+ 'Datadog SDK is already tracking resources',
52
55
  SdkVerbosity.WARN
53
56
  );
54
57
  return;
55
58
  }
56
59
 
57
- this._requestProxy = XHRProxy.createWithResourceReporter();
58
- this._requestProxy.onTrackingStart({
60
+ const requestProxyOptions = {
59
61
  tracingSamplingRate: resourceTraceSampleRate,
60
62
  firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder(
61
63
  firstPartyHosts
62
64
  )
63
- });
65
+ };
66
+
67
+ const xhrProxy = XHRProxy.createWithResourceReporter();
68
+ xhrProxy.onTrackingStart(requestProxyOptions);
69
+ this._requestProxies.push(xhrProxy);
64
70
 
65
71
  InternalLog.log(
66
72
  'Datadog SDK is tracking XHR resources',
67
73
  SdkVerbosity.INFO
68
74
  );
69
75
 
76
+ if (trackFetchResources) {
77
+ if (typeof globalThis.fetch !== 'function') {
78
+ InternalLog.log(
79
+ 'Datadog SDK did not install Fetch resource tracking because global Fetch is not available',
80
+ SdkVerbosity.INFO
81
+ );
82
+ } else {
83
+ const fetchProxy = FetchProxy.createWithResourceReporter();
84
+ fetchProxy.onTrackingStart(requestProxyOptions);
85
+ this._requestProxies.push(fetchProxy);
86
+ InternalLog.log(
87
+ 'Datadog SDK is tracking Fetch resources',
88
+ SdkVerbosity.INFO
89
+ );
90
+ }
91
+ }
92
+
70
93
  this._isTracking = true;
71
94
  DistributedTracingSampling.setResourceTraceSampleRate(
72
95
  resourceTraceSampleRate
@@ -85,11 +108,13 @@ class RumResourceTracking {
85
108
  }: {
86
109
  resourceTraceSampleRate: number;
87
110
  }): void {
88
- if (!this._isTracking || !this._requestProxy) {
111
+ if (!this._isTracking) {
89
112
  return;
90
113
  }
91
- this._requestProxy.onTrackingUpdate({
92
- tracingSamplingRate: resourceTraceSampleRate
114
+ this._requestProxies.forEach(requestProxy => {
115
+ requestProxy.onTrackingUpdate({
116
+ tracingSamplingRate: resourceTraceSampleRate
117
+ });
93
118
  });
94
119
  // Keep the distributed-tracing sampler's max-trace-id in sync; the
95
120
  // shouldSampleTrace path consults this for rates strictly between 0
@@ -102,10 +127,10 @@ class RumResourceTracking {
102
127
  stopTracking(): void {
103
128
  if (this._isTracking) {
104
129
  this._isTracking = false;
105
- if (this._requestProxy) {
106
- this._requestProxy.onTrackingStop();
107
- }
108
- this._requestProxy = null;
130
+ this._requestProxies.forEach(requestProxy =>
131
+ requestProxy.onTrackingStop()
132
+ );
133
+ this._requestProxies = [];
109
134
  this._maxSampledTraceId = null;
110
135
  }
111
136
  }
@@ -14,6 +14,7 @@ import { SAMPLING_PRIORITY_HEADER_KEY } from '../distributedTracing/headers';
14
14
  import { XMLHttpRequestMock } from './__utils__/XMLHttpRequestMock';
15
15
 
16
16
  const DdRum = NativeModules.DdRum;
17
+ const originalFetch = global.fetch;
17
18
 
18
19
  const flushPromises = () =>
19
20
  new Promise(jest.requireActual('timers').setImmediate);
@@ -26,7 +27,9 @@ beforeEach(() => {
26
27
  });
27
28
 
28
29
  afterEach(() => {
30
+ DdRumResourceTracking.stopTracking();
29
31
  global.XMLHttpRequest = undefined;
32
+ global.fetch = originalFetch;
30
33
  });
31
34
 
32
35
  const executeRequest = (url: string = 'https://api.example.com/v2/user') => {
@@ -92,6 +95,104 @@ describe('DdRumResourceTracking', () => {
92
95
  expect(DdRum.stopResource).not.toHaveBeenCalled();
93
96
  });
94
97
 
98
+ it('tracks Expo Fetch and XHR resources when Fetch tracking is enabled', async () => {
99
+ const fetchResponse = ({
100
+ status: 200,
101
+ headers: {
102
+ get: (header: string) =>
103
+ header.toLowerCase() === 'content-length' ? '12' : null
104
+ }
105
+ } as unknown) as Response;
106
+ const expoFetch = jest
107
+ .fn()
108
+ .mockResolvedValue(fetchResponse) as jest.MockedFunction<
109
+ typeof fetch
110
+ >;
111
+ global.fetch = expoFetch;
112
+ DdRumResourceTracking.startTracking({
113
+ resourceTraceSampleRate: 100,
114
+ firstPartyHosts: [],
115
+ trackFetchResources: true
116
+ });
117
+
118
+ executeRequest();
119
+ await global.fetch('https://api.example.com/v2/user');
120
+ await flushPromises();
121
+
122
+ expect(DdRum.startResource).toHaveBeenCalledTimes(2);
123
+ expect(DdRum.stopResource).toHaveBeenCalledTimes(2);
124
+ expect(DdRum.stopResource.mock.calls.map(call => call[2])).toEqual(
125
+ expect.arrayContaining(['xhr', 'fetch'])
126
+ );
127
+ expect(expoFetch).toHaveBeenCalledTimes(1);
128
+ });
129
+
130
+ it('tracks a native Fetch implementation without relying on an Expo marker', () => {
131
+ const fetchImplementation = jest.fn() as jest.MockedFunction<
132
+ typeof fetch
133
+ >;
134
+ global.fetch = fetchImplementation;
135
+
136
+ DdRumResourceTracking.startTracking({
137
+ resourceTraceSampleRate: 100,
138
+ firstPartyHosts: [],
139
+ trackFetchResources: true
140
+ });
141
+
142
+ expect(global.fetch).not.toBe(fetchImplementation);
143
+ });
144
+
145
+ it('does not wrap Expo Fetch when Fetch tracking is disabled', () => {
146
+ const expoFetch = jest.fn() as jest.MockedFunction<typeof fetch>;
147
+ global.fetch = expoFetch;
148
+
149
+ DdRumResourceTracking.startTracking({
150
+ resourceTraceSampleRate: 100,
151
+ firstPartyHosts: []
152
+ });
153
+
154
+ expect(global.fetch).toBe(expoFetch);
155
+ });
156
+
157
+ it('does not double report an XHR-backed Fetch and still tracks direct XHR', async () => {
158
+ const fetchResponse = ({
159
+ status: 200,
160
+ headers: { get: () => null }
161
+ } as unknown) as Response;
162
+ const xhrBackedFetch = jest.fn(
163
+ (input: RequestInfo | URL, init?: RequestInit) => {
164
+ const xhr = new XMLHttpRequestMock();
165
+ xhr.open(init?.method ?? 'GET', String(input));
166
+ new Headers(init?.headers).forEach((value, header) => {
167
+ xhr.setRequestHeader(header, value);
168
+ });
169
+ xhr.send();
170
+ xhr.notifyResponseArrived();
171
+ xhr.complete(200, 'ok');
172
+ return Promise.resolve(fetchResponse);
173
+ }
174
+ ) as jest.MockedFunction<typeof fetch>;
175
+ global.fetch = xhrBackedFetch;
176
+
177
+ DdRumResourceTracking.startTracking({
178
+ resourceTraceSampleRate: 100,
179
+ firstPartyHosts: [],
180
+ trackFetchResources: true
181
+ });
182
+
183
+ await global.fetch('https://api.example.com/fetch');
184
+ executeRequest('https://api.example.com/xhr');
185
+ await flushPromises();
186
+
187
+ expect(global.fetch).not.toBe(xhrBackedFetch);
188
+ expect(xhrBackedFetch).toHaveBeenCalledTimes(1);
189
+ expect(DdRum.startResource).toHaveBeenCalledTimes(2);
190
+ expect(DdRum.stopResource).toHaveBeenCalledTimes(2);
191
+ expect(DdRum.stopResource.mock.calls.map(call => call[2])).toEqual(
192
+ expect.arrayContaining(['fetch', 'xhr'])
193
+ );
194
+ });
195
+
95
196
  describe('updateTrackingContext', () => {
96
197
  beforeEach(() => {
97
198
  DdRumResourceTracking.stopTracking();