feat(api): import-boundary guard, path-encoding, cache-invalidation, pagination (#1332 #1333 #1335 #1336) - #1454
Open
misrasamuelisiguzor-oss wants to merge 5 commits into
Conversation
|
@misrasamuelisiguzor-oss 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
API Client: import boundary guard, path-encoding, cache-invalidation, pagination
Four
frontend/src/lib/api/issues. Three are "regression trap" issues whose fix alreadylanded in an earlier commit - the delta here is the guard test that keeps it from
regressing, plus one missed call site. #1336 is a new helper.
What changed and why
#1332 - public/admin client split guard
The split (
public-client.ts/admin-client.ts, commit895748e) and an exportboundary test (
public-client.test.ts) already exist. Added the missing import boundaryguard:
client-import-boundary.test.tsstatically scanssrc/app/**and fails if any routeoutside
src/app/admin/**(and the privilegedmarkets/<id>/resolveroute) importsadmin-clientdirectly. It also re-asserts thatpublic-client.tsnever importsadmin-clientand exposes no/api/v1/admin,/api/v1/audit, or/api/v1/emailpath.#1333 - centralize path-parameter encoding
fillPath()was the intended single encoder (commitdd027a9) but lived inpublic-client.tsand threesrc/lib/api/call sites still calledencodeURIComponentdirectly (
admin-client.tsemail preview,tts-client.tsjob status + audio).fillPath(plus a newfillPathParamsfor multi-segment templates) into adedicated
paths.ts;public-client.tsre-exports it so existing importers areunaffected.
fillPath.path-encoding.test.ts: (a) amarket_id/tx_hashcontaining/,?,#round-trips as a single encoded path segment (asserted against a mocked
fetch);(b)
fillPathencodes exactly once; (c) a grep guard - nosrc/lib/api/*.tsfileexcept
paths.tscallsencodeURIComponent.fetch()calls in app pages/components that never used the client -a broader refactor with its own issues.
#1335 - invalidate cache tags only on mutation success
The
succeededguard (a 200 body withsuccess: falsemust not bust the cache, commit4a15eda) already exists in both request helpers. Addedcache-invalidation-on-success.test.ts: a POST returning{ success: false }leaves thetagged entry untouched;
{ success: true }and non-envelope bodies invalidate as before.(The guard lives in the request helper, not
cache.ts, because that is where the responsebody is parsed.)
#1336 - offset/cursor pagination helper (new
pagination.ts)buildPaginationParams({ mode: 'offset' | 'cursor', limit?, offset?/cursor? })builds thequery params for either mode.
limitdefaults to 20 and throwsRangeErrorbefore therequest is sent when it exceeds 100, mirroring the server's documented 400 message.
CursorPagerholds the opaque cursor for cursor-mode paging;setSort(key)drops thestale cursor when the sort order actually changes, so the next page restarts from the top.
How to test
src/lib/apiJest suite: 135 pre-existing + 21 new tests pass.tsc --noEmit: the new/changed files add no errors over the repo's pre-existing count.npm run build(generate-client && next build) not run here - needs the full monorepobuild; nothing in this change touches build config.
Breaking changes
None.
fillPathkeeps itspublic-clientexport; the request/cache behaviour is unchanged.Related issues
Closes #1332
Closes #1333
Closes #1335
Closes #1336
PR Checklist
main