Skip to content

feat(frontend): add shared API client infrastructure - #117

Open
huyanxius wants to merge 10 commits into
1024XEngineer:mainfrom
huyanxius:feat/shared-api-client
Open

feat(frontend): add shared API client infrastructure#117
huyanxius wants to merge 10 commits into
1024XEngineer:mainfrom
huyanxius:feat/shared-api-client

Conversation

@huyanxius

@huyanxius huyanxius commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

功能说明

  • 增加不含业务语义的共享 HTTP 客户端,为后续各 XxxApis 实现提供统一请求入口。
  • 对齐后端公共响应、分页、业务码与 Bearer Token 契约。
  • 提供惰性的 Token Provider 注册边界,供后续登录模块注入读取函数。
  • 保持 Projects、entities、pages、Mock 和 UI 不变。

实现方式

  • VITE_API_BASE_URL 读取服务地址,并在请求发出时读取当前 Token。
  • 统一处理 JSON、查询参数、Response<T>ListResponse<T> 与四类 API 错误。
  • 通过 registerApiAccessTokenProvider 注册读取函数,公共层不保存、刷新或解析 Token。
  • 将 HTTP 列表结果留在 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:通过。

范围边界

  • 不包含 Project 或 Character 接口接入。
  • 不修改页面、路由、UI、Mock 或 livedemo。
  • 不负责登录、Token 保存、自动刷新或业务 DTO 映射。
  • 不增加运行时依赖。

关联

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.
@vercel

vercel Bot commented Aug 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
windup Ready Ready Preview Aug 4, 2026 8:03pm

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new client looks sound overall, but I found one concrete transport-classification bug.

Comment thread frontend/src/shared/api/index.ts Outdated
@huyanxius
huyanxius requested a review from xyh202131 August 4, 2026 18:42
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.
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.

feat: 增加前端通用 API 客户端基础设施

1 participant