@teincfood/core 0.10.6 → 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.
@@ -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 failedAttempts = member?.failed_attempts ?? 0;
208
- const lockedUntil = member?.locked_until ?? null;
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 member = await getOfflineMember(userId, businessId);
219
- if (!member)
219
+ const stored = await getOfflineMember(userId, businessId);
220
+ if (!stored)
220
221
  return false;
221
- if (member.locked_until && new Date(member.locked_until).getTime() > Date.now()) {
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teincfood/core",
3
- "version": "0.10.6",
3
+ "version": "0.10.7",
4
4
  "description": "TeincFood shared offline-first core — types, sync engine, local DB, reference data, and repositories for mobile + desktop",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",