110 lines
4.2 KiB
TypeScript
110 lines
4.2 KiB
TypeScript
import { apiRequest } from '../../lib/api';
|
|
import { filterAppsByCurrentAdmin } from '../../lib/admin-app-permissions';
|
|
import type { ApiApp, RuntimeEnvProfile, RuntimeEvent, RuntimePodMetric, RuntimeResourceResponse, RuntimeWorkloadLogResponse } from '../../types/runtime';
|
|
|
|
export function loadApps() {
|
|
return apiRequest<ApiApp[]>('/apps').then(filterAppsByCurrentAdmin);
|
|
}
|
|
|
|
export function loadRuntimeProfiles(appId?: string) {
|
|
const query = appId ? `?appId=${encodeURIComponent(appId)}` : '';
|
|
return apiRequest<RuntimeEnvProfile[]>(`/apps/runtime-profiles${query}`);
|
|
}
|
|
|
|
export function createRuntimeProfile(input: { appId: string; name: string; environment: string; namespace: string }) {
|
|
return apiRequest<{ profile: RuntimeEnvProfile }>('/apps/runtime-profiles', {
|
|
method: 'POST',
|
|
body: JSON.stringify(input)
|
|
});
|
|
}
|
|
|
|
export function deleteRuntimeProfile(profileId: string) {
|
|
return apiRequest<{ deleted: boolean; profileId: string; name: string }>(`/apps/runtime-profiles/${profileId}`, {
|
|
method: 'DELETE'
|
|
});
|
|
}
|
|
|
|
export function createRuntimeVariable(
|
|
profileId: string,
|
|
input: { componentId: string; key: string; value: string; isSecret: boolean }
|
|
) {
|
|
return apiRequest(`/apps/runtime-profiles/${profileId}/variables`, {
|
|
method: 'POST',
|
|
body: JSON.stringify(input)
|
|
});
|
|
}
|
|
|
|
export function createRuntimeIngressRule(
|
|
profileId: string,
|
|
input: { componentId: string; host: string; path?: string; servicePort: number; stripPrefix?: boolean; tlsEnabled?: boolean; tlsSecretName?: string }
|
|
) {
|
|
return apiRequest(`/apps/runtime-profiles/${profileId}/ingress-rules`, {
|
|
method: 'POST',
|
|
body: JSON.stringify(input)
|
|
});
|
|
}
|
|
|
|
export function deleteRuntimeIngressRule(profileId: string, ruleId: string) {
|
|
return apiRequest(`/apps/runtime-profiles/${profileId}/ingress-rules/${ruleId}`, {
|
|
method: 'DELETE'
|
|
});
|
|
}
|
|
|
|
export function deleteRuntimeVariable(profileId: string, variableId: string) {
|
|
return apiRequest(`/apps/runtime-profiles/${profileId}/variables/${variableId}`, {
|
|
method: 'DELETE'
|
|
});
|
|
}
|
|
|
|
export function applyRuntimeProfile(profileId: string) {
|
|
return apiRequest<{ profile: RuntimeEnvProfile; logs: string }>(`/apps/runtime-profiles/${profileId}/apply`, {
|
|
method: 'PATCH'
|
|
});
|
|
}
|
|
|
|
export function loadRuntimeResources(namespace: string) {
|
|
return apiRequest<RuntimeResourceResponse>(`/apps/runtime-namespaces/${encodeURIComponent(namespace)}/resources`);
|
|
}
|
|
|
|
export function loadRuntimeResourceYaml(namespace: string, kind: string, name: string) {
|
|
return apiRequest<{ namespace: string; kind: string; name: string; yaml: string }>(
|
|
`/apps/runtime-namespaces/${encodeURIComponent(namespace)}/resources/${encodeURIComponent(kind)}/${encodeURIComponent(name)}/yaml`
|
|
);
|
|
}
|
|
|
|
export function loadRuntimePodMetrics(namespace?: string) {
|
|
const query = namespace ? `?namespace=${encodeURIComponent(namespace)}` : '';
|
|
return apiRequest<RuntimePodMetric[]>(`/runtime/metrics/pods${query}`);
|
|
}
|
|
|
|
export function loadRuntimeEvents(namespace?: string) {
|
|
const query = namespace ? `?namespace=${encodeURIComponent(namespace)}` : '';
|
|
return apiRequest<RuntimeEvent[]>(`/runtime/events${query}`);
|
|
}
|
|
|
|
export function loadRuntimeWorkloadLogs(namespace: string, kind: string, name: string, tail = 100) {
|
|
return apiRequest<RuntimeWorkloadLogResponse>(
|
|
`/runtime/workloads/${encodeURIComponent(namespace)}/${encodeURIComponent(kind)}/${encodeURIComponent(name)}/logs?tail=${tail}`
|
|
);
|
|
}
|
|
|
|
export function ensureRuntimeNamespace(namespace: string) {
|
|
return apiRequest<{ namespace: string; created: boolean; logs: string }>('/apps/runtime-namespaces', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ namespace })
|
|
});
|
|
}
|
|
|
|
export function scaleRuntimeWorkload(namespace: string, kind: string, name: string, replicas: number) {
|
|
return apiRequest(`/runtime/workloads/${encodeURIComponent(namespace)}/${encodeURIComponent(kind)}/${encodeURIComponent(name)}/scale`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({ replicas })
|
|
});
|
|
}
|
|
|
|
export function restartRuntimeWorkload(namespace: string, kind: string, name: string) {
|
|
return apiRequest(`/runtime/workloads/${encodeURIComponent(namespace)}/${encodeURIComponent(kind)}/${encodeURIComponent(name)}/restart`, {
|
|
method: 'POST'
|
|
});
|
|
}
|