@logbrew/react-native 0.1.36 → 0.1.38

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/README.md CHANGED
@@ -122,6 +122,24 @@ client key before creating a new client. A `429` preserves the queue and
122
122
  reports `pausedReason: "rate_limit"` plus the bounded retry signal exposed by
123
123
  the failed flush.
124
124
 
125
+ ## Read Events Back
126
+
127
+ A successful send shows that LogBrew accepted the request. It does not show
128
+ that you can read the event. After your app sends one event, read it
129
+ back with a project read key:
130
+
131
+ ```bash
132
+ logbrew projects keys create "<project_id>" --kind read \
133
+ --ingest-key-file "$HOME/.logbrew/setup-check.read" --json
134
+ export LOGBREW_TOKEN="$(< "$HOME/.logbrew/setup-check.read")"
135
+ logbrew read logs --since 1h --json
136
+ logbrew issues --since 1h --json
137
+ ```
138
+
139
+ A read key reads 1 project and cannot send telemetry. Run `unset LOGBREW_TOKEN`
140
+ when you finish. [Read your events back](https://docs.logbrew.co/guides/verify-setup)
141
+ covers key kinds, empty results, and how to revoke the key.
142
+
125
143
  ## Offline And Restart Delivery
126
144
 
127
145
  The React Native entry uses an app-private native queue by default when the
@@ -166,6 +184,9 @@ delivery. When the queue is full, a fatal JavaScript report removes the oldest
166
184
  events that are not fatal and are not being sent, and counts each one as
167
185
  `evicted_for_fatal` in `deliveryHealth().droppedByReason`. The fatal is dropped
168
186
  only when the rest of the queue is fatal reports or a batch being sent.
187
+ Drop counts not yet reported to LogBrew are kept in a separate native queue,
188
+ so the next app start sends them, and a report that was already sent keeps
189
+ its `report_id` so LogBrew counts it once.
169
190
 
170
191
  A successful `shutdown()` drains and closes the queue. A failed flush or
171
192
  shutdown leaves the exact remainder available to the same client and the next
package/index.cjs CHANGED
@@ -16,7 +16,7 @@ const {
16
16
  } = require("./metadata.cjs");
17
17
 
18
18
  const DEFAULT_SDK_NAME = "logbrew-react-native";
19
- const DEFAULT_SDK_VERSION = "0.1.36";
19
+ const DEFAULT_SDK_VERSION = "0.1.38";
20
20
  const DEFAULT_ENDPOINT = "https://api.logbrew.co/v1/events";
21
21
  const NATIVE_RANDOM_HEX = Symbol.for("co.logbrew.react-native.secure-random-hex");
22
22
  const MAX_ACTION_NAME_LENGTH = 64;
@@ -368,6 +368,7 @@ function installGlobalXMLHttpRequestInstrumentation(client, {
368
368
  const doneState = typeof xhrType.DONE === "number" ? xhrType.DONE : 4;
369
369
  const safeRouteTemplateFactory = routeTemplateFactory ?? defaultXhrRouteTemplateFactory;
370
370
 
371
+ /** @this {XMLHttpRequest} */
371
372
  function wrappedOpen(method, url) {
372
373
  this[contextKey] = {
373
374
  method: normalizeXhrMethod(method),
@@ -377,6 +378,7 @@ function installGlobalXMLHttpRequestInstrumentation(client, {
377
378
  return originalOpen.apply(this, arguments);
378
379
  }
379
380
 
381
+ /** @this {XMLHttpRequest} */
380
382
  function wrappedSend(body) {
381
383
  const context = this[contextKey];
382
384
  if (!context) {
@@ -3,7 +3,7 @@ import Foundation
3
3
  @objc(LBRNAppleNativeDiagnostics)
4
4
  public final class LBRNAppleNativeDiagnostics: NSObject, @unchecked Sendable {
5
5
  private static let shared = LBRNAppleNativeDiagnostics()
6
- private static let sdkVersion = "0.1.36"
6
+ private static let sdkVersion = "0.1.38"
7
7
 
8
8
  private let lock = NSLock()
9
9
  private let replayQueue = DispatchQueue(label: "co.logbrew.react-native.apple-diagnostics-replay")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logbrew/react-native",
3
- "version": "0.1.36",
3
+ "version": "0.1.38",
4
4
  "description": "React Native offline delivery, native diagnostics, screen, error, trace, action, and network timeline helpers for LogBrew.",
5
5
  "type": "module",
6
6
  "main": "./index.cjs",
@@ -252,7 +252,7 @@
252
252
  "url": "git+https://github.com/LogBrewCo/sdk.git"
253
253
  },
254
254
  "peerDependencies": {
255
- "@logbrew/sdk": "^0.1.26",
255
+ "@logbrew/sdk": "^0.1.33",
256
256
  "expo": ">=49",
257
257
  "react": ">=18",
258
258
  "react-native": ">=0.72"
@@ -12,6 +12,8 @@ const NATIVE_STORE_METHODS = [
12
12
  "purgeEventRecords"
13
13
  ];
14
14
  const PERSISTENT_QUEUE_MODES = new Set(["auto", "disabled", "required"]);
15
+ // Drop counts live in a separate native queue, so existing native binaries keep them without changes.
16
+ const CLIENT_REPORT_QUEUE_SUFFIX = ":client-report";
15
17
 
16
18
  export function resolveReactNativePersistentEventStore({
17
19
  authKey,
@@ -122,6 +124,7 @@ export function purgeReactNativePersistentQueue({ apiKey, clientKey } = {}) {
122
124
  }
123
125
 
124
126
  function createNativeEventStore(nativeStore, authKey, release) {
127
+ const reportKey = `${authKey}${CLIENT_REPORT_QUEUE_SUFFIX}`;
125
128
  const eventStore = {
126
129
  load() {
127
130
  const result = requireStatus(
@@ -181,7 +184,42 @@ function createNativeEventStore(nativeStore, authKey, release) {
181
184
  "purged"
182
185
  );
183
186
  },
187
+ // Appends the new state before acknowledging the old one, so a crash keeps one of them.
188
+ loadClientReport() {
189
+ const { records } = requireStatus(
190
+ "load",
191
+ callNative(nativeStore, "loadEventRecords", reportKey),
192
+ "loaded"
193
+ );
194
+ const latest = Array.isArray(records) ? records.at(-1)?.serializedEvent : undefined;
195
+ return typeof latest === "string" ? JSON.parse(latest) : undefined;
196
+ },
197
+ saveClientReport(state) {
198
+ const { records } = requireStatus(
199
+ "load",
200
+ callNative(nativeStore, "loadEventRecords", reportKey),
201
+ "loaded"
202
+ );
203
+ const serialized = JSON.stringify(state);
204
+ requireStatus(
205
+ "append",
206
+ callNative(nativeStore, "appendEventRecord", reportKey, serialized, serialized.length),
207
+ "appended"
208
+ );
209
+ if (Array.isArray(records) && records.length > 0) {
210
+ requireStatus(
211
+ "acknowledge",
212
+ callNative(nativeStore, "acknowledgeEventRecords", reportKey, records.length),
213
+ "acknowledged"
214
+ );
215
+ }
216
+ },
184
217
  close() {
218
+ try {
219
+ callNative(nativeStore, "closeEventStore", reportKey);
220
+ } catch {
221
+ // The drop-count queue is advisory; closing the event queue decides the outcome.
222
+ }
185
223
  try {
186
224
  requireStatus(
187
225
  "close",