@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
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import NativeBugsee from '../NativeBugsee';
|
|
2
|
+
import { encodeBridgeObject } from '../bridge/json';
|
|
3
|
+
import { normalizeSnapshot, toReportError } from './BugseeReport';
|
|
4
|
+
import { BugseeReportError, ReportErrorCode } from './errors';
|
|
5
|
+
import type { BugseeCreatedReport, BugseeReportSnapshot, ReportPatch } from './types';
|
|
6
|
+
import {
|
|
7
|
+
normalizeFilePath,
|
|
8
|
+
validateBase64,
|
|
9
|
+
validateNonEmptyString,
|
|
10
|
+
validateReportPatch,
|
|
11
|
+
} from './validate';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The live `BugseeCreatedReport` `createReport()` hands back.
|
|
15
|
+
*
|
|
16
|
+
* One instance per handle. `upload()` marks it dead synchronously, before the
|
|
17
|
+
* call crosses, so a second `upload()` rejects locally and the bridge sees
|
|
18
|
+
* the first call only.
|
|
19
|
+
*/
|
|
20
|
+
export class CreatedReport implements BugseeCreatedReport {
|
|
21
|
+
private readonly handleId: string;
|
|
22
|
+
private dead = false;
|
|
23
|
+
|
|
24
|
+
constructor(handleId: string) {
|
|
25
|
+
this.handleId = handleId;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private ensureAlive(): void {
|
|
29
|
+
if (this.dead) {
|
|
30
|
+
throw new BugseeReportError(
|
|
31
|
+
ReportErrorCode.HandleDead,
|
|
32
|
+
'This created report handle is no longer valid: upload() has already been called.',
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private async callNative<T>(fn: () => Promise<T>): Promise<T> {
|
|
38
|
+
try {
|
|
39
|
+
return await fn();
|
|
40
|
+
} catch (error) {
|
|
41
|
+
throw toReportError(error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async read(): Promise<BugseeReportSnapshot> {
|
|
46
|
+
this.ensureAlive();
|
|
47
|
+
const raw = await this.callNative(() =>
|
|
48
|
+
NativeBugsee.createdReportRead(this.handleId),
|
|
49
|
+
);
|
|
50
|
+
return normalizeSnapshot(raw);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async update(patch: ReportPatch): Promise<void> {
|
|
54
|
+
this.ensureAlive();
|
|
55
|
+
// Validated in full before anything crosses the bridge: a patch with one
|
|
56
|
+
// bad field must send nothing, not everything except that field. Then
|
|
57
|
+
// sent as JSON text, the only form in which a clearing `null` survives
|
|
58
|
+
// iOS's TurboModule argument conversion.
|
|
59
|
+
const wire = encodeBridgeObject(validateReportPatch(patch));
|
|
60
|
+
await this.callNative(() =>
|
|
61
|
+
NativeBugsee.createdReportUpdate(this.handleId, wire),
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async addFileAttachment(
|
|
66
|
+
path: string,
|
|
67
|
+
options: { name: string; mimeType?: string },
|
|
68
|
+
): Promise<void> {
|
|
69
|
+
this.ensureAlive();
|
|
70
|
+
const normalizedPath = normalizeFilePath(
|
|
71
|
+
validateNonEmptyString(path, 'path'),
|
|
72
|
+
);
|
|
73
|
+
validateNonEmptyString(normalizedPath, 'path');
|
|
74
|
+
const name = validateNonEmptyString(options?.name, 'name');
|
|
75
|
+
await this.callNative(() =>
|
|
76
|
+
NativeBugsee.createdReportAddFileAttachment(
|
|
77
|
+
this.handleId,
|
|
78
|
+
normalizedPath,
|
|
79
|
+
name,
|
|
80
|
+
options?.mimeType ?? null,
|
|
81
|
+
),
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async addDataAttachment(
|
|
86
|
+
base64: string,
|
|
87
|
+
options: { name: string; mimeType?: string },
|
|
88
|
+
): Promise<void> {
|
|
89
|
+
this.ensureAlive();
|
|
90
|
+
const validBase64 = validateBase64(base64);
|
|
91
|
+
const name = validateNonEmptyString(options?.name, 'name');
|
|
92
|
+
await this.callNative(() =>
|
|
93
|
+
NativeBugsee.createdReportAddDataAttachment(
|
|
94
|
+
this.handleId,
|
|
95
|
+
validBase64,
|
|
96
|
+
name,
|
|
97
|
+
options?.mimeType ?? null,
|
|
98
|
+
),
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async upload(): Promise<boolean> {
|
|
103
|
+
this.ensureAlive();
|
|
104
|
+
// Before the call, not after it resolves: two overlapping upload() calls
|
|
105
|
+
// must cross once. The handle stays dead whatever the native result is.
|
|
106
|
+
this.dead = true;
|
|
107
|
+
return this.callNative(() => NativeBugsee.createdReportUpload(this.handleId));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Asks native for a created report and wraps the handle it mints.
|
|
113
|
+
* `null` is "the SDK made none". A native `E_REPORT_CREATE_BUSY` (and any
|
|
114
|
+
* other known report code) comes back as a `BugseeReportError`.
|
|
115
|
+
*/
|
|
116
|
+
export async function createReport(): Promise<BugseeCreatedReport | null> {
|
|
117
|
+
let handleId: string | null;
|
|
118
|
+
try {
|
|
119
|
+
handleId = await NativeBugsee.createReport();
|
|
120
|
+
} catch (error) {
|
|
121
|
+
throw toReportError(error);
|
|
122
|
+
}
|
|
123
|
+
if (handleId == null) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
return new CreatedReport(handleId);
|
|
127
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import NativeBugsee from '../NativeBugsee';
|
|
2
|
+
import { BugseeReportProxy } from './BugseeReport';
|
|
3
|
+
import type { BugseeReportHandler } from './types';
|
|
4
|
+
import { errorName } from '../errorName';
|
|
5
|
+
|
|
6
|
+
interface ReportHandlerRequestEvent {
|
|
7
|
+
handleId: string;
|
|
8
|
+
phase: string;
|
|
9
|
+
reportId: string;
|
|
10
|
+
type: string;
|
|
11
|
+
deadlineMs: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let currentHandler: BugseeReportHandler | null = null;
|
|
15
|
+
let subscribed = false;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Installs the report handler. See `BugseeReportHandler` for the phase
|
|
19
|
+
* contract; this only wires it up.
|
|
20
|
+
*
|
|
21
|
+
* Subscribes to the native event on the first non-null call and stays
|
|
22
|
+
* subscribed for the rest of the process -- `null` tells native to stop
|
|
23
|
+
* delivering (`setReportHandlerPhases(false, false)`) rather than tearing the
|
|
24
|
+
* subscription down, since a later `setReportHandler` call must still be able
|
|
25
|
+
* to resume delivery.
|
|
26
|
+
*/
|
|
27
|
+
export function setReportHandler(handler: BugseeReportHandler | null): void {
|
|
28
|
+
currentHandler = handler;
|
|
29
|
+
NativeBugsee.setReportHandlerPhases(
|
|
30
|
+
!!handler?.onBeforeReportCreated,
|
|
31
|
+
!!handler?.onAfterReportCreated,
|
|
32
|
+
);
|
|
33
|
+
if (handler && !subscribed) {
|
|
34
|
+
subscribed = true;
|
|
35
|
+
NativeBugsee.onReportHandlerRequest(onReportHandlerRequest);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Handles one `onReportHandlerRequest` delivery.
|
|
41
|
+
*
|
|
42
|
+
* The callback is read from `currentHandler` here, at dispatch, and never
|
|
43
|
+
* again -- a `setReportHandler` call made while this delivery is in flight
|
|
44
|
+
* replaces what the NEXT event sees, not this one. `completeReportHandler` is
|
|
45
|
+
* called exactly once, from `finally`, whether the callback resolved,
|
|
46
|
+
* rejected, threw synchronously, or never settled before its deadline.
|
|
47
|
+
*/
|
|
48
|
+
function onReportHandlerRequest(event: ReportHandlerRequestEvent): void {
|
|
49
|
+
const handler = currentHandler;
|
|
50
|
+
const callback =
|
|
51
|
+
event.phase === 'before'
|
|
52
|
+
? handler?.onBeforeReportCreated
|
|
53
|
+
: event.phase === 'after'
|
|
54
|
+
? handler?.onAfterReportCreated
|
|
55
|
+
: undefined;
|
|
56
|
+
|
|
57
|
+
if (!callback) {
|
|
58
|
+
NativeBugsee.completeReportHandler(event.handleId);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const proxy = new BugseeReportProxy(event.handleId, event.reportId, event.type);
|
|
63
|
+
|
|
64
|
+
// Local only: this never tells native anything. It marks the proxy dead so
|
|
65
|
+
// an op made after the deadline rejects without crossing the bridge, while
|
|
66
|
+
// JS still waits for the callback to settle before it calls
|
|
67
|
+
// `completeReportHandler` -- native treats a second completion as a no-op,
|
|
68
|
+
// so there is nothing to reconcile if the callback finishes after this.
|
|
69
|
+
const deadlineTimer = setTimeout(() => proxy.markDead(), event.deadlineMs);
|
|
70
|
+
|
|
71
|
+
Promise.resolve()
|
|
72
|
+
// `.call(handler, proxy)`, not `callback(proxy)`: `callback` was read off
|
|
73
|
+
// `handler` as a bare function reference, so an unbound call would give a
|
|
74
|
+
// class-based handler's method `this === undefined`. `handler` here is
|
|
75
|
+
// the one captured above, at dispatch -- not `currentHandler` re-read --
|
|
76
|
+
// so a `setReportHandler` mid-flight still cannot change the receiver a
|
|
77
|
+
// delivery already in progress calls back into.
|
|
78
|
+
.then(() => callback.call(handler, proxy))
|
|
79
|
+
.catch((error: unknown) => {
|
|
80
|
+
// Never an unhandled rejection: a handler's own bug must not become
|
|
81
|
+
// one, on top of whatever else it broke.
|
|
82
|
+
console.error('[Bugsee] report handler threw', errorName(error));
|
|
83
|
+
})
|
|
84
|
+
.finally(() => {
|
|
85
|
+
clearTimeout(deadlineTimer);
|
|
86
|
+
proxy.markDead();
|
|
87
|
+
NativeBugsee.completeReportHandler(event.handleId);
|
|
88
|
+
})
|
|
89
|
+
.catch((error: unknown) => {
|
|
90
|
+
// The native call itself threw (a torn-down bridge, say). Native
|
|
91
|
+
// completes the handle at its deadline or on detach regardless; this
|
|
92
|
+
// only keeps the failure from becoming an unhandled rejection.
|
|
93
|
+
console.error('[Bugsee] could not complete the report handler', errorName(error));
|
|
94
|
+
});
|
|
95
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The four stable codes a report operation can fail with.
|
|
3
|
+
*
|
|
4
|
+
* Stable, and worth stating: an app matches on `.code`, so these strings are
|
|
5
|
+
* part of the public contract, not an implementation detail free to change
|
|
6
|
+
* between releases like an error message is.
|
|
7
|
+
*/
|
|
8
|
+
export const ReportErrorCode = {
|
|
9
|
+
/**
|
|
10
|
+
* The handle's callback has already settled, or its deadline already
|
|
11
|
+
* passed, or a created report has already been uploaded. Raised locally --
|
|
12
|
+
* without crossing the bridge -- for every operation after that point, and
|
|
13
|
+
* reproduced with the same code when a native rejection reports it instead.
|
|
14
|
+
*/
|
|
15
|
+
HandleDead: 'E_REPORT_HANDLE_DEAD',
|
|
16
|
+
/** Native declined an attachment (`addFileAttachment`/`addDataAttachment`). */
|
|
17
|
+
AttachmentRejected: 'E_REPORT_ATTACHMENT_REJECTED',
|
|
18
|
+
/** JS-side validation rejected the argument before it crossed the bridge. */
|
|
19
|
+
BadArgument: 'E_REPORT_BAD_ARGUMENT',
|
|
20
|
+
/**
|
|
21
|
+
* A created report is already outstanding. A second `createReport()` rejects
|
|
22
|
+
* with this until that report is uploaded. iOS beta3 keeps created-report
|
|
23
|
+
* attributes in file-scope globals, so a second create would wipe the first.
|
|
24
|
+
*/
|
|
25
|
+
CreateBusy: 'E_REPORT_CREATE_BUSY',
|
|
26
|
+
} as const;
|
|
27
|
+
|
|
28
|
+
export type ReportErrorCode =
|
|
29
|
+
(typeof ReportErrorCode)[keyof typeof ReportErrorCode];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* What every `BugseeReport` rejection is an instance of, whether it was
|
|
33
|
+
* raised locally (JS validation, a dead handle) or translated from a native
|
|
34
|
+
* rejection that carried one of the codes above.
|
|
35
|
+
*/
|
|
36
|
+
export class BugseeReportError extends Error {
|
|
37
|
+
readonly code: ReportErrorCode;
|
|
38
|
+
|
|
39
|
+
constructor(code: ReportErrorCode, message: string) {
|
|
40
|
+
super(message);
|
|
41
|
+
this.name = 'BugseeReportError';
|
|
42
|
+
this.code = code;
|
|
43
|
+
// Restores `instanceof` across the ES5 transpile some consumers still
|
|
44
|
+
// build with -- without it, `Error` subclasses lose their prototype chain
|
|
45
|
+
// and `error instanceof BugseeReportError` reads false for a real one.
|
|
46
|
+
Object.setPrototypeOf(this, BugseeReportError.prototype);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared argument checks for `upload` and `showReportDialog`.
|
|
3
|
+
*
|
|
4
|
+
* Messages name the method and the field. They never include the rejected
|
|
5
|
+
* value: a label or a severity string can be something the caller did not
|
|
6
|
+
* mean to put in a log.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** 0 for undefined; RangeError unless an integer 1..5. A non-number is a TypeError. */
|
|
10
|
+
export function severityArgument(severity: unknown, method: string): number {
|
|
11
|
+
if (severity === undefined) {
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
if (typeof severity !== 'number') {
|
|
15
|
+
throw new TypeError(`Bugsee.${method} severity must be an integer 1..5`);
|
|
16
|
+
}
|
|
17
|
+
if (!Number.isInteger(severity) || severity < 1 || severity > 5) {
|
|
18
|
+
throw new RangeError(`Bugsee.${method} severity must be an integer 1..5`);
|
|
19
|
+
}
|
|
20
|
+
return severity;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** null for undefined; TypeError unless an array of strings; a fresh copy. */
|
|
24
|
+
export function labelsArgument(
|
|
25
|
+
labels: unknown,
|
|
26
|
+
method: string,
|
|
27
|
+
): string[] | null {
|
|
28
|
+
if (labels === undefined) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
if (!Array.isArray(labels)) {
|
|
32
|
+
throw new TypeError(`Bugsee.${method} labels must be an array of strings`);
|
|
33
|
+
}
|
|
34
|
+
for (const label of labels) {
|
|
35
|
+
if (typeof label !== 'string') {
|
|
36
|
+
throw new TypeError(`Bugsee.${method} labels must be an array of strings`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return [...labels];
|
|
40
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { IssueSeverity } from '../options/enums';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A report's kind, as the native side names it.
|
|
5
|
+
*
|
|
6
|
+
* An open set, deliberately: `'bug' | 'crash' | 'error'` is what both SDKs
|
|
7
|
+
* emit today, but a newer native SDK adding a kind must still reach a JS
|
|
8
|
+
* handler rather than being rejected by a wrapper that predates it.
|
|
9
|
+
*/
|
|
10
|
+
export type ReportType = 'bug' | 'crash' | 'error' | (string & {});
|
|
11
|
+
|
|
12
|
+
/** The report's fields as of one `read()`. */
|
|
13
|
+
export interface BugseeReportSnapshot {
|
|
14
|
+
summary: string | undefined;
|
|
15
|
+
description: string | undefined;
|
|
16
|
+
/** iOS reports 0 for "unset"; anything outside 1..5 reads as `undefined`. */
|
|
17
|
+
severity: IssueSeverity | undefined;
|
|
18
|
+
labels: string[];
|
|
19
|
+
attributes: Record<string, string | number | boolean>;
|
|
20
|
+
/** Ascending, always -- native is not guaranteed to be (Android #178). */
|
|
21
|
+
screenshotDisplayIds: number[];
|
|
22
|
+
attachmentNames: string[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A patch applied to a report through `update()`.
|
|
27
|
+
*
|
|
28
|
+
* Every field is optional and, together, all-or-nothing: nothing is applied
|
|
29
|
+
* unless every field present is valid. `labels` REPLACES the report's whole
|
|
30
|
+
* list (Android `setLabels`, iOS `replaceLabels:`), not appends to it.
|
|
31
|
+
* `clearAttributes` is applied before `attributes`, so a patch can clear and
|
|
32
|
+
* then set in one call. Within `attributes`, a `null` value removes that key
|
|
33
|
+
* rather than setting it to null.
|
|
34
|
+
*/
|
|
35
|
+
export interface ReportPatch {
|
|
36
|
+
summary?: string | null;
|
|
37
|
+
description?: string | null;
|
|
38
|
+
severity?: IssueSeverity;
|
|
39
|
+
labels?: readonly string[];
|
|
40
|
+
attributes?: Readonly<Record<string, string | number | boolean | null>>;
|
|
41
|
+
clearAttributes?: true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A live handle onto the report a `BugseeReportHandler` callback was given.
|
|
46
|
+
*
|
|
47
|
+
* Scoped to the handle the native event carried: every operation crosses the
|
|
48
|
+
* bridge with the same `handleId`, and every one of them rejects with
|
|
49
|
+
* `BugseeReportError` code `E_REPORT_HANDLE_DEAD` -- without crossing the
|
|
50
|
+
* bridge at all -- once the callback that received this report has settled or
|
|
51
|
+
* its deadline has passed. `id` and `type` need no round trip: both arrive
|
|
52
|
+
* with the event that produced this proxy.
|
|
53
|
+
*/
|
|
54
|
+
export interface BugseeReport {
|
|
55
|
+
readonly id: string;
|
|
56
|
+
readonly type: ReportType;
|
|
57
|
+
|
|
58
|
+
/** One native call; every getter below is sugar over this. */
|
|
59
|
+
read(): Promise<BugseeReportSnapshot>;
|
|
60
|
+
|
|
61
|
+
getSummary(): Promise<string | undefined>;
|
|
62
|
+
setSummary(value: string | null): Promise<void>;
|
|
63
|
+
getDescription(): Promise<string | undefined>;
|
|
64
|
+
setDescription(value: string | null): Promise<void>;
|
|
65
|
+
getSeverity(): Promise<IssueSeverity | undefined>;
|
|
66
|
+
setSeverity(value: IssueSeverity): Promise<void>;
|
|
67
|
+
getLabels(): Promise<string[]>;
|
|
68
|
+
/** Replaces the whole list, in one `reportUpdate` call. */
|
|
69
|
+
setLabels(labels: readonly string[]): Promise<void>;
|
|
70
|
+
getAttributes(): Promise<Record<string, string | number | boolean>>;
|
|
71
|
+
/** `value: null` removes the attribute rather than setting it to null. */
|
|
72
|
+
setAttribute(
|
|
73
|
+
name: string,
|
|
74
|
+
value: string | number | boolean | null,
|
|
75
|
+
): Promise<void>;
|
|
76
|
+
clearAttributes(): Promise<void>;
|
|
77
|
+
getScreenshotDisplayIds(): Promise<number[]>;
|
|
78
|
+
getAttachmentNames(): Promise<string[]>;
|
|
79
|
+
/**
|
|
80
|
+
* `path` is either a `file://` URL, which is stripped and percent-decoded,
|
|
81
|
+
* or a plain filesystem path, which is used verbatim (`%` included).
|
|
82
|
+
*/
|
|
83
|
+
addFileAttachment(
|
|
84
|
+
path: string,
|
|
85
|
+
options: { name: string; mimeType?: string; move?: boolean },
|
|
86
|
+
): Promise<void>;
|
|
87
|
+
addDataAttachment(
|
|
88
|
+
base64: string,
|
|
89
|
+
options: { name: string; mimeType?: string },
|
|
90
|
+
): Promise<void>;
|
|
91
|
+
update(patch: ReportPatch): Promise<void>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* A report the app fills and then uploads, from `createReport()`.
|
|
96
|
+
*
|
|
97
|
+
* Unlike a handler `BugseeReport`, this has no id, no type and no deadline.
|
|
98
|
+
* `upload()` ends it: every later call rejects `E_REPORT_HANDLE_DEAD`.
|
|
99
|
+
*/
|
|
100
|
+
export interface BugseeCreatedReport {
|
|
101
|
+
read(): Promise<BugseeReportSnapshot>;
|
|
102
|
+
update(patch: ReportPatch): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* The file is copied when it is added. There is no `move`: a created report
|
|
105
|
+
* does not take the file away from the app.
|
|
106
|
+
*/
|
|
107
|
+
addFileAttachment(
|
|
108
|
+
path: string,
|
|
109
|
+
options: { name: string; mimeType?: string },
|
|
110
|
+
): Promise<void>;
|
|
111
|
+
addDataAttachment(
|
|
112
|
+
base64: string,
|
|
113
|
+
options: { name: string; mimeType?: string },
|
|
114
|
+
): Promise<void>;
|
|
115
|
+
/** Uploads; resolves the SDK's result. Every later call rejects E_REPORT_HANDLE_DEAD. */
|
|
116
|
+
upload(): Promise<boolean>;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Registered through `setReportHandler`. Register before `launch()` to see
|
|
121
|
+
* reports the SDK recovers at launch.
|
|
122
|
+
*
|
|
123
|
+
* `onBeforeReportCreated` is at-most-once and may be skipped entirely for a
|
|
124
|
+
* given report -- a crash recovered at launch, for instance, can go straight
|
|
125
|
+
* to `onAfterReportCreated`. `onAfterReportCreated` is at-least-once and MUST
|
|
126
|
+
* be idempotent: prefer `setLabels`/`setAttribute` over appending, and check
|
|
127
|
+
* `getAttachmentNames()` before adding an attachment a previous delivery may
|
|
128
|
+
* already have added.
|
|
129
|
+
*
|
|
130
|
+
* **Attachments.** A handler report takes up to 1000 attachments on both
|
|
131
|
+
* platforms. A file is captured when it is added, and `move` is honoured.
|
|
132
|
+
* `onAfterReportCreated` must check `getAttachmentNames()` before adding.
|
|
133
|
+
*
|
|
134
|
+
* A mutation made after the callback settles, or after
|
|
135
|
+
* its handle's deadline passes, does not reach the report -- the deadline is
|
|
136
|
+
* the SDK's own, not something the app negotiates.
|
|
137
|
+
*
|
|
138
|
+
* **Time budget per callback, by platform.** A live report gives each
|
|
139
|
+
* callback 25 s on both platforms. That is never raised, even if an app
|
|
140
|
+
* raises the SDK's handler timeout (Android `report-handler-callback-timeout`;
|
|
141
|
+
* iOS has no such option), but on Android it drops to a second under that
|
|
142
|
+
* option when the app sets it lower. A report recovered at launch differs:
|
|
143
|
+
* - iOS gives JS 2.5 s, off the main thread and best-effort -- edits land
|
|
144
|
+
* only until the SDK assembles the bundle;
|
|
145
|
+
* - Android's Java uncaught-exception relaunch, when the SDK was launched
|
|
146
|
+
* from JS, runs on `BugseeReportHandlerThread` and gives the live 25 s;
|
|
147
|
+
* - Android's NDK relaunch (SIGSEGV / SIGABRT), and the SDK's own early
|
|
148
|
+
* bounded recovery, run off that thread (`bugsee-report-handler-bounded`
|
|
149
|
+
* for an NDK crash) and never reach JS.
|
|
150
|
+
* So async I/O in `onAfterReportCreated` can succeed on a Java relaunch and
|
|
151
|
+
* silently miss on an iOS recovered report or an Android NDK relaunch. Keep
|
|
152
|
+
* recovery-time work short.
|
|
153
|
+
*/
|
|
154
|
+
export interface BugseeReportHandler {
|
|
155
|
+
onBeforeReportCreated?(report: BugseeReport): void | Promise<void>;
|
|
156
|
+
onAfterReportCreated?(report: BugseeReport): void | Promise<void>;
|
|
157
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation the JS side runs BEFORE crossing the bridge.
|
|
3
|
+
*
|
|
4
|
+
* Every function here either returns a wire-ready value or throws
|
|
5
|
+
* `BugseeReportError` with code `BadArgument` -- never something a caller has
|
|
6
|
+
* to translate. `validateReportPatch` is all-or-nothing: it fully validates
|
|
7
|
+
* every field present before returning anything, so a caller that only
|
|
8
|
+
* inspects its return value can never observe a half-applied patch.
|
|
9
|
+
*/
|
|
10
|
+
import type { IssueSeverity } from '../options/enums';
|
|
11
|
+
import { BugseeReportError, ReportErrorCode } from './errors';
|
|
12
|
+
import type { ReportPatch } from './types';
|
|
13
|
+
|
|
14
|
+
function badArgument(message: string): never {
|
|
15
|
+
throw new BugseeReportError(ReportErrorCode.BadArgument, message);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Integers 1..5 -- the only values the SDKs accept as a severity to SET. */
|
|
19
|
+
export function isValidSeverityValue(value: unknown): value is IssueSeverity {
|
|
20
|
+
return (
|
|
21
|
+
typeof value === 'number' &&
|
|
22
|
+
Number.isInteger(value) &&
|
|
23
|
+
value >= 1 &&
|
|
24
|
+
value <= 5
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function validateSeverity(value: unknown): IssueSeverity {
|
|
29
|
+
if (!isValidSeverityValue(value)) {
|
|
30
|
+
// Never the value itself: anything JSON allows can arrive here.
|
|
31
|
+
badArgument('severity must be an integer 1..5');
|
|
32
|
+
}
|
|
33
|
+
return value as IssueSeverity;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The severity a `read()` reports, or `undefined` for anything that is not a
|
|
38
|
+
* valid 1..5 -- including iOS's 0-for-unset. Reading is more permissive than
|
|
39
|
+
* writing on purpose: a value outside 1..5 arriving from native is not this
|
|
40
|
+
* layer's argument to reject, only one it cannot say anything useful about.
|
|
41
|
+
*/
|
|
42
|
+
export function severityFromNative(value: unknown): IssueSeverity | undefined {
|
|
43
|
+
return isValidSeverityValue(value) ? value : undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function validateLabels(labels: unknown): string[] {
|
|
47
|
+
if (!Array.isArray(labels)) {
|
|
48
|
+
badArgument(`labels must be an array of strings, got ${typeof labels}`);
|
|
49
|
+
}
|
|
50
|
+
for (const label of labels) {
|
|
51
|
+
if (typeof label !== 'string') {
|
|
52
|
+
badArgument(`labels must all be strings, got ${typeof label}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return [...(labels as string[])];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function isValidAttributeValue(
|
|
59
|
+
value: unknown,
|
|
60
|
+
): value is string | number | boolean | null {
|
|
61
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean') {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function validateAttributes(
|
|
68
|
+
attributes: unknown,
|
|
69
|
+
): Record<string, string | number | boolean | null> {
|
|
70
|
+
if (
|
|
71
|
+
typeof attributes !== 'object' ||
|
|
72
|
+
attributes === null ||
|
|
73
|
+
Array.isArray(attributes)
|
|
74
|
+
) {
|
|
75
|
+
badArgument('attributes must be a plain object');
|
|
76
|
+
}
|
|
77
|
+
// No prototype, so every name is an ordinary key -- "__proto__" included.
|
|
78
|
+
// In a plain `{}` it would hit Object.prototype's setter instead and never
|
|
79
|
+
// reach native: silently for a string or number, and by swapping this
|
|
80
|
+
// object's prototype for null. Both SDKs store it like any other name.
|
|
81
|
+
const result: Record<string, string | number | boolean | null> =
|
|
82
|
+
Object.create(null);
|
|
83
|
+
for (const [key, value] of Object.entries(
|
|
84
|
+
attributes as Record<string, unknown>,
|
|
85
|
+
)) {
|
|
86
|
+
if (key.length === 0) {
|
|
87
|
+
badArgument('attribute name must be a non-empty string');
|
|
88
|
+
}
|
|
89
|
+
if (!isValidAttributeValue(value)) {
|
|
90
|
+
badArgument(
|
|
91
|
+
`attribute "${key}" must be a string, boolean, finite number or null, got ${typeof value}`,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
result[key] = value;
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function validateNonEmptyString(value: unknown, field: string): string {
|
|
100
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
101
|
+
badArgument(`${field} must be a non-empty string`);
|
|
102
|
+
}
|
|
103
|
+
return value as string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const FILE_URL_PREFIX = 'file://';
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* A `file://` URL is stripped and percent-decoded. Anything else is a plain
|
|
110
|
+
* filesystem path and passes through verbatim: `%` is a legal filename
|
|
111
|
+
* character, so decoding it would reject `/…/100%done.log` and silently turn
|
|
112
|
+
* `/logs/a%41.log` into `/logs/aA.log`.
|
|
113
|
+
*/
|
|
114
|
+
export function normalizeFilePath(path: string): string {
|
|
115
|
+
if (!path.startsWith(FILE_URL_PREFIX)) return path;
|
|
116
|
+
try {
|
|
117
|
+
return decodeURIComponent(path.slice(FILE_URL_PREFIX.length));
|
|
118
|
+
} catch {
|
|
119
|
+
// Never the path itself: a path is app data (it can name the user).
|
|
120
|
+
return badArgument('path is not valid percent-encoding');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const BASE64_PATTERN = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
125
|
+
|
|
126
|
+
export function validateBase64(value: unknown): string {
|
|
127
|
+
if (
|
|
128
|
+
typeof value !== 'string' ||
|
|
129
|
+
value.length % 4 !== 0 ||
|
|
130
|
+
!BASE64_PATTERN.test(value)
|
|
131
|
+
) {
|
|
132
|
+
badArgument('data must be base64-encoded');
|
|
133
|
+
}
|
|
134
|
+
return value as string;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const PATCH_KEYS: ReadonlySet<string> = new Set([
|
|
138
|
+
'summary',
|
|
139
|
+
'description',
|
|
140
|
+
'severity',
|
|
141
|
+
'labels',
|
|
142
|
+
'clearAttributes',
|
|
143
|
+
'attributes',
|
|
144
|
+
]);
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Validates a whole `ReportPatch` and returns the exact object to send to
|
|
148
|
+
* `reportUpdate`, or throws before anything is sent.
|
|
149
|
+
*
|
|
150
|
+
* An unknown key fails the whole patch rather than being ignored: a caller
|
|
151
|
+
* that misspelled a field would otherwise see its patch silently drop part of
|
|
152
|
+
* itself.
|
|
153
|
+
*/
|
|
154
|
+
export function validateReportPatch(patch: ReportPatch): Record<string, unknown> {
|
|
155
|
+
if (typeof patch !== 'object' || patch === null) {
|
|
156
|
+
badArgument('update() requires a patch object');
|
|
157
|
+
}
|
|
158
|
+
for (const key of Object.keys(patch)) {
|
|
159
|
+
if (!PATCH_KEYS.has(key)) {
|
|
160
|
+
badArgument(`update() received an unknown key "${key}"`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const wire: Record<string, unknown> = {};
|
|
165
|
+
|
|
166
|
+
if ('summary' in patch) {
|
|
167
|
+
const { summary } = patch;
|
|
168
|
+
if (summary !== null && typeof summary !== 'string') {
|
|
169
|
+
badArgument('summary must be a string or null');
|
|
170
|
+
}
|
|
171
|
+
wire.summary = summary;
|
|
172
|
+
}
|
|
173
|
+
if ('description' in patch) {
|
|
174
|
+
const { description } = patch;
|
|
175
|
+
if (description !== null && typeof description !== 'string') {
|
|
176
|
+
badArgument('description must be a string or null');
|
|
177
|
+
}
|
|
178
|
+
wire.description = description;
|
|
179
|
+
}
|
|
180
|
+
if ('severity' in patch) {
|
|
181
|
+
wire.severity = validateSeverity(patch.severity);
|
|
182
|
+
}
|
|
183
|
+
if ('labels' in patch) {
|
|
184
|
+
wire.labels = validateLabels(patch.labels);
|
|
185
|
+
}
|
|
186
|
+
if ('clearAttributes' in patch) {
|
|
187
|
+
if (patch.clearAttributes !== true) {
|
|
188
|
+
badArgument('clearAttributes must be true when present');
|
|
189
|
+
}
|
|
190
|
+
wire.clearAttributes = true;
|
|
191
|
+
}
|
|
192
|
+
if ('attributes' in patch) {
|
|
193
|
+
wire.attributes = validateAttributes(patch.attributes);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return wire;
|
|
197
|
+
}
|