46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
|
|
export type RuntimeRecordType = 'role' | 'dashboard' | 'onboarding';
|
||
|
|
export type RuntimeRecordStatus = 'draft' | 'published';
|
||
|
|
|
||
|
|
const KEY = 'nxtgauge_admin_runtime_builder_v1';
|
||
|
|
|
||
|
|
type RuntimeStore = {
|
||
|
|
role: Record<string, unknown>;
|
||
|
|
dashboard: Record<string, unknown>;
|
||
|
|
onboarding: Record<string, unknown>;
|
||
|
|
};
|
||
|
|
|
||
|
|
function readStore(): RuntimeStore {
|
||
|
|
if (typeof window === 'undefined') {
|
||
|
|
return { role: {}, dashboard: {}, onboarding: {} };
|
||
|
|
}
|
||
|
|
const raw = window.localStorage.getItem(KEY);
|
||
|
|
if (!raw) return { role: {}, dashboard: {}, onboarding: {} };
|
||
|
|
try {
|
||
|
|
const parsed = JSON.parse(raw) as Partial<RuntimeStore>;
|
||
|
|
return {
|
||
|
|
role: parsed.role || {},
|
||
|
|
dashboard: parsed.dashboard || {},
|
||
|
|
onboarding: parsed.onboarding || {},
|
||
|
|
};
|
||
|
|
} catch {
|
||
|
|
return { role: {}, dashboard: {}, onboarding: {} };
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function writeStore(store: RuntimeStore) {
|
||
|
|
if (typeof window === 'undefined') return;
|
||
|
|
window.localStorage.setItem(KEY, JSON.stringify(store));
|
||
|
|
}
|
||
|
|
|
||
|
|
export function saveRuntimeConfig(type: RuntimeRecordType, key: string, payload: unknown, status: RuntimeRecordStatus) {
|
||
|
|
const store = readStore();
|
||
|
|
const bucket = store[type];
|
||
|
|
bucket[key] = {
|
||
|
|
status,
|
||
|
|
updatedAt: new Date().toISOString(),
|
||
|
|
payload,
|
||
|
|
};
|
||
|
|
writeStore(store);
|
||
|
|
}
|
||
|
|
|