@logbrew/react-native 0.1.39 → 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/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 -1243
- 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/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 +43 -1
- 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/metadata.cjs
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
const { NULL_VALUE } = require("./null-value.cjs");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @import { IssueExceptionChain, IssueExceptionChainEntry, IssueStackFrame, Metadata, MetadataValue } from "@logbrew/sdk"
|
|
7
|
+
* @typedef {(metadata: Readonly<Record<string, unknown>>) => Metadata} CompactMetadata
|
|
8
|
+
*/
|
|
9
|
+
|
|
3
10
|
const SENSITIVE_METADATA_FACTORY_KEY_RE = new RegExp([
|
|
4
11
|
"body",
|
|
5
12
|
"payload",
|
|
@@ -7,187 +14,345 @@ const SENSITIVE_METADATA_FACTORY_KEY_RE = new RegExp([
|
|
|
7
14
|
"header",
|
|
8
15
|
"authorization",
|
|
9
16
|
"cookie",
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
17
|
+
"token",
|
|
18
|
+
"secret",
|
|
19
|
+
"password"
|
|
13
20
|
].join("|"), "u");
|
|
14
21
|
const REACT_NATIVE_DEBUG_ID_REGISTRY = Symbol.for("@logbrew/react-native/debug-ids");
|
|
15
22
|
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
23
|
const MAX_REACT_NATIVE_DEBUG_ID_REGISTRY_ENTRIES = 64;
|
|
17
24
|
const MAX_REACT_NATIVE_DEBUG_ID_REGISTRY_FRAMES = 128;
|
|
18
25
|
const GENERIC_REACT_NATIVE_FRAME_FUNCTION = /^(?:<anonymous>|anonymous|apply|call|eval|global code|native|next)$/iu;
|
|
26
|
+
const GROUPING_KEY_RE = /^(?<kind>[^:]+):(?<scope>[^:]+):(?<location>.+)$/u;
|
|
27
|
+
const POSITIVE_INTEGER_RE = /^[1-9]\d*$/u;
|
|
28
|
+
const NO_ITEMS = 0;
|
|
29
|
+
const FIRST = 0;
|
|
30
|
+
const STEP = 1;
|
|
31
|
+
const AT_PREFIX_LENGTH = 3;
|
|
32
|
+
const MIN_LOCATION_PARTS = 3;
|
|
33
|
+
const NOT_FOUND = -1;
|
|
34
|
+
/** @type {readonly Readonly<IssueStackFrame>[]} */
|
|
35
|
+
const DEFAULT_STACK_FRAMES = Object.freeze([]);
|
|
19
36
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
37
|
+
/**
|
|
38
|
+
* @param {unknown} value
|
|
39
|
+
* @returns {value is Readonly<Record<string, unknown>>}
|
|
40
|
+
*/
|
|
41
|
+
function isRecord(value) {
|
|
42
|
+
return typeof value === "object" && value !== null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param {unknown} value
|
|
47
|
+
* @returns {value is (context: unknown) => unknown}
|
|
48
|
+
*/
|
|
49
|
+
function isMetadataFactory(value) {
|
|
50
|
+
return typeof value === "function";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @param {readonly Readonly<IssueStackFrame>[] | undefined} value
|
|
55
|
+
* @returns {value is readonly Readonly<IssueStackFrame>[]}
|
|
56
|
+
*/
|
|
57
|
+
function isFrameList(value) {
|
|
58
|
+
return Array.isArray(value);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {unknown} value
|
|
63
|
+
* @returns {value is MetadataValue}
|
|
64
|
+
*/
|
|
65
|
+
function isMetadataValue(value) {
|
|
66
|
+
return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
28
67
|
}
|
|
29
68
|
|
|
69
|
+
/**
|
|
70
|
+
* @param {unknown} key
|
|
71
|
+
* @returns {boolean}
|
|
72
|
+
*/
|
|
73
|
+
function isSensitiveMetadataKey(key) {
|
|
74
|
+
return SENSITIVE_METADATA_FACTORY_KEY_RE.test(String(key).toLowerCase());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @param {unknown} candidate
|
|
79
|
+
* @returns {Metadata}
|
|
80
|
+
*/
|
|
30
81
|
function safeReactNativeMetadataFactoryResult(candidate) {
|
|
31
|
-
if (!candidate ||
|
|
82
|
+
if (!isRecord(candidate) || Array.isArray(candidate)) {
|
|
32
83
|
return {};
|
|
33
84
|
}
|
|
85
|
+
/** @type {Metadata} */
|
|
34
86
|
const metadata = {};
|
|
35
87
|
for (const [key, value] of Object.entries(candidate)) {
|
|
36
|
-
if (isSensitiveMetadataKey(key)) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
88
|
+
if (!isSensitiveMetadataKey(key) && isMetadataValue(value)) {
|
|
40
89
|
metadata[key] = value;
|
|
41
90
|
}
|
|
42
91
|
}
|
|
43
92
|
return metadata;
|
|
44
93
|
}
|
|
45
94
|
|
|
95
|
+
/**
|
|
96
|
+
* @param {Readonly<Metadata> | undefined} metadata
|
|
97
|
+
* @param {unknown} metadataFactory
|
|
98
|
+
* @param {unknown} context
|
|
99
|
+
* @returns {Readonly<Metadata> | undefined}
|
|
100
|
+
*/
|
|
101
|
+
function createSafeReactNativeMetadata(metadata, metadataFactory, context) {
|
|
102
|
+
if (!isMetadataFactory(metadataFactory)) {
|
|
103
|
+
return metadata;
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
...metadata,
|
|
107
|
+
...safeReactNativeMetadataFactoryResult(metadataFactory(context))
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @param {string} path
|
|
113
|
+
* @returns {string}
|
|
114
|
+
*/
|
|
115
|
+
function stripQueryAndHash(path) {
|
|
116
|
+
return (path.split(/[?#]/u, STEP)[FIRST] ?? "").replaceAll("\\", "/");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @param {string} value
|
|
121
|
+
* @returns {string}
|
|
122
|
+
*/
|
|
123
|
+
function urlPathname(value) {
|
|
124
|
+
const URLConstructor = globalThis.URL;
|
|
125
|
+
if (typeof URLConstructor !== "function") {
|
|
126
|
+
return stripQueryAndHash(value);
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
return new URLConstructor(value).pathname || value;
|
|
130
|
+
} catch {
|
|
131
|
+
return stripQueryAndHash(value);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @param {unknown} value
|
|
137
|
+
* @returns {string | undefined}
|
|
138
|
+
*/
|
|
139
|
+
function reactNativeCodePath(value) {
|
|
140
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
const path = urlPathname(value.trim());
|
|
144
|
+
if (/^[A-Za-z]:\//u.test(path) || /^\/(?:Users|home|private|tmp|var)\//u.test(path)) {
|
|
145
|
+
const trimmed = path.replace(/\/+$/u, "");
|
|
146
|
+
return trimmed.slice(trimmed.lastIndexOf("/") + STEP) || undefined;
|
|
147
|
+
}
|
|
148
|
+
return path || undefined;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @param {string | undefined} path
|
|
153
|
+
* @param {readonly Readonly<IssueStackFrame>[]} [stackFrames]
|
|
154
|
+
* @returns {string | undefined}
|
|
155
|
+
*/
|
|
156
|
+
function reactNativeGroupingIdentity(path, stackFrames = DEFAULT_STACK_FRAMES) {
|
|
157
|
+
if (path !== "/" || stackFrames.length === NO_ITEMS) {
|
|
158
|
+
return path;
|
|
159
|
+
}
|
|
160
|
+
const named = stackFrames.find(({ function: name }) => name !== undefined && name !== "" && !GENERIC_REACT_NATIVE_FRAME_FUNCTION.test(name));
|
|
161
|
+
if (named) {
|
|
162
|
+
return `function=${String(named.function)}`;
|
|
163
|
+
}
|
|
164
|
+
const frame = stackFrames[FIRST];
|
|
165
|
+
return `position=${String(frame?.line)}:${String(frame?.column)}`;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @param {Readonly<Metadata> | undefined} metadata
|
|
170
|
+
* @param {CompactMetadata} compactMetadata
|
|
171
|
+
* @param {readonly Readonly<IssueStackFrame>[] | undefined} stackFrames
|
|
172
|
+
* @returns {Metadata}
|
|
173
|
+
*/
|
|
46
174
|
function sanitizeReactNativeIssueMetadata(metadata, compactMetadata, stackFrames) {
|
|
175
|
+
/** @type {Record<string, unknown>} */
|
|
47
176
|
const next = { ...metadata };
|
|
48
177
|
for (const key of ["errorFrameFile", "releaseArtifactCodeFile"]) {
|
|
49
178
|
next[key] = reactNativeCodePath(next[key]) ?? next[key];
|
|
50
179
|
}
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
180
|
+
const groupingKey = next["issueGroupingKey"];
|
|
181
|
+
const groups = typeof groupingKey === "string" ? GROUPING_KEY_RE.exec(groupingKey)?.groups : undefined;
|
|
182
|
+
const identity = groups ? reactNativeGroupingIdentity(reactNativeCodePath(groups["location"]), stackFrames) : undefined;
|
|
183
|
+
if (groups && identity !== undefined && identity !== "") {
|
|
184
|
+
next["issueGroupingKey"] = `${String(groups["kind"])}:${String(groups["scope"])}:${identity}`;
|
|
55
185
|
}
|
|
56
186
|
return compactMetadata(next);
|
|
57
187
|
}
|
|
58
188
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
189
|
+
/**
|
|
190
|
+
* @param {readonly Readonly<IssueStackFrame>[] | undefined} stackFrames
|
|
191
|
+
* @returns {IssueStackFrame[] | undefined}
|
|
192
|
+
*/
|
|
69
193
|
function sanitizeReactNativeIssueStackFrames(stackFrames) {
|
|
70
|
-
if (!
|
|
194
|
+
if (!isFrameList(stackFrames)) {
|
|
71
195
|
return undefined;
|
|
72
196
|
}
|
|
73
|
-
return stackFrames.map(
|
|
197
|
+
return stackFrames.map(frame => ({
|
|
74
198
|
...frame,
|
|
75
199
|
filename: reactNativeCodePath(frame.filename) ?? frame.filename
|
|
76
200
|
}));
|
|
77
201
|
}
|
|
78
202
|
|
|
203
|
+
/**
|
|
204
|
+
* @param {IssueExceptionChain | undefined} exceptionChain
|
|
205
|
+
* @returns {IssueExceptionChain | undefined}
|
|
206
|
+
*/
|
|
79
207
|
function sanitizeReactNativeIssueExceptionChain(exceptionChain) {
|
|
80
208
|
if (!exceptionChain || !Array.isArray(exceptionChain.entries)) {
|
|
81
209
|
return undefined;
|
|
82
210
|
}
|
|
83
211
|
return {
|
|
84
212
|
...exceptionChain,
|
|
85
|
-
entries: exceptionChain.entries.map(
|
|
213
|
+
entries: exceptionChain.entries.map(entry => {
|
|
86
214
|
const stackFrames = sanitizeReactNativeIssueStackFrames(entry.stackFrames);
|
|
87
|
-
|
|
215
|
+
/** @type {IssueExceptionChainEntry} */
|
|
216
|
+
const sanitized = {
|
|
88
217
|
...entry,
|
|
89
218
|
...(stackFrames ? { stackFrames } : {})
|
|
90
219
|
};
|
|
220
|
+
return sanitized;
|
|
91
221
|
})
|
|
92
222
|
};
|
|
93
223
|
}
|
|
94
224
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
const debugIdMap = Object.create(null);
|
|
106
|
-
let frameCount = 0;
|
|
107
|
-
for (const [stack, debugId] of entries) {
|
|
108
|
-
if (typeof debugId !== "string" || !SAFE_RELEASE_ARTIFACT_DEBUG_ID.test(debugId)) {
|
|
109
|
-
return undefined;
|
|
110
|
-
}
|
|
111
|
-
const normalizedDebugId = debugId.toLowerCase();
|
|
112
|
-
let stackFrameCount = 0;
|
|
113
|
-
for (const line of stack.split(/\r?\n/u)) {
|
|
114
|
-
const filename = runtimeStackFrameFilename(line);
|
|
115
|
-
if (!filename) {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
frameCount += 1;
|
|
119
|
-
stackFrameCount += 1;
|
|
120
|
-
if (frameCount > MAX_REACT_NATIVE_DEBUG_ID_REGISTRY_FRAMES) {
|
|
121
|
-
return undefined;
|
|
122
|
-
}
|
|
123
|
-
const existingDebugId = debugIdMap[filename];
|
|
124
|
-
if (existingDebugId && existingDebugId !== normalizedDebugId) {
|
|
125
|
-
return undefined;
|
|
126
|
-
}
|
|
127
|
-
debugIdMap[filename] = normalizedDebugId;
|
|
128
|
-
}
|
|
129
|
-
if (stackFrameCount === 0) {
|
|
130
|
-
return undefined;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return frameCount > 0 ? debugIdMap : undefined;
|
|
134
|
-
} catch {
|
|
135
|
-
return undefined;
|
|
225
|
+
/**
|
|
226
|
+
* @param {string} rawLine
|
|
227
|
+
* @returns {string}
|
|
228
|
+
*/
|
|
229
|
+
function stackFrameLocation(rawLine) {
|
|
230
|
+
const location = rawLine.trim();
|
|
231
|
+
if (location.startsWith("at ")) {
|
|
232
|
+
const inner = location.slice(AT_PREFIX_LENGTH).trim();
|
|
233
|
+
return inner.endsWith(")") && inner.includes("(") ? inner.slice(inner.lastIndexOf("(") + STEP, NOT_FOUND) : inner;
|
|
136
234
|
}
|
|
235
|
+
return location.includes("@") ? location.slice(location.lastIndexOf("@") + STEP) : location;
|
|
137
236
|
}
|
|
138
237
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function
|
|
144
|
-
let location = typeof rawLine === "string" ? rawLine.trim() : "";
|
|
145
|
-
if (!location) {
|
|
146
|
-
return undefined;
|
|
147
|
-
}
|
|
148
|
-
if (location.startsWith("at ")) {
|
|
149
|
-
location = location.slice(3).trim();
|
|
150
|
-
if (location.endsWith(")") && location.includes("(")) {
|
|
151
|
-
location = location.slice(location.lastIndexOf("(") + 1, -1);
|
|
152
|
-
}
|
|
153
|
-
} else if (location.includes("@")) {
|
|
154
|
-
location = location.slice(location.lastIndexOf("@") + 1);
|
|
155
|
-
}
|
|
238
|
+
/**
|
|
239
|
+
* @param {string} location
|
|
240
|
+
* @returns {string | undefined}
|
|
241
|
+
*/
|
|
242
|
+
function locationFilename(location) {
|
|
156
243
|
const parts = location.replace(/^address at /u, "").split(":");
|
|
157
|
-
if (parts.length <
|
|
244
|
+
if (parts.length < MIN_LOCATION_PARTS) {
|
|
158
245
|
return undefined;
|
|
159
246
|
}
|
|
160
|
-
const columnText = parts.pop();
|
|
161
|
-
const lineText = parts.pop();
|
|
247
|
+
const columnText = parts.pop() ?? "";
|
|
248
|
+
const lineText = parts.pop() ?? "";
|
|
162
249
|
const filename = parts.join(":").trim();
|
|
163
|
-
if (
|
|
250
|
+
if (!POSITIVE_INTEGER_RE.test(lineText) || !POSITIVE_INTEGER_RE.test(columnText)) {
|
|
164
251
|
return undefined;
|
|
165
252
|
}
|
|
166
|
-
|
|
167
|
-
const column = Number(columnText);
|
|
168
|
-
return Number.isSafeInteger(line) && Number.isSafeInteger(column) && filename ? filename : undefined;
|
|
253
|
+
return Number.isSafeInteger(Number(lineText)) && Number.isSafeInteger(Number(columnText)) && filename ? filename : undefined;
|
|
169
254
|
}
|
|
170
255
|
|
|
171
|
-
|
|
172
|
-
|
|
256
|
+
/**
|
|
257
|
+
* @param {unknown} rawLine
|
|
258
|
+
* @returns {string | undefined}
|
|
259
|
+
*/
|
|
260
|
+
function runtimeStackFrameFilename(rawLine) {
|
|
261
|
+
const trimmed = typeof rawLine === "string" ? rawLine.trim() : "";
|
|
262
|
+
return trimmed ? locationFilename(stackFrameLocation(trimmed)) : undefined;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* @param {string} stack
|
|
267
|
+
* @returns {string[]}
|
|
268
|
+
*/
|
|
269
|
+
function stackFilenames(stack) {
|
|
270
|
+
/** @type {string[]} */
|
|
271
|
+
const filenames = [];
|
|
272
|
+
for (const line of stack.split(/\r?\n/u)) {
|
|
273
|
+
const filename = runtimeStackFrameFilename(line);
|
|
274
|
+
if (filename !== undefined) {
|
|
275
|
+
filenames.push(filename);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return filenames;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* @param {unknown} debugId
|
|
283
|
+
* @returns {debugId is string}
|
|
284
|
+
*/
|
|
285
|
+
function isSafeDebugId(debugId) {
|
|
286
|
+
return typeof debugId === "string" && SAFE_RELEASE_ARTIFACT_DEBUG_ID.test(debugId);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* @param {string} stack
|
|
291
|
+
* @param {unknown} debugId
|
|
292
|
+
* @returns {{ debugId: string, filenames: string[] } | undefined}
|
|
293
|
+
*/
|
|
294
|
+
function stackDebugIds(stack, debugId) {
|
|
295
|
+
if (!isSafeDebugId(debugId)) {
|
|
173
296
|
return undefined;
|
|
174
297
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
298
|
+
const filenames = stackFilenames(stack);
|
|
299
|
+
return filenames.length === NO_ITEMS ? undefined : { debugId: debugId.toLowerCase(), filenames };
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* @param {readonly (readonly [string, string])[]} debugIds
|
|
304
|
+
* @returns {Record<string, string>}
|
|
305
|
+
*/
|
|
306
|
+
function nullPrototypeRecord(debugIds) {
|
|
307
|
+
/** @type {Record<string, string>} */
|
|
308
|
+
const record = {};
|
|
309
|
+
Object.setPrototypeOf(record, NULL_VALUE);
|
|
310
|
+
for (const [filename, debugId] of debugIds) {
|
|
311
|
+
record[filename] = debugId;
|
|
312
|
+
}
|
|
313
|
+
return record;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* @param {readonly (readonly [string, unknown])[]} entries
|
|
318
|
+
* @returns {Record<string, string> | undefined}
|
|
319
|
+
*/
|
|
320
|
+
function debugIdMapFromEntries(entries) {
|
|
321
|
+
/** @type {Map<string, string>} */
|
|
322
|
+
const debugIds = new Map();
|
|
323
|
+
let frameCount = NO_ITEMS;
|
|
324
|
+
for (const [stack, debugId] of entries) {
|
|
325
|
+
const stackIds = stackDebugIds(stack, debugId);
|
|
326
|
+
frameCount += stackIds?.filenames.length ?? NO_ITEMS;
|
|
327
|
+
if (stackIds === undefined || frameCount > MAX_REACT_NATIVE_DEBUG_ID_REGISTRY_FRAMES
|
|
328
|
+
|| stackIds.filenames.some(filename => (debugIds.get(filename) ?? stackIds.debugId) !== stackIds.debugId)) {
|
|
329
|
+
return undefined;
|
|
330
|
+
}
|
|
331
|
+
for (const filename of stackIds.filenames) {
|
|
332
|
+
debugIds.set(filename, stackIds.debugId);
|
|
182
333
|
}
|
|
183
|
-
} else {
|
|
184
|
-
path = path.split(/[?#]/u, 1)[0].replace(/\\/g, "/");
|
|
185
334
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
335
|
+
return frameCount > NO_ITEMS ? nullPrototypeRecord([...debugIds]) : undefined;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* @returns {Record<string, string> | undefined}
|
|
340
|
+
*/
|
|
341
|
+
function runtimeReactNativeDebugIdMap() {
|
|
342
|
+
try {
|
|
343
|
+
/** @type {unknown} */
|
|
344
|
+
const registry = Reflect.get(globalThis, REACT_NATIVE_DEBUG_ID_REGISTRY);
|
|
345
|
+
if (!isRecord(registry) || Array.isArray(registry)) {
|
|
346
|
+
return undefined;
|
|
347
|
+
}
|
|
348
|
+
const entries = Object.entries(registry);
|
|
349
|
+
if (entries.length === NO_ITEMS || entries.length > MAX_REACT_NATIVE_DEBUG_ID_REGISTRY_ENTRIES) {
|
|
350
|
+
return undefined;
|
|
351
|
+
}
|
|
352
|
+
return debugIdMapFromEntries(entries);
|
|
353
|
+
} catch {
|
|
354
|
+
return undefined;
|
|
189
355
|
}
|
|
190
|
-
return path || undefined;
|
|
191
356
|
}
|
|
192
357
|
|
|
193
358
|
module.exports = {
|