chore: standardize security and quality foundations
Magent CI/CD / verify (push) Failing after 9m34s
Magent CI/CD / deploy-beta (push) Skipped

This commit is contained in:
2026-09-17 20:03:47 +12:00
parent 5639dbcb83
commit f852e7c941
127 changed files with 17928 additions and 10741 deletions
+30 -30
View File
@@ -1,48 +1,48 @@
'use client'
"use client";
import { useEffect, useState } from 'react'
import { useEffect, useState } from "react";
const USER_VIEW_STORAGE_KEY = 'magent_user_view_preview'
const USER_VIEW_EVENT = 'magent:user-view-change'
const USER_VIEW_STORAGE_KEY = "magent_user_view_preview";
const USER_VIEW_EVENT = "magent:user-view-change";
const readUserViewPreview = () => {
if (typeof window === 'undefined') return false
return window.sessionStorage.getItem(USER_VIEW_STORAGE_KEY) === '1'
}
if (typeof window === "undefined") return false;
return window.sessionStorage.getItem(USER_VIEW_STORAGE_KEY) === "1";
};
const applyDocumentMode = (enabled: boolean) => {
if (typeof document === 'undefined') return
document.documentElement.dataset.userView = enabled ? 'true' : 'false'
}
if (typeof document === "undefined") return;
document.documentElement.dataset.userView = enabled ? "true" : "false";
};
export const setUserViewPreview = (enabled: boolean) => {
if (typeof window === 'undefined') return
if (typeof window === "undefined") return;
if (enabled) {
window.sessionStorage.setItem(USER_VIEW_STORAGE_KEY, '1')
window.sessionStorage.setItem(USER_VIEW_STORAGE_KEY, "1");
} else {
window.sessionStorage.removeItem(USER_VIEW_STORAGE_KEY)
window.sessionStorage.removeItem(USER_VIEW_STORAGE_KEY);
}
applyDocumentMode(enabled)
window.dispatchEvent(new CustomEvent(USER_VIEW_EVENT, { detail: { enabled } }))
}
applyDocumentMode(enabled);
window.dispatchEvent(new CustomEvent(USER_VIEW_EVENT, { detail: { enabled } }));
};
export const useUserViewPreview = () => {
const [enabled, setEnabled] = useState(false)
const [enabled, setEnabled] = useState(false);
useEffect(() => {
const sync = () => {
const nextValue = readUserViewPreview()
applyDocumentMode(nextValue)
setEnabled(nextValue)
}
sync()
window.addEventListener(USER_VIEW_EVENT, sync)
window.addEventListener('storage', sync)
const nextValue = readUserViewPreview();
applyDocumentMode(nextValue);
setEnabled(nextValue);
};
sync();
window.addEventListener(USER_VIEW_EVENT, sync);
window.addEventListener("storage", sync);
return () => {
window.removeEventListener(USER_VIEW_EVENT, sync)
window.removeEventListener('storage', sync)
}
}, [])
window.removeEventListener(USER_VIEW_EVENT, sync);
window.removeEventListener("storage", sync);
};
}, []);
return enabled
}
return enabled;
};