{"version":3,"file":"npm.skype.15592f426a019f4fb90f.js","mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;ACrCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;ACrCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;ACnFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACnDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;ACjFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;ACbA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;AC7QA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;ACpIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;ACvDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;ACpBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;AChFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sources":["webpack://approvals/./node_modules/@skype/ecsclient/dist/AllowBackgroundFetchData.js","webpack://approvals/./node_modules/@skype/ecsclient/dist/AppActiveData.js","webpack://approvals/./node_modules/@skype/ecsclient/dist/Cache.js","webpack://approvals/./node_modules/@skype/ecsclient/dist/Config.js","webpack://approvals/./node_modules/@skype/ecsclient/dist/EcsClient.js","webpack://approvals/./node_modules/@skype/ecsclient/dist/Models.js","webpack://approvals/./node_modules/@skype/ecsclient/dist/RestClient.js","webpack://approvals/./node_modules/@skype/ecsclient/dist/Scheduler.js","webpack://approvals/./node_modules/@skype/ecsclient/dist/SkypeTokenData.js","webpack://approvals/./node_modules/@skype/ecsclient/dist/TelemetryEventBase.js","webpack://approvals/./node_modules/@skype/ecsclient/dist/TelemetryEvents.js","webpack://approvals/./node_modules/@skype/ecsclient/dist/TelemetryManager.js"],"sourcesContent":["\"use strict\";\r\n/**\r\n* AllowBackgroundFetchData.ts\r\n* Author: CALIB http://aka.ms/CALIB\r\n* Copyright: Microsoft 2017\r\n*\r\n* Holder for information if background fetch is allowed\r\n*/\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nvar SyncTasks = require(\"synctasks\");\r\nvar AllowBackgroundFetchData = /** @class */ (function () {\r\n function AllowBackgroundFetchData() {\r\n this._isAllowed = false;\r\n }\r\n AllowBackgroundFetchData.prototype.putBackgroundFetchAllowed = function (isAllowed) {\r\n this._isAllowed = isAllowed;\r\n if (this.isBackgroundFetchAllowed() && this._isAllowedDeferral) {\r\n var deferral = this._isAllowedDeferral;\r\n this._isAllowedDeferral = undefined;\r\n deferral.resolve(void 0);\r\n }\r\n };\r\n AllowBackgroundFetchData.prototype.isBackgroundFetchAllowed = function () {\r\n return this._isAllowed;\r\n };\r\n AllowBackgroundFetchData.prototype.waitForBackgroundFetchAllowed = function () {\r\n if (this.isBackgroundFetchAllowed()) {\r\n return SyncTasks.Resolved();\r\n }\r\n // Set up deferral to wait until background fetch is allowed\r\n if (!this._isAllowedDeferral) {\r\n this._isAllowedDeferral = SyncTasks.Defer();\r\n }\r\n return this._isAllowedDeferral.promise();\r\n };\r\n return AllowBackgroundFetchData;\r\n}());\r\nexports.default = AllowBackgroundFetchData;\r\n","\"use strict\";\r\n/**\r\n* AppActiveData.ts\r\n* Author: CALIB http://aka.ms/CALIB\r\n* Copyright: Microsoft 2017\r\n*\r\n* Holder for App Active (foreground/background) information\r\n*/\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nvar SyncTasks = require(\"synctasks\");\r\nvar AppActiveData = /** @class */ (function () {\r\n function AppActiveData() {\r\n this._isActive = false;\r\n }\r\n AppActiveData.prototype.putAppActive = function (isActive) {\r\n this._isActive = isActive;\r\n if (this.isAppActive() && this._appActiveDeferral) {\r\n var deferral = this._appActiveDeferral;\r\n this._appActiveDeferral = undefined;\r\n deferral.resolve(void 0);\r\n }\r\n };\r\n AppActiveData.prototype.isAppActive = function () {\r\n return this._isActive;\r\n };\r\n AppActiveData.prototype.waitForAppActive = function () {\r\n if (this.isAppActive()) {\r\n return SyncTasks.Resolved();\r\n }\r\n // Set up deferral to wait for app to become active\r\n if (!this._appActiveDeferral) {\r\n this._appActiveDeferral = SyncTasks.Defer();\r\n }\r\n return this._appActiveDeferral.promise();\r\n };\r\n return AppActiveData;\r\n}());\r\nexports.default = AppActiveData;\r\n","\"use strict\";\r\n/**\r\n* Cache.ts\r\n* Author: CALIB http://aka.ms/CALIB\r\n* Copyright: Microsoft 2017\r\n*\r\n* ECS data cache\r\n*/\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nvar subscribableevent_1 = require(\"subscribableevent\");\r\nvar SyncTasks = require(\"synctasks\");\r\nvar Models_1 = require(\"./Models\");\r\nvar Cache = /** @class */ (function () {\r\n function Cache(_config) {\r\n this._config = _config;\r\n this.configUpdated = new subscribableevent_1.default();\r\n this._cachedConfigs = {};\r\n // noop\r\n }\r\n Cache.prototype.initialize = function () {\r\n return this.updateConfigsToFetch();\r\n };\r\n Cache.prototype.updateConfigsToFetch = function () {\r\n var _this = this;\r\n var _a = this._config.getConfig(), databaseInterface = _a.databaseInterface, configsToFetch = _a.configsToFetch;\r\n // If we don't have DB support, we can't pre-populate any cache\r\n if (!databaseInterface) {\r\n return SyncTasks.Resolved();\r\n }\r\n var dbFetchPromises = [];\r\n var _loop_1 = function (configType) {\r\n // If we've already retrieved from the cache, don't fetch again\r\n if (this_1._cachedConfigs[configType]) {\r\n return \"continue\";\r\n }\r\n dbFetchPromises.push(databaseInterface.getData(configType).then(function (ecsConfig) {\r\n if (ecsConfig) {\r\n _this._cachedConfigs[configType] = ecsConfig;\r\n }\r\n }).catch(function () {\r\n // Return resolved no matter what happens\r\n return SyncTasks.Resolved();\r\n }));\r\n };\r\n var this_1 = this;\r\n for (var _i = 0, configsToFetch_1 = configsToFetch; _i < configsToFetch_1.length; _i++) {\r\n var configType = configsToFetch_1[_i];\r\n _loop_1(configType);\r\n }\r\n return SyncTasks.all(dbFetchPromises).then(function () {\r\n // If we fetched 1 or more configs, trigger a change\r\n if (dbFetchPromises.length > 0) {\r\n _this.configUpdated.fire();\r\n }\r\n });\r\n };\r\n Cache.prototype.getEcsConfig = function () {\r\n // Try user, then fallback to default\r\n return (this._cachedConfigs[Models_1.EcsConfigType.User] || this._cachedConfigs[Models_1.EcsConfigType.Default]);\r\n };\r\n Cache.prototype.getEcsConfigByType = function (configType) {\r\n return this._cachedConfigs[configType];\r\n };\r\n Cache.prototype.putConfig = function (ecsConfig) {\r\n // Store the config that we used before putting\r\n var oldEcsConfig = this.getEcsConfig();\r\n // Store new config\r\n this._cachedConfigs[ecsConfig.configType] = ecsConfig;\r\n var currentEcsConfig = this.getEcsConfig();\r\n // Only notify if the config of the same type changed or we've changed config types\r\n if (currentEcsConfig && currentEcsConfig.configType === ecsConfig.configType ||\r\n (oldEcsConfig && currentEcsConfig && oldEcsConfig.configType !== currentEcsConfig.configType)) {\r\n this.configUpdated.fire();\r\n }\r\n var databaseInterface = this._config.getConfig().databaseInterface;\r\n // If we don't have DB support, we can't pre-populate any cache\r\n if (!databaseInterface) {\r\n return SyncTasks.Resolved();\r\n }\r\n return databaseInterface.putData(ecsConfig.configType, ecsConfig);\r\n };\r\n return Cache;\r\n}());\r\nexports.default = Cache;\r\n","\"use strict\";\r\n/**\r\n* Config.ts\r\n* Author: CALIB http://aka.ms/CALIB\r\n* Copyright: Microsoft 2017\r\n*\r\n* ECS global configuration\r\n*/\r\nvar __assign = (this && this.__assign) || function () {\r\n __assign = Object.assign || function(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\r\n t[p] = s[p];\r\n }\r\n return t;\r\n };\r\n return __assign.apply(this, arguments);\r\n};\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nvar Config = /** @class */ (function () {\r\n function Config() {\r\n }\r\n Config.prototype.initialize = function (config) {\r\n if (this._config) {\r\n throw 'ECS Configuration already initialized';\r\n }\r\n this._config = config;\r\n };\r\n Config.prototype.getConfig = function () {\r\n if (!this._config) {\r\n throw 'ECS Configuration not yet initialized';\r\n }\r\n return this._config;\r\n };\r\n Config.prototype.setConfigsToFetch = function (configsToFetch) {\r\n // Create a new config object since it's fully read-only\r\n if (!this._config) {\r\n throw 'ECS Configuration not yet initialized';\r\n }\r\n this._config = __assign({}, this._config, { configsToFetch: configsToFetch });\r\n };\r\n Config.prototype.setFetchTimeout = function (fetchTimeout) {\r\n // Create a new config object since it's fully read-only\r\n if (!this._config) {\r\n throw 'ECS Configuration not yet initialized';\r\n }\r\n this._config = __assign({}, this._config, { fetchTimeout: fetchTimeout });\r\n };\r\n return Config;\r\n}());\r\nexports.default = Config;\r\n","\"use strict\";\r\n/**\r\n*\r\n* Author: CALIB http://aka.ms/CALIB\r\n* Copyright: Microsoft 2017\r\n*\r\n* ECS Module\r\n*/\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nvar AllowBackgroundFetchData_1 = require(\"./AllowBackgroundFetchData\");\r\nvar AppActiveData_1 = require(\"./AppActiveData\");\r\nvar Cache_1 = require(\"./Cache\");\r\nvar Config_1 = require(\"./Config\");\r\nvar Models = require(\"./Models\");\r\nexports.Models = Models;\r\nvar Scheduler_1 = require(\"./Scheduler\");\r\nvar SkypeTokenData_1 = require(\"./SkypeTokenData\");\r\nvar TelemetryManager_1 = require(\"./TelemetryManager\");\r\nvar EcsClient = /** @class */ (function () {\r\n function EcsClient() {\r\n this._allowBackgroundFetchData = new AllowBackgroundFetchData_1.default();\r\n this._appActiveData = new AppActiveData_1.default();\r\n this._config = new Config_1.default();\r\n this._cache = new Cache_1.default(this._config);\r\n this._skypeTokenData = new SkypeTokenData_1.default();\r\n this._telemetryManager = new TelemetryManager_1.default(this._cache);\r\n this._scheduler = new Scheduler_1.default(this._config, this._skypeTokenData, this._cache, this._appActiveData, this._allowBackgroundFetchData, this._telemetryManager);\r\n // Typescript 3.X has started inlining type requires for inferred type-only imports if the import isn't used elsewhere in the file\r\n // Older versions of typescript do not support this so specify it here for backwards definition file compatibility\r\n this.telemetryEventAdded = this._telemetryManager.telemetryEventAdded;\r\n this.configUpdated = this._cache.configUpdated;\r\n }\r\n EcsClient.prototype.initialize = function (config) {\r\n var _this = this;\r\n this._config.initialize(config);\r\n this._skypeTokenData.putSkypeTokenData(config.initialSkypeTokenData);\r\n this._appActiveData.putAppActive(config.initialAppActiveState);\r\n return this._cache.initialize().then(function () {\r\n _this._scheduler.initialize();\r\n });\r\n };\r\n EcsClient.prototype.getConfig = function () {\r\n return this._cache.getEcsConfig();\r\n };\r\n EcsClient.prototype.getConfigType = function () {\r\n var cacheConfig = this._cache.getEcsConfig();\r\n if (!cacheConfig) {\r\n return undefined;\r\n }\r\n return cacheConfig.configType;\r\n };\r\n EcsClient.prototype.requestUpdate = function () {\r\n this._scheduler.requestUpdate();\r\n };\r\n EcsClient.prototype.pause = function () {\r\n this._scheduler.pause();\r\n };\r\n EcsClient.prototype.resume = function () {\r\n this._scheduler.resume();\r\n };\r\n EcsClient.prototype.setAllowBackgroundFetch = function (allowBackgroundFetch) {\r\n this._allowBackgroundFetchData.putBackgroundFetchAllowed(allowBackgroundFetch);\r\n };\r\n EcsClient.prototype.useSkypeToken = function (skypeToken, skypeTokenExpiration) {\r\n this._skypeTokenData.putSkypeTokenData({ skypeToken: skypeToken, skypeTokenExpiration: skypeTokenExpiration });\r\n };\r\n EcsClient.prototype.setAppActive = function (active) {\r\n this._appActiveData.putAppActive(active);\r\n };\r\n EcsClient.prototype.setConfigsToFetch = function (types) {\r\n var _this = this;\r\n this._config.setConfigsToFetch(types);\r\n return this._cache.updateConfigsToFetch().then(function () {\r\n _this._scheduler.updateConfigsToFetch();\r\n });\r\n };\r\n EcsClient.prototype.setFetchTimeout = function (fetchTimeout) {\r\n this._config.setFetchTimeout(fetchTimeout);\r\n };\r\n return EcsClient;\r\n}());\r\nexports.default = EcsClient;\r\n","\"use strict\";\r\n/**\r\n* Models.ts\r\n* Author: CALIB http://aka.ms/CALIB\r\n* Copyright: Microsoft 2017\r\n*\r\n* ECS models\r\n*/\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nvar EcsConfigType;\r\n(function (EcsConfigType) {\r\n EcsConfigType[EcsConfigType[\"Default\"] = 0] = \"Default\";\r\n EcsConfigType[EcsConfigType[\"User\"] = 1] = \"User\";\r\n})(EcsConfigType = exports.EcsConfigType || (exports.EcsConfigType = {}));\r\n","\"use strict\";\r\n/**\r\n* RestClient.ts\r\n* Author: CALIB http://aka.ms/CALIB\r\n* Copyright: Microsoft 2017\r\n*\r\n* Client helper for accessing ECS.\r\n*/\r\nvar __extends = (this && this.__extends) || (function () {\r\n var extendStatics = function (d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n };\r\n return function (d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n };\r\n})();\r\nvar __assign = (this && this.__assign) || function () {\r\n __assign = Object.assign || function(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\r\n t[p] = s[p];\r\n }\r\n return t;\r\n };\r\n return __assign.apply(this, arguments);\r\n};\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nvar simplerestclients_1 = require(\"simplerestclients\");\r\nvar SyncTasks = require(\"synctasks\");\r\nvar Models_1 = require(\"./Models\");\r\nvar TelemetryEvents = require(\"./TelemetryEvents\");\r\nvar ForceFetchTimeout = (48 * 60 * 60 * 1000); // Fetch every 48 hours at a minimum\r\nvar EcsExpirationFallbackDuration = 30 * 60 * 1000; // 30 minutes\r\nvar EcsFetchDurationLimit = (365 * 24 * 60 * 60 * 1000); // fetch duration beyond 1 year is considered invalid\r\nvar EcsMinFetchTimeout = (30 * 1000); // Fail-safe lower bound for the fetchTimeout config parameter\r\nvar lastResponseTime;\r\nvar currentRequestTime;\r\n// Fetches the ECS configuration from a specific ECS endpoint and project\r\nvar EcsFetcher = /** @class */ (function (_super) {\r\n __extends(EcsFetcher, _super);\r\n function EcsFetcher(url, _config, _skypeTokenData, _appActiveData, _allowBackgroundFetchData, _etag, _getUserConfig, parameters) {\r\n var _this = _super.call(this, url) || this;\r\n _this._config = _config;\r\n _this._skypeTokenData = _skypeTokenData;\r\n _this._appActiveData = _appActiveData;\r\n _this._allowBackgroundFetchData = _allowBackgroundFetchData;\r\n _this._etag = _etag;\r\n _this._getUserConfig = _getUserConfig;\r\n var config = _this._config.getConfig();\r\n _this._apiPath = config.clientTeam\r\n ? \"/config/v1/\" + config.clientName + \"/\" + config.clientVersion + \"/\" + config.clientTeam\r\n : \"/config/v1/\" + config.clientName + \"/\" + config.clientVersion;\r\n if (parameters) {\r\n var paramList = Object.keys(parameters).map(function (key) {\r\n return encodeURIComponent(key) + '=' + encodeURIComponent(parameters[key].toString());\r\n });\r\n if (paramList) {\r\n _this._apiPath += '?' + paramList.join('&');\r\n }\r\n }\r\n return _this;\r\n }\r\n EcsFetcher.prototype._blockRequestUntil = function (options) {\r\n var _this = this;\r\n if (this._getUserConfig && !this._skypeTokenData.isSkypeTokenValid()) {\r\n console.log('ECS - Delaying User config fetch until we have a valid SkypeToken');\r\n }\r\n if (!this._appActiveData.isAppActive() && !this._allowBackgroundFetchData.isBackgroundFetchAllowed()) {\r\n var configType = this._getUserConfig ? 'User config' : 'config';\r\n console.log(\"ECS - Delaying \" + configType + \" fetch until the app is active (or background fetch is allowed)\");\r\n }\r\n return SyncTasks.race([\r\n this._appActiveData.waitForAppActive(),\r\n this._allowBackgroundFetchData.waitForBackgroundFetchAllowed()\r\n ]).then(function () {\r\n if (_this._getUserConfig) {\r\n return _this._skypeTokenData.waitForValidSkypeToken();\r\n }\r\n }).then(function () {\r\n currentRequestTime = Date.now();\r\n });\r\n };\r\n EcsFetcher.prototype._getHeaders = function () {\r\n var headers = {};\r\n if (this._etag) {\r\n headers['If-None-Match'] = this._etag;\r\n }\r\n if (this._getUserConfig) {\r\n headers['Authorization'] = this._skypeTokenData.getSkypeToken();\r\n }\r\n return headers;\r\n };\r\n EcsFetcher.prototype.getConfig = function () {\r\n // Make sure the timeout is undefined, 0, or at least EcsMinFetchTimeout\r\n var timeout = this._config.getConfig().fetchTimeout;\r\n if (timeout !== undefined) {\r\n if (timeout < 0) {\r\n timeout = 0;\r\n }\r\n else if (timeout > 0 && timeout < EcsMinFetchTimeout) {\r\n timeout = EcsMinFetchTimeout;\r\n }\r\n }\r\n return _super.prototype.performApiGetDetailed.call(this, this._apiPath, { timeout: timeout });\r\n };\r\n return EcsFetcher;\r\n}(simplerestclients_1.GenericRestClient));\r\n// Main ECS client. Supports alternate ECS backend URLs and configuration fetch retries.\r\nvar EcsClient = /** @class */ (function () {\r\n function EcsClient(_config, _skypeTokenData, _appActiveData, _allowBackgroundFetchData, _telemetryManager) {\r\n this._config = _config;\r\n this._skypeTokenData = _skypeTokenData;\r\n this._appActiveData = _appActiveData;\r\n this._allowBackgroundFetchData = _allowBackgroundFetchData;\r\n this._telemetryManager = _telemetryManager;\r\n this._ecsFailureBackoffTimer = new simplerestclients_1.ExponentialTime(1000, 300000);\r\n this._cacheMaxAgeRegex = /.*max-age=(\\d+).*/ig;\r\n this._serverIndex = NaN;\r\n }\r\n EcsClient.prototype.getConfig = function (oldConfig, userConfig, parameters) {\r\n var _this = this;\r\n var urls = this._config.getConfig().hosts;\r\n // Randomly select the ECS server url to issue the first request against and store the index\r\n if (isNaN(this._serverIndex) || this._serverIndex > urls.length - 1) {\r\n this._serverIndex = Math.floor(Math.random() * urls.length);\r\n }\r\n if (!urls || !urls.length) {\r\n return SyncTasks.Rejected(new Error('no configuration service endpoint'));\r\n }\r\n var deferred = SyncTasks.Defer();\r\n var fetchAttempts = 0;\r\n // Keep trying to fetch config (w/ Exponential Backoff) until it's fetched succesfully\r\n var callConfigServer = function () {\r\n var etag = oldConfig && oldConfig.eTag ? oldConfig.eTag : undefined;\r\n var fetcher = new EcsFetcher(urls[_this._serverIndex], _this._config, _this._skypeTokenData, _this._appActiveData, _this._allowBackgroundFetchData, etag, userConfig, parameters);\r\n fetchAttempts++;\r\n fetcher.getConfig().then(function (res) {\r\n var eTagHeader = res.headers['etag'];\r\n var expirationHeader = res.headers['expires'];\r\n if (res.body && res.body.Headers) {\r\n // If the service headers are missing, try to get them from the response body\r\n if (!eTagHeader) {\r\n eTagHeader = res.body.Headers.ETag;\r\n }\r\n if (!expirationHeader) {\r\n expirationHeader = res.body.Headers.Expires;\r\n }\r\n }\r\n var responseTimeInfo = _this._calculateResponseTimeInfo(oldConfig);\r\n // As per ECS guidance, if ETag or expiration are missing, treat as a failure.\r\n if (!eTagHeader || !expirationHeader) {\r\n console.warn('ECS - Service returned an empty ETag or Expiration header: ' +\r\n JSON.stringify(res));\r\n return SyncTasks.Rejected({\r\n timedOut: false,\r\n responseParsingException: new Error('ECS Service returned empty ETag or Expiration header'),\r\n responseCode: res.statusCode\r\n });\r\n }\r\n // Override to deal with client clock skew.\r\n var updatedExpiration = new Date(_this._calculateExpirationDate(res.headers)).getTime();\r\n var ecsData;\r\n if (res.statusCode === 304 && oldConfig) {\r\n // Etag matched, so no change. Use old config values and continue as normal.\r\n // Use a shallow clone since we don't need to make a full clone of the config data.\r\n ecsData = __assign({}, oldConfig);\r\n ecsData.configType = userConfig ? Models_1.EcsConfigType.User : Models_1.EcsConfigType.Default;\r\n ecsData.eTag = eTagHeader;\r\n ecsData.expiration = updatedExpiration;\r\n ecsData.cacheUpdateTime = responseTimeInfo.lastResponseTime;\r\n ecsData.lastFetchTokenHash = _this._skypeTokenData.getSkypeTokenHash(res.requestHeaders['Authorization']);\r\n }\r\n else {\r\n if (typeof res.body !== 'object') {\r\n console.warn('ECS - Service returned invalid response ' + JSON.stringify(res));\r\n return SyncTasks.Rejected({\r\n timedOut: false,\r\n responseParsingException: new Error('ECS Service returned invalid response body'),\r\n responseCode: res.statusCode\r\n });\r\n }\r\n // Take from response\r\n ecsData = {\r\n config: res.body,\r\n configType: userConfig ? Models_1.EcsConfigType.User : Models_1.EcsConfigType.Default,\r\n eTag: eTagHeader,\r\n expiration: updatedExpiration,\r\n cacheUpdateTime: currentRequestTime,\r\n lastFetchTokenHash: _this._skypeTokenData.getSkypeTokenHash(res.requestHeaders['Authorization']),\r\n appVersion: _this._config.getConfig().clientVersion\r\n };\r\n }\r\n _this._telemetryManager.sendTelemetryEvent(new TelemetryEvents.EcsConfigFetchResponse(responseTimeInfo.fetchDelayMs, res.statusCode, fetchAttempts, _this._skypeTokenData.isSkypeTokenValid(), urls[_this._serverIndex], responseTimeInfo.fetchDurationValid, !!etag, JSON.stringify(res).length, responseTimeInfo.cacheAge, !(oldConfig && oldConfig.expiration - Date.now() > 0), currentRequestTime, responseTimeInfo.lastResponseTime, userConfig, eTagHeader));\r\n _this._ecsFailureBackoffTimer.reset();\r\n deferred.resolve(ecsData);\r\n }).catch(function (e) {\r\n var errorInfo = {\r\n timedOut: (e && e.timedOut) || false,\r\n responseParseError: (e && e.responseParsingException),\r\n responseCode: (e && e.statusCode) || 0,\r\n message: _this._getErrorMessage(e)\r\n };\r\n console.error(\"ECS - Service request failed to return a response (timedOut: \" + errorInfo.timedOut + \", responseParseError: \" + errorInfo.responseParseError + \")\");\r\n // send telemetry event with info about the failure\r\n var responseTimeInfo = _this._calculateResponseTimeInfo(oldConfig);\r\n _this._telemetryManager.sendTelemetryEvent(new TelemetryEvents.EcsConfigFetchResponse(responseTimeInfo.fetchDelayMs, errorInfo.responseCode, fetchAttempts, _this._skypeTokenData.isSkypeTokenValid(), urls[_this._serverIndex], responseTimeInfo.fetchDurationValid, !!etag, 0, responseTimeInfo.cacheAge, !(oldConfig && oldConfig.expiration - Date.now() > 0), currentRequestTime, responseTimeInfo.lastResponseTime, userConfig, undefined, errorInfo.timedOut, errorInfo.responseParseError, errorInfo.message));\r\n // Backoff and Switch ECS servers if possible.\r\n setTimeout(function () {\r\n callConfigServer();\r\n }, _this._ecsFailureBackoffTimer.getTimeAndCalculateNext());\r\n });\r\n };\r\n callConfigServer();\r\n return deferred.promise();\r\n };\r\n EcsClient.prototype._calculateExpirationDate = function (headers) {\r\n var forceFetchTime = Date.now() + ForceFetchTimeout;\r\n if (headers['date'] && headers['expires']) {\r\n // Calculate client clock skew\r\n var responseDate = new Date(headers['date']).getTime();\r\n var clockSkew = Date.now() - responseDate;\r\n // Ensure we don't do Math.min(forceFetchTime, NaN) => NaN\r\n var headerExpirationTime = new Date(headers['expires']).getTime();\r\n if (isNaN(headerExpirationTime)) {\r\n return forceFetchTime;\r\n }\r\n return Math.min(forceFetchTime, headerExpirationTime + clockSkew);\r\n }\r\n // This is a fix for browsers that don't implement Access-Control-Expose-Headers header properly\r\n // and Date header is not propagated (IE, Edge). We take the value from the cache-control\r\n // header (seconds) and add it to the client's current time.\r\n var match = this._cacheMaxAgeRegex.exec(headers['cache-control']);\r\n this._cacheMaxAgeRegex.lastIndex = 0;\r\n if (match && match.length === 2) {\r\n return Math.min(forceFetchTime, Date.now() + (Number(match[1]) * 1000));\r\n }\r\n // Backup - send next request in 30 minutes.\r\n return Date.now() + EcsExpirationFallbackDuration;\r\n };\r\n EcsClient.prototype._calculateResponseTimeInfo = function (oldConfig) {\r\n lastResponseTime = Date.now();\r\n var fetchDelayMs = lastResponseTime - currentRequestTime;\r\n return {\r\n lastResponseTime: lastResponseTime,\r\n fetchDelayMs: fetchDelayMs,\r\n fetchDurationValid: !(fetchDelayMs < 0 || fetchDelayMs > EcsFetchDurationLimit),\r\n cacheAge: oldConfig ? (lastResponseTime - oldConfig.cacheUpdateTime) : 0\r\n };\r\n };\r\n EcsClient.prototype._getErrorMessage = function (err) {\r\n if (!err) {\r\n return undefined;\r\n }\r\n if (typeof err === 'string') {\r\n return err;\r\n }\r\n if (typeof err === 'object' && (err.statusText || err.message)) {\r\n return err.statusText || err.message;\r\n }\r\n return undefined;\r\n };\r\n return EcsClient;\r\n}());\r\nexports.default = EcsClient;\r\n","\"use strict\";\r\n/**\r\n* Scheduler.ts\r\n* Author: CALIB http://aka.ms/CALIB\r\n* Copyright: Microsoft 2017\r\n*\r\n* Scheduling module for fetching ECS config\r\n*/\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nvar Models_1 = require(\"./Models\");\r\nvar RestClient_1 = require(\"./RestClient\");\r\nvar Scheduler = /** @class */ (function () {\r\n function Scheduler(_config, _skypeTokenData, _cache, appActiveData, allowBackgroundFetchData, telemetryManager) {\r\n var _this = this;\r\n this._config = _config;\r\n this._skypeTokenData = _skypeTokenData;\r\n this._cache = _cache;\r\n this._isFetchingSettings = {};\r\n this._pendingFetch = {};\r\n this._paused = false;\r\n this._fetchEcsSettingsIfNeeded = function (configType) {\r\n var config = _this._config.getConfig();\r\n var cachedConfig = _this._cache.getEcsConfigByType(configType);\r\n // If we don't care about this config, abort\r\n if (config.configsToFetch.indexOf(configType) === -1) {\r\n return;\r\n }\r\n // Don't refresh if we're already fetching.\r\n if (_this._isFetchingSettings[configType]) {\r\n return;\r\n }\r\n if (!cachedConfig && _this._pendingFetch[configType]) {\r\n _this._fetchSkypeEcsSettings(configType);\r\n return;\r\n }\r\n // Get time until expiration, negative if we have no config.\r\n var configExpirationMs = cachedConfig ? cachedConfig.expiration - Date.now() : -1;\r\n // If config expired, fetch now.\r\n if (configExpirationMs <= 0) {\r\n _this._fetchSkypeEcsSettings(configType);\r\n return;\r\n }\r\n // If SkypeToken used to fetch has changed, fetchNow\r\n if (cachedConfig && configType === Models_1.EcsConfigType.User && _this._skypeTokenData.isSkypeTokenValid() &&\r\n cachedConfig.lastFetchTokenHash !== _this._skypeTokenData.getSkypeTokenHash(_this._skypeTokenData.getSkypeToken())) {\r\n _this._fetchSkypeEcsSettings(configType);\r\n return;\r\n }\r\n // Schedule another check.\r\n setTimeout(function () { return _this._fetchEcsSettingsIfNeeded(configType); }, configExpirationMs);\r\n };\r\n this._fetchSkypeEcsSettings = function (configType, bypassPause) {\r\n if (bypassPause === void 0) { bypassPause = false; }\r\n if (_this._isFetchingSettings[configType] || (_this._paused && !bypassPause)) {\r\n _this._pendingFetch[configType] = true;\r\n return;\r\n }\r\n _this._pendingFetch[configType] = false;\r\n _this._isFetchingSettings[configType] = true;\r\n var config = _this._config.getConfig();\r\n // will never fail. We'll keep trying to fetch with exponential backoff until the end of time.\r\n config.getEcsParameters()\r\n .catch(function () {\r\n // If we fail to get parameters, continue with none\r\n console.warn('ECS - Failed to fetch ECS fetching parameters');\r\n return {};\r\n })\r\n .then(function (parameters) {\r\n return _this._ecsClient\r\n .getConfig(_this._cache.getEcsConfig(), configType === Models_1.EcsConfigType.User, parameters);\r\n })\r\n .then(function (ecsConfig) {\r\n console.log('ECS - Config fetch complete');\r\n _this._isFetchingSettings[configType] = false;\r\n _this._cache.putConfig(ecsConfig);\r\n // Queue a refresh\r\n _this._fetchEcsSettingsIfNeeded(configType);\r\n });\r\n };\r\n this._ecsClient = new RestClient_1.default(this._config, this._skypeTokenData, appActiveData, allowBackgroundFetchData, telemetryManager);\r\n }\r\n Scheduler.prototype.initialize = function () {\r\n var _this = this;\r\n this.updateConfigsToFetch();\r\n // Re-fetch user settings when skype token changes\r\n this._skypeTokenData.skypeTokenChanged.subscribe(function () { return _this._fetchEcsSettingsIfNeeded(Models_1.EcsConfigType.User); });\r\n };\r\n Scheduler.prototype.updateConfigsToFetch = function () {\r\n var config = this._config.getConfig();\r\n for (var _i = 0, _a = config.configsToFetch; _i < _a.length; _i++) {\r\n var configType = _a[_i];\r\n if (!(configType in this._isFetchingSettings)) {\r\n this._isFetchingSettings[configType] = false;\r\n }\r\n if (!(configType in this._isFetchingSettings)) {\r\n this._pendingFetch[configType] = false;\r\n }\r\n }\r\n // If we haven't downloaded a config yet (which should happen only on\r\n // first run), download it immediately so we have the settings by the time\r\n // the UI loads, and we can enable or disable specific UI features.\r\n for (var _b = 0, _c = config.configsToFetch; _b < _c.length; _b++) {\r\n var configType = _c[_b];\r\n var cachedData = this._cache.getEcsConfigByType(configType);\r\n if (!cachedData || (cachedData.appVersion && cachedData.appVersion !== config.clientVersion)) {\r\n this._fetchSkypeEcsSettings(configType, true);\r\n }\r\n else {\r\n this._fetchEcsSettingsIfNeeded(configType);\r\n }\r\n }\r\n };\r\n Scheduler.prototype.requestUpdate = function () {\r\n var config = this._config.getConfig();\r\n for (var _i = 0, _a = config.configsToFetch; _i < _a.length; _i++) {\r\n var configType = _a[_i];\r\n this._fetchSkypeEcsSettings(configType);\r\n }\r\n };\r\n Scheduler.prototype.pause = function () {\r\n this._paused = true;\r\n };\r\n Scheduler.prototype.resume = function () {\r\n this._paused = false;\r\n var config = this._config.getConfig();\r\n for (var _i = 0, _a = config.configsToFetch; _i < _a.length; _i++) {\r\n var configType = _a[_i];\r\n this._fetchEcsSettingsIfNeeded(configType);\r\n }\r\n };\r\n return Scheduler;\r\n}());\r\nexports.default = Scheduler;\r\n","\"use strict\";\r\n/**\r\n* SkypeTokenData.ts\r\n* Author: CALIB http://aka.ms/CALIB\r\n* Copyright: Microsoft 2017\r\n*\r\n* Holder for SkypeToken information\r\n*/\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nvar subscribableevent_1 = require(\"subscribableevent\");\r\nvar SyncTasks = require(\"synctasks\");\r\nvar SkypeTokenData = /** @class */ (function () {\r\n function SkypeTokenData() {\r\n this.skypeTokenChanged = new subscribableevent_1.default();\r\n }\r\n SkypeTokenData.prototype.putSkypeTokenData = function (initialData) {\r\n this._data = initialData;\r\n if (this.isSkypeTokenValid()) {\r\n this.skypeTokenChanged.fire();\r\n }\r\n if (this.isSkypeTokenValid() && this._validSkypeTokenDeferral) {\r\n var deferral = this._validSkypeTokenDeferral;\r\n this._validSkypeTokenDeferral = undefined;\r\n deferral.resolve(void 0);\r\n }\r\n };\r\n SkypeTokenData.prototype.isSkypeTokenValid = function () {\r\n var tokenData = this._data;\r\n return !!tokenData && !!tokenData.skypeToken && tokenData.skypeTokenExpiration > Date.now();\r\n };\r\n SkypeTokenData.prototype.getSkypeToken = function () {\r\n var tokenData = this._data;\r\n if (!tokenData || !tokenData.skypeToken) {\r\n throw 'No Skype Token provided';\r\n }\r\n return tokenData.skypeToken;\r\n };\r\n SkypeTokenData.prototype.getSkypeTokenHash = function (token) {\r\n if (token === undefined) {\r\n return 0;\r\n }\r\n return token.split('').reduce(function (mem, next) { return (mem * 101 + next.charCodeAt(0)) % 999727999; }, token.length);\r\n };\r\n SkypeTokenData.prototype.waitForValidSkypeToken = function () {\r\n if (this.isSkypeTokenValid()) {\r\n return SyncTasks.Resolved();\r\n }\r\n // Need to wait for a new one to be poked in\r\n if (!this._validSkypeTokenDeferral) {\r\n this._validSkypeTokenDeferral = SyncTasks.Defer();\r\n }\r\n return this._validSkypeTokenDeferral.promise();\r\n };\r\n return SkypeTokenData;\r\n}());\r\nexports.default = SkypeTokenData;\r\n","\"use strict\";\r\n/**\r\n* TelemetryEventBase.ts\r\n* Author: CALIB http://aka.ms/CALIB\r\n* Copyright: Microsoft 2017\r\n*\r\n* Holds ECS client telemetry event base\r\n*/\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nvar TelemetryEventBase = /** @class */ (function () {\r\n function TelemetryEventBase() {\r\n }\r\n TelemetryEventBase.prototype.getAttributes = function () {\r\n var attributes = {\r\n 'Source': 'ecs_client'\r\n };\r\n return attributes;\r\n };\r\n return TelemetryEventBase;\r\n}());\r\nexports.TelemetryEventBase = TelemetryEventBase;\r\n","\"use strict\";\r\n/**\r\n* TelemetryEvents.ts\r\n* Author: CALIB http://aka.ms/CALIB\r\n* Copyright: Microsoft 2017\r\n*\r\n* All the ECS client telemetry events\r\n*/\r\nvar __extends = (this && this.__extends) || (function () {\r\n var extendStatics = function (d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n };\r\n return function (d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n };\r\n})();\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nvar TelemetryEventBase_1 = require(\"./TelemetryEventBase\");\r\nvar EcsConfigFetchResponse = /** @class */ (function (_super) {\r\n __extends(EcsConfigFetchResponse, _super);\r\n function EcsConfigFetchResponse(_responseTime, _responseCode, _fetchAttempts, _hasValidToken, _serverEndpoint, _fetchDurationValid, _cacheAvailable, _responseSize, _configAge, _configExpired, _fetchStart, _fetchEnd, _isUserConfig, _etag, _timedOut, _responseParsingException, _errorMessage) {\r\n var _this = _super.call(this) || this;\r\n _this._responseTime = _responseTime;\r\n _this._responseCode = _responseCode;\r\n _this._fetchAttempts = _fetchAttempts;\r\n _this._hasValidToken = _hasValidToken;\r\n _this._serverEndpoint = _serverEndpoint;\r\n _this._fetchDurationValid = _fetchDurationValid;\r\n _this._cacheAvailable = _cacheAvailable;\r\n _this._responseSize = _responseSize;\r\n _this._configAge = _configAge;\r\n _this._configExpired = _configExpired;\r\n _this._fetchStart = _fetchStart;\r\n _this._fetchEnd = _fetchEnd;\r\n _this._isUserConfig = _isUserConfig;\r\n _this._etag = _etag;\r\n _this._timedOut = _timedOut;\r\n _this._responseParsingException = _responseParsingException;\r\n _this._errorMessage = _errorMessage;\r\n return _this;\r\n }\r\n EcsConfigFetchResponse.prototype.getEventName = function () {\r\n return 'ecs_tsclient_fetch_config';\r\n };\r\n EcsConfigFetchResponse.prototype.getAttributes = function () {\r\n var attributes = _super.prototype.getAttributes.call(this);\r\n attributes['fetch_delay_ms'] = this._responseTime;\r\n attributes['fetch_response_code'] = this._responseCode;\r\n attributes['fetch_attempts'] = this._fetchAttempts;\r\n attributes['authenticated_user'] = this._hasValidToken;\r\n attributes['url'] = this._serverEndpoint;\r\n attributes['fetch_duration_valid'] = this._fetchDurationValid;\r\n attributes['cache_available'] = this._cacheAvailable;\r\n attributes['response_size'] = this._responseSize;\r\n attributes['config_age'] = this._configAge;\r\n attributes['config_expired'] = this._configExpired;\r\n attributes['fetch_start'] = this._fetchStart;\r\n attributes['fetch_end'] = this._fetchEnd;\r\n attributes['is_user_config'] = this._isUserConfig;\r\n if (this._etag) {\r\n attributes['fetched_etag'] = this._etag;\r\n }\r\n if (this._timedOut !== undefined) {\r\n attributes['fetch_timed_out'] = this._timedOut;\r\n }\r\n if (this._responseParsingException) {\r\n attributes['fetch_response_parsing_error'] = this._responseParsingException.message;\r\n }\r\n if (this._errorMessage) {\r\n attributes['fetch_error_message'] = this._errorMessage;\r\n }\r\n return attributes;\r\n };\r\n return EcsConfigFetchResponse;\r\n}(TelemetryEventBase_1.TelemetryEventBase));\r\nexports.EcsConfigFetchResponse = EcsConfigFetchResponse;\r\n","\"use strict\";\r\n/**\r\n* TelemetryManager.ts\r\n* Author: CALIB http://aka.ms/CALIB\r\n* Copyright: Microsoft 2017\r\n*\r\n* Record new telemtry events and fires update\r\n*/\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nvar subscribableevent_1 = require(\"subscribableevent\");\r\nvar TelemetryManager = /** @class */ (function () {\r\n function TelemetryManager(_cache) {\r\n this._cache = _cache;\r\n this.telemetryEventAdded = new subscribableevent_1.default();\r\n //noop\r\n }\r\n TelemetryManager.prototype.sendTelemetryEvent = function (event) {\r\n var eventName = event.getEventName();\r\n var eventData = event.getAttributes();\r\n var telemetryEnabled = false;\r\n var clientTelemetryConfig = this._cache.getEcsConfig();\r\n if (!clientTelemetryConfig) {\r\n // in the scenario where we have no cached previously ECS config that was successfully fetched in the past,\r\n // fallback to sending telemetry event\r\n console.warn('No previously cached ECS telemetry config exists - fallback to sending event');\r\n telemetryEnabled = true;\r\n }\r\n else if (TelemetryManager._containsEcsClientTelemetryConfig(clientTelemetryConfig.config)) {\r\n var ecsConfig = clientTelemetryConfig.config.ECSCONFIG;\r\n if (ecsConfig && ecsConfig.ecsClientTelemetry) {\r\n telemetryEnabled = !!ecsConfig.ecsClientTelemetry[eventName];\r\n }\r\n }\r\n if (telemetryEnabled) {\r\n this.telemetryEventAdded.fire(eventName, eventData);\r\n }\r\n };\r\n TelemetryManager._containsEcsClientTelemetryConfig = function (config) {\r\n return !!config && !!config.ECSCONFIG && !!config.ECSCONFIG.ecsClientTelemetry;\r\n };\r\n return TelemetryManager;\r\n}());\r\nexports.default = TelemetryManager;\r\n"],"names":[],"sourceRoot":""}