refactor: simplify widget and integration architecture
This commit is contained in:
1 parent
c988c35b29
commit
8f9efd0074
179 files changed
+1509
-4187
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { objectKeys } from "@homarr/common";
|
||||
|
||||
import { integrationDefs } from "./integration";
|
||||
import { getIntegrationDockerMetadata, integrationDefs } from "./integration";
|
||||
import type { IntegrationKind } from "./integration";
|
||||
|
||||
export const extractContainerImageName = (image: string): string => image.split("/").at(-1)?.split(":").at(0) ?? "";
|
||||
@@ -28,7 +28,7 @@ export const matchIntegrationKind = (search: string): IntegrationKind | null =>
|
||||
}
|
||||
|
||||
for (const kind of objectKeys(integrationDefs)) {
|
||||
if (integrationDefs[kind].features.docker.aliases.some((alias) => alias === normalized)) return kind;
|
||||
if (getIntegrationDockerMetadata(kind).aliases.some((alias) => alias === normalized)) return kind;
|
||||
}
|
||||
|
||||
for (const kind of objectKeys(integrationDefs)) {
|
||||
@@ -47,10 +47,10 @@ interface ContainerMatchInput {
|
||||
export const matchIntegrationKindFromContainer = (container: ContainerMatchInput): IntegrationKind | null => {
|
||||
const imageName = extractContainerImageName(container.image);
|
||||
const fromImage = matchIntegrationKind(imageName);
|
||||
if (fromImage && integrationDefs[fromImage].features.docker.discoverable) return fromImage;
|
||||
if (fromImage && getIntegrationDockerMetadata(fromImage).discoverable) return fromImage;
|
||||
|
||||
const fromName = matchIntegrationKind(container.name);
|
||||
if (fromName && integrationDefs[fromName].features.docker.discoverable) return fromName;
|
||||
if (fromName && getIntegrationDockerMetadata(fromName).discoverable) return fromName;
|
||||
|
||||
return null;
|
||||
};
|
||||
@@ -5,8 +5,8 @@ import { XMLParser } from "fast-xml-parser";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
import { createDocumentationLink } from "./index";
|
||||
import { integrationDocSlugs } from "./integration-doc-slugs";
|
||||
import { widgetDocSlugs } from "./widget-doc-slugs";
|
||||
import { getIntegrationDocumentationSlug, integrationKinds } from "../integration";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
@@ -60,7 +60,8 @@ const updateSitemapTypeFileAsync = async (sitemapPathType: string) => {
|
||||
};
|
||||
|
||||
const slugMapPaths = [
|
||||
...Object.values(integrationDocSlugs)
|
||||
...integrationKinds
|
||||
.map(getIntegrationDocumentationSlug)
|
||||
.filter(Boolean)
|
||||
.map((slug) => `/docs/integrations/${slug}`),
|
||||
...Object.values(widgetDocSlugs)
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import { objectEntries } from "@homarr/common";
|
||||
|
||||
import type { IntegrationKind } from "../integration";
|
||||
import { integrationDefs } from "../integration";
|
||||
|
||||
export const integrationDocSlugs = Object.fromEntries(
|
||||
objectEntries(integrationDefs).map(([kind, definition]) => [kind, definition.documentationSlug]),
|
||||
) as Record<IntegrationKind, string | null>;
|
||||
@@ -1,6 +1,63 @@
|
||||
import type { WidgetKind } from "../widget";
|
||||
import { widgetFeatureCatalog, widgetKinds } from "../widget";
|
||||
|
||||
export const widgetDocSlugs = Object.fromEntries(
|
||||
widgetKinds.map((kind) => [kind, widgetFeatureCatalog[kind].documentationSlug]),
|
||||
) as Record<WidgetKind, string | null>;
|
||||
export const widgetDocSlugs = {
|
||||
clock: "clock",
|
||||
weather: "weather",
|
||||
airQuality: "air-quality",
|
||||
countdown: "countdown",
|
||||
timer: "timer",
|
||||
app: "app",
|
||||
iframe: "iframe",
|
||||
video: "video",
|
||||
notebook: "notebook",
|
||||
anchorNote: "anchor-note",
|
||||
dnsHoleSummary: "dns-hole-summary",
|
||||
dnsHoleControls: "dns-hole-controls",
|
||||
"smartHome-entityState": "smart-home-entity-state",
|
||||
"smartHome-executeAutomation": "smart-home-execute-automation",
|
||||
stockPrice: "stock-price",
|
||||
mediaServer: "media-server",
|
||||
calendar: "calendar",
|
||||
downloads: "downloads",
|
||||
"mediaRequests-requestList": "media-request-list",
|
||||
"mediaRequests-requestStats": "media-request-stats",
|
||||
mediaTranscoding: "media-transcoding",
|
||||
mediaMissing: "media-missing",
|
||||
minecraftServerStatus: "minecraft-server-status",
|
||||
networkControllerSummary: "network-controller-summary",
|
||||
networkControllerStatus: "network-controller-status",
|
||||
rssFeed: "rss-feed",
|
||||
bookmarks: "bookmarks",
|
||||
indexerManager: "indexer-manager",
|
||||
healthMonitoring: "health-monitoring",
|
||||
releases: "releases",
|
||||
mediaReleases: "media-releases",
|
||||
dockerContainers: "docker-containers",
|
||||
firewall: "firewall",
|
||||
notifications: "notifications",
|
||||
systemResources: "system-resources",
|
||||
coolify: "coolify",
|
||||
systemDisks: "system-disks",
|
||||
timetable: "timetable",
|
||||
"immich-serverStats": "immich-server-stats",
|
||||
"immich-albumCarousel": "immich-album-carousel",
|
||||
paperlessNgx: "paperless-ngx",
|
||||
patchmon: "patchmon",
|
||||
bazarr: "bazarr",
|
||||
tracearr: "tracearr",
|
||||
speedtestTracker: "speedtest-tracker",
|
||||
uptimeKuma: "uptime-kuma",
|
||||
audioStats: "audio-stats",
|
||||
umami: "umami",
|
||||
vpn: "vpn",
|
||||
ups: "ups",
|
||||
archiveTeamWarrior: null,
|
||||
beszelSystemTable: "beszel-system-table",
|
||||
beszelSystemGrid: "beszel-system-grid",
|
||||
beszelAlerts: "beszel-alerts",
|
||||
beszelSystemStats: "beszel-system-stats",
|
||||
traefik: "traefik",
|
||||
customApi: "custom-api",
|
||||
assistant: "assistant",
|
||||
wud: "whats-up-docker",
|
||||
} satisfies Record<WidgetKind, string | null>;
|
||||
@@ -1,16 +0,0 @@
|
||||
// This file is generated by pnpm integrations:sync. Do not edit it directly.
|
||||
|
||||
export const generatedIntegrationDefinitions = {
|
||||
beszel: {
|
||||
name: "Beszel",
|
||||
secretKinds: [["username", "password"]],
|
||||
iconUrl: "https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons@master/svg/beszel.svg",
|
||||
category: ["beszel"],
|
||||
documentationSlug: "beszel",
|
||||
defaultPort: 8090,
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const generatedIntegrationDocumentationSources = {
|
||||
beszel: "packages/integrations/src/beszel/docs",
|
||||
} as const;
|
||||
@@ -1,59 +0,0 @@
|
||||
// This file is generated by pnpm widgets:sync. Do not edit it directly.
|
||||
|
||||
export const generatedWidgetFeatureCatalog = {
|
||||
downloads: {
|
||||
documentationSlug: "downloads",
|
||||
capability: {
|
||||
integrations: ["sabNzbd", "nzbGet", "deluge", "transmission", "qBittorrent", "aria2", "slskd", "mock"] as const,
|
||||
},
|
||||
query: { paths: [["widget", "downloads", "getJobsAndStatuses"]] as const, refetchIntervalSeconds: 10 },
|
||||
},
|
||||
weather: {
|
||||
documentationSlug: "weather",
|
||||
defaultSize: { width: 2, height: 1 },
|
||||
query: { paths: [["widget", "weather", "atLocation"]] as const, refetchIntervalSeconds: 600 },
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const widgetServerCachePolicies = {
|
||||
downloads: {
|
||||
getJobsAndStatuses: { namespace: "downloads:jobs-and-status", ttlMs: 10000, scope: "integration" },
|
||||
},
|
||||
weather: {
|
||||
atLocation: { namespace: "weather:at-location", ttlMs: 300000, scope: "shared" },
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const generatedWidgetOperationPolicies = [
|
||||
{
|
||||
widgetKind: "downloads",
|
||||
operation: "getJobsAndStatuses",
|
||||
kind: "query",
|
||||
path: ["widget", "downloads", "getJobsAndStatuses"],
|
||||
refetchIntervalSeconds: 10,
|
||||
staleTimeSeconds: 10,
|
||||
persist: true,
|
||||
},
|
||||
{
|
||||
widgetKind: "weather",
|
||||
operation: "atLocation",
|
||||
kind: "query",
|
||||
path: ["widget", "weather", "atLocation"],
|
||||
refetchIntervalSeconds: 600,
|
||||
staleTimeSeconds: 300,
|
||||
persist: true,
|
||||
},
|
||||
] as const;
|
||||
|
||||
export const generatedWidgetDocumentationSources = {
|
||||
downloads: "packages/widgets/src/downloads/docs",
|
||||
weather: "packages/widgets/src/weather/docs",
|
||||
} as const;
|
||||
|
||||
export const getWidgetServerCachePolicy = <
|
||||
TKind extends keyof typeof widgetServerCachePolicies,
|
||||
TOperation extends keyof (typeof widgetServerCachePolicies)[TKind],
|
||||
>(
|
||||
kind: TKind,
|
||||
operation: TOperation,
|
||||
): (typeof widgetServerCachePolicies)[TKind][TOperation] => widgetServerCachePolicies[kind][operation];
|
||||
@@ -1,7 +1,5 @@
|
||||
export * from "./board";
|
||||
export * from "./integration";
|
||||
export * from "./integration-module";
|
||||
export * from "./generated/integration-modules";
|
||||
export * from "./section";
|
||||
export * from "./widget";
|
||||
export * from "./widget-name";
|
||||
@@ -16,8 +14,6 @@ export * from "./cookie";
|
||||
export * from "./search-engine";
|
||||
export * from "./onboarding";
|
||||
export * from "./widget-integration-map";
|
||||
export * from "./widget-module";
|
||||
export * from "./generated/widget-modules";
|
||||
export * from "./emptysuperjson";
|
||||
export * from "./hotkeys";
|
||||
export * from "./docker-integration-match";
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
import type { IntegrationCategory, IntegrationSecretKind } from "./integration";
|
||||
|
||||
export interface IntegrationModuleDocumentation {
|
||||
slug: string;
|
||||
sourceDirectory: string;
|
||||
}
|
||||
|
||||
export interface IntegrationModuleDockerMetadata {
|
||||
aliases?: readonly string[];
|
||||
discoverable?: boolean;
|
||||
}
|
||||
|
||||
export interface IntegrationModuleOnboardingMetadata {
|
||||
featuredOrder?: number;
|
||||
hidden?: boolean;
|
||||
}
|
||||
|
||||
export type IntegrationModuleCreatorEntry =
|
||||
| {
|
||||
type: "constructor";
|
||||
module: string;
|
||||
exportName: string;
|
||||
}
|
||||
| {
|
||||
type: "factory";
|
||||
module: string;
|
||||
exportName: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Pure, server-safe authoring contract for a vertical integration module.
|
||||
*
|
||||
* Runtime entry points are strings so reading metadata never imports an
|
||||
* integration implementation or its transitive server dependencies.
|
||||
*/
|
||||
export interface IntegrationModuleDefinition {
|
||||
kind: string;
|
||||
name: string;
|
||||
iconUrl: string;
|
||||
secretKinds: readonly [readonly IntegrationSecretKind[], ...(readonly IntegrationSecretKind[])[]];
|
||||
categories: readonly [IntegrationCategory, ...IntegrationCategory[]];
|
||||
documentation: IntegrationModuleDocumentation;
|
||||
creator: IntegrationModuleCreatorEntry;
|
||||
defaultUrl?: string;
|
||||
defaultPort?: number;
|
||||
apiKeySettingsPath?: string;
|
||||
docker?: IntegrationModuleDockerMetadata;
|
||||
onboarding?: IntegrationModuleOnboardingMetadata;
|
||||
}
|
||||
|
||||
export const defineIntegrationModule = <const TDefinition extends IntegrationModuleDefinition>(
|
||||
definition: TDefinition,
|
||||
) => definition;
|
||||
@@ -1,12 +1,12 @@
|
||||
import { objectEntries, objectKeys } from "@homarr/common";
|
||||
import type { AtLeastOneOf } from "@homarr/common/types";
|
||||
|
||||
import { createDocumentationLink } from "./docs";
|
||||
import type { HomarrDocumentationPath } from "./docs/homarr-docs-sitemap";
|
||||
import { generatedIntegrationDefinitions } from "./generated/integration-modules";
|
||||
|
||||
type IntegrationDocumentationPath = Extract<HomarrDocumentationPath, `/docs/integrations/${string}`>;
|
||||
type IntegrationDocumentationSlug = string;
|
||||
type IntegrationDocumentationSlug = IntegrationDocumentationPath extends `/docs/integrations/${infer TSlug}`
|
||||
? TSlug
|
||||
: never;
|
||||
|
||||
export const integrationSecretKindObject = {
|
||||
apiKey: { isPublic: false, multiline: false },
|
||||
@@ -27,7 +27,7 @@ export const integrationSecretKindObject = {
|
||||
slug: { isPublic: true, multiline: false },
|
||||
} satisfies Record<string, { isPublic: boolean; multiline: boolean }>;
|
||||
|
||||
export const integrationSecretKinds = objectKeys(integrationSecretKindObject);
|
||||
export const integrationSecretKinds = Object.keys(integrationSecretKindObject) as IntegrationSecretKind[];
|
||||
|
||||
interface IntegrationFeatureMetadata {
|
||||
docker?: {
|
||||
@@ -40,17 +40,6 @@ interface IntegrationFeatureMetadata {
|
||||
};
|
||||
}
|
||||
|
||||
interface ResolvedIntegrationFeatureMetadata {
|
||||
docker: {
|
||||
aliases: readonly string[];
|
||||
discoverable: boolean;
|
||||
};
|
||||
onboarding: {
|
||||
featuredOrder: number | null;
|
||||
hidden: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
interface integrationDefinition {
|
||||
name: string;
|
||||
iconUrl: string;
|
||||
@@ -63,45 +52,7 @@ interface integrationDefinition {
|
||||
apiKeySettingsPath?: string;
|
||||
}
|
||||
|
||||
type ResolvedIntegrationDefinitions<TDefinitions extends Record<string, integrationDefinition>> = {
|
||||
[TKind in keyof TDefinitions]: TDefinitions[TKind] & {
|
||||
documentationUrl: string | null;
|
||||
features: ResolvedIntegrationFeatureMetadata;
|
||||
};
|
||||
};
|
||||
|
||||
const createIntegrationDefinitions = <const TDefinitions extends Record<string, integrationDefinition>>(
|
||||
definitions: TDefinitions,
|
||||
): ResolvedIntegrationDefinitions<TDefinitions> => {
|
||||
return Object.fromEntries(
|
||||
objectEntries(definitions).map(([kind, definition]) => {
|
||||
let documentationUrl: string | null = null;
|
||||
if (definition.documentationSlug !== null) {
|
||||
const documentationPath = `/docs/integrations/${definition.documentationSlug}` as IntegrationDocumentationPath;
|
||||
documentationUrl = createDocumentationLink(documentationPath);
|
||||
}
|
||||
return [
|
||||
kind,
|
||||
{
|
||||
...definition,
|
||||
documentationUrl,
|
||||
features: {
|
||||
docker: {
|
||||
aliases: definition.features?.docker?.aliases ?? [],
|
||||
discoverable: definition.features?.docker?.discoverable ?? true,
|
||||
},
|
||||
onboarding: {
|
||||
featuredOrder: definition.features?.onboarding?.featuredOrder ?? null,
|
||||
hidden: definition.features?.onboarding?.hidden ?? false,
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
}),
|
||||
) as unknown as ResolvedIntegrationDefinitions<TDefinitions>;
|
||||
};
|
||||
|
||||
export const integrationDefs = createIntegrationDefinitions({
|
||||
export const integrationDefs = {
|
||||
sabNzbd: {
|
||||
name: "SABnzbd",
|
||||
secretKinds: [["apiKey"]],
|
||||
@@ -551,7 +502,14 @@ export const integrationDefs = createIntegrationDefinitions({
|
||||
documentationSlug: "peanut",
|
||||
defaultPort: 8080,
|
||||
},
|
||||
...generatedIntegrationDefinitions,
|
||||
beszel: {
|
||||
name: "Beszel",
|
||||
secretKinds: [["username", "password"]],
|
||||
iconUrl: "https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons@master/svg/beszel.svg",
|
||||
category: ["beszel"],
|
||||
documentationSlug: "beszel",
|
||||
defaultPort: 8090,
|
||||
},
|
||||
gluetun: {
|
||||
name: "Gluetun",
|
||||
secretKinds: [["username", "password"], ["apiKey"], []],
|
||||
@@ -612,9 +570,9 @@ export const integrationDefs = createIntegrationDefinitions({
|
||||
onboarding: { hidden: true },
|
||||
},
|
||||
},
|
||||
} as const satisfies Record<string, integrationDefinition>);
|
||||
} as const satisfies Record<string, integrationDefinition>;
|
||||
|
||||
export const integrationKinds = objectKeys(integrationDefs) as AtLeastOneOf<IntegrationKind>;
|
||||
export const integrationKinds = Object.keys(integrationDefs) as AtLeastOneOf<IntegrationKind>;
|
||||
|
||||
export const getIconUrl = (integration: IntegrationKind) => integrationDefs[integration].iconUrl;
|
||||
|
||||
@@ -624,10 +582,10 @@ export const getDefaultSecretKinds = (integration: IntegrationKind): Integration
|
||||
...integrationDefs[integration].secretKinds[0],
|
||||
];
|
||||
|
||||
export const getAllSecretKindOptions = (integration: IntegrationKind): AtLeastOneOf<IntegrationSecretKind[]> =>
|
||||
integrationDefs[integration].secretKinds.map((secretKinds) => [...secretKinds]) as AtLeastOneOf<
|
||||
IntegrationSecretKind[]
|
||||
>;
|
||||
export const getAllSecretKindOptions = (integration: IntegrationKind): AtLeastOneOf<IntegrationSecretKind[]> => {
|
||||
const [first, ...rest] = integrationDefs[integration].secretKinds;
|
||||
return [[...first], ...rest.map((secretKinds) => [...secretKinds])];
|
||||
};
|
||||
|
||||
export const getIntegrationDefaultUrl = (integration: IntegrationKind) => {
|
||||
const definition = integrationDefs[integration];
|
||||
@@ -639,8 +597,30 @@ export const getIntegrationDefaultPort = (kind: IntegrationKind): number | undef
|
||||
return "defaultPort" in definition ? definition.defaultPort : undefined;
|
||||
};
|
||||
|
||||
export const getIntegrationDocumentationUrl = (kind: IntegrationKind): string | null =>
|
||||
integrationDefs[kind].documentationUrl;
|
||||
export const getIntegrationDocumentationSlug = (kind: IntegrationKind): IntegrationDocumentationSlug | null =>
|
||||
integrationDefs[kind].documentationSlug;
|
||||
|
||||
export const getIntegrationDocumentationUrl = (kind: IntegrationKind): string | null => {
|
||||
const slug = getIntegrationDocumentationSlug(kind);
|
||||
if (slug === null) return null;
|
||||
return createDocumentationLink(`/docs/integrations/${slug}`);
|
||||
};
|
||||
|
||||
export const getIntegrationDockerMetadata = (kind: IntegrationKind) => {
|
||||
const definition: integrationDefinition = integrationDefs[kind];
|
||||
return {
|
||||
aliases: definition.features?.docker?.aliases ?? [],
|
||||
discoverable: definition.features?.docker?.discoverable ?? true,
|
||||
};
|
||||
};
|
||||
|
||||
export const getIntegrationOnboardingMetadata = (kind: IntegrationKind) => {
|
||||
const definition: integrationDefinition = integrationDefs[kind];
|
||||
return {
|
||||
featuredOrder: definition.features?.onboarding?.featuredOrder ?? null,
|
||||
hidden: definition.features?.onboarding?.hidden ?? false,
|
||||
};
|
||||
};
|
||||
|
||||
export const getIntegrationApiKeyUrl = (integrationUrl: string, kind: IntegrationKind): string | null => {
|
||||
const definition = integrationDefs[kind];
|
||||
@@ -666,7 +646,7 @@ export const getIntegrationApiKeyUrl = (integrationUrl: string, kind: Integratio
|
||||
* @returns Partial list of integration kinds
|
||||
*/
|
||||
export const getIntegrationKindsByCategory = <TCategory extends IntegrationCategory>(category: TCategory) => {
|
||||
return objectKeys(integrationDefs).filter((integration) =>
|
||||
return (Object.keys(integrationDefs) as IntegrationKind[]).filter((integration) =>
|
||||
integrationDefs[integration].category.some((defCategory) => defCategory === category),
|
||||
) as AtLeastOneOf<IntegrationKindByCategory<TCategory>>;
|
||||
};
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { getIntegrationApiKeyUrl, integrationDefs } from "../integration";
|
||||
import { objectEntries } from "@homarr/common";
|
||||
|
||||
import { getIntegrationApiKeyUrl, getIntegrationDocumentationUrl, integrationDefs } from "../integration";
|
||||
|
||||
describe("getIntegrationApiKeyUrl", () => {
|
||||
it("links every user-facing integration to its Homarr setup guide", () => {
|
||||
expect(
|
||||
Object.entries(integrationDefs)
|
||||
.filter(([kind, definition]) => kind !== "mock" && !definition.documentationUrl)
|
||||
objectEntries(integrationDefs)
|
||||
.filter(([kind]) => kind !== "mock" && !getIntegrationDocumentationUrl(kind))
|
||||
.map(([kind]) => kind),
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
@@ -4,19 +4,19 @@ import { integrationKinds } from "../integration";
|
||||
import {
|
||||
getWidgetKindsForIntegration,
|
||||
integrationWidgetSupport,
|
||||
nativeFeatureCapabilities,
|
||||
widgetIntegrationConfigs,
|
||||
widgetIntegrationLimits,
|
||||
widgetIntegrationSupport,
|
||||
widgetKindsWithOptionalIntegrations,
|
||||
} from "../widget-integration-map";
|
||||
|
||||
describe("native feature capability descriptor", () => {
|
||||
describe("widget integration config", () => {
|
||||
test("derives forward and reverse support without losing relationships", () => {
|
||||
for (const [widgetKind, capability] of Object.entries(nativeFeatureCapabilities)) {
|
||||
for (const [widgetKind, capability] of Object.entries(widgetIntegrationConfigs)) {
|
||||
expect(widgetIntegrationSupport[widgetKind as keyof typeof widgetIntegrationSupport]).toEqual(
|
||||
capability.integrations,
|
||||
capability.supportedIntegrations,
|
||||
);
|
||||
for (const integrationKind of capability.integrations) {
|
||||
for (const integrationKind of capability.supportedIntegrations) {
|
||||
expect(integrationWidgetSupport[integrationKind]).toContain(widgetKind);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,419 +0,0 @@
|
||||
import type { AtLeastOneOf } from "@homarr/common/types";
|
||||
|
||||
import type { IntegrationKind } from "./integration";
|
||||
import { getIntegrationKindsByCategory } from "./integration";
|
||||
import type { IntegrationKindByCategory } from "./integration";
|
||||
import { generatedWidgetFeatureCatalog } from "./generated/widget-modules";
|
||||
|
||||
const {
|
||||
weather: generatedWeatherFeature,
|
||||
downloads: generatedDownloadsFeature,
|
||||
...additionalGeneratedWidgetFeatures
|
||||
} = generatedWidgetFeatureCatalog;
|
||||
|
||||
export interface NativeFeatureCapabilityDescriptor {
|
||||
integrations: Readonly<AtLeastOneOf<IntegrationKind>>;
|
||||
connectionOptional?: true;
|
||||
serverMaxIntegrations?: number;
|
||||
}
|
||||
|
||||
interface WidgetFeatureDescriptorBase {
|
||||
documentationSlug: string | null;
|
||||
defaultSize?: Readonly<{ width: number; height: number }>;
|
||||
query?: {
|
||||
paths: readonly (readonly string[])[];
|
||||
refetchIntervalSeconds?: number | null;
|
||||
};
|
||||
}
|
||||
|
||||
interface WidgetFeatureDescriptorWithDefaultName extends WidgetFeatureDescriptorBase {
|
||||
displayNameFromIntegration?: false;
|
||||
capability?: NativeFeatureCapabilityDescriptor;
|
||||
}
|
||||
|
||||
interface WidgetFeatureDescriptorWithIntegrationName extends WidgetFeatureDescriptorBase {
|
||||
displayNameFromIntegration: true;
|
||||
capability: Omit<NativeFeatureCapabilityDescriptor, "integrations"> & {
|
||||
integrations: readonly [IntegrationKind];
|
||||
};
|
||||
}
|
||||
|
||||
export type WidgetFeatureDescriptor =
|
||||
| WidgetFeatureDescriptorWithDefaultName
|
||||
| WidgetFeatureDescriptorWithIntegrationName;
|
||||
|
||||
const defineWidgetFeatureCatalog = <const TCatalog extends Record<string, WidgetFeatureDescriptor>>(
|
||||
catalog: TCatalog,
|
||||
) => catalog;
|
||||
|
||||
type GeneralHealthMonitoringIntegrationKind = Exclude<
|
||||
IntegrationKindByCategory<"healthMonitoring">,
|
||||
"patchmon" | "wud"
|
||||
>;
|
||||
|
||||
const generalHealthMonitoringIntegrationKinds = getIntegrationKindsByCategory("healthMonitoring").filter(
|
||||
(kind): kind is GeneralHealthMonitoringIntegrationKind => kind !== "patchmon" && kind !== "wud",
|
||||
) as AtLeastOneOf<GeneralHealthMonitoringIntegrationKind>;
|
||||
|
||||
/**
|
||||
* Server-safe source of truth for native widgets.
|
||||
*
|
||||
* Keep each widget's stable kind, documentation, default size, and integration
|
||||
* contract together so every lightweight consumer can derive the same view.
|
||||
*/
|
||||
export const widgetFeatureCatalog = defineWidgetFeatureCatalog({
|
||||
clock: {
|
||||
documentationSlug: "clock",
|
||||
defaultSize: { width: 2, height: 1 },
|
||||
query: { paths: [["widget", "weather", "atLocation"]] },
|
||||
},
|
||||
weather: generatedWeatherFeature,
|
||||
airQuality: {
|
||||
documentationSlug: "air-quality",
|
||||
defaultSize: { width: 2, height: 1 },
|
||||
query: { paths: [["widget", "airQuality", "atLocation"]], refetchIntervalSeconds: 900 },
|
||||
},
|
||||
countdown: { documentationSlug: "countdown", defaultSize: { width: 2, height: 1 } },
|
||||
timer: { documentationSlug: "timer", defaultSize: { width: 2, height: 1 } },
|
||||
app: {
|
||||
documentationSlug: "app",
|
||||
query: {
|
||||
paths: [
|
||||
["app", "byId"],
|
||||
["widget", "app", "ping"],
|
||||
],
|
||||
},
|
||||
},
|
||||
iframe: { documentationSlug: "iframe" },
|
||||
video: { documentationSlug: "video" },
|
||||
notebook: { documentationSlug: "notebook" },
|
||||
anchorNote: {
|
||||
documentationSlug: "anchor-note",
|
||||
capability: { integrations: ["anchor"], serverMaxIntegrations: 1 },
|
||||
query: { paths: [["widget", "anchorNotes"]] },
|
||||
},
|
||||
dnsHoleSummary: {
|
||||
documentationSlug: "dns-hole-summary",
|
||||
capability: { integrations: getIntegrationKindsByCategory("dnsHole") },
|
||||
query: { paths: [["widget", "dnsHole"]], refetchIntervalSeconds: 10 },
|
||||
},
|
||||
dnsHoleControls: {
|
||||
documentationSlug: "dns-hole-controls",
|
||||
capability: { integrations: getIntegrationKindsByCategory("dnsHole") },
|
||||
query: { paths: [["widget", "dnsHole"]], refetchIntervalSeconds: 10 },
|
||||
},
|
||||
"smartHome-entityState": {
|
||||
documentationSlug: "smart-home-entity-state",
|
||||
capability: {
|
||||
integrations: getIntegrationKindsByCategory("smartHomeServer"),
|
||||
serverMaxIntegrations: 1,
|
||||
},
|
||||
query: { paths: [["widget", "smartHome"]] },
|
||||
},
|
||||
"smartHome-executeAutomation": {
|
||||
documentationSlug: "smart-home-execute-automation",
|
||||
capability: {
|
||||
integrations: getIntegrationKindsByCategory("smartHomeServer"),
|
||||
serverMaxIntegrations: 1,
|
||||
},
|
||||
},
|
||||
stockPrice: {
|
||||
documentationSlug: "stock-price",
|
||||
query: { paths: [["widget", "stockPrice", "getPriceHistory"]], refetchIntervalSeconds: null },
|
||||
},
|
||||
mediaServer: {
|
||||
documentationSlug: "media-server",
|
||||
capability: { integrations: getIntegrationKindsByCategory("mediaService") },
|
||||
query: { paths: [["widget", "mediaServer", "getCurrentStreams"]], refetchIntervalSeconds: 10 },
|
||||
},
|
||||
calendar: {
|
||||
documentationSlug: "calendar",
|
||||
capability: { integrations: getIntegrationKindsByCategory("calendar"), connectionOptional: true },
|
||||
query: { paths: [["widget", "calendar", "findAllEvents"]] },
|
||||
},
|
||||
downloads: generatedDownloadsFeature,
|
||||
"mediaRequests-requestList": {
|
||||
documentationSlug: "media-request-list",
|
||||
capability: { integrations: getIntegrationKindsByCategory("mediaRequest") },
|
||||
query: { paths: [["widget", "mediaRequests", "getLatestRequests"]] },
|
||||
},
|
||||
"mediaRequests-requestStats": {
|
||||
documentationSlug: "media-request-stats",
|
||||
capability: { integrations: getIntegrationKindsByCategory("mediaRequest") },
|
||||
query: { paths: [["widget", "mediaRequests", "getStats"]] },
|
||||
},
|
||||
mediaTranscoding: {
|
||||
documentationSlug: "media-transcoding",
|
||||
capability: {
|
||||
integrations: getIntegrationKindsByCategory("mediaTranscoding"),
|
||||
serverMaxIntegrations: 1,
|
||||
},
|
||||
query: { paths: [["widget", "mediaTranscoding", "getDataAsync"]], refetchIntervalSeconds: null },
|
||||
},
|
||||
mediaMissing: {
|
||||
documentationSlug: "media-missing",
|
||||
defaultSize: { width: 4, height: 3 },
|
||||
capability: { integrations: getIntegrationKindsByCategory("mediaOrganizer") },
|
||||
query: { paths: [["widget", "mediaOrganizer", "getData"]] },
|
||||
},
|
||||
minecraftServerStatus: {
|
||||
documentationSlug: "minecraft-server-status",
|
||||
query: { paths: [["widget", "minecraft", "getServerStatus"]], refetchIntervalSeconds: null },
|
||||
},
|
||||
networkControllerSummary: {
|
||||
documentationSlug: "network-controller-summary",
|
||||
capability: { integrations: getIntegrationKindsByCategory("networkController") },
|
||||
query: { paths: [["widget", "networkController"]], refetchIntervalSeconds: null },
|
||||
},
|
||||
networkControllerStatus: {
|
||||
documentationSlug: "network-controller-status",
|
||||
capability: { integrations: getIntegrationKindsByCategory("networkController") },
|
||||
query: { paths: [["widget", "networkController"]], refetchIntervalSeconds: null },
|
||||
},
|
||||
rssFeed: {
|
||||
documentationSlug: "rss-feed",
|
||||
query: { paths: [["widget", "rssFeed", "getFeeds"]], refetchIntervalSeconds: null },
|
||||
},
|
||||
bookmarks: {
|
||||
documentationSlug: "bookmarks",
|
||||
defaultSize: { width: 2, height: 2 },
|
||||
query: { paths: [["app", "byIds"]] },
|
||||
},
|
||||
indexerManager: {
|
||||
documentationSlug: "indexer-manager",
|
||||
capability: { integrations: getIntegrationKindsByCategory("indexerManager") },
|
||||
query: { paths: [["widget", "indexerManager"]], refetchIntervalSeconds: null },
|
||||
},
|
||||
healthMonitoring: {
|
||||
documentationSlug: "health-monitoring",
|
||||
capability: { integrations: generalHealthMonitoringIntegrationKinds },
|
||||
query: {
|
||||
paths: [
|
||||
["integration", "byIds"],
|
||||
["widget", "healthMonitoring"],
|
||||
],
|
||||
refetchIntervalSeconds: 10,
|
||||
},
|
||||
},
|
||||
releases: {
|
||||
documentationSlug: "releases",
|
||||
query: { paths: [["widget", "releases", "getLatest"]], refetchIntervalSeconds: null },
|
||||
},
|
||||
mediaReleases: {
|
||||
documentationSlug: "media-releases",
|
||||
capability: { integrations: ["mock", "emby", "jellyfin", "plex"] },
|
||||
query: { paths: [["widget", "mediaRelease"]], refetchIntervalSeconds: null },
|
||||
},
|
||||
dockerContainers: {
|
||||
documentationSlug: "docker-containers",
|
||||
query: { paths: [["docker", "getContainers"]], refetchIntervalSeconds: 30 },
|
||||
},
|
||||
firewall: {
|
||||
documentationSlug: "firewall",
|
||||
capability: { integrations: getIntegrationKindsByCategory("firewall") },
|
||||
query: { paths: [["widget", "firewall"]], refetchIntervalSeconds: 10 },
|
||||
},
|
||||
notifications: {
|
||||
documentationSlug: "notifications",
|
||||
capability: { integrations: getIntegrationKindsByCategory("notifications") },
|
||||
query: { paths: [["widget", "notifications", "getNotifications"]] },
|
||||
},
|
||||
systemResources: {
|
||||
documentationSlug: "system-resources",
|
||||
capability: {
|
||||
integrations: ["dashDot", "openmediavault", "truenas", "unraid", "glances", "synology"],
|
||||
},
|
||||
query: { paths: [["widget", "healthMonitoring"]], refetchIntervalSeconds: 10 },
|
||||
},
|
||||
coolify: {
|
||||
documentationSlug: "coolify",
|
||||
displayNameFromIntegration: true,
|
||||
capability: { integrations: ["coolify"] },
|
||||
query: { paths: [["widget", "coolify"]] },
|
||||
},
|
||||
systemDisks: {
|
||||
documentationSlug: "system-disks",
|
||||
capability: { integrations: ["dashDot", "openmediavault", "truenas", "unraid", "synology"] },
|
||||
query: { paths: [["widget", "healthMonitoring"]], refetchIntervalSeconds: 10 },
|
||||
},
|
||||
timetable: {
|
||||
documentationSlug: "timetable",
|
||||
query: { paths: [["widget", "timetable"]] },
|
||||
},
|
||||
"immich-serverStats": {
|
||||
documentationSlug: "immich-server-stats",
|
||||
capability: { integrations: ["immich"], serverMaxIntegrations: 1 },
|
||||
query: {
|
||||
paths: [
|
||||
["widget", "immich", "getServerStats"],
|
||||
["widget", "immich", "getAlbums"],
|
||||
],
|
||||
refetchIntervalSeconds: null,
|
||||
},
|
||||
},
|
||||
"immich-albumCarousel": {
|
||||
documentationSlug: "immich-album-carousel",
|
||||
capability: { integrations: ["immich"], serverMaxIntegrations: 1 },
|
||||
query: {
|
||||
paths: [
|
||||
["widget", "immich", "getAlbum"],
|
||||
["widget", "immich", "getAlbums"],
|
||||
],
|
||||
refetchIntervalSeconds: null,
|
||||
},
|
||||
},
|
||||
paperlessNgx: {
|
||||
documentationSlug: "paperless-ngx",
|
||||
defaultSize: { width: 2, height: 2 },
|
||||
displayNameFromIntegration: true,
|
||||
capability: { integrations: ["paperlessNgx"], serverMaxIntegrations: 1 },
|
||||
query: { paths: [["widget", "paperlessNgx"]], refetchIntervalSeconds: null },
|
||||
},
|
||||
patchmon: {
|
||||
documentationSlug: "patchmon",
|
||||
defaultSize: { width: 2, height: 2 },
|
||||
displayNameFromIntegration: true,
|
||||
capability: { integrations: ["patchmon"], serverMaxIntegrations: 1 },
|
||||
query: { paths: [["widget", "patchmon"]] },
|
||||
},
|
||||
bazarr: {
|
||||
documentationSlug: "bazarr",
|
||||
defaultSize: { width: 2, height: 2 },
|
||||
displayNameFromIntegration: true,
|
||||
capability: { integrations: ["bazarr"], serverMaxIntegrations: 1 },
|
||||
query: { paths: [["widget", "bazarr"]] },
|
||||
},
|
||||
tracearr: {
|
||||
documentationSlug: "tracearr",
|
||||
displayNameFromIntegration: true,
|
||||
capability: { integrations: ["tracearr"] },
|
||||
query: { paths: [["widget", "tracearr"]], refetchIntervalSeconds: 10 },
|
||||
},
|
||||
speedtestTracker: {
|
||||
documentationSlug: "speedtest-tracker",
|
||||
capability: { integrations: ["speedtestTracker"] },
|
||||
query: { paths: [["widget", "speedtestTracker"]], refetchIntervalSeconds: null },
|
||||
},
|
||||
uptimeKuma: {
|
||||
documentationSlug: "uptime-kuma",
|
||||
defaultSize: { width: 2, height: 3 },
|
||||
displayNameFromIntegration: true,
|
||||
capability: { integrations: ["uptimeKuma"] },
|
||||
query: { paths: [["widget", "uptimeKuma"]] },
|
||||
},
|
||||
audioStats: {
|
||||
documentationSlug: "audio-stats",
|
||||
defaultSize: { width: 2, height: 2 },
|
||||
capability: { integrations: ["navidrome", "audiobookshelf"], serverMaxIntegrations: 1 },
|
||||
query: {
|
||||
paths: [
|
||||
["widget", "audioStats", "getStats"],
|
||||
["widget", "mediaServer", "getCurrentStreams"],
|
||||
],
|
||||
},
|
||||
},
|
||||
umami: {
|
||||
documentationSlug: "umami",
|
||||
capability: { integrations: ["umami"], serverMaxIntegrations: 1 },
|
||||
query: {
|
||||
paths: [
|
||||
["widget", "umami", "getVisitorStats"],
|
||||
["widget", "umami", "getActiveVisitors"],
|
||||
["widget", "umami", "getMultiEventTimeSeries"],
|
||||
["widget", "umami", "getTopPages"],
|
||||
["widget", "umami", "getTopReferrers"],
|
||||
],
|
||||
refetchIntervalSeconds: null,
|
||||
},
|
||||
},
|
||||
vpn: {
|
||||
documentationSlug: "vpn",
|
||||
capability: { integrations: getIntegrationKindsByCategory("vpn") },
|
||||
query: { paths: [["widget", "vpn"]], refetchIntervalSeconds: null },
|
||||
},
|
||||
archiveTeamWarrior: {
|
||||
documentationSlug: null,
|
||||
capability: { integrations: ["archiveTeamWarrior"], serverMaxIntegrations: 1 },
|
||||
query: { paths: [["widget", "archiveTeamWarrior"]] },
|
||||
},
|
||||
ups: {
|
||||
documentationSlug: "ups",
|
||||
capability: { integrations: getIntegrationKindsByCategory("ups") },
|
||||
query: { paths: [["widget", "ups"]] },
|
||||
},
|
||||
beszelSystemTable: {
|
||||
documentationSlug: "beszel-system-table",
|
||||
capability: { integrations: ["beszel", "mock"] },
|
||||
query: {
|
||||
paths: [
|
||||
["widget", "beszel", "getSystems"],
|
||||
["widget", "beszel", "getSystemStats"],
|
||||
],
|
||||
},
|
||||
},
|
||||
beszelSystemGrid: {
|
||||
documentationSlug: "beszel-system-grid",
|
||||
capability: { integrations: ["beszel", "mock"] },
|
||||
query: {
|
||||
paths: [
|
||||
["widget", "beszel", "getSystems"],
|
||||
["widget", "beszel", "getSystemStats"],
|
||||
],
|
||||
},
|
||||
},
|
||||
beszelAlerts: {
|
||||
documentationSlug: "beszel-alerts",
|
||||
capability: { integrations: ["beszel", "mock"] },
|
||||
query: { paths: [["widget", "beszel", "getAlerts"]] },
|
||||
},
|
||||
beszelSystemStats: {
|
||||
documentationSlug: "beszel-system-stats",
|
||||
capability: { integrations: ["beszel", "mock"] },
|
||||
query: {
|
||||
paths: [
|
||||
["widget", "beszel", "getSystems"],
|
||||
["widget", "beszel", "getSystemStats"],
|
||||
],
|
||||
},
|
||||
},
|
||||
traefik: {
|
||||
documentationSlug: "traefik",
|
||||
displayNameFromIntegration: true,
|
||||
capability: { integrations: ["traefik"] },
|
||||
query: { paths: [["widget", "traefik"]] },
|
||||
},
|
||||
customApi: {
|
||||
documentationSlug: "custom-api",
|
||||
query: { paths: [["widget", "customApi"]] },
|
||||
},
|
||||
assistant: { documentationSlug: "assistant", defaultSize: { width: 10, height: 4 } },
|
||||
wud: {
|
||||
documentationSlug: "whats-up-docker",
|
||||
capability: { integrations: ["wud"], serverMaxIntegrations: 1 },
|
||||
query: { paths: [["widget", "wud"]], refetchIntervalSeconds: null },
|
||||
},
|
||||
...additionalGeneratedWidgetFeatures,
|
||||
});
|
||||
|
||||
export type WidgetFeatureKind = keyof typeof widgetFeatureCatalog;
|
||||
|
||||
export type WidgetIntegrationKind<TKind extends WidgetFeatureKind> = (typeof widgetFeatureCatalog)[TKind] extends {
|
||||
capability: { integrations: readonly (infer TIntegrationKind extends IntegrationKind)[] };
|
||||
}
|
||||
? TIntegrationKind
|
||||
: never;
|
||||
|
||||
export type WidgetKindWithIntegration = {
|
||||
[TKind in WidgetFeatureKind]: WidgetIntegrationKind<TKind> extends never ? never : TKind;
|
||||
}[WidgetFeatureKind];
|
||||
|
||||
export const getWidgetFeatureIntegrationKinds = <TKind extends WidgetKindWithIntegration>(
|
||||
kind: TKind,
|
||||
): AtLeastOneOf<WidgetIntegrationKind<TKind>> => {
|
||||
const descriptor = widgetFeatureCatalog[kind];
|
||||
if (!("capability" in descriptor) || descriptor.capability.integrations.length === 0) {
|
||||
throw new Error(`Widget kind ${kind} does not declare integration support`);
|
||||
}
|
||||
|
||||
return [...descriptor.capability.integrations] as AtLeastOneOf<WidgetIntegrationKind<TKind>>;
|
||||
};
|
||||
@@ -1,31 +1,91 @@
|
||||
import { objectEntries } from "@homarr/common";
|
||||
|
||||
import { createDocumentationLink } from "./docs";
|
||||
import type { IntegrationKind } from "./integration";
|
||||
import { integrationKinds } from "./integration";
|
||||
import { getIntegrationKindsByCategory, integrationKinds } from "./integration";
|
||||
import type { WidgetKind } from "./widget";
|
||||
import { widgetDefaultSizes, widgetFeatureCatalog, widgetKinds } from "./widget";
|
||||
import type { NativeFeatureCapabilityDescriptor } from "./widget-feature-catalog";
|
||||
import { widgetDefaultSizes } from "./widget";
|
||||
|
||||
export type { NativeFeatureCapabilityDescriptor } from "./widget-feature-catalog";
|
||||
/** Integration selection shared by the widget UI and API trust boundary. */
|
||||
export interface WidgetIntegrationConfig {
|
||||
supportedIntegrations: IntegrationKind[];
|
||||
integrationsRequired?: false;
|
||||
maxIntegrations?: number;
|
||||
}
|
||||
|
||||
const createNativeFeatureCapabilities = () => {
|
||||
const result: Partial<Record<WidgetKind, NativeFeatureCapabilityDescriptor>> = {};
|
||||
for (const kind of widgetKinds) {
|
||||
const descriptor = widgetFeatureCatalog[kind];
|
||||
if ("capability" in descriptor) result[kind] = descriptor.capability;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
export const widgetIntegrationConfigs = {
|
||||
dnsHoleSummary: { supportedIntegrations: getIntegrationKindsByCategory("dnsHole") },
|
||||
dnsHoleControls: { supportedIntegrations: getIntegrationKindsByCategory("dnsHole") },
|
||||
"smartHome-entityState": {
|
||||
supportedIntegrations: getIntegrationKindsByCategory("smartHomeServer"),
|
||||
maxIntegrations: 1,
|
||||
},
|
||||
"smartHome-executeAutomation": {
|
||||
supportedIntegrations: getIntegrationKindsByCategory("smartHomeServer"),
|
||||
maxIntegrations: 1,
|
||||
},
|
||||
mediaServer: { supportedIntegrations: getIntegrationKindsByCategory("mediaService") },
|
||||
calendar: { supportedIntegrations: getIntegrationKindsByCategory("calendar"), integrationsRequired: false },
|
||||
downloads: { supportedIntegrations: getIntegrationKindsByCategory("downloadClient") },
|
||||
"mediaRequests-requestList": { supportedIntegrations: getIntegrationKindsByCategory("mediaRequest") },
|
||||
"mediaRequests-requestStats": { supportedIntegrations: getIntegrationKindsByCategory("mediaRequest") },
|
||||
mediaTranscoding: {
|
||||
supportedIntegrations: getIntegrationKindsByCategory("mediaTranscoding"),
|
||||
maxIntegrations: 1,
|
||||
},
|
||||
mediaMissing: { supportedIntegrations: getIntegrationKindsByCategory("mediaOrganizer") },
|
||||
networkControllerSummary: { supportedIntegrations: getIntegrationKindsByCategory("networkController") },
|
||||
networkControllerStatus: { supportedIntegrations: getIntegrationKindsByCategory("networkController") },
|
||||
indexerManager: { supportedIntegrations: getIntegrationKindsByCategory("indexerManager") },
|
||||
healthMonitoring: {
|
||||
supportedIntegrations: getIntegrationKindsByCategory("healthMonitoring").filter(
|
||||
(kind) => kind !== "patchmon" && kind !== "wud",
|
||||
),
|
||||
},
|
||||
firewall: { supportedIntegrations: getIntegrationKindsByCategory("firewall") },
|
||||
notifications: { supportedIntegrations: getIntegrationKindsByCategory("notifications") },
|
||||
mediaReleases: { supportedIntegrations: ["mock", "emby", "jellyfin", "plex"] },
|
||||
systemResources: {
|
||||
supportedIntegrations: ["dashDot", "openmediavault", "truenas", "unraid", "glances", "synology"],
|
||||
},
|
||||
systemDisks: { supportedIntegrations: ["dashDot", "openmediavault", "truenas", "unraid", "synology"] },
|
||||
beszelAlerts: { supportedIntegrations: ["beszel", "mock"] },
|
||||
beszelSystemGrid: { supportedIntegrations: ["beszel", "mock"] },
|
||||
beszelSystemStats: { supportedIntegrations: ["beszel", "mock"] },
|
||||
beszelSystemTable: { supportedIntegrations: ["beszel", "mock"] },
|
||||
coolify: { supportedIntegrations: ["coolify"] },
|
||||
"immich-serverStats": { supportedIntegrations: ["immich"], maxIntegrations: 1 },
|
||||
"immich-albumCarousel": { supportedIntegrations: ["immich"], maxIntegrations: 1 },
|
||||
paperlessNgx: { supportedIntegrations: ["paperlessNgx"], maxIntegrations: 1 },
|
||||
patchmon: { supportedIntegrations: ["patchmon"], maxIntegrations: 1 },
|
||||
bazarr: { supportedIntegrations: ["bazarr"], maxIntegrations: 1 },
|
||||
tracearr: { supportedIntegrations: ["tracearr"] },
|
||||
speedtestTracker: { supportedIntegrations: ["speedtestTracker"] },
|
||||
uptimeKuma: { supportedIntegrations: ["uptimeKuma"] },
|
||||
audioStats: { supportedIntegrations: ["navidrome", "audiobookshelf"], maxIntegrations: 1 },
|
||||
umami: { supportedIntegrations: ["umami"], maxIntegrations: 1 },
|
||||
vpn: { supportedIntegrations: getIntegrationKindsByCategory("vpn") },
|
||||
ups: { supportedIntegrations: getIntegrationKindsByCategory("ups") },
|
||||
archiveTeamWarrior: { supportedIntegrations: ["archiveTeamWarrior"], maxIntegrations: 1 },
|
||||
anchorNote: { supportedIntegrations: ["anchor"], maxIntegrations: 1 },
|
||||
traefik: { supportedIntegrations: ["traefik"] },
|
||||
wud: { supportedIntegrations: ["wud"], maxIntegrations: 1 },
|
||||
} satisfies Partial<Record<WidgetKind, WidgetIntegrationConfig>>;
|
||||
|
||||
export const nativeFeatureCapabilities = createNativeFeatureCapabilities();
|
||||
export type WidgetKindWithIntegration = keyof typeof widgetIntegrationConfigs;
|
||||
|
||||
const nativeFeatureCapabilityEntries = Object.entries(nativeFeatureCapabilities) as [
|
||||
WidgetKind,
|
||||
NativeFeatureCapabilityDescriptor,
|
||||
][];
|
||||
export type WidgetIntegrationKind<TKind extends WidgetKindWithIntegration> =
|
||||
(typeof widgetIntegrationConfigs)[TKind]["supportedIntegrations"][number];
|
||||
|
||||
export const getWidgetIntegrationConfig = <TKind extends WidgetKindWithIntegration>(
|
||||
kind: TKind,
|
||||
): (typeof widgetIntegrationConfigs)[TKind] => widgetIntegrationConfigs[kind];
|
||||
|
||||
const widgetIntegrationConfigEntries = objectEntries(widgetIntegrationConfigs);
|
||||
|
||||
const createWidgetIntegrationSupport = () => {
|
||||
const result: Partial<Record<WidgetKind, readonly IntegrationKind[]>> = {};
|
||||
for (const [kind, capability] of nativeFeatureCapabilityEntries) result[kind] = capability.integrations;
|
||||
for (const [kind, config] of widgetIntegrationConfigEntries) result[kind] = config.supportedIntegrations;
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -33,16 +93,15 @@ export const widgetIntegrationSupport = createWidgetIntegrationSupport();
|
||||
|
||||
/** Widgets that remain useful without a configured integration. */
|
||||
export const widgetKindsWithOptionalIntegrations = new Set<WidgetKind>(
|
||||
nativeFeatureCapabilityEntries
|
||||
.filter(([, capability]) => capability.connectionOptional === true)
|
||||
widgetIntegrationConfigEntries
|
||||
.filter(([, config]) => "integrationsRequired" in config && config.integrationsRequired === false)
|
||||
.map(([kind]) => kind),
|
||||
);
|
||||
|
||||
/** Widgets that support fewer integrations than the default unlimited selection. */
|
||||
const createWidgetIntegrationLimits = () => {
|
||||
const result: Partial<Record<WidgetKind, number>> = {};
|
||||
for (const [kind, capability] of nativeFeatureCapabilityEntries) {
|
||||
if (capability.serverMaxIntegrations !== undefined) result[kind] = capability.serverMaxIntegrations;
|
||||
for (const [kind, config] of widgetIntegrationConfigEntries) {
|
||||
if ("maxIntegrations" in config) result[kind] = config.maxIntegrations;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
@@ -75,7 +134,8 @@ export const getWidgetIntegrationIssue = (
|
||||
return { code: "integration-required" };
|
||||
}
|
||||
const incompatibleKinds = selectedIntegrationKinds.filter((kind) => !supportedIntegrations?.includes(kind));
|
||||
return incompatibleKinds.length > 0 ? { code: "incompatible-integration", incompatibleKinds } : null;
|
||||
if (incompatibleKinds.length === 0) return null;
|
||||
return { code: "incompatible-integration", incompatibleKinds };
|
||||
};
|
||||
|
||||
export const getWidgetIntegrationIssueMessage = (widgetKind: WidgetKind, issue: WidgetIntegrationIssue) => {
|
||||
@@ -87,17 +147,19 @@ export const getWidgetIntegrationIssueMessage = (widgetKind: WidgetKind, issue:
|
||||
return `${widgetKind} does not support integration kind${issue.incompatibleKinds.length === 1 ? "" : "s"}: ${issue.incompatibleKinds.join(", ")}`;
|
||||
};
|
||||
|
||||
/** Reverse capability index generated from nativeFeatureCapabilities. */
|
||||
const createIntegrationWidgetSupport = () => {
|
||||
const result = {} as Record<IntegrationKind, readonly WidgetKind[]>;
|
||||
for (const integrationKind of integrationKinds) {
|
||||
result[integrationKind] = nativeFeatureCapabilityEntries
|
||||
.filter(([, capability]) => capability.integrations.includes(integrationKind))
|
||||
result[integrationKind] = widgetIntegrationConfigEntries
|
||||
.filter(([, config]) => supportsIntegration(config, integrationKind))
|
||||
.map(([widgetKind]) => widgetKind);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const supportsIntegration = (config: WidgetIntegrationConfig, integrationKind: IntegrationKind) =>
|
||||
config.supportedIntegrations.includes(integrationKind);
|
||||
|
||||
export const integrationWidgetSupport = createIntegrationWidgetSupport();
|
||||
|
||||
export const getWidgetKindsForIntegration = (integrationKind: IntegrationKind): WidgetKind[] => {
|
||||
@@ -112,28 +174,12 @@ export interface DefaultWidgetConfig {
|
||||
skip?: boolean;
|
||||
}
|
||||
|
||||
type WidgetKindWithDefaultSize = {
|
||||
[TKind in WidgetKind]: (typeof widgetFeatureCatalog)[TKind] extends { defaultSize: Readonly<{ width: number }> }
|
||||
? TKind
|
||||
: never;
|
||||
}[WidgetKind];
|
||||
|
||||
type DefaultWidgetConfigRecipe = Omit<DefaultWidgetConfig, "kind" | "width" | "height"> & {
|
||||
kind: WidgetKindWithDefaultSize;
|
||||
};
|
||||
|
||||
const defaultWidgetConfigDefinitions: DefaultWidgetConfigRecipe[] = [
|
||||
{ kind: "clock" },
|
||||
{ kind: "weather", options: { showHumidity: false, showCity: false, hasForecast: false } },
|
||||
{ kind: "bookmarks", options: { title: "Useful Links", layout: "grid", openNewTab: true } },
|
||||
export const defaultWidgetConfigs: DefaultWidgetConfig[] = [
|
||||
{ kind: "clock", width: 2, height: 1 },
|
||||
{ kind: "weather", width: 2, height: 1, options: { showHumidity: false, showCity: false, hasForecast: false } },
|
||||
{ kind: "bookmarks", width: 2, height: 2, options: { title: "Useful Links", layout: "grid", openNewTab: true } },
|
||||
];
|
||||
|
||||
export const defaultWidgetConfigs: DefaultWidgetConfig[] = defaultWidgetConfigDefinitions.map((recipe) => {
|
||||
const defaultSize = widgetDefaultSizes[recipe.kind];
|
||||
if (!defaultSize) throw new Error(`Default widget ${recipe.kind} must declare a default size`);
|
||||
return { ...recipe, ...defaultSize };
|
||||
});
|
||||
|
||||
const defaultWidgetConfigByKind = new Map(defaultWidgetConfigs.map((config) => [config.kind, config]));
|
||||
|
||||
export const getDefaultWidgetConfig = (kind: WidgetKind): DefaultWidgetConfig =>
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
import type { AtLeastOneOf } from "@homarr/common/types";
|
||||
|
||||
import type { IntegrationCategory, IntegrationKind } from "./integration";
|
||||
|
||||
export type WidgetModuleIconName = `Icon${string}`;
|
||||
export type WidgetModuleOperationKind = "query" | "mutation" | "subscription" | "route";
|
||||
|
||||
export interface WidgetModuleClientPolicy {
|
||||
refetchIntervalSeconds?: number | null;
|
||||
staleTimeSeconds?: number;
|
||||
persist?: boolean;
|
||||
}
|
||||
|
||||
export interface WidgetModuleServerCachePolicy {
|
||||
namespace: string;
|
||||
ttlMs: number;
|
||||
staleIfErrorTtlMs?: number;
|
||||
scope: "integration" | "shared" | "private";
|
||||
}
|
||||
|
||||
export interface WidgetModuleOperation {
|
||||
name: string;
|
||||
kind?: WidgetModuleOperationKind;
|
||||
path: readonly [string, ...string[]];
|
||||
client?: WidgetModuleClientPolicy;
|
||||
serverCache?: WidgetModuleServerCachePolicy;
|
||||
}
|
||||
|
||||
type WidgetModuleIntegrationSelection =
|
||||
| {
|
||||
categories: Readonly<AtLeastOneOf<IntegrationCategory>>;
|
||||
kinds?: readonly IntegrationKind[];
|
||||
}
|
||||
| {
|
||||
categories?: readonly IntegrationCategory[];
|
||||
kinds: Readonly<AtLeastOneOf<IntegrationKind>>;
|
||||
};
|
||||
|
||||
export type WidgetModuleIntegrationCapability = WidgetModuleIntegrationSelection & {
|
||||
excludeKinds?: readonly IntegrationKind[];
|
||||
connectionOptional?: true;
|
||||
serverMaxIntegrations?: number;
|
||||
};
|
||||
|
||||
export interface WidgetModuleRouterRegistration {
|
||||
namespace: string;
|
||||
module: string;
|
||||
exportName: string;
|
||||
additionalWidgetKinds?: readonly string[];
|
||||
mcp?: true | string;
|
||||
}
|
||||
|
||||
export interface WidgetModuleDocumentation {
|
||||
slug: string;
|
||||
sourceDirectory: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pure authoring contract for a vertical widget module.
|
||||
*
|
||||
* This descriptor intentionally contains import paths instead of importing
|
||||
* client or server implementations. The sync tool turns them into explicit
|
||||
* static imports for Next.js and Turbopack without crossing runtime boundaries.
|
||||
*/
|
||||
export interface WidgetModuleDefinition {
|
||||
kind: string;
|
||||
icon: WidgetModuleIconName;
|
||||
clientEntry: string;
|
||||
documentation: WidgetModuleDocumentation;
|
||||
defaultSize?: Readonly<{ width: number; height: number }>;
|
||||
displayNameFromIntegration?: true;
|
||||
integration?: WidgetModuleIntegrationCapability;
|
||||
operations?: readonly WidgetModuleOperation[];
|
||||
routers?: readonly WidgetModuleRouterRegistration[];
|
||||
}
|
||||
|
||||
export const defineWidgetModule = <const TDefinition extends WidgetModuleDefinition>(definition: TDefinition) =>
|
||||
definition;
|
||||
|
||||
export type WidgetServerPermission =
|
||||
| "public"
|
||||
| "authenticated"
|
||||
| "integration-query"
|
||||
| "integration-interact"
|
||||
| "custom";
|
||||
|
||||
export interface WidgetServerInputSchema<TInput> {
|
||||
parseAsync: (input: unknown) => Promise<TInput>;
|
||||
}
|
||||
|
||||
export interface WidgetServerContext<TServices = unknown, TAuthorization = unknown> {
|
||||
services: TServices;
|
||||
authorization: TAuthorization;
|
||||
signal: AbortSignal;
|
||||
}
|
||||
|
||||
export interface WidgetServerOperationDefinition<TInput, TOutput, TContext = WidgetServerContext> {
|
||||
kind: "query" | "mutation";
|
||||
permission: WidgetServerPermission;
|
||||
input: WidgetServerInputSchema<TInput>;
|
||||
cache?: WidgetModuleServerCachePolicy;
|
||||
resolve: (context: TContext, input: TInput) => Promise<TOutput>;
|
||||
}
|
||||
|
||||
export interface WidgetServerSubscriptionDefinition<TInput, TOutput, TContext = WidgetServerContext> {
|
||||
kind: "subscription";
|
||||
permission: WidgetServerPermission;
|
||||
input: WidgetServerInputSchema<TInput>;
|
||||
transport: "sse" | "websocket";
|
||||
subscribe: (context: TContext, input: TInput) => AsyncIterable<TOutput>;
|
||||
}
|
||||
|
||||
export interface WidgetServerRouteDefinition<TRequest = unknown, TResponse = unknown, TContext = WidgetServerContext> {
|
||||
kind: "route";
|
||||
permission: WidgetServerPermission;
|
||||
handle: (context: TContext, request: TRequest) => Promise<TResponse>;
|
||||
}
|
||||
|
||||
export const defineWidgetServerOperation = <TInput, TOutput, TContext = WidgetServerContext>(
|
||||
operation: WidgetServerOperationDefinition<TInput, TOutput, TContext>,
|
||||
) => operation;
|
||||
|
||||
export const defineWidgetServerSubscription = <TInput, TOutput, TContext = WidgetServerContext>(
|
||||
subscription: WidgetServerSubscriptionDefinition<TInput, TOutput, TContext>,
|
||||
) => subscription;
|
||||
|
||||
export const defineWidgetServerRoute = <TRequest, TResponse, TContext = WidgetServerContext>(
|
||||
route: WidgetServerRouteDefinition<TRequest, TResponse, TContext>,
|
||||
) => route;
|
||||
|
||||
export const defineWidgetServerModule = <
|
||||
const TModule extends {
|
||||
operations?: Readonly<Record<string, object>>;
|
||||
subscriptions?: Readonly<Record<string, object>>;
|
||||
routes?: Readonly<Record<string, object>>;
|
||||
},
|
||||
>(
|
||||
module: TModule,
|
||||
) => module;
|
||||
@@ -1,11 +1,21 @@
|
||||
import type { IntegrationKind } from "./integration";
|
||||
import { getIntegrationName } from "./integration";
|
||||
import type { WidgetKind } from "./widget";
|
||||
import { widgetFeatureCatalog } from "./widget-feature-catalog";
|
||||
|
||||
const widgetIntegrationKinds: Partial<Record<WidgetKind, IntegrationKind>> = {
|
||||
coolify: "coolify",
|
||||
tracearr: "tracearr",
|
||||
paperlessNgx: "paperlessNgx",
|
||||
patchmon: "patchmon",
|
||||
bazarr: "bazarr",
|
||||
uptimeKuma: "uptimeKuma",
|
||||
traefik: "traefik",
|
||||
};
|
||||
|
||||
export const getWidgetIntegrationName = (kind: WidgetKind): string | undefined => {
|
||||
const descriptor = widgetFeatureCatalog[kind];
|
||||
if (!("displayNameFromIntegration" in descriptor) || !descriptor.displayNameFromIntegration) return undefined;
|
||||
return getIntegrationName(descriptor.capability.integrations[0]);
|
||||
const integrationKind = widgetIntegrationKinds[kind];
|
||||
if (!integrationKind) return undefined;
|
||||
return getIntegrationName(integrationKind);
|
||||
};
|
||||
|
||||
type WidgetNameTranslator = (key: never) => string;
|
||||
|
||||
@@ -1,19 +1,79 @@
|
||||
import { widgetFeatureCatalog } from "./widget-feature-catalog";
|
||||
export const widgetKinds = [
|
||||
"clock",
|
||||
"weather",
|
||||
"airQuality",
|
||||
"countdown",
|
||||
"timer",
|
||||
"app",
|
||||
"iframe",
|
||||
"video",
|
||||
"notebook",
|
||||
"anchorNote",
|
||||
"dnsHoleSummary",
|
||||
"dnsHoleControls",
|
||||
"smartHome-entityState",
|
||||
"smartHome-executeAutomation",
|
||||
"stockPrice",
|
||||
"mediaServer",
|
||||
"calendar",
|
||||
"downloads",
|
||||
"mediaRequests-requestList",
|
||||
"mediaRequests-requestStats",
|
||||
"mediaTranscoding",
|
||||
"mediaMissing",
|
||||
"minecraftServerStatus",
|
||||
"networkControllerSummary",
|
||||
"networkControllerStatus",
|
||||
"rssFeed",
|
||||
"bookmarks",
|
||||
"indexerManager",
|
||||
"healthMonitoring",
|
||||
"releases",
|
||||
"mediaReleases",
|
||||
"dockerContainers",
|
||||
"firewall",
|
||||
"notifications",
|
||||
"systemResources",
|
||||
"coolify",
|
||||
"systemDisks",
|
||||
"timetable",
|
||||
"immich-serverStats",
|
||||
"immich-albumCarousel",
|
||||
"paperlessNgx",
|
||||
"patchmon",
|
||||
"bazarr",
|
||||
"tracearr",
|
||||
"speedtestTracker",
|
||||
"uptimeKuma",
|
||||
"audioStats",
|
||||
"umami",
|
||||
"vpn",
|
||||
"archiveTeamWarrior",
|
||||
"ups",
|
||||
"beszelSystemTable",
|
||||
"beszelSystemGrid",
|
||||
"beszelAlerts",
|
||||
"beszelSystemStats",
|
||||
"traefik",
|
||||
"customApi",
|
||||
"assistant",
|
||||
"wud",
|
||||
] as const;
|
||||
|
||||
export * from "./widget-feature-catalog";
|
||||
export type { WidgetFeatureDescriptor } from "./widget-feature-catalog";
|
||||
export type WidgetKind = (typeof widgetKinds)[number];
|
||||
|
||||
export type WidgetKind = keyof typeof widgetFeatureCatalog;
|
||||
|
||||
export const widgetKinds = Object.keys(widgetFeatureCatalog) as unknown as readonly [WidgetKind, ...WidgetKind[]];
|
||||
|
||||
const createWidgetDefaultSizes = () => {
|
||||
const result: Partial<Record<WidgetKind, { width: number; height: number }>> = {};
|
||||
for (const kind of widgetKinds) {
|
||||
const descriptor = widgetFeatureCatalog[kind];
|
||||
if ("defaultSize" in descriptor) result[kind] = descriptor.defaultSize;
|
||||
}
|
||||
return result;
|
||||
export const widgetDefaultSizes: Partial<Record<WidgetKind, { width: number; height: number }>> = {
|
||||
clock: { width: 2, height: 1 },
|
||||
weather: { width: 2, height: 1 },
|
||||
airQuality: { width: 2, height: 1 },
|
||||
countdown: { width: 2, height: 1 },
|
||||
timer: { width: 2, height: 1 },
|
||||
bookmarks: { width: 2, height: 2 },
|
||||
uptimeKuma: { width: 2, height: 3 },
|
||||
audioStats: { width: 2, height: 2 },
|
||||
paperlessNgx: { width: 2, height: 2 },
|
||||
patchmon: { width: 2, height: 2 },
|
||||
mediaMissing: { width: 4, height: 3 },
|
||||
bazarr: { width: 2, height: 2 },
|
||||
assistant: { width: 10, height: 4 },
|
||||
};
|
||||
|
||||
export const widgetDefaultSizes = createWidgetDefaultSizes();
|
||||
Reference in new issue
Block a user