feat: add shared infiplot workspace packages

Signed-off-by: baizhi958216 <1475289190@qq.com>
This commit is contained in:
baizhi958216
2026-06-30 00:44:36 +08:00
parent caca4369aa
commit e585bb2eed
17 changed files with 240 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
{
"name": "@infiplot/api-client",
"version": "0.1.0",
"private": true,
"type": "module",
"exports": {
".": {
"types": "./src/index.ts",
"default": "./src/index.ts"
}
},
"scripts": {
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@infiplot/types": "workspace:*"
},
"devDependencies": {
"typescript": "^6.0.3"
}
}
+36
View File
@@ -0,0 +1,36 @@
import type { SceneRequest, SceneResponse } from "@infiplot/types";
export interface InfiplotApiClientOptions {
baseUrl: string;
fetcher?: typeof fetch;
}
export class InfiplotApiClient {
private readonly baseUrl: string;
private readonly fetcher: typeof fetch;
constructor(options: InfiplotApiClientOptions) {
this.baseUrl = options.baseUrl.replace(/\/$/, "");
this.fetcher = options.fetcher ?? fetch;
}
async createScene(request: SceneRequest): Promise<SceneResponse> {
return this.post<SceneResponse>("/api/scene", request);
}
private async post<TResponse>(path: string, body: unknown): Promise<TResponse> {
const response = await this.fetcher(`${this.baseUrl}${path}`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(body)
});
if (!response.ok) {
throw new Error(`Infiplot API request failed: ${response.status}`);
}
return response.json() as Promise<TResponse>;
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"lib": ["ES2022", "DOM"],
"noEmit": true
},
"include": ["src/**/*.ts"]
}