UNPKG

@microsoft/windows-admin-center-sdk

Version:

Microsoft - Windows Admin Center Shell

389 lines (387 loc) 16.9 kB
import { from } from 'rxjs'; import { map } from 'rxjs/operators'; import { VersionedObject } from '../base/versioned-object'; import { RpcSettingsClient } from '../rpc/settings/rpc-settings-client'; import { RpcSettingsOperationType, RpcSettingsProviderType, RpcSettingsScope } from '../rpc/settings/rpc-settings-model'; /** * The Versioned representation of the Shell User Settings * This object is used for settings that specific to the current user and to shell */ export class CommonUserSettings extends VersionedObject { static propertyNames = { banners: 'banners' }; /** * Getter for the latest version of the common user settings */ get latestVersion() { return 1; } /** * Getter for the users preference on banner settings */ get banners() { return this.getProperty(CommonUserSettings.propertyNames.banners); } /** * Setter for the users preference on banner settings */ set banners(value) { this.setProperty(CommonUserSettings.propertyNames.banners, value); } constructor(objectWrapper, handlers) { super(objectWrapper, handlers); } /** * Attempts to upgrade the current version of the object at least one version toward the latest version. * if this.currentVersion is null or undefined, then the upgrade should initialize to the latest version * this is called iteratively until the current version is equal to the latest version */ upgrade() { // For now, we dont need to do anything but initialize to the latest version. // NOTE: When latestVersion is updated, then we need to add logic here to upgrade old user profile objects. // In this case, we ALWAYS must maintain backwards and forwards compatibility. This object is shared back and forth be if (MsftSme.isNullOrUndefined(this.currentVersion)) { this.clear(); this.banners = []; this.currentVersion = this.latestVersion; return; } else if (this.currentVersion < this.latestVersion) { this.currentVersion = this.latestVersion; } else { // current version is newer than the version we know about. TODO: there may need to be handling here in the future. } } } /** * Defines the common application settings object that is shared through the whole application. */ export class CommonApplicationSettings extends VersionedObject { static propertyNames = { // TODO: add properties when needed }; /** * Getter for the latest version of the common application settings */ get latestVersion() { return 1; } constructor(objectWrapper, handlers) { super(objectWrapper, handlers); } /** * Attempts to upgrade the current version of the object at least one version toward the latest version. * if this.currentVersion is null or undefined, then the upgrade should initialize to the latest version * this is called iteratively until the current version is equal to the latest version */ upgrade() { // For now, we dont need to do anything but initialize to the latest version. // NOTE: When latestVersion is updated, then we need to add logic here to upgrade old application settings objects. // In this case, we ALWAYS must maintain backwards and forwards compatibility. This object is shared back and forth be if (MsftSme.isNullOrUndefined(this.currentVersion)) { this.clear(); this.currentVersion = this.latestVersion; return; } else if (this.currentVersion < this.latestVersion) { this.currentVersion = this.latestVersion; } else { // current version is newer than the version we know about. TODO: there may need to be handling here in the future. } } } /** * Defines the common admin settings object that is shared through the whole application. */ export class CommonAdminSettings extends VersionedObject { static propertyNames = { connectivityLevel: 'connectivityLevel', autoGatewayUpdate: 'autoGatewayUpdate', autoExtensionsUpdate: 'autoExtensionsUpdate', scheduledUpdateTime: 'scheduledUpdateTime', updateRescheduled: 'updateRescheduled', sessionsExpirationMinutes: 'sessionsExpirationMinutes', credentialsExpirationTimeInMs: 'credentialsExpirationTimeInMs' }; /** * Getter for the latest version of the common admin settings */ get latestVersion() { return 1; } /** * Getter for the admin's preference on the connectivity level */ get connectivityLevel() { return this.getProperty(CommonAdminSettings.propertyNames.connectivityLevel); } /** * Setter for the admin's preference on the connectivity level */ set connectivityLevel(value) { this.setProperty(CommonAdminSettings.propertyNames.connectivityLevel, value); } get autoGatewayUpdate() { return this.getProperty(CommonAdminSettings.propertyNames.autoGatewayUpdate); } set autoGatewayUpdate(value) { this.setProperty(CommonAdminSettings.propertyNames.autoGatewayUpdate, value); } get autoExtensionsUpdate() { return this.getProperty(CommonAdminSettings.propertyNames.autoExtensionsUpdate); } set autoExtensionsUpdate(value) { this.setProperty(CommonAdminSettings.propertyNames.autoExtensionsUpdate, value); } get scheduledUpdateTime() { return this.getProperty(CommonAdminSettings.propertyNames.scheduledUpdateTime); } set scheduledUpdateTime(value) { this.setProperty(CommonAdminSettings.propertyNames.scheduledUpdateTime, value); } get updateRescheduled() { return this.getProperty(CommonAdminSettings.propertyNames.updateRescheduled); } sessionsExpirationMinutesCache; get sessionsExpirationMinutes() { if (MsftSme.isNullOrUndefined(this.sessionsExpirationMinutesCache)) { this.sessionsExpirationMinutesCache = this.getProperty(CommonAdminSettings.propertyNames.sessionsExpirationMinutes); } MsftSme.self().Init.sessionExpiration = this.sessionsExpirationMinutesCache; return this.sessionsExpirationMinutesCache; } set sessionsExpirationMinutes(value) { this.setProperty(CommonAdminSettings.propertyNames.sessionsExpirationMinutes, value); this.sessionsExpirationMinutesCache = undefined; MsftSme.self().Init.sessionExpiration = undefined; } credentialsExpirationTimeInMsCache; /** * Get stored manage as credentials expiration time in milliseconds */ get credentialsExpirationTimeInMs() { if (MsftSme.isNullOrUndefined(this.credentialsExpirationTimeInMsCache)) { this.credentialsExpirationTimeInMsCache = this.getProperty(CommonAdminSettings.propertyNames.credentialsExpirationTimeInMs); } return this.credentialsExpirationTimeInMsCache; } /** * Store manage as credentials expiration time in milliseconds */ set credentialsExpirationTimeInMs(value) { this.setProperty(CommonAdminSettings.propertyNames.credentialsExpirationTimeInMs, value); this.credentialsExpirationTimeInMsCache = undefined; } set updateRescheduled(value) { this.setProperty(CommonAdminSettings.propertyNames.updateRescheduled, value); } constructor(objectWrapper, handlers, gatewayService) { super(objectWrapper, handlers, gatewayService); } /** * Attempts to upgrade the current version of the object at least one version toward the latest version. * if this.currentVersion is null or undefined, then the upgrade should initialize to the latest version * this is called iteratively until the current version is equal to the latest version */ upgrade() { // For now, we dont need to do anything but initialize to the latest version. // NOTE: When latestVersion is updated, then we need to add logic here to upgrade old admin settings objects. // In this case, we ALWAYS must maintain backwards and forwards compatibility. This object is shared back and forth be if (MsftSme.isNullOrUndefined(this.currentVersion)) { this.clear(); this.currentVersion = this.latestVersion; this.connectivityLevel = ''; this.scheduledUpdateTime = null; this.updateRescheduled = false; this.autoExtensionsUpdate = true; this.autoGatewayUpdate = false; this.gatewayService.get('gateway/autoupdate').subscribe((result) => this.autoGatewayUpdate = result.autoUpdate); return; } else if (this.currentVersion < this.latestVersion) { this.currentVersion = this.latestVersion; } else { // current version is newer than the version we know about. TODO: there may need to be handling here in the future. } } } /** * Manager for the settings. Provides an api for managing user and application settings. */ export class SettingsManager { rpc; gatewayService; /** * Initializes a new instance of the SettingsManager class. * * @param rpc the RPC class instance. */ constructor(rpc, gatewayService) { this.rpc = rpc; this.gatewayService = gatewayService; } /** * Gets the http server header if any. */ get httpServerHeader() { return null; } /** * Get common user settings. This is currently read-only */ getCommonUserSettings() { return from(RpcSettingsClient.settings(this.rpc, { operation: RpcSettingsOperationType.Get, scope: RpcSettingsScope.User, provider: RpcSettingsProviderType.Common })) .pipe(map(response => { // If the extension settings are not versioned (or not defined), then start with an empty settings. const settings = VersionedObject.ensureIsVersionedObject(response.data); return new CommonUserSettings(settings, { save: (object) => { return from(RpcSettingsClient.settings(this.rpc, { operation: RpcSettingsOperationType.Set, scope: RpcSettingsScope.User, provider: RpcSettingsProviderType.Common, value: object })); } }); })); } /** * Get common application settings. This is currently read-only */ getCommonApplicationSettings() { return from(RpcSettingsClient.settings(this.rpc, { operation: RpcSettingsOperationType.Get, scope: RpcSettingsScope.Application, provider: RpcSettingsProviderType.Common })) .pipe(map(response => { // If the extension settings are not versioned (or not defined), then start with an empty settings. const settings = VersionedObject.ensureIsVersionedObject(response.data); return new CommonApplicationSettings(settings, { save: (object) => { return from(RpcSettingsClient.settings(this.rpc, { operation: RpcSettingsOperationType.Set, scope: RpcSettingsScope.Application, provider: RpcSettingsProviderType.Common, value: object })); } }); })); } /** * Get common admin settings. This is currently read-only */ getCommonAdminSettings() { return from(RpcSettingsClient.settings(this.rpc, { operation: RpcSettingsOperationType.Get, scope: RpcSettingsScope.Admin, provider: RpcSettingsProviderType.Common })) .pipe(map(response => { // If the extension settings are not versioned (or not defined), then start with an empty settings. const settings = VersionedObject.ensureIsVersionedObject(response.data); return new CommonAdminSettings(settings, { save: (object) => { return from(RpcSettingsClient.settings(this.rpc, { operation: RpcSettingsOperationType.Set, scope: RpcSettingsScope.Admin, provider: RpcSettingsProviderType.Common, value: object })); } }, this.gatewayService); })); } /** * Get extension user settings * Extension settings objects must be an object that extends VersionedObject or implements the VersionedObjectConstructor * example: if TestObject extends VersionedObject, then getExtensionUserSettings(TestObject) will return an Observable<TestObject> * you should only create 1 versioned object for your extensions user settings. */ getExtensionUserSettings(type) { return from(RpcSettingsClient.settings(this.rpc, { operation: RpcSettingsOperationType.Get, scope: RpcSettingsScope.User, provider: RpcSettingsProviderType.Extension })) .pipe(map(response => { // If the extension settings are not versioned (or not defined), then start with an empty settings. const settings = VersionedObject.ensureIsVersionedObject(response.data); return new type(settings, { save: (object) => { return from(RpcSettingsClient.settings(this.rpc, { operation: RpcSettingsOperationType.Set, scope: RpcSettingsScope.User, provider: RpcSettingsProviderType.Extension, value: object })); } }); })); } /** * Get extension application settings * Extension settings objects must be an object that extends VersionedObject or implements the VersionedObjectConstructor * example: if TestObject extends VersionedObject, then getExtensionApplicationSettings(TestObject) will return an * Observable<TestObject>. You should only create 1 versioned object for your extensions application settings. */ getExtensionApplicationSettings(type) { return from(RpcSettingsClient.settings(this.rpc, { operation: RpcSettingsOperationType.Get, scope: RpcSettingsScope.Application, provider: RpcSettingsProviderType.Extension })) .pipe(map(response => { // If the extension settings are not versioned (or not defined), then start with an empty settings. const settings = VersionedObject.ensureIsVersionedObject(response.data); return new type(settings, { save: (object) => { return from(RpcSettingsClient.settings(this.rpc, { operation: RpcSettingsOperationType.Set, scope: RpcSettingsScope.Application, provider: RpcSettingsProviderType.Extension, value: object })); } }); })); } /** * Get extension admin settings * Extension settings objects must be an object that extends VersionedObject or implements the VersionedObjectConstructor * example: if TestObject extends VersionedObject, then getExtensionAdminSettings(TestObject) will return an * Observable<TestObject>. You should only create 1 versioned object for your extensions admin settings. */ getExtensionAdminSettings(type) { return from(RpcSettingsClient.settings(this.rpc, { operation: RpcSettingsOperationType.Get, scope: RpcSettingsScope.Admin, provider: RpcSettingsProviderType.Extension })) .pipe(map(response => { // If the extension settings are not versioned (or not defined), then start with an empty settings. const settings = VersionedObject.ensureIsVersionedObject(response.data); return new type(settings, { save: (object) => { return from(RpcSettingsClient.settings(this.rpc, { operation: RpcSettingsOperationType.Set, scope: RpcSettingsScope.Admin, provider: RpcSettingsProviderType.Extension, value: object })); } }); })); } } //# sourceMappingURL=settings-manager.js.map