@logbrew/react-native 0.1.38 → 0.1.40
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/LogBrewReactNative.podspec +1 -1
- package/README.md +17 -15
- package/android-native-diagnostics.d.ts +15 -5
- package/android-native-diagnostics.js +170 -94
- package/apollo.cjs +435 -226
- package/apollo.d.cts +2 -70
- package/apollo.d.ts +24 -12
- package/apollo.js +438 -221
- package/apple-native-diagnostics-config.js +176 -0
- package/apple-native-diagnostics-context.js +232 -0
- package/apple-native-diagnostics-module.js +229 -0
- package/apple-native-diagnostics.d.ts +42 -11
- package/apple-native-diagnostics.js +60 -389
- package/expo.cjs +29 -16
- package/expo.d.ts +10 -9
- package/expo.js +4 -3
- package/fatal-admission.cjs +113 -0
- package/fatal-record.cjs +317 -0
- package/fatal-replay.cjs +297 -508
- package/global-errors-capture.cjs +369 -0
- package/global-errors-event.cjs +174 -0
- package/global-errors-support.cjs +128 -0
- package/global-errors.cjs +75 -351
- package/global-errors.d.cts +29 -278
- package/global-errors.d.ts +57 -27
- package/global-errors.js +7 -2
- package/global-errors.native.js +83 -48
- package/index-breadcrumbs.cjs +139 -0
- package/index-errors.cjs +167 -0
- package/index-events.cjs +365 -0
- package/index-navigation.cjs +327 -0
- package/index-random.cjs +120 -0
- package/index-react.cjs +189 -0
- package/index-spans.cjs +190 -0
- package/index-trace-fetch.cjs +322 -0
- package/index-trace.cjs +335 -0
- package/index-transport.cjs +201 -0
- package/index-values.cjs +232 -0
- package/index.cjs +95 -1220
- package/index.d.cts +2 -505
- package/index.d.ts +130 -469
- package/index.native.d.ts +146 -22
- package/index.native.js +184 -159
- package/instrumentation-fetch.cjs +113 -0
- package/instrumentation-install.cjs +241 -0
- package/instrumentation-runtime.cjs +65 -0
- package/instrumentation-teardown.cjs +93 -0
- package/instrumentation-values.cjs +282 -0
- package/instrumentation-xhr-request.cjs +298 -0
- package/instrumentation-xhr.cjs +233 -0
- package/instrumentation.cjs +110 -599
- package/instrumentation.d.cts +2 -84
- package/instrumentation.d.ts +22 -8
- package/ios/AppleDiagnostics/LBRNAppleNativeDiagnostics.swift +1 -1
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngine.swift +7 -1
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineAutomatic.swift +36 -4
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineQueue.swift +17 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryLifecycle.swift +2 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/Transport.swift +41 -6
- package/ios/GeneratedAppleDiagnostics/SOURCE-MANIFEST.json +5 -5
- package/lifecycle.cjs +181 -78
- package/lifecycle.d.cts +1 -50
- package/lifecycle.d.ts +17 -6
- package/metadata.cjs +279 -114
- package/metro-debug-id.cjs +296 -0
- package/metro-serializer.cjs +219 -0
- package/metro.cjs +153 -297
- package/metro.d.cts +2 -57
- package/metro.d.ts +27 -13
- package/metro.js +2 -3
- package/native-bridge-async.cjs +165 -0
- package/native-bridge-scope.cjs +148 -0
- package/native-bridge.cjs +83 -186
- package/native-bridge.d.cts +2 -94
- package/native-bridge.d.ts +28 -15
- package/native-client-bindings.js +230 -0
- package/native-diagnostics-values.js +120 -0
- package/native-module-lookup.js +31 -0
- package/native-null.js +3 -0
- package/null-value.cjs +4 -0
- package/package.json +44 -2
- package/persistent-delivery-store.js +247 -0
- package/persistent-delivery.native.js +183 -261
- package/promise-rejection-handlers.cjs +368 -0
- package/promise-rejections.cjs +169 -361
- package/react-native.config.js +3 -1
- package/release-artifacts-files.cjs +94 -0
- package/release-artifacts-options.cjs +182 -0
- package/release-artifacts.cjs +278 -207
- package/release-artifacts.d.cts +2 -55
- package/release-artifacts.d.ts +18 -7
- package/release-artifacts.js +2 -4
- package/resource-fetch-graphql.cjs +265 -0
- package/resource-fetch-size.cjs +156 -0
- package/resource-fetch.cjs +227 -428
- package/resource-fetch.d.cts +1 -60
- package/resource-fetch.d.ts +17 -6
- package/scripts/sync-apple-native-sources.mjs +101 -53
- package/types/capture.d.ts +95 -0
- package/types/config.d.ts +85 -0
- package/types/defaults.d.ts +55 -0
- package/types/events.d.ts +203 -0
- package/types/provider.d.ts +81 -0
- package/types/trace.d.ts +104 -0
|
@@ -1,9 +1,25 @@
|
|
|
1
|
+
import { callNative, createNativeEventStore, requireStatus } from "./persistent-delivery-store.js";
|
|
1
2
|
import { SdkError } from "@logbrew/sdk";
|
|
2
|
-
import {
|
|
3
|
+
import { lookupNativeModule } from "./native-module-lookup.js";
|
|
4
|
+
import { readField } from "./native-diagnostics-values.js";
|
|
3
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {{ durable: boolean, eventStore: unknown, abort: () => void, release: () => void }} ResolvedEventStore
|
|
8
|
+
* @typedef {Readonly<{
|
|
9
|
+
* authKey: string,
|
|
10
|
+
* eventStore?: unknown,
|
|
11
|
+
* hasExplicitPersistentQueue?: boolean,
|
|
12
|
+
* maxQueueBytes?: unknown,
|
|
13
|
+
* maxQueueSize?: unknown,
|
|
14
|
+
* persistentQueue?: unknown
|
|
15
|
+
* }>} PersistentEventStoreOptions
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** @type {Set<string>} */
|
|
4
19
|
const ACTIVE_QUEUE_KEYS = new Set();
|
|
5
|
-
const MAX_NATIVE_QUEUE_BYTES =
|
|
20
|
+
const MAX_NATIVE_QUEUE_BYTES = 4_194_304;
|
|
6
21
|
const MAX_NATIVE_QUEUE_EVENTS = 1000;
|
|
22
|
+
const MIN_QUEUE_LIMIT = 0;
|
|
7
23
|
const NATIVE_STORE_METHODS = [
|
|
8
24
|
"acknowledgeEventRecords",
|
|
9
25
|
"appendEventRecord",
|
|
@@ -11,62 +27,109 @@ const NATIVE_STORE_METHODS = [
|
|
|
11
27
|
"loadEventRecords",
|
|
12
28
|
"purgeEventRecords"
|
|
13
29
|
];
|
|
30
|
+
/** @type {ReadonlySet<unknown>} */
|
|
14
31
|
const PERSISTENT_QUEUE_MODES = new Set(["auto", "disabled", "required"]);
|
|
15
|
-
|
|
16
|
-
const CLIENT_REPORT_QUEUE_SUFFIX = ":client-report";
|
|
32
|
+
const UNAVAILABLE_NATIVE_QUEUE = "React Native persistent queue requires the linked LogBrew native module";
|
|
17
33
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
throw new SdkError(
|
|
30
|
-
"configuration_error",
|
|
31
|
-
"eventStore and persistentQueue are mutually exclusive"
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
return { eventStore, durable: false, abort() {}, release() {} };
|
|
34
|
+
/**
|
|
35
|
+
* @returns {unknown}
|
|
36
|
+
*/
|
|
37
|
+
function defaultNativeStore() {
|
|
38
|
+
try {
|
|
39
|
+
const nativeStore = lookupNativeModule("LogBrewFatalStore");
|
|
40
|
+
return NATIVE_STORE_METHODS.every(method => typeof readField(nativeStore, method) === "function")
|
|
41
|
+
? nativeStore
|
|
42
|
+
: undefined;
|
|
43
|
+
} catch {
|
|
44
|
+
return undefined;
|
|
35
45
|
}
|
|
36
|
-
|
|
37
|
-
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {unknown} limit
|
|
50
|
+
* @param {number} maximum
|
|
51
|
+
* @returns {boolean}
|
|
52
|
+
*/
|
|
53
|
+
function isValidQueueLimit(limit, maximum) {
|
|
54
|
+
return limit === undefined
|
|
55
|
+
|| (typeof limit === "number" && Number.isSafeInteger(limit) && limit > MIN_QUEUE_LIMIT && limit <= maximum);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param {unknown} maxQueueBytes
|
|
60
|
+
* @param {unknown} maxQueueSize
|
|
61
|
+
*/
|
|
62
|
+
function validateNativeQueueLimits(maxQueueBytes, maxQueueSize) {
|
|
63
|
+
if (!isValidQueueLimit(maxQueueBytes, MAX_NATIVE_QUEUE_BYTES)) {
|
|
64
|
+
throw new SdkError(
|
|
65
|
+
"configuration_error",
|
|
66
|
+
`persistent React Native maxQueueBytes must be at most ${MAX_NATIVE_QUEUE_BYTES}`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
if (!isValidQueueLimit(maxQueueSize, MAX_NATIVE_QUEUE_EVENTS)) {
|
|
70
|
+
throw new SdkError(
|
|
71
|
+
"configuration_error",
|
|
72
|
+
`persistent React Native maxQueueSize must be at most ${MAX_NATIVE_QUEUE_EVENTS}`
|
|
73
|
+
);
|
|
38
74
|
}
|
|
75
|
+
}
|
|
39
76
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
77
|
+
/**
|
|
78
|
+
* @param {unknown} mode
|
|
79
|
+
*/
|
|
80
|
+
function validatePersistentQueueMode(mode) {
|
|
81
|
+
if (!PERSISTENT_QUEUE_MODES.has(mode)) {
|
|
82
|
+
throw new SdkError(
|
|
83
|
+
"configuration_error",
|
|
84
|
+
"persistentQueue must be auto, required, or disabled"
|
|
85
|
+
);
|
|
49
86
|
}
|
|
50
|
-
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @param {unknown} eventStore
|
|
91
|
+
* @returns {ResolvedEventStore}
|
|
92
|
+
*/
|
|
93
|
+
function memoryEventStore(eventStore) {
|
|
94
|
+
return {
|
|
95
|
+
eventStore,
|
|
96
|
+
|
|
97
|
+
durable: false,
|
|
98
|
+
|
|
99
|
+
abort() {
|
|
100
|
+
return undefined;
|
|
101
|
+
},
|
|
102
|
+
release() {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @param {unknown} nativeStore
|
|
110
|
+
* @param {string} authKey
|
|
111
|
+
* @returns {ResolvedEventStore}
|
|
112
|
+
*/
|
|
113
|
+
function durableEventStore(nativeStore, authKey) {
|
|
51
114
|
if (ACTIVE_QUEUE_KEYS.has(authKey)) {
|
|
52
115
|
throw new SdkError(
|
|
53
116
|
"configuration_error",
|
|
54
117
|
"React Native persistent queue already has an active client for this key"
|
|
55
118
|
);
|
|
56
119
|
}
|
|
57
|
-
|
|
58
120
|
ACTIVE_QUEUE_KEYS.add(authKey);
|
|
59
121
|
let released = false;
|
|
60
|
-
|
|
122
|
+
function release() {
|
|
61
123
|
if (!released) {
|
|
62
124
|
released = true;
|
|
63
125
|
ACTIVE_QUEUE_KEYS.delete(authKey);
|
|
64
126
|
}
|
|
65
|
-
}
|
|
127
|
+
}
|
|
66
128
|
const nativeEventStore = createNativeEventStore(nativeStore, authKey, release);
|
|
67
129
|
return {
|
|
68
130
|
durable: true,
|
|
69
131
|
eventStore: nativeEventStore,
|
|
132
|
+
|
|
70
133
|
abort() {
|
|
71
134
|
try {
|
|
72
135
|
nativeEventStore.close();
|
|
@@ -78,255 +141,114 @@ export function resolveReactNativePersistentEventStore({
|
|
|
78
141
|
};
|
|
79
142
|
}
|
|
80
143
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
if (ACTIVE_QUEUE_KEYS.has(authKey)) {
|
|
90
|
-
throw new SdkError(
|
|
91
|
-
"persistence_error",
|
|
92
|
-
"cannot purge a React Native persistent queue while its client is active"
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
const nativeStore = defaultNativeStore();
|
|
96
|
-
if (!nativeStore) {
|
|
144
|
+
/**
|
|
145
|
+
* @param {unknown} eventStore
|
|
146
|
+
* @param {boolean} hasExplicitPersistentQueue
|
|
147
|
+
* @returns {ResolvedEventStore}
|
|
148
|
+
*/
|
|
149
|
+
function explicitEventStore(eventStore, hasExplicitPersistentQueue) {
|
|
150
|
+
if (hasExplicitPersistentQueue) {
|
|
97
151
|
throw new SdkError(
|
|
98
152
|
"configuration_error",
|
|
99
|
-
"
|
|
153
|
+
"eventStore and persistentQueue are mutually exclusive"
|
|
100
154
|
);
|
|
101
155
|
}
|
|
102
|
-
|
|
103
|
-
try {
|
|
104
|
-
requireStatus(
|
|
105
|
-
"purge",
|
|
106
|
-
callNative(nativeStore, "purgeEventRecords", authKey),
|
|
107
|
-
"purged"
|
|
108
|
-
);
|
|
109
|
-
} catch (error) {
|
|
110
|
-
failure = error;
|
|
111
|
-
}
|
|
112
|
-
try {
|
|
113
|
-
requireStatus(
|
|
114
|
-
"close",
|
|
115
|
-
callNative(nativeStore, "closeEventStore", authKey),
|
|
116
|
-
"closed"
|
|
117
|
-
);
|
|
118
|
-
} catch (error) {
|
|
119
|
-
failure ??= error;
|
|
120
|
-
}
|
|
121
|
-
if (failure) {
|
|
122
|
-
throw failure;
|
|
123
|
-
}
|
|
156
|
+
return memoryEventStore(eventStore);
|
|
124
157
|
}
|
|
125
158
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (!Array.isArray(result.records)) {
|
|
136
|
-
throw persistenceFailure("load");
|
|
137
|
-
}
|
|
138
|
-
return result.records.map((record) => {
|
|
139
|
-
if (!record
|
|
140
|
-
|| Array.isArray(record)
|
|
141
|
-
|| typeof record !== "object"
|
|
142
|
-
|| typeof record.serializedEvent !== "string"
|
|
143
|
-
|| !Number.isSafeInteger(record.eventBytes)
|
|
144
|
-
|| record.eventBytes <= 0) {
|
|
145
|
-
throw persistenceFailure("load");
|
|
146
|
-
}
|
|
147
|
-
let event;
|
|
148
|
-
try {
|
|
149
|
-
event = JSON.parse(record.serializedEvent);
|
|
150
|
-
} catch {
|
|
151
|
-
throw persistenceFailure("load");
|
|
152
|
-
}
|
|
153
|
-
return {
|
|
154
|
-
event,
|
|
155
|
-
eventBytes: record.eventBytes,
|
|
156
|
-
serializedEvent: record.serializedEvent
|
|
157
|
-
};
|
|
158
|
-
});
|
|
159
|
-
},
|
|
160
|
-
append(record) {
|
|
161
|
-
requireStatus(
|
|
162
|
-
"append",
|
|
163
|
-
callNative(
|
|
164
|
-
nativeStore,
|
|
165
|
-
"appendEventRecord",
|
|
166
|
-
authKey,
|
|
167
|
-
record.serializedEvent,
|
|
168
|
-
record.eventBytes
|
|
169
|
-
),
|
|
170
|
-
"appended"
|
|
171
|
-
);
|
|
172
|
-
},
|
|
173
|
-
acknowledge(count) {
|
|
174
|
-
requireStatus(
|
|
175
|
-
"acknowledge",
|
|
176
|
-
callNative(nativeStore, "acknowledgeEventRecords", authKey, count),
|
|
177
|
-
"acknowledged"
|
|
178
|
-
);
|
|
179
|
-
},
|
|
180
|
-
purge() {
|
|
181
|
-
requireStatus(
|
|
182
|
-
"purge",
|
|
183
|
-
callNative(nativeStore, "purgeEventRecords", authKey),
|
|
184
|
-
"purged"
|
|
185
|
-
);
|
|
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
|
-
},
|
|
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
|
-
}
|
|
223
|
-
try {
|
|
224
|
-
requireStatus(
|
|
225
|
-
"close",
|
|
226
|
-
callNative(nativeStore, "closeEventStore", authKey),
|
|
227
|
-
"closed"
|
|
228
|
-
);
|
|
229
|
-
} finally {
|
|
230
|
-
release();
|
|
231
|
-
}
|
|
232
|
-
}
|
|
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;
|
|
159
|
+
/**
|
|
160
|
+
* @param {unknown} persistentQueue
|
|
161
|
+
* @returns {ResolvedEventStore}
|
|
162
|
+
*/
|
|
163
|
+
function unavailableEventStore(persistentQueue) {
|
|
164
|
+
if (persistentQueue === "required") {
|
|
165
|
+
throw new SdkError("configuration_error", UNAVAILABLE_NATIVE_QUEUE);
|
|
166
|
+
}
|
|
167
|
+
return memoryEventStore(undefined);
|
|
243
168
|
}
|
|
244
169
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
170
|
+
/**
|
|
171
|
+
* @param {PersistentEventStoreOptions} options
|
|
172
|
+
* @returns {ResolvedEventStore}
|
|
173
|
+
*/
|
|
174
|
+
function resolveReactNativePersistentEventStore({
|
|
175
|
+
authKey,
|
|
176
|
+
eventStore,
|
|
177
|
+
hasExplicitPersistentQueue = false,
|
|
178
|
+
maxQueueBytes,
|
|
179
|
+
maxQueueSize,
|
|
180
|
+
persistentQueue = "auto"
|
|
181
|
+
}) {
|
|
182
|
+
validatePersistentQueueMode(persistentQueue);
|
|
183
|
+
if (eventStore !== undefined) {
|
|
184
|
+
return explicitEventStore(eventStore, hasExplicitPersistentQueue);
|
|
185
|
+
}
|
|
186
|
+
if (persistentQueue === "disabled") {
|
|
187
|
+
return memoryEventStore(undefined);
|
|
254
188
|
}
|
|
189
|
+
const nativeStore = defaultNativeStore();
|
|
190
|
+
if (nativeStore === undefined) {
|
|
191
|
+
return unavailableEventStore(persistentQueue);
|
|
192
|
+
}
|
|
193
|
+
validateNativeQueueLimits(maxQueueBytes, maxQueueSize);
|
|
194
|
+
return durableEventStore(nativeStore, authKey);
|
|
255
195
|
}
|
|
256
196
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
"configuration_error",
|
|
264
|
-
`persistent React Native maxQueueBytes must be at most ${MAX_NATIVE_QUEUE_BYTES}`
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
if (maxQueueSize !== undefined
|
|
268
|
-
&& (!Number.isSafeInteger(maxQueueSize)
|
|
269
|
-
|| maxQueueSize <= 0
|
|
270
|
-
|| maxQueueSize > MAX_NATIVE_QUEUE_EVENTS)) {
|
|
197
|
+
/**
|
|
198
|
+
* @param {unknown} authKey
|
|
199
|
+
* @returns {string}
|
|
200
|
+
*/
|
|
201
|
+
function purgeAuthKey(authKey) {
|
|
202
|
+
if (typeof authKey !== "string" || authKey.trim() === "") {
|
|
271
203
|
throw new SdkError(
|
|
272
204
|
"configuration_error",
|
|
273
|
-
|
|
205
|
+
"purgeLogBrewReactNativePersistentQueue requires clientKey or apiKey"
|
|
274
206
|
);
|
|
275
207
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
function validatePersistentQueueMode(mode) {
|
|
279
|
-
if (!PERSISTENT_QUEUE_MODES.has(mode)) {
|
|
208
|
+
if (ACTIVE_QUEUE_KEYS.has(authKey)) {
|
|
280
209
|
throw new SdkError(
|
|
281
|
-
"
|
|
282
|
-
"
|
|
210
|
+
"persistence_error",
|
|
211
|
+
"cannot purge a React Native persistent queue while its client is active"
|
|
283
212
|
);
|
|
284
213
|
}
|
|
214
|
+
return authKey;
|
|
285
215
|
}
|
|
286
216
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
217
|
+
/**
|
|
218
|
+
* @param {() => void} operation
|
|
219
|
+
* @returns {Error | undefined}
|
|
220
|
+
*/
|
|
221
|
+
function failureOf(operation) {
|
|
291
222
|
try {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
if (!result
|
|
300
|
-
|| Array.isArray(result)
|
|
301
|
-
|| typeof result !== "object"
|
|
302
|
-
|| result.status !== expected) {
|
|
303
|
-
throw persistenceFailure(operation);
|
|
223
|
+
operation();
|
|
224
|
+
return undefined;
|
|
225
|
+
} catch (error) {
|
|
226
|
+
if (error instanceof Error) {
|
|
227
|
+
return error;
|
|
228
|
+
}
|
|
229
|
+
throw error;
|
|
304
230
|
}
|
|
305
|
-
return result;
|
|
306
231
|
}
|
|
307
232
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
233
|
+
/**
|
|
234
|
+
* @param {Readonly<{ apiKey?: unknown, clientKey?: unknown }>} [config]
|
|
235
|
+
*/
|
|
236
|
+
function purgeReactNativePersistentQueue({ apiKey, clientKey } = {}) {
|
|
237
|
+
const authKey = purgeAuthKey(clientKey ?? apiKey);
|
|
238
|
+
const nativeStore = defaultNativeStore();
|
|
239
|
+
if (nativeStore === undefined) {
|
|
240
|
+
throw new SdkError("configuration_error", UNAVAILABLE_NATIVE_QUEUE);
|
|
241
|
+
}
|
|
242
|
+
const purged = failureOf(() => {
|
|
243
|
+
requireStatus("purge", callNative(nativeStore, "purgeEventRecords", authKey), "purged");
|
|
244
|
+
});
|
|
245
|
+
const closed = failureOf(() => {
|
|
246
|
+
requireStatus("close", callNative(nativeStore, "closeEventStore", authKey), "closed");
|
|
247
|
+
});
|
|
248
|
+
const failure = purged ?? closed;
|
|
249
|
+
if (failure !== undefined) {
|
|
250
|
+
throw failure;
|
|
324
251
|
}
|
|
325
252
|
}
|
|
326
253
|
|
|
327
|
-
|
|
328
|
-
return new SdkError(
|
|
329
|
-
"persistence_error",
|
|
330
|
-
`React Native persistent queue ${operation} failed`
|
|
331
|
-
);
|
|
332
|
-
}
|
|
254
|
+
export { purgeReactNativePersistentQueue, resolveReactNativePersistentEventStore };
|