@logbrew/react-native 0.1.38 → 0.1.40
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/LogBrewReactNative.podspec +1 -1
- package/README.md +17 -15
- package/android-native-diagnostics.d.ts +15 -5
- package/android-native-diagnostics.js +170 -94
- package/apollo.cjs +435 -226
- package/apollo.d.cts +2 -70
- package/apollo.d.ts +24 -12
- package/apollo.js +438 -221
- package/apple-native-diagnostics-config.js +176 -0
- package/apple-native-diagnostics-context.js +232 -0
- package/apple-native-diagnostics-module.js +229 -0
- package/apple-native-diagnostics.d.ts +42 -11
- package/apple-native-diagnostics.js +60 -389
- package/expo.cjs +29 -16
- package/expo.d.ts +10 -9
- package/expo.js +4 -3
- package/fatal-admission.cjs +113 -0
- package/fatal-record.cjs +317 -0
- package/fatal-replay.cjs +297 -508
- package/global-errors-capture.cjs +369 -0
- package/global-errors-event.cjs +174 -0
- package/global-errors-support.cjs +128 -0
- package/global-errors.cjs +75 -351
- package/global-errors.d.cts +29 -278
- package/global-errors.d.ts +57 -27
- package/global-errors.js +7 -2
- package/global-errors.native.js +83 -48
- package/index-breadcrumbs.cjs +139 -0
- package/index-errors.cjs +167 -0
- package/index-events.cjs +365 -0
- package/index-navigation.cjs +327 -0
- package/index-random.cjs +120 -0
- package/index-react.cjs +189 -0
- package/index-spans.cjs +190 -0
- package/index-trace-fetch.cjs +322 -0
- package/index-trace.cjs +335 -0
- package/index-transport.cjs +201 -0
- package/index-values.cjs +232 -0
- package/index.cjs +95 -1220
- package/index.d.cts +2 -505
- package/index.d.ts +130 -469
- package/index.native.d.ts +146 -22
- package/index.native.js +184 -159
- package/instrumentation-fetch.cjs +113 -0
- package/instrumentation-install.cjs +241 -0
- package/instrumentation-runtime.cjs +65 -0
- package/instrumentation-teardown.cjs +93 -0
- package/instrumentation-values.cjs +282 -0
- package/instrumentation-xhr-request.cjs +298 -0
- package/instrumentation-xhr.cjs +233 -0
- package/instrumentation.cjs +110 -599
- package/instrumentation.d.cts +2 -84
- package/instrumentation.d.ts +22 -8
- package/ios/AppleDiagnostics/LBRNAppleNativeDiagnostics.swift +1 -1
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngine.swift +7 -1
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineAutomatic.swift +36 -4
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineQueue.swift +17 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryLifecycle.swift +2 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/Transport.swift +41 -6
- package/ios/GeneratedAppleDiagnostics/SOURCE-MANIFEST.json +5 -5
- package/lifecycle.cjs +181 -78
- package/lifecycle.d.cts +1 -50
- package/lifecycle.d.ts +17 -6
- package/metadata.cjs +279 -114
- package/metro-debug-id.cjs +296 -0
- package/metro-serializer.cjs +219 -0
- package/metro.cjs +153 -297
- package/metro.d.cts +2 -57
- package/metro.d.ts +27 -13
- package/metro.js +2 -3
- package/native-bridge-async.cjs +165 -0
- package/native-bridge-scope.cjs +148 -0
- package/native-bridge.cjs +83 -186
- package/native-bridge.d.cts +2 -94
- package/native-bridge.d.ts +28 -15
- package/native-client-bindings.js +230 -0
- package/native-diagnostics-values.js +120 -0
- package/native-module-lookup.js +31 -0
- package/native-null.js +3 -0
- package/null-value.cjs +4 -0
- package/package.json +44 -2
- package/persistent-delivery-store.js +247 -0
- package/persistent-delivery.native.js +183 -261
- package/promise-rejection-handlers.cjs +368 -0
- package/promise-rejections.cjs +169 -361
- package/react-native.config.js +3 -1
- package/release-artifacts-files.cjs +94 -0
- package/release-artifacts-options.cjs +182 -0
- package/release-artifacts.cjs +278 -207
- package/release-artifacts.d.cts +2 -55
- package/release-artifacts.d.ts +18 -7
- package/release-artifacts.js +2 -4
- package/resource-fetch-graphql.cjs +265 -0
- package/resource-fetch-size.cjs +156 -0
- package/resource-fetch.cjs +227 -428
- package/resource-fetch.d.cts +1 -60
- package/resource-fetch.d.ts +17 -6
- package/scripts/sync-apple-native-sources.mjs +101 -53
- package/types/capture.d.ts +95 -0
- package/types/config.d.ts +85 -0
- package/types/defaults.d.ts +55 -0
- package/types/events.d.ts +203 -0
- package/types/provider.d.ts +81 -0
- package/types/trace.d.ts +104 -0
package/metro.d.ts
CHANGED
|
@@ -1,57 +1,71 @@
|
|
|
1
|
-
|
|
1
|
+
type LogBrewMetroSerializerResult = string | {
|
|
2
2
|
code: string;
|
|
3
3
|
map: string;
|
|
4
4
|
[key: string]: unknown;
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
type LogBrewMetroSerializer<TModule = unknown, TGraph = unknown, TOptions = unknown> = (
|
|
8
8
|
entryPoint: string,
|
|
9
9
|
preModules: readonly TModule[],
|
|
10
10
|
graph: TGraph,
|
|
11
11
|
options: TOptions,
|
|
12
12
|
) => LogBrewMetroSerializerResult | Promise<LogBrewMetroSerializerResult>;
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
type LogBrewMetroConfig = {
|
|
15
15
|
serializer?: {
|
|
16
16
|
customSerializer?: unknown;
|
|
17
17
|
} | Record<string, unknown>;
|
|
18
18
|
} | Record<string, unknown>;
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
type LogBrewMetroConfigOptions = {
|
|
21
21
|
enabled?: boolean;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
type LogBrewExpoSerializationInput<TModule = unknown, TGraph = unknown> = {
|
|
25
25
|
debugId?: string;
|
|
26
26
|
graph: TGraph;
|
|
27
27
|
premodules: TModule[];
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
type LogBrewExpoDebugIdPlugin<TModule = unknown, TGraph = unknown> = (
|
|
31
31
|
input: LogBrewExpoSerializationInput<TModule, TGraph>,
|
|
32
32
|
) => TModule[];
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
type LogBrewExpoConfigOptions<TConfig extends LogBrewMetroConfig = LogBrewMetroConfig> = {
|
|
35
35
|
enabled?: boolean;
|
|
36
36
|
getDefaultConfig?: (...args: never[]) => TConfig;
|
|
37
37
|
unstable_beforeAssetSerializationPlugins?: LogBrewExpoDebugIdPlugin[];
|
|
38
38
|
[key: string]: unknown;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
declare function createLogBrewMetroSerializer<TModule, TGraph, TOptions>(
|
|
42
42
|
customSerializer: LogBrewMetroSerializer<TModule, TGraph, TOptions>,
|
|
43
43
|
): LogBrewMetroSerializer<TModule, TGraph, TOptions>;
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
declare function createLogBrewMetroSerializer(customSerializer?: null): LogBrewMetroSerializer;
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
declare function getLogBrewExpoConfig<TConfig extends LogBrewMetroConfig = LogBrewMetroConfig>(
|
|
48
48
|
projectRoot: string,
|
|
49
49
|
options?: LogBrewExpoConfigOptions<TConfig>,
|
|
50
50
|
): TConfig;
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
config:
|
|
52
|
+
declare function withLogBrewMetroConfig<TConfig extends LogBrewMetroConfig>(
|
|
53
|
+
config: TConfig,
|
|
54
54
|
options?: LogBrewMetroConfigOptions,
|
|
55
|
-
):
|
|
55
|
+
): TConfig;
|
|
56
56
|
|
|
57
|
+
export type {
|
|
58
|
+
LogBrewExpoConfigOptions,
|
|
59
|
+
LogBrewExpoDebugIdPlugin,
|
|
60
|
+
LogBrewExpoSerializationInput,
|
|
61
|
+
LogBrewMetroConfig,
|
|
62
|
+
LogBrewMetroConfigOptions,
|
|
63
|
+
LogBrewMetroSerializer,
|
|
64
|
+
LogBrewMetroSerializerResult
|
|
65
|
+
};
|
|
66
|
+
export {
|
|
67
|
+
createLogBrewMetroSerializer,
|
|
68
|
+
getLogBrewExpoConfig,
|
|
69
|
+
withLogBrewMetroConfig
|
|
70
|
+
};
|
|
57
71
|
export default withLogBrewMetroConfig;
|
package/metro.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import metro from "./metro.cjs";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
export const getLogBrewExpoConfig = metro.getLogBrewExpoConfig;
|
|
5
|
-
export const withLogBrewMetroConfig = metro.withLogBrewMetroConfig;
|
|
3
|
+
const { createLogBrewMetroSerializer, getLogBrewExpoConfig, withLogBrewMetroConfig } = metro;
|
|
6
4
|
|
|
5
|
+
export { createLogBrewMetroSerializer, getLogBrewExpoConfig, withLogBrewMetroConfig };
|
|
7
6
|
export default withLogBrewMetroConfig;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { SdkError } = require("@logbrew/sdk");
|
|
4
|
+
const { isCallable, isObjectLike } = require("./instrumentation-values.cjs");
|
|
5
|
+
const { bridgeClear, bridgeSetter, createLogBrewNativeBridgeScope } = require("./native-bridge-scope.cjs");
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @import { NativeBridgeCall, NativeBridgeScope, NativeBridgeScopeInput } from "./native-bridge-scope.cjs"
|
|
9
|
+
* @import { Callable } from "./instrumentation-values.cjs"
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {{ readonly clear: () => unknown, readonly payload: NativeBridgeScope, readonly sync: NativeBridgeCall }} PreparedScope
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** @type {WeakMap<object, number>} */
|
|
17
|
+
const ASYNC_BRIDGE_PENDING = new WeakMap();
|
|
18
|
+
/** @type {WeakMap<object, PromiseLike<unknown>>} */
|
|
19
|
+
const ASYNC_BRIDGE_TAILS = new WeakMap();
|
|
20
|
+
const MAX_PENDING_ASYNC_SCOPES = 128;
|
|
21
|
+
const MAX_ASYNC_SCOPE_METADATA_ENTRIES = 64;
|
|
22
|
+
const MAX_ASYNC_SCOPE_JSON_LENGTH = 8192;
|
|
23
|
+
const NO_PENDING = 0;
|
|
24
|
+
const ONE_SCOPE = 1;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {object} nativeBridge
|
|
28
|
+
* @returns {void}
|
|
29
|
+
*/
|
|
30
|
+
function releaseAsyncScopeReservation(nativeBridge) {
|
|
31
|
+
const pending = (ASYNC_BRIDGE_PENDING.get(nativeBridge) ?? ONE_SCOPE) - ONE_SCOPE;
|
|
32
|
+
ASYNC_BRIDGE_PENDING.set(nativeBridge, pending);
|
|
33
|
+
if (pending === NO_PENDING) {
|
|
34
|
+
ASYNC_BRIDGE_PENDING.delete(nativeBridge);
|
|
35
|
+
ASYNC_BRIDGE_TAILS.delete(nativeBridge);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {object} nativeBridge
|
|
41
|
+
* @param {NativeBridgeScopeInput} options
|
|
42
|
+
* @returns {PreparedScope}
|
|
43
|
+
*/
|
|
44
|
+
function prepareAsyncScope(nativeBridge, options) {
|
|
45
|
+
try {
|
|
46
|
+
const sync = bridgeSetter(nativeBridge);
|
|
47
|
+
const clear = bridgeClear(nativeBridge, true);
|
|
48
|
+
const payload = createLogBrewNativeBridgeScope(options);
|
|
49
|
+
if (Object.keys(payload.metadata).length > MAX_ASYNC_SCOPE_METADATA_ENTRIES
|
|
50
|
+
|| JSON.stringify(payload).length > MAX_ASYNC_SCOPE_JSON_LENGTH) {
|
|
51
|
+
throw new SdkError("native_scope_too_large", "async native bridge scope exceeds its payload limit");
|
|
52
|
+
}
|
|
53
|
+
return { clear, payload, sync };
|
|
54
|
+
} catch (error) {
|
|
55
|
+
releaseAsyncScopeReservation(nativeBridge);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @param {() => unknown} clear
|
|
62
|
+
* @returns {Promise<boolean>}
|
|
63
|
+
*/
|
|
64
|
+
async function clearIgnoringFailure(clear) {
|
|
65
|
+
try {
|
|
66
|
+
await clear();
|
|
67
|
+
} catch {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @param {PreparedScope} prepared
|
|
75
|
+
* @param {Callable} work
|
|
76
|
+
* @returns {Promise<unknown>}
|
|
77
|
+
*/
|
|
78
|
+
async function syncAndRunScopedWork({ clear, payload, sync }, work) {
|
|
79
|
+
try {
|
|
80
|
+
await sync(payload);
|
|
81
|
+
return await work(payload);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
await clearIgnoringFailure(clear);
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @param {object} nativeBridge
|
|
90
|
+
* @param {PreparedScope} prepared
|
|
91
|
+
* @param {Callable} work
|
|
92
|
+
* @returns {Promise<unknown>}
|
|
93
|
+
*/
|
|
94
|
+
async function runQueuedNativeBridgeScope(nativeBridge, prepared, work) {
|
|
95
|
+
await (ASYNC_BRIDGE_TAILS.get(nativeBridge) ?? Promise.resolve());
|
|
96
|
+
try {
|
|
97
|
+
await prepared.clear();
|
|
98
|
+
const result = await syncAndRunScopedWork(prepared, work);
|
|
99
|
+
await prepared.clear();
|
|
100
|
+
return result;
|
|
101
|
+
} finally {
|
|
102
|
+
releaseAsyncScopeReservation(nativeBridge);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @returns {undefined}
|
|
108
|
+
*/
|
|
109
|
+
function settledTurn() {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @param {Readonly<Promise<unknown>>} run
|
|
115
|
+
* @returns {PromiseLike<unknown>}
|
|
116
|
+
*/
|
|
117
|
+
function queueTurn(run) {
|
|
118
|
+
return run.then(settledTurn, settledTurn);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @param {unknown} nativeBridge
|
|
123
|
+
* @param {unknown} work
|
|
124
|
+
* @returns {{ readonly bridge: object, readonly scopedWork: Callable }}
|
|
125
|
+
*/
|
|
126
|
+
function requireAsyncScopeTarget(nativeBridge, work) {
|
|
127
|
+
if (!isCallable(work)) {
|
|
128
|
+
throw new SdkError("configuration_error", "withLogBrewNativeBridgeScopeAsync requires a callback");
|
|
129
|
+
}
|
|
130
|
+
if (!isObjectLike(nativeBridge)) {
|
|
131
|
+
throw new SdkError("configuration_error", "async native bridge scope requires an adapter object or function");
|
|
132
|
+
}
|
|
133
|
+
return { bridge: nativeBridge, scopedWork: work };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @param {object} nativeBridge
|
|
138
|
+
* @returns {void}
|
|
139
|
+
*/
|
|
140
|
+
function reserveAsyncScope(nativeBridge) {
|
|
141
|
+
const pending = ASYNC_BRIDGE_PENDING.get(nativeBridge) ?? NO_PENDING;
|
|
142
|
+
if (pending >= MAX_PENDING_ASYNC_SCOPES) {
|
|
143
|
+
throw new SdkError("native_scope_queue_full", "async native bridge scope queue is full");
|
|
144
|
+
}
|
|
145
|
+
ASYNC_BRIDGE_PENDING.set(nativeBridge, pending + ONE_SCOPE);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @param {unknown} nativeBridge
|
|
150
|
+
* @param {NativeBridgeScopeInput | Callable | null | undefined} options
|
|
151
|
+
* @param {unknown} [work]
|
|
152
|
+
* @returns {Promise<unknown>}
|
|
153
|
+
*/
|
|
154
|
+
async function withLogBrewNativeBridgeScopeAsync(nativeBridge, options, work) {
|
|
155
|
+
const resolvedOptions = typeof options === "function" ? {} : options ?? {};
|
|
156
|
+
const resolvedWork = typeof options === "function" ? options : work;
|
|
157
|
+
const { bridge, scopedWork } = requireAsyncScopeTarget(nativeBridge, resolvedWork);
|
|
158
|
+
reserveAsyncScope(bridge);
|
|
159
|
+
const prepared = prepareAsyncScope(bridge, resolvedOptions);
|
|
160
|
+
const run = runQueuedNativeBridgeScope(bridge, prepared, scopedWork);
|
|
161
|
+
ASYNC_BRIDGE_TAILS.set(bridge, queueTurn(run));
|
|
162
|
+
return run;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
module.exports = { withLogBrewNativeBridgeScopeAsync };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { SdkError } = require("@logbrew/sdk");
|
|
4
|
+
const { indexRuntime, isCallable, readField } = require("./instrumentation-values.cjs");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @import { Metadata, MetadataValue } from "@logbrew/sdk"
|
|
8
|
+
* @import { TraceInput } from "./instrumentation-values.cjs"
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {{
|
|
13
|
+
* readonly logger?: string | undefined,
|
|
14
|
+
* readonly metadata?: { readonly [key: string]: unknown } | undefined,
|
|
15
|
+
* readonly screen?: string | undefined,
|
|
16
|
+
* readonly sessionId?: string | undefined,
|
|
17
|
+
* readonly source?: string | undefined,
|
|
18
|
+
* readonly trace?: TraceInput | null | undefined
|
|
19
|
+
* }} NativeBridgeScopeInput
|
|
20
|
+
* @typedef {{ readonly [key: string]: MetadataValue | undefined }} NativeBridgeTrace
|
|
21
|
+
* @typedef {{ readonly trace: NativeBridgeTrace | undefined, readonly metadata: Readonly<Metadata> }} NativeBridgeScope
|
|
22
|
+
* @typedef {(scope?: NativeBridgeScope) => unknown} NativeBridgeCall
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const DEFAULT_SCOPE_SOURCE = "react-native.native_bridge";
|
|
26
|
+
const NO_ENTRIES = 0;
|
|
27
|
+
const RESERVED_TRACE_METADATA_KEYS = new Set([
|
|
28
|
+
"parentSpanId",
|
|
29
|
+
"spanId",
|
|
30
|
+
"traceFlags",
|
|
31
|
+
"traceId",
|
|
32
|
+
"traceSampled",
|
|
33
|
+
"traceparent"
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {unknown} value
|
|
38
|
+
* @returns {value is MetadataValue}
|
|
39
|
+
*/
|
|
40
|
+
function isMetadataValue(value) {
|
|
41
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param {{ readonly [key: string]: unknown }} metadata
|
|
46
|
+
* @returns {Metadata}
|
|
47
|
+
*/
|
|
48
|
+
function compactScopeMetadata(metadata) {
|
|
49
|
+
/** @type {Metadata} */
|
|
50
|
+
const compacted = {};
|
|
51
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
52
|
+
if (value !== undefined && !RESERVED_TRACE_METADATA_KEYS.has(key) && isMetadataValue(value)) {
|
|
53
|
+
compacted[key] = value;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return compacted;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {NativeBridgeScopeInput} [input]
|
|
61
|
+
* @returns {NativeBridgeScope}
|
|
62
|
+
*/
|
|
63
|
+
function createLogBrewNativeBridgeScope({
|
|
64
|
+
logger,
|
|
65
|
+
metadata = {},
|
|
66
|
+
screen,
|
|
67
|
+
sessionId,
|
|
68
|
+
source = DEFAULT_SCOPE_SOURCE,
|
|
69
|
+
trace = indexRuntime.getActiveLogBrewTrace()
|
|
70
|
+
} = {}) {
|
|
71
|
+
const traceMetadata = indexRuntime.getReactNativeTraceMetadata(trace);
|
|
72
|
+
return {
|
|
73
|
+
trace: Object.keys(traceMetadata).length === NO_ENTRIES ? undefined : {
|
|
74
|
+
parentSpanId: traceMetadata["parentSpanId"],
|
|
75
|
+
spanId: traceMetadata["spanId"],
|
|
76
|
+
traceFlags: traceMetadata["traceFlags"],
|
|
77
|
+
traceId: traceMetadata["traceId"],
|
|
78
|
+
traceSampled: traceMetadata["traceSampled"]
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
metadata: compactScopeMetadata({
|
|
82
|
+
...metadata,
|
|
83
|
+
logger,
|
|
84
|
+
screen,
|
|
85
|
+
sessionId,
|
|
86
|
+
source
|
|
87
|
+
})
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @param {unknown} nativeBridge
|
|
93
|
+
* @returns {NativeBridgeCall}
|
|
94
|
+
*/
|
|
95
|
+
function bridgeSetter(nativeBridge) {
|
|
96
|
+
if (isCallable(nativeBridge)) {
|
|
97
|
+
return nativeBridge;
|
|
98
|
+
}
|
|
99
|
+
const setScope = readField(nativeBridge, "setLogBrewScope");
|
|
100
|
+
if (isCallable(setScope)) {
|
|
101
|
+
return setScope.bind(nativeBridge);
|
|
102
|
+
}
|
|
103
|
+
const syncScope = readField(nativeBridge, "syncLogBrewScope");
|
|
104
|
+
if (isCallable(syncScope)) {
|
|
105
|
+
return syncScope.bind(nativeBridge);
|
|
106
|
+
}
|
|
107
|
+
throw new SdkError(
|
|
108
|
+
"configuration_error",
|
|
109
|
+
"LogBrew native bridge scope sync requires a function, setLogBrewScope, or syncLogBrewScope"
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @param {unknown} nativeBridge
|
|
115
|
+
* @param {boolean} required
|
|
116
|
+
* @returns {() => unknown}
|
|
117
|
+
*/
|
|
118
|
+
function fallbackClear(nativeBridge, required) {
|
|
119
|
+
if (isCallable(nativeBridge)) {
|
|
120
|
+
return () => nativeBridge(undefined);
|
|
121
|
+
}
|
|
122
|
+
if (required) {
|
|
123
|
+
throw new SdkError(
|
|
124
|
+
"configuration_error",
|
|
125
|
+
"async LogBrew native bridge scope requires clearLogBrewScope or clearLogBrewTraceContext"
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
return () => undefined;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @param {unknown} nativeBridge
|
|
133
|
+
* @param {boolean} [required]
|
|
134
|
+
* @returns {() => unknown}
|
|
135
|
+
*/
|
|
136
|
+
function bridgeClear(nativeBridge, required = false) {
|
|
137
|
+
const clearScope = readField(nativeBridge, "clearLogBrewScope");
|
|
138
|
+
if (isCallable(clearScope)) {
|
|
139
|
+
return clearScope.bind(nativeBridge);
|
|
140
|
+
}
|
|
141
|
+
const clearTraceContext = readField(nativeBridge, "clearLogBrewTraceContext");
|
|
142
|
+
if (isCallable(clearTraceContext)) {
|
|
143
|
+
return clearTraceContext.bind(nativeBridge);
|
|
144
|
+
}
|
|
145
|
+
return fallbackClear(nativeBridge, required);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
module.exports = { bridgeClear, bridgeSetter, createLogBrewNativeBridgeScope };
|