@logbrew/react-native 0.1.7 → 0.1.9

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
@@ -71,6 +71,11 @@ export async function verifyLogBrewSetup() {
71
71
  }
72
72
  ```
73
73
 
74
+ Screen labels remain available as the original `metadata.screen` value. The
75
+ helper preserves an already machine-safe action name and otherwise normalizes
76
+ and bounds it for hosted ingestion, so labels such as `Checkout Complete` do
77
+ not cause a rejected batch.
78
+
74
79
  For mobile apps, prefer an app-scoped public key through `clientKey`. Expo
75
80
  inlines `EXPO_PUBLIC_*` values into the app, so never use a server key there.
76
81
  `apiKey` is still accepted for compatibility with lower-level SDK examples.
@@ -229,7 +234,30 @@ The callbacks match the common `(id, rejection)` and `(id)` tracker shapes, but
229
234
 
230
235
  `onUnhandled()` emits a fixed-content issue and deliberately does not inspect or send the rejection value, raw runtime rejection ID, error message, stack, Promise, or arbitrary metadata. Numeric IDs and bounded strings are retained only in local memory for duplicate suppression and `onHandled()` health. The set defaults to 128 entries and can be configured from 1 to 1024 with `maxTrackedRejections`; old entries are evicted. Missing or unsafe IDs still produce an untracked privacy-safe report. `onHandled()` updates local health only and cannot retract an issue that was already queued. Use `health()` for frozen counters and the last bounded outcome. Capture and diagnostic failures never escape these callbacks.
231
236
 
232
- When you prepare React Native release artifacts, wrap the app-owned Metro config once. Production bundles and source maps receive one matching Debug ID, while development and hot-reload serialization remain unchanged:
237
+ When you prepare Expo release artifacts, create the Expo Metro config through
238
+ LogBrew. The helper uses Expo's pre-serialization hook, so each production
239
+ bundle receives Expo's final Debug ID before Hermes compilation. Apply
240
+ the React Native Worklets bundle-mode transform after
241
+ `getLogBrewExpoConfig()`, as shown:
242
+
243
+ ```js
244
+ // metro.config.js
245
+ const { getLogBrewExpoConfig } = require("@logbrew/react-native/metro");
246
+ const { getBundleModeMetroConfig } = require("react-native-worklets/bundleMode");
247
+
248
+ const config = getLogBrewExpoConfig(__dirname);
249
+
250
+ module.exports = getBundleModeMetroConfig(config);
251
+ ```
252
+
253
+ Pass normal Expo Metro options directly to the helper. If the app owns a
254
+ custom `getDefaultConfig` function, pass it as the `getDefaultConfig` option.
255
+ Existing `unstable_beforeAssetSerializationPlugins` are preserved and run
256
+ before LogBrew's plugin.
257
+
258
+ Bare React Native apps should instead wrap the completed app-owned Metro
259
+ config once. Production bundles and source maps receive one matching Debug ID,
260
+ while development and hot-reload serialization remain unchanged:
233
261
 
234
262
  ```js
235
263
  // metro.config.js
@@ -241,6 +269,11 @@ module.exports = withLogBrewMetroConfig(
241
269
  );
242
270
  ```
243
271
 
272
+ Do not apply `withLogBrewMetroConfig()` to an Expo config. Expo static exports
273
+ return asset sets and can produce Hermes bytecode; the bare React Native
274
+ serializer wrapper stops with a recovery message that points to
275
+ `getLogBrewExpoConfig()` rather than producing an untraceable build.
276
+
244
277
  Then use the same release identity when capturing the error. The Metro-injected runtime registry connects each matching parsed JavaScript frame to its Debug ID without another app option:
245
278
 
246
279
  ```js
@@ -255,7 +288,18 @@ captureReactNativeError(client, error, {
255
288
  });
256
289
  ```
257
290
 
258
- The wrapper composes an existing custom serializer, is idempotent, and adds no network behavior. A string-returning custom serializer may preserve Metro's default bundle code; a serializer that changes code must return `{ code, map }` so LogBrew cannot attach a mismatched source map. If an advanced build pipeline cannot use the wrapper, `debugIdMap` remains an explicit override and takes precedence over runtime discovery. LogBrew records up to 32 ordered path-only generated frames with matching Debug IDs, release/environment/service/runtime, and active trace IDs when available. It strips query strings, hashes, hosts, and local absolute paths from React Native frame data; raw stack text is still opt-in with `includeStack: true`. Hosted source-map lookup remains backend-owned and requires the matching uploaded release artifact.
291
+ The Expo helper and bare wrapper add no network behavior. The bare wrapper
292
+ composes an existing custom serializer and is idempotent. A string-returning
293
+ custom serializer may preserve Metro's default bundle code; a serializer that
294
+ changes code must return `{ code, map }` so LogBrew cannot attach a mismatched
295
+ source map. If an advanced build pipeline cannot use either integration,
296
+ `debugIdMap` remains an explicit override and takes precedence over runtime
297
+ discovery. LogBrew records up to 32 ordered path-only generated frames with
298
+ matching Debug IDs, release/environment/service/runtime, and active trace IDs
299
+ when available. It strips query strings, hashes, hosts, and local absolute
300
+ paths from React Native frame data; raw stack text is still opt-in with
301
+ `includeStack: true`. Hosted source-map lookup remains backend-owned and
302
+ requires the matching uploaded release artifact.
259
303
 
260
304
  ## Provider And Hooks
261
305
 
package/index.cjs CHANGED
@@ -16,6 +16,8 @@ const {
16
16
  const DEFAULT_SDK_NAME = "logbrew-react-native";
17
17
  const DEFAULT_SDK_VERSION = "0.1.0";
18
18
  const DEFAULT_ENDPOINT = "https://api.logbrew.co/v1/events";
19
+ const MAX_ACTION_NAME_LENGTH = 64;
20
+ const SCREEN_ACTION_PREFIX = "screen:";
19
21
  const BACKGROUND_APP_STATES = new Set(["background", "inactive"]);
20
22
  const LogBrewNativeContext = React.createContext(null);
21
23
  const activeTraceScopes = [];
@@ -294,7 +296,7 @@ function captureScreenView(client, screenName, {
294
296
  requireClient(client);
295
297
  requireNonEmpty("screen name", screenName);
296
298
  client.action(id, timestamp, {
297
- name: `screen:${screenName}`,
299
+ name: screenActionName(screenName),
298
300
  status,
299
301
  metadata: {
300
302
  ...getReactNativeContext({ platform, appState }),
@@ -1023,6 +1025,22 @@ function slugify(value) {
1023
1025
  .replace(/^_+|_+$/g, "") || "event";
1024
1026
  }
1025
1027
 
1028
+ function screenActionName(screenName) {
1029
+ const directName = `${SCREEN_ACTION_PREFIX}${screenName}`;
1030
+ if (
1031
+ directName.length <= MAX_ACTION_NAME_LENGTH
1032
+ && /^[a-z0-9_.:-]+$/i.test(directName)
1033
+ ) {
1034
+ return directName;
1035
+ }
1036
+
1037
+ const maxScreenSegmentLength = MAX_ACTION_NAME_LENGTH - SCREEN_ACTION_PREFIX.length;
1038
+ const screenSegment = slugify(screenName)
1039
+ .slice(0, maxScreenSegmentLength)
1040
+ .replace(/_+$/g, "") || "event";
1041
+ return `${SCREEN_ACTION_PREFIX}${screenSegment}`;
1042
+ }
1043
+
1026
1044
  function statusFromStatusCode(statusCode) {
1027
1045
  if (typeof statusCode === "number" && Number.isFinite(statusCode) && statusCode >= 400) {
1028
1046
  return "failure";
package/index.js CHANGED
@@ -16,6 +16,8 @@ import {
16
16
  const DEFAULT_SDK_NAME = "logbrew-react-native";
17
17
  const DEFAULT_SDK_VERSION = "0.1.0";
18
18
  const DEFAULT_ENDPOINT = "https://api.logbrew.co/v1/events";
19
+ const MAX_ACTION_NAME_LENGTH = 64;
20
+ const SCREEN_ACTION_PREFIX = "screen:";
19
21
  const BACKGROUND_APP_STATES = new Set(["background", "inactive"]);
20
22
  const LogBrewNativeContext = React.createContext(null);
21
23
  const activeTraceScopes = [];
@@ -294,7 +296,7 @@ export function captureScreenView(client, screenName, {
294
296
  requireClient(client);
295
297
  requireNonEmpty("screen name", screenName);
296
298
  client.action(id, timestamp, {
297
- name: `screen:${screenName}`,
299
+ name: screenActionName(screenName),
298
300
  status,
299
301
  metadata: {
300
302
  ...getReactNativeContext({ platform, appState }),
@@ -1012,6 +1014,22 @@ function slugify(value) {
1012
1014
  .replace(/^_+|_+$/g, "") || "event";
1013
1015
  }
1014
1016
 
1017
+ function screenActionName(screenName) {
1018
+ const directName = `${SCREEN_ACTION_PREFIX}${screenName}`;
1019
+ if (
1020
+ directName.length <= MAX_ACTION_NAME_LENGTH
1021
+ && /^[a-z0-9_.:-]+$/i.test(directName)
1022
+ ) {
1023
+ return directName;
1024
+ }
1025
+
1026
+ const maxScreenSegmentLength = MAX_ACTION_NAME_LENGTH - SCREEN_ACTION_PREFIX.length;
1027
+ const screenSegment = slugify(screenName)
1028
+ .slice(0, maxScreenSegmentLength)
1029
+ .replace(/_+$/g, "") || "event";
1030
+ return `${SCREEN_ACTION_PREFIX}${screenSegment}`;
1031
+ }
1032
+
1015
1033
  function statusFromStatusCode(statusCode) {
1016
1034
  if (typeof statusCode === "number" && Number.isFinite(statusCode) && statusCode >= 400) {
1017
1035
  return "failure";
package/metro.cjs CHANGED
@@ -2,12 +2,15 @@
2
2
 
3
3
  const crypto = require("node:crypto");
4
4
  const { Buffer } = require("node:buffer");
5
+ const { createRequire } = require("node:module");
6
+ const path = require("node:path");
5
7
 
6
8
  const DEBUG_ID_PLACEHOLDER = "__LOGBREW_REACT_NATIVE_DEBUG_ID__";
7
9
  const DEBUG_ID_MODULE_PATH = "__logbrew_debug_id__";
8
10
  const DEBUG_ID_REGISTRY_NAME = "@logbrew/react-native/debug-ids";
9
11
  const DEBUG_ID_KEYS = ["debug_id", "debugId", "debugID", "x_debug_id"];
10
12
  const DEBUG_ID_COMMENT_RE = /(?:\/\/[#@]|\/\*[#@])\s*debugId=[^\r\n]*/iu;
13
+ 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;
11
14
  const SOURCE_MAPPING_COMMENT_RE = /(?:\/\/[#@]|\/\*[#@])\s*sourceMappingURL=[^\r\n]*/giu;
12
15
  const WRAPPED_SERIALIZER = Symbol.for("@logbrew/react-native/metro-serializer");
13
16
 
@@ -35,8 +38,8 @@ function countLines(source) {
35
38
  return source === "" ? 0 : source.split("\n").length;
36
39
  }
37
40
 
38
- function createDebugIdModule() {
39
- const code = runtimeDebugIdSnippet(DEBUG_ID_PLACEHOLDER);
41
+ function createDebugIdModule(debugId = DEBUG_ID_PLACEHOLDER) {
42
+ const code = runtimeDebugIdSnippet(debugId);
40
43
  return {
41
44
  dependencies: new Map(),
42
45
  getSource: () => Buffer.from(code),
@@ -55,14 +58,14 @@ function createDebugIdModule() {
55
58
  };
56
59
  }
57
60
 
58
- function prependDebugIdModule(preModules) {
61
+ function prependDebugIdModule(preModules, debugId = DEBUG_ID_PLACEHOLDER) {
59
62
  if (!Array.isArray(preModules)) {
60
63
  throw configurationError("LogBrew Metro serializer expected preModules to be an array");
61
64
  }
62
65
  if (preModules.some((module) => module?.path === DEBUG_ID_MODULE_PATH)) {
63
66
  return preModules;
64
67
  }
65
- const debugIdModule = createDebugIdModule();
68
+ const debugIdModule = createDebugIdModule(debugId);
66
69
  if (preModules[0]?.path === "__prelude__") {
67
70
  return [preModules[0], debugIdModule, ...preModules.slice(1)];
68
71
  }
@@ -130,7 +133,12 @@ function sourceWithDebugId(source, debugId) {
130
133
  }
131
134
 
132
135
  function productionResult(result) {
133
- if (!result || Array.isArray(result) || typeof result !== "object") {
136
+ if (Array.isArray(result)) {
137
+ throw configurationError(
138
+ "LogBrew Metro received Expo static assets; use getLogBrewExpoConfig instead of withLogBrewMetroConfig for Expo projects",
139
+ );
140
+ }
141
+ if (!result || typeof result !== "object") {
134
142
  throw configurationError("LogBrew Metro production serializer must return { code, map }");
135
143
  }
136
144
  if (typeof result.code !== "string") {
@@ -156,6 +164,81 @@ function productionResult(result) {
156
164
  };
157
165
  }
158
166
 
167
+ function requireExpoPluginOptions(options) {
168
+ requireOptions(options);
169
+ if (
170
+ options.unstable_beforeAssetSerializationPlugins !== undefined &&
171
+ (!Array.isArray(options.unstable_beforeAssetSerializationPlugins) ||
172
+ options.unstable_beforeAssetSerializationPlugins.some((plugin) => typeof plugin !== "function"))
173
+ ) {
174
+ throw configurationError(
175
+ "LogBrew Expo option unstable_beforeAssetSerializationPlugins must be an array of functions",
176
+ );
177
+ }
178
+ if (options.getDefaultConfig !== undefined && typeof options.getDefaultConfig !== "function") {
179
+ throw configurationError("LogBrew Expo option getDefaultConfig must be a function");
180
+ }
181
+ return options;
182
+ }
183
+
184
+ function createLogBrewExpoDebugIdPlugin(options = {}) {
185
+ requireOptions(options);
186
+ return (input) => {
187
+ if (!input || Array.isArray(input) || typeof input !== "object") {
188
+ throw configurationError("LogBrew Expo Debug ID plugin requires a serialization input object");
189
+ }
190
+ const preModules = input.premodules;
191
+ if (!Array.isArray(preModules)) {
192
+ throw configurationError("LogBrew Expo Debug ID plugin expected premodules to be an array");
193
+ }
194
+ if (options.enabled === false || input.debugId === undefined || input.debugId === null) {
195
+ return preModules;
196
+ }
197
+ if (typeof input.debugId !== "string" || !DEBUG_ID_RE.test(input.debugId)) {
198
+ throw configurationError("LogBrew Expo Debug ID plugin requires a valid Expo Debug ID");
199
+ }
200
+ return prependDebugIdModule(preModules, input.debugId.toLowerCase());
201
+ };
202
+ }
203
+
204
+ function loadExpoGetDefaultConfig(projectRoot) {
205
+ let expoMetroConfig;
206
+ try {
207
+ const projectRequire = createRequire(path.join(projectRoot, "package.json"));
208
+ expoMetroConfig = projectRequire("expo/metro-config");
209
+ } catch (error) {
210
+ throw configurationError(
211
+ "LogBrew could not load expo/metro-config from the app; install a supported Expo SDK or pass getDefaultConfig",
212
+ { cause: error },
213
+ );
214
+ }
215
+ if (typeof expoMetroConfig?.getDefaultConfig !== "function") {
216
+ throw configurationError("LogBrew could not resolve getDefaultConfig from expo/metro-config");
217
+ }
218
+ return expoMetroConfig.getDefaultConfig;
219
+ }
220
+
221
+ function getLogBrewExpoConfig(projectRoot, options = {}) {
222
+ if (typeof projectRoot !== "string" || projectRoot.trim() === "") {
223
+ throw configurationError("getLogBrewExpoConfig requires a non-empty Expo project root");
224
+ }
225
+ requireExpoPluginOptions(options);
226
+ const root = path.resolve(projectRoot);
227
+ const {
228
+ enabled = true,
229
+ getDefaultConfig = loadExpoGetDefaultConfig(root),
230
+ unstable_beforeAssetSerializationPlugins = [],
231
+ ...expoOptions
232
+ } = options;
233
+ const plugins = enabled
234
+ ? [...unstable_beforeAssetSerializationPlugins, createLogBrewExpoDebugIdPlugin()]
235
+ : [...unstable_beforeAssetSerializationPlugins];
236
+ return getDefaultConfig(root, {
237
+ ...expoOptions,
238
+ unstable_beforeAssetSerializationPlugins: plugins,
239
+ });
240
+ }
241
+
159
242
  function requireMetroModule(privatePath, sourcePath) {
160
243
  try {
161
244
  return require(privatePath);
@@ -305,6 +388,7 @@ function withLogBrewMetroConfig(config, options = {}) {
305
388
 
306
389
  module.exports = {
307
390
  createLogBrewMetroSerializer,
391
+ getLogBrewExpoConfig,
308
392
  withLogBrewMetroConfig,
309
393
  default: withLogBrewMetroConfig,
310
394
  };
package/metro.d.cts CHANGED
@@ -14,21 +14,41 @@ export type LogBrewMetroSerializer<TModule = unknown, TGraph = unknown, TOptions
14
14
  export type LogBrewMetroConfig = {
15
15
  serializer?: {
16
16
  customSerializer?: unknown;
17
- [key: string]: unknown;
18
- };
19
- [key: string]: unknown;
20
- };
17
+ } | Record<string, unknown>;
18
+ } | Record<string, unknown>;
21
19
 
22
20
  export type LogBrewMetroConfigOptions = {
23
21
  enabled?: boolean;
24
22
  };
25
23
 
24
+ export type LogBrewExpoSerializationInput<TModule = unknown, TGraph = unknown> = {
25
+ debugId?: string;
26
+ graph: TGraph;
27
+ premodules: TModule[];
28
+ };
29
+
30
+ export type LogBrewExpoDebugIdPlugin<TModule = unknown, TGraph = unknown> = (
31
+ input: LogBrewExpoSerializationInput<TModule, TGraph>,
32
+ ) => TModule[];
33
+
34
+ export type LogBrewExpoConfigOptions<TConfig extends LogBrewMetroConfig = LogBrewMetroConfig> = {
35
+ enabled?: boolean;
36
+ getDefaultConfig?: (...args: never[]) => TConfig;
37
+ unstable_beforeAssetSerializationPlugins?: LogBrewExpoDebugIdPlugin[];
38
+ [key: string]: unknown;
39
+ };
40
+
26
41
  export declare function createLogBrewMetroSerializer<TModule, TGraph, TOptions>(
27
42
  customSerializer: LogBrewMetroSerializer<TModule, TGraph, TOptions>,
28
43
  ): LogBrewMetroSerializer<TModule, TGraph, TOptions>;
29
44
 
30
45
  export declare function createLogBrewMetroSerializer(customSerializer?: null): LogBrewMetroSerializer;
31
46
 
47
+ export declare function getLogBrewExpoConfig<TConfig extends LogBrewMetroConfig = LogBrewMetroConfig>(
48
+ projectRoot: string,
49
+ options?: LogBrewExpoConfigOptions<TConfig>,
50
+ ): TConfig;
51
+
32
52
  export declare function withLogBrewMetroConfig<T extends LogBrewMetroConfig>(
33
53
  config: T,
34
54
  options?: LogBrewMetroConfigOptions,
package/metro.d.ts CHANGED
@@ -14,21 +14,41 @@ export type LogBrewMetroSerializer<TModule = unknown, TGraph = unknown, TOptions
14
14
  export type LogBrewMetroConfig = {
15
15
  serializer?: {
16
16
  customSerializer?: unknown;
17
- [key: string]: unknown;
18
- };
19
- [key: string]: unknown;
20
- };
17
+ } | Record<string, unknown>;
18
+ } | Record<string, unknown>;
21
19
 
22
20
  export type LogBrewMetroConfigOptions = {
23
21
  enabled?: boolean;
24
22
  };
25
23
 
24
+ export type LogBrewExpoSerializationInput<TModule = unknown, TGraph = unknown> = {
25
+ debugId?: string;
26
+ graph: TGraph;
27
+ premodules: TModule[];
28
+ };
29
+
30
+ export type LogBrewExpoDebugIdPlugin<TModule = unknown, TGraph = unknown> = (
31
+ input: LogBrewExpoSerializationInput<TModule, TGraph>,
32
+ ) => TModule[];
33
+
34
+ export type LogBrewExpoConfigOptions<TConfig extends LogBrewMetroConfig = LogBrewMetroConfig> = {
35
+ enabled?: boolean;
36
+ getDefaultConfig?: (...args: never[]) => TConfig;
37
+ unstable_beforeAssetSerializationPlugins?: LogBrewExpoDebugIdPlugin[];
38
+ [key: string]: unknown;
39
+ };
40
+
26
41
  export declare function createLogBrewMetroSerializer<TModule, TGraph, TOptions>(
27
42
  customSerializer: LogBrewMetroSerializer<TModule, TGraph, TOptions>,
28
43
  ): LogBrewMetroSerializer<TModule, TGraph, TOptions>;
29
44
 
30
45
  export declare function createLogBrewMetroSerializer(customSerializer?: null): LogBrewMetroSerializer;
31
46
 
47
+ export declare function getLogBrewExpoConfig<TConfig extends LogBrewMetroConfig = LogBrewMetroConfig>(
48
+ projectRoot: string,
49
+ options?: LogBrewExpoConfigOptions<TConfig>,
50
+ ): TConfig;
51
+
32
52
  export declare function withLogBrewMetroConfig<T extends LogBrewMetroConfig>(
33
53
  config: T,
34
54
  options?: LogBrewMetroConfigOptions,
package/metro.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import metro from "./metro.cjs";
2
2
 
3
3
  export const createLogBrewMetroSerializer = metro.createLogBrewMetroSerializer;
4
+ export const getLogBrewExpoConfig = metro.getLogBrewExpoConfig;
4
5
  export const withLogBrewMetroConfig = metro.withLogBrewMetroConfig;
5
6
 
6
7
  export default withLogBrewMetroConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logbrew/react-native",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "React Native screen, error, trace, action, and network timeline helpers for LogBrew.",
5
5
  "type": "module",
6
6
  "main": "./index.cjs",