@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,345 @@
|
|
|
1
|
+
#import "BGSRNReportOps.h"
|
|
2
|
+
#import "BGSRNErrorMessage.h"
|
|
3
|
+
#import "BGSRNJSON.h"
|
|
4
|
+
|
|
5
|
+
#include <math.h>
|
|
6
|
+
|
|
7
|
+
NSErrorDomain const BGSRNReportErrorDomain = @"BGSRNReportErrorDomain";
|
|
8
|
+
|
|
9
|
+
NSString *BGSRNReportErrorWireCode(NSError *error) {
|
|
10
|
+
if (![error.domain isEqualToString:BGSRNReportErrorDomain]) {
|
|
11
|
+
return nil;
|
|
12
|
+
}
|
|
13
|
+
switch ((BGSRNReportError)error.code) {
|
|
14
|
+
case BGSRNReportErrorBadArgument:
|
|
15
|
+
return @"E_REPORT_BAD_ARGUMENT";
|
|
16
|
+
case BGSRNReportErrorAttachmentRejected:
|
|
17
|
+
return @"E_REPORT_ATTACHMENT_REJECTED";
|
|
18
|
+
}
|
|
19
|
+
return nil;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/// JS numbers are doubles; beyond 2^53 a double is no longer an exact integer.
|
|
23
|
+
static const double kMaxSafeInteger = 9007199254740992.0;
|
|
24
|
+
|
|
25
|
+
/// Hands `made` to the caller's out-parameter. Every error this file makes is
|
|
26
|
+
/// built inline, with a string-literal description, so the scanner
|
|
27
|
+
/// (`scripts/raw-messages.ts`) can see that no value goes into it.
|
|
28
|
+
static BOOL Fail(NSError **out, NSError *made) {
|
|
29
|
+
if (out != NULL) {
|
|
30
|
+
*out = made;
|
|
31
|
+
}
|
|
32
|
+
return NO;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/// A JS boolean crosses as the CFBoolean singleton, which is also an NSNumber;
|
|
36
|
+
/// a JS number never does. The two must not be confused either way.
|
|
37
|
+
static BOOL IsBoolean(id value) {
|
|
38
|
+
return [value isKindOfClass:NSNumber.class] &&
|
|
39
|
+
CFGetTypeID((__bridge CFTypeRef)value) == CFBooleanGetTypeID();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static BOOL IsFiniteNumber(id value) {
|
|
43
|
+
return [value isKindOfClass:NSNumber.class] && !IsBoolean(value) && isfinite([value doubleValue]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// The value the SDK should store for a JS number: an integer when it is an
|
|
47
|
+
/// exact one (so an attribute of 3 is stored as 3, not 3.0), a double otherwise.
|
|
48
|
+
static NSNumber *WireNumber(NSNumber *number) {
|
|
49
|
+
const double value = number.doubleValue;
|
|
50
|
+
if (value == floor(value) && fabs(value) <= kMaxSafeInteger) {
|
|
51
|
+
return @((long long)value);
|
|
52
|
+
}
|
|
53
|
+
return @(value);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@implementation BGSRNReportOps
|
|
57
|
+
|
|
58
|
+
+ (NSDictionary<NSString *, id> *)readReport:(id<BGSReportContract>)report {
|
|
59
|
+
NSMutableDictionary<NSString *, id> *result = [NSMutableDictionary dictionary];
|
|
60
|
+
|
|
61
|
+
// Omitted when unset rather than NSNull: JS reads either as undefined.
|
|
62
|
+
NSString *summary = report.summary;
|
|
63
|
+
if ([summary isKindOfClass:NSString.class]) {
|
|
64
|
+
result[@"summary"] = summary;
|
|
65
|
+
}
|
|
66
|
+
NSString *description = report.reportDescription;
|
|
67
|
+
if ([description isKindOfClass:NSString.class]) {
|
|
68
|
+
result[@"description"] = description;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// By value. 0 is "not set" and passes through; JS maps it to undefined.
|
|
72
|
+
result[@"severity"] = @((NSInteger)report.severity);
|
|
73
|
+
|
|
74
|
+
NSMutableArray<NSString *> *labels = [NSMutableArray array];
|
|
75
|
+
for (id label in report.labels) {
|
|
76
|
+
if ([label isKindOfClass:NSString.class]) {
|
|
77
|
+
[labels addObject:label];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
result[@"labels"] = labels;
|
|
81
|
+
|
|
82
|
+
// The JS type is string | number | boolean; anything else has no
|
|
83
|
+
// representation there, and a description would read as a real value.
|
|
84
|
+
NSMutableDictionary<NSString *, id> *attributes = [NSMutableDictionary dictionary];
|
|
85
|
+
[report.attributes enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) {
|
|
86
|
+
if ([key isKindOfClass:NSString.class] &&
|
|
87
|
+
([value isKindOfClass:NSString.class] || [value isKindOfClass:NSNumber.class])) {
|
|
88
|
+
attributes[key] = value;
|
|
89
|
+
}
|
|
90
|
+
}];
|
|
91
|
+
result[@"attributes"] = attributes;
|
|
92
|
+
|
|
93
|
+
// The SDK documents these ascending; sorted again so the wire contract does
|
|
94
|
+
// not rest on that.
|
|
95
|
+
NSMutableArray<NSNumber *> *displayIds = [NSMutableArray array];
|
|
96
|
+
for (id displayId in report.screenshotDisplayIds) {
|
|
97
|
+
if ([displayId isKindOfClass:NSNumber.class]) {
|
|
98
|
+
[displayIds addObject:displayId];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
result[@"screenshotDisplayIds"] = [displayIds sortedArrayUsingSelector:@selector(compare:)];
|
|
102
|
+
|
|
103
|
+
NSMutableArray<NSString *> *attachmentNames = [NSMutableArray array];
|
|
104
|
+
for (id<BGSAttachmentContract> attachment in report.attachments) {
|
|
105
|
+
NSString *name = attachment.name;
|
|
106
|
+
if ([name isKindOfClass:NSString.class]) {
|
|
107
|
+
[attachmentNames addObject:name];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
result[@"attachmentNames"] = attachmentNames;
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
+ (nullable NSDictionary<NSString *, id> *)validatedPatch:(NSDictionary *)patch
|
|
115
|
+
error:(NSError **)error {
|
|
116
|
+
static NSSet<NSString *> *knownKeys;
|
|
117
|
+
static dispatch_once_t once;
|
|
118
|
+
dispatch_once(&once, ^{
|
|
119
|
+
knownKeys = [NSSet setWithArray:@[ @"summary", @"description", @"severity", @"labels",
|
|
120
|
+
@"clearAttributes", @"attributes" ]];
|
|
121
|
+
});
|
|
122
|
+
for (id key in patch) {
|
|
123
|
+
if (![knownKeys containsObject:key]) {
|
|
124
|
+
Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
125
|
+
code:BGSRNReportErrorBadArgument
|
|
126
|
+
userInfo:@{
|
|
127
|
+
NSLocalizedDescriptionKey : @"update() received an unknown key \"{identifier}\"",
|
|
128
|
+
BGSRNErrorIdentifierKey : key,
|
|
129
|
+
}]);
|
|
130
|
+
return nil;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Validate everything first. Nothing below the next comment can reject.
|
|
135
|
+
id summary = patch[@"summary"];
|
|
136
|
+
if (summary != nil && summary != NSNull.null && ![summary isKindOfClass:NSString.class]) {
|
|
137
|
+
Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
138
|
+
code:BGSRNReportErrorBadArgument
|
|
139
|
+
userInfo:@{NSLocalizedDescriptionKey : @"summary must be a string or null"}]);
|
|
140
|
+
return nil;
|
|
141
|
+
}
|
|
142
|
+
id description = patch[@"description"];
|
|
143
|
+
if (description != nil && description != NSNull.null && ![description isKindOfClass:NSString.class]) {
|
|
144
|
+
Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
145
|
+
code:BGSRNReportErrorBadArgument
|
|
146
|
+
userInfo:@{NSLocalizedDescriptionKey : @"description must be a string or null"}]);
|
|
147
|
+
return nil;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Checked 1..5 HERE: the SDK setter ignores anything else and keeps the
|
|
151
|
+
// current value, silently -- `setSeverity(0)` would resolve as if it had
|
|
152
|
+
// worked.
|
|
153
|
+
id severity = patch[@"severity"];
|
|
154
|
+
if (severity != nil) {
|
|
155
|
+
const double value = IsFiniteNumber(severity) ? [severity doubleValue] : NAN;
|
|
156
|
+
if (!(value == floor(value) && value >= BugseeSeverityLow && value <= BugseeSeverityBlocker)) {
|
|
157
|
+
// Never the value itself: anything JS allows can arrive here.
|
|
158
|
+
Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
159
|
+
code:BGSRNReportErrorBadArgument
|
|
160
|
+
userInfo:@{NSLocalizedDescriptionKey : @"severity must be an integer 1..5"}]);
|
|
161
|
+
return nil;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
id labels = patch[@"labels"];
|
|
166
|
+
if (labels != nil) {
|
|
167
|
+
if (![labels isKindOfClass:NSArray.class]) {
|
|
168
|
+
Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
169
|
+
code:BGSRNReportErrorBadArgument
|
|
170
|
+
userInfo:@{NSLocalizedDescriptionKey : @"labels must be an array of strings"}]);
|
|
171
|
+
return nil;
|
|
172
|
+
}
|
|
173
|
+
for (id label in (NSArray *)labels) {
|
|
174
|
+
if (![label isKindOfClass:NSString.class]) {
|
|
175
|
+
Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
176
|
+
code:BGSRNReportErrorBadArgument
|
|
177
|
+
userInfo:@{NSLocalizedDescriptionKey : @"labels must all be strings"}]);
|
|
178
|
+
return nil;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
id clearAttributes = patch[@"clearAttributes"];
|
|
184
|
+
if (clearAttributes != nil && !(IsBoolean(clearAttributes) && [clearAttributes boolValue])) {
|
|
185
|
+
Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
186
|
+
code:BGSRNReportErrorBadArgument
|
|
187
|
+
userInfo:@{NSLocalizedDescriptionKey : @"clearAttributes must be true when present"}]);
|
|
188
|
+
return nil;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
id rawAttributes = patch[@"attributes"];
|
|
192
|
+
NSMutableDictionary<NSString *, id> *attributes = nil;
|
|
193
|
+
if (rawAttributes != nil) {
|
|
194
|
+
if (![rawAttributes isKindOfClass:NSDictionary.class]) {
|
|
195
|
+
Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
196
|
+
code:BGSRNReportErrorBadArgument
|
|
197
|
+
userInfo:@{NSLocalizedDescriptionKey : @"attributes must be a plain object"}]);
|
|
198
|
+
return nil;
|
|
199
|
+
}
|
|
200
|
+
attributes = [NSMutableDictionary dictionary];
|
|
201
|
+
for (id key in (NSDictionary *)rawAttributes) {
|
|
202
|
+
id value = ((NSDictionary *)rawAttributes)[key];
|
|
203
|
+
const BOOL valid = value == NSNull.null || [value isKindOfClass:NSString.class] ||
|
|
204
|
+
IsBoolean(value) || IsFiniteNumber(value);
|
|
205
|
+
if (![key isKindOfClass:NSString.class] || !valid) {
|
|
206
|
+
Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
207
|
+
code:BGSRNReportErrorBadArgument
|
|
208
|
+
userInfo:@{
|
|
209
|
+
NSLocalizedDescriptionKey : @"attribute \"{identifier}\" must be a string, boolean, finite number or null",
|
|
210
|
+
BGSRNErrorIdentifierKey : key,
|
|
211
|
+
}]);
|
|
212
|
+
return nil;
|
|
213
|
+
}
|
|
214
|
+
// Parity with the JS proxy, which rejects it before crossing.
|
|
215
|
+
if ([(NSString *)key length] == 0) {
|
|
216
|
+
Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
217
|
+
code:BGSRNReportErrorBadArgument
|
|
218
|
+
userInfo:@{NSLocalizedDescriptionKey : @"attribute name must be a non-empty string"}]);
|
|
219
|
+
return nil;
|
|
220
|
+
}
|
|
221
|
+
attributes[key] = IsFiniteNumber(value) ? WireNumber(value) : value;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
NSMutableDictionary<NSString *, id> *valid = [NSMutableDictionary dictionary];
|
|
226
|
+
if (summary != nil) {
|
|
227
|
+
valid[@"summary"] = summary;
|
|
228
|
+
}
|
|
229
|
+
if (description != nil) {
|
|
230
|
+
valid[@"description"] = description;
|
|
231
|
+
}
|
|
232
|
+
if (severity != nil) {
|
|
233
|
+
valid[@"severity"] = severity;
|
|
234
|
+
}
|
|
235
|
+
if (labels != nil) {
|
|
236
|
+
valid[@"labels"] = labels;
|
|
237
|
+
}
|
|
238
|
+
if (clearAttributes != nil) {
|
|
239
|
+
valid[@"clearAttributes"] = clearAttributes;
|
|
240
|
+
}
|
|
241
|
+
if (attributes != nil) {
|
|
242
|
+
valid[@"attributes"] = attributes;
|
|
243
|
+
}
|
|
244
|
+
return valid;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
+ (BOOL)applyPatch:(NSDictionary *)patch
|
|
248
|
+
toReport:(id<BGSReportContract>)report
|
|
249
|
+
error:(NSError **)error {
|
|
250
|
+
NSDictionary<NSString *, id> *valid = [self validatedPatch:patch error:error];
|
|
251
|
+
if (valid == nil) {
|
|
252
|
+
return NO;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Everything is valid; apply.
|
|
256
|
+
id summary = valid[@"summary"];
|
|
257
|
+
if (summary != nil) {
|
|
258
|
+
report.summary = summary == NSNull.null ? nil : summary;
|
|
259
|
+
}
|
|
260
|
+
id description = valid[@"description"];
|
|
261
|
+
if (description != nil) {
|
|
262
|
+
report.reportDescription = description == NSNull.null ? nil : description;
|
|
263
|
+
}
|
|
264
|
+
id severity = valid[@"severity"];
|
|
265
|
+
if (severity != nil) {
|
|
266
|
+
report.severity = (BugseeSeverityLevel)[severity integerValue];
|
|
267
|
+
}
|
|
268
|
+
id labels = valid[@"labels"];
|
|
269
|
+
if (labels != nil) {
|
|
270
|
+
// One atomic call: clear-then-add would expose a label-less report between the two.
|
|
271
|
+
[report replaceLabels:labels];
|
|
272
|
+
}
|
|
273
|
+
if (valid[@"clearAttributes"] != nil) {
|
|
274
|
+
// Before the attributes, so clear-then-set holds whatever order the patch
|
|
275
|
+
// was written in.
|
|
276
|
+
[report clearAllAttributes];
|
|
277
|
+
}
|
|
278
|
+
[valid[@"attributes"] enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) {
|
|
279
|
+
if (value == NSNull.null) {
|
|
280
|
+
[report removeAttributeForName:key];
|
|
281
|
+
} else {
|
|
282
|
+
[report setAttribute:value forName:key];
|
|
283
|
+
}
|
|
284
|
+
}];
|
|
285
|
+
return YES;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
+ (BOOL)applyPatchJSON:(NSString *)json
|
|
289
|
+
toReport:(id<BGSReportContract>)report
|
|
290
|
+
error:(NSError **)error {
|
|
291
|
+
NSError *parseError = nil;
|
|
292
|
+
NSDictionary *patch = BGSRNJSONObject(json, &parseError);
|
|
293
|
+
if (patch == nil) {
|
|
294
|
+
return Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
295
|
+
code:BGSRNReportErrorBadArgument
|
|
296
|
+
userInfo:@{
|
|
297
|
+
NSLocalizedDescriptionKey : @"update() patch is not a JSON object",
|
|
298
|
+
NSUnderlyingErrorKey : parseError ?: NSNull.null,
|
|
299
|
+
}]);
|
|
300
|
+
}
|
|
301
|
+
return [self applyPatch:patch toReport:report error:error];
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
+ (BOOL)addFileAtPath:(NSString *)path
|
|
305
|
+
name:(NSString *)name
|
|
306
|
+
mimeType:(NSString *)mimeType
|
|
307
|
+
move:(BOOL)move
|
|
308
|
+
toReport:(id<BGSReportContract>)report
|
|
309
|
+
error:(NSError **)error {
|
|
310
|
+
id<BGSAttachmentContract> added = [report addAttachmentWithFilePath:path name:name mimeType:mimeType move:move];
|
|
311
|
+
if (added == nil) {
|
|
312
|
+
return Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
313
|
+
code:BGSRNReportErrorAttachmentRejected
|
|
314
|
+
userInfo:@{NSLocalizedDescriptionKey : @"The SDK declined the attachment"}]);
|
|
315
|
+
}
|
|
316
|
+
return YES;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
+ (BOOL)addData:(NSString *)base64
|
|
320
|
+
name:(NSString *)name
|
|
321
|
+
mimeType:(NSString *)mimeType
|
|
322
|
+
toReport:(id<BGSReportContract>)report
|
|
323
|
+
error:(NSError **)error {
|
|
324
|
+
NSData *data = [base64 isKindOfClass:NSString.class]
|
|
325
|
+
? [[NSData alloc] initWithBase64EncodedString:base64 options:0]
|
|
326
|
+
: nil;
|
|
327
|
+
if (data == nil) {
|
|
328
|
+
return Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
329
|
+
code:BGSRNReportErrorBadArgument
|
|
330
|
+
userInfo:@{NSLocalizedDescriptionKey : @"data must be base64-encoded"}]);
|
|
331
|
+
}
|
|
332
|
+
id<BGSAttachmentContract> added = [report addAttachmentWithData:data name:name mimeType:mimeType];
|
|
333
|
+
if (added == nil) {
|
|
334
|
+
return Fail(error, [NSError errorWithDomain:BGSRNReportErrorDomain
|
|
335
|
+
code:BGSRNReportErrorAttachmentRejected
|
|
336
|
+
userInfo:@{NSLocalizedDescriptionKey : @"The SDK declined the attachment"}]);
|
|
337
|
+
}
|
|
338
|
+
return YES;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
+ (NSString *)failureMessageForOperation:(NSString *)operation {
|
|
342
|
+
return [operation stringByAppendingString:@" failed"];
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
@end
|