@logbrew/sdk 0.1.21 → 0.1.22
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/core.cjs +12 -4
- package/package.json +1 -1
package/core.cjs
CHANGED
|
@@ -1194,6 +1194,11 @@ function loadStoredEvents({
|
|
|
1194
1194
|
return { events, queuedEventBytes, serializedEventBytes, serializedEvents };
|
|
1195
1195
|
}
|
|
1196
1196
|
|
|
1197
|
+
function structuralJson(value) {
|
|
1198
|
+
return JSON.stringify(value, (_, entry) => entry && !Array.isArray(entry) && typeof entry === "object"
|
|
1199
|
+
? Object.fromEntries(Object.entries(entry).sort(([left], [right]) => left.localeCompare(right))) : entry);
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1197
1202
|
function normalizeStoredRecord(record) {
|
|
1198
1203
|
try {
|
|
1199
1204
|
if (!record || Array.isArray(record) || typeof record !== "object") {
|
|
@@ -1215,11 +1220,14 @@ function normalizeStoredRecord(record) {
|
|
|
1215
1220
|
if (JSON.stringify(event) !== serializedEvent || utf8ByteLength(serializedEvent) !== eventBytes) {
|
|
1216
1221
|
throw invalidStoredRecord();
|
|
1217
1222
|
}
|
|
1218
|
-
const
|
|
1223
|
+
const recoveredAttributes = event.type === "issue" && event.attributes.level === "fatal"
|
|
1224
|
+
? { ...event.attributes, level: "critical" }
|
|
1225
|
+
: event.attributes;
|
|
1226
|
+
const context = recoveredAttributes.context;
|
|
1219
1227
|
const recoveredEvent = context && !Array.isArray(context) && typeof context === "object"
|
|
1220
1228
|
&& context.schemaVersion === undefined
|
|
1221
|
-
? { ...event, attributes: { ...
|
|
1222
|
-
: event;
|
|
1229
|
+
? { ...event, attributes: { ...recoveredAttributes, context: { schemaVersion: 1, ...context } } }
|
|
1230
|
+
: { ...event, attributes: recoveredAttributes };
|
|
1223
1231
|
const normalizedEvent = {
|
|
1224
1232
|
type: recoveredEvent.type,
|
|
1225
1233
|
id: recoveredEvent.id,
|
|
@@ -1227,7 +1235,7 @@ function normalizeStoredRecord(record) {
|
|
|
1227
1235
|
attributes: validator(recoveredEvent.attributes)
|
|
1228
1236
|
};
|
|
1229
1237
|
const normalizedSerializedEvent = JSON.stringify(normalizedEvent);
|
|
1230
|
-
if (
|
|
1238
|
+
if (structuralJson(normalizedEvent) !== structuralJson(recoveredEvent)) {
|
|
1231
1239
|
throw invalidStoredRecord();
|
|
1232
1240
|
}
|
|
1233
1241
|
return {
|