@bugsee/react-native 0.0.0-stage → 7.0.0-beta1
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 +552 -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 +944 -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
package/src/apm/span.ts
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import NativeBugsee from '../NativeBugsee';
|
|
2
|
+
import { encodeBridgeJson, encodeBridgeObject } from '../bridge/json';
|
|
3
|
+
import {
|
|
4
|
+
BugseeSpanError,
|
|
5
|
+
SpanErrorCode,
|
|
6
|
+
SpanStatus,
|
|
7
|
+
type SpanAttribute,
|
|
8
|
+
type SpanWire,
|
|
9
|
+
} from './types';
|
|
10
|
+
|
|
11
|
+
const live = new Map<string, SpanObject>();
|
|
12
|
+
|
|
13
|
+
function dead(): never {
|
|
14
|
+
throw new BugseeSpanError(
|
|
15
|
+
SpanErrorCode.HandleDead,
|
|
16
|
+
'Bugsee span handle is dead; finish already released it',
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function assertText(value: unknown, method: string, field: string): string {
|
|
21
|
+
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
22
|
+
throw new TypeError(`Bugsee.${method} requires ${field} to be a non-empty string`);
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function assertStatus(status: unknown): SpanStatus {
|
|
28
|
+
if (typeof status !== 'number') {
|
|
29
|
+
throw new TypeError('Bugsee span status must be an integer 0..5');
|
|
30
|
+
}
|
|
31
|
+
if (!Number.isInteger(status) || status < SpanStatus.OK || status > SpanStatus.Unknown) {
|
|
32
|
+
throw new RangeError('Bugsee span status must be an integer 0..5');
|
|
33
|
+
}
|
|
34
|
+
return status as SpanStatus;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function assertAttribute(value: unknown): SpanAttribute {
|
|
38
|
+
if (typeof value === 'string') {
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
if (typeof value === 'boolean') {
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
// Number.isFinite is true only for finite numbers, so the typeof check is redundant.
|
|
45
|
+
if (Number.isFinite(value)) {
|
|
46
|
+
return value as number;
|
|
47
|
+
}
|
|
48
|
+
throw new TypeError('Bugsee span attribute must be a string, a finite number or a boolean');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function assertAttributes(
|
|
52
|
+
attributes: unknown,
|
|
53
|
+
): Record<string, SpanAttribute> | null {
|
|
54
|
+
if (attributes === undefined) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
if (attributes === null || typeof attributes !== 'object' || Array.isArray(attributes)) {
|
|
58
|
+
throw new TypeError('Bugsee.startTransaction attributes must be an object');
|
|
59
|
+
}
|
|
60
|
+
const copy: Record<string, SpanAttribute> = Object.create(null);
|
|
61
|
+
for (const key of Object.keys(attributes as Record<string, unknown>)) {
|
|
62
|
+
copy[key] = assertAttribute((attributes as Record<string, unknown>)[key]);
|
|
63
|
+
}
|
|
64
|
+
return copy;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function asWire(value: unknown): SpanWire {
|
|
68
|
+
const wire = value as SpanWire;
|
|
69
|
+
return {
|
|
70
|
+
handle: typeof wire.handle === 'string' ? wire.handle : '',
|
|
71
|
+
spanId: typeof wire.spanId === 'string' ? wire.spanId : '',
|
|
72
|
+
traceId: typeof wire.traceId === 'string' ? wire.traceId : '',
|
|
73
|
+
operation: typeof wire.operation === 'string' ? wire.operation : '',
|
|
74
|
+
description: typeof wire.description === 'string' ? wire.description : null,
|
|
75
|
+
status: typeof wire.status === 'number' ? wire.status : SpanStatus.OK,
|
|
76
|
+
finished: wire.finished === true,
|
|
77
|
+
attributesJson: wire.attributesJson,
|
|
78
|
+
...(typeof wire.name === 'string' ? { name: wire.name, sampled: wire.sampled === true } : {}),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function adopt(value: unknown): SpanObject | null {
|
|
83
|
+
const wire = asWire(value);
|
|
84
|
+
if (wire.handle === '') {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const existing = live.get(wire.handle);
|
|
88
|
+
if (existing !== undefined) {
|
|
89
|
+
return existing;
|
|
90
|
+
}
|
|
91
|
+
const span = new SpanObject(wire);
|
|
92
|
+
live.set(wire.handle, span);
|
|
93
|
+
return span;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function markReleased(handles: readonly string[]): void {
|
|
97
|
+
for (const handle of handles) {
|
|
98
|
+
const span = live.get(handle);
|
|
99
|
+
if (span !== undefined) {
|
|
100
|
+
span.markDead();
|
|
101
|
+
}
|
|
102
|
+
live.delete(handle);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* A span the bridge is holding. `finish` tells native to drop it. A parent
|
|
108
|
+
* finish also drops children the SDK has finished; native reports every
|
|
109
|
+
* handle it released, and those objects die here without another call.
|
|
110
|
+
*/
|
|
111
|
+
class SpanObject {
|
|
112
|
+
private dead = false;
|
|
113
|
+
private operation: string;
|
|
114
|
+
private description: string | null;
|
|
115
|
+
private status: number;
|
|
116
|
+
private finishedFlag: boolean;
|
|
117
|
+
private attributes: Record<string, SpanAttribute>;
|
|
118
|
+
readonly spanId: string;
|
|
119
|
+
readonly traceId: string;
|
|
120
|
+
/** Set only when the wire is a transaction. */
|
|
121
|
+
readonly transactionName: string | undefined;
|
|
122
|
+
readonly transactionSampled: boolean;
|
|
123
|
+
|
|
124
|
+
constructor(private readonly wire: SpanWire) {
|
|
125
|
+
this.spanId = wire.spanId;
|
|
126
|
+
this.traceId = wire.traceId;
|
|
127
|
+
this.operation = wire.operation;
|
|
128
|
+
this.description = wire.description;
|
|
129
|
+
this.status = wire.status;
|
|
130
|
+
this.finishedFlag = wire.finished;
|
|
131
|
+
this.attributes = parseAttributes(wire.attributesJson);
|
|
132
|
+
// `asWire` already kept `name` only when it is a string.
|
|
133
|
+
this.transactionName = wire.name;
|
|
134
|
+
this.transactionSampled = wire.sampled === true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Native `setName`, which sets the operation on both SDKs. */
|
|
138
|
+
setName(name: string): this {
|
|
139
|
+
this.guard();
|
|
140
|
+
const text = assertText(name, 'setName', 'name');
|
|
141
|
+
NativeBugsee.spanSetName(this.wire.handle, text);
|
|
142
|
+
this.operation = text;
|
|
143
|
+
return this;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
setDescription(description: string | null): this {
|
|
147
|
+
this.guard();
|
|
148
|
+
if (description !== null && typeof description !== 'string') {
|
|
149
|
+
throw new TypeError('Bugsee.setDescription requires a string or null');
|
|
150
|
+
}
|
|
151
|
+
NativeBugsee.spanSetDescription(this.wire.handle, description);
|
|
152
|
+
this.description = description;
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
setAttribute(key: string, value: SpanAttribute): this {
|
|
157
|
+
this.guard();
|
|
158
|
+
const name = assertText(key, 'setAttribute', 'key');
|
|
159
|
+
const attribute = assertAttribute(value);
|
|
160
|
+
const wire = encodeBridgeJson(attribute);
|
|
161
|
+
if (NativeBugsee.spanSetAttribute(this.wire.handle, name, wire)) {
|
|
162
|
+
const stored = JSON.parse(wire) as SpanAttribute;
|
|
163
|
+
this.attributes = { ...this.attributes, [name]: stored };
|
|
164
|
+
}
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
setStatus(status: SpanStatus): this {
|
|
169
|
+
this.guard();
|
|
170
|
+
const wire = assertStatus(status);
|
|
171
|
+
NativeBugsee.spanSetStatus(this.wire.handle, wire);
|
|
172
|
+
this.status = wire;
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
startChildSpan(operation: string, description?: string | null): SpanObject {
|
|
177
|
+
this.guard();
|
|
178
|
+
const op = assertText(operation, 'startChildSpan', 'operation');
|
|
179
|
+
const body = optionalDescription(description);
|
|
180
|
+
const child = adopt(NativeBugsee.spanStartChild(this.wire.handle, op, body));
|
|
181
|
+
if (child === null) {
|
|
182
|
+
dead();
|
|
183
|
+
}
|
|
184
|
+
return child;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Finishes the span. No argument is the SDK's no-arg `finish` (status OK).
|
|
189
|
+
* The native handle is released, including any child this finish ended.
|
|
190
|
+
*/
|
|
191
|
+
finish(status?: SpanStatus): void {
|
|
192
|
+
this.guard();
|
|
193
|
+
const explicit = status !== undefined;
|
|
194
|
+
const wire = explicit ? assertStatus(status) : 0;
|
|
195
|
+
const released = NativeBugsee.spanFinish(this.wire.handle, wire, explicit);
|
|
196
|
+
markReleased(released);
|
|
197
|
+
// Dead even when native omits this handle. A later call is what throws.
|
|
198
|
+
this.markDead();
|
|
199
|
+
live.delete(this.wire.handle);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
get operationName(): string {
|
|
203
|
+
return this.operation;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
get descriptionText(): string | null {
|
|
207
|
+
return this.description;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
get statusValue(): number {
|
|
211
|
+
return this.status;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
get isFinished(): boolean {
|
|
215
|
+
return this.finishedFlag;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
get attributeMap(): Readonly<Record<string, SpanAttribute>> {
|
|
219
|
+
return this.attributes;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
markDead(): void {
|
|
223
|
+
this.dead = true;
|
|
224
|
+
this.finishedFlag = true;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private guard(): void {
|
|
228
|
+
if (this.dead) {
|
|
229
|
+
dead();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function parseAttributes(json: string): Record<string, SpanAttribute> {
|
|
235
|
+
try {
|
|
236
|
+
const parsed: unknown = JSON.parse(json);
|
|
237
|
+
// `null` is typeof "object"; Object.entries throws and the catch
|
|
238
|
+
// reports the same empty map a non-object would.
|
|
239
|
+
if (typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
240
|
+
return Object.create(null);
|
|
241
|
+
}
|
|
242
|
+
const result: Record<string, SpanAttribute> = Object.create(null);
|
|
243
|
+
for (const [key, value] of Object.entries(parsed as Record<string, unknown>)) {
|
|
244
|
+
if (typeof value === 'string' || typeof value === 'boolean') {
|
|
245
|
+
result[key] = value;
|
|
246
|
+
} else if (typeof value === 'number') {
|
|
247
|
+
// JSON.parse only yields finite numbers, so no separate finite check.
|
|
248
|
+
result[key] = value;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return result;
|
|
252
|
+
} catch {
|
|
253
|
+
return Object.create(null);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function optionalDescription(description: string | null | undefined): string | null {
|
|
258
|
+
if (description === undefined || description === null) {
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
if (typeof description !== 'string') {
|
|
262
|
+
throw new TypeError('Bugsee span description must be a string or null');
|
|
263
|
+
}
|
|
264
|
+
return description;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export interface BugseeSpan {
|
|
268
|
+
readonly spanId: string;
|
|
269
|
+
readonly traceId: string;
|
|
270
|
+
readonly operation: string;
|
|
271
|
+
readonly description: string | null;
|
|
272
|
+
readonly status: SpanStatus;
|
|
273
|
+
readonly finished: boolean;
|
|
274
|
+
readonly attributes: Readonly<Record<string, SpanAttribute>>;
|
|
275
|
+
setName(name: string): this;
|
|
276
|
+
setDescription(description: string | null): this;
|
|
277
|
+
setAttribute(key: string, value: SpanAttribute): this;
|
|
278
|
+
setStatus(status: SpanStatus): this;
|
|
279
|
+
startChildSpan(operation: string, description?: string | null): BugseeSpan;
|
|
280
|
+
finish(status?: SpanStatus): void;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export interface BugseeTransaction extends BugseeSpan {
|
|
284
|
+
readonly name: string;
|
|
285
|
+
readonly sampled: boolean;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
class PublicSpan implements BugseeSpan {
|
|
289
|
+
constructor(private readonly inner: SpanObject) {}
|
|
290
|
+
|
|
291
|
+
get spanId(): string {
|
|
292
|
+
return this.inner.spanId;
|
|
293
|
+
}
|
|
294
|
+
get traceId(): string {
|
|
295
|
+
return this.inner.traceId;
|
|
296
|
+
}
|
|
297
|
+
get operation(): string {
|
|
298
|
+
return this.inner.operationName;
|
|
299
|
+
}
|
|
300
|
+
get description(): string | null {
|
|
301
|
+
return this.inner.descriptionText;
|
|
302
|
+
}
|
|
303
|
+
get status(): SpanStatus {
|
|
304
|
+
return this.inner.statusValue as SpanStatus;
|
|
305
|
+
}
|
|
306
|
+
get finished(): boolean {
|
|
307
|
+
return this.inner.isFinished;
|
|
308
|
+
}
|
|
309
|
+
get attributes(): Readonly<Record<string, SpanAttribute>> {
|
|
310
|
+
return this.inner.attributeMap;
|
|
311
|
+
}
|
|
312
|
+
setName(name: string): this {
|
|
313
|
+
this.inner.setName(name);
|
|
314
|
+
return this;
|
|
315
|
+
}
|
|
316
|
+
setDescription(description: string | null): this {
|
|
317
|
+
this.inner.setDescription(description);
|
|
318
|
+
return this;
|
|
319
|
+
}
|
|
320
|
+
setAttribute(key: string, value: SpanAttribute): this {
|
|
321
|
+
this.inner.setAttribute(key, value);
|
|
322
|
+
return this;
|
|
323
|
+
}
|
|
324
|
+
setStatus(status: SpanStatus): this {
|
|
325
|
+
this.inner.setStatus(status);
|
|
326
|
+
return this;
|
|
327
|
+
}
|
|
328
|
+
startChildSpan(operation: string, description?: string | null): BugseeSpan {
|
|
329
|
+
return wrap(this.inner.startChildSpan(operation, description));
|
|
330
|
+
}
|
|
331
|
+
finish(status?: SpanStatus): void {
|
|
332
|
+
this.inner.finish(status);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
class PublicTransaction extends PublicSpan implements BugseeTransaction {
|
|
337
|
+
readonly name: string;
|
|
338
|
+
readonly sampled: boolean;
|
|
339
|
+
|
|
340
|
+
constructor(inner: SpanObject, name: string, sampled: boolean) {
|
|
341
|
+
super(inner);
|
|
342
|
+
this.name = name;
|
|
343
|
+
this.sampled = sampled;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const wrapped = new WeakMap<SpanObject, BugseeSpan>();
|
|
348
|
+
|
|
349
|
+
function wrap(inner: SpanObject): BugseeSpan {
|
|
350
|
+
const existing = wrapped.get(inner);
|
|
351
|
+
if (existing !== undefined) {
|
|
352
|
+
return existing;
|
|
353
|
+
}
|
|
354
|
+
const name = innerWireName(inner);
|
|
355
|
+
const span =
|
|
356
|
+
name === undefined
|
|
357
|
+
? new PublicSpan(inner)
|
|
358
|
+
: new PublicTransaction(inner, name.name, name.sampled);
|
|
359
|
+
wrapped.set(inner, span);
|
|
360
|
+
return span;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function innerWireName(inner: SpanObject): { name: string; sampled: boolean } | undefined {
|
|
364
|
+
if (inner.transactionName === undefined) {
|
|
365
|
+
return undefined;
|
|
366
|
+
}
|
|
367
|
+
return { name: inner.transactionName, sampled: inner.transactionSampled };
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export function startTransaction(
|
|
371
|
+
name: string,
|
|
372
|
+
operation: string,
|
|
373
|
+
attributes?: Readonly<Record<string, SpanAttribute>>,
|
|
374
|
+
): BugseeTransaction {
|
|
375
|
+
const txnName = assertText(name, 'startTransaction', 'name');
|
|
376
|
+
const op = assertText(operation, 'startTransaction', 'operation');
|
|
377
|
+
const attrs = assertAttributes(attributes);
|
|
378
|
+
const span = adopt(
|
|
379
|
+
NativeBugsee.startTransaction(
|
|
380
|
+
txnName,
|
|
381
|
+
op,
|
|
382
|
+
attrs === null ? null : encodeBridgeObject(attrs),
|
|
383
|
+
),
|
|
384
|
+
);
|
|
385
|
+
if (span === null || !('name' in wrap(span))) {
|
|
386
|
+
throw new Error('Bugsee.startTransaction did not return a transaction');
|
|
387
|
+
}
|
|
388
|
+
return wrap(span) as BugseeTransaction;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export function startSpan(operation: string, description?: string | null): BugseeSpan {
|
|
392
|
+
const op = assertText(operation, 'startSpan', 'operation');
|
|
393
|
+
const span = adopt(NativeBugsee.startSpan(op, optionalDescription(description)));
|
|
394
|
+
if (span === null) {
|
|
395
|
+
throw new Error('Bugsee.startSpan did not return a span');
|
|
396
|
+
}
|
|
397
|
+
return wrap(span);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export function getActiveSpan(): BugseeSpan | null {
|
|
401
|
+
const span = adopt(NativeBugsee.getActiveSpan());
|
|
402
|
+
return span === null ? null : wrap(span);
|
|
403
|
+
}
|
package/src/apm/types.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal status of a span, the integer both SDKs use.
|
|
3
|
+
*
|
|
4
|
+
* Android `SpanStatus` is a plain enum whose ordinal is this value
|
|
5
|
+
* (`OK` is 0). iOS `BGSSpanStatus` declares the same integers. The bundle
|
|
6
|
+
* writes the name (`OK`, `ERROR`, `DEADLINE_EXCEEDED`); this is the value
|
|
7
|
+
* `setStatus` and `finish(status)` cross.
|
|
8
|
+
*/
|
|
9
|
+
export const SpanStatus = {
|
|
10
|
+
OK: 0,
|
|
11
|
+
Error: 1,
|
|
12
|
+
Timeout: 2,
|
|
13
|
+
Cancelled: 3,
|
|
14
|
+
DeadlineExceeded: 4,
|
|
15
|
+
Unknown: 5,
|
|
16
|
+
} as const;
|
|
17
|
+
export type SpanStatus = (typeof SpanStatus)[keyof typeof SpanStatus];
|
|
18
|
+
|
|
19
|
+
export const SpanErrorCode = {
|
|
20
|
+
/**
|
|
21
|
+
* `finish` already released this span, or a parent finish released it.
|
|
22
|
+
* Raised locally, without crossing, for every operation after that.
|
|
23
|
+
*/
|
|
24
|
+
HandleDead: 'E_SPAN_HANDLE_DEAD',
|
|
25
|
+
} as const;
|
|
26
|
+
export type SpanErrorCode = (typeof SpanErrorCode)[keyof typeof SpanErrorCode];
|
|
27
|
+
|
|
28
|
+
export class BugseeSpanError extends Error {
|
|
29
|
+
readonly code: SpanErrorCode;
|
|
30
|
+
|
|
31
|
+
constructor(code: SpanErrorCode, message: string) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = 'BugseeSpanError';
|
|
34
|
+
this.code = code;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A span attribute. Both SDKs take a string, number or boolean. */
|
|
39
|
+
export type SpanAttribute = string | number | boolean;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* What `startTransaction` / `startSpan` / `getActiveSpan` / `spanStartChild`
|
|
43
|
+
* return. `handle` `''` means there is no span. `name` is present only for
|
|
44
|
+
* a transaction.
|
|
45
|
+
*/
|
|
46
|
+
export interface SpanWire {
|
|
47
|
+
handle: string;
|
|
48
|
+
spanId: string;
|
|
49
|
+
traceId: string;
|
|
50
|
+
operation: string;
|
|
51
|
+
description: string | null;
|
|
52
|
+
status: number;
|
|
53
|
+
finished: boolean;
|
|
54
|
+
attributesJson: string;
|
|
55
|
+
name?: string;
|
|
56
|
+
sampled?: boolean;
|
|
57
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
import NativeBugsee from '../NativeBugsee';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* One camelCase name, two native keys.
|
|
7
|
+
*
|
|
8
|
+
* Android values are the `ReportAppearance` constants in bugsee-android 7.3.0
|
|
9
|
+
* (`setColor(ReportAppearance.X, int)`). iOS values are writable report color
|
|
10
|
+
* properties on `BugseeTheme` in the vendored 7.0.0-beta4 header. A name that
|
|
11
|
+
* exists on only one platform has only that side. Setting it on the other
|
|
12
|
+
* throws, so a color that will not be applied is not stored as if it had been.
|
|
13
|
+
* Reading it returns `undefined` and does not call native.
|
|
14
|
+
*
|
|
15
|
+
* String placeholders (`Report::SummaryPlaceholder`, `reportSummaryPlaceholder`)
|
|
16
|
+
* are not colors. Android sets them with `setString`, not `setColor`, so they
|
|
17
|
+
* are not on this surface.
|
|
18
|
+
*
|
|
19
|
+
* Feedback colors are not here. They live in `@bugsee/react-native-feedback`.
|
|
20
|
+
*/
|
|
21
|
+
export const REPORT_APPEARANCE = {
|
|
22
|
+
actionBarButtonBackgroundClickedColor: {
|
|
23
|
+
android: 'Report::ActionBarButtonBackgroundClickedColor',
|
|
24
|
+
},
|
|
25
|
+
actionBarColor: { android: 'Report::ActionBarColor' },
|
|
26
|
+
actionBarTextColor: { android: 'Report::ActionBarTextColor' },
|
|
27
|
+
backgroundColor: {
|
|
28
|
+
android: 'Report::BackgroundColor',
|
|
29
|
+
ios: 'reportBackgroundColor',
|
|
30
|
+
},
|
|
31
|
+
cellBackgroundColor: { ios: 'reportCellBackgroundColor' },
|
|
32
|
+
closeButtonColor: { ios: 'reportCloseButtonColor' },
|
|
33
|
+
editTextBackgroundColor: { android: 'Report::EditTextBackgroundColor' },
|
|
34
|
+
hintColor: { android: 'Report::HintColor' },
|
|
35
|
+
navigationBarColor: { ios: 'reportNavigationBarColor' },
|
|
36
|
+
placeholderColor: { ios: 'reportPlaceholderColor' },
|
|
37
|
+
sendButtonColor: { ios: 'reportSendButtonColor' },
|
|
38
|
+
severityLabelActiveColor: { android: 'Report::SeverityLabelActiveColor' },
|
|
39
|
+
textColor: { android: 'Report::TextColor', ios: 'reportTextColor' },
|
|
40
|
+
versionColor: { android: 'Report::VersionColor', ios: 'reportVersionColor' },
|
|
41
|
+
} as const;
|
|
42
|
+
|
|
43
|
+
export type ReportAppearanceName = keyof typeof REPORT_APPEARANCE;
|
|
44
|
+
|
|
45
|
+
export type ReportAppearance = {
|
|
46
|
+
[K in ReportAppearanceName]: string | undefined;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const HEX = /^#?([0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
|
|
50
|
+
|
|
51
|
+
interface Rgba {
|
|
52
|
+
r: number;
|
|
53
|
+
g: number;
|
|
54
|
+
b: number;
|
|
55
|
+
a: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** CSS hex: `#RGB`, `#RGBA`, `#RRGGBB`, `#RRGGBBAA` (alpha last). `#RRGGBB` is opaque. */
|
|
59
|
+
function parseReportColor(input: string): Rgba | undefined {
|
|
60
|
+
if (typeof input !== 'string') {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
const match = HEX.exec(input.trim());
|
|
64
|
+
if (match === null) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
const body = match[1];
|
|
68
|
+
if (body === undefined) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
const hex =
|
|
72
|
+
body.length <= 4
|
|
73
|
+
? body
|
|
74
|
+
.split('')
|
|
75
|
+
.map((ch) => ch + ch)
|
|
76
|
+
.join('')
|
|
77
|
+
: body;
|
|
78
|
+
const r = Number.parseInt(hex.slice(0, 2), 16);
|
|
79
|
+
const g = Number.parseInt(hex.slice(2, 4), 16);
|
|
80
|
+
const b = Number.parseInt(hex.slice(4, 6), 16);
|
|
81
|
+
const a = hex.length === 8 ? Number.parseInt(hex.slice(6, 8), 16) : 255;
|
|
82
|
+
if ([r, g, b, a].some((n) => Number.isNaN(n))) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
return { r, g, b, a };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function unknownKey(name: string): RangeError {
|
|
89
|
+
return new RangeError(`Bugsee appearance ${name} is not a report color`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function bindingKey(
|
|
93
|
+
name: ReportAppearanceName,
|
|
94
|
+
platform: string,
|
|
95
|
+
): string | undefined {
|
|
96
|
+
const binding: { readonly android?: string; readonly ios?: string } =
|
|
97
|
+
REPORT_APPEARANCE[name];
|
|
98
|
+
return platform === 'android' ? binding.android : binding.ios;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function read(name: ReportAppearanceName): string | undefined {
|
|
102
|
+
const key = bindingKey(name, Platform.OS);
|
|
103
|
+
if (key === undefined) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
const hex = NativeBugsee.getAppearanceColor(key);
|
|
107
|
+
if (typeof hex !== 'string' || hex.length === 0) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
return hex;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function write(name: ReportAppearanceName, color: string): void {
|
|
114
|
+
if (typeof color !== 'string') {
|
|
115
|
+
throw new TypeError(
|
|
116
|
+
`Bugsee appearance ${name} requires a hex color string, got ${typeof color}`,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
const parsed = parseReportColor(color);
|
|
120
|
+
if (parsed === undefined) {
|
|
121
|
+
// The key only: the rejected text is the app's.
|
|
122
|
+
throw new RangeError(`Bugsee appearance ${name} requires a hex color`);
|
|
123
|
+
}
|
|
124
|
+
const key = bindingKey(name, Platform.OS);
|
|
125
|
+
if (key === undefined) {
|
|
126
|
+
throw new RangeError(
|
|
127
|
+
`Bugsee appearance ${name} is not available on ${Platform.OS}`,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
const applied = NativeBugsee.setAppearanceColor(
|
|
131
|
+
key,
|
|
132
|
+
parsed.r,
|
|
133
|
+
parsed.g,
|
|
134
|
+
parsed.b,
|
|
135
|
+
parsed.a,
|
|
136
|
+
);
|
|
137
|
+
if (applied !== true) {
|
|
138
|
+
throw new Error(`Bugsee appearance ${name} was not applied`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function createAppearance(): ReportAppearance {
|
|
143
|
+
const target = {} as ReportAppearance;
|
|
144
|
+
const names = Object.keys(REPORT_APPEARANCE) as ReportAppearanceName[];
|
|
145
|
+
for (const name of names) {
|
|
146
|
+
Object.defineProperty(target, name, {
|
|
147
|
+
enumerable: true,
|
|
148
|
+
configurable: false,
|
|
149
|
+
get: () => read(name),
|
|
150
|
+
set: (color: string) => {
|
|
151
|
+
write(name, color);
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
// Known colors are own properties, so `Object.keys` and `in` see them and
|
|
156
|
+
// `constructor` / `toString` / `then` stay on the prototype. The trap only
|
|
157
|
+
// refuses a name that is not a report color.
|
|
158
|
+
return new Proxy(target, {
|
|
159
|
+
set(obj, prop, value: string) {
|
|
160
|
+
if (
|
|
161
|
+
typeof prop !== 'string' ||
|
|
162
|
+
!Object.prototype.hasOwnProperty.call(REPORT_APPEARANCE, prop)
|
|
163
|
+
) {
|
|
164
|
+
throw unknownKey(String(prop));
|
|
165
|
+
}
|
|
166
|
+
return Reflect.set(obj, prop, value);
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export const appearance: ReportAppearance = createAppearance();
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The New Architecture check that runs before the TurboModule is looked up.
|
|
3
|
+
*
|
|
4
|
+
* React Native 0.81 still lets an app turn the New Architecture off, and this
|
|
5
|
+
* package does not support that (design 4.5). On the legacy architecture
|
|
6
|
+
* `TurboModuleRegistry.getEnforcing` does not fail: it falls back to the
|
|
7
|
+
* bridge's `NativeModules`, finds the module there, and hands back an object
|
|
8
|
+
* without the codegen event emitters. The import then succeeds, `Bugsee.wrap`
|
|
9
|
+
* throws a `TypeError` about `onDataRequest`, `launch()` resolves, and every
|
|
10
|
+
* lifecycle event fails natively -- half working, which is worse than not
|
|
11
|
+
* working. So the import refuses instead, with an error that names the cause
|
|
12
|
+
* and the fix.
|
|
13
|
+
*
|
|
14
|
+
* How the New Architecture shows itself to JS (React Native's
|
|
15
|
+
* `TurboModuleBinding::install`): bridgeless (the New Architecture default
|
|
16
|
+
* since 0.74) defines `RN$Bridgeless`; the New Architecture on a bridge
|
|
17
|
+
* installs `__turboModuleProxy`. The legacy architecture installs neither.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** The globals the check reads; `globalThis` in the app, a plain object in tests. */
|
|
21
|
+
export interface ArchitectureGlobals {
|
|
22
|
+
readonly RN$Bridgeless?: unknown;
|
|
23
|
+
readonly __turboModuleProxy?: unknown;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** True when the JS runtime is on the New Architecture (bridgeless or not). */
|
|
27
|
+
export function isNewArchitecture(globals: ArchitectureGlobals): boolean {
|
|
28
|
+
return globals.RN$Bridgeless === true || typeof globals.__turboModuleProxy === 'function';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The error the import throws on the legacy architecture: the package, the
|
|
33
|
+
* module, the cause and the fix. A literal (the privacy scanner admits only
|
|
34
|
+
* literals and identifiers into an error).
|
|
35
|
+
*/
|
|
36
|
+
export const LEGACY_ARCHITECTURE_MESSAGE =
|
|
37
|
+
"@bugsee/react-native: the native module 'Bugsee' needs React Native's New Architecture, " +
|
|
38
|
+
'and this app runs the legacy architecture. React Native 0.81 is the last release that ' +
|
|
39
|
+
'allows turning it off; this package does not support that. Turn the New Architecture on ' +
|
|
40
|
+
'(newArchEnabled=true in android/gradle.properties; RCT_NEW_ARCH_ENABLED=1 when running ' +
|
|
41
|
+
"pod install; \"newArchEnabled\": true in an Expo app's config) and rebuild the app.";
|
|
42
|
+
|
|
43
|
+
/** Throws {@link LEGACY_ARCHITECTURE_MESSAGE} unless the runtime is on the New Architecture. */
|
|
44
|
+
export function requireNewArchitecture(globals: ArchitectureGlobals = globalThis as ArchitectureGlobals): void {
|
|
45
|
+
if (!isNewArchitecture(globals)) {
|
|
46
|
+
throw new Error(LEGACY_ARCHITECTURE_MESSAGE);
|
|
47
|
+
}
|
|
48
|
+
}
|