201 lines
4.9 KiB
TypeScript
201 lines
4.9 KiB
TypeScript
import axios from 'axios'
|
|
|
|
const api = axios.create({
|
|
baseURL: '/api/v1',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
})
|
|
|
|
// Types
|
|
export interface Server {
|
|
id: string
|
|
name: string
|
|
template: string
|
|
pillar: string
|
|
provider: string
|
|
ip_address: string
|
|
status: 'provisioning' | 'starting' | 'active' | 'draining' | 'stopping' | 'stopped' | 'error'
|
|
created_at: string
|
|
updated_at: string
|
|
}
|
|
|
|
export interface AdminUser {
|
|
id: string
|
|
email: string
|
|
created_at: string
|
|
}
|
|
|
|
export interface Bucket {
|
|
id: string
|
|
public: boolean
|
|
}
|
|
|
|
export interface StorageObject {
|
|
name: string
|
|
metadata?: {
|
|
size: number
|
|
mimetype: string
|
|
}
|
|
}
|
|
|
|
export interface DbTable {
|
|
schema: string
|
|
name: string
|
|
}
|
|
|
|
export interface EdgeFunction {
|
|
name: string
|
|
runtime: string
|
|
code?: string
|
|
}
|
|
|
|
export interface Template {
|
|
id: string
|
|
name: string
|
|
description: string
|
|
min_hetzner_plan: string
|
|
estimated_monthly_cost: number
|
|
services: Service[]
|
|
requirements: TemplateRequirements
|
|
}
|
|
|
|
export interface Service {
|
|
id: string
|
|
name: string
|
|
image: string
|
|
ports: string[]
|
|
}
|
|
|
|
export interface TemplateRequirements {
|
|
min_nodes: number
|
|
max_nodes: number
|
|
supports_ha: boolean
|
|
}
|
|
|
|
export interface Provider {
|
|
name: string
|
|
provider: string
|
|
supported: boolean
|
|
plans: Plan[]
|
|
regions: number
|
|
}
|
|
|
|
export interface Plan {
|
|
id: string
|
|
name: string
|
|
cpu_cores: number
|
|
memory_gb: number
|
|
disk_gb: number
|
|
monthly_cost: number
|
|
}
|
|
|
|
export interface ClusterHealth {
|
|
healthy: boolean
|
|
total_servers: number
|
|
active_servers: number
|
|
error_servers: number
|
|
services_up: number
|
|
services_down: number
|
|
}
|
|
|
|
export interface ScalingPlan {
|
|
scaling_plan: ScalingStep[]
|
|
total_cost_monthly: number
|
|
estimated_time_minutes: number
|
|
}
|
|
|
|
export interface ScalingStep {
|
|
provider: string
|
|
action: string
|
|
template: string
|
|
plan: string
|
|
count: number
|
|
cost_per_server: number
|
|
total_cost: number
|
|
}
|
|
|
|
export const apiService = {
|
|
// Servers
|
|
getServers: () => api.get<Server[]>('/servers'),
|
|
getServer: (id: string) => api.get<Server>(`/servers/${id}`),
|
|
addServer: (data: AddServerRequest) => api.post('/servers', data),
|
|
removeServer: (id: string) => api.delete(`/servers/${id}`),
|
|
fortifyServer: (id: string, data: FortifyRequest) => api.post(`/servers/${id}/fortify`, data),
|
|
|
|
// Templates
|
|
getTemplates: () => api.get<Template[]>('/templates'),
|
|
getTemplate: (id: string) => api.get<Template>(`/templates/${id}`),
|
|
|
|
// Providers
|
|
getProviders: () => api.get<Provider[]>('/providers'),
|
|
getPlans: (provider: string) => api.get<Plan[]>(`/providers/${provider}/plans`),
|
|
getRegions: (provider: string) => api.get<any[]>(`/providers/${provider}/regions`),
|
|
|
|
// Scaling
|
|
createScalingPlan: (data: ScalingPlanRequest) => api.post<ScalingPlan>('/cluster/scale-plan', data),
|
|
executeScalingPlan: (plan: ScalingStep[]) => api.post('/cluster/scale-execute', plan),
|
|
getClusterHealth: () => api.get<ClusterHealth>('/cluster/health'),
|
|
|
|
// Users
|
|
getUsers: () => api.get<AdminUser[]>('/users'),
|
|
deleteUser: (id: string) => api.delete(`/users/${id}`),
|
|
|
|
// Projects
|
|
getProjects: () => api.get<any[]>('/projects'),
|
|
createProject: (data: { name: string; owner_id?: string | null }) => api.post('/projects', data),
|
|
deleteProject: (id: string) => api.delete(`/projects/${id}`),
|
|
|
|
// Storage
|
|
getBuckets: () => api.get<Bucket[]>('/storage/buckets'),
|
|
getBucketObjects: (bucketId: string) => api.post<StorageObject[]>(`/storage/buckets/${bucketId}/objects`),
|
|
deleteObject: (bucketId: string, objectName: string) => api.delete(`/storage/${bucketId}/${objectName}`),
|
|
|
|
// Database
|
|
getTables: () => api.get<DbTable[]>('/db/tables'),
|
|
getTableData: (schema: string, name: string) => api.get<any[]>(`/db/tables/${schema}/${name}`),
|
|
|
|
// Functions
|
|
getFunctions: () => api.get<EdgeFunction[]>('/functions'),
|
|
getFunction: (name: string) => api.get<EdgeFunction>(`/functions/${name}`),
|
|
deployFunction: (data: { name: string; runtime: string; code_base64: string }) => api.post('/functions', data),
|
|
|
|
// Observability
|
|
getPillars: () => api.get<any[]>('/cluster/pillars'),
|
|
getLogs: (params: { query: string; limit: number }) => api.get('/logs', { params }),
|
|
|
|
// Auth/Session
|
|
login: (password: string) => api.post('/login', { password }),
|
|
logout: () => api.post('/logout'),
|
|
getAdminConfig: () => api.get('/admin/config'),
|
|
getCsrfToken: () => api.get<{ token: string }>('/csrf-token'),
|
|
}
|
|
|
|
export interface AddServerRequest {
|
|
name: string
|
|
template: string
|
|
provider: string
|
|
plan: string
|
|
region: string
|
|
features?: string[]
|
|
environment?: string
|
|
ssh_key_id?: string
|
|
tags?: Record<string, string>
|
|
}
|
|
|
|
export interface FortifyRequest {
|
|
enable_firewall?: boolean
|
|
enable_fail2ban?: boolean
|
|
harden_ssh?: boolean
|
|
enable_monitoring?: boolean
|
|
}
|
|
|
|
export interface ScalingPlanRequest {
|
|
provider: string
|
|
plan?: string
|
|
region?: string
|
|
target_worker_count?: number
|
|
target_db_count?: number
|
|
min_ha_nodes?: boolean
|
|
}
|