فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
feat(A03): deterministic legacy audit metadata and hash migration
davoodmehraban89 committed
Oct 20, 2026 at 08:36 UTC
626f41bd0127008da2b1fb8f91bb446857d291de
1 file changed
+21
src/core/AuditChain.js
+21
@@ -40,3 +40,24 @@ export function verifyChain(rows, anchor = null) {
40
return {valid:false,index:ordered.length,reason:'anchor mismatch'};
41
return {valid:true,count:ordered.length,headHash:previous,anchored:anchor!==null};
42
}
43
+
44
+export function normalizeLegacyAudit(row, index, prevHash) {
45
+ if (!row || typeof row !== 'object' || Array.isArray(row)) throw new Error('Invalid audit record');
46
+ const copy = { ...row };
47
+ copy.actorId ??= 'legacy-unknown';
48
+ copy.sourceType ??= 'legacy';
49
+ copy.occurredAtUtc ??= '1970-01-01T00:00:00.000Z';
50
+ copy.businessDate ??= null;
51
+ copy.correlationId ??= `legacy:${copy.id}`;
52
+ copy.schemaVersion ??= 1;
53
+ copy.documentVersion ??= 1;
54
+ copy.result ??= 'committed';
55
+ copy.createdByService ??= false;
56
+ copy.safeSummary ??= { lineCount: 0 };
57
+ if (copy.chainIndex === undefined && copy.prevHash === undefined && copy.eventHash === undefined) {
58
+ copy.chainIndex = index;
59
+ copy.prevHash = prevHash;
60
+ copy.eventHash = auditHash(copy);
61
+ }
62
+ return copy;
63
+}