Reconstruye el Webhook Messenger nativo de SAP B1 (FP2605) para clientes que aun no estan en esa version: captura eventos via SBO_SP_PostTransactionNotice, provisiona UserTables OEVC/EVC1/OEVN/EVN1 y despacha CloudEvents al mismo endpoint que el messenger real. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import type { ServiceLayerClient } from '../service-layer-client.ts';
|
|
import { userTableEntity } from '../lib/service-layer-paths.ts';
|
|
|
|
const ENTITY = userTableEntity('OEVN');
|
|
|
|
export interface OevnRow {
|
|
code: string;
|
|
sourceDb: string;
|
|
status: string;
|
|
objectType: string;
|
|
transType: string;
|
|
fieldNames: string;
|
|
fieldValue: string;
|
|
}
|
|
|
|
function toRow(raw: Record<string, unknown>): OevnRow {
|
|
return {
|
|
code: raw.Code as string,
|
|
sourceDb: raw.U_SourceDB as string,
|
|
status: raw.U_Status as string,
|
|
objectType: raw.U_ObjectType as string,
|
|
transType: raw.U_TransType as string,
|
|
fieldNames: raw.U_FieldNames as string,
|
|
fieldValue: raw.U_FieldValue as string,
|
|
};
|
|
}
|
|
|
|
export async function listNewEvents(client: ServiceLayerClient): Promise<OevnRow[]> {
|
|
const rows = await client.getAll(`/${ENTITY}?$filter=${encodeURIComponent("U_Status eq 'N'")}`);
|
|
return rows.map(toRow);
|
|
}
|
|
|
|
export async function getEvent(client: ServiceLayerClient, code: string): Promise<OevnRow | null> {
|
|
const res = await client.get(`/${ENTITY}('${code}')`);
|
|
return res.status === 200 ? toRow(res.data) : null;
|
|
}
|
|
|
|
export async function deleteEvent(client: ServiceLayerClient, code: string): Promise<void> {
|
|
await client.delete(`/${ENTITY}('${code}')`);
|
|
}
|
|
|
|
export async function setEventStatus(client: ServiceLayerClient, code: string, status: string): Promise<void> {
|
|
await client.patch(`/${ENTITY}('${code}')`, { U_Status: status });
|
|
}
|