Skip to content

fix: split API client into public and admin modules (#1158) - #1241

Open
euniceamoni wants to merge 5 commits into
solutions-plug:mainfrom
euniceamoni:fix/full-admin-internal-api-surface-ships-in-the-pub
Open

fix: split API client into public and admin modules (#1158)#1241
euniceamoni wants to merge 5 commits into
solutions-plug:mainfrom
euniceamoni:fix/full-admin-internal-api-surface-ships-in-the-pub

Conversation

@euniceamoni

@euniceamoni euniceamoni commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1158. client.ts was imported wholesale by Statistics.tsx and LandingPage.tsx, which prevented bundlers from tree-shaking unused code. As a result, every visitor's browser received:

  • Admin-only endpoints: resolveMarket, emailPreview, emailSendTest, getEmailAnalytics, getEmailQueueStats
  • The full Soroban contract error-code map: CONTRACT_ERROR_MESSAGES (~64 entries) and getContractErrorMessage

Changes

File Change
src/lib/api/public-client.ts New. Public endpoints only — no admin methods, no contract error map. Imported by landing-page components.
src/lib/api/admin-client.ts New. Re-exports public api, adds admin-only endpoints + CONTRACT_ERROR_MESSAGES. For admin/internal use only.
src/lib/api/client.ts Replaced with a thin re-export barrel from admin-client.ts. All existing imports continue to work unchanged.
src/components/Statistics.tsx Import changed from clientpublic-client
src/components/LandingPage.tsx Import changed from clientpublic-client
src/lib/api/__tests__/public-client.test.ts New. 17 tests asserting the module boundary is enforced.

Testing

Test Suites: 2 passed (client.test.ts, public-client.test.ts)
Tests:       78 passed, 78 total

cd frontend && npm run build — Compiled successfully, zero warnings.

Acceptance Criteria

  • Public landing-page bundle no longer includes admin-only API methods or the full contract error-code map
  • Admin functionality continues to work via admin-client.ts
  • Tests confirm admin endpoint code is absent from the public module
  • All existing tests continue to pass via the client.ts barrel

PR Checklist

PII (email address) was being sent as a URL query parameter on
GET /api/v1/newsletter/gdpr/export, exposing it to server access
logs, browser history, and proxy logs.

Changes:
- frontend: newsletterGdprExport now uses POST with body: { email }
  instead of GET with params: { email } (client.ts)
- backend: added NewsletterExportBody struct, changed handler extractor
  from Query to Json, updated utoipa path attribute to post,
  updated route registration from get() to post() (handlers.rs, main.rs)
- tests: updated it.each entry to expect POST; added new test in
  'GDPR export (solutions-plug#1156)' describe block asserting email is in the
  request body and absent from the URL

Fixes solutions-plug#1156
Update openapi.yaml /api/v1/newsletter/gdpr/export from GET with
query parameter to POST with requestBody (EmailRequest schema), matching
the handler change in handlers.rs.

Update SPEC_ROUTES in openapi_contract_test.rs from GET to POST to
keep the contract test in sync with the spec and runtime router.
…-plug#1157)

Wrap all path-segment interpolations with encodeURIComponent() to
prevent path corruption and request-smuggling when values contain
special characters (/, ?, #).

Affected endpoints: getBlockchainMarket, getUserBets, getOracleResult,
getTransactionStatus, resolveMarket, emailPreview.

Add URI encoding test block (7 tests) covering all 6 endpoints and
asserting that slash-containing values produce correctly encoded paths.
)

The full admin API surface (resolveMarket, emailPreview, emailSendTest,
getEmailAnalytics, getEmailQueueStats) and the entire Soroban contract
error-code map (CONTRACT_ERROR_MESSAGES, ~64 entries) were bundled into
the public landing-page build because client.ts was imported wholesale
by Statistics.tsx and LandingPage.tsx.

Changes:
- public-client.ts: new module containing only public-facing endpoints
  (health, getStatistics, getFeaturedMarkets, getContent, blockchain
  read-only, newsletter self-service). No admin methods, no contract
  error map.
- admin-client.ts: new module that re-exports the public api and adds
  admin-only endpoints + CONTRACT_ERROR_MESSAGES/getContractErrorMessage.
- client.ts: replaced with a thin re-export barrel from admin-client.ts
  so all existing imports continue to work without changes.
- Statistics.tsx, LandingPage.tsx: updated to import from public-client.ts
  so the landing-page bundle no longer pulls in admin code.
- public-client.test.ts: 17 new tests asserting admin symbols are absent
  from the public module and present on the admin module.

All 78 tests pass. next build succeeds with zero warnings.
@drips-wave

drips-wave Bot commented Jul 27, 2026

Copy link
Copy Markdown

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

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.

[Bug] Full admin/internal API surface ships in the public landing-page client bundle

1 participant