@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
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { isObjectLike, safeFunction } = require("./global-errors-support.cjs");
|
|
4
|
+
const { resultStatus } = require("./fatal-record.cjs");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @import { UnknownFunction } from "./global-errors-support.cjs"
|
|
8
|
+
* @typedef {"admitted" | "dropped" | "filtered" | "unavailable"} Admission
|
|
9
|
+
* @typedef {Readonly<{
|
|
10
|
+
* acknowledge: UnknownFunction,
|
|
11
|
+
* discard: UnknownFunction,
|
|
12
|
+
* read: UnknownFunction,
|
|
13
|
+
* write: UnknownFunction
|
|
14
|
+
* }>} FatalStoreMethods
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const MAX_ADMITTED_FATAL_IDS = 256;
|
|
18
|
+
|
|
19
|
+
/** @type {WeakMap<object, Set<string>>} */
|
|
20
|
+
const admittedFatalIdsByClient = new WeakMap();
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {() => unknown} operation
|
|
24
|
+
* @returns {unknown}
|
|
25
|
+
*/
|
|
26
|
+
function attempt(operation) {
|
|
27
|
+
try {
|
|
28
|
+
return operation();
|
|
29
|
+
} catch {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @type {(client: unknown, issue: UnknownFunction, ...issueArguments: readonly unknown[]) => Admission} */
|
|
35
|
+
function captureIssueWithAdmission(client, issue, ...issueArguments) {
|
|
36
|
+
const [id, timestamp, attributes] = issueArguments;
|
|
37
|
+
const capture = safeFunction(client, "issueWithAdmission");
|
|
38
|
+
if (!capture) {
|
|
39
|
+
issue.call(client, id, timestamp, attributes);
|
|
40
|
+
return "unavailable";
|
|
41
|
+
}
|
|
42
|
+
const status = resultStatus(capture.call(client, id, timestamp, attributes));
|
|
43
|
+
return status === "admitted" || status === "filtered" || status === "dropped"
|
|
44
|
+
? status
|
|
45
|
+
: "unavailable";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {unknown} client
|
|
50
|
+
* @param {string} recordId
|
|
51
|
+
* @returns {boolean}
|
|
52
|
+
*/
|
|
53
|
+
function wasAdmittedInRuntime(client, recordId) {
|
|
54
|
+
return isObjectLike(client) && admittedFatalIdsByClient.get(client)?.has(recordId) === true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {object} client
|
|
59
|
+
* @returns {Set<string>}
|
|
60
|
+
*/
|
|
61
|
+
function admittedIdsFor(client) {
|
|
62
|
+
const existing = admittedFatalIdsByClient.get(client);
|
|
63
|
+
if (existing) {
|
|
64
|
+
return existing;
|
|
65
|
+
}
|
|
66
|
+
/** @type {Set<string>} */
|
|
67
|
+
const admittedIds = new Set();
|
|
68
|
+
admittedFatalIdsByClient.set(client, admittedIds);
|
|
69
|
+
return admittedIds;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @param {unknown} client
|
|
74
|
+
* @param {string} recordId
|
|
75
|
+
* @returns {void}
|
|
76
|
+
*/
|
|
77
|
+
function rememberAdmittedFatalId(client, recordId) {
|
|
78
|
+
if (!isObjectLike(client)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const admittedIds = admittedIdsFor(client);
|
|
82
|
+
if (admittedIds.has(recordId)) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
admittedIds.add(recordId);
|
|
86
|
+
const oldest = admittedIds.values().next().value;
|
|
87
|
+
if (admittedIds.size > MAX_ADMITTED_FATAL_IDS && oldest !== undefined) {
|
|
88
|
+
admittedIds.delete(oldest);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @param {unknown} fatalStore
|
|
94
|
+
* @returns {FatalStoreMethods | undefined}
|
|
95
|
+
*/
|
|
96
|
+
function fatalStoreMethods(fatalStore) {
|
|
97
|
+
if (!isObjectLike(fatalStore)) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
const acknowledge = safeFunction(fatalStore, "acknowledgeFatalRecord");
|
|
101
|
+
const discard = safeFunction(fatalStore, "discardFatalRecord");
|
|
102
|
+
const read = safeFunction(fatalStore, "readFatalRecord");
|
|
103
|
+
const write = safeFunction(fatalStore, "writeFatalRecord");
|
|
104
|
+
return acknowledge && discard && read && write ? { acknowledge, discard, read, write } : undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
module.exports = {
|
|
108
|
+
attempt,
|
|
109
|
+
captureIssueWithAdmission,
|
|
110
|
+
fatalStoreMethods,
|
|
111
|
+
rememberAdmittedFatalId,
|
|
112
|
+
wasAdmittedInRuntime
|
|
113
|
+
};
|
package/fatal-record.cjs
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { hasControlCharacter, safeReadProperty } = require("./global-errors-support.cjs");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {Readonly<{ column: unknown, filename: string, line: unknown }>} FatalFrame
|
|
7
|
+
* @typedef {Readonly<{
|
|
8
|
+
* corruptRecords: number,
|
|
9
|
+
* droppedRecords: number,
|
|
10
|
+
* errorName: unknown,
|
|
11
|
+
* id: string,
|
|
12
|
+
* schemaVersion: number,
|
|
13
|
+
* stackFrames: readonly FatalFrame[],
|
|
14
|
+
* timestamp: string
|
|
15
|
+
* }>} FatalRecord
|
|
16
|
+
* @typedef {Readonly<{
|
|
17
|
+
* id: string,
|
|
18
|
+
* timestamp: string,
|
|
19
|
+
* attributes: Readonly<{
|
|
20
|
+
* exception?: Readonly<{ type: string }> | undefined,
|
|
21
|
+
* stackFrames?: readonly Readonly<{ column: number, filename: string, line: number }>[] | undefined
|
|
22
|
+
* }>
|
|
23
|
+
* }>} FatalEventInput
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const FATAL_RECORD_SCHEMA_VERSION = 1;
|
|
27
|
+
const MAX_FATAL_FILENAME_BYTES = 512;
|
|
28
|
+
const MAX_FATAL_STACK_FRAMES = 24;
|
|
29
|
+
const MAX_FATAL_ID_LENGTH = 128;
|
|
30
|
+
const MAX_FATAL_RECORD_BYTES = 16_384;
|
|
31
|
+
const MIN_FATAL_TIMESTAMP_LENGTH = 20;
|
|
32
|
+
const MAX_FATAL_TIMESTAMP_LENGTH = 35;
|
|
33
|
+
const MAX_FRAME_POSITION = 2_147_483_647;
|
|
34
|
+
const NO_COUNT = 0;
|
|
35
|
+
const FIRST_INDEX = 0;
|
|
36
|
+
const SECOND_INDEX = 1;
|
|
37
|
+
const MIN_POSITION = 0;
|
|
38
|
+
const ONE_BYTE_LIMIT = 0x7F;
|
|
39
|
+
const TWO_BYTE_LIMIT = 0x7_FF;
|
|
40
|
+
const THREE_BYTE_LIMIT = 0xFF_FF;
|
|
41
|
+
const ONE_BYTE = 1;
|
|
42
|
+
const TWO_BYTES = 2;
|
|
43
|
+
const THREE_BYTES = 3;
|
|
44
|
+
const FOUR_BYTES = 4;
|
|
45
|
+
const FATAL_ID_PATTERN = /^evt_rn_fatal_[a-z0-9]+(?:_[a-z0-9]+)*$/u;
|
|
46
|
+
const DRIVE_PREFIX_PATTERN = /^[A-Za-z]:/u;
|
|
47
|
+
const FATAL_TIMESTAMP_PATTERN = /^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\.[0-9]{1,9})?Z$/u;
|
|
48
|
+
const RECORD_KEYS = ["corruptRecords", "droppedRecords", "errorName", "id", "schemaVersion", "stackFrames", "timestamp"];
|
|
49
|
+
const FRAME_KEYS = ["column", "filename", "line"];
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {string} value
|
|
53
|
+
* @returns {number}
|
|
54
|
+
*/
|
|
55
|
+
function utf8ByteLength(value) {
|
|
56
|
+
let bytes = NO_COUNT;
|
|
57
|
+
for (const character of value) {
|
|
58
|
+
const code = character.codePointAt(FIRST_INDEX) ?? NO_COUNT;
|
|
59
|
+
if (code <= ONE_BYTE_LIMIT) {
|
|
60
|
+
bytes += ONE_BYTE;
|
|
61
|
+
} else if (code <= TWO_BYTE_LIMIT) {
|
|
62
|
+
bytes += TWO_BYTES;
|
|
63
|
+
} else {
|
|
64
|
+
bytes += code <= THREE_BYTE_LIMIT ? THREE_BYTES : FOUR_BYTES;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return bytes;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {unknown} value
|
|
72
|
+
* @returns {value is string}
|
|
73
|
+
*/
|
|
74
|
+
function validFatalFilename(value) {
|
|
75
|
+
return typeof value === "string"
|
|
76
|
+
&& value.length > NO_COUNT
|
|
77
|
+
&& utf8ByteLength(value) <= MAX_FATAL_FILENAME_BYTES
|
|
78
|
+
&& !hasControlCharacter(value)
|
|
79
|
+
&& !value.startsWith("/")
|
|
80
|
+
&& !DRIVE_PREFIX_PATTERN.test(value)
|
|
81
|
+
&& !value.includes("\\")
|
|
82
|
+
&& !value.includes("://")
|
|
83
|
+
&& !value.includes("?")
|
|
84
|
+
&& !value.includes("#")
|
|
85
|
+
&& !value.split("/").includes("..");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @param {unknown} value
|
|
90
|
+
* @returns {unknown}
|
|
91
|
+
*/
|
|
92
|
+
function normalizedStoredFatalFilename(value) {
|
|
93
|
+
return typeof value === "string"
|
|
94
|
+
&& value.startsWith("/")
|
|
95
|
+
&& value.length > SECOND_INDEX
|
|
96
|
+
&& !value.includes("/", SECOND_INDEX)
|
|
97
|
+
? value.slice(SECOND_INDEX)
|
|
98
|
+
: value;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @param {unknown} value
|
|
103
|
+
* @returns {value is string}
|
|
104
|
+
*/
|
|
105
|
+
function validFatalTimestamp(value) {
|
|
106
|
+
return typeof value === "string"
|
|
107
|
+
&& value.length >= MIN_FATAL_TIMESTAMP_LENGTH
|
|
108
|
+
&& value.length <= MAX_FATAL_TIMESTAMP_LENGTH
|
|
109
|
+
&& FATAL_TIMESTAMP_PATTERN.test(value);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @param {unknown} value
|
|
114
|
+
* @returns {value is number}
|
|
115
|
+
*/
|
|
116
|
+
function isBoundedCounter(value) {
|
|
117
|
+
return Number.isSafeInteger(value) && typeof value === "number" && value >= NO_COUNT;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @param {unknown} value
|
|
122
|
+
* @returns {boolean}
|
|
123
|
+
*/
|
|
124
|
+
function positiveInteger(value) {
|
|
125
|
+
return Number.isSafeInteger(value) && typeof value === "number" && value > MIN_POSITION && value <= MAX_FRAME_POSITION;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @param {unknown} value
|
|
130
|
+
* @returns {value is Readonly<Record<string, unknown>>}
|
|
131
|
+
*/
|
|
132
|
+
function isPlainObject(value) {
|
|
133
|
+
if (value === null || typeof value !== "object") {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
/** @type {unknown} */
|
|
138
|
+
const prototype = Object.getPrototypeOf(value);
|
|
139
|
+
return prototype === Object.prototype || prototype === null;
|
|
140
|
+
} catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @param {object} value
|
|
147
|
+
* @param {readonly string[]} expected
|
|
148
|
+
* @returns {boolean}
|
|
149
|
+
*/
|
|
150
|
+
function hasExactKeys(value, expected) {
|
|
151
|
+
try {
|
|
152
|
+
const keys = Object.keys(value);
|
|
153
|
+
keys.sort();
|
|
154
|
+
return keys.length === expected.length
|
|
155
|
+
&& keys.every((key, index) => key === expected[index]);
|
|
156
|
+
} catch {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @param {unknown} result
|
|
163
|
+
* @returns {string | undefined}
|
|
164
|
+
*/
|
|
165
|
+
function resultStatus(result) {
|
|
166
|
+
try {
|
|
167
|
+
const status = isPlainObject(result) ? result["status"] : undefined;
|
|
168
|
+
return typeof status === "string" ? status : undefined;
|
|
169
|
+
} catch {
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @param {unknown} result
|
|
176
|
+
* @param {string} property
|
|
177
|
+
* @param {number} fallback
|
|
178
|
+
* @returns {number}
|
|
179
|
+
*/
|
|
180
|
+
function boundedResultCounter(result, property, fallback) {
|
|
181
|
+
const value = isPlainObject(result) ? safeReadProperty(result, property) : undefined;
|
|
182
|
+
return isBoundedCounter(value) ? value : fallback;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @param {FatalEventInput} event
|
|
187
|
+
* @returns {FatalRecord}
|
|
188
|
+
*/
|
|
189
|
+
function createFatalRecord(event) {
|
|
190
|
+
const { exception } = event.attributes;
|
|
191
|
+
if (exception === undefined) {
|
|
192
|
+
throw new TypeError("fatal event has no exception type");
|
|
193
|
+
}
|
|
194
|
+
const record = {
|
|
195
|
+
corruptRecords: NO_COUNT,
|
|
196
|
+
droppedRecords: NO_COUNT,
|
|
197
|
+
errorName: exception.type,
|
|
198
|
+
id: event.id,
|
|
199
|
+
schemaVersion: FATAL_RECORD_SCHEMA_VERSION,
|
|
200
|
+
stackFrames: (event.attributes.stackFrames ?? []).flatMap(({ column, filename, line }) => {
|
|
201
|
+
const stored = normalizedStoredFatalFilename(filename);
|
|
202
|
+
return validFatalFilename(stored) ? [{ column, filename: stored, line }] : [];
|
|
203
|
+
}).slice(FIRST_INDEX, MAX_FATAL_STACK_FRAMES),
|
|
204
|
+
timestamp: event.timestamp
|
|
205
|
+
};
|
|
206
|
+
while (record.stackFrames.length > NO_COUNT && utf8ByteLength(JSON.stringify(record)) > MAX_FATAL_RECORD_BYTES) {
|
|
207
|
+
record.stackFrames.pop();
|
|
208
|
+
}
|
|
209
|
+
return record;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @param {unknown} value
|
|
214
|
+
* @returns {FatalFrame | undefined}
|
|
215
|
+
*/
|
|
216
|
+
function validatedFatalFrame(value) {
|
|
217
|
+
try {
|
|
218
|
+
if (!isPlainObject(value) || !hasExactKeys(value, FRAME_KEYS)) {
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
const { column, filename, line } = value;
|
|
222
|
+
if (!validFatalFilename(filename) || !positiveInteger(line) || !positiveInteger(column)) {
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
column,
|
|
227
|
+
filename,
|
|
228
|
+
line
|
|
229
|
+
};
|
|
230
|
+
} catch {
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* @param {unknown} value
|
|
237
|
+
* @returns {value is readonly unknown[]}
|
|
238
|
+
*/
|
|
239
|
+
function isList(value) {
|
|
240
|
+
return Array.isArray(value);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @param {readonly unknown[]} stackFrames
|
|
245
|
+
* @param {number} frameCount
|
|
246
|
+
* @returns {FatalFrame[] | undefined}
|
|
247
|
+
*/
|
|
248
|
+
function validatedFatalFrames(stackFrames, frameCount) {
|
|
249
|
+
/** @type {FatalFrame[]} */
|
|
250
|
+
const frames = [];
|
|
251
|
+
for (let index = FIRST_INDEX; index < frameCount; index += SECOND_INDEX) {
|
|
252
|
+
const frame = validatedFatalFrame(stackFrames[index]);
|
|
253
|
+
if (!frame) {
|
|
254
|
+
return undefined;
|
|
255
|
+
}
|
|
256
|
+
frames.push(frame);
|
|
257
|
+
}
|
|
258
|
+
return frames;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* @param {unknown} value
|
|
263
|
+
* @param {(value: unknown) => boolean} isErrorName
|
|
264
|
+
* @returns {FatalRecord | undefined}
|
|
265
|
+
*/
|
|
266
|
+
function readFatalRecord(value, isErrorName) {
|
|
267
|
+
if (!isPlainObject(value) || !hasExactKeys(value, RECORD_KEYS)) {
|
|
268
|
+
return undefined;
|
|
269
|
+
}
|
|
270
|
+
const { corruptRecords, droppedRecords, errorName, id, schemaVersion, stackFrames, timestamp } = value;
|
|
271
|
+
const frameCount = isList(stackFrames) ? stackFrames.length : undefined;
|
|
272
|
+
if (schemaVersion !== FATAL_RECORD_SCHEMA_VERSION
|
|
273
|
+
|| typeof id !== "string"
|
|
274
|
+
|| id.length > MAX_FATAL_ID_LENGTH
|
|
275
|
+
|| !FATAL_ID_PATTERN.test(id)
|
|
276
|
+
|| !isErrorName(errorName)
|
|
277
|
+
|| !isBoundedCounter(corruptRecords)
|
|
278
|
+
|| !isBoundedCounter(droppedRecords)
|
|
279
|
+
|| !validFatalTimestamp(timestamp)
|
|
280
|
+
|| !isBoundedCounter(frameCount)
|
|
281
|
+
|| frameCount > MAX_FATAL_STACK_FRAMES
|
|
282
|
+
|| !isList(stackFrames)) {
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
const frames = validatedFatalFrames(stackFrames, frameCount);
|
|
286
|
+
const record = frames && {
|
|
287
|
+
corruptRecords,
|
|
288
|
+
droppedRecords,
|
|
289
|
+
errorName,
|
|
290
|
+
id,
|
|
291
|
+
schemaVersion: FATAL_RECORD_SCHEMA_VERSION,
|
|
292
|
+
stackFrames: frames,
|
|
293
|
+
timestamp
|
|
294
|
+
};
|
|
295
|
+
return record && utf8ByteLength(JSON.stringify(record)) <= MAX_FATAL_RECORD_BYTES ? record : undefined;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* @param {unknown} value
|
|
300
|
+
* @param {(value: unknown) => boolean} isErrorName
|
|
301
|
+
* @returns {FatalRecord | undefined}
|
|
302
|
+
*/
|
|
303
|
+
function validatedFatalRecord(value, isErrorName) {
|
|
304
|
+
try {
|
|
305
|
+
return readFatalRecord(value, isErrorName);
|
|
306
|
+
} catch {
|
|
307
|
+
return undefined;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
module.exports = {
|
|
312
|
+
boundedResultCounter,
|
|
313
|
+
createFatalRecord,
|
|
314
|
+
isPlainObject,
|
|
315
|
+
resultStatus,
|
|
316
|
+
validatedFatalRecord
|
|
317
|
+
};
|