Setting the file. One moment.
Site Regional Gate · Wix Replatform · wix/skills · Skills Docs
ContentsBack to the top of the page lib/site-regional-gate.js
lib/ site-regional-gate.js
JavaScript · 62 lines · 3 KB
{
hashArtifact
}
=
require
(
'./artifact-freshness.js'
);
11
12 const GATE_CODES = Object. freeze ({
13 SITE_LOCALE_NOT_READY: { action: 'The site locale entity has not passed for this site, plan, source and owner decision. Run setup.' },
14 SITE_LOCALE_KEPT: { action: 'The owner kept a differing site locale. Neutral records may continue; change the relevant site value or answer, rerun setup, then catch up this held task.' },
15 });
16
17 function verificationRow ( projectDir ) {
18 const verification = core. readJsonSync (path. join (projectDir, 'setup' , 'setup-verification.json' ));
19 if ( ! verification) return { verification: null , row: null };
20 return { verification, row: (verification.requirements || []). find (( item ) => item && item.id === core. STEP_ID ) || null };
21 }
22
23 function receiptIsCurrent ( projectDir , siteId , verification , row ) {
24 if ( ! verification || ! row || row.status !== 'passed' || ! row.regional) return false ;
25 if (verification.siteId !== siteId) return false ;
26 if (verification.planDigest !== hashArtifact (projectDir, path. join ( 'setup' , 'setup-plan.json' ))) return false ;
27 if (row.regional.sourceDigest !== core. fileSha256 (projectDir, sr. SOURCE_REGIONAL_FILE )) return false ;
28 if (row.regional.decisionDigest !== core. approvalDigest (projectDir, siteId)) return false ;
29 return core. SETTINGS . every (( field ) => row.regional.fields?.[field]?.verified === true );
30 }
31
32 function regionalDependency ({ projectDir , siteId , entityRefs }) {
33 const refuse = ( code , extra = {}) => ({ ok: false , gated: true , code, ... GATE_CODES [code], ... extra });
34 try {
35 if ( ! sr. readSourceRegionalSync (projectDir)) return refuse ( 'SITE_LOCALE_NOT_READY' , { reason: 'source-locale-missing' });
36 } catch {
37 return refuse ( 'SITE_LOCALE_NOT_READY' , { reason: 'source-locale-invalid' });
38 }
39 if ( ! core. planHasRegionalStep (projectDir)) return refuse ( 'SITE_LOCALE_NOT_READY' , { reason: 'site-locale-step-missing' });
40 const { verification , row } = verificationRow (projectDir);
41 if ( ! receiptIsCurrent (projectDir, siteId, verification, row)) return refuse ( 'SITE_LOCALE_NOT_READY' , { reason: 'site-locale-receipt-not-current' });
42
43 const parts = core. partitionRefs (entityRefs);
44 const fields = row.regional.fields || {};
45 const keptFields = [];
46 const affectedRefs = new Set ();
47 if (fields.currency?.action === 'kept' ) {
48 keptFields. push ( 'currency' );
49 for ( const ref of parts.moneyBearingRefs) affectedRefs. add (ref);
50 }
51 if (fields.timeZone?.action === 'kept' ) {
52 keptFields. push ( 'timeZone' );
53 for ( const ref of parts.wallClockRefs) affectedRefs. add (ref);
54 }
55 // Unknown families are never silently neutral. While either semantic setting is kept, hold
56 // them until their domain is classified and the coverage test is updated.
57 if (keptFields. length ) for ( const ref of parts.unclassifiedRefs) affectedRefs. add (ref);
58 if (affectedRefs.size) return refuse ( 'SITE_LOCALE_KEPT' , { keptFields, affectedRefs: [ ... affectedRefs]. sort () });
59 return { ok: true , gated: true , keptFields, affectedRefs: [] };
60 }
61
62 module . exports = { GATE_CODES, regionalDependency, receiptIsCurrent, verificationRow };