Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/packages/view-models/src/apps-engine/integration-catalog.vm.ts
T
2026-07-08 16:15:37 +02:00

73 lines
2.6 KiB
TypeScript

import type { VMState } from "../index.js";
/**
* Integrations catalog view-model (R-P5). Pure function (DoD A.3): the loader
* builds it once server-side; the UI only renders. The catalog itself is code-
* defined (@hivegrid/integrations INTEGRATION_CATALOG); the loader passes the
* per-app live connection count. NO credentials anywhere.
*/
export type IntegrationCategory = "erp" | "communication" | "calendar" | "signature" | "payment" | "ki";
export interface CatalogAppRow {
readonly key: string;
/** i18n key for the app display name. */
readonly titleKey: string;
readonly category: IntegrationCategory;
/** i18n key for the category label (e.g. `integrations.category.erp`). */
readonly categoryKey: string;
readonly connectionType: "oauth2" | "api_key" | "rest_api" | "windows_client";
/** Loader-computed number of the tenant's connections for this app. */
readonly connectionCount: number;
/** Internal route to this app's connection management. */
readonly detailHref: string;
}
export interface IntegrationCatalogData {
readonly rows: readonly CatalogAppRow[];
readonly canConnect: boolean;
readonly emptyHeadlineKey: string;
readonly emptyBodyKey: string;
}
export type IntegrationCatalogVM = VMState<IntegrationCatalogData>;
export function integrationCategoryKey(category: IntegrationCategory): string {
return `integrations.category.${category}`;
}
/** Normalized prop-model for the catalog UI implementations (M015/M017). */
export interface IntegrationCatalogModel {
readonly titleKey: string;
readonly rows: readonly CatalogAppRow[];
readonly rowCount: number;
/** Number of apps with at least one tenant connection (status light). */
readonly connectedCount: number;
readonly canConnect: boolean;
readonly emptyHeadlineKey: string;
readonly emptyBodyKey: string;
}
export function toIntegrationCatalogModel(data: IntegrationCatalogData): IntegrationCatalogModel {
return {
titleKey: "integrations.catalog.title",
rows: data.rows,
rowCount: data.rows.length,
connectedCount: data.rows.filter((row) => row.connectionCount > 0).length,
canConnect: data.canConnect,
emptyHeadlineKey: data.emptyHeadlineKey,
emptyBodyKey: data.emptyBodyKey,
};
}
export function buildIntegrationCatalogVM(input: { rows: readonly CatalogAppRow[]; canConnect: boolean }): IntegrationCatalogVM {
return {
status: "ready",
data: {
rows: input.rows,
canConnect: input.canConnect,
emptyHeadlineKey: "integrations.catalog.empty.headline",
emptyBodyKey: "integrations.catalog.empty.body",
},
};
}