fix(eoc-push): mappa feedback-tidsstämpel till "skapad" per EOC-kontraktet

This commit is contained in:
Sven (AAMOS AI)
2026-08-11 17:27:53 +07:00
parent af05f084b8
commit 125192f24a
2 changed files with 79 additions and 2 deletions
+41 -1
View File
@@ -14,6 +14,44 @@ function ingestUrl(base: string): string {
return `${trimmed}/api/v1/apps/cibello/ingest`;
}
interface EocFeedbackPost {
typ?: string;
rubrik?: string;
status?: string;
created_at?: string;
skapad?: string;
[key: string]: unknown;
}
interface EocFeedback {
oppna?: number;
senaste?: EocFeedbackPost[];
[key: string]: unknown;
}
/**
* Build a payload that matches EOC's authoritative contract:
* feedback.senaste[].created_at must be sent as feedback.senaste[].skapad.
* All other keys are forwarded unchanged.
*/
function mapPayloadForEoc(parsed: Record<string, unknown>): Record<string, unknown> {
const mapped: Record<string, unknown> = { ...parsed };
const feedback = mapped.feedback as EocFeedback | undefined;
if (feedback && Array.isArray(feedback.senaste)) {
mapped.feedback = {
...feedback,
senaste: feedback.senaste.map((post) => {
const { created_at, ...rest } = post;
return {
...rest,
...(created_at !== undefined ? { skapad: created_at } : {}),
};
}),
};
}
return mapped;
}
/**
* Push the cached ops summary to EOC. Never throws; failures are returned
* as `ok: false` and must be logged by the caller.
@@ -42,6 +80,8 @@ export async function pushOpsSummaryToEoc(redis: Redis): Promise<EocPushResult>
return { ok: false, status: null, error: "ops summary cache is not a JSON object" };
}
const body = JSON.stringify(mapPayloadForEoc(parsed as Record<string, unknown>));
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), EOC_PUSH_TIMEOUT_MS);
@@ -52,7 +92,7 @@ export async function pushOpsSummaryToEoc(redis: Redis): Promise<EocPushResult>
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
body: json,
body,
signal: controller.signal,
});
clearTimeout(timeout);