@logbrew/react-native 0.1.0 → 0.1.2

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 (51) hide show
  1. package/README.md +431 -18
  2. package/apollo.cjs +301 -0
  3. package/apollo.d.cts +70 -0
  4. package/apollo.d.ts +70 -0
  5. package/apollo.js +294 -0
  6. package/examples/apollo-link-spans.mjs +149 -0
  7. package/examples/index.mjs +29 -1
  8. package/examples/instrumentation-kit.mjs +304 -0
  9. package/examples/lifecycle-spans.mjs +131 -0
  10. package/examples/native-bridge-scope.mjs +107 -0
  11. package/examples/navigation-resource-spans.mjs +156 -0
  12. package/examples/package.json +8 -1
  13. package/examples/real-user-smoke.mjs +106 -9
  14. package/examples/resource-fetch-spans.mjs +133 -0
  15. package/examples/trace-correlation.mjs +135 -0
  16. package/global-errors.cjs +366 -0
  17. package/global-errors.d.cts +63 -0
  18. package/global-errors.d.ts +63 -0
  19. package/global-errors.js +7 -0
  20. package/index.cjs +625 -111
  21. package/index.d.cts +236 -0
  22. package/index.d.ts +236 -0
  23. package/index.js +613 -95
  24. package/index.native.js +18 -0
  25. package/instrumentation.cjs +639 -0
  26. package/instrumentation.d.cts +84 -0
  27. package/instrumentation.d.ts +84 -0
  28. package/instrumentation.js +634 -0
  29. package/lifecycle.cjs +129 -0
  30. package/lifecycle.d.cts +50 -0
  31. package/lifecycle.d.ts +50 -0
  32. package/lifecycle.js +121 -0
  33. package/metadata.cjs +175 -0
  34. package/metadata.js +165 -0
  35. package/metro.cjs +310 -0
  36. package/metro.d.cts +37 -0
  37. package/metro.d.ts +37 -0
  38. package/metro.js +6 -0
  39. package/native-bridge.cjs +127 -0
  40. package/native-bridge.d.cts +60 -0
  41. package/native-bridge.d.ts +60 -0
  42. package/native-bridge.js +125 -0
  43. package/package.json +128 -4
  44. package/release-artifacts.cjs +344 -0
  45. package/release-artifacts.d.cts +55 -0
  46. package/release-artifacts.d.ts +53 -0
  47. package/release-artifacts.js +8 -0
  48. package/resource-fetch.cjs +469 -0
  49. package/resource-fetch.d.cts +60 -0
  50. package/resource-fetch.d.ts +60 -0
  51. package/resource-fetch.js +464 -0
package/metro.cjs ADDED
@@ -0,0 +1,310 @@
1
+ "use strict";
2
+
3
+ const crypto = require("node:crypto");
4
+ const { Buffer } = require("node:buffer");
5
+
6
+ const DEBUG_ID_PLACEHOLDER = "__LOGBREW_REACT_NATIVE_DEBUG_ID__";
7
+ const DEBUG_ID_MODULE_PATH = "__logbrew_debug_id__";
8
+ const DEBUG_ID_REGISTRY_NAME = "@logbrew/react-native/debug-ids";
9
+ const DEBUG_ID_KEYS = ["debug_id", "debugId", "debugID", "x_debug_id"];
10
+ const DEBUG_ID_COMMENT_RE = /(?:\/\/[#@]|\/\*[#@])\s*debugId=[^\r\n]*/iu;
11
+ const SOURCE_MAPPING_COMMENT_RE = /(?:\/\/[#@]|\/\*[#@])\s*sourceMappingURL=[^\r\n]*/giu;
12
+ const WRAPPED_SERIALIZER = Symbol.for("@logbrew/react-native/metro-serializer");
13
+
14
+ function configurationError(message, options) {
15
+ const error = new Error(message, options);
16
+ error.code = "configuration_error";
17
+ return error;
18
+ }
19
+
20
+ function requireOptions(options) {
21
+ if (!options || Array.isArray(options) || typeof options !== "object") {
22
+ throw configurationError("LogBrew Metro options must be an object");
23
+ }
24
+ if (options.enabled !== undefined && typeof options.enabled !== "boolean") {
25
+ throw configurationError("LogBrew Metro option enabled must be a boolean");
26
+ }
27
+ return options;
28
+ }
29
+
30
+ function runtimeDebugIdSnippet(debugId) {
31
+ 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{}})();`;
32
+ }
33
+
34
+ function countLines(source) {
35
+ return source === "" ? 0 : source.split("\n").length;
36
+ }
37
+
38
+ function createDebugIdModule() {
39
+ const code = runtimeDebugIdSnippet(DEBUG_ID_PLACEHOLDER);
40
+ return {
41
+ dependencies: new Map(),
42
+ getSource: () => Buffer.from(code),
43
+ inverseDependencies: new Set(),
44
+ path: DEBUG_ID_MODULE_PATH,
45
+ output: [
46
+ {
47
+ type: "js/script/virtual",
48
+ data: {
49
+ code,
50
+ lineCount: countLines(code),
51
+ map: [],
52
+ },
53
+ },
54
+ ],
55
+ };
56
+ }
57
+
58
+ function prependDebugIdModule(preModules) {
59
+ if (!Array.isArray(preModules)) {
60
+ throw configurationError("LogBrew Metro serializer expected preModules to be an array");
61
+ }
62
+ if (preModules.some((module) => module?.path === DEBUG_ID_MODULE_PATH)) {
63
+ return preModules;
64
+ }
65
+ const debugIdModule = createDebugIdModule();
66
+ if (preModules[0]?.path === "__prelude__") {
67
+ return [preModules[0], debugIdModule, ...preModules.slice(1)];
68
+ }
69
+ return [debugIdModule, ...preModules];
70
+ }
71
+
72
+ function isDevelopmentGraph(graph) {
73
+ const transformOptions = graph?.transformOptions;
74
+ return transformOptions?.hot === true || transformOptions?.dev === true;
75
+ }
76
+
77
+ function parseSourceMap(value) {
78
+ if (typeof value !== "string" || value.trim() === "") {
79
+ throw configurationError("LogBrew Metro production serializer must return a non-empty source map string");
80
+ }
81
+ let sourceMap;
82
+ try {
83
+ sourceMap = JSON.parse(value);
84
+ } catch (error) {
85
+ throw configurationError(`LogBrew Metro production serializer returned invalid source map JSON: ${error.message}`);
86
+ }
87
+ if (!sourceMap || Array.isArray(sourceMap) || typeof sourceMap !== "object") {
88
+ throw configurationError("LogBrew Metro production serializer source map must be an object");
89
+ }
90
+ return sourceMap;
91
+ }
92
+
93
+ function canonicalSourceMap(sourceMap) {
94
+ const copy = { ...sourceMap };
95
+ for (const key of DEBUG_ID_KEYS) {
96
+ delete copy[key];
97
+ }
98
+ return JSON.stringify(copy);
99
+ }
100
+
101
+ function formatDebugId(bytes) {
102
+ const value = Buffer.from(bytes.subarray(0, 16));
103
+ value[6] = (value[6] & 0x0f) | 0x50;
104
+ value[8] = (value[8] & 0x3f) | 0x80;
105
+ const hex = value.toString("hex");
106
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
107
+ }
108
+
109
+ function createDebugId(code, sourceMap) {
110
+ const digest = crypto
111
+ .createHash("sha256")
112
+ .update(code.split(DEBUG_ID_PLACEHOLDER).join(""))
113
+ .update("\0")
114
+ .update(canonicalSourceMap(sourceMap))
115
+ .digest();
116
+ return formatDebugId(digest);
117
+ }
118
+
119
+ function sourceWithDebugId(source, debugId) {
120
+ const replaced = source.split(DEBUG_ID_PLACEHOLDER).join(debugId);
121
+ const debugLine = `//# debugId=${debugId}\n`;
122
+ const matches = [...replaced.matchAll(SOURCE_MAPPING_COMMENT_RE)];
123
+ if (matches.length === 0) {
124
+ return `${replaced}${replaced.endsWith("\n") ? "" : "\n"}${debugLine}`;
125
+ }
126
+ const last = matches.at(-1);
127
+ const prefix = replaced.slice(0, last.index);
128
+ const separator = prefix.endsWith("\n") || prefix.endsWith("\r") ? "" : "\n";
129
+ return `${prefix}${separator}${debugLine}${replaced.slice(last.index)}`;
130
+ }
131
+
132
+ function productionResult(result) {
133
+ if (!result || Array.isArray(result) || typeof result !== "object") {
134
+ throw configurationError("LogBrew Metro production serializer must return { code, map }");
135
+ }
136
+ if (typeof result.code !== "string") {
137
+ throw configurationError("LogBrew Metro production serializer code must be a string");
138
+ }
139
+ if (result.code.split(DEBUG_ID_PLACEHOLDER).length !== 2) {
140
+ throw configurationError("LogBrew Metro production serializer must include the injected Debug ID module exactly once");
141
+ }
142
+ if (DEBUG_ID_COMMENT_RE.test(result.code)) {
143
+ throw configurationError("LogBrew Metro production serializer already contains Debug ID metadata");
144
+ }
145
+ const sourceMap = parseSourceMap(result.map);
146
+ if (DEBUG_ID_KEYS.some((key) => Object.prototype.hasOwnProperty.call(sourceMap, key))) {
147
+ throw configurationError("LogBrew Metro production serializer already contains Debug ID metadata");
148
+ }
149
+ const debugId = createDebugId(result.code, sourceMap);
150
+ sourceMap.debug_id = debugId;
151
+ sourceMap.debugId = debugId;
152
+ return {
153
+ ...result,
154
+ code: sourceWithDebugId(result.code, debugId),
155
+ map: JSON.stringify(sourceMap),
156
+ };
157
+ }
158
+
159
+ function requireMetroModule(privatePath, sourcePath) {
160
+ try {
161
+ return require(privatePath);
162
+ } catch (privateError) {
163
+ try {
164
+ return require(sourcePath);
165
+ } catch {
166
+ throw configurationError(
167
+ `LogBrew Metro could not load ${privatePath}; install a supported React Native Metro package`,
168
+ { cause: privateError },
169
+ );
170
+ }
171
+ }
172
+ }
173
+
174
+ function moduleFunction(moduleValue, names, label) {
175
+ if (typeof moduleValue === "function") {
176
+ return moduleValue;
177
+ }
178
+ for (const name of names) {
179
+ if (typeof moduleValue?.[name] === "function") {
180
+ return moduleValue[name];
181
+ }
182
+ }
183
+ throw configurationError(`LogBrew Metro could not resolve ${label} from the installed Metro package`);
184
+ }
185
+
186
+ function sortedModules(graph, options) {
187
+ const modules = [...(graph?.dependencies?.values?.() ?? [])];
188
+ if (typeof options?.createModuleId !== "function") {
189
+ return modules;
190
+ }
191
+ return modules.sort((left, right) => options.createModuleId(left.path) - options.createModuleId(right.path));
192
+ }
193
+
194
+ function createMetroSourceMapSerializer() {
195
+ const sourceMapModule = requireMetroModule(
196
+ "metro/private/DeltaBundler/Serializers/sourceMapString",
197
+ "metro/src/DeltaBundler/Serializers/sourceMapString",
198
+ );
199
+ const sourceMapString = moduleFunction(
200
+ sourceMapModule,
201
+ ["sourceMapStringNonBlocking", "sourceMapString", "default"],
202
+ "sourceMapString",
203
+ );
204
+
205
+ return (preModules, graph, options) =>
206
+ sourceMapString([...preModules, ...sortedModules(graph, options)], {
207
+ excludeSource: options?.excludeSource === true,
208
+ getSourceUrl: typeof options?.getSourceUrl === "function" ? options.getSourceUrl : null,
209
+ processModuleFilter: typeof options?.processModuleFilter === "function" ? options.processModuleFilter : () => true,
210
+ shouldAddToIgnoreList:
211
+ typeof options?.shouldAddToIgnoreList === "function" ? options.shouldAddToIgnoreList : () => false,
212
+ });
213
+ }
214
+
215
+ function createDefaultMetroSerializer() {
216
+ const baseJSBundle = moduleFunction(
217
+ requireMetroModule(
218
+ "metro/private/DeltaBundler/Serializers/baseJSBundle",
219
+ "metro/src/DeltaBundler/Serializers/baseJSBundle",
220
+ ),
221
+ ["baseJSBundle", "default"],
222
+ "baseJSBundle",
223
+ );
224
+ const bundleToString = moduleFunction(
225
+ requireMetroModule("metro/private/lib/bundleToString", "metro/src/lib/bundleToString"),
226
+ ["bundleToString", "default"],
227
+ "bundleToString",
228
+ );
229
+ const serializeSourceMap = createMetroSourceMapSerializer();
230
+
231
+ return async (entryPoint, preModules, graph, options) => {
232
+ const code = bundleToString(baseJSBundle(entryPoint, preModules, graph, options)).code;
233
+ if (isDevelopmentGraph(graph)) {
234
+ return code;
235
+ }
236
+ const map = await serializeSourceMap(preModules, graph, options);
237
+ return { code, map };
238
+ };
239
+ }
240
+
241
+ function createLogBrewMetroSerializer(customSerializer) {
242
+ if (customSerializer !== undefined && customSerializer !== null && typeof customSerializer !== "function") {
243
+ throw configurationError("LogBrew Metro custom serializer must be a function");
244
+ }
245
+ if (customSerializer?.[WRAPPED_SERIALIZER] === true) {
246
+ return customSerializer;
247
+ }
248
+
249
+ let serializerSource = customSerializer ?? undefined;
250
+ let fallbackSerializer;
251
+ const resolveSerializer = () => {
252
+ serializerSource ??= createDefaultMetroSerializer();
253
+ return serializerSource;
254
+ };
255
+ const resolveFallbackSerializer = () => {
256
+ fallbackSerializer ??= createDefaultMetroSerializer();
257
+ return fallbackSerializer;
258
+ };
259
+
260
+ const serializer = async (entryPoint, preModules, graph, options) => {
261
+ const source = resolveSerializer();
262
+ if (isDevelopmentGraph(graph)) {
263
+ return source(entryPoint, preModules, graph, options);
264
+ }
265
+ const releaseModules = prependDebugIdModule(preModules);
266
+ const result = await source(entryPoint, releaseModules, graph, options);
267
+ if (typeof result === "string") {
268
+ const fallbackResult = await resolveFallbackSerializer()(entryPoint, releaseModules, graph, options);
269
+ if (typeof fallbackResult === "string" || fallbackResult.code !== result) {
270
+ throw configurationError(
271
+ "LogBrew Metro string-returning custom serializer changed bundle code; return { code, map } to preserve source-map accuracy",
272
+ );
273
+ }
274
+ return productionResult(fallbackResult);
275
+ }
276
+ return productionResult(result);
277
+ };
278
+ Object.defineProperty(serializer, WRAPPED_SERIALIZER, { value: true });
279
+ return serializer;
280
+ }
281
+
282
+ function withLogBrewMetroConfig(config, options = {}) {
283
+ requireOptions(options);
284
+ if (!config || Array.isArray(config) || typeof config !== "object") {
285
+ throw configurationError("withLogBrewMetroConfig requires a Metro config object");
286
+ }
287
+ if (options.enabled === false) {
288
+ return config;
289
+ }
290
+ const serializerConfig = config.serializer ?? {};
291
+ if (!serializerConfig || Array.isArray(serializerConfig) || typeof serializerConfig !== "object") {
292
+ throw configurationError("withLogBrewMetroConfig requires config.serializer to be an object");
293
+ }
294
+ if (serializerConfig.customSerializer?.[WRAPPED_SERIALIZER] === true) {
295
+ return config;
296
+ }
297
+ return {
298
+ ...config,
299
+ serializer: {
300
+ ...serializerConfig,
301
+ customSerializer: createLogBrewMetroSerializer(serializerConfig.customSerializer),
302
+ },
303
+ };
304
+ }
305
+
306
+ module.exports = {
307
+ createLogBrewMetroSerializer,
308
+ withLogBrewMetroConfig,
309
+ default: withLogBrewMetroConfig,
310
+ };
package/metro.d.cts ADDED
@@ -0,0 +1,37 @@
1
+ export type LogBrewMetroSerializerResult = string | {
2
+ code: string;
3
+ map: string;
4
+ [key: string]: unknown;
5
+ };
6
+
7
+ export type LogBrewMetroSerializer<TModule = unknown, TGraph = unknown, TOptions = unknown> = (
8
+ entryPoint: string,
9
+ preModules: readonly TModule[],
10
+ graph: TGraph,
11
+ options: TOptions,
12
+ ) => LogBrewMetroSerializerResult | Promise<LogBrewMetroSerializerResult>;
13
+
14
+ export type LogBrewMetroConfig = {
15
+ serializer?: {
16
+ customSerializer?: unknown;
17
+ [key: string]: unknown;
18
+ };
19
+ [key: string]: unknown;
20
+ };
21
+
22
+ export type LogBrewMetroConfigOptions = {
23
+ enabled?: boolean;
24
+ };
25
+
26
+ export declare function createLogBrewMetroSerializer<TModule, TGraph, TOptions>(
27
+ customSerializer: LogBrewMetroSerializer<TModule, TGraph, TOptions>,
28
+ ): LogBrewMetroSerializer<TModule, TGraph, TOptions>;
29
+
30
+ export declare function createLogBrewMetroSerializer(customSerializer?: null): LogBrewMetroSerializer;
31
+
32
+ export declare function withLogBrewMetroConfig<T extends LogBrewMetroConfig>(
33
+ config: T,
34
+ options?: LogBrewMetroConfigOptions,
35
+ ): T;
36
+
37
+ export default withLogBrewMetroConfig;
package/metro.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ export type LogBrewMetroSerializerResult = string | {
2
+ code: string;
3
+ map: string;
4
+ [key: string]: unknown;
5
+ };
6
+
7
+ export type LogBrewMetroSerializer<TModule = unknown, TGraph = unknown, TOptions = unknown> = (
8
+ entryPoint: string,
9
+ preModules: readonly TModule[],
10
+ graph: TGraph,
11
+ options: TOptions,
12
+ ) => LogBrewMetroSerializerResult | Promise<LogBrewMetroSerializerResult>;
13
+
14
+ export type LogBrewMetroConfig = {
15
+ serializer?: {
16
+ customSerializer?: unknown;
17
+ [key: string]: unknown;
18
+ };
19
+ [key: string]: unknown;
20
+ };
21
+
22
+ export type LogBrewMetroConfigOptions = {
23
+ enabled?: boolean;
24
+ };
25
+
26
+ export declare function createLogBrewMetroSerializer<TModule, TGraph, TOptions>(
27
+ customSerializer: LogBrewMetroSerializer<TModule, TGraph, TOptions>,
28
+ ): LogBrewMetroSerializer<TModule, TGraph, TOptions>;
29
+
30
+ export declare function createLogBrewMetroSerializer(customSerializer?: null): LogBrewMetroSerializer;
31
+
32
+ export declare function withLogBrewMetroConfig<T extends LogBrewMetroConfig>(
33
+ config: T,
34
+ options?: LogBrewMetroConfigOptions,
35
+ ): T;
36
+
37
+ export default withLogBrewMetroConfig;
package/metro.js ADDED
@@ -0,0 +1,6 @@
1
+ import metro from "./metro.cjs";
2
+
3
+ export const createLogBrewMetroSerializer = metro.createLogBrewMetroSerializer;
4
+ export const withLogBrewMetroConfig = metro.withLogBrewMetroConfig;
5
+
6
+ export default withLogBrewMetroConfig;
@@ -0,0 +1,127 @@
1
+ const { SdkError } = require("@logbrew/sdk");
2
+ const {
3
+ getActiveLogBrewTrace,
4
+ getReactNativeTraceMetadata
5
+ } = require("./index.cjs");
6
+
7
+ const DEFAULT_SCOPE_SOURCE = "react-native.native_bridge";
8
+ const RESERVED_TRACE_METADATA_KEYS = new Set([
9
+ "parentSpanId",
10
+ "spanId",
11
+ "traceFlags",
12
+ "traceId",
13
+ "traceSampled",
14
+ "traceparent"
15
+ ]);
16
+
17
+ function createLogBrewNativeBridgeScope({
18
+ logger,
19
+ metadata = {},
20
+ screen,
21
+ sessionId,
22
+ source = DEFAULT_SCOPE_SOURCE,
23
+ trace = getActiveLogBrewTrace()
24
+ } = {}) {
25
+ const traceMetadata = getReactNativeTraceMetadata(trace);
26
+ return {
27
+ trace: Object.keys(traceMetadata).length === 0 ? undefined : {
28
+ parentSpanId: traceMetadata.parentSpanId,
29
+ spanId: traceMetadata.spanId,
30
+ traceFlags: traceMetadata.traceFlags,
31
+ traceId: traceMetadata.traceId,
32
+ traceSampled: traceMetadata.traceSampled
33
+ },
34
+ metadata: compactMetadata({
35
+ ...metadata,
36
+ logger,
37
+ screen,
38
+ sessionId,
39
+ source
40
+ })
41
+ };
42
+ }
43
+
44
+ function syncLogBrewNativeBridgeScope(nativeBridge, options = {}) {
45
+ const payload = createLogBrewNativeBridgeScope(options);
46
+ bridgeSync(nativeBridge)(payload);
47
+ return payload;
48
+ }
49
+
50
+ function clearLogBrewNativeBridgeScope(nativeBridge) {
51
+ bridgeClear(nativeBridge)();
52
+ }
53
+
54
+ function withLogBrewNativeBridgeScope(nativeBridge, options, callback) {
55
+ const resolvedOptions = typeof options === "function" ? {} : options ?? {};
56
+ const resolvedCallback = typeof options === "function" ? options : callback;
57
+ if (typeof resolvedCallback !== "function") {
58
+ throw new SdkError("configuration_error", "withLogBrewNativeBridgeScope requires a callback");
59
+ }
60
+
61
+ const payload = syncLogBrewNativeBridgeScope(nativeBridge, resolvedOptions);
62
+ try {
63
+ const result = resolvedCallback(payload);
64
+ if (result && typeof result.then === "function") {
65
+ return Promise.resolve(result).finally(() => clearLogBrewNativeBridgeScope(nativeBridge));
66
+ }
67
+ clearLogBrewNativeBridgeScope(nativeBridge);
68
+ return result;
69
+ } catch (error) {
70
+ clearLogBrewNativeBridgeScope(nativeBridge);
71
+ throw error;
72
+ }
73
+ }
74
+
75
+ function bridgeSync(nativeBridge) {
76
+ if (typeof nativeBridge === "function") {
77
+ return nativeBridge;
78
+ }
79
+ if (nativeBridge && typeof nativeBridge.setLogBrewScope === "function") {
80
+ return nativeBridge.setLogBrewScope.bind(nativeBridge);
81
+ }
82
+ if (nativeBridge && typeof nativeBridge.syncLogBrewScope === "function") {
83
+ return nativeBridge.syncLogBrewScope.bind(nativeBridge);
84
+ }
85
+ throw new SdkError(
86
+ "configuration_error",
87
+ "LogBrew native bridge scope sync requires a function, setLogBrewScope, or syncLogBrewScope"
88
+ );
89
+ }
90
+
91
+ function bridgeClear(nativeBridge) {
92
+ if (nativeBridge && typeof nativeBridge.clearLogBrewScope === "function") {
93
+ return nativeBridge.clearLogBrewScope.bind(nativeBridge);
94
+ }
95
+ if (nativeBridge && typeof nativeBridge.clearLogBrewTraceContext === "function") {
96
+ return nativeBridge.clearLogBrewTraceContext.bind(nativeBridge);
97
+ }
98
+ if (typeof nativeBridge === "function") {
99
+ return () => nativeBridge(undefined);
100
+ }
101
+ return () => {};
102
+ }
103
+
104
+ function compactMetadata(metadata) {
105
+ const compacted = {};
106
+ for (const [key, value] of Object.entries(metadata)) {
107
+ if (value === undefined) {
108
+ continue;
109
+ }
110
+ if (RESERVED_TRACE_METADATA_KEYS.has(key)) {
111
+ continue;
112
+ }
113
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null) {
114
+ compacted[key] = value;
115
+ }
116
+ }
117
+ return compacted;
118
+ }
119
+
120
+ const defaultExport = {
121
+ clearLogBrewNativeBridgeScope,
122
+ createLogBrewNativeBridgeScope,
123
+ syncLogBrewNativeBridgeScope,
124
+ withLogBrewNativeBridgeScope
125
+ };
126
+
127
+ module.exports = { ...defaultExport, default: defaultExport };
@@ -0,0 +1,60 @@
1
+ import type { Metadata } from "@logbrew/sdk";
2
+ import type { ReactNativeTraceInput } from "./index.js";
3
+
4
+ export type LogBrewNativeBridgeScope = {
5
+ trace?: {
6
+ traceId: string;
7
+ spanId: string;
8
+ parentSpanId?: string;
9
+ traceFlags: string;
10
+ traceSampled: boolean;
11
+ };
12
+ metadata: Metadata;
13
+ };
14
+
15
+ export type LogBrewNativeBridgeLike =
16
+ | ((scope: LogBrewNativeBridgeScope | undefined) => void)
17
+ | {
18
+ setLogBrewScope?: (scope: LogBrewNativeBridgeScope) => void;
19
+ syncLogBrewScope?: (scope: LogBrewNativeBridgeScope) => void;
20
+ clearLogBrewScope?: () => void;
21
+ clearLogBrewTraceContext?: () => void;
22
+ };
23
+
24
+ export type LogBrewNativeBridgeScopeInput = {
25
+ logger?: string;
26
+ metadata?: Metadata;
27
+ screen?: string;
28
+ sessionId?: string;
29
+ source?: string;
30
+ trace?: ReactNativeTraceInput;
31
+ };
32
+
33
+ export declare function createLogBrewNativeBridgeScope(
34
+ input?: LogBrewNativeBridgeScopeInput
35
+ ): LogBrewNativeBridgeScope;
36
+ export declare function syncLogBrewNativeBridgeScope(
37
+ nativeBridge: LogBrewNativeBridgeLike,
38
+ input?: LogBrewNativeBridgeScopeInput
39
+ ): LogBrewNativeBridgeScope;
40
+ export declare function clearLogBrewNativeBridgeScope(
41
+ nativeBridge: LogBrewNativeBridgeLike
42
+ ): void;
43
+ export declare function withLogBrewNativeBridgeScope<TResult>(
44
+ nativeBridge: LogBrewNativeBridgeLike,
45
+ callback: (scope: LogBrewNativeBridgeScope) => TResult
46
+ ): TResult;
47
+ export declare function withLogBrewNativeBridgeScope<TResult>(
48
+ nativeBridge: LogBrewNativeBridgeLike,
49
+ input: LogBrewNativeBridgeScopeInput,
50
+ callback: (scope: LogBrewNativeBridgeScope) => TResult
51
+ ): TResult;
52
+
53
+ declare const defaultExport: {
54
+ clearLogBrewNativeBridgeScope: typeof clearLogBrewNativeBridgeScope;
55
+ createLogBrewNativeBridgeScope: typeof createLogBrewNativeBridgeScope;
56
+ syncLogBrewNativeBridgeScope: typeof syncLogBrewNativeBridgeScope;
57
+ withLogBrewNativeBridgeScope: typeof withLogBrewNativeBridgeScope;
58
+ };
59
+
60
+ export default defaultExport;
@@ -0,0 +1,60 @@
1
+ import type { Metadata } from "@logbrew/sdk";
2
+ import type { ReactNativeTraceInput } from "./index.js";
3
+
4
+ export type LogBrewNativeBridgeScope = {
5
+ trace?: {
6
+ traceId: string;
7
+ spanId: string;
8
+ parentSpanId?: string;
9
+ traceFlags: string;
10
+ traceSampled: boolean;
11
+ };
12
+ metadata: Metadata;
13
+ };
14
+
15
+ export type LogBrewNativeBridgeLike =
16
+ | ((scope: LogBrewNativeBridgeScope | undefined) => void)
17
+ | {
18
+ setLogBrewScope?: (scope: LogBrewNativeBridgeScope) => void;
19
+ syncLogBrewScope?: (scope: LogBrewNativeBridgeScope) => void;
20
+ clearLogBrewScope?: () => void;
21
+ clearLogBrewTraceContext?: () => void;
22
+ };
23
+
24
+ export type LogBrewNativeBridgeScopeInput = {
25
+ logger?: string;
26
+ metadata?: Metadata;
27
+ screen?: string;
28
+ sessionId?: string;
29
+ source?: string;
30
+ trace?: ReactNativeTraceInput;
31
+ };
32
+
33
+ export declare function createLogBrewNativeBridgeScope(
34
+ input?: LogBrewNativeBridgeScopeInput
35
+ ): LogBrewNativeBridgeScope;
36
+ export declare function syncLogBrewNativeBridgeScope(
37
+ nativeBridge: LogBrewNativeBridgeLike,
38
+ input?: LogBrewNativeBridgeScopeInput
39
+ ): LogBrewNativeBridgeScope;
40
+ export declare function clearLogBrewNativeBridgeScope(
41
+ nativeBridge: LogBrewNativeBridgeLike
42
+ ): void;
43
+ export declare function withLogBrewNativeBridgeScope<TResult>(
44
+ nativeBridge: LogBrewNativeBridgeLike,
45
+ callback: (scope: LogBrewNativeBridgeScope) => TResult
46
+ ): TResult;
47
+ export declare function withLogBrewNativeBridgeScope<TResult>(
48
+ nativeBridge: LogBrewNativeBridgeLike,
49
+ input: LogBrewNativeBridgeScopeInput,
50
+ callback: (scope: LogBrewNativeBridgeScope) => TResult
51
+ ): TResult;
52
+
53
+ declare const defaultExport: {
54
+ clearLogBrewNativeBridgeScope: typeof clearLogBrewNativeBridgeScope;
55
+ createLogBrewNativeBridgeScope: typeof createLogBrewNativeBridgeScope;
56
+ syncLogBrewNativeBridgeScope: typeof syncLogBrewNativeBridgeScope;
57
+ withLogBrewNativeBridgeScope: typeof withLogBrewNativeBridgeScope;
58
+ };
59
+
60
+ export default defaultExport;