Consume raw arma-sync-events into a validated, idempotent operation ledger: contract v1, reject/dead-letter with zero effects, effect keys with unique-constraint race handling, and a staged-activation flag hook. Registers the operations permission domains. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
108 lines
No EOL
3.2 KiB
TypeScript
108 lines
No EOL
3.2 KiB
TypeScript
import type { CollectionConfig } from "payload";
|
|
|
|
/**
|
|
* Validated operation-event ledger.
|
|
*
|
|
* Consumes immutable raw `arma-sync-events` evidence and records the outcome
|
|
* of validating it against the supported operation event contract. Every raw
|
|
* event that reaches the ledger gets exactly one row here (idempotent by
|
|
* `sourceEvent`), including malformed or unsupported events, which are kept
|
|
* as `rejected` / `dead-letter` records with zero derived effects.
|
|
*
|
|
* Writes are internal only (create/update/delete are denied to everyone; the
|
|
* bridge writes via `overrideAccess`). Read is open to any logged-in user.
|
|
*/
|
|
export const OperationEvents: CollectionConfig = {
|
|
slug: "operation-events",
|
|
admin: {
|
|
group: "Operations",
|
|
useAsTitle: "eventId",
|
|
defaultColumns: ["eventId", "operationId", "type", "status", "occurredAt"],
|
|
},
|
|
access: {
|
|
read: ({ req }) => !!req.user,
|
|
create: () => false,
|
|
update: () => false,
|
|
delete: () => false,
|
|
},
|
|
fields: [
|
|
{
|
|
name: "sourceEvent",
|
|
type: "relationship",
|
|
relationTo: "arma-sync-events",
|
|
required: true,
|
|
unique: true,
|
|
index: true,
|
|
admin: {
|
|
description: "The immutable raw sync event this record was derived from.",
|
|
},
|
|
},
|
|
{
|
|
name: "eventId",
|
|
type: "text",
|
|
required: true,
|
|
unique: true,
|
|
index: true,
|
|
admin: {
|
|
description: "Mirror of the raw event's server-prefixed id (serverId:eventId).",
|
|
},
|
|
},
|
|
{
|
|
name: "operationId",
|
|
type: "text",
|
|
required: true,
|
|
index: true,
|
|
admin: {
|
|
description: "Operation identity from the event payload, or \"unknown\".",
|
|
},
|
|
},
|
|
{
|
|
name: "type",
|
|
type: "text",
|
|
required: true,
|
|
index: true,
|
|
admin: {
|
|
description:
|
|
"Event type as received. Supported: operation.start, operation.end, operation.objective, operation.extraction, operation.inventory, player.kill. Unknown types are kept as dead-letter records.",
|
|
},
|
|
},
|
|
{
|
|
name: "version",
|
|
type: "number",
|
|
required: true,
|
|
defaultValue: 1,
|
|
admin: { description: "Event contract version from the payload (default 1)." },
|
|
},
|
|
{
|
|
name: "status",
|
|
type: "select",
|
|
required: true,
|
|
defaultValue: "validated",
|
|
options: [
|
|
{ label: "Validated", value: "validated" },
|
|
{ label: "Rejected", value: "rejected" },
|
|
{ label: "Dead Letter", value: "dead-letter" },
|
|
],
|
|
admin: {
|
|
description: "Validation outcome. Only validated events derive effects.",
|
|
},
|
|
},
|
|
{
|
|
name: "error",
|
|
type: "json",
|
|
admin: { description: "Rejection/dead-letter reason: { code, message }." },
|
|
},
|
|
{
|
|
name: "payloadHash",
|
|
type: "text",
|
|
required: true,
|
|
admin: { description: "SHA-256 of the stable-stringified raw payload." },
|
|
},
|
|
{ name: "actor", type: "relationship", relationTo: "users" },
|
|
{ name: "server", type: "relationship", relationTo: "game-servers" },
|
|
{ name: "mission", type: "relationship", relationTo: "missions" },
|
|
{ name: "occurredAt", type: "date", required: true },
|
|
{ name: "validatedAt", type: "date" },
|
|
{ name: "reconciliationNotes", type: "textarea" },
|
|
],
|
|
}; |