refactor: 集中管理共享状态常量

This commit is contained in:
que01 committed 2026-09-19 09:52:09 +08:00
1 parent 868a4251ce
commit 3b05df6edf
3 files changed
+21 -2

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@
"name": "@personal-brand/miniapp",
"private": true,
"type": "module",
"dependencies": { "@personal-brand/api-client": "workspace:*" },
"dependencies": { "@personal-brand/api-client": "workspace:*", "@personal-brand/types": "workspace:*" },
"scripts": {
"lint": "eslint . --ext .ts",
"typecheck": "tsc -p tsconfig.json --noEmit",
+2 -1
View File
@@ -1,4 +1,5 @@
import { ApiClient, type CreateBookingInput, type FetchLike } from "@personal-brand/api-client";
import { HTTP_STATUS } from "@personal-brand/types";
export interface MiniappRequestAdapter {
request(options: { url: string; method: string; header: Record<string, string>; data?: string }): Promise<{ statusCode: number; data: unknown }>;
@@ -7,7 +8,7 @@ export interface MiniappRequestAdapter {
export function createMiniappClient(baseUrl: string, adapter: MiniappRequestAdapter, token?: string): ApiClient {
const fetcher: FetchLike = async (url, init) => {
const response = await adapter.request({ url, method: init?.method ?? "GET", header: init?.headers ?? {}, ...(init?.body ? { data: init.body } : {}) });
return { status: response.statusCode, ok: response.statusCode >= 200 && response.statusCode < 300, json: () => Promise.resolve(response.data) };
return { status: response.statusCode, ok: response.statusCode >= HTTP_STATUS.OK && response.statusCode < HTTP_STATUS.BAD_REQUEST, json: () => Promise.resolve(response.data) };
};
return new ApiClient({ baseUrl, fetcher, ...(token ? { token } : {}) });
}