feat(frontend): add shared API client infrastructure - #117
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.
集成验证反馈:信封形状这条踩对了,另附一个争用点把 1.
|
Review feedback identified the pagination envelope as an integration hotspot for future entity APIs. Document that list data is an array and pagination fields remain at the envelope top level. Future API implementations now have an explicit parsing boundary without changing runtime behavior.
|
感谢集成验证,这两点都确认了。
|
功能说明
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:通过。范围边界
关联