@scalebun-release/react-native 2.5.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/LICENSE +21 -0
- package/README.md +154 -0
- package/android/build.gradle +94 -0
- package/android/consumer-rules.pro +28 -0
- package/android/src/androidTest/java/com/scalebun/rn/ota/ScaleBunOtaVerifierInstrumentedTest.kt +112 -0
- package/android/src/main/AndroidManifest.xml +14 -0
- package/android/src/main/java/com/scalebun/core/crash/CrashStorage.kt +155 -0
- package/android/src/main/java/com/scalebun/core/crash/NativeCrashHandler.kt +93 -0
- package/android/src/main/java/com/scalebun/core/performance/ANRWatchdog.kt +100 -0
- package/android/src/main/java/com/scalebun/core/performance/AppStartCollector.kt +180 -0
- package/android/src/main/java/com/scalebun/core/performance/FrameMetricsCollector.kt +230 -0
- package/android/src/main/java/com/scalebun/core/performance/PerformanceCore.kt +165 -0
- package/android/src/main/java/com/scalebun/profiler/ProfilerModule.kt +398 -0
- package/android/src/main/java/com/scalebun/profiler/ProfilerPackage.kt +24 -0
- package/android/src/main/java/com/scalebun/profiler/collectors/CpuCollector.kt +161 -0
- package/android/src/main/java/com/scalebun/profiler/collectors/IncidentDetector.kt +223 -0
- package/android/src/main/java/com/scalebun/profiler/collectors/MemoryCollector.kt +157 -0
- package/android/src/main/java/com/scalebun/profiler/collectors/RenderCollector.kt +194 -0
- package/android/src/main/java/com/scalebun/profiler/collectors/SamplerScheduler.kt +218 -0
- package/android/src/main/java/com/scalebun/profiler/collectors/ThreadCollector.kt +142 -0
- package/android/src/main/java/com/scalebun/replaysdk/ReplaySdkModule.kt +1117 -0
- package/android/src/main/java/com/scalebun/replaysdk/ReplaySdkPackage.kt +24 -0
- package/android/src/main/java/com/scalebun/replaysdk/capture/CaptureReason.kt +47 -0
- package/android/src/main/java/com/scalebun/replaysdk/capture/FrameCaptureManager.kt +574 -0
- package/android/src/main/java/com/scalebun/replaysdk/capture/FrameCaptureScheduler.kt +187 -0
- package/android/src/main/java/com/scalebun/replaysdk/capture/UiStabilityDetector.kt +214 -0
- package/android/src/main/java/com/scalebun/replaysdk/core/ReplayConfig.kt +144 -0
- package/android/src/main/java/com/scalebun/replaysdk/core/ReplayLogger.kt +31 -0
- package/android/src/main/java/com/scalebun/replaysdk/core/SessionIdGenerator.kt +15 -0
- package/android/src/main/java/com/scalebun/replaysdk/models/ReplayModels.kt +94 -0
- package/android/src/main/java/com/scalebun/replaysdk/outbox/NativeOutbox.kt +574 -0
- package/android/src/main/java/com/scalebun/replaysdk/outbox/OutboxUploader.kt +559 -0
- package/android/src/main/java/com/scalebun/replaysdk/privacy/PrivacyMaskProcessor.kt +126 -0
- package/android/src/main/java/com/scalebun/replaysdk/session/SessionManager.kt +322 -0
- package/android/src/main/java/com/scalebun/replaysdk/storage/ReplayStorage.kt +136 -0
- package/android/src/main/java/com/scalebun/replaysdk/timeline/TimelineCollector.kt +28 -0
- package/android/src/main/java/com/scalebun/replaysdk/tracking/InteractionTracker.kt +470 -0
- package/android/src/main/java/com/scalebun/replaysdk/tracking/ScreenTracker.kt +20 -0
- package/android/src/main/java/com/scalebun/replaysdk/tracking/ScrollContextProbe.kt +188 -0
- package/android/src/main/java/com/scalebun/replaysdk/transport/ReplayTransport.kt +99 -0
- package/android/src/main/java/com/scalebun/replaysdk/voice/VoiceRecorder.kt +121 -0
- package/android/src/main/java/com/scalebun/replaysdk/voice/VoiceTranscriber.kt +170 -0
- package/android/src/main/java/com/scalebun/rn/ScaleBunPackage.kt +113 -0
- package/android/src/main/java/com/scalebun/rn/crash/ScaleBunCrashModule.kt +188 -0
- package/android/src/main/java/com/scalebun/rn/crash/ScaleBunCrashPackage.kt +22 -0
- package/android/src/main/java/com/scalebun/rn/engage/ScaleBunEngageModule.kt +579 -0
- package/android/src/main/java/com/scalebun/rn/engage/ScaleBunEngagePackage.kt +22 -0
- package/android/src/main/java/com/scalebun/rn/engage/ScaleBunNotificationPresenter.kt +110 -0
- package/android/src/main/java/com/scalebun/rn/ota/BsPatch.kt +240 -0
- package/android/src/main/java/com/scalebun/rn/ota/BundleDownloader.kt +195 -0
- package/android/src/main/java/com/scalebun/rn/ota/DeviceIntegrity.kt +81 -0
- package/android/src/main/java/com/scalebun/rn/ota/DownloadFailure.kt +55 -0
- package/android/src/main/java/com/scalebun/rn/ota/OtaProtocol.kt +244 -0
- package/android/src/main/java/com/scalebun/rn/ota/ScaleBunOtaKeyRegistry.kt +100 -0
- package/android/src/main/java/com/scalebun/rn/ota/ScaleBunOtaModule.kt +683 -0
- package/android/src/main/java/com/scalebun/rn/ota/ScaleBunOtaReleaseVerifier.kt +136 -0
- package/android/src/main/java/com/scalebun/rn/ota/SlotManager.kt +578 -0
- package/android/src/main/java/com/scalebun/rn/ota/TlsPinning.kt +118 -0
- package/android/src/main/java/com/scalebun/rn/performance/PerformanceModule.kt +217 -0
- package/android/src/main/java/com/scalebun/rn/referrer/ScaleBunInstallReferrerModule.kt +77 -0
- package/android/src/main/java/com/scalebun/rn/storage/ScaleBunStorageModule.kt +68 -0
- package/android/src/main/java/com/scalebun/storage/KvFileStore.kt +174 -0
- package/android/src/newarch/java/com/scalebun/profiler/ProfilerSpec.kt +12 -0
- package/android/src/newarch/java/com/scalebun/replaysdk/ReplaySdkSpec.kt +12 -0
- package/android/src/newarch/java/com/scalebun/rn/crash/ScaleBunCrashSpec.kt +15 -0
- package/android/src/newarch/java/com/scalebun/rn/ota/ScaleBunOtaSpec.kt +16 -0
- package/android/src/newarch/java/com/scalebun/rn/performance/PerformanceSpec.kt +12 -0
- package/android/src/newarch/java/com/scalebun/rn/referrer/ScaleBunInstallReferrerSpec.kt +14 -0
- package/android/src/newarch/java/com/scalebun/rn/storage/ScaleBunStorageSpec.kt +16 -0
- package/android/src/oldarch/java/com/scalebun/profiler/ProfilerSpec.kt +34 -0
- package/android/src/oldarch/java/com/scalebun/replaysdk/ReplaySdkSpec.kt +77 -0
- package/android/src/oldarch/java/com/scalebun/rn/crash/ScaleBunCrashSpec.kt +40 -0
- package/android/src/oldarch/java/com/scalebun/rn/ota/ScaleBunOtaSpec.kt +42 -0
- package/android/src/oldarch/java/com/scalebun/rn/performance/PerformanceSpec.kt +27 -0
- package/android/src/oldarch/java/com/scalebun/rn/referrer/ScaleBunInstallReferrerSpec.kt +18 -0
- package/android/src/oldarch/java/com/scalebun/rn/storage/ScaleBunStorageSpec.kt +26 -0
- package/bin/lib/androidCodemod.js +370 -0
- package/bin/lib/iosCodemod.js +343 -0
- package/bin/scalebun.js +1004 -0
- package/dist/scalebun.full.js +37348 -0
- package/dist/scalebun.slim.js +34137 -0
- package/ios/Capture/InteractionTracker.swift +237 -0
- package/ios/Capture/PrivacyMaskProcessor.swift +158 -0
- package/ios/Capture/ScreenshotCaptureManager.swift +398 -0
- package/ios/Capture/WindowResolver.swift +63 -0
- package/ios/Core/DeviceIdentity.swift +50 -0
- package/ios/Core/ReplayConfig.swift +100 -0
- package/ios/Core/ReplayLogger.swift +22 -0
- package/ios/Core/SessionIdGenerator.swift +18 -0
- package/ios/Crash/ScaleBunCrashBridge.mm +74 -0
- package/ios/Crash/ScaleBunCrashHandler.swift +84 -0
- package/ios/Crash/ScaleBunCrashModule.swift +98 -0
- package/ios/Crash/ScaleBunCrashSignalBridge.h +49 -0
- package/ios/Crash/ScaleBunCrashSignalBridge.m +296 -0
- package/ios/Crash/ScaleBunCrashSignalStress.c +137 -0
- package/ios/Crash/ScaleBunCrashStorage.swift +121 -0
- package/ios/Crash/ScaleBunExceptionChain.swift +71 -0
- package/ios/CrashTests/ScaleBunExceptionChainTests.swift +144 -0
- package/ios/Engage/ScaleBunEngageBridge.m +32 -0
- package/ios/Engage/ScaleBunEngageModule.swift +250 -0
- package/ios/Engage/ScaleBunPushNotificationCenter.swift +185 -0
- package/ios/Ota/BsPatch.swift +203 -0
- package/ios/Ota/BundleDownloader.swift +249 -0
- package/ios/Ota/DeviceIntegrity.swift +112 -0
- package/ios/Ota/DownloadFailure.swift +56 -0
- package/ios/Ota/OtaProtocol.swift +246 -0
- package/ios/Ota/OtaSlotManager.swift +613 -0
- package/ios/Ota/ScaleBunOtaBridge.mm +92 -0
- package/ios/Ota/ScaleBunOtaEventsModule.swift +61 -0
- package/ios/Ota/ScaleBunOtaKeyRegistry.swift +147 -0
- package/ios/Ota/ScaleBunOtaModule.swift +587 -0
- package/ios/Ota/ScaleBunOtaReleaseVerifier.swift +119 -0
- package/ios/Ota/TlsPinning.swift +222 -0
- package/ios/OtaTests/DownloadFailureTests.swift +78 -0
- package/ios/OtaTests/ScaleBunOtaVerifierTests.swift +548 -0
- package/ios/Outbox/NativeOutbox.swift +632 -0
- package/ios/Outbox/OutboxUploader.swift +578 -0
- package/ios/Performance/ScaleBunPerformanceBridge.m +32 -0
- package/ios/Performance/ScaleBunPerformanceModule.swift +290 -0
- package/ios/PrivacyInfo.xcprivacy +97 -0
- package/ios/Profiler/ScaleBunProfilerBridge.m +55 -0
- package/ios/Profiler/ScaleBunProfilerModule.swift +966 -0
- package/ios/ReplaySdk-Bridging-Header.h +2 -0
- package/ios/ReplaySdk.swift +793 -0
- package/ios/ReplaySdkBridge.m +97 -0
- package/ios/Session/SessionManager.swift +273 -0
- package/ios/Skan/ScaleBunSkanBridge.m +14 -0
- package/ios/Skan/ScaleBunSkanModule.swift +61 -0
- package/ios/Storage/ReplayStorage.swift +61 -0
- package/ios/Storage/ScaleBunKvFileStore.swift +125 -0
- package/ios/Storage/ScaleBunStorageBridge.mm +72 -0
- package/ios/Storage/ScaleBunStorageModule.swift +57 -0
- package/ios/Transport/ReplayTransport.swift +70 -0
- package/ios/VoiceRecorder.swift +145 -0
- package/lib/commonjs/analytics/EventTracker.js +598 -0
- package/lib/commonjs/analytics/automaticEvents.js +71 -0
- package/lib/commonjs/analytics/batching.js +64 -0
- package/lib/commonjs/analytics/eventLane.js +55 -0
- package/lib/commonjs/analytics/revenue.js +125 -0
- package/lib/commonjs/analytics/subscription.js +94 -0
- package/lib/commonjs/bootstrap/FeatureRegistry.js +86 -0
- package/lib/commonjs/bootstrap/SDKBootstrapper.js +748 -0
- package/lib/commonjs/bucketing/fnv1a32.js +45 -0
- package/lib/commonjs/compat/codepush.js +153 -0
- package/lib/commonjs/config/ConfigManager.js +238 -0
- package/lib/commonjs/config/configTypes.js +16 -0
- package/lib/commonjs/config/otaPolicyState.js +85 -0
- package/lib/commonjs/config/quotaState.js +435 -0
- package/lib/commonjs/core/architecture.js +45 -0
- package/lib/commonjs/core/clock/now.js +13 -0
- package/lib/commonjs/core/config/defaults.js +2 -0
- package/lib/commonjs/core/config/schema.js +512 -0
- package/lib/commonjs/core/constants/endpoints.js +19 -0
- package/lib/commonjs/core/constants/protocol.js +31 -0
- package/lib/commonjs/core/constants/timings.js +39 -0
- package/lib/commonjs/core/constants/version.js +18 -0
- package/lib/commonjs/core/context/app.js +2 -0
- package/lib/commonjs/core/context/device.js +155 -0
- package/lib/commonjs/core/context/session.js +2 -0
- package/lib/commonjs/core/context/user.js +2 -0
- package/lib/commonjs/core/contracts/IFeature.js +2 -0
- package/lib/commonjs/core/di/container.js +29 -0
- package/lib/commonjs/core/encoding/base64.js +50 -0
- package/lib/commonjs/core/id/deviceId.js +52 -0
- package/lib/commonjs/core/id/installationId.js +55 -0
- package/lib/commonjs/core/id/sessionId.js +2 -0
- package/lib/commonjs/core/lifecycle/appLifecycle.js +31 -0
- package/lib/commonjs/core/lifecycle/crashSafe.js +33 -0
- package/lib/commonjs/core/logger/errorClassification.js +107 -0
- package/lib/commonjs/core/logger/internalLogger.js +63 -0
- package/lib/commonjs/core/logger/levels.js +2 -0
- package/lib/commonjs/crypto/hmacSha256.js +132 -0
- package/lib/commonjs/debug/bootstrap.js +429 -0
- package/lib/commonjs/debug/commands.js +732 -0
- package/lib/commonjs/debug/configBuilder.js +70 -0
- package/lib/commonjs/debug/exportBridge.js +155 -0
- package/lib/commonjs/debug/hostResolver.js +42 -0
- package/lib/commonjs/debug/index.js +141 -0
- package/lib/commonjs/debug/metrics.js +39 -0
- package/lib/commonjs/debug/perf.js +186 -0
- package/lib/commonjs/debug/perfWiring.js +109 -0
- package/lib/commonjs/debug/protocol.js +121 -0
- package/lib/commonjs/debug/redaction.js +422 -0
- package/lib/commonjs/debug/replayWiring.js +149 -0
- package/lib/commonjs/debug/screenTracking.js +60 -0
- package/lib/commonjs/debug/sessionWiring.js +48 -0
- package/lib/commonjs/debug/stream.js +542 -0
- package/lib/commonjs/debug/transport.js +368 -0
- package/lib/commonjs/features/bugreport/BugReportFeature.js +112 -0
- package/lib/commonjs/features/bugreport/buildPayload.js +97 -0
- package/lib/commonjs/features/bugreport/index.js +2 -0
- package/lib/commonjs/features/crash/CrashFeature.js +86 -0
- package/lib/commonjs/features/crash/CrashReporter.js +160 -0
- package/lib/commonjs/features/crash/NativeCrashFeature.js +42 -0
- package/lib/commonjs/features/crash/capture.js +48 -0
- package/lib/commonjs/features/crash/globalHandler.js +41 -0
- package/lib/commonjs/features/crash/index.js +14 -0
- package/lib/commonjs/features/crash/nativeCrashBridge.js +361 -0
- package/lib/commonjs/features/crash/rejectionHandler.js +180 -0
- package/lib/commonjs/features/crash/scrubCrash.js +158 -0
- package/lib/commonjs/features/engage/EngageAnchor.js +132 -0
- package/lib/commonjs/features/engage/EngageArchetypeRenderers.js +4292 -0
- package/lib/commonjs/features/engage/EngageInAppView.js +2670 -0
- package/lib/commonjs/features/engage/EngageInlinePlacement.js +133 -0
- package/lib/commonjs/features/engage/EngagePromptProvider.js +1063 -0
- package/lib/commonjs/features/engage/EngagePromptView.js +1252 -0
- package/lib/commonjs/features/engage/EngageTransport.js +608 -0
- package/lib/commonjs/features/engage/EngageVariantContent.js +1778 -0
- package/lib/commonjs/features/engage/__test-support__/reactNativeStub.js +54 -0
- package/lib/commonjs/features/engage/attachmentCapture.js +48 -0
- package/lib/commonjs/features/engage/captureVoiceAttachment.js +88 -0
- package/lib/commonjs/features/engage/engageCoachmarkTour.js +106 -0
- package/lib/commonjs/features/engage/engageGameLogic.js +308 -0
- package/lib/commonjs/features/engage/engageMediaSizing.js +60 -0
- package/lib/commonjs/features/engage/engageMultiStepSheet.js +43 -0
- package/lib/commonjs/features/engage/engageOutcome.js +118 -0
- package/lib/commonjs/features/engage/engagePushTokenBridge.js +72 -0
- package/lib/commonjs/features/engage/engageShakeBridge.js +62 -0
- package/lib/commonjs/features/engage/engageSignals.js +39 -0
- package/lib/commonjs/features/engage/engageStoreReviewBridge.js +49 -0
- package/lib/commonjs/features/engage/engageTestSeenStore.js +99 -0
- package/lib/commonjs/features/engage/engageThrottle.js +404 -0
- package/lib/commonjs/features/engage/engageTriggerEngine.js +365 -0
- package/lib/commonjs/features/engage/engageTypes.js +116 -0
- package/lib/commonjs/features/engage/engageVariantResolver.js +143 -0
- package/lib/commonjs/features/engage/engageWindowInsets.js +98 -0
- package/lib/commonjs/features/engage/gestureTriggerDetector.js +85 -0
- package/lib/commonjs/features/engage/transcription/TranscriptionProvider.js +55 -0
- package/lib/commonjs/features/install-referrer/installReferrer.js +113 -0
- package/lib/commonjs/features/journey/ScaleBunDebugRoot.js +1038 -0
- package/lib/commonjs/features/journey/ScaleBunFlatList.js +39 -0
- package/lib/commonjs/features/journey/ScaleBunImpression.js +113 -0
- package/lib/commonjs/features/journey/ScaleBunScrollView.js +102 -0
- package/lib/commonjs/features/journey/ScaleBunSectionList.js +39 -0
- package/lib/commonjs/features/journey/autoInstrumentScroll.js +161 -0
- package/lib/commonjs/features/journey/calibrationContext.js +42 -0
- package/lib/commonjs/features/journey/gestureBuffer.js +63 -0
- package/lib/commonjs/features/journey/gestureDetector.js +176 -0
- package/lib/commonjs/features/journey/impression.js +93 -0
- package/lib/commonjs/features/journey/interactionProtocol.js +168 -0
- package/lib/commonjs/features/journey/journeyManager.js +466 -0
- package/lib/commonjs/features/journey/journeyTypes.js +55 -0
- package/lib/commonjs/features/journey/nativeScroll.js +85 -0
- package/lib/commonjs/features/journey/navDetector.js +161 -0
- package/lib/commonjs/features/journey/screenshotHelper.js +136 -0
- package/lib/commonjs/features/journey/scrollContext.js +154 -0
- package/lib/commonjs/features/journey/targetGeometry.js +185 -0
- package/lib/commonjs/features/journey/targetRegistry.js +53 -0
- package/lib/commonjs/features/journey/touchTarget.js +249 -0
- package/lib/commonjs/features/journey/uiState.js +188 -0
- package/lib/commonjs/features/navigation/AutoScreenDetector.js +607 -0
- package/lib/commonjs/features/network/NetworkFeature.js +216 -0
- package/lib/commonjs/features/network/index.js +23 -0
- package/lib/commonjs/features/network/thirdParty.js +151 -0
- package/lib/commonjs/features/ota/OtaEventEmitter.js +129 -0
- package/lib/commonjs/features/ota/OtaOrchestrator.js +1309 -0
- package/lib/commonjs/features/ota/OtaTypes.js +6 -0
- package/lib/commonjs/features/ota/deviceAttributes.js +48 -0
- package/lib/commonjs/features/ota/environment.js +172 -0
- package/lib/commonjs/features/ota/geoCountry.js +93 -0
- package/lib/commonjs/features/ota/retry.js +96 -0
- package/lib/commonjs/features/ota/signedDownload.js +187 -0
- package/lib/commonjs/features/ota/useOtaUpdate.js +106 -0
- package/lib/commonjs/features/performance/PerformanceFeature.js +649 -0
- package/lib/commonjs/features/performance/collectors/AppLaunchCollector.js +122 -0
- package/lib/commonjs/features/performance/collectors/AutoScreenLoadCollector.js +232 -0
- package/lib/commonjs/features/performance/collectors/CustomTraceCollector.js +99 -0
- package/lib/commonjs/features/performance/collectors/FrameMetricsCollector.js +184 -0
- package/lib/commonjs/features/performance/collectors/JsStallCollector.js +165 -0
- package/lib/commonjs/features/performance/collectors/NetworkPerfCollector.js +59 -0
- package/lib/commonjs/features/performance/collectors/ScreenLoadCollector.js +78 -0
- package/lib/commonjs/features/performance/collectors/UiHangCollector.js +78 -0
- package/lib/commonjs/features/performance/config.js +58 -0
- package/lib/commonjs/features/performance/getNativePerformanceModule.js +44 -0
- package/lib/commonjs/features/performance/index.js +58 -0
- package/lib/commonjs/features/performance/metrics/MetricsEngine.js +148 -0
- package/lib/commonjs/features/performance/models.js +48 -0
- package/lib/commonjs/features/performance/transport/PerformanceTransport.js +168 -0
- package/lib/commonjs/features/profiler/ProfilerFeature.js +600 -0
- package/lib/commonjs/features/profiler/config.js +151 -0
- package/lib/commonjs/features/profiler/contracts.js +62 -0
- package/lib/commonjs/features/profiler/index.js +40 -0
- package/lib/commonjs/features/profiler/models.js +112 -0
- package/lib/commonjs/features/profiler/transport/ProfilerTransport.js +94 -0
- package/lib/commonjs/features/replay/bridge/adapters/bridgeAdapter.js +203 -0
- package/lib/commonjs/features/replay/bridge/eventEmitter.js +128 -0
- package/lib/commonjs/features/replay/bridge/nativeModule.js +95 -0
- package/lib/commonjs/features/replay/bridge/nativeQuota.js +121 -0
- package/lib/commonjs/features/replay/core/clock/clock.js +47 -0
- package/lib/commonjs/features/replay/core/config/defaults.js +88 -0
- package/lib/commonjs/features/replay/core/config/validator.js +109 -0
- package/lib/commonjs/features/replay/core/env/environmentDetector.js +28 -0
- package/lib/commonjs/features/replay/core/errors/safeCall.js +42 -0
- package/lib/commonjs/features/replay/core/ids/sessionId.js +53 -0
- package/lib/commonjs/features/replay/core/logger/logger.js +36 -0
- package/lib/commonjs/features/replay/core/privacy/privacyTypes.js +34 -0
- package/lib/commonjs/features/replay/core/queue/boundedQueue.js +71 -0
- package/lib/commonjs/features/replay/integrations/alert/alertInstrumentation.js +259 -0
- package/lib/commonjs/features/replay/integrations/logs/consoleIntegration.js +139 -0
- package/lib/commonjs/features/replay/integrations/network/networkAdapter.js +77 -0
- package/lib/commonjs/features/replay/integrations/react-navigation/navigationIntegration.js +88 -0
- package/lib/commonjs/features/replay/integrations/touch/ReplayRoot.js +103 -0
- package/lib/commonjs/features/replay/pipeline/batching/batchManager.js +119 -0
- package/lib/commonjs/features/replay/pipeline/envelope/envelopeBuilder.js +52 -0
- package/lib/commonjs/features/replay/pipeline/retry/retryPolicy.js +53 -0
- package/lib/commonjs/features/replay/pipeline/transport/transportTypes.js +67 -0
- package/lib/commonjs/features/replay/public/api.js +336 -0
- package/lib/commonjs/features/replay/public/enums.js +85 -0
- package/lib/commonjs/features/replay/public/types.js +6 -0
- package/lib/commonjs/features/replay/replay/breadcrumbs/breadcrumbCollector.js +119 -0
- package/lib/commonjs/features/replay/replay/frames/frameModels.js +40 -0
- package/lib/commonjs/features/replay/replay/session/sessionOrchestrator.js +279 -0
- package/lib/commonjs/features/replay/replay/timeline/timelineModels.js +120 -0
- package/lib/commonjs/features/replay/transport/BackendReplayTransport.js +175 -0
- package/lib/commonjs/features/replay/transport/CompositeReplayTransport.js +75 -0
- package/lib/commonjs/features/replay/transport/DesktopReplayTransport.js +124 -0
- package/lib/commonjs/features/replay/transport/ReplayTransport.js +2 -0
- package/lib/commonjs/features/session/BackendSessionAdapter.js +1915 -0
- package/lib/commonjs/features/session/DesktopSessionTransport.js +124 -0
- package/lib/commonjs/features/session/JourneyEventPipeline.js +244 -0
- package/lib/commonjs/features/session/ReplayCaptureManager.js +1253 -0
- package/lib/commonjs/features/session/ScrollTracker.js +147 -0
- package/lib/commonjs/features/session/SessionManager.js +1448 -0
- package/lib/commonjs/features/session/SyncDecisionEngine.js +95 -0
- package/lib/commonjs/features/session/frameLink.js +36 -0
- package/lib/commonjs/features/session/frameScrollState.js +41 -0
- package/lib/commonjs/features/session/index.js +84 -0
- package/lib/commonjs/features/session/nativeCapture.js +53 -0
- package/lib/commonjs/features/session/outboxFrameCapture.js +83 -0
- package/lib/commonjs/features/session/sessionTypes.js +230 -0
- package/lib/commonjs/features/session/viewportPlausibility.js +143 -0
- package/lib/commonjs/features/skan/skanBridge.js +54 -0
- package/lib/commonjs/features/skan/skanConversionManager.js +134 -0
- package/lib/commonjs/index.js +267 -0
- package/lib/commonjs/integrations/fetch/fetchInterceptor.js +174 -0
- package/lib/commonjs/integrations/navigation/screenTracker.js +2 -0
- package/lib/commonjs/integrations/network/bodyCapture.js +336 -0
- package/lib/commonjs/integrations/xhr/xhrInterceptor.js +224 -0
- package/lib/commonjs/metro/composeSourceMap.js +105 -0
- package/lib/commonjs/metro/featureModules.js +131 -0
- package/lib/commonjs/metro/index.js +230 -0
- package/lib/commonjs/metro/optionalDependencyStub.js +6 -0
- package/lib/commonjs/metro/optionalModules.js +31 -0
- package/lib/commonjs/metro/serializerCompose.js +161 -0
- package/lib/commonjs/pipeline/dispatcher/dispatcher.js +28 -0
- package/lib/commonjs/pipeline/envelope/envelope.js +17 -0
- package/lib/commonjs/pipeline/envelope/serializer.js +14 -0
- package/lib/commonjs/pipeline/processors/dedupe.js +2 -0
- package/lib/commonjs/pipeline/processors/enrich.js +16 -0
- package/lib/commonjs/pipeline/processors/sampling.js +2 -0
- package/lib/commonjs/pipeline/processors/sanitize.js +28 -0
- package/lib/commonjs/pipeline/queue/flushQueue.js +107 -0
- package/lib/commonjs/pipeline/queue/memoryQueue.js +31 -0
- package/lib/commonjs/pipeline/queue/persistentQueue.js +342 -0
- package/lib/commonjs/pipeline/queue/queuePolicy.js +2 -0
- package/lib/commonjs/pipeline/scheduler/flushScheduler.js +45 -0
- package/lib/commonjs/pipeline/scheduler/retryPolicy.js +15 -0
- package/lib/commonjs/public/ScaleBunErrorBoundary.js +91 -0
- package/lib/commonjs/public/ScaleBunFacade.js +2044 -0
- package/lib/commonjs/public/ScaleBunProvider.js +62 -0
- package/lib/commonjs/public/typedTracker.js +79 -0
- package/lib/commonjs/public/types.js +6 -0
- package/lib/commonjs/push/PushManager.js +270 -0
- package/lib/commonjs/push/adapters/ManualAdapter.js +86 -0
- package/lib/commonjs/push/adapters/NativeBridgeAdapter.js +131 -0
- package/lib/commonjs/push/adapters/NoopAdapter.js +45 -0
- package/lib/commonjs/push/adapters/RNFirebaseMessagingAdapter.js +248 -0
- package/lib/commonjs/push/adapters/loadMessaging.js +29 -0
- package/lib/commonjs/push/adapters/loadNotifee.js +36 -0
- package/lib/commonjs/push/adapters/selectAdapter.js +153 -0
- package/lib/commonjs/push/detect/capabilities.js +136 -0
- package/lib/commonjs/push/index.js +33 -0
- package/lib/commonjs/push/native/nativeNotifications.js +168 -0
- package/lib/commonjs/push/types.js +2 -0
- package/lib/commonjs/specs/NativeReplaySdk.js +28 -0
- package/lib/commonjs/specs/NativeScaleBunCrash.js +30 -0
- package/lib/commonjs/specs/NativeScaleBunInstallReferrer.js +24 -0
- package/lib/commonjs/specs/NativeScaleBunOta.js +32 -0
- package/lib/commonjs/specs/NativeScaleBunPerformance.js +25 -0
- package/lib/commonjs/specs/NativeScaleBunProfiler.js +26 -0
- package/lib/commonjs/specs/NativeScaleBunStorage.js +40 -0
- package/lib/commonjs/storage/StorageBackend.js +240 -0
- package/lib/commonjs/storage/db/sqlite.js +2 -0
- package/lib/commonjs/storage/files/fileStore.js +2 -0
- package/lib/commonjs/transport/auth/sdkSession.js +28 -0
- package/lib/commonjs/transport/backoff/exponentialJitter.js +16 -0
- package/lib/commonjs/transport/http/endpoints.js +46 -0
- package/lib/commonjs/transport/http/httpClient.js +72 -0
- package/lib/commonjs/transport/rateLimit/retryAfter.js +2 -0
- package/lib/commonjs/transport/signing/requestSigner.js +2 -0
- package/lib/commonjs/vendor/protocol/index.js +327 -0
- package/lib/commonjs/vendor/protocol/internal/validation.js +429 -0
- package/lib/commonjs/vendor/sdk-contracts/bridge.js +2 -0
- package/lib/commonjs/vendor/sdk-contracts/config.js +2 -0
- package/lib/commonjs/vendor/sdk-contracts/events.js +2 -0
- package/lib/commonjs/vendor/sdk-contracts/features.js +2 -0
- package/lib/commonjs/vendor/sdk-contracts/index.js +2 -0
- package/lib/commonjs/vendor/sdk-contracts/platform.js +2 -0
- package/lib/commonjs/vendor/sdk-contracts/session-boundary.js +6 -0
- package/lib/commonjs/vendor/sdk-contracts/session.js +2 -0
- package/lib/commonjs/vendor/vendor.manifest +10 -0
- package/lib/module/analytics/EventTracker.js +592 -0
- package/lib/module/analytics/automaticEvents.js +63 -0
- package/lib/module/analytics/batching.js +55 -0
- package/lib/module/analytics/eventLane.js +47 -0
- package/lib/module/analytics/revenue.js +117 -0
- package/lib/module/analytics/subscription.js +86 -0
- package/lib/module/bootstrap/FeatureRegistry.js +79 -0
- package/lib/module/bootstrap/SDKBootstrapper.js +742 -0
- package/lib/module/bucketing/fnv1a32.js +37 -0
- package/lib/module/compat/codepush.js +147 -0
- package/lib/module/config/ConfigManager.js +230 -0
- package/lib/module/config/configTypes.js +10 -0
- package/lib/module/config/otaPolicyState.js +76 -0
- package/lib/module/config/quotaState.js +423 -0
- package/lib/module/core/architecture.js +38 -0
- package/lib/module/core/clock/now.js +7 -0
- package/lib/module/core/config/defaults.js +2 -0
- package/lib/module/core/config/schema.js +506 -0
- package/lib/module/core/constants/endpoints.js +13 -0
- package/lib/module/core/constants/protocol.js +25 -0
- package/lib/module/core/constants/timings.js +26 -0
- package/lib/module/core/constants/version.js +12 -0
- package/lib/module/core/context/app.js +2 -0
- package/lib/module/core/context/device.js +143 -0
- package/lib/module/core/context/session.js +2 -0
- package/lib/module/core/context/user.js +2 -0
- package/lib/module/core/contracts/IFeature.js +2 -0
- package/lib/module/core/di/container.js +22 -0
- package/lib/module/core/encoding/base64.js +44 -0
- package/lib/module/core/id/deviceId.js +45 -0
- package/lib/module/core/id/installationId.js +50 -0
- package/lib/module/core/id/sessionId.js +2 -0
- package/lib/module/core/lifecycle/appLifecycle.js +25 -0
- package/lib/module/core/lifecycle/crashSafe.js +26 -0
- package/lib/module/core/logger/errorClassification.js +96 -0
- package/lib/module/core/logger/internalLogger.js +59 -0
- package/lib/module/core/logger/levels.js +2 -0
- package/lib/module/crypto/hmacSha256.js +126 -0
- package/lib/module/debug/bootstrap.js +393 -0
- package/lib/module/debug/commands.js +726 -0
- package/lib/module/debug/configBuilder.js +63 -0
- package/lib/module/debug/exportBridge.js +148 -0
- package/lib/module/debug/hostResolver.js +37 -0
- package/lib/module/debug/index.js +13 -0
- package/lib/module/debug/metrics.js +33 -0
- package/lib/module/debug/perf.js +180 -0
- package/lib/module/debug/perfWiring.js +102 -0
- package/lib/module/debug/protocol.js +19 -0
- package/lib/module/debug/redaction.js +411 -0
- package/lib/module/debug/replayWiring.js +139 -0
- package/lib/module/debug/screenTracking.js +53 -0
- package/lib/module/debug/sessionWiring.js +43 -0
- package/lib/module/debug/stream.js +536 -0
- package/lib/module/debug/transport.js +362 -0
- package/lib/module/features/bugreport/BugReportFeature.js +105 -0
- package/lib/module/features/bugreport/buildPayload.js +91 -0
- package/lib/module/features/bugreport/index.js +2 -0
- package/lib/module/features/crash/CrashFeature.js +79 -0
- package/lib/module/features/crash/CrashReporter.js +151 -0
- package/lib/module/features/crash/NativeCrashFeature.js +36 -0
- package/lib/module/features/crash/capture.js +42 -0
- package/lib/module/features/crash/globalHandler.js +36 -0
- package/lib/module/features/crash/index.js +8 -0
- package/lib/module/features/crash/nativeCrashBridge.js +350 -0
- package/lib/module/features/crash/rejectionHandler.js +171 -0
- package/lib/module/features/crash/scrubCrash.js +149 -0
- package/lib/module/features/engage/EngageAnchor.js +121 -0
- package/lib/module/features/engage/EngageArchetypeRenderers.js +4264 -0
- package/lib/module/features/engage/EngageInAppView.js +2656 -0
- package/lib/module/features/engage/EngageInlinePlacement.js +123 -0
- package/lib/module/features/engage/EngagePromptProvider.js +1054 -0
- package/lib/module/features/engage/EngagePromptView.js +1243 -0
- package/lib/module/features/engage/EngageTransport.js +602 -0
- package/lib/module/features/engage/EngageVariantContent.js +1771 -0
- package/lib/module/features/engage/__test-support__/reactNativeStub.js +52 -0
- package/lib/module/features/engage/attachmentCapture.js +42 -0
- package/lib/module/features/engage/captureVoiceAttachment.js +80 -0
- package/lib/module/features/engage/engageCoachmarkTour.js +94 -0
- package/lib/module/features/engage/engageGameLogic.js +287 -0
- package/lib/module/features/engage/engageMediaSizing.js +51 -0
- package/lib/module/features/engage/engageMultiStepSheet.js +35 -0
- package/lib/module/features/engage/engageOutcome.js +108 -0
- package/lib/module/features/engage/engagePushTokenBridge.js +65 -0
- package/lib/module/features/engage/engageShakeBridge.js +56 -0
- package/lib/module/features/engage/engageSignals.js +34 -0
- package/lib/module/features/engage/engageStoreReviewBridge.js +43 -0
- package/lib/module/features/engage/engageTestSeenStore.js +92 -0
- package/lib/module/features/engage/engageThrottle.js +390 -0
- package/lib/module/features/engage/engageTriggerEngine.js +360 -0
- package/lib/module/features/engage/engageTypes.js +110 -0
- package/lib/module/features/engage/engageVariantResolver.js +135 -0
- package/lib/module/features/engage/engageWindowInsets.js +89 -0
- package/lib/module/features/engage/gestureTriggerDetector.js +80 -0
- package/lib/module/features/engage/transcription/TranscriptionProvider.js +46 -0
- package/lib/module/features/install-referrer/installReferrer.js +104 -0
- package/lib/module/features/journey/ScaleBunDebugRoot.js +1030 -0
- package/lib/module/features/journey/ScaleBunFlatList.js +32 -0
- package/lib/module/features/journey/ScaleBunImpression.js +105 -0
- package/lib/module/features/journey/ScaleBunScrollView.js +95 -0
- package/lib/module/features/journey/ScaleBunSectionList.js +32 -0
- package/lib/module/features/journey/autoInstrumentScroll.js +155 -0
- package/lib/module/features/journey/calibrationContext.js +35 -0
- package/lib/module/features/journey/gestureBuffer.js +56 -0
- package/lib/module/features/journey/gestureDetector.js +169 -0
- package/lib/module/features/journey/impression.js +84 -0
- package/lib/module/features/journey/interactionProtocol.js +158 -0
- package/lib/module/features/journey/journeyManager.js +459 -0
- package/lib/module/features/journey/journeyTypes.js +49 -0
- package/lib/module/features/journey/nativeScroll.js +77 -0
- package/lib/module/features/journey/navDetector.js +154 -0
- package/lib/module/features/journey/screenshotHelper.js +129 -0
- package/lib/module/features/journey/scrollContext.js +142 -0
- package/lib/module/features/journey/targetGeometry.js +175 -0
- package/lib/module/features/journey/targetRegistry.js +44 -0
- package/lib/module/features/journey/touchTarget.js +241 -0
- package/lib/module/features/journey/uiState.js +176 -0
- package/lib/module/features/navigation/AutoScreenDetector.js +601 -0
- package/lib/module/features/network/NetworkFeature.js +209 -0
- package/lib/module/features/network/index.js +17 -0
- package/lib/module/features/network/thirdParty.js +142 -0
- package/lib/module/features/ota/OtaEventEmitter.js +123 -0
- package/lib/module/features/ota/OtaOrchestrator.js +1302 -0
- package/lib/module/features/ota/OtaTypes.js +2 -0
- package/lib/module/features/ota/deviceAttributes.js +43 -0
- package/lib/module/features/ota/environment.js +165 -0
- package/lib/module/features/ota/geoCountry.js +86 -0
- package/lib/module/features/ota/retry.js +87 -0
- package/lib/module/features/ota/signedDownload.js +174 -0
- package/lib/module/features/ota/useOtaUpdate.js +100 -0
- package/lib/module/features/performance/PerformanceFeature.js +643 -0
- package/lib/module/features/performance/collectors/AppLaunchCollector.js +115 -0
- package/lib/module/features/performance/collectors/AutoScreenLoadCollector.js +225 -0
- package/lib/module/features/performance/collectors/CustomTraceCollector.js +92 -0
- package/lib/module/features/performance/collectors/FrameMetricsCollector.js +177 -0
- package/lib/module/features/performance/collectors/JsStallCollector.js +158 -0
- package/lib/module/features/performance/collectors/NetworkPerfCollector.js +52 -0
- package/lib/module/features/performance/collectors/ScreenLoadCollector.js +71 -0
- package/lib/module/features/performance/collectors/UiHangCollector.js +71 -0
- package/lib/module/features/performance/config.js +51 -0
- package/lib/module/features/performance/getNativePerformanceModule.js +39 -0
- package/lib/module/features/performance/index.js +9 -0
- package/lib/module/features/performance/metrics/MetricsEngine.js +139 -0
- package/lib/module/features/performance/models.js +42 -0
- package/lib/module/features/performance/transport/PerformanceTransport.js +162 -0
- package/lib/module/features/profiler/ProfilerFeature.js +594 -0
- package/lib/module/features/profiler/config.js +143 -0
- package/lib/module/features/profiler/contracts.js +56 -0
- package/lib/module/features/profiler/index.js +11 -0
- package/lib/module/features/profiler/models.js +106 -0
- package/lib/module/features/profiler/transport/ProfilerTransport.js +87 -0
- package/lib/module/features/replay/bridge/adapters/bridgeAdapter.js +198 -0
- package/lib/module/features/replay/bridge/eventEmitter.js +122 -0
- package/lib/module/features/replay/bridge/nativeModule.js +89 -0
- package/lib/module/features/replay/bridge/nativeQuota.js +109 -0
- package/lib/module/features/replay/core/clock/clock.js +37 -0
- package/lib/module/features/replay/core/config/defaults.js +82 -0
- package/lib/module/features/replay/core/config/validator.js +103 -0
- package/lib/module/features/replay/core/env/environmentDetector.js +22 -0
- package/lib/module/features/replay/core/errors/safeCall.js +35 -0
- package/lib/module/features/replay/core/ids/sessionId.js +44 -0
- package/lib/module/features/replay/core/logger/logger.js +29 -0
- package/lib/module/features/replay/core/privacy/privacyTypes.js +27 -0
- package/lib/module/features/replay/core/queue/boundedQueue.js +64 -0
- package/lib/module/features/replay/integrations/alert/alertInstrumentation.js +252 -0
- package/lib/module/features/replay/integrations/logs/consoleIntegration.js +131 -0
- package/lib/module/features/replay/integrations/network/networkAdapter.js +70 -0
- package/lib/module/features/replay/integrations/react-navigation/navigationIntegration.js +82 -0
- package/lib/module/features/replay/integrations/touch/ReplayRoot.js +96 -0
- package/lib/module/features/replay/pipeline/batching/batchManager.js +113 -0
- package/lib/module/features/replay/pipeline/envelope/envelopeBuilder.js +43 -0
- package/lib/module/features/replay/pipeline/retry/retryPolicy.js +45 -0
- package/lib/module/features/replay/pipeline/transport/transportTypes.js +60 -0
- package/lib/module/features/replay/public/api.js +332 -0
- package/lib/module/features/replay/public/enums.js +85 -0
- package/lib/module/features/replay/public/types.js +2 -0
- package/lib/module/features/replay/replay/breadcrumbs/breadcrumbCollector.js +113 -0
- package/lib/module/features/replay/replay/frames/frameModels.js +33 -0
- package/lib/module/features/replay/replay/session/sessionOrchestrator.js +272 -0
- package/lib/module/features/replay/replay/timeline/timelineModels.js +108 -0
- package/lib/module/features/replay/transport/BackendReplayTransport.js +169 -0
- package/lib/module/features/replay/transport/CompositeReplayTransport.js +68 -0
- package/lib/module/features/replay/transport/DesktopReplayTransport.js +119 -0
- package/lib/module/features/replay/transport/ReplayTransport.js +2 -0
- package/lib/module/features/session/BackendSessionAdapter.js +1908 -0
- package/lib/module/features/session/DesktopSessionTransport.js +118 -0
- package/lib/module/features/session/JourneyEventPipeline.js +239 -0
- package/lib/module/features/session/ReplayCaptureManager.js +1248 -0
- package/lib/module/features/session/ScrollTracker.js +141 -0
- package/lib/module/features/session/SessionManager.js +1443 -0
- package/lib/module/features/session/SyncDecisionEngine.js +88 -0
- package/lib/module/features/session/frameLink.js +29 -0
- package/lib/module/features/session/frameScrollState.js +34 -0
- package/lib/module/features/session/index.js +35 -0
- package/lib/module/features/session/nativeCapture.js +45 -0
- package/lib/module/features/session/outboxFrameCapture.js +77 -0
- package/lib/module/features/session/sessionTypes.js +226 -0
- package/lib/module/features/session/viewportPlausibility.js +137 -0
- package/lib/module/features/skan/skanBridge.js +48 -0
- package/lib/module/features/skan/skanConversionManager.js +128 -0
- package/lib/module/index.js +80 -0
- package/lib/module/integrations/fetch/fetchInterceptor.js +169 -0
- package/lib/module/integrations/navigation/screenTracker.js +2 -0
- package/lib/module/integrations/network/bodyCapture.js +320 -0
- package/lib/module/integrations/xhr/xhrInterceptor.js +219 -0
- package/lib/module/metro/composeSourceMap.js +97 -0
- package/lib/module/metro/featureModules.js +123 -0
- package/lib/module/metro/index.js +218 -0
- package/lib/module/metro/optionalDependencyStub.js +14 -0
- package/lib/module/metro/optionalModules.js +25 -0
- package/lib/module/metro/serializerCompose.js +152 -0
- package/lib/module/pipeline/dispatcher/dispatcher.js +21 -0
- package/lib/module/pipeline/envelope/envelope.js +11 -0
- package/lib/module/pipeline/envelope/serializer.js +8 -0
- package/lib/module/pipeline/processors/dedupe.js +2 -0
- package/lib/module/pipeline/processors/enrich.js +10 -0
- package/lib/module/pipeline/processors/sampling.js +2 -0
- package/lib/module/pipeline/processors/sanitize.js +22 -0
- package/lib/module/pipeline/queue/flushQueue.js +102 -0
- package/lib/module/pipeline/queue/memoryQueue.js +24 -0
- package/lib/module/pipeline/queue/persistentQueue.js +336 -0
- package/lib/module/pipeline/queue/queuePolicy.js +2 -0
- package/lib/module/pipeline/scheduler/flushScheduler.js +38 -0
- package/lib/module/pipeline/scheduler/retryPolicy.js +9 -0
- package/lib/module/public/ScaleBunErrorBoundary.js +82 -0
- package/lib/module/public/ScaleBunFacade.js +2038 -0
- package/lib/module/public/ScaleBunProvider.js +54 -0
- package/lib/module/public/typedTracker.js +72 -0
- package/lib/module/public/types.js +2 -0
- package/lib/module/push/PushManager.js +263 -0
- package/lib/module/push/adapters/ManualAdapter.js +79 -0
- package/lib/module/push/adapters/NativeBridgeAdapter.js +124 -0
- package/lib/module/push/adapters/NoopAdapter.js +38 -0
- package/lib/module/push/adapters/RNFirebaseMessagingAdapter.js +241 -0
- package/lib/module/push/adapters/loadMessaging.js +23 -0
- package/lib/module/push/adapters/loadNotifee.js +30 -0
- package/lib/module/push/adapters/selectAdapter.js +147 -0
- package/lib/module/push/detect/capabilities.js +130 -0
- package/lib/module/push/index.js +9 -0
- package/lib/module/push/native/nativeNotifications.js +155 -0
- package/lib/module/push/types.js +2 -0
- package/lib/module/specs/NativeReplaySdk.js +24 -0
- package/lib/module/specs/NativeScaleBunCrash.js +26 -0
- package/lib/module/specs/NativeScaleBunInstallReferrer.js +20 -0
- package/lib/module/specs/NativeScaleBunOta.js +28 -0
- package/lib/module/specs/NativeScaleBunPerformance.js +21 -0
- package/lib/module/specs/NativeScaleBunProfiler.js +22 -0
- package/lib/module/specs/NativeScaleBunStorage.js +36 -0
- package/lib/module/storage/StorageBackend.js +231 -0
- package/lib/module/storage/db/sqlite.js +2 -0
- package/lib/module/storage/files/fileStore.js +2 -0
- package/lib/module/transport/auth/sdkSession.js +21 -0
- package/lib/module/transport/backoff/exponentialJitter.js +10 -0
- package/lib/module/transport/http/endpoints.js +40 -0
- package/lib/module/transport/http/httpClient.js +64 -0
- package/lib/module/transport/rateLimit/retryAfter.js +2 -0
- package/lib/module/transport/signing/requestSigner.js +2 -0
- package/lib/module/vendor/protocol/index.js +312 -0
- package/lib/module/vendor/protocol/internal/validation.js +423 -0
- package/lib/module/vendor/sdk-contracts/bridge.js +2 -0
- package/lib/module/vendor/sdk-contracts/config.js +2 -0
- package/lib/module/vendor/sdk-contracts/events.js +2 -0
- package/lib/module/vendor/sdk-contracts/features.js +2 -0
- package/lib/module/vendor/sdk-contracts/index.js +2 -0
- package/lib/module/vendor/sdk-contracts/platform.js +2 -0
- package/lib/module/vendor/sdk-contracts/session-boundary.js +2 -0
- package/lib/module/vendor/sdk-contracts/session.js +2 -0
- package/lib/module/vendor/vendor.manifest +10 -0
- package/lib/typescript/analytics/EventTracker.d.ts +197 -0
- package/lib/typescript/analytics/automaticEvents.d.ts +30 -0
- package/lib/typescript/analytics/batching.d.ts +33 -0
- package/lib/typescript/analytics/eventLane.d.ts +22 -0
- package/lib/typescript/analytics/revenue.d.ts +94 -0
- package/lib/typescript/analytics/subscription.d.ts +35 -0
- package/lib/typescript/bootstrap/FeatureRegistry.d.ts +36 -0
- package/lib/typescript/bootstrap/SDKBootstrapper.d.ts +82 -0
- package/lib/typescript/bucketing/fnv1a32.d.ts +20 -0
- package/lib/typescript/compat/codepush.d.ts +76 -0
- package/lib/typescript/config/ConfigManager.d.ts +82 -0
- package/lib/typescript/config/configTypes.d.ts +73 -0
- package/lib/typescript/config/otaPolicyState.d.ts +55 -0
- package/lib/typescript/config/quotaState.d.ts +155 -0
- package/lib/typescript/core/architecture.d.ts +29 -0
- package/lib/typescript/core/clock/now.d.ts +5 -0
- package/lib/typescript/core/config/defaults.d.ts +1 -0
- package/lib/typescript/core/config/schema.d.ts +107 -0
- package/lib/typescript/core/constants/endpoints.d.ts +13 -0
- package/lib/typescript/core/constants/protocol.d.ts +23 -0
- package/lib/typescript/core/constants/timings.d.ts +22 -0
- package/lib/typescript/core/constants/version.d.ts +12 -0
- package/lib/typescript/core/context/app.d.ts +1 -0
- package/lib/typescript/core/context/device.d.ts +61 -0
- package/lib/typescript/core/context/session.d.ts +1 -0
- package/lib/typescript/core/context/user.d.ts +24 -0
- package/lib/typescript/core/contracts/IFeature.d.ts +44 -0
- package/lib/typescript/core/di/container.d.ts +9 -0
- package/lib/typescript/core/encoding/base64.d.ts +13 -0
- package/lib/typescript/core/id/deviceId.d.ts +9 -0
- package/lib/typescript/core/id/installationId.d.ts +20 -0
- package/lib/typescript/core/id/sessionId.d.ts +1 -0
- package/lib/typescript/core/lifecycle/appLifecycle.d.ts +14 -0
- package/lib/typescript/core/lifecycle/crashSafe.d.ts +7 -0
- package/lib/typescript/core/logger/errorClassification.d.ts +46 -0
- package/lib/typescript/core/logger/internalLogger.d.ts +24 -0
- package/lib/typescript/core/logger/levels.d.ts +1 -0
- package/lib/typescript/crypto/hmacSha256.d.ts +10 -0
- package/lib/typescript/debug/bootstrap.d.ts +148 -0
- package/lib/typescript/debug/commands.d.ts +77 -0
- package/lib/typescript/debug/configBuilder.d.ts +13 -0
- package/lib/typescript/debug/exportBridge.d.ts +27 -0
- package/lib/typescript/debug/hostResolver.d.ts +14 -0
- package/lib/typescript/debug/index.d.ts +12 -0
- package/lib/typescript/debug/metrics.d.ts +2 -0
- package/lib/typescript/debug/perf.d.ts +43 -0
- package/lib/typescript/debug/perfWiring.d.ts +33 -0
- package/lib/typescript/debug/protocol.d.ts +15 -0
- package/lib/typescript/debug/redaction.d.ts +69 -0
- package/lib/typescript/debug/replayWiring.d.ts +25 -0
- package/lib/typescript/debug/screenTracking.d.ts +16 -0
- package/lib/typescript/debug/sessionWiring.d.ts +16 -0
- package/lib/typescript/debug/stream.d.ts +77 -0
- package/lib/typescript/debug/transport.d.ts +110 -0
- package/lib/typescript/features/bugreport/BugReportFeature.d.ts +59 -0
- package/lib/typescript/features/bugreport/buildPayload.d.ts +51 -0
- package/lib/typescript/features/bugreport/index.d.ts +1 -0
- package/lib/typescript/features/crash/CrashFeature.d.ts +21 -0
- package/lib/typescript/features/crash/CrashReporter.d.ts +107 -0
- package/lib/typescript/features/crash/NativeCrashFeature.d.ts +17 -0
- package/lib/typescript/features/crash/capture.d.ts +22 -0
- package/lib/typescript/features/crash/globalHandler.d.ts +14 -0
- package/lib/typescript/features/crash/index.d.ts +2 -0
- package/lib/typescript/features/crash/nativeCrashBridge.d.ts +43 -0
- package/lib/typescript/features/crash/rejectionHandler.d.ts +65 -0
- package/lib/typescript/features/crash/scrubCrash.d.ts +35 -0
- package/lib/typescript/features/engage/EngageAnchor.d.ts +36 -0
- package/lib/typescript/features/engage/EngageArchetypeRenderers.d.ts +66 -0
- package/lib/typescript/features/engage/EngageInAppView.d.ts +164 -0
- package/lib/typescript/features/engage/EngageInlinePlacement.d.ts +42 -0
- package/lib/typescript/features/engage/EngagePromptProvider.d.ts +233 -0
- package/lib/typescript/features/engage/EngagePromptView.d.ts +97 -0
- package/lib/typescript/features/engage/EngageTransport.d.ts +158 -0
- package/lib/typescript/features/engage/EngageVariantContent.d.ts +12 -0
- package/lib/typescript/features/engage/attachmentCapture.d.ts +17 -0
- package/lib/typescript/features/engage/captureVoiceAttachment.d.ts +31 -0
- package/lib/typescript/features/engage/engageCoachmarkTour.d.ts +18 -0
- package/lib/typescript/features/engage/engageGameLogic.d.ts +34 -0
- package/lib/typescript/features/engage/engageMediaSizing.d.ts +23 -0
- package/lib/typescript/features/engage/engageMultiStepSheet.d.ts +25 -0
- package/lib/typescript/features/engage/engageOutcome.d.ts +38 -0
- package/lib/typescript/features/engage/engagePushTokenBridge.d.ts +30 -0
- package/lib/typescript/features/engage/engageShakeBridge.d.ts +20 -0
- package/lib/typescript/features/engage/engageSignals.d.ts +13 -0
- package/lib/typescript/features/engage/engageStoreReviewBridge.d.ts +23 -0
- package/lib/typescript/features/engage/engageTestSeenStore.d.ts +46 -0
- package/lib/typescript/features/engage/engageThrottle.d.ts +180 -0
- package/lib/typescript/features/engage/engageTriggerEngine.d.ts +16 -0
- package/lib/typescript/features/engage/engageTypes.d.ts +576 -0
- package/lib/typescript/features/engage/engageVariantResolver.d.ts +46 -0
- package/lib/typescript/features/engage/engageWindowInsets.d.ts +25 -0
- package/lib/typescript/features/engage/gestureTriggerDetector.d.ts +20 -0
- package/lib/typescript/features/engage/transcription/TranscriptionProvider.d.ts +51 -0
- package/lib/typescript/features/install-referrer/installReferrer.d.ts +39 -0
- package/lib/typescript/features/journey/ScaleBunDebugRoot.d.ts +49 -0
- package/lib/typescript/features/journey/ScaleBunFlatList.d.ts +20 -0
- package/lib/typescript/features/journey/ScaleBunImpression.d.ts +30 -0
- package/lib/typescript/features/journey/ScaleBunScrollView.d.ts +25 -0
- package/lib/typescript/features/journey/ScaleBunSectionList.d.ts +20 -0
- package/lib/typescript/features/journey/autoInstrumentScroll.d.ts +46 -0
- package/lib/typescript/features/journey/calibrationContext.d.ts +26 -0
- package/lib/typescript/features/journey/gestureBuffer.d.ts +27 -0
- package/lib/typescript/features/journey/gestureDetector.d.ts +40 -0
- package/lib/typescript/features/journey/impression.d.ts +48 -0
- package/lib/typescript/features/journey/interactionProtocol.d.ts +159 -0
- package/lib/typescript/features/journey/journeyManager.d.ts +62 -0
- package/lib/typescript/features/journey/journeyTypes.d.ts +161 -0
- package/lib/typescript/features/journey/nativeScroll.d.ts +47 -0
- package/lib/typescript/features/journey/navDetector.d.ts +42 -0
- package/lib/typescript/features/journey/screenshotHelper.d.ts +33 -0
- package/lib/typescript/features/journey/scrollContext.d.ts +49 -0
- package/lib/typescript/features/journey/targetGeometry.d.ts +126 -0
- package/lib/typescript/features/journey/targetRegistry.d.ts +28 -0
- package/lib/typescript/features/journey/touchTarget.d.ts +174 -0
- package/lib/typescript/features/journey/uiState.d.ts +93 -0
- package/lib/typescript/features/navigation/AutoScreenDetector.d.ts +196 -0
- package/lib/typescript/features/network/NetworkFeature.d.ts +43 -0
- package/lib/typescript/features/network/index.d.ts +46 -0
- package/lib/typescript/features/network/thirdParty.d.ts +95 -0
- package/lib/typescript/features/ota/OtaEventEmitter.d.ts +93 -0
- package/lib/typescript/features/ota/OtaOrchestrator.d.ts +287 -0
- package/lib/typescript/features/ota/OtaTypes.d.ts +193 -0
- package/lib/typescript/features/ota/deviceAttributes.d.ts +18 -0
- package/lib/typescript/features/ota/environment.d.ts +99 -0
- package/lib/typescript/features/ota/geoCountry.d.ts +14 -0
- package/lib/typescript/features/ota/retry.d.ts +53 -0
- package/lib/typescript/features/ota/signedDownload.d.ts +81 -0
- package/lib/typescript/features/ota/useOtaUpdate.d.ts +72 -0
- package/lib/typescript/features/performance/PerformanceFeature.d.ts +132 -0
- package/lib/typescript/features/performance/collectors/AppLaunchCollector.d.ts +27 -0
- package/lib/typescript/features/performance/collectors/AutoScreenLoadCollector.d.ts +70 -0
- package/lib/typescript/features/performance/collectors/CustomTraceCollector.d.ts +35 -0
- package/lib/typescript/features/performance/collectors/FrameMetricsCollector.d.ts +74 -0
- package/lib/typescript/features/performance/collectors/JsStallCollector.d.ts +45 -0
- package/lib/typescript/features/performance/collectors/NetworkPerfCollector.d.ts +23 -0
- package/lib/typescript/features/performance/collectors/ScreenLoadCollector.d.ts +30 -0
- package/lib/typescript/features/performance/collectors/UiHangCollector.d.ts +21 -0
- package/lib/typescript/features/performance/config.d.ts +73 -0
- package/lib/typescript/features/performance/getNativePerformanceModule.d.ts +2 -0
- package/lib/typescript/features/performance/index.d.ts +10 -0
- package/lib/typescript/features/performance/metrics/MetricsEngine.d.ts +69 -0
- package/lib/typescript/features/performance/models.d.ts +169 -0
- package/lib/typescript/features/performance/transport/PerformanceTransport.d.ts +40 -0
- package/lib/typescript/features/profiler/ProfilerFeature.d.ts +92 -0
- package/lib/typescript/features/profiler/config.d.ts +85 -0
- package/lib/typescript/features/profiler/contracts.d.ts +142 -0
- package/lib/typescript/features/profiler/index.d.ts +13 -0
- package/lib/typescript/features/profiler/models.d.ts +332 -0
- package/lib/typescript/features/profiler/transport/ProfilerTransport.d.ts +30 -0
- package/lib/typescript/features/replay/bridge/adapters/bridgeAdapter.d.ts +52 -0
- package/lib/typescript/features/replay/bridge/eventEmitter.d.ts +100 -0
- package/lib/typescript/features/replay/bridge/nativeModule.d.ts +166 -0
- package/lib/typescript/features/replay/bridge/nativeQuota.d.ts +26 -0
- package/lib/typescript/features/replay/core/clock/clock.d.ts +16 -0
- package/lib/typescript/features/replay/core/config/defaults.d.ts +28 -0
- package/lib/typescript/features/replay/core/config/validator.d.ts +13 -0
- package/lib/typescript/features/replay/core/env/environmentDetector.d.ts +14 -0
- package/lib/typescript/features/replay/core/errors/safeCall.d.ts +12 -0
- package/lib/typescript/features/replay/core/ids/sessionId.d.ts +15 -0
- package/lib/typescript/features/replay/core/logger/logger.d.ts +15 -0
- package/lib/typescript/features/replay/core/privacy/privacyTypes.d.ts +24 -0
- package/lib/typescript/features/replay/core/queue/boundedQueue.d.ts +29 -0
- package/lib/typescript/features/replay/integrations/alert/alertInstrumentation.d.ts +48 -0
- package/lib/typescript/features/replay/integrations/logs/consoleIntegration.d.ts +18 -0
- package/lib/typescript/features/replay/integrations/network/networkAdapter.d.ts +31 -0
- package/lib/typescript/features/replay/integrations/react-navigation/navigationIntegration.d.ts +25 -0
- package/lib/typescript/features/replay/integrations/touch/ReplayRoot.d.ts +26 -0
- package/lib/typescript/features/replay/pipeline/batching/batchManager.d.ts +47 -0
- package/lib/typescript/features/replay/pipeline/envelope/envelopeBuilder.d.ts +12 -0
- package/lib/typescript/features/replay/pipeline/retry/retryPolicy.d.ts +17 -0
- package/lib/typescript/features/replay/pipeline/transport/transportTypes.d.ts +40 -0
- package/lib/typescript/features/replay/public/api.d.ts +83 -0
- package/lib/typescript/features/replay/public/enums.d.ts +73 -0
- package/lib/typescript/features/replay/public/types.d.ts +249 -0
- package/lib/typescript/features/replay/replay/breadcrumbs/breadcrumbCollector.d.ts +26 -0
- package/lib/typescript/features/replay/replay/frames/frameModels.d.ts +23 -0
- package/lib/typescript/features/replay/replay/session/sessionOrchestrator.d.ts +53 -0
- package/lib/typescript/features/replay/replay/timeline/timelineModels.d.ts +29 -0
- package/lib/typescript/features/replay/transport/BackendReplayTransport.d.ts +45 -0
- package/lib/typescript/features/replay/transport/CompositeReplayTransport.d.ts +22 -0
- package/lib/typescript/features/replay/transport/DesktopReplayTransport.d.ts +35 -0
- package/lib/typescript/features/replay/transport/ReplayTransport.d.ts +72 -0
- package/lib/typescript/features/session/BackendSessionAdapter.d.ts +528 -0
- package/lib/typescript/features/session/DesktopSessionTransport.d.ts +28 -0
- package/lib/typescript/features/session/JourneyEventPipeline.d.ts +74 -0
- package/lib/typescript/features/session/ReplayCaptureManager.d.ts +391 -0
- package/lib/typescript/features/session/ScrollTracker.d.ts +48 -0
- package/lib/typescript/features/session/SessionManager.d.ts +414 -0
- package/lib/typescript/features/session/SyncDecisionEngine.d.ts +33 -0
- package/lib/typescript/features/session/frameLink.d.ts +27 -0
- package/lib/typescript/features/session/frameScrollState.d.ts +27 -0
- package/lib/typescript/features/session/index.d.ts +23 -0
- package/lib/typescript/features/session/nativeCapture.d.ts +18 -0
- package/lib/typescript/features/session/outboxFrameCapture.d.ts +20 -0
- package/lib/typescript/features/session/sessionTypes.d.ts +362 -0
- package/lib/typescript/features/session/viewportPlausibility.d.ts +72 -0
- package/lib/typescript/features/skan/skanBridge.d.ts +18 -0
- package/lib/typescript/features/skan/skanConversionManager.d.ts +69 -0
- package/lib/typescript/index.d.ts +59 -0
- package/lib/typescript/integrations/fetch/fetchInterceptor.d.ts +41 -0
- package/lib/typescript/integrations/navigation/screenTracker.d.ts +1 -0
- package/lib/typescript/integrations/network/bodyCapture.d.ts +101 -0
- package/lib/typescript/integrations/xhr/xhrInterceptor.d.ts +46 -0
- package/lib/typescript/metro/composeSourceMap.d.ts +26 -0
- package/lib/typescript/metro/featureModules.d.ts +49 -0
- package/lib/typescript/metro/index.d.ts +99 -0
- package/lib/typescript/metro/optionalDependencyStub.d.ts +14 -0
- package/lib/typescript/metro/optionalModules.d.ts +20 -0
- package/lib/typescript/metro/serializerCompose.d.ts +46 -0
- package/lib/typescript/pipeline/dispatcher/dispatcher.d.ts +7 -0
- package/lib/typescript/pipeline/envelope/envelope.d.ts +16 -0
- package/lib/typescript/pipeline/envelope/serializer.d.ts +7 -0
- package/lib/typescript/pipeline/processors/dedupe.d.ts +1 -0
- package/lib/typescript/pipeline/processors/enrich.d.ts +3 -0
- package/lib/typescript/pipeline/processors/sampling.d.ts +1 -0
- package/lib/typescript/pipeline/processors/sanitize.d.ts +3 -0
- package/lib/typescript/pipeline/queue/flushQueue.d.ts +12 -0
- package/lib/typescript/pipeline/queue/memoryQueue.d.ts +12 -0
- package/lib/typescript/pipeline/queue/persistentQueue.d.ts +120 -0
- package/lib/typescript/pipeline/queue/queuePolicy.d.ts +1 -0
- package/lib/typescript/pipeline/scheduler/flushScheduler.d.ts +9 -0
- package/lib/typescript/pipeline/scheduler/retryPolicy.d.ts +5 -0
- package/lib/typescript/public/ScaleBunErrorBoundary.d.ts +44 -0
- package/lib/typescript/public/ScaleBunFacade.d.ts +800 -0
- package/lib/typescript/public/ScaleBunProvider.d.ts +23 -0
- package/lib/typescript/public/typedTracker.d.ts +88 -0
- package/lib/typescript/public/types.d.ts +316 -0
- package/lib/typescript/push/PushManager.d.ts +69 -0
- package/lib/typescript/push/adapters/ManualAdapter.d.ts +40 -0
- package/lib/typescript/push/adapters/NativeBridgeAdapter.d.ts +37 -0
- package/lib/typescript/push/adapters/NoopAdapter.d.ts +21 -0
- package/lib/typescript/push/adapters/RNFirebaseMessagingAdapter.d.ts +39 -0
- package/lib/typescript/push/adapters/loadMessaging.d.ts +17 -0
- package/lib/typescript/push/adapters/loadNotifee.d.ts +15 -0
- package/lib/typescript/push/adapters/selectAdapter.d.ts +20 -0
- package/lib/typescript/push/detect/capabilities.d.ts +15 -0
- package/lib/typescript/push/index.d.ts +10 -0
- package/lib/typescript/push/native/nativeNotifications.d.ts +65 -0
- package/lib/typescript/push/types.d.ts +143 -0
- package/lib/typescript/specs/NativeReplaySdk.d.ts +69 -0
- package/lib/typescript/specs/NativeScaleBunCrash.d.ts +58 -0
- package/lib/typescript/specs/NativeScaleBunInstallReferrer.d.ts +28 -0
- package/lib/typescript/specs/NativeScaleBunOta.d.ts +141 -0
- package/lib/typescript/specs/NativeScaleBunPerformance.d.ts +31 -0
- package/lib/typescript/specs/NativeScaleBunProfiler.d.ts +38 -0
- package/lib/typescript/specs/NativeScaleBunStorage.d.ts +55 -0
- package/lib/typescript/storage/StorageBackend.d.ts +131 -0
- package/lib/typescript/storage/db/sqlite.d.ts +1 -0
- package/lib/typescript/storage/files/fileStore.d.ts +1 -0
- package/lib/typescript/transport/auth/sdkSession.d.ts +10 -0
- package/lib/typescript/transport/backoff/exponentialJitter.d.ts +5 -0
- package/lib/typescript/transport/http/endpoints.d.ts +26 -0
- package/lib/typescript/transport/http/httpClient.d.ts +23 -0
- package/lib/typescript/transport/rateLimit/retryAfter.d.ts +1 -0
- package/lib/typescript/transport/signing/requestSigner.d.ts +1 -0
- package/lib/typescript/vendor/protocol/index.d.ts +345 -0
- package/lib/typescript/vendor/protocol/internal/validation.d.ts +114 -0
- package/lib/typescript/vendor/sdk-contracts/bridge.d.ts +104 -0
- package/lib/typescript/vendor/sdk-contracts/config.d.ts +156 -0
- package/lib/typescript/vendor/sdk-contracts/events.d.ts +42 -0
- package/lib/typescript/vendor/sdk-contracts/features.d.ts +38 -0
- package/lib/typescript/vendor/sdk-contracts/index.d.ts +15 -0
- package/lib/typescript/vendor/sdk-contracts/platform.d.ts +35 -0
- package/lib/typescript/vendor/sdk-contracts/session-boundary.d.ts +42 -0
- package/lib/typescript/vendor/sdk-contracts/session.d.ts +157 -0
- package/package.json +153 -0
- package/react-native.config.js +24 -0
- package/scalebun-react-native.podspec +44 -0
- package/src/analytics/EventTracker.ts +654 -0
- package/src/analytics/automaticEvents.ts +109 -0
- package/src/analytics/batching.ts +54 -0
- package/src/analytics/eventLane.ts +48 -0
- package/src/analytics/revenue.ts +143 -0
- package/src/analytics/subscription.ts +145 -0
- package/src/bootstrap/FeatureRegistry.ts +81 -0
- package/src/bootstrap/SDKBootstrapper.ts +769 -0
- package/src/bucketing/fnv1a32.ts +40 -0
- package/src/compat/codepush.ts +189 -0
- package/src/config/ConfigManager.ts +233 -0
- package/src/config/configTypes.ts +62 -0
- package/src/config/otaPolicyState.ts +79 -0
- package/src/config/quotaState.ts +484 -0
- package/src/core/architecture.ts +39 -0
- package/src/core/clock/now.ts +6 -0
- package/src/core/config/defaults.ts +0 -0
- package/src/core/config/schema.ts +455 -0
- package/src/core/constants/endpoints.ts +12 -0
- package/src/core/constants/protocol.ts +24 -0
- package/src/core/constants/timings.ts +25 -0
- package/src/core/constants/version.ts +11 -0
- package/src/core/context/app.ts +0 -0
- package/src/core/context/device.ts +169 -0
- package/src/core/context/session.ts +0 -0
- package/src/core/context/user.ts +26 -0
- package/src/core/contracts/IFeature.ts +53 -0
- package/src/core/di/container.ts +26 -0
- package/src/core/encoding/base64.ts +46 -0
- package/src/core/id/deviceId.ts +51 -0
- package/src/core/id/installationId.ts +52 -0
- package/src/core/id/sessionId.ts +0 -0
- package/src/core/lifecycle/appLifecycle.ts +33 -0
- package/src/core/lifecycle/crashSafe.ts +29 -0
- package/src/core/logger/errorClassification.ts +108 -0
- package/src/core/logger/internalLogger.ts +65 -0
- package/src/core/logger/levels.ts +0 -0
- package/src/crypto/hmacSha256.ts +106 -0
- package/src/debug/bootstrap.ts +436 -0
- package/src/debug/commands.ts +597 -0
- package/src/debug/configBuilder.ts +56 -0
- package/src/debug/exportBridge.ts +155 -0
- package/src/debug/hostResolver.ts +34 -0
- package/src/debug/index.ts +25 -0
- package/src/debug/metrics.ts +29 -0
- package/src/debug/perf.ts +212 -0
- package/src/debug/perfWiring.ts +119 -0
- package/src/debug/protocol.ts +58 -0
- package/src/debug/redaction.ts +483 -0
- package/src/debug/replayWiring.ts +148 -0
- package/src/debug/screenTracking.ts +55 -0
- package/src/debug/sessionWiring.ts +59 -0
- package/src/debug/stream.ts +561 -0
- package/src/debug/transport.ts +440 -0
- package/src/features/bugreport/BugReportFeature.ts +128 -0
- package/src/features/bugreport/buildPayload.ts +116 -0
- package/src/features/bugreport/index.ts +0 -0
- package/src/features/crash/CrashFeature.ts +87 -0
- package/src/features/crash/CrashReporter.ts +189 -0
- package/src/features/crash/NativeCrashFeature.ts +42 -0
- package/src/features/crash/capture.ts +48 -0
- package/src/features/crash/globalHandler.ts +39 -0
- package/src/features/crash/index.ts +8 -0
- package/src/features/crash/nativeCrashBridge.ts +352 -0
- package/src/features/crash/rejectionHandler.ts +196 -0
- package/src/features/crash/scrubCrash.ts +175 -0
- package/src/features/engage/EngageAnchor.tsx +159 -0
- package/src/features/engage/EngageArchetypeRenderers.tsx +3705 -0
- package/src/features/engage/EngageInAppView.tsx +2678 -0
- package/src/features/engage/EngageInlinePlacement.tsx +169 -0
- package/src/features/engage/EngagePromptProvider.tsx +1318 -0
- package/src/features/engage/EngagePromptView.tsx +1400 -0
- package/src/features/engage/EngageTransport.ts +668 -0
- package/src/features/engage/EngageVariantContent.tsx +1483 -0
- package/src/features/engage/__test-support__/reactNativeStub.js +40 -0
- package/src/features/engage/attachmentCapture.ts +45 -0
- package/src/features/engage/captureVoiceAttachment.ts +81 -0
- package/src/features/engage/engageCoachmarkTour.ts +120 -0
- package/src/features/engage/engageGameLogic.ts +347 -0
- package/src/features/engage/engageMediaSizing.ts +76 -0
- package/src/features/engage/engageMultiStepSheet.ts +53 -0
- package/src/features/engage/engageOutcome.ts +157 -0
- package/src/features/engage/engagePushTokenBridge.ts +84 -0
- package/src/features/engage/engageShakeBridge.ts +67 -0
- package/src/features/engage/engageSignals.ts +40 -0
- package/src/features/engage/engageStoreReviewBridge.ts +48 -0
- package/src/features/engage/engageTestSeenStore.ts +95 -0
- package/src/features/engage/engageThrottle.ts +478 -0
- package/src/features/engage/engageTriggerEngine.ts +350 -0
- package/src/features/engage/engageTypes.ts +712 -0
- package/src/features/engage/engageVariantResolver.ts +364 -0
- package/src/features/engage/engageWindowInsets.ts +108 -0
- package/src/features/engage/gestureTriggerDetector.ts +83 -0
- package/src/features/engage/transcription/TranscriptionProvider.ts +68 -0
- package/src/features/install-referrer/installReferrer.ts +112 -0
- package/src/features/journey/ScaleBunDebugRoot.tsx +1045 -0
- package/src/features/journey/ScaleBunFlatList.tsx +39 -0
- package/src/features/journey/ScaleBunImpression.tsx +109 -0
- package/src/features/journey/ScaleBunScrollView.tsx +101 -0
- package/src/features/journey/ScaleBunSectionList.tsx +39 -0
- package/src/features/journey/autoInstrumentScroll.ts +155 -0
- package/src/features/journey/calibrationContext.ts +44 -0
- package/src/features/journey/gestureBuffer.ts +59 -0
- package/src/features/journey/gestureDetector.ts +162 -0
- package/src/features/journey/impression.ts +92 -0
- package/src/features/journey/interactionProtocol.ts +243 -0
- package/src/features/journey/journeyManager.ts +469 -0
- package/src/features/journey/journeyTypes.ts +215 -0
- package/src/features/journey/nativeScroll.ts +94 -0
- package/src/features/journey/navDetector.ts +149 -0
- package/src/features/journey/screenshotHelper.ts +137 -0
- package/src/features/journey/scrollContext.ts +146 -0
- package/src/features/journey/targetGeometry.ts +197 -0
- package/src/features/journey/targetRegistry.ts +43 -0
- package/src/features/journey/touchTarget.ts +339 -0
- package/src/features/journey/uiState.ts +182 -0
- package/src/features/navigation/AutoScreenDetector.ts +617 -0
- package/src/features/network/NetworkFeature.ts +232 -0
- package/src/features/network/index.ts +59 -0
- package/src/features/network/thirdParty.ts +160 -0
- package/src/features/ota/OtaEventEmitter.ts +187 -0
- package/src/features/ota/OtaOrchestrator.ts +1513 -0
- package/src/features/ota/OtaTypes.ts +230 -0
- package/src/features/ota/deviceAttributes.ts +46 -0
- package/src/features/ota/environment.ts +199 -0
- package/src/features/ota/geoCountry.ts +85 -0
- package/src/features/ota/retry.ts +123 -0
- package/src/features/ota/signedDownload.ts +202 -0
- package/src/features/ota/useOtaUpdate.ts +161 -0
- package/src/features/performance/PerformanceFeature.ts +729 -0
- package/src/features/performance/collectors/AppLaunchCollector.ts +131 -0
- package/src/features/performance/collectors/AutoScreenLoadCollector.ts +258 -0
- package/src/features/performance/collectors/CustomTraceCollector.ts +116 -0
- package/src/features/performance/collectors/FrameMetricsCollector.ts +210 -0
- package/src/features/performance/collectors/JsStallCollector.ts +184 -0
- package/src/features/performance/collectors/NetworkPerfCollector.ts +69 -0
- package/src/features/performance/collectors/ScreenLoadCollector.ts +95 -0
- package/src/features/performance/collectors/UiHangCollector.ts +98 -0
- package/src/features/performance/config.ts +136 -0
- package/src/features/performance/getNativePerformanceModule.ts +38 -0
- package/src/features/performance/index.ts +28 -0
- package/src/features/performance/metrics/MetricsEngine.ts +152 -0
- package/src/features/performance/models.ts +235 -0
- package/src/features/performance/transport/PerformanceTransport.ts +161 -0
- package/src/features/profiler/ProfilerFeature.ts +661 -0
- package/src/features/profiler/config.ts +230 -0
- package/src/features/profiler/contracts.ts +176 -0
- package/src/features/profiler/index.ts +45 -0
- package/src/features/profiler/models.ts +430 -0
- package/src/features/profiler/transport/ProfilerTransport.ts +93 -0
- package/src/features/replay/bridge/adapters/bridgeAdapter.ts +235 -0
- package/src/features/replay/bridge/eventEmitter.ts +176 -0
- package/src/features/replay/bridge/nativeModule.ts +252 -0
- package/src/features/replay/bridge/nativeQuota.ts +111 -0
- package/src/features/replay/core/clock/clock.ts +38 -0
- package/src/features/replay/core/config/defaults.ts +66 -0
- package/src/features/replay/core/config/validator.ts +113 -0
- package/src/features/replay/core/env/environmentDetector.ts +21 -0
- package/src/features/replay/core/errors/safeCall.ts +34 -0
- package/src/features/replay/core/ids/sessionId.ts +44 -0
- package/src/features/replay/core/logger/logger.ts +36 -0
- package/src/features/replay/core/privacy/privacyTypes.ts +41 -0
- package/src/features/replay/core/queue/boundedQueue.ts +71 -0
- package/src/features/replay/integrations/alert/alertInstrumentation.ts +277 -0
- package/src/features/replay/integrations/logs/consoleIntegration.ts +136 -0
- package/src/features/replay/integrations/network/networkAdapter.ts +73 -0
- package/src/features/replay/integrations/react-navigation/navigationIntegration.ts +89 -0
- package/src/features/replay/integrations/touch/ReplayRoot.tsx +114 -0
- package/src/features/replay/pipeline/batching/batchManager.ts +133 -0
- package/src/features/replay/pipeline/envelope/envelopeBuilder.ts +66 -0
- package/src/features/replay/pipeline/retry/retryPolicy.ts +62 -0
- package/src/features/replay/pipeline/transport/transportTypes.ts +85 -0
- package/src/features/replay/public/api.ts +364 -0
- package/src/features/replay/public/enums.ts +78 -0
- package/src/features/replay/public/types.ts +297 -0
- package/src/features/replay/replay/breadcrumbs/breadcrumbCollector.ts +115 -0
- package/src/features/replay/replay/frames/frameModels.ts +45 -0
- package/src/features/replay/replay/session/sessionOrchestrator.ts +286 -0
- package/src/features/replay/replay/timeline/timelineModels.ts +129 -0
- package/src/features/replay/transport/BackendReplayTransport.ts +215 -0
- package/src/features/replay/transport/CompositeReplayTransport.ts +82 -0
- package/src/features/replay/transport/DesktopReplayTransport.ts +140 -0
- package/src/features/replay/transport/ReplayTransport.ts +84 -0
- package/src/features/session/BackendSessionAdapter.ts +1977 -0
- package/src/features/session/DesktopSessionTransport.ts +130 -0
- package/src/features/session/JourneyEventPipeline.ts +278 -0
- package/src/features/session/ReplayCaptureManager.ts +1401 -0
- package/src/features/session/ScrollTracker.ts +166 -0
- package/src/features/session/SessionManager.ts +1687 -0
- package/src/features/session/SyncDecisionEngine.ts +117 -0
- package/src/features/session/frameLink.ts +41 -0
- package/src/features/session/frameScrollState.ts +36 -0
- package/src/features/session/index.ts +88 -0
- package/src/features/session/nativeCapture.ts +43 -0
- package/src/features/session/outboxFrameCapture.ts +79 -0
- package/src/features/session/sessionTypes.ts +528 -0
- package/src/features/session/viewportPlausibility.ts +134 -0
- package/src/features/skan/skanBridge.ts +53 -0
- package/src/features/skan/skanConversionManager.ts +173 -0
- package/src/index.ts +206 -0
- package/src/integrations/fetch/fetchInterceptor.ts +201 -0
- package/src/integrations/navigation/screenTracker.ts +0 -0
- package/src/integrations/network/bodyCapture.ts +328 -0
- package/src/integrations/xhr/xhrInterceptor.ts +259 -0
- package/src/metro/composeSourceMap.ts +104 -0
- package/src/metro/featureModules.ts +143 -0
- package/src/metro/index.ts +336 -0
- package/src/metro/optionalDependencyStub.ts +13 -0
- package/src/metro/optionalModules.ts +27 -0
- package/src/metro/serializerCompose.ts +193 -0
- package/src/pipeline/dispatcher/dispatcher.ts +22 -0
- package/src/pipeline/envelope/envelope.ts +31 -0
- package/src/pipeline/envelope/serializer.ts +14 -0
- package/src/pipeline/processors/dedupe.ts +0 -0
- package/src/pipeline/processors/enrich.ts +11 -0
- package/src/pipeline/processors/sampling.ts +0 -0
- package/src/pipeline/processors/sanitize.ts +23 -0
- package/src/pipeline/queue/flushQueue.ts +144 -0
- package/src/pipeline/queue/memoryQueue.ts +31 -0
- package/src/pipeline/queue/persistentQueue.ts +385 -0
- package/src/pipeline/queue/queuePolicy.ts +0 -0
- package/src/pipeline/scheduler/flushScheduler.ts +47 -0
- package/src/pipeline/scheduler/retryPolicy.ts +8 -0
- package/src/public/ScaleBunErrorBoundary.tsx +91 -0
- package/src/public/ScaleBunFacade.ts +2129 -0
- package/src/public/ScaleBunProvider.tsx +91 -0
- package/src/public/typedTracker.ts +123 -0
- package/src/public/types.ts +362 -0
- package/src/push/PushManager.ts +318 -0
- package/src/push/adapters/ManualAdapter.ts +100 -0
- package/src/push/adapters/NativeBridgeAdapter.ts +142 -0
- package/src/push/adapters/NoopAdapter.ts +46 -0
- package/src/push/adapters/RNFirebaseMessagingAdapter.ts +271 -0
- package/src/push/adapters/loadMessaging.ts +24 -0
- package/src/push/adapters/loadNotifee.ts +29 -0
- package/src/push/adapters/selectAdapter.ts +176 -0
- package/src/push/detect/capabilities.ts +124 -0
- package/src/push/index.ts +22 -0
- package/src/push/native/nativeNotifications.ts +207 -0
- package/src/push/types.ts +159 -0
- package/src/specs/NativeReplaySdk.ts +101 -0
- package/src/specs/NativeScaleBunCrash.ts +64 -0
- package/src/specs/NativeScaleBunInstallReferrer.ts +29 -0
- package/src/specs/NativeScaleBunOta.ts +154 -0
- package/src/specs/NativeScaleBunPerformance.ts +34 -0
- package/src/specs/NativeScaleBunProfiler.ts +41 -0
- package/src/specs/NativeScaleBunStorage.ts +59 -0
- package/src/storage/StorageBackend.ts +272 -0
- package/src/storage/db/sqlite.ts +0 -0
- package/src/storage/files/fileStore.ts +0 -0
- package/src/transport/auth/sdkSession.ts +27 -0
- package/src/transport/backoff/exponentialJitter.ts +9 -0
- package/src/transport/http/endpoints.ts +33 -0
- package/src/transport/http/httpClient.ts +73 -0
- package/src/transport/rateLimit/retryAfter.ts +0 -0
- package/src/transport/signing/requestSigner.ts +0 -0
- package/src/vendor/protocol/index.ts +391 -0
- package/src/vendor/protocol/internal/validation.ts +497 -0
- package/src/vendor/sdk-contracts/bridge.ts +162 -0
- package/src/vendor/sdk-contracts/config.ts +192 -0
- package/src/vendor/sdk-contracts/events.ts +50 -0
- package/src/vendor/sdk-contracts/features.ts +42 -0
- package/src/vendor/sdk-contracts/index.ts +98 -0
- package/src/vendor/sdk-contracts/platform.ts +42 -0
- package/src/vendor/sdk-contracts/session-boundary.ts +55 -0
- package/src/vendor/sdk-contracts/session.ts +225 -0
- package/src/vendor/vendor.manifest +10 -0
|
@@ -0,0 +1,2038 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ScaleBun SDK — Public Facade
|
|
3
|
+
*
|
|
4
|
+
* Single clean entry point for the ScaleBun SDK.
|
|
5
|
+
* Delegates initialization to SDKBootstrapper, which handles config validation,
|
|
6
|
+
* core service setup, handshake, and feature registration via FeatureRegistry.
|
|
7
|
+
*
|
|
8
|
+
* Config model preserved exactly: projectId, publishableKey, apiBaseUrl.
|
|
9
|
+
* Features are default-on with explicit opt-out via `features: { replay: false }`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { noThrow, safeAsync } from '../core/lifecycle/crashSafe';
|
|
13
|
+
import { logger } from '../core/logger/internalLogger';
|
|
14
|
+
import { createEnvelope } from '../pipeline/envelope/envelope';
|
|
15
|
+
import { generateEventId } from '../features/replay/core/ids/sessionId';
|
|
16
|
+
import { buildBugReportPayload } from '../features/bugreport/buildPayload';
|
|
17
|
+
import { BugReportFeature } from '../features/bugreport/BugReportFeature';
|
|
18
|
+
import { PersistentQueue } from '../pipeline/queue/persistentQueue';
|
|
19
|
+
import { MemoryBackend, createStorageBackend } from '../storage/StorageBackend';
|
|
20
|
+
import { getDeviceId } from '../core/id/deviceId';
|
|
21
|
+
import { mergeDeviceContext, nativeDeviceContext, resolveEventPlatform } from '../core/context/device';
|
|
22
|
+
import { coreContainer } from '../core/di/container';
|
|
23
|
+
import { flushQueue } from '../pipeline/queue/flushQueue';
|
|
24
|
+
import { enableDebug as _enableDebug, disableDebug as _disableDebug, isDebugEnabled, addBreadcrumb as _addBreadcrumb, ping as _ping, _getStream, _setFlushFn, getPerformanceFeature as _getPerformanceFeature, requestExport as _requestExport, buildDebugConfigFromInitConfig, applyFeatureGatesToDebugConfig, sendDebugMetric } from '../debug';
|
|
25
|
+
import { ReplaySdk } from '../features/replay/public/api';
|
|
26
|
+
import { SDKBootstrapper } from '../bootstrap/SDKBootstrapper';
|
|
27
|
+
import { EventTracker } from '../analytics/EventTracker';
|
|
28
|
+
import { bridgeAdapter } from '../features/replay/bridge/adapters/bridgeAdapter';
|
|
29
|
+
import { emitAutomaticEvent } from '../analytics/automaticEvents';
|
|
30
|
+
import { resolveEventLane, isUploadedSessionEvent } from '../analytics/eventLane';
|
|
31
|
+
import { ConfigManager } from '../config/ConfigManager';
|
|
32
|
+
import { quotaState } from '../config/quotaState';
|
|
33
|
+
import { resolveInstallationId } from '../core/id/installationId';
|
|
34
|
+
import { SDK_VERSION } from '../core/constants/version';
|
|
35
|
+
import { EngageTransport } from '../features/engage/EngageTransport';
|
|
36
|
+
import { getNativePushToken, subscribeNativePushTokenRefresh } from '../features/engage/engagePushTokenBridge';
|
|
37
|
+
import { requestNativeStoreReview } from '../features/engage/engageStoreReviewBridge';
|
|
38
|
+
import { PushManager } from '../push/PushManager';
|
|
39
|
+
import { ENGAGE_SCHEMA_VERSION } from '../features/engage/engageTypes';
|
|
40
|
+
import { EngageThrottleStore } from '../features/engage/engageThrottle';
|
|
41
|
+
import { EngageTestSeenStore } from '../features/engage/engageTestSeenStore';
|
|
42
|
+
import { engageSignals } from '../features/engage/engageSignals';
|
|
43
|
+
import { PerformanceFeature } from '../features/performance/PerformanceFeature';
|
|
44
|
+
import { SessionManager } from '../features/session/SessionManager';
|
|
45
|
+
import { getCrashReporter } from '../features/crash/CrashReporter';
|
|
46
|
+
import { triggerNativeCrash } from '../features/crash/nativeCrashBridge';
|
|
47
|
+
import { updateSkanConversionValue, isSkanAvailable } from '../features/skan/skanBridge';
|
|
48
|
+
import { SkanConversionManager } from '../features/skan/skanConversionManager';
|
|
49
|
+
import { isInstallReferrerAvailable, getInstallReferrer, captureInstallReferrerOnce } from '../features/install-referrer/installReferrer';
|
|
50
|
+
class ScaleBunFacade {
|
|
51
|
+
initialized = false;
|
|
52
|
+
/** In-flight init promise — guards against a second init() racing before the first resolves. */
|
|
53
|
+
_initInFlight = null;
|
|
54
|
+
bootstrapper = new SDKBootstrapper();
|
|
55
|
+
_features = {};
|
|
56
|
+
_performanceFeature = null;
|
|
57
|
+
_privacyConfig = {};
|
|
58
|
+
_brandingConfig = {};
|
|
59
|
+
_clientKey = undefined;
|
|
60
|
+
_apiBaseUrl = undefined;
|
|
61
|
+
_engageTransport = null;
|
|
62
|
+
_engageTokenUnsubscribe = null;
|
|
63
|
+
_pushManager = null;
|
|
64
|
+
/** Phase 1 envelope event-tracking lane (POST /v1/batch). Null until init with appId. */
|
|
65
|
+
_eventTracker = null;
|
|
66
|
+
/** External identity last supplied through identify(); used by config targeting. */
|
|
67
|
+
_identifiedUserId = null;
|
|
68
|
+
/** Identity supplied while async initialization is still in flight. */
|
|
69
|
+
_pendingIdentity = null;
|
|
70
|
+
_configManager = null;
|
|
71
|
+
/**
|
|
72
|
+
* The ConfigManager that owns /config refreshes for quota: `_configManager` when the event
|
|
73
|
+
* tracker created one, else a quota-only instance (no appId → no tracker, but a clientKey still
|
|
74
|
+
* has a plan with limits). Never exposed through the flags/experiments API.
|
|
75
|
+
*/
|
|
76
|
+
_configRefresher = null;
|
|
77
|
+
_configForegroundListener = null;
|
|
78
|
+
/** The developer's locally-configured replay captureMode — the value to revert to when an
|
|
79
|
+
* admin-forced frequency override (from /config) is withdrawn. Default matches the SDK default. */
|
|
80
|
+
_devCaptureMode = 'interactions';
|
|
81
|
+
/** True while an admin frequency override from /config is applied, so we know to revert. */
|
|
82
|
+
_replayOverrideActive = false;
|
|
83
|
+
/** Signature of the last identity POSTed to the ingestion identify endpoint, to skip redundant re-sends. */
|
|
84
|
+
_lastIngestionIdentityKey = null;
|
|
85
|
+
/** Phase 3: auto-applies SKAN conversion values from the server schema (iOS only). */
|
|
86
|
+
_skanManager = null;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Pre-init memory buffer.
|
|
90
|
+
* Events tracked before init() completes are buffered here,
|
|
91
|
+
* then drained into the real persistent queue post-init.
|
|
92
|
+
*/
|
|
93
|
+
_preInitBuffer = new PersistentQueue(new MemoryBackend(), {
|
|
94
|
+
enabled: false,
|
|
95
|
+
maxEntries: 500,
|
|
96
|
+
maxBytes: 1_048_576,
|
|
97
|
+
// 1 MB
|
|
98
|
+
redactBeforeWrite: false // No redaction for memory-only buffer
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
/** Resolve the active queue (DI container or pre-init buffer) */
|
|
102
|
+
_getQueue() {
|
|
103
|
+
if (this.initialized) {
|
|
104
|
+
try {
|
|
105
|
+
return coreContainer.get('PersistentQueue');
|
|
106
|
+
} catch {
|
|
107
|
+
// Container not ready yet — shouldn't happen post-init
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return this._preInitBuffer;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ─── Initialization ─────────────────────────────────────────────────
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Initialize the ScaleBun SDK.
|
|
117
|
+
*
|
|
118
|
+
* **Simplified usage** (recommended):
|
|
119
|
+
* ```ts
|
|
120
|
+
* await ScaleBun.init({
|
|
121
|
+
* projectId: 'proj_xxx',
|
|
122
|
+
* publishableKey: 'pk_xxx',
|
|
123
|
+
* apiBaseUrl: 'https://api.scalebun.com',
|
|
124
|
+
* debug: true,
|
|
125
|
+
* });
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* Accepts both `SimplifiedInitConfig` (new) and `ScaleBunInitConfig` (legacy).
|
|
129
|
+
* If `debug` key is present, auto-connects to the desktop debugger.
|
|
130
|
+
*/
|
|
131
|
+
async init(rawConfig) {
|
|
132
|
+
if (this.initialized) return;
|
|
133
|
+
// Coalesce concurrent init() calls: a second call before the first resolves
|
|
134
|
+
// must not run a second bootstrap (which would double-register lifecycle
|
|
135
|
+
// listeners and repeat the backend handshake).
|
|
136
|
+
if (this._initInFlight) return this._initInFlight;
|
|
137
|
+
this._initInFlight = safeAsync(async () => {
|
|
138
|
+
if (this.initialized) return;
|
|
139
|
+
|
|
140
|
+
// Store feature flags (all default true)
|
|
141
|
+
this._features = rawConfig?.features ?? {};
|
|
142
|
+
// Remember the developer's local replay captureMode so we can revert to it if an
|
|
143
|
+
// admin-forced frequency override (delivered via /config) is later withdrawn.
|
|
144
|
+
this._devCaptureMode = rawConfig?.replay?.captureMode ?? 'interactions';
|
|
145
|
+
if (rawConfig?.sessionReplay !== undefined) {
|
|
146
|
+
this._features.replay = rawConfig.sessionReplay;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Store privacy config if provided
|
|
150
|
+
if (rawConfig?.privacy) {
|
|
151
|
+
this._privacyConfig = rawConfig.privacy;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Phase 3 (entitlements) — COST suppression: don't even register a
|
|
155
|
+
// collector the org isn't entitled to (no traffic → no server cost).
|
|
156
|
+
// Read from the cached /config (sync); first run has no cache → fail-open
|
|
157
|
+
// (all entitled), and the server still rejects a closed feature anyway.
|
|
158
|
+
const ent = ConfigManager.readCachedEntitlements();
|
|
159
|
+
const effectiveFeatures = {
|
|
160
|
+
...this._features,
|
|
161
|
+
replay: this._features.replay !== false && ent.replay !== false,
|
|
162
|
+
network: this._features.network !== false && ent.networkMonitoring !== false,
|
|
163
|
+
crashes: this._features.crashes !== false && ent.crashReporting !== false,
|
|
164
|
+
performance: this._features.performance !== false && ent.performanceMonitoring !== false
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// Backend bootstrap (non-blocking for debug connection)
|
|
168
|
+
// If the backend is unreachable, the debug WebSocket should still connect.
|
|
169
|
+
try {
|
|
170
|
+
const result = await this.bootstrapper.bootstrap(rawConfig, (name, payload) => this.track(name, payload), () => this.flush(), effectiveFeatures);
|
|
171
|
+
if (result) {
|
|
172
|
+
this.initialized = true;
|
|
173
|
+
this._clientKey = result.config.clientKey;
|
|
174
|
+
this._apiBaseUrl = result.config.apiBaseUrl;
|
|
175
|
+
|
|
176
|
+
// Phase 1 envelope tracking lane. Enabled when an appId is supplied
|
|
177
|
+
// (and not explicitly disabled). Runs alongside the replay lane.
|
|
178
|
+
this._maybeStartEventTracker(rawConfig);
|
|
179
|
+
// Quota (contract v1): /config must be live whenever a clientKey is configured,
|
|
180
|
+
// not only when the appId-gated event tracker created a ConfigManager above.
|
|
181
|
+
this._startConfigLifecycle();
|
|
182
|
+
if (this._pendingIdentity) {
|
|
183
|
+
const pending = this._pendingIdentity;
|
|
184
|
+
this._pendingIdentity = null;
|
|
185
|
+
this.identify(pending.userId, pending.traits);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Drain pre-init buffer into the real persistent queue
|
|
189
|
+
const realQueue = coreContainer.get('PersistentQueue');
|
|
190
|
+
const buffered = this._preInitBuffer.popBatch(this._preInitBuffer.length());
|
|
191
|
+
if (buffered.length > 0) {
|
|
192
|
+
logger.debug(`[ScaleBun] Draining ${buffered.length} pre-init events into persistent queue`);
|
|
193
|
+
for (const envelope of buffered) {
|
|
194
|
+
realQueue.add(envelope);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Grab a reference to the PerformanceFeature for the public API
|
|
199
|
+
const perfFeature = result.featureRegistry.get('performance');
|
|
200
|
+
if (perfFeature && perfFeature instanceof PerformanceFeature) {
|
|
201
|
+
this._performanceFeature = perfFeature;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
} catch (bootstrapErr) {
|
|
205
|
+
logger.warn('[ScaleBun] Backend bootstrap failed (non-blocking):', bootstrapErr?.message);
|
|
206
|
+
// Continue — debug connection is independent of backend API
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// OTA from init config. Without this the whole `ota` config block was
|
|
210
|
+
// inert: `otaOrchestrator.init()` was reachable only by importing the
|
|
211
|
+
// orchestrator directly, so an app that followed the documented
|
|
212
|
+
// `ota: { enabled: true }` path silently got no updates AND no
|
|
213
|
+
// signature enforcement (sync() gates on the flag init() sets).
|
|
214
|
+
this._maybeStartOta(rawConfig);
|
|
215
|
+
|
|
216
|
+
// Auto debug connection from init config — runs regardless of backend status
|
|
217
|
+
const debugConfig = rawConfig?.desktopDebug ?? rawConfig?.debug;
|
|
218
|
+
if (debugConfig) {
|
|
219
|
+
this._autoEnableDebug(debugConfig);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
try {
|
|
223
|
+
return await this._initInFlight;
|
|
224
|
+
} finally {
|
|
225
|
+
this._initInFlight = null;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Boot the OTA orchestrator when the init config asks for it.
|
|
231
|
+
*
|
|
232
|
+
* Signature enforcement is no longer configured from JS. Signed releases are
|
|
233
|
+
* verified and staged in NATIVE code against RSA keys embedded in the app
|
|
234
|
+
* package (SB-OTA-RSA-SHA256-V1); unsigned releases keep working on SHA-256
|
|
235
|
+
* integrity. There are no signing-key or `verifySignature` options to pass
|
|
236
|
+
* through — the host embeds its trusted keys natively.
|
|
237
|
+
*/
|
|
238
|
+
_maybeStartOta(rawConfig) {
|
|
239
|
+
const ota = rawConfig?.ota;
|
|
240
|
+
if (!ota?.enabled) return;
|
|
241
|
+
try {
|
|
242
|
+
// Required lazily: hosts that never enable OTA should not pay for the
|
|
243
|
+
// module (or touch the native spec) at import time.
|
|
244
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
245
|
+
const {
|
|
246
|
+
otaOrchestrator
|
|
247
|
+
} = require('../features/ota/OtaOrchestrator');
|
|
248
|
+
// `healthyAfterMs` is the field BootGuardConfig actually declares.
|
|
249
|
+
// This passed `healthyTimeoutMs`, which nothing reads, so a host that
|
|
250
|
+
// tuned the boot-guard window silently got the 10s default instead.
|
|
251
|
+
// Both spellings are accepted so the older one keeps working.
|
|
252
|
+
const healthyAfterMs = typeof ota.healthyAfterMs === 'number' ? ota.healthyAfterMs : typeof ota.healthyTimeoutMs === 'number' ? ota.healthyTimeoutMs : undefined;
|
|
253
|
+
|
|
254
|
+
// Root/jailbreak policy. ONLY the literal string 'withhold' opts in;
|
|
255
|
+
// anything else (absent, a typo, a truthy object) falls through to
|
|
256
|
+
// 'allow', which is the behaviour every existing app already has.
|
|
257
|
+
// A config typo must never be able to stop a fleet's updates.
|
|
258
|
+
const onCompromisedDevice = ota.onCompromisedDevice === 'withhold' ? 'withhold' : 'allow';
|
|
259
|
+
otaOrchestrator.init({
|
|
260
|
+
...(healthyAfterMs !== undefined ? {
|
|
261
|
+
healthyAfterMs
|
|
262
|
+
} : {}),
|
|
263
|
+
onCompromisedDevice
|
|
264
|
+
});
|
|
265
|
+
if (onCompromisedDevice === 'withhold') {
|
|
266
|
+
logger.info("[ScaleBun] OTA will be WITHHELD on devices reporting root/jailbreak indicators (ota.onCompromisedDevice: 'withhold').");
|
|
267
|
+
}
|
|
268
|
+
logger.info('[ScaleBun] OTA enabled from init config.');
|
|
269
|
+
|
|
270
|
+
// Run the checks the config asked for. Until this existed, `ota.enabled`
|
|
271
|
+
// initialised the orchestrator and then never checked anything: the
|
|
272
|
+
// documented `checkOnForeground` and `channelOverride` options were read
|
|
273
|
+
// by no code at all, and an app following the documented config received
|
|
274
|
+
// updates only if it ALSO drove `useOtaUpdate` or the CodePush shim by
|
|
275
|
+
// hand. Nothing logged, because "no update available" and "never asked"
|
|
276
|
+
// look identical from the outside.
|
|
277
|
+
this._startOtaChecks(ota);
|
|
278
|
+
} catch (err) {
|
|
279
|
+
logger.warn(`[ScaleBun] OTA init failed: ${err?.message ?? err}`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** Guards against overlapping config-driven OTA checks. */
|
|
284
|
+
_otaCheckInFlight = false;
|
|
285
|
+
/** Wall clock of the last config-driven check, for the foreground floor. */
|
|
286
|
+
_otaLastCheckAt = 0;
|
|
287
|
+
_otaForegroundListener = null;
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Minimum gap between config-driven checks.
|
|
291
|
+
*
|
|
292
|
+
* A foreground transition is cheap to trigger — app switchers, permission
|
|
293
|
+
* dialogs and share sheets all produce one — so an unthrottled check would
|
|
294
|
+
* put a request on the hot path every time the user glanced away. Ten
|
|
295
|
+
* minutes is well below any realistic release cadence and well above that
|
|
296
|
+
* noise. A host that wants a check on demand calls `useOtaUpdate().sync()`,
|
|
297
|
+
* which is never throttled.
|
|
298
|
+
*/
|
|
299
|
+
static OTA_MIN_CHECK_INTERVAL_MS = 10 * 60 * 1000;
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Drive OTA checks from init config: once at startup, then on each
|
|
303
|
+
* foreground when `checkOnForeground` is on (the schema default).
|
|
304
|
+
*
|
|
305
|
+
* `appVersion` is resolved from the native bridge rather than asked of the
|
|
306
|
+
* integrator, because it gates the server's `targetAppVersion` semver check
|
|
307
|
+
* — sending a wrong or invented value is worse than sending none, and there
|
|
308
|
+
* is no honest default. If it cannot be resolved, the check is skipped with
|
|
309
|
+
* a warning instead of guessing.
|
|
310
|
+
*/
|
|
311
|
+
_startOtaChecks(ota) {
|
|
312
|
+
// Never in a debug build. `ScaleBunOtaModule.getJSBundleFile()` returns null
|
|
313
|
+
// there on purpose so Metro keeps ownership of the bundle — so a bundle
|
|
314
|
+
// downloaded in dev is installed into a slot that will never be loaded, and
|
|
315
|
+
// the identity check on the next launch then correctly observes that the
|
|
316
|
+
// running code is not what was installed and reports APPLY_FAILED. Checking
|
|
317
|
+
// at all in dev buys nothing and manufactures that false alarm. A developer
|
|
318
|
+
// testing the OTA path drives `useOtaUpdate().sync()` explicitly.
|
|
319
|
+
if (__DEV__) {
|
|
320
|
+
logger.info('[ScaleBun] OTA checks are skipped in debug builds (Metro owns the bundle).');
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
const runCheck = async trigger => {
|
|
324
|
+
if (this._otaCheckInFlight) return;
|
|
325
|
+
if (trigger === 'foreground' && Date.now() - this._otaLastCheckAt < ScaleBunFacade.OTA_MIN_CHECK_INTERVAL_MS) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const clientKey = this._clientKey;
|
|
329
|
+
const apiUrl = this._apiBaseUrl;
|
|
330
|
+
if (!clientKey || !apiUrl) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
this._otaCheckInFlight = true;
|
|
334
|
+
try {
|
|
335
|
+
const info = await bridgeAdapter.getDeviceInfo();
|
|
336
|
+
const appVersion = info?.appVersion;
|
|
337
|
+
if (!appVersion) {
|
|
338
|
+
logger.warn('[ScaleBun] OTA check skipped — the app version could not be read from the ' + 'native bridge. Rebuild the native app, or drive checks yourself with ' + 'useOtaUpdate({ appVersion }).');
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
this._otaLastCheckAt = Date.now();
|
|
342
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
343
|
+
const {
|
|
344
|
+
otaOrchestrator
|
|
345
|
+
} = require('../features/ota/OtaOrchestrator');
|
|
346
|
+
await otaOrchestrator.sync({
|
|
347
|
+
apiUrl,
|
|
348
|
+
clientKey,
|
|
349
|
+
appVersion,
|
|
350
|
+
// The documented option, finally connected. Omitted means the
|
|
351
|
+
// server's `default` channel, exactly as before.
|
|
352
|
+
channelName: typeof ota.channelOverride === 'string' ? ota.channelOverride : undefined
|
|
353
|
+
// Never forced from config: the release's own installMode
|
|
354
|
+
// decides when the app restarts, and yanking the screen out
|
|
355
|
+
// from under a user is not a decision this switch should make.
|
|
356
|
+
});
|
|
357
|
+
} catch (err) {
|
|
358
|
+
logger.warn(`[ScaleBun] OTA check failed: ${err?.message ?? err}`);
|
|
359
|
+
} finally {
|
|
360
|
+
this._otaCheckInFlight = false;
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
void runCheck('startup');
|
|
364
|
+
if (ota.checkOnForeground === false) return;
|
|
365
|
+
if (this._otaForegroundListener) return; // idempotent across repeated init()
|
|
366
|
+
try {
|
|
367
|
+
// Through `appLifecycle`, not a second AppState subscription: the SDK
|
|
368
|
+
// already owns one and fanning out from it keeps every consumer on the
|
|
369
|
+
// same transition sequence.
|
|
370
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
371
|
+
const {
|
|
372
|
+
appLifecycle
|
|
373
|
+
} = require('../core/lifecycle/appLifecycle');
|
|
374
|
+
this._otaForegroundListener = state => {
|
|
375
|
+
if (state === 'active') void runCheck('foreground');
|
|
376
|
+
};
|
|
377
|
+
appLifecycle.addListener(this._otaForegroundListener);
|
|
378
|
+
} catch {
|
|
379
|
+
// Lifecycle unavailable (tests, exotic hosts) — the startup check stands.
|
|
380
|
+
this._otaForegroundListener = null;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
_autoEnableDebug(debugConfig) {
|
|
384
|
+
try {
|
|
385
|
+
const dbgConfig = buildDebugConfigFromInitConfig(debugConfig);
|
|
386
|
+
if (!dbgConfig) return;
|
|
387
|
+
dbgConfig.__skipDeprecationWarning = true;
|
|
388
|
+
this.enableDebug(dbgConfig);
|
|
389
|
+
logger.info('[ScaleBun] Debug auto-connected via init({ debug }).');
|
|
390
|
+
} catch (err) {
|
|
391
|
+
logger.warn('[ScaleBun] Auto debug connection failed:', err?.message);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Keep /config (and with it the per-feature quota state) live for any clientKey-configured app.
|
|
397
|
+
*
|
|
398
|
+
* - Creates a quota-only ConfigManager when the appId-gated event tracker did not create one.
|
|
399
|
+
* Its exposure/stamp hooks are inert; it is not the flags API's manager.
|
|
400
|
+
* - Registers the FORCED refresh quotaState runs when a block's refresh time is reached (the
|
|
401
|
+
* only way a block is lifted — never the device clock alone).
|
|
402
|
+
* - Refreshes on foreground, throttled by ConfigManager's 5-minute TTL (ETag-aware), which is how
|
|
403
|
+
* a raised limit reaches a long-lived app.
|
|
404
|
+
*
|
|
405
|
+
* BEHAVIOUR CHANGE, deliberate (quota contract v1): apps WITHOUT an appId now fetch /config once
|
|
406
|
+
* per launch, and every clientKey app re-fetches it on foreground after 5 minutes. That fetch is
|
|
407
|
+
* how a block — and the raising of a limit — reaches the device; it is not an ingestion request.
|
|
408
|
+
* The quota-only manager applies NOTHING else from /config: no flags API, no experiment
|
|
409
|
+
* exposure, and no admin replayCapture override (that stays an appId-app behaviour, as before).
|
|
410
|
+
*/
|
|
411
|
+
_startConfigLifecycle() {
|
|
412
|
+
try {
|
|
413
|
+
const clientKey = this._clientKey;
|
|
414
|
+
const apiBaseUrl = this._apiBaseUrl;
|
|
415
|
+
if (!clientKey || !apiBaseUrl) return;
|
|
416
|
+
let mgr = this._configManager;
|
|
417
|
+
// Repeat init() without an appId: reuse the quota-only manager instead of stacking one
|
|
418
|
+
// ConfigManager (and one /config fetch) per call.
|
|
419
|
+
if (!mgr && this._configRefresher) mgr = this._configRefresher;
|
|
420
|
+
if (!mgr) {
|
|
421
|
+
mgr = new ConfigManager({
|
|
422
|
+
apiBaseUrl,
|
|
423
|
+
clientKey,
|
|
424
|
+
installationId: resolveInstallationId(),
|
|
425
|
+
emitExposure: () => {},
|
|
426
|
+
stamp: () => {}
|
|
427
|
+
// Quota only: no onReplayCapture — an app without appId never honored the admin
|
|
428
|
+
// capture override before, and fetching /config for quota must not change that.
|
|
429
|
+
});
|
|
430
|
+
mgr.refresh().catch(() => {});
|
|
431
|
+
}
|
|
432
|
+
this._configRefresher = mgr;
|
|
433
|
+
const refresher = mgr;
|
|
434
|
+
quotaState.setRefresher(() => refresher.refresh({
|
|
435
|
+
force: true
|
|
436
|
+
}));
|
|
437
|
+
if (this._configForegroundListener) return; // idempotent across repeated init()
|
|
438
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
439
|
+
const {
|
|
440
|
+
appLifecycle
|
|
441
|
+
} = require('../core/lifecycle/appLifecycle');
|
|
442
|
+
this._configForegroundListener = state => {
|
|
443
|
+
if (state === 'active') this._configRefresher?.maybeRefresh();
|
|
444
|
+
};
|
|
445
|
+
appLifecycle.addListener(this._configForegroundListener);
|
|
446
|
+
} catch (err) {
|
|
447
|
+
logger.warn('[ScaleBun] Config lifecycle unavailable:', err?.message);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Release what _startConfigLifecycle registered (the forced-refresh hook and the foreground
|
|
453
|
+
* listener). The facade has no teardown path today; this is the one to call when it gets one.
|
|
454
|
+
*/
|
|
455
|
+
_stopConfigLifecycle() {
|
|
456
|
+
try {
|
|
457
|
+
quotaState.setRefresher(null);
|
|
458
|
+
if (this._configForegroundListener) {
|
|
459
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
460
|
+
const {
|
|
461
|
+
appLifecycle
|
|
462
|
+
} = require('../core/lifecycle/appLifecycle');
|
|
463
|
+
appLifecycle.removeListener(this._configForegroundListener);
|
|
464
|
+
}
|
|
465
|
+
} catch {/* no-throw */}
|
|
466
|
+
this._configForegroundListener = null;
|
|
467
|
+
this._configRefresher = null;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/** Boot the Phase 1 envelope tracking lane if an appId is configured. */
|
|
471
|
+
_maybeStartEventTracker(rawConfig) {
|
|
472
|
+
try {
|
|
473
|
+
const appId = rawConfig?.appId;
|
|
474
|
+
const enabled = rawConfig?.eventTracking !== false;
|
|
475
|
+
const clientKey = this._clientKey ?? rawConfig?.clientKey;
|
|
476
|
+
// apiBaseUrl is LOCKED — use only the bootstrapped value, never fall back to raw
|
|
477
|
+
// integrator input, so the event-tracker/SKAdNetwork lane can't be repointed either.
|
|
478
|
+
const apiBaseUrl = this._apiBaseUrl;
|
|
479
|
+
if (!enabled || !appId || !clientKey || !apiBaseUrl) {
|
|
480
|
+
if (enabled && !appId) {
|
|
481
|
+
logger.info('[ScaleBun] Envelope event tracking disabled — no appId in init config.');
|
|
482
|
+
}
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
// Phase 3: auto-apply SKAdNetwork conversion values from the server-side
|
|
486
|
+
// CV schema (iOS only; no-op elsewhere). Created BEFORE the tracker so the
|
|
487
|
+
// onEvent hook is live for the very first event (first_open).
|
|
488
|
+
if (isSkanAvailable()) {
|
|
489
|
+
this._skanManager = new SkanConversionManager({
|
|
490
|
+
apiBaseUrl,
|
|
491
|
+
clientKey
|
|
492
|
+
});
|
|
493
|
+
this._skanManager.refreshSchema().catch(() => {});
|
|
494
|
+
}
|
|
495
|
+
this._eventTracker = new EventTracker({
|
|
496
|
+
appId,
|
|
497
|
+
clientKey,
|
|
498
|
+
apiBaseUrl,
|
|
499
|
+
// Auto-detected (Platform.OS) unless the integration overrides it — see resolveEventPlatform.
|
|
500
|
+
platform: rawConfig?.platform ?? resolveEventPlatform(),
|
|
501
|
+
appVersion: rawConfig?.appVersion,
|
|
502
|
+
osVersion: rawConfig?.osVersion,
|
|
503
|
+
autoLifecycleEvents: rawConfig?.autoLifecycleEvents !== false,
|
|
504
|
+
// Backward-compatible opt-in: existing init-only integrations do
|
|
505
|
+
// not begin uploading the new automatic collector stream merely
|
|
506
|
+
// because they upgraded the package. ScaleBunProvider sets this
|
|
507
|
+
// to true unless the integrator explicitly disables it.
|
|
508
|
+
automaticEventTracking: rawConfig?.automaticEventTracking === true,
|
|
509
|
+
flushIntervalMs: rawConfig?.flushIntervalMs,
|
|
510
|
+
/**
|
|
511
|
+
* DETECTED, not configured.
|
|
512
|
+
*
|
|
513
|
+
* This was `rawConfig?.context` — whatever the app typed. Production carries
|
|
514
|
+
* `device_model: "android"` and `manufacturer: "android"` from a hand-written
|
|
515
|
+
* literal, while the replay lane was reading the real values off the native bridge
|
|
516
|
+
* the whole time. The SDK knows the device; the integrator is guessing at it.
|
|
517
|
+
* Everything outside the detected keys is still theirs.
|
|
518
|
+
*/
|
|
519
|
+
// Everything Platform.constants knows. On iOS that is neither the model nor the
|
|
520
|
+
// manufacturer, so the bridge completes it below once it answers.
|
|
521
|
+
context: mergeDeviceContext(rawConfig?.context),
|
|
522
|
+
// Use the same foreground id as replay/journey capture. The
|
|
523
|
+
// callback is resolved per event because the session subsystem
|
|
524
|
+
// may start after this tracker is constructed.
|
|
525
|
+
sessionIdProvider: () => {
|
|
526
|
+
const manager = SessionManager.getExistingInstance();
|
|
527
|
+
return manager?.currentSessionId ?? manager?.getBackendTransport()?.analyticsSessionId ?? null;
|
|
528
|
+
},
|
|
529
|
+
// Feed every tracked event to the SKAN CV manager (iOS; no-op otherwise).
|
|
530
|
+
onEvent: (eventName, revenue) => this._skanManager?.onEvent(eventName, revenue)
|
|
531
|
+
});
|
|
532
|
+
this._eventTracker.start();
|
|
533
|
+
logger.info('[ScaleBun] Envelope event tracking started → /v1/batch.');
|
|
534
|
+
|
|
535
|
+
// Complete the device context from the native bridge.
|
|
536
|
+
//
|
|
537
|
+
// `Platform.constants` answers Android synchronously — model and manufacturer ride the
|
|
538
|
+
// first event. It answers NEITHER on iOS, so without this every iOS installation
|
|
539
|
+
// reported no device model at all: `nativeDeviceContext` existed for exactly this and
|
|
540
|
+
// had no caller, and the bridge's own answer was `UIDevice.current.model` — the string
|
|
541
|
+
// "iPhone", identical on every iPhone ever made.
|
|
542
|
+
//
|
|
543
|
+
// Fire-and-forget on purpose. The bridge is async and absent entirely on Expo Go or an
|
|
544
|
+
// older native binary; waiting on it would delay the first event, and failing on it
|
|
545
|
+
// would take analytics down over a nice-to-have field.
|
|
546
|
+
this._applyNativeDeviceContext(this._eventTracker);
|
|
547
|
+
|
|
548
|
+
// Android: capture the Play Install Referrer once per install → feeds the
|
|
549
|
+
// deterministic click_id path + a one-off install_referrer event (UTM/gclid).
|
|
550
|
+
// Fire-and-forget; no-op off Android.
|
|
551
|
+
this._captureInstallReferrer(this._eventTracker);
|
|
552
|
+
|
|
553
|
+
// Phase 4: runtime config (flags / remote config / experiments / rollouts).
|
|
554
|
+
// Resolves locally; exposure + stamps flow through the event lane above.
|
|
555
|
+
const tracker = this._eventTracker;
|
|
556
|
+
this._configManager = new ConfigManager({
|
|
557
|
+
apiBaseUrl,
|
|
558
|
+
clientKey,
|
|
559
|
+
installationId: tracker.ids.installationId,
|
|
560
|
+
emitExposure: (experiment, variant) => tracker.track('experiment_exposure', {
|
|
561
|
+
experiment,
|
|
562
|
+
variant
|
|
563
|
+
}),
|
|
564
|
+
stamp: (key, value) => tracker.stamp(key, value),
|
|
565
|
+
// Admin-controlled replay capture override: apply/revert timer capture as the
|
|
566
|
+
// server dictates, overriding the developer's local captureMode.
|
|
567
|
+
onReplayCapture: override => this._applyReplayCaptureOverride(override)
|
|
568
|
+
});
|
|
569
|
+
// Apply any cached override immediately (offline / pre-first-fetch); refresh() then
|
|
570
|
+
// re-applies with the latest value once /config responds.
|
|
571
|
+
this._applyReplayCaptureOverride(this._configManager.getReplayCapture());
|
|
572
|
+
this._configManager.refresh().catch(() => {});
|
|
573
|
+
} catch (err) {
|
|
574
|
+
logger.warn('[ScaleBun] Failed to start envelope event tracking:', err?.message);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Fold the native bridge's device facts into the analytics context once it answers.
|
|
580
|
+
*
|
|
581
|
+
* Detected values never overwrite a populated one with an empty one — `nativeDeviceContext`
|
|
582
|
+
* drops absent keys and `applyDetectedContext` ignores an empty patch — so a bridge that
|
|
583
|
+
* cannot answer leaves whatever `Platform.constants` already found.
|
|
584
|
+
*/
|
|
585
|
+
_applyNativeDeviceContext(tracker) {
|
|
586
|
+
Promise.resolve().then(() => bridgeAdapter.getDeviceInfo()).then(info => {
|
|
587
|
+
if (!info) return;
|
|
588
|
+
tracker.applyDetectedContext(nativeDeviceContext({
|
|
589
|
+
osVersion: info.osVersion,
|
|
590
|
+
deviceModel: info.deviceModel
|
|
591
|
+
// iOS ships no manufacturer over the bridge; it is a constant there and the
|
|
592
|
+
// static path already set it. Android's arrives via Platform.constants.
|
|
593
|
+
}));
|
|
594
|
+
}).catch(() => {/* bridge unavailable — the static context stands */});
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Apply (or revert) the admin-controlled replay capture override delivered via GET /config.
|
|
599
|
+
*
|
|
600
|
+
* When the super-admin has forced timer capture, `override` is `{ mode: 'frequency', intervalMs }`
|
|
601
|
+
* and we switch replay to frequency at that interval — overriding the developer's local
|
|
602
|
+
* captureMode (which Part 1 restricts to navigation/interactions). When the override is withdrawn
|
|
603
|
+
* (`null`) AND we had previously applied one, we revert to the developer's configured mode.
|
|
604
|
+
*
|
|
605
|
+
* Non-throwing and a no-op when replay is disabled. Idempotent — re-applying the same override
|
|
606
|
+
* just re-asserts the native state, which is harmless.
|
|
607
|
+
*/
|
|
608
|
+
_applyReplayCaptureOverride(override) {
|
|
609
|
+
try {
|
|
610
|
+
if (this._features.replay === false) return; // replay off — nothing to drive
|
|
611
|
+
if (override && override.mode === 'frequency') {
|
|
612
|
+
this._replayOverrideActive = true;
|
|
613
|
+
this.replay.setCaptureMode('frequency').catch(() => {});
|
|
614
|
+
ReplaySdk.setScreenshotCaptureInterval(override.intervalMs).catch(() => {});
|
|
615
|
+
} else if (this._replayOverrideActive) {
|
|
616
|
+
// Override withdrawn — restore the developer's configured captureMode.
|
|
617
|
+
this._replayOverrideActive = false;
|
|
618
|
+
this.replay.setCaptureMode(this._devCaptureMode).catch(() => {});
|
|
619
|
+
}
|
|
620
|
+
} catch {/* no-throw */}
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Android-only: read the Play Install Referrer once per install and route it into
|
|
624
|
+
* attribution. `scalebun_click_id` → the deterministic click path; the full
|
|
625
|
+
* referrer (utm_source/gclid/…) rides on a one-off `install_referrer` event. A
|
|
626
|
+
* `null` fetch (Play unavailable/transient) is not marked captured, so a later
|
|
627
|
+
* launch retries while Play still has the referrer. Never throws.
|
|
628
|
+
*/
|
|
629
|
+
_captureInstallReferrer(tracker) {
|
|
630
|
+
try {
|
|
631
|
+
if (!isInstallReferrerAvailable()) return;
|
|
632
|
+
const storage = createStorageBackend();
|
|
633
|
+
const KEY = 'scalebun_install_referrer_done';
|
|
634
|
+
const sink = {
|
|
635
|
+
alreadyCaptured: () => {
|
|
636
|
+
try {
|
|
637
|
+
return storage.get(KEY) === '1';
|
|
638
|
+
} catch {
|
|
639
|
+
return false;
|
|
640
|
+
}
|
|
641
|
+
},
|
|
642
|
+
markCaptured: () => {
|
|
643
|
+
try {
|
|
644
|
+
storage.set(KEY, '1');
|
|
645
|
+
} catch {/* no-throw */}
|
|
646
|
+
},
|
|
647
|
+
setClickId: id => tracker.setAttributionClickId(id),
|
|
648
|
+
emit: (name, props) => tracker.track(name, props),
|
|
649
|
+
fetch: () => getInstallReferrer()
|
|
650
|
+
};
|
|
651
|
+
void captureInstallReferrerOnce(sink);
|
|
652
|
+
} catch (err) {
|
|
653
|
+
logger.warn('[ScaleBun] Install Referrer capture failed:', err?.message);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* Phase 1 envelope event tracking API (POST /v1/batch).
|
|
659
|
+
* Methods are no-ops (never throw) until init() is called with an `appId`.
|
|
660
|
+
*/
|
|
661
|
+
get events() {
|
|
662
|
+
const tracker = this._eventTracker;
|
|
663
|
+
return {
|
|
664
|
+
track: (eventName, properties) => tracker?.track(eventName, properties),
|
|
665
|
+
identify: (userId, traits) => tracker?.identify(userId, traits),
|
|
666
|
+
trackPurchase: input => tracker?.trackPurchase(input),
|
|
667
|
+
trackSubscription: input => tracker?.trackSubscription(input),
|
|
668
|
+
setIdentifiers: ids => tracker?.setIdentifiers(ids),
|
|
669
|
+
// Phase 2: record a deferred deep-link click token for deterministic install attribution.
|
|
670
|
+
setAttributionClickId: clickId => tracker?.setAttributionClickId(clickId),
|
|
671
|
+
flush: () => tracker?.flush() ?? Promise.resolve(),
|
|
672
|
+
newSession: () => tracker?.newSession(),
|
|
673
|
+
ids: () => tracker?.ids ?? null,
|
|
674
|
+
/** Pending and dropped event counts for host diagnostics. */
|
|
675
|
+
stats: () => tracker?.stats ?? null,
|
|
676
|
+
// Phase 3: update the SKAdNetwork conversion value (iOS only; no-op elsewhere).
|
|
677
|
+
updateSkanConversionValue: (value, coarseValue, lockWindow) => updateSkanConversionValue(value, coarseValue, lockWindow)
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Phase 4: runtime config delivered via GET /v1/config. All resolution is local
|
|
683
|
+
* and non-throwing; values default sensibly until init() runs / config is fetched.
|
|
684
|
+
*
|
|
685
|
+
* ScaleBun.config.get('max_items', 10)
|
|
686
|
+
* ScaleBun.flags.isEnabled('new_checkout')
|
|
687
|
+
* ScaleBun.rollouts.isOn('beta_paywall')
|
|
688
|
+
* ScaleBun.experiments.variant('checkout_cta') // → 'control' | 'treatment' | null
|
|
689
|
+
*/
|
|
690
|
+
get config() {
|
|
691
|
+
const cm = this._configManager;
|
|
692
|
+
return {
|
|
693
|
+
get: (key, fallback) => cm ? cm.get(key, fallback) : fallback,
|
|
694
|
+
refresh: () => cm?.refresh() ?? Promise.resolve()
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
get flags() {
|
|
698
|
+
const cm = this._configManager;
|
|
699
|
+
return {
|
|
700
|
+
isEnabled: key => cm?.isEnabled(key) ?? false
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
get rollouts() {
|
|
704
|
+
const cm = this._configManager;
|
|
705
|
+
return {
|
|
706
|
+
isOn: key => cm?.rolloutIsOn(key) ?? false
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
get experiments() {
|
|
710
|
+
const cm = this._configManager;
|
|
711
|
+
return {
|
|
712
|
+
variant: key => cm?.variant(key) ?? null
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
/** Convenience: emit a Phase 1 purchase event (revenue + currency + transaction_id). */
|
|
717
|
+
/**
|
|
718
|
+
* Declare which UI state the user is looking at, so taps are attributed to the surface they
|
|
719
|
+
* happened on rather than averaged across every variant of the screen.
|
|
720
|
+
*
|
|
721
|
+
* ScaleBun.setUiState('filter-sheet', 'open');
|
|
722
|
+
* ScaleBun.setUiState('checkout-step', 'payment');
|
|
723
|
+
*
|
|
724
|
+
* Call it when the state CHANGES — the value is read at tap time, so it only has to be right by
|
|
725
|
+
* the time the next tap lands. On React Native this is the ONLY source of UI state: unlike the web,
|
|
726
|
+
* there is no queryable accessibility tree that says a sheet is up, and guessing would produce a
|
|
727
|
+
* state key that is right on some apps and silently wrong on others.
|
|
728
|
+
*
|
|
729
|
+
* Names and values are identifiers, not content: they become query keys in the dashboard, so a
|
|
730
|
+
* person's name or a cart total does not belong in one. `;`, `:` and `|` are stripped and both
|
|
731
|
+
* halves are capped at 32 characters.
|
|
732
|
+
*/
|
|
733
|
+
setUiState(name, value) {
|
|
734
|
+
try {
|
|
735
|
+
const {
|
|
736
|
+
setUiState
|
|
737
|
+
} = require('../features/journey/uiState');
|
|
738
|
+
setUiState(name, value);
|
|
739
|
+
} catch {/* no-throw: a state declaration must never break the host */}
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* Stop reporting a UI state dimension — or, with no argument, all of them.
|
|
744
|
+
*
|
|
745
|
+
* Clear on screen unmount. A declaration left behind follows the user onto a surface where it means
|
|
746
|
+
* nothing, and every tap there is filed under a state that was not on screen.
|
|
747
|
+
*/
|
|
748
|
+
clearUiState(name) {
|
|
749
|
+
try {
|
|
750
|
+
const {
|
|
751
|
+
clearUiState
|
|
752
|
+
} = require('../features/journey/uiState');
|
|
753
|
+
clearUiState(name);
|
|
754
|
+
} catch {/* no-throw */}
|
|
755
|
+
}
|
|
756
|
+
trackPurchase(input) {
|
|
757
|
+
noThrow(() => this._eventTracker?.trackPurchase(input));
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/** Record a trial, renewal, plan change or cancellation in the subscription ledger. */
|
|
761
|
+
trackSubscription(input) {
|
|
762
|
+
noThrow(() => this._eventTracker?.trackSubscription(input));
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* Phase 3: set the SKAdNetwork fine conversion value (0–63), optionally with a
|
|
767
|
+
* SKAN 4.0 coarse value and window-lock. iOS only — a no-op on Android / Expo Go.
|
|
768
|
+
*/
|
|
769
|
+
updateSkanConversionValue(value, coarseValue, lockWindow) {
|
|
770
|
+
noThrow(() => {
|
|
771
|
+
void updateSkanConversionValue(value, coarseValue, lockWindow);
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
// ─── Feature Flags ──────────────────────────────────────────────────
|
|
776
|
+
|
|
777
|
+
/** Get the current feature flags (consumed by enableDebug) */
|
|
778
|
+
getFeatureFlags() {
|
|
779
|
+
return this._features;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// ─── Identity ───────────────────────────────────────────────────────
|
|
783
|
+
|
|
784
|
+
/** Identify a user by ID and optional traits */
|
|
785
|
+
identify(userId, traits) {
|
|
786
|
+
return noThrow(() => {
|
|
787
|
+
this._identifiedUserId = userId;
|
|
788
|
+
if (!this.initialized) {
|
|
789
|
+
this._pendingIdentity = {
|
|
790
|
+
userId,
|
|
791
|
+
traits
|
|
792
|
+
};
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
this._pendingIdentity = null;
|
|
796
|
+
// Forward to the Phase 1 envelope lane (sets user_id for subsequent events).
|
|
797
|
+
this._eventTracker?.identify(userId, traits);
|
|
798
|
+
/**
|
|
799
|
+
* The session marker carries the user id ONLY — never the traits.
|
|
800
|
+
*
|
|
801
|
+
* This used to spread `...traits` into the event, and `track()` uploads it as a
|
|
802
|
+
* `USER_ACTION` on the session lane, unredacted. Production held 751 such rows in 7
|
|
803
|
+
* days with name/email/phone-verified fields in `replay_events.data`, shown in the
|
|
804
|
+
* replay timeline as user actions. Traits already travel on the lanes built for them:
|
|
805
|
+
* `_eventTracker.identify` above and the ingestion identify POST below.
|
|
806
|
+
*/
|
|
807
|
+
this.track('$identify', {
|
|
808
|
+
id: userId
|
|
809
|
+
});
|
|
810
|
+
const sessionId = SessionManager.getExistingInstance()?.currentSessionId;
|
|
811
|
+
if (this._clientKey && sessionId) {
|
|
812
|
+
// Skip the network POST when the same identity was already sent for this
|
|
813
|
+
// session (repeat identify() with identical traits is a no-op upsert).
|
|
814
|
+
const identityKey = `${sessionId}|${userId}|${JSON.stringify(traits ?? {})}`;
|
|
815
|
+
if (identityKey !== this._lastIngestionIdentityKey) {
|
|
816
|
+
this._lastIngestionIdentityKey = identityKey;
|
|
817
|
+
const user = {
|
|
818
|
+
id: userId,
|
|
819
|
+
name: traits?.name,
|
|
820
|
+
email: traits?.email,
|
|
821
|
+
properties: traits
|
|
822
|
+
};
|
|
823
|
+
this._callIngestionIdentify(sessionId, user).catch(() => {
|
|
824
|
+
// Re-arm on failure so a later retry is not suppressed.
|
|
825
|
+
this._lastIngestionIdentityKey = null;
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* Stable public alias for {@link identify}. Part of the minimal public push
|
|
834
|
+
* API surface (ScaleBun.init / identifyUser / enablePush) that stays
|
|
835
|
+
* identical across RN versions and future platforms.
|
|
836
|
+
*/
|
|
837
|
+
identifyUser(userId, traits) {
|
|
838
|
+
return this.identify(userId, traits);
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
/** POST user identity to the SaaS ingestion identify endpoint */
|
|
842
|
+
async _callIngestionIdentify(sessionId, user) {
|
|
843
|
+
if (!this._clientKey || !this._apiBaseUrl) return;
|
|
844
|
+
const url = `${this._apiBaseUrl}/ingestion/sessions/${sessionId}/identify`;
|
|
845
|
+
try {
|
|
846
|
+
await fetch(url, {
|
|
847
|
+
method: 'POST',
|
|
848
|
+
headers: {
|
|
849
|
+
'Content-Type': 'application/json',
|
|
850
|
+
'x-scalebun-client-key': this._clientKey
|
|
851
|
+
},
|
|
852
|
+
body: JSON.stringify({
|
|
853
|
+
userId: user.id,
|
|
854
|
+
username: user.name,
|
|
855
|
+
email: user.email,
|
|
856
|
+
properties: user.properties
|
|
857
|
+
})
|
|
858
|
+
});
|
|
859
|
+
} catch (err) {
|
|
860
|
+
logger.warn('[ScaleBun] ingestion identify failed:', err?.message);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
/** Set user identity (for session context) */
|
|
865
|
+
setUser(user) {
|
|
866
|
+
return noThrow(() => {
|
|
867
|
+
this.identify(user.id, {
|
|
868
|
+
name: user.name,
|
|
869
|
+
email: user.email,
|
|
870
|
+
...user.attributes
|
|
871
|
+
});
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* Clear user identity.
|
|
877
|
+
*
|
|
878
|
+
* SB-11: pass `{ purgeLocal: true }` on logout / consent withdrawal to also
|
|
879
|
+
* erase all locally-stored SDK data (see {@link eraseLocalData}). Without it,
|
|
880
|
+
* behaviour is unchanged (identity-only clear).
|
|
881
|
+
*/
|
|
882
|
+
clearUser(options) {
|
|
883
|
+
return noThrow(() => {
|
|
884
|
+
this._identifiedUserId = null;
|
|
885
|
+
this._pendingIdentity = null;
|
|
886
|
+
if (!this.initialized) return;
|
|
887
|
+
this._eventTracker?.clearIdentity();
|
|
888
|
+
this.track('$clear_user', {});
|
|
889
|
+
if (options?.purgeLocal) void this.eraseLocalData();
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* SB-11: erase all locally-stored SDK data from the device — the durable event
|
|
895
|
+
* queue, the pre-init buffer, and the first-party KV store (cached install /
|
|
896
|
+
* anonymous / session IDs, plus any queued payloads including SB-26 disk data).
|
|
897
|
+
*
|
|
898
|
+
* Order matters: capture is stopped FIRST so nothing is written back in behind
|
|
899
|
+
* the delete. Best-effort and never throws.
|
|
900
|
+
*
|
|
901
|
+
* Note: native replay frames written to disk on iOS are addressed separately
|
|
902
|
+
* (SB-15); this covers every store reachable from JS today.
|
|
903
|
+
*/
|
|
904
|
+
async eraseLocalData() {
|
|
905
|
+
try {
|
|
906
|
+
// 1) Stop capture so no new frames/events are produced mid-erase.
|
|
907
|
+
try {
|
|
908
|
+
SessionManager.getExistingInstance()?.endSession('ended');
|
|
909
|
+
} catch {/* best-effort */}
|
|
910
|
+
// 2) Clear the durable queue and the pre-init buffer.
|
|
911
|
+
try {
|
|
912
|
+
this._getQueue().clear();
|
|
913
|
+
} catch {/* best-effort */}
|
|
914
|
+
try {
|
|
915
|
+
this._preInitBuffer.clear();
|
|
916
|
+
} catch {/* best-effort */}
|
|
917
|
+
// 3) Wipe the first-party KV store (cached IDs + any on-disk queue
|
|
918
|
+
// residue) by removing every key through the backend interface.
|
|
919
|
+
try {
|
|
920
|
+
const store = createStorageBackend();
|
|
921
|
+
for (const key of store.getAllKeys()) {
|
|
922
|
+
store.delete(key);
|
|
923
|
+
}
|
|
924
|
+
} catch {/* best-effort */}
|
|
925
|
+
} catch {
|
|
926
|
+
// Never throw — erasure is a safety operation on a best-effort basis.
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/**
|
|
931
|
+
* SB-11: record the user's data-collection consent. When `enabled` is false,
|
|
932
|
+
* capture is stopped immediately; pass `{ purgeLocal: true }` to also erase
|
|
933
|
+
* everything already stored locally. Never throws.
|
|
934
|
+
*/
|
|
935
|
+
setConsent(enabled, options) {
|
|
936
|
+
noThrow(() => {
|
|
937
|
+
if (enabled) return;
|
|
938
|
+
try {
|
|
939
|
+
SessionManager.getExistingInstance()?.endSession('ended');
|
|
940
|
+
} catch {/* best-effort */}
|
|
941
|
+
if (options?.purgeLocal) void this.eraseLocalData();
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* SB-10: return the effective privacy policy actually in force, resolving the
|
|
947
|
+
* public config against the SDK's safe defaults. Lets callers and tests assert
|
|
948
|
+
* what is active rather than guessing from the (previously dead) config object.
|
|
949
|
+
*/
|
|
950
|
+
getEffectivePrivacyPolicy() {
|
|
951
|
+
const p = this._privacyConfig ?? {};
|
|
952
|
+
return {
|
|
953
|
+
// Real default is true (matches the replay capture default) — the old
|
|
954
|
+
// doc comment claiming "false" was both wrong and less safe.
|
|
955
|
+
maskTextInputs: p.maskTextInputs ?? true,
|
|
956
|
+
maskImages: p.maskImages ?? false,
|
|
957
|
+
redactAuth: p.redactAuth ?? true,
|
|
958
|
+
redactCookies: p.redactCookies ?? true,
|
|
959
|
+
redactBodies: p.redactBodies ?? false
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
* Submit in-app rating (1-5 stars).
|
|
965
|
+
* Attaches to current session when available; otherwise sends standalone.
|
|
966
|
+
* Never throws.
|
|
967
|
+
*/
|
|
968
|
+
submitRating(input) {
|
|
969
|
+
return safeAsync(async () => {
|
|
970
|
+
if (!this._clientKey || !this._apiBaseUrl) return {
|
|
971
|
+
ok: false,
|
|
972
|
+
reason: 'sdk_not_configured'
|
|
973
|
+
};
|
|
974
|
+
const rating = Math.round(Number(input?.rating));
|
|
975
|
+
if (!Number.isFinite(rating) || rating < 1 || rating > 5) {
|
|
976
|
+
return {
|
|
977
|
+
ok: false,
|
|
978
|
+
reason: 'invalid_rating'
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
const sessionId = this.getActiveSessionId();
|
|
982
|
+
const meta = SessionManager.getExistingInstance()?.currentSessionMetadata;
|
|
983
|
+
const path = sessionId ? `/ingestion/sessions/${sessionId}/rating` : `/ingestion/ratings`;
|
|
984
|
+
const url = `${this._apiBaseUrl}${path}`;
|
|
985
|
+
try {
|
|
986
|
+
const res = await fetch(url, {
|
|
987
|
+
method: 'POST',
|
|
988
|
+
headers: {
|
|
989
|
+
'Content-Type': 'application/json',
|
|
990
|
+
'x-scalebun-client-key': this._clientKey
|
|
991
|
+
},
|
|
992
|
+
body: JSON.stringify({
|
|
993
|
+
rating,
|
|
994
|
+
comment: input.comment,
|
|
995
|
+
source: input.source ?? 'in_app',
|
|
996
|
+
appVersion: meta?.appVersion,
|
|
997
|
+
platform: meta?.platform,
|
|
998
|
+
// [ADDITIVE] idempotency + versioning (contract §1.4); omitted when unset.
|
|
999
|
+
...(input.clientRatingId ? {
|
|
1000
|
+
clientRatingId: input.clientRatingId
|
|
1001
|
+
} : {}),
|
|
1002
|
+
schemaVersion: ENGAGE_SCHEMA_VERSION
|
|
1003
|
+
})
|
|
1004
|
+
});
|
|
1005
|
+
if (!res.ok) {
|
|
1006
|
+
logger.warn('[ScaleBun] submitRating non-ok', res.status);
|
|
1007
|
+
return {
|
|
1008
|
+
ok: false,
|
|
1009
|
+
reason: 'http_error',
|
|
1010
|
+
status: res.status
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
return {
|
|
1014
|
+
ok: true
|
|
1015
|
+
};
|
|
1016
|
+
} catch (err) {
|
|
1017
|
+
logger.warn('[ScaleBun] submitRating failed:', err?.message);
|
|
1018
|
+
return {
|
|
1019
|
+
ok: false,
|
|
1020
|
+
reason: 'network_error'
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
getActiveSessionId() {
|
|
1026
|
+
try {
|
|
1027
|
+
return SessionManager.getExistingInstance()?.currentSessionId ?? null;
|
|
1028
|
+
} catch {}
|
|
1029
|
+
return null;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
// ─── Bug reports (F-BUG) ────────────────────────────────────────────
|
|
1033
|
+
|
|
1034
|
+
/**
|
|
1035
|
+
* Thin feature object; the facade owns the HTTP, mirroring the web SDK split.
|
|
1036
|
+
* Its only job here is raising the 'report' capture signal so replay flushes.
|
|
1037
|
+
*/
|
|
1038
|
+
_bugReport = new BugReportFeature();
|
|
1039
|
+
|
|
1040
|
+
/**
|
|
1041
|
+
* Submit a bug report against the CURRENT session.
|
|
1042
|
+
*
|
|
1043
|
+
* Mirrors the web SDK's `reportBugDetailed` ordering, which is load-bearing rather than
|
|
1044
|
+
* incidental:
|
|
1045
|
+
*
|
|
1046
|
+
* 1. resolve the session — a report with no session cannot be joined to its evidence
|
|
1047
|
+
* 2. signal 'report' — replay flushes its buffer so the report has visual context
|
|
1048
|
+
* 3. snapshot the anchor — BEFORE the POST. A flush asks the recorder to deliver pending
|
|
1049
|
+
* bytes; it cannot retroactively manufacture a frame, so an absent
|
|
1050
|
+
* coordinate must stay absent rather than becoming a misleading
|
|
1051
|
+
* "start of session" link in the dashboard
|
|
1052
|
+
* 4. build + POST — bounds enforced by buildBugReportPayload against the server DTO
|
|
1053
|
+
*
|
|
1054
|
+
* Returns the report id, or `{ e }` naming which branch failed — 'init' (SDK not configured)
|
|
1055
|
+
* reads differently from 'send' (network), and that difference is what tells an integrator
|
|
1056
|
+
* whether to check their setup or their connection. It never throws: this is called from a UI
|
|
1057
|
+
* the host app renders, usually from a user gesture, and an exception escaping into a React
|
|
1058
|
+
* Native render tree is a redbox shown to the customer's user over a report they were sending us.
|
|
1059
|
+
*/
|
|
1060
|
+
async reportBugDetailed(input) {
|
|
1061
|
+
if (!input || !input.message || input.message.trim().length === 0) {
|
|
1062
|
+
logger.warn('[ScaleBun] reportBug: a message is required');
|
|
1063
|
+
return {
|
|
1064
|
+
e: 'empty'
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
if (!this._clientKey || !this._apiBaseUrl) {
|
|
1068
|
+
logger.warn('[ScaleBun] reportBug: SDK is not configured (clientKey/apiBaseUrl)');
|
|
1069
|
+
return {
|
|
1070
|
+
e: 'init'
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
const sessionId = this.getActiveSessionId();
|
|
1074
|
+
if (!sessionId) {
|
|
1075
|
+
// No session means no row to attach to, and the ingestion route is session-scoped.
|
|
1076
|
+
logger.warn('[ScaleBun] reportBug: no active session');
|
|
1077
|
+
return {
|
|
1078
|
+
e: 'init'
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
try {
|
|
1082
|
+
// Flush replay into the session BEFORE reading the anchor below.
|
|
1083
|
+
this._bugReport.signalReport();
|
|
1084
|
+
const coord = this._replayCoord();
|
|
1085
|
+
const payload = buildBugReportPayload(input, this._recentBreadcrumbs(), {
|
|
1086
|
+
replayCoord: coord,
|
|
1087
|
+
timestamp: Date.now()
|
|
1088
|
+
});
|
|
1089
|
+
const res = await fetch(`${this._apiBaseUrl}/ingestion/sessions/${sessionId}/bug-reports`, {
|
|
1090
|
+
method: 'POST',
|
|
1091
|
+
headers: {
|
|
1092
|
+
'Content-Type': 'application/json',
|
|
1093
|
+
'x-scalebun-client-key': this._clientKey
|
|
1094
|
+
},
|
|
1095
|
+
body: JSON.stringify(payload)
|
|
1096
|
+
});
|
|
1097
|
+
if (!res.ok) {
|
|
1098
|
+
logger.warn('[ScaleBun] reportBug: server rejected the report', res.status);
|
|
1099
|
+
return {
|
|
1100
|
+
e: 'send'
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
const body = await res.json().catch(() => null);
|
|
1104
|
+
return body?.id ?? {
|
|
1105
|
+
e: 'send'
|
|
1106
|
+
};
|
|
1107
|
+
} catch (err) {
|
|
1108
|
+
logger.warn('[ScaleBun] reportBug failed:', err?.message);
|
|
1109
|
+
return {
|
|
1110
|
+
e: 'send'
|
|
1111
|
+
};
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
/**
|
|
1116
|
+
* The replay coordinate at submit time, or null.
|
|
1117
|
+
*
|
|
1118
|
+
* Deliberately returns null rather than a zeroed coordinate when replay is disabled, paused, or
|
|
1119
|
+
* has not produced a frame yet — see the anchor note on reportBug.
|
|
1120
|
+
*/
|
|
1121
|
+
/**
|
|
1122
|
+
* The replay coordinate at submit time.
|
|
1123
|
+
*
|
|
1124
|
+
* ALWAYS null today, deliberately and visibly.
|
|
1125
|
+
*
|
|
1126
|
+
* The web SDK reads this from its recorder, but the RN replay subsystem exposes no sequence or
|
|
1127
|
+
* segment accessor on its public API (features/replay/public/api.ts) -- there is currently no
|
|
1128
|
+
* supported way to ask it where playback is. Probing for it through an `any` cast would compile,
|
|
1129
|
+
* miss, and leave every report anchor-less while looking wired: the same defect as the existing
|
|
1130
|
+
* reportBug(), which emits an analytics event and looks like it files a report.
|
|
1131
|
+
*
|
|
1132
|
+
* Returning null keeps the payload HONEST -- buildBugReportPayload omits replaySeq entirely, so
|
|
1133
|
+
* the dashboard shows no anchor rather than a false one pointing at the start of the session.
|
|
1134
|
+
* To finish this: expose the current seq + segment id from the replay recorder, then read them
|
|
1135
|
+
* here. The payload builder and its contract tests already handle a real coordinate, including
|
|
1136
|
+
* a genuine seq of 0.
|
|
1137
|
+
*/
|
|
1138
|
+
_replayCoord() {
|
|
1139
|
+
return null;
|
|
1140
|
+
}
|
|
1141
|
+
/** Recent console breadcrumbs for quick triage. The full set already travels with the session. */
|
|
1142
|
+
_recentBreadcrumbs() {
|
|
1143
|
+
try {
|
|
1144
|
+
const f = this._loggerFeature ?? this._consoleFeature;
|
|
1145
|
+
return f?.getRecent?.() ?? [];
|
|
1146
|
+
} catch {
|
|
1147
|
+
return [];
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
// ─── Engage ─────────────────────────────────────────────────────────
|
|
1152
|
+
|
|
1153
|
+
/**
|
|
1154
|
+
* Lazily resolve the Engage transport. Requires a configured SaaS clientKey +
|
|
1155
|
+
* apiBaseUrl (same gate as the rating/ingestion lanes); returns null otherwise.
|
|
1156
|
+
* The transport mirrors the existing BackendSessionAdapter outbox: upload lanes
|
|
1157
|
+
* batch-flush and re-queue on failure, the config GET is a direct fetch.
|
|
1158
|
+
*/
|
|
1159
|
+
_getEngageTransport() {
|
|
1160
|
+
if (!this._clientKey || !this._apiBaseUrl) return null;
|
|
1161
|
+
if (!this._engageTransport) {
|
|
1162
|
+
this._engageTransport = new EngageTransport({
|
|
1163
|
+
endpoint: this._apiBaseUrl,
|
|
1164
|
+
clientKey: this._clientKey
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
return this._engageTransport;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
/**
|
|
1171
|
+
* Engage surface namespace (foundation: transport + native push-token plumbing).
|
|
1172
|
+
*
|
|
1173
|
+
* Rendering of campaigns/in-app messages is a SHARED cross-platform JS overlay
|
|
1174
|
+
* (D4) built in a later stage. This namespace exposes only the foundation:
|
|
1175
|
+
* versioned config fetch, idempotent response/event upload (via the existing
|
|
1176
|
+
* outbox), and native push-token registration on both platforms.
|
|
1177
|
+
*/
|
|
1178
|
+
engage = {
|
|
1179
|
+
/** Current external identity, forwarded by the provider for segment targeting. */
|
|
1180
|
+
getIdentifiedUserId: () => this._identifiedUserId ?? undefined,
|
|
1181
|
+
/**
|
|
1182
|
+
* Fetch the versioned Engage config (campaigns + in-app messages).
|
|
1183
|
+
*
|
|
1184
|
+
* slice-agent: the shared cross-platform JS overlay renderer consumes this
|
|
1185
|
+
* payload (EngageConfigResponse.campaigns / .inAppMessages) in a later stage.
|
|
1186
|
+
*/
|
|
1187
|
+
fetchConfig: async context => {
|
|
1188
|
+
const transport = this._getEngageTransport();
|
|
1189
|
+
if (!transport) return null;
|
|
1190
|
+
const [engageConfig, coachConfig] = await Promise.all([transport.fetchEngageConfig(context), transport.fetchCoachConfig()]);
|
|
1191
|
+
if (!engageConfig && !coachConfig) return null;
|
|
1192
|
+
const coachMessages = (coachConfig?.tours ?? []).filter(tour => Array.isArray(tour.steps) && tour.steps.length > 0).map(tour => ({
|
|
1193
|
+
id: tour.id,
|
|
1194
|
+
layout: 'tooltip',
|
|
1195
|
+
trigger: 'app_open',
|
|
1196
|
+
variantKey: 'coachmark_spotlight',
|
|
1197
|
+
revision: String(tour.version),
|
|
1198
|
+
preview: tour.preview === true,
|
|
1199
|
+
spec: {
|
|
1200
|
+
title: tour.name,
|
|
1201
|
+
body: tour.steps[0]?.body ?? tour.name,
|
|
1202
|
+
anchorKey: tour.steps[0]?.anchorKey,
|
|
1203
|
+
ext: {
|
|
1204
|
+
coachTourId: tour.id,
|
|
1205
|
+
coachTourVersion: tour.version,
|
|
1206
|
+
steps: tour.steps
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
}));
|
|
1210
|
+
return {
|
|
1211
|
+
configVersion: engageConfig?.configVersion ?? 1,
|
|
1212
|
+
serverTime: engageConfig?.serverTime ?? new Date().toISOString(),
|
|
1213
|
+
campaigns: engageConfig?.campaigns ?? [],
|
|
1214
|
+
inAppMessages: [...(engageConfig?.inAppMessages ?? []), ...coachMessages]
|
|
1215
|
+
};
|
|
1216
|
+
},
|
|
1217
|
+
/** Internal bridge used by the shared renderer to feed standalone tour analytics. */
|
|
1218
|
+
trackCoachmarkEvent: (name, properties) => {
|
|
1219
|
+
this.track(name, properties);
|
|
1220
|
+
},
|
|
1221
|
+
/**
|
|
1222
|
+
* DEBUG/DEV ONLY — clear the persisted in-app/campaign frequency-cap state
|
|
1223
|
+
* (every `scalebun_engage_throttle:*` key: impressions, showOnce/completed, cooldown).
|
|
1224
|
+
* Lets a tester see throttled/dismissed messages again WITHOUT uninstalling the
|
|
1225
|
+
* app. Does NOT change the device id (identity is preserved). Returns the number
|
|
1226
|
+
* of cleared entries. NOT a substitute for the real fix (revision-scoped state +
|
|
1227
|
+
* test-preview bypass already make normal Send Test work without this).
|
|
1228
|
+
*/
|
|
1229
|
+
clearInAppMessageCache: () => {
|
|
1230
|
+
return noThrow(() => new EngageThrottleStore().clearAll() + new EngageTestSeenStore().clear()) ?? 0;
|
|
1231
|
+
},
|
|
1232
|
+
/**
|
|
1233
|
+
* DEBUG/DEV ONLY — alias of {@link clearInAppMessageCache} with the broader name
|
|
1234
|
+
* used in docs. Resets all on-device in-app frequency/dismiss/impression state so
|
|
1235
|
+
* the next config poll can show messages again. Identity (device id) is untouched.
|
|
1236
|
+
*/
|
|
1237
|
+
resetInAppState: () => {
|
|
1238
|
+
// Clears BOTH lanes: production frequency/dismiss/impression state (throttle
|
|
1239
|
+
// store) AND the one-shot test-seen store — so a dismissed test reappears after
|
|
1240
|
+
// a debug reset (the "block forever UNLESS debug reset" contract). Identity
|
|
1241
|
+
// (device id) is a separate key and stays untouched.
|
|
1242
|
+
return noThrow(() => new EngageThrottleStore().clearAll() + new EngageTestSeenStore().clear()) ?? 0;
|
|
1243
|
+
},
|
|
1244
|
+
/**
|
|
1245
|
+
* Force an immediate flush of queued in-app events. The provider calls this right
|
|
1246
|
+
* after a TEST preview's impression/dismiss ACK so the backend consumes the
|
|
1247
|
+
* one-shot preview row promptly — a fast close→kill→reopen can't re-serve a
|
|
1248
|
+
* still-`delivered` test. Best-effort, never throws.
|
|
1249
|
+
*/
|
|
1250
|
+
flushEvents: () => {
|
|
1251
|
+
noThrow(() => this._getEngageTransport()?.flushEventsNow());
|
|
1252
|
+
},
|
|
1253
|
+
/**
|
|
1254
|
+
* DEBUG/DEV ONLY — force a fresh config fetch (deviceId in context) and return the
|
|
1255
|
+
* in-app messages the backend is serving THIS device right now, including any
|
|
1256
|
+
* queued test previews (`preview:true`). Use it to verify Send Test targeting/
|
|
1257
|
+
* delivery without rendering. Logs a one-line summary for the dev console.
|
|
1258
|
+
*/
|
|
1259
|
+
debugFetchInAppMessages: async context => {
|
|
1260
|
+
const cfg = await (this._getEngageTransport()?.fetchEngageConfig(context) ?? Promise.resolve(null));
|
|
1261
|
+
const messages = cfg?.inAppMessages ?? [];
|
|
1262
|
+
const previews = messages.filter(m => m.preview === true || m.isTest === true);
|
|
1263
|
+
logger.info(`[Engage] debugFetchInAppMessages → ${messages.length} message(s), ${previews.length} test preview(s)`);
|
|
1264
|
+
return messages;
|
|
1265
|
+
},
|
|
1266
|
+
/** Upload a survey/NPS/feedback response (idempotent, rides the outbox). */
|
|
1267
|
+
submitResponse: input => {
|
|
1268
|
+
noThrow(() => this._getEngageTransport()?.uploadEngageResponse(input));
|
|
1269
|
+
},
|
|
1270
|
+
/**
|
|
1271
|
+
* [P3-e] Submit a response carrying native attachments (screenshot/voice).
|
|
1272
|
+
* Presigns + PUTs bytes direct to storage, then enqueues the response with
|
|
1273
|
+
* key-only metadata linked by responseId. Falls back to a plain response
|
|
1274
|
+
* (no media) when storage is disabled. Best-effort, never throws.
|
|
1275
|
+
*/
|
|
1276
|
+
submitResponseWithAttachments: (input, attachments) => {
|
|
1277
|
+
noThrow(() => {
|
|
1278
|
+
void this._getEngageTransport()?.submitResponseWithAttachments(input, attachments);
|
|
1279
|
+
});
|
|
1280
|
+
},
|
|
1281
|
+
/**
|
|
1282
|
+
* [Slice D5] CONFIRMED response submit for the in-prompt submitting→success→error
|
|
1283
|
+
* UI. UNLIKE submitResponse*, this AWAITS real server persistence (presign+PUT any
|
|
1284
|
+
* audio/screenshot bytes, then a direct response POST) and REJECTS on failure so the
|
|
1285
|
+
* caller can show a retryable error. Idempotent: pass the SAME `responseId` on retry
|
|
1286
|
+
* — both response and attachments de-dupe server-side. Used by EVERY question type.
|
|
1287
|
+
*/
|
|
1288
|
+
submitResponseConfirmed: (input, attachments, opts) => {
|
|
1289
|
+
const transport = this._getEngageTransport();
|
|
1290
|
+
if (!transport) return Promise.reject(new Error('sdk_not_configured'));
|
|
1291
|
+
return transport.submitResponseConfirmed(input, attachments, opts);
|
|
1292
|
+
},
|
|
1293
|
+
/** Upload an in-app impression/click/dismiss event (idempotent, rides the outbox). */
|
|
1294
|
+
trackEvent: input => {
|
|
1295
|
+
noThrow(() => {
|
|
1296
|
+
const automaticName = {
|
|
1297
|
+
impression: 'in_app_displayed',
|
|
1298
|
+
rendered: 'in_app_displayed',
|
|
1299
|
+
completion: 'in_app_completed',
|
|
1300
|
+
click: 'in_app_clicked',
|
|
1301
|
+
dismiss: 'in_app_dismissed',
|
|
1302
|
+
interaction: 'in_app_interaction',
|
|
1303
|
+
render_failed: 'in_app_render_failed',
|
|
1304
|
+
cta_open_failed: 'in_app_cta_open_failed'
|
|
1305
|
+
};
|
|
1306
|
+
const eventName = automaticName[input.type];
|
|
1307
|
+
if (eventName) {
|
|
1308
|
+
emitAutomaticEvent(eventName, {
|
|
1309
|
+
campaign_id: input.campaignId,
|
|
1310
|
+
variant_id: input.variantId,
|
|
1311
|
+
preview_id: input.previewId,
|
|
1312
|
+
is_test: input.isTest,
|
|
1313
|
+
source: input.source,
|
|
1314
|
+
interaction_type: typeof input.meta?.type === 'string' ? input.meta.type : undefined
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
this._getEngageTransport()?.uploadEngageEvent(input);
|
|
1318
|
+
});
|
|
1319
|
+
},
|
|
1320
|
+
/** Upload an idempotent survey shown/started funnel beacon. */
|
|
1321
|
+
trackSurveyImpression: input => {
|
|
1322
|
+
noThrow(() => this._getEngageTransport()?.uploadSurveyImpression(input));
|
|
1323
|
+
},
|
|
1324
|
+
/**
|
|
1325
|
+
* Emit a rating-funnel tracking event (ratings-rebuild CONTRACT §1.2). These
|
|
1326
|
+
* are dimensioned FACTS feeding the Overview funnel — NOT campaign responses
|
|
1327
|
+
* (D1) — so they ride their own `/ingestion/rating-events` lane. Idempotent
|
|
1328
|
+
* (client `eventId`, D8). Best-effort, never throws.
|
|
1329
|
+
*/
|
|
1330
|
+
emitRatingEvent: input => {
|
|
1331
|
+
noThrow(() => {
|
|
1332
|
+
emitAutomaticEvent(input.type, {
|
|
1333
|
+
prompt_id: input.promptId,
|
|
1334
|
+
trigger_id: input.triggerId,
|
|
1335
|
+
variant_id: input.variantId,
|
|
1336
|
+
stars: input.stars
|
|
1337
|
+
});
|
|
1338
|
+
this._getEngageTransport()?.uploadRatingEvent(input);
|
|
1339
|
+
});
|
|
1340
|
+
},
|
|
1341
|
+
/**
|
|
1342
|
+
* Trigger the native in-app review sheet (Play In-App Review on Android,
|
|
1343
|
+
* SKStoreReviewController on iOS) — the genuinely-native leg of the rating
|
|
1344
|
+
* funnel (D5). Resolves `true` ONLY when the OS flow ran/resolved after a
|
|
1345
|
+
* positive route, so the caller emits `store_redirect_clicked` solely on a
|
|
1346
|
+
* `true` result. Fail-soft: resolves `false` when native review is unavailable.
|
|
1347
|
+
*/
|
|
1348
|
+
requestStoreReview: async () => {
|
|
1349
|
+
return (await safeAsync(async () => requestNativeStoreReview())) ?? false;
|
|
1350
|
+
},
|
|
1351
|
+
/**
|
|
1352
|
+
* Submit a 1–5 app-store rating via the EXISTING app-rating lane (D1 keeps
|
|
1353
|
+
* ratings a distinct funnel — NOT submitResponse). Delegates to the
|
|
1354
|
+
* facade's `submitRating`, threading the renderer's `clientRatingId` for
|
|
1355
|
+
* idempotency (D8). Used by the RATING_PROMPT render branch.
|
|
1356
|
+
*/
|
|
1357
|
+
submitRating: input => {
|
|
1358
|
+
noThrow(() => {
|
|
1359
|
+
void this.submitRating(input);
|
|
1360
|
+
});
|
|
1361
|
+
},
|
|
1362
|
+
/**
|
|
1363
|
+
* Acquire the native push token (FCM/APNs) and register it for delivery.
|
|
1364
|
+
* Subscribes to native token-refresh (rotation) so the backend always holds
|
|
1365
|
+
* the live token. Fail-soft: no-op when native push is unavailable.
|
|
1366
|
+
*/
|
|
1367
|
+
registerForPush: async () => {
|
|
1368
|
+
return safeAsync(async () => {
|
|
1369
|
+
const transport = this._getEngageTransport();
|
|
1370
|
+
if (!transport) return;
|
|
1371
|
+
const initial = await getNativePushToken();
|
|
1372
|
+
if (initial) {
|
|
1373
|
+
transport.registerDeviceToken({
|
|
1374
|
+
pushToken: initial.token,
|
|
1375
|
+
platform: initial.platform,
|
|
1376
|
+
pushProvider: initial.platform === 'ios' ? 'apns' : 'fcm'
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
// Avoid stacking listeners on repeated calls.
|
|
1381
|
+
this._engageTokenUnsubscribe?.();
|
|
1382
|
+
this._engageTokenUnsubscribe = subscribeNativePushTokenRefresh(refreshed => {
|
|
1383
|
+
this._getEngageTransport()?.registerDeviceToken({
|
|
1384
|
+
pushToken: refreshed.token,
|
|
1385
|
+
platform: refreshed.platform,
|
|
1386
|
+
pushProvider: refreshed.platform === 'ios' ? 'apns' : 'fcm'
|
|
1387
|
+
});
|
|
1388
|
+
});
|
|
1389
|
+
});
|
|
1390
|
+
}
|
|
1391
|
+
};
|
|
1392
|
+
|
|
1393
|
+
// ─── Push Notifications ─────────────────────────────────────────────
|
|
1394
|
+
|
|
1395
|
+
/**
|
|
1396
|
+
* Lazily build the PushManager. Backend token registration is injected and
|
|
1397
|
+
* routes through the existing Engage outbox (EngageTransport.registerDeviceToken),
|
|
1398
|
+
* so push reuses the SDK's single device-token lane rather than a parallel
|
|
1399
|
+
* fetch. Returns {ok:false} when the SDK isn't configured (clientKey absent).
|
|
1400
|
+
*/
|
|
1401
|
+
_getPushManager() {
|
|
1402
|
+
if (!this._pushManager) {
|
|
1403
|
+
this._pushManager = new PushManager({
|
|
1404
|
+
registerToken: async input => {
|
|
1405
|
+
const transport = this._getEngageTransport();
|
|
1406
|
+
if (!transport) return {
|
|
1407
|
+
ok: false,
|
|
1408
|
+
reason: 'sdk_not_configured'
|
|
1409
|
+
};
|
|
1410
|
+
transport.registerDeviceToken({
|
|
1411
|
+
pushToken: input.pushToken,
|
|
1412
|
+
platform: input.platform,
|
|
1413
|
+
pushProvider: input.pushProvider,
|
|
1414
|
+
sdkVersion: SDK_VERSION,
|
|
1415
|
+
...(this._eventTracker ? {
|
|
1416
|
+
installationId: this._eventTracker.getInstallationId()
|
|
1417
|
+
} : {})
|
|
1418
|
+
});
|
|
1419
|
+
return {
|
|
1420
|
+
ok: true
|
|
1421
|
+
};
|
|
1422
|
+
}
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
1425
|
+
return this._pushManager;
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
/**
|
|
1429
|
+
* Enable push notifications with smart, version-aware adapter selection.
|
|
1430
|
+
*
|
|
1431
|
+
* Detects the RN version, architecture (legacy bridge vs New
|
|
1432
|
+
* Architecture/bridgeless), whether @react-native-firebase/messaging is
|
|
1433
|
+
* installed & compatible, and whether the ScaleBunEngage native token bridge is
|
|
1434
|
+
* linked, then picks the safest supported path automatically: RNFirebase
|
|
1435
|
+
* (full callbacks) → native ScaleBunEngage bridge (token-only fallback that works
|
|
1436
|
+
* under bridgeless regardless of RNFirebase version) → manual → noop.
|
|
1437
|
+
*
|
|
1438
|
+
* Requests OS permission, creates the Android channel, acquires the push
|
|
1439
|
+
* token, keeps it in sync on refresh, registers it with the ScaleBun backend
|
|
1440
|
+
* (via the Engage outbox), and wires foreground/opened callbacks.
|
|
1441
|
+
*
|
|
1442
|
+
* Fails clearly (ok:false + actionable reason) when no usable provider
|
|
1443
|
+
* exists — never silently breaks. Never throws.
|
|
1444
|
+
*
|
|
1445
|
+
* ```ts
|
|
1446
|
+
* await ScaleBun.enablePush({
|
|
1447
|
+
* onForegroundNotification: (n) => {},
|
|
1448
|
+
* onNotificationOpened: (n) => {},
|
|
1449
|
+
* });
|
|
1450
|
+
* ```
|
|
1451
|
+
*/
|
|
1452
|
+
enablePush(options) {
|
|
1453
|
+
return this._getPushManager().enable(options ?? {});
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
/**
|
|
1457
|
+
* Subscribe to notifications received while the app is foregrounded. Thin,
|
|
1458
|
+
* platform-agnostic alias for `enablePush({ onForegroundNotification })`; use it
|
|
1459
|
+
* to attach a handler after enablePush. Returns an unsubscribe function. Inert
|
|
1460
|
+
* until push is enabled. (iOS direct APNs delivers these via the native
|
|
1461
|
+
* UNUserNotificationCenter surface.)
|
|
1462
|
+
*/
|
|
1463
|
+
onForegroundNotification(cb) {
|
|
1464
|
+
return noThrow(() => this._getPushManager().onForegroundNotification(cb)) ?? (() => {});
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
/**
|
|
1468
|
+
* Subscribe to the user tapping a notification (open / deep-link), including the
|
|
1469
|
+
* cold-start notification that launched the app. Thin alias for
|
|
1470
|
+
* `enablePush({ onNotificationOpened })`. Returns an unsubscribe function. The
|
|
1471
|
+
* event shape ({ data, title?, body? }) matches across Android and iOS.
|
|
1472
|
+
*/
|
|
1473
|
+
onNotificationOpened(cb) {
|
|
1474
|
+
return noThrow(() => this._getPushManager().onNotificationOpened(cb)) ?? (() => {});
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
/**
|
|
1478
|
+
* Push control namespace. Most apps only need {@link enablePush}; these are
|
|
1479
|
+
* for the manual/custom provider path and diagnostics.
|
|
1480
|
+
*/
|
|
1481
|
+
push = {
|
|
1482
|
+
/** Inject/rotate a token (manual provider) — syncs to the backend. */
|
|
1483
|
+
setToken: token => {
|
|
1484
|
+
noThrow(() => this._getPushManager().setToken(token));
|
|
1485
|
+
},
|
|
1486
|
+
/** Current push token, if acquired. */
|
|
1487
|
+
getToken: () => {
|
|
1488
|
+
return noThrow(() => this._getPushManager().getToken()) ?? null;
|
|
1489
|
+
},
|
|
1490
|
+
/** Deliver a foreground notification to registered callbacks (manual provider). */
|
|
1491
|
+
emitForeground: message => {
|
|
1492
|
+
noThrow(() => this._getPushManager().emitForeground(message));
|
|
1493
|
+
},
|
|
1494
|
+
/** Deliver a notification-open event to registered callbacks (manual provider). */
|
|
1495
|
+
emitNotificationOpened: message => {
|
|
1496
|
+
noThrow(() => this._getPushManager().emitNotificationOpened(message));
|
|
1497
|
+
},
|
|
1498
|
+
/** Current push status: selected adapter, usability, reason, token. */
|
|
1499
|
+
status: () => this._getPushManager().status(),
|
|
1500
|
+
/** Tear down all push listeners. */
|
|
1501
|
+
teardown: () => {
|
|
1502
|
+
noThrow(() => this._pushManager?.teardown());
|
|
1503
|
+
}
|
|
1504
|
+
};
|
|
1505
|
+
|
|
1506
|
+
// ─── Event Tracking ─────────────────────────────────────────────────
|
|
1507
|
+
|
|
1508
|
+
/**
|
|
1509
|
+
* Report the outcome of an OS permission prompt.
|
|
1510
|
+
*
|
|
1511
|
+
* Permission results were state the SDK held privately and never an event, so the core mobile
|
|
1512
|
+
* growth loop — "reached the paywall → was prompted → granted" — could not be expressed as a funnel.
|
|
1513
|
+
*
|
|
1514
|
+
* Notification permission is captured AUTOMATICALLY (the SDK runs that prompt itself, see
|
|
1515
|
+
* PushManager). Every other permission belongs to the host app: the SDK never sees a camera or
|
|
1516
|
+
* location request, so guessing at one would be inventing data. Call this right after the prompt
|
|
1517
|
+
* resolves:
|
|
1518
|
+
*
|
|
1519
|
+
* ```ts
|
|
1520
|
+
* const { status } = await Location.requestForegroundPermissionsAsync();
|
|
1521
|
+
* ScaleBun.trackPermission('location', status === 'granted' ? 'granted' : 'denied');
|
|
1522
|
+
* ```
|
|
1523
|
+
*
|
|
1524
|
+
* `permission` is free-form on purpose — platforms disagree on names and a fixed enum would go
|
|
1525
|
+
* stale — but stick to one spelling per permission or the funnel splits in two.
|
|
1526
|
+
*/
|
|
1527
|
+
trackPermission(permission, status, details) {
|
|
1528
|
+
return noThrow(() => {
|
|
1529
|
+
const name = String(permission || '').trim();
|
|
1530
|
+
if (!name) return; // Nothing to attribute the result to — drop rather than emit a blank.
|
|
1531
|
+
emitAutomaticEvent('permission_result', {
|
|
1532
|
+
...details,
|
|
1533
|
+
permission: name,
|
|
1534
|
+
status,
|
|
1535
|
+
// Distinguishes a host-reported result from the SDK's own push prompt.
|
|
1536
|
+
source: 'host'
|
|
1537
|
+
});
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
/** Track a named event with optional payload */
|
|
1542
|
+
track(name, payload) {
|
|
1543
|
+
return noThrow(() => {
|
|
1544
|
+
if (!this.initialized && !name.startsWith('$')) {
|
|
1545
|
+
logger.warn('SDK not initialized. Event dropped:', name);
|
|
1546
|
+
return;
|
|
1547
|
+
}
|
|
1548
|
+
logger.debug('Tracking event:', name);
|
|
1549
|
+
|
|
1550
|
+
// Fan this event out to the Engage trigger engine. Same single funnel,
|
|
1551
|
+
// extra observer — lets behavioral triggers (custom_event, failed_action,
|
|
1552
|
+
// after_crash, network_error, before_logout, …) fire off events the SDK
|
|
1553
|
+
// already produces, without a parallel capture pipeline.
|
|
1554
|
+
engageSignals.emit(name, payload);
|
|
1555
|
+
const adapter = SessionManager.getExistingInstance()?.getBackendTransport();
|
|
1556
|
+
// Internal-only signals ($network_request, …) fan out to engage/perf/debug below but
|
|
1557
|
+
// are never uploaded as session events — their data already travels on a dedicated
|
|
1558
|
+
// lane (see INTERNAL_ONLY_SIGNALS in analytics/eventLane). The uploaded copy was pure
|
|
1559
|
+
// duplication: ~15% of measured mobile event volume, filtered out as noise by every
|
|
1560
|
+
// dashboard reader.
|
|
1561
|
+
if (!isUploadedSessionEvent(name)) {
|
|
1562
|
+
// fall through to the in-process consumers
|
|
1563
|
+
} else if (this._clientKey && adapter) {
|
|
1564
|
+
// SaaS mode → always-on analytics ingestion lane (NOT /sdk/events).
|
|
1565
|
+
// sessionId is stamped by the lane at flush time, so the call-time
|
|
1566
|
+
// value is a placeholder; endpoint id == body sessionId by construction.
|
|
1567
|
+
adapter.trackEvent({
|
|
1568
|
+
eventId: generateEventId(),
|
|
1569
|
+
sessionId: adapter.analyticsSessionId ?? '',
|
|
1570
|
+
ts: Date.now(),
|
|
1571
|
+
type: name === '$log' ? 'LOG_EMITTED' : 'USER_ACTION',
|
|
1572
|
+
subtype: name,
|
|
1573
|
+
payload
|
|
1574
|
+
});
|
|
1575
|
+
} else {
|
|
1576
|
+
// Legacy mode (projectId/publishableKey): persistent queue → /sdk/events.
|
|
1577
|
+
const envelope = createEnvelope('event', {
|
|
1578
|
+
name,
|
|
1579
|
+
...payload
|
|
1580
|
+
});
|
|
1581
|
+
this._getQueue().add(envelope);
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
// Phase 1 analytics envelope lane (/batch → raw_events → events).
|
|
1585
|
+
// Runs alongside the session/replay lane above; only active when an
|
|
1586
|
+
// appId was configured at init. SDK-internal ($-prefixed) signals stay
|
|
1587
|
+
// on the session/debug lane and must not pollute the events table — the
|
|
1588
|
+
// split is owned by resolveEventLane (see analytics/eventLane).
|
|
1589
|
+
if (this._eventTracker && resolveEventLane(name) === 'analytics') {
|
|
1590
|
+
this._eventTracker.track(name, payload);
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
// Tap into debug stream if enabled (non-blocking)
|
|
1594
|
+
const stream = _getStream();
|
|
1595
|
+
if (stream) {
|
|
1596
|
+
stream.tapEnvelope(createEnvelope('event', {
|
|
1597
|
+
name,
|
|
1598
|
+
...payload
|
|
1599
|
+
}));
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
// Tap network events into performance feature
|
|
1603
|
+
if (name === '$network_request' && this._performanceFeature?.isActive && payload) {
|
|
1604
|
+
this._performanceFeature.processNetworkEvent(payload);
|
|
1605
|
+
}
|
|
1606
|
+
});
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
/**
|
|
1610
|
+
* Log a message. Delivered to BOTH lanes:
|
|
1611
|
+
* - the Diagnose → Logs lane (tagged `source: 'sdk'`), so an explicit `log()` call shows
|
|
1612
|
+
* up where a developer looks for logs. The method name promised this, but it previously
|
|
1613
|
+
* only emitted a `$log` analytics EVENT and never reached the Logs page.
|
|
1614
|
+
* - the analytics `$log` event (unchanged), so anything already built on it keeps working.
|
|
1615
|
+
* `queueLog` self-gates on `clientKey`, so the Logs-lane write is a no-op outside SaaS mode.
|
|
1616
|
+
*/
|
|
1617
|
+
log(level, message, data) {
|
|
1618
|
+
try {
|
|
1619
|
+
const transport = SessionManager.getExistingInstance()?.getBackendTransport();
|
|
1620
|
+
transport?.queueLog({
|
|
1621
|
+
level,
|
|
1622
|
+
message,
|
|
1623
|
+
source: 'sdk',
|
|
1624
|
+
platform: 'js',
|
|
1625
|
+
timestamp: new Date().toISOString(),
|
|
1626
|
+
...(data ? {
|
|
1627
|
+
metadata: data
|
|
1628
|
+
} : {})
|
|
1629
|
+
});
|
|
1630
|
+
} catch {/* no-throw: a logging call must never break the host app */}
|
|
1631
|
+
return this.track('$log', {
|
|
1632
|
+
level,
|
|
1633
|
+
message,
|
|
1634
|
+
...data
|
|
1635
|
+
});
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
/**
|
|
1639
|
+
* Capture a handled error/exception and deliver it to the backend
|
|
1640
|
+
* errors endpoint (shows up in the dashboard Crashes view).
|
|
1641
|
+
*
|
|
1642
|
+
* No-throw. Routes to: desktop debug stream ($crash event) + SaaS
|
|
1643
|
+
* backend errors ingestion (when a clientKey session is active).
|
|
1644
|
+
*/
|
|
1645
|
+
captureError(error, context) {
|
|
1646
|
+
return noThrow(() => {
|
|
1647
|
+
const err = typeof error === 'string' ? new Error(error) : error;
|
|
1648
|
+
const isFatal = context?.fatal ?? false;
|
|
1649
|
+
getCrashReporter().report({
|
|
1650
|
+
source: 'handled',
|
|
1651
|
+
type: context?.type ?? (isFatal ? 'crash' : 'handled'),
|
|
1652
|
+
isFatal,
|
|
1653
|
+
message: err.message,
|
|
1654
|
+
stack: err.stack,
|
|
1655
|
+
screenName: context?.screenName,
|
|
1656
|
+
metadata: context?.metadata
|
|
1657
|
+
});
|
|
1658
|
+
|
|
1659
|
+
// Flush the event queue (desktop $crash) too
|
|
1660
|
+
this.flush().catch(() => {});
|
|
1661
|
+
});
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
/**
|
|
1665
|
+
* DEV/TEST ONLY — trigger a real native crash to validate the native
|
|
1666
|
+
* capture → next-launch drain → backend pipeline. No-op when the native
|
|
1667
|
+
* module is unavailable. Do not ship calls to this in production code.
|
|
1668
|
+
*/
|
|
1669
|
+
nativeCrash() {
|
|
1670
|
+
return noThrow(() => triggerNativeCrash());
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
/** Report a bug (convenience wrapper over track) */
|
|
1674
|
+
reportBug(description, metadata) {
|
|
1675
|
+
// D11: this used to be ONLY `track('$bug_report')` — an analytics event
|
|
1676
|
+
// with zero consumers (no mapper, no handler, no BugReport row), so
|
|
1677
|
+
// /diagnose/bug-reports stayed empty forever for RN apps while the web
|
|
1678
|
+
// SDK used the real ingest. Route to the same endpoint the web SDK
|
|
1679
|
+
// uses; the analytics event is kept as a breadcrumb, not the delivery.
|
|
1680
|
+
try {
|
|
1681
|
+
const transport = SessionManager.getExistingInstance()?.getBackendTransport();
|
|
1682
|
+
transport?.submitBugReport({
|
|
1683
|
+
message: description,
|
|
1684
|
+
title: typeof metadata?.title === 'string' ? metadata.title : undefined,
|
|
1685
|
+
email: typeof metadata?.email === 'string' ? metadata.email : undefined
|
|
1686
|
+
});
|
|
1687
|
+
} catch {
|
|
1688
|
+
/* delivery is best-effort; the track below still records intent */
|
|
1689
|
+
}
|
|
1690
|
+
return this.track('$bug_report', {
|
|
1691
|
+
description,
|
|
1692
|
+
...metadata
|
|
1693
|
+
});
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
/** Set a custom attribute on the current session */
|
|
1697
|
+
setAttribute(key, value) {
|
|
1698
|
+
return this.track('$set_attribute', {
|
|
1699
|
+
key,
|
|
1700
|
+
value
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
// ─── Flush ──────────────────────────────────────────────────────────
|
|
1705
|
+
|
|
1706
|
+
/** Force-flush all pending events */
|
|
1707
|
+
async flush() {
|
|
1708
|
+
return safeAsync(async () => {
|
|
1709
|
+
if (!this.initialized) return;
|
|
1710
|
+
// SaaS mode has two analytics lanes: EventTracker writes normalized
|
|
1711
|
+
// product events to /batch, while BackendSessionAdapter writes the
|
|
1712
|
+
// matching timeline events to /ingestion/sessions/:id/events. Drain
|
|
1713
|
+
// both before an app background/navigation can suspend their timers.
|
|
1714
|
+
// The legacy persistent queue posts to /sdk/events, which the SaaS
|
|
1715
|
+
// backend does not serve, so it remains exclusive to legacy mode.
|
|
1716
|
+
if (this._clientKey) {
|
|
1717
|
+
const adapter = SessionManager.getExistingInstance()?.getBackendTransport();
|
|
1718
|
+
await Promise.all([this._eventTracker?.flush() ?? Promise.resolve(), adapter?.flushAnalytics() ?? Promise.resolve()]);
|
|
1719
|
+
return;
|
|
1720
|
+
}
|
|
1721
|
+
logger.debug('Flushing events from persistent queue...');
|
|
1722
|
+
const httpClient = coreContainer.get('HttpClient');
|
|
1723
|
+
await flushQueue(this._getQueue(), httpClient, getDeviceId());
|
|
1724
|
+
});
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
/**
|
|
1728
|
+
* Enable the debug subsystem.
|
|
1729
|
+
*
|
|
1730
|
+
* @deprecated Use `ScaleBun.init({ debug: true })` instead.
|
|
1731
|
+
* This method still works for backward compatibility.
|
|
1732
|
+
*/
|
|
1733
|
+
enableDebug(config) {
|
|
1734
|
+
return noThrow(() => {
|
|
1735
|
+
if (!config.__skipDeprecationWarning) {
|
|
1736
|
+
logger.warn('[ScaleBun] enableDebug() is deprecated. ' + 'Use ScaleBun.init({ ..., debug: true }) instead.');
|
|
1737
|
+
}
|
|
1738
|
+
const gatedConfig = applyFeatureGatesToDebugConfig(config, this._features);
|
|
1739
|
+
_enableDebug(gatedConfig);
|
|
1740
|
+
_setFlushFn(() => this.flush());
|
|
1741
|
+
const bootstrapPerfFeature = _getPerformanceFeature();
|
|
1742
|
+
if (bootstrapPerfFeature) {
|
|
1743
|
+
this._performanceFeature = bootstrapPerfFeature;
|
|
1744
|
+
logger.debug('Performance feature linked from bootstrap');
|
|
1745
|
+
}
|
|
1746
|
+
logger.info('Debug enabled');
|
|
1747
|
+
});
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
/** Disable the debug subsystem and clean up */
|
|
1751
|
+
disableDebug() {
|
|
1752
|
+
return noThrow(() => {
|
|
1753
|
+
_disableDebug();
|
|
1754
|
+
});
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
/**
|
|
1758
|
+
* Diagnostic-only: stamp the *expected* target for the very next gesture
|
|
1759
|
+
* event. Calibration screens call this immediately before their onPress
|
|
1760
|
+
* fires so SessionManager merges expectedTargetId / expectedNX / expectedNY
|
|
1761
|
+
* into the stored gesture payload. Pure observability — never affects
|
|
1762
|
+
* capture, normalization, or marker placement. TTL ≈ 500 ms.
|
|
1763
|
+
*/
|
|
1764
|
+
setCalibrationTarget(target) {
|
|
1765
|
+
noThrow(() => {
|
|
1766
|
+
const mod = require('../features/journey/calibrationContext');
|
|
1767
|
+
mod.setCalibrationTarget(target);
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
/**
|
|
1772
|
+
* Debug utilities namespace.
|
|
1773
|
+
* All methods are no-op if debug is not enabled.
|
|
1774
|
+
*/
|
|
1775
|
+
debug = {
|
|
1776
|
+
addBreadcrumb: (message, data) => {
|
|
1777
|
+
noThrow(() => _addBreadcrumb(message, data));
|
|
1778
|
+
},
|
|
1779
|
+
ping: () => {
|
|
1780
|
+
noThrow(() => _ping());
|
|
1781
|
+
},
|
|
1782
|
+
isEnabled: () => isDebugEnabled(),
|
|
1783
|
+
sendMetric: (name, value, unit, tags) => {
|
|
1784
|
+
sendDebugMetric(name, value, unit, tags);
|
|
1785
|
+
}
|
|
1786
|
+
};
|
|
1787
|
+
|
|
1788
|
+
// ─── Replay ─────────────────────────────────────────────────────────
|
|
1789
|
+
|
|
1790
|
+
/**
|
|
1791
|
+
* Session Replay namespace.
|
|
1792
|
+
* Provides control over session replay: recording, capture,
|
|
1793
|
+
* user identity, privacy, breadcrumbs, and transport.
|
|
1794
|
+
* All methods are no-op if replay feature is disabled.
|
|
1795
|
+
*/
|
|
1796
|
+
replay = {
|
|
1797
|
+
start: () => ReplaySdk.start(),
|
|
1798
|
+
stop: () => ReplaySdk.stop(),
|
|
1799
|
+
pause: () => ReplaySdk.pause(),
|
|
1800
|
+
resume: () => ReplaySdk.resume(),
|
|
1801
|
+
captureFrame: () => ReplaySdk.captureManualFrame(),
|
|
1802
|
+
setUser: user => ReplaySdk.setUser(user),
|
|
1803
|
+
clearUser: () => ReplaySdk.clearUser(),
|
|
1804
|
+
addBreadcrumb: breadcrumb => ReplaySdk.addBreadcrumb(breadcrumb),
|
|
1805
|
+
setPrivacy: opts => ReplaySdk.setPrivacyOptions(opts),
|
|
1806
|
+
setEnabled: enabled => ReplaySdk.setEnabled(enabled),
|
|
1807
|
+
setQuality: quality => ReplaySdk.setScreenshotQuality(quality),
|
|
1808
|
+
setCaptureMode: mode => ReplaySdk.setCapturingMode(mode),
|
|
1809
|
+
setScreen: name => ReplaySdk.setCurrentScreen(name),
|
|
1810
|
+
flush: () => ReplaySdk.flush(),
|
|
1811
|
+
get isRecording() {
|
|
1812
|
+
return ReplaySdk.isRecording;
|
|
1813
|
+
},
|
|
1814
|
+
get sessionId() {
|
|
1815
|
+
return ReplaySdk.sessionId;
|
|
1816
|
+
}
|
|
1817
|
+
};
|
|
1818
|
+
|
|
1819
|
+
// ─── Performance ────────────────────────────────────────────────────
|
|
1820
|
+
|
|
1821
|
+
/**
|
|
1822
|
+
* Performance monitoring namespace.
|
|
1823
|
+
* Provides control over custom traces, screen load markers,
|
|
1824
|
+
* and access to captured metrics.
|
|
1825
|
+
* All methods are no-op if performance feature is disabled.
|
|
1826
|
+
*/
|
|
1827
|
+
performance = {
|
|
1828
|
+
/** Start a custom trace. Returns traceId or null. */
|
|
1829
|
+
startTrace: name => {
|
|
1830
|
+
return this._performanceFeature?.startTrace(name) ?? null;
|
|
1831
|
+
},
|
|
1832
|
+
/** Stop a custom trace by ID. */
|
|
1833
|
+
stopTrace: traceId => {
|
|
1834
|
+
this._performanceFeature?.stopTrace(traceId);
|
|
1835
|
+
},
|
|
1836
|
+
/** Add a span to an active custom trace. */
|
|
1837
|
+
addTraceSpan: (traceId, name, durationMs, data) => {
|
|
1838
|
+
this._performanceFeature?.addTraceSpan(traceId, name, durationMs, data);
|
|
1839
|
+
},
|
|
1840
|
+
/** Attach a measurement to an active custom trace. */
|
|
1841
|
+
addTraceMeasurement: (traceId, name, value, unit) => {
|
|
1842
|
+
this._performanceFeature?.addTraceMeasurement(traceId, name, value, unit);
|
|
1843
|
+
},
|
|
1844
|
+
/** Mark the start of a screen load. */
|
|
1845
|
+
markScreenLoadStart: screenName => {
|
|
1846
|
+
this._performanceFeature?.markScreenLoadStart(screenName);
|
|
1847
|
+
},
|
|
1848
|
+
/** Mark the end of a screen load. */
|
|
1849
|
+
markScreenLoadEnd: screenName => {
|
|
1850
|
+
this._performanceFeature?.markScreenLoadEnd(screenName);
|
|
1851
|
+
},
|
|
1852
|
+
/** Set the current screen for context correlation. */
|
|
1853
|
+
setCurrentScreen: screenName => {
|
|
1854
|
+
this._performanceFeature?.setCurrentScreen(screenName);
|
|
1855
|
+
},
|
|
1856
|
+
/** Forward navigation state changes for auto screen load detection. */
|
|
1857
|
+
onNavigationStateChange: state => {
|
|
1858
|
+
this._performanceFeature?.onNavigationStateChange(state);
|
|
1859
|
+
},
|
|
1860
|
+
/** Check if performance monitoring is active */
|
|
1861
|
+
isActive: () => {
|
|
1862
|
+
return this._performanceFeature?.isActive ?? false;
|
|
1863
|
+
},
|
|
1864
|
+
/**
|
|
1865
|
+
* Send a raw performance metric through the transport.
|
|
1866
|
+
* Used for manual/simulated performance metrics.
|
|
1867
|
+
*/
|
|
1868
|
+
sendMetric: (name, value, unit, tags) => {
|
|
1869
|
+
if (!this._performanceFeature) {
|
|
1870
|
+
logger.warn('performance.sendMetric: PerformanceFeature not available — is debug enabled?');
|
|
1871
|
+
return;
|
|
1872
|
+
}
|
|
1873
|
+
this._performanceFeature.sendMetric(name, value, unit, tags);
|
|
1874
|
+
}
|
|
1875
|
+
};
|
|
1876
|
+
|
|
1877
|
+
// ─── Unified Session ────────────────────────────────────────────────
|
|
1878
|
+
|
|
1879
|
+
/**
|
|
1880
|
+
* Unified Session namespace.
|
|
1881
|
+
* Provides access to the unified SessionManager.
|
|
1882
|
+
* Sessions auto-start on desktop connect.
|
|
1883
|
+
*/
|
|
1884
|
+
session = {
|
|
1885
|
+
get isActive() {
|
|
1886
|
+
return SessionManager.getExistingInstance()?.isActive ?? false;
|
|
1887
|
+
},
|
|
1888
|
+
get currentSessionId() {
|
|
1889
|
+
return SessionManager.getExistingInstance()?.currentSessionId ?? null;
|
|
1890
|
+
},
|
|
1891
|
+
start: metadata => {
|
|
1892
|
+
const sm = SessionManager.getExistingInstance();
|
|
1893
|
+
if (!sm) {
|
|
1894
|
+
logger.warn('session.start() — SessionManager not available.');
|
|
1895
|
+
return false;
|
|
1896
|
+
}
|
|
1897
|
+
sm.startSession(metadata);
|
|
1898
|
+
logger.info('session.start() ✅ sessionId:', sm.currentSessionId);
|
|
1899
|
+
return true;
|
|
1900
|
+
},
|
|
1901
|
+
end: reason => {
|
|
1902
|
+
const sm = SessionManager.getExistingInstance();
|
|
1903
|
+
if (!sm || !sm.isActive) return false;
|
|
1904
|
+
sm.endSession(reason);
|
|
1905
|
+
logger.info('session.end() ✅');
|
|
1906
|
+
return true;
|
|
1907
|
+
},
|
|
1908
|
+
emitEvent: (type, data) => {
|
|
1909
|
+
const sm = SessionManager.getExistingInstance();
|
|
1910
|
+
if (!sm || !sm.isActive) return;
|
|
1911
|
+
sm.emitEvent(type, data);
|
|
1912
|
+
}
|
|
1913
|
+
};
|
|
1914
|
+
|
|
1915
|
+
// ─── Session Convenience Methods ────────────────────────────────────
|
|
1916
|
+
|
|
1917
|
+
/** Start a session (delegates to session namespace) */
|
|
1918
|
+
startSession(metadata) {
|
|
1919
|
+
return this.session.start(metadata);
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
/** Stop the current session (delegates to session namespace) */
|
|
1923
|
+
stopSession(reason) {
|
|
1924
|
+
return this.session.end(reason);
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
// ─── Report / Export ───────────────────────────────────────────
|
|
1928
|
+
|
|
1929
|
+
/**
|
|
1930
|
+
* Report generation and export namespace.
|
|
1931
|
+
*
|
|
1932
|
+
* Usage:
|
|
1933
|
+
* ```ts
|
|
1934
|
+
* // Export with default preset
|
|
1935
|
+
* const result = await ScaleBun.report.export();
|
|
1936
|
+
*
|
|
1937
|
+
* // Export with a named preset
|
|
1938
|
+
* const result = await ScaleBun.report.export('engineering');
|
|
1939
|
+
*
|
|
1940
|
+
* // Export with custom options
|
|
1941
|
+
* const result = await ScaleBun.report.export({ format: 'pdf', detail: 'detailed' });
|
|
1942
|
+
* ```
|
|
1943
|
+
*
|
|
1944
|
+
* Requires an active desktop debug connection (`debug: true` in init).
|
|
1945
|
+
*/
|
|
1946
|
+
report = {
|
|
1947
|
+
/**
|
|
1948
|
+
* Trigger a report export on the desktop application.
|
|
1949
|
+
*
|
|
1950
|
+
* @param presetOrOptions - Optional. A preset name ('executive', 'engineering', 'qa',
|
|
1951
|
+
* 'forensic', 'journey', 'compact') or a SimplifiedExportOptions object.
|
|
1952
|
+
* @returns Promise<ExportResult> with success status, file path, or error.
|
|
1953
|
+
*/
|
|
1954
|
+
export: presetOrOptions => {
|
|
1955
|
+
return _requestExport(presetOrOptions);
|
|
1956
|
+
},
|
|
1957
|
+
/** Set SDK-wide privacy settings for report generation. */
|
|
1958
|
+
setPrivacy: config => {
|
|
1959
|
+
this._privacyConfig = {
|
|
1960
|
+
...this._privacyConfig,
|
|
1961
|
+
...config
|
|
1962
|
+
};
|
|
1963
|
+
logger.debug('[report] Privacy config updated');
|
|
1964
|
+
},
|
|
1965
|
+
/** Set branding for exported reports. */
|
|
1966
|
+
setBranding: config => {
|
|
1967
|
+
this._brandingConfig = {
|
|
1968
|
+
...this._brandingConfig,
|
|
1969
|
+
...config
|
|
1970
|
+
};
|
|
1971
|
+
logger.debug('[report] Branding config updated');
|
|
1972
|
+
},
|
|
1973
|
+
/** Get current privacy config. */
|
|
1974
|
+
getPrivacy: () => ({
|
|
1975
|
+
...this._privacyConfig
|
|
1976
|
+
}),
|
|
1977
|
+
/** Get current branding config. */
|
|
1978
|
+
getBranding: () => ({
|
|
1979
|
+
...this._brandingConfig
|
|
1980
|
+
})
|
|
1981
|
+
};
|
|
1982
|
+
|
|
1983
|
+
// ─── Navigation ───────────────────────────────────────────────
|
|
1984
|
+
|
|
1985
|
+
/**
|
|
1986
|
+
* Set the React Navigation container ref for automatic screen detection.
|
|
1987
|
+
*
|
|
1988
|
+
* This is the **recommended** way to enable auto screen detection.
|
|
1989
|
+
* Once set, the SDK automatically detects screen changes and feeds them
|
|
1990
|
+
* to all subsystems (SessionManager, PerformanceFeature, ProfilerFeature).
|
|
1991
|
+
* No per-screen `<ScaleBunScreen>` or `useScaleBunScreen()` needed.
|
|
1992
|
+
*
|
|
1993
|
+
* ```ts
|
|
1994
|
+
* import { NavigationContainer } from '@react-navigation/native';
|
|
1995
|
+
* import ScaleBun from '@scalebun/react-native';
|
|
1996
|
+
*
|
|
1997
|
+
* const navigationRef = React.createRef();
|
|
1998
|
+
*
|
|
1999
|
+
* function App() {
|
|
2000
|
+
* useEffect(() => {
|
|
2001
|
+
* ScaleBun.setNavigationRef(navigationRef);
|
|
2002
|
+
* }, []);
|
|
2003
|
+
*
|
|
2004
|
+
* return (
|
|
2005
|
+
* <NavigationContainer ref={navigationRef}>
|
|
2006
|
+
* ...screens...
|
|
2007
|
+
* </NavigationContainer>
|
|
2008
|
+
* );
|
|
2009
|
+
* }
|
|
2010
|
+
* ```
|
|
2011
|
+
*/
|
|
2012
|
+
setNavigationRef(ref) {
|
|
2013
|
+
noThrow(() => {
|
|
2014
|
+
// Always stash on the global so heuristic polling / late consumers resolve it.
|
|
2015
|
+
globalThis.__scalebun_navigationRef = ref;
|
|
2016
|
+
|
|
2017
|
+
// Wire the LIVE AutoScreenDetector singleton (started by SDKBootstrapper in
|
|
2018
|
+
// production). _getAutoScreenDetector() is the debug-only handle and is null
|
|
2019
|
+
// when desktopDebug is off, so relying on it alone never wires the explicit
|
|
2020
|
+
// React-Navigation 'state' listener and degrades to slow heuristic polling.
|
|
2021
|
+
try {
|
|
2022
|
+
const {
|
|
2023
|
+
AutoScreenDetector
|
|
2024
|
+
} = require('../features/navigation/AutoScreenDetector');
|
|
2025
|
+
AutoScreenDetector.getInstance().setNavigationRef(ref);
|
|
2026
|
+
logger.info('[ScaleBun] Navigation ref set → auto screen detection active');
|
|
2027
|
+
} catch (err) {
|
|
2028
|
+
logger.debug('[ScaleBun] Navigation ref stashed (detector not ready):', err?.message);
|
|
2029
|
+
}
|
|
2030
|
+
});
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
|
|
2034
|
+
/** Singleton Facade instance */
|
|
2035
|
+
const instance = new ScaleBunFacade();
|
|
2036
|
+
export default instance;
|
|
2037
|
+
export { ScaleBunFacade };
|
|
2038
|
+
//# sourceMappingURL=ScaleBunFacade.js.map
|