feat(frontend): add shared API client infrastructure - #117
Open
huyanxius wants to merge 10 commits into
Open
Conversation
Frontend entity APIs need a shared transport boundary aligned with backend response contracts. Add environment-based URL resolution, Bearer token injection, envelope decoding, pagination mapping, and normalized errors. Future entity implementations can reuse one business-agnostic client without page-level configuration.
The shared client needs executable evidence for the response and authentication rules declared by the backend. Cover success, business errors, pagination, request serialization, Bearer headers, invalid envelopes, HTTP failures, and network failures. Contract regressions now fail before entity API implementations depend on the transport layer.
The architecture docs need to distinguish the new transport layer from business-specific API implementations. Describe shared API ownership, environment configuration, token consumption, response handling, and explicit exclusions. Future entity work can reuse the client without expanding shared-layer responsibilities.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Non-2xx responses could be misclassified as business errors when their envelopes also used non-200 codes. Check the HTTP status before evaluating the backend business code. Transport failures now retain HTTP semantics while HTTP 200 business failures remain unchanged.
The transport classifier needs a regression case where both HTTP status and backend business code indicate failure. Add a response fixture with HTTP 503 and business code 500. The test prevents non-2xx responses from regressing to business-error classification.
Business API clients need a shared lazy token boundary. Register and restore token reader functions without storing token values. Project and character adapters can consume authentication supplied later.
The shared token boundary needs deterministic registration behavior. Cover latest-provider selection and restoration after unregistering. Future login integration can rely on the provider lifecycle.
Shared API documentation needs to describe the consumed authentication edge. Explain provider registration while keeping token ownership outside shared code. Later login work can integrate without redefining the transport layer.
The shared API boundary now exposes a provider registry for future login work. Document the lazy token registration path in the architecture and frontend guide. Business API modules can depend on one stable injection boundary without owning auth state.
Projects documentation must merge independently after the shared API pull request. Move transport guidance away from project status and workspace routing text. The two pull requests can update their own documentation without overlapping hunks.
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.
功能说明
XxxApis实现提供统一请求入口。实现方式
VITE_API_BASE_URL读取服务地址,并在请求发出时读取当前 Token。Response<T>、ListResponse<T>与四类 API 错误。registerApiAccessTokenProvider注册读取函数,公共层不保存、刷新或解析 Token。shared/api自身边界内,避免违反主线同层模块不互相依赖的规则。测试
npm run format:check:通过,46 个文件。npm run lint:通过。npm run typecheck:通过。npm run test:通过,4 个测试文件、17 项测试。npm run build:通过,89 个模块完成构建。git diff --check:通过。范围边界
关联