Commit 20c7da8
authored
* [#1403] Frontend-react data layer: HTTP client + TanStack Query + OpenAPI codegen
HTTP wrapper at src/lib/http.ts handles bearer + CSRF, /api/v1/<resource>
to /api/v1/g/{slug}/<resource> rewriting, single-flight refresh on 401,
and surfaces non-2xx as HttpError so React Query can react via onError.
Storage keys (inventario_token, inventario_csrf_token, inventario_user)
match the legacy Vue frontend so a session survives the dual-bundle
INVENTARIO_FRONTEND switch (#1401).
QueryClient defaults: staleTime 30s, retry 1 (skipped for 4xx).
Providers wraps QueryClientProvider + ReactQueryDevtools (dev only) +
ThemeProvider; main.tsx uses it.
OpenAPI codegen converts go/docs/swagger.json (Swagger 2.0) to OAS3 via
swagger2openapi, then emits src/types/api.d.ts via openapi-typescript.
Exposed as npm run codegen / codegen:check, make codegen-frontend-react
/ codegen-frontend-react-check, and a new frontend-react-codegen
workflow that fails the build on drift.
Sample feature slice at features/session/ proves the layer end-to-end:
useCurrentUser query and an optimistic useLogout mutation with cache
rollback on error.
Tests: 40 (Vitest + MSW v2) covering each prefix rewrite, /auth/*
pass-through, slug encoding, CSRF only on mutations + rotation from
response headers, AbortSignal forwarding, 4xx/5xx HttpError, the full
refresh+retry path, refresh-failure clear+navigate, background
/auth/me 401 non-redirect, and single-flight refresh dedup.
.npmrc pins legacy-peer-deps=true because openapi-typescript@7 declares
peer typescript@^5.x while the scaffold is on TS 6 — the peer is
build-time only and emit goes through openapi-typescript's bundled
compiler, so the mismatch is benign. Drop the flag once
openapi-typescript ships TS 6 support.
Closes #1403.
* [#1403] Document legacy-peer-deps workaround with upstream PR link
The .npmrc workaround is metadata-only — npm ls confirms typescript@6.0.3
is the only version installed. Add a TODO link to openapi-ts/openapi-typescript#2774
so it's clear when the flag can come off.
* [#1403] Address CI failures + Copilot review
- Dockerfile: copy frontend-react/.npmrc into the React builder stage so
npm ci picks up legacy-peer-deps=true (Build linux/{amd64,arm64} fix).
- ApiResponse helper: try application/vnd.api+json first then fall back
to application/json, and accept any 2xx status. Most Inventario
endpoints serve JSON:API, so the previous 'application/json'-only
shape resolved to never for them.
- useLogout: removeQueries() instead of setQueryData(..., null) so the
cache stays type-true to the query's CurrentUser shape; consumers see
data === undefined rather than a surprise null at runtime.
- Drop the meCalls > 1 assertion in the optimistic-logout test — it
encoded an implementation detail (invalidate-after-remove timing) that
did not survive the removeQueries switch. New assertion pins the real
invariant: cache stays cleared after a successful logout.
- Prettier: re-format http.ts, http.test.ts, types/index.ts, generated
api.d.ts, and the session test (Lint Frontend (React) job fix).
* [#1403] Exclude generated api.d.ts from prettier
The previous commit's prettier sweep reformatted src/types/api.d.ts,
which then disagreed with what scripts/codegen.mjs produces — the
codegen-drift CI job rejected the result.
Add .prettierignore to keep the generator's emit untouched, and
restore api.d.ts to the codegen-true output.
1 parent 59ef8da commit 20c7da8
25 files changed
Lines changed: 8158 additions & 33 deletions
File tree
- .github/workflows
- frontend-react
- scripts
- src
- app
- features/session
- __tests__
- lib
- __tests__
- test
- types
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
240 | 251 | | |
241 | 252 | | |
242 | 253 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| |||
0 commit comments