@logbrew/react-native 0.1.39 → 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.
Files changed (96) hide show
  1. package/android-native-diagnostics.d.ts +15 -5
  2. package/android-native-diagnostics.js +170 -94
  3. package/apollo.cjs +435 -226
  4. package/apollo.d.cts +2 -70
  5. package/apollo.d.ts +24 -12
  6. package/apollo.js +438 -221
  7. package/apple-native-diagnostics-config.js +176 -0
  8. package/apple-native-diagnostics-context.js +232 -0
  9. package/apple-native-diagnostics-module.js +229 -0
  10. package/apple-native-diagnostics.d.ts +42 -11
  11. package/apple-native-diagnostics.js +60 -389
  12. package/expo.cjs +29 -16
  13. package/expo.d.ts +10 -9
  14. package/expo.js +4 -3
  15. package/fatal-admission.cjs +113 -0
  16. package/fatal-record.cjs +317 -0
  17. package/fatal-replay.cjs +297 -508
  18. package/global-errors-capture.cjs +369 -0
  19. package/global-errors-event.cjs +174 -0
  20. package/global-errors-support.cjs +128 -0
  21. package/global-errors.cjs +75 -351
  22. package/global-errors.d.cts +29 -278
  23. package/global-errors.d.ts +57 -27
  24. package/global-errors.js +7 -2
  25. package/global-errors.native.js +83 -48
  26. package/index-breadcrumbs.cjs +139 -0
  27. package/index-errors.cjs +167 -0
  28. package/index-events.cjs +365 -0
  29. package/index-navigation.cjs +327 -0
  30. package/index-random.cjs +120 -0
  31. package/index-react.cjs +189 -0
  32. package/index-spans.cjs +190 -0
  33. package/index-trace-fetch.cjs +322 -0
  34. package/index-trace.cjs +335 -0
  35. package/index-transport.cjs +201 -0
  36. package/index-values.cjs +232 -0
  37. package/index.cjs +95 -1243
  38. package/index.d.cts +2 -505
  39. package/index.d.ts +130 -469
  40. package/index.native.d.ts +146 -22
  41. package/index.native.js +184 -159
  42. package/instrumentation-fetch.cjs +113 -0
  43. package/instrumentation-install.cjs +241 -0
  44. package/instrumentation-runtime.cjs +65 -0
  45. package/instrumentation-teardown.cjs +93 -0
  46. package/instrumentation-values.cjs +282 -0
  47. package/instrumentation-xhr-request.cjs +298 -0
  48. package/instrumentation-xhr.cjs +233 -0
  49. package/instrumentation.cjs +110 -599
  50. package/instrumentation.d.cts +2 -84
  51. package/instrumentation.d.ts +22 -8
  52. package/ios/AppleDiagnostics/LBRNAppleNativeDiagnostics.swift +1 -1
  53. package/lifecycle.cjs +181 -78
  54. package/lifecycle.d.cts +1 -50
  55. package/lifecycle.d.ts +17 -6
  56. package/metadata.cjs +279 -114
  57. package/metro-debug-id.cjs +296 -0
  58. package/metro-serializer.cjs +219 -0
  59. package/metro.cjs +153 -297
  60. package/metro.d.cts +2 -57
  61. package/metro.d.ts +27 -13
  62. package/metro.js +2 -3
  63. package/native-bridge-async.cjs +165 -0
  64. package/native-bridge-scope.cjs +148 -0
  65. package/native-bridge.cjs +83 -186
  66. package/native-bridge.d.cts +2 -94
  67. package/native-bridge.d.ts +28 -15
  68. package/native-client-bindings.js +230 -0
  69. package/native-diagnostics-values.js +120 -0
  70. package/native-module-lookup.js +31 -0
  71. package/native-null.js +3 -0
  72. package/null-value.cjs +4 -0
  73. package/package.json +43 -1
  74. package/persistent-delivery-store.js +247 -0
  75. package/persistent-delivery.native.js +183 -261
  76. package/promise-rejection-handlers.cjs +368 -0
  77. package/promise-rejections.cjs +169 -361
  78. package/react-native.config.js +3 -1
  79. package/release-artifacts-files.cjs +94 -0
  80. package/release-artifacts-options.cjs +182 -0
  81. package/release-artifacts.cjs +278 -207
  82. package/release-artifacts.d.cts +2 -55
  83. package/release-artifacts.d.ts +18 -7
  84. package/release-artifacts.js +2 -4
  85. package/resource-fetch-graphql.cjs +265 -0
  86. package/resource-fetch-size.cjs +156 -0
  87. package/resource-fetch.cjs +227 -428
  88. package/resource-fetch.d.cts +1 -60
  89. package/resource-fetch.d.ts +17 -6
  90. package/scripts/sync-apple-native-sources.mjs +101 -53
  91. package/types/capture.d.ts +95 -0
  92. package/types/config.d.ts +85 -0
  93. package/types/defaults.d.ts +55 -0
  94. package/types/events.d.ts +203 -0
  95. package/types/provider.d.ts +81 -0
  96. 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 { NativeModules, TurboModuleRegistry } from "react-native";
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 = 4 * 1024 * 1024;
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
- // Drop counts live in a separate native queue, so existing native binaries keep them without changes.
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
- export function resolveReactNativePersistentEventStore({
19
- authKey,
20
- eventStore,
21
- hasExplicitPersistentQueue = false,
22
- maxQueueBytes,
23
- maxQueueSize,
24
- persistentQueue = "auto"
25
- }) {
26
- validatePersistentQueueMode(persistentQueue);
27
- if (eventStore !== undefined) {
28
- if (hasExplicitPersistentQueue) {
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
- if (persistentQueue === "disabled") {
37
- return { eventStore: undefined, durable: false, abort() {}, release() {} };
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
- const nativeStore = defaultNativeStore();
41
- if (!nativeStore) {
42
- if (persistentQueue === "required") {
43
- throw new SdkError(
44
- "configuration_error",
45
- "React Native persistent queue requires the linked LogBrew native module"
46
- );
47
- }
48
- return { eventStore: undefined, durable: false, abort() {}, release() {} };
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
- validateNativeQueueLimits({ maxQueueBytes, maxQueueSize });
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
- const release = () => {
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
- export function purgeReactNativePersistentQueue({ apiKey, clientKey } = {}) {
82
- const authKey = clientKey ?? apiKey;
83
- if (typeof authKey !== "string" || authKey.trim() === "") {
84
- throw new SdkError(
85
- "configuration_error",
86
- "purgeLogBrewReactNativePersistentQueue requires clientKey or apiKey"
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
- "React Native persistent queue requires the linked LogBrew native module"
153
+ "eventStore and persistentQueue are mutually exclusive"
100
154
  );
101
155
  }
102
- let failure;
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
- function createNativeEventStore(nativeStore, authKey, release) {
127
- const reportKey = `${authKey}${CLIENT_REPORT_QUEUE_SUFFIX}`;
128
- const eventStore = {
129
- load() {
130
- const result = requireStatus(
131
- "load",
132
- callNative(nativeStore, "loadEventRecords", authKey),
133
- "loaded"
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
- function defaultNativeStore() {
246
- try {
247
- const nativeStore = TurboModuleRegistry?.get?.("LogBrewFatalStore")
248
- ?? NativeModules?.LogBrewFatalStore;
249
- return NATIVE_STORE_METHODS.every((method) => typeof nativeStore?.[method] === "function")
250
- ? nativeStore
251
- : undefined;
252
- } catch {
253
- return undefined;
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
- function validateNativeQueueLimits({ maxQueueBytes, maxQueueSize }) {
258
- if (maxQueueBytes !== undefined
259
- && (!Number.isSafeInteger(maxQueueBytes)
260
- || maxQueueBytes <= 0
261
- || maxQueueBytes > MAX_NATIVE_QUEUE_BYTES)) {
262
- throw new SdkError(
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
- `persistent React Native maxQueueSize must be at most ${MAX_NATIVE_QUEUE_EVENTS}`
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
- "configuration_error",
282
- "persistentQueue must be auto, required, or disabled"
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
- function callNative(nativeStore, method, ...args) {
288
- if (typeof nativeStore?.[method] !== "function") {
289
- throw persistenceFailure(methodName(method));
290
- }
217
+ /**
218
+ * @param {() => void} operation
219
+ * @returns {Error | undefined}
220
+ */
221
+ function failureOf(operation) {
291
222
  try {
292
- return nativeStore[method](...args);
293
- } catch {
294
- throw persistenceFailure(methodName(method));
295
- }
296
- }
297
-
298
- function requireStatus(operation, result, expected) {
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
- function methodName(method) {
309
- switch (method) {
310
- case "loadEventRecords":
311
- return "load";
312
- case "appendEventRecord":
313
- return "append";
314
- case "acknowledgeEventRecords":
315
- return "acknowledge";
316
- case "removeEventRecords":
317
- return "remove";
318
- case "purgeEventRecords":
319
- return "purge";
320
- case "closeEventStore":
321
- return "close";
322
- default:
323
- return "operation";
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
- function persistenceFailure(operation) {
328
- return new SdkError(
329
- "persistence_error",
330
- `React Native persistent queue ${operation} failed`
331
- );
332
- }
254
+ export { purgeReactNativePersistentQueue, resolveReactNativePersistentEventStore };