package content fully tenant-editable and versioned in the admin
This commit is contained in:
@@ -173,6 +173,9 @@ export const DISCLAIMER_TEMPLATE =
|
||||
'premium savings are illustrative only and must be confirmed with your insurance carrier or licensed ' +
|
||||
'insurance professional. Historical storm information is not a forecast or guarantee.';
|
||||
|
||||
// Schema version of the config shape. The *published* tenant version is this plus
|
||||
// a revision suffix (e.g. tenant-config-v1.r4) that bumps on every admin save, so
|
||||
// each report records exactly which package content/pricing produced it (§14, §18).
|
||||
export const TENANT_CONFIG_VERSION = 'tenant-config-v1';
|
||||
export const DISCLAIMER_VERSION = 'disclaimer-v1';
|
||||
|
||||
@@ -214,11 +217,36 @@ export function resetConfigOverrides() {
|
||||
try { localStorage.removeItem(CONFIG_STORAGE_KEY); } catch { /* ignore */ }
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish a new tenant config version (spec §14: "versioned"). Bumps the revision,
|
||||
* stamps versionedAt, and appends to a capped version history so admins can see and
|
||||
* audit every change. Returns the saved overrides (with the new version metadata).
|
||||
*/
|
||||
export function publishConfigOverrides(overrides) {
|
||||
const prev = loadConfigOverrides();
|
||||
const revision = (Number(prev.revision) || 0) + 1;
|
||||
const version = `${TENANT_CONFIG_VERSION}.r${revision}`;
|
||||
const versionedAt = new Date().toISOString();
|
||||
const history = Array.isArray(prev.versionHistory) ? prev.versionHistory : [];
|
||||
|
||||
const saved = {
|
||||
...overrides,
|
||||
revision,
|
||||
version,
|
||||
versionedAt,
|
||||
versionHistory: [{ revision, version, versionedAt }, ...history].slice(0, 25),
|
||||
};
|
||||
saveConfigOverrides(saved);
|
||||
return saved;
|
||||
}
|
||||
|
||||
export function getTenantConfig() {
|
||||
const base = defaults();
|
||||
const o = loadConfigOverrides();
|
||||
|
||||
// Shallow-merge top-level objects so partial admin edits don't drop defaults.
|
||||
// `...o` lets a published version/versionedAt/revision override the base schema
|
||||
// version, so getTenantConfig().version reflects the tenant's edits.
|
||||
return {
|
||||
...base,
|
||||
...o,
|
||||
|
||||
Reference in New Issue
Block a user