@bugsee/react-native 0.0.0-stage → 7.0.0-beta2
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/BugseeReactNative.podspec +95 -0
- package/LICENSE +21 -0
- package/README.md +557 -2
- package/android/build.gradle +162 -0
- package/android/consumer-rules.pro +2 -0
- package/android/src/main/AndroidManifest.xml +33 -0
- package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
- package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
- package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
- package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
- package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
- package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
- package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
- package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
- package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
- package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
- package/app.plugin.js +4 -0
- package/ios/BGSRNConsoleCapture.h +52 -0
- package/ios/BGSRNConsoleCapture.mm +344 -0
- package/ios/BugseeModule.h +25 -0
- package/ios/BugseeModule.mm +2728 -0
- package/ios/Package.swift +71 -0
- package/ios/Support/Package.resolved +14 -0
- package/ios/Support/Package.swift +44 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
- package/ios/react-native-spm-prefix.h +10 -0
- package/native-versions.json +10 -0
- package/package.json +62 -3
- package/plugin/build/bundle-phase.d.ts +41 -0
- package/plugin/build/bundle-phase.js +116 -0
- package/plugin/build/bundle-phase.js.map +1 -0
- package/plugin/build/dsym-script.d.ts +32 -0
- package/plugin/build/dsym-script.js +159 -0
- package/plugin/build/dsym-script.js.map +1 -0
- package/plugin/build/endpoint.d.ts +30 -0
- package/plugin/build/endpoint.js +69 -0
- package/plugin/build/endpoint.js.map +1 -0
- package/plugin/build/gradle.d.ts +65 -0
- package/plugin/build/gradle.js +1066 -0
- package/plugin/build/gradle.js.map +1 -0
- package/plugin/build/index.d.ts +85 -0
- package/plugin/build/index.js +217 -0
- package/plugin/build/index.js.map +1 -0
- package/plugin/build/manifest.d.ts +48 -0
- package/plugin/build/manifest.js +69 -0
- package/plugin/build/manifest.js.map +1 -0
- package/plugin/build/native-versions.baked.json +4 -0
- package/plugin/build/native-versions.d.ts +10 -0
- package/plugin/build/native-versions.js +27 -0
- package/plugin/build/native-versions.js.map +1 -0
- package/plugin/build/pbx-string.d.ts +8 -0
- package/plugin/build/pbx-string.js +31 -0
- package/plugin/build/pbx-string.js.map +1 -0
- package/plugin/build/podfile.d.ts +3 -0
- package/plugin/build/podfile.js +28 -0
- package/plugin/build/podfile.js.map +1 -0
- package/plugin/build/properties.d.ts +19 -0
- package/plugin/build/properties.js +41 -0
- package/plugin/build/properties.js.map +1 -0
- package/plugin/build/scheme.d.ts +20 -0
- package/plugin/build/scheme.js +107 -0
- package/plugin/build/scheme.js.map +1 -0
- package/react-native.config.js +26 -0
- package/scripts/bugsee-sourcemaps.gradle +201 -0
- package/scripts/bugsee-xcode.sh +83 -0
- package/scripts/compose-then-inject.js +113 -0
- package/scripts/hermes-sourcemaps.js +634 -0
- package/scripts/hermesc-preserve-js.cmd +6 -0
- package/scripts/hermesc-preserve-js.js +200 -0
- package/scripts/hermesc-preserve-js.sh +7 -0
- package/src/NativeBugsee.ts +622 -0
- package/src/apm/notify.ts +58 -0
- package/src/apm/span.ts +403 -0
- package/src/apm/types.ts +57 -0
- package/src/appearance/report.ts +171 -0
- package/src/architecture.ts +48 -0
- package/src/attributes/errors.ts +39 -0
- package/src/attributes/validate.ts +150 -0
- package/src/breadcrumbs/add.ts +58 -0
- package/src/breadcrumbs/data.ts +33 -0
- package/src/breadcrumbs/filter.ts +215 -0
- package/src/breadcrumbs/types.ts +64 -0
- package/src/bridge/json.ts +110 -0
- package/src/console/capture.ts +180 -0
- package/src/console/dedup.ts +175 -0
- package/src/data/validate.ts +259 -0
- package/src/errorName.ts +32 -0
- package/src/exceptions/ErrorBoundary.tsx +92 -0
- package/src/exceptions/RootErrorReporter.tsx +61 -0
- package/src/exceptions/debugIds.ts +118 -0
- package/src/exceptions/handlers.ts +236 -0
- package/src/exceptions/options.ts +85 -0
- package/src/exceptions/payload.ts +456 -0
- package/src/exceptions/report.ts +170 -0
- package/src/exceptions/sha1.ts +148 -0
- package/src/exceptions/stack.ts +355 -0
- package/src/index.ts +962 -0
- package/src/logs/filter.ts +90 -0
- package/src/logs/log.ts +36 -0
- package/src/network/add.ts +165 -0
- package/src/network/filter.ts +198 -0
- package/src/options/AndroidLaunchOptions.ts +78 -0
- package/src/options/BugseeLaunchOptions.ts +190 -0
- package/src/options/IOSLaunchOptions.ts +57 -0
- package/src/options/android-options-manifest.json +646 -0
- package/src/options/createDefaultLaunchOptions.ts +29 -0
- package/src/options/endpoint.ts +58 -0
- package/src/options/enums.ts +104 -0
- package/src/options/ios-enums.json +19 -0
- package/src/options/keys.ts +39 -0
- package/src/options/option-enums.json +34 -0
- package/src/options/option-keys.json +107 -0
- package/src/report/BugseeReport.ts +264 -0
- package/src/report/CreatedReport.ts +127 -0
- package/src/report/dispatcher.ts +95 -0
- package/src/report/errors.ts +48 -0
- package/src/report/fields.ts +40 -0
- package/src/report/types.ts +157 -0
- package/src/report/validate.ts +197 -0
- package/src/secure/BugseeSecure.tsx +202 -0
- package/src/secure/ancestry.ts +622 -0
- package/src/secure/drivers.ts +342 -0
- package/src/secure/followEvents.ts +57 -0
- package/src/secure/hold.ts +99 -0
- package/src/secure/measureLoop.ts +323 -0
- package/src/secure/nativeAnimation.ts +1005 -0
- package/src/secure/rectangles.ts +93 -0
- package/src/secure/registry.ts +237 -0
- package/src/secure/surface.ts +83 -0
- package/src/secure/tracker.ts +723 -0
- package/src/secure/transition.ts +488 -0
- package/src/secure/unit.ts +22 -0
- package/src/status.ts +16 -0
- package/src/version.ts +9 -0
- package/src/viewtree/anchor.tsx +105 -0
- package/src/viewtree/constants.ts +20 -0
- package/src/viewtree/fiber.ts +251 -0
- package/src/viewtree/requests.ts +347 -0
- package/src/viewtree/walk.ts +902 -0
- package/src/wrapper/channel.ts +33 -0
- package/src/wrapper/collect.ts +52 -0
- package/src/wrapper/events.ts +45 -0
- package/src/wrapper/identity.ts +54 -0
- package/src/wrapper/lifecycle-events.ts +89 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import NativeBugsee from '../NativeBugsee';
|
|
2
|
+
import { LogLevel } from '../options/enums';
|
|
3
|
+
import { forwardLog } from '../wrapper/channel';
|
|
4
|
+
import {
|
|
5
|
+
claimEcho,
|
|
6
|
+
protectLine,
|
|
7
|
+
readDev,
|
|
8
|
+
shouldForwardJsPatch,
|
|
9
|
+
} from './dedup';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The launch option that turns console forwarding off. Absent means on,
|
|
13
|
+
* which is the SDK default. Read on every install, including a second one:
|
|
14
|
+
* the functions are wrapped only once, but a later `launch` / `relaunch` /
|
|
15
|
+
* `attach` can still stop or resume forwarding.
|
|
16
|
+
*/
|
|
17
|
+
const CAPTURE_LOGS_OPTION = 'com.bugsee.option.capture.logs';
|
|
18
|
+
|
|
19
|
+
const METHODS = ['error', 'warn', 'log', 'info', 'debug'] as const;
|
|
20
|
+
type ConsoleMethod = (typeof METHODS)[number];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* `console.error` → Error (1), `warn` → Warning (2), `log` and `info` →
|
|
24
|
+
* Info (3), `debug` → Debug (4). There is no `console.trace` mapping.
|
|
25
|
+
*/
|
|
26
|
+
const LEVEL_BY_METHOD: Record<ConsoleMethod, LogLevel> = {
|
|
27
|
+
error: LogLevel.Error,
|
|
28
|
+
warn: LogLevel.Warning,
|
|
29
|
+
log: LogLevel.Info,
|
|
30
|
+
info: LogLevel.Info,
|
|
31
|
+
debug: LogLevel.Debug,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
let installed = false;
|
|
35
|
+
let forwardEnabled!: boolean;
|
|
36
|
+
/** Set around the original console call when this patch will also forward. */
|
|
37
|
+
let expectingEcho = false;
|
|
38
|
+
|
|
39
|
+
interface NativeLoggingHost {
|
|
40
|
+
nativeLoggingHook?: (message: string, level: number) => void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface WrappedHook {
|
|
44
|
+
(message: string, level: number): void;
|
|
45
|
+
bugseeConsoleHook?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function loggingHost(): NativeLoggingHost {
|
|
49
|
+
return globalThis as NativeLoggingHost;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Wraps `nativeLoggingHook` once. The original hook still runs, so logcat
|
|
54
|
+
* and the Xcode console keep the line. While this patch is inside a console
|
|
55
|
+
* call it will forward, the hook's message is claimed before the original
|
|
56
|
+
* hook runs. That is before logcat is written, so the claim exists when the
|
|
57
|
+
* echo is filtered, even if the channel line has not been noted yet.
|
|
58
|
+
*
|
|
59
|
+
* `noteConsoleEcho` returns a value, so codegen runs it here on the JS
|
|
60
|
+
* thread, and the native credit exists before the original hook writes
|
|
61
|
+
* the line. A `void` method would be queued, and the SDK's logcat reader
|
|
62
|
+
* could filter the echo first.
|
|
63
|
+
*/
|
|
64
|
+
function installNativeHook(): void {
|
|
65
|
+
const host = loggingHost();
|
|
66
|
+
const current = host.nativeLoggingHook;
|
|
67
|
+
if (typeof current !== 'function' || isWrappedHook(current)) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const wrapped: WrappedHook = (message: string, level: number): void => {
|
|
71
|
+
if (expectingEcho) {
|
|
72
|
+
expectingEcho = false;
|
|
73
|
+
claimEcho(message);
|
|
74
|
+
// Synchronous, before the original hook writes logcat or os_log, so
|
|
75
|
+
// the native drop is armed when the echo is captured. Not a second
|
|
76
|
+
// log route. The returned value carries nothing.
|
|
77
|
+
try {
|
|
78
|
+
NativeBugsee.noteConsoleEcho(message);
|
|
79
|
+
} catch {
|
|
80
|
+
// The echo may reach the filter. The claim still drops a stamp.
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
current(message, level);
|
|
84
|
+
};
|
|
85
|
+
wrapped.bugseeConsoleHook = true;
|
|
86
|
+
host.nativeLoggingHook = wrapped;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function isWrappedHook(
|
|
90
|
+
hook: (message: string, level: number) => void,
|
|
91
|
+
): hook is WrappedHook {
|
|
92
|
+
return (hook as WrappedHook).bugseeConsoleHook === true;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* One argument, via `String`. That is the success path, including functions.
|
|
97
|
+
* `String` throws for a null-prototype object and for a throwing `toString`
|
|
98
|
+
* / `valueOf`. The fallback is the ordinary tag, which does not copy fields.
|
|
99
|
+
*/
|
|
100
|
+
function stringifyArg(arg: unknown): string {
|
|
101
|
+
try {
|
|
102
|
+
return String(arg);
|
|
103
|
+
} catch {
|
|
104
|
+
return Object.prototype.toString.call(arg);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* One console line, the way a console prints several arguments: joined with
|
|
110
|
+
* a space. Objects that `String` can convert stay `[object Object]` — they
|
|
111
|
+
* are not JSON, so a field that holds a secret is not copied into the log.
|
|
112
|
+
*/
|
|
113
|
+
function formatConsoleLine(args: readonly unknown[]): string {
|
|
114
|
+
// A loop, not map+join: the intermediate array showed up on this hot path.
|
|
115
|
+
let result = '';
|
|
116
|
+
let first = true;
|
|
117
|
+
for (const arg of args) {
|
|
118
|
+
result += (first ? '' : ' ') + stringifyArg(arg);
|
|
119
|
+
first = false;
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function patch(method: ConsoleMethod): void {
|
|
125
|
+
const level = LEVEL_BY_METHOD[method];
|
|
126
|
+
const original = console[method].bind(console);
|
|
127
|
+
const wrapped = (...args: unknown[]): void => {
|
|
128
|
+
const dev = readDev();
|
|
129
|
+
const owns = forwardEnabled && shouldForwardJsPatch(dev);
|
|
130
|
+
if (!owns) {
|
|
131
|
+
original(...args);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
// The patch owns the call, so the echo is claimed and the line is
|
|
135
|
+
// protected. That is shouldDropConsoleEcho(dev, true).
|
|
136
|
+
const line = formatConsoleLine(args);
|
|
137
|
+
expectingEcho = true;
|
|
138
|
+
try {
|
|
139
|
+
original(...args);
|
|
140
|
+
} finally {
|
|
141
|
+
expectingEcho = false;
|
|
142
|
+
}
|
|
143
|
+
// The channel can throw. The original call has already run; this wrap
|
|
144
|
+
// must not turn that into an uncaught exception.
|
|
145
|
+
try {
|
|
146
|
+
protectLine(line);
|
|
147
|
+
forwardLog(line, level);
|
|
148
|
+
} catch {
|
|
149
|
+
// Drop the line. The console call itself succeeded.
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
console[method] = wrapped as typeof console.log;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Patches `console.log`, `console.info`, `console.warn`, `console.error`
|
|
157
|
+
* and `console.debug`. Each call still performs the original console call,
|
|
158
|
+
* then forwards one line through `forwardLog` — the only native route for
|
|
159
|
+
* the patch. The app's log filter is not run here. Under `__DEV__` the
|
|
160
|
+
* same call also reaches `RCTLog`; that echo is claimed so the filter
|
|
161
|
+
* runs once. The patch still forwards in release: `RCTLog` does not carry
|
|
162
|
+
* `console.*` there.
|
|
163
|
+
*
|
|
164
|
+
* Idempotent. A second call does not wrap the already-patched functions.
|
|
165
|
+
* It does re-read `com.bugsee.option.capture.logs`: `false` stops
|
|
166
|
+
* forwarding, and an absent option leaves forwarding on.
|
|
167
|
+
*
|
|
168
|
+
* An explicit `Bugsee.log` does not go through this patch.
|
|
169
|
+
*/
|
|
170
|
+
export function installConsoleCapture(options: Record<string, unknown> = {}): void {
|
|
171
|
+
forwardEnabled = options[CAPTURE_LOGS_OPTION] !== false;
|
|
172
|
+
installNativeHook();
|
|
173
|
+
if (installed) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
installed = true;
|
|
177
|
+
for (const method of METHODS) {
|
|
178
|
+
patch(method);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which of the two console streams may reach the user's log filter.
|
|
3
|
+
*
|
|
4
|
+
* Under `__DEV__`, one `console.*` call is seen by the JS patch and by
|
|
5
|
+
* React Native's `RCTLog` (`nativeLoggingHook`). Both streams stay live:
|
|
6
|
+
* the patch is how a release build still records console output (React
|
|
7
|
+
* Native does not route `console.*` through `RCTLog` then, and a Hermes
|
|
8
|
+
* release build often strips the call before `RCTLog` could see it), and
|
|
9
|
+
* `RCTLog` is how RN-internal lines that the patch never sees are recorded.
|
|
10
|
+
*
|
|
11
|
+
* The overlap is removed by dropping the echo, not the patch. Dropping the
|
|
12
|
+
* patch because `RCTLog` "will also see it" would drop release logs.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** How long an echo claim can still suppress a second filter pass. */
|
|
16
|
+
export const ECHO_WINDOW_MS = 2_000;
|
|
17
|
+
|
|
18
|
+
const MAX_CLAIMS = 32;
|
|
19
|
+
|
|
20
|
+
interface Claim {
|
|
21
|
+
text: string;
|
|
22
|
+
expires: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Equal text and the stderr stamp are separate claims. Delivering the patch
|
|
27
|
+
* removes the equal-text claim on both platforms: Android already dropped
|
|
28
|
+
* the logcat echo, and iOS does not forward `RCTLogSourceJavaScript`.
|
|
29
|
+
* os_log capture is disabled, so there is no unstamped stderr copy to wait
|
|
30
|
+
* for. The stamp is a different string and is dropped on its own.
|
|
31
|
+
*/
|
|
32
|
+
const exactEchoes = new Array<Claim>();
|
|
33
|
+
const stampEchoes = new Array<Claim>();
|
|
34
|
+
const protectedLines = new Array<Claim>();
|
|
35
|
+
|
|
36
|
+
/** `__DEV__` when the runtime defined it, otherwise a release-shaped build. */
|
|
37
|
+
export function readDev(): boolean {
|
|
38
|
+
const devFlag = (globalThis as { __DEV__?: unknown }).__DEV__;
|
|
39
|
+
return typeof devFlag === 'boolean' ? devFlag : false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The JS patch forwards in dev and in release. A build that forwarded only
|
|
44
|
+
* in one of them would either double-filter dev or drop release.
|
|
45
|
+
*/
|
|
46
|
+
// The build flag is part of the signature. Both values forward.
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
48
|
+
export function shouldForwardJsPatch(dev: boolean): boolean {
|
|
49
|
+
// Dev and release both forward. The argument stays so a caller cannot
|
|
50
|
+
// select one build and skip the other.
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The RCTLog echo of a call the patch is forwarding. Dropped in dev, where
|
|
56
|
+
* that overlap exists, and in release if the echo is still produced: the
|
|
57
|
+
* patch already has the line. An RCTLog line the patch does not own (RN
|
|
58
|
+
* core, a native module) is not an echo and is kept.
|
|
59
|
+
*/
|
|
60
|
+
export function shouldDropConsoleEcho(dev: boolean, patchOwnsCall: boolean): boolean {
|
|
61
|
+
// The echo is dropped in dev and in release. Only whether the patch owns
|
|
62
|
+
// the call changes the answer.
|
|
63
|
+
return patchOwnsCall;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The equal-text claim dies with the patch. No unstamped echo of that line
|
|
68
|
+
* reaches JS: Android drops it in the bridge, and iOS writes only os_log of
|
|
69
|
+
* the raw message while this package skips `RCTLogSourceJavaScript`.
|
|
70
|
+
*/
|
|
71
|
+
function retireExact(text: string): void {
|
|
72
|
+
const echoAt = exactEchoes.findIndex((claim) => claim.text === text);
|
|
73
|
+
if (echoAt !== -1) {
|
|
74
|
+
exactEchoes.splice(echoAt, 1);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function prune(list: Claim[], now: number): void {
|
|
79
|
+
let index = 0;
|
|
80
|
+
while (index < list.length) {
|
|
81
|
+
const claim = list[index]!;
|
|
82
|
+
if (claim.expires <= now) {
|
|
83
|
+
if (list === protectedLines) {
|
|
84
|
+
retireExact(claim.text);
|
|
85
|
+
}
|
|
86
|
+
list.splice(index, 1);
|
|
87
|
+
} else {
|
|
88
|
+
index += 1;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function remember(list: Claim[], text: string, now: number): void {
|
|
94
|
+
list.push({ text, expires: now + ECHO_WINDOW_MS });
|
|
95
|
+
while (list.length > MAX_CLAIMS) {
|
|
96
|
+
list.shift();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The text `nativeLoggingHook` actually emitted for this console call. */
|
|
101
|
+
export function claimEcho(message: string, now: number = Date.now()): void {
|
|
102
|
+
remember(exactEchoes, message, now);
|
|
103
|
+
remember(stampEchoes, message, now);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The line the JS patch is about to forward. That copy reaches the filter. */
|
|
107
|
+
export function protectLine(line: string, now: number = Date.now()): void {
|
|
108
|
+
remember(protectedLines, line, now);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* A stderr line the iOS SDK stored as
|
|
113
|
+
* `2026-10-02 18:40:35.273 BareExample[60839:42420530] <message>`.
|
|
114
|
+
* The stamp is a different string from the patch. Dropping it does not
|
|
115
|
+
* retire the equal-text claim; delivering the patch does. os_log capture
|
|
116
|
+
* is disabled, and this package does not wait for an unstamped stderr
|
|
117
|
+
* copy. Android's logcat echo is dropped in the bridge before JS is asked.
|
|
118
|
+
*/
|
|
119
|
+
export function isConsoleStampOf(line: string, message: string): boolean {
|
|
120
|
+
const tail = `] ${message}`;
|
|
121
|
+
if (message.length === 0 || !line.endsWith(tail)) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
const head = line.slice(0, line.length - tail.length);
|
|
125
|
+
const splitAt = head.indexOf('[');
|
|
126
|
+
const when = head.slice(0, splitAt);
|
|
127
|
+
const pid = head.slice(splitAt + 1);
|
|
128
|
+
return (
|
|
129
|
+
/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ [^\s[]+$/.test(when) && /^\d+:\d+$/.test(pid)
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* `deliver` runs the user's filter. `drop` answers the native request with
|
|
135
|
+
* null and does not call the user.
|
|
136
|
+
*
|
|
137
|
+
* The equal-text claim dies when the patch is delivered, on Android and
|
|
138
|
+
* on iOS. A later `Bugsee.log`, native line, or second `console.*` of that
|
|
139
|
+
* string is kept. An echo that is actually classified — a stderr stamp, or
|
|
140
|
+
* an equal line that arrives while the claim is still live — is dropped
|
|
141
|
+
* once. os_log capture is disabled. There is no unstamped stderr copy to
|
|
142
|
+
* wait for.
|
|
143
|
+
*/
|
|
144
|
+
export function classifyFilterRequest(
|
|
145
|
+
line: string,
|
|
146
|
+
now: number = Date.now(),
|
|
147
|
+
): 'deliver' | 'drop' {
|
|
148
|
+
prune(protectedLines, now);
|
|
149
|
+
prune(exactEchoes, now);
|
|
150
|
+
prune(stampEchoes, now);
|
|
151
|
+
const stampAt = stampEchoes.findIndex((claim) => isConsoleStampOf(line, claim.text));
|
|
152
|
+
if (stampAt !== -1) {
|
|
153
|
+
stampEchoes.splice(stampAt, 1);
|
|
154
|
+
return 'drop';
|
|
155
|
+
}
|
|
156
|
+
const protectAt = protectedLines.findIndex((claim) => claim.text === line);
|
|
157
|
+
if (protectAt !== -1) {
|
|
158
|
+
protectedLines.splice(protectAt, 1);
|
|
159
|
+
retireExact(line);
|
|
160
|
+
return 'deliver';
|
|
161
|
+
}
|
|
162
|
+
const echoAt = exactEchoes.findIndex((claim) => claim.text === line);
|
|
163
|
+
if (echoAt !== -1) {
|
|
164
|
+
exactEchoes.splice(echoAt, 1);
|
|
165
|
+
return 'drop';
|
|
166
|
+
}
|
|
167
|
+
return 'deliver';
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Tests start from an empty ledger. Production never calls this. */
|
|
171
|
+
export function resetConsoleDedup(): void {
|
|
172
|
+
exactEchoes.length = 0;
|
|
173
|
+
stampEchoes.length = 0;
|
|
174
|
+
protectedLines.length = 0;
|
|
175
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The value domain shared by `Bugsee.event` and `Bugsee.trace`.
|
|
3
|
+
*
|
|
4
|
+
* Both SDKs serialise nested maps, lists, strings, booleans, numbers and null
|
|
5
|
+
* (design doc Phase 4, "Verified facts"), but neither does anything useful
|
|
6
|
+
* with a value outside that set: a `Date` silently becomes whatever its
|
|
7
|
+
* `HashMap`/`NSDictionary` conversion does with an opaque object, a cycle
|
|
8
|
+
* hangs the native JSON writer, and `undefined` has no wire representation at
|
|
9
|
+
* all. So everything here is checked and copied in JS, before crossing,
|
|
10
|
+
* rather than left for native to discover.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** One value inside an event's params, recursively. */
|
|
14
|
+
export type EventParamValue =
|
|
15
|
+
| string
|
|
16
|
+
| number
|
|
17
|
+
| boolean
|
|
18
|
+
| null
|
|
19
|
+
| readonly EventParamValue[]
|
|
20
|
+
| { readonly [key: string]: EventParamValue | undefined };
|
|
21
|
+
|
|
22
|
+
/** An event's params: a plain object of {@link EventParamValue}s. */
|
|
23
|
+
export type EventParams = { readonly [key: string]: EventParamValue | undefined };
|
|
24
|
+
|
|
25
|
+
/** A trace's value: a string, a finite number or a boolean. */
|
|
26
|
+
export type TraceValue = string | number | boolean;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Nesting past this is almost certainly a cycle or an accident, not a
|
|
30
|
+
* deliberate payload. Rejected with the path that hit it.
|
|
31
|
+
*/
|
|
32
|
+
export const EVENT_PARAMS_MAX_DEPTH = 16;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The one numeric bound for every number that reaches a bundle -- event
|
|
36
|
+
* params, trace values, and (Phase 5) attributes: finite and smaller than
|
|
37
|
+
* `2^63` in magnitude. Exclusive of `2^63` itself: Android's JSON writer
|
|
38
|
+
* sends any integral value at or beyond `Long.MAX_VALUE` through
|
|
39
|
+
* `longValue()`, and every double `>= 2^63` silently becomes
|
|
40
|
+
* `9223372036854775807` there rather than round-tripping, so the bound must
|
|
41
|
+
* reject before that point, not at it. Shared with `src/attributes/validate.ts`.
|
|
42
|
+
*/
|
|
43
|
+
export const BUNDLE_NUMBER_LIMIT = 2 ** 63;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* {@link BUNDLE_NUMBER_LIMIT} as the exact decimal integer string, for use in
|
|
47
|
+
* rejection messages. Printing the bound (or a rejected value near it) via
|
|
48
|
+
* `Number`'s own string conversion rounds: `String(BUNDLE_NUMBER_LIMIT)`
|
|
49
|
+
* reads `9223372036854776000`, not the true `9223372036854775808`, and a
|
|
50
|
+
* value like `1e19` prints as `10000000000000000000`. Derived with `BigInt`,
|
|
51
|
+
* which has no such rounding, rather than hard-coded, so it can never drift
|
|
52
|
+
* from {@link BUNDLE_NUMBER_LIMIT}.
|
|
53
|
+
*/
|
|
54
|
+
export const BUNDLE_NUMBER_LIMIT_DECIMAL = (2n ** 63n).toString();
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Whether `value` satisfies the domain every bundle number must:
|
|
58
|
+
* `typeof value === 'number'`, finite, and `|value| < BUNDLE_NUMBER_LIMIT`.
|
|
59
|
+
* Takes `unknown`, like `Number.isFinite`'s own signature in this codebase's
|
|
60
|
+
* lib target, so a caller need not narrow first.
|
|
61
|
+
*/
|
|
62
|
+
export function isWithinBundleNumberLimit(value: unknown): boolean {
|
|
63
|
+
return (
|
|
64
|
+
typeof value === 'number' &&
|
|
65
|
+
Number.isFinite(value) &&
|
|
66
|
+
Math.abs(value) < BUNDLE_NUMBER_LIMIT
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A short, human-legible name for a rejected value's type. */
|
|
71
|
+
function describeType(value: unknown): string {
|
|
72
|
+
if (value === null) return 'null';
|
|
73
|
+
if (value === undefined) return 'undefined';
|
|
74
|
+
if (Array.isArray(value)) return 'array';
|
|
75
|
+
if (typeof value === 'object') {
|
|
76
|
+
if (value instanceof Date) return 'Date';
|
|
77
|
+
if (value instanceof Map) return 'Map';
|
|
78
|
+
if (value instanceof Set) return 'Set';
|
|
79
|
+
if (ArrayBuffer.isView(value)) {
|
|
80
|
+
return (value as object).constructor?.name ?? 'TypedArray';
|
|
81
|
+
}
|
|
82
|
+
return (value as object).constructor?.name ?? 'object';
|
|
83
|
+
}
|
|
84
|
+
return typeof value;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* A plain object: its prototype is `Object.prototype` or `null`. Excludes
|
|
89
|
+
* arrays (their own branch), `Date`, `Map`, `Set`, typed arrays and class
|
|
90
|
+
* instances, none of which either SDK's JSON writer round-trips faithfully.
|
|
91
|
+
*/
|
|
92
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
93
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
const proto: unknown = Object.getPrototypeOf(value);
|
|
97
|
+
return proto === Object.prototype || proto === null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** One rejected value, at `keyPath`, as a `TypeError` naming what it actually was. */
|
|
101
|
+
function rejectValue(keyPath: string, value: unknown): never {
|
|
102
|
+
throw new TypeError(
|
|
103
|
+
`${keyPath} must be a plain object, an array, a string, a finite number, ` +
|
|
104
|
+
`a boolean or null; got ${describeType(value)}`,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function copyValue(
|
|
109
|
+
value: unknown,
|
|
110
|
+
keyPath: string,
|
|
111
|
+
depth: number,
|
|
112
|
+
ancestors: Set<object>,
|
|
113
|
+
): unknown {
|
|
114
|
+
if (value === null) return null;
|
|
115
|
+
const kind = typeof value;
|
|
116
|
+
if (kind === 'string' || kind === 'boolean') return value;
|
|
117
|
+
if (kind === 'number') {
|
|
118
|
+
// Never echo the rejected value: `String`/template-literal conversion of
|
|
119
|
+
// a number this size rounds -- see {@link BUNDLE_NUMBER_LIMIT_DECIMAL}.
|
|
120
|
+
// The path is still named.
|
|
121
|
+
if (!Number.isFinite(value)) {
|
|
122
|
+
throw new RangeError(`${keyPath} must be a finite number`);
|
|
123
|
+
}
|
|
124
|
+
if (!isWithinBundleNumberLimit(value)) {
|
|
125
|
+
throw new RangeError(
|
|
126
|
+
`${keyPath} must be smaller than 2^63 (${BUNDLE_NUMBER_LIMIT_DECIMAL}) in magnitude`,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
131
|
+
if (kind === 'object') {
|
|
132
|
+
if (Array.isArray(value)) {
|
|
133
|
+
return copyArray(value, keyPath, depth, ancestors);
|
|
134
|
+
}
|
|
135
|
+
if (isPlainObject(value)) {
|
|
136
|
+
return copyObject(value, keyPath, depth, ancestors);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return rejectValue(keyPath, value);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function copyObject(
|
|
143
|
+
obj: Record<string, unknown>,
|
|
144
|
+
keyPath: string,
|
|
145
|
+
depth: number,
|
|
146
|
+
ancestors: Set<object>,
|
|
147
|
+
): Record<string, unknown> {
|
|
148
|
+
if (depth > EVENT_PARAMS_MAX_DEPTH) {
|
|
149
|
+
throw new RangeError(
|
|
150
|
+
`${keyPath} nests deeper than the maximum of ${EVENT_PARAMS_MAX_DEPTH}`,
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
if (ancestors.has(obj)) {
|
|
154
|
+
throw new TypeError(`${keyPath} is a cycle: it contains itself`);
|
|
155
|
+
}
|
|
156
|
+
ancestors.add(obj);
|
|
157
|
+
try {
|
|
158
|
+
// No prototype, so every key is kept as an own key -- "__proto__"
|
|
159
|
+
// included. On a plain `{}` that assignment hits Object.prototype's
|
|
160
|
+
// setter instead of creating an own property, and the key silently
|
|
161
|
+
// vanishes from the copy (and from the JSON text it is later encoded
|
|
162
|
+
// into) rather than being rejected or kept.
|
|
163
|
+
const result: Record<string, unknown> = Object.create(null);
|
|
164
|
+
for (const key of Object.keys(obj)) {
|
|
165
|
+
const value = obj[key];
|
|
166
|
+
// Omitted, as JSON.stringify does -- not an error. An array element
|
|
167
|
+
// gets no such pass, since an array has no key to drop.
|
|
168
|
+
if (value === undefined) continue;
|
|
169
|
+
result[key] = copyValue(value, `${keyPath}.${key}`, depth + 1, ancestors);
|
|
170
|
+
}
|
|
171
|
+
return result;
|
|
172
|
+
} finally {
|
|
173
|
+
ancestors.delete(obj);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function copyArray(
|
|
178
|
+
arr: readonly unknown[],
|
|
179
|
+
keyPath: string,
|
|
180
|
+
depth: number,
|
|
181
|
+
ancestors: Set<object>,
|
|
182
|
+
): unknown[] {
|
|
183
|
+
if (depth > EVENT_PARAMS_MAX_DEPTH) {
|
|
184
|
+
throw new RangeError(
|
|
185
|
+
`${keyPath} nests deeper than the maximum of ${EVENT_PARAMS_MAX_DEPTH}`,
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
if (ancestors.has(arr as object)) {
|
|
189
|
+
throw new TypeError(`${keyPath} is a cycle: it contains itself`);
|
|
190
|
+
}
|
|
191
|
+
ancestors.add(arr as object);
|
|
192
|
+
try {
|
|
193
|
+
const result: unknown[] = [];
|
|
194
|
+
for (let i = 0; i < arr.length; i += 1) {
|
|
195
|
+
const value = arr[i];
|
|
196
|
+
if (value === undefined) {
|
|
197
|
+
throw new TypeError(`${keyPath}[${i}] must not be undefined`);
|
|
198
|
+
}
|
|
199
|
+
result.push(copyValue(value, `${keyPath}[${i}]`, depth + 1, ancestors));
|
|
200
|
+
}
|
|
201
|
+
return result;
|
|
202
|
+
} finally {
|
|
203
|
+
ancestors.delete(arr as object);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Validates `params` against the accepted value domain and returns a fresh
|
|
209
|
+
* plain copy, with `undefined` object members omitted.
|
|
210
|
+
*
|
|
211
|
+
* Throws `TypeError` for a value of the wrong type (naming its path, e.g.
|
|
212
|
+
* `params.a.b[1]`) and `RangeError` for a non-finite number or nesting past
|
|
213
|
+
* {@link EVENT_PARAMS_MAX_DEPTH}. The copy means a caller mutating its
|
|
214
|
+
* original object afterwards cannot change what already crossed.
|
|
215
|
+
*/
|
|
216
|
+
export function copyEventParams(params: EventParams): Record<string, unknown> {
|
|
217
|
+
if (!isPlainObject(params)) {
|
|
218
|
+
throw new TypeError(
|
|
219
|
+
`Bugsee.event requires params to be a plain object, got ${describeType(params)}`,
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
return copyObject(params, 'params', 1, new Set());
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** Validates an event or trace name: a non-empty string. */
|
|
226
|
+
export function assertEventOrTraceName(
|
|
227
|
+
kind: 'event' | 'trace',
|
|
228
|
+
name: unknown,
|
|
229
|
+
): asserts name is string {
|
|
230
|
+
if (typeof name !== 'string') {
|
|
231
|
+
throw new TypeError(
|
|
232
|
+
`Bugsee.${kind} requires name to be a string, got ${describeType(name)}`,
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
if (name.length === 0) {
|
|
236
|
+
throw new RangeError(`Bugsee.${kind} requires a non-empty name`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Validates a trace value: a string, a finite number or a boolean. */
|
|
241
|
+
export function assertTraceValue(value: unknown): asserts value is TraceValue {
|
|
242
|
+
const kind = typeof value;
|
|
243
|
+
if (kind === 'string' || kind === 'boolean') return;
|
|
244
|
+
if (kind === 'number') {
|
|
245
|
+
// Never echo the rejected value -- see {@link BUNDLE_NUMBER_LIMIT_DECIMAL}.
|
|
246
|
+
if (!Number.isFinite(value)) {
|
|
247
|
+
throw new RangeError(`Bugsee.trace requires a finite number`);
|
|
248
|
+
}
|
|
249
|
+
if (!isWithinBundleNumberLimit(value)) {
|
|
250
|
+
throw new RangeError(
|
|
251
|
+
`Bugsee.trace requires a number smaller than 2^63 (${BUNDLE_NUMBER_LIMIT_DECIMAL}) in magnitude`,
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
throw new TypeError(
|
|
257
|
+
`Bugsee.trace requires a string, a finite number or a boolean, got ${describeType(value)}`,
|
|
258
|
+
);
|
|
259
|
+
}
|
package/src/errorName.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a package log line may say about something thrown: an `Error`'s class
|
|
3
|
+
* name, or the type of anything else. Never its message or stack -- those are
|
|
4
|
+
* whatever the throwing code put there (an app callback's own text, a value),
|
|
5
|
+
* and the SDK captures console output into the report it uploads.
|
|
6
|
+
*
|
|
7
|
+
* Never throws. It runs inside the catch blocks that keep one failure from
|
|
8
|
+
* reaching the rest (the secure measure loop, the report dispatcher, the
|
|
9
|
+
* view-tree reply), and the thrown value is the app's: a `name` getter can
|
|
10
|
+
* throw, and so can `instanceof` on a Proxy whose `getPrototypeOf` trap
|
|
11
|
+
* throws. The first reads as `'Error'`, the second as the value's type. (The same guard
|
|
12
|
+
* as `exceptions/payload.ts`'s `safeIsError`/`safeGetString`.)
|
|
13
|
+
*/
|
|
14
|
+
export function errorName(error: unknown): string {
|
|
15
|
+
if (!isError(error)) {
|
|
16
|
+
return error === null ? 'null' : typeof error;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const name: unknown = error.name;
|
|
20
|
+
return typeof name === 'string' && name !== '' ? name : 'Error';
|
|
21
|
+
} catch {
|
|
22
|
+
return 'Error';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isError(value: unknown): value is Error {
|
|
27
|
+
try {
|
|
28
|
+
return value instanceof Error;
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|