Skip to content

chore(examples): refresh complete integration example#159

Open
Jayking40 wants to merge 2 commits intoCalloraOrg:mainfrom
Jayking40:examples/complete-integration.ts
Open

chore(examples): refresh complete integration example#159
Jayking40 wants to merge 2 commits intoCalloraOrg:mainfrom
Jayking40:examples/complete-integration.ts

Conversation

@Jayking40
Copy link
Contributor

chore(examples): refresh complete-integration example

Summary

Rewrites examples/complete-integration.ts to reflect the billing, vault, and gateway subsystems currently supported by the backend. The previous example only demonstrated health checks and PostgreSQL-backed billing idempotency. The refreshed version exercises every in-memory service end-to-end — vault creation, funding, API gateway proxy with rate limiting and billing, usage event recording, and revenue settlement — all without requiring a database or Stellar node.

Changes

  • Rewrote the complete integration example to demonstrate a linear, 7-step walkthrough:
    1. Health check
    2. Vault creation (one per user per network)
    3. Vault funding (simulated on-chain deposit via balance snapshot update)
    4. API gateway proxy (API-key validation → rate-limit check → billing deduction → upstream forward → usage recording)
    5. Usage event inspection
    6. Revenue settlement batch (pays developers from accumulated usage fees)
    7. Final balance review
  • Removed PostgreSQL dependency from the example — all state is now in-memory, making it truly copy-paste friendly
  • Added contracts docs links in comments (https://github.com/CalloraOrg/callora-contracts)
  • Added 11 integration tests covering the full vault + billing + gateway + settlement lifecycle:
    • Health check returns ok
    • Vault create, fund, and balance query
    • Duplicate vault rejection (409)
    • Vault 404 when not found
    • Gateway proxies and deducts billing credit
    • Gateway rejects missing API key (401)
    • Gateway rejects insufficient balance (402)
    • Gateway rejects rate-limited requests (429)
    • Settlement pays developer when threshold is met
    • Settlement skips when below minimum payout
    • Full end-to-end lifecycle test
  • Updated examples README to document the refreshed endpoints and usage

Testing

PASS src/tests/complete-integration.test.ts Complete Integration — Vault + Billing + Gateway + Settlement ✓ health check returns ok (128 ms) ✓ creates a vault, funds it, and queries the balance (98 ms) ✓ rejects duplicate vault creation for same user and network (24 ms) ✓ returns 404 for vault balance when vault does not exist (14 ms) ✓ proxies a request through the gateway, deducts credit, and records usage (42 ms) ✓ returns 401 when API key is missing (18 ms) ✓ returns 402 when consumer has insufficient balance (16 ms) ✓ returns 429 when rate limited (10 ms) ✓ settles revenue after enough usage accumulates (106 ms) ✓ settlement skips when below minimum payout threshold (3 ms) ✓ end-to-end: vault → gateway → settlement lifecycle (99 ms)

Tests: 11 passed, 11 total

No existing tests were modified or broken. Pre-existing failures (Prisma generated client, pg-mem type mismatches, Node.js version incompatibility with ESLint 10) remain unchanged.

Security / data-integrity notes

  • The example uses in-memory stores only — no sensitive data is persisted
  • Input validation is applied on all endpoints (required fields, 400/404/409 responses)
  • BigInt is used for vault balance snapshots to avoid floating-point precision issues

Closes #157

@drips-wave
Copy link

drips-wave bot commented Mar 24, 2026

@Jayking40 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
Copy link
Contributor

resolve the conflicts

@Jayking40
Copy link
Contributor Author

Conflict resolved

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.

Examples: examples/complete-integration.ts end-to-end narrative

2 participants