mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 00:33:44 +00:00
SM-90: Add Server Version to Browser About Page (#3223)
* Add structure to display server version on browser * Add getConfig to State Service interface * Clean up settings component code * Switch to ServerConfig, use Observables in the ConfigService, and more * Fix runtime error * Sm 90 addison (#3275) * Use await instead of then * Rename stateServerConfig -> storedServerConfig * Move config validation logic to the model * Use implied check for undefined * Rename getStateServicerServerConfig -> buildServerConfig * Rename getApiServiceServerConfig -> pollServerConfig * Build server config in async * small fixes and add last seen text * Move config server to /config folder * Update with concatMap and other changes * Config project updates * Rename fileds to convention and remove unneeded migration * Update libs/common/src/services/state.service.ts Update based on Oscar's recommendation Co-authored-by: Oscar Hinton <Hinton@users.noreply.github.com> * Update options for Oscar's rec * Rename abstractions to abstracitons * Fix null issues and add options * Combine classes into one file, per Oscar's rec * Add null checking * Fix dependency issue * Add null checks, await, and fix date issue * Remove unneeded null check * In progress commit, unsuitable for for more than dev env, just backing up changes made with Oscar * Fix temp code to force last seen state * Add localization and escapes in the browser about section * Call complete on destroy subject rather than unsubscribe * use mediumDate and formatDate for the last seen date messaging * Add ThirdPartyServerName in example * Add deprecated note per Oscar's comment * [SM-90] Change to using a modal for browser about (#3417) * Fix inconsistent constructor null checking * ServerConfig can be null, fixes this * Switch to call super first, as required * remove unneeded null checks * Remove null checks from server-config.data.ts class * Update via PR comments and add back needed null check in server conf obj * Remove type annotation from serverConfig$ * Update self-hosted to be <small> per design decision * Re-fetch config every hour * Make third party server version <small> and change wording per Oscar's PR comment * Add expiresSoon function and re-fetch if the serverConfig will expire soon (older than 18 hours) * Fix misaligned small third party server message text Co-authored-by: Addison Beck <addisonbeck1@gmail.com> Co-authored-by: Oscar Hinton <Hinton@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
import { ServerConfigResponse } from "@bitwarden/common/models/response/server-config-response";
|
||||
|
||||
export abstract class ConfigApiServiceAbstraction {
|
||||
get: () => Promise<ServerConfigResponse>;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { Observable } from "rxjs";
|
||||
|
||||
import { ServerConfig } from "./server-config";
|
||||
|
||||
export abstract class ConfigServiceAbstraction {
|
||||
serverConfig$: Observable<ServerConfig | null>;
|
||||
}
|
||||
40
libs/common/src/abstractions/config/server-config.ts
Normal file
40
libs/common/src/abstractions/config/server-config.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import {
|
||||
ServerConfigData,
|
||||
ThirdPartyServerConfigData,
|
||||
EnvironmentServerConfigData,
|
||||
} from "@bitwarden/common/models/data/server-config.data";
|
||||
|
||||
const dayInMilliseconds = 24 * 3600 * 1000;
|
||||
const eighteenHoursInMilliseconds = 18 * 3600 * 1000;
|
||||
|
||||
export class ServerConfig {
|
||||
version: string;
|
||||
gitHash: string;
|
||||
server?: ThirdPartyServerConfigData;
|
||||
environment?: EnvironmentServerConfigData;
|
||||
utcDate: Date;
|
||||
|
||||
constructor(serverConfigData: ServerConfigData) {
|
||||
this.version = serverConfigData.version;
|
||||
this.gitHash = serverConfigData.gitHash;
|
||||
this.server = serverConfigData.server;
|
||||
this.utcDate = new Date(serverConfigData.utcDate);
|
||||
this.environment = serverConfigData.environment;
|
||||
|
||||
if (this.server?.name == null && this.server?.url == null) {
|
||||
this.server = null;
|
||||
}
|
||||
}
|
||||
|
||||
private getAgeInMilliseconds(): number {
|
||||
return new Date().getTime() - this.utcDate?.getTime();
|
||||
}
|
||||
|
||||
isValid(): boolean {
|
||||
return this.getAgeInMilliseconds() <= dayInMilliseconds;
|
||||
}
|
||||
|
||||
expiresSoon(): boolean {
|
||||
return this.getAgeInMilliseconds() >= eighteenHoursInMilliseconds;
|
||||
}
|
||||
}
|
||||
@@ -33,4 +33,5 @@ export abstract class EnvironmentService {
|
||||
setUrlsFromStorage: () => Promise<void>;
|
||||
setUrls: (urls: Urls) => Promise<Urls>;
|
||||
getUrls: () => Urls;
|
||||
isCloud: () => boolean;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import { OrganizationData } from "../models/data/organizationData";
|
||||
import { PolicyData } from "../models/data/policyData";
|
||||
import { ProviderData } from "../models/data/providerData";
|
||||
import { SendData } from "../models/data/sendData";
|
||||
import { ServerConfigData } from "../models/data/server-config.data";
|
||||
import { Account, AccountSettingsSettings } from "../models/domain/account";
|
||||
import { EncString } from "../models/domain/encString";
|
||||
import { EnvironmentUrls } from "../models/domain/environmentUrls";
|
||||
@@ -319,4 +320,12 @@ export abstract class StateService<T extends Account = Account> {
|
||||
setStateVersion: (value: number) => Promise<void>;
|
||||
getWindow: () => Promise<WindowState>;
|
||||
setWindow: (value: WindowState) => Promise<void>;
|
||||
/**
|
||||
* @deprecated Do not call this directly, use ConfigService
|
||||
*/
|
||||
getServerConfig: (options?: StorageOptions) => Promise<ServerConfigData>;
|
||||
/**
|
||||
* @deprecated Do not call this directly, use ConfigService
|
||||
*/
|
||||
setServerConfig: (value: ServerConfigData, options?: StorageOptions) => Promise<void>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user