Skip to content

Feature [Needs Review]: Append-only EPOS audit event log foundation (main/core/audit.ts) #287

Open

Description

@khaira777

Problem

FloCafe currently records security and financial history across four fragmented tables (order_audit_log, auth_audit_log, authorization_audit_log, tax_config_audit), while several high-risk operational actions still lack unified append-only audit coverage (e.g., item voids in main/routes/order-items.ts, manual price/discount overrides, cash-drawer no-sale opens, shift start/end, and future closed-session amendments). Furthermore, every existing audit table assumes a human users.id (user_id / actor_user_id), leaving no clean actor-attribution model for non-human callers such as scoped Integration API keys (Open Integration Platform RFC) or Kiosk tokens (#367).

Codebase Anchor

  • Existing audit tables in main/db.ts: order_audit_log (main/db.ts:11688), auth_audit_log, authorization_audit_log, tax_config_audit.
  • High-risk mutation surfaces: main/routes/order-items.ts:259-362 (voids), main/routes/bills.ts (discounts & payment-method corrections), main/services/refund.ts (refunds), main/routes/cash-sessions.ts & main/routes/cash-closures.ts (drawer opens, shifts, Z-reports), main/routes/database.ts & main/routes/database-tools.ts (backup/restore/reset).

Core Invariants & Constraints

  • Append-only integrity: Audit rows must never be updated or deleted by ordinary application routes (with documented retention/export policy only under explicit owner maintenance).
  • Backup & privacy safety: Never log raw passwords, PINs, JWTs, API keys, or webhook secrets in payload_json; scrub sensitive fields before persistence.
  • No ownership gating (Core Invariant feat: POS UI improvements — dev-server, frontend submodule update #6): Audit attribution is for accountability and compliance, never for hiding orders between staff.

Scope / Acceptance Criteria

  • Design and implement a unified append-only audit_events table (id, actor_type: 'user'|'integration'|'kiosk'|'system', actor_id, actor_label, action, resource_type, resource_id, payload_json, ip_address, created_at) and helper module main/services/audit.ts (SQLite triggers or service guard rejecting UPDATE/DELETE).
  • Emit structured events for highest-risk actions: ORDER_VOID, ITEM_VOID, DISCOUNT_APPLIED, REFUND_ISSUED, CASH_DRAWER_OPEN, SHIFT_OPEN, SHIFT_CLOSE, CASH_CLOSE_AMENDED, MASTER_PIN_ACTION, API_KEY_MUTATION.
  • Add owner-only read/filter API (GET /api/audit-events gated on dedicated audit.view permission) with pagination and CSV/JSON export.
  • Add tests wired into package.json verifying append-only guarantees, secret redaction, and user vs integration actor attribution.

Concrete Design Decisions to Lock Before Coding

  1. Consolidation vs coexistence: Confirm whether existing order_audit_log / tax_config_audit remain intact for backward compatibility while new/high-risk events write to unified audit_events (recommended to avoid risky legacy migrations).
  2. Actor schema alignment: Lock actor_type + actor_id columns jointly with the Open Integration Platform RFC and #367 (Kiosk) so all three share one attribution contract.
  3. Retention policy: Define whether audit logs are retained indefinitely by default (matching #1450 purge boundary and #703 void/archive rules).

Out of Scope

  • Tamper-evident external blockchain/cloud hash anchoring or real-time SIEM streaming (can be layered via outbound webhooks later).

Activity

  1. khaira777 commented on Aug 16, 2026

    @khaira777
    ContributorAuthor

    Verdict: VALID ENHANCEMENT — needs product/security review and rescoping

    Findings:

    • No general append-only audit table exists. What does exist: tax_config_audit (main/db.ts:4351), loyalty_ledger (:4244), print_logs (:2305), payment_idempotency/order_idempotency (:3292, :3347), and support/diagnostics outboxes. Voids mutate order_items.status (main/routes/order-items.ts:116) without an actor/action record.
    • Precedent: tax packs already require an audit trail (tax_config_audit + audit route in main/routes/tax-packs.ts), so an audit subsystem fits FloCafe's compliance direction.

    Suggested scope: minimal append-only audit_events table + recorder for the highest-risk actions (item void, price override, discount, refund, master-PIN actions), owner-only read API, and retention policy. Coordinate with #278 (refunds), #279 (shift events), #280 (inventory ledger) so we don't build four parallel ledgers. Maintainer decision needed: event list + retention.

  2. added
    enhancement
    area:backend
    on Aug 16, 2026
  3. added
    priority:high
    type:design
    state:needs-design
    on Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:backendenhancementpriority:highstate:needs-designtype:design

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions