@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,10 +1,14 @@
1
- import type { TelemetrySessionContext, TelemetrySubjectContext, TelemetryTraceContext } from "@logbrew/sdk";
1
+ import type {
2
+ TelemetrySessionContext,
3
+ TelemetrySubjectContext,
4
+ TelemetryTraceContext
5
+ } from "@logbrew/sdk";
2
6
 
3
7
  type LogBrewAppleNativeDiagnosticsAuth =
4
8
  | { apiKey: string; clientKey?: never }
5
9
  | { clientKey: string; apiKey?: never };
6
10
 
7
- export type LogBrewAppleNativeDiagnosticsConfiguration =
11
+ type LogBrewAppleNativeDiagnosticsConfiguration =
8
12
  LogBrewAppleNativeDiagnosticsAuth & {
9
13
  projectId: string;
10
14
  release: string;
@@ -18,7 +22,7 @@ export type LogBrewAppleNativeDiagnosticsConfiguration =
18
22
  endpoint?: string;
19
23
  };
20
24
 
21
- export type LogBrewAppleNativeDiagnosticsStatus = Readonly<{
25
+ type LogBrewAppleNativeDiagnosticsStatus = Readonly<{
22
26
  status: "already_installed" | "installed" | "not_installed" | "ready";
23
27
  lifecycle: "failed" | "idle" | "installed" | "replaying" | "stopped" | "unknown";
24
28
  pending: number;
@@ -26,7 +30,7 @@ export type LogBrewAppleNativeDiagnosticsStatus = Readonly<{
26
30
  discarded: number;
27
31
  }>;
28
32
 
29
- export type LogBrewAppleNativeDiagnosticsReplayResult = Readonly<{
33
+ type LogBrewAppleNativeDiagnosticsReplayResult = Readonly<{
30
34
  status: "replayed";
31
35
  attempted: number;
32
36
  acknowledged: number;
@@ -34,8 +38,10 @@ export type LogBrewAppleNativeDiagnosticsReplayResult = Readonly<{
34
38
  pending: number;
35
39
  }>;
36
40
 
37
- export type LogBrewAppleNativeCrashContext = {
38
- schemaVersion: 1;
41
+ declare const CRASH_CONTEXT_SCHEMA_VERSION = 1;
42
+
43
+ type LogBrewAppleNativeCrashContext = {
44
+ schemaVersion: typeof CRASH_CONTEXT_SCHEMA_VERSION;
39
45
  /** App-reported failed action and optional user-visible result. Never include raw input or identity. */
40
46
  impact?: {
41
47
  failedAction: string;
@@ -48,25 +54,35 @@ export type LogBrewAppleNativeCrashContext = {
48
54
  tags?: never;
49
55
  };
50
56
 
51
- export type LogBrewAppleNativeCrashContextResult = Readonly<{
57
+ type LogBrewAppleNativeCrashContextResult = Readonly<{
52
58
  status: "cleared" | "updated";
53
59
  }>;
54
60
 
55
- export declare function installLogBrewAppleNativeDiagnostics(
61
+ declare function installLogBrewAppleNativeDiagnostics(
56
62
  configuration: LogBrewAppleNativeDiagnosticsConfiguration
57
63
  ): LogBrewAppleNativeDiagnosticsStatus;
58
64
 
59
- export declare function replayLogBrewAppleNativeDiagnostics(): Promise<
65
+ declare function replayLogBrewAppleNativeDiagnostics(): Promise<
60
66
  LogBrewAppleNativeDiagnosticsReplayResult
61
67
  >;
62
68
 
63
- export declare function getLogBrewAppleNativeDiagnosticsStatus():
69
+ declare function getLogBrewAppleNativeDiagnosticsStatus():
64
70
  LogBrewAppleNativeDiagnosticsStatus;
65
71
 
66
- export declare function setLogBrewAppleNativeCrashContext(
72
+ declare function setLogBrewAppleNativeCrashContext(
67
73
  context: LogBrewAppleNativeCrashContext | null
68
74
  ): LogBrewAppleNativeCrashContextResult;
69
75
 
76
+ type LogBrewAppleNativeCrashBreadcrumbsSnapshot = Readonly<{
77
+ breadcrumbs: readonly Readonly<Record<string, unknown>>[];
78
+ schemaVersion: typeof CRASH_CONTEXT_SCHEMA_VERSION;
79
+ truncated: boolean;
80
+ }>;
81
+
82
+ declare function syncLogBrewAppleNativeCrashBreadcrumbs(
83
+ snapshot: LogBrewAppleNativeCrashBreadcrumbsSnapshot | null
84
+ ): LogBrewAppleNativeCrashContextResult;
85
+
70
86
  declare const defaultExport: {
71
87
  getLogBrewAppleNativeDiagnosticsStatus: typeof getLogBrewAppleNativeDiagnosticsStatus;
72
88
  installLogBrewAppleNativeDiagnostics: typeof installLogBrewAppleNativeDiagnostics;
@@ -74,4 +90,19 @@ declare const defaultExport: {
74
90
  setLogBrewAppleNativeCrashContext: typeof setLogBrewAppleNativeCrashContext;
75
91
  };
76
92
 
93
+ export type {
94
+ LogBrewAppleNativeCrashBreadcrumbsSnapshot,
95
+ LogBrewAppleNativeCrashContext,
96
+ LogBrewAppleNativeCrashContextResult,
97
+ LogBrewAppleNativeDiagnosticsConfiguration,
98
+ LogBrewAppleNativeDiagnosticsReplayResult,
99
+ LogBrewAppleNativeDiagnosticsStatus
100
+ };
101
+ export {
102
+ installLogBrewAppleNativeDiagnostics,
103
+ replayLogBrewAppleNativeDiagnostics,
104
+ getLogBrewAppleNativeDiagnosticsStatus,
105
+ setLogBrewAppleNativeCrashContext,
106
+ syncLogBrewAppleNativeCrashBreadcrumbs
107
+ };
77
108
  export default defaultExport;
@@ -1,17 +1,33 @@
1
+ import {
2
+ callNative,
3
+ requireApplePlatform,
4
+ requireNativeModule,
5
+ requireReplayResult,
6
+ requireStatusResult,
7
+ updateNativeSnapshot
8
+ } from "./apple-native-diagnostics-module.js";
1
9
  import { SdkError } from "@logbrew/sdk";
2
- import { NativeModules, Platform, TurboModuleRegistry } from "react-native";
3
-
10
+ import { normalizeConfiguration } from "./apple-native-diagnostics-config.js";
11
+ import { normalizeCorrelationContext } from "./apple-native-diagnostics-context.js";
12
+
13
+ /**
14
+ * @import {
15
+ * LogBrewAppleNativeCrashContextResult,
16
+ * LogBrewAppleNativeDiagnosticsReplayResult,
17
+ * LogBrewAppleNativeDiagnosticsStatus
18
+ * } from "./apple-native-diagnostics.js"
19
+ */
20
+
21
+ /** @type {ReadonlySet<string>} */
4
22
  const INSTALL_STATUSES = new Set(["already_installed", "installed"]);
5
- const LIFECYCLE_STATUSES = new Set([
6
- "failed",
7
- "idle",
8
- "installed",
9
- "replaying",
10
- "stopped",
11
- "unknown"
12
- ]);
13
-
14
- export function installLogBrewAppleNativeDiagnostics(configuration = {}) {
23
+ /** @type {ReadonlySet<string>} */
24
+ const STATUS_STATUSES = new Set(["not_installed", "ready"]);
25
+
26
+ /**
27
+ * @param {unknown} [configuration]
28
+ * @returns {LogBrewAppleNativeDiagnosticsStatus}
29
+ */
30
+ function installLogBrewAppleNativeDiagnostics(configuration = {}) {
15
31
  requireApplePlatform();
16
32
  const nativeModule = requireNativeModule();
17
33
  const payload = normalizeConfiguration(configuration);
@@ -19,12 +35,13 @@ export function installLogBrewAppleNativeDiagnostics(configuration = {}) {
19
35
  return requireStatusResult("install", result, INSTALL_STATUSES);
20
36
  }
21
37
 
22
- export async function replayLogBrewAppleNativeDiagnostics() {
23
- requireApplePlatform();
24
- const nativeModule = requireNativeModule();
25
- let result;
38
+ /**
39
+ * @param {unknown} nativeModule
40
+ * @returns {Promise<unknown>}
41
+ */
42
+ async function replayFromNative(nativeModule) {
26
43
  try {
27
- result = await callNative(nativeModule, "replayNativeDiagnostics");
44
+ return await callNative(nativeModule, "replayNativeDiagnostics");
28
45
  } catch (error) {
29
46
  if (error instanceof SdkError) {
30
47
  throw error;
@@ -34,389 +51,36 @@ export async function replayLogBrewAppleNativeDiagnostics() {
34
51
  "LogBrew Apple native diagnostics replay failed"
35
52
  );
36
53
  }
37
- return requireReplayResult(result);
38
54
  }
39
55
 
40
- export function getLogBrewAppleNativeDiagnosticsStatus() {
56
+ /**
57
+ * @returns {Promise<LogBrewAppleNativeDiagnosticsReplayResult>}
58
+ */
59
+ async function replayLogBrewAppleNativeDiagnostics() {
41
60
  requireApplePlatform();
42
61
  const nativeModule = requireNativeModule();
43
- const result = callNative(nativeModule, "nativeDiagnosticsStatus");
44
- return requireStatusResult("status", result, new Set(["not_installed", "ready"]));
62
+ return requireReplayResult(await replayFromNative(nativeModule));
45
63
  }
46
64
 
47
- export function setLogBrewAppleNativeCrashContext(context) {
65
+ /**
66
+ * @returns {LogBrewAppleNativeDiagnosticsStatus}
67
+ */
68
+ function getLogBrewAppleNativeDiagnosticsStatus() {
48
69
  requireApplePlatform();
49
70
  const nativeModule = requireNativeModule();
50
- const payload = context === null ? null : normalizeCorrelationContext(context);
51
- return updateNativeSnapshot(nativeModule, "setNativeDiagnosticsContext", payload, "context");
71
+ const result = callNative(nativeModule, "nativeDiagnosticsStatus");
72
+ return requireStatusResult("status", result, STATUS_STATUSES);
52
73
  }
53
74
 
54
- export function syncLogBrewAppleNativeCrashBreadcrumbs(snapshot) {
75
+ /**
76
+ * @param {unknown} context
77
+ * @returns {LogBrewAppleNativeCrashContextResult}
78
+ */
79
+ function setLogBrewAppleNativeCrashContext(context) {
55
80
  requireApplePlatform();
56
- return updateNativeSnapshot(
57
- requireNativeModule(),
58
- "setNativeDiagnosticsBreadcrumbs",
59
- snapshot,
60
- "breadcrumbs"
61
- );
62
- }
63
-
64
- function updateNativeSnapshot(nativeModule, method, payload, label) {
65
- const result = callNative(nativeModule, method, payload);
66
- const expectedStatus = payload === null ? "cleared" : "updated";
67
- if (isErrorResult(result)) {
68
- throw new SdkError(result.code, `LogBrew Apple native diagnostics ${label} failed with ${result.code}`);
69
- }
70
- if (!isPlainObject(result)
71
- || Object.keys(result).length !== 1
72
- || result.status !== expectedStatus) {
73
- throw new SdkError(
74
- "native_diagnostics_invalid_response",
75
- `LogBrew Apple native diagnostics ${label} returned an invalid response`
76
- );
77
- }
78
- return Object.freeze({ status: expectedStatus });
79
- }
80
-
81
- function normalizeConfiguration(configuration) {
82
- if (!configuration
83
- || Array.isArray(configuration)
84
- || typeof configuration !== "object") {
85
- throw configurationError("configuration must be an object");
86
- }
87
- const allowedKeys = new Set([
88
- "apiKey",
89
- "clientKey",
90
- "endpoint",
91
- "environment",
92
- "fatalHandlerOwnership",
93
- "hangThresholdSeconds",
94
- "projectId",
95
- "release",
96
- "service"
97
- ]);
98
- for (const key of Object.keys(configuration)) {
99
- if (!allowedKeys.has(key)) {
100
- throw configurationError(`configuration contains unsupported key ${JSON.stringify(key)}`);
101
- }
102
- }
103
- if (Object.prototype.hasOwnProperty.call(configuration, "apiKey")
104
- && Object.prototype.hasOwnProperty.call(configuration, "clientKey")) {
105
- throw configurationError("apiKey and clientKey are mutually exclusive");
106
- }
107
- const authKey = exactString(
108
- "apiKey or clientKey",
109
- configuration.clientKey ?? configuration.apiKey,
110
- 4096
111
- );
112
- const projectId = exactString("projectId", configuration.projectId, 64);
113
- if (!/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/u.test(projectId)) {
114
- throw configurationError("projectId must be a lowercase UUID");
115
- }
116
- if (configuration.fatalHandlerOwnership !== "logbrew") {
117
- throw configurationError(
118
- "fatalHandlerOwnership must be the exact string logbrew after confirming no other native fatal handler is installed"
119
- );
120
- }
121
-
122
- const payload = {
123
- apiKey: authKey,
124
- environment: exactString("environment", configuration.environment),
125
- fatalHandlerOwnership: "logbrew",
126
- projectId,
127
- release: exactString("release", configuration.release),
128
- service: exactString("service", configuration.service)
129
- };
130
- if (configuration.endpoint !== undefined) {
131
- payload.endpoint = exactDeliveryEndpoint(configuration.endpoint);
132
- }
133
- if (configuration.hangThresholdSeconds !== undefined) {
134
- const threshold = configuration.hangThresholdSeconds;
135
- if (typeof threshold !== "number"
136
- || !Number.isFinite(threshold)
137
- || threshold < 1
138
- || threshold > 30) {
139
- throw configurationError("hangThresholdSeconds must be a finite number from 1 through 30");
140
- }
141
- payload.hangThresholdSeconds = threshold;
142
- }
143
- return payload;
144
- }
145
-
146
- function normalizeCorrelationContext(context) {
147
- const source = exactObject(
148
- context,
149
- ["impact", "schemaVersion", "session", "subject", "trace"],
150
- "context"
151
- );
152
- if (source.schemaVersion !== 1) {
153
- throw configurationError("context schemaVersion must be 1");
154
- }
155
- const output = { schemaVersion: 1 };
156
- if (source.trace !== undefined) {
157
- const trace = exactObject(
158
- source.trace,
159
- ["parentSpanId", "sampled", "spanId", "traceId"],
160
- "context trace"
161
- );
162
- output.trace = { traceId: correlationHexId(trace.traceId, 32, "traceId") };
163
- for (const [key, width] of [["spanId", 16], ["parentSpanId", 16]]) {
164
- if (trace[key] !== undefined) {
165
- output.trace[key] = correlationHexId(trace[key], width, key);
166
- }
167
- }
168
- if (trace.sampled !== undefined) {
169
- if (typeof trace.sampled !== "boolean") {
170
- throw configurationError("context trace sampled must be a boolean");
171
- }
172
- output.trace.sampled = trace.sampled;
173
- }
174
- }
175
- if (source.session !== undefined) {
176
- const session = exactObject(source.session, ["id", "previousId"], "context session");
177
- output.session = { id: opaqueCorrelationId(session.id, "session id") };
178
- if (session.previousId !== undefined) {
179
- output.session.previousId = opaqueCorrelationId(session.previousId, "session previousId");
180
- if (output.session.previousId === output.session.id) {
181
- throw configurationError("context session previousId must differ from id");
182
- }
183
- }
184
- }
185
- if (source.subject !== undefined) {
186
- const subject = exactObject(source.subject, ["id", "kind"], "context subject");
187
- if (subject.kind !== "anonymous" && subject.kind !== "user") {
188
- throw configurationError("context subject kind must be anonymous or user");
189
- }
190
- output.subject = { id: opaqueCorrelationId(subject.id, "subject id"), kind: subject.kind };
191
- }
192
- if (source.impact !== undefined) {
193
- const impact = exactObject(
194
- source.impact,
195
- ["failedAction", "userVisibleOutcome"],
196
- "context impact"
197
- );
198
- output.impact = {
199
- failedAction: diagnosticText(impact.failedAction, 256, true, "failedAction")
200
- };
201
- if (impact.userVisibleOutcome !== undefined) {
202
- output.impact.userVisibleOutcome = diagnosticText(
203
- impact.userVisibleOutcome,
204
- 512,
205
- false,
206
- "userVisibleOutcome"
207
- );
208
- }
209
- }
210
- if (Object.keys(output).length === 1) {
211
- throw configurationError("context must include trace, session, subject, or impact");
212
- }
213
- return output;
214
- }
215
-
216
- function exactObject(value, allowedKeys, name) {
217
- if (!isPlainObject(value)) {
218
- throw configurationError(`${name} must be an object`);
219
- }
220
- const unknown = Object.keys(value).filter((key) => !allowedKeys.includes(key)).sort();
221
- if (unknown.length > 0) {
222
- throw configurationError(`${name} contains unsupported fields`);
223
- }
224
- return value;
225
- }
226
-
227
- function correlationHexId(value, width, name) {
228
- if (typeof value !== "string"
229
- || !new RegExp(`^[0-9a-f]{${width}}$`, "iu").test(value)
230
- || /^0+$/u.test(value)) {
231
- throw configurationError(`context trace ${name} must be a non-zero ${width}-character hex value`);
232
- }
233
- return value.toLowerCase();
234
- }
235
-
236
- function opaqueCorrelationId(value, name) {
237
- if (typeof value !== "string" || !/^[A-Za-z0-9][A-Za-z0-9_-]{0,199}$/u.test(value)) {
238
- throw configurationError(`context ${name} must be an opaque app-owned identifier`);
239
- }
240
- return value;
241
- }
242
-
243
- function diagnosticText(value, maximum, rejectLocationText, name) {
244
- const normalized = typeof value === "string" ? value.trim() : "";
245
- if (normalized.length === 0
246
- || Array.from(normalized).length > maximum
247
- || hasControlCharacter(normalized)
248
- || (rejectLocationText && /[?#]/u.test(normalized))) {
249
- throw configurationError(`context impact ${name} is invalid`);
250
- }
251
- return normalized;
252
- }
253
-
254
- function requireApplePlatform() {
255
- if (Platform?.OS !== "ios") {
256
- throw new SdkError(
257
- "unsupported_platform",
258
- "LogBrew Apple native diagnostics are available only in an iOS native build"
259
- );
260
- }
261
- }
262
-
263
- function requireNativeModule() {
264
- let nativeModule;
265
- try {
266
- nativeModule = TurboModuleRegistry?.get?.("LogBrewAppleDiagnostics")
267
- ?? NativeModules?.LogBrewAppleDiagnostics;
268
- } catch {
269
- nativeModule = undefined;
270
- }
271
- if (!nativeModule) {
272
- throw new SdkError(
273
- "native_diagnostics_unavailable",
274
- "LogBrew Apple native diagnostics require the AppleDiagnostics CocoaPods subspec; Expo projects can add @logbrew/react-native/expo"
275
- );
276
- }
277
- return nativeModule;
278
- }
279
-
280
- function callNative(nativeModule, method, ...args) {
281
- if (typeof nativeModule?.[method] !== "function") {
282
- throw new SdkError(
283
- "native_diagnostics_unavailable",
284
- `linked LogBrew Apple diagnostics do not implement ${method}`
285
- );
286
- }
287
- try {
288
- return nativeModule[method](...args);
289
- } catch {
290
- throw new SdkError(
291
- "native_diagnostics_failed",
292
- `LogBrew Apple native diagnostics ${method} failed`
293
- );
294
- }
295
- }
296
-
297
- function requireStatusResult(operation, result, allowedStatuses) {
298
- if (isErrorResult(result)) {
299
- throw new SdkError(
300
- result.code,
301
- `LogBrew Apple native diagnostics ${operation} failed with ${result.code}`
302
- );
303
- }
304
- if (!isPlainObject(result)
305
- || !allowedStatuses.has(result.status)
306
- || !LIFECYCLE_STATUSES.has(result.lifecycle)
307
- || !isCount(result.pending)
308
- || !isCount(result.acknowledged)
309
- || !isCount(result.discarded)) {
310
- throw new SdkError(
311
- "native_diagnostics_invalid_response",
312
- `LogBrew Apple native diagnostics ${operation} returned an invalid response`
313
- );
314
- }
315
- return Object.freeze({
316
- acknowledged: result.acknowledged,
317
- discarded: result.discarded,
318
- lifecycle: result.lifecycle,
319
- pending: result.pending,
320
- status: result.status
321
- });
322
- }
323
-
324
- function requireReplayResult(result) {
325
- if (isErrorResult(result)) {
326
- throw new SdkError(
327
- result.code,
328
- `LogBrew Apple native diagnostics replay failed with ${result.code}`
329
- );
330
- }
331
- if (!isPlainObject(result)
332
- || result.status !== "replayed"
333
- || !isCount(result.attempted)
334
- || !isCount(result.acknowledged)
335
- || !isCount(result.discarded)
336
- || !isCount(result.pending)
337
- || result.acknowledged + result.discarded > result.attempted) {
338
- throw new SdkError(
339
- "native_diagnostics_invalid_response",
340
- "LogBrew Apple native diagnostics replay returned an invalid response"
341
- );
342
- }
343
- return Object.freeze({
344
- acknowledged: result.acknowledged,
345
- attempted: result.attempted,
346
- discarded: result.discarded,
347
- pending: result.pending,
348
- status: result.status
349
- });
350
- }
351
-
352
- function isErrorResult(result) {
353
- return isPlainObject(result)
354
- && result.status === "error"
355
- && typeof result.code === "string"
356
- && /^[a-z0-9_]{1,128}$/u.test(result.code);
357
- }
358
-
359
- function isPlainObject(value) {
360
- return value !== null && !Array.isArray(value) && typeof value === "object";
361
- }
362
-
363
- function isCount(value) {
364
- return Number.isSafeInteger(value) && value >= 0;
365
- }
366
-
367
- function exactString(name, value, maxBytes = 256) {
368
- if (typeof value !== "string"
369
- || value.length === 0
370
- || value.trim() !== value
371
- || hasControlCharacter(value)
372
- || utf8Length(value) > maxBytes) {
373
- throw configurationError(`${name} must be a non-empty bounded string without surrounding whitespace or control characters`);
374
- }
375
- return value;
376
- }
377
-
378
- function exactDeliveryEndpoint(value) {
379
- const endpoint = exactString("endpoint", value, 2048);
380
- let parsed;
381
- try {
382
- parsed = new URL(endpoint);
383
- } catch {
384
- throw configurationError("endpoint must be an absolute HTTPS URL");
385
- }
386
- if (parsed.protocol !== "https:") {
387
- throw configurationError("endpoint must use HTTPS");
388
- }
389
- if (parsed.username
390
- || parsed.password
391
- || parsed.search
392
- || parsed.hash
393
- || endpoint !== `${parsed.origin}${parsed.pathname}`) {
394
- throw configurationError("endpoint must be a plain HTTPS path without embedded auth, query, or fragment values");
395
- }
396
- return endpoint;
397
- }
398
-
399
- function hasControlCharacter(value) {
400
- for (const scalar of value) {
401
- const codePoint = scalar.codePointAt(0);
402
- if (codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f)) {
403
- return true;
404
- }
405
- }
406
- return false;
407
- }
408
-
409
- function utf8Length(value) {
410
- let bytes = 0;
411
- for (const scalar of value) {
412
- const codePoint = scalar.codePointAt(0);
413
- bytes += codePoint <= 0x7f ? 1 : codePoint <= 0x7ff ? 2 : codePoint <= 0xffff ? 3 : 4;
414
- }
415
- return bytes;
416
- }
417
-
418
- function configurationError(message) {
419
- return new SdkError("configuration_error", `LogBrew Apple native diagnostics ${message}`);
81
+ const nativeModule = requireNativeModule();
82
+ const payload = context === null ? context : normalizeCorrelationContext(context);
83
+ return updateNativeSnapshot(nativeModule, payload, { label: "context", method: "setNativeDiagnosticsContext" });
420
84
  }
421
85
 
422
86
  const logBrewAppleNativeDiagnostics = {
@@ -426,4 +90,11 @@ const logBrewAppleNativeDiagnostics = {
426
90
  setLogBrewAppleNativeCrashContext
427
91
  };
428
92
 
93
+ export {
94
+ getLogBrewAppleNativeDiagnosticsStatus,
95
+ installLogBrewAppleNativeDiagnostics,
96
+ replayLogBrewAppleNativeDiagnostics,
97
+ setLogBrewAppleNativeCrashContext
98
+ };
99
+ export { syncLogBrewAppleNativeCrashBreadcrumbs } from "./apple-native-diagnostics-module.js";
429
100
  export default logBrewAppleNativeDiagnostics;
package/expo.cjs CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @import { ExpoConfig } from "expo/config"
3
+ * @import { LogBrewExpoPluginOptions } from "./expo.js"
4
+ */
5
+
1
6
  const PLUGIN_NAME = "@logbrew/react-native/expo";
2
7
  const START_MARKER = " # @generated by @logbrew/react-native/expo";
3
8
  const END_MARKER = " # @end @logbrew/react-native/expo";
@@ -10,31 +15,39 @@ const POD_BLOCK = [
10
15
  END_MARKER
11
16
  ].join("\n");
12
17
 
13
- function withLogBrewReactNative(config, options = {}) {
14
- const { withPodfile } = require("expo/config-plugins");
15
- const enabled = options?.appleNativeDiagnostics !== false;
16
- return withPodfile(config, podfileConfig => {
17
- const podfile = podfileConfig.modResults;
18
- podfile.contents = modifyPodfile(podfile.contents, enabled);
19
- return podfileConfig;
20
- });
21
- }
22
-
18
+ /**
19
+ * @param {unknown} contents
20
+ * @param {boolean} [enabled]
21
+ * @returns {string}
22
+ */
23
23
  function modifyPodfile(contents, enabled = true) {
24
24
  if (typeof contents !== "string") {
25
25
  throw new TypeError(`${PLUGIN_NAME} expected Podfile text`);
26
26
  }
27
- const withoutManagedBlock = contents.replace(MANAGED_BLOCK, "");
27
+ const withoutManagedBlock = contents.replaceAll(MANAGED_BLOCK, "");
28
28
  if (!enabled) {
29
29
  return withoutManagedBlock;
30
30
  }
31
- const targetPattern = /^(target\s+['"][^'"]+['"]\s+do\s*)$/mu;
31
+ const targetPattern = /^(?<target>target\s+['"][^'"]+['"]\s+do\s*)$/mu;
32
32
  if (!targetPattern.test(withoutManagedBlock)) {
33
33
  throw new Error(`${PLUGIN_NAME} could not locate an iOS application target in the Podfile`);
34
34
  }
35
- return withoutManagedBlock.replace(targetPattern, `$1\n${POD_BLOCK}`);
35
+ return withoutManagedBlock.replace(targetPattern, `$<target>\n${POD_BLOCK}`);
36
+ }
37
+
38
+ /**
39
+ * @param {ExpoConfig} config
40
+ * @param {Readonly<LogBrewExpoPluginOptions> | null} [options]
41
+ * @returns {ExpoConfig}
42
+ */
43
+ function withLogBrewReactNative(config, options = {}) {
44
+ const { withPodfile } = require("expo/config-plugins");
45
+ const enabled = options?.appleNativeDiagnostics !== false;
46
+ return withPodfile(config, podfileConfig => {
47
+ const podfile = podfileConfig.modResults;
48
+ podfile.contents = modifyPodfile(podfile.contents, enabled);
49
+ return podfileConfig;
50
+ });
36
51
  }
37
52
 
38
- module.exports = withLogBrewReactNative;
39
- module.exports.modifyPodfile = modifyPodfile;
40
- module.exports.withLogBrewReactNative = withLogBrewReactNative;
53
+ module.exports = Object.assign(withLogBrewReactNative, { modifyPodfile, withLogBrewReactNative });
package/expo.d.ts CHANGED
@@ -1,16 +1,17 @@
1
- export type LogBrewExpoPluginOptions = {
1
+ type LogBrewExpoPluginOptions = {
2
2
  /** Add the opt-in Apple native crash and app-hang CocoaPods subspec. Defaults to true. */
3
3
  appleNativeDiagnostics?: boolean;
4
4
  };
5
5
 
6
- export type ExpoConfigLike = Record<string, unknown>;
7
- export type LogBrewExpoConfigPlugin = (
8
- config: ExpoConfigLike,
9
- options?: LogBrewExpoPluginOptions
6
+ type ExpoConfigLike = Record<string, unknown>;
7
+ type LogBrewExpoConfigPlugin = (
8
+ config: Readonly<ExpoConfigLike>,
9
+ options?: Readonly<LogBrewExpoPluginOptions>
10
10
  ) => ExpoConfigLike;
11
11
 
12
- export declare const withLogBrewReactNative: LogBrewExpoConfigPlugin;
13
- export declare function modifyPodfile(contents: string, enabled?: boolean): string;
12
+ declare const withLogBrewReactNative: LogBrewExpoConfigPlugin;
13
+ declare function modifyPodfile(contents: string, enabled?: boolean): string;
14
14
 
15
- declare const defaultExport: LogBrewExpoConfigPlugin;
16
- export default defaultExport;
15
+ export type { ExpoConfigLike, LogBrewExpoConfigPlugin, LogBrewExpoPluginOptions };
16
+ export { modifyPodfile, withLogBrewReactNative };
17
+ export default withLogBrewReactNative;
package/expo.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import plugin from "./expo.cjs";
2
2
 
3
- export const modifyPodfile = plugin.modifyPodfile;
4
- export const withLogBrewReactNative = plugin.withLogBrewReactNative;
5
- export default plugin;
3
+ const { modifyPodfile, withLogBrewReactNative } = plugin;
4
+
5
+ export { modifyPodfile, withLogBrewReactNative };
6
+ export default withLogBrewReactNative;