import { getLocalizedString } from "@olenbetong/appframe-core"; import type { AppMenuCategory } from "./types.js"; export type DeveloperCategoryOptions = { /** Article the "Edit article"/"Edit app" links point at. Defaults to `af.article.id`. */ articleId?: string; /** CMS host name used by the app designer links. Defaults to `af.article.hostName`. */ hostName?: string; /** App designer host. */ devUrl?: string; /** Content editor host. */ testUrl?: string; /** * Include the cache clearing buttons. They post to `/api/debug/cache/...`, * which requires two verified authentication factors. */ includeCacheTools?: boolean; }; /** * Build the Articles/Developer/Debug categories that used to live in the * sidebar's developer disclosure menu. * * Only render these for users where `af.userSession.isDeveloper` is true — the * targets are all developer-only and will return 403 for everyone else. */ export function createDeveloperCategories({ articleId = globalThis.af?.article?.id ?? "", hostName = globalThis.af?.article?.hostName ?? "", devUrl = "https://dev.obet.no", testUrl = "https://test.synergi.olenbetong.no", includeCacheTools = true, }: DeveloperCategoryOptions = {}): AppMenuCategory[] { let section = getLocalizedString("Developer"); return [ { id: "dev-articles", label: getLocalizedString("Articles"), section, groups: [ { title: getLocalizedString("Apps & articles"), items: [ { label: getLocalizedString("New article"), href: `${testUrl}/content` }, { label: getLocalizedString("Edit article"), href: `${testUrl}/content?${articleId}` }, ], }, { title: getLocalizedString("App designer"), items: [ { label: getLocalizedString("New app"), href: `${devUrl}/appdesigner?${hostName}` }, { label: getLocalizedString("Edit app"), href: `${devUrl}/appdesigner?${hostName}/${articleId}` }, { label: getLocalizedString("Article List"), href: "/appdesigner-articlelist" }, { label: getLocalizedString("Manage translations"), href: "/system-translate" }, ], }, { title: getLocalizedString("Navigation"), items: [ { label: getLocalizedString("Edit sidebar"), href: `${devUrl}/appdesigner?${hostName}/sidebar` }, { label: getLocalizedString("Sidebar applications"), href: `${devUrl}/manage-sidebar-applications` }, { label: getLocalizedString("Article Icons"), href: "/article-icons" }, ], }, ], }, { id: "dev-tools", label: getLocalizedString("Development"), section, groups: [ { title: getLocalizedString("Developer"), items: [ { label: "DB Manager", href: "/af-dbmanager" }, { label: "Code Modules", href: "/code-modules" }, { label: "Assemblies", href: "/af-assemblies" }, { label: "Site Setup", href: "/sitesetup" }, { label: "Bundles", href: "/af-bundle" }, { label: "Updater", href: "/af-updater" }, { label: "Scheduler", href: "/af-scheduler" }, ], }, { title: "System", items: [ { label: getLocalizedString("Manage Users"), href: "/system-users" }, { label: getLocalizedString("Manage Roles"), href: "/system-roles" }, { label: getLocalizedString("Manage Domains"), href: "/system-domains" }, ], }, ], }, { id: "dev-debug", label: getLocalizedString("Debugging"), section, groups: [ { title: getLocalizedString("Debug"), items: [ { label: getLocalizedString("Cache Control"), href: "/api/debug/cache" }, { label: getLocalizedString("Razor"), href: "/api/debug/razor" }, { label: getLocalizedString("Placeholders"), href: "/api/debug/placeholders" }, { label: getLocalizedString("Routes"), href: "/api/debug/routes" }, { label: getLocalizedString("DB Trace"), href: "/api/debug/trace" }, { label: getLocalizedString("DB Profiler"), href: "/api/debug/profiler" }, { label: getLocalizedString("Errors"), href: "/api/debug/errors" }, { label: getLocalizedString("Modules"), href: "/api/debug/modules" }, { label: getLocalizedString("Assemblies"), href: "/api/debug/assemblies" }, ], }, ...(includeCacheTools ? [ { title: getLocalizedString("Clear cache"), // Handled by the delegated `[data-action=clear-cache]` listener in the site scripts. items: [ { label: getLocalizedString("Data object definition"), cache: "object-definitions" }, { label: getLocalizedString("Article"), cache: "article-cache" }, { label: getLocalizedString("File groups"), cache: "file-groups" }, { label: getLocalizedString("Content delivery"), cache: "content-delivery" }, { label: getLocalizedString("Localization"), cache: "localization" }, { label: getLocalizedString("Code modules"), cache: "code-modules", method: "reload" }, ].map(({ label, cache, method }) => ({ label, keepOpen: true, attributes: { "data-action": "clear-cache", "data-cache": cache, ...(method ? { "data-cache-method": method } : {}), }, })), }, ] : []), ], }, ]; }