@bugsee/react-native 7.0.0-beta3 → 7.0.0-beta4

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.
Files changed (76) hide show
  1. package/README.md +228 -10
  2. package/android/build.gradle +9 -0
  3. package/android/consumer-rules.pro +3 -0
  4. package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +224 -20
  5. package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +44 -21
  6. package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +15 -0
  7. package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +119 -5
  8. package/android/src/main/java/com/bugsee/reactnative/NetworkCaptureProbe.java +107 -0
  9. package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +129 -14
  10. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +48 -0
  11. package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +64 -8
  12. package/android/src/main/java/com/bugsee/reactnative/StartupHold.java +237 -0
  13. package/ios/BugseeModule.mm +293 -155
  14. package/ios/Support/Package.resolved +2 -2
  15. package/ios/Support/Package.swift +1 -1
  16. package/ios/Support/Sources/BugseeRNSupport/BGSRNBlackout.m +14 -0
  17. package/ios/Support/Sources/BugseeRNSupport/BGSRNDeleteCollectedData.m +33 -0
  18. package/ios/Support/Sources/BugseeRNSupport/BGSRNFilterArming.m +22 -0
  19. package/ios/Support/Sources/BugseeRNSupport/BGSRNFilterDeadline.m +110 -0
  20. package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +40 -6
  21. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +1 -1
  22. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNBlackout.h +23 -0
  23. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +2 -0
  24. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDeleteCollectedData.h +29 -0
  25. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNFilterArming.h +26 -0
  26. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNFilterDeadline.h +68 -0
  27. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +5 -0
  28. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +5 -0
  29. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +16 -2
  30. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +5 -0
  31. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNBlackoutTests.m +38 -0
  32. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDeleteCollectedDataTests.m +135 -0
  33. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +5 -0
  34. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFilterArmingTests.m +48 -0
  35. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFilterDeadlineTests.m +230 -0
  36. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +5 -0
  37. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +86 -6
  38. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +5 -0
  39. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +1 -1
  40. package/native-versions.json +2 -2
  41. package/package.json +1 -1
  42. package/plugin/build/dsym-script.d.ts +11 -0
  43. package/plugin/build/dsym-script.js +26 -3
  44. package/plugin/build/dsym-script.js.map +1 -1
  45. package/plugin/build/index.d.ts +27 -0
  46. package/plugin/build/index.js +33 -21
  47. package/plugin/build/index.js.map +1 -1
  48. package/plugin/build/manifest.d.ts +37 -0
  49. package/plugin/build/manifest.js +67 -1
  50. package/plugin/build/manifest.js.map +1 -1
  51. package/plugin/build/native-versions.baked.json +1 -1
  52. package/scripts/compose-then-inject.js +4 -2
  53. package/scripts/hermes-sourcemaps.js +40 -3
  54. package/src/NativeBugsee.ts +39 -22
  55. package/src/apm/span.ts +42 -7
  56. package/src/breadcrumbs/filter.ts +104 -13
  57. package/src/breadcrumbs/types.ts +6 -4
  58. package/src/breadcrumbs/url-scrub.ts +75 -0
  59. package/src/exceptions/ErrorBoundary.tsx +4 -1
  60. package/src/exceptions/RootErrorReporter.tsx +1 -1
  61. package/src/exceptions/handlers.ts +17 -1
  62. package/src/exceptions/report.ts +30 -8
  63. package/src/index.ts +125 -33
  64. package/src/logs/filter.ts +19 -8
  65. package/src/network/filter.ts +17 -5
  66. package/src/options/AndroidLaunchOptions.ts +310 -24
  67. package/src/options/BugseeLaunchOptions.ts +463 -18
  68. package/src/options/IOSLaunchOptions.ts +164 -8
  69. package/src/options/android-options-manifest.json +63 -6
  70. package/src/options/enums.ts +28 -0
  71. package/src/options/ios-enums.json +6 -5
  72. package/src/options/ios-options-manifest.json +594 -0
  73. package/src/options/keys.ts +19 -1
  74. package/src/options/noAccessor.ts +16 -0
  75. package/src/options/option-keys.json +9 -3
  76. package/src/options/unknownKeys.ts +198 -0
@@ -7,6 +7,11 @@
7
7
  // with "use of '@import' when C++ modules are disabled", and then with a
8
8
  // cascade of undeclared identifiers that hides the real cause.
9
9
  #import <Bugsee/Bugsee.h>
10
+ // 7.0 GA moves the wrapper contract to the Bugsee.SPI submodule (BugseeSPI.h);
11
+ // the 7.0 betas declare it in Bugsee.h.
12
+ #if __has_include(<Bugsee/BugseeSPI.h>)
13
+ #import <Bugsee/BugseeSPI.h>
14
+ #endif
10
15
  #import <UIKit/UIKit.h>
11
16
  #import <os/lock.h>
12
17
 
@@ -31,12 +36,16 @@
31
36
  #import <BugseeRNSupport/BGSRNValues.h>
32
37
  #import <BugseeRNSupport/BGSRNJSON.h>
33
38
  #import <BugseeRNSupport/BGSRNNetworkFilter.h>
39
+ #import <BugseeRNSupport/BGSRNFilterArming.h>
34
40
  #import <BugseeRNSupport/BGSRNNetworkEvents.h>
35
41
  #import <BugseeRNSupport/BGSRNAttributes.h>
36
42
  #import <BugseeRNSupport/BGSRNDataRequestBridge.h>
37
43
  #import <BugseeRNSupport/BGSRNReactWindow.h>
38
44
  #import <BugseeRNSupport/BGSRNExceptions.h>
39
45
  #import <BugseeRNSupport/BGSRNSettleOnce.h>
46
+ #import <BugseeRNSupport/BGSRNFilterDeadline.h>
47
+ #import <BugseeRNSupport/BGSRNDeleteCollectedData.h>
48
+ #import <BugseeRNSupport/BGSRNBlackout.h>
40
49
  #import <BugseeRNSupport/BGSRNReportArgs.h>
41
50
  #import <BugseeRNSupport/BGSRNCreatedReports.h>
42
51
  #import <BugseeRNSupport/BGSRNCreatedReportOps.h>
@@ -59,12 +68,16 @@
59
68
  #import "BGSRNValues.h"
60
69
  #import "BGSRNJSON.h"
61
70
  #import "BGSRNNetworkFilter.h"
71
+ #import "BGSRNFilterArming.h"
62
72
  #import "BGSRNNetworkEvents.h"
63
73
  #import "BGSRNAttributes.h"
64
74
  #import "BGSRNDataRequestBridge.h"
65
75
  #import "BGSRNReactWindow.h"
66
76
  #import "BGSRNExceptions.h"
67
77
  #import "BGSRNSettleOnce.h"
78
+ #import "BGSRNFilterDeadline.h"
79
+ #import "BGSRNDeleteCollectedData.h"
80
+ #import "BGSRNBlackout.h"
68
81
  #import "BGSRNReportArgs.h"
69
82
  #import "BGSRNCreatedReports.h"
70
83
  #import "BGSRNCreatedReportOps.h"
@@ -442,10 +455,13 @@ static void BGSRNSetAttribute(NSString *name,
442
455
  /// One in-flight network-filter request. The decision block is copied: the
443
456
  /// SDK's block argument is not guaranteed to outlive the filter call, and the
444
457
  /// reply comes back later, from JS. iOS's decision block is once-only and the
445
- /// provider does not recycle the event, so a late reply still records. There
446
- /// is no timer here: one that called `decision(nil)` would drop an event the
447
- /// SDK is still willing to keep.
458
+ /// SDK has no timeout, so the wrapper arms its own (`BGSRNFilterDeadlineMs`,
459
+ /// fail closed): past it the event is dropped and a late reply is a no-op.
448
460
  @interface BGSRNNetworkFilterPending : NSObject
461
+ /// The wrapper's 9 s deadline; cancelled when the request is taken.
462
+ @property (nonatomic, copy, nullable) dispatch_block_t deadline;
463
+ /// Monotonic instant (ns) after which a reply is refused.
464
+ @property (nonatomic, strong, nullable) NSNumber *expiresAt;
449
465
  @property (nonatomic, strong) BugseeNetworkEvent *event;
450
466
  @property (nonatomic, copy) BugseeNetworkFilterDecisionBlock decision;
451
467
  @property (nonatomic, weak) BugseeModule *owner;
@@ -455,6 +471,26 @@ static void BGSRNSetAttribute(NSString *name,
455
471
 
456
472
  static __weak BugseeModule *BGSRNNetworkFilterModule = nil;
457
473
  static BOOL BGSRNNetworkFilterInstalled = NO;
474
+ // Which module's JS installed the filter. A reload leaves the filter block in
475
+ // place and attaches a new module that has not; see BGSRNFilterArming.
476
+ /// Orders a module's claim of the three filter pointers against a setter's
477
+ /// ownership check and arm, so a superseded module cannot pass the check,
478
+ /// pause, and arm or disable after the replacement attached. Lock order is
479
+ /// this lock, then a filter's own lock. The setters hold it across the SDK
480
+ /// uninstall on the disable paths (those calls only take locks); the filter
481
+ /// blocks the SDK calls never take it.
482
+ static id BGSRNFilterOwnerLock(void) {
483
+ static id lock;
484
+ static dispatch_once_t once;
485
+ dispatch_once(&once, ^{ lock = [NSObject new]; });
486
+ return lock;
487
+ }
488
+ static BGSRNFilterArming *BGSRNNetworkFilterArming(void) {
489
+ static BGSRNFilterArming *arming;
490
+ static dispatch_once_t once;
491
+ dispatch_once(&once, ^{ arming = [BGSRNFilterArming new]; });
492
+ return arming;
493
+ }
458
494
  static NSMutableDictionary<NSString *, BGSRNNetworkFilterPending *> *BGSRNNetworkFilterPendingTable;
459
495
  static int64_t BGSRNNetworkFilterNextId = 0;
460
496
 
@@ -472,17 +508,21 @@ static id BGSRNNetworkFilterLock(void) {
472
508
  /// Called outside the lock: the SDK's decision block must not re-enter it.
473
509
  static void BGSRNDropNetworkFiltersOwnedBy(BugseeModule *module) {
474
510
  NSMutableArray<BugseeNetworkFilterDecisionBlock> *decisions = [NSMutableArray array];
511
+ NSMutableArray<NSString *> *owned = [NSMutableArray array];
475
512
  @synchronized (BGSRNNetworkFilterLock()) {
476
513
  for (NSString *key in BGSRNNetworkFilterPendingTable.allKeys) {
477
- BGSRNNetworkFilterPending *item = BGSRNNetworkFilterPendingTable[key];
478
- if (item.owner == module) {
479
- [BGSRNNetworkFilterPendingTable removeObjectForKey:key];
480
- if (item.decision != nil) {
481
- [decisions addObject:item.decision];
482
- }
514
+ if (BGSRNNetworkFilterPendingTable[key].owner == module) {
515
+ [owned addObject:key];
483
516
  }
484
517
  }
485
518
  }
519
+ // Through the shared take, so each request's deadline is cancelled too.
520
+ for (NSString *key in owned) {
521
+ BGSRNNetworkFilterPending *item = BGSRNTakePendingFilter((NSMutableDictionary *)BGSRNNetworkFilterPendingTable, BGSRNNetworkFilterLock(), key);
522
+ if (item.decision != nil) {
523
+ [decisions addObject:item.decision];
524
+ }
525
+ }
486
526
  for (BugseeNetworkFilterDecisionBlock decision in decisions) {
487
527
  decision(nil);
488
528
  }
@@ -490,6 +530,10 @@ static void BGSRNDropNetworkFiltersOwnedBy(BugseeModule *module) {
490
530
 
491
531
 
492
532
  @interface BGSRNLogFilterPending : NSObject
533
+ /// The wrapper's 9 s deadline; cancelled when the request is taken.
534
+ @property (nonatomic, copy, nullable) dispatch_block_t deadline;
535
+ /// Monotonic instant (ns) after which a reply is refused.
536
+ @property (nonatomic, strong, nullable) NSNumber *expiresAt;
493
537
  @property (nonatomic, strong) BugseeLogEvent *event;
494
538
  @property (nonatomic, copy) BugseeLogFilterDecisionBlock decision;
495
539
  @property (nonatomic, weak) BugseeModule *owner;
@@ -499,6 +543,12 @@ static void BGSRNDropNetworkFiltersOwnedBy(BugseeModule *module) {
499
543
 
500
544
  static __weak BugseeModule *BGSRNLogFilterModule = nil;
501
545
  static BOOL BGSRNLogFilterInstalled = NO;
546
+ static BGSRNFilterArming *BGSRNLogFilterArming(void) {
547
+ static BGSRNFilterArming *arming;
548
+ static dispatch_once_t once;
549
+ dispatch_once(&once, ^{ arming = [BGSRNFilterArming new]; });
550
+ return arming;
551
+ }
502
552
  /** The JS round trip. Off is the native pass-through, which stays installed. */
503
553
  static BOOL BGSRNLogFilterUserEnabled = NO;
504
554
  static NSMutableDictionary<NSString *, BGSRNLogFilterPending *> *BGSRNLogFilterPendingTable;
@@ -518,17 +568,21 @@ static id BGSRNLogFilterLock(void) {
518
568
  /// Called outside the lock: the SDK's decision block must not re-enter it.
519
569
  static void BGSRNDropLogFiltersOwnedBy(BugseeModule *module) {
520
570
  NSMutableArray<BugseeLogFilterDecisionBlock> *decisions = [NSMutableArray array];
571
+ NSMutableArray<NSString *> *owned = [NSMutableArray array];
521
572
  @synchronized (BGSRNLogFilterLock()) {
522
573
  for (NSString *key in BGSRNLogFilterPendingTable.allKeys) {
523
- BGSRNLogFilterPending *item = BGSRNLogFilterPendingTable[key];
524
- if (item.owner == module) {
525
- [BGSRNLogFilterPendingTable removeObjectForKey:key];
526
- if (item.decision != nil) {
527
- [decisions addObject:item.decision];
528
- }
574
+ if (BGSRNLogFilterPendingTable[key].owner == module) {
575
+ [owned addObject:key];
529
576
  }
530
577
  }
531
578
  }
579
+ // Through the shared take, so each request's deadline is cancelled too.
580
+ for (NSString *key in owned) {
581
+ BGSRNLogFilterPending *item = BGSRNTakePendingFilter((NSMutableDictionary *)BGSRNLogFilterPendingTable, BGSRNLogFilterLock(), key);
582
+ if (item.decision != nil) {
583
+ [decisions addObject:item.decision];
584
+ }
585
+ }
532
586
  for (BugseeLogFilterDecisionBlock decision in decisions) {
533
587
  decision(nil);
534
588
  }
@@ -591,7 +645,10 @@ static void BGSRNInstallLogEventFilter(void) {
591
645
  return;
592
646
  }
593
647
  BugseeModule *module = BGSRNLogFilterModule;
594
- if (module == nil) {
648
+ // A reload kept the user's filter on but the new runtime has not called
649
+ // setLogFilter yet: drop, never record unfiltered and never emit to a
650
+ // module whose JS is not listening.
651
+ if (module == nil || ![BGSRNLogFilterArming() isArmedFor:module]) {
595
652
  decision(nil);
596
653
  return;
597
654
  }
@@ -605,26 +662,28 @@ static void BGSRNInstallLogEventFilter(void) {
605
662
  requestId = [NSString stringWithFormat:@"%lld", BGSRNLogFilterNextId];
606
663
  BGSRNLogFilterPendingTable[requestId] = item;
607
664
  }
665
+ BGSRNArmPendingFilterDeadline(
666
+ (NSMutableDictionary *)BGSRNLogFilterPendingTable,
667
+ BGSRNLogFilterLock(),
668
+ requestId);
608
669
  const BOOL delivered = [module emitLogFilterRequest:requestId line:line];
609
670
  if (!delivered) {
610
- BugseeLogFilterDecisionBlock drop = nil;
611
- @synchronized (BGSRNLogFilterLock()) {
612
- BGSRNLogFilterPending *removed = BGSRNLogFilterPendingTable[requestId];
613
- [BGSRNLogFilterPendingTable removeObjectForKey:requestId];
614
- drop = removed.decision;
615
- }
616
- if (drop != nil) {
617
- drop(nil);
618
- }
671
+ BGSRNDropPendingFilter((NSMutableDictionary *)BGSRNLogFilterPendingTable,
672
+ BGSRNLogFilterLock(), requestId);
619
673
  }
620
674
  }];
621
675
  }
622
676
 
623
677
  /// One in-flight breadcrumb-filter request. The decision block is copied: the
624
678
  /// SDK's block argument is not guaranteed to outlive the filter call, and the
625
- /// reply comes back later, from JS. There is no timer. The SDK does not time
626
- /// the filter out, and a late decision still records.
679
+ /// reply comes back later, from JS. The SDK does not time the filter out, so
680
+ /// the wrapper arms `BGSRNFilterDeadlineMs`, fail closed: past it the crumb
681
+ /// is dropped and a late reply is a no-op.
627
682
  @interface BGSRNBreadcrumbFilterPending : NSObject
683
+ /// The wrapper's 9 s deadline; cancelled when the request is taken.
684
+ @property (nonatomic, copy, nullable) dispatch_block_t deadline;
685
+ /// Monotonic instant (ns) after which a reply is refused.
686
+ @property (nonatomic, strong, nullable) NSNumber *expiresAt;
628
687
  @property (nonatomic, strong) id<BGSBreadcrumb> breadcrumb;
629
688
  @property (nonatomic, copy) BugseeBreadcrumbFilterDecisionBlock decision;
630
689
  @property (nonatomic, weak) BugseeModule *owner;
@@ -634,6 +693,12 @@ static void BGSRNInstallLogEventFilter(void) {
634
693
 
635
694
  static __weak BugseeModule *BGSRNBreadcrumbFilterModule = nil;
636
695
  static BOOL BGSRNBreadcrumbFilterInstalled = NO;
696
+ static BGSRNFilterArming *BGSRNBreadcrumbFilterArming(void) {
697
+ static BGSRNFilterArming *arming;
698
+ static dispatch_once_t once;
699
+ dispatch_once(&once, ^{ arming = [BGSRNFilterArming new]; });
700
+ return arming;
701
+ }
637
702
  /// Bumped on every enable and every disable. A disable queued on main nils
638
703
  /// the filter only when this is still the generation it captured, so a later
639
704
  /// enable is not wiped by a nil that was already queued.
@@ -660,17 +725,21 @@ static id BGSRNBreadcrumbFilterLock(void) {
660
725
  /// This is teardown, not a timeout.
661
726
  static void BGSRNDropBreadcrumbFiltersOwnedBy(BugseeModule *module) {
662
727
  NSMutableArray<BugseeBreadcrumbFilterDecisionBlock> *decisions = [NSMutableArray array];
728
+ NSMutableArray<NSString *> *owned = [NSMutableArray array];
663
729
  @synchronized (BGSRNBreadcrumbFilterLock()) {
664
730
  for (NSString *key in BGSRNBreadcrumbFilterPendingTable.allKeys) {
665
- BGSRNBreadcrumbFilterPending *item = BGSRNBreadcrumbFilterPendingTable[key];
666
- if (item.owner == module) {
667
- [BGSRNBreadcrumbFilterPendingTable removeObjectForKey:key];
668
- if (item.decision != nil) {
669
- [decisions addObject:item.decision];
670
- }
731
+ if (BGSRNBreadcrumbFilterPendingTable[key].owner == module) {
732
+ [owned addObject:key];
671
733
  }
672
734
  }
673
735
  }
736
+ // Through the shared take, so each request's deadline is cancelled too.
737
+ for (NSString *key in owned) {
738
+ BGSRNBreadcrumbFilterPending *item = BGSRNTakePendingFilter((NSMutableDictionary *)BGSRNBreadcrumbFilterPendingTable, BGSRNBreadcrumbFilterLock(), key);
739
+ if (item.decision != nil) {
740
+ [decisions addObject:item.decision];
741
+ }
742
+ }
674
743
  for (BugseeBreadcrumbFilterDecisionBlock decision in decisions) {
675
744
  decision(nil);
676
745
  }
@@ -857,6 +926,10 @@ static BOOL BGSRNApplyBreadcrumbKeep(id<BGSBreadcrumb> breadcrumb, NSDictionary
857
926
  return _span.isFinished;
858
927
  }
859
928
 
929
+ - (NSInteger)bgsrnStatus {
930
+ return (NSInteger)_span.status;
931
+ }
932
+
860
933
  @end
861
934
 
862
935
  /// One JSON value, or nil when it is missing, null, an object or an array.
@@ -1023,14 +1096,16 @@ RCT_EXPORT_MODULE(Bugsee)
1023
1096
  // After the emitter exists. A network filter installed earlier reads this
1024
1097
  // pointer when an event arrives; it is nil until then, and a nil module
1025
1098
  // drops the event.
1026
- BGSRNNetworkFilterModule = self;
1027
- // After the emitter exists. The native log filter is already installed.
1028
- // While a user callback is on, a nil module drops the line. With no user
1029
- // callback the same filter returns the line.
1030
- BGSRNLogFilterModule = self;
1031
- // Same lifetime as the log filter: nil until the emitter exists, and a nil
1032
- // module drops the crumb.
1033
- BGSRNBreadcrumbFilterModule = self;
1099
+ @synchronized (BGSRNFilterOwnerLock()) {
1100
+ BGSRNNetworkFilterModule = self;
1101
+ // After the emitter exists. The native log filter is already installed.
1102
+ // While a user callback is on, a nil module drops the line. With no user
1103
+ // callback the same filter returns the line.
1104
+ BGSRNLogFilterModule = self;
1105
+ // Same lifetime as the log filter: nil until the emitter exists, and a nil
1106
+ // module drops the crumb.
1107
+ BGSRNBreadcrumbFilterModule = self;
1108
+ }
1034
1109
  }
1035
1110
 
1036
1111
  /// Identity-checked inside the bus: a reload can construct and attach the NEW
@@ -1056,23 +1131,30 @@ RCT_EXPORT_MODULE(Bugsee)
1056
1131
  // Drop this module's unanswered network events. A reload may already have
1057
1132
  // attached the new module; only clear the pointer when it is still us.
1058
1133
  BGSRNDropNetworkFiltersOwnedBy(self);
1059
- if (BGSRNNetworkFilterModule == self) {
1060
- BGSRNNetworkFilterModule = nil;
1134
+ @synchronized (BGSRNFilterOwnerLock()) {
1135
+ if (BGSRNNetworkFilterModule == self) {
1136
+ BGSRNNetworkFilterModule = nil;
1137
+ }
1061
1138
  }
1062
1139
  // Drop this module's unanswered log lines. A reload may already have
1063
1140
  // attached the new module; only clear the pointer when it is still us.
1064
1141
  BGSRNDropLogFiltersOwnedBy(self);
1065
- if (BGSRNLogFilterModule == self) {
1066
- BGSRNLogFilterModule = nil;
1142
+ @synchronized (BGSRNFilterOwnerLock()) {
1143
+ if (BGSRNLogFilterModule == self) {
1144
+ BGSRNLogFilterModule = nil;
1145
+ }
1067
1146
  }
1068
1147
  // Drop this module's unanswered crumbs. A reload may already have attached
1069
1148
  // the new module; only clear the pointer when it is still us.
1070
1149
  BGSRNDropBreadcrumbFiltersOwnedBy(self);
1071
- if (BGSRNBreadcrumbFilterModule == self) {
1072
- BGSRNBreadcrumbFilterModule = nil;
1150
+ @synchronized (BGSRNFilterOwnerLock()) {
1151
+ if (BGSRNBreadcrumbFilterModule == self) {
1152
+ BGSRNBreadcrumbFilterModule = nil;
1153
+ }
1073
1154
  }
1074
- // The next runtime cannot know these handles. Drop them without finishing:
1075
- // a reload must not close a transaction the SDK still has. The getter
1155
+ // The next runtime cannot know these handles, so nothing would ever finish
1156
+ // them and the SDK would keep the transactions open. Cancel what is still
1157
+ // open, then drop the handles. The getter
1076
1158
  // must not allocate a fresh registry after this: a span call still in
1077
1159
  // flight would adopt into an object invalidate already abandoned.
1078
1160
  os_unfair_lock_lock(&_spanRegistryLock);
@@ -1080,7 +1162,12 @@ RCT_EXPORT_MODULE(Bugsee)
1080
1162
  BGSRNSpanHandles *previous = _spanHandles;
1081
1163
  _spanHandles = [BGSRNSpanHandles closedRegistry];
1082
1164
  os_unfair_lock_unlock(&_spanRegistryLock);
1083
- [previous releaseAll];
1165
+ // Span calls run on the main thread; so does this finish. Async: invalidate
1166
+ // can run while the main thread waits on the runtime, and a sync hop would
1167
+ // deadlock. The registry is already swapped out, so nothing races it.
1168
+ BGSRNRunOnMain(^{
1169
+ [previous cancelOpenAndReleaseAll];
1170
+ });
1084
1171
  }
1085
1172
 
1086
1173
  /// The SDK touches UIKit during start-up, so it must not be constructed on a
@@ -1257,9 +1344,11 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
1257
1344
  return;
1258
1345
  }
1259
1346
  BGSRNRunOnMain(^{
1260
- // launchWithToken: returns the instance, or nil when the SDK declines —
1261
- // already running, or the token was rejected. Declining is a normal
1262
- // outcome, so it resolves false rather than rejecting.
1347
+ // launchWithToken: returns the instance, or nil when the SDK declines
1348
+ // (the token was rejected). Declining is a normal outcome, so it
1349
+ // resolves false rather than rejecting. When the SDK is already running
1350
+ // it returns the running instance, so this resolves true and the new
1351
+ // options are ignored.
1263
1352
  Bugsee *instance = [Bugsee launchWithToken:token andOptions:BGSRNResolvedLaunchOptions(options)];
1264
1353
  // launch can replace the log filter. Put the pass-through, or the user
1265
1354
  // filter if one is already on, back. This does not set the filter to nil.
@@ -1268,6 +1357,9 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
1268
1357
  });
1269
1358
  }
1270
1359
 
1360
+ // Deliberately NOT given the stop() treatment (#143): relaunch is one call that
1361
+ // restarts the SDK, not a session the app ended, and whether the iOS SDK keeps
1362
+ // a blackout across it is unverified; the app can call endBlackout().
1271
1363
  - (void)relaunch:(NSDictionary *)options
1272
1364
  resolve:(RCTPromiseResolveBlock)resolve
1273
1365
  reject:(RCTPromiseRejectBlock)reject {
@@ -1295,6 +1387,11 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
1295
1387
  - (void)stop:(RCTPromiseResolveBlock)resolve
1296
1388
  reject:(RCTPromiseRejectBlock)reject {
1297
1389
  BGSRNRunOnMain(^{
1390
+ // TODO(#143): temporary; the iOS SDK should end the blackout on stop
1391
+ // itself (see BGSRNBlackout.h). End it first, while still launched, so
1392
+ // BlackoutEnded is delivered. Skipped for a never-launched SDK so a
1393
+ // pre-launch startBlackout() survives.
1394
+ BGSRNEndBlackoutForStop();
1298
1395
  [Bugsee stop:^{
1299
1396
  resolve(@YES);
1300
1397
  }];
@@ -1595,8 +1692,8 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
1595
1692
  /// with. `enabled` registers the bridge; `NO` passes nil, which removes it.
1596
1693
  /// The write is synchronized and does not need the main queue, so it happens
1597
1694
  /// before this method returns: a later Bugsee call on the same turn already
1598
- /// sees the filter. The block returns without waiting on JS. There is no
1599
- /// deadline here.
1695
+ /// sees the filter. The block returns without waiting on JS. A request JS
1696
+ /// does not answer within `BGSRNFilterDeadlineMs` is dropped.
1600
1697
  ///
1601
1698
  /// Returns `@YES`. The return is what keeps the call on the JS thread:
1602
1699
  /// codegen queues a `void` TurboModule method onto the module queue, so a
@@ -1604,6 +1701,18 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
1604
1701
  /// install landed, with its url, headers and body unfiltered. The SDK setter
1605
1702
  /// only takes a lock, so it is safe on the JS thread.
1606
1703
  - (NSNumber *)setNetworkFilterEnabled:(BOOL)enabled {
1704
+ // A reload can attach the new module before this one is invalidated. A
1705
+ // superseded module must neither arm nor disable the process-wide filter.
1706
+ BOOL owner = NO;
1707
+ @synchronized (BGSRNFilterOwnerLock()) {
1708
+ owner = BGSRNNetworkFilterModule == self;
1709
+ if (owner && enabled) {
1710
+ [BGSRNNetworkFilterArming() armFor:self];
1711
+ }
1712
+ }
1713
+ if (!owner) {
1714
+ return @YES;
1715
+ }
1607
1716
  if (enabled) {
1608
1717
  @synchronized (BGSRNNetworkFilterLock()) {
1609
1718
  if (BGSRNNetworkFilterInstalled) {
@@ -1620,7 +1729,10 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
1620
1729
  return;
1621
1730
  }
1622
1731
  BugseeModule *module = BGSRNNetworkFilterModule;
1623
- if (module == nil) {
1732
+ // After a reload the new module's JS has not installed its filter:
1733
+ // drop now rather than wait out the deadline for a runtime that is
1734
+ // not listening.
1735
+ if (module == nil || ![BGSRNNetworkFilterArming() isArmedFor:module]) {
1624
1736
  decision(nil);
1625
1737
  return;
1626
1738
  }
@@ -1639,25 +1751,30 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
1639
1751
  requestId = [NSString stringWithFormat:@"%lld", BGSRNNetworkFilterNextId];
1640
1752
  BGSRNNetworkFilterPendingTable[requestId] = item;
1641
1753
  }
1754
+ BGSRNArmPendingFilterDeadline(
1755
+ (NSMutableDictionary *)BGSRNNetworkFilterPendingTable,
1756
+ BGSRNNetworkFilterLock(),
1757
+ requestId);
1642
1758
  const BOOL delivered = [module emitNetworkFilterRequest:requestId eventJson:eventJson];
1643
1759
  if (!delivered) {
1644
- BugseeNetworkFilterDecisionBlock drop = nil;
1645
- @synchronized (BGSRNNetworkFilterLock()) {
1646
- BGSRNNetworkFilterPending *removed = BGSRNNetworkFilterPendingTable[requestId];
1647
- [BGSRNNetworkFilterPendingTable removeObjectForKey:requestId];
1648
- drop = removed.decision;
1649
- }
1650
- if (drop != nil) {
1651
- drop(nil);
1652
- }
1760
+ BGSRNDropPendingFilter((NSMutableDictionary *)BGSRNNetworkFilterPendingTable,
1761
+ BGSRNNetworkFilterLock(), requestId);
1653
1762
  }
1654
1763
  }];
1655
1764
  return @YES;
1656
1765
  }
1657
- @synchronized (BGSRNNetworkFilterLock()) {
1658
- BGSRNNetworkFilterInstalled = NO;
1766
+ // Ownership is checked again under the owner lock and held through the
1767
+ // uninstall: a stale module that passed the check above must not remove a
1768
+ // filter the replacement has since relied on. The SDK setter only takes
1769
+ // locks.
1770
+ @synchronized (BGSRNFilterOwnerLock()) {
1771
+ if (BGSRNNetworkFilterModule == self) {
1772
+ @synchronized (BGSRNNetworkFilterLock()) {
1773
+ BGSRNNetworkFilterInstalled = NO;
1774
+ }
1775
+ [Bugsee setNetworkEventFilter:nil];
1776
+ }
1659
1777
  }
1660
- [Bugsee setNetworkEventFilter:nil];
1661
1778
  return @YES;
1662
1779
  }
1663
1780
 
@@ -1669,19 +1786,17 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
1669
1786
  }
1670
1787
 
1671
1788
  /// `eventJson` nil drops. A JSON object is written onto the same event, so
1672
- /// the timestamp stays. A second reply is a no-op. A late reply still
1673
- /// records: this method does not expire the decision.
1789
+ /// the timestamp stays. A second reply is a no-op, and so is a reply after
1790
+ /// `BGSRNFilterDeadlineMs`: the deadline already dropped the event.
1674
1791
  - (void)replyNetworkFilter:(NSString *)requestId eventJson:(NSString * _Nullable)eventJson {
1675
1792
  if (requestId == nil) {
1676
1793
  return;
1677
1794
  }
1678
- BGSRNNetworkFilterPending *item = nil;
1679
- @synchronized (BGSRNNetworkFilterLock()) {
1680
- item = BGSRNNetworkFilterPendingTable[requestId];
1681
- if (item != nil) {
1682
- [BGSRNNetworkFilterPendingTable removeObjectForKey:requestId];
1683
- }
1684
- }
1795
+ BGSRNNetworkFilterPending *item =
1796
+ BGSRNTakePendingFilter(
1797
+ (NSMutableDictionary *)BGSRNNetworkFilterPendingTable,
1798
+ BGSRNNetworkFilterLock(),
1799
+ requestId);
1685
1800
  if (item.decision == nil) {
1686
1801
  return;
1687
1802
  }
@@ -1700,8 +1815,7 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
1700
1815
  /// epoch milliseconds and builds a `BugseeNetworkEvent`. Beta3's exchange
1701
1816
  /// factory `createNetworkEvent` always returns nil, so this does not call it.
1702
1817
  /// The event is submitted with filtering required. The one-argument
1703
- /// `addNetworkEvent:` passes NO and is not used. There is no timer that
1704
- /// would pass the original through.
1818
+ /// `addNetworkEvent:` passes NO and is not used.
1705
1819
  - (void)addNetworkEvent:(NSString *)eventJson {
1706
1820
  NSError *error = nil;
1707
1821
  NSDictionary *object = BGSRNJSONObject(eventJson, &error);
@@ -1727,8 +1841,22 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
1727
1841
  /// console line written on the next line could be captured before a queued
1728
1842
  /// flag flip landed. The flag write and the SDK setter only take locks.
1729
1843
  - (NSNumber *)setLogFilterEnabled:(BOOL)enabled {
1730
- @synchronized (BGSRNLogFilterLock()) {
1731
- BGSRNLogFilterUserEnabled = enabled;
1844
+ // A reload can attach the new module before this one is invalidated. A
1845
+ // superseded module must neither arm nor disable the process-wide filter.
1846
+ BOOL owner = NO;
1847
+ @synchronized (BGSRNFilterOwnerLock()) {
1848
+ owner = BGSRNLogFilterModule == self;
1849
+ if (owner) {
1850
+ if (enabled) {
1851
+ [BGSRNLogFilterArming() armFor:self];
1852
+ }
1853
+ @synchronized (BGSRNLogFilterLock()) {
1854
+ BGSRNLogFilterUserEnabled = enabled;
1855
+ }
1856
+ }
1857
+ }
1858
+ if (!owner) {
1859
+ return @YES;
1732
1860
  }
1733
1861
  BGSRNInstallLogEventFilter();
1734
1862
  return @YES;
@@ -1743,18 +1871,17 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
1743
1871
 
1744
1872
  /// `line` nil drops. A string is written onto the same event, so the level
1745
1873
  /// and the timestamp stay. If the write does not stick, the line is dropped
1746
- /// rather than kept unredacted. A second reply is a no-op.
1874
+ /// rather than kept unredacted. A second reply is a no-op, and so is a reply
1875
+ /// after `BGSRNFilterDeadlineMs`: the deadline already dropped the line.
1747
1876
  - (void)replyLogFilter:(NSString *)requestId line:(NSString * _Nullable)line {
1748
1877
  if (requestId == nil) {
1749
1878
  return;
1750
1879
  }
1751
- BGSRNLogFilterPending *item = nil;
1752
- @synchronized (BGSRNLogFilterLock()) {
1753
- item = BGSRNLogFilterPendingTable[requestId];
1754
- if (item != nil) {
1755
- [BGSRNLogFilterPendingTable removeObjectForKey:requestId];
1756
- }
1757
- }
1880
+ BGSRNLogFilterPending *item =
1881
+ BGSRNTakePendingFilter(
1882
+ (NSMutableDictionary *)BGSRNLogFilterPendingTable,
1883
+ BGSRNLogFilterLock(),
1884
+ requestId);
1758
1885
  if (item.decision == nil) {
1759
1886
  return;
1760
1887
  }
@@ -1786,9 +1913,20 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
1786
1913
  /// the nil cannot overtake the crumb. The generation this disable captured
1787
1914
  /// has to still be current or the nil does not run: a clear and then a new
1788
1915
  /// callback, before main runs, must not have the queued nil remove the newer
1789
- /// filter. There is no timer that calls `decision(nil)`. A late decision
1790
- /// still records.
1916
+ /// filter.
1791
1917
  - (NSNumber *)setBreadcrumbFilterEnabled:(BOOL)enabled {
1918
+ // A reload can attach the new module before this one is invalidated. A
1919
+ // superseded module must neither arm nor disable the process-wide filter.
1920
+ BOOL owner = NO;
1921
+ @synchronized (BGSRNFilterOwnerLock()) {
1922
+ owner = BGSRNBreadcrumbFilterModule == self;
1923
+ if (owner && enabled) {
1924
+ [BGSRNBreadcrumbFilterArming() armFor:self];
1925
+ }
1926
+ }
1927
+ if (!owner) {
1928
+ return @YES;
1929
+ }
1792
1930
  if (enabled) {
1793
1931
  @synchronized (BGSRNBreadcrumbFilterLock()) {
1794
1932
  BGSRNBreadcrumbFilterGeneration += 1;
@@ -1806,7 +1944,8 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
1806
1944
  return;
1807
1945
  }
1808
1946
  BugseeModule *module = BGSRNBreadcrumbFilterModule;
1809
- if (module == nil) {
1947
+ // Same reload case as the network filter.
1948
+ if (module == nil || ![BGSRNBreadcrumbFilterArming() isArmedFor:module]) {
1810
1949
  decision(nil);
1811
1950
  return;
1812
1951
  }
@@ -1825,6 +1964,10 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
1825
1964
  requestId = [NSString stringWithFormat:@"%lld", BGSRNBreadcrumbFilterNextId];
1826
1965
  BGSRNBreadcrumbFilterPendingTable[requestId] = item;
1827
1966
  }
1967
+ BGSRNArmPendingFilterDeadline(
1968
+ (NSMutableDictionary *)BGSRNBreadcrumbFilterPendingTable,
1969
+ BGSRNBreadcrumbFilterLock(),
1970
+ requestId);
1828
1971
  NSString *manualAddId = nil;
1829
1972
  @synchronized (BGSRNBreadcrumbFilterLock()) {
1830
1973
  manualAddId = BGSRNBreadcrumbManualAddId;
@@ -1840,15 +1983,8 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
1840
1983
  }
1841
1984
  }
1842
1985
  if (!delivered) {
1843
- BugseeBreadcrumbFilterDecisionBlock drop = nil;
1844
- @synchronized (BGSRNBreadcrumbFilterLock()) {
1845
- BGSRNBreadcrumbFilterPending *removed = BGSRNBreadcrumbFilterPendingTable[requestId];
1846
- [BGSRNBreadcrumbFilterPendingTable removeObjectForKey:requestId];
1847
- drop = removed.decision;
1848
- }
1849
- if (drop != nil) {
1850
- drop(nil);
1851
- }
1986
+ BGSRNDropPendingFilter((NSMutableDictionary *)BGSRNBreadcrumbFilterPendingTable,
1987
+ BGSRNBreadcrumbFilterLock(), requestId);
1852
1988
  }
1853
1989
  }];
1854
1990
  return @YES;
@@ -1859,12 +1995,20 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
1859
1995
  generation = BGSRNBreadcrumbFilterGeneration;
1860
1996
  }
1861
1997
  BGSRNRunOnMain(^{
1862
- @synchronized (BGSRNBreadcrumbFilterLock()) {
1863
- if (BGSRNBreadcrumbFilterGeneration != generation) {
1998
+ // The generation does not catch a stale disable that captured it after
1999
+ // the replacement's enable, so ownership is checked here too, under the
2000
+ // owner lock held through the uninstall.
2001
+ @synchronized (BGSRNFilterOwnerLock()) {
2002
+ if (BGSRNBreadcrumbFilterModule != self) {
1864
2003
  return;
1865
2004
  }
1866
- BGSRNBreadcrumbFilterInstalled = NO;
1867
- [Bugsee setBreadcrumbFilter:nil];
2005
+ @synchronized (BGSRNBreadcrumbFilterLock()) {
2006
+ if (BGSRNBreadcrumbFilterGeneration != generation) {
2007
+ return;
2008
+ }
2009
+ BGSRNBreadcrumbFilterInstalled = NO;
2010
+ [Bugsee setBreadcrumbFilter:nil];
2011
+ }
1868
2012
  }
1869
2013
  });
1870
2014
  return @YES;
@@ -1884,7 +2028,7 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
1884
2028
  /// The main-queue record dropped this id (no factory, no crumb, or the filter
1885
2029
  /// never asked). JS drops the owed callback. `crumbJson` is empty, so the
1886
2030
  /// callback does not run. The request id is not in the pending table, so the
1887
- /// reply is a no-op. There is no timer.
2031
+ /// reply is a no-op.
1888
2032
  - (void)releaseBreadcrumbManualAdd:(NSString *)addId {
1889
2033
  if (addId.length == 0) {
1890
2034
  return;
@@ -1896,18 +2040,16 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
1896
2040
  /// `timestamp` is not written: `BGSEvent.timestamp` is read-only, and the SDK
1897
2041
  /// pins the time it observed before the filter ran. If a write does not
1898
2042
  /// stick, the crumb is dropped rather than kept unredacted. A second reply
1899
- /// is a no-op. There is no timer.
2043
+ /// is a no-op, and so is a reply after `BGSRNFilterDeadlineMs`.
1900
2044
  - (void)replyBreadcrumbFilter:(NSString *)requestId crumbJson:(NSString * _Nullable)crumbJson {
1901
2045
  if (requestId == nil) {
1902
2046
  return;
1903
2047
  }
1904
- BGSRNBreadcrumbFilterPending *item = nil;
1905
- @synchronized (BGSRNBreadcrumbFilterLock()) {
1906
- item = BGSRNBreadcrumbFilterPendingTable[requestId];
1907
- if (item != nil) {
1908
- [BGSRNBreadcrumbFilterPendingTable removeObjectForKey:requestId];
1909
- }
1910
- }
2048
+ BGSRNBreadcrumbFilterPending *item =
2049
+ BGSRNTakePendingFilter(
2050
+ (NSMutableDictionary *)BGSRNBreadcrumbFilterPendingTable,
2051
+ BGSRNBreadcrumbFilterLock(),
2052
+ requestId);
1911
2053
  if (item.decision == nil) {
1912
2054
  return;
1913
2055
  }
@@ -2409,11 +2551,16 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
2409
2551
  }
2410
2552
 
2411
2553
  - (NSDictionary *)adoptSpan:(id<BGSSpan>)span {
2554
+ return [self adoptSpan:span owned:YES];
2555
+ }
2556
+
2557
+ /// `owned` NO is a span JS only found (the active span), not one it started.
2558
+ - (NSDictionary *)adoptSpan:(id<BGSSpan>)span owned:(BOOL)owned {
2412
2559
  if (span == nil) {
2413
2560
  return BGSRNNoSpan();
2414
2561
  }
2415
2562
  BGSRNLiveSpan *adapter = [[BGSRNLiveSpan alloc] initWithSpan:span];
2416
- NSString *handle = [self.spanHandles retainSpan:span adapter:adapter];
2563
+ NSString *handle = [self.spanHandles retainSpan:span adapter:adapter owned:owned];
2417
2564
  return BGSRNSpanSnapshot(handle, span);
2418
2565
  }
2419
2566
 
@@ -2485,7 +2632,7 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
2485
2632
  - (NSDictionary *)getActiveSpan {
2486
2633
  __block NSDictionary *snapshot = nil;
2487
2634
  BGSRNRunOnMainSync(^{
2488
- snapshot = [self adoptSpan:[Bugsee getActiveSpan]];
2635
+ snapshot = [self adoptSpan:[Bugsee getActiveSpan] owned:NO];
2489
2636
  });
2490
2637
  return snapshot;
2491
2638
  }
@@ -2574,10 +2721,10 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
2574
2721
  return snapshot;
2575
2722
  }
2576
2723
 
2577
- - (NSArray<NSString *> *)spanFinish:(NSString *)handle
2724
+ - (NSDictionary *)spanFinish:(NSString *)handle
2578
2725
  status:(double)status
2579
2726
  statusSet:(BOOL)statusSet {
2580
- __block NSArray<NSString *> *released = @[];
2727
+ __block NSArray<NSDictionary *> *released = @[];
2581
2728
  BGSRNRunOnMainSync(^{
2582
2729
  NSNumber *wire = nil;
2583
2730
  if (statusSet) {
@@ -2590,7 +2737,7 @@ static NSDictionary *BGSRNResolvedLaunchOptions(NSDictionary *options) {
2590
2737
  }
2591
2738
  released = [self.spanHandles finishHandle:handle status:wire];
2592
2739
  });
2593
- return released;
2740
+ return @{@"released": released};
2594
2741
  }
2595
2742
 
2596
2743
  /// Writable report colors on BugseeTheme (7.0.0-beta4; unchanged from beta3). Feedback properties
@@ -2673,47 +2820,38 @@ static NSString *BGSRNHexFromColor(UIColor *color) {
2673
2820
  return hex;
2674
2821
  }
2675
2822
 
2676
- /// iOS 7.0.0-beta3 and beta4 return without invoking `completion` when the SDK is
2677
- /// not stopped, so a launched call resolves `false` immediately. That is the
2678
- /// missing completion, not a wait. Stopped, including a nil instance, still
2679
- /// calls the SDK method and settles through `BGSRNSettleOnce`: the
2680
- /// completion's success, or `false` if the deadline fires first. Status and
2681
- /// both SDK calls run on the main queue. A completion that arrives off main
2682
- /// hops back before it writes the result the settler resolves.
2823
+ /// Resolves with the SDK's own outcome. iOS 7.0.0-beta7 always invokes the
2824
+ /// completion (on the main thread): `NO` when the SDK is not stopped, otherwise
2825
+ /// once the deletion has finished. The only timer is the long backstop in
2826
+ /// `BGSRNDeleteCollectedData`, which REJECTS with `E_DELETE_TIMEOUT` (outcome
2827
+ /// unknown, the deletion may still finish) rather than resolving `false`.
2828
+ /// `includingFinishedReports` selects the SDK form that also deletes the report
2829
+ /// bundles waiting for upload, the crashes not reported yet and the anomaly
2830
+ /// baselines; that form has no `includingIntermediate` flag because it deletes
2831
+ /// the snapshots too.
2683
2832
  - (void)deleteCollectedDataOnDevice:(BOOL)includingIntermediate
2684
- resolve:(RCTPromiseResolveBlock)resolve
2685
- reject:(RCTPromiseRejectBlock)reject {
2833
+ includingFinishedReports:(BOOL)includingFinishedReports
2834
+ resolve:(RCTPromiseResolveBlock)resolve
2835
+ reject:(RCTPromiseRejectBlock)reject {
2686
2836
  BGSRNRunOnMain(^{
2687
- Bugsee *instance = [Bugsee sharedInstance];
2688
- BugseeStatus status = instance != nil ? instance.status : BugseeStatusStopped;
2689
- if (status != BugseeStatusStopped) {
2690
- __block BOOL settled = NO;
2691
- [Bugsee deleteCollectedDataOnDevice:includingIntermediate completion:^(BOOL success) {
2692
- BGSRNRunOnMain(^{
2693
- if (settled) {
2694
- return;
2837
+ BGSRNDeleteCollectedData(
2838
+ ^(void (^completion)(BOOL)) {
2839
+ if (includingFinishedReports) {
2840
+ [Bugsee deleteCollectedDataOnDevice:completion];
2841
+ } else {
2842
+ [Bugsee deleteCollectedDataOnDevice:includingIntermediate completion:completion];
2695
2843
  }
2696
- settled = YES;
2844
+ },
2845
+ BGSRNDeleteCollectedDataBackstopMs, dispatch_get_main_queue(),
2846
+ ^(BOOL success) {
2697
2847
  resolve(@(success));
2848
+ },
2849
+ ^(NSString *code) {
2850
+ reject(code,
2851
+ @"Bugsee did not report the outcome of deleteCollectedDataOnDevice in time; "
2852
+ @"the deletion may still finish.",
2853
+ nil);
2698
2854
  });
2699
- }];
2700
- if (!settled) {
2701
- settled = YES;
2702
- resolve(@NO);
2703
- }
2704
- return;
2705
- }
2706
- __block NSNumber *result = @NO;
2707
- dispatch_block_t done =
2708
- BGSRNSettleOnce(BGSRNUnhandledCompletionDeadlineMs, dispatch_get_main_queue(), ^{
2709
- resolve(result);
2710
- });
2711
- [Bugsee deleteCollectedDataOnDevice:includingIntermediate completion:^(BOOL success) {
2712
- BGSRNRunOnMain(^{
2713
- result = @(success);
2714
- done();
2715
- });
2716
- }];
2717
2855
  });
2718
2856
  }
2719
2857