UNPKG

coinley-checkout

Version:

A React SDK for Coinley cryptocurrency payment processing with multi-network support

1 lines 1.38 MB
{"version":3,"file":"metamask-sdk-ecd96cdb.mjs","sources":["../node_modules/cross-fetch/dist/browser-ponyfill.js","../node_modules/eventemitter2/lib/eventemitter2.js","../node_modules/uuid/dist/esm-browser/rng.js","../node_modules/uuid/dist/esm-browser/regex.js","../node_modules/uuid/dist/esm-browser/validate.js","../node_modules/uuid/dist/esm-browser/stringify.js","../node_modules/uuid/dist/esm-browser/v4.js","../node_modules/engine.io-parser/build/esm/commons.js","../node_modules/engine.io-parser/build/esm/encodePacket.browser.js","../node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.js","../node_modules/engine.io-parser/build/esm/decodePacket.browser.js","../node_modules/engine.io-parser/build/esm/index.js","../node_modules/@socket.io/component-emitter/lib/esm/index.js","../node_modules/engine.io-client/build/esm/globals.js","../node_modules/engine.io-client/build/esm/util.js","../node_modules/engine.io-client/build/esm/contrib/parseqs.js","../node_modules/engine.io-client/build/esm/transport.js","../node_modules/engine.io-client/build/esm/transports/polling.js","../node_modules/engine.io-client/build/esm/contrib/has-cors.js","../node_modules/engine.io-client/build/esm/transports/polling-xhr.js","../node_modules/engine.io-client/build/esm/transports/websocket.js","../node_modules/engine.io-client/build/esm/transports/webtransport.js","../node_modules/engine.io-client/build/esm/transports/index.js","../node_modules/engine.io-client/build/esm/contrib/parseuri.js","../node_modules/engine.io-client/build/esm/socket.js","../node_modules/socket.io-client/build/esm/url.js","../node_modules/socket.io-parser/build/esm/is-binary.js","../node_modules/socket.io-parser/build/esm/binary.js","../node_modules/socket.io-parser/build/esm/index.js","../node_modules/socket.io-client/build/esm/on.js","../node_modules/socket.io-client/build/esm/socket.js","../node_modules/socket.io-client/build/esm/contrib/backo2.js","../node_modules/socket.io-client/build/esm/manager.js","../node_modules/socket.io-client/build/esm/index.js","../node_modules/@metamask/sdk/dist/browser/es/metamask-sdk.js"],"sourcesContent":["// Save global object in a variable\nvar __global__ =\n(typeof globalThis !== 'undefined' && globalThis) ||\n(typeof self !== 'undefined' && self) ||\n(typeof global !== 'undefined' && global);\n// Create an object that extends from __global__ without the fetch function\nvar __globalThis__ = (function () {\nfunction F() {\nthis.fetch = false;\nthis.DOMException = __global__.DOMException\n}\nF.prototype = __global__; // Needed for feature detection on whatwg-fetch's code\nreturn new F();\n})();\n// Wraps whatwg-fetch with a function scope to hijack the global object\n// \"globalThis\" that's going to be patched\n(function(globalThis) {\n\nvar irrelevant = (function (exports) {\n\n /* eslint-disable no-prototype-builtins */\n var g =\n (typeof globalThis !== 'undefined' && globalThis) ||\n (typeof self !== 'undefined' && self) ||\n // eslint-disable-next-line no-undef\n (typeof global !== 'undefined' && global) ||\n {};\n\n var support = {\n searchParams: 'URLSearchParams' in g,\n iterable: 'Symbol' in g && 'iterator' in Symbol,\n blob:\n 'FileReader' in g &&\n 'Blob' in g &&\n (function() {\n try {\n new Blob();\n return true\n } catch (e) {\n return false\n }\n })(),\n formData: 'FormData' in g,\n arrayBuffer: 'ArrayBuffer' in g\n };\n\n function isDataView(obj) {\n return obj && DataView.prototype.isPrototypeOf(obj)\n }\n\n if (support.arrayBuffer) {\n var viewClasses = [\n '[object Int8Array]',\n '[object Uint8Array]',\n '[object Uint8ClampedArray]',\n '[object Int16Array]',\n '[object Uint16Array]',\n '[object Int32Array]',\n '[object Uint32Array]',\n '[object Float32Array]',\n '[object Float64Array]'\n ];\n\n var isArrayBufferView =\n ArrayBuffer.isView ||\n function(obj) {\n return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1\n };\n }\n\n function normalizeName(name) {\n if (typeof name !== 'string') {\n name = String(name);\n }\n if (/[^a-z0-9\\-#$%&'*+.^_`|~!]/i.test(name) || name === '') {\n throw new TypeError('Invalid character in header field name: \"' + name + '\"')\n }\n return name.toLowerCase()\n }\n\n function normalizeValue(value) {\n if (typeof value !== 'string') {\n value = String(value);\n }\n return value\n }\n\n // Build a destructive iterator for the value list\n function iteratorFor(items) {\n var iterator = {\n next: function() {\n var value = items.shift();\n return {done: value === undefined, value: value}\n }\n };\n\n if (support.iterable) {\n iterator[Symbol.iterator] = function() {\n return iterator\n };\n }\n\n return iterator\n }\n\n function Headers(headers) {\n this.map = {};\n\n if (headers instanceof Headers) {\n headers.forEach(function(value, name) {\n this.append(name, value);\n }, this);\n } else if (Array.isArray(headers)) {\n headers.forEach(function(header) {\n if (header.length != 2) {\n throw new TypeError('Headers constructor: expected name/value pair to be length 2, found' + header.length)\n }\n this.append(header[0], header[1]);\n }, this);\n } else if (headers) {\n Object.getOwnPropertyNames(headers).forEach(function(name) {\n this.append(name, headers[name]);\n }, this);\n }\n }\n\n Headers.prototype.append = function(name, value) {\n name = normalizeName(name);\n value = normalizeValue(value);\n var oldValue = this.map[name];\n this.map[name] = oldValue ? oldValue + ', ' + value : value;\n };\n\n Headers.prototype['delete'] = function(name) {\n delete this.map[normalizeName(name)];\n };\n\n Headers.prototype.get = function(name) {\n name = normalizeName(name);\n return this.has(name) ? this.map[name] : null\n };\n\n Headers.prototype.has = function(name) {\n return this.map.hasOwnProperty(normalizeName(name))\n };\n\n Headers.prototype.set = function(name, value) {\n this.map[normalizeName(name)] = normalizeValue(value);\n };\n\n Headers.prototype.forEach = function(callback, thisArg) {\n for (var name in this.map) {\n if (this.map.hasOwnProperty(name)) {\n callback.call(thisArg, this.map[name], name, this);\n }\n }\n };\n\n Headers.prototype.keys = function() {\n var items = [];\n this.forEach(function(value, name) {\n items.push(name);\n });\n return iteratorFor(items)\n };\n\n Headers.prototype.values = function() {\n var items = [];\n this.forEach(function(value) {\n items.push(value);\n });\n return iteratorFor(items)\n };\n\n Headers.prototype.entries = function() {\n var items = [];\n this.forEach(function(value, name) {\n items.push([name, value]);\n });\n return iteratorFor(items)\n };\n\n if (support.iterable) {\n Headers.prototype[Symbol.iterator] = Headers.prototype.entries;\n }\n\n function consumed(body) {\n if (body._noBody) return\n if (body.bodyUsed) {\n return Promise.reject(new TypeError('Already read'))\n }\n body.bodyUsed = true;\n }\n\n function fileReaderReady(reader) {\n return new Promise(function(resolve, reject) {\n reader.onload = function() {\n resolve(reader.result);\n };\n reader.onerror = function() {\n reject(reader.error);\n };\n })\n }\n\n function readBlobAsArrayBuffer(blob) {\n var reader = new FileReader();\n var promise = fileReaderReady(reader);\n reader.readAsArrayBuffer(blob);\n return promise\n }\n\n function readBlobAsText(blob) {\n var reader = new FileReader();\n var promise = fileReaderReady(reader);\n var match = /charset=([A-Za-z0-9_-]+)/.exec(blob.type);\n var encoding = match ? match[1] : 'utf-8';\n reader.readAsText(blob, encoding);\n return promise\n }\n\n function readArrayBufferAsText(buf) {\n var view = new Uint8Array(buf);\n var chars = new Array(view.length);\n\n for (var i = 0; i < view.length; i++) {\n chars[i] = String.fromCharCode(view[i]);\n }\n return chars.join('')\n }\n\n function bufferClone(buf) {\n if (buf.slice) {\n return buf.slice(0)\n } else {\n var view = new Uint8Array(buf.byteLength);\n view.set(new Uint8Array(buf));\n return view.buffer\n }\n }\n\n function Body() {\n this.bodyUsed = false;\n\n this._initBody = function(body) {\n /*\n fetch-mock wraps the Response object in an ES6 Proxy to\n provide useful test harness features such as flush. However, on\n ES5 browsers without fetch or Proxy support pollyfills must be used;\n the proxy-pollyfill is unable to proxy an attribute unless it exists\n on the object before the Proxy is created. This change ensures\n Response.bodyUsed exists on the instance, while maintaining the\n semantic of setting Request.bodyUsed in the constructor before\n _initBody is called.\n */\n // eslint-disable-next-line no-self-assign\n this.bodyUsed = this.bodyUsed;\n this._bodyInit = body;\n if (!body) {\n this._noBody = true;\n this._bodyText = '';\n } else if (typeof body === 'string') {\n this._bodyText = body;\n } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {\n this._bodyBlob = body;\n } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {\n this._bodyFormData = body;\n } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {\n this._bodyText = body.toString();\n } else if (support.arrayBuffer && support.blob && isDataView(body)) {\n this._bodyArrayBuffer = bufferClone(body.buffer);\n // IE 10-11 can't handle a DataView body.\n this._bodyInit = new Blob([this._bodyArrayBuffer]);\n } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {\n this._bodyArrayBuffer = bufferClone(body);\n } else {\n this._bodyText = body = Object.prototype.toString.call(body);\n }\n\n if (!this.headers.get('content-type')) {\n if (typeof body === 'string') {\n this.headers.set('content-type', 'text/plain;charset=UTF-8');\n } else if (this._bodyBlob && this._bodyBlob.type) {\n this.headers.set('content-type', this._bodyBlob.type);\n } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {\n this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');\n }\n }\n };\n\n if (support.blob) {\n this.blob = function() {\n var rejected = consumed(this);\n if (rejected) {\n return rejected\n }\n\n if (this._bodyBlob) {\n return Promise.resolve(this._bodyBlob)\n } else if (this._bodyArrayBuffer) {\n return Promise.resolve(new Blob([this._bodyArrayBuffer]))\n } else if (this._bodyFormData) {\n throw new Error('could not read FormData body as blob')\n } else {\n return Promise.resolve(new Blob([this._bodyText]))\n }\n };\n }\n\n this.arrayBuffer = function() {\n if (this._bodyArrayBuffer) {\n var isConsumed = consumed(this);\n if (isConsumed) {\n return isConsumed\n } else if (ArrayBuffer.isView(this._bodyArrayBuffer)) {\n return Promise.resolve(\n this._bodyArrayBuffer.buffer.slice(\n this._bodyArrayBuffer.byteOffset,\n this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength\n )\n )\n } else {\n return Promise.resolve(this._bodyArrayBuffer)\n }\n } else if (support.blob) {\n return this.blob().then(readBlobAsArrayBuffer)\n } else {\n throw new Error('could not read as ArrayBuffer')\n }\n };\n\n this.text = function() {\n var rejected = consumed(this);\n if (rejected) {\n return rejected\n }\n\n if (this._bodyBlob) {\n return readBlobAsText(this._bodyBlob)\n } else if (this._bodyArrayBuffer) {\n return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))\n } else if (this._bodyFormData) {\n throw new Error('could not read FormData body as text')\n } else {\n return Promise.resolve(this._bodyText)\n }\n };\n\n if (support.formData) {\n this.formData = function() {\n return this.text().then(decode)\n };\n }\n\n this.json = function() {\n return this.text().then(JSON.parse)\n };\n\n return this\n }\n\n // HTTP methods whose capitalization should be normalized\n var methods = ['CONNECT', 'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT', 'TRACE'];\n\n function normalizeMethod(method) {\n var upcased = method.toUpperCase();\n return methods.indexOf(upcased) > -1 ? upcased : method\n }\n\n function Request(input, options) {\n if (!(this instanceof Request)) {\n throw new TypeError('Please use the \"new\" operator, this DOM object constructor cannot be called as a function.')\n }\n\n options = options || {};\n var body = options.body;\n\n if (input instanceof Request) {\n if (input.bodyUsed) {\n throw new TypeError('Already read')\n }\n this.url = input.url;\n this.credentials = input.credentials;\n if (!options.headers) {\n this.headers = new Headers(input.headers);\n }\n this.method = input.method;\n this.mode = input.mode;\n this.signal = input.signal;\n if (!body && input._bodyInit != null) {\n body = input._bodyInit;\n input.bodyUsed = true;\n }\n } else {\n this.url = String(input);\n }\n\n this.credentials = options.credentials || this.credentials || 'same-origin';\n if (options.headers || !this.headers) {\n this.headers = new Headers(options.headers);\n }\n this.method = normalizeMethod(options.method || this.method || 'GET');\n this.mode = options.mode || this.mode || null;\n this.signal = options.signal || this.signal || (function () {\n if ('AbortController' in g) {\n var ctrl = new AbortController();\n return ctrl.signal;\n }\n }());\n this.referrer = null;\n\n if ((this.method === 'GET' || this.method === 'HEAD') && body) {\n throw new TypeError('Body not allowed for GET or HEAD requests')\n }\n this._initBody(body);\n\n if (this.method === 'GET' || this.method === 'HEAD') {\n if (options.cache === 'no-store' || options.cache === 'no-cache') {\n // Search for a '_' parameter in the query string\n var reParamSearch = /([?&])_=[^&]*/;\n if (reParamSearch.test(this.url)) {\n // If it already exists then set the value with the current time\n this.url = this.url.replace(reParamSearch, '$1_=' + new Date().getTime());\n } else {\n // Otherwise add a new '_' parameter to the end with the current time\n var reQueryString = /\\?/;\n this.url += (reQueryString.test(this.url) ? '&' : '?') + '_=' + new Date().getTime();\n }\n }\n }\n }\n\n Request.prototype.clone = function() {\n return new Request(this, {body: this._bodyInit})\n };\n\n function decode(body) {\n var form = new FormData();\n body\n .trim()\n .split('&')\n .forEach(function(bytes) {\n if (bytes) {\n var split = bytes.split('=');\n var name = split.shift().replace(/\\+/g, ' ');\n var value = split.join('=').replace(/\\+/g, ' ');\n form.append(decodeURIComponent(name), decodeURIComponent(value));\n }\n });\n return form\n }\n\n function parseHeaders(rawHeaders) {\n var headers = new Headers();\n // Replace instances of \\r\\n and \\n followed by at least one space or horizontal tab with a space\n // https://tools.ietf.org/html/rfc7230#section-3.2\n var preProcessedHeaders = rawHeaders.replace(/\\r?\\n[\\t ]+/g, ' ');\n // Avoiding split via regex to work around a common IE11 bug with the core-js 3.6.0 regex polyfill\n // https://github.com/github/fetch/issues/748\n // https://github.com/zloirock/core-js/issues/751\n preProcessedHeaders\n .split('\\r')\n .map(function(header) {\n return header.indexOf('\\n') === 0 ? header.substr(1, header.length) : header\n })\n .forEach(function(line) {\n var parts = line.split(':');\n var key = parts.shift().trim();\n if (key) {\n var value = parts.join(':').trim();\n try {\n headers.append(key, value);\n } catch (error) {\n console.warn('Response ' + error.message);\n }\n }\n });\n return headers\n }\n\n Body.call(Request.prototype);\n\n function Response(bodyInit, options) {\n if (!(this instanceof Response)) {\n throw new TypeError('Please use the \"new\" operator, this DOM object constructor cannot be called as a function.')\n }\n if (!options) {\n options = {};\n }\n\n this.type = 'default';\n this.status = options.status === undefined ? 200 : options.status;\n if (this.status < 200 || this.status > 599) {\n throw new RangeError(\"Failed to construct 'Response': The status provided (0) is outside the range [200, 599].\")\n }\n this.ok = this.status >= 200 && this.status < 300;\n this.statusText = options.statusText === undefined ? '' : '' + options.statusText;\n this.headers = new Headers(options.headers);\n this.url = options.url || '';\n this._initBody(bodyInit);\n }\n\n Body.call(Response.prototype);\n\n Response.prototype.clone = function() {\n return new Response(this._bodyInit, {\n status: this.status,\n statusText: this.statusText,\n headers: new Headers(this.headers),\n url: this.url\n })\n };\n\n Response.error = function() {\n var response = new Response(null, {status: 200, statusText: ''});\n response.ok = false;\n response.status = 0;\n response.type = 'error';\n return response\n };\n\n var redirectStatuses = [301, 302, 303, 307, 308];\n\n Response.redirect = function(url, status) {\n if (redirectStatuses.indexOf(status) === -1) {\n throw new RangeError('Invalid status code')\n }\n\n return new Response(null, {status: status, headers: {location: url}})\n };\n\n exports.DOMException = g.DOMException;\n try {\n new exports.DOMException();\n } catch (err) {\n exports.DOMException = function(message, name) {\n this.message = message;\n this.name = name;\n var error = Error(message);\n this.stack = error.stack;\n };\n exports.DOMException.prototype = Object.create(Error.prototype);\n exports.DOMException.prototype.constructor = exports.DOMException;\n }\n\n function fetch(input, init) {\n return new Promise(function(resolve, reject) {\n var request = new Request(input, init);\n\n if (request.signal && request.signal.aborted) {\n return reject(new exports.DOMException('Aborted', 'AbortError'))\n }\n\n var xhr = new XMLHttpRequest();\n\n function abortXhr() {\n xhr.abort();\n }\n\n xhr.onload = function() {\n var options = {\n statusText: xhr.statusText,\n headers: parseHeaders(xhr.getAllResponseHeaders() || '')\n };\n // This check if specifically for when a user fetches a file locally from the file system\n // Only if the status is out of a normal range\n if (request.url.indexOf('file://') === 0 && (xhr.status < 200 || xhr.status > 599)) {\n options.status = 200;\n } else {\n options.status = xhr.status;\n }\n options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL');\n var body = 'response' in xhr ? xhr.response : xhr.responseText;\n setTimeout(function() {\n resolve(new Response(body, options));\n }, 0);\n };\n\n xhr.onerror = function() {\n setTimeout(function() {\n reject(new TypeError('Network request failed'));\n }, 0);\n };\n\n xhr.ontimeout = function() {\n setTimeout(function() {\n reject(new TypeError('Network request timed out'));\n }, 0);\n };\n\n xhr.onabort = function() {\n setTimeout(function() {\n reject(new exports.DOMException('Aborted', 'AbortError'));\n }, 0);\n };\n\n function fixUrl(url) {\n try {\n return url === '' && g.location.href ? g.location.href : url\n } catch (e) {\n return url\n }\n }\n\n xhr.open(request.method, fixUrl(request.url), true);\n\n if (request.credentials === 'include') {\n xhr.withCredentials = true;\n } else if (request.credentials === 'omit') {\n xhr.withCredentials = false;\n }\n\n if ('responseType' in xhr) {\n if (support.blob) {\n xhr.responseType = 'blob';\n } else if (\n support.arrayBuffer\n ) {\n xhr.responseType = 'arraybuffer';\n }\n }\n\n if (init && typeof init.headers === 'object' && !(init.headers instanceof Headers || (g.Headers && init.headers instanceof g.Headers))) {\n var names = [];\n Object.getOwnPropertyNames(init.headers).forEach(function(name) {\n names.push(normalizeName(name));\n xhr.setRequestHeader(name, normalizeValue(init.headers[name]));\n });\n request.headers.forEach(function(value, name) {\n if (names.indexOf(name) === -1) {\n xhr.setRequestHeader(name, value);\n }\n });\n } else {\n request.headers.forEach(function(value, name) {\n xhr.setRequestHeader(name, value);\n });\n }\n\n if (request.signal) {\n request.signal.addEventListener('abort', abortXhr);\n\n xhr.onreadystatechange = function() {\n // DONE (success or failure)\n if (xhr.readyState === 4) {\n request.signal.removeEventListener('abort', abortXhr);\n }\n };\n }\n\n xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit);\n })\n }\n\n fetch.polyfill = true;\n\n if (!g.fetch) {\n g.fetch = fetch;\n g.Headers = Headers;\n g.Request = Request;\n g.Response = Response;\n }\n\n exports.Headers = Headers;\n exports.Request = Request;\n exports.Response = Response;\n exports.fetch = fetch;\n\n return exports;\n\n})({});\n})(__globalThis__);\n// This is a ponyfill, so...\n__globalThis__.fetch.ponyfill = true;\ndelete __globalThis__.fetch.polyfill;\n// Choose between native implementation (__global__) or custom implementation (__globalThis__)\nvar ctx = __global__.fetch ? __global__ : __globalThis__;\nexports = ctx.fetch // To enable: import fetch from 'cross-fetch'\nexports.default = ctx.fetch // For TypeScript consumers without esModuleInterop.\nexports.fetch = ctx.fetch // To enable: import {fetch} from 'cross-fetch'\nexports.Headers = ctx.Headers\nexports.Request = ctx.Request\nexports.Response = ctx.Response\nmodule.exports = exports\n","/*!\n * EventEmitter2\n * https://github.com/hij1nx/EventEmitter2\n *\n * Copyright (c) 2013 hij1nx\n * Licensed under the MIT license.\n */\n;!function(undefined) {\n var hasOwnProperty= Object.hasOwnProperty;\n var isArray = Array.isArray ? Array.isArray : function _isArray(obj) {\n return Object.prototype.toString.call(obj) === \"[object Array]\";\n };\n var defaultMaxListeners = 10;\n var nextTickSupported= typeof process=='object' && typeof process.nextTick=='function';\n var symbolsSupported= typeof Symbol==='function';\n var reflectSupported= typeof Reflect === 'object';\n var setImmediateSupported= typeof setImmediate === 'function';\n var _setImmediate= setImmediateSupported ? setImmediate : setTimeout;\n var ownKeys= symbolsSupported? (reflectSupported && typeof Reflect.ownKeys==='function'? Reflect.ownKeys : function(obj){\n var arr= Object.getOwnPropertyNames(obj);\n arr.push.apply(arr, Object.getOwnPropertySymbols(obj));\n return arr;\n }) : Object.keys;\n\n function init() {\n this._events = {};\n if (this._conf) {\n configure.call(this, this._conf);\n }\n }\n\n function configure(conf) {\n if (conf) {\n this._conf = conf;\n\n conf.delimiter && (this.delimiter = conf.delimiter);\n\n if(conf.maxListeners!==undefined){\n this._maxListeners= conf.maxListeners;\n }\n\n conf.wildcard && (this.wildcard = conf.wildcard);\n conf.newListener && (this._newListener = conf.newListener);\n conf.removeListener && (this._removeListener = conf.removeListener);\n conf.verboseMemoryLeak && (this.verboseMemoryLeak = conf.verboseMemoryLeak);\n conf.ignoreErrors && (this.ignoreErrors = conf.ignoreErrors);\n\n if (this.wildcard) {\n this.listenerTree = {};\n }\n }\n }\n\n function logPossibleMemoryLeak(count, eventName) {\n var errorMsg = '(node) warning: possible EventEmitter memory ' +\n 'leak detected. ' + count + ' listeners added. ' +\n 'Use emitter.setMaxListeners() to increase limit.';\n\n if(this.verboseMemoryLeak){\n errorMsg += ' Event name: ' + eventName + '.';\n }\n\n if(typeof process !== 'undefined' && process.emitWarning){\n var e = new Error(errorMsg);\n e.name = 'MaxListenersExceededWarning';\n e.emitter = this;\n e.count = count;\n process.emitWarning(e);\n } else {\n console.error(errorMsg);\n\n if (console.trace){\n console.trace();\n }\n }\n }\n\n var toArray = function (a, b, c) {\n var n = arguments.length;\n switch (n) {\n case 0:\n return [];\n case 1:\n return [a];\n case 2:\n return [a, b];\n case 3:\n return [a, b, c];\n default:\n var arr = new Array(n);\n while (n--) {\n arr[n] = arguments[n];\n }\n return arr;\n }\n };\n\n function toObject(keys, values) {\n var obj = {};\n var key;\n var len = keys.length;\n var valuesCount = values ? values.length : 0;\n for (var i = 0; i < len; i++) {\n key = keys[i];\n obj[key] = i < valuesCount ? values[i] : undefined;\n }\n return obj;\n }\n\n function TargetObserver(emitter, target, options) {\n this._emitter = emitter;\n this._target = target;\n this._listeners = {};\n this._listenersCount = 0;\n\n var on, off;\n\n if (options.on || options.off) {\n on = options.on;\n off = options.off;\n }\n\n if (target.addEventListener) {\n on = target.addEventListener;\n off = target.removeEventListener;\n } else if (target.addListener) {\n on = target.addListener;\n off = target.removeListener;\n } else if (target.on) {\n on = target.on;\n off = target.off;\n }\n\n if (!on && !off) {\n throw Error('target does not implement any known event API');\n }\n\n if (typeof on !== 'function') {\n throw TypeError('on method must be a function');\n }\n\n if (typeof off !== 'function') {\n throw TypeError('off method must be a function');\n }\n\n this._on = on;\n this._off = off;\n\n var _observers= emitter._observers;\n if(_observers){\n _observers.push(this);\n }else{\n emitter._observers= [this];\n }\n }\n\n Object.assign(TargetObserver.prototype, {\n subscribe: function(event, localEvent, reducer){\n var observer= this;\n var target= this._target;\n var emitter= this._emitter;\n var listeners= this._listeners;\n var handler= function(){\n var args= toArray.apply(null, arguments);\n var eventObj= {\n data: args,\n name: localEvent,\n original: event\n };\n if(reducer){\n var result= reducer.call(target, eventObj);\n if(result!==false){\n emitter.emit.apply(emitter, [eventObj.name].concat(args))\n }\n return;\n }\n emitter.emit.apply(emitter, [localEvent].concat(args));\n };\n\n\n if(listeners[event]){\n throw Error('Event \\'' + event + '\\' is already listening');\n }\n\n this._listenersCount++;\n\n if(emitter._newListener && emitter._removeListener && !observer._onNewListener){\n\n this._onNewListener = function (_event) {\n if (_event === localEvent && listeners[event] === null) {\n listeners[event] = handler;\n observer._on.call(target, event, handler);\n }\n };\n\n emitter.on('newListener', this._onNewListener);\n\n this._onRemoveListener= function(_event){\n if(_event === localEvent && !emitter.hasListeners(_event) && listeners[event]){\n listeners[event]= null;\n observer._off.call(target, event, handler);\n }\n };\n\n listeners[event]= null;\n\n emitter.on('removeListener', this._onRemoveListener);\n }else{\n listeners[event]= handler;\n observer._on.call(target, event, handler);\n }\n },\n\n unsubscribe: function(event){\n var observer= this;\n var listeners= this._listeners;\n var emitter= this._emitter;\n var handler;\n var events;\n var off= this._off;\n var target= this._target;\n var i;\n\n if(event && typeof event!=='string'){\n throw TypeError('event must be a string');\n }\n\n function clearRefs(){\n if(observer._onNewListener){\n emitter.off('newListener', observer._onNewListener);\n emitter.off('removeListener', observer._onRemoveListener);\n observer._onNewListener= null;\n observer._onRemoveListener= null;\n }\n var index= findTargetIndex.call(emitter, observer);\n emitter._observers.splice(index, 1);\n }\n\n if(event){\n handler= listeners[event];\n if(!handler) return;\n off.call(target, event, handler);\n delete listeners[event];\n if(!--this._listenersCount){\n clearRefs();\n }\n }else{\n events= ownKeys(listeners);\n i= events.length;\n while(i-->0){\n event= events[i];\n off.call(target, event, listeners[event]);\n }\n this._listeners= {};\n this._listenersCount= 0;\n clearRefs();\n }\n }\n });\n\n function resolveOptions(options, schema, reducers, allowUnknown) {\n var computedOptions = Object.assign({}, schema);\n\n if (!options) return computedOptions;\n\n if (typeof options !== 'object') {\n throw TypeError('options must be an object')\n }\n\n var keys = Object.keys(options);\n var length = keys.length;\n var option, value;\n var reducer;\n\n function reject(reason) {\n throw Error('Invalid \"' + option + '\" option value' + (reason ? '. Reason: ' + reason : ''))\n }\n\n for (var i = 0; i < length; i++) {\n option = keys[i];\n if (!allowUnknown && !hasOwnProperty.call(schema, option)) {\n throw Error('Unknown \"' + option + '\" option');\n }\n value = options[option];\n if (value !== undefined) {\n reducer = reducers[option];\n computedOptions[option] = reducer ? reducer(value, reject) : value;\n }\n }\n return computedOptions;\n }\n\n function constructorReducer(value, reject) {\n if (typeof value !== 'function' || !value.hasOwnProperty('prototype')) {\n reject('value must be a constructor');\n }\n return value;\n }\n\n function makeTypeReducer(types) {\n var message= 'value must be type of ' + types.join('|');\n var len= types.length;\n var firstType= types[0];\n var secondType= types[1];\n\n if (len === 1) {\n return function (v, reject) {\n if (typeof v === firstType) {\n return v;\n }\n reject(message);\n }\n }\n\n if (len === 2) {\n return function (v, reject) {\n var kind= typeof v;\n if (kind === firstType || kind === secondType) return v;\n reject(message);\n }\n }\n\n return function (v, reject) {\n var kind = typeof v;\n var i = len;\n while (i-- > 0) {\n if (kind === types[i]) return v;\n }\n reject(message);\n }\n }\n\n var functionReducer= makeTypeReducer(['function']);\n\n var objectFunctionReducer= makeTypeReducer(['object', 'function']);\n\n function makeCancelablePromise(Promise, executor, options) {\n var isCancelable;\n var callbacks;\n var timer= 0;\n var subscriptionClosed;\n\n var promise = new Promise(function (resolve, reject, onCancel) {\n options= resolveOptions(options, {\n timeout: 0,\n overload: false\n }, {\n timeout: function(value, reject){\n value*= 1;\n if (typeof value !== 'number' || value < 0 || !Number.isFinite(value)) {\n reject('timeout must be a positive number');\n }\n return value;\n }\n });\n\n isCancelable = !options.overload && typeof Promise.prototype.cancel === 'function' && typeof onCancel === 'function';\n\n function cleanup() {\n if (callbacks) {\n callbacks = null;\n }\n if (timer) {\n clearTimeout(timer);\n timer = 0;\n }\n }\n\n var _resolve= function(value){\n cleanup();\n resolve(value);\n };\n\n var _reject= function(err){\n cleanup();\n reject(err);\n };\n\n if (isCancelable) {\n executor(_resolve, _reject, onCancel);\n } else {\n callbacks = [function(reason){\n _reject(reason || Error('canceled'));\n }];\n executor(_resolve, _reject, function (cb) {\n if (subscriptionClosed) {\n throw Error('Unable to subscribe on cancel event asynchronously')\n }\n if (typeof cb !== 'function') {\n throw TypeError('onCancel callback must be a function');\n }\n callbacks.push(cb);\n });\n subscriptionClosed= true;\n }\n\n if (options.timeout > 0) {\n timer= setTimeout(function(){\n var reason= Error('timeout');\n reason.code = 'ETIMEDOUT'\n timer= 0;\n promise.cancel(reason);\n reject(reason);\n }, options.timeout);\n }\n });\n\n if (!isCancelable) {\n promise.cancel = function (reason) {\n if (!callbacks) {\n return;\n }\n var length = callbacks.length;\n for (var i = 1; i < length; i++) {\n callbacks[i](reason);\n }\n // internal callback to reject the promise\n callbacks[0](reason);\n callbacks = null;\n };\n }\n\n return promise;\n }\n\n function findTargetIndex(observer) {\n var observers = this._observers;\n if(!observers){\n return -1;\n }\n var len = observers.length;\n for (var i = 0; i < len; i++) {\n if (observers[i]._target === observer) return i;\n }\n return -1;\n }\n\n // Attention, function return type now is array, always !\n // It has zero elements if no any matches found and one or more\n // elements (leafs) if there are matches\n //\n function searchListenerTree(handlers, type, tree, i, typeLength) {\n if (!tree) {\n return null;\n }\n\n if (i === 0) {\n var kind = typeof type;\n if (kind === 'string') {\n var ns, n, l = 0, j = 0, delimiter = this.delimiter, dl = delimiter.length;\n if ((n = type.indexOf(delimiter)) !== -1) {\n ns = new Array(5);\n do {\n ns[l++] = type.slice(j, n);\n j = n + dl;\n } while ((n = type.indexOf(delimiter, j)) !== -1);\n\n ns[l++] = type.slice(j);\n type = ns;\n typeLength = l;\n } else {\n type = [type];\n typeLength = 1;\n }\n } else if (kind === 'object') {\n typeLength = type.length;\n } else {\n type = [type];\n typeLength = 1;\n }\n }\n\n var listeners= null, branch, xTree, xxTree, isolatedBranch, endReached, currentType = type[i],\n nextType = type[i + 1], branches, _listeners;\n\n if (i === typeLength) {\n //\n // If at the end of the event(s) list and the tree has listeners\n // invoke those listeners.\n //\n\n if(tree._listeners) {\n if (typeof tree._listeners === 'function') {\n handlers && handlers.push(tree._listeners);\n listeners = [tree];\n } else {\n handlers && handlers.push.apply(handlers, tree._listeners);\n listeners = [tree];\n }\n }\n } else {\n\n if (currentType === '*') {\n //\n // If the event emitted is '*' at this part\n // or there is a concrete match at this patch\n //\n branches = ownKeys(tree);\n n = branches.length;\n while (n-- > 0) {\n branch = branches[n];\n if (branch !== '_listeners') {\n _listeners = searchListenerTree(handlers, type, tree[branch], i + 1, typeLength);\n if (_listeners) {\n if (listeners) {\n listeners.push.apply(listeners, _listeners);\n } else {\n listeners = _listeners;\n }\n }\n }\n }\n return listeners;\n } else if (currentType === '**') {\n endReached = (i + 1 === typeLength || (i + 2 === typeLength && nextType === '*'));\n if (endReached && tree._listeners) {\n // The next element has a _listeners, add it to the handlers.\n listeners = searchListenerTree(handlers, type, tree, typeLength, typeLength);\n }\n\n branches = ownKeys(tree);\n n = branches.length;\n while (n-- > 0) {\n branch = branches[n];\n if (branch !== '_listeners') {\n if (branch === '*' || branch === '**') {\n if (tree[branch]._listeners && !endReached) {\n _listeners = searchListenerTree(handlers, type, tree[branch], typeLength, typeLength);\n if (_listeners) {\n if (listeners) {\n listeners.push.apply(listeners, _listeners);\n } else {\n listeners = _listeners;\n }\n }\n }\n _listeners = searchListenerTree(handlers, type, tree[branch], i, typeLength);\n } else if (branch === nextType) {\n _listeners = searchListenerTree(handlers, type, tree[branch], i + 2, typeLength);\n } else {\n // No match on this one, shift into the tree but not in the type array.\n _listeners = searchListenerTree(handlers, type, tree[branch], i, typeLength);\n }\n if (_listeners) {\n if (listeners) {\n listeners.push.apply(listeners, _listeners);\n } else {\n listeners = _listeners;\n }\n }\n }\n }\n return listeners;\n } else if (tree[currentType]) {\n listeners = searchListenerTree(handlers, type, tree[currentType], i + 1, typeLength);\n }\n }\n\n xTree = tree['*'];\n if (xTree) {\n //\n // If the listener tree will allow any match for this part,\n // then recursively explore all branches of the tree\n //\n searchListenerTree(handlers, type, xTree, i + 1, typeLength);\n }\n\n xxTree = tree['**'];\n if (xxTree) {\n if (i < typeLength) {\n if (xxTree._listeners) {\n // If we have a listener on a '**', it will catch all, so add its handler.\n searchListenerTree(handlers, type, xxTree, typeLength, typeLength);\n }\n\n // Build arrays of matching next branches and others.\n branches= ownKeys(xxTree);\n n= branches.length;\n while(n-->0){\n branch= branches[n];\n if (branch !== '_listeners') {\n if (branch === nextType) {\n // We know the next element will match, so jump twice.\n searchListenerTree(handlers, type, xxTree[branch], i + 2, typeLength);\n } else if (branch === currentType) {\n // Current node matches, move into the tree.\n searchListenerTree(handlers, type, xxTree[branch], i + 1, typeLength);\n } else {\n isolatedBranch = {};\n isolatedBranch[branch] = xxTree[branch];\n searchListenerTree(handlers, type, {'**': isolatedBranch}, i + 1, typeLength);\n }\n }\n }\n } else if (xxTree._listeners) {\n // We have reached the end and still on a '**'\n searchListenerTree(handlers, type, xxTree, typeLength, typeLength);\n } else if (xxTree['*'] && xxTree['*']._listeners) {\n searchListenerTree(handlers, type, xxTree['*'], typeLength, typeLength);\n }\n }\n\n return listeners;\n }\n\n function growListenerTree(type, listener, prepend) {\n var len = 0, j = 0, i, delimiter = this.delimiter, dl= delimiter.length, ns;\n\n if(typeof type==='string') {\n if ((i = type.indexOf(delimiter)) !== -1) {\n ns = new Array(5);\n do {\n ns[len++] = type.slice(j, i);\n j = i + dl;\n } while ((i = type.indexOf(delimiter, j)) !== -1);\n\n ns[len++] = type.slice(j);\n }else{\n ns= [type];\n len= 1;\n }\n }else{\n ns= type;\n len= type.length;\n }\n\n //\n // Looks for two consecutive '**', if so, don't add the event at all.\n //\n if (len > 1) {\n for (i = 0; i + 1 < len; i++) {\n if (ns[i] === '**' && ns[i + 1] === '**') {\n return;\n }\n }\n }\n\n\n\n var tree = this.listenerTree, name;\n\n for (i = 0; i < len; i++) {\n name = ns[i];\n\n tree = tree[name] || (tree[name] = {});\n\n if (i === len - 1) {\n if (!tree._listeners) {\n tree._listeners = listener;\n } else {\n if (typeof tree._listeners === 'function') {\n tree._listeners = [tree._listeners];\n }\n\n if (prepend) {\n tree._listeners.unshift(listener);\n } else {\n tree._listeners.push(listener);\n }\n\n if (\n !tree._listeners.warned &&\n this._maxListeners > 0 &&\n tree._listeners.length > this._maxListeners\n ) {\n tree._listeners.warned = true;\n logPossibleMemoryLeak.call(this, tree._listeners.length, name);\n }\n }\n return true;\n }\n }\n\n return true;\n }\n\n function collectTreeEvents(tree, events, root, asArray){\n var branches= ownKeys(tree);\n var i= branches.length;\n var branch, branchName, path;\n var hasListeners= tree['_listeners'];\n var isArrayPath;\n\n while(i-->0){\n branchName= branches[i];\n\n branch= tree[branchName];\n\n if(branchName==='_listeners'){\n path= root;\n }else {\n path = root ? root.concat(branchName) : [branchName];\n }\n\n isArrayPath= asArray || typeof branchName==='symbol';\n\n hasListeners && events.push(isArrayPath? path : path.join(this.delimiter));\n\n if(typeof branch==='object'){\n collectTreeEvents.call(this, branch, events, path, isArrayPath);\n }\n }\n\n return events;\n }\n\n function recursivelyGarbageCollect(root) {\n var keys = ownKeys(root);\n var i= keys.length;\n var obj, key, flag;\n while(i-->0){\n key = keys[i];\n obj = root[key];\n\n if(obj){\n flag= true;\n if(key !== '_listeners' && !recursivelyGarbageCollect(obj)){\n delete root[key];\n }\n }\n }\n\n return flag;\n }\n\n function Listener(emitter, event, listener){\n this.emitter= emitter;\n this.event= event;\n this.listener= listener;\n }\n\n Listener.prototype.off= function(){\n this.emitter.off(this.event, this.listener);\n return this;\n };\n\n function setupListener(event, listener, options){\n if (options === true) {\n promisify = true;\n } else if (options === false) {\n async = true;\n } else {\n if (!options || typeof options !== 'object') {\n throw TypeError('options should be an object or true');\n }\n var async = options.async;\n var promisify = options.promisify;\n var nextTick = options.nextTick;\n var objectify = options.objectify;\n }\n\n if (async || nextTick || promisify) {\n var _listener = listener;\n var _origin = listener._origin || listener;\n\n if (nextTick && !nextTickSupported) {\n throw Error('process.nextTick is not supported');\n }\n\n if (promisify === undefined) {\n promisify = listener.constructor.name === 'AsyncFunction';\n }\n\n listener = function () {\n var args = arguments;\n var context = this;\n var event = this.event;\n\n return promisify ? (nextTick ? Promise.resolve() : new Promise(function (resolve) {\n _setImmediate(resolve);\n }).then(function () {\n context.event = event;\n return _listener.apply(context, args)\n })) : (nextTick ? process.nextTick : _setImmediate)(function () {\n context.event = event;\n _listener.apply(context, args)\n });\n };\n\n listener._async = true;\n listener._origin = _origin;\n }\n\n return [listener, objectify? new Listener(this, event, listener): this];\n }\n\n function EventEmitter(conf) {\n this._events = {};\n this._newListener = false;\n this._removeListener = false;\n this.verboseMemoryLeak = false;\n configure.call(this, conf);\n }\n\n EventEmitter.EventEmitter2 = EventEmitter; // backwards compatibility for exporting EventEmitter property\n\n EventEmitter.prototype.listenTo= function(target, events, options){\n if(typeof target!=='object'){\n throw TypeError('target musts be an object');\n }\n\n var emitter= this;\n\n options = resolveOptions(options, {\n on: undefined,\n off: undefined,\n reducers: undefined\n }, {\n on: functionReducer,\n off: functionReducer,\n reducers: objectFunctionReducer\n });\n\n function listen(events){\n if(typeof events!=='object'){\n throw TypeError('events must be an object');\n }\n\n var reducers= options.reducers;\n var index= findTargetIndex.call(emitter, target);\n var observer;\n\n if(index===-1){\n observer= new TargetObserver(emitter, target, options);\n }else{\n observer= emitter._observers[index];\n }\n\n var keys= ownKeys(events);\n var len= keys.length;\n var event;\n var isSingleReducer= typeof reducers==='function';\n\n for(var i=0; i<len; i++){\n event= keys[i];\n observer.subscribe(\n event,\n events[event] || event,\n isSingleReducer ? reducers : reducers && reducers[event]\n );\n }\n }\n\n isArray(events)?\n listen(toObject(events)) :\n (typeof events==='string'? listen(toObject(events.split(/\\s+/))): listen(events));\n\n return this;\n };\n\n EventEmitter.prototype.stopListeningTo = function (target, event) {\n var observers = this._observers;\n\n if(!observers){\n return false;\n }\n\n var i = observers.length;\n var observer;\n var matched= false;\n\n if(target && typeof target!=='object'){\n throw TypeError('target should be an object');\n }\n\n while (i-- > 0) {\n observer = observers[i];\n if (!target || observer._target === target) {\n observer.unsubscribe(event);\n matched= true;\n }\n }\n\n return matched;\n };\n\n // By default EventEmitters will print a warning if more than\n // 10 listeners are added to it. This is a useful default which\n // helps finding memory leaks.\n //\n // Obviously not all Emitters should be limited to 10. This function allows\n // that to be increased. Set to zero for unlimited.\n\n EventEmitter.prototype.delimiter = '.';\n\n EventEmitter.prototype.setMaxListeners = function(n) {\n if (n !== undefined) {\n this._maxListeners = n;\n if (!this._conf) this._conf = {};\n this._conf.maxListeners = n;\n }\n };\n\n EventEmitter.prototype.getMaxListeners = function() {\n return this._maxListeners;\n };\n\n EventEmitter.prototype.event = '';\n\n EventEmitter.prototype.once = function(event, fn, options) {\n return this._once(event, fn, false, options);\n };\n\n EventEmitter.prototype.prependOnceListener = function(event, fn, options) {\n return this._once(event, fn, true, options);\n };\n\n EventEmitter.prototype._once = function(event, fn, prepend, options) {\n return this._many(event, 1, fn, prepend, options);\n };\n\n EventEmitter.prototype.many = function(event, ttl, fn, options) {\n return this.