@logbrew/react-native 0.1.19 → 0.1.21

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.
package/index.native.d.ts CHANGED
@@ -46,6 +46,7 @@ declare const defaultExport: Omit<
46
46
  installLogBrewAppleNativeDiagnostics: typeof import("./apple-native-diagnostics.js").installLogBrewAppleNativeDiagnostics;
47
47
  purgeLogBrewReactNativePersistentQueue: typeof purgeLogBrewReactNativePersistentQueue;
48
48
  replayLogBrewAppleNativeDiagnostics: typeof import("./apple-native-diagnostics.js").replayLogBrewAppleNativeDiagnostics;
49
+ setLogBrewAppleNativeCrashContext: typeof import("./apple-native-diagnostics.js").setLogBrewAppleNativeCrashContext;
49
50
  };
50
51
 
51
52
  export default defaultExport;
package/index.native.js CHANGED
@@ -13,7 +13,9 @@ import baseDefault from "./index.js";
13
13
  import {
14
14
  getLogBrewAppleNativeDiagnosticsStatus,
15
15
  installLogBrewAppleNativeDiagnostics,
16
- replayLogBrewAppleNativeDiagnostics
16
+ replayLogBrewAppleNativeDiagnostics,
17
+ setLogBrewAppleNativeCrashContext,
18
+ syncLogBrewAppleNativeCrashBreadcrumbs
17
19
  } from "./apple-native-diagnostics.js";
18
20
  import {
19
21
  purgeReactNativePersistentQueue,
@@ -26,7 +28,8 @@ export {
26
28
  export {
27
29
  getLogBrewAppleNativeDiagnosticsStatus,
28
30
  installLogBrewAppleNativeDiagnostics,
29
- replayLogBrewAppleNativeDiagnostics
31
+ replayLogBrewAppleNativeDiagnostics,
32
+ setLogBrewAppleNativeCrashContext
30
33
  };
31
34
 
32
35
  export * from "./index.js";
@@ -48,7 +51,7 @@ export function createLogBrewReactNativeClient(config = {}) {
48
51
  ) && input.persistentQueue !== undefined;
49
52
  const authKey = clientKey ?? apiKey;
50
53
  if (typeof authKey !== "string" || authKey.trim() === "") {
51
- return createPlatformNeutralClient(input);
54
+ return bindAppleNativeCrashBreadcrumbs(createPlatformNeutralClient(input));
52
55
  }
53
56
  const resolved = resolveReactNativePersistentEventStore({
54
57
  authKey,
@@ -59,20 +62,72 @@ export function createLogBrewReactNativeClient(config = {}) {
59
62
  hasExplicitPersistentQueue
60
63
  });
61
64
  try {
62
- return createPlatformNeutralClient({
65
+ return bindAppleNativeCrashBreadcrumbs(createPlatformNeutralClient({
63
66
  ...forwarded,
64
67
  apiKey,
65
68
  clientKey,
66
69
  eventStore: resolved.eventStore,
67
70
  maxQueueBytes,
68
71
  maxQueueSize
69
- });
72
+ }));
70
73
  } catch (error) {
71
74
  resolved.abort();
72
75
  throw error;
73
76
  }
74
77
  }
75
78
 
79
+ function bindAppleNativeCrashBreadcrumbs(client) {
80
+ if (Platform?.OS !== "ios") {
81
+ return client;
82
+ }
83
+ const addBreadcrumb = client.addBreadcrumb.bind(client);
84
+ const clearBreadcrumbs = client.clearBreadcrumbs.bind(client);
85
+ client.addBreadcrumb = (...args) => updateAppleNativeBreadcrumbs(
86
+ client, () => addBreadcrumb(...args)
87
+ );
88
+ client.clearBreadcrumbs = () => updateAppleNativeBreadcrumbs(client, clearBreadcrumbs);
89
+ syncAppleNativeCrashBreadcrumbs(client);
90
+ return client;
91
+ }
92
+
93
+ function updateAppleNativeBreadcrumbs(client, update) {
94
+ const previous = [client.issueBreadcrumbs.slice(), client.issueBreadcrumbsTruncated];
95
+ const result = update();
96
+ try {
97
+ syncAppleNativeCrashBreadcrumbs(client);
98
+ } catch (error) {
99
+ restoreBreadcrumbs(client, previous);
100
+ throw error;
101
+ }
102
+ return result;
103
+ }
104
+
105
+ function restoreBreadcrumbs(client, [breadcrumbs, truncated]) {
106
+ client.issueBreadcrumbs.splice(0, client.issueBreadcrumbs.length, ...breadcrumbs);
107
+ client.issueBreadcrumbsTruncated = truncated;
108
+ }
109
+
110
+ function syncAppleNativeCrashBreadcrumbs(client) {
111
+ const snapshot = client.issueBreadcrumbs.length === 0
112
+ ? null
113
+ : {
114
+ breadcrumbs: client.issueBreadcrumbs.map(({ data, ...breadcrumb }) => ({
115
+ ...breadcrumb,
116
+ ...(data === undefined ? {} : { data: { ...data } })
117
+ })),
118
+ schemaVersion: 1,
119
+ truncated: client.issueBreadcrumbsTruncated
120
+ };
121
+ try {
122
+ syncLogBrewAppleNativeCrashBreadcrumbs(snapshot);
123
+ } catch (error) {
124
+ if (error?.code !== "native_diagnostics_unavailable"
125
+ && error?.code !== "native_diagnostics_not_installed") {
126
+ throw error;
127
+ }
128
+ }
129
+ }
130
+
76
131
  export function purgeLogBrewReactNativePersistentQueue(config = {}) {
77
132
  purgeReactNativePersistentQueue(config);
78
133
  }
@@ -146,7 +201,8 @@ const defaultExport = {
146
201
  getLogBrewAppleNativeDiagnosticsStatus,
147
202
  installLogBrewAppleNativeDiagnostics,
148
203
  purgeLogBrewReactNativePersistentQueue,
149
- replayLogBrewAppleNativeDiagnostics
204
+ replayLogBrewAppleNativeDiagnostics,
205
+ setLogBrewAppleNativeCrashContext
150
206
  };
151
207
 
152
208
  export default defaultExport;