Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/utils/app/PublicRouteSegments.ts
T
2026-07-08 16:15:37 +02:00

149 lines
3.5 KiB
TypeScript

export const publicWebRouteExactPaths = ["/sitemap.xml"] as const;
export const protectedWebRouteExactPaths = ["/postman_collection.json"] as const;
export const publicWebRoutePrefixes = [
"/401",
"/403",
"/404",
"/500",
"/auth/",
"/deactivated/",
"/docs",
"/feature-disabled",
"/forgot-password",
"/healthcheck",
"/healthz",
"/invitation/",
"/login",
"/logout",
"/mfa-challenge",
"/new-account",
"/oauth/",
"/onboarding/",
"/plan-required/",
"/preferences",
"/privacy-policy",
"/readyz",
"/register",
"/reset",
"/select-tenant",
"/signup",
"/sitemap.xml",
"/subscribe/",
"/terms-and-conditions",
"/unauthorized",
"/verify/",
] as const;
export const protectedWebRoutePrefixes = ["/swagger"] as const;
export const absoluteWebHostRoutePrefixes = publicWebRoutePrefixes;
export const canonicalAdminRouteSlugs = [
"accounts",
"analytics",
"api",
"audit",
"audit-trails",
"dashboard",
"email-sequences",
"entities",
"events",
"feature-flags",
"internal",
"marketing-funnels",
"marketing-integrations",
"marketing-leads",
"metrics",
"mfa-challenge",
"notifications",
"onboarding",
"settings",
"select-tenant",
] as const;
export const disabledPluginRouteSlugs = [
"ai",
"chat",
"crm",
"email-marketing",
"help",
"help-desk",
"knowledge-base",
"mcp",
"portals",
"prompts",
"workflow-engine",
] as const;
export const reservedTenantRouteSlugs = [
"admin",
"api",
"app",
"null",
"undefined",
"v1",
...canonicalAdminRouteSlugs,
...disabledPluginRouteSlugs,
...new Set(
[...publicWebRoutePrefixes, ...protectedWebRoutePrefixes]
.flatMap((prefix) => prefix.split("/").filter(Boolean).slice(0, 1))
.concat(protectedWebRouteExactPaths.flatMap((path) => path.split("/").filter(Boolean).slice(0, 1)))
.filter(Boolean)
),
] as const;
export const reservedTenantChildRouteSlugs = [
"__portals",
"__widgets",
"__workflows",
"chat",
"crm",
"dashboard",
"email-marketing",
"g",
"internal",
"notifications",
"portals",
"settings",
"sites",
"widgets",
"workflow-engine",
] as const;
export function pathMatchesRoutePrefix(pathname: string, prefix: string) {
const normalizedPrefix = prefix.replace(/\/$/, "");
return pathname === normalizedPrefix || pathname.startsWith(`${normalizedPrefix}/`);
}
export function normalizeRoutePath(pathname: string) {
const normalizedPathname = pathname.startsWith("/") ? pathname : `/${pathname}`;
return normalizedPathname.replace(/\.data$/, "");
}
export function isPublicWebRoutePath(pathname: string) {
const routePathname = normalizeRoutePath(pathname);
if ((publicWebRouteExactPaths as readonly string[]).includes(routePathname)) {
return true;
}
return publicWebRoutePrefixes.some((prefix) => pathMatchesRoutePrefix(routePathname, prefix));
}
export function isWebRoutePath(pathname: string) {
const routePathname = normalizeRoutePath(pathname);
if (isPublicWebRoutePath(routePathname)) {
return true;
}
if ((protectedWebRouteExactPaths as readonly string[]).includes(routePathname)) {
return true;
}
return protectedWebRoutePrefixes.some((prefix) => pathMatchesRoutePrefix(routePathname, prefix));
}
export function isAbsoluteWebHostPath(pathname: string) {
const routePathname = normalizeRoutePath(pathname);
if ((publicWebRouteExactPaths as readonly string[]).includes(routePathname)) {
return true;
}
return absoluteWebHostRoutePrefixes.some((prefix) => pathMatchesRoutePrefix(routePathname, prefix));
}