@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,233 @@
1
+ "use strict";
2
+
3
+ const { SdkError } = require("@logbrew/sdk");
4
+ const {
5
+ defaultRouteTemplateFactory,
6
+ isCallable,
7
+ isWritableRecord,
8
+ readField,
9
+ toText
10
+ } = require("./instrumentation-values.cjs");
11
+ const { XhrRequestState } = require("./instrumentation-xhr-request.cjs");
12
+
13
+ /**
14
+ * @import { LogBrewClient, Metadata } from "@logbrew/sdk"
15
+ * @import { TracePropagationTarget } from "./index.cjs"
16
+ * @import { AppStateInput, Callable, PlatformInput, TraceInput } from "./instrumentation-values.cjs"
17
+ * @import { XhrMethods, XhrWrapperSettings } from "./instrumentation-xhr-request.cjs"
18
+ */
19
+
20
+ /**
21
+ * @typedef {{
22
+ * readonly appState: AppStateInput | undefined,
23
+ * readonly globalObject: unknown,
24
+ * readonly measureXhrResponseBodySize: boolean,
25
+ * readonly metadata: Readonly<Metadata>,
26
+ * readonly metadataFactory: unknown,
27
+ * readonly now: () => string,
28
+ * readonly nowMs: () => number,
29
+ * readonly platform: PlatformInput | undefined,
30
+ * readonly routeTemplate: string | undefined,
31
+ * readonly routeTemplateFactory: unknown,
32
+ * readonly screen: string | undefined,
33
+ * readonly sessionId: string | undefined,
34
+ * readonly trace: TraceInput,
35
+ * readonly tracePropagationTargets: readonly TracePropagationTarget[]
36
+ * }} XhrInstallOptions
37
+ * @typedef {{ readonly open: Callable, readonly send: Callable }} XhrWrappers
38
+ */
39
+
40
+ const HEADERS_RECEIVED = 2;
41
+ const DONE = 4;
42
+ const OPEN_LENGTH = 2;
43
+ const SEND_LENGTH = 1;
44
+
45
+ /**
46
+ * @param {unknown} method
47
+ * @returns {string}
48
+ */
49
+ function normalizeXhrMethod(method) {
50
+ return toText(method ?? "GET").toUpperCase();
51
+ }
52
+
53
+ /**
54
+ * @param {unknown} url
55
+ * @returns {unknown}
56
+ */
57
+ function xhrUrl(url) {
58
+ if (typeof url === "string") {
59
+ return url;
60
+ }
61
+ try {
62
+ const toStringMethod = readField(url, "toString");
63
+ return isCallable(toStringMethod) ? Reflect.apply(toStringMethod, url, []) : toText(url);
64
+ } catch {
65
+ return toText(url);
66
+ }
67
+ }
68
+
69
+ /**
70
+ * @param {unknown} value
71
+ * @param {number} fallback
72
+ * @returns {unknown}
73
+ */
74
+ function readyState(value, fallback) {
75
+ return typeof value === "number" ? value : fallback;
76
+ }
77
+
78
+ /**
79
+ * @param {unknown} prototype
80
+ * @returns {XhrMethods}
81
+ */
82
+ function readXhrMethods(prototype) {
83
+ const open = readField(prototype, "open");
84
+ const send = readField(prototype, "send");
85
+ const setRequestHeader = readField(prototype, "setRequestHeader");
86
+ if (!isCallable(open) || !isCallable(send) || !isCallable(setRequestHeader)) {
87
+ throw new SdkError("configuration_error", "instrumentGlobalXMLHttpRequest requires open, send, and setRequestHeader");
88
+ }
89
+ return { open, send, setRequestHeader };
90
+ }
91
+
92
+ /**
93
+ * @param {unknown} xhrType
94
+ * @returns {unknown}
95
+ */
96
+ function xhrPrototype(xhrType) {
97
+ const prototype = isCallable(xhrType) ? readField(xhrType, "prototype") : undefined;
98
+ const hasPrototype = Boolean(prototype);
99
+ if (!isCallable(xhrType) || !hasPrototype) {
100
+ throw new SdkError("configuration_error", "instrumentGlobalXMLHttpRequest requires globalObject.XMLHttpRequest");
101
+ }
102
+ return prototype;
103
+ }
104
+
105
+ /**
106
+ * @param {unknown} globalObject
107
+ * @returns {{ readonly methods: XhrMethods, readonly prototype: Record<PropertyKey, unknown>, readonly xhrType: unknown }}
108
+ */
109
+ function requireXhrTarget(globalObject) {
110
+ if (!isWritableRecord(globalObject)) {
111
+ throw new SdkError("configuration_error", "instrumentGlobalXMLHttpRequest requires a globalObject");
112
+ }
113
+ const xhrType = globalObject["XMLHttpRequest"];
114
+ const prototype = xhrPrototype(xhrType);
115
+ const methods = readXhrMethods(prototype);
116
+ if (!isWritableRecord(prototype)) {
117
+ throw new SdkError("configuration_error", "instrumentGlobalXMLHttpRequest requires open, send, and setRequestHeader");
118
+ }
119
+ return { methods, prototype, xhrType };
120
+ }
121
+
122
+ /**
123
+ * @param {LogBrewClient} client
124
+ * @param {XhrInstallOptions} options
125
+ * @param {unknown} xhrType
126
+ * @returns {XhrWrapperSettings}
127
+ */
128
+ function xhrWrapperSettings(client, options, xhrType) {
129
+ return {
130
+ capture: {
131
+ appState: options.appState,
132
+ client,
133
+ doneState: readyState(readField(xhrType, "DONE"), DONE),
134
+ headersReceivedState: readyState(readField(xhrType, "HEADERS_RECEIVED"), HEADERS_RECEIVED),
135
+ measureXhrResponseBodySize: options.measureXhrResponseBodySize,
136
+ metadata: options.metadata,
137
+ metadataFactory: options.metadataFactory,
138
+ nowMs: options.nowMs,
139
+ platform: options.platform,
140
+ routeTemplate: options.routeTemplate,
141
+ routeTemplateFactory: isCallable(options.routeTemplateFactory) ? options.routeTemplateFactory : defaultRouteTemplateFactory,
142
+ screen: options.screen,
143
+ sessionId: options.sessionId,
144
+ status: undefined,
145
+ trace: options.trace
146
+ },
147
+ now: options.now,
148
+ tracePropagationTargets: options.tracePropagationTargets
149
+ };
150
+ }
151
+
152
+ /**
153
+ * @param {XhrMethods} methods
154
+ * @param {XhrWrapperSettings} settings
155
+ * @returns {XhrWrappers}
156
+ */
157
+ function createXhrWrappers(methods, settings) {
158
+ const contextKey = Symbol("logbrew.xhr");
159
+ /**
160
+ * @this {unknown}
161
+ * @param {readonly unknown[]} args
162
+ * @returns {unknown}
163
+ */
164
+ function wrappedOpen(...args) {
165
+ const [method, url] = args;
166
+ const context = new XhrRequestState(normalizeXhrMethod(method), xhrUrl(url));
167
+ if (!isWritableRecord(this)) {
168
+ throw new TypeError("XMLHttpRequest.open requires an XMLHttpRequest");
169
+ }
170
+ this[contextKey] = context;
171
+ return Reflect.apply(methods.open, this, args);
172
+ }
173
+ /**
174
+ * @this {unknown}
175
+ * @param {readonly unknown[]} args
176
+ * @returns {unknown}
177
+ */
178
+ function wrappedSend(...args) {
179
+ const context = readField(this, contextKey);
180
+ if (!(context instanceof XhrRequestState)) {
181
+ return Reflect.apply(methods.send, this, args);
182
+ }
183
+ return context.send(this, { args, methods, settings });
184
+ }
185
+ Object.defineProperty(wrappedOpen, "length", { value: OPEN_LENGTH });
186
+ Object.defineProperty(wrappedSend, "length", { value: SEND_LENGTH });
187
+ return { open: wrappedOpen, send: wrappedSend };
188
+ }
189
+
190
+ /**
191
+ * @param {unknown} prototype
192
+ * @param {XhrWrappers} wrappers
193
+ * @returns {void}
194
+ */
195
+ function requirePatched(prototype, wrappers) {
196
+ if (readField(prototype, "open") !== wrappers.open || readField(prototype, "send") !== wrappers.send) {
197
+ throw new SdkError("configuration_error", "instrumentGlobalXMLHttpRequest could not patch XMLHttpRequest");
198
+ }
199
+ }
200
+
201
+ /**
202
+ * @param {LogBrewClient} client
203
+ * @param {XhrInstallOptions} options
204
+ * @returns {Readonly<{ remove: () => void, stop: () => void }>}
205
+ */
206
+ function installGlobalXMLHttpRequestInstrumentation(client, options) {
207
+ const { methods, prototype, xhrType } = requireXhrTarget(options.globalObject);
208
+ const wrappers = createXhrWrappers(methods, xhrWrapperSettings(client, options, xhrType));
209
+ prototype["open"] = wrappers.open;
210
+ prototype["send"] = wrappers.send;
211
+ requirePatched(prototype, wrappers);
212
+ let removed = false;
213
+ const { remove } = {
214
+ remove: () => {
215
+ if (removed) {
216
+ return;
217
+ }
218
+ removed = true;
219
+ if (prototype["open"] === wrappers.open) {
220
+ prototype["open"] = methods.open;
221
+ }
222
+ if (prototype["send"] === wrappers.send) {
223
+ prototype["send"] = methods.send;
224
+ }
225
+ }
226
+ };
227
+ return Object.freeze({
228
+ remove,
229
+ stop: remove
230
+ });
231
+ }
232
+
233
+ module.exports = { installGlobalXMLHttpRequestInstrumentation };