Track HiveGrid Cloud planning reference

This commit is contained in:
david committed 2026-06-26 20:48:01 +02:00
1 parent b3d5ea6764
commit e341c5938a
5784 files changed
+1104929 -3

No files matched your search

@@ -0,0 +1,9 @@
// Sites Framework - Server Configuration
// Environment-based server retrieval - do not modify
import { SITE_TYPE } from "../site-types";
import { SiteServerConfig } from "./types";
export function getSiteServers(_type?: SITE_TYPE): SiteServerConfig[] {
return [];
}
@@ -0,0 +1,61 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { SiteTypeConfig } from "../site-types";
const getSiteTypeMock = vi.hoisted(() => vi.fn());
vi.mock("../site-types", () => ({
getSiteType: getSiteTypeMock,
}));
import { buildCopyWithFallbacks, getSiteCopyFallbackKey } from "./site-settings-utils";
const siteTypeConfig: SiteTypeConfig = {
enabled: true,
name: "Portal",
description: "Customer-facing portal",
copyKeys: [
{
section: "Hero",
name: "Title",
key: "heroTitle",
fallback: "Welcome",
},
],
};
describe("site settings i18n fallbacks", () => {
beforeEach(() => {
getSiteTypeMock.mockReset();
getSiteTypeMock.mockReturnValue(siteTypeConfig);
});
it("derives stable copy fallback translation keys from the site type and copy key", () => {
expect(getSiteCopyFallbackKey("customer-portal", "heroTitle")).toBe("models.site.types.customer-portal.copy.heroTitle.fallback");
});
it("preserves saved tenant copy before resolving fallback translations", () => {
const t = vi.fn((key: string) => `translated:${key}`);
expect(buildCopyWithFallbacks("portal", { heroTitle: "Tenant welcome" }, t)).toEqual({
heroTitle: "Tenant welcome",
});
expect(t).not.toHaveBeenCalled();
});
it("resolves missing copy through the i18n fallback key", () => {
const t = vi.fn((key: string) => (key === "models.site.types.portal.copy.heroTitle.fallback" ? "Willkommen" : key));
expect(buildCopyWithFallbacks("portal", {}, t)).toEqual({
heroTitle: "Willkommen",
});
expect(t).toHaveBeenCalledWith("models.site.types.portal.copy.heroTitle.fallback");
});
it("keeps the config fallback as the last resort when an i18n key is missing", () => {
const t = vi.fn((key: string) => key);
expect(buildCopyWithFallbacks("portal", {}, t)).toEqual({
heroTitle: "Welcome",
});
});
});
@@ -0,0 +1,34 @@
// ============================================
// Site Settings Utilities
// Helper functions for copy configuration
// ============================================
import { getSiteType } from "../site-types";
type SiteCopyTranslator = (key: string) => string;
export function getSiteCopyFallbackKey(type: string, key: string): string {
return `models.site.types.${type}.copy.${key}.fallback`;
}
function resolveCopyFallback(type: string, key: string, fallback: string, t?: SiteCopyTranslator): string {
if (!t) return fallback;
const fallbackKey = getSiteCopyFallbackKey(type, key);
const translated = t(fallbackKey);
return translated === fallbackKey ? fallback : translated;
}
/**
* Build copy object with fallback values for missing keys
*/
export function buildCopyWithFallbacks(type: string, savedCopy: Record<string, string> | null, t?: SiteCopyTranslator): Record<string, string> {
const siteType = getSiteType(type);
if (!siteType) return {};
const result: Record<string, string> = {};
for (const { key, fallback } of siteType.copyKeys) {
result[key] = savedCopy?.[key] || resolveCopyFallback(type, key, fallback, t);
}
return result;
}
@@ -0,0 +1,38 @@
// Sites Framework Types
// These are the core type definitions - do not modify
export type SiteTypeConfig = {
enabled: boolean;
name: string;
nameKey?: string;
description: string;
descriptionKey?: string;
copyKeys: { section: string; name: string; key: string; fallback: string }[];
};
export const SiteServerResolutionModes = [
{
nameKey: "models.site.resolutionModes.domain",
value: "domain",
description: "https://{siteId}",
},
{
nameKey: "models.site.resolutionModes.path",
value: "path",
description: "https://example.com/{siteId}",
},
{
nameKey: "models.site.resolutionModes.subdomain",
value: "subdomain",
description: "https://{siteId}.example.com",
},
] as const;
export type SiteServerResolutionMode = (typeof SiteServerResolutionModes)[number]["value"];
export type SiteServerConfig = {
name: string;
description?: string;
host: string; // e.g., "localhost:3001" or "booking.example.com"
resolutionMode: SiteServerResolutionMode;
};
@@ -0,0 +1,36 @@
// Sites Framework Utilities
// URL building utilities - do not modify
import { SiteServerConfig, SiteServerResolutionMode } from "./types";
export function buildSiteUrl(params: { serverHost: string; serverResolution: SiteServerResolutionMode | (string & {}); siteId: string }): string {
return buildSiteUrlFromFields(params.serverHost, params.serverResolution, params.siteId);
}
export function buildSiteUrlFromServer(server: SiteServerConfig, siteId: string): string {
const protocol = server.host.startsWith("localhost") ? "http" : "https";
switch (server.resolutionMode) {
case "domain":
return `${protocol}://${server.host}`;
case "path":
return `${protocol}://${server.host}/${siteId}`;
case "subdomain":
return `${protocol}://${siteId}.${server.host}`;
default:
return `${protocol}://${server.host}/${siteId}`;
}
}
export function buildSiteUrlFromFields(serverHost: string, serverResolution: SiteServerResolutionMode | (string & {}), siteId: string): string {
const protocol = serverHost.startsWith("localhost") ? "http" : "https";
switch (serverResolution) {
case "domain":
return `${protocol}://${serverHost}`;
case "path":
return `${protocol}://${serverHost}/${siteId}`;
case "subdomain":
return `${protocol}://${siteId}.${serverHost}`;
default:
return `${protocol}://${serverHost}/${siteId}`;
}
}