@datadog/mobile-react-native 3.11.0 → 3.13.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 (342) hide show
  1. package/DatadogSDKReactNative.podspec +357 -14
  2. package/README.md +5 -3
  3. package/android/build.gradle +23 -14
  4. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +27 -2
  5. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +27 -2
  6. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +25 -0
  7. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  8. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkNativeInitializationTest.kt +4 -0
  9. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +104 -0
  10. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +8 -0
  11. package/android/src/test/resources/input/complete-configuration.json +5 -0
  12. package/datadog-configuration.gradle +59 -18
  13. package/datadog-configuration.schema.json +140 -0
  14. package/ios/Sources/DdFlagsImplementation.swift +3 -0
  15. package/ios/Sources/DdSdkConfiguration.swift +11 -1
  16. package/ios/Sources/DdSdkNativeInitialization.swift +24 -2
  17. package/ios/Sources/RNDdSdkConfiguration.swift +14 -2
  18. package/ios/Sources/SdkVersion.swift +1 -1
  19. package/lib/commonjs/DdSdkReactNative.js +6 -1
  20. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  21. package/lib/commonjs/config/FileBasedConfiguration.js +4 -1
  22. package/lib/commonjs/config/FileBasedConfiguration.js.map +1 -1
  23. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js +3 -1
  24. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  25. package/lib/commonjs/config/features/RumConfiguration.js +8 -0
  26. package/lib/commonjs/config/features/RumConfiguration.js.map +1 -1
  27. package/lib/commonjs/config/features/RumConfigurationNative.js +4 -0
  28. package/lib/commonjs/config/types/TimeseriesConfiguration.js +25 -0
  29. package/lib/commonjs/config/types/TimeseriesConfiguration.js.map +1 -0
  30. package/lib/commonjs/config/types/index.js +7 -0
  31. package/lib/commonjs/config/types/index.js.map +1 -1
  32. package/lib/commonjs/flags/DdFlags.js +4 -2
  33. package/lib/commonjs/flags/DdFlags.js.map +1 -1
  34. package/lib/commonjs/flags/FlagsClient.js +4 -2
  35. package/lib/commonjs/flags/FlagsClient.js.map +1 -1
  36. package/lib/commonjs/index.js +7 -0
  37. package/lib/commonjs/index.js.map +1 -1
  38. package/lib/commonjs/internal.js +97 -0
  39. package/lib/commonjs/internal.js.map +1 -0
  40. package/lib/commonjs/logs/DdLogs.js +4 -2
  41. package/lib/commonjs/logs/DdLogs.js.map +1 -1
  42. package/lib/commonjs/rum/DdRum.js +4 -2
  43. package/lib/commonjs/rum/DdRum.js.map +1 -1
  44. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +20 -15
  45. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  46. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +5 -2
  47. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  48. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js +2 -1
  49. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -1
  50. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
  51. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js +308 -0
  52. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js.map +1 -0
  53. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js +275 -0
  54. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js.map +1 -0
  55. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js +167 -0
  56. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js.map +1 -0
  57. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js +36 -0
  58. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js.map +1 -0
  59. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js +158 -0
  60. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js.map +1 -0
  61. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js +58 -0
  62. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js.map +1 -0
  63. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js +39 -0
  64. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js.map +1 -0
  65. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js +38 -0
  66. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js.map +1 -0
  67. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/types.js +2 -0
  68. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/types.js.map +1 -0
  69. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +17 -2
  70. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
  71. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +25 -3
  72. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  73. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +2 -35
  74. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -1
  75. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +3 -1
  76. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
  77. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js +8 -2
  78. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -1
  79. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js +88 -0
  80. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js.map +1 -0
  81. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
  82. package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +2 -3
  83. package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -1
  84. package/lib/commonjs/sdk/DdSdkInternal.js +27 -22
  85. package/lib/commonjs/sdk/DdSdkInternal.js.map +1 -1
  86. package/lib/commonjs/specs/NativeDdFlags.js +19 -3
  87. package/lib/commonjs/specs/NativeDdFlags.js.map +1 -1
  88. package/lib/commonjs/specs/NativeDdLogs.js +19 -3
  89. package/lib/commonjs/specs/NativeDdLogs.js.map +1 -1
  90. package/lib/commonjs/specs/NativeDdRum.js +19 -3
  91. package/lib/commonjs/specs/NativeDdRum.js.map +1 -1
  92. package/lib/commonjs/specs/NativeDdSdk.js +19 -3
  93. package/lib/commonjs/specs/NativeDdSdk.js.map +1 -1
  94. package/lib/commonjs/specs/NativeDdTrace.js +19 -3
  95. package/lib/commonjs/specs/NativeDdTrace.js.map +1 -1
  96. package/lib/commonjs/trace/DdTrace.js +4 -2
  97. package/lib/commonjs/trace/DdTrace.js.map +1 -1
  98. package/lib/commonjs/utils/stringUtils.js +48 -0
  99. package/lib/commonjs/utils/stringUtils.js.map +1 -0
  100. package/lib/commonjs/version.js +1 -1
  101. package/lib/module/DdSdkReactNative.js +6 -1
  102. package/lib/module/DdSdkReactNative.js.map +1 -1
  103. package/lib/module/config/FileBasedConfiguration.js +4 -1
  104. package/lib/module/config/FileBasedConfiguration.js.map +1 -1
  105. package/lib/module/config/async/AutoInstrumentationConfiguration.js +3 -1
  106. package/lib/module/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  107. package/lib/module/config/features/RumConfiguration.js +8 -0
  108. package/lib/module/config/features/RumConfiguration.js.map +1 -1
  109. package/lib/module/config/features/RumConfigurationNative.js +1 -1
  110. package/lib/module/config/types/TimeseriesConfiguration.js +19 -0
  111. package/lib/module/config/types/TimeseriesConfiguration.js.map +1 -0
  112. package/lib/module/config/types/index.js +1 -0
  113. package/lib/module/config/types/index.js.map +1 -1
  114. package/lib/module/flags/DdFlags.js +4 -2
  115. package/lib/module/flags/DdFlags.js.map +1 -1
  116. package/lib/module/flags/FlagsClient.js +5 -2
  117. package/lib/module/flags/FlagsClient.js.map +1 -1
  118. package/lib/module/index.js +2 -1
  119. package/lib/module/index.js.map +1 -1
  120. package/lib/module/internal.js +27 -0
  121. package/lib/module/internal.js.map +1 -0
  122. package/lib/module/logs/DdLogs.js +4 -2
  123. package/lib/module/logs/DdLogs.js.map +1 -1
  124. package/lib/module/rum/DdRum.js +4 -2
  125. package/lib/module/rum/DdRum.js.map +1 -1
  126. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +20 -14
  127. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  128. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +5 -2
  129. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  130. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js +1 -1
  131. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -1
  132. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
  133. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js +298 -0
  134. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js.map +1 -0
  135. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js +268 -0
  136. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js.map +1 -0
  137. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js +160 -0
  138. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js.map +1 -0
  139. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js +30 -0
  140. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js.map +1 -0
  141. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js +150 -0
  142. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js.map +1 -0
  143. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js +51 -0
  144. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js.map +1 -0
  145. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js +32 -0
  146. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js.map +1 -0
  147. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js +32 -0
  148. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js.map +1 -0
  149. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/types.js +2 -0
  150. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/types.js.map +1 -0
  151. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +17 -2
  152. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
  153. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +25 -3
  154. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  155. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +1 -34
  156. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -1
  157. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +3 -1
  158. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
  159. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js +8 -2
  160. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -1
  161. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js +79 -0
  162. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js.map +1 -0
  163. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
  164. package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +2 -3
  165. package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -1
  166. package/lib/module/sdk/DdSdkInternal.js +27 -22
  167. package/lib/module/sdk/DdSdkInternal.js.map +1 -1
  168. package/lib/module/specs/NativeDdFlags.js +14 -2
  169. package/lib/module/specs/NativeDdFlags.js.map +1 -1
  170. package/lib/module/specs/NativeDdLogs.js +14 -2
  171. package/lib/module/specs/NativeDdLogs.js.map +1 -1
  172. package/lib/module/specs/NativeDdRum.js +14 -2
  173. package/lib/module/specs/NativeDdRum.js.map +1 -1
  174. package/lib/module/specs/NativeDdSdk.js +14 -2
  175. package/lib/module/specs/NativeDdSdk.js.map +1 -1
  176. package/lib/module/specs/NativeDdTrace.js +14 -2
  177. package/lib/module/specs/NativeDdTrace.js.map +1 -1
  178. package/lib/module/trace/DdTrace.js +4 -2
  179. package/lib/module/trace/DdTrace.js.map +1 -1
  180. package/lib/module/utils/stringUtils.js +42 -0
  181. package/lib/module/utils/stringUtils.js.map +1 -0
  182. package/lib/module/version.js +1 -1
  183. package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
  184. package/lib/typescript/config/FileBasedConfiguration.d.ts.map +1 -1
  185. package/lib/typescript/config/FileBasedConfiguration.type.d.ts +4 -1
  186. package/lib/typescript/config/FileBasedConfiguration.type.d.ts.map +1 -1
  187. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts +6 -0
  188. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts.map +1 -1
  189. package/lib/typescript/config/async/PartialInitializationConfiguration.d.ts +2 -1
  190. package/lib/typescript/config/async/PartialInitializationConfiguration.d.ts.map +1 -1
  191. package/lib/typescript/config/features/RumConfiguration.d.ts +6 -1
  192. package/lib/typescript/config/features/RumConfiguration.d.ts.map +1 -1
  193. package/lib/typescript/config/features/RumConfiguration.type.d.ts +116 -1
  194. package/lib/typescript/config/features/RumConfiguration.type.d.ts.map +1 -1
  195. package/lib/typescript/config/features/RumConfigurationNative.d.ts +2 -0
  196. package/lib/typescript/config/features/RumConfigurationNative.d.ts.map +1 -1
  197. package/lib/typescript/config/types/TimeseriesConfiguration.d.ts +19 -0
  198. package/lib/typescript/config/types/TimeseriesConfiguration.d.ts.map +1 -0
  199. package/lib/typescript/config/types/index.d.ts +2 -0
  200. package/lib/typescript/config/types/index.d.ts.map +1 -1
  201. package/lib/typescript/flags/DdFlags.d.ts.map +1 -1
  202. package/lib/typescript/flags/FlagsClient.d.ts +1 -1
  203. package/lib/typescript/flags/FlagsClient.d.ts.map +1 -1
  204. package/lib/typescript/index.d.ts +5 -2
  205. package/lib/typescript/index.d.ts.map +1 -1
  206. package/lib/typescript/internal.d.ts +26 -0
  207. package/lib/typescript/internal.d.ts.map +1 -0
  208. package/lib/typescript/logs/DdLogs.d.ts +1 -1
  209. package/lib/typescript/logs/DdLogs.d.ts.map +1 -1
  210. package/lib/typescript/rum/DdRum.d.ts +1 -1
  211. package/lib/typescript/rum/DdRum.d.ts.map +1 -1
  212. package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts.map +1 -1
  213. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +3 -1
  214. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts.map +1 -1
  215. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts +1 -0
  216. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts.map +1 -1
  217. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.d.ts +85 -0
  218. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.d.ts.map +1 -0
  219. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.d.ts +18 -0
  220. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.d.ts.map +1 -0
  221. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.d.ts +24 -0
  222. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.d.ts.map +1 -0
  223. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.d.ts +12 -0
  224. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.d.ts.map +1 -0
  225. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.d.ts +28 -0
  226. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.d.ts.map +1 -0
  227. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.d.ts +16 -0
  228. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.d.ts.map +1 -0
  229. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.d.ts +13 -0
  230. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.d.ts.map +1 -0
  231. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.d.ts +13 -0
  232. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.d.ts.map +1 -0
  233. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/types.d.ts +27 -0
  234. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/types.d.ts.map +1 -0
  235. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.d.ts.map +1 -1
  236. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
  237. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.d.ts.map +1 -1
  238. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts +2 -0
  239. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts.map +1 -1
  240. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.d.ts +43 -0
  241. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.d.ts.map +1 -0
  242. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts +2 -0
  243. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts.map +1 -1
  244. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts +2 -0
  245. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts.map +1 -1
  246. package/lib/typescript/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.d.ts.map +1 -1
  247. package/lib/typescript/sdk/DdSdkInternal.d.ts +1 -0
  248. package/lib/typescript/sdk/DdSdkInternal.d.ts.map +1 -1
  249. package/lib/typescript/specs/NativeDdFlags.d.ts +7 -2
  250. package/lib/typescript/specs/NativeDdFlags.d.ts.map +1 -1
  251. package/lib/typescript/specs/NativeDdLogs.d.ts +7 -2
  252. package/lib/typescript/specs/NativeDdLogs.d.ts.map +1 -1
  253. package/lib/typescript/specs/NativeDdRum.d.ts +7 -2
  254. package/lib/typescript/specs/NativeDdRum.d.ts.map +1 -1
  255. package/lib/typescript/specs/NativeDdSdk.d.ts +7 -2
  256. package/lib/typescript/specs/NativeDdSdk.d.ts.map +1 -1
  257. package/lib/typescript/specs/NativeDdTrace.d.ts +7 -2
  258. package/lib/typescript/specs/NativeDdTrace.d.ts.map +1 -1
  259. package/lib/typescript/trace/DdTrace.d.ts.map +1 -1
  260. package/lib/typescript/utils/stringUtils.d.ts +12 -0
  261. package/lib/typescript/utils/stringUtils.d.ts.map +1 -0
  262. package/lib/typescript/version.d.ts +1 -1
  263. package/package.json +8 -3
  264. package/src/DdSdkReactNative.tsx +11 -1
  265. package/src/__tests__/DdSdkReactNative.test.tsx +145 -20
  266. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +6 -0
  267. package/src/__tests__/internalEntry.test.ts +26 -0
  268. package/src/__tests__/mock.test.ts +1 -3
  269. package/src/__tests__/nativeSpecGetters.test.ts +102 -0
  270. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +3 -3
  271. package/src/__tests__/wrapperImportSafety.test.ts +129 -0
  272. package/src/config/FileBasedConfiguration.ts +6 -1
  273. package/src/config/FileBasedConfiguration.type.ts +4 -0
  274. package/src/config/__tests__/FileBasedConfiguration.test.ts +73 -0
  275. package/src/config/__tests__/__fixtures__/configuration-all-fields.json +14 -1
  276. package/src/config/async/AutoInstrumentationConfiguration.ts +9 -1
  277. package/src/config/async/PartialInitializationConfiguration.ts +2 -0
  278. package/src/config/features/RumConfiguration.ts +15 -0
  279. package/src/config/features/RumConfiguration.type.ts +128 -1
  280. package/src/config/features/RumConfigurationNative.ts +3 -0
  281. package/src/config/types/TimeseriesConfiguration.ts +26 -0
  282. package/src/config/types/index.ts +5 -0
  283. package/src/flags/DdFlags.ts +4 -3
  284. package/src/flags/FlagsClient.ts +4 -3
  285. package/src/index.tsx +15 -0
  286. package/src/internal.ts +32 -0
  287. package/src/logs/DdLogs.ts +4 -3
  288. package/src/rum/DdRum.ts +4 -3
  289. package/src/rum/__tests__/DdRum.test.ts +4 -4
  290. package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +33 -26
  291. package/src/rum/instrumentation/interactionTracking/__tests__/BabelOptionalHandlers.test.ts +120 -0
  292. package/src/rum/instrumentation/interactionTracking/__tests__/DdBabelInteractionTracking.test.ts +82 -2
  293. package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +7 -2
  294. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +46 -0
  295. package/src/rum/instrumentation/resourceTracking/__tests__/__utils__/XMLHttpRequestMock.ts +1 -1
  296. package/src/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.ts +1 -1
  297. package/src/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
  298. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/captureHeaders.test.ts +853 -0
  299. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/compileHeaderConfig.test.ts +697 -0
  300. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/enforceSizeLimits.integration.test.ts +183 -0
  301. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/enforceSizeLimits.test.ts +337 -0
  302. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/isHeaderAllowed.test.ts +35 -0
  303. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/normalizeUrlForMatching.test.ts +176 -0
  304. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/parseResponseHeaders.test.ts +114 -0
  305. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/sensitiveHeaderBlocklist.test.ts +112 -0
  306. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/tracingHeaderExclusion.test.ts +59 -0
  307. package/src/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.ts +437 -0
  308. package/src/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.ts +339 -0
  309. package/src/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.ts +208 -0
  310. package/src/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.ts +29 -0
  311. package/src/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.ts +181 -0
  312. package/src/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.ts +59 -0
  313. package/src/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.ts +31 -0
  314. package/src/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.ts +61 -0
  315. package/src/rum/instrumentation/resourceTracking/headerCapture/types.ts +33 -0
  316. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.ts +21 -2
  317. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/__tests__/FetchProxy.test.ts +274 -0
  318. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/__tests__/ResourceReporter.test.ts +120 -0
  319. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +34 -3
  320. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +624 -2
  321. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.ts +1 -34
  322. package/src/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.ts +6 -1
  323. package/src/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.ts +16 -2
  324. package/src/rum/instrumentation/resourceTracking/requestProxy/common/__tests__/headerCapture.test.ts +164 -0
  325. package/src/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.ts +119 -0
  326. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.ts +2 -0
  327. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.ts +2 -0
  328. package/src/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.tsx +3 -4
  329. package/src/sdk/DatadogInternalBridge/__tests__/DdSdkNativeBridge.test.tsx +35 -2
  330. package/src/sdk/DatadogProvider/Buffer/__tests__/BoundedBuffer.test.ts +5 -5
  331. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +54 -1
  332. package/src/sdk/DdSdkInternal.ts +27 -24
  333. package/src/sdk/EventMappers/__tests__/EventMapper.test.ts +2 -2
  334. package/src/specs/NativeDdFlags.ts +14 -2
  335. package/src/specs/NativeDdLogs.ts +14 -2
  336. package/src/specs/NativeDdRum.ts +14 -2
  337. package/src/specs/NativeDdSdk.ts +14 -2
  338. package/src/specs/NativeDdTrace.ts +14 -2
  339. package/src/trace/DdTrace.ts +4 -3
  340. package/src/utils/__tests__/stringUtils.test.ts +90 -0
  341. package/src/utils/stringUtils.ts +41 -0
  342. package/src/version.ts +1 -1
@@ -6,13 +6,10 @@
6
6
 
7
7
  import type { DdSdkNativeConfiguration } from '../config/features/CoreConfigurationNative';
8
8
  import type { DdNativeSdkType } from '../nativeModulesTypes';
9
+ import { getNativeDdSdk } from '../specs/NativeDdSdk';
9
10
 
10
11
  import type { AttributeEncoder } from './AttributesEncoding/types';
11
12
 
12
- // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
13
- const NativeDdSdkSpec: DdNativeSdkType = require('../specs/NativeDdSdk')
14
- .default;
15
-
16
13
  export type DdSdkType = DdNativeSdkType & {
17
14
  readonly attributeEncoders: AttributeEncoder<any>[];
18
15
  };
@@ -23,51 +20,57 @@ export class DdSdkWrapper implements DdNativeSdkType {
23
20
  }
24
21
  private _attributeEncoders: AttributeEncoder<any>[] = [];
25
22
 
23
+ // Resolved on use rather than at import, so importing this module is safe
24
+ // on platforms without the native module (e.g. Vega).
25
+ private get nativeSdk(): DdNativeSdkType {
26
+ return getNativeDdSdk() as DdNativeSdkType;
27
+ }
28
+
26
29
  initialize(configuration: DdSdkNativeConfiguration): Promise<void> {
27
30
  this._attributeEncoders = [...configuration.attributeEncoders];
28
- return NativeDdSdkSpec.initialize(configuration);
31
+ return this.nativeSdk.initialize(configuration);
29
32
  }
30
33
 
31
34
  getConstants() {
32
- return NativeDdSdkSpec.getConstants();
35
+ return this.nativeSdk.getConstants();
33
36
  }
34
37
 
35
38
  setUserInfo(user: object): Promise<object> {
36
- return NativeDdSdkSpec.setUserInfo(user);
39
+ return this.nativeSdk.setUserInfo(user);
37
40
  }
38
41
 
39
42
  clearUserInfo(): Promise<void> {
40
- return NativeDdSdkSpec.clearUserInfo();
43
+ return this.nativeSdk.clearUserInfo();
41
44
  }
42
45
 
43
46
  addUserExtraInfo(extraInfo: object): Promise<object> {
44
- return NativeDdSdkSpec.addUserExtraInfo(extraInfo);
47
+ return this.nativeSdk.addUserExtraInfo(extraInfo);
45
48
  }
46
49
 
47
50
  addAttribute(key: string, value: object): Promise<void> {
48
- return NativeDdSdkSpec.addAttribute(key, value);
51
+ return this.nativeSdk.addAttribute(key, value);
49
52
  }
50
53
  removeAttribute(key: string): Promise<void> {
51
- return NativeDdSdkSpec.removeAttribute(key);
54
+ return this.nativeSdk.removeAttribute(key);
52
55
  }
53
56
  addAttributes(attributes: object): Promise<void> {
54
- return NativeDdSdkSpec.addAttributes(attributes);
57
+ return this.nativeSdk.addAttributes(attributes);
55
58
  }
56
59
  removeAttributes(keys: string[]): Promise<void> {
57
- return NativeDdSdkSpec.removeAttributes(keys);
60
+ return this.nativeSdk.removeAttributes(keys);
58
61
  }
59
62
  setAccountInfo(account: object): Promise<object> {
60
- return NativeDdSdkSpec.setAccountInfo(account);
63
+ return this.nativeSdk.setAccountInfo(account);
61
64
  }
62
65
  clearAccountInfo(): Promise<void> {
63
- return NativeDdSdkSpec.clearAccountInfo();
66
+ return this.nativeSdk.clearAccountInfo();
64
67
  }
65
68
  addAccountExtraInfo(extraInfo: object): Promise<object> {
66
- return NativeDdSdkSpec.addAccountExtraInfo(extraInfo);
69
+ return this.nativeSdk.addAccountExtraInfo(extraInfo);
67
70
  }
68
71
 
69
72
  setTrackingConsent(trackingConsent: string): Promise<void> {
70
- return NativeDdSdkSpec.setTrackingConsent(trackingConsent);
73
+ return this.nativeSdk.setTrackingConsent(trackingConsent);
71
74
  }
72
75
 
73
76
  sendTelemetryLog(
@@ -75,11 +78,11 @@ export class DdSdkWrapper implements DdNativeSdkType {
75
78
  attributes: object,
76
79
  config: object
77
80
  ): Promise<void> {
78
- return NativeDdSdkSpec.sendTelemetryLog(message, attributes, config);
81
+ return this.nativeSdk.sendTelemetryLog(message, attributes, config);
79
82
  }
80
83
 
81
84
  telemetryDebug(message: string): Promise<void> {
82
- return NativeDdSdkSpec.telemetryDebug(message);
85
+ return this.nativeSdk.telemetryDebug(message);
83
86
  }
84
87
 
85
88
  telemetryError(
@@ -87,23 +90,23 @@ export class DdSdkWrapper implements DdNativeSdkType {
87
90
  stack: string,
88
91
  kind: string
89
92
  ): Promise<void> {
90
- return NativeDdSdkSpec.telemetryError(message, stack, kind);
93
+ return this.nativeSdk.telemetryError(message, stack, kind);
91
94
  }
92
95
 
93
96
  consumeWebviewEvent(message: string): Promise<void> {
94
- return NativeDdSdkSpec.consumeWebviewEvent(message);
97
+ return this.nativeSdk.consumeWebviewEvent(message);
95
98
  }
96
99
 
97
100
  clearAllData(): Promise<void> {
98
- return NativeDdSdkSpec.clearAllData();
101
+ return this.nativeSdk.clearAllData();
99
102
  }
100
103
 
101
104
  addListener(eventType: string): void {
102
- return NativeDdSdkSpec.addListener(eventType);
105
+ return this.nativeSdk.addListener(eventType);
103
106
  }
104
107
 
105
108
  removeListeners(count: number): void {
106
- return NativeDdSdkSpec.removeListeners(count);
109
+ return this.nativeSdk.removeListeners(count);
107
110
  }
108
111
 
109
112
  _setAttributeEncodersForTesting(
@@ -4,7 +4,7 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import NativeDdSdkSpec from '../../../specs/NativeDdSdk';
7
+ import { getNativeDdSdk } from '../../../specs/NativeDdSdk';
8
8
  import { EventMapper } from '../EventMapper';
9
9
 
10
10
  describe('EventMapper', () => {
@@ -26,7 +26,7 @@ describe('EventMapper', () => {
26
26
  ).toEqual({
27
27
  someData: 'some data'
28
28
  });
29
- expect(NativeDdSdkSpec.telemetryDebug).toHaveBeenCalledWith(
29
+ expect(getNativeDdSdk()?.telemetryDebug).toHaveBeenCalledWith(
30
30
  'Error while running the event mapper'
31
31
  );
32
32
  });
@@ -31,5 +31,17 @@ export interface Spec extends TurboModule {
31
31
  ) => Promise<void>;
32
32
  }
33
33
 
34
- // eslint-disable-next-line import/no-default-export
35
- export default TurboModuleRegistry.get<Spec>('DdFlags');
34
+ let cachedModule: Spec | null = null;
35
+
36
+ /**
37
+ * Lazily resolves the native TurboModule on first call and caches it once found.
38
+ * A missing module is not cached, so later calls retry the lookup.
39
+ * Resolving lazily (instead of at module load) keeps this package importable on
40
+ * platforms where the native module is absent (e.g. Vega).
41
+ */
42
+ export const getNativeDdFlags = (): Spec | null => {
43
+ if (!cachedModule) {
44
+ cachedModule = TurboModuleRegistry.get<Spec>('DdFlags');
45
+ }
46
+ return cachedModule;
47
+ };
@@ -107,5 +107,17 @@ export interface Spec extends TurboModule {
107
107
  ) => Promise<void>;
108
108
  }
109
109
 
110
- // eslint-disable-next-line import/no-default-export
111
- export default TurboModuleRegistry.get<Spec>('DdLogs');
110
+ let cachedModule: Spec | null = null;
111
+
112
+ /**
113
+ * Lazily resolves the native TurboModule on first call and caches it once found.
114
+ * A missing module is not cached, so later calls retry the lookup.
115
+ * Resolving lazily (instead of at module load) keeps this package importable on
116
+ * platforms where the native module is absent (e.g. Vega).
117
+ */
118
+ export const getNativeDdLogs = (): Spec | null => {
119
+ if (!cachedModule) {
120
+ cachedModule = TurboModuleRegistry.get<Spec>('DdLogs');
121
+ }
122
+ return cachedModule;
123
+ };
@@ -236,5 +236,17 @@ export interface Spec extends TurboModule {
236
236
  ): Promise<void>;
237
237
  }
238
238
 
239
- // eslint-disable-next-line import/no-default-export
240
- export default TurboModuleRegistry.get<Spec>('DdRum');
239
+ let cachedModule: Spec | null = null;
240
+
241
+ /**
242
+ * Lazily resolves the native TurboModule on first call and caches it once found.
243
+ * A missing module is not cached, so later calls retry the lookup.
244
+ * Resolving lazily (instead of at module load) keeps this package importable on
245
+ * platforms where the native module is absent (e.g. Vega).
246
+ */
247
+ export const getNativeDdRum = (): Spec | null => {
248
+ if (!cachedModule) {
249
+ cachedModule = TurboModuleRegistry.get<Spec>('DdRum');
250
+ }
251
+ return cachedModule;
252
+ };
@@ -134,5 +134,17 @@ export interface Spec extends TurboModule {
134
134
  removeListeners: (count: number) => void;
135
135
  }
136
136
 
137
- // eslint-disable-next-line import/no-default-export
138
- export default TurboModuleRegistry.get<Spec>('DdSdk');
137
+ let cachedModule: Spec | null = null;
138
+
139
+ /**
140
+ * Lazily resolves the native TurboModule on first call and caches it once found.
141
+ * A missing module is not cached, so later calls retry the lookup.
142
+ * Resolving lazily (instead of at module load) keeps this package importable on
143
+ * platforms where the native module is absent (e.g. Vega).
144
+ */
145
+ export const getNativeDdSdk = (): Spec | null => {
146
+ if (!cachedModule) {
147
+ cachedModule = TurboModuleRegistry.get<Spec>('DdSdk');
148
+ }
149
+ return cachedModule;
150
+ };
@@ -39,5 +39,17 @@ export interface Spec extends TurboModule {
39
39
  ): Promise<void>;
40
40
  }
41
41
 
42
- // eslint-disable-next-line import/no-default-export
43
- export default TurboModuleRegistry.get<Spec>('DdTrace');
42
+ let cachedModule: Spec | null = null;
43
+
44
+ /**
45
+ * Lazily resolves the native TurboModule on first call and caches it once found.
46
+ * A missing module is not cached, so later calls retry the lookup.
47
+ * Resolving lazily (instead of at module load) keeps this package importable on
48
+ * platforms where the native module is absent (e.g. Vega).
49
+ */
50
+ export const getNativeDdTrace = (): Spec | null => {
51
+ if (!cachedModule) {
52
+ cachedModule = TurboModuleRegistry.get<Spec>('DdTrace');
53
+ }
54
+ return cachedModule;
55
+ };
@@ -12,6 +12,7 @@ import {
12
12
  bufferNativeCallReturningId,
13
13
  bufferNativeCallWithId
14
14
  } from '../sdk/DatadogProvider/Buffer/bufferNativeCall';
15
+ import { getNativeDdTrace } from '../specs/NativeDdTrace';
15
16
  import type { DdTraceType } from '../types';
16
17
  import { getGlobalInstance } from '../utils/singletonUtils';
17
18
  import { DefaultTimeProvider } from '../utils/time-provider/DefaultTimeProvider';
@@ -21,9 +22,9 @@ const TRACE_MODULE = 'com.datadog.reactnative.trace';
21
22
  const timeProvider = new DefaultTimeProvider();
22
23
 
23
24
  class DdTraceWrapper implements DdTraceType {
24
- // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
25
- private nativeTrace: DdNativeTraceType = require('../specs/NativeDdTrace')
26
- .default;
25
+ private get nativeTrace(): DdNativeTraceType {
26
+ return getNativeDdTrace() as DdNativeTraceType;
27
+ }
27
28
 
28
29
  startSpan = (
29
30
  operation: string,
@@ -0,0 +1,90 @@
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 { utf8ByteLength } from '../stringUtils';
8
+
9
+ describe('utf8ByteLength', () => {
10
+ describe('ASCII strings (1 byte per char)', () => {
11
+ it('returns 0 for empty string', () => {
12
+ expect(utf8ByteLength('')).toBe(0);
13
+ });
14
+
15
+ it('counts single ASCII character as 1 byte', () => {
16
+ expect(utf8ByteLength('a')).toBe(1);
17
+ });
18
+
19
+ it('counts ASCII string correctly', () => {
20
+ expect(utf8ByteLength('hello')).toBe(5);
21
+ });
22
+ });
23
+
24
+ describe('2-byte characters (U+0080 – U+07FF)', () => {
25
+ it('counts a 2-byte character correctly', () => {
26
+ // 'é' is U+00E9 → 2 bytes in UTF-8
27
+ expect(utf8ByteLength('é')).toBe(2);
28
+ });
29
+
30
+ it('counts mixed ASCII and 2-byte characters', () => {
31
+ // 'café' → c(1) + a(1) + f(1) + é(2) = 5
32
+ expect(utf8ByteLength('café')).toBe(5);
33
+ });
34
+ });
35
+
36
+ describe('3-byte characters (U+0800 – U+FFFF, excluding surrogates)', () => {
37
+ it('counts a 3-byte CJK character correctly', () => {
38
+ // '中' is U+4E2D → 3 bytes in UTF-8
39
+ expect(utf8ByteLength('中')).toBe(3);
40
+ });
41
+
42
+ it('counts a string of 3-byte characters correctly', () => {
43
+ // '中文' → 3 + 3 = 6
44
+ expect(utf8ByteLength('中文')).toBe(6);
45
+ });
46
+ });
47
+
48
+ describe('4-byte characters — valid surrogate pairs', () => {
49
+ it('counts a valid surrogate pair (emoji) as 4 bytes', () => {
50
+ // '😀' is U+1F600, encoded as surrogate pair 😀
51
+ expect(utf8ByteLength('😀')).toBe(4);
52
+ });
53
+
54
+ it('counts multiple emoji correctly', () => {
55
+ expect(utf8ByteLength('😀😀')).toBe(8);
56
+ });
57
+
58
+ it('counts mixed ASCII and emoji', () => {
59
+ // 'a😀b' → 1 + 4 + 1 = 6
60
+ expect(utf8ByteLength('a😀b')).toBe(6);
61
+ });
62
+ });
63
+
64
+ describe('unpaired surrogates — malformed strings', () => {
65
+ it('counts a lone high surrogate as 3 bytes', () => {
66
+ // \uD83D is a high surrogate not followed by a low surrogate
67
+ const loneHigh = '\uD83D';
68
+ expect(utf8ByteLength(loneHigh)).toBe(3);
69
+ });
70
+
71
+ it('counts a lone low surrogate as 3 bytes', () => {
72
+ // \uDE00 is a low surrogate not preceded by a high surrogate
73
+ const loneLow = '\uDE00';
74
+ expect(utf8ByteLength(loneLow)).toBe(3);
75
+ });
76
+
77
+ it('does not under-count when a high surrogate is followed by a non-low-surrogate', () => {
78
+ // \uD83D (high surrogate) + 'a' (not a low surrogate)
79
+ // Should be 3 + 1 = 4, not 4 (treating as pair)
80
+ const highPlusAscii = '\uD83Da';
81
+ expect(utf8ByteLength(highPlusAscii)).toBe(4);
82
+ });
83
+
84
+ it('counts two consecutive lone surrogates as 6 bytes', () => {
85
+ // \uD83D\uD83D — two high surrogates, each lone
86
+ const twoHighSurrogates = '\uD83D\uD83D';
87
+ expect(utf8ByteLength(twoHighSurrogates)).toBe(6);
88
+ });
89
+ });
90
+ });
@@ -0,0 +1,41 @@
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
+ * Returns the number of bytes needed to encode a string in UTF-8.
9
+ *
10
+ * Works in all JS environments (Hermes, JSC, Node.js) — no TextEncoder or
11
+ * deprecated APIs required.
12
+ *
13
+ * Handles surrogate pairs correctly: a valid high+low pair counts as 4 bytes.
14
+ * Lone surrogates (unpaired high or low) each count as 3 bytes, matching the
15
+ * WTF-8 / WHATWG encoding convention for malformed strings.
16
+ */
17
+ export function utf8ByteLength(str: string): number {
18
+ let bytes = 0;
19
+ for (let i = 0; i < str.length; i++) {
20
+ const code = str.charCodeAt(i);
21
+ if (code < 0x80) {
22
+ bytes += 1;
23
+ } else if (code < 0x800) {
24
+ bytes += 2;
25
+ } else if (code >= 0xd800 && code <= 0xdbff) {
26
+ // High surrogate — check for a following low surrogate
27
+ const next = i + 1 < str.length ? str.charCodeAt(i + 1) : 0;
28
+ if (next >= 0xdc00 && next <= 0xdfff) {
29
+ i += 1; // consume the low surrogate
30
+ bytes += 4;
31
+ } else {
32
+ bytes += 3; // lone high surrogate
33
+ }
34
+ } else if (code >= 0xdc00 && code <= 0xdfff) {
35
+ bytes += 3; // lone low surrogate
36
+ } else {
37
+ bytes += 3;
38
+ }
39
+ }
40
+ return bytes;
41
+ }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '3.11.0';
2
+ export const version = '3.13.0';