diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..b4d6e6e --- /dev/null +++ b/biome.json @@ -0,0 +1,14 @@ +{ + "files": { + "ignore": ["**/node_modules", "node_modules/"] + }, + "vcs": { + "enabled": true, + "clientKind": "git" + }, + "javascript": { + "formatter": { + "semicolons": "asNeeded" + } + } +} diff --git a/bun.lockb b/bun.lockb index 51f3761..838fc73 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/client.ts b/client.ts new file mode 100644 index 0000000..ab14649 --- /dev/null +++ b/client.ts @@ -0,0 +1,42 @@ +type Headers = { + "Content-Type": string + "X-Version": string + Authorization?: string +} + +async function createClient(config: { + baseUrl: string + token: string + version: string + method: string + publicKey: string +}): Promise { + const version = config.version ?? "1.0.1" + const method = config.method ?? "GET" + + const headers: Headers = { + "Content-Type": "application/json", + "X-Version": version, + } + + if (config.token !== undefined) { + headers.Authorization = `Bearer ${config.token}` + const response = await fetch(config.baseUrl, { method: method, headers }) + if (!response.ok) { + throw new Error(response.statusText) + } + return (await response.json()) as T + } + + const response = await fetch(`${config.baseUrl}/token`, { + method: "POST", + headers, + body: JSON.stringify({ + publicKey: config.publicKey, + }), + }) + if (!response.ok) { + throw new Error(response.statusText) + } + return (await response.json()) as T +} diff --git a/entities/account.d.ts b/entities/account.d.ts index d32c162..bc0fddd 100644 --- a/entities/account.d.ts +++ b/entities/account.d.ts @@ -1,6 +1,6 @@ export type Account = { - uuid: string - username?: string - publicKey: string - currency: string + uuid: string + username?: string + publicKey: string + currency: string } diff --git a/entities/compose.d.ts b/entities/compose.d.ts index be4af74..d3745b6 100644 --- a/entities/compose.d.ts +++ b/entities/compose.d.ts @@ -1,209 +1,220 @@ type Label = { - [label: string]: string + [label: string]: string } type WeightDevice = Array<{ - path: string - weight: number + path: string + weight: number }> type DeviceBLK = Array<{ - path: string - rate: number | string + path: string + rate: number | string }> type BuildServices = { - context: string - dockefile: string - dockerfile_inline: string - args: Label - ssh: Array - cache_from: Array - cache_to: Array - additional_contexts: Array