@logbrew/react-native 0.1.39 → 0.1.41

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 (99) hide show
  1. package/README.md +3 -3
  2. package/android-native-diagnostics.d.ts +15 -5
  3. package/android-native-diagnostics.js +170 -94
  4. package/apollo.cjs +435 -226
  5. package/apollo.d.cts +2 -70
  6. package/apollo.d.ts +24 -12
  7. package/apollo.js +438 -221
  8. package/apple-native-diagnostics-config.js +176 -0
  9. package/apple-native-diagnostics-context.js +232 -0
  10. package/apple-native-diagnostics-module.js +229 -0
  11. package/apple-native-diagnostics.d.ts +42 -11
  12. package/apple-native-diagnostics.js +60 -389
  13. package/expo.cjs +29 -16
  14. package/expo.d.ts +10 -9
  15. package/expo.js +4 -3
  16. package/fatal-admission.cjs +113 -0
  17. package/fatal-record.cjs +317 -0
  18. package/fatal-replay.cjs +297 -508
  19. package/global-errors-capture.cjs +369 -0
  20. package/global-errors-event.cjs +174 -0
  21. package/global-errors-support.cjs +128 -0
  22. package/global-errors.cjs +75 -351
  23. package/global-errors.d.cts +29 -278
  24. package/global-errors.d.ts +57 -27
  25. package/global-errors.js +7 -2
  26. package/global-errors.native.js +83 -48
  27. package/index-breadcrumbs.cjs +139 -0
  28. package/index-errors.cjs +167 -0
  29. package/index-events.cjs +365 -0
  30. package/index-navigation.cjs +327 -0
  31. package/index-random.cjs +120 -0
  32. package/index-react.cjs +189 -0
  33. package/index-spans.cjs +190 -0
  34. package/index-trace-fetch.cjs +322 -0
  35. package/index-trace.cjs +335 -0
  36. package/index-transport.cjs +201 -0
  37. package/index-values.cjs +232 -0
  38. package/index.cjs +97 -1245
  39. package/index.d.cts +2 -505
  40. package/index.d.ts +130 -469
  41. package/index.native.d.ts +146 -22
  42. package/index.native.js +184 -159
  43. package/instrumentation-fetch.cjs +113 -0
  44. package/instrumentation-install.cjs +241 -0
  45. package/instrumentation-runtime.cjs +65 -0
  46. package/instrumentation-teardown.cjs +93 -0
  47. package/instrumentation-values.cjs +282 -0
  48. package/instrumentation-xhr-request.cjs +298 -0
  49. package/instrumentation-xhr.cjs +233 -0
  50. package/instrumentation.cjs +110 -599
  51. package/instrumentation.d.cts +2 -84
  52. package/instrumentation.d.ts +22 -8
  53. package/ios/AppleDiagnostics/LBRNAppleNativeDiagnostics.swift +1 -1
  54. package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryLifecycle.swift +1 -1
  55. package/ios/GeneratedAppleDiagnostics/SOURCE-MANIFEST.json +1 -1
  56. package/lifecycle.cjs +181 -78
  57. package/lifecycle.d.cts +1 -50
  58. package/lifecycle.d.ts +17 -6
  59. package/metadata.cjs +279 -114
  60. package/metro-debug-id.cjs +296 -0
  61. package/metro-serializer.cjs +219 -0
  62. package/metro.cjs +153 -297
  63. package/metro.d.cts +2 -57
  64. package/metro.d.ts +27 -13
  65. package/metro.js +2 -3
  66. package/native-bridge-async.cjs +165 -0
  67. package/native-bridge-scope.cjs +148 -0
  68. package/native-bridge.cjs +83 -186
  69. package/native-bridge.d.cts +2 -94
  70. package/native-bridge.d.ts +28 -15
  71. package/native-client-bindings.js +230 -0
  72. package/native-diagnostics-values.js +120 -0
  73. package/native-module-lookup.js +31 -0
  74. package/native-null.js +3 -0
  75. package/null-value.cjs +4 -0
  76. package/package.json +43 -1
  77. package/persistent-delivery-store.js +247 -0
  78. package/persistent-delivery.native.js +183 -261
  79. package/promise-rejection-handlers.cjs +368 -0
  80. package/promise-rejections.cjs +169 -361
  81. package/react-native.config.js +3 -1
  82. package/release-artifacts-files.cjs +94 -0
  83. package/release-artifacts-options.cjs +182 -0
  84. package/release-artifacts.cjs +278 -207
  85. package/release-artifacts.d.cts +2 -55
  86. package/release-artifacts.d.ts +18 -7
  87. package/release-artifacts.js +2 -4
  88. package/resource-fetch-graphql.cjs +265 -0
  89. package/resource-fetch-size.cjs +156 -0
  90. package/resource-fetch.cjs +227 -428
  91. package/resource-fetch.d.cts +1 -60
  92. package/resource-fetch.d.ts +17 -6
  93. package/scripts/sync-apple-native-sources.mjs +101 -53
  94. package/types/capture.d.ts +95 -0
  95. package/types/config.d.ts +85 -0
  96. package/types/defaults.d.ts +55 -0
  97. package/types/events.d.ts +203 -0
  98. package/types/provider.d.ts +81 -0
  99. package/types/trace.d.ts +104 -0
package/README.md CHANGED
@@ -80,9 +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. 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
83
+ Supplying `transport` enables the core SDK's bounded automatic delivery. It
84
+ sends 1 second after the first queued event or at 50 queued events, whichever
85
+ comes first; set `deliveryIntervalMs` to change it. It
86
86
  coalesces concurrent work, retries transient failures, retains rejected
87
87
  batches, waits out short rate limits on its own, and pauses repeated automatic
88
88
  sends after authentication, usage-limit, or non-retryable failures. Do not add a second app-owned flush interval.
@@ -1,4 +1,4 @@
1
- export type LogBrewAndroidNativeDiagnosticsConfiguration = Readonly<{
1
+ type LogBrewAndroidNativeDiagnosticsConfiguration = Readonly<{
2
2
  anrThresholdMs?: number;
3
3
  clientKey: string;
4
4
  environment: string;
@@ -8,7 +8,7 @@ export type LogBrewAndroidNativeDiagnosticsConfiguration = Readonly<{
8
8
  service: string;
9
9
  }>;
10
10
 
11
- export type LogBrewAndroidNativeDiagnosticsReceipt = Readonly<{
11
+ type LogBrewAndroidNativeDiagnosticsReceipt = Readonly<{
12
12
  pending: number;
13
13
  status:
14
14
  | "already_installed"
@@ -18,12 +18,22 @@ export type LogBrewAndroidNativeDiagnosticsReceipt = Readonly<{
18
18
  | "uninstalled";
19
19
  }>;
20
20
 
21
- export declare function installLogBrewAndroidNativeDiagnostics(
21
+ declare function installLogBrewAndroidNativeDiagnostics(
22
22
  configuration: LogBrewAndroidNativeDiagnosticsConfiguration
23
23
  ): LogBrewAndroidNativeDiagnosticsReceipt;
24
24
 
25
- export declare function getLogBrewAndroidNativeDiagnosticsStatus():
25
+ declare function getLogBrewAndroidNativeDiagnosticsStatus():
26
26
  LogBrewAndroidNativeDiagnosticsReceipt;
27
27
 
28
- export declare function uninstallLogBrewAndroidNativeDiagnostics():
28
+ declare function uninstallLogBrewAndroidNativeDiagnostics():
29
29
  LogBrewAndroidNativeDiagnosticsReceipt;
30
+
31
+ export type {
32
+ LogBrewAndroidNativeDiagnosticsConfiguration,
33
+ LogBrewAndroidNativeDiagnosticsReceipt
34
+ };
35
+ export {
36
+ installLogBrewAndroidNativeDiagnostics,
37
+ getLogBrewAndroidNativeDiagnosticsStatus,
38
+ uninstallLogBrewAndroidNativeDiagnostics
39
+ };
@@ -1,5 +1,11 @@
1
+ import { hasControlCharacter, isCount, isRecord, nativeMethod, utf8Length } from "./native-diagnostics-values.js";
2
+ import { lookupNativeModule, platformOS } from "./native-module-lookup.js";
1
3
  import { SdkError } from "@logbrew/sdk";
2
- import { NativeModules, Platform, TurboModuleRegistry } from "react-native";
4
+
5
+ /**
6
+ * @import { LogBrewAndroidNativeDiagnosticsReceipt } from "./android-native-diagnostics.js"
7
+ * @typedef {LogBrewAndroidNativeDiagnosticsReceipt["status"]} ReceiptStatus
8
+ */
3
9
 
4
10
  const INSTALL_KEYS = new Set([
5
11
  "anrThresholdMs",
@@ -11,36 +17,85 @@ const INSTALL_KEYS = new Set([
11
17
  "service"
12
18
  ]);
13
19
  const RECEIPT_KEYS = new Set(["pending", "status"]);
20
+ /** @type {ReadonlySet<string>} */
21
+ const INSTALL_STATUSES = new Set(["already_installed", "installed"]);
22
+ /** @type {ReadonlySet<string>} */
23
+ const STATUS_STATUSES = new Set(["not_installed", "ready"]);
24
+ /** @type {ReadonlySet<string>} */
25
+ const UNINSTALL_STATUSES = new Set(["not_installed", "uninstalled"]);
26
+ const PROJECT_ID_PATTERN = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/u;
27
+ const SCOPE_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._/-]{0,127}$/u;
28
+ const ERROR_CODE_PATTERN = /^[a-z0-9_]{1,128}$/u;
29
+ const DEFAULT_ANR_THRESHOLD_MS = 5000;
30
+ const MIN_ANR_THRESHOLD_MS = 2000;
31
+ const MAX_ANR_THRESHOLD_MS = 60_000;
32
+ const PROJECT_ID_BYTES = 64;
33
+ const CLIENT_KEY_BYTES = 4096;
34
+ const ENVIRONMENT_BYTES = 128;
35
+ const RELEASE_BYTES = 256;
36
+ const SCOPE_BYTES = 128;
37
+ const EMPTY_LENGTH = 0;
14
38
 
15
- export function installLogBrewAndroidNativeDiagnostics(configuration = {}) {
16
- requireAndroid();
17
- return receipt(
18
- "install",
19
- call("installAndroidDiagnostics", normalizeConfiguration(configuration)),
20
- new Set(["already_installed", "installed"])
21
- );
39
+ /**
40
+ * @param {string} message
41
+ * @returns {SdkError}
42
+ */
43
+ function configurationError(message) {
44
+ return new SdkError("configuration_error", `LogBrew Android native diagnostics ${message}`);
22
45
  }
23
46
 
24
- export function getLogBrewAndroidNativeDiagnosticsStatus() {
25
- requireAndroid();
26
- return receipt(
27
- "status",
28
- call("androidDiagnosticsStatus"),
29
- new Set(["not_installed", "ready"])
30
- );
47
+ /**
48
+ * @param {unknown} value
49
+ * @param {number} maximumBytes
50
+ * @param {string} name
51
+ * @returns {string}
52
+ */
53
+ function exactText(value, maximumBytes, name) {
54
+ if (typeof value !== "string"
55
+ || value.length === EMPTY_LENGTH
56
+ || value.trim() !== value
57
+ || hasControlCharacter(value)
58
+ || utf8Length(value) > maximumBytes) {
59
+ throw configurationError(`${name} must be a bounded non-empty string`);
60
+ }
61
+ return value;
31
62
  }
32
63
 
33
- export function uninstallLogBrewAndroidNativeDiagnostics() {
34
- requireAndroid();
35
- return receipt(
36
- "uninstall",
37
- call("uninstallAndroidDiagnostics"),
38
- new Set(["not_installed", "uninstalled"])
39
- );
64
+ /**
65
+ * @param {unknown} value
66
+ * @param {string} name
67
+ * @returns {string}
68
+ */
69
+ function exactScope(value, name) {
70
+ const text = exactText(value, SCOPE_BYTES, name);
71
+ if (!SCOPE_PATTERN.test(text)
72
+ || text.includes("..")
73
+ || text.includes("//")) {
74
+ throw configurationError(`${name} must be a bounded deployment identifier`);
75
+ }
76
+ return text;
40
77
  }
41
78
 
42
- function normalizeConfiguration(value) {
43
- if (!isObject(value)) {
79
+ /**
80
+ * @param {unknown} threshold
81
+ * @returns {number}
82
+ */
83
+ function anrThreshold(threshold) {
84
+ if (typeof threshold !== "number"
85
+ || !Number.isSafeInteger(threshold)
86
+ || threshold < MIN_ANR_THRESHOLD_MS
87
+ || threshold > MAX_ANR_THRESHOLD_MS) {
88
+ throw configurationError("anrThresholdMs must be an integer from 2000 through 60000");
89
+ }
90
+ return threshold;
91
+ }
92
+
93
+ /**
94
+ * @param {unknown} value
95
+ * @returns {Readonly<Record<string, unknown>>}
96
+ */
97
+ function knownConfiguration(value) {
98
+ if (!isRecord(value)) {
44
99
  throw configurationError("configuration must be an object");
45
100
  }
46
101
  for (const key of Object.keys(value)) {
@@ -48,53 +103,38 @@ function normalizeConfiguration(value) {
48
103
  throw configurationError("configuration contains an unsupported key");
49
104
  }
50
105
  }
51
- if (value.fatalHandlerOwnership !== "logbrew") {
106
+ if (value["fatalHandlerOwnership"] !== "logbrew") {
52
107
  throw configurationError(
53
108
  "fatalHandlerOwnership must be logbrew after removing every other Android fatal handler"
54
109
  );
55
110
  }
56
- const projectId = exactText(value.projectId, 64, "projectId");
57
- if (!/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/u.test(projectId)) {
111
+ return value;
112
+ }
113
+
114
+ /**
115
+ * @param {unknown} configuration
116
+ * @returns {Record<string, unknown>}
117
+ */
118
+ function normalizeConfiguration(configuration) {
119
+ const value = knownConfiguration(configuration);
120
+ const projectId = exactText(value["projectId"], PROJECT_ID_BYTES, "projectId");
121
+ if (!PROJECT_ID_PATTERN.test(projectId)) {
58
122
  throw configurationError("projectId must be a lowercase UUID");
59
123
  }
60
- const threshold = value.anrThresholdMs ?? 5000;
61
- if (!Number.isSafeInteger(threshold) || threshold < 2000 || threshold > 60000) {
62
- throw configurationError("anrThresholdMs must be an integer from 2000 through 60000");
63
- }
124
+ const threshold = anrThreshold(value["anrThresholdMs"] ?? DEFAULT_ANR_THRESHOLD_MS);
64
125
  return {
65
126
  anrThresholdMs: threshold,
66
- clientKey: exactText(value.clientKey, 4096, "clientKey"),
67
- environment: exactText(value.environment, 128, "environment"),
127
+ clientKey: exactText(value["clientKey"], CLIENT_KEY_BYTES, "clientKey"),
128
+ environment: exactText(value["environment"], ENVIRONMENT_BYTES, "environment"),
68
129
  fatalHandlerOwnership: "logbrew",
69
130
  projectId,
70
- release: exactText(value.release, 256, "release"),
71
- service: exactScope(value.service, "service")
131
+ release: exactText(value["release"], RELEASE_BYTES, "release"),
132
+ service: exactScope(value["service"], "service")
72
133
  };
73
134
  }
74
135
 
75
- function exactScope(value, name) {
76
- const text = exactText(value, 128, name);
77
- if (!/^[A-Za-z0-9][A-Za-z0-9._/-]{0,127}$/u.test(text)
78
- || text.includes("..")
79
- || text.includes("//")) {
80
- throw configurationError(`${name} must be a bounded deployment identifier`);
81
- }
82
- return text;
83
- }
84
-
85
- function exactText(value, maximumBytes, name) {
86
- if (typeof value !== "string"
87
- || value.length === 0
88
- || value.trim() !== value
89
- || controlCharacter(value)
90
- || utf8Length(value) > maximumBytes) {
91
- throw configurationError(`${name} must be a bounded non-empty string`);
92
- }
93
- return value;
94
- }
95
-
96
136
  function requireAndroid() {
97
- if (Platform?.OS !== "android") {
137
+ if (platformOS() !== "android") {
98
138
  throw new SdkError(
99
139
  "unsupported_platform",
100
140
  "LogBrew Android native diagnostics require an Android native build"
@@ -102,22 +142,32 @@ function requireAndroid() {
102
142
  }
103
143
  }
104
144
 
105
- function call(method, ...args) {
106
- let nativeModule;
145
+ /**
146
+ * @returns {unknown}
147
+ */
148
+ function fatalStoreModule() {
107
149
  try {
108
- nativeModule = TurboModuleRegistry?.get?.("LogBrewFatalStore")
109
- ?? NativeModules?.LogBrewFatalStore;
150
+ return lookupNativeModule("LogBrewFatalStore");
110
151
  } catch {
111
- nativeModule = undefined;
152
+ return undefined;
112
153
  }
113
- if (typeof nativeModule?.[method] !== "function") {
154
+ }
155
+
156
+ /**
157
+ * @param {string} method
158
+ * @param {readonly unknown[]} args
159
+ * @returns {unknown}
160
+ */
161
+ function call(method, ...args) {
162
+ const native = nativeMethod(fatalStoreModule(), method, args);
163
+ if (!native.found) {
114
164
  throw new SdkError(
115
165
  "native_diagnostics_unavailable",
116
166
  `linked LogBrew Android diagnostics do not implement ${method}`
117
167
  );
118
168
  }
119
169
  try {
120
- return nativeModule[method](...args);
170
+ return native.call();
121
171
  } catch {
122
172
  throw new SdkError(
123
173
  "native_diagnostics_failed",
@@ -126,23 +176,38 @@ function call(method, ...args) {
126
176
  }
127
177
  }
128
178
 
179
+ /**
180
+ * @param {unknown} value
181
+ * @param {Readonly<ReadonlySet<string>>} statuses
182
+ * @returns {value is Readonly<{ pending: number, status: ReceiptStatus }>}
183
+ */
184
+ function isReceipt(value, statuses) {
185
+ if (!isRecord(value)) {
186
+ return false;
187
+ }
188
+ const keys = Object.keys(value);
189
+ return keys.length === RECEIPT_KEYS.size
190
+ && keys.every(key => RECEIPT_KEYS.has(key))
191
+ && typeof value["status"] === "string"
192
+ && statuses.has(value["status"])
193
+ && isCount(value["pending"]);
194
+ }
195
+
196
+ /**
197
+ * @param {string} operation
198
+ * @param {unknown} value
199
+ * @param {Readonly<ReadonlySet<string>>} statuses
200
+ * @returns {LogBrewAndroidNativeDiagnosticsReceipt}
201
+ */
129
202
  function receipt(operation, value, statuses) {
130
- const keys = isObject(value) ? Object.keys(value) : [];
131
- if (isObject(value)
132
- && value.status === "error"
133
- && typeof value.code === "string"
134
- && /^[a-z0-9_]{1,128}$/u.test(value.code)) {
203
+ const code = isRecord(value) && value["status"] === "error" ? value["code"] : undefined;
204
+ if (typeof code === "string" && ERROR_CODE_PATTERN.test(code)) {
135
205
  throw new SdkError(
136
- value.code,
137
- `LogBrew Android native diagnostics ${operation} failed with ${value.code}`
206
+ code,
207
+ `LogBrew Android native diagnostics ${operation} failed with ${code}`
138
208
  );
139
209
  }
140
- if (!isObject(value)
141
- || keys.length !== RECEIPT_KEYS.size
142
- || !keys.every((key) => RECEIPT_KEYS.has(key))
143
- || !statuses.has(value.status)
144
- || !Number.isSafeInteger(value.pending)
145
- || value.pending < 0) {
210
+ if (!isReceipt(value, statuses)) {
146
211
  throw new SdkError(
147
212
  "native_diagnostics_invalid_response",
148
213
  `LogBrew Android native diagnostics ${operation} returned an invalid response`
@@ -151,26 +216,37 @@ function receipt(operation, value, statuses) {
151
216
  return Object.freeze({ pending: value.pending, status: value.status });
152
217
  }
153
218
 
154
- function isObject(value) {
155
- return value !== null && !Array.isArray(value) && typeof value === "object";
219
+ /**
220
+ * @param {unknown} [configuration]
221
+ * @returns {LogBrewAndroidNativeDiagnosticsReceipt}
222
+ */
223
+ function installLogBrewAndroidNativeDiagnostics(configuration = {}) {
224
+ requireAndroid();
225
+ return receipt(
226
+ "install",
227
+ call("installAndroidDiagnostics", normalizeConfiguration(configuration)),
228
+ INSTALL_STATUSES
229
+ );
156
230
  }
157
231
 
158
- function controlCharacter(value) {
159
- return Array.from(value).some((character) => {
160
- const code = character.codePointAt(0);
161
- return code <= 31 || (code >= 127 && code <= 159);
162
- });
232
+ /**
233
+ * @returns {LogBrewAndroidNativeDiagnosticsReceipt}
234
+ */
235
+ function getLogBrewAndroidNativeDiagnosticsStatus() {
236
+ requireAndroid();
237
+ return receipt("status", call("androidDiagnosticsStatus"), STATUS_STATUSES);
163
238
  }
164
239
 
165
- function utf8Length(value) {
166
- let length = 0;
167
- for (const character of value) {
168
- const code = character.codePointAt(0);
169
- length += code <= 127 ? 1 : code <= 2047 ? 2 : code <= 65535 ? 3 : 4;
170
- }
171
- return length;
240
+ /**
241
+ * @returns {LogBrewAndroidNativeDiagnosticsReceipt}
242
+ */
243
+ function uninstallLogBrewAndroidNativeDiagnostics() {
244
+ requireAndroid();
245
+ return receipt("uninstall", call("uninstallAndroidDiagnostics"), UNINSTALL_STATUSES);
172
246
  }
173
247
 
174
- function configurationError(message) {
175
- return new SdkError("configuration_error", `LogBrew Android native diagnostics ${message}`);
176
- }
248
+ export {
249
+ getLogBrewAndroidNativeDiagnosticsStatus,
250
+ installLogBrewAndroidNativeDiagnostics,
251
+ uninstallLogBrewAndroidNativeDiagnostics
252
+ };