@datadog/mobile-react-native 3.10.0 → 3.12.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 (332) hide show
  1. package/DatadogSDKReactNative.podspec +7 -7
  2. package/README.md +2 -1
  3. package/android/build.gradle +23 -13
  4. package/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt +10 -0
  5. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  6. package/android/src/newarch/kotlin/com/datadog/reactnative/DdRum.kt +10 -0
  7. package/android/src/oldarchCommon/kotlin/com/datadog/reactnative/DdRum.kt +10 -0
  8. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +9 -0
  9. package/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt +3 -3
  10. package/datadog-configuration.gradle +59 -18
  11. package/datadog-configuration.schema.json +119 -0
  12. package/ios/Sources/DdRum.mm +13 -1
  13. package/ios/Sources/DdRumImplementation.swift +6 -0
  14. package/ios/Sources/SdkVersion.swift +1 -1
  15. package/jest/mock.js +3 -0
  16. package/lib/commonjs/DdSdkReactNative.js +6 -1
  17. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  18. package/lib/commonjs/config/FileBasedConfiguration.js +2 -0
  19. package/lib/commonjs/config/FileBasedConfiguration.js.map +1 -1
  20. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js +2 -1
  21. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  22. package/lib/commonjs/config/features/RumConfiguration.js +4 -0
  23. package/lib/commonjs/config/features/RumConfiguration.js.map +1 -1
  24. package/lib/commonjs/flags/DdFlags.js +4 -2
  25. package/lib/commonjs/flags/DdFlags.js.map +1 -1
  26. package/lib/commonjs/flags/FlagsClient.js +4 -2
  27. package/lib/commonjs/flags/FlagsClient.js.map +1 -1
  28. package/lib/commonjs/internal.js +97 -0
  29. package/lib/commonjs/internal.js.map +1 -0
  30. package/lib/commonjs/logs/DdLogs.js +4 -2
  31. package/lib/commonjs/logs/DdLogs.js.map +1 -1
  32. package/lib/commonjs/rum/DdRum.js +8 -2
  33. package/lib/commonjs/rum/DdRum.js.map +1 -1
  34. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +20 -15
  35. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  36. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +5 -2
  37. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  38. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js +2 -1
  39. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -1
  40. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
  41. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js +308 -0
  42. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js.map +1 -0
  43. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js +275 -0
  44. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js.map +1 -0
  45. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js +167 -0
  46. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js.map +1 -0
  47. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js +36 -0
  48. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js.map +1 -0
  49. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js +158 -0
  50. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js.map +1 -0
  51. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js +58 -0
  52. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js.map +1 -0
  53. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js +39 -0
  54. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js.map +1 -0
  55. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js +38 -0
  56. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js.map +1 -0
  57. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/types.js +2 -0
  58. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/types.js.map +1 -0
  59. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +19 -4
  60. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
  61. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +26 -4
  62. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  63. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +2 -35
  64. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -1
  65. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +10 -2
  66. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
  67. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js +8 -2
  68. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -1
  69. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js +88 -0
  70. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js.map +1 -0
  71. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
  72. package/lib/commonjs/rum/types.js.map +1 -1
  73. package/lib/commonjs/sdk/AccountInfoSingleton/AccountInfoSingleton.js +1 -0
  74. package/lib/commonjs/sdk/AccountInfoSingleton/AccountInfoSingleton.js.map +1 -1
  75. package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +2 -3
  76. package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -1
  77. package/lib/commonjs/sdk/DdSdkInternal.js +27 -22
  78. package/lib/commonjs/sdk/DdSdkInternal.js.map +1 -1
  79. package/lib/commonjs/sdk/UserInfoSingleton/UserInfoSingleton.js +1 -0
  80. package/lib/commonjs/sdk/UserInfoSingleton/UserInfoSingleton.js.map +1 -1
  81. package/lib/commonjs/specs/NativeDdFlags.js +19 -3
  82. package/lib/commonjs/specs/NativeDdFlags.js.map +1 -1
  83. package/lib/commonjs/specs/NativeDdLogs.js +19 -3
  84. package/lib/commonjs/specs/NativeDdLogs.js.map +1 -1
  85. package/lib/commonjs/specs/NativeDdRum.js +19 -3
  86. package/lib/commonjs/specs/NativeDdRum.js.map +1 -1
  87. package/lib/commonjs/specs/NativeDdSdk.js +19 -3
  88. package/lib/commonjs/specs/NativeDdSdk.js.map +1 -1
  89. package/lib/commonjs/specs/NativeDdTrace.js +19 -3
  90. package/lib/commonjs/specs/NativeDdTrace.js.map +1 -1
  91. package/lib/commonjs/trace/DdTrace.js +4 -2
  92. package/lib/commonjs/trace/DdTrace.js.map +1 -1
  93. package/lib/commonjs/utils/stringUtils.js +48 -0
  94. package/lib/commonjs/utils/stringUtils.js.map +1 -0
  95. package/lib/commonjs/version.js +1 -1
  96. package/lib/module/DdSdkReactNative.js +6 -1
  97. package/lib/module/DdSdkReactNative.js.map +1 -1
  98. package/lib/module/config/FileBasedConfiguration.js +2 -0
  99. package/lib/module/config/FileBasedConfiguration.js.map +1 -1
  100. package/lib/module/config/async/AutoInstrumentationConfiguration.js +2 -1
  101. package/lib/module/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  102. package/lib/module/config/features/RumConfiguration.js +4 -0
  103. package/lib/module/config/features/RumConfiguration.js.map +1 -1
  104. package/lib/module/flags/DdFlags.js +4 -2
  105. package/lib/module/flags/DdFlags.js.map +1 -1
  106. package/lib/module/flags/FlagsClient.js +5 -2
  107. package/lib/module/flags/FlagsClient.js.map +1 -1
  108. package/lib/module/internal.js +27 -0
  109. package/lib/module/internal.js.map +1 -0
  110. package/lib/module/logs/DdLogs.js +4 -2
  111. package/lib/module/logs/DdLogs.js.map +1 -1
  112. package/lib/module/rum/DdRum.js +8 -2
  113. package/lib/module/rum/DdRum.js.map +1 -1
  114. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +20 -14
  115. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  116. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +5 -2
  117. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  118. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js +1 -1
  119. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -1
  120. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
  121. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js +298 -0
  122. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js.map +1 -0
  123. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js +268 -0
  124. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js.map +1 -0
  125. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js +160 -0
  126. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js.map +1 -0
  127. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js +30 -0
  128. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js.map +1 -0
  129. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js +150 -0
  130. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js.map +1 -0
  131. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js +51 -0
  132. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js.map +1 -0
  133. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js +32 -0
  134. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js.map +1 -0
  135. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js +32 -0
  136. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js.map +1 -0
  137. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/types.js +2 -0
  138. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/types.js.map +1 -0
  139. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +20 -5
  140. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
  141. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +27 -5
  142. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  143. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +1 -34
  144. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -1
  145. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +8 -1
  146. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
  147. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js +8 -2
  148. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -1
  149. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js +79 -0
  150. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js.map +1 -0
  151. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
  152. package/lib/module/rum/types.js.map +1 -1
  153. package/lib/module/sdk/AccountInfoSingleton/AccountInfoSingleton.js +2 -1
  154. package/lib/module/sdk/AccountInfoSingleton/AccountInfoSingleton.js.map +1 -1
  155. package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +2 -3
  156. package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -1
  157. package/lib/module/sdk/DdSdkInternal.js +27 -22
  158. package/lib/module/sdk/DdSdkInternal.js.map +1 -1
  159. package/lib/module/sdk/UserInfoSingleton/UserInfoSingleton.js +2 -1
  160. package/lib/module/sdk/UserInfoSingleton/UserInfoSingleton.js.map +1 -1
  161. package/lib/module/specs/NativeDdFlags.js +14 -2
  162. package/lib/module/specs/NativeDdFlags.js.map +1 -1
  163. package/lib/module/specs/NativeDdLogs.js +14 -2
  164. package/lib/module/specs/NativeDdLogs.js.map +1 -1
  165. package/lib/module/specs/NativeDdRum.js +14 -2
  166. package/lib/module/specs/NativeDdRum.js.map +1 -1
  167. package/lib/module/specs/NativeDdSdk.js +14 -2
  168. package/lib/module/specs/NativeDdSdk.js.map +1 -1
  169. package/lib/module/specs/NativeDdTrace.js +14 -2
  170. package/lib/module/specs/NativeDdTrace.js.map +1 -1
  171. package/lib/module/trace/DdTrace.js +4 -2
  172. package/lib/module/trace/DdTrace.js.map +1 -1
  173. package/lib/module/utils/stringUtils.js +42 -0
  174. package/lib/module/utils/stringUtils.js.map +1 -0
  175. package/lib/module/version.js +1 -1
  176. package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
  177. package/lib/typescript/config/FileBasedConfiguration.d.ts.map +1 -1
  178. package/lib/typescript/config/FileBasedConfiguration.type.d.ts +2 -0
  179. package/lib/typescript/config/FileBasedConfiguration.type.d.ts.map +1 -1
  180. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts +3 -0
  181. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts.map +1 -1
  182. package/lib/typescript/config/features/RumConfiguration.d.ts +3 -1
  183. package/lib/typescript/config/features/RumConfiguration.d.ts.map +1 -1
  184. package/lib/typescript/config/features/RumConfiguration.type.d.ts +107 -0
  185. package/lib/typescript/config/features/RumConfiguration.type.d.ts.map +1 -1
  186. package/lib/typescript/flags/DdFlags.d.ts.map +1 -1
  187. package/lib/typescript/flags/FlagsClient.d.ts +1 -1
  188. package/lib/typescript/flags/FlagsClient.d.ts.map +1 -1
  189. package/lib/typescript/index.d.ts +1 -0
  190. package/lib/typescript/index.d.ts.map +1 -1
  191. package/lib/typescript/internal.d.ts +26 -0
  192. package/lib/typescript/internal.d.ts.map +1 -0
  193. package/lib/typescript/logs/DdLogs.d.ts +1 -1
  194. package/lib/typescript/logs/DdLogs.d.ts.map +1 -1
  195. package/lib/typescript/rum/DdRum.d.ts +2 -1
  196. package/lib/typescript/rum/DdRum.d.ts.map +1 -1
  197. package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts.map +1 -1
  198. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +3 -1
  199. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts.map +1 -1
  200. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts +1 -0
  201. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts.map +1 -1
  202. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.d.ts +85 -0
  203. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.d.ts.map +1 -0
  204. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.d.ts +18 -0
  205. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.d.ts.map +1 -0
  206. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.d.ts +24 -0
  207. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.d.ts.map +1 -0
  208. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.d.ts +12 -0
  209. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.d.ts.map +1 -0
  210. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.d.ts +28 -0
  211. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.d.ts.map +1 -0
  212. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.d.ts +16 -0
  213. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.d.ts.map +1 -0
  214. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.d.ts +13 -0
  215. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.d.ts.map +1 -0
  216. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.d.ts +13 -0
  217. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.d.ts.map +1 -0
  218. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/types.d.ts +27 -0
  219. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/types.d.ts.map +1 -0
  220. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.d.ts.map +1 -1
  221. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
  222. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.d.ts.map +1 -1
  223. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts +4 -0
  224. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts.map +1 -1
  225. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.d.ts +43 -0
  226. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.d.ts.map +1 -0
  227. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts +2 -0
  228. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts.map +1 -1
  229. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts +2 -0
  230. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts.map +1 -1
  231. package/lib/typescript/rum/types.d.ts +6 -0
  232. package/lib/typescript/rum/types.d.ts.map +1 -1
  233. package/lib/typescript/sdk/AccountInfoSingleton/AccountInfoSingleton.d.ts.map +1 -1
  234. package/lib/typescript/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.d.ts.map +1 -1
  235. package/lib/typescript/sdk/DdSdkInternal.d.ts +1 -0
  236. package/lib/typescript/sdk/DdSdkInternal.d.ts.map +1 -1
  237. package/lib/typescript/sdk/UserInfoSingleton/UserInfoSingleton.d.ts.map +1 -1
  238. package/lib/typescript/specs/NativeDdFlags.d.ts +7 -2
  239. package/lib/typescript/specs/NativeDdFlags.d.ts.map +1 -1
  240. package/lib/typescript/specs/NativeDdLogs.d.ts +7 -2
  241. package/lib/typescript/specs/NativeDdLogs.d.ts.map +1 -1
  242. package/lib/typescript/specs/NativeDdRum.d.ts +13 -2
  243. package/lib/typescript/specs/NativeDdRum.d.ts.map +1 -1
  244. package/lib/typescript/specs/NativeDdSdk.d.ts +7 -2
  245. package/lib/typescript/specs/NativeDdSdk.d.ts.map +1 -1
  246. package/lib/typescript/specs/NativeDdTrace.d.ts +7 -2
  247. package/lib/typescript/specs/NativeDdTrace.d.ts.map +1 -1
  248. package/lib/typescript/trace/DdTrace.d.ts.map +1 -1
  249. package/lib/typescript/utils/stringUtils.d.ts +12 -0
  250. package/lib/typescript/utils/stringUtils.d.ts.map +1 -0
  251. package/lib/typescript/version.d.ts +1 -1
  252. package/package.json +7 -2
  253. package/src/DdSdkReactNative.tsx +11 -1
  254. package/src/__tests__/DdSdkReactNative.test.tsx +145 -20
  255. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +3 -0
  256. package/src/__tests__/internalEntry.test.ts +26 -0
  257. package/src/__tests__/mock.test.ts +1 -3
  258. package/src/__tests__/nativeSpecGetters.test.ts +102 -0
  259. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +3 -3
  260. package/src/__tests__/wrapperImportSafety.test.ts +129 -0
  261. package/src/config/FileBasedConfiguration.ts +3 -0
  262. package/src/config/FileBasedConfiguration.type.ts +2 -0
  263. package/src/config/__tests__/FileBasedConfiguration.test.ts +66 -0
  264. package/src/config/__tests__/__fixtures__/configuration-all-fields.json +8 -0
  265. package/src/config/async/AutoInstrumentationConfiguration.ts +5 -1
  266. package/src/config/features/RumConfiguration.ts +9 -0
  267. package/src/config/features/RumConfiguration.type.ts +117 -0
  268. package/src/flags/DdFlags.ts +4 -3
  269. package/src/flags/FlagsClient.ts +4 -3
  270. package/src/index.tsx +7 -0
  271. package/src/internal.ts +32 -0
  272. package/src/logs/DdLogs.ts +4 -3
  273. package/src/rum/DdRum.ts +14 -3
  274. package/src/rum/__tests__/DdRum.test.ts +14 -4
  275. package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +33 -26
  276. package/src/rum/instrumentation/interactionTracking/__tests__/BabelOptionalHandlers.test.ts +120 -0
  277. package/src/rum/instrumentation/interactionTracking/__tests__/DdBabelInteractionTracking.test.ts +82 -2
  278. package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +7 -2
  279. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +46 -0
  280. package/src/rum/instrumentation/resourceTracking/__tests__/__utils__/XMLHttpRequestMock.ts +1 -1
  281. package/src/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.ts +1 -1
  282. package/src/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
  283. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/captureHeaders.test.ts +853 -0
  284. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/compileHeaderConfig.test.ts +697 -0
  285. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/enforceSizeLimits.integration.test.ts +183 -0
  286. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/enforceSizeLimits.test.ts +337 -0
  287. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/isHeaderAllowed.test.ts +35 -0
  288. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/normalizeUrlForMatching.test.ts +176 -0
  289. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/parseResponseHeaders.test.ts +114 -0
  290. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/sensitiveHeaderBlocklist.test.ts +112 -0
  291. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/tracingHeaderExclusion.test.ts +59 -0
  292. package/src/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.ts +437 -0
  293. package/src/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.ts +339 -0
  294. package/src/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.ts +208 -0
  295. package/src/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.ts +29 -0
  296. package/src/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.ts +181 -0
  297. package/src/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.ts +59 -0
  298. package/src/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.ts +31 -0
  299. package/src/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.ts +61 -0
  300. package/src/rum/instrumentation/resourceTracking/headerCapture/types.ts +33 -0
  301. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.ts +24 -5
  302. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/__tests__/FetchProxy.test.ts +303 -0
  303. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/__tests__/ResourceReporter.test.ts +120 -0
  304. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +36 -5
  305. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +664 -2
  306. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.ts +1 -34
  307. package/src/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.ts +15 -1
  308. package/src/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.ts +16 -2
  309. package/src/rum/instrumentation/resourceTracking/requestProxy/common/__tests__/headerCapture.test.ts +164 -0
  310. package/src/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.ts +119 -0
  311. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.ts +2 -0
  312. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.ts +2 -0
  313. package/src/rum/types.ts +7 -0
  314. package/src/sdk/AccountInfoSingleton/AccountInfoSingleton.ts +2 -1
  315. package/src/sdk/AccountInfoSingleton/__tests__/AccountInfoSingleton.test.ts +59 -0
  316. package/src/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.tsx +3 -4
  317. package/src/sdk/DatadogInternalBridge/__tests__/DdSdkNativeBridge.test.tsx +35 -2
  318. package/src/sdk/DatadogProvider/Buffer/__tests__/BoundedBuffer.test.ts +5 -5
  319. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +2 -1
  320. package/src/sdk/DdSdkInternal.ts +27 -24
  321. package/src/sdk/EventMappers/__tests__/EventMapper.test.ts +2 -2
  322. package/src/sdk/UserInfoSingleton/UserInfoSingleton.ts +2 -1
  323. package/src/sdk/UserInfoSingleton/__tests__/UserInfoSingleton.test.ts +55 -0
  324. package/src/specs/NativeDdFlags.ts +14 -2
  325. package/src/specs/NativeDdLogs.ts +14 -2
  326. package/src/specs/NativeDdRum.ts +21 -2
  327. package/src/specs/NativeDdSdk.ts +14 -2
  328. package/src/specs/NativeDdTrace.ts +14 -2
  329. package/src/trace/DdTrace.ts +4 -3
  330. package/src/utils/__tests__/stringUtils.test.ts +90 -0
  331. package/src/utils/stringUtils.ts +41 -0
  332. package/src/version.ts +1 -1
@@ -0,0 +1,697 @@
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 {
10
+ DEFAULT_REQUEST_HEADERS,
11
+ DEFAULT_RESPONSE_HEADERS,
12
+ CANONICAL_REQUEST_HEADERS,
13
+ CANONICAL_RESPONSE_HEADERS
14
+ } from '../captureHeaders';
15
+ import { compileHeaderCaptureConfig } from '../compileHeaderConfig';
16
+ import { normalizeUrlForMatching } from '../normalizeUrlForMatching';
17
+
18
+ jest.mock('../../../../../InternalLog', () => ({
19
+ InternalLog: {
20
+ log: jest.fn()
21
+ }
22
+ }));
23
+
24
+ const mockLog = InternalLog.log as jest.Mock;
25
+
26
+ beforeEach(() => {
27
+ mockLog.mockClear();
28
+ });
29
+
30
+ describe('compileHeaderCaptureConfig', () => {
31
+ describe('disabled / null output', () => {
32
+ it('returns null for undefined', () => {
33
+ expect(compileHeaderCaptureConfig(undefined)).toBeNull();
34
+ });
35
+
36
+ it('returns null for empty array and logs WARN', () => {
37
+ const result = compileHeaderCaptureConfig([]);
38
+ expect(result).toBeNull();
39
+ expect(mockLog).toHaveBeenCalledWith(
40
+ expect.stringContaining(
41
+ 'headerCaptureRules is empty, no headers will be captured'
42
+ ),
43
+ SdkVerbosity.WARN
44
+ );
45
+ });
46
+
47
+ it('returns null for totally invalid value and logs WARN', () => {
48
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
+ const result = compileHeaderCaptureConfig(
50
+ 'totally-invalid-value' as any
51
+ );
52
+ expect(result).toBeNull();
53
+ expect(mockLog).toHaveBeenCalledWith(
54
+ expect.any(String),
55
+ SdkVerbosity.WARN
56
+ );
57
+ });
58
+ });
59
+
60
+ describe('"defaults" string shortcut', () => {
61
+ it('returns an array with exactly 1 rule', () => {
62
+ const result = compileHeaderCaptureConfig('defaults');
63
+ expect(result).not.toBeNull();
64
+ expect(result).toHaveLength(1);
65
+ });
66
+
67
+ it('has requestHeaderNames equal to DEFAULT_REQUEST_HEADERS', () => {
68
+ const result = compileHeaderCaptureConfig('defaults');
69
+ expect(result).not.toBeNull();
70
+ expect(result?.[0].requestHeaderNames).toEqual(
71
+ new Set(DEFAULT_REQUEST_HEADERS)
72
+ );
73
+ });
74
+
75
+ it('has responseHeaderNames equal to DEFAULT_RESPONSE_HEADERS', () => {
76
+ const result = compileHeaderCaptureConfig('defaults');
77
+ expect(result).not.toBeNull();
78
+ expect(result?.[0].responseHeaderNames).toEqual(
79
+ new Set(DEFAULT_RESPONSE_HEADERS)
80
+ );
81
+ });
82
+
83
+ it('has urlRegex matching any URL', () => {
84
+ const result = compileHeaderCaptureConfig('defaults');
85
+ expect(result).not.toBeNull();
86
+ expect(result?.[0].urlRegex.test('https://anything.com/path')).toBe(
87
+ true
88
+ );
89
+ });
90
+
91
+ it('has isScoped equal to false', () => {
92
+ const result = compileHeaderCaptureConfig('defaults');
93
+ expect(result).not.toBeNull();
94
+ expect(result?.[0].isScoped).toBe(false);
95
+ });
96
+ });
97
+
98
+ describe('array input — rule variants', () => {
99
+ it('compiles a defaults rule with default header sets', () => {
100
+ const result = compileHeaderCaptureConfig([{ type: 'defaults' }]);
101
+ expect(result).not.toBeNull();
102
+ expect(result).toHaveLength(1);
103
+ const rule = (result ?? [])[0];
104
+ expect(rule.requestHeaderNames).toEqual(
105
+ new Set(DEFAULT_REQUEST_HEADERS)
106
+ );
107
+ expect(rule.responseHeaderNames).toEqual(
108
+ new Set(DEFAULT_RESPONSE_HEADERS)
109
+ );
110
+ expect(rule.urlRegex.test('https://anything.com/path')).toBe(true);
111
+ expect(rule.isScoped).toBe(false);
112
+ });
113
+
114
+ it('compiles a matchHeaders rule with both request and response sets', () => {
115
+ const result = compileHeaderCaptureConfig([
116
+ { type: 'matchHeaders', headers: ['Content-Type', 'X-Custom'] }
117
+ ]);
118
+ expect(result).not.toBeNull();
119
+ expect(result).toHaveLength(1);
120
+ const rule = (result ?? [])[0];
121
+ expect(rule.requestHeaderNames).toEqual(
122
+ new Set(['content-type', 'x-custom'])
123
+ );
124
+ expect(rule.responseHeaderNames).toEqual(
125
+ new Set(['content-type', 'x-custom'])
126
+ );
127
+ });
128
+
129
+ it('compiles a matchRequestHeaders rule with request set only', () => {
130
+ const result = compileHeaderCaptureConfig([
131
+ {
132
+ type: 'matchRequestHeaders',
133
+ headers: ['X-Request-ID', 'Authorization']
134
+ }
135
+ ]);
136
+ expect(result).not.toBeNull();
137
+ expect(result).toHaveLength(1);
138
+ const rule = (result ?? [])[0];
139
+ expect(rule.requestHeaderNames).toEqual(
140
+ new Set(['x-request-id', 'authorization'])
141
+ );
142
+ expect(rule.responseHeaderNames).toEqual(new Set());
143
+ });
144
+
145
+ it('compiles a matchResponseHeaders rule with response set only', () => {
146
+ const result = compileHeaderCaptureConfig([
147
+ {
148
+ type: 'matchResponseHeaders',
149
+ headers: ['ETag', 'X-RateLimit-Remaining']
150
+ }
151
+ ]);
152
+ expect(result).not.toBeNull();
153
+ expect(result).toHaveLength(1);
154
+ const rule = (result ?? [])[0];
155
+ expect(rule.requestHeaderNames).toEqual(new Set());
156
+ expect(rule.responseHeaderNames).toEqual(
157
+ new Set(['etag', 'x-ratelimit-remaining'])
158
+ );
159
+ });
160
+
161
+ it('lowercases header names regardless of input casing', () => {
162
+ const result = compileHeaderCaptureConfig([
163
+ {
164
+ type: 'matchHeaders',
165
+ headers: ['X-Request-ID', 'AUTHORIZATION', 'Cache-Control']
166
+ }
167
+ ]);
168
+ expect(result).not.toBeNull();
169
+ expect(result?.[0].requestHeaderNames).toEqual(
170
+ new Set(['x-request-id', 'authorization', 'cache-control'])
171
+ );
172
+ expect(result?.[0].responseHeaderNames).toEqual(
173
+ new Set(['x-request-id', 'authorization', 'cache-control'])
174
+ );
175
+ });
176
+
177
+ it('{ type: "defaults" } in array produces rule with isScoped: false', () => {
178
+ const result = compileHeaderCaptureConfig([{ type: 'defaults' }]);
179
+ expect(result).not.toBeNull();
180
+ expect(result?.[0].isScoped).toBe(false);
181
+ });
182
+
183
+ it('matchHeaders with specific forURLs produces rule with isScoped: true', () => {
184
+ const result = compileHeaderCaptureConfig([
185
+ {
186
+ type: 'matchHeaders',
187
+ headers: ['etag'],
188
+ forURLs: ['api.example.com']
189
+ }
190
+ ]);
191
+ expect(result).not.toBeNull();
192
+ expect(result?.[0].isScoped).toBe(true);
193
+ });
194
+ });
195
+
196
+ describe('forURLs handling', () => {
197
+ it('omitting forURLs produces catch-all regex and isScoped: false', () => {
198
+ const result = compileHeaderCaptureConfig([
199
+ { type: 'matchResponseHeaders', headers: ['etag'] }
200
+ ]);
201
+ expect(result).not.toBeNull();
202
+ const { urlRegex, isScoped } = (result ?? [])[0];
203
+ expect(urlRegex.test('https://anything.com/path')).toBe(true);
204
+ expect(urlRegex.test('http://other.io')).toBe(true);
205
+ expect(isScoped).toBe(false);
206
+ });
207
+
208
+ it('forURLs: ["*"] produces catch-all regex and isScoped: false', () => {
209
+ const result = compileHeaderCaptureConfig([
210
+ {
211
+ type: 'matchResponseHeaders',
212
+ headers: ['etag'],
213
+ forURLs: ['*']
214
+ }
215
+ ]);
216
+ expect(result).not.toBeNull();
217
+ const { urlRegex, isScoped } = (result ?? [])[0];
218
+ expect(urlRegex.test('https://anything.com/path')).toBe(true);
219
+ expect(urlRegex.test('')).toBe(true);
220
+ expect(isScoped).toBe(false);
221
+ });
222
+
223
+ it('forURLs containing "*" alongside other patterns is catch-all', () => {
224
+ const result = compileHeaderCaptureConfig([
225
+ {
226
+ type: 'matchHeaders',
227
+ headers: ['x-foo'],
228
+ forURLs: ['*', 'api.example.com']
229
+ }
230
+ ]);
231
+ const { urlRegex, isScoped } = (result ?? [])[0];
232
+ expect(isScoped).toBe(false);
233
+ expect(urlRegex.test('https://other.com/path')).toBe(true);
234
+ });
235
+
236
+ it('specific forURLs patterns produce isScoped: true', () => {
237
+ const result = compileHeaderCaptureConfig([
238
+ {
239
+ type: 'matchResponseHeaders',
240
+ headers: ['etag'],
241
+ forURLs: ['api.example.com']
242
+ }
243
+ ]);
244
+ expect(result).not.toBeNull();
245
+ const { urlRegex, isScoped } = (result ?? [])[0];
246
+ expect(urlRegex.test('https://api.example.com/any')).toBe(true);
247
+ expect(urlRegex.test('https://api.example.com')).toBe(true);
248
+ expect(urlRegex.test('https://other.com/api')).toBe(false);
249
+ // Dots in the hostname are escaped (literal), not wildcards
250
+ expect(urlRegex.test('https://apiXexampleYcom/any')).toBe(false);
251
+ expect(isScoped).toBe(true);
252
+ });
253
+
254
+ it('forURLs: ["api.example.com/v2"] matches /v2 paths but not /v1', () => {
255
+ const result = compileHeaderCaptureConfig([
256
+ {
257
+ type: 'matchResponseHeaders',
258
+ headers: ['etag'],
259
+ forURLs: ['api.example.com/v2']
260
+ }
261
+ ]);
262
+ expect(result).not.toBeNull();
263
+ const { urlRegex } = (result ?? [])[0];
264
+ expect(urlRegex.test('https://api.example.com/v2/users')).toBe(
265
+ true
266
+ );
267
+ expect(urlRegex.test('https://api.example.com/v1/users')).toBe(
268
+ false
269
+ );
270
+ // Dots in hostname and path are escaped (literal), not wildcards
271
+ expect(urlRegex.test('https://apiXexampleYcom/v2/users')).toBe(
272
+ false
273
+ );
274
+ });
275
+
276
+ it('forURLs path prefix ends on a path segment boundary', () => {
277
+ const result = compileHeaderCaptureConfig([
278
+ {
279
+ type: 'matchResponseHeaders',
280
+ headers: ['etag'],
281
+ forURLs: ['api.example.com/v2']
282
+ }
283
+ ]);
284
+ const { urlRegex } = (result ?? [])[0];
285
+ expect(urlRegex.test('https://api.example.com/v2')).toBe(true);
286
+ expect(urlRegex.test('https://api.example.com/v2?page=1')).toBe(
287
+ true
288
+ );
289
+ expect(urlRegex.test('https://api.example.com/v2#top')).toBe(true);
290
+ expect(urlRegex.test('https://api.example.com/v22/users')).toBe(
291
+ false
292
+ );
293
+ expect(urlRegex.test('https://api.example.com/v2-beta')).toBe(
294
+ false
295
+ );
296
+ });
297
+
298
+ it('forURLs matches URLs with userinfo on the configured host', () => {
299
+ const result = compileHeaderCaptureConfig([
300
+ {
301
+ type: 'matchResponseHeaders',
302
+ headers: ['etag'],
303
+ forURLs: ['api.example.com/v2']
304
+ }
305
+ ]);
306
+ const { urlRegex } = (result ?? [])[0];
307
+ expect(
308
+ urlRegex.test('https://user:pass@api.example.com/v2/users')
309
+ ).toBe(true);
310
+ expect(urlRegex.test('https://user@cdn.api.example.com/v2')).toBe(
311
+ true
312
+ );
313
+ expect(
314
+ urlRegex.test('https://user:pass@api.example.com/v1/users')
315
+ ).toBe(false);
316
+ });
317
+
318
+ it('forURLs path scope applies to the resolved path', () => {
319
+ const result = compileHeaderCaptureConfig([
320
+ {
321
+ type: 'matchResponseHeaders',
322
+ headers: ['etag'],
323
+ forURLs: ['api.example.com/public']
324
+ }
325
+ ]);
326
+ const { urlRegex } = (result ?? [])[0];
327
+ const matches = (url: string) =>
328
+ urlRegex.test(normalizeUrlForMatching(url));
329
+
330
+ expect(matches('https://api.example.com/public/../private')).toBe(
331
+ false
332
+ );
333
+ expect(
334
+ matches('https://api.example.com/public/%2e%2e/private')
335
+ ).toBe(false);
336
+ expect(matches('https://api.example.com/public/\t../private')).toBe(
337
+ false
338
+ );
339
+ expect(matches('https://api.example.com/other/../public/x')).toBe(
340
+ true
341
+ );
342
+ });
343
+
344
+ it('forURLs matches the host case-insensitively and the path case-sensitively', () => {
345
+ const result = compileHeaderCaptureConfig([
346
+ {
347
+ type: 'matchResponseHeaders',
348
+ headers: ['etag'],
349
+ forURLs: ['API.Example.com/Public']
350
+ }
351
+ ]);
352
+ const { urlRegex } = (result ?? [])[0];
353
+ const matches = (url: string) =>
354
+ urlRegex.test(normalizeUrlForMatching(url));
355
+
356
+ expect(matches('https://api.example.com/Public/users')).toBe(true);
357
+ expect(matches('HTTPS://API.EXAMPLE.COM/Public/users')).toBe(true);
358
+ expect(matches('https://api.example.com/public/users')).toBe(false);
359
+ expect(matches('https://api.example.com/PUBLIC/users')).toBe(false);
360
+ });
361
+
362
+ it('forURLs normalizes configured hostnames like request hostnames', () => {
363
+ const result = compileHeaderCaptureConfig([
364
+ {
365
+ type: 'matchResponseHeaders',
366
+ headers: ['etag'],
367
+ forURLs: ['API\uFF0EExample.com/v2']
368
+ }
369
+ ]);
370
+ const { urlRegex } = (result ?? [])[0];
371
+
372
+ expect(
373
+ urlRegex.test(
374
+ normalizeUrlForMatching('https://api.example.com/v2/users')
375
+ )
376
+ ).toBe(true);
377
+ });
378
+
379
+ it('forURLs root path scope matches requests without a path', () => {
380
+ const result = compileHeaderCaptureConfig([
381
+ {
382
+ type: 'matchResponseHeaders',
383
+ headers: ['etag'],
384
+ forURLs: ['api.example.com/']
385
+ }
386
+ ]);
387
+ const { urlRegex } = (result ?? [])[0];
388
+ const matches = (url: string) =>
389
+ urlRegex.test(normalizeUrlForMatching(url));
390
+
391
+ expect(matches('https://api.example.com')).toBe(true);
392
+ expect(matches('https://api.example.com?view=home')).toBe(true);
393
+ expect(matches('https://api.example.com#top')).toBe(true);
394
+ expect(matches('https://api.example.com/users')).toBe(true);
395
+ expect(matches('https://other.example.com')).toBe(false);
396
+ });
397
+
398
+ it('forURLs path prefix ending with a slash matches nested paths', () => {
399
+ const result = compileHeaderCaptureConfig([
400
+ {
401
+ type: 'matchResponseHeaders',
402
+ headers: ['etag'],
403
+ forURLs: ['api.example.com/v2/']
404
+ }
405
+ ]);
406
+ const { urlRegex } = (result ?? [])[0];
407
+ expect(urlRegex.test('https://api.example.com/v2/users')).toBe(
408
+ true
409
+ );
410
+ expect(urlRegex.test('https://api.example.com/v2')).toBe(false);
411
+ });
412
+
413
+ it('forURLs matches subdomains but not hostnames in the path, query or userinfo', () => {
414
+ const result = compileHeaderCaptureConfig([
415
+ {
416
+ type: 'matchResponseHeaders',
417
+ headers: ['etag'],
418
+ forURLs: ['api.example.com']
419
+ }
420
+ ]);
421
+ const { urlRegex } = (result ?? [])[0];
422
+ expect(urlRegex.test('https://cdn.api.example.com/users')).toBe(
423
+ true
424
+ );
425
+ expect(urlRegex.test('https://a.b.api.example.com:8443/x')).toBe(
426
+ true
427
+ );
428
+ expect(
429
+ urlRegex.test(
430
+ 'https://unrelated.test/assets.api.example.com/users'
431
+ )
432
+ ).toBe(false);
433
+ expect(
434
+ urlRegex.test(
435
+ 'https://unrelated.test/?next=cdn.api.example.com/users'
436
+ )
437
+ ).toBe(false);
438
+ expect(
439
+ urlRegex.test('https://unrelated.test#x.api.example.com')
440
+ ).toBe(false);
441
+ expect(
442
+ urlRegex.test('https://user.api.example.com@unrelated.test/')
443
+ ).toBe(false);
444
+ expect(urlRegex.test('https://api.example.com.evil.test/')).toBe(
445
+ false
446
+ );
447
+ expect(urlRegex.test('https://notapi.example.com/')).toBe(false);
448
+ expect(
449
+ urlRegex.test('https://api.example.com@unrelated.test/users')
450
+ ).toBe(false);
451
+ expect(
452
+ urlRegex.test(
453
+ 'https://user:pass@unrelated.test/api.example.com'
454
+ )
455
+ ).toBe(false);
456
+ // URL parsers treat '\\' as '/', so this request goes to unrelated.test
457
+ expect(
458
+ urlRegex.test('https://unrelated.test\\.api.example.com/users')
459
+ ).toBe(false);
460
+ });
461
+
462
+ it('forURLs: [] (empty) skips the rule with WARN log', () => {
463
+ const result = compileHeaderCaptureConfig([
464
+ {
465
+ type: 'matchResponseHeaders',
466
+ headers: ['etag'],
467
+ forURLs: []
468
+ }
469
+ ]);
470
+ // With only one rule that gets skipped, all rules fail -> null
471
+ expect(result).toBeNull();
472
+ expect(mockLog).toHaveBeenCalledWith(
473
+ expect.stringContaining('empty forURLs'),
474
+ SdkVerbosity.WARN
475
+ );
476
+ });
477
+
478
+ it('forURLs with special regex characters treats them as literal hostname characters', () => {
479
+ // Metacharacters like '[' are escaped by escapeRegExp so they become literal matches
480
+ const result = compileHeaderCaptureConfig([
481
+ {
482
+ type: 'matchResponseHeaders',
483
+ headers: ['etag'],
484
+ forURLs: ['[special].example.com']
485
+ }
486
+ ]);
487
+ expect(result).not.toBeNull();
488
+ const rule0 = (result ?? [])[0];
489
+ expect(rule0.isScoped).toBe(true);
490
+ // The pattern is treated literally: it matches the host '[special].example.com'
491
+ expect(
492
+ rule0.urlRegex.test('https://[special].example.com/path')
493
+ ).toBe(true);
494
+ // It does NOT match hosts that would match the unescaped regex interpretation
495
+ expect(
496
+ rule0.urlRegex.test('https://xspecialx.example.com/path')
497
+ ).toBe(false);
498
+ });
499
+
500
+ it('forURLs with multiple patterns produces combined regex', () => {
501
+ const result = compileHeaderCaptureConfig([
502
+ {
503
+ type: 'matchResponseHeaders',
504
+ headers: ['etag'],
505
+ forURLs: ['api.example.com', 'cdn.example.com']
506
+ }
507
+ ]);
508
+ expect(result).not.toBeNull();
509
+ expect(result).toHaveLength(1);
510
+ const { urlRegex } = (result ?? [])[0];
511
+ expect(urlRegex.test('https://api.example.com/v2')).toBe(true);
512
+ expect(urlRegex.test('https://cdn.example.com/assets')).toBe(true);
513
+ expect(urlRegex.test('https://other.com')).toBe(false);
514
+ // Dots in hostnames are escaped (literal), not wildcards
515
+ expect(urlRegex.test('https://apiXexampleYcom/v2')).toBe(false);
516
+ expect(urlRegex.test('https://cdnXexampleYcom/assets')).toBe(false);
517
+ });
518
+ });
519
+
520
+ describe('multiple rules', () => {
521
+ it('compiles multiple rules of different types', () => {
522
+ const result = compileHeaderCaptureConfig([
523
+ { type: 'defaults' },
524
+ {
525
+ type: 'matchHeaders',
526
+ headers: ['X-Custom'],
527
+ forURLs: ['api.example.com']
528
+ },
529
+ { type: 'matchRequestHeaders', headers: ['Authorization'] },
530
+ { type: 'matchResponseHeaders', headers: ['ETag'] }
531
+ ]);
532
+ expect(result).not.toBeNull();
533
+ expect(result).toHaveLength(4);
534
+ });
535
+
536
+ it('keeps valid rules and skips invalid ones', () => {
537
+ const result = compileHeaderCaptureConfig([
538
+ { type: 'matchResponseHeaders', headers: ['etag'] },
539
+ {
540
+ type: 'matchResponseHeaders',
541
+ headers: ['etag'],
542
+ forURLs: []
543
+ } // skipped
544
+ ]);
545
+ expect(result).not.toBeNull();
546
+ expect(result).toHaveLength(1);
547
+ expect(mockLog).toHaveBeenCalledTimes(1);
548
+ });
549
+ });
550
+
551
+ describe('malformed rules', () => {
552
+ it.each([
553
+ ['null', null],
554
+ ['a string', 'defaults'],
555
+ ['a rule without type', { headers: ['etag'] }],
556
+ ['a rule with an unknown type', { type: 'all', headers: ['etag'] }],
557
+ ['a match rule without headers', { type: 'matchHeaders' }],
558
+ [
559
+ 'a match rule with non-string headers',
560
+ { type: 'matchRequestHeaders', headers: ['etag', 42] }
561
+ ],
562
+ [
563
+ 'a rule with null forURLs',
564
+ {
565
+ type: 'matchResponseHeaders',
566
+ headers: ['etag'],
567
+ forURLs: null
568
+ }
569
+ ],
570
+ [
571
+ 'a rule with non-array forURLs',
572
+ { type: 'defaults', forURLs: 'api.example.com' }
573
+ ],
574
+ ['a rule with a non-string type', { type: ['defaults'] }],
575
+ [
576
+ 'a rule whose type cannot be converted to a string',
577
+ { type: { toString: null } }
578
+ ]
579
+ ])('skips %s with a WARN log instead of throwing', (_, rule) => {
580
+ const result = compileHeaderCaptureConfig([
581
+ rule,
582
+ { type: 'matchResponseHeaders', headers: ['etag'] }
583
+ ] as any);
584
+
585
+ expect(result).toHaveLength(1);
586
+ expect(result?.[0].responseHeaderNames).toEqual(new Set(['etag']));
587
+ expect(mockLog).toHaveBeenCalledWith(
588
+ expect.stringContaining('Skipping invalid rule'),
589
+ SdkVerbosity.WARN
590
+ );
591
+ });
592
+
593
+ it('returns null when every rule is malformed', () => {
594
+ expect(
595
+ compileHeaderCaptureConfig([
596
+ null,
597
+ { type: 'matchHeaders' }
598
+ ] as any)
599
+ ).toBeNull();
600
+ });
601
+ });
602
+
603
+ describe('casing maps', () => {
604
+ it('"defaults" shortcut produces canonical casing maps', () => {
605
+ const result = compileHeaderCaptureConfig('defaults');
606
+ expect(result).not.toBeNull();
607
+ const rule = (result ?? [])[0];
608
+ expect(rule.requestHeaderCasing).toEqual(
609
+ new Map(CANONICAL_REQUEST_HEADERS)
610
+ );
611
+ expect(rule.responseHeaderCasing).toEqual(
612
+ new Map(CANONICAL_RESPONSE_HEADERS)
613
+ );
614
+ });
615
+
616
+ it('{ type: "defaults" } rule produces canonical casing maps', () => {
617
+ const result = compileHeaderCaptureConfig([{ type: 'defaults' }]);
618
+ expect(result).not.toBeNull();
619
+ const rule = (result ?? [])[0];
620
+ expect(rule.requestHeaderCasing).toEqual(
621
+ new Map(CANONICAL_REQUEST_HEADERS)
622
+ );
623
+ expect(rule.responseHeaderCasing).toEqual(
624
+ new Map(CANONICAL_RESPONSE_HEADERS)
625
+ );
626
+ });
627
+
628
+ it('matchHeaders preserves user casing in both maps', () => {
629
+ const result = compileHeaderCaptureConfig([
630
+ {
631
+ type: 'matchHeaders',
632
+ headers: ['Content-Type', 'X-Custom']
633
+ }
634
+ ]);
635
+ expect(result).not.toBeNull();
636
+ const rule = (result ?? [])[0];
637
+ expect(rule.requestHeaderCasing).toEqual(
638
+ new Map([
639
+ ['content-type', 'Content-Type'],
640
+ ['x-custom', 'X-Custom']
641
+ ])
642
+ );
643
+ expect(rule.responseHeaderCasing).toEqual(
644
+ new Map([
645
+ ['content-type', 'Content-Type'],
646
+ ['x-custom', 'X-Custom']
647
+ ])
648
+ );
649
+ });
650
+
651
+ it('matchRequestHeaders populates requestHeaderCasing only', () => {
652
+ const result = compileHeaderCaptureConfig([
653
+ { type: 'matchRequestHeaders', headers: ['X-Api-Key'] }
654
+ ]);
655
+ expect(result).not.toBeNull();
656
+ const rule = (result ?? [])[0];
657
+ expect(rule.requestHeaderCasing).toEqual(
658
+ new Map([['x-api-key', 'X-Api-Key']])
659
+ );
660
+ expect(rule.responseHeaderCasing).toEqual(new Map());
661
+ });
662
+
663
+ it('matchResponseHeaders populates responseHeaderCasing only', () => {
664
+ const result = compileHeaderCaptureConfig([
665
+ { type: 'matchResponseHeaders', headers: ['X-RateLimit'] }
666
+ ]);
667
+ expect(result).not.toBeNull();
668
+ const rule = (result ?? [])[0];
669
+ expect(rule.requestHeaderCasing).toEqual(new Map());
670
+ expect(rule.responseHeaderCasing).toEqual(
671
+ new Map([['x-ratelimit', 'X-RateLimit']])
672
+ );
673
+ });
674
+
675
+ it('each rule carries its own casing map independently', () => {
676
+ const result = compileHeaderCaptureConfig([
677
+ { type: 'defaults' },
678
+ {
679
+ type: 'matchResponseHeaders',
680
+ headers: ['content-type']
681
+ }
682
+ ]);
683
+ expect(result).not.toBeNull();
684
+ expect(result).toHaveLength(2);
685
+
686
+ // Defaults rule has canonical Title-Case
687
+ expect(result?.[0].responseHeaderCasing.get('content-type')).toBe(
688
+ 'Content-Type'
689
+ );
690
+
691
+ // Custom rule preserves user-provided lowercase
692
+ expect(result?.[1].responseHeaderCasing.get('content-type')).toBe(
693
+ 'content-type'
694
+ );
695
+ });
696
+ });
697
+ });