فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

fix(A06): distinguish first install from corrupt persisted trial state

davoodmehraban89 committed Oct 16, 2026 at 22:11 UTC 279a007630ab66c790ff2a38da5de53ac2703389
1 file changed +12 -6
src/core/LicenseService.js
+12 -6
@@ -20,18 +20,24 @@ class LicenseServiceImpl {
20
21 async init() {
22 let stored = await SecureState.get(KEY);
23 - if (!stored) {
24 - try { stored = JSON.parse(localStorage.getItem(LEGACY_KEY) || 'null'); }
25 - catch (_) { /* Invalid legacy state is not an entitlement. */ }
23 + let hadStoredState = stored !== null && stored !== undefined;
24 + if (!hadStoredState) {
25 + const legacyRaw = localStorage.getItem(LEGACY_KEY);
26 + if (legacyRaw !== null) {
27 + hadStoredState = true;
28 + try { stored = JSON.parse(legacyRaw); }
29 + catch (_) { stored = null; /* Invalid legacy state must fail closed. */ }
30 + }
31 }
32 stored = stored && typeof stored === 'object' && !Array.isArray(stored) ? stored : {};
33 const now = Date.now();
29 - if (!stored.trialStartedAt || !Number.isFinite(Date.parse(stored.trialStartedAt))) {
34 + if (!hadStoredState) {
35 + // Only a truly new installation receives an initial free trial.
36 stored.trialStartedAt = new Date(now).toISOString();
31 - }
32 - if (!Number.isSafeInteger(stored.issuedInvoiceCount) || stored.issuedInvoiceCount < 0) {
37 stored.issuedInvoiceCount = 0;
38 }
39 + // Never rewrite malformed persisted dates/counters into a fresh trial.
40 + // trialStatus() leaves financial data readable but rejects further writes.
41 if (!stored.installationId || typeof stored.installationId !== 'string') {
42 stored.installationId = crypto.randomUUID();
43 }