@mushi-mushi/core 1.18.0 → 1.19.0
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/dist/index.cjs +42 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +42 -40
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1000,6 +1000,30 @@ function createOfflineQueue(config = {}) {
|
|
|
1000
1000
|
lsWrite(rows);
|
|
1001
1001
|
}
|
|
1002
1002
|
}
|
|
1003
|
+
async function removeRow(backend, rowId) {
|
|
1004
|
+
try {
|
|
1005
|
+
if (backend === "indexeddb") await idbDelete(rowId);
|
|
1006
|
+
else lsDelete(rowId);
|
|
1007
|
+
} catch (err) {
|
|
1008
|
+
queueLog.debug("Offline queue: row removal failed (will age out)", {
|
|
1009
|
+
id: rowId,
|
|
1010
|
+
err: String(err)
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
async function persistRow(backend, row) {
|
|
1015
|
+
try {
|
|
1016
|
+
if (backend === "indexeddb") await idbPutRow(row);
|
|
1017
|
+
else lsUpdateRow(row);
|
|
1018
|
+
return true;
|
|
1019
|
+
} catch (err) {
|
|
1020
|
+
queueLog.debug("Offline queue: row persist failed", {
|
|
1021
|
+
id: row.id,
|
|
1022
|
+
err: String(err)
|
|
1023
|
+
});
|
|
1024
|
+
return false;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1003
1027
|
async function enqueue(report) {
|
|
1004
1028
|
if (!enabled) return;
|
|
1005
1029
|
const currentSize = await size();
|
|
@@ -1045,12 +1069,7 @@ function createOfflineQueue(config = {}) {
|
|
|
1045
1069
|
for (const row of rows) {
|
|
1046
1070
|
if (isExpired(row, now)) {
|
|
1047
1071
|
const rowId = row.id;
|
|
1048
|
-
|
|
1049
|
-
if (backend === "indexeddb") await idbDelete(rowId);
|
|
1050
|
-
else lsDelete(rowId);
|
|
1051
|
-
} catch {
|
|
1052
|
-
lsDelete(rowId);
|
|
1053
|
-
}
|
|
1072
|
+
await removeRow(backend, rowId);
|
|
1054
1073
|
queueLog.debug("Offline queue: evicting stale report", { id: rowId });
|
|
1055
1074
|
} else {
|
|
1056
1075
|
fresh.push(row);
|
|
@@ -1065,23 +1084,13 @@ function createOfflineQueue(config = {}) {
|
|
|
1065
1084
|
const rowId = row.id;
|
|
1066
1085
|
const report = await unwrapForSend(row);
|
|
1067
1086
|
if (!report) {
|
|
1068
|
-
|
|
1069
|
-
if (backend === "indexeddb") await idbDelete(rowId);
|
|
1070
|
-
else lsDelete(rowId);
|
|
1071
|
-
} catch {
|
|
1072
|
-
lsDelete(rowId);
|
|
1073
|
-
}
|
|
1087
|
+
await removeRow(backend, rowId);
|
|
1074
1088
|
failed++;
|
|
1075
1089
|
continue;
|
|
1076
1090
|
}
|
|
1077
1091
|
const result = await client.submitReport(report);
|
|
1078
1092
|
if (result.ok) {
|
|
1079
|
-
|
|
1080
|
-
if (backend === "indexeddb") await idbDelete(rowId);
|
|
1081
|
-
else lsDelete(rowId);
|
|
1082
|
-
} catch {
|
|
1083
|
-
lsDelete(rowId);
|
|
1084
|
-
}
|
|
1093
|
+
await removeRow(backend, rowId);
|
|
1085
1094
|
sent++;
|
|
1086
1095
|
} else {
|
|
1087
1096
|
const permanent = result.error?.code === "HTTP_400" || result.error?.code === "HTTP_413" || result.error?.code === "HTTP_422" || result.error?.code === "INGEST_ERROR" || result.error?.code === "VALIDATION_ERROR" || // A payload that exceeds the size guard will never shrink on its own;
|
|
@@ -1093,21 +1102,11 @@ function createOfflineQueue(config = {}) {
|
|
|
1093
1102
|
);
|
|
1094
1103
|
const transient = !permanent && (result.error?.code === "NETWORK_ERROR" || result.error?.code === "HTTP_403" || result.error?.code === "HTTP_429" || result.error?.code === "HTTP_502" || result.error?.code === "HTTP_503" || result.error?.code === "HTTP_504" || typeof result.error?.code === "string" && result.error.code.startsWith("HTTP_5"));
|
|
1095
1104
|
if (permanent) {
|
|
1096
|
-
|
|
1097
|
-
if (backend === "indexeddb") await idbDelete(rowId);
|
|
1098
|
-
else lsDelete(rowId);
|
|
1099
|
-
} catch {
|
|
1100
|
-
lsDelete(rowId);
|
|
1101
|
-
}
|
|
1105
|
+
await removeRow(backend, rowId);
|
|
1102
1106
|
} else if (transient) {
|
|
1103
1107
|
const nextAttempts = rowAttempts(row) + 1;
|
|
1104
1108
|
if (nextAttempts >= MAX_DELIVERY_ATTEMPTS) {
|
|
1105
|
-
|
|
1106
|
-
if (backend === "indexeddb") await idbDelete(rowId);
|
|
1107
|
-
else lsDelete(rowId);
|
|
1108
|
-
} catch {
|
|
1109
|
-
lsDelete(rowId);
|
|
1110
|
-
}
|
|
1109
|
+
await removeRow(backend, rowId);
|
|
1111
1110
|
queueLog.warn("Offline queue: giving up on report after repeated failures", {
|
|
1112
1111
|
id: rowId,
|
|
1113
1112
|
attempts: nextAttempts,
|
|
@@ -1115,17 +1114,20 @@ function createOfflineQueue(config = {}) {
|
|
|
1115
1114
|
});
|
|
1116
1115
|
} else {
|
|
1117
1116
|
row.attempts = nextAttempts;
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1117
|
+
const persisted = await persistRow(backend, row);
|
|
1118
|
+
if (persisted) {
|
|
1119
|
+
queueLog.debug("Offline queue: transient failure, will retry", {
|
|
1120
|
+
id: rowId,
|
|
1121
|
+
attempts: nextAttempts,
|
|
1122
|
+
code: result.error?.code
|
|
1123
|
+
});
|
|
1124
|
+
} else {
|
|
1125
|
+
await removeRow(backend, rowId);
|
|
1126
|
+
queueLog.warn("Offline queue: dropping report (attempt counter unpersistable)", {
|
|
1127
|
+
id: rowId,
|
|
1128
|
+
code: result.error?.code
|
|
1129
|
+
});
|
|
1123
1130
|
}
|
|
1124
|
-
queueLog.debug("Offline queue: transient failure, will retry", {
|
|
1125
|
-
id: rowId,
|
|
1126
|
-
attempts: nextAttempts,
|
|
1127
|
-
code: result.error?.code
|
|
1128
|
-
});
|
|
1129
1131
|
}
|
|
1130
1132
|
}
|
|
1131
1133
|
failed++;
|