import { z } from 'zod';
/**
* Schema for a single context mapping
*/
export const ContextMappingSchema = z.object({
id: z.string(),
name: z.string(),
namespace: z.string(),
jobRequestKind: z.number(),
jobResultKind: z.number(),
rootEntity: z.object({
type: z.string(),
initialState: z.string(),
schema: z.record(z.any()),
required: z.array(z.string()).default([]),
transitions: z.array(
z.object({
name: z.string(),
description: z.string(),
from: z.string(),
to: z.string(),
inputSchema: z.record(z.any()).optional(),
})
),
}),
queries: z
.object({
enabled: z.boolean().default(true),
apiEndpoint: z.string().url().optional(),
cacheEnabled: z.boolean().default(true),
cacheTTL: z.number().default(300),
})
.optional(),
});
export type ContextMapping = z.infer<typeof ContextMappingSchema>;
/**
* Schema for the contexts configuration file
*/
export const ContextsConfigSchema = z.object({
contexts: z.array(ContextMappingSchema),
});
export type ContextsConfig = z.infer<typeof ContextsConfigSchema>;
/**
* Load contexts from JSON file
*/
export function loadContextsFromFile(filePath: string): ContextsConfig {
const fs = require('fs');
const data = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
return ContextsConfigSchema.parse(data);
}
/**
* Default contexts for CBZ Tesorería
*/
export const defaultContexts: ContextMapping[] = [
{
id: 'cbz_tesoreria_pagos',
name: 'CBZ Tesorería - Pagos Ejecutados',
namespace: 'cbz-tesoreria-pagos-ejecutados',
jobRequestKind: 5053,
jobResultKind: 6053,
rootEntity: {
type: 'pago-tesoreria',
initialState: 'planificado',
schema: {
importe: {
type: 'number',
description: 'Importe del pago en EUR',
minimum: 0,
},
concepto: {
type: 'string',
description: 'Concepto del pago',
maxLength: 255,
},
beneficiario: {
type: 'string',
description: 'Beneficiario del pago',
},
cuenta_destino: {
type: 'string',
description: 'IBAN de la cuenta destino',
pattern: '^[A-Z]{2}[0-9]{2}[A-Z0-9]+$',
},
fecha_ejecucion: {
type: 'string',
format: 'date',
description: 'Fecha planificada de ejecución',
},
},
required: ['importe', 'concepto', 'beneficiario'],
transitions: [
{
name: 'validar',
description: 'Validar datos del pago',
from: 'planificado',
to: 'validado',
inputSchema: {},
},
{
name: 'aprobar',
description: 'Aprobar pago para ejecución',
from: 'validado',
to: 'aprobado',
inputSchema: {
aprobador_id: {
type: 'string',
description: 'ID del usuario que aprueba',
},
},
},
{
name: 'ejecutar',
description: 'Ejecutar pago bancario',
from: 'aprobado',
to: 'ejecutado',
inputSchema: {
referencia_bancaria: {
type: 'string',
description: 'Referencia de la transacción bancaria',
},
},
},
{
name: 'rechazar',
description: 'Rechazar pago',
from: 'validado',
to: 'rechazado',
inputSchema: {
motivo: {
type: 'string',
description: 'Motivo del rechazo',
},
},
},
],
},
queries: {
enabled: true,
cacheEnabled: true,
cacheTTL: 300,
},
},
];