2026-10-05 11:13:51 +00:00
|
|
|
import type { ResourceCatalog } from "./resource-catalog.aggregate";
|
|
|
|
|
import type { ResourceDefinitionSpec, ResourceFieldType } from "./resource-definition";
|
2026-10-09 08:38:19 +00:00
|
|
|
import { ResourceDefinitionValues } from "./value-objects/resource-definition-values.vo";
|
2026-10-05 11:13:51 +00:00
|
|
|
|
2026-10-07 11:26:59 +00:00
|
|
|
const FIELDS: readonly [string, string, ResourceFieldType, (readonly string[])?][] = [
|
2026-10-05 11:13:51 +00:00
|
|
|
["email", "Dirección de correo", "text"],
|
|
|
|
|
["provider", "Proveedor", "text"],
|
|
|
|
|
["context", "Contexto", "text"],
|
|
|
|
|
["unc", "Ruta UNC", "text"],
|
|
|
|
|
["server", "Servidor (referencia documental)", "text"],
|
|
|
|
|
["description", "Descripción", "text"],
|
|
|
|
|
["url", "URL", "text"],
|
|
|
|
|
["holder", "Titular", "text"],
|
|
|
|
|
["issuer", "Emisor", "text"],
|
|
|
|
|
["expires", "Caducidad", "date"],
|
|
|
|
|
["fingerprint", "Huella digital", "text"],
|
|
|
|
|
["purpose", "Finalidad", "text"],
|
2026-10-05 15:01:32 +00:00
|
|
|
["reference", "Referencia", "text"],
|
2026-10-07 11:26:59 +00:00
|
|
|
["software_product", "Producto de software", "text"],
|
|
|
|
|
["software_edition", "Edición o plan", "text"],
|
|
|
|
|
["license_model", "Modalidad de licencia", "choice", ["Suscripción", "Perpetua", "OEM", "Otra"]],
|
|
|
|
|
[
|
|
|
|
|
"license_metric",
|
|
|
|
|
"Criterio de licenciamiento",
|
|
|
|
|
"choice",
|
|
|
|
|
["Por usuario", "Por dispositivo", "Por servidor", "Concurrente", "Corporativa", "Otro"],
|
|
|
|
|
],
|
|
|
|
|
["license_quantity", "Cantidad contratada", "number"],
|
|
|
|
|
["renews", "Fecha de renovación", "date"],
|
|
|
|
|
["auto_renew", "Renovación automática", "boolean"],
|
2026-10-05 11:13:51 +00:00
|
|
|
];
|
|
|
|
|
const TEMPLATES: readonly [string, string, readonly string[]][] = [
|
|
|
|
|
["mailbox", "Buzón de correo", ["email", "provider", "context"]],
|
2026-10-05 15:01:32 +00:00
|
|
|
["access", "Recurso de acceso", ["reference"]],
|
2026-10-05 11:13:51 +00:00
|
|
|
["shared_folder", "Carpeta compartida", ["unc", "server", "description"]],
|
|
|
|
|
["application", "Aplicación", ["provider", "url", "description"]],
|
|
|
|
|
["certificate", "Certificado digital", ["holder", "issuer", "expires", "fingerprint", "purpose"]],
|
2026-10-07 11:26:59 +00:00
|
|
|
[
|
|
|
|
|
"software_license",
|
|
|
|
|
"Licencia de software",
|
|
|
|
|
[
|
|
|
|
|
"software_product",
|
|
|
|
|
"software_edition",
|
|
|
|
|
"provider",
|
|
|
|
|
"license_model",
|
|
|
|
|
"license_metric",
|
|
|
|
|
"license_quantity",
|
|
|
|
|
"reference",
|
|
|
|
|
"expires",
|
|
|
|
|
"renews",
|
|
|
|
|
"auto_renew",
|
|
|
|
|
"description",
|
|
|
|
|
],
|
|
|
|
|
],
|
2026-10-05 11:13:51 +00:00
|
|
|
];
|
|
|
|
|
/** Solo alimenta definiciones; no crea recursos ni migra registros anteriores. */
|
|
|
|
|
export function seedResourceCatalog(catalog: ResourceCatalog) {
|
|
|
|
|
let current = catalog;
|
|
|
|
|
const add = (key: string, input: ResourceDefinitionSpec) => {
|
|
|
|
|
const values = ResourceDefinitionValues.create(input);
|
|
|
|
|
if (!values.isSuccess) {
|
|
|
|
|
throw new Error("Definición inicial de recursos inválida.");
|
|
|
|
|
}
|
|
|
|
|
const result = current.seed(key, values.data);
|
|
|
|
|
if (!result.isSuccess) {
|
|
|
|
|
throw new Error("Catálogo inicial de recursos inconsistente.");
|
|
|
|
|
}
|
|
|
|
|
current = result.data;
|
|
|
|
|
};
|
2026-10-07 11:26:59 +00:00
|
|
|
for (const [key, name, type, choices] of FIELDS) {
|
|
|
|
|
add(`field:${key}`, {
|
|
|
|
|
kind: "field",
|
|
|
|
|
name,
|
|
|
|
|
description: "",
|
|
|
|
|
type,
|
|
|
|
|
unit: "",
|
|
|
|
|
choices: [...(choices ?? [])],
|
|
|
|
|
});
|
2026-10-05 11:13:51 +00:00
|
|
|
}
|
|
|
|
|
for (const [key, name, fields] of TEMPLATES) {
|
|
|
|
|
const references = fields.map((field) => {
|
|
|
|
|
const id = current.definitions
|
|
|
|
|
.find((item) => item.stockKey.getOrUndefined() === `field:${field}`)
|
|
|
|
|
?.id.toPrimitive();
|
|
|
|
|
if (!id) {
|
|
|
|
|
throw new Error("Campo inicial de recursos ausente.");
|
|
|
|
|
}
|
|
|
|
|
return { fieldId: id, required: false };
|
|
|
|
|
});
|
|
|
|
|
add(`template:${key}`, { kind: "template", name, description: "", fields: references });
|
|
|
|
|
}
|
|
|
|
|
return current;
|
|
|
|
|
}
|