feat: apply baseos target state
This commit is contained in:
@@ -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}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user