@teincfood/core 0.10.5 → 0.10.7
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/offline/store.js +10 -5
- package/dist/reference/service.js +17 -4
- package/package.json +1 -1
package/dist/offline/store.js
CHANGED
|
@@ -204,8 +204,9 @@ export async function createOfflineMemberCredential(args) {
|
|
|
204
204
|
export const OFFLINE_PIN_MAX_ATTEMPTS = 5;
|
|
205
205
|
export async function getOfflinePinLockState(userId, businessId) {
|
|
206
206
|
const member = await getOfflineMember(userId, businessId);
|
|
207
|
-
const
|
|
208
|
-
const
|
|
207
|
+
const lockExpired = Boolean(member?.locked_until && new Date(member.locked_until).getTime() <= Date.now());
|
|
208
|
+
const failedAttempts = lockExpired ? 0 : member?.failed_attempts ?? 0;
|
|
209
|
+
const lockedUntil = lockExpired ? null : member?.locked_until ?? null;
|
|
209
210
|
const locked = Boolean(lockedUntil && new Date(lockedUntil).getTime() > Date.now());
|
|
210
211
|
return {
|
|
211
212
|
failedAttempts,
|
|
@@ -215,12 +216,16 @@ export async function getOfflinePinLockState(userId, businessId) {
|
|
|
215
216
|
};
|
|
216
217
|
}
|
|
217
218
|
export async function verifyOfflineMemberPin(userId, pin, businessId) {
|
|
218
|
-
const
|
|
219
|
-
if (!
|
|
219
|
+
const stored = await getOfflineMember(userId, businessId);
|
|
220
|
+
if (!stored)
|
|
220
221
|
return false;
|
|
221
|
-
if (
|
|
222
|
+
if (stored.locked_until && new Date(stored.locked_until).getTime() > Date.now()) {
|
|
222
223
|
return false;
|
|
223
224
|
}
|
|
225
|
+
// An expired cooldown grants a fresh set of attempts.
|
|
226
|
+
const member = stored.locked_until && new Date(stored.locked_until).getTime() <= Date.now()
|
|
227
|
+
? { ...stored, failed_attempts: 0, locked_until: null }
|
|
228
|
+
: stored;
|
|
224
229
|
if (!/^\d{6}$/.test(pin)) {
|
|
225
230
|
await recordFailedPinAttempt(member);
|
|
226
231
|
return false;
|
|
@@ -469,16 +469,29 @@ class ReferenceSyncService {
|
|
|
469
469
|
// have the bytes in its durable image cache. Fetch only missing keys.
|
|
470
470
|
const peerConnectivity = getConnectivityState();
|
|
471
471
|
if (!peerConnectivity.isOnline || peerConnectivity.isCloudReachable === "unreachable") {
|
|
472
|
+
const missing = [];
|
|
472
473
|
for (const url of urls) {
|
|
473
474
|
if (!url || !url.startsWith("http"))
|
|
474
475
|
continue;
|
|
475
476
|
if (await hasCachedImage(url))
|
|
476
477
|
continue;
|
|
477
|
-
|
|
478
|
-
if (asset?.base64) {
|
|
479
|
-
await cacheImageFromBase64(url, asset.base64);
|
|
480
|
-
}
|
|
478
|
+
missing.push(url);
|
|
481
479
|
}
|
|
480
|
+
// A menu can reference dozens of images. Keep peer transfers bounded so
|
|
481
|
+
// a dark-LAN catch-up does not serialize 15s timeouts.
|
|
482
|
+
const queue = [...missing];
|
|
483
|
+
const worker = async () => {
|
|
484
|
+
for (;;) {
|
|
485
|
+
const url = queue.shift();
|
|
486
|
+
if (!url)
|
|
487
|
+
return;
|
|
488
|
+
const asset = await requestAssetFromPeer(businessId, url);
|
|
489
|
+
if (asset?.base64) {
|
|
490
|
+
await cacheImageFromBase64(url, asset.base64);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
await Promise.all(Array.from({ length: Math.min(3, queue.length) }, worker));
|
|
482
495
|
}
|
|
483
496
|
await pruneImageCache(urls);
|
|
484
497
|
}
|
package/package.json
CHANGED