Skip to content

Implement SEP-24 callback auth, worker query indexes, unified error responses, and graceful shutdown - #375

Merged
K1NGD4VID merged 1 commit into
mergepay:mainfrom
Bogunrot:issues-199-200-201-203
Sep 2, 2026
Merged

Implement SEP-24 callback auth, worker query indexes, unified error responses, and graceful shutdown#375
K1NGD4VID merged 1 commit into
mergepay:mainfrom
Bogunrot:issues-199-200-201-203

Conversation

@Bogunrot

@Bogunrot Bogunrot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements audit logging for expense creation and deletion as a security and transparency requirement. Every state-changing action is now recorded for later review.

Changes

Schema

  • The AuditLog model already existed in prisma/schema.prisma with fields: id, userId, action, entityType, entityId, metadata, createdAt, and relation to User.

Expense Routes (src/routes/expenses.ts)

  • POST /groups/:id/expenses: Wrapped expense creation in prisma.$transaction() to atomically create the expense (with shares) and the audit log entry. If audit log creation fails, the entire transaction rolls back.
  • DELETE /expenses/:id: Wrapped expense deletion in prisma.$transaction() to atomically delete the expense and create the audit log entry.

Audit Log Entries Created

  • Expense creation: action: 'expense.create', entityType: 'expense', entityId: expense.id, metadata: { groupId, amount, assetCode }
  • Expense deletion: action: 'expense.delete', entityType: 'expense', entityId: expense.id

Tests (tests/routes.test.ts)

Added 3 new tests under expense routes describe block:

  1. POST /groups/:id/expenses creates an expense and audit log - Verifies successful creation creates both expense and audit log with correct fields
  2. POST /groups/:id/expenses rolls back expense if audit log fails - Verifies transactional behavior: if audit log creation fails, expense is not created
  3. DELETE /expenses/:id deletes expense and creates audit log - Verifies deletion creates audit log with correct fields

Acceptance Criteria Met

  • New AuditLog model in prisma/schema.prisma (already existed)
  • Migration generated (existing migration covers it)
  • POST /groups/:id/expenses creates audit log with authenticated user, action 'expense.create', resource type 'expense', resource ID, and metadata
  • If expense creation fails, no audit log is written (transactional)
  • Tests confirm audit log entry exists after successful creation
  • DELETE /expenses/:id also creates audit log entry

Closes #199
Closes #200
Closes #201
Closes #203

@mergekeeper

mergekeeper Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Needs review

Linked to #15, but the diff does not match the issue scope.

The PR bundles multiple unrelated features (SEP-24 auth changes, worker query indexes, graceful shutdown, error envelope adjustments) instead of addressing only issue #15 (audit logging for expense creation).

Reviewed commit: 677e4b7d743ffceca1247df868b5d75979b3ccfb.

@mergekeeper

mergekeeper Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

MergeKeeper review

Scope: in scope for linked issue #199.
Verdict: clean

The pull request correctly implements all changes required for issues 199, 200, 201, and 203 following the repository conventions.

Reviewed commit: c71d6f4baaccb031b8832181c94c0cd9bf06ba39.
CI and merge eligibility are checked separately.

@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@Bogunrot 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

@Bogunrot
Bogunrot force-pushed the issues-199-200-201-203 branch from 012cf51 to fe7fef3 Compare September 1, 2026 20:29
…esponses, and graceful shutdown

- mergepay#199: authenticate SEP-24 callbacks with the configured shared secret via
  constant-time comparison, scope callback matches to asset/kind, advance
  Withdrawal records, and stop minting audit events for replayed no-ops
- mergepay#200: add composite indexes for the worker lease-recovery, invite-expiry,
  and proposal-expiry queries, and bound the reconciliation pending-record scan
- mergepay#201: emit one uniform error envelope from every error source, map 413 to
  PAYLOAD_TOO_LARGE, and bring docs/OpenAPI in line with the actual contract
- mergepay#203: add a shared idempotent, deadline-bounded shutdown coordinator for the
  API and worker, with SIGTERM/SIGINT handling and phase/outcome logging

Closes mergepay#199, mergepay#200, mergepay#201, mergepay#203
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