@datadog/mobile-react-native 3.11.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.
- package/README.md +2 -1
- package/android/build.gradle +14 -5
- package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
- package/datadog-configuration.gradle +59 -18
- package/datadog-configuration.schema.json +119 -0
- package/ios/Sources/SdkVersion.swift +1 -1
- package/lib/commonjs/DdSdkReactNative.js +6 -1
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/config/FileBasedConfiguration.js +2 -0
- package/lib/commonjs/config/FileBasedConfiguration.js.map +1 -1
- package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js +2 -1
- package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js.map +1 -1
- package/lib/commonjs/config/features/RumConfiguration.js +4 -0
- package/lib/commonjs/config/features/RumConfiguration.js.map +1 -1
- package/lib/commonjs/flags/DdFlags.js +4 -2
- package/lib/commonjs/flags/DdFlags.js.map +1 -1
- package/lib/commonjs/flags/FlagsClient.js +4 -2
- package/lib/commonjs/flags/FlagsClient.js.map +1 -1
- package/lib/commonjs/internal.js +97 -0
- package/lib/commonjs/internal.js.map +1 -0
- package/lib/commonjs/logs/DdLogs.js +4 -2
- package/lib/commonjs/logs/DdLogs.js.map +1 -1
- package/lib/commonjs/rum/DdRum.js +4 -2
- package/lib/commonjs/rum/DdRum.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +20 -15
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +5 -2
- package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js +2 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js +308 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js +275 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js +167 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js +36 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js +158 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js +58 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js +39 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js +38 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/types.js +2 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/types.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +17 -2
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +25 -3
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +2 -35
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +3 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js +8 -2
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js +88 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
- package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +2 -3
- package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -1
- package/lib/commonjs/sdk/DdSdkInternal.js +27 -22
- package/lib/commonjs/sdk/DdSdkInternal.js.map +1 -1
- package/lib/commonjs/specs/NativeDdFlags.js +19 -3
- package/lib/commonjs/specs/NativeDdFlags.js.map +1 -1
- package/lib/commonjs/specs/NativeDdLogs.js +19 -3
- package/lib/commonjs/specs/NativeDdLogs.js.map +1 -1
- package/lib/commonjs/specs/NativeDdRum.js +19 -3
- package/lib/commonjs/specs/NativeDdRum.js.map +1 -1
- package/lib/commonjs/specs/NativeDdSdk.js +19 -3
- package/lib/commonjs/specs/NativeDdSdk.js.map +1 -1
- package/lib/commonjs/specs/NativeDdTrace.js +19 -3
- package/lib/commonjs/specs/NativeDdTrace.js.map +1 -1
- package/lib/commonjs/trace/DdTrace.js +4 -2
- package/lib/commonjs/trace/DdTrace.js.map +1 -1
- package/lib/commonjs/utils/stringUtils.js +48 -0
- package/lib/commonjs/utils/stringUtils.js.map +1 -0
- package/lib/commonjs/version.js +1 -1
- package/lib/module/DdSdkReactNative.js +6 -1
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/config/FileBasedConfiguration.js +2 -0
- package/lib/module/config/FileBasedConfiguration.js.map +1 -1
- package/lib/module/config/async/AutoInstrumentationConfiguration.js +2 -1
- package/lib/module/config/async/AutoInstrumentationConfiguration.js.map +1 -1
- package/lib/module/config/features/RumConfiguration.js +4 -0
- package/lib/module/config/features/RumConfiguration.js.map +1 -1
- package/lib/module/flags/DdFlags.js +4 -2
- package/lib/module/flags/DdFlags.js.map +1 -1
- package/lib/module/flags/FlagsClient.js +5 -2
- package/lib/module/flags/FlagsClient.js.map +1 -1
- package/lib/module/internal.js +27 -0
- package/lib/module/internal.js.map +1 -0
- package/lib/module/logs/DdLogs.js +4 -2
- package/lib/module/logs/DdLogs.js.map +1 -1
- package/lib/module/rum/DdRum.js +4 -2
- package/lib/module/rum/DdRum.js.map +1 -1
- package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +20 -14
- package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +5 -2
- package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js +298 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js +268 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js +160 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js +30 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js +150 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js +51 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js +32 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js +32 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/types.js +2 -0
- package/lib/module/rum/instrumentation/resourceTracking/headerCapture/types.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +17 -2
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +25 -3
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +1 -34
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +3 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js +8 -2
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js +79 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
- package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +2 -3
- package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -1
- package/lib/module/sdk/DdSdkInternal.js +27 -22
- package/lib/module/sdk/DdSdkInternal.js.map +1 -1
- package/lib/module/specs/NativeDdFlags.js +14 -2
- package/lib/module/specs/NativeDdFlags.js.map +1 -1
- package/lib/module/specs/NativeDdLogs.js +14 -2
- package/lib/module/specs/NativeDdLogs.js.map +1 -1
- package/lib/module/specs/NativeDdRum.js +14 -2
- package/lib/module/specs/NativeDdRum.js.map +1 -1
- package/lib/module/specs/NativeDdSdk.js +14 -2
- package/lib/module/specs/NativeDdSdk.js.map +1 -1
- package/lib/module/specs/NativeDdTrace.js +14 -2
- package/lib/module/specs/NativeDdTrace.js.map +1 -1
- package/lib/module/trace/DdTrace.js +4 -2
- package/lib/module/trace/DdTrace.js.map +1 -1
- package/lib/module/utils/stringUtils.js +42 -0
- package/lib/module/utils/stringUtils.js.map +1 -0
- package/lib/module/version.js +1 -1
- package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
- package/lib/typescript/config/FileBasedConfiguration.d.ts.map +1 -1
- package/lib/typescript/config/FileBasedConfiguration.type.d.ts +2 -0
- package/lib/typescript/config/FileBasedConfiguration.type.d.ts.map +1 -1
- package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts +3 -0
- package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts.map +1 -1
- package/lib/typescript/config/features/RumConfiguration.d.ts +3 -1
- package/lib/typescript/config/features/RumConfiguration.d.ts.map +1 -1
- package/lib/typescript/config/features/RumConfiguration.type.d.ts +107 -0
- package/lib/typescript/config/features/RumConfiguration.type.d.ts.map +1 -1
- package/lib/typescript/flags/DdFlags.d.ts.map +1 -1
- package/lib/typescript/flags/FlagsClient.d.ts +1 -1
- package/lib/typescript/flags/FlagsClient.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/internal.d.ts +26 -0
- package/lib/typescript/internal.d.ts.map +1 -0
- package/lib/typescript/logs/DdLogs.d.ts +1 -1
- package/lib/typescript/logs/DdLogs.d.ts.map +1 -1
- package/lib/typescript/rum/DdRum.d.ts +1 -1
- package/lib/typescript/rum/DdRum.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +3 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.d.ts +85 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.d.ts +18 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.d.ts +24 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.d.ts +12 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.d.ts +28 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.d.ts +16 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.d.ts +13 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.d.ts +13 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/types.d.ts +27 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/types.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts +2 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.d.ts +43 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.d.ts.map +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts +2 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts +2 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts.map +1 -1
- package/lib/typescript/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.d.ts.map +1 -1
- package/lib/typescript/sdk/DdSdkInternal.d.ts +1 -0
- package/lib/typescript/sdk/DdSdkInternal.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdFlags.d.ts +7 -2
- package/lib/typescript/specs/NativeDdFlags.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdLogs.d.ts +7 -2
- package/lib/typescript/specs/NativeDdLogs.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdRum.d.ts +7 -2
- package/lib/typescript/specs/NativeDdRum.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdSdk.d.ts +7 -2
- package/lib/typescript/specs/NativeDdSdk.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdTrace.d.ts +7 -2
- package/lib/typescript/specs/NativeDdTrace.d.ts.map +1 -1
- package/lib/typescript/trace/DdTrace.d.ts.map +1 -1
- package/lib/typescript/utils/stringUtils.d.ts +12 -0
- package/lib/typescript/utils/stringUtils.d.ts.map +1 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +7 -2
- package/src/DdSdkReactNative.tsx +11 -1
- package/src/__tests__/DdSdkReactNative.test.tsx +145 -20
- package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +3 -0
- package/src/__tests__/internalEntry.test.ts +26 -0
- package/src/__tests__/mock.test.ts +1 -3
- package/src/__tests__/nativeSpecGetters.test.ts +102 -0
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +3 -3
- package/src/__tests__/wrapperImportSafety.test.ts +129 -0
- package/src/config/FileBasedConfiguration.ts +3 -0
- package/src/config/FileBasedConfiguration.type.ts +2 -0
- package/src/config/__tests__/FileBasedConfiguration.test.ts +66 -0
- package/src/config/__tests__/__fixtures__/configuration-all-fields.json +8 -0
- package/src/config/async/AutoInstrumentationConfiguration.ts +5 -1
- package/src/config/features/RumConfiguration.ts +9 -0
- package/src/config/features/RumConfiguration.type.ts +117 -0
- package/src/flags/DdFlags.ts +4 -3
- package/src/flags/FlagsClient.ts +4 -3
- package/src/index.tsx +7 -0
- package/src/internal.ts +32 -0
- package/src/logs/DdLogs.ts +4 -3
- package/src/rum/DdRum.ts +4 -3
- package/src/rum/__tests__/DdRum.test.ts +4 -4
- package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +33 -26
- package/src/rum/instrumentation/interactionTracking/__tests__/BabelOptionalHandlers.test.ts +120 -0
- package/src/rum/instrumentation/interactionTracking/__tests__/DdBabelInteractionTracking.test.ts +82 -2
- package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +7 -2
- package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +46 -0
- package/src/rum/instrumentation/resourceTracking/__tests__/__utils__/XMLHttpRequestMock.ts +1 -1
- package/src/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.ts +1 -1
- package/src/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/captureHeaders.test.ts +853 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/compileHeaderConfig.test.ts +697 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/enforceSizeLimits.integration.test.ts +183 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/enforceSizeLimits.test.ts +337 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/isHeaderAllowed.test.ts +35 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/normalizeUrlForMatching.test.ts +176 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/parseResponseHeaders.test.ts +114 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/sensitiveHeaderBlocklist.test.ts +112 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/tracingHeaderExclusion.test.ts +59 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.ts +437 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.ts +339 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.ts +208 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.ts +29 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.ts +181 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.ts +59 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.ts +31 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.ts +61 -0
- package/src/rum/instrumentation/resourceTracking/headerCapture/types.ts +33 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.ts +21 -2
- package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/__tests__/FetchProxy.test.ts +274 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/__tests__/ResourceReporter.test.ts +120 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +34 -3
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +624 -2
- package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.ts +1 -34
- package/src/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.ts +6 -1
- package/src/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.ts +16 -2
- package/src/rum/instrumentation/resourceTracking/requestProxy/common/__tests__/headerCapture.test.ts +164 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.ts +119 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.ts +2 -0
- package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.ts +2 -0
- package/src/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.tsx +3 -4
- package/src/sdk/DatadogInternalBridge/__tests__/DdSdkNativeBridge.test.tsx +35 -2
- package/src/sdk/DatadogProvider/Buffer/__tests__/BoundedBuffer.test.ts +5 -5
- package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +2 -1
- package/src/sdk/DdSdkInternal.ts +27 -24
- package/src/sdk/EventMappers/__tests__/EventMapper.test.ts +2 -2
- package/src/specs/NativeDdFlags.ts +14 -2
- package/src/specs/NativeDdLogs.ts +14 -2
- package/src/specs/NativeDdRum.ts +14 -2
- package/src/specs/NativeDdSdk.ts +14 -2
- package/src/specs/NativeDdTrace.ts +14 -2
- package/src/trace/DdTrace.ts +4 -3
- package/src/utils/__tests__/stringUtils.test.ts +90 -0
- package/src/utils/stringUtils.ts +41 -0
- package/src/version.ts +1 -1
package/src/sdk/DdSdkInternal.ts
CHANGED
|
@@ -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
|
|
31
|
+
return this.nativeSdk.initialize(configuration);
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
getConstants() {
|
|
32
|
-
return
|
|
35
|
+
return this.nativeSdk.getConstants();
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
setUserInfo(user: object): Promise<object> {
|
|
36
|
-
return
|
|
39
|
+
return this.nativeSdk.setUserInfo(user);
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
clearUserInfo(): Promise<void> {
|
|
40
|
-
return
|
|
43
|
+
return this.nativeSdk.clearUserInfo();
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
addUserExtraInfo(extraInfo: object): Promise<object> {
|
|
44
|
-
return
|
|
47
|
+
return this.nativeSdk.addUserExtraInfo(extraInfo);
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
addAttribute(key: string, value: object): Promise<void> {
|
|
48
|
-
return
|
|
51
|
+
return this.nativeSdk.addAttribute(key, value);
|
|
49
52
|
}
|
|
50
53
|
removeAttribute(key: string): Promise<void> {
|
|
51
|
-
return
|
|
54
|
+
return this.nativeSdk.removeAttribute(key);
|
|
52
55
|
}
|
|
53
56
|
addAttributes(attributes: object): Promise<void> {
|
|
54
|
-
return
|
|
57
|
+
return this.nativeSdk.addAttributes(attributes);
|
|
55
58
|
}
|
|
56
59
|
removeAttributes(keys: string[]): Promise<void> {
|
|
57
|
-
return
|
|
60
|
+
return this.nativeSdk.removeAttributes(keys);
|
|
58
61
|
}
|
|
59
62
|
setAccountInfo(account: object): Promise<object> {
|
|
60
|
-
return
|
|
63
|
+
return this.nativeSdk.setAccountInfo(account);
|
|
61
64
|
}
|
|
62
65
|
clearAccountInfo(): Promise<void> {
|
|
63
|
-
return
|
|
66
|
+
return this.nativeSdk.clearAccountInfo();
|
|
64
67
|
}
|
|
65
68
|
addAccountExtraInfo(extraInfo: object): Promise<object> {
|
|
66
|
-
return
|
|
69
|
+
return this.nativeSdk.addAccountExtraInfo(extraInfo);
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
setTrackingConsent(trackingConsent: string): Promise<void> {
|
|
70
|
-
return
|
|
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
|
|
81
|
+
return this.nativeSdk.sendTelemetryLog(message, attributes, config);
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
telemetryDebug(message: string): Promise<void> {
|
|
82
|
-
return
|
|
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
|
|
93
|
+
return this.nativeSdk.telemetryError(message, stack, kind);
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
consumeWebviewEvent(message: string): Promise<void> {
|
|
94
|
-
return
|
|
97
|
+
return this.nativeSdk.consumeWebviewEvent(message);
|
|
95
98
|
}
|
|
96
99
|
|
|
97
100
|
clearAllData(): Promise<void> {
|
|
98
|
-
return
|
|
101
|
+
return this.nativeSdk.clearAllData();
|
|
99
102
|
}
|
|
100
103
|
|
|
101
104
|
addListener(eventType: string): void {
|
|
102
|
-
return
|
|
105
|
+
return this.nativeSdk.addListener(eventType);
|
|
103
106
|
}
|
|
104
107
|
|
|
105
108
|
removeListeners(count: number): void {
|
|
106
|
-
return
|
|
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
|
|
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(
|
|
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
|
-
|
|
35
|
-
|
|
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
|
-
|
|
111
|
-
|
|
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
|
+
};
|
package/src/specs/NativeDdRum.ts
CHANGED
|
@@ -236,5 +236,17 @@ export interface Spec extends TurboModule {
|
|
|
236
236
|
): Promise<void>;
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
|
|
240
|
-
|
|
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
|
+
};
|
package/src/specs/NativeDdSdk.ts
CHANGED
|
@@ -134,5 +134,17 @@ export interface Spec extends TurboModule {
|
|
|
134
134
|
removeListeners: (count: number) => void;
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
43
|
-
|
|
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
|
+
};
|
package/src/trace/DdTrace.ts
CHANGED
|
@@ -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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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.
|
|
2
|
+
export const version = '3.12.0';
|