feat: 接入小程序 API 客户端

This commit is contained in:
que01 committed 2026-09-19 09:50:16 +08:00
1 parent a6d30d1222
commit 868a4251ce
2 files changed
+16

No files matched your search

+1
View File
@@ -2,6 +2,7 @@
"name": "@personal-brand/miniapp",
"private": true,
"type": "module",
"dependencies": { "@personal-brand/api-client": "workspace:*" },
"scripts": {
"lint": "eslint . --ext .ts",
"typecheck": "tsc -p tsconfig.json --noEmit",
+15
View File
@@ -1 +1,16 @@
import { ApiClient, type CreateBookingInput, type FetchLike } from "@personal-brand/api-client";
export interface MiniappRequestAdapter {
request(options: { url: string; method: string; header: Record<string, string>; data?: string }): Promise<{ statusCode: number; data: unknown }>;
}
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 new ApiClient({ baseUrl, fetcher, ...(token ? { token } : {}) });
}
export async function submitBooking(client: ApiClient, input: CreateBookingInput): Promise<void> { await client.createCustomerBooking(input); }
export const miniappName = "personal-brand-miniapp";