Skip to content

feat: Advanced audit log, ORGUSD Soroban contract & standardized API errors#854

Merged
Wilfred007 merged 4 commits into
Gildado:mainfrom
Samuel1505:main
May 30, 2026
Merged

feat: Advanced audit log, ORGUSD Soroban contract & standardized API errors#854
Wilfred007 merged 4 commits into
Gildado:mainfrom
Samuel1505:main

Conversation

@Samuel1505
Copy link
Copy Markdown
Contributor

This PR resolves four open issues across the backend and smart-contract layers of PayD.

Closes #696
Closes #186
Closes #187
Closes #341

Summary of Changes

Issue #696 — Advanced Audit Log for All Admin Actions (backend)

  • backend/src/db/migrations/048_create_admin_audit_log.sql — New append-only admin_audit_log table with 6 covering indexes, PostgreSQL rules preventing UPDATE/DELETE, and JSONB old_state/new_state columns for diff-style auditing.
  • backend/src/services/adminAuditService.ts — Service with log(), list() (multi-filter pagination by action type, resource type, actor, severity, date range), summary() (aggregated counts for dashboards), and exportCsv() (up to 10 000 rows).
  • backend/src/routes/adminAuditRoutes.tsGET /api/v1/admin-audit (list), /summary, and /export behind EMPLOYER JWT + org-isolation guards with Swagger docs.
  • backend/src/middlewares/adminAuditMiddleware.tsauditAction() factory: fire-and-forget middleware that wraps any mutating route and appends a structured audit entry without blocking the response path.
  • backend/src/routes/v1/index.ts — Register /admin-audit under dataRateLimit.
  • backend/src/services/__tests__/adminAuditService.test.ts — Unit tests for all service methods including filter combinations, CSV escaping, and error swallowing.

Issues #186 / #187 — ORGUSD Custom Asset on Stellar Testnet (Soroban contract)

  • contracts/orgusd/Cargo.toml — Package manifest inheriting workspace version, authors, and license.
  • contracts/orgusd/src/lib.rs — Full Soroban contract implementing:
    • initialize(admin) — one-shot setup
    • authorize(account) / revoke(account) — mirrors Stellar auth_required/auth_revocable
    • freeze(account) / unfreeze(account) — regulatory hold
    • mint(to, amount) — admin-only issuance
    • transfer(from, to, amount) — with auth, dual active-account checks, self-transfer guard
    • burn(from, amount) / clawback(from, amount) — holder and admin token destruction
    • SEP-0034 metadata (name, version, author)
    • Typed #[contracterror] enum (9 variants) and #[contractevent] for every state transition
    • 20 unit tests covering the full issuance flow and all error paths
  • Cargo.toml — Added contracts/orgusd to workspace members.

Issue #341 — Standardize API Error Response Format (backend)

  • backend/src/middlewares/errorHandlerMiddleware.ts — Central Express error handler that maps every error type to the canonical shape { code, message, details, requestId }:
    • ZodError → 400 VALIDATION_ERROR with per-field details
    • HTTP-tagged errors → status passthrough, code inferred from status or err.code
    • TypeError / RangeError / SyntaxError → 400 BAD_REQUEST
    • Unhandled errors → 500 INTERNAL_ERROR (message redacted in production)
  • backend/src/app.ts — Replace the inline catch-all handler with errorHandlerMiddleware.
  • backend/src/__tests__/errorHandlerMiddleware.test.ts — 18 integration tests covering all error categories, production/development message visibility, non-Error thrown values, and shape compliance.

Test Plan

  • cd backend && npm test — all existing tests pass; adminAuditService.test.ts and errorHandlerMiddleware.test.ts pass
  • Apply migration 048_create_admin_audit_log.sql against a local database; confirm table, indexes, and rules are created
  • GET /api/v1/admin-audit with a valid EMPLOYER JWT → { success: true, data: [], total: 0 }
  • GET /api/v1/admin-audit/summary{ success: true, data: { totalActions: 0, ... } }
  • GET /api/v1/admin-audit/exporttext/csv with correct header row
  • Trigger a Zod validation failure → response body matches { code: "VALIDATION_ERROR", details: [...] }
  • Trigger a 404 → { code: "NOT_FOUND", message: "...", details: [] }
  • cargo test -p orgusd — all 20 contract unit tests pass (requires Soroban toolchain)

🤖 Generated with Claude Code

Samuel1505 and others added 4 commits May 30, 2026 16:57
…ldado#696)

- Add migration 048 creating append-only admin_audit_log table with
  severity levels, resource snapshots, actor context, and request
  correlation; enforced via PostgreSQL rules (no UPDATE/DELETE).
- Add AdminAuditService with log(), list() (filtering by action type,
  resource type, actor, severity, date range), summary() (aggregated
  counts), and exportCsv() (max 10 000 rows).
- Add adminAuditRoutes.ts exposing GET /api/v1/admin-audit, /summary,
  and /export behind EMPLOYER JWT + org isolation guards.
- Add auditAction() middleware factory for fire-and-forget logging on
  mutating routes without blocking the main request path.
- Register /admin-audit in v1 router with dataRateLimit.
- Add comprehensive unit/integration tests for all service methods.

Closes Gildado#696

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Gildado#187)

- Implement OrgUsdContract in Rust using the Soroban SDK with:
    • Admin-gated minting with positive-amount guard.
    • Per-account authorization (mirrors Stellar auth_required flag).
    • Freeze / unfreeze for regulatory holds (auth_revocable).
    • Transfer with sender-auth, dual active-account checks, and
      self-transfer guard.
    • Burn (holder-initiated) and admin clawback, both reducing
      total supply.
    • SEP-0034 metadata (name, version, author).
    • Typed errors via #[contracterror] with repr(u32) codes.
    • Events for every state transition (mint, transfer, burn, etc.).
- Add comprehensive unit tests covering the full issuance flow:
  initialize, authorize, mint, transfer, burn, clawback, freeze,
  and all error paths (unauthorized, frozen, insufficient funds, etc.).
- Register contracts/orgusd in the Cargo workspace.

Closes Gildado#186
Closes Gildado#187

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add errorHandlerMiddleware.ts — a single Express error-handler that
  maps every error type to the canonical shape:
    { code: string, message: string, details: unknown[], requestId }
  covering ZodError (400 + per-field details), HTTP-tagged errors
  (4xx with code inference), client-side JS errors (TypeError /
  RangeError / SyntaxError → 400), and unhandled exceptions (500,
  message redacted in production).
- Replace the inline catch-all handler in app.ts with a call to
  errorHandlerMiddleware so all routes share the same error format.
- Add comprehensive integration tests covering ZodError, HTTP-tagged
  errors for all common status codes, JS error types, production vs
  development message visibility, and shape compliance across error
  types.

Closes Gildado#341

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 30, 2026

@Samuel1505 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Wilfred007 Wilfred007 merged commit efe26b5 into Gildado:main May 30, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants