Initialize Aidoit v0.1 monorepo
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "@aidoit/sdk",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc --noEmit",
|
||||
"lint": "tsc --noEmit",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "echo \"No SDK tests yet\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@aidoit/contracts": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@aidoit/config": "workspace:*",
|
||||
"typescript": "^5.8.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import type { CreateProjectRequest, Project } from "@aidoit/contracts";
|
||||
|
||||
export class AidoitClient {
|
||||
public constructor(
|
||||
private readonly baseUrl: string,
|
||||
private readonly token?: string,
|
||||
) {}
|
||||
|
||||
private async request<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
const response = await fetch(`${this.baseUrl}${path}`, {
|
||||
...init,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...(this.token ? { Authorization: `Bearer ${this.token}` } : {}),
|
||||
...init?.headers,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Aidoit API request failed: ${response.status}`);
|
||||
}
|
||||
|
||||
return response.json() as Promise<T>;
|
||||
}
|
||||
|
||||
public listProjects(): Promise<Project[]> {
|
||||
return this.request<Project[]>("/api/v1/projects");
|
||||
}
|
||||
|
||||
public createProject(payload: CreateProjectRequest): Promise<Project> {
|
||||
return this.request<Project>("/api/v1/projects", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "@aidoit/config/base.json",
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in New Issue
Block a user