Skip to content

feat: add GET /api/internal/reconciliation/diff/:streamId (#593)#805

Merged
greatest0fallt1me merged 3 commits into
Streampay-Org:mainfrom
Awointa:feature/recon-diff
Jun 29, 2026
Merged

feat: add GET /api/internal/reconciliation/diff/:streamId (#593)#805
greatest0fallt1me merged 3 commits into
Streampay-Org:mainfrom
Awointa:feature/recon-diff

Conversation

@Awointa

@Awointa Awointa commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

closes #593

Summary

Adds a focused read endpoint that returns a structured field-by-field diff
between the DB record and on-chain state for a single stream — without
triggering a full reconciliation run.

Changes

  • app/api/internal/reconciliation/diff/[id]/route.ts (new) — GET handler
  • app/api/internal/reconciliation/diff/[id]/route.test.ts (new) — 10 tests
  • CHANGELOG.md — [Unreleased] entry

Endpoint

GET /api/internal/reconciliation/diff/:streamId

Auth: HMAC-signed service-to-service headers (ops-automation or
reconciliation-worker). Route is concealed behind 404 on any auth failure.

200 response:

{
  "data": {
    "streamId": "stream_2",
    "checkedAt": "2026-06-29T08:38:45Z",
    "inSync": false,
    "diffs": [
      {
        "field": "released_amount",
        "dbValue": "1000000000",
        "onChainValue": "1100000000",
        "toleranceApplied": false
      }
    ],
    "db": { "id": "stream_2", "recipient_address": "", "status": "ACTIVE", 
},
    "onChain": { "id": "stream_2", "recipient_address": "", "status":
"ACTIVE", }
  },
  "meta": { "auth": { "keyId": "current", "timestamp": "" } }
}

404 — stream unknown to both DB and on-chain, or any auth failure.

Testing

10 tests covering:

- Auth guard: no headers, invalid signature, unknown key, disallowed service
- Happy path: in-sync stream, stream with diff, stream with no on-chain
record, checkedAt timestamp, service name reflection
- Error path: unknown stream ID

Tests: 10 passed, 10 total — 0 regressions against baseline (pre-existing: 40
suites / 138 tests)

Notes

- onChainClient.fetchStream throws SorobanError for missing streams; the

  route catches it and treats it as onChain: null rather than propagating.

- Follows the same auth/logging/error-envelope patterns as

  POST /api/internal/reconciliation.

Implements Streampay-Org#593. Returns a structured field-by-field diff between
DB and on-chain state for a single stream.

- GET /api/internal/reconciliation/diff/:id
- HMAC-signed internal service auth (concealed 404 on failure)
- Allowed services: ops-automation, reconciliation-worker
- Catches SorobanError from fetchStream (treat as no on-chain record)
- Structured JSON logging with correlation IDs
- 10 tests covering auth guard, happy paths, and error paths
- No regressions (pre-existing: 40 suites / 138 tests failing)
@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

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

@greatest0fallt1me greatest0fallt1me merged commit 2b0bf44 into Streampay-Org:main Jun 29, 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

Development

Successfully merging this pull request may close these issues.

Add /api/internal/reconciliation/diff/:streamId

2 participants