@logbrew/react-native 0.1.30 → 0.1.32

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
@@ -597,9 +597,11 @@ source map. If an advanced build pipeline cannot use either integration,
597
597
  discovery. LogBrew records up to 32 ordered path-only generated frames with
598
598
  matching Debug IDs, release/environment/service/runtime, and active trace IDs
599
599
  when available. It strips query strings, hashes, hosts, and local absolute
600
- paths from React Native frame data; raw stack text is still opt-in with
601
- `includeStack: true`. Hosted source-map lookup remains backend-owned and
602
- requires the matching uploaded release artifact.
600
+ paths from React Native frame data. Grouping keeps an informative sanitized
601
+ path, or falls back to a safe function name and then generated position for a
602
+ root-only runtime URL; raw stack text is still opt-in with `includeStack: true`.
603
+ Hosted source-map lookup remains backend-owned and requires the matching
604
+ uploaded release artifact.
603
605
 
604
606
  ## Provider And Hooks
605
607
 
@@ -978,7 +980,7 @@ uploadLogBrewReactNativeReleaseArtifacts({
978
980
  });
979
981
  ```
980
982
 
981
- The helper requires explicit `release`, `environment`, `service`, and `platform` metadata. Hosted uploads also require a UUID `projectId`; local preparation and loopback upload remain valid without it. It defaults minified bundle URLs to `app:///react-native/<platform>/...`, removes query strings and hashes from manifest URLs, and strips source paths under `root` or `stripSourcePrefix`. Hosted endpoints must use HTTPS and must not include embedded auth values, query strings, or fragments. The helper never uses normal SDK ingest keys or account/session API auth values. When `sourcemap` points at a final Hermes-composed map, the helper makes the bundle's `sourceMappingURL` point at that explicit map, so stale packager-map comments do not block manifest generation. The explicit Metro wrapper changes only app-owned serialization and one bounded runtime Debug-ID registry; neither helper patches Gradle, Xcode, global fetch/XHR, request payloads, or transport behavior.
983
+ The helper requires explicit `release`, `environment`, `service`, and `platform` metadata. Hosted uploads also require a UUID `projectId`; local preparation and loopback upload remain valid without it. It defaults minified bundle URLs to `app:///react-native/<platform>/...`, removes query strings and hashes from manifest URLs, and strips source paths under `root` or `stripSourcePrefix`. Hosted endpoints must use HTTPS and must not include embedded auth values, query strings, or fragments. The helper never uses normal SDK ingest keys or account/session API auth values. For text bundles, `sourcemap` can name another file inside `buildDir` and the helper updates the bundle's `sourceMappingURL`. Final Hermes bytecode is never rewritten; stage its final composed map as `<bundle>.map`, as in the example above. The explicit Metro wrapper changes only app-owned serialization and one bounded runtime Debug-ID registry; neither helper patches Gradle, Xcode, global fetch/XHR, request payloads, or transport behavior.
982
984
 
983
985
  React Native native symbols are release artifacts, not runtime telemetry. Use
984
986
  the repository release-artifact tooling for local dry-run checks of app-owned
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.30";
19
+ const DEFAULT_SDK_VERSION = "0.1.32";
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;
@@ -650,7 +650,7 @@ function createReactNativeErrorEvent(error, {
650
650
  ...(stackFrames ? { stackFrames } : {}),
651
651
  title: `React Native error: ${details.message}`,
652
652
  message: details.message,
653
- metadata: sanitizeReactNativeIssueMetadata(attributes.metadata, compactMetadata)
653
+ metadata: sanitizeReactNativeIssueMetadata(attributes.metadata, compactMetadata, stackFrames)
654
654
  }
655
655
  };
656
656
  }
@@ -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.30"
6
+ private static let sdkVersion = "0.1.32"
7
7
 
8
8
  private let lock = NSLock()
9
9
  private let replayQueue = DispatchQueue(label: "co.logbrew.react-native.apple-diagnostics-replay")
package/metadata.cjs CHANGED
@@ -15,6 +15,7 @@ const REACT_NATIVE_DEBUG_ID_REGISTRY = Symbol.for("@logbrew/react-native/debug-i
15
15
  const SAFE_RELEASE_ARTIFACT_DEBUG_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu;
16
16
  const MAX_REACT_NATIVE_DEBUG_ID_REGISTRY_ENTRIES = 64;
17
17
  const MAX_REACT_NATIVE_DEBUG_ID_REGISTRY_FRAMES = 128;
18
+ const GENERIC_REACT_NATIVE_FRAME_FUNCTION = /^(?:<anonymous>|anonymous|apply|call|eval|global code|native|next)$/iu;
18
19
 
19
20
  function createSafeReactNativeMetadata(metadata, metadataFactory, context) {
20
21
  if (typeof metadataFactory !== "function") {
@@ -42,22 +43,29 @@ function safeReactNativeMetadataFactoryResult(candidate) {
42
43
  return metadata;
43
44
  }
44
45
 
45
- function sanitizeReactNativeIssueMetadata(metadata, compactMetadata) {
46
+ function sanitizeReactNativeIssueMetadata(metadata, compactMetadata, stackFrames) {
46
47
  const next = { ...metadata };
47
48
  for (const key of ["errorFrameFile", "releaseArtifactCodeFile"]) {
48
- const path = reactNativeCodePath(next[key]);
49
- if (path) {
50
- next[key] = path;
51
- }
49
+ next[key] = reactNativeCodePath(next[key]) ?? next[key];
52
50
  }
53
51
  const match = typeof next.issueGroupingKey === "string" ? next.issueGroupingKey.match(/^([^:]+):([^:]+):(.+)$/u) : null;
54
- const path = match ? reactNativeCodePath(match[3]) : undefined;
55
- if (path) {
56
- next.issueGroupingKey = `${match[1]}:${match[2]}:${path}`;
52
+ const identity = match ? reactNativeGroupingIdentity(reactNativeCodePath(match[3]), stackFrames) : undefined;
53
+ if (identity) {
54
+ next.issueGroupingKey = `${match[1]}:${match[2]}:${identity}`;
57
55
  }
58
56
  return compactMetadata(next);
59
57
  }
60
58
 
59
+ function reactNativeGroupingIdentity(path, stackFrames = []) {
60
+ if (path !== "/" || stackFrames.length === 0) {
61
+ return path;
62
+ }
63
+ const named = stackFrames.find(({ function: name }) => name && !GENERIC_REACT_NATIVE_FRAME_FUNCTION.test(name));
64
+ const frame = named ?? stackFrames[0];
65
+ return named ? `function=${named.function}`
66
+ : `position=${frame.line}:${frame.column}`;
67
+ }
68
+
61
69
  function sanitizeReactNativeIssueStackFrames(stackFrames) {
62
70
  if (!Array.isArray(stackFrames)) {
63
71
  return undefined;
package/metro.cjs CHANGED
@@ -8,6 +8,7 @@ const path = require("node:path");
8
8
  const DEBUG_ID_PLACEHOLDER = "__LOGBREW_REACT_NATIVE_DEBUG_ID__";
9
9
  const DEBUG_ID_MODULE_PATH = "__logbrew_debug_id__";
10
10
  const DEBUG_ID_REGISTRY_NAME = "@logbrew/react-native/debug-ids";
11
+ const RUNTIME_DEBUG_ID_MARKER = "/*logbrew-runtime-debug-id*/";
11
12
  const DEBUG_ID_KEYS = ["debug_id", "debugId", "debugID", "x_debug_id"];
12
13
  const DEBUG_ID_COMMENT_RE = /(?:\/\/[#@]|\/\*[#@])\s*debugId=[^\r\n]*/iu;
13
14
  const DEBUG_ID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu;
@@ -31,7 +32,8 @@ function requireOptions(options) {
31
32
  }
32
33
 
33
34
  function runtimeDebugIdSnippet(debugId) {
34
- return `;(()=>{try{const k=Symbol.for(${JSON.stringify(DEBUG_ID_REGISTRY_NAME)}),g=globalThis,r=g[k]||(g[k]=Object.create(null)),s=(new Error).stack;if(s){r[s]=${JSON.stringify(debugId)};const e=Object.keys(r);if(e.length>64)delete r[e[0]]}}catch{}})();`;
35
+ const embedded = `${RUNTIME_DEBUG_ID_MARKER}//# debugId=${debugId}`;
36
+ return `;(()=>{try{const d=${JSON.stringify(embedded)}.slice(-36),k=Symbol.for(${JSON.stringify(DEBUG_ID_REGISTRY_NAME)}),g=globalThis,r=g[k]||(g[k]=Object.create(null)),s=(new Error).stack;if(s){r[s]=d;const e=Object.keys(r);if(e.length>64)delete r[e[0]]}}catch{}})();`;
35
37
  }
36
38
 
37
39
  function countLines(source) {
@@ -147,7 +149,7 @@ function productionResult(result) {
147
149
  if (result.code.split(DEBUG_ID_PLACEHOLDER).length !== 2) {
148
150
  throw configurationError("LogBrew Metro production serializer must include the injected Debug ID module exactly once");
149
151
  }
150
- if (DEBUG_ID_COMMENT_RE.test(result.code)) {
152
+ if (DEBUG_ID_COMMENT_RE.test(result.code.replace(`${RUNTIME_DEBUG_ID_MARKER}//# debugId=${DEBUG_ID_PLACEHOLDER}`, ""))) {
151
153
  throw configurationError("LogBrew Metro production serializer already contains Debug ID metadata");
152
154
  }
153
155
  const sourceMap = parseSourceMap(result.map);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logbrew/react-native",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
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",
@@ -7,6 +7,9 @@ const path = require("node:path");
7
7
 
8
8
  const PACKAGE_DIR = path.dirname(require.resolve("./package.json"));
9
9
  const DEFAULT_MANIFEST_NAME = "logbrew-release-artifacts.json";
10
+ const HERMES_MAGIC = Buffer.from("c61fbc03c103191f", "hex");
11
+ const HERMES_RUNTIME_DEBUG_ID_RE =
12
+ /\/\*logbrew-runtime-debug-id\*\/\/\/# debugId=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}(?![0-9a-f-])/iu;
10
13
  const HOSTED_UPLOAD_ENDPOINT = "https://api.logbrew.co/api/release-artifacts";
11
14
  const SUPPORTED_PLATFORMS = new Set(["android", "ios"]);
12
15
  const SOURCE_MAPPING_COMMENT_RE = /(?:\/\/#|\/\*#)\s*sourceMappingURL=[^\r\n]*/giu;
@@ -176,8 +179,18 @@ function sourceWithSourceMappingUrl(source, reference) {
176
179
  }
177
180
 
178
181
  function applyExplicitSourceMapReference(bundlePath, sourcemapPath) {
182
+ const bundle = fs.readFileSync(bundlePath);
183
+ if (bundle.subarray(0, HERMES_MAGIC.length).equals(HERMES_MAGIC)) {
184
+ if (!HERMES_RUNTIME_DEBUG_ID_RE.test(bundle.toString("latin1"))) {
185
+ throw new Error("LogBrew React Native Hermes bytecode requires the LogBrew Metro wrapper");
186
+ }
187
+ if (sourcemapPath !== `${bundlePath}.map`) {
188
+ throw new Error("LogBrew React Native Hermes source map must use the bundle's sibling .map path");
189
+ }
190
+ return;
191
+ }
179
192
  const reference = sourceMapReferenceForBundle(bundlePath, sourcemapPath);
180
- const source = fs.readFileSync(bundlePath, "utf8");
193
+ const source = bundle.toString("utf8");
181
194
  const updated = sourceWithSourceMappingUrl(source, reference);
182
195
  if (updated !== source) {
183
196
  fs.writeFileSync(bundlePath, updated, "utf8");