feat: apply baseos target state

This commit is contained in:
2026-05-07 20:33:14 +00:00
parent e49591c9c8
commit 27a5f6ffd8
6 changed files with 115 additions and 3 deletions
+25 -1
View File
@@ -39,6 +39,29 @@ export class SupervisorClient {
return await this.requestJson<IBalenaStateStatus>('/v2/state/status');
}
public async getLocalTargetState(): Promise<Record<string, unknown>> {
const response = await this.requestJson<{ state?: Record<string, unknown> }>(
'/v2/local/target-state',
{},
false,
);
return response.state || {};
}
public async setLocalTargetState(targetStateArg: Record<string, unknown>) {
await this.requestJson<{ status?: string; message?: string }>(
'/v2/local/target-state',
{
method: 'POST',
body: JSON.stringify(targetStateArg),
headers: {
'content-type': 'application/json',
},
},
false,
);
}
public async getSupervisorVersion(): Promise<string | undefined> {
const response = await this.requestJson<{ version?: string }>('/v2/version');
return response.version;
@@ -72,8 +95,9 @@ export class SupervisorClient {
private async requestJson<TResponse>(
pathArg: string,
initArg: RequestInit = {},
includeApiKeyArg = true,
): Promise<TResponse> {
const response = await fetch(this.buildUrl(pathArg, true), initArg);
const response = await fetch(this.buildUrl(pathArg, includeApiKeyArg), initArg);
if (!response.ok) {
throw new Error(`Supervisor request failed: ${pathArg} -> HTTP ${response.status}`);
}