@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.
Files changed (104) hide show
  1. package/LogBrewReactNative.podspec +1 -1
  2. package/README.md +17 -15
  3. package/android-native-diagnostics.d.ts +15 -5
  4. package/android-native-diagnostics.js +170 -94
  5. package/apollo.cjs +435 -226
  6. package/apollo.d.cts +2 -70
  7. package/apollo.d.ts +24 -12
  8. package/apollo.js +438 -221
  9. package/apple-native-diagnostics-config.js +176 -0
  10. package/apple-native-diagnostics-context.js +232 -0
  11. package/apple-native-diagnostics-module.js +229 -0
  12. package/apple-native-diagnostics.d.ts +42 -11
  13. package/apple-native-diagnostics.js +60 -389
  14. package/expo.cjs +29 -16
  15. package/expo.d.ts +10 -9
  16. package/expo.js +4 -3
  17. package/fatal-admission.cjs +113 -0
  18. package/fatal-record.cjs +317 -0
  19. package/fatal-replay.cjs +297 -508
  20. package/global-errors-capture.cjs +369 -0
  21. package/global-errors-event.cjs +174 -0
  22. package/global-errors-support.cjs +128 -0
  23. package/global-errors.cjs +75 -351
  24. package/global-errors.d.cts +29 -278
  25. package/global-errors.d.ts +57 -27
  26. package/global-errors.js +7 -2
  27. package/global-errors.native.js +83 -48
  28. package/index-breadcrumbs.cjs +139 -0
  29. package/index-errors.cjs +167 -0
  30. package/index-events.cjs +365 -0
  31. package/index-navigation.cjs +327 -0
  32. package/index-random.cjs +120 -0
  33. package/index-react.cjs +189 -0
  34. package/index-spans.cjs +190 -0
  35. package/index-trace-fetch.cjs +322 -0
  36. package/index-trace.cjs +335 -0
  37. package/index-transport.cjs +201 -0
  38. package/index-values.cjs +232 -0
  39. package/index.cjs +95 -1220
  40. package/index.d.cts +2 -505
  41. package/index.d.ts +130 -469
  42. package/index.native.d.ts +146 -22
  43. package/index.native.js +184 -159
  44. package/instrumentation-fetch.cjs +113 -0
  45. package/instrumentation-install.cjs +241 -0
  46. package/instrumentation-runtime.cjs +65 -0
  47. package/instrumentation-teardown.cjs +93 -0
  48. package/instrumentation-values.cjs +282 -0
  49. package/instrumentation-xhr-request.cjs +298 -0
  50. package/instrumentation-xhr.cjs +233 -0
  51. package/instrumentation.cjs +110 -599
  52. package/instrumentation.d.cts +2 -84
  53. package/instrumentation.d.ts +22 -8
  54. package/ios/AppleDiagnostics/LBRNAppleNativeDiagnostics.swift +1 -1
  55. package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngine.swift +7 -1
  56. package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineAutomatic.swift +36 -4
  57. package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineQueue.swift +17 -0
  58. package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryLifecycle.swift +2 -0
  59. package/ios/GeneratedAppleDiagnostics/LogBrew/Transport.swift +41 -6
  60. package/ios/GeneratedAppleDiagnostics/SOURCE-MANIFEST.json +5 -5
  61. package/lifecycle.cjs +181 -78
  62. package/lifecycle.d.cts +1 -50
  63. package/lifecycle.d.ts +17 -6
  64. package/metadata.cjs +279 -114
  65. package/metro-debug-id.cjs +296 -0
  66. package/metro-serializer.cjs +219 -0
  67. package/metro.cjs +153 -297
  68. package/metro.d.cts +2 -57
  69. package/metro.d.ts +27 -13
  70. package/metro.js +2 -3
  71. package/native-bridge-async.cjs +165 -0
  72. package/native-bridge-scope.cjs +148 -0
  73. package/native-bridge.cjs +83 -186
  74. package/native-bridge.d.cts +2 -94
  75. package/native-bridge.d.ts +28 -15
  76. package/native-client-bindings.js +230 -0
  77. package/native-diagnostics-values.js +120 -0
  78. package/native-module-lookup.js +31 -0
  79. package/native-null.js +3 -0
  80. package/null-value.cjs +4 -0
  81. package/package.json +44 -2
  82. package/persistent-delivery-store.js +247 -0
  83. package/persistent-delivery.native.js +183 -261
  84. package/promise-rejection-handlers.cjs +368 -0
  85. package/promise-rejections.cjs +169 -361
  86. package/react-native.config.js +3 -1
  87. package/release-artifacts-files.cjs +94 -0
  88. package/release-artifacts-options.cjs +182 -0
  89. package/release-artifacts.cjs +278 -207
  90. package/release-artifacts.d.cts +2 -55
  91. package/release-artifacts.d.ts +18 -7
  92. package/release-artifacts.js +2 -4
  93. package/resource-fetch-graphql.cjs +265 -0
  94. package/resource-fetch-size.cjs +156 -0
  95. package/resource-fetch.cjs +227 -428
  96. package/resource-fetch.d.cts +1 -60
  97. package/resource-fetch.d.ts +17 -6
  98. package/scripts/sync-apple-native-sources.mjs +101 -53
  99. package/types/capture.d.ts +95 -0
  100. package/types/config.d.ts +85 -0
  101. package/types/defaults.d.ts +55 -0
  102. package/types/events.d.ts +203 -0
  103. package/types/provider.d.ts +81 -0
  104. package/types/trace.d.ts +104 -0
@@ -0,0 +1,368 @@
1
+ "use strict";
2
+
3
+ const { createReactNativeErrorEvent } = require("./index.cjs");
4
+ const { captureIssueWithAdmission } = require("./fatal-replay.cjs");
5
+ const {
6
+ DiagnosticGate,
7
+ emitDiagnostic,
8
+ hasControlCharacter,
9
+ incrementBounded,
10
+ isObjectLike,
11
+ safeFunction,
12
+ safeReadProperty
13
+ } = require("./global-errors-support.cjs");
14
+
15
+ /**
16
+ * @import { UnknownFunction } from "./global-errors-support.cjs"
17
+ * @import { ReactNativeErrorEvent } from "./index.cjs"
18
+ * @import { Admission } from "./fatal-admission.cjs"
19
+ * @import { LogBrewReactNativePromiseRejectionHandlers, ReactNativePromiseRejectionHealth } from "./global-errors.cjs"
20
+ * @typedef {ReactNativePromiseRejectionHealth["lastOutcome"]} RejectionOutcome
21
+ * @typedef {Readonly<{
22
+ * client: unknown,
23
+ * issue: UnknownFunction,
24
+ * maxTrackedRejections: number,
25
+ * mechanism: string,
26
+ * onDiagnostic: unknown
27
+ * }>} RejectionTrackingOptions
28
+ */
29
+
30
+ const AUTOMATIC_MESSAGE = "Unhandled Promise rejection";
31
+ const DEFAULT_MAX_TRACKED_REJECTIONS = 128;
32
+ const MAX_TRACKED_REJECTIONS = 1024;
33
+ const MIN_TRACKED_REJECTIONS = 1;
34
+ const MAX_STRING_ID_LENGTH = 128;
35
+ const MIN_NUMBER_ID = 0;
36
+ const MIN_STRING_ID_LENGTH = 1;
37
+ const NO_COUNT = 0;
38
+ const ID_RADIX = 36;
39
+ /** @type {Readonly<Record<"dropped" | "filtered" | "unavailable", readonly [RejectionOutcome, string]>>} */
40
+ const ADMISSION_FAILURES = {
41
+ dropped: ["capture_failed", "promise_rejection_capture_failed"],
42
+ filtered: ["filtered", "promise_rejection_filtered"],
43
+ unavailable: ["admission_unavailable", "promise_rejection_admission_unavailable"]
44
+ };
45
+ const sequence = { next: NO_COUNT };
46
+
47
+ /**
48
+ * @returns {string}
49
+ */
50
+ function nextEventId() {
51
+ sequence.next = incrementBounded(sequence.next);
52
+ return `evt_rn_promise_${Date.now().toString(ID_RADIX)}_${sequence.next.toString(ID_RADIX)}`;
53
+ }
54
+
55
+ /**
56
+ * @param {string} mechanism
57
+ * @returns {ReactNativeErrorEvent}
58
+ */
59
+ function createEvent(mechanism) {
60
+ const error = new Error(AUTOMATIC_MESSAGE);
61
+ delete error.stack;
62
+ const event = createReactNativeErrorEvent(error, {
63
+ handled: false,
64
+ id: nextEventId(),
65
+ includeStack: false,
66
+ mechanism
67
+ });
68
+ return {
69
+ ...event,
70
+ attributes: {
71
+ ...event.attributes,
72
+ message: AUTOMATIC_MESSAGE,
73
+ metadata: {
74
+ ...event.attributes.metadata,
75
+ automatic: true,
76
+ fatal: false,
77
+ handled: false,
78
+ mechanism,
79
+ source: "react-native.promise_rejection"
80
+ },
81
+ title: AUTOMATIC_MESSAGE
82
+ }
83
+ };
84
+ }
85
+
86
+ /**
87
+ * @param {unknown} value
88
+ * @returns {string | undefined}
89
+ */
90
+ function rejectionKey(value) {
91
+ if (typeof value === "number" && Number.isSafeInteger(value) && value >= MIN_NUMBER_ID) {
92
+ return `number:${value}`;
93
+ }
94
+ if (typeof value === "string"
95
+ && value.length >= MIN_STRING_ID_LENGTH
96
+ && value.length <= MAX_STRING_ID_LENGTH
97
+ && !hasControlCharacter(value)) {
98
+ return `string:${value}`;
99
+ }
100
+ return undefined;
101
+ }
102
+
103
+ /**
104
+ * @param {unknown} value
105
+ * @returns {value is number}
106
+ */
107
+ function validMaximum(value) {
108
+ return Number.isInteger(value) && typeof value === "number"
109
+ && value >= MIN_TRACKED_REJECTIONS && value <= MAX_TRACKED_REJECTIONS;
110
+ }
111
+
112
+ /**
113
+ * @returns {LogBrewReactNativePromiseRejectionHandlers}
114
+ */
115
+ function inactiveHandlers() {
116
+ const snapshot = Object.freeze({
117
+ available: false,
118
+ capturedEvents: NO_COUNT,
119
+ evictedRejections: NO_COUNT,
120
+ handledLaterEvents: NO_COUNT,
121
+ lastOutcome: "unavailable",
122
+ maxTrackedRejections: NO_COUNT,
123
+ suppressedEvents: NO_COUNT,
124
+ trackedRejections: NO_COUNT,
125
+ unknownHandledEvents: NO_COUNT,
126
+ untrackedEvents: NO_COUNT
127
+ });
128
+ return Object.freeze({
129
+ health: () => snapshot,
130
+ onHandled: () => undefined,
131
+ onUnhandled: () => undefined
132
+ });
133
+ }
134
+
135
+ class RejectionTracking {
136
+ capturedEvents = NO_COUNT;
137
+ emittedEvictionDiagnostic = false;
138
+ evictedRejections = NO_COUNT;
139
+ handledLaterEvents = NO_COUNT;
140
+ handling = false;
141
+ suppressedEvents = NO_COUNT;
142
+ unknownHandledEvents = NO_COUNT;
143
+ untrackedEvents = NO_COUNT;
144
+
145
+ /**
146
+ * @param {RejectionTrackingOptions} options
147
+ */
148
+ constructor(options) {
149
+ this.options = options;
150
+ this.diagnostics = new DiagnosticGate(options.onDiagnostic);
151
+ /** @type {RejectionOutcome} */
152
+ this.lastOutcome = "idle";
153
+ /** @type {Map<string, boolean>} */
154
+ this.tracked = new Map();
155
+ }
156
+
157
+ /**
158
+ * @returns {ReactNativePromiseRejectionHealth}
159
+ */
160
+ health() {
161
+ return Object.freeze({
162
+ available: true,
163
+ capturedEvents: this.capturedEvents,
164
+ evictedRejections: this.evictedRejections,
165
+ handledLaterEvents: this.handledLaterEvents,
166
+ lastOutcome: this.lastOutcome,
167
+ maxTrackedRejections: this.options.maxTrackedRejections,
168
+ suppressedEvents: this.suppressedEvents,
169
+ trackedRejections: this.tracked.size,
170
+ unknownHandledEvents: this.unknownHandledEvents,
171
+ untrackedEvents: this.untrackedEvents
172
+ });
173
+ }
174
+
175
+ /**
176
+ * @param {string} code
177
+ * @param {RejectionOutcome} outcome
178
+ * @returns {void}
179
+ */
180
+ suppress(code, outcome) {
181
+ this.suppressedEvents = incrementBounded(this.suppressedEvents);
182
+ this.lastOutcome = outcome;
183
+ this.diagnostics.emit(code);
184
+ }
185
+
186
+ /**
187
+ * @returns {void}
188
+ */
189
+ recordUnknownHandled() {
190
+ this.unknownHandledEvents = incrementBounded(this.unknownHandledEvents);
191
+ this.lastOutcome = "handled_unknown";
192
+ }
193
+
194
+ /**
195
+ * @param {unknown} runtimeRejectionId
196
+ * @returns {void}
197
+ */
198
+ handled(runtimeRejectionId) {
199
+ const key = rejectionKey(runtimeRejectionId);
200
+ const handled = key === undefined ? undefined : this.tracked.get(key);
201
+ if (key === undefined || handled === undefined) {
202
+ this.recordUnknownHandled();
203
+ return;
204
+ }
205
+ if (handled) {
206
+ this.suppress("promise_rejection_duplicate_suppressed", "duplicate_suppressed");
207
+ } else {
208
+ this.recordHandledLater(key);
209
+ }
210
+ }
211
+
212
+ /**
213
+ * @param {string} key
214
+ * @returns {void}
215
+ */
216
+ recordHandledLater(key) {
217
+ this.tracked.set(key, true);
218
+ this.handledLaterEvents = incrementBounded(this.handledLaterEvents);
219
+ this.lastOutcome = "handled_later";
220
+ }
221
+
222
+ /**
223
+ * @param {Exclude<Admission, "admitted">} admission
224
+ * @returns {void}
225
+ */
226
+ rejectAdmission(admission) {
227
+ const [outcome, code] = ADMISSION_FAILURES[admission];
228
+ this.lastOutcome = outcome;
229
+ this.diagnostics.emit(code);
230
+ }
231
+
232
+ /**
233
+ * @returns {boolean}
234
+ */
235
+ evictOldestAtCapacity() {
236
+ const oldest = this.tracked.keys().next().value;
237
+ if (this.tracked.size !== this.options.maxTrackedRejections || oldest === undefined) {
238
+ return false;
239
+ }
240
+ this.tracked.delete(oldest);
241
+ this.evictedRejections = incrementBounded(this.evictedRejections);
242
+ if (!this.emittedEvictionDiagnostic) {
243
+ this.emittedEvictionDiagnostic = true;
244
+ this.diagnostics.emit("promise_rejection_tracking_evicted");
245
+ }
246
+ return true;
247
+ }
248
+
249
+ /**
250
+ * @param {string} key
251
+ * @returns {void}
252
+ */
253
+ track(key) {
254
+ const evicted = this.evictOldestAtCapacity();
255
+ this.tracked.set(key, false);
256
+ this.lastOutcome = evicted ? "captured_with_eviction" : "captured";
257
+ }
258
+
259
+ /**
260
+ * @param {string | undefined} key
261
+ * @returns {void}
262
+ */
263
+ capture(key) {
264
+ if (key === undefined) {
265
+ this.diagnostics.emit("promise_rejection_id_unavailable");
266
+ }
267
+ const { client, issue, mechanism } = this.options;
268
+ const event = createEvent(mechanism);
269
+ const admission = captureIssueWithAdmission(client, issue, event.id, event.timestamp, event.attributes);
270
+ if (admission === "admitted") {
271
+ this.recordCaptured(key);
272
+ } else {
273
+ this.rejectAdmission(admission);
274
+ }
275
+ }
276
+
277
+ /**
278
+ * @param {string | undefined} key
279
+ * @returns {void}
280
+ */
281
+ recordCaptured(key) {
282
+ this.capturedEvents = incrementBounded(this.capturedEvents);
283
+ if (key === undefined) {
284
+ this.untrackedEvents = incrementBounded(this.untrackedEvents);
285
+ this.lastOutcome = "captured_untracked";
286
+ return;
287
+ }
288
+ this.track(key);
289
+ }
290
+
291
+ /**
292
+ * @param {unknown} runtimeRejectionId
293
+ * @returns {void}
294
+ */
295
+ unhandled(runtimeRejectionId) {
296
+ if (this.handling) {
297
+ this.suppress("promise_rejection_recursive_capture_suppressed", "recursive_suppressed");
298
+ return;
299
+ }
300
+ const key = rejectionKey(runtimeRejectionId);
301
+ if (key !== undefined && this.tracked.has(key)) {
302
+ this.suppress("promise_rejection_duplicate_suppressed", "duplicate_suppressed");
303
+ return;
304
+ }
305
+ this.captureOnce(key);
306
+ }
307
+
308
+ /**
309
+ * @param {string | undefined} key
310
+ * @returns {void}
311
+ */
312
+ captureOnce(key) {
313
+ this.handling = true;
314
+ try {
315
+ this.capture(key);
316
+ } catch {
317
+ this.lastOutcome = "capture_failed";
318
+ this.diagnostics.emit("promise_rejection_capture_failed");
319
+ } finally {
320
+ this.handling = false;
321
+ }
322
+ }
323
+ }
324
+
325
+ /**
326
+ * @param {object} input
327
+ * @param {unknown} onDiagnostic
328
+ * @returns {number}
329
+ */
330
+ function trackedMaximum(input, onDiagnostic) {
331
+ const configuredMaximum = safeReadProperty(input, "maxTrackedRejections");
332
+ const maxTrackedRejections = validMaximum(configuredMaximum) ? configuredMaximum : DEFAULT_MAX_TRACKED_REJECTIONS;
333
+ if (configuredMaximum !== undefined && maxTrackedRejections !== configuredMaximum) {
334
+ emitDiagnostic(onDiagnostic, "promise_rejection_configuration_invalid");
335
+ }
336
+ return maxTrackedRejections;
337
+ }
338
+
339
+ /**
340
+ * @param {unknown} options
341
+ * @param {string} mechanism
342
+ * @returns {LogBrewReactNativePromiseRejectionHandlers}
343
+ */
344
+ function createPromiseRejectionHandlers(options, mechanism) {
345
+ const input = isObjectLike(options) ? options : {};
346
+ const client = safeReadProperty(input, "client");
347
+ const issue = safeFunction(client, "issue");
348
+ const onDiagnostic = safeFunction(input, "onDiagnostic");
349
+ if (!issue) {
350
+ emitDiagnostic(onDiagnostic, "promise_rejection_handler_unavailable");
351
+ return inactiveHandlers();
352
+ }
353
+ const maxTrackedRejections = trackedMaximum(input, onDiagnostic);
354
+ const tracking = new RejectionTracking({ client, issue, maxTrackedRejections, mechanism, onDiagnostic });
355
+ return Object.freeze({
356
+ health() {
357
+ return tracking.health();
358
+ },
359
+ onHandled(runtimeRejectionId) {
360
+ tracking.handled(runtimeRejectionId);
361
+ },
362
+ onUnhandled(runtimeRejectionId) {
363
+ tracking.unhandled(runtimeRejectionId);
364
+ }
365
+ });
366
+ }
367
+
368
+ module.exports = { createPromiseRejectionHandlers, inactiveHandlers };