feat: implement mock data support with API interceptor and update documentation

This commit is contained in:
2026-02-26 02:37:01 +00:00
parent 30501f5f4c
commit 20eaa50935
9 changed files with 410 additions and 5 deletions

View File

@@ -16,6 +16,7 @@ import { apiBaseOverride } from "./store"
import { incrementRequests, decrementRequests } from "./requestsStore"
import { setServerBuildTime } from "./serverBuildInfo"
import { checkBuildVersion } from "./versionCheck"
import { mockApiRequest } from "./mock"
// ---------------------------------------------------------------------------
// Request deduplication
@@ -84,6 +85,14 @@ export const api = async <T>(
}
incrementRequests()
// ── Mock interceptor (tree-shaken when __MOCK__ is false) ──
if (__MOCK__) {
const mockResult = mockApiRequest(endpoint, mergedOptions, body)
if (mockResult) return mockResult as ApiResult<T>
// No mock data for this endpoint → 404
throw { response: { status: 404 }, data: { error: `[mock] No mock data for "${endpoint}"` } }
}
const data = await apiRequest(_apiBaseOverride + endpoint, mergedOptions, body, sentry)
// Build-version check only on GETs (don't reload mid-write)