2023-07-04 21:21:34 +00:00
|
|
|
import {BaseAPI, IOptions} from 'app/common/BaseAPI';
|
2024-05-23 20:40:31 +00:00
|
|
|
import {BootProbeInfo, BootProbeResult} from 'app/common/BootProbe';
|
2023-07-04 21:21:34 +00:00
|
|
|
import {InstallPrefs} from 'app/common/Install';
|
|
|
|
import {TelemetryLevel} from 'app/common/Telemetry';
|
|
|
|
import {addCurrentOrgToPath} from 'app/common/urlUtils';
|
|
|
|
|
|
|
|
export const installPropertyKeys = ['prefs'];
|
|
|
|
|
|
|
|
export interface InstallProperties {
|
|
|
|
prefs: InstallPrefs;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface InstallPrefsWithSources {
|
|
|
|
telemetry: {
|
|
|
|
telemetryLevel: PrefWithSource<TelemetryLevel>;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export type TelemetryPrefsWithSources = InstallPrefsWithSources['telemetry'];
|
|
|
|
|
|
|
|
export interface PrefWithSource<T> {
|
|
|
|
value: T;
|
|
|
|
source: PrefSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type PrefSource = 'environment-variable' | 'preferences';
|
|
|
|
|
2024-04-29 14:54:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* JSON returned to the client (exported for tests).
|
|
|
|
*/
|
|
|
|
export interface LatestVersion {
|
|
|
|
/**
|
|
|
|
* Latest version of core component of the client.
|
|
|
|
*/
|
|
|
|
latestVersion: string;
|
|
|
|
/**
|
|
|
|
* If there were any critical updates after client's version. Undefined if
|
|
|
|
* we don't know client version or couldn't figure this out for some other reason.
|
|
|
|
*/
|
|
|
|
isCritical?: boolean;
|
|
|
|
/**
|
|
|
|
* Url where the client can download the latest version (if applicable)
|
|
|
|
*/
|
|
|
|
updateURL?: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When the latest version was updated (in ISO format).
|
|
|
|
*/
|
|
|
|
updatedAt?: string;
|
|
|
|
}
|
|
|
|
|
2023-07-04 21:21:34 +00:00
|
|
|
export interface InstallAPI {
|
|
|
|
getInstallPrefs(): Promise<InstallPrefsWithSources>;
|
|
|
|
updateInstallPrefs(prefs: Partial<InstallPrefs>): Promise<void>;
|
2024-04-29 14:54:03 +00:00
|
|
|
/**
|
|
|
|
* Returns information about latest version of Grist
|
|
|
|
*/
|
|
|
|
checkUpdates(): Promise<LatestVersion>;
|
2024-05-23 20:40:31 +00:00
|
|
|
getChecks(): Promise<{probes: BootProbeInfo[]}>;
|
|
|
|
runCheck(id: string): Promise<BootProbeResult>;
|
2023-07-04 21:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class InstallAPIImpl extends BaseAPI implements InstallAPI {
|
|
|
|
constructor(private _homeUrl: string, options: IOptions = {}) {
|
|
|
|
super(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async getInstallPrefs(): Promise<InstallPrefsWithSources> {
|
|
|
|
return this.requestJson(`${this._url}/api/install/prefs`, {method: 'GET'});
|
|
|
|
}
|
|
|
|
|
|
|
|
public async updateInstallPrefs(prefs: Partial<InstallPrefs>): Promise<void> {
|
|
|
|
await this.request(`${this._url}/api/install/prefs`, {
|
|
|
|
method: 'PATCH',
|
|
|
|
body: JSON.stringify({...prefs}),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-04-29 14:54:03 +00:00
|
|
|
public checkUpdates(): Promise<LatestVersion> {
|
|
|
|
return this.requestJson(`${this._url}/api/install/updates`, {method: 'GET'});
|
|
|
|
}
|
|
|
|
|
2024-05-23 20:40:31 +00:00
|
|
|
public getChecks(): Promise<{probes: BootProbeInfo[]}> {
|
|
|
|
return this.requestJson(`${this._url}/api/probes`, {method: 'GET'});
|
|
|
|
}
|
|
|
|
|
|
|
|
public runCheck(id: string): Promise<BootProbeResult> {
|
|
|
|
return this.requestJson(`${this._url}/api/probes/${id}`, {method: 'GET'});
|
|
|
|
}
|
|
|
|
|
2023-07-04 21:21:34 +00:00
|
|
|
private get _url(): string {
|
|
|
|
return addCurrentOrgToPath(this._homeUrl);
|
|
|
|
}
|
|
|
|
}
|