{"version":3,"sources":["../../../packages/core/shared/gateway-inventory/gateway-inventory-cache.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAA2B,gBAAgB,EAAE,oBAAoB,EAAE,sBAAsB,EAAuC,MAAM,qBAAqB,CAAC;AAEnK;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,WAAW,CAAC,gBAAgB,EAAE,oBAAoB,EAAE,sBAAsB,CAAC;IAWtG,OAAO,CAAC,UAAU;IAV9B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAsC;IAC7D,OAAO,CAAC,MAAM,CAAC,aAAa,CAAK;IACjC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAa;IAEvC;;;;;OAKG;gBACiB,UAAU,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,kBAAkB;IAWxE;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAgCjB;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAKtB;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAKvB;;;;OAIG;IACH,OAAO,CAAC,aAAa;CAIxB","file":"gateway-inventory-cache.d.ts","sourcesContent":["import { Observable } from 'rxjs';\r\nimport { map } from 'rxjs/operators';\r\nimport { AppContext } from '../../data/app-context';\r\nimport { SharedCache, SharedCacheOptions } from '../shared-cache';\r\nimport { GatewayInstallationType, GatewayInventory, GatewayInventoryData, GatewayInventoryParams, GatewayMode, GatewayOperationalMode } from './gateway-inventory';\r\n\r\n/**\r\n * Gateway Inventory cache class.\r\n */\r\nexport class GatewayInventoryCache extends SharedCache<GatewayInventory, GatewayInventoryData, GatewayInventoryParams> {\r\n    private static uniqueId = '@msft-sme/shell:gatewayInventory';\r\n    private static uniqueVersion = 6;\r\n    private static gatewayName = 'gateway';\r\n\r\n    /**\r\n     * Initializes a new instance of the GatewayInventoryCache class.\r\n     *\r\n     * @param appContext the app context.\r\n     * @param options the option of shared cache.\r\n     */\r\n    constructor(private appContext: AppContext, options?: SharedCacheOptions) {\r\n        super(\r\n            GatewayInventoryCache.uniqueId,\r\n            GatewayInventoryCache.uniqueVersion,\r\n            () => this.dataInstanceId(),\r\n            (instance) => this.dataSerialize(instance),\r\n            (serialized) => this.dataDeserialize(serialized),\r\n            () => this.dataQuery(),\r\n            options);\r\n    }\r\n\r\n    /**\r\n     * Defines how to collect the gateway inventory data.\r\n     *\r\n     * @return the Observable of ServerInventory data.\r\n     */\r\n    private dataQuery(): Observable<GatewayInventory> {\r\n        return this.appContext.gateway.get('gateway/status')\r\n            .pipe(map((data: any) => {\r\n                const inventory = new GatewayInventory();\r\n\r\n                if (data) {\r\n                    inventory.availableMemoryMByte = data.availableMemoryMByte;\r\n                    inventory.gatewayWorkingSetMByte = data.gatewayWorkingSetMByte;\r\n                    inventory.totalCpuUtilizationPercent = data.totalCpuUtilizationPercent;\r\n                    inventory.gatewayCpuUtilizationPercent = data.gatewayCpuUtilizationPercent;\r\n                    inventory.gatewayVersion = data.gatewayVersion;\r\n                    inventory.gatewayDisplayVersion = data.gatewayDisplayVersion;\r\n                    inventory.friendlyOsName = data.friendlyOsName;\r\n                    inventory.installedDate = data.installedDate;\r\n                    inventory.logicalProcessorCount = data.logicalProcessorCount;\r\n                    inventory.name = data.name.toLowerCase();\r\n                    inventory.isGatewayProcessElevated = data.isGatewayProcessElevated;\r\n                    inventory.mode = GatewayMode[<string>data.gatewayMode] || GatewayMode.Desktop;\r\n                    inventory.gatewayOperationalMode = GatewayOperationalMode[<string>data.gatewayOperationalMode]\r\n                            || GatewayOperationalMode.Production;\r\n                    inventory.jwk = JSON.stringify(data.jwk);\r\n                    inventory.installationType = data.installationType || GatewayInstallationType.Standard;\r\n                    inventory.allowedHostOrigins = data.allowedHostOrigins || [];\r\n                    if (MsftSme.isShell()) {\r\n                        inventory.allowedHostOrigins.push(MsftSme.getSafeOrigin());\r\n                    }\r\n                }\r\n\r\n                return inventory;\r\n            }));\r\n    }\r\n\r\n    /**\r\n     * Defines how to identify the cache entry by params.\r\n     *\r\n     * @return the id string.\r\n     */\r\n    private dataInstanceId(): string {\r\n        // dont use the passed in name. Gateway cache is always to the same name\r\n        return GatewayInventoryCache.gatewayName;\r\n    }\r\n\r\n    /**\r\n     * Defines how to deserialize the class object from seralized data.\r\n     *\r\n     * @param serialized the serialized string;\r\n     */\r\n    private dataDeserialize(serialized: string): GatewayInventory {\r\n        const inventory: GatewayInventoryData = JSON.parse(serialized);\r\n        return new GatewayInventory(inventory);\r\n    }\r\n\r\n    /**\r\n     * Defines how to serialize the class object to seralized data.\r\n     *\r\n     * @param instance the class instance.\r\n     */\r\n    private dataSerialize(instance: GatewayInventory): string {\r\n        // automatically stripped out class related data.\r\n        return JSON.stringify(instance);\r\n    }\r\n}\r\n"]}