71 lines
No EOL
2.1 KiB
TypeScript
71 lines
No EOL
2.1 KiB
TypeScript
// Auto-generated by scripts/generate-bindings.mjs — do not edit.
|
|
|
|
export interface GapmindClientConfig { baseUrl: string; token?: string; }
|
|
|
|
export class GapmindClient {
|
|
private baseUrl: string;
|
|
private token?: string;
|
|
constructor(config: GapmindClientConfig) {
|
|
this.baseUrl = config.baseUrl.replace(/\/$/, '');
|
|
this.token = config.token;
|
|
}
|
|
private headers(): Record<string, string> {
|
|
const h: Record<string, string> = { 'Content-Type': 'application/json' };
|
|
if (this.token) h["Authorization"] = "Bearer " + this.token;
|
|
return h;
|
|
}
|
|
private async request<T>(method: string, path: string, body?: unknown): Promise<T> {
|
|
const res = await fetch(this.baseUrl + path, { method, headers: this.headers(), body: body ? JSON.stringify(body) : undefined });
|
|
if (!res.ok) throw new Error("API error " + res.status + ": " + (await res.text()));
|
|
return res.json() as Promise<T>;
|
|
}
|
|
|
|
async health(): Promise<unknown> {
|
|
return this.request("GET", `/health`);
|
|
}
|
|
|
|
async routes(): Promise<unknown> {
|
|
return this.request("GET", `/api/routes`);
|
|
}
|
|
|
|
async ips_get(path: string): Promise<unknown> {
|
|
return this.request("GET", `/ips/${path}`);
|
|
}
|
|
|
|
async ips_post(path: string): Promise<unknown> {
|
|
return this.request("POST", `/ips/${path}`);
|
|
}
|
|
|
|
async ips_put(path: string): Promise<unknown> {
|
|
return this.request("PUT", `/ips/${path}`);
|
|
}
|
|
|
|
async ips_delete(path: string): Promise<unknown> {
|
|
return this.request("DELETE", `/ips/${path}`);
|
|
}
|
|
|
|
async ips_patch(path: string): Promise<unknown> {
|
|
return this.request("PATCH", `/ips/${path}`);
|
|
}
|
|
|
|
async socials_get(path: string): Promise<unknown> {
|
|
return this.request("GET", `/socials/${path}`);
|
|
}
|
|
|
|
async socials_post(path: string): Promise<unknown> {
|
|
return this.request("POST", `/socials/${path}`);
|
|
}
|
|
|
|
async socials_put(path: string): Promise<unknown> {
|
|
return this.request("PUT", `/socials/${path}`);
|
|
}
|
|
|
|
async socials_delete(path: string): Promise<unknown> {
|
|
return this.request("DELETE", `/socials/${path}`);
|
|
}
|
|
|
|
async socials_patch(path: string): Promise<unknown> {
|
|
return this.request("PATCH", `/socials/${path}`);
|
|
}
|
|
|
|
} |