@logbrew/react-native 0.1.35 → 0.1.37
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/README.md +13 -3
- package/android/src/main/java/co/logbrew/reactnative/AndroidDiagnosticsRuntime.java +2 -0
- package/android/src/main/java/co/logbrew/reactnative/AndroidNativeDiagnostics.java +23 -2
- package/android/src/main/java/co/logbrew/reactnative/EventRecordStore.java +25 -0
- package/android/src/main/java/co/logbrew/reactnative/FatalStoreModuleImpl.java +22 -0
- package/android/src/newarch/java/co/logbrew/reactnative/FatalStoreModule.java +6 -0
- package/android/src/oldarch/java/co/logbrew/reactnative/FatalStoreModule.java +6 -0
- package/expo.cjs +1 -1
- package/index.cjs +4 -2
- package/index.d.cts +1 -0
- package/index.d.ts +1 -0
- package/instrumentation.cjs +0 -2
- package/ios/AppleDiagnostics/LBRNAppleNativeDiagnostics.swift +1 -1
- package/ios/LBRNEventRecordStore.h +1 -0
- package/ios/LBRNEventRecordStore.m +43 -0
- package/ios/LBRNFatalStoreModule.mm +14 -0
- package/package.json +2 -2
- package/persistent-delivery.native.js +50 -1
- package/src/NativeLogBrewFatalStore.ts +4 -0
package/README.md
CHANGED
|
@@ -80,7 +80,9 @@ For mobile apps, prefer an app-scoped public key through `clientKey`. Expo
|
|
|
80
80
|
inlines `EXPO_PUBLIC_*` values into the app, so never use a server key there.
|
|
81
81
|
`apiKey` is still accepted for compatibility with lower-level SDK examples.
|
|
82
82
|
|
|
83
|
-
Supplying `transport` enables the core SDK's bounded automatic delivery.
|
|
83
|
+
Supplying `transport` enables the core SDK's bounded automatic delivery. On
|
|
84
|
+
mobile it sends 5 seconds after the first queued event or at 50 queued events,
|
|
85
|
+
which saves battery and radio wakeups; set `deliveryIntervalMs` to change it. It
|
|
84
86
|
coalesces concurrent work, retries transient failures, retains rejected
|
|
85
87
|
batches, and pauses repeated automatic sends after authentication, rate-limit,
|
|
86
88
|
or non-retryable failures. Do not add a second app-owned flush interval.
|
|
@@ -160,7 +162,13 @@ The native queue stores one compact event per atomic record, is limited to
|
|
|
160
162
|
when you configure them on the client. Both platforms use app-private storage.
|
|
161
163
|
The client key is not written to disk; its SHA-256 digest separates queues
|
|
162
164
|
after key rotation. The queue does not provide mathematically exactly-once
|
|
163
|
-
delivery.
|
|
165
|
+
delivery. When the queue is full, a fatal JavaScript report removes the oldest
|
|
166
|
+
events that are not fatal and are not being sent, and counts each one as
|
|
167
|
+
`evicted_for_fatal` in `deliveryHealth().droppedByReason`. The fatal is dropped
|
|
168
|
+
only when the rest of the queue is fatal reports or a batch being sent.
|
|
169
|
+
Drop counts not yet reported to LogBrew are kept in a separate native queue,
|
|
170
|
+
so the next app start sends them, and a report that was already sent keeps
|
|
171
|
+
its `report_id` so LogBrew counts it once.
|
|
164
172
|
|
|
165
173
|
A successful `shutdown()` drains and closes the queue. A failed flush or
|
|
166
174
|
shutdown leaves the exact remainder available to the same client and the next
|
|
@@ -306,7 +314,9 @@ main-thread hangs.
|
|
|
306
314
|
Android diagnostics are opt-in and require a native build. They persist Java
|
|
307
315
|
crashes, one NDK fault frame, and main-thread hangs to the normal app-private
|
|
308
316
|
event queue. NDK evidence enters that queue on the next launch and remains
|
|
309
|
-
until queue admission succeeds.
|
|
317
|
+
until queue admission succeeds. A Java crash or hang report that finds the
|
|
318
|
+
queue full waits in a separate app-private pending store and enters the queue
|
|
319
|
+
when diagnostics are next installed with room. Native signal records retain the project,
|
|
310
320
|
release, environment, and service active at crash time, so an app update before
|
|
311
321
|
relaunch cannot reassign the crash to a newer build.
|
|
312
322
|
|
|
@@ -35,6 +35,8 @@ final class AndroidDiagnosticsRuntime implements Thread.UncaughtExceptionHandler
|
|
|
35
35
|
new AndroidNativeDiagnostics(
|
|
36
36
|
eventStore,
|
|
37
37
|
signalStore,
|
|
38
|
+
new EventRecordStore(
|
|
39
|
+
new File(storageRoot, "logbrew-android-pending-v1"), new AndroidParentDirectorySync()),
|
|
38
40
|
configuration,
|
|
39
41
|
scheduler,
|
|
40
42
|
afterPersist,
|
|
@@ -93,6 +93,7 @@ final class AndroidNativeDiagnostics {
|
|
|
93
93
|
|
|
94
94
|
final EventRecordStore eventStore;
|
|
95
95
|
final AndroidNativeSignalStore signalStore;
|
|
96
|
+
final EventRecordStore pendingStore;
|
|
96
97
|
final Configuration configuration;
|
|
97
98
|
private final Scheduler scheduler;
|
|
98
99
|
private final Runnable afterPersist;
|
|
@@ -105,6 +106,7 @@ final class AndroidNativeDiagnostics {
|
|
|
105
106
|
AndroidNativeDiagnostics(
|
|
106
107
|
EventRecordStore eventStore,
|
|
107
108
|
AndroidNativeSignalStore signalStore,
|
|
109
|
+
EventRecordStore pendingStore,
|
|
108
110
|
Configuration configuration,
|
|
109
111
|
Scheduler scheduler,
|
|
110
112
|
Runnable afterPersist,
|
|
@@ -113,6 +115,7 @@ final class AndroidNativeDiagnostics {
|
|
|
113
115
|
String applicationPackage) {
|
|
114
116
|
this.eventStore = eventStore;
|
|
115
117
|
this.signalStore = signalStore;
|
|
118
|
+
this.pendingStore = pendingStore;
|
|
116
119
|
this.configuration = configuration;
|
|
117
120
|
this.scheduler = scheduler;
|
|
118
121
|
this.afterPersist = afterPersist;
|
|
@@ -127,6 +130,7 @@ final class AndroidNativeDiagnostics {
|
|
|
127
130
|
return "already_installed";
|
|
128
131
|
}
|
|
129
132
|
replaySignalRecord();
|
|
133
|
+
replayPendingRecords();
|
|
130
134
|
scheduler.start(configuration.anrThresholdMs, this::reportHang);
|
|
131
135
|
installed = true;
|
|
132
136
|
return "installed";
|
|
@@ -144,7 +148,7 @@ final class AndroidNativeDiagnostics {
|
|
|
144
148
|
void handleUncaught(Thread thread, Throwable error) {
|
|
145
149
|
try {
|
|
146
150
|
if (!claimPersistedJavaScriptFatal(error, System.nanoTime())) {
|
|
147
|
-
|
|
151
|
+
appendOrKeepPending(javaCrashEvent(error));
|
|
148
152
|
}
|
|
149
153
|
} finally {
|
|
150
154
|
previousHandler.uncaughtException(thread, error);
|
|
@@ -157,7 +161,7 @@ final class AndroidNativeDiagnostics {
|
|
|
157
161
|
}
|
|
158
162
|
long boundedDuration =
|
|
159
163
|
Math.max(configuration.anrThresholdMs, Math.min(durationMs, 300_000));
|
|
160
|
-
|
|
164
|
+
appendOrKeepPending(hangEvent(mainFrames.get(), boundedDuration));
|
|
161
165
|
}
|
|
162
166
|
|
|
163
167
|
/** Notes a JavaScript fatal report that this process just persisted to the shared queue. */
|
|
@@ -198,6 +202,23 @@ final class AndroidNativeDiagnostics {
|
|
|
198
202
|
}
|
|
199
203
|
}
|
|
200
204
|
|
|
205
|
+
// A full or failing queue keeps the report in the pending store; the next install appends it.
|
|
206
|
+
private void appendOrKeepPending(String serializedEvent) {
|
|
207
|
+
if (!append(serializedEvent)) {
|
|
208
|
+
pendingStore.append(serializedEvent, serializedEvent.getBytes(StandardCharsets.UTF_8).length);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private void replayPendingRecords() {
|
|
213
|
+
EventRecordStore.Result pending = pendingStore.load();
|
|
214
|
+
int appended = 0;
|
|
215
|
+
while (appended < pending.records.size()
|
|
216
|
+
&& append(pending.records.get(appended).serializedEvent)) {
|
|
217
|
+
appended += 1;
|
|
218
|
+
}
|
|
219
|
+
pendingStore.acknowledge(appended);
|
|
220
|
+
}
|
|
221
|
+
|
|
201
222
|
private boolean append(String serializedEvent) {
|
|
202
223
|
int bytes = serializedEvent.getBytes(StandardCharsets.UTF_8).length;
|
|
203
224
|
EventRecordStore.Result result = eventStore.append(serializedEvent, bytes);
|
|
@@ -99,6 +99,31 @@ final class EventRecordStore {
|
|
|
99
99
|
return Result.status("acknowledged");
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
/** Deletes queued records at ascending load() positions so a fatal report can take their place. */
|
|
103
|
+
synchronized Result remove(int[] indexes) {
|
|
104
|
+
Snapshot snapshot = snapshot();
|
|
105
|
+
int previous = -1;
|
|
106
|
+
for (int index : indexes) {
|
|
107
|
+
if (snapshot == null || index <= previous || index >= snapshot.records.size()) {
|
|
108
|
+
return Result.status("storage_error");
|
|
109
|
+
}
|
|
110
|
+
previous = index;
|
|
111
|
+
}
|
|
112
|
+
for (int index : indexes) {
|
|
113
|
+
File recordFile = new File(directory, eventFileName(snapshot.records.get(index).sequence));
|
|
114
|
+
if (!isSafeRegularFile(recordFile) || !recordFile.delete()) {
|
|
115
|
+
// Earlier deletions may have committed; fail closed instead of diverging from the client.
|
|
116
|
+
poisoned = true;
|
|
117
|
+
return Result.status("storage_error");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (parentDirectorySync.sync(directory) == ParentDirectorySyncResult.FAILED) {
|
|
121
|
+
poisoned = true;
|
|
122
|
+
return Result.status("storage_error");
|
|
123
|
+
}
|
|
124
|
+
return Result.status("removed");
|
|
125
|
+
}
|
|
126
|
+
|
|
102
127
|
synchronized Result purge() {
|
|
103
128
|
if (poisoned || !prepareDirectory() || !removeStaleTemporaryFiles()) {
|
|
104
129
|
return Result.status("storage_error");
|
|
@@ -2,6 +2,7 @@ package co.logbrew.reactnative;
|
|
|
2
2
|
|
|
3
3
|
import com.facebook.react.bridge.Arguments;
|
|
4
4
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
5
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
5
6
|
import com.facebook.react.bridge.ReadableMap;
|
|
6
7
|
import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
|
7
8
|
import com.facebook.react.bridge.ReadableType;
|
|
@@ -97,6 +98,27 @@ final class FatalStoreModuleImpl {
|
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
WritableMap removeEventRecords(String queueKey, ReadableArray indexes) {
|
|
102
|
+
try {
|
|
103
|
+
EventRecordStore eventStore = eventStore(queueKey);
|
|
104
|
+
int[] recordIndexes = new int[indexes == null ? 0 : indexes.size()];
|
|
105
|
+
for (int position = 0; position < recordIndexes.length; position += 1) {
|
|
106
|
+
Integer index = indexes.getType(position) == ReadableType.Number
|
|
107
|
+
? integer(indexes.getDouble(position))
|
|
108
|
+
: null;
|
|
109
|
+
if (index == null) {
|
|
110
|
+
return status("storage_error");
|
|
111
|
+
}
|
|
112
|
+
recordIndexes[position] = index;
|
|
113
|
+
}
|
|
114
|
+
return eventStore == null || indexes == null
|
|
115
|
+
? status("storage_error")
|
|
116
|
+
: eventResultMap(eventStore.remove(recordIndexes));
|
|
117
|
+
} catch (RuntimeException error) {
|
|
118
|
+
return status("storage_error");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
100
122
|
WritableMap purgeEventRecords(String queueKey) {
|
|
101
123
|
try {
|
|
102
124
|
EventRecordStore eventStore = eventStore(queueKey);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package co.logbrew.reactnative;
|
|
2
2
|
|
|
3
3
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
4
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
4
5
|
import com.facebook.react.bridge.ReadableMap;
|
|
5
6
|
import com.facebook.react.bridge.WritableMap;
|
|
6
7
|
|
|
@@ -38,6 +39,11 @@ final class FatalStoreModule extends NativeLogBrewFatalStoreSpec {
|
|
|
38
39
|
return implementation.acknowledgeEventRecords(queueKey, count);
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
@Override
|
|
43
|
+
public WritableMap removeEventRecords(String queueKey, ReadableArray indexes) {
|
|
44
|
+
return implementation.removeEventRecords(queueKey, indexes);
|
|
45
|
+
}
|
|
46
|
+
|
|
41
47
|
@Override
|
|
42
48
|
public WritableMap purgeEventRecords(String queueKey) {
|
|
43
49
|
return implementation.purgeEventRecords(queueKey);
|
|
@@ -3,6 +3,7 @@ package co.logbrew.reactnative;
|
|
|
3
3
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
4
4
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
5
5
|
import com.facebook.react.bridge.ReactMethod;
|
|
6
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
6
7
|
import com.facebook.react.bridge.ReadableMap;
|
|
7
8
|
import com.facebook.react.bridge.WritableMap;
|
|
8
9
|
|
|
@@ -40,6 +41,11 @@ final class FatalStoreModule extends ReactContextBaseJavaModule {
|
|
|
40
41
|
return implementation.acknowledgeEventRecords(queueKey, count);
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
45
|
+
public WritableMap removeEventRecords(String queueKey, ReadableArray indexes) {
|
|
46
|
+
return implementation.removeEventRecords(queueKey, indexes);
|
|
47
|
+
}
|
|
48
|
+
|
|
43
49
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
44
50
|
public WritableMap purgeEventRecords(String queueKey) {
|
|
45
51
|
return implementation.purgeEventRecords(queueKey);
|
package/expo.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const PLUGIN_NAME = "@logbrew/react-native/expo";
|
|
2
2
|
const START_MARKER = " # @generated by @logbrew/react-native/expo";
|
|
3
3
|
const END_MARKER = " # @end @logbrew/react-native/expo";
|
|
4
|
-
const MANAGED_BLOCK = /
|
|
4
|
+
const MANAGED_BLOCK = / {2}# @generated by @logbrew\/react-native\/expo[\s\S]*? {2}# @end @logbrew\/react-native\/expo\n?/gu;
|
|
5
5
|
const POD_BLOCK = [
|
|
6
6
|
START_MARKER,
|
|
7
7
|
" require 'pathname'",
|
package/index.cjs
CHANGED
|
@@ -16,7 +16,7 @@ const {
|
|
|
16
16
|
} = require("./metadata.cjs");
|
|
17
17
|
|
|
18
18
|
const DEFAULT_SDK_NAME = "logbrew-react-native";
|
|
19
|
-
const DEFAULT_SDK_VERSION = "0.1.
|
|
19
|
+
const DEFAULT_SDK_VERSION = "0.1.37";
|
|
20
20
|
const DEFAULT_ENDPOINT = "https://api.logbrew.co/v1/events";
|
|
21
21
|
const NATIVE_RANDOM_HEX = Symbol.for("co.logbrew.react-native.secure-random-hex");
|
|
22
22
|
const MAX_ACTION_NAME_LENGTH = 64;
|
|
@@ -24,6 +24,8 @@ const MAX_PRODUCT_ANALYTICS_SURFACE_LENGTH = 256;
|
|
|
24
24
|
const SCREEN_ACTION_PREFIX = "screen:";
|
|
25
25
|
const LAST_ROUTE = Symbol.for("co.logbrew.react-native.last-route");
|
|
26
26
|
const BACKGROUND_APP_STATES = new Set(["background", "inactive"]);
|
|
27
|
+
// Mobile keeps a 5-second interval to save battery and radio wakeups; flushOnBackground sends the rest.
|
|
28
|
+
const DEFAULT_REACT_NATIVE_DELIVERY_INTERVAL_MS = 5000;
|
|
27
29
|
const LogBrewNativeContext = React.createContext(null);
|
|
28
30
|
const activeTraceScopes = [];
|
|
29
31
|
let nextTraceScopeId = 0;
|
|
@@ -54,7 +56,7 @@ function createLogBrewReactNativeClient({
|
|
|
54
56
|
apiKey: authKey,
|
|
55
57
|
automaticDelivery,
|
|
56
58
|
context,
|
|
57
|
-
deliveryIntervalMs,
|
|
59
|
+
deliveryIntervalMs: deliveryIntervalMs ?? DEFAULT_REACT_NATIVE_DELIVERY_INTERVAL_MS,
|
|
58
60
|
deliveryQueueThreshold,
|
|
59
61
|
eventStore,
|
|
60
62
|
maxBatchBytes,
|
package/index.d.cts
CHANGED
|
@@ -36,6 +36,7 @@ export type CreateLogBrewReactNativeClientConfig = {
|
|
|
36
36
|
apiKey?: string;
|
|
37
37
|
clientKey?: string;
|
|
38
38
|
context?: TelemetryContext;
|
|
39
|
+
/** Automatic delivery interval in milliseconds. Defaults to 5000 on mobile to save battery. */
|
|
39
40
|
deliveryIntervalMs?: number;
|
|
40
41
|
deliveryQueueThreshold?: number;
|
|
41
42
|
/** Advanced synchronous persistence seam. React Native apps normally use the native entry's persistentQueue mode. */
|
package/index.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export type CreateLogBrewReactNativeClientConfig = {
|
|
|
36
36
|
apiKey?: string;
|
|
37
37
|
clientKey?: string;
|
|
38
38
|
context?: TelemetryContext;
|
|
39
|
+
/** Automatic delivery interval in milliseconds. Defaults to 5000 on mobile to save battery. */
|
|
39
40
|
deliveryIntervalMs?: number;
|
|
40
41
|
deliveryQueueThreshold?: number;
|
|
41
42
|
/** Advanced synchronous persistence seam. React Native apps normally use the native entry's persistentQueue mode. */
|
package/instrumentation.cjs
CHANGED
|
@@ -332,7 +332,6 @@ function installGlobalFetchInstrumentation(client, {
|
|
|
332
332
|
});
|
|
333
333
|
}
|
|
334
334
|
|
|
335
|
-
/* eslint-disable no-invalid-this */
|
|
336
335
|
function installGlobalXMLHttpRequestInstrumentation(client, {
|
|
337
336
|
appState,
|
|
338
337
|
globalObject,
|
|
@@ -654,7 +653,6 @@ function utf8ByteLength(value) {
|
|
|
654
653
|
function errorName(error) {
|
|
655
654
|
return typeof error?.name === "string" && error.name.trim() !== "" ? error.name : "Error";
|
|
656
655
|
}
|
|
657
|
-
/* eslint-enable no-invalid-this */
|
|
658
656
|
|
|
659
657
|
module.exports = {
|
|
660
658
|
createLogBrewReactNativeInstrumentation,
|
|
@@ -3,7 +3,7 @@ import Foundation
|
|
|
3
3
|
@objc(LBRNAppleNativeDiagnostics)
|
|
4
4
|
public final class LBRNAppleNativeDiagnostics: NSObject, @unchecked Sendable {
|
|
5
5
|
private static let shared = LBRNAppleNativeDiagnostics()
|
|
6
|
-
private static let sdkVersion = "0.1.
|
|
6
|
+
private static let sdkVersion = "0.1.37"
|
|
7
7
|
|
|
8
8
|
private let lock = NSLock()
|
|
9
9
|
private let replayQueue = DispatchQueue(label: "co.logbrew.react-native.apple-diagnostics-replay")
|
|
@@ -21,6 +21,7 @@ typedef BOOL (^LBRNEventDirectoryPreparation)(NSURL *directoryURL);
|
|
|
21
21
|
- (NSDictionary *)appendSerializedEvent:(NSString *)serializedEvent
|
|
22
22
|
eventBytes:(NSNumber *)eventBytes;
|
|
23
23
|
- (NSDictionary *)acknowledgeRecordCount:(NSNumber *)count;
|
|
24
|
+
- (NSDictionary *)removeRecordsAtIndexes:(NSArray *)indexes;
|
|
24
25
|
- (NSDictionary *)purgeRecords;
|
|
25
26
|
- (NSDictionary *)closeStore;
|
|
26
27
|
|
|
@@ -148,6 +148,49 @@ static const NSInteger LBRNEventFileSchemaVersion = 1;
|
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
- (NSDictionary *)removeRecordsAtIndexes:(NSArray *)indexes
|
|
152
|
+
{
|
|
153
|
+
@synchronized(self) {
|
|
154
|
+
if (self.poisoned || ![indexes isKindOfClass:[NSArray class]]) {
|
|
155
|
+
return [self storageError];
|
|
156
|
+
}
|
|
157
|
+
int directoryFD = [self openPreparedDirectory];
|
|
158
|
+
if (directoryFD < 0) {
|
|
159
|
+
return [self storageError];
|
|
160
|
+
}
|
|
161
|
+
@try {
|
|
162
|
+
NSArray *records = [self snapshotFromDirectory:directoryFD][@"records"];
|
|
163
|
+
NSMutableArray<NSString *> *filenames = [NSMutableArray array];
|
|
164
|
+
NSInteger previous = -1;
|
|
165
|
+
for (id index in indexes) {
|
|
166
|
+
NSUInteger recordIndex = 0;
|
|
167
|
+
if (records == nil || ![index isKindOfClass:[NSNumber class]]
|
|
168
|
+
|| ![self nonnegativeInteger:index output:&recordIndex]
|
|
169
|
+
|| recordIndex >= records.count || (NSInteger)recordIndex <= previous) {
|
|
170
|
+
return [self storageError];
|
|
171
|
+
}
|
|
172
|
+
previous = (NSInteger)recordIndex;
|
|
173
|
+
[filenames addObject:[self recordFilename:[records[recordIndex][@"sequence"] unsignedLongLongValue]]];
|
|
174
|
+
}
|
|
175
|
+
for (NSString *filename in filenames) {
|
|
176
|
+
if (![self safeRegularFilename:filename directoryFD:directoryFD]
|
|
177
|
+
|| unlinkat(directoryFD, filename.UTF8String, 0) != 0) {
|
|
178
|
+
// Earlier deletions may have committed; fail closed instead of diverging.
|
|
179
|
+
self.poisoned = YES;
|
|
180
|
+
return [self storageError];
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (![self synchronizeDirectory:directoryFD]) {
|
|
184
|
+
self.poisoned = YES;
|
|
185
|
+
return [self storageError];
|
|
186
|
+
}
|
|
187
|
+
return @{ @"status" : @"removed" };
|
|
188
|
+
} @finally {
|
|
189
|
+
close(directoryFD);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
151
194
|
- (NSDictionary *)purgeRecords
|
|
152
195
|
{
|
|
153
196
|
@synchronized(self) {
|
|
@@ -177,6 +177,20 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(acknowledgeEventRecords:(NSString *)queue
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(removeEventRecords:(NSString *)queueKey
|
|
181
|
+
indexes:(NSArray *)indexes)
|
|
182
|
+
{
|
|
183
|
+
LBRNEventRecordStore *eventStore = [self eventStoreForQueueKey:queueKey];
|
|
184
|
+
if (eventStore == nil) {
|
|
185
|
+
return LBRNStorageError();
|
|
186
|
+
}
|
|
187
|
+
@try {
|
|
188
|
+
return [eventStore removeRecordsAtIndexes:indexes];
|
|
189
|
+
} @catch (__unused NSException *exception) {
|
|
190
|
+
return LBRNStorageError();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
180
194
|
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(purgeEventRecords:(NSString *)queueKey)
|
|
181
195
|
{
|
|
182
196
|
LBRNEventRecordStore *eventStore = [self eventStoreForQueueKey:queueKey];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logbrew/react-native",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.37",
|
|
4
4
|
"description": "React Native offline delivery, native diagnostics, screen, error, trace, action, and network timeline helpers for LogBrew.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.cjs",
|
|
@@ -252,7 +252,7 @@
|
|
|
252
252
|
"url": "git+https://github.com/LogBrewCo/sdk.git"
|
|
253
253
|
},
|
|
254
254
|
"peerDependencies": {
|
|
255
|
-
"@logbrew/sdk": "^0.1.
|
|
255
|
+
"@logbrew/sdk": "^0.1.33",
|
|
256
256
|
"expo": ">=49",
|
|
257
257
|
"react": ">=18",
|
|
258
258
|
"react-native": ">=0.72"
|
|
@@ -12,6 +12,8 @@ const NATIVE_STORE_METHODS = [
|
|
|
12
12
|
"purgeEventRecords"
|
|
13
13
|
];
|
|
14
14
|
const PERSISTENT_QUEUE_MODES = new Set(["auto", "disabled", "required"]);
|
|
15
|
+
// Drop counts live in a separate native queue, so existing native binaries keep them without changes.
|
|
16
|
+
const CLIENT_REPORT_QUEUE_SUFFIX = ":client-report";
|
|
15
17
|
|
|
16
18
|
export function resolveReactNativePersistentEventStore({
|
|
17
19
|
authKey,
|
|
@@ -122,7 +124,8 @@ export function purgeReactNativePersistentQueue({ apiKey, clientKey } = {}) {
|
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
function createNativeEventStore(nativeStore, authKey, release) {
|
|
125
|
-
|
|
127
|
+
const reportKey = `${authKey}${CLIENT_REPORT_QUEUE_SUFFIX}`;
|
|
128
|
+
const eventStore = {
|
|
126
129
|
load() {
|
|
127
130
|
const result = requireStatus(
|
|
128
131
|
"load",
|
|
@@ -181,7 +184,42 @@ function createNativeEventStore(nativeStore, authKey, release) {
|
|
|
181
184
|
"purged"
|
|
182
185
|
);
|
|
183
186
|
},
|
|
187
|
+
// Appends the new state before acknowledging the old one, so a crash keeps one of them.
|
|
188
|
+
loadClientReport() {
|
|
189
|
+
const { records } = requireStatus(
|
|
190
|
+
"load",
|
|
191
|
+
callNative(nativeStore, "loadEventRecords", reportKey),
|
|
192
|
+
"loaded"
|
|
193
|
+
);
|
|
194
|
+
const latest = Array.isArray(records) ? records.at(-1)?.serializedEvent : undefined;
|
|
195
|
+
return typeof latest === "string" ? JSON.parse(latest) : undefined;
|
|
196
|
+
},
|
|
197
|
+
saveClientReport(state) {
|
|
198
|
+
const { records } = requireStatus(
|
|
199
|
+
"load",
|
|
200
|
+
callNative(nativeStore, "loadEventRecords", reportKey),
|
|
201
|
+
"loaded"
|
|
202
|
+
);
|
|
203
|
+
const serialized = JSON.stringify(state);
|
|
204
|
+
requireStatus(
|
|
205
|
+
"append",
|
|
206
|
+
callNative(nativeStore, "appendEventRecord", reportKey, serialized, serialized.length),
|
|
207
|
+
"appended"
|
|
208
|
+
);
|
|
209
|
+
if (Array.isArray(records) && records.length > 0) {
|
|
210
|
+
requireStatus(
|
|
211
|
+
"acknowledge",
|
|
212
|
+
callNative(nativeStore, "acknowledgeEventRecords", reportKey, records.length),
|
|
213
|
+
"acknowledged"
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
},
|
|
184
217
|
close() {
|
|
218
|
+
try {
|
|
219
|
+
callNative(nativeStore, "closeEventStore", reportKey);
|
|
220
|
+
} catch {
|
|
221
|
+
// The drop-count queue is advisory; closing the event queue decides the outcome.
|
|
222
|
+
}
|
|
185
223
|
try {
|
|
186
224
|
requireStatus(
|
|
187
225
|
"close",
|
|
@@ -193,6 +231,15 @@ function createNativeEventStore(nativeStore, authKey, release) {
|
|
|
193
231
|
}
|
|
194
232
|
}
|
|
195
233
|
};
|
|
234
|
+
// Older native binaries lack removal; the core then drops a fatal at a full queue.
|
|
235
|
+
if (typeof nativeStore.removeEventRecords === "function") {
|
|
236
|
+
eventStore.remove = (indexes) => requireStatus(
|
|
237
|
+
"remove",
|
|
238
|
+
callNative(nativeStore, "removeEventRecords", authKey, indexes),
|
|
239
|
+
"removed"
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
return eventStore;
|
|
196
243
|
}
|
|
197
244
|
|
|
198
245
|
function defaultNativeStore() {
|
|
@@ -266,6 +313,8 @@ function methodName(method) {
|
|
|
266
313
|
return "append";
|
|
267
314
|
case "acknowledgeEventRecords":
|
|
268
315
|
return "acknowledge";
|
|
316
|
+
case "removeEventRecords":
|
|
317
|
+
return "remove";
|
|
269
318
|
case "purgeEventRecords":
|
|
270
319
|
return "purge";
|
|
271
320
|
case "closeEventStore":
|
|
@@ -10,6 +10,10 @@ export interface Spec extends TurboModule {
|
|
|
10
10
|
eventBytes: number
|
|
11
11
|
): CodegenTypes.UnsafeObject;
|
|
12
12
|
acknowledgeEventRecords(queueKey: string, count: number): CodegenTypes.UnsafeObject;
|
|
13
|
+
removeEventRecords(
|
|
14
|
+
queueKey: string,
|
|
15
|
+
indexes: ReadonlyArray<number>
|
|
16
|
+
): CodegenTypes.UnsafeObject;
|
|
13
17
|
purgeEventRecords(queueKey: string): CodegenTypes.UnsafeObject;
|
|
14
18
|
closeEventStore(queueKey: string): CodegenTypes.UnsafeObject;
|
|
15
19
|
installAndroidDiagnostics(
|