UNPKG

amazon-connect-streams

Version:
1,364 lines (1,324 loc) 1.53 MB
/******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ 19 (__unused_webpack_module, exports) { "use strict"; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 Object.defineProperty(exports, "__esModule", ({ value: true })); exports.isValidRevisionID = exports.isValidAssetGroup = exports.resolveURL = exports.addQueryParams = exports.withQueryString = exports.withRequestHeaders = exports.fetchWithBehavior = void 0; function fetchWithBehavior(url, init, fetchBehavior) { if (!fetchBehavior) { return fetch(url, init); } const withQuery = withQueryString(url, fetchBehavior); const withHeaders = withRequestHeaders(init, fetchBehavior); return fetch(withQuery, withHeaders); } exports.fetchWithBehavior = fetchWithBehavior; function withRequestHeaders(init, fetchBehavior) { if (!(fetchBehavior === null || fetchBehavior === void 0 ? void 0 : fetchBehavior.headers)) { return init; } if (!init) { return { headers: fetchBehavior.headers, }; } return Object.assign(Object.assign({}, init), { headers: Object.assign(Object.assign({}, init.headers || {}), fetchBehavior.headers) }); } exports.withRequestHeaders = withRequestHeaders; function withQueryString(url, fetchBehavior) { if (!(fetchBehavior === null || fetchBehavior === void 0 ? void 0 : fetchBehavior.escapedQueryString)) { return url; } const hasQuery = url.lastIndexOf('?') !== -1; return `${url}${hasQuery ? '&' : '?'}${fetchBehavior.escapedQueryString}`; } exports.withQueryString = withQueryString; function addQueryParams(fetchBehavior, queryParams) { const keys = Object.keys(queryParams); if (!keys.length) { return fetchBehavior; } const params = new URLSearchParams(fetchBehavior === null || fetchBehavior === void 0 ? void 0 : fetchBehavior.escapedQueryString); for (const key of keys) { params.append(key, queryParams[key]); } return Object.assign(Object.assign({}, fetchBehavior), { escapedQueryString: params.toString() }); } exports.addQueryParams = addQueryParams; const HEAD_OPTIONS = { method: 'HEAD', mode: 'cors', credentials: 'omit', redirect: 'follow', referrerPolicy: 'origin', }; function resolveURL(url, fetchBehavior) { return fetchWithBehavior(url, HEAD_OPTIONS, fetchBehavior) .then(response => response.redirected ? response.url : url); } exports.resolveURL = resolveURL; function isValidAssetGroup(assetGroup) { return !!assetGroup && /^[-.a-zA-Z0-9]+$/.test(assetGroup); } exports.isValidAssetGroup = isValidAssetGroup; function isValidRevisionID(revisionID) { return !!revisionID && /^[123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ]{22}$/.test(revisionID); } exports.isValidRevisionID = isValidRevisionID; /***/ }, /***/ 60 () { function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); } function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); } function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } /* * Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * SPDX-License-Identifier: Apache-2.0 */ (function () { var global = this || globalThis; var connect = global.connect || {}; global.connect = connect; global.lily = connect; var userAgent = navigator.userAgent; var ONE_DAY_MILLIS = 24 * 60 * 60 * 1000; var DEFAULT_POPUP_HEIGHT = 578; var DEFAULT_POPUP_WIDTH = 433; var COPYABLE_EVENT_FIELDS = ["bubbles", "cancelBubble", "cancelable", "composed", "data", "defaultPrevented", "eventPhase", "isTrusted", "lastEventId", "origin", "returnValue", "timeStamp", "type"]; /** * Unpollute sprintf functions from the global namespace. */ connect.sprintf = global.sprintf; connect.vsprintf = global.vsprintf; delete global.sprintf; delete global.vsprintf; connect.HTTP_STATUS_CODES = { SUCCESS: 200, UNAUTHORIZED: 401, ACCESS_DENIED: 403, TOO_MANY_REQUESTS: 429, INTERNAL_SERVER_ERROR: 500 }; connect.TRANSPORT_TYPES = { CHAT_TOKEN: "chat_token", WEB_SOCKET: "web_socket", AGENT_DISCOVERY: "agent_discovery", WEB_RTC: "web_rtc" }; /** * Binds the given instance object as the context for * the method provided. * * @param scope The instance object to be set as the scope * of the function. * @param method The method to be encapsulated. * * All other arguments, if any, are bound to the method * invocation inside the closure. * * @return A closure encapsulating the invocation of the * method provided in context of the given instance. */ connect.hitch = function () { var args = Array.prototype.slice.call(arguments); var scope = args.shift(); var method = args.shift(); connect.assertNotNull(scope, 'scope'); connect.assertNotNull(method, 'method'); connect.assertTrue(connect.isFunction(method), 'method must be a function'); return function () { var closureArgs = Array.prototype.slice.call(arguments); return method.apply(scope, args.concat(closureArgs)); }; }; /** * Determine if the given value is a callable function type. * Borrowed from Underscore.js. */ connect.isFunction = function (obj) { return !!(obj && obj.constructor && obj.call && obj.apply); }; /** * Determine if the given value is an array. */ connect.isArray = function (obj) { return Object.prototype.toString.call(obj) === '[object Array]'; }; /** * Get a list of keys from a Javascript object used * as a hash map. */ connect.keys = function (map) { var keys = []; connect.assertNotNull(map, 'map'); for (var k in map) { keys.push(k); } return keys; }; /** * Get a list of values from a Javascript object used * as a hash map. */ connect.values = function (map) { var values = []; connect.assertNotNull(map, 'map'); for (var k in map) { values.push(map[k]); } return values; }; /** * Get a list of key/value pairs from the given map. */ connect.entries = function (map) { var entries = []; for (var k in map) { entries.push({ key: k, value: map[k] }); } return entries; }; /** * Merge two or more maps together into a new map, * or simply copy a single map. */ connect.merge = function () { var argMaps = Array.prototype.slice.call(arguments, 0); var resultMap = {}; argMaps.forEach(function (map) { connect.entries(map).forEach(function (kv) { resultMap[kv.key] = kv.value; }); }); return resultMap; }; connect.now = function () { return new Date().getTime(); }; connect.find = function (array, predicate) { for (var x = 0; x < array.length; x++) { if (predicate(array[x])) { return array[x]; } } return null; }; connect.contains = function (obj, value) { if (obj instanceof Array) { return connect.find(obj, function (v) { return v === value; }) != null; } else { return value in obj; } }; connect.containsValue = function (obj, value) { if (obj instanceof Array) { return connect.find(obj, function (v) { return v === value; }) != null; } else { return connect.find(connect.values(obj), function (v) { return v === value; }) != null; } }; /** * Generate a random ID consisting of the current timestamp * and a random base-36 number based on Math.random(). */ connect.randomId = function () { return connect.sprintf("%s-%s", connect.now(), Math.random().toString(36).slice(2)); }; /** * Generate an enum from the given list of lower-case enum values, * where the enum keys will be upper case. * * Conversion from pascal case based on code from here: * http://stackoverflow.com/questions/30521224 */ connect.makeEnum = function (values) { var enumObj = {}; values.forEach(function (value) { var key = value.replace(/\.?([a-z]+)_?/g, function (x, y) { return y.toUpperCase() + "_"; }).replace(/_$/, ""); enumObj[key] = value; }); return enumObj; }; connect.makeNamespacedEnum = function (prefix, values) { var enumObj = connect.makeEnum(values); connect.keys(enumObj).forEach(function (key) { enumObj[key] = connect.sprintf("%s::%s", prefix, enumObj[key]); }); return enumObj; }; connect.makeGenericNamespacedEnum = function (prefix, values, delimiter) { var enumObj = connect.makeEnum(values); connect.keys(enumObj).forEach(function (key) { enumObj[key] = connect.sprintf("%s" + delimiter + "%s", prefix, enumObj[key]); }); return enumObj; }; /** * Methods to determine browser type and versions, used for softphone initialization. */ /* This will also return True for Edge and Opera since they include Chrome in the user agent string, as they are built off of Chrome. */ connect.isChromeBrowser = function () { return userAgent.indexOf("Chrome") !== -1; }; connect.isFirefoxBrowser = function () { return userAgent.indexOf("Firefox") !== -1; }; connect.isOperaBrowser = function () { return userAgent.indexOf("Opera") !== -1; }; connect.isEdgeBrowser = function () { return userAgent.indexOf("Edg") !== -1; }; connect.getChromeBrowserVersion = function () { var chromeVersion = userAgent.substring(userAgent.indexOf("Chrome") + 7); if (chromeVersion) { return parseFloat(chromeVersion); } else { return -1; } }; connect.getFirefoxBrowserVersion = function () { var firefoxVersion = userAgent.substring(userAgent.indexOf("Firefox") + 8); if (firefoxVersion) { return parseFloat(firefoxVersion); } else { return -1; } }; connect.isValidLocale = function (locale) { var languages = [{ id: 'en_US', label: 'English' }, { id: 'de_DE', label: 'Deutsch' }, { id: 'es_ES', label: 'Español' }, { id: 'fr_FR', label: 'Français' }, { id: 'ja_JP', label: '日本語' }, { id: 'it_IT', label: 'Italiano' }, { id: 'ko_KR', label: '한국어' }, { id: 'pt_BR', label: 'Português' }, { id: 'zh_CN', label: '中文(简体)' }, { id: 'zh_TW', label: '中文(繁體)' }]; return languages.map(function (language) { return language.id; }).includes(locale); }; connect.getOperaBrowserVersion = function () { var versionOffset = userAgent.indexOf("Opera"); var operaVersion = userAgent.indexOf("Version") !== -1 ? userAgent.substring(versionOffset + 8) : userAgent.substring(versionOffset + 6); if (operaVersion) { return parseFloat(operaVersion); } else { return -1; } }; /** * Return a map of items in the given list indexed by * keys determined by the closure provided. * * @param iterable A list-like object. * @param closure A closure to determine the index for the * items in the iterable. * @return A map from index to item for each item in the iterable. */ connect.index = function (iterable, closure) { var map = {}; iterable.forEach(function (item) { map[closure(item)] = item; }); return map; }; /** * Converts the given array into a map as a set, * where elements in the array are mapped to 1. */ connect.set = function (arrayIn) { var setMap = {}; arrayIn.forEach(function (key) { setMap[key] = 1; }); return setMap; }; /** * Returns a map for each key in mapB which * is NOT in mapA. */ connect.relativeComplement = function (mapA, mapB) { var compMap = {}; connect.keys(mapB).forEach(function (key) { if (!(key in mapA)) { compMap[key] = mapB[key]; } }); return compMap; }; /** * Asserts that a premise is true. */ connect.assertTrue = function (premise, message) { if (!premise) { throw new connect.ValueError(message); } }; /** * Asserts that a value is not null or undefined. */ connect.assertNotNull = function (value, name) { connect.assertTrue(value != null && _typeof(value) !== undefined, connect.sprintf("%s must be provided", name || 'A value')); return value; }; connect.deepcopy = function (src) { return JSON.parse(JSON.stringify(src)); }; connect.deepcopyCrossOriginEvent = function (event) { var obj = {}; var listOfAcceptableKeys = COPYABLE_EVENT_FIELDS; listOfAcceptableKeys.forEach(function (key) { try { obj[key] = event[key]; } catch (e) { connect.getLog().info("deepcopyCrossOriginEvent failed on key: ", key).sendInternalLogToServer(); } }); return connect.deepcopy(obj); }; /** * Get the current base url of the open page, e.g. if the page is * https://example.com:9494/oranges, this will be "https://example.com:9494". */ connect.getBaseUrl = function () { var location = global.location; return connect.sprintf("%s//%s:%s", location.protocol, location.hostname, location.port); }; connect.getUrlWithProtocol = function (url) { var protocol = global.location.protocol; if (url.substr(0, protocol.length) !== protocol) { return connect.sprintf("%s//%s", protocol, url); } return url; }; /** * Determine if the current window is in an iframe. * Courtesy: http://stackoverflow.com/questions/326069/ */ connect.isFramed = function () { try { return window.self !== window.top; } catch (e) { return true; } }; connect.hasOtherConnectedCCPs = function () { return connect.numberOfConnectedCCPs > 1; }; connect.fetch = function (endpoint, options, milliInterval, maxRetry) { maxRetry = maxRetry || 5; milliInterval = milliInterval || 1000; options = options || {}; return new Promise(function (resolve, reject) { function fetchData(maxRetry) { fetch(endpoint, options).then(function (res) { if (res.status === connect.HTTP_STATUS_CODES.SUCCESS) { res.json().then(function (json) { return resolve(json); })["catch"](function () { return resolve({}); }); } else if (maxRetry !== 1 && (res.status >= connect.HTTP_STATUS_CODES.INTERNAL_SERVER_ERROR || res.status === connect.HTTP_STATUS_CODES.TOO_MANY_REQUESTS)) { setTimeout(function () { fetchData(--maxRetry); }, milliInterval); } else { reject(res); } })["catch"](function (e) { reject(e); }); } fetchData(maxRetry); }); }; connect.fetchWithTimeout = /*#__PURE__*/function () { var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(endpoint, timeoutMs, options, milliInterval, maxRetry) { var controller, id, response; return _regenerator().w(function (_context) { while (1) switch (_context.n) { case 0: options = options || {}; if (timeoutMs) { _context.n = 1; break; } return _context.a(2, connect.fetch(endpoint, options, milliInterval, maxRetry)); case 1: controller = new AbortController(); id = setTimeout(function () { return controller.abort(); }, timeoutMs); _context.n = 2; return connect.fetch(endpoint, _objectSpread(_objectSpread({}, options), {}, { signal: controller.signal }), milliInterval, maxRetry); case 2: response = _context.v; clearTimeout(id); return _context.a(2, response); } }, _callee); })); return function (_x, _x2, _x3, _x4, _x5) { return _ref.apply(this, arguments); }; }(); /** * Calling a function with exponential backoff with full jitter retry strategy * It will retry calling the function for maximum maxRetry times if it fails. * Success callback will be called if the function succeeded. * Failure callback will be called only if the last try failed. */ connect.backoff = function (func, milliInterval, maxRetry, callbacks) { connect.assertTrue(connect.isFunction(func), "func must be a Function"); var self = this; var ratio = 2; func({ success: function success(data) { if (callbacks && callbacks.success) { callbacks.success(data); } }, failure: function failure(err, data) { if (maxRetry > 0) { var interval = milliInterval * 2 * Math.random(); global.setTimeout(function () { self.backoff(func, interval * ratio, --maxRetry, callbacks); }, interval); } else { if (callbacks && callbacks.failure) { callbacks.failure(err, data); } } } }); }; connect.publishMetric = function (metricData) { connect.core.getUpstream().sendUpstream(connect.EventType.BROADCAST, { event: connect.EventType.CLIENT_METRIC, data: metricData }); }; connect.publishSoftphoneStats = function (stats) { connect.core.getUpstream().sendUpstream(connect.EventType.BROADCAST, { event: connect.EventType.SOFTPHONE_STATS, data: stats }); }; connect.publishSoftphoneReport = function (report) { connect.core.getUpstream().sendUpstream(connect.EventType.BROADCAST, { event: connect.EventType.SOFTPHONE_REPORT, data: report }); }; connect.publishClickStreamData = function (report) { connect.core.getUpstream().sendUpstream(connect.EventType.BROADCAST, { event: connect.EventType.CLICK_STREAM_DATA, data: report }); }; connect.publishClientSideLogs = function (logs) { var bus = connect.core.getEventBus(); bus.trigger(connect.EventType.CLIENT_SIDE_LOGS, logs); }; connect.addNamespaceToLogs = function (namespace) { var methods = ['log', 'error', 'warn', 'info', 'debug']; methods.forEach(function (method) { var consoleMethod = window.console[method]; window.console[method] = function () { var args = Array.from(arguments); args.unshift("[".concat(namespace, "]")); consoleMethod.apply(window.console, args); }; }); }; /** * A wrapper around Window.open() for managing single instance popups. * Tracks window references to enable window reuse without reload and provides security. */ connect.PopupManager = function () { this.windows = {}; this.windowUrls = {}; }; connect.PopupManager.prototype.open = function (url, name, options) { var features = ''; if (options) { // default values are chosen to provide a minimum height without scrolling // and a uniform margin based on the css of the ccp login page var height = options.height || DEFAULT_POPUP_HEIGHT; var width = options.width || DEFAULT_POPUP_WIDTH; var top = options.top || 0; var left = options.left || 0; features = "width=" + width + ", height=" + height + ", top=" + top + ", left=" + left; } var cachedWin = this.windows[name]; var cachedUrl = this.windowUrls[name]; // Check if window exists and is still open if (cachedWin) { try { if (!cachedWin.closed) { if (cachedUrl === url) { // Same URL - reuse existing window without reload try { cachedWin.focus(); } catch (e) { // Focus may fail due to browser restrictions, this is acceptable } connect.getLog().info("[PopupManager] Reusing existing popup window").sendInternalLogToServer(); return cachedWin; } } else { // Window was closed, clean up tracking delete this.windows[name]; delete this.windowUrls[name]; } } catch (e) { // Can't access window (likely cross-origin), assume closed and clean up delete this.windows[name]; delete this.windowUrls[name]; } } // Open new window directly to URL var win = window.open(url, name, features); if (win) { // Check if window is already closed (edge case in testing scenarios) try { if (!win.closed) { this.windows[name] = win; this.windowUrls[name] = url; connect.getLog().info("[PopupManager] Opened popup window").withObject({ url: url, name: name }).sendInternalLogToServer(); } } catch (e) { // Can't access window properties, but still return it } } return win; }; connect.PopupManager.prototype.clear = function (name) { // Clean up window tracking delete this.windows[name]; delete this.windowUrls[name]; // Clean up localStorage var key = this._getLocalStorageKey(name); global.localStorage.removeItem(key); }; connect.PopupManager.prototype._getLastOpenedTimestamp = function (name) { var key = this._getLocalStorageKey(name); var value = global.localStorage.getItem(key); if (value) { return parseInt(value, 10); } else { return 0; } }; connect.PopupManager.prototype._setLastOpenedTimestamp = function (name, ts) { var key = this._getLocalStorageKey(name); global.localStorage.setItem(key, '' + ts); }; connect.PopupManager.prototype._getLocalStorageKey = function (name) { return "connectPopupManager::" + name; }; /** * An enumeration of the HTML5 notification permission values. */ var NotificationPermission = connect.makeEnum(['granted', 'denied', 'default']); /** * A simple engine for showing notification popups. */ connect.NotificationManager = function () { this.queue = []; this.permission = NotificationPermission.DEFAULT; }; connect.NotificationManager.prototype.requestPermission = function () { var self = this; if (!("Notification" in global)) { connect.getLog().warn("This browser doesn't support notifications.").sendInternalLogToServer(); this.permission = NotificationPermission.DENIED; } else if (global.Notification.permission === NotificationPermission.DENIED) { connect.getLog().warn("The user has requested to not receive notifications.").sendInternalLogToServer(); this.permission = NotificationPermission.DENIED; } else if (this.permission !== NotificationPermission.GRANTED) { global.Notification.requestPermission().then(function (permission) { self.permission = permission; if (permission === NotificationPermission.GRANTED) { self._showQueued(); } else { self.queue = []; } }); } }; connect.NotificationManager.prototype.show = function (title, options) { if (this.permission === NotificationPermission.GRANTED) { return this._showImpl({ title: title, options: options }); } else if (this.permission === NotificationPermission.DENIED) { connect.getLog().warn("Unable to show notification.").sendInternalLogToServer().withObject({ title: title, options: options }); } else { var params = { title: title, options: options }; connect.getLog().warn("Deferring notification until user decides to allow or deny.").withObject(params).sendInternalLogToServer(); this.queue.push(params); } }; connect.NotificationManager.prototype._showQueued = function () { var self = this; var notifications = this.queue.map(function (params) { return self._showImpl(params); }); this.queue = []; return notifications; }; connect.NotificationManager.prototype._showImpl = function (params) { var notification = new global.Notification(params.title, params.options); if (params.options.clicked) { notification.onclick = function () { params.options.clicked.call(notification); }; } return notification; }; connect.ValueError = function () { var args = Array.prototype.slice.call(arguments, 0); var format = args.shift(); var instance = new Error(connect.vsprintf(format, args)); Object.setPrototypeOf(instance, connect.ValueError.prototype); return instance; }; Object.setPrototypeOf(connect.ValueError.prototype, Error.prototype); Object.setPrototypeOf(connect.ValueError, Error); connect.ValueError.prototype.name = 'ValueError'; connect.NotImplementedError = function () { var args = Array.prototype.slice.call(arguments, 0); var format = args.shift(); var instance = new Error(connect.vsprintf(format, args)); Object.setPrototypeOf(instance, connect.NotImplementedError.prototype); return instance; }; Object.setPrototypeOf(connect.NotImplementedError.prototype, Error.prototype); Object.setPrototypeOf(connect.NotImplementedError, Error); connect.NotImplementedError.prototype.name = 'NotImplementedError'; connect.StateError = function () { var args = Array.prototype.slice.call(arguments, 0); var format = args.shift(); var instance = new Error(connect.vsprintf(format, args)); Object.setPrototypeOf(instance, connect.StateError.prototype); return instance; }; Object.setPrototypeOf(connect.StateError.prototype, Error.prototype); Object.setPrototypeOf(connect.StateError, Error); connect.StateError.prototype.name = 'StateError'; connect.VoiceIdError = function (type, message, err) { var error = {}; error.type = type; error.message = message; error.stack = Error(message).stack; error.err = err; return error; }; // internal use only connect.isCCP = function () { if (!connect.core.upstream) { return false; } var conduit = connect.core.getUpstream(); return conduit.name === 'ConnectSharedWorkerConduit'; }; connect.isSharedWorker = function () { return connect.worker && !!connect.worker.clientEngine; }; connect.isCRM = function () { if (!connect.core.upstream) { return false; } return connect.core.getUpstream() instanceof connect.IFrameConduit || connect.core.getUpstream() instanceof connect.GRProxyIframeConduit; }; // internal use only connect.isActiveConduit = function (conduit) { var grProxyConduit = connect.core.getUpstream(); if (grProxyConduit instanceof connect.GRProxyIframeConduit) { return conduit.name === grProxyConduit.activeRegionUrl; } else { connect.getLog().debug('connect.isActiveConduit is called but there is no GR proxy conduit').sendInternalLogToServer(); return true; } }; })(); /***/ }, /***/ 95 () { function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } !function (e) { var n = {}; function t(o) { if (n[o]) return n[o].exports; var r = n[o] = { i: o, l: !1, exports: {} }; return e[o].call(r.exports, r, r.exports, t), r.l = !0, r.exports; } t.m = e, t.c = n, t.d = function (e, n, o) { t.o(e, n) || Object.defineProperty(e, n, { enumerable: !0, get: o }); }, t.r = function (e) { "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(e, "__esModule", { value: !0 }); }, t.t = function (e, n) { if (1 & n && (e = t(e)), 8 & n) return e; if (4 & n && "object" == _typeof(e) && e && e.__esModule) return e; var o = Object.create(null); if (t.r(o), Object.defineProperty(o, "default", { enumerable: !0, value: e }), 2 & n && "string" != typeof e) for (var r in e) t.d(o, r, function (n) { return e[n]; }.bind(null, r)); return o; }, t.n = function (e) { var n = e && e.__esModule ? function () { return e["default"]; } : function () { return e; }; return t.d(n, "a", n), n; }, t.o = function (e, n) { return Object.prototype.hasOwnProperty.call(e, n); }, t.p = "", t(t.s = 2); }([function (e, n, t) { "use strict"; var o = t(1), r = "NULL", i = "CLIENT_LOGGER", c = "DEBUG", a = 2e3, s = "AMZ_WEB_SOCKET_MANAGER:", u = "Network offline", l = "Network online, connecting to WebSocket server", f = "Network offline, ignoring this getWebSocketConnConfig request", d = "Heartbeat response not received", p = "Heartbeat response received", g = "Sending heartbeat", b = "Failed to send heartbeat since WebSocket is not open", y = "WebSocket connection established!", m = "WebSocket connection is closed", v = "WebSocketManager Error, error_event: ", S = "Scheduling WebSocket reinitialization, after delay ", h = "WebSocket URL cannot be used to establish connection", k = "WebSocket Initialization failed - Terminating and cleaning subscriptions", w = "Terminating WebSocket Manager", C = "Fetching new WebSocket connection configuration", L = "Successfully fetched webSocket connection configuration", T = "Failed to fetch webSocket connection configuration", O = "Retrying fetching new WebSocket connection configuration", W = "Initializing Websocket Manager", I = "Initializing Websocket Manager Failed!", N = "Websocket connection open", _ = "Websocket connection close", E = "Websocket connection gain", F = "Websocket connection lost", A = "Websocket subscription failure", R = "Reset Websocket state", x = "WebSocketManager Message Error", D = "Message received for topic ", j = "Invalid incoming message", M = "WebsocketManager invoke callbacks for topic success ", G = "aws/subscribe", z = "aws/unsubscribe", P = "aws/heartbeat", H = "connected", U = "disconnected"; function q(e) { return (q = "function" == typeof Symbol && "symbol" == _typeof(Symbol.iterator) ? function (e) { return _typeof(e); } : function (e) { return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : _typeof(e); })(e); } var J = { assertTrue: function assertTrue(e, n) { if (!e) throw new Error(n); }, assertNotNull: function assertNotNull(e, n) { return J.assertTrue(null !== e && void 0 !== q(e), Object(o.sprintf)("%s must be provided", n || "A value")), e; }, isNonEmptyString: function isNonEmptyString(e) { return "string" == typeof e && e.length > 0; }, assertIsList: function assertIsList(e, n) { if (!Array.isArray(e)) throw new Error(n + " is not an array"); }, isFunction: function isFunction(e) { return !!(e && e.constructor && e.call && e.apply); }, isObject: function isObject(e) { return !("object" !== q(e) || null === e); }, isString: function isString(e) { return "string" == typeof e; }, isNumber: function isNumber(e) { return "number" == typeof e; } }, B = new RegExp("^(wss://)\\w*"); J.validWSUrl = function (e) { return B.test(e); }, J.getSubscriptionResponse = function (e, n, t) { return { topic: e, content: { status: n ? "success" : "failure", topics: t } }; }, J.assertIsObject = function (e, n) { if (!J.isObject(e)) throw new Error(n + " is not an object!"); }, J.addJitter = function (e) { var n = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 1; n = Math.min(n, 1); var t = Math.random() > .5 ? 1 : -1; return Math.floor(e + t * e * Math.random() * n); }, J.isNetworkOnline = function () { return navigator.onLine; }, J.isNetworkFailure = function (e) { return !(!e._debug || !e._debug.type) && "NetworkingError" === e._debug.type; }; var V = J; function X(e, n) { return !n || "object" !== Z(n) && "function" != typeof n ? function (e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }(e) : n; } function $(e) { return ($ = Object.setPrototypeOf ? Object.getPrototypeOf : function (e) { return e.__proto__ || Object.getPrototypeOf(e); })(e); } function K(e, n) { return (K = Object.setPrototypeOf || function (e, n) { return e.__proto__ = n, e; })(e, n); } function Z(e) { return (Z = "function" == typeof Symbol && "symbol" == _typeof(Symbol.iterator) ? function (e) { return _typeof(e); } : function (e) { return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : _typeof(e); })(e); } function Q(e, n) { if (!(e instanceof n)) throw new TypeError("Cannot call a class as a function"); } function Y(e, n) { for (var t = 0; t < n.length; t++) { var o = n[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, o.key, o); } } function ee(e, n, t) { return n && Y(e.prototype, n), t && Y(e, t), e; } var ne = function () { function e() { Q(this, e); } return ee(e, [{ key: "debug", value: function value(e) {} }, { key: "info", value: function value(e) {} }, { key: "warn", value: function value(e) {} }, { key: "error", value: function value(e) {} }, { key: "advancedLog", value: function value(e) {} }]), e; }(), te = s, oe = { DEBUG: 10, INFO: 20, WARN: 30, ERROR: 40, ADVANCED_LOG: 50 }, re = function () { function e() { Q(this, e), this.updateLoggerConfig(), this.consoleLoggerWrapper = ae(); } return ee(e, [{ key: "writeToClientLogger", value: function value(e, n) { if (this.hasClientLogger()) switch (e) { case oe.DEBUG: return this._clientLogger.debug(n) || n; case oe.INFO: return this._clientLogger.info(n) || n; case oe.WARN: return this._clientLogger.warn(n) || n; case oe.ERROR: return this._clientLogger.error(n) || n; case oe.ADVANCED_LOG: return this._advancedLogWriter ? this._clientLogger[this._advancedLogWriter](n) || n : ""; } } }, { key: "isLevelEnabled", value: function value(e) { return e >= this._level; } }, { key: "hasClientLogger", value: function value() { return null !== this._clientLogger; } }, { key: "getLogger", value: function value(e) { var n = e.prefix || te; return this._logsDestination === c ? this.consoleLoggerWrapper : new ce(n); } }, { key: "updateLoggerConfig", value: function value(e) { var n = e || {}; this._level = n.level || oe.INFO, this._advancedLogWriter = "warn", n.advancedLogWriter && (this._advancedLogWriter = n.advancedLogWriter), n.customizedLogger && "object" === Z(n.customizedLogger) && (this.useClientLogger = !0), this._clientLogger = n.logger || this.selectLogger(n), this._logsDestination = r, n.debug && (this._logsDestination = c), n.logger && (this._logsDestination = i); } }, { key: "selectLogger", value: function value(e) { return e.customizedLogger && "object" === Z(e.customizedLogger) ? e.customizedLogger : e.useDefaultLogger ? (this.consoleLoggerWrapper = ae(), this.consoleLoggerWrapper) : null; } }]), e; }(), ie = function () { function e() { Q(this, e); } return ee(e, [{ key: "debug", value: function value() {} }, { key: "info", value: function value() {} }, { key: "warn", value: function value() {} }, { key: "error", value: function value() {} }, { key: "advancedLog", value: function value() {} }]), e; }(), ce = function (e) { function n(e) { var t; return Q(this, n), (t = X(this, $(n).call(this))).prefix = e || te, t; } return function (e, n) { if ("function" != typeof n && null !== n) throw new TypeError("Super expression must either be null or a function"); e.prototype = Object.create(n && n.prototype, { constructor: { value: e, writable: !0, configurable: !0 } }), n && K(e, n); }(n, ie), ee(n, [{ key: "debug", value: function value() { for (var e = arguments.length, n = new Array(e), t = 0; t < e; t++) n[t] = arguments[t]; return this._log(oe.DEBUG, n); } }, { key: "info", value: function value() { for (var e = arguments.length, n = new Array(e), t = 0; t < e; t++) n[t] = arguments[t]; return this._log(oe.INFO, n); } }, { key: "warn", value: function value() { for (var e = arguments.length, n = new Array(e), t = 0; t < e; t++) n[t] = arguments[t]; return this._log(oe.WARN, n); } }, { key: "error", value: function value() { for (var e = arguments.length, n = new Array(e), t = 0; t < e; t++) n[t] = arguments[t]; return this._log(oe.ERROR, n); } }, { key: "advancedLog", value: function value() { for (var e = arguments.length, n = new Array(e), t = 0; t < e; t++) n[t] = arguments[t]; return this._log(oe.ADVANCED_LOG, n); } }, { key: "_shouldLog", value: function value(e) { return se.hasClientLogger() && se.isLevelEnabled(e); } }, { key: "_writeToClientLogger", value: function value(e, n) { return se.writeToClientLogger(e, n); } }, { key: "_log", value: function value(e, n) { if (this._shouldLog(e)) { var t = se.useClientLogger ? n : this._convertToSingleStatement(n, e); return this._writeToClientLogger(e, t); } } }, { key: "_convertToSingleStatement", value: function value(e, n) { var t = new Date(Date.now()).toISOString(), o = this._getLogLevelByValue(n), r = "[".concat(t, "][").concat(o, "]"); this.prefix && (r += this.prefix + " "), this.options && (this.options.prefix ? r += " " + this.options.prefix + ":" : r += "", this.options.logMetaData ? r += " Meta data: " + JSON.stringify(this.options.logMetaData) : r += ""); for (var i = 0; i < e.length; i++) { var c = e[i]; r += this._convertToString(c) + " "; } return r; } }, { key: "_getLogLevelByValue", value: function value(e) { switch (e) { case 10: return "DEBUG"; case 20: return "INFO"; case 30: return "WARN"; case 40: return "ERROR"; case 50: return "ADVANCED_LOG"; } } }, { key: "_convertToString", value: function value(e) { try { if (!e) return ""; if (V.isString(e)) return e; if (V.isObject(e) && V.isFunction(e.toString)) { var n = e.toString(); if ("[object Object]" !== n) return n; } return JSON.stringify(e); } catch (n) { return console.error("Error while converting argument to string", e, n), ""; } } }]), n; }(), ae = function ae() { var e = new ie(); return e.debug = function () { for (var e = arguments.length, n = new Array(e), t = 0; t < e; t++) n[t] = arguments[t]; return console.debug.apply(window.console, [].concat(n)); }, e.info = function () { for (var e = arguments.length, n = new Array(e), t = 0; t < e; t++) n[t] = arguments[t]; return console.info.apply(window.console, [].concat(n)); }, e.warn = function () { for (var e = arguments.length, n = new Array(e), t = 0; t < e; t++) n[t] = arguments[t]; return console.warn.apply(window.console, [].concat(n)); }, e.error = function () { for (var e = arguments.length, n = new Array(e), t = 0; t < e; t++) n[t] = arguments[t]; return console.error.apply(window.console, [].concat(n)); }, e; }, se = new re(); function ue(e, n) { for (var t = 0; t < n.length; t++) { var o = n[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, o.key, o); } } var le = function () { function e(n) { var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : a; !function (e, n) { if (!(e instanceof n)) throw new TypeError("Cannot call a class as a function"); }(this, e), this.numAttempts = 0, this.executor = n, this.hasActiveReconnection = !1, this.defaultRetry = t; } var n, t, o; return n = e, (t = [{ key: "retry", value: function value() { var e = this; this.hasActiveReconnection || (this.hasActiveReconnection = !0, setTimeout(function () { e._execute(); }, this._getDelay())); } }, { key: "_execute", value: function value() { this.hasActiveReconnection = !1, this.executor(), this.numAttempts++; } }, { key: "connected", value: function value() { this.numAttempts = 0; } }, { key: "_getDelay", value: function value() { var e = Math.pow(2, this.numAttempts) * this.defaultRetry; return e <= 3e4 ? e : 3e4; } }, { key: "getIsConnected", value: function value() { return !this.numAttempts; } }]) && ue(n.prototype, t), o && ue(n, o), e; }(); t.d(n, "a", function () { return de; }); var fe = function fe() { var e = se.getLogger({ prefix: s }), n = V.isNetworkOnline(), t = { primary: null, secondary: null }, o = { reconnectWebSocket: !0, websocketInitFailed: !1, exponentialBackOffTime: 1e3, exponentialTimeoutHandle: null, lifeTimeTimeoutHandle: null, webSocketInitCheckerTimeoutId: null, connState: null }, r = { connectWebSocketRetryCount: 0, connectionAttemptStartTime: null, noOpenConnectionsTimestamp: null }, i = { pendingResponse: !1, intervalHandle: null }, c = { initFailure: new Set(), getWebSocketTransport: null, subscriptionUpdate: new Set(), subscriptionFailure: new Set(), topic: new Map(), allMessage: new Set(), connectionGain: new Set(), connectionLost: new Set(), connectionOpen: new Set(), connectionClose: new Set() }, a = { connConfig: null, promiseHandle: null, promiseCompleted: !0 }, q = { subscribed: new Set(), pending: new Set(), subscriptionHistory: new Set() }, J = { responseCheckIntervalId: null, requestCompleted: !0, reSubscribeIntervalId: null, consecutiveFailedSubscribeAttempts: 0, consecutiveNoResponseRequest: 0 }, B = new le(function () { he(); }), X = new Set([G, z, P]), $ = setInterval(function () { if (n !== V.isNetworkOnline()) { if (!(n = V.isNetworkOnline())) return e.advancedLog(u), void Ce(e.info(u));