@esri/telemetry
Advanced tools
Comparing version 4.1.3 to 4.2.0
define((function () { 'use strict'; | ||
function anonymize(user) { | ||
if (!user) return undefined; | ||
return CryptoJS.SHA256(user).toString(CryptoJS.enc.Hex); | ||
} | ||
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
var internalOrgs = ['esri.com', 'esriuk.com', 'esri.de', 'esri.ca', 'esrifrance.fr', 'esri.nl', 'esri-portugal.pt', 'esribulgaria.com', 'esri.fi', 'esri.kr', 'esrimalaysia.com.my', 'esri.es', 'esriaustralia.com.au', 'esri-southafrica.com', 'esri.cl', 'esrichina.com.cn', 'esri.co', 'esriturkey.com.tr', 'geodata.no', 'esriitalia.it', 'esri.pl']; | ||
function commonjsRequire (path) { | ||
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.'); | ||
} | ||
var storage = { | ||
storage: {}, | ||
memory: true, | ||
get: function get(key) { | ||
var stored = void 0; | ||
try { | ||
stored = window.localStorage && window.localStorage.getItem(key) || this.storage[key]; | ||
} catch (e) { | ||
stored = this.storage[key]; | ||
} | ||
if (stored) { | ||
try { | ||
return JSON.parse(stored); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
}, | ||
set: function set(key, value) { | ||
// handle Safari private mode (setItem is not allowed) | ||
value = JSON.stringify(value); | ||
try { | ||
window.localStorage.setItem(key, value); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
this.storage[key] = value; | ||
} | ||
}, | ||
delete: function _delete(key) { | ||
try { | ||
window.localStorage.removeItem(key); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
delete this.storage[key]; | ||
} | ||
} | ||
}; | ||
var sha256$1 = {exports: {}}; | ||
/* | ||
* Determines whether or not the telemetry library should be enabled based on passed in options | ||
*/ | ||
function telemetryEnabled() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var core = {exports: {}}; | ||
var portal = options.portal || {}; | ||
(function (module, exports) { | ||
(function (root, factory) { | ||
{ | ||
// CommonJS | ||
module.exports = factory(); | ||
} | ||
}(commonjsGlobal, function () { | ||
if (options.disabled) { | ||
// Tracking is manually disabled | ||
return false; | ||
} | ||
/*globals window, global, require*/ | ||
if (_hasDoNotTrackEnabled()) { | ||
// user's browser has turned off tracking | ||
return false; | ||
} | ||
/** | ||
* CryptoJS core components. | ||
*/ | ||
var CryptoJS = CryptoJS || (function (Math, undefined$1) { | ||
if (typeof portal.eueiEnabled !== 'undefined' && portal.eueiEnabled === false) { | ||
// Portal does not allow tracking | ||
return false; | ||
} | ||
var crypto; | ||
if (portal.eueiEnabled && portal.user && portal.user.orgId === portal.id) { | ||
// Portal allows tracking; except when user is anonymous or doesn't belong to portal's org | ||
return true; | ||
} | ||
// Native crypto from window (Browser) | ||
if (typeof window !== 'undefined' && window.crypto) { | ||
crypto = window.crypto; | ||
} | ||
if (portal.user && !portal.user.orgId && portal.ipCntryCode === 'US') { | ||
// Public user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
// Native crypto in web worker (Browser) | ||
if (typeof self !== 'undefined' && self.crypto) { | ||
crypto = self.crypto; | ||
} | ||
if (!portal.user && portal.ipCntryCode === 'US') { | ||
// Anonymous user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
// Native crypto from worker | ||
if (typeof globalThis !== 'undefined' && globalThis.crypto) { | ||
crypto = globalThis.crypto; | ||
} | ||
if (Object.keys(portal).length > 0) { | ||
// Initialized with a Portal object but does not meet tracking conditions | ||
return false; | ||
} | ||
// Native (experimental IE 11) crypto from window (Browser) | ||
if (!crypto && typeof window !== 'undefined' && window.msCrypto) { | ||
crypto = window.msCrypto; | ||
} | ||
// Default condition not initialized with a Portal-Self object | ||
return true; | ||
} | ||
// Native crypto from global (NodeJS) | ||
if (!crypto && typeof commonjsGlobal !== 'undefined' && commonjsGlobal.crypto) { | ||
crypto = commonjsGlobal.crypto; | ||
} | ||
function _hasDoNotTrackEnabled() { | ||
return (typeof navigator !== 'undefined' && navigator.doNotTrack) === '1' || typeof window !== 'undefined' && window.doNotTrack === '1'; | ||
} | ||
// Native crypto import via require (NodeJS) | ||
if (!crypto && typeof commonjsRequire === 'function') { | ||
try { | ||
crypto = require('crypto'); | ||
} catch (err) {} | ||
} | ||
/* | ||
(c) 2009-2013 by Jeff Mott. All rights reserved. | ||
/* | ||
* Cryptographically secure pseudorandom number generator | ||
* | ||
* As Math.random() is cryptographically not safe to use | ||
*/ | ||
var cryptoSecureRandomInt = function () { | ||
if (crypto) { | ||
// Use getRandomValues method (Browser) | ||
if (typeof crypto.getRandomValues === 'function') { | ||
try { | ||
return crypto.getRandomValues(new Uint32Array(1))[0]; | ||
} catch (err) {} | ||
} | ||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
// Use randomBytes method (NodeJS) | ||
if (typeof crypto.randomBytes === 'function') { | ||
try { | ||
return crypto.randomBytes(4).readInt32LE(); | ||
} catch (err) {} | ||
} | ||
} | ||
Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer. | ||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation or other materials provided with the distribution. | ||
Neither the name CryptoJS nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS," AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
var CryptoJS = function (h, s) { | ||
var f = {}, | ||
g = f.lib = {}, | ||
q = function q() {}, | ||
m = g.Base = { | ||
extend: function extend(a) { | ||
q.prototype = this; | ||
var c = new q(); | ||
a && c.mixIn(a); | ||
c.hasOwnProperty('init') || (c.init = function () { | ||
c.$super.init.apply(this, arguments); | ||
}); | ||
c.init.prototype = c; | ||
c.$super = this; | ||
return c; | ||
}, | ||
create: function create() { | ||
var a = this.extend(); | ||
a.init.apply(a, arguments); | ||
return a; | ||
}, | ||
init: function init() {}, | ||
mixIn: function mixIn(a) { | ||
for (var c in a) { | ||
a.hasOwnProperty(c) && (this[c] = a[c]); | ||
}a.hasOwnProperty('toString') && (this.toString = a.toString); | ||
}, | ||
clone: function clone() { | ||
return this.init.prototype.extend(this); | ||
} | ||
}, | ||
r = g.WordArray = m.extend({ | ||
init: function init(a, c) { | ||
a = this.words = a || []; | ||
this.sigBytes = c != s ? c : 4 * a.length; | ||
}, | ||
toString: function toString(a) { | ||
return (a || k).stringify(this); | ||
}, | ||
concat: function concat(a) { | ||
var c = this.words, | ||
d = a.words, | ||
b = this.sigBytes; | ||
a = a.sigBytes; | ||
this.clamp(); | ||
if (b % 4) for (var e = 0; e < a; e++) { | ||
c[b + e >>> 2] |= (d[e >>> 2] >>> 24 - 8 * (e % 4) & 255) << 24 - 8 * ((b + e) % 4); | ||
} else if (d.length > 65535) for (e = 0; e < a; e += 4) { | ||
c[b + e >>> 2] = d[e >>> 2]; | ||
} else c.push.apply(c, d); | ||
this.sigBytes += a; | ||
return this; | ||
}, | ||
clamp: function clamp() { | ||
var a = this.words, | ||
c = this.sigBytes; | ||
a[c >>> 2] &= 4294967295 << 32 - 8 * (c % 4); | ||
a.length = h.ceil(c / 4); | ||
}, | ||
clone: function clone() { | ||
var a = m.clone.call(this); | ||
a.words = this.words.slice(0); | ||
return a; | ||
}, | ||
random: function random(a) { | ||
for (var c = [], d = 0; d < a; d += 4) { | ||
c.push(4294967296 * h.random() | 0); | ||
}return new r.init(c, a); | ||
} | ||
}), | ||
l = f.enc = {}, | ||
k = l.Hex = { | ||
stringify: function stringify(a) { | ||
var c = a.words; | ||
a = a.sigBytes; | ||
for (var d = [], b = 0; b < a; b++) { | ||
var e = c[b >>> 2] >>> 24 - 8 * (b % 4) & 255; | ||
d.push((e >>> 4).toString(16)); | ||
d.push((e & 15).toString(16)); | ||
} | ||
return d.join(''); | ||
}, | ||
parse: function parse(a) { | ||
for (var c = a.length, d = [], b = 0; b < c; b += 2) { | ||
d[b >>> 3] |= parseInt(a.substr(b, 2), 16) << 24 - 4 * (b % 8); | ||
} | ||
return new r.init(d, c / 2); | ||
} | ||
}, | ||
n = l.Latin1 = { | ||
stringify: function stringify(a) { | ||
var c = a.words; | ||
a = a.sigBytes; | ||
for (var d = [], b = 0; b < a; b++) { | ||
d.push(String.fromCharCode(c[b >>> 2] >>> 24 - 8 * (b % 4) & 255)); | ||
}return d.join(''); | ||
}, | ||
parse: function parse(a) { | ||
for (var c = a.length, d = [], b = 0; b < c; b++) { | ||
d[b >>> 2] |= (a.charCodeAt(b) & 255) << 24 - 8 * (b % 4); | ||
}return new r.init(d, c); | ||
} | ||
}, | ||
j = l.Utf8 = { | ||
stringify: function stringify(a) { | ||
try { | ||
return decodeURIComponent(escape(n.stringify(a))); | ||
} catch (c) { | ||
throw Error('Malformed UTF-8 data'); | ||
} | ||
}, | ||
parse: function parse(a) { | ||
return n.parse(unescape(encodeURIComponent(a))); | ||
} | ||
}, | ||
u = g.BufferedBlockAlgorithm = m.extend({ | ||
reset: function reset() { | ||
this._data = new r.init(); | ||
this._nDataBytes = 0; | ||
}, | ||
_append: function _append(a) { | ||
typeof a === 'string' && (a = j.parse(a)); | ||
this._data.concat(a); | ||
this._nDataBytes += a.sigBytes; | ||
}, | ||
_process: function _process(a) { | ||
var c = this._data, | ||
d = c.words, | ||
b = c.sigBytes, | ||
e = this.blockSize, | ||
f = b / (4 * e), | ||
f = a ? h.ceil(f) : h.max((f | 0) - this._minBufferSize, 0); | ||
a = f * e; | ||
b = h.min(4 * a, b); | ||
if (a) { | ||
for (var g = 0; g < a; g += e) { | ||
this._doProcessBlock(d, g); | ||
}g = d.splice(0, a); | ||
c.sigBytes -= b; | ||
} | ||
return new r.init(g, b); | ||
}, | ||
clone: function clone() { | ||
var a = m.clone.call(this); | ||
a._data = this._data.clone(); | ||
return a; | ||
}, | ||
_minBufferSize: 0 | ||
}); | ||
g.Hasher = u.extend({ | ||
cfg: m.extend(), | ||
init: function init(a) { | ||
this.cfg = this.cfg.extend(a); | ||
this.reset(); | ||
}, | ||
reset: function reset() { | ||
u.reset.call(this); | ||
this._doReset(); | ||
}, | ||
update: function update(a) { | ||
this._append(a); | ||
this._process(); | ||
return this; | ||
}, | ||
finalize: function finalize(a) { | ||
a && this._append(a); | ||
return this._doFinalize(); | ||
}, | ||
blockSize: 16, | ||
_createHelper: function _createHelper(a) { | ||
return function (c, d) { | ||
return new a.init(d).finalize(c); | ||
}; | ||
}, | ||
_createHmacHelper: function _createHmacHelper(a) { | ||
return function (c, d) { | ||
return new t.HMAC.init(a, d).finalize(c); | ||
}; | ||
} | ||
}); | ||
var t = f.algo = {}; | ||
return f; | ||
}(Math); | ||
(function (h) { | ||
for (var s = CryptoJS, f = s.lib, g = f.WordArray, q = f.Hasher, f = s.algo, m = [], r = [], l = function l(a) { | ||
return 4294967296 * (a - (a | 0)) | 0; | ||
}, k = 2, n = 0; n < 64;) { | ||
var j; | ||
a: { | ||
j = k; | ||
for (var u = h.sqrt(j), t = 2; t <= u; t++) { | ||
if (!(j % t)) { | ||
j = !1; | ||
break a; | ||
} | ||
}j = !0; | ||
} | ||
j && (n < 8 && (m[n] = l(h.pow(k, 0.5))), r[n] = l(h.pow(k, 1 / 3)), n++); | ||
k++; | ||
} | ||
var a = [], | ||
f = f.SHA256 = q.extend({ | ||
_doReset: function _doReset() { | ||
this._hash = new g.init(m.slice(0)); | ||
}, | ||
_doProcessBlock: function _doProcessBlock(c, d) { | ||
for (var b = this._hash.words, e = b[0], f = b[1], g = b[2], j = b[3], h = b[4], m = b[5], n = b[6], q = b[7], p = 0; p < 64; p++) { | ||
if (p < 16) { | ||
a[p] = c[d + p] | 0; | ||
} else { | ||
var k = a[p - 15], | ||
l = a[p - 2]; | ||
a[p] = ((k << 25 | k >>> 7) ^ (k << 14 | k >>> 18) ^ k >>> 3) + a[p - 7] + ((l << 15 | l >>> 17) ^ (l << 13 | l >>> 19) ^ l >>> 10) + a[p - 16]; | ||
} | ||
k = q + ((h << 26 | h >>> 6) ^ (h << 21 | h >>> 11) ^ (h << 7 | h >>> 25)) + (h & m ^ ~h & n) + r[p] + a[p]; | ||
l = ((e << 30 | e >>> 2) ^ (e << 19 | e >>> 13) ^ (e << 10 | e >>> 22)) + (e & f ^ e & g ^ f & g); | ||
q = n; | ||
n = m; | ||
m = h; | ||
h = j + k | 0; | ||
j = g; | ||
g = f; | ||
f = e; | ||
e = k + l | 0; | ||
} | ||
b[0] = b[0] + e | 0; | ||
b[1] = b[1] + f | 0; | ||
b[2] = b[2] + g | 0; | ||
b[3] = b[3] + j | 0; | ||
b[4] = b[4] + h | 0; | ||
b[5] = b[5] + m | 0; | ||
b[6] = b[6] + n | 0; | ||
b[7] = b[7] + q | 0; | ||
}, | ||
_doFinalize: function _doFinalize() { | ||
var a = this._data, | ||
d = a.words, | ||
b = 8 * this._nDataBytes, | ||
e = 8 * a.sigBytes; | ||
d[e >>> 5] |= 128 << 24 - e % 32; | ||
d[(e + 64 >>> 9 << 4) + 14] = h.floor(b / 4294967296); | ||
d[(e + 64 >>> 9 << 4) + 15] = b; | ||
a.sigBytes = 4 * d.length; | ||
this._process(); | ||
return this._hash; | ||
}, | ||
clone: function clone() { | ||
var a = q.clone.call(this); | ||
a._hash = this._hash.clone(); | ||
return a; | ||
} | ||
}); | ||
s.SHA256 = q._createHelper(f); | ||
s.HmacSHA256 = q._createHmacHelper(f); | ||
})(Math); | ||
(function () { | ||
var h = CryptoJS, | ||
s = h.enc.Utf8; | ||
h.algo.HMAC = h.lib.Base.extend({ | ||
init: function init(f, g) { | ||
f = this._hasher = new f.init(); | ||
typeof g === 'string' && (g = s.parse(g)); | ||
var h = f.blockSize, | ||
m = 4 * h; | ||
g.sigBytes > m && (g = f.finalize(g)); | ||
g.clamp(); | ||
for (var r = this._oKey = g.clone(), l = this._iKey = g.clone(), k = r.words, n = l.words, j = 0; j < h; j++) { | ||
k[j] ^= 1549556828, n[j] ^= 909522486; | ||
}r.sigBytes = l.sigBytes = m; | ||
this.reset(); | ||
}, | ||
reset: function reset() { | ||
var f = this._hasher; | ||
f.reset(); | ||
f.update(this._iKey); | ||
}, | ||
update: function update(f) { | ||
this._hasher.update(f); | ||
return this; | ||
}, | ||
finalize: function finalize(f) { | ||
var g = this._hasher; | ||
f = g.finalize(f); | ||
g.reset(); | ||
return g.finalize(this._oKey.clone().concat(f)); | ||
} | ||
}); | ||
})(); | ||
throw new Error('Native crypto module could not be used to get secure random number.'); | ||
}; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
/* | ||
* Local polyfill of Object.create | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
*/ | ||
var create = Object.create || (function () { | ||
function F() {} | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (obj) { | ||
var subtype; | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
F.prototype = obj; | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
subtype = new F(); | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
F.prototype = null; | ||
return target; | ||
}; | ||
return subtype; | ||
}; | ||
}()); | ||
var slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
/** | ||
* CryptoJS namespace. | ||
*/ | ||
var C = {}; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
/** | ||
* Library namespace. | ||
*/ | ||
var C_lib = C.lib = {}; | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
/** | ||
* Base object for prototypal inheritance. | ||
*/ | ||
var Base = C_lib.Base = (function () { | ||
return _arr; | ||
} | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
return { | ||
/** | ||
* Creates a new object that inherits from this object. | ||
* | ||
* @param {Object} overrides Properties to copy into the new object. | ||
* | ||
* @return {Object} The new object. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var MyType = CryptoJS.lib.Base.extend({ | ||
* field: 'value', | ||
* | ||
* method: function () { | ||
* } | ||
* }); | ||
*/ | ||
extend: function (overrides) { | ||
// Spawn | ||
var subtype = create(this); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
// Augment | ||
if (overrides) { | ||
subtype.mixIn(overrides); | ||
} | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
// Create default initializer | ||
if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { | ||
subtype.init = function () { | ||
subtype.$super.init.apply(this, arguments); | ||
}; | ||
} | ||
var Telemetry = function () { | ||
function Telemetry(options) { | ||
classCallCheck(this, Telemetry); | ||
// Initializer's prototype is the subtype object | ||
subtype.init.prototype = subtype; | ||
// Make sure failure to init this library cannot have side-effects | ||
try { | ||
this.trackers = []; | ||
this.workflows = {}; | ||
this.test = options.test; | ||
this.debug = options.debug; | ||
this.disabled = !telemetryEnabled(options); | ||
// Reference supertype | ||
subtype.$super = this; | ||
if (this.disabled) { | ||
console.log('Telemetry Disabled'); | ||
} | ||
return subtype; | ||
}, | ||
if (options.portal && options.portal.user) { | ||
var subscriptionInfo = options.portal.subscriptionInfo || {}; | ||
this.setUser(options.portal.user, subscriptionInfo.type); | ||
} else if (options.user) { | ||
this.setUser(options.user); | ||
} | ||
/** | ||
* Extends this object and runs the init method. | ||
* Arguments to create() will be passed to init(). | ||
* | ||
* @return {Object} The new object. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var instance = MyType.create(); | ||
*/ | ||
create: function () { | ||
var instance = this.extend(); | ||
instance.init.apply(instance, arguments); | ||
if (!this.disabled) { | ||
this._initializeTrackers(options); | ||
} | ||
} catch (e) { | ||
console.error('Telemetry Disabled'); | ||
console.error(e); | ||
this.disabled = true; | ||
} | ||
} | ||
return instance; | ||
}, | ||
createClass(Telemetry, [{ | ||
key: '_initializeTrackers', | ||
value: function _initializeTrackers(options) { | ||
if (options.plugins) { | ||
var _trackers; | ||
/** | ||
* Initializes a newly created object. | ||
* Override this method to add some logic when your objects are created. | ||
* | ||
* @example | ||
* | ||
* var MyType = CryptoJS.lib.Base.extend({ | ||
* init: function () { | ||
* // ... | ||
* } | ||
* }); | ||
*/ | ||
init: function () { | ||
}, | ||
(_trackers = this.trackers).push.apply(_trackers, toConsumableArray(options.plugins)); | ||
} | ||
/** | ||
* Copies properties into this object. | ||
* | ||
* @param {Object} properties The properties to mix in. | ||
* | ||
* @example | ||
* | ||
* MyType.mixIn({ | ||
* field: 'value' | ||
* }); | ||
*/ | ||
mixIn: function (properties) { | ||
for (var propertyName in properties) { | ||
if (properties.hasOwnProperty(propertyName)) { | ||
this[propertyName] = properties[propertyName]; | ||
} | ||
} | ||
if (!this.trackers.length) { | ||
console.error(new Error('No trackers configured')); | ||
} | ||
} | ||
}, { | ||
key: 'setUser', | ||
value: function setUser() { | ||
var user = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var orgType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Public'; | ||
// IE won't copy toString using the loop above | ||
if (properties.hasOwnProperty('toString')) { | ||
this.toString = properties.toString; | ||
} | ||
}, | ||
user = typeof user === 'string' ? { username: user } : user; | ||
this.user = user; | ||
this.user.accountType = orgType; | ||
var internalDomain = void 0; | ||
/** | ||
* Creates a copy of this object. | ||
* | ||
* @return {Object} The clone. | ||
* | ||
* @example | ||
* | ||
* var clone = instance.clone(); | ||
*/ | ||
clone: function () { | ||
return this.init.prototype.extend(this); | ||
} | ||
}; | ||
}()); | ||
if (user.email && user.email.split) { | ||
var domain = user.email.split('@')[1]; | ||
internalDomain = internalOrgs.filter(function (org) { | ||
return domain === org; | ||
}).length > 0; | ||
} | ||
/** | ||
* An array of 32-bit words. | ||
* | ||
* @property {Array} words The array of 32-bit words. | ||
* @property {number} sigBytes The number of significant bytes in this word array. | ||
*/ | ||
var WordArray = C_lib.WordArray = Base.extend({ | ||
/** | ||
* Initializes a newly created word array. | ||
* | ||
* @param {Array} words (Optional) An array of 32-bit words. | ||
* @param {number} sigBytes (Optional) The number of significant bytes in the words. | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.lib.WordArray.create(); | ||
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); | ||
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); | ||
*/ | ||
init: function (words, sigBytes) { | ||
words = this.words = words || []; | ||
if (internalDomain || ['In House', 'Demo and Marketing'].indexOf(orgType) > -1) { | ||
this.user.internalUser = true; | ||
} | ||
} | ||
}, { | ||
key: 'logPageView', | ||
value: function logPageView(page) { | ||
var event = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
if (sigBytes != undefined$1) { | ||
this.sigBytes = sigBytes; | ||
} else { | ||
this.sigBytes = words.length * 4; | ||
} | ||
}, | ||
var attributes = this.preProcess(event, options); | ||
/** | ||
* Converts this word array to a string. | ||
* | ||
* @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex | ||
* | ||
* @return {string} The stringified word array. | ||
* | ||
* @example | ||
* | ||
* var string = wordArray + ''; | ||
* var string = wordArray.toString(); | ||
* var string = wordArray.toString(CryptoJS.enc.Utf8); | ||
*/ | ||
toString: function (encoder) { | ||
return (encoder || Hex).stringify(this); | ||
}, | ||
if (this.debug) { | ||
console.log('Tracking page view', JSON.stringify(attributes)); | ||
} | ||
/** | ||
* Concatenates a word array to this word array. | ||
* | ||
* @param {WordArray} wordArray The word array to append. | ||
* | ||
* @return {WordArray} This word array. | ||
* | ||
* @example | ||
* | ||
* wordArray1.concat(wordArray2); | ||
*/ | ||
concat: function (wordArray) { | ||
// Shortcuts | ||
var thisWords = this.words; | ||
var thatWords = wordArray.words; | ||
var thisSigBytes = this.sigBytes; | ||
var thatSigBytes = wordArray.sigBytes; | ||
if (this.test && !this.disabled) { | ||
return attributes; | ||
} | ||
// Clamp excess bits | ||
this.clamp(); | ||
var trackers = this.trackers.filter(function (_ref) { | ||
var disabled = _ref.disabled; | ||
return !disabled; | ||
}); | ||
// Concat | ||
if (thisSigBytes % 4) { | ||
// Copy one byte at a time | ||
for (var i = 0; i < thatSigBytes; i++) { | ||
var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); | ||
} | ||
} else { | ||
// Copy one word at a time | ||
for (var j = 0; j < thatSigBytes; j += 4) { | ||
thisWords[(thisSigBytes + j) >>> 2] = thatWords[j >>> 2]; | ||
} | ||
} | ||
this.sigBytes += thatSigBytes; | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Page view was not logged because no trackers are configured.')); | ||
} | ||
// Chainable | ||
return this; | ||
}, | ||
return false; | ||
} | ||
/** | ||
* Removes insignificant bits. | ||
* | ||
* @example | ||
* | ||
* wordArray.clamp(); | ||
*/ | ||
clamp: function () { | ||
// Shortcuts | ||
var words = this.words; | ||
var sigBytes = this.sigBytes; | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
}); | ||
// Clamp | ||
words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); | ||
words.length = Math.ceil(sigBytes / 4); | ||
}, | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logEvent', | ||
value: function logEvent(event) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* Creates a copy of this word array. | ||
* | ||
* @return {WordArray} The clone. | ||
* | ||
* @example | ||
* | ||
* var clone = wordArray.clone(); | ||
*/ | ||
clone: function () { | ||
var clone = Base.clone.call(this); | ||
clone.words = this.words.slice(0); | ||
event = this.preProcess(event, options); | ||
return clone; | ||
}, | ||
if (this.debug) { | ||
console.log('Tracking event', JSON.stringify(event)); | ||
} | ||
/** | ||
* Creates a word array filled with random bytes. | ||
* | ||
* @param {number} nBytes The number of random bytes to generate. | ||
* | ||
* @return {WordArray} The random word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.lib.WordArray.random(16); | ||
*/ | ||
random: function (nBytes) { | ||
var words = []; | ||
if (this.test) { | ||
return event; | ||
} | ||
for (var i = 0; i < nBytes; i += 4) { | ||
words.push(cryptoSecureRandomInt()); | ||
} | ||
var trackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
return new WordArray.init(words, nBytes); | ||
} | ||
}); | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Event was not logged because no trackers are configured.')); | ||
} | ||
/** | ||
* Encoder namespace. | ||
*/ | ||
var C_enc = C.enc = {}; | ||
return false; | ||
} | ||
/** | ||
* Hex encoding strategy. | ||
*/ | ||
var Hex = C_enc.Hex = { | ||
/** | ||
* Converts a word array to a hex string. | ||
* | ||
* @param {WordArray} wordArray The word array. | ||
* | ||
* @return {string} The hex string. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var hexString = CryptoJS.enc.Hex.stringify(wordArray); | ||
*/ | ||
stringify: function (wordArray) { | ||
// Shortcuts | ||
var words = wordArray.words; | ||
var sigBytes = wordArray.sigBytes; | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
}); | ||
// Convert | ||
var hexChars = []; | ||
for (var i = 0; i < sigBytes; i++) { | ||
var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
hexChars.push((bite >>> 4).toString(16)); | ||
hexChars.push((bite & 0x0f).toString(16)); | ||
} | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logError', | ||
value: function logError() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return hexChars.join(''); | ||
}, | ||
var event = _extends({ eventType: 'error' }, options); | ||
this.logEvent(event); | ||
} | ||
}, { | ||
key: 'startWorkflow', | ||
value: function startWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* Converts a hex string to a word array. | ||
* | ||
* @param {string} hexStr The hex string. | ||
* | ||
* @return {WordArray} The word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.enc.Hex.parse(hexString); | ||
*/ | ||
parse: function (hexStr) { | ||
// Shortcut | ||
var hexStrLength = hexStr.length; | ||
var workflow = { | ||
name: name, | ||
start: Date.now(), | ||
steps: [], | ||
workflowId: Math.floor((1 + Math.random()) * 0x100000000000).toString(16) | ||
}; | ||
this._saveWorkflow(workflow); | ||
var workflowObj = _extends({ name: name, step: 'start' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
return workflow; | ||
} | ||
}, { | ||
key: 'stepWorkflow', | ||
value: function stepWorkflow(name, step) { | ||
var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
// Convert | ||
var words = []; | ||
for (var i = 0; i < hexStrLength; i += 2) { | ||
words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); | ||
} | ||
//TODO: check if the check for attributes being a string is useful or can be removed | ||
var details = typeof attributes === 'string' ? attributes : attributes.details; | ||
var workflowObj = _extends({ name: name, step: step, details: details }, attributes); | ||
this._logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'endWorkflow', | ||
value: function endWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return new WordArray.init(words, hexStrLength / 2); | ||
} | ||
}; | ||
var workflowObj = _extends({ name: name, step: 'finish' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'cancelWorkflow', | ||
value: function cancelWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* Latin1 encoding strategy. | ||
*/ | ||
var Latin1 = C_enc.Latin1 = { | ||
/** | ||
* Converts a word array to a Latin1 string. | ||
* | ||
* @param {WordArray} wordArray The word array. | ||
* | ||
* @return {string} The Latin1 string. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); | ||
*/ | ||
stringify: function (wordArray) { | ||
// Shortcuts | ||
var words = wordArray.words; | ||
var sigBytes = wordArray.sigBytes; | ||
var workflowObj = _extends({ name: name, step: 'cancel' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'getWorkflow', | ||
value: function getWorkflow(name) { | ||
var workflow = storage.get('TELEMETRY-WORKFLOW:' + name); | ||
// do not let old workflows be returned | ||
if (workflow) { | ||
var workflowAge = Date.now() - workflow.start; | ||
var timeout = 30 * 60 * 1000; | ||
if (workflowAge < timeout) { | ||
return workflow; | ||
} else { | ||
this._deleteWorkflow(workflow); | ||
} | ||
} | ||
} | ||
}, { | ||
key: '_saveWorkflow', | ||
value: function _saveWorkflow(workflow) { | ||
storage.set('TELEMETRY-WORKFLOW:' + workflow.name, workflow); | ||
} | ||
}, { | ||
key: '_deleteWorkflow', | ||
value: function _deleteWorkflow(workflow) { | ||
storage.delete('TELEMETRY-WORKFLOW:' + workflow.name); | ||
} | ||
}, { | ||
key: '_logWorkflow', | ||
value: function _logWorkflow() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
// Convert | ||
var latin1Chars = []; | ||
for (var i = 0; i < sigBytes; i++) { | ||
var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
latin1Chars.push(String.fromCharCode(bite)); | ||
} | ||
/* | ||
const workflow = { | ||
name: 'add layer to map', | ||
step: 'start', | ||
details: 'some details about the step' | ||
} | ||
*/ | ||
options = this.preProcess(options); | ||
var workflow = this.getWorkflow(options.name); | ||
return latin1Chars.join(''); | ||
}, | ||
if (!workflow) { | ||
this.startWorkflow(options.name); | ||
workflow = this.getWorkflow(options.name); | ||
} | ||
workflow.steps.push(options.step); | ||
workflow.duration = (Date.now() - workflow.start) / 1000; | ||
/** | ||
* Converts a Latin1 string to a word array. | ||
* | ||
* @param {string} latin1Str The Latin1 string. | ||
* | ||
* @return {WordArray} The word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.enc.Latin1.parse(latin1String); | ||
*/ | ||
parse: function (latin1Str) { | ||
// Shortcut | ||
var latin1StrLength = latin1Str.length; | ||
if (['cancel', 'finish'].indexOf(options.step) > -1) { | ||
this._deleteWorkflow(workflow); | ||
} else { | ||
this._saveWorkflow(workflow); | ||
} | ||
// Convert | ||
var words = []; | ||
for (var i = 0; i < latin1StrLength; i++) { | ||
words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); | ||
} | ||
var track = _extends(options, { | ||
eventType: 'workflow', | ||
category: options.name, | ||
action: options.step, | ||
label: options.details, | ||
duration: workflow.duration, | ||
workflowId: workflow.workflowId | ||
}); | ||
return new WordArray.init(words, latin1StrLength); | ||
} | ||
}; | ||
this.logEvent(track); | ||
} | ||
}, { | ||
key: 'preProcess', | ||
value: function preProcess() { | ||
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* UTF-8 encoding strategy. | ||
*/ | ||
var Utf8 = C_enc.Utf8 = { | ||
/** | ||
* Converts a word array to a UTF-8 string. | ||
* | ||
* @param {WordArray} wordArray The word array. | ||
* | ||
* @return {string} The UTF-8 string. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); | ||
*/ | ||
stringify: function (wordArray) { | ||
try { | ||
return decodeURIComponent(escape(Latin1.stringify(wordArray))); | ||
} catch (e) { | ||
throw new Error('Malformed UTF-8 data'); | ||
} | ||
}, | ||
var userMetadata = {}; | ||
/** | ||
* Converts a UTF-8 string to a word array. | ||
* | ||
* @param {string} utf8Str The UTF-8 string. | ||
* | ||
* @return {WordArray} The word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.enc.Utf8.parse(utf8String); | ||
*/ | ||
parse: function (utf8Str) { | ||
return Latin1.parse(unescape(encodeURIComponent(utf8Str))); | ||
} | ||
}; | ||
if (this.user) { | ||
userMetadata = { | ||
user: anonymize(this.user.username), | ||
org: anonymize(this.user.orgId), | ||
lastLogin: this.user.lastLogin, | ||
userSince: this.user.created, | ||
internalUser: this.user.internalUser || false, | ||
accountType: this.user.accountType | ||
}; | ||
} | ||
/** | ||
* Abstract buffered block algorithm template. | ||
* | ||
* The property blockSize must be implemented in a concrete subtype. | ||
* | ||
* @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 | ||
*/ | ||
var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ | ||
/** | ||
* Resets this block algorithm's data buffer to its initial state. | ||
* | ||
* @example | ||
* | ||
* bufferedBlockAlgorithm.reset(); | ||
*/ | ||
reset: function () { | ||
// Initial values | ||
this._data = new WordArray.init(); | ||
this._nDataBytes = 0; | ||
}, | ||
return Object.entries(_extends({}, event, userMetadata)).reduce(_makeEventPayload(options.omitComplexData), {}); | ||
} | ||
}, { | ||
key: 'disableTracker', | ||
value: function disableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref3) { | ||
var name = _ref3.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = true; | ||
} | ||
} | ||
}, { | ||
key: 'enableTracker', | ||
value: function enableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref4) { | ||
var name = _ref4.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = false; | ||
} | ||
} | ||
}]); | ||
return Telemetry; | ||
}(); | ||
/** | ||
* Adds new data to this block algorithm's buffer. | ||
* | ||
* @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. | ||
* | ||
* @example | ||
* | ||
* bufferedBlockAlgorithm._append('data'); | ||
* bufferedBlockAlgorithm._append(wordArray); | ||
*/ | ||
_append: function (data) { | ||
// Convert string to WordArray, else assume WordArray already | ||
if (typeof data == 'string') { | ||
data = Utf8.parse(data); | ||
} | ||
Telemetry.anonymize = anonymize; | ||
Telemetry.internalOrgs = internalOrgs; | ||
Telemetry.telemetryEnabled = telemetryEnabled; | ||
Telemetry.storage = storage; | ||
// Append | ||
this._data.concat(data); | ||
this._nDataBytes += data.sigBytes; | ||
}, | ||
/** | ||
* Processes available data blocks. | ||
* | ||
* This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. | ||
* | ||
* @param {boolean} doFlush Whether all blocks and partial blocks should be processed. | ||
* | ||
* @return {WordArray} The processed data. | ||
* | ||
* @example | ||
* | ||
* var processedData = bufferedBlockAlgorithm._process(); | ||
* var processedData = bufferedBlockAlgorithm._process(!!'flush'); | ||
*/ | ||
_process: function (doFlush) { | ||
var processedWords; | ||
function _makeEventPayload(omitComplexData) { | ||
return function (acc, _ref5) { | ||
var _ref6 = slicedToArray(_ref5, 2), | ||
key = _ref6[0], | ||
val = _ref6[1]; | ||
// Shortcuts | ||
var data = this._data; | ||
var dataWords = data.words; | ||
var dataSigBytes = data.sigBytes; | ||
var blockSize = this.blockSize; | ||
var blockSizeBytes = blockSize * 4; | ||
if (_isPrimitive(val)) { | ||
acc[key] = val; | ||
} else if (!omitComplexData) { | ||
console.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
acc[key] = val; | ||
} | ||
return acc; | ||
}; | ||
} | ||
// Count blocks ready | ||
var nBlocksReady = dataSigBytes / blockSizeBytes; | ||
if (doFlush) { | ||
// Round up to include partial blocks | ||
nBlocksReady = Math.ceil(nBlocksReady); | ||
} else { | ||
// Round down to include only full blocks, | ||
// less the number of blocks that must remain in the buffer | ||
nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); | ||
} | ||
function _isPrimitive(val) { | ||
var primitives = ['string', 'number', 'boolean', 'undefined']; | ||
return primitives.includes(typeof val === 'undefined' ? 'undefined' : _typeof(val)) || val && typeof val.valueOf() === 'string'; | ||
} | ||
// Count words ready | ||
var nWordsReady = nBlocksReady * blockSize; | ||
return Telemetry; | ||
// Count bytes ready | ||
var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); | ||
// Process blocks | ||
if (nWordsReady) { | ||
for (var offset = 0; offset < nWordsReady; offset += blockSize) { | ||
// Perform concrete-algorithm logic | ||
this._doProcessBlock(dataWords, offset); | ||
} | ||
// Remove processed words | ||
processedWords = dataWords.splice(0, nWordsReady); | ||
data.sigBytes -= nBytesReady; | ||
} | ||
// Return processed words | ||
return new WordArray.init(processedWords, nBytesReady); | ||
}, | ||
/** | ||
* Creates a copy of this object. | ||
* | ||
* @return {Object} The clone. | ||
* | ||
* @example | ||
* | ||
* var clone = bufferedBlockAlgorithm.clone(); | ||
*/ | ||
clone: function () { | ||
var clone = Base.clone.call(this); | ||
clone._data = this._data.clone(); | ||
return clone; | ||
}, | ||
_minBufferSize: 0 | ||
}); | ||
/** | ||
* Abstract hasher template. | ||
* | ||
* @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) | ||
*/ | ||
C_lib.Hasher = BufferedBlockAlgorithm.extend({ | ||
/** | ||
* Configuration options. | ||
*/ | ||
cfg: Base.extend(), | ||
/** | ||
* Initializes a newly created hasher. | ||
* | ||
* @param {Object} cfg (Optional) The configuration options to use for this hash computation. | ||
* | ||
* @example | ||
* | ||
* var hasher = CryptoJS.algo.SHA256.create(); | ||
*/ | ||
init: function (cfg) { | ||
// Apply config defaults | ||
this.cfg = this.cfg.extend(cfg); | ||
// Set initial values | ||
this.reset(); | ||
}, | ||
/** | ||
* Resets this hasher to its initial state. | ||
* | ||
* @example | ||
* | ||
* hasher.reset(); | ||
*/ | ||
reset: function () { | ||
// Reset data buffer | ||
BufferedBlockAlgorithm.reset.call(this); | ||
// Perform concrete-hasher logic | ||
this._doReset(); | ||
}, | ||
/** | ||
* Updates this hasher with a message. | ||
* | ||
* @param {WordArray|string} messageUpdate The message to append. | ||
* | ||
* @return {Hasher} This hasher. | ||
* | ||
* @example | ||
* | ||
* hasher.update('message'); | ||
* hasher.update(wordArray); | ||
*/ | ||
update: function (messageUpdate) { | ||
// Append | ||
this._append(messageUpdate); | ||
// Update the hash | ||
this._process(); | ||
// Chainable | ||
return this; | ||
}, | ||
/** | ||
* Finalizes the hash computation. | ||
* Note that the finalize operation is effectively a destructive, read-once operation. | ||
* | ||
* @param {WordArray|string} messageUpdate (Optional) A final message update. | ||
* | ||
* @return {WordArray} The hash. | ||
* | ||
* @example | ||
* | ||
* var hash = hasher.finalize(); | ||
* var hash = hasher.finalize('message'); | ||
* var hash = hasher.finalize(wordArray); | ||
*/ | ||
finalize: function (messageUpdate) { | ||
// Final message update | ||
if (messageUpdate) { | ||
this._append(messageUpdate); | ||
} | ||
// Perform concrete-hasher logic | ||
var hash = this._doFinalize(); | ||
return hash; | ||
}, | ||
blockSize: 512/32, | ||
/** | ||
* Creates a shortcut function to a hasher's object interface. | ||
* | ||
* @param {Hasher} hasher The hasher to create a helper for. | ||
* | ||
* @return {Function} The shortcut function. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); | ||
*/ | ||
_createHelper: function (hasher) { | ||
return function (message, cfg) { | ||
return new hasher.init(cfg).finalize(message); | ||
}; | ||
}, | ||
/** | ||
* Creates a shortcut function to the HMAC's object interface. | ||
* | ||
* @param {Hasher} hasher The hasher to use in this HMAC helper. | ||
* | ||
* @return {Function} The shortcut function. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); | ||
*/ | ||
_createHmacHelper: function (hasher) { | ||
return function (message, key) { | ||
return new C_algo.HMAC.init(hasher, key).finalize(message); | ||
}; | ||
} | ||
}); | ||
/** | ||
* Algorithm namespace. | ||
*/ | ||
var C_algo = C.algo = {}; | ||
return C; | ||
}(Math)); | ||
return CryptoJS; | ||
})); | ||
}(core)); | ||
(function (module, exports) { | ||
(function (root, factory) { | ||
{ | ||
// CommonJS | ||
module.exports = factory(core.exports); | ||
} | ||
}(commonjsGlobal, function (CryptoJS) { | ||
(function (Math) { | ||
// Shortcuts | ||
var C = CryptoJS; | ||
var C_lib = C.lib; | ||
var WordArray = C_lib.WordArray; | ||
var Hasher = C_lib.Hasher; | ||
var C_algo = C.algo; | ||
// Initialization and round constants tables | ||
var H = []; | ||
var K = []; | ||
// Compute constants | ||
(function () { | ||
function isPrime(n) { | ||
var sqrtN = Math.sqrt(n); | ||
for (var factor = 2; factor <= sqrtN; factor++) { | ||
if (!(n % factor)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function getFractionalBits(n) { | ||
return ((n - (n | 0)) * 0x100000000) | 0; | ||
} | ||
var n = 2; | ||
var nPrime = 0; | ||
while (nPrime < 64) { | ||
if (isPrime(n)) { | ||
if (nPrime < 8) { | ||
H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); | ||
} | ||
K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); | ||
nPrime++; | ||
} | ||
n++; | ||
} | ||
}()); | ||
// Reusable object | ||
var W = []; | ||
/** | ||
* SHA-256 hash algorithm. | ||
*/ | ||
var SHA256 = C_algo.SHA256 = Hasher.extend({ | ||
_doReset: function () { | ||
this._hash = new WordArray.init(H.slice(0)); | ||
}, | ||
_doProcessBlock: function (M, offset) { | ||
// Shortcut | ||
var H = this._hash.words; | ||
// Working variables | ||
var a = H[0]; | ||
var b = H[1]; | ||
var c = H[2]; | ||
var d = H[3]; | ||
var e = H[4]; | ||
var f = H[5]; | ||
var g = H[6]; | ||
var h = H[7]; | ||
// Computation | ||
for (var i = 0; i < 64; i++) { | ||
if (i < 16) { | ||
W[i] = M[offset + i] | 0; | ||
} else { | ||
var gamma0x = W[i - 15]; | ||
var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ | ||
((gamma0x << 14) | (gamma0x >>> 18)) ^ | ||
(gamma0x >>> 3); | ||
var gamma1x = W[i - 2]; | ||
var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ | ||
((gamma1x << 13) | (gamma1x >>> 19)) ^ | ||
(gamma1x >>> 10); | ||
W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; | ||
} | ||
var ch = (e & f) ^ (~e & g); | ||
var maj = (a & b) ^ (a & c) ^ (b & c); | ||
var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); | ||
var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); | ||
var t1 = h + sigma1 + ch + K[i] + W[i]; | ||
var t2 = sigma0 + maj; | ||
h = g; | ||
g = f; | ||
f = e; | ||
e = (d + t1) | 0; | ||
d = c; | ||
c = b; | ||
b = a; | ||
a = (t1 + t2) | 0; | ||
} | ||
// Intermediate hash value | ||
H[0] = (H[0] + a) | 0; | ||
H[1] = (H[1] + b) | 0; | ||
H[2] = (H[2] + c) | 0; | ||
H[3] = (H[3] + d) | 0; | ||
H[4] = (H[4] + e) | 0; | ||
H[5] = (H[5] + f) | 0; | ||
H[6] = (H[6] + g) | 0; | ||
H[7] = (H[7] + h) | 0; | ||
}, | ||
_doFinalize: function () { | ||
// Shortcuts | ||
var data = this._data; | ||
var dataWords = data.words; | ||
var nBitsTotal = this._nDataBytes * 8; | ||
var nBitsLeft = data.sigBytes * 8; | ||
// Add padding | ||
dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); | ||
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); | ||
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; | ||
data.sigBytes = dataWords.length * 4; | ||
// Hash final blocks | ||
this._process(); | ||
// Return final computed hash | ||
return this._hash; | ||
}, | ||
clone: function () { | ||
var clone = Hasher.clone.call(this); | ||
clone._hash = this._hash.clone(); | ||
return clone; | ||
} | ||
}); | ||
/** | ||
* Shortcut function to the hasher's object interface. | ||
* | ||
* @param {WordArray|string} message The message to hash. | ||
* | ||
* @return {WordArray} The hash. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var hash = CryptoJS.SHA256('message'); | ||
* var hash = CryptoJS.SHA256(wordArray); | ||
*/ | ||
C.SHA256 = Hasher._createHelper(SHA256); | ||
/** | ||
* Shortcut function to the HMAC's object interface. | ||
* | ||
* @param {WordArray|string} message The message to hash. | ||
* @param {WordArray|string} key The secret key. | ||
* | ||
* @return {WordArray} The HMAC. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var hmac = CryptoJS.HmacSHA256(message, key); | ||
*/ | ||
C.HmacSHA256 = Hasher._createHmacHelper(SHA256); | ||
}(Math)); | ||
return CryptoJS.SHA256; | ||
})); | ||
}(sha256$1)); | ||
var sha256 = sha256$1.exports; | ||
var encHex = {exports: {}}; | ||
(function (module, exports) { | ||
(function (root, factory) { | ||
{ | ||
// CommonJS | ||
module.exports = factory(core.exports); | ||
} | ||
}(commonjsGlobal, function (CryptoJS) { | ||
return CryptoJS.enc.Hex; | ||
})); | ||
}(encHex)); | ||
var hex = encHex.exports; | ||
var storage = { | ||
storage: {}, | ||
memory: true, | ||
get: function get(key) { | ||
var stored = void 0; | ||
try { | ||
stored = window.localStorage && window.localStorage.getItem(key) || this.storage[key]; | ||
} catch (e) { | ||
stored = this.storage[key]; | ||
} | ||
if (stored) { | ||
try { | ||
return JSON.parse(stored); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
}, | ||
set: function set(key, value) { | ||
// handle Safari private mode (setItem is not allowed) | ||
var valueToString = JSON.stringify(value); | ||
try { | ||
window.localStorage.setItem(key, valueToString); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
this.storage[key] = value; | ||
} | ||
}, | ||
delete: function _delete(key) { | ||
try { | ||
window.localStorage.removeItem(key); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
delete this.storage[key]; | ||
} | ||
} | ||
}; | ||
function telemetryEnabled() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var portal = options.portal || {}; | ||
if (options.disabled) { | ||
return false; | ||
} | ||
if (_hasDoNotTrackEnabled()) { | ||
return false; | ||
} | ||
if (typeof portal.eueiEnabled !== 'undefined' && portal.eueiEnabled === false) { | ||
// Portal does not allow tracking | ||
return false; | ||
} | ||
if (portal.eueiEnabled && portal.user && portal.user.orgId === portal.id) { | ||
// Portal allows tracking; except when user is anonymous or doesn't belong to portal's org | ||
return true; | ||
} | ||
if (portal.user && !portal.user.orgId && portal.ipCntryCode === 'US') { | ||
// Public user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (!portal.user && portal.ipCntryCode === 'US') { | ||
// Anonymous user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (Object.keys(portal).length > 0) { | ||
// Initialized with a Portal object but does not meet tracking conditions | ||
return false; | ||
} | ||
// Default condition not initialized with a Portal-Self object | ||
return true; | ||
} | ||
function _hasDoNotTrackEnabled() { | ||
return (typeof navigator !== 'undefined' && navigator.doNotTrack) === '1' || typeof window !== 'undefined' && window.doNotTrack === '1'; | ||
} | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
var slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
var INTERNAL_ORGS = ['esri.com', 'esriuk.com', 'esri.de', 'esri.ca', 'esrifrance.fr', 'esri.nl', 'esri-portugal.pt', 'esribulgaria.com', 'esri.fi', 'esri.kr', 'esrimalaysia.com.my', 'esri.es', 'esriaustralia.com.au', 'esri-southafrica.com', 'esri.cl', 'esrichina.com.cn', 'esri.co', 'esriturkey.com.tr', 'geodata.no', 'esriitalia.it', 'esri.pl']; | ||
var Telemetry = function () { | ||
function Telemetry(options) { | ||
classCallCheck(this, Telemetry); | ||
var _a, _b, _c; | ||
this.trackers = []; | ||
this.options = options; | ||
this.test = options.test; | ||
this.debug = options.debug; | ||
this.disabled = !telemetryEnabled(options); | ||
if (this.disabled) { | ||
console.warn('Telemetry Disabled'); | ||
} | ||
var user = ((_a = options.portal) === null || _a === void 0 ? void 0 : _a.user) || options.user; | ||
if (user) { | ||
this.setUser(user, (_c = (_b = options.portal) === null || _b === void 0 ? void 0 : _b.subscriptionInfo) === null || _c === void 0 ? void 0 : _c.type); | ||
} | ||
if (!this.disabled) { | ||
this.initializeTrackers(); | ||
} | ||
} | ||
createClass(Telemetry, [{ | ||
key: 'initializeTrackers', | ||
value: function initializeTrackers() { | ||
if (this.options.plugins) { | ||
var _trackers; | ||
(_trackers = this.trackers).push.apply(_trackers, toConsumableArray(this.options.plugins)); | ||
} | ||
if (!this.trackers.length) { | ||
console.error(new Error('No trackers configured')); | ||
} | ||
} | ||
}, { | ||
key: 'setUser', | ||
value: function setUser() { | ||
var user = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var orgType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Public'; | ||
user = typeof user === 'string' ? { username: user } : user; | ||
this.user = user; | ||
this.user.accountType = orgType; | ||
var internalDomain = void 0; | ||
if (user.email && user.email.split) { | ||
var domain = user.email.split('@')[1]; | ||
internalDomain = INTERNAL_ORGS.filter(function (org) { | ||
return domain === org; | ||
}).length > 0; | ||
} | ||
if (internalDomain || ['In House', 'Demo and Marketing'].indexOf(orgType) > -1) { | ||
this.user.internalUser = true; | ||
} | ||
} | ||
}, { | ||
key: 'logPageView', | ||
value: function logPageView(page) { | ||
var event = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var attributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking page view', JSON.stringify(attributes)); | ||
} | ||
if (this.test && !this.disabled) { | ||
return attributes; | ||
} | ||
var trackers = this.trackers.filter(function (_ref) { | ||
var disabled = _ref.disabled; | ||
return !disabled; | ||
}); | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Page view was not logged because no trackers are configured.')); | ||
} | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
}); | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logEvent', | ||
value: function logEvent(event) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
event = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking event', JSON.stringify(event)); | ||
} | ||
if (this.test) { | ||
return event; | ||
} | ||
var trackers = void 0; | ||
if (this.trackers.length) { | ||
trackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
} | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Event was not logged because no trackers are configured.')); | ||
} | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
}); | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logError', | ||
value: function logError() { | ||
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
event = _extends({ eventType: 'error' }, event); | ||
this.logEvent(event); | ||
} | ||
}, { | ||
key: 'startWorkflow', | ||
value: function startWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflow = { | ||
name: name, | ||
start: Date.now(), | ||
steps: [], | ||
workflowId: Math.floor((1 + Math.random()) * 0x100000000000).toString(16) | ||
}; | ||
this.saveWorkflow(workflow); | ||
var workflowObj = _extends({ name: name, step: 'start' }, attributes); | ||
this.logWorkflow(workflowObj); | ||
return workflow; | ||
} | ||
}, { | ||
key: 'stepWorkflow', | ||
value: function stepWorkflow(name, step) { | ||
var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
//TODO: check if the check for attributes being a string is useful or can be removed | ||
var details = typeof attributes === 'string' ? attributes : attributes.details; | ||
var workflowObj = _extends({ name: name, step: step, details: details }, attributes); | ||
this.logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'endWorkflow', | ||
value: function endWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflowObj = _extends({ name: name, step: 'finish' }, attributes); | ||
this.logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'cancelWorkflow', | ||
value: function cancelWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflowObj = _extends({ name: name, step: 'cancel' }, attributes); | ||
this.logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'getWorkflow', | ||
value: function getWorkflow(name) { | ||
var workflow = storage.get('TELEMETRY-WORKFLOW:' + name); | ||
// do not let old workflows be returned | ||
if (workflow) { | ||
var workflowAge = Date.now() - workflow.start; | ||
var timeout = 30 * 60 * 1000; | ||
if (workflowAge < timeout) { | ||
return workflow; | ||
} else { | ||
this.deleteWorkflow(workflow); | ||
} | ||
} | ||
} | ||
}, { | ||
key: 'saveWorkflow', | ||
value: function saveWorkflow(workflow) { | ||
storage.set('TELEMETRY-WORKFLOW:' + workflow.name, workflow); | ||
} | ||
}, { | ||
key: 'deleteWorkflow', | ||
value: function deleteWorkflow(workflow) { | ||
storage.delete('TELEMETRY-WORKFLOW:' + workflow.name); | ||
} | ||
}, { | ||
key: 'logWorkflow', | ||
value: function logWorkflow() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
/* | ||
const workflow = { | ||
name: 'add layer to map', | ||
step: 'start', | ||
details: 'some details about the step' | ||
} | ||
*/ | ||
options = this.preProcess(options); | ||
var workflow = this.getWorkflow(options.name); | ||
if (!workflow) { | ||
this.startWorkflow(options.name); | ||
workflow = this.getWorkflow(options.name); | ||
} | ||
workflow.steps.push(options.step); | ||
workflow.duration = (Date.now() - workflow.start) / 1000; | ||
if (['cancel', 'finish'].indexOf(options.step) > -1) { | ||
this.deleteWorkflow(workflow); | ||
} else { | ||
this.saveWorkflow(workflow); | ||
} | ||
var track = _extends(options, { | ||
eventType: 'workflow', | ||
category: options.name, | ||
action: options.step, | ||
label: options.details, | ||
duration: workflow.duration, | ||
workflowId: workflow.workflowId | ||
}); | ||
this.logEvent(track); | ||
} | ||
}, { | ||
key: 'preProcess', | ||
value: function preProcess() { | ||
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var userMetadata = {}; | ||
if (this.user) { | ||
userMetadata = { | ||
user: anonymize(this.user.username), | ||
org: anonymize(this.user.orgId), | ||
lastLogin: this.user.lastLogin, | ||
userSince: this.user.created, | ||
internalUser: this.user.internalUser || false, | ||
accountType: this.user.accountType | ||
}; | ||
} | ||
return Object.entries(_extends(_extends({}, event), userMetadata)).reduce(makeEventPayload(options.omitComplexData), {}); | ||
} | ||
}, { | ||
key: 'disableTracker', | ||
value: function disableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref3) { | ||
var name = _ref3.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = true; | ||
} | ||
} | ||
}, { | ||
key: 'enableTracker', | ||
value: function enableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref4) { | ||
var name = _ref4.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = false; | ||
} | ||
} | ||
}]); | ||
return Telemetry; | ||
}(); | ||
Telemetry.storage = storage; | ||
function anonymize(user) { | ||
if (!user) return; | ||
return sha256(user).toString(hex); | ||
} | ||
function makeEventPayload(omitComplexData) { | ||
return function (acc, _ref5) { | ||
var _ref6 = slicedToArray(_ref5, 2), | ||
key = _ref6[0], | ||
val = _ref6[1]; | ||
if (isPrimitive(val)) { | ||
acc[key] = val; | ||
} else if (!omitComplexData) { | ||
console.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
acc[key] = val; | ||
} | ||
return acc; | ||
}; | ||
} | ||
function isPrimitive(val) { | ||
var primitives = ['string', 'number', 'boolean', 'undefined']; | ||
return primitives.includes(typeof val === 'undefined' ? 'undefined' : _typeof(val)) || val && typeof val.valueOf() === 'string'; | ||
} | ||
return Telemetry; | ||
})); | ||
//# sourceMappingURL=telemetry.amd.js.map |
define((function () { 'use strict'; | ||
function anonymize(user) { | ||
if (!user) return undefined; | ||
return CryptoJS.SHA256(user).toString(CryptoJS.enc.Hex); | ||
} | ||
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
var internalOrgs = ['esri.com', 'esriuk.com', 'esri.de', 'esri.ca', 'esrifrance.fr', 'esri.nl', 'esri-portugal.pt', 'esribulgaria.com', 'esri.fi', 'esri.kr', 'esrimalaysia.com.my', 'esri.es', 'esriaustralia.com.au', 'esri-southafrica.com', 'esri.cl', 'esrichina.com.cn', 'esri.co', 'esriturkey.com.tr', 'geodata.no', 'esriitalia.it', 'esri.pl']; | ||
function commonjsRequire (path) { | ||
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.'); | ||
} | ||
var storage = { | ||
storage: {}, | ||
memory: true, | ||
get: function get(key) { | ||
var stored = void 0; | ||
try { | ||
stored = window.localStorage && window.localStorage.getItem(key) || this.storage[key]; | ||
} catch (e) { | ||
stored = this.storage[key]; | ||
} | ||
if (stored) { | ||
try { | ||
return JSON.parse(stored); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
}, | ||
set: function set(key, value) { | ||
// handle Safari private mode (setItem is not allowed) | ||
value = JSON.stringify(value); | ||
try { | ||
window.localStorage.setItem(key, value); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
this.storage[key] = value; | ||
} | ||
}, | ||
delete: function _delete(key) { | ||
try { | ||
window.localStorage.removeItem(key); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
delete this.storage[key]; | ||
} | ||
} | ||
}; | ||
var sha256$1 = {exports: {}}; | ||
/* | ||
* Determines whether or not the telemetry library should be enabled based on passed in options | ||
*/ | ||
function telemetryEnabled() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var core = {exports: {}}; | ||
var portal = options.portal || {}; | ||
(function (module, exports) { | ||
(function (root, factory) { | ||
{ | ||
// CommonJS | ||
module.exports = factory(); | ||
} | ||
}(commonjsGlobal, function () { | ||
if (options.disabled) { | ||
// Tracking is manually disabled | ||
return false; | ||
} | ||
/*globals window, global, require*/ | ||
if (_hasDoNotTrackEnabled()) { | ||
// user's browser has turned off tracking | ||
return false; | ||
} | ||
/** | ||
* CryptoJS core components. | ||
*/ | ||
var CryptoJS = CryptoJS || (function (Math, undefined$1) { | ||
if (typeof portal.eueiEnabled !== 'undefined' && portal.eueiEnabled === false) { | ||
// Portal does not allow tracking | ||
return false; | ||
} | ||
var crypto; | ||
if (portal.eueiEnabled && portal.user && portal.user.orgId === portal.id) { | ||
// Portal allows tracking; except when user is anonymous or doesn't belong to portal's org | ||
return true; | ||
} | ||
// Native crypto from window (Browser) | ||
if (typeof window !== 'undefined' && window.crypto) { | ||
crypto = window.crypto; | ||
} | ||
if (portal.user && !portal.user.orgId && portal.ipCntryCode === 'US') { | ||
// Public user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
// Native crypto in web worker (Browser) | ||
if (typeof self !== 'undefined' && self.crypto) { | ||
crypto = self.crypto; | ||
} | ||
if (!portal.user && portal.ipCntryCode === 'US') { | ||
// Anonymous user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
// Native crypto from worker | ||
if (typeof globalThis !== 'undefined' && globalThis.crypto) { | ||
crypto = globalThis.crypto; | ||
} | ||
if (Object.keys(portal).length > 0) { | ||
// Initialized with a Portal object but does not meet tracking conditions | ||
return false; | ||
} | ||
// Native (experimental IE 11) crypto from window (Browser) | ||
if (!crypto && typeof window !== 'undefined' && window.msCrypto) { | ||
crypto = window.msCrypto; | ||
} | ||
// Default condition not initialized with a Portal-Self object | ||
return true; | ||
} | ||
// Native crypto from global (NodeJS) | ||
if (!crypto && typeof commonjsGlobal !== 'undefined' && commonjsGlobal.crypto) { | ||
crypto = commonjsGlobal.crypto; | ||
} | ||
function _hasDoNotTrackEnabled() { | ||
return (typeof navigator !== 'undefined' && navigator.doNotTrack) === '1' || typeof window !== 'undefined' && window.doNotTrack === '1'; | ||
} | ||
// Native crypto import via require (NodeJS) | ||
if (!crypto && typeof commonjsRequire === 'function') { | ||
try { | ||
crypto = require('crypto'); | ||
} catch (err) {} | ||
} | ||
/* | ||
(c) 2009-2013 by Jeff Mott. All rights reserved. | ||
/* | ||
* Cryptographically secure pseudorandom number generator | ||
* | ||
* As Math.random() is cryptographically not safe to use | ||
*/ | ||
var cryptoSecureRandomInt = function () { | ||
if (crypto) { | ||
// Use getRandomValues method (Browser) | ||
if (typeof crypto.getRandomValues === 'function') { | ||
try { | ||
return crypto.getRandomValues(new Uint32Array(1))[0]; | ||
} catch (err) {} | ||
} | ||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
// Use randomBytes method (NodeJS) | ||
if (typeof crypto.randomBytes === 'function') { | ||
try { | ||
return crypto.randomBytes(4).readInt32LE(); | ||
} catch (err) {} | ||
} | ||
} | ||
Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer. | ||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation or other materials provided with the distribution. | ||
Neither the name CryptoJS nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS," AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
var CryptoJS = function (h, s) { | ||
var f = {}, | ||
g = f.lib = {}, | ||
q = function q() {}, | ||
m = g.Base = { | ||
extend: function extend(a) { | ||
q.prototype = this; | ||
var c = new q(); | ||
a && c.mixIn(a); | ||
c.hasOwnProperty('init') || (c.init = function () { | ||
c.$super.init.apply(this, arguments); | ||
}); | ||
c.init.prototype = c; | ||
c.$super = this; | ||
return c; | ||
}, | ||
create: function create() { | ||
var a = this.extend(); | ||
a.init.apply(a, arguments); | ||
return a; | ||
}, | ||
init: function init() {}, | ||
mixIn: function mixIn(a) { | ||
for (var c in a) { | ||
a.hasOwnProperty(c) && (this[c] = a[c]); | ||
}a.hasOwnProperty('toString') && (this.toString = a.toString); | ||
}, | ||
clone: function clone() { | ||
return this.init.prototype.extend(this); | ||
} | ||
}, | ||
r = g.WordArray = m.extend({ | ||
init: function init(a, c) { | ||
a = this.words = a || []; | ||
this.sigBytes = c != s ? c : 4 * a.length; | ||
}, | ||
toString: function toString(a) { | ||
return (a || k).stringify(this); | ||
}, | ||
concat: function concat(a) { | ||
var c = this.words, | ||
d = a.words, | ||
b = this.sigBytes; | ||
a = a.sigBytes; | ||
this.clamp(); | ||
if (b % 4) for (var e = 0; e < a; e++) { | ||
c[b + e >>> 2] |= (d[e >>> 2] >>> 24 - 8 * (e % 4) & 255) << 24 - 8 * ((b + e) % 4); | ||
} else if (d.length > 65535) for (e = 0; e < a; e += 4) { | ||
c[b + e >>> 2] = d[e >>> 2]; | ||
} else c.push.apply(c, d); | ||
this.sigBytes += a; | ||
return this; | ||
}, | ||
clamp: function clamp() { | ||
var a = this.words, | ||
c = this.sigBytes; | ||
a[c >>> 2] &= 4294967295 << 32 - 8 * (c % 4); | ||
a.length = h.ceil(c / 4); | ||
}, | ||
clone: function clone() { | ||
var a = m.clone.call(this); | ||
a.words = this.words.slice(0); | ||
return a; | ||
}, | ||
random: function random(a) { | ||
for (var c = [], d = 0; d < a; d += 4) { | ||
c.push(4294967296 * h.random() | 0); | ||
}return new r.init(c, a); | ||
} | ||
}), | ||
l = f.enc = {}, | ||
k = l.Hex = { | ||
stringify: function stringify(a) { | ||
var c = a.words; | ||
a = a.sigBytes; | ||
for (var d = [], b = 0; b < a; b++) { | ||
var e = c[b >>> 2] >>> 24 - 8 * (b % 4) & 255; | ||
d.push((e >>> 4).toString(16)); | ||
d.push((e & 15).toString(16)); | ||
} | ||
return d.join(''); | ||
}, | ||
parse: function parse(a) { | ||
for (var c = a.length, d = [], b = 0; b < c; b += 2) { | ||
d[b >>> 3] |= parseInt(a.substr(b, 2), 16) << 24 - 4 * (b % 8); | ||
} | ||
return new r.init(d, c / 2); | ||
} | ||
}, | ||
n = l.Latin1 = { | ||
stringify: function stringify(a) { | ||
var c = a.words; | ||
a = a.sigBytes; | ||
for (var d = [], b = 0; b < a; b++) { | ||
d.push(String.fromCharCode(c[b >>> 2] >>> 24 - 8 * (b % 4) & 255)); | ||
}return d.join(''); | ||
}, | ||
parse: function parse(a) { | ||
for (var c = a.length, d = [], b = 0; b < c; b++) { | ||
d[b >>> 2] |= (a.charCodeAt(b) & 255) << 24 - 8 * (b % 4); | ||
}return new r.init(d, c); | ||
} | ||
}, | ||
j = l.Utf8 = { | ||
stringify: function stringify(a) { | ||
try { | ||
return decodeURIComponent(escape(n.stringify(a))); | ||
} catch (c) { | ||
throw Error('Malformed UTF-8 data'); | ||
} | ||
}, | ||
parse: function parse(a) { | ||
return n.parse(unescape(encodeURIComponent(a))); | ||
} | ||
}, | ||
u = g.BufferedBlockAlgorithm = m.extend({ | ||
reset: function reset() { | ||
this._data = new r.init(); | ||
this._nDataBytes = 0; | ||
}, | ||
_append: function _append(a) { | ||
typeof a === 'string' && (a = j.parse(a)); | ||
this._data.concat(a); | ||
this._nDataBytes += a.sigBytes; | ||
}, | ||
_process: function _process(a) { | ||
var c = this._data, | ||
d = c.words, | ||
b = c.sigBytes, | ||
e = this.blockSize, | ||
f = b / (4 * e), | ||
f = a ? h.ceil(f) : h.max((f | 0) - this._minBufferSize, 0); | ||
a = f * e; | ||
b = h.min(4 * a, b); | ||
if (a) { | ||
for (var g = 0; g < a; g += e) { | ||
this._doProcessBlock(d, g); | ||
}g = d.splice(0, a); | ||
c.sigBytes -= b; | ||
} | ||
return new r.init(g, b); | ||
}, | ||
clone: function clone() { | ||
var a = m.clone.call(this); | ||
a._data = this._data.clone(); | ||
return a; | ||
}, | ||
_minBufferSize: 0 | ||
}); | ||
g.Hasher = u.extend({ | ||
cfg: m.extend(), | ||
init: function init(a) { | ||
this.cfg = this.cfg.extend(a); | ||
this.reset(); | ||
}, | ||
reset: function reset() { | ||
u.reset.call(this); | ||
this._doReset(); | ||
}, | ||
update: function update(a) { | ||
this._append(a); | ||
this._process(); | ||
return this; | ||
}, | ||
finalize: function finalize(a) { | ||
a && this._append(a); | ||
return this._doFinalize(); | ||
}, | ||
blockSize: 16, | ||
_createHelper: function _createHelper(a) { | ||
return function (c, d) { | ||
return new a.init(d).finalize(c); | ||
}; | ||
}, | ||
_createHmacHelper: function _createHmacHelper(a) { | ||
return function (c, d) { | ||
return new t.HMAC.init(a, d).finalize(c); | ||
}; | ||
} | ||
}); | ||
var t = f.algo = {}; | ||
return f; | ||
}(Math); | ||
(function (h) { | ||
for (var s = CryptoJS, f = s.lib, g = f.WordArray, q = f.Hasher, f = s.algo, m = [], r = [], l = function l(a) { | ||
return 4294967296 * (a - (a | 0)) | 0; | ||
}, k = 2, n = 0; n < 64;) { | ||
var j; | ||
a: { | ||
j = k; | ||
for (var u = h.sqrt(j), t = 2; t <= u; t++) { | ||
if (!(j % t)) { | ||
j = !1; | ||
break a; | ||
} | ||
}j = !0; | ||
} | ||
j && (n < 8 && (m[n] = l(h.pow(k, 0.5))), r[n] = l(h.pow(k, 1 / 3)), n++); | ||
k++; | ||
} | ||
var a = [], | ||
f = f.SHA256 = q.extend({ | ||
_doReset: function _doReset() { | ||
this._hash = new g.init(m.slice(0)); | ||
}, | ||
_doProcessBlock: function _doProcessBlock(c, d) { | ||
for (var b = this._hash.words, e = b[0], f = b[1], g = b[2], j = b[3], h = b[4], m = b[5], n = b[6], q = b[7], p = 0; p < 64; p++) { | ||
if (p < 16) { | ||
a[p] = c[d + p] | 0; | ||
} else { | ||
var k = a[p - 15], | ||
l = a[p - 2]; | ||
a[p] = ((k << 25 | k >>> 7) ^ (k << 14 | k >>> 18) ^ k >>> 3) + a[p - 7] + ((l << 15 | l >>> 17) ^ (l << 13 | l >>> 19) ^ l >>> 10) + a[p - 16]; | ||
} | ||
k = q + ((h << 26 | h >>> 6) ^ (h << 21 | h >>> 11) ^ (h << 7 | h >>> 25)) + (h & m ^ ~h & n) + r[p] + a[p]; | ||
l = ((e << 30 | e >>> 2) ^ (e << 19 | e >>> 13) ^ (e << 10 | e >>> 22)) + (e & f ^ e & g ^ f & g); | ||
q = n; | ||
n = m; | ||
m = h; | ||
h = j + k | 0; | ||
j = g; | ||
g = f; | ||
f = e; | ||
e = k + l | 0; | ||
} | ||
b[0] = b[0] + e | 0; | ||
b[1] = b[1] + f | 0; | ||
b[2] = b[2] + g | 0; | ||
b[3] = b[3] + j | 0; | ||
b[4] = b[4] + h | 0; | ||
b[5] = b[5] + m | 0; | ||
b[6] = b[6] + n | 0; | ||
b[7] = b[7] + q | 0; | ||
}, | ||
_doFinalize: function _doFinalize() { | ||
var a = this._data, | ||
d = a.words, | ||
b = 8 * this._nDataBytes, | ||
e = 8 * a.sigBytes; | ||
d[e >>> 5] |= 128 << 24 - e % 32; | ||
d[(e + 64 >>> 9 << 4) + 14] = h.floor(b / 4294967296); | ||
d[(e + 64 >>> 9 << 4) + 15] = b; | ||
a.sigBytes = 4 * d.length; | ||
this._process(); | ||
return this._hash; | ||
}, | ||
clone: function clone() { | ||
var a = q.clone.call(this); | ||
a._hash = this._hash.clone(); | ||
return a; | ||
} | ||
}); | ||
s.SHA256 = q._createHelper(f); | ||
s.HmacSHA256 = q._createHmacHelper(f); | ||
})(Math); | ||
(function () { | ||
var h = CryptoJS, | ||
s = h.enc.Utf8; | ||
h.algo.HMAC = h.lib.Base.extend({ | ||
init: function init(f, g) { | ||
f = this._hasher = new f.init(); | ||
typeof g === 'string' && (g = s.parse(g)); | ||
var h = f.blockSize, | ||
m = 4 * h; | ||
g.sigBytes > m && (g = f.finalize(g)); | ||
g.clamp(); | ||
for (var r = this._oKey = g.clone(), l = this._iKey = g.clone(), k = r.words, n = l.words, j = 0; j < h; j++) { | ||
k[j] ^= 1549556828, n[j] ^= 909522486; | ||
}r.sigBytes = l.sigBytes = m; | ||
this.reset(); | ||
}, | ||
reset: function reset() { | ||
var f = this._hasher; | ||
f.reset(); | ||
f.update(this._iKey); | ||
}, | ||
update: function update(f) { | ||
this._hasher.update(f); | ||
return this; | ||
}, | ||
finalize: function finalize(f) { | ||
var g = this._hasher; | ||
f = g.finalize(f); | ||
g.reset(); | ||
return g.finalize(this._oKey.clone().concat(f)); | ||
} | ||
}); | ||
})(); | ||
throw new Error('Native crypto module could not be used to get secure random number.'); | ||
}; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
/* | ||
* Local polyfill of Object.create | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
*/ | ||
var create = Object.create || (function () { | ||
function F() {} | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (obj) { | ||
var subtype; | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
F.prototype = obj; | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
subtype = new F(); | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
F.prototype = null; | ||
return target; | ||
}; | ||
return subtype; | ||
}; | ||
}()); | ||
var slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
/** | ||
* CryptoJS namespace. | ||
*/ | ||
var C = {}; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
/** | ||
* Library namespace. | ||
*/ | ||
var C_lib = C.lib = {}; | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
/** | ||
* Base object for prototypal inheritance. | ||
*/ | ||
var Base = C_lib.Base = (function () { | ||
return _arr; | ||
} | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
return { | ||
/** | ||
* Creates a new object that inherits from this object. | ||
* | ||
* @param {Object} overrides Properties to copy into the new object. | ||
* | ||
* @return {Object} The new object. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var MyType = CryptoJS.lib.Base.extend({ | ||
* field: 'value', | ||
* | ||
* method: function () { | ||
* } | ||
* }); | ||
*/ | ||
extend: function (overrides) { | ||
// Spawn | ||
var subtype = create(this); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
// Augment | ||
if (overrides) { | ||
subtype.mixIn(overrides); | ||
} | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
// Create default initializer | ||
if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { | ||
subtype.init = function () { | ||
subtype.$super.init.apply(this, arguments); | ||
}; | ||
} | ||
var Telemetry = function () { | ||
function Telemetry(options) { | ||
classCallCheck(this, Telemetry); | ||
// Initializer's prototype is the subtype object | ||
subtype.init.prototype = subtype; | ||
// Make sure failure to init this library cannot have side-effects | ||
try { | ||
this.trackers = []; | ||
this.workflows = {}; | ||
this.test = options.test; | ||
this.debug = options.debug; | ||
this.disabled = !telemetryEnabled(options); | ||
// Reference supertype | ||
subtype.$super = this; | ||
if (this.disabled) { | ||
console.log('Telemetry Disabled'); | ||
} | ||
return subtype; | ||
}, | ||
if (options.portal && options.portal.user) { | ||
var subscriptionInfo = options.portal.subscriptionInfo || {}; | ||
this.setUser(options.portal.user, subscriptionInfo.type); | ||
} else if (options.user) { | ||
this.setUser(options.user); | ||
} | ||
/** | ||
* Extends this object and runs the init method. | ||
* Arguments to create() will be passed to init(). | ||
* | ||
* @return {Object} The new object. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var instance = MyType.create(); | ||
*/ | ||
create: function () { | ||
var instance = this.extend(); | ||
instance.init.apply(instance, arguments); | ||
if (!this.disabled) { | ||
this._initializeTrackers(options); | ||
} | ||
} catch (e) { | ||
console.error('Telemetry Disabled'); | ||
console.error(e); | ||
this.disabled = true; | ||
} | ||
} | ||
return instance; | ||
}, | ||
createClass(Telemetry, [{ | ||
key: '_initializeTrackers', | ||
value: function _initializeTrackers(options) { | ||
if (options.plugins) { | ||
var _trackers; | ||
/** | ||
* Initializes a newly created object. | ||
* Override this method to add some logic when your objects are created. | ||
* | ||
* @example | ||
* | ||
* var MyType = CryptoJS.lib.Base.extend({ | ||
* init: function () { | ||
* // ... | ||
* } | ||
* }); | ||
*/ | ||
init: function () { | ||
}, | ||
(_trackers = this.trackers).push.apply(_trackers, toConsumableArray(options.plugins)); | ||
} | ||
/** | ||
* Copies properties into this object. | ||
* | ||
* @param {Object} properties The properties to mix in. | ||
* | ||
* @example | ||
* | ||
* MyType.mixIn({ | ||
* field: 'value' | ||
* }); | ||
*/ | ||
mixIn: function (properties) { | ||
for (var propertyName in properties) { | ||
if (properties.hasOwnProperty(propertyName)) { | ||
this[propertyName] = properties[propertyName]; | ||
} | ||
} | ||
if (!this.trackers.length) { | ||
console.error(new Error('No trackers configured')); | ||
} | ||
} | ||
}, { | ||
key: 'setUser', | ||
value: function setUser() { | ||
var user = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var orgType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Public'; | ||
// IE won't copy toString using the loop above | ||
if (properties.hasOwnProperty('toString')) { | ||
this.toString = properties.toString; | ||
} | ||
}, | ||
user = typeof user === 'string' ? { username: user } : user; | ||
this.user = user; | ||
this.user.accountType = orgType; | ||
var internalDomain = void 0; | ||
/** | ||
* Creates a copy of this object. | ||
* | ||
* @return {Object} The clone. | ||
* | ||
* @example | ||
* | ||
* var clone = instance.clone(); | ||
*/ | ||
clone: function () { | ||
return this.init.prototype.extend(this); | ||
} | ||
}; | ||
}()); | ||
if (user.email && user.email.split) { | ||
var domain = user.email.split('@')[1]; | ||
internalDomain = internalOrgs.filter(function (org) { | ||
return domain === org; | ||
}).length > 0; | ||
} | ||
/** | ||
* An array of 32-bit words. | ||
* | ||
* @property {Array} words The array of 32-bit words. | ||
* @property {number} sigBytes The number of significant bytes in this word array. | ||
*/ | ||
var WordArray = C_lib.WordArray = Base.extend({ | ||
/** | ||
* Initializes a newly created word array. | ||
* | ||
* @param {Array} words (Optional) An array of 32-bit words. | ||
* @param {number} sigBytes (Optional) The number of significant bytes in the words. | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.lib.WordArray.create(); | ||
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); | ||
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); | ||
*/ | ||
init: function (words, sigBytes) { | ||
words = this.words = words || []; | ||
if (internalDomain || ['In House', 'Demo and Marketing'].indexOf(orgType) > -1) { | ||
this.user.internalUser = true; | ||
} | ||
} | ||
}, { | ||
key: 'logPageView', | ||
value: function logPageView(page) { | ||
var event = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
if (sigBytes != undefined$1) { | ||
this.sigBytes = sigBytes; | ||
} else { | ||
this.sigBytes = words.length * 4; | ||
} | ||
}, | ||
var attributes = this.preProcess(event, options); | ||
/** | ||
* Converts this word array to a string. | ||
* | ||
* @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex | ||
* | ||
* @return {string} The stringified word array. | ||
* | ||
* @example | ||
* | ||
* var string = wordArray + ''; | ||
* var string = wordArray.toString(); | ||
* var string = wordArray.toString(CryptoJS.enc.Utf8); | ||
*/ | ||
toString: function (encoder) { | ||
return (encoder || Hex).stringify(this); | ||
}, | ||
if (this.debug) { | ||
console.log('Tracking page view', JSON.stringify(attributes)); | ||
} | ||
/** | ||
* Concatenates a word array to this word array. | ||
* | ||
* @param {WordArray} wordArray The word array to append. | ||
* | ||
* @return {WordArray} This word array. | ||
* | ||
* @example | ||
* | ||
* wordArray1.concat(wordArray2); | ||
*/ | ||
concat: function (wordArray) { | ||
// Shortcuts | ||
var thisWords = this.words; | ||
var thatWords = wordArray.words; | ||
var thisSigBytes = this.sigBytes; | ||
var thatSigBytes = wordArray.sigBytes; | ||
if (this.test && !this.disabled) { | ||
return attributes; | ||
} | ||
// Clamp excess bits | ||
this.clamp(); | ||
var trackers = this.trackers.filter(function (_ref) { | ||
var disabled = _ref.disabled; | ||
return !disabled; | ||
}); | ||
// Concat | ||
if (thisSigBytes % 4) { | ||
// Copy one byte at a time | ||
for (var i = 0; i < thatSigBytes; i++) { | ||
var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); | ||
} | ||
} else { | ||
// Copy one word at a time | ||
for (var j = 0; j < thatSigBytes; j += 4) { | ||
thisWords[(thisSigBytes + j) >>> 2] = thatWords[j >>> 2]; | ||
} | ||
} | ||
this.sigBytes += thatSigBytes; | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Page view was not logged because no trackers are configured.')); | ||
} | ||
// Chainable | ||
return this; | ||
}, | ||
return false; | ||
} | ||
/** | ||
* Removes insignificant bits. | ||
* | ||
* @example | ||
* | ||
* wordArray.clamp(); | ||
*/ | ||
clamp: function () { | ||
// Shortcuts | ||
var words = this.words; | ||
var sigBytes = this.sigBytes; | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
}); | ||
// Clamp | ||
words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); | ||
words.length = Math.ceil(sigBytes / 4); | ||
}, | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logEvent', | ||
value: function logEvent(event) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* Creates a copy of this word array. | ||
* | ||
* @return {WordArray} The clone. | ||
* | ||
* @example | ||
* | ||
* var clone = wordArray.clone(); | ||
*/ | ||
clone: function () { | ||
var clone = Base.clone.call(this); | ||
clone.words = this.words.slice(0); | ||
event = this.preProcess(event, options); | ||
return clone; | ||
}, | ||
if (this.debug) { | ||
console.log('Tracking event', JSON.stringify(event)); | ||
} | ||
/** | ||
* Creates a word array filled with random bytes. | ||
* | ||
* @param {number} nBytes The number of random bytes to generate. | ||
* | ||
* @return {WordArray} The random word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.lib.WordArray.random(16); | ||
*/ | ||
random: function (nBytes) { | ||
var words = []; | ||
if (this.test) { | ||
return event; | ||
} | ||
for (var i = 0; i < nBytes; i += 4) { | ||
words.push(cryptoSecureRandomInt()); | ||
} | ||
var trackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
return new WordArray.init(words, nBytes); | ||
} | ||
}); | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Event was not logged because no trackers are configured.')); | ||
} | ||
/** | ||
* Encoder namespace. | ||
*/ | ||
var C_enc = C.enc = {}; | ||
return false; | ||
} | ||
/** | ||
* Hex encoding strategy. | ||
*/ | ||
var Hex = C_enc.Hex = { | ||
/** | ||
* Converts a word array to a hex string. | ||
* | ||
* @param {WordArray} wordArray The word array. | ||
* | ||
* @return {string} The hex string. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var hexString = CryptoJS.enc.Hex.stringify(wordArray); | ||
*/ | ||
stringify: function (wordArray) { | ||
// Shortcuts | ||
var words = wordArray.words; | ||
var sigBytes = wordArray.sigBytes; | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
}); | ||
// Convert | ||
var hexChars = []; | ||
for (var i = 0; i < sigBytes; i++) { | ||
var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
hexChars.push((bite >>> 4).toString(16)); | ||
hexChars.push((bite & 0x0f).toString(16)); | ||
} | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logError', | ||
value: function logError() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return hexChars.join(''); | ||
}, | ||
var event = _extends({ eventType: 'error' }, options); | ||
this.logEvent(event); | ||
} | ||
}, { | ||
key: 'startWorkflow', | ||
value: function startWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* Converts a hex string to a word array. | ||
* | ||
* @param {string} hexStr The hex string. | ||
* | ||
* @return {WordArray} The word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.enc.Hex.parse(hexString); | ||
*/ | ||
parse: function (hexStr) { | ||
// Shortcut | ||
var hexStrLength = hexStr.length; | ||
var workflow = { | ||
name: name, | ||
start: Date.now(), | ||
steps: [], | ||
workflowId: Math.floor((1 + Math.random()) * 0x100000000000).toString(16) | ||
}; | ||
this._saveWorkflow(workflow); | ||
var workflowObj = _extends({ name: name, step: 'start' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
return workflow; | ||
} | ||
}, { | ||
key: 'stepWorkflow', | ||
value: function stepWorkflow(name, step) { | ||
var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
// Convert | ||
var words = []; | ||
for (var i = 0; i < hexStrLength; i += 2) { | ||
words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); | ||
} | ||
//TODO: check if the check for attributes being a string is useful or can be removed | ||
var details = typeof attributes === 'string' ? attributes : attributes.details; | ||
var workflowObj = _extends({ name: name, step: step, details: details }, attributes); | ||
this._logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'endWorkflow', | ||
value: function endWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return new WordArray.init(words, hexStrLength / 2); | ||
} | ||
}; | ||
var workflowObj = _extends({ name: name, step: 'finish' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'cancelWorkflow', | ||
value: function cancelWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* Latin1 encoding strategy. | ||
*/ | ||
var Latin1 = C_enc.Latin1 = { | ||
/** | ||
* Converts a word array to a Latin1 string. | ||
* | ||
* @param {WordArray} wordArray The word array. | ||
* | ||
* @return {string} The Latin1 string. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); | ||
*/ | ||
stringify: function (wordArray) { | ||
// Shortcuts | ||
var words = wordArray.words; | ||
var sigBytes = wordArray.sigBytes; | ||
var workflowObj = _extends({ name: name, step: 'cancel' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'getWorkflow', | ||
value: function getWorkflow(name) { | ||
var workflow = storage.get('TELEMETRY-WORKFLOW:' + name); | ||
// do not let old workflows be returned | ||
if (workflow) { | ||
var workflowAge = Date.now() - workflow.start; | ||
var timeout = 30 * 60 * 1000; | ||
if (workflowAge < timeout) { | ||
return workflow; | ||
} else { | ||
this._deleteWorkflow(workflow); | ||
} | ||
} | ||
} | ||
}, { | ||
key: '_saveWorkflow', | ||
value: function _saveWorkflow(workflow) { | ||
storage.set('TELEMETRY-WORKFLOW:' + workflow.name, workflow); | ||
} | ||
}, { | ||
key: '_deleteWorkflow', | ||
value: function _deleteWorkflow(workflow) { | ||
storage.delete('TELEMETRY-WORKFLOW:' + workflow.name); | ||
} | ||
}, { | ||
key: '_logWorkflow', | ||
value: function _logWorkflow() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
// Convert | ||
var latin1Chars = []; | ||
for (var i = 0; i < sigBytes; i++) { | ||
var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
latin1Chars.push(String.fromCharCode(bite)); | ||
} | ||
/* | ||
const workflow = { | ||
name: 'add layer to map', | ||
step: 'start', | ||
details: 'some details about the step' | ||
} | ||
*/ | ||
options = this.preProcess(options); | ||
var workflow = this.getWorkflow(options.name); | ||
return latin1Chars.join(''); | ||
}, | ||
if (!workflow) { | ||
this.startWorkflow(options.name); | ||
workflow = this.getWorkflow(options.name); | ||
} | ||
workflow.steps.push(options.step); | ||
workflow.duration = (Date.now() - workflow.start) / 1000; | ||
/** | ||
* Converts a Latin1 string to a word array. | ||
* | ||
* @param {string} latin1Str The Latin1 string. | ||
* | ||
* @return {WordArray} The word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.enc.Latin1.parse(latin1String); | ||
*/ | ||
parse: function (latin1Str) { | ||
// Shortcut | ||
var latin1StrLength = latin1Str.length; | ||
if (['cancel', 'finish'].indexOf(options.step) > -1) { | ||
this._deleteWorkflow(workflow); | ||
} else { | ||
this._saveWorkflow(workflow); | ||
} | ||
// Convert | ||
var words = []; | ||
for (var i = 0; i < latin1StrLength; i++) { | ||
words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); | ||
} | ||
var track = _extends(options, { | ||
eventType: 'workflow', | ||
category: options.name, | ||
action: options.step, | ||
label: options.details, | ||
duration: workflow.duration, | ||
workflowId: workflow.workflowId | ||
}); | ||
return new WordArray.init(words, latin1StrLength); | ||
} | ||
}; | ||
this.logEvent(track); | ||
} | ||
}, { | ||
key: 'preProcess', | ||
value: function preProcess() { | ||
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* UTF-8 encoding strategy. | ||
*/ | ||
var Utf8 = C_enc.Utf8 = { | ||
/** | ||
* Converts a word array to a UTF-8 string. | ||
* | ||
* @param {WordArray} wordArray The word array. | ||
* | ||
* @return {string} The UTF-8 string. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); | ||
*/ | ||
stringify: function (wordArray) { | ||
try { | ||
return decodeURIComponent(escape(Latin1.stringify(wordArray))); | ||
} catch (e) { | ||
throw new Error('Malformed UTF-8 data'); | ||
} | ||
}, | ||
var userMetadata = {}; | ||
/** | ||
* Converts a UTF-8 string to a word array. | ||
* | ||
* @param {string} utf8Str The UTF-8 string. | ||
* | ||
* @return {WordArray} The word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.enc.Utf8.parse(utf8String); | ||
*/ | ||
parse: function (utf8Str) { | ||
return Latin1.parse(unescape(encodeURIComponent(utf8Str))); | ||
} | ||
}; | ||
if (this.user) { | ||
userMetadata = { | ||
user: anonymize(this.user.username), | ||
org: anonymize(this.user.orgId), | ||
lastLogin: this.user.lastLogin, | ||
userSince: this.user.created, | ||
internalUser: this.user.internalUser || false, | ||
accountType: this.user.accountType | ||
}; | ||
} | ||
/** | ||
* Abstract buffered block algorithm template. | ||
* | ||
* The property blockSize must be implemented in a concrete subtype. | ||
* | ||
* @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 | ||
*/ | ||
var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ | ||
/** | ||
* Resets this block algorithm's data buffer to its initial state. | ||
* | ||
* @example | ||
* | ||
* bufferedBlockAlgorithm.reset(); | ||
*/ | ||
reset: function () { | ||
// Initial values | ||
this._data = new WordArray.init(); | ||
this._nDataBytes = 0; | ||
}, | ||
return Object.entries(_extends({}, event, userMetadata)).reduce(_makeEventPayload(options.omitComplexData), {}); | ||
} | ||
}, { | ||
key: 'disableTracker', | ||
value: function disableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref3) { | ||
var name = _ref3.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = true; | ||
} | ||
} | ||
}, { | ||
key: 'enableTracker', | ||
value: function enableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref4) { | ||
var name = _ref4.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = false; | ||
} | ||
} | ||
}]); | ||
return Telemetry; | ||
}(); | ||
/** | ||
* Adds new data to this block algorithm's buffer. | ||
* | ||
* @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. | ||
* | ||
* @example | ||
* | ||
* bufferedBlockAlgorithm._append('data'); | ||
* bufferedBlockAlgorithm._append(wordArray); | ||
*/ | ||
_append: function (data) { | ||
// Convert string to WordArray, else assume WordArray already | ||
if (typeof data == 'string') { | ||
data = Utf8.parse(data); | ||
} | ||
Telemetry.anonymize = anonymize; | ||
Telemetry.internalOrgs = internalOrgs; | ||
Telemetry.telemetryEnabled = telemetryEnabled; | ||
Telemetry.storage = storage; | ||
// Append | ||
this._data.concat(data); | ||
this._nDataBytes += data.sigBytes; | ||
}, | ||
/** | ||
* Processes available data blocks. | ||
* | ||
* This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. | ||
* | ||
* @param {boolean} doFlush Whether all blocks and partial blocks should be processed. | ||
* | ||
* @return {WordArray} The processed data. | ||
* | ||
* @example | ||
* | ||
* var processedData = bufferedBlockAlgorithm._process(); | ||
* var processedData = bufferedBlockAlgorithm._process(!!'flush'); | ||
*/ | ||
_process: function (doFlush) { | ||
var processedWords; | ||
function _makeEventPayload(omitComplexData) { | ||
return function (acc, _ref5) { | ||
var _ref6 = slicedToArray(_ref5, 2), | ||
key = _ref6[0], | ||
val = _ref6[1]; | ||
// Shortcuts | ||
var data = this._data; | ||
var dataWords = data.words; | ||
var dataSigBytes = data.sigBytes; | ||
var blockSize = this.blockSize; | ||
var blockSizeBytes = blockSize * 4; | ||
if (_isPrimitive(val)) { | ||
acc[key] = val; | ||
} else if (!omitComplexData) { | ||
console.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
acc[key] = val; | ||
} | ||
return acc; | ||
}; | ||
} | ||
// Count blocks ready | ||
var nBlocksReady = dataSigBytes / blockSizeBytes; | ||
if (doFlush) { | ||
// Round up to include partial blocks | ||
nBlocksReady = Math.ceil(nBlocksReady); | ||
} else { | ||
// Round down to include only full blocks, | ||
// less the number of blocks that must remain in the buffer | ||
nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); | ||
} | ||
function _isPrimitive(val) { | ||
var primitives = ['string', 'number', 'boolean', 'undefined']; | ||
return primitives.includes(typeof val === 'undefined' ? 'undefined' : _typeof(val)) || val && typeof val.valueOf() === 'string'; | ||
} | ||
// Count words ready | ||
var nWordsReady = nBlocksReady * blockSize; | ||
return Telemetry; | ||
// Count bytes ready | ||
var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); | ||
// Process blocks | ||
if (nWordsReady) { | ||
for (var offset = 0; offset < nWordsReady; offset += blockSize) { | ||
// Perform concrete-algorithm logic | ||
this._doProcessBlock(dataWords, offset); | ||
} | ||
// Remove processed words | ||
processedWords = dataWords.splice(0, nWordsReady); | ||
data.sigBytes -= nBytesReady; | ||
} | ||
// Return processed words | ||
return new WordArray.init(processedWords, nBytesReady); | ||
}, | ||
/** | ||
* Creates a copy of this object. | ||
* | ||
* @return {Object} The clone. | ||
* | ||
* @example | ||
* | ||
* var clone = bufferedBlockAlgorithm.clone(); | ||
*/ | ||
clone: function () { | ||
var clone = Base.clone.call(this); | ||
clone._data = this._data.clone(); | ||
return clone; | ||
}, | ||
_minBufferSize: 0 | ||
}); | ||
/** | ||
* Abstract hasher template. | ||
* | ||
* @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) | ||
*/ | ||
C_lib.Hasher = BufferedBlockAlgorithm.extend({ | ||
/** | ||
* Configuration options. | ||
*/ | ||
cfg: Base.extend(), | ||
/** | ||
* Initializes a newly created hasher. | ||
* | ||
* @param {Object} cfg (Optional) The configuration options to use for this hash computation. | ||
* | ||
* @example | ||
* | ||
* var hasher = CryptoJS.algo.SHA256.create(); | ||
*/ | ||
init: function (cfg) { | ||
// Apply config defaults | ||
this.cfg = this.cfg.extend(cfg); | ||
// Set initial values | ||
this.reset(); | ||
}, | ||
/** | ||
* Resets this hasher to its initial state. | ||
* | ||
* @example | ||
* | ||
* hasher.reset(); | ||
*/ | ||
reset: function () { | ||
// Reset data buffer | ||
BufferedBlockAlgorithm.reset.call(this); | ||
// Perform concrete-hasher logic | ||
this._doReset(); | ||
}, | ||
/** | ||
* Updates this hasher with a message. | ||
* | ||
* @param {WordArray|string} messageUpdate The message to append. | ||
* | ||
* @return {Hasher} This hasher. | ||
* | ||
* @example | ||
* | ||
* hasher.update('message'); | ||
* hasher.update(wordArray); | ||
*/ | ||
update: function (messageUpdate) { | ||
// Append | ||
this._append(messageUpdate); | ||
// Update the hash | ||
this._process(); | ||
// Chainable | ||
return this; | ||
}, | ||
/** | ||
* Finalizes the hash computation. | ||
* Note that the finalize operation is effectively a destructive, read-once operation. | ||
* | ||
* @param {WordArray|string} messageUpdate (Optional) A final message update. | ||
* | ||
* @return {WordArray} The hash. | ||
* | ||
* @example | ||
* | ||
* var hash = hasher.finalize(); | ||
* var hash = hasher.finalize('message'); | ||
* var hash = hasher.finalize(wordArray); | ||
*/ | ||
finalize: function (messageUpdate) { | ||
// Final message update | ||
if (messageUpdate) { | ||
this._append(messageUpdate); | ||
} | ||
// Perform concrete-hasher logic | ||
var hash = this._doFinalize(); | ||
return hash; | ||
}, | ||
blockSize: 512/32, | ||
/** | ||
* Creates a shortcut function to a hasher's object interface. | ||
* | ||
* @param {Hasher} hasher The hasher to create a helper for. | ||
* | ||
* @return {Function} The shortcut function. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); | ||
*/ | ||
_createHelper: function (hasher) { | ||
return function (message, cfg) { | ||
return new hasher.init(cfg).finalize(message); | ||
}; | ||
}, | ||
/** | ||
* Creates a shortcut function to the HMAC's object interface. | ||
* | ||
* @param {Hasher} hasher The hasher to use in this HMAC helper. | ||
* | ||
* @return {Function} The shortcut function. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); | ||
*/ | ||
_createHmacHelper: function (hasher) { | ||
return function (message, key) { | ||
return new C_algo.HMAC.init(hasher, key).finalize(message); | ||
}; | ||
} | ||
}); | ||
/** | ||
* Algorithm namespace. | ||
*/ | ||
var C_algo = C.algo = {}; | ||
return C; | ||
}(Math)); | ||
return CryptoJS; | ||
})); | ||
}(core)); | ||
(function (module, exports) { | ||
(function (root, factory) { | ||
{ | ||
// CommonJS | ||
module.exports = factory(core.exports); | ||
} | ||
}(commonjsGlobal, function (CryptoJS) { | ||
(function (Math) { | ||
// Shortcuts | ||
var C = CryptoJS; | ||
var C_lib = C.lib; | ||
var WordArray = C_lib.WordArray; | ||
var Hasher = C_lib.Hasher; | ||
var C_algo = C.algo; | ||
// Initialization and round constants tables | ||
var H = []; | ||
var K = []; | ||
// Compute constants | ||
(function () { | ||
function isPrime(n) { | ||
var sqrtN = Math.sqrt(n); | ||
for (var factor = 2; factor <= sqrtN; factor++) { | ||
if (!(n % factor)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function getFractionalBits(n) { | ||
return ((n - (n | 0)) * 0x100000000) | 0; | ||
} | ||
var n = 2; | ||
var nPrime = 0; | ||
while (nPrime < 64) { | ||
if (isPrime(n)) { | ||
if (nPrime < 8) { | ||
H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); | ||
} | ||
K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); | ||
nPrime++; | ||
} | ||
n++; | ||
} | ||
}()); | ||
// Reusable object | ||
var W = []; | ||
/** | ||
* SHA-256 hash algorithm. | ||
*/ | ||
var SHA256 = C_algo.SHA256 = Hasher.extend({ | ||
_doReset: function () { | ||
this._hash = new WordArray.init(H.slice(0)); | ||
}, | ||
_doProcessBlock: function (M, offset) { | ||
// Shortcut | ||
var H = this._hash.words; | ||
// Working variables | ||
var a = H[0]; | ||
var b = H[1]; | ||
var c = H[2]; | ||
var d = H[3]; | ||
var e = H[4]; | ||
var f = H[5]; | ||
var g = H[6]; | ||
var h = H[7]; | ||
// Computation | ||
for (var i = 0; i < 64; i++) { | ||
if (i < 16) { | ||
W[i] = M[offset + i] | 0; | ||
} else { | ||
var gamma0x = W[i - 15]; | ||
var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ | ||
((gamma0x << 14) | (gamma0x >>> 18)) ^ | ||
(gamma0x >>> 3); | ||
var gamma1x = W[i - 2]; | ||
var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ | ||
((gamma1x << 13) | (gamma1x >>> 19)) ^ | ||
(gamma1x >>> 10); | ||
W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; | ||
} | ||
var ch = (e & f) ^ (~e & g); | ||
var maj = (a & b) ^ (a & c) ^ (b & c); | ||
var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); | ||
var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); | ||
var t1 = h + sigma1 + ch + K[i] + W[i]; | ||
var t2 = sigma0 + maj; | ||
h = g; | ||
g = f; | ||
f = e; | ||
e = (d + t1) | 0; | ||
d = c; | ||
c = b; | ||
b = a; | ||
a = (t1 + t2) | 0; | ||
} | ||
// Intermediate hash value | ||
H[0] = (H[0] + a) | 0; | ||
H[1] = (H[1] + b) | 0; | ||
H[2] = (H[2] + c) | 0; | ||
H[3] = (H[3] + d) | 0; | ||
H[4] = (H[4] + e) | 0; | ||
H[5] = (H[5] + f) | 0; | ||
H[6] = (H[6] + g) | 0; | ||
H[7] = (H[7] + h) | 0; | ||
}, | ||
_doFinalize: function () { | ||
// Shortcuts | ||
var data = this._data; | ||
var dataWords = data.words; | ||
var nBitsTotal = this._nDataBytes * 8; | ||
var nBitsLeft = data.sigBytes * 8; | ||
// Add padding | ||
dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); | ||
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); | ||
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; | ||
data.sigBytes = dataWords.length * 4; | ||
// Hash final blocks | ||
this._process(); | ||
// Return final computed hash | ||
return this._hash; | ||
}, | ||
clone: function () { | ||
var clone = Hasher.clone.call(this); | ||
clone._hash = this._hash.clone(); | ||
return clone; | ||
} | ||
}); | ||
/** | ||
* Shortcut function to the hasher's object interface. | ||
* | ||
* @param {WordArray|string} message The message to hash. | ||
* | ||
* @return {WordArray} The hash. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var hash = CryptoJS.SHA256('message'); | ||
* var hash = CryptoJS.SHA256(wordArray); | ||
*/ | ||
C.SHA256 = Hasher._createHelper(SHA256); | ||
/** | ||
* Shortcut function to the HMAC's object interface. | ||
* | ||
* @param {WordArray|string} message The message to hash. | ||
* @param {WordArray|string} key The secret key. | ||
* | ||
* @return {WordArray} The HMAC. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var hmac = CryptoJS.HmacSHA256(message, key); | ||
*/ | ||
C.HmacSHA256 = Hasher._createHmacHelper(SHA256); | ||
}(Math)); | ||
return CryptoJS.SHA256; | ||
})); | ||
}(sha256$1)); | ||
var sha256 = sha256$1.exports; | ||
var encHex = {exports: {}}; | ||
(function (module, exports) { | ||
(function (root, factory) { | ||
{ | ||
// CommonJS | ||
module.exports = factory(core.exports); | ||
} | ||
}(commonjsGlobal, function (CryptoJS) { | ||
return CryptoJS.enc.Hex; | ||
})); | ||
}(encHex)); | ||
var hex = encHex.exports; | ||
var storage = { | ||
storage: {}, | ||
memory: true, | ||
get: function get(key) { | ||
var stored = void 0; | ||
try { | ||
stored = window.localStorage && window.localStorage.getItem(key) || this.storage[key]; | ||
} catch (e) { | ||
stored = this.storage[key]; | ||
} | ||
if (stored) { | ||
try { | ||
return JSON.parse(stored); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
}, | ||
set: function set(key, value) { | ||
// handle Safari private mode (setItem is not allowed) | ||
var valueToString = JSON.stringify(value); | ||
try { | ||
window.localStorage.setItem(key, valueToString); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
this.storage[key] = value; | ||
} | ||
}, | ||
delete: function _delete(key) { | ||
try { | ||
window.localStorage.removeItem(key); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
delete this.storage[key]; | ||
} | ||
} | ||
}; | ||
function telemetryEnabled() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var portal = options.portal || {}; | ||
if (options.disabled) { | ||
return false; | ||
} | ||
if (_hasDoNotTrackEnabled()) { | ||
return false; | ||
} | ||
if (typeof portal.eueiEnabled !== 'undefined' && portal.eueiEnabled === false) { | ||
// Portal does not allow tracking | ||
return false; | ||
} | ||
if (portal.eueiEnabled && portal.user && portal.user.orgId === portal.id) { | ||
// Portal allows tracking; except when user is anonymous or doesn't belong to portal's org | ||
return true; | ||
} | ||
if (portal.user && !portal.user.orgId && portal.ipCntryCode === 'US') { | ||
// Public user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (!portal.user && portal.ipCntryCode === 'US') { | ||
// Anonymous user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (Object.keys(portal).length > 0) { | ||
// Initialized with a Portal object but does not meet tracking conditions | ||
return false; | ||
} | ||
// Default condition not initialized with a Portal-Self object | ||
return true; | ||
} | ||
function _hasDoNotTrackEnabled() { | ||
return (typeof navigator !== 'undefined' && navigator.doNotTrack) === '1' || typeof window !== 'undefined' && window.doNotTrack === '1'; | ||
} | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
var slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
var INTERNAL_ORGS = ['esri.com', 'esriuk.com', 'esri.de', 'esri.ca', 'esrifrance.fr', 'esri.nl', 'esri-portugal.pt', 'esribulgaria.com', 'esri.fi', 'esri.kr', 'esrimalaysia.com.my', 'esri.es', 'esriaustralia.com.au', 'esri-southafrica.com', 'esri.cl', 'esrichina.com.cn', 'esri.co', 'esriturkey.com.tr', 'geodata.no', 'esriitalia.it', 'esri.pl']; | ||
var Telemetry = function () { | ||
function Telemetry(options) { | ||
classCallCheck(this, Telemetry); | ||
var _a, _b, _c; | ||
this.trackers = []; | ||
this.options = options; | ||
this.test = options.test; | ||
this.debug = options.debug; | ||
this.disabled = !telemetryEnabled(options); | ||
if (this.disabled) { | ||
console.warn('Telemetry Disabled'); | ||
} | ||
var user = ((_a = options.portal) === null || _a === void 0 ? void 0 : _a.user) || options.user; | ||
if (user) { | ||
this.setUser(user, (_c = (_b = options.portal) === null || _b === void 0 ? void 0 : _b.subscriptionInfo) === null || _c === void 0 ? void 0 : _c.type); | ||
} | ||
if (!this.disabled) { | ||
this.initializeTrackers(); | ||
} | ||
} | ||
createClass(Telemetry, [{ | ||
key: 'initializeTrackers', | ||
value: function initializeTrackers() { | ||
if (this.options.plugins) { | ||
var _trackers; | ||
(_trackers = this.trackers).push.apply(_trackers, toConsumableArray(this.options.plugins)); | ||
} | ||
if (!this.trackers.length) { | ||
console.error(new Error('No trackers configured')); | ||
} | ||
} | ||
}, { | ||
key: 'setUser', | ||
value: function setUser() { | ||
var user = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var orgType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Public'; | ||
user = typeof user === 'string' ? { username: user } : user; | ||
this.user = user; | ||
this.user.accountType = orgType; | ||
var internalDomain = void 0; | ||
if (user.email && user.email.split) { | ||
var domain = user.email.split('@')[1]; | ||
internalDomain = INTERNAL_ORGS.filter(function (org) { | ||
return domain === org; | ||
}).length > 0; | ||
} | ||
if (internalDomain || ['In House', 'Demo and Marketing'].indexOf(orgType) > -1) { | ||
this.user.internalUser = true; | ||
} | ||
} | ||
}, { | ||
key: 'logPageView', | ||
value: function logPageView(page) { | ||
var event = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var attributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking page view', JSON.stringify(attributes)); | ||
} | ||
if (this.test && !this.disabled) { | ||
return attributes; | ||
} | ||
var trackers = this.trackers.filter(function (_ref) { | ||
var disabled = _ref.disabled; | ||
return !disabled; | ||
}); | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Page view was not logged because no trackers are configured.')); | ||
} | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
}); | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logEvent', | ||
value: function logEvent(event) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
event = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking event', JSON.stringify(event)); | ||
} | ||
if (this.test) { | ||
return event; | ||
} | ||
var trackers = void 0; | ||
if (this.trackers.length) { | ||
trackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
} | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Event was not logged because no trackers are configured.')); | ||
} | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
}); | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logError', | ||
value: function logError() { | ||
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
event = _extends({ eventType: 'error' }, event); | ||
this.logEvent(event); | ||
} | ||
}, { | ||
key: 'startWorkflow', | ||
value: function startWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflow = { | ||
name: name, | ||
start: Date.now(), | ||
steps: [], | ||
workflowId: Math.floor((1 + Math.random()) * 0x100000000000).toString(16) | ||
}; | ||
this.saveWorkflow(workflow); | ||
var workflowObj = _extends({ name: name, step: 'start' }, attributes); | ||
this.logWorkflow(workflowObj); | ||
return workflow; | ||
} | ||
}, { | ||
key: 'stepWorkflow', | ||
value: function stepWorkflow(name, step) { | ||
var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
//TODO: check if the check for attributes being a string is useful or can be removed | ||
var details = typeof attributes === 'string' ? attributes : attributes.details; | ||
var workflowObj = _extends({ name: name, step: step, details: details }, attributes); | ||
this.logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'endWorkflow', | ||
value: function endWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflowObj = _extends({ name: name, step: 'finish' }, attributes); | ||
this.logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'cancelWorkflow', | ||
value: function cancelWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflowObj = _extends({ name: name, step: 'cancel' }, attributes); | ||
this.logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'getWorkflow', | ||
value: function getWorkflow(name) { | ||
var workflow = storage.get('TELEMETRY-WORKFLOW:' + name); | ||
// do not let old workflows be returned | ||
if (workflow) { | ||
var workflowAge = Date.now() - workflow.start; | ||
var timeout = 30 * 60 * 1000; | ||
if (workflowAge < timeout) { | ||
return workflow; | ||
} else { | ||
this.deleteWorkflow(workflow); | ||
} | ||
} | ||
} | ||
}, { | ||
key: 'saveWorkflow', | ||
value: function saveWorkflow(workflow) { | ||
storage.set('TELEMETRY-WORKFLOW:' + workflow.name, workflow); | ||
} | ||
}, { | ||
key: 'deleteWorkflow', | ||
value: function deleteWorkflow(workflow) { | ||
storage.delete('TELEMETRY-WORKFLOW:' + workflow.name); | ||
} | ||
}, { | ||
key: 'logWorkflow', | ||
value: function logWorkflow() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
/* | ||
const workflow = { | ||
name: 'add layer to map', | ||
step: 'start', | ||
details: 'some details about the step' | ||
} | ||
*/ | ||
options = this.preProcess(options); | ||
var workflow = this.getWorkflow(options.name); | ||
if (!workflow) { | ||
this.startWorkflow(options.name); | ||
workflow = this.getWorkflow(options.name); | ||
} | ||
workflow.steps.push(options.step); | ||
workflow.duration = (Date.now() - workflow.start) / 1000; | ||
if (['cancel', 'finish'].indexOf(options.step) > -1) { | ||
this.deleteWorkflow(workflow); | ||
} else { | ||
this.saveWorkflow(workflow); | ||
} | ||
var track = _extends(options, { | ||
eventType: 'workflow', | ||
category: options.name, | ||
action: options.step, | ||
label: options.details, | ||
duration: workflow.duration, | ||
workflowId: workflow.workflowId | ||
}); | ||
this.logEvent(track); | ||
} | ||
}, { | ||
key: 'preProcess', | ||
value: function preProcess() { | ||
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var userMetadata = {}; | ||
if (this.user) { | ||
userMetadata = { | ||
user: anonymize(this.user.username), | ||
org: anonymize(this.user.orgId), | ||
lastLogin: this.user.lastLogin, | ||
userSince: this.user.created, | ||
internalUser: this.user.internalUser || false, | ||
accountType: this.user.accountType | ||
}; | ||
} | ||
return Object.entries(_extends(_extends({}, event), userMetadata)).reduce(makeEventPayload(options.omitComplexData), {}); | ||
} | ||
}, { | ||
key: 'disableTracker', | ||
value: function disableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref3) { | ||
var name = _ref3.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = true; | ||
} | ||
} | ||
}, { | ||
key: 'enableTracker', | ||
value: function enableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref4) { | ||
var name = _ref4.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = false; | ||
} | ||
} | ||
}]); | ||
return Telemetry; | ||
}(); | ||
Telemetry.storage = storage; | ||
function anonymize(user) { | ||
if (!user) return; | ||
return sha256(user).toString(hex); | ||
} | ||
function makeEventPayload(omitComplexData) { | ||
return function (acc, _ref5) { | ||
var _ref6 = slicedToArray(_ref5, 2), | ||
key = _ref6[0], | ||
val = _ref6[1]; | ||
if (isPrimitive(val)) { | ||
acc[key] = val; | ||
} else if (!omitComplexData) { | ||
console.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
acc[key] = val; | ||
} | ||
return acc; | ||
}; | ||
} | ||
function isPrimitive(val) { | ||
var primitives = ['string', 'number', 'boolean', 'undefined']; | ||
return primitives.includes(typeof val === 'undefined' ? 'undefined' : _typeof(val)) || val && typeof val.valueOf() === 'string'; | ||
} | ||
return Telemetry; | ||
})); | ||
//# sourceMappingURL=telemetry.amd.min.js.map |
define((function () { 'use strict'; | ||
function anonymize(user) { | ||
if (!user) return undefined; | ||
return CryptoJS.SHA256(user).toString(CryptoJS.enc.Hex); | ||
} | ||
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
var internalOrgs = ['esri.com', 'esriuk.com', 'esri.de', 'esri.ca', 'esrifrance.fr', 'esri.nl', 'esri-portugal.pt', 'esribulgaria.com', 'esri.fi', 'esri.kr', 'esrimalaysia.com.my', 'esri.es', 'esriaustralia.com.au', 'esri-southafrica.com', 'esri.cl', 'esrichina.com.cn', 'esri.co', 'esriturkey.com.tr', 'geodata.no', 'esriitalia.it', 'esri.pl']; | ||
function commonjsRequire (path) { | ||
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.'); | ||
} | ||
var storage = { | ||
storage: {}, | ||
memory: true, | ||
get: function get(key) { | ||
var stored = void 0; | ||
try { | ||
stored = window.localStorage && window.localStorage.getItem(key) || this.storage[key]; | ||
} catch (e) { | ||
stored = this.storage[key]; | ||
} | ||
if (stored) { | ||
try { | ||
return JSON.parse(stored); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
}, | ||
set: function set(key, value) { | ||
// handle Safari private mode (setItem is not allowed) | ||
value = JSON.stringify(value); | ||
try { | ||
window.localStorage.setItem(key, value); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
this.storage[key] = value; | ||
} | ||
}, | ||
delete: function _delete(key) { | ||
try { | ||
window.localStorage.removeItem(key); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
delete this.storage[key]; | ||
} | ||
} | ||
}; | ||
var sha256$1 = {exports: {}}; | ||
/* | ||
* Determines whether or not the telemetry library should be enabled based on passed in options | ||
*/ | ||
function telemetryEnabled() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var core = {exports: {}}; | ||
var portal = options.portal || {}; | ||
(function (module, exports) { | ||
(function (root, factory) { | ||
{ | ||
// CommonJS | ||
module.exports = factory(); | ||
} | ||
}(commonjsGlobal, function () { | ||
if (options.disabled) { | ||
// Tracking is manually disabled | ||
return false; | ||
} | ||
/*globals window, global, require*/ | ||
if (_hasDoNotTrackEnabled()) { | ||
// user's browser has turned off tracking | ||
return false; | ||
} | ||
/** | ||
* CryptoJS core components. | ||
*/ | ||
var CryptoJS = CryptoJS || (function (Math, undefined$1) { | ||
if (typeof portal.eueiEnabled !== 'undefined' && portal.eueiEnabled === false) { | ||
// Portal does not allow tracking | ||
return false; | ||
} | ||
var crypto; | ||
if (portal.eueiEnabled && portal.user && portal.user.orgId === portal.id) { | ||
// Portal allows tracking; except when user is anonymous or doesn't belong to portal's org | ||
return true; | ||
} | ||
// Native crypto from window (Browser) | ||
if (typeof window !== 'undefined' && window.crypto) { | ||
crypto = window.crypto; | ||
} | ||
if (portal.user && !portal.user.orgId && portal.ipCntryCode === 'US') { | ||
// Public user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
// Native crypto in web worker (Browser) | ||
if (typeof self !== 'undefined' && self.crypto) { | ||
crypto = self.crypto; | ||
} | ||
if (!portal.user && portal.ipCntryCode === 'US') { | ||
// Anonymous user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
// Native crypto from worker | ||
if (typeof globalThis !== 'undefined' && globalThis.crypto) { | ||
crypto = globalThis.crypto; | ||
} | ||
if (Object.keys(portal).length > 0) { | ||
// Initialized with a Portal object but does not meet tracking conditions | ||
return false; | ||
} | ||
// Native (experimental IE 11) crypto from window (Browser) | ||
if (!crypto && typeof window !== 'undefined' && window.msCrypto) { | ||
crypto = window.msCrypto; | ||
} | ||
// Default condition not initialized with a Portal-Self object | ||
return true; | ||
} | ||
// Native crypto from global (NodeJS) | ||
if (!crypto && typeof commonjsGlobal !== 'undefined' && commonjsGlobal.crypto) { | ||
crypto = commonjsGlobal.crypto; | ||
} | ||
function _hasDoNotTrackEnabled() { | ||
return (typeof navigator !== 'undefined' && navigator.doNotTrack) === '1' || typeof window !== 'undefined' && window.doNotTrack === '1'; | ||
} | ||
// Native crypto import via require (NodeJS) | ||
if (!crypto && typeof commonjsRequire === 'function') { | ||
try { | ||
crypto = require('crypto'); | ||
} catch (err) {} | ||
} | ||
/* | ||
(c) 2009-2013 by Jeff Mott. All rights reserved. | ||
/* | ||
* Cryptographically secure pseudorandom number generator | ||
* | ||
* As Math.random() is cryptographically not safe to use | ||
*/ | ||
var cryptoSecureRandomInt = function () { | ||
if (crypto) { | ||
// Use getRandomValues method (Browser) | ||
if (typeof crypto.getRandomValues === 'function') { | ||
try { | ||
return crypto.getRandomValues(new Uint32Array(1))[0]; | ||
} catch (err) {} | ||
} | ||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
// Use randomBytes method (NodeJS) | ||
if (typeof crypto.randomBytes === 'function') { | ||
try { | ||
return crypto.randomBytes(4).readInt32LE(); | ||
} catch (err) {} | ||
} | ||
} | ||
Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer. | ||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation or other materials provided with the distribution. | ||
Neither the name CryptoJS nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS," AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
var CryptoJS = function (h, s) { | ||
var f = {}, | ||
g = f.lib = {}, | ||
q = function q() {}, | ||
m = g.Base = { | ||
extend: function extend(a) { | ||
q.prototype = this; | ||
var c = new q(); | ||
a && c.mixIn(a); | ||
c.hasOwnProperty('init') || (c.init = function () { | ||
c.$super.init.apply(this, arguments); | ||
}); | ||
c.init.prototype = c; | ||
c.$super = this; | ||
return c; | ||
}, | ||
create: function create() { | ||
var a = this.extend(); | ||
a.init.apply(a, arguments); | ||
return a; | ||
}, | ||
init: function init() {}, | ||
mixIn: function mixIn(a) { | ||
for (var c in a) { | ||
a.hasOwnProperty(c) && (this[c] = a[c]); | ||
}a.hasOwnProperty('toString') && (this.toString = a.toString); | ||
}, | ||
clone: function clone() { | ||
return this.init.prototype.extend(this); | ||
} | ||
}, | ||
r = g.WordArray = m.extend({ | ||
init: function init(a, c) { | ||
a = this.words = a || []; | ||
this.sigBytes = c != s ? c : 4 * a.length; | ||
}, | ||
toString: function toString(a) { | ||
return (a || k).stringify(this); | ||
}, | ||
concat: function concat(a) { | ||
var c = this.words, | ||
d = a.words, | ||
b = this.sigBytes; | ||
a = a.sigBytes; | ||
this.clamp(); | ||
if (b % 4) for (var e = 0; e < a; e++) { | ||
c[b + e >>> 2] |= (d[e >>> 2] >>> 24 - 8 * (e % 4) & 255) << 24 - 8 * ((b + e) % 4); | ||
} else if (d.length > 65535) for (e = 0; e < a; e += 4) { | ||
c[b + e >>> 2] = d[e >>> 2]; | ||
} else c.push.apply(c, d); | ||
this.sigBytes += a; | ||
return this; | ||
}, | ||
clamp: function clamp() { | ||
var a = this.words, | ||
c = this.sigBytes; | ||
a[c >>> 2] &= 4294967295 << 32 - 8 * (c % 4); | ||
a.length = h.ceil(c / 4); | ||
}, | ||
clone: function clone() { | ||
var a = m.clone.call(this); | ||
a.words = this.words.slice(0); | ||
return a; | ||
}, | ||
random: function random(a) { | ||
for (var c = [], d = 0; d < a; d += 4) { | ||
c.push(4294967296 * h.random() | 0); | ||
}return new r.init(c, a); | ||
} | ||
}), | ||
l = f.enc = {}, | ||
k = l.Hex = { | ||
stringify: function stringify(a) { | ||
var c = a.words; | ||
a = a.sigBytes; | ||
for (var d = [], b = 0; b < a; b++) { | ||
var e = c[b >>> 2] >>> 24 - 8 * (b % 4) & 255; | ||
d.push((e >>> 4).toString(16)); | ||
d.push((e & 15).toString(16)); | ||
} | ||
return d.join(''); | ||
}, | ||
parse: function parse(a) { | ||
for (var c = a.length, d = [], b = 0; b < c; b += 2) { | ||
d[b >>> 3] |= parseInt(a.substr(b, 2), 16) << 24 - 4 * (b % 8); | ||
} | ||
return new r.init(d, c / 2); | ||
} | ||
}, | ||
n = l.Latin1 = { | ||
stringify: function stringify(a) { | ||
var c = a.words; | ||
a = a.sigBytes; | ||
for (var d = [], b = 0; b < a; b++) { | ||
d.push(String.fromCharCode(c[b >>> 2] >>> 24 - 8 * (b % 4) & 255)); | ||
}return d.join(''); | ||
}, | ||
parse: function parse(a) { | ||
for (var c = a.length, d = [], b = 0; b < c; b++) { | ||
d[b >>> 2] |= (a.charCodeAt(b) & 255) << 24 - 8 * (b % 4); | ||
}return new r.init(d, c); | ||
} | ||
}, | ||
j = l.Utf8 = { | ||
stringify: function stringify(a) { | ||
try { | ||
return decodeURIComponent(escape(n.stringify(a))); | ||
} catch (c) { | ||
throw Error('Malformed UTF-8 data'); | ||
} | ||
}, | ||
parse: function parse(a) { | ||
return n.parse(unescape(encodeURIComponent(a))); | ||
} | ||
}, | ||
u = g.BufferedBlockAlgorithm = m.extend({ | ||
reset: function reset() { | ||
this._data = new r.init(); | ||
this._nDataBytes = 0; | ||
}, | ||
_append: function _append(a) { | ||
typeof a === 'string' && (a = j.parse(a)); | ||
this._data.concat(a); | ||
this._nDataBytes += a.sigBytes; | ||
}, | ||
_process: function _process(a) { | ||
var c = this._data, | ||
d = c.words, | ||
b = c.sigBytes, | ||
e = this.blockSize, | ||
f = b / (4 * e), | ||
f = a ? h.ceil(f) : h.max((f | 0) - this._minBufferSize, 0); | ||
a = f * e; | ||
b = h.min(4 * a, b); | ||
if (a) { | ||
for (var g = 0; g < a; g += e) { | ||
this._doProcessBlock(d, g); | ||
}g = d.splice(0, a); | ||
c.sigBytes -= b; | ||
} | ||
return new r.init(g, b); | ||
}, | ||
clone: function clone() { | ||
var a = m.clone.call(this); | ||
a._data = this._data.clone(); | ||
return a; | ||
}, | ||
_minBufferSize: 0 | ||
}); | ||
g.Hasher = u.extend({ | ||
cfg: m.extend(), | ||
init: function init(a) { | ||
this.cfg = this.cfg.extend(a); | ||
this.reset(); | ||
}, | ||
reset: function reset() { | ||
u.reset.call(this); | ||
this._doReset(); | ||
}, | ||
update: function update(a) { | ||
this._append(a); | ||
this._process(); | ||
return this; | ||
}, | ||
finalize: function finalize(a) { | ||
a && this._append(a); | ||
return this._doFinalize(); | ||
}, | ||
blockSize: 16, | ||
_createHelper: function _createHelper(a) { | ||
return function (c, d) { | ||
return new a.init(d).finalize(c); | ||
}; | ||
}, | ||
_createHmacHelper: function _createHmacHelper(a) { | ||
return function (c, d) { | ||
return new t.HMAC.init(a, d).finalize(c); | ||
}; | ||
} | ||
}); | ||
var t = f.algo = {}; | ||
return f; | ||
}(Math); | ||
(function (h) { | ||
for (var s = CryptoJS, f = s.lib, g = f.WordArray, q = f.Hasher, f = s.algo, m = [], r = [], l = function l(a) { | ||
return 4294967296 * (a - (a | 0)) | 0; | ||
}, k = 2, n = 0; n < 64;) { | ||
var j; | ||
a: { | ||
j = k; | ||
for (var u = h.sqrt(j), t = 2; t <= u; t++) { | ||
if (!(j % t)) { | ||
j = !1; | ||
break a; | ||
} | ||
}j = !0; | ||
} | ||
j && (n < 8 && (m[n] = l(h.pow(k, 0.5))), r[n] = l(h.pow(k, 1 / 3)), n++); | ||
k++; | ||
} | ||
var a = [], | ||
f = f.SHA256 = q.extend({ | ||
_doReset: function _doReset() { | ||
this._hash = new g.init(m.slice(0)); | ||
}, | ||
_doProcessBlock: function _doProcessBlock(c, d) { | ||
for (var b = this._hash.words, e = b[0], f = b[1], g = b[2], j = b[3], h = b[4], m = b[5], n = b[6], q = b[7], p = 0; p < 64; p++) { | ||
if (p < 16) { | ||
a[p] = c[d + p] | 0; | ||
} else { | ||
var k = a[p - 15], | ||
l = a[p - 2]; | ||
a[p] = ((k << 25 | k >>> 7) ^ (k << 14 | k >>> 18) ^ k >>> 3) + a[p - 7] + ((l << 15 | l >>> 17) ^ (l << 13 | l >>> 19) ^ l >>> 10) + a[p - 16]; | ||
} | ||
k = q + ((h << 26 | h >>> 6) ^ (h << 21 | h >>> 11) ^ (h << 7 | h >>> 25)) + (h & m ^ ~h & n) + r[p] + a[p]; | ||
l = ((e << 30 | e >>> 2) ^ (e << 19 | e >>> 13) ^ (e << 10 | e >>> 22)) + (e & f ^ e & g ^ f & g); | ||
q = n; | ||
n = m; | ||
m = h; | ||
h = j + k | 0; | ||
j = g; | ||
g = f; | ||
f = e; | ||
e = k + l | 0; | ||
} | ||
b[0] = b[0] + e | 0; | ||
b[1] = b[1] + f | 0; | ||
b[2] = b[2] + g | 0; | ||
b[3] = b[3] + j | 0; | ||
b[4] = b[4] + h | 0; | ||
b[5] = b[5] + m | 0; | ||
b[6] = b[6] + n | 0; | ||
b[7] = b[7] + q | 0; | ||
}, | ||
_doFinalize: function _doFinalize() { | ||
var a = this._data, | ||
d = a.words, | ||
b = 8 * this._nDataBytes, | ||
e = 8 * a.sigBytes; | ||
d[e >>> 5] |= 128 << 24 - e % 32; | ||
d[(e + 64 >>> 9 << 4) + 14] = h.floor(b / 4294967296); | ||
d[(e + 64 >>> 9 << 4) + 15] = b; | ||
a.sigBytes = 4 * d.length; | ||
this._process(); | ||
return this._hash; | ||
}, | ||
clone: function clone() { | ||
var a = q.clone.call(this); | ||
a._hash = this._hash.clone(); | ||
return a; | ||
} | ||
}); | ||
s.SHA256 = q._createHelper(f); | ||
s.HmacSHA256 = q._createHmacHelper(f); | ||
})(Math); | ||
(function () { | ||
var h = CryptoJS, | ||
s = h.enc.Utf8; | ||
h.algo.HMAC = h.lib.Base.extend({ | ||
init: function init(f, g) { | ||
f = this._hasher = new f.init(); | ||
typeof g === 'string' && (g = s.parse(g)); | ||
var h = f.blockSize, | ||
m = 4 * h; | ||
g.sigBytes > m && (g = f.finalize(g)); | ||
g.clamp(); | ||
for (var r = this._oKey = g.clone(), l = this._iKey = g.clone(), k = r.words, n = l.words, j = 0; j < h; j++) { | ||
k[j] ^= 1549556828, n[j] ^= 909522486; | ||
}r.sigBytes = l.sigBytes = m; | ||
this.reset(); | ||
}, | ||
reset: function reset() { | ||
var f = this._hasher; | ||
f.reset(); | ||
f.update(this._iKey); | ||
}, | ||
update: function update(f) { | ||
this._hasher.update(f); | ||
return this; | ||
}, | ||
finalize: function finalize(f) { | ||
var g = this._hasher; | ||
f = g.finalize(f); | ||
g.reset(); | ||
return g.finalize(this._oKey.clone().concat(f)); | ||
} | ||
}); | ||
})(); | ||
throw new Error('Native crypto module could not be used to get secure random number.'); | ||
}; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
/* | ||
* Local polyfill of Object.create | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
*/ | ||
var create = Object.create || (function () { | ||
function F() {} | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (obj) { | ||
var subtype; | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
F.prototype = obj; | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
subtype = new F(); | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
F.prototype = null; | ||
return target; | ||
}; | ||
return subtype; | ||
}; | ||
}()); | ||
var slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
/** | ||
* CryptoJS namespace. | ||
*/ | ||
var C = {}; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
/** | ||
* Library namespace. | ||
*/ | ||
var C_lib = C.lib = {}; | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
/** | ||
* Base object for prototypal inheritance. | ||
*/ | ||
var Base = C_lib.Base = (function () { | ||
return _arr; | ||
} | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
return { | ||
/** | ||
* Creates a new object that inherits from this object. | ||
* | ||
* @param {Object} overrides Properties to copy into the new object. | ||
* | ||
* @return {Object} The new object. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var MyType = CryptoJS.lib.Base.extend({ | ||
* field: 'value', | ||
* | ||
* method: function () { | ||
* } | ||
* }); | ||
*/ | ||
extend: function (overrides) { | ||
// Spawn | ||
var subtype = create(this); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
// Augment | ||
if (overrides) { | ||
subtype.mixIn(overrides); | ||
} | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
// Create default initializer | ||
if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { | ||
subtype.init = function () { | ||
subtype.$super.init.apply(this, arguments); | ||
}; | ||
} | ||
var Telemetry = function () { | ||
function Telemetry(options) { | ||
classCallCheck(this, Telemetry); | ||
// Initializer's prototype is the subtype object | ||
subtype.init.prototype = subtype; | ||
// Make sure failure to init this library cannot have side-effects | ||
try { | ||
this.trackers = []; | ||
this.workflows = {}; | ||
this.test = options.test; | ||
this.debug = options.debug; | ||
this.disabled = !telemetryEnabled(options); | ||
// Reference supertype | ||
subtype.$super = this; | ||
if (this.disabled) { | ||
console.log('Telemetry Disabled'); | ||
} | ||
return subtype; | ||
}, | ||
if (options.portal && options.portal.user) { | ||
var subscriptionInfo = options.portal.subscriptionInfo || {}; | ||
this.setUser(options.portal.user, subscriptionInfo.type); | ||
} else if (options.user) { | ||
this.setUser(options.user); | ||
} | ||
/** | ||
* Extends this object and runs the init method. | ||
* Arguments to create() will be passed to init(). | ||
* | ||
* @return {Object} The new object. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var instance = MyType.create(); | ||
*/ | ||
create: function () { | ||
var instance = this.extend(); | ||
instance.init.apply(instance, arguments); | ||
if (!this.disabled) { | ||
this._initializeTrackers(options); | ||
} | ||
} catch (e) { | ||
console.error('Telemetry Disabled'); | ||
console.error(e); | ||
this.disabled = true; | ||
} | ||
} | ||
return instance; | ||
}, | ||
createClass(Telemetry, [{ | ||
key: '_initializeTrackers', | ||
value: function _initializeTrackers(options) { | ||
if (options.plugins) { | ||
var _trackers; | ||
/** | ||
* Initializes a newly created object. | ||
* Override this method to add some logic when your objects are created. | ||
* | ||
* @example | ||
* | ||
* var MyType = CryptoJS.lib.Base.extend({ | ||
* init: function () { | ||
* // ... | ||
* } | ||
* }); | ||
*/ | ||
init: function () { | ||
}, | ||
(_trackers = this.trackers).push.apply(_trackers, toConsumableArray(options.plugins)); | ||
} | ||
/** | ||
* Copies properties into this object. | ||
* | ||
* @param {Object} properties The properties to mix in. | ||
* | ||
* @example | ||
* | ||
* MyType.mixIn({ | ||
* field: 'value' | ||
* }); | ||
*/ | ||
mixIn: function (properties) { | ||
for (var propertyName in properties) { | ||
if (properties.hasOwnProperty(propertyName)) { | ||
this[propertyName] = properties[propertyName]; | ||
} | ||
} | ||
if (!this.trackers.length) { | ||
console.error(new Error('No trackers configured')); | ||
} | ||
} | ||
}, { | ||
key: 'setUser', | ||
value: function setUser() { | ||
var user = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var orgType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Public'; | ||
// IE won't copy toString using the loop above | ||
if (properties.hasOwnProperty('toString')) { | ||
this.toString = properties.toString; | ||
} | ||
}, | ||
user = typeof user === 'string' ? { username: user } : user; | ||
this.user = user; | ||
this.user.accountType = orgType; | ||
var internalDomain = void 0; | ||
/** | ||
* Creates a copy of this object. | ||
* | ||
* @return {Object} The clone. | ||
* | ||
* @example | ||
* | ||
* var clone = instance.clone(); | ||
*/ | ||
clone: function () { | ||
return this.init.prototype.extend(this); | ||
} | ||
}; | ||
}()); | ||
if (user.email && user.email.split) { | ||
var domain = user.email.split('@')[1]; | ||
internalDomain = internalOrgs.filter(function (org) { | ||
return domain === org; | ||
}).length > 0; | ||
} | ||
/** | ||
* An array of 32-bit words. | ||
* | ||
* @property {Array} words The array of 32-bit words. | ||
* @property {number} sigBytes The number of significant bytes in this word array. | ||
*/ | ||
var WordArray = C_lib.WordArray = Base.extend({ | ||
/** | ||
* Initializes a newly created word array. | ||
* | ||
* @param {Array} words (Optional) An array of 32-bit words. | ||
* @param {number} sigBytes (Optional) The number of significant bytes in the words. | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.lib.WordArray.create(); | ||
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); | ||
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); | ||
*/ | ||
init: function (words, sigBytes) { | ||
words = this.words = words || []; | ||
if (internalDomain || ['In House', 'Demo and Marketing'].indexOf(orgType) > -1) { | ||
this.user.internalUser = true; | ||
} | ||
} | ||
}, { | ||
key: 'logPageView', | ||
value: function logPageView(page) { | ||
var event = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
if (sigBytes != undefined$1) { | ||
this.sigBytes = sigBytes; | ||
} else { | ||
this.sigBytes = words.length * 4; | ||
} | ||
}, | ||
var attributes = this.preProcess(event, options); | ||
/** | ||
* Converts this word array to a string. | ||
* | ||
* @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex | ||
* | ||
* @return {string} The stringified word array. | ||
* | ||
* @example | ||
* | ||
* var string = wordArray + ''; | ||
* var string = wordArray.toString(); | ||
* var string = wordArray.toString(CryptoJS.enc.Utf8); | ||
*/ | ||
toString: function (encoder) { | ||
return (encoder || Hex).stringify(this); | ||
}, | ||
if (this.debug) { | ||
console.log('Tracking page view', JSON.stringify(attributes)); | ||
} | ||
/** | ||
* Concatenates a word array to this word array. | ||
* | ||
* @param {WordArray} wordArray The word array to append. | ||
* | ||
* @return {WordArray} This word array. | ||
* | ||
* @example | ||
* | ||
* wordArray1.concat(wordArray2); | ||
*/ | ||
concat: function (wordArray) { | ||
// Shortcuts | ||
var thisWords = this.words; | ||
var thatWords = wordArray.words; | ||
var thisSigBytes = this.sigBytes; | ||
var thatSigBytes = wordArray.sigBytes; | ||
if (this.test && !this.disabled) { | ||
return attributes; | ||
} | ||
// Clamp excess bits | ||
this.clamp(); | ||
var trackers = this.trackers.filter(function (_ref) { | ||
var disabled = _ref.disabled; | ||
return !disabled; | ||
}); | ||
// Concat | ||
if (thisSigBytes % 4) { | ||
// Copy one byte at a time | ||
for (var i = 0; i < thatSigBytes; i++) { | ||
var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); | ||
} | ||
} else { | ||
// Copy one word at a time | ||
for (var j = 0; j < thatSigBytes; j += 4) { | ||
thisWords[(thisSigBytes + j) >>> 2] = thatWords[j >>> 2]; | ||
} | ||
} | ||
this.sigBytes += thatSigBytes; | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Page view was not logged because no trackers are configured.')); | ||
} | ||
// Chainable | ||
return this; | ||
}, | ||
return false; | ||
} | ||
/** | ||
* Removes insignificant bits. | ||
* | ||
* @example | ||
* | ||
* wordArray.clamp(); | ||
*/ | ||
clamp: function () { | ||
// Shortcuts | ||
var words = this.words; | ||
var sigBytes = this.sigBytes; | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
}); | ||
// Clamp | ||
words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); | ||
words.length = Math.ceil(sigBytes / 4); | ||
}, | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logEvent', | ||
value: function logEvent(event) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* Creates a copy of this word array. | ||
* | ||
* @return {WordArray} The clone. | ||
* | ||
* @example | ||
* | ||
* var clone = wordArray.clone(); | ||
*/ | ||
clone: function () { | ||
var clone = Base.clone.call(this); | ||
clone.words = this.words.slice(0); | ||
event = this.preProcess(event, options); | ||
return clone; | ||
}, | ||
if (this.debug) { | ||
console.log('Tracking event', JSON.stringify(event)); | ||
} | ||
/** | ||
* Creates a word array filled with random bytes. | ||
* | ||
* @param {number} nBytes The number of random bytes to generate. | ||
* | ||
* @return {WordArray} The random word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.lib.WordArray.random(16); | ||
*/ | ||
random: function (nBytes) { | ||
var words = []; | ||
if (this.test) { | ||
return event; | ||
} | ||
for (var i = 0; i < nBytes; i += 4) { | ||
words.push(cryptoSecureRandomInt()); | ||
} | ||
var trackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
return new WordArray.init(words, nBytes); | ||
} | ||
}); | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Event was not logged because no trackers are configured.')); | ||
} | ||
/** | ||
* Encoder namespace. | ||
*/ | ||
var C_enc = C.enc = {}; | ||
return false; | ||
} | ||
/** | ||
* Hex encoding strategy. | ||
*/ | ||
var Hex = C_enc.Hex = { | ||
/** | ||
* Converts a word array to a hex string. | ||
* | ||
* @param {WordArray} wordArray The word array. | ||
* | ||
* @return {string} The hex string. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var hexString = CryptoJS.enc.Hex.stringify(wordArray); | ||
*/ | ||
stringify: function (wordArray) { | ||
// Shortcuts | ||
var words = wordArray.words; | ||
var sigBytes = wordArray.sigBytes; | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
}); | ||
// Convert | ||
var hexChars = []; | ||
for (var i = 0; i < sigBytes; i++) { | ||
var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
hexChars.push((bite >>> 4).toString(16)); | ||
hexChars.push((bite & 0x0f).toString(16)); | ||
} | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logError', | ||
value: function logError() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return hexChars.join(''); | ||
}, | ||
var event = _extends({ eventType: 'error' }, options); | ||
this.logEvent(event); | ||
} | ||
}, { | ||
key: 'startWorkflow', | ||
value: function startWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* Converts a hex string to a word array. | ||
* | ||
* @param {string} hexStr The hex string. | ||
* | ||
* @return {WordArray} The word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.enc.Hex.parse(hexString); | ||
*/ | ||
parse: function (hexStr) { | ||
// Shortcut | ||
var hexStrLength = hexStr.length; | ||
var workflow = { | ||
name: name, | ||
start: Date.now(), | ||
steps: [], | ||
workflowId: Math.floor((1 + Math.random()) * 0x100000000000).toString(16) | ||
}; | ||
this._saveWorkflow(workflow); | ||
var workflowObj = _extends({ name: name, step: 'start' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
return workflow; | ||
} | ||
}, { | ||
key: 'stepWorkflow', | ||
value: function stepWorkflow(name, step) { | ||
var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
// Convert | ||
var words = []; | ||
for (var i = 0; i < hexStrLength; i += 2) { | ||
words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); | ||
} | ||
//TODO: check if the check for attributes being a string is useful or can be removed | ||
var details = typeof attributes === 'string' ? attributes : attributes.details; | ||
var workflowObj = _extends({ name: name, step: step, details: details }, attributes); | ||
this._logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'endWorkflow', | ||
value: function endWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return new WordArray.init(words, hexStrLength / 2); | ||
} | ||
}; | ||
var workflowObj = _extends({ name: name, step: 'finish' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'cancelWorkflow', | ||
value: function cancelWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* Latin1 encoding strategy. | ||
*/ | ||
var Latin1 = C_enc.Latin1 = { | ||
/** | ||
* Converts a word array to a Latin1 string. | ||
* | ||
* @param {WordArray} wordArray The word array. | ||
* | ||
* @return {string} The Latin1 string. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); | ||
*/ | ||
stringify: function (wordArray) { | ||
// Shortcuts | ||
var words = wordArray.words; | ||
var sigBytes = wordArray.sigBytes; | ||
var workflowObj = _extends({ name: name, step: 'cancel' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'getWorkflow', | ||
value: function getWorkflow(name) { | ||
var workflow = storage.get('TELEMETRY-WORKFLOW:' + name); | ||
// do not let old workflows be returned | ||
if (workflow) { | ||
var workflowAge = Date.now() - workflow.start; | ||
var timeout = 30 * 60 * 1000; | ||
if (workflowAge < timeout) { | ||
return workflow; | ||
} else { | ||
this._deleteWorkflow(workflow); | ||
} | ||
} | ||
} | ||
}, { | ||
key: '_saveWorkflow', | ||
value: function _saveWorkflow(workflow) { | ||
storage.set('TELEMETRY-WORKFLOW:' + workflow.name, workflow); | ||
} | ||
}, { | ||
key: '_deleteWorkflow', | ||
value: function _deleteWorkflow(workflow) { | ||
storage.delete('TELEMETRY-WORKFLOW:' + workflow.name); | ||
} | ||
}, { | ||
key: '_logWorkflow', | ||
value: function _logWorkflow() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
// Convert | ||
var latin1Chars = []; | ||
for (var i = 0; i < sigBytes; i++) { | ||
var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
latin1Chars.push(String.fromCharCode(bite)); | ||
} | ||
/* | ||
const workflow = { | ||
name: 'add layer to map', | ||
step: 'start', | ||
details: 'some details about the step' | ||
} | ||
*/ | ||
options = this.preProcess(options); | ||
var workflow = this.getWorkflow(options.name); | ||
return latin1Chars.join(''); | ||
}, | ||
if (!workflow) { | ||
this.startWorkflow(options.name); | ||
workflow = this.getWorkflow(options.name); | ||
} | ||
workflow.steps.push(options.step); | ||
workflow.duration = (Date.now() - workflow.start) / 1000; | ||
/** | ||
* Converts a Latin1 string to a word array. | ||
* | ||
* @param {string} latin1Str The Latin1 string. | ||
* | ||
* @return {WordArray} The word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.enc.Latin1.parse(latin1String); | ||
*/ | ||
parse: function (latin1Str) { | ||
// Shortcut | ||
var latin1StrLength = latin1Str.length; | ||
if (['cancel', 'finish'].indexOf(options.step) > -1) { | ||
this._deleteWorkflow(workflow); | ||
} else { | ||
this._saveWorkflow(workflow); | ||
} | ||
// Convert | ||
var words = []; | ||
for (var i = 0; i < latin1StrLength; i++) { | ||
words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); | ||
} | ||
var track = _extends(options, { | ||
eventType: 'workflow', | ||
category: options.name, | ||
action: options.step, | ||
label: options.details, | ||
duration: workflow.duration, | ||
workflowId: workflow.workflowId | ||
}); | ||
return new WordArray.init(words, latin1StrLength); | ||
} | ||
}; | ||
this.logEvent(track); | ||
} | ||
}, { | ||
key: 'preProcess', | ||
value: function preProcess() { | ||
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* UTF-8 encoding strategy. | ||
*/ | ||
var Utf8 = C_enc.Utf8 = { | ||
/** | ||
* Converts a word array to a UTF-8 string. | ||
* | ||
* @param {WordArray} wordArray The word array. | ||
* | ||
* @return {string} The UTF-8 string. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); | ||
*/ | ||
stringify: function (wordArray) { | ||
try { | ||
return decodeURIComponent(escape(Latin1.stringify(wordArray))); | ||
} catch (e) { | ||
throw new Error('Malformed UTF-8 data'); | ||
} | ||
}, | ||
var userMetadata = {}; | ||
/** | ||
* Converts a UTF-8 string to a word array. | ||
* | ||
* @param {string} utf8Str The UTF-8 string. | ||
* | ||
* @return {WordArray} The word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.enc.Utf8.parse(utf8String); | ||
*/ | ||
parse: function (utf8Str) { | ||
return Latin1.parse(unescape(encodeURIComponent(utf8Str))); | ||
} | ||
}; | ||
if (this.user) { | ||
userMetadata = { | ||
user: anonymize(this.user.username), | ||
org: anonymize(this.user.orgId), | ||
lastLogin: this.user.lastLogin, | ||
userSince: this.user.created, | ||
internalUser: this.user.internalUser || false, | ||
accountType: this.user.accountType | ||
}; | ||
} | ||
/** | ||
* Abstract buffered block algorithm template. | ||
* | ||
* The property blockSize must be implemented in a concrete subtype. | ||
* | ||
* @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 | ||
*/ | ||
var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ | ||
/** | ||
* Resets this block algorithm's data buffer to its initial state. | ||
* | ||
* @example | ||
* | ||
* bufferedBlockAlgorithm.reset(); | ||
*/ | ||
reset: function () { | ||
// Initial values | ||
this._data = new WordArray.init(); | ||
this._nDataBytes = 0; | ||
}, | ||
return Object.entries(_extends({}, event, userMetadata)).reduce(_makeEventPayload(options.omitComplexData), {}); | ||
} | ||
}, { | ||
key: 'disableTracker', | ||
value: function disableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref3) { | ||
var name = _ref3.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = true; | ||
} | ||
} | ||
}, { | ||
key: 'enableTracker', | ||
value: function enableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref4) { | ||
var name = _ref4.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = false; | ||
} | ||
} | ||
}]); | ||
return Telemetry; | ||
}(); | ||
/** | ||
* Adds new data to this block algorithm's buffer. | ||
* | ||
* @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. | ||
* | ||
* @example | ||
* | ||
* bufferedBlockAlgorithm._append('data'); | ||
* bufferedBlockAlgorithm._append(wordArray); | ||
*/ | ||
_append: function (data) { | ||
// Convert string to WordArray, else assume WordArray already | ||
if (typeof data == 'string') { | ||
data = Utf8.parse(data); | ||
} | ||
Telemetry.anonymize = anonymize; | ||
Telemetry.internalOrgs = internalOrgs; | ||
Telemetry.telemetryEnabled = telemetryEnabled; | ||
Telemetry.storage = storage; | ||
// Append | ||
this._data.concat(data); | ||
this._nDataBytes += data.sigBytes; | ||
}, | ||
/** | ||
* Processes available data blocks. | ||
* | ||
* This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. | ||
* | ||
* @param {boolean} doFlush Whether all blocks and partial blocks should be processed. | ||
* | ||
* @return {WordArray} The processed data. | ||
* | ||
* @example | ||
* | ||
* var processedData = bufferedBlockAlgorithm._process(); | ||
* var processedData = bufferedBlockAlgorithm._process(!!'flush'); | ||
*/ | ||
_process: function (doFlush) { | ||
var processedWords; | ||
function _makeEventPayload(omitComplexData) { | ||
return function (acc, _ref5) { | ||
var _ref6 = slicedToArray(_ref5, 2), | ||
key = _ref6[0], | ||
val = _ref6[1]; | ||
// Shortcuts | ||
var data = this._data; | ||
var dataWords = data.words; | ||
var dataSigBytes = data.sigBytes; | ||
var blockSize = this.blockSize; | ||
var blockSizeBytes = blockSize * 4; | ||
if (_isPrimitive(val)) { | ||
acc[key] = val; | ||
} else if (!omitComplexData) { | ||
console.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
acc[key] = val; | ||
} | ||
return acc; | ||
}; | ||
} | ||
// Count blocks ready | ||
var nBlocksReady = dataSigBytes / blockSizeBytes; | ||
if (doFlush) { | ||
// Round up to include partial blocks | ||
nBlocksReady = Math.ceil(nBlocksReady); | ||
} else { | ||
// Round down to include only full blocks, | ||
// less the number of blocks that must remain in the buffer | ||
nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); | ||
} | ||
function _isPrimitive(val) { | ||
var primitives = ['string', 'number', 'boolean', 'undefined']; | ||
return primitives.includes(typeof val === 'undefined' ? 'undefined' : _typeof(val)) || val && typeof val.valueOf() === 'string'; | ||
} | ||
// Count words ready | ||
var nWordsReady = nBlocksReady * blockSize; | ||
return Telemetry; | ||
// Count bytes ready | ||
var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); | ||
// Process blocks | ||
if (nWordsReady) { | ||
for (var offset = 0; offset < nWordsReady; offset += blockSize) { | ||
// Perform concrete-algorithm logic | ||
this._doProcessBlock(dataWords, offset); | ||
} | ||
// Remove processed words | ||
processedWords = dataWords.splice(0, nWordsReady); | ||
data.sigBytes -= nBytesReady; | ||
} | ||
// Return processed words | ||
return new WordArray.init(processedWords, nBytesReady); | ||
}, | ||
/** | ||
* Creates a copy of this object. | ||
* | ||
* @return {Object} The clone. | ||
* | ||
* @example | ||
* | ||
* var clone = bufferedBlockAlgorithm.clone(); | ||
*/ | ||
clone: function () { | ||
var clone = Base.clone.call(this); | ||
clone._data = this._data.clone(); | ||
return clone; | ||
}, | ||
_minBufferSize: 0 | ||
}); | ||
/** | ||
* Abstract hasher template. | ||
* | ||
* @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) | ||
*/ | ||
C_lib.Hasher = BufferedBlockAlgorithm.extend({ | ||
/** | ||
* Configuration options. | ||
*/ | ||
cfg: Base.extend(), | ||
/** | ||
* Initializes a newly created hasher. | ||
* | ||
* @param {Object} cfg (Optional) The configuration options to use for this hash computation. | ||
* | ||
* @example | ||
* | ||
* var hasher = CryptoJS.algo.SHA256.create(); | ||
*/ | ||
init: function (cfg) { | ||
// Apply config defaults | ||
this.cfg = this.cfg.extend(cfg); | ||
// Set initial values | ||
this.reset(); | ||
}, | ||
/** | ||
* Resets this hasher to its initial state. | ||
* | ||
* @example | ||
* | ||
* hasher.reset(); | ||
*/ | ||
reset: function () { | ||
// Reset data buffer | ||
BufferedBlockAlgorithm.reset.call(this); | ||
// Perform concrete-hasher logic | ||
this._doReset(); | ||
}, | ||
/** | ||
* Updates this hasher with a message. | ||
* | ||
* @param {WordArray|string} messageUpdate The message to append. | ||
* | ||
* @return {Hasher} This hasher. | ||
* | ||
* @example | ||
* | ||
* hasher.update('message'); | ||
* hasher.update(wordArray); | ||
*/ | ||
update: function (messageUpdate) { | ||
// Append | ||
this._append(messageUpdate); | ||
// Update the hash | ||
this._process(); | ||
// Chainable | ||
return this; | ||
}, | ||
/** | ||
* Finalizes the hash computation. | ||
* Note that the finalize operation is effectively a destructive, read-once operation. | ||
* | ||
* @param {WordArray|string} messageUpdate (Optional) A final message update. | ||
* | ||
* @return {WordArray} The hash. | ||
* | ||
* @example | ||
* | ||
* var hash = hasher.finalize(); | ||
* var hash = hasher.finalize('message'); | ||
* var hash = hasher.finalize(wordArray); | ||
*/ | ||
finalize: function (messageUpdate) { | ||
// Final message update | ||
if (messageUpdate) { | ||
this._append(messageUpdate); | ||
} | ||
// Perform concrete-hasher logic | ||
var hash = this._doFinalize(); | ||
return hash; | ||
}, | ||
blockSize: 512/32, | ||
/** | ||
* Creates a shortcut function to a hasher's object interface. | ||
* | ||
* @param {Hasher} hasher The hasher to create a helper for. | ||
* | ||
* @return {Function} The shortcut function. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); | ||
*/ | ||
_createHelper: function (hasher) { | ||
return function (message, cfg) { | ||
return new hasher.init(cfg).finalize(message); | ||
}; | ||
}, | ||
/** | ||
* Creates a shortcut function to the HMAC's object interface. | ||
* | ||
* @param {Hasher} hasher The hasher to use in this HMAC helper. | ||
* | ||
* @return {Function} The shortcut function. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); | ||
*/ | ||
_createHmacHelper: function (hasher) { | ||
return function (message, key) { | ||
return new C_algo.HMAC.init(hasher, key).finalize(message); | ||
}; | ||
} | ||
}); | ||
/** | ||
* Algorithm namespace. | ||
*/ | ||
var C_algo = C.algo = {}; | ||
return C; | ||
}(Math)); | ||
return CryptoJS; | ||
})); | ||
}(core)); | ||
(function (module, exports) { | ||
(function (root, factory) { | ||
{ | ||
// CommonJS | ||
module.exports = factory(core.exports); | ||
} | ||
}(commonjsGlobal, function (CryptoJS) { | ||
(function (Math) { | ||
// Shortcuts | ||
var C = CryptoJS; | ||
var C_lib = C.lib; | ||
var WordArray = C_lib.WordArray; | ||
var Hasher = C_lib.Hasher; | ||
var C_algo = C.algo; | ||
// Initialization and round constants tables | ||
var H = []; | ||
var K = []; | ||
// Compute constants | ||
(function () { | ||
function isPrime(n) { | ||
var sqrtN = Math.sqrt(n); | ||
for (var factor = 2; factor <= sqrtN; factor++) { | ||
if (!(n % factor)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function getFractionalBits(n) { | ||
return ((n - (n | 0)) * 0x100000000) | 0; | ||
} | ||
var n = 2; | ||
var nPrime = 0; | ||
while (nPrime < 64) { | ||
if (isPrime(n)) { | ||
if (nPrime < 8) { | ||
H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); | ||
} | ||
K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); | ||
nPrime++; | ||
} | ||
n++; | ||
} | ||
}()); | ||
// Reusable object | ||
var W = []; | ||
/** | ||
* SHA-256 hash algorithm. | ||
*/ | ||
var SHA256 = C_algo.SHA256 = Hasher.extend({ | ||
_doReset: function () { | ||
this._hash = new WordArray.init(H.slice(0)); | ||
}, | ||
_doProcessBlock: function (M, offset) { | ||
// Shortcut | ||
var H = this._hash.words; | ||
// Working variables | ||
var a = H[0]; | ||
var b = H[1]; | ||
var c = H[2]; | ||
var d = H[3]; | ||
var e = H[4]; | ||
var f = H[5]; | ||
var g = H[6]; | ||
var h = H[7]; | ||
// Computation | ||
for (var i = 0; i < 64; i++) { | ||
if (i < 16) { | ||
W[i] = M[offset + i] | 0; | ||
} else { | ||
var gamma0x = W[i - 15]; | ||
var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ | ||
((gamma0x << 14) | (gamma0x >>> 18)) ^ | ||
(gamma0x >>> 3); | ||
var gamma1x = W[i - 2]; | ||
var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ | ||
((gamma1x << 13) | (gamma1x >>> 19)) ^ | ||
(gamma1x >>> 10); | ||
W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; | ||
} | ||
var ch = (e & f) ^ (~e & g); | ||
var maj = (a & b) ^ (a & c) ^ (b & c); | ||
var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); | ||
var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); | ||
var t1 = h + sigma1 + ch + K[i] + W[i]; | ||
var t2 = sigma0 + maj; | ||
h = g; | ||
g = f; | ||
f = e; | ||
e = (d + t1) | 0; | ||
d = c; | ||
c = b; | ||
b = a; | ||
a = (t1 + t2) | 0; | ||
} | ||
// Intermediate hash value | ||
H[0] = (H[0] + a) | 0; | ||
H[1] = (H[1] + b) | 0; | ||
H[2] = (H[2] + c) | 0; | ||
H[3] = (H[3] + d) | 0; | ||
H[4] = (H[4] + e) | 0; | ||
H[5] = (H[5] + f) | 0; | ||
H[6] = (H[6] + g) | 0; | ||
H[7] = (H[7] + h) | 0; | ||
}, | ||
_doFinalize: function () { | ||
// Shortcuts | ||
var data = this._data; | ||
var dataWords = data.words; | ||
var nBitsTotal = this._nDataBytes * 8; | ||
var nBitsLeft = data.sigBytes * 8; | ||
// Add padding | ||
dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); | ||
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); | ||
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; | ||
data.sigBytes = dataWords.length * 4; | ||
// Hash final blocks | ||
this._process(); | ||
// Return final computed hash | ||
return this._hash; | ||
}, | ||
clone: function () { | ||
var clone = Hasher.clone.call(this); | ||
clone._hash = this._hash.clone(); | ||
return clone; | ||
} | ||
}); | ||
/** | ||
* Shortcut function to the hasher's object interface. | ||
* | ||
* @param {WordArray|string} message The message to hash. | ||
* | ||
* @return {WordArray} The hash. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var hash = CryptoJS.SHA256('message'); | ||
* var hash = CryptoJS.SHA256(wordArray); | ||
*/ | ||
C.SHA256 = Hasher._createHelper(SHA256); | ||
/** | ||
* Shortcut function to the HMAC's object interface. | ||
* | ||
* @param {WordArray|string} message The message to hash. | ||
* @param {WordArray|string} key The secret key. | ||
* | ||
* @return {WordArray} The HMAC. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var hmac = CryptoJS.HmacSHA256(message, key); | ||
*/ | ||
C.HmacSHA256 = Hasher._createHmacHelper(SHA256); | ||
}(Math)); | ||
return CryptoJS.SHA256; | ||
})); | ||
}(sha256$1)); | ||
var sha256 = sha256$1.exports; | ||
var encHex = {exports: {}}; | ||
(function (module, exports) { | ||
(function (root, factory) { | ||
{ | ||
// CommonJS | ||
module.exports = factory(core.exports); | ||
} | ||
}(commonjsGlobal, function (CryptoJS) { | ||
return CryptoJS.enc.Hex; | ||
})); | ||
}(encHex)); | ||
var hex = encHex.exports; | ||
var storage = { | ||
storage: {}, | ||
memory: true, | ||
get: function get(key) { | ||
var stored = void 0; | ||
try { | ||
stored = window.localStorage && window.localStorage.getItem(key) || this.storage[key]; | ||
} catch (e) { | ||
stored = this.storage[key]; | ||
} | ||
if (stored) { | ||
try { | ||
return JSON.parse(stored); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
}, | ||
set: function set(key, value) { | ||
// handle Safari private mode (setItem is not allowed) | ||
var valueToString = JSON.stringify(value); | ||
try { | ||
window.localStorage.setItem(key, valueToString); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
this.storage[key] = value; | ||
} | ||
}, | ||
delete: function _delete(key) { | ||
try { | ||
window.localStorage.removeItem(key); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
delete this.storage[key]; | ||
} | ||
} | ||
}; | ||
function telemetryEnabled() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var portal = options.portal || {}; | ||
if (options.disabled) { | ||
return false; | ||
} | ||
if (_hasDoNotTrackEnabled()) { | ||
return false; | ||
} | ||
if (typeof portal.eueiEnabled !== 'undefined' && portal.eueiEnabled === false) { | ||
// Portal does not allow tracking | ||
return false; | ||
} | ||
if (portal.eueiEnabled && portal.user && portal.user.orgId === portal.id) { | ||
// Portal allows tracking; except when user is anonymous or doesn't belong to portal's org | ||
return true; | ||
} | ||
if (portal.user && !portal.user.orgId && portal.ipCntryCode === 'US') { | ||
// Public user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (!portal.user && portal.ipCntryCode === 'US') { | ||
// Anonymous user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (Object.keys(portal).length > 0) { | ||
// Initialized with a Portal object but does not meet tracking conditions | ||
return false; | ||
} | ||
// Default condition not initialized with a Portal-Self object | ||
return true; | ||
} | ||
function _hasDoNotTrackEnabled() { | ||
return (typeof navigator !== 'undefined' && navigator.doNotTrack) === '1' || typeof window !== 'undefined' && window.doNotTrack === '1'; | ||
} | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
var slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
var INTERNAL_ORGS = ['esri.com', 'esriuk.com', 'esri.de', 'esri.ca', 'esrifrance.fr', 'esri.nl', 'esri-portugal.pt', 'esribulgaria.com', 'esri.fi', 'esri.kr', 'esrimalaysia.com.my', 'esri.es', 'esriaustralia.com.au', 'esri-southafrica.com', 'esri.cl', 'esrichina.com.cn', 'esri.co', 'esriturkey.com.tr', 'geodata.no', 'esriitalia.it', 'esri.pl']; | ||
var Telemetry = function () { | ||
function Telemetry(options) { | ||
classCallCheck(this, Telemetry); | ||
var _a, _b, _c; | ||
this.trackers = []; | ||
this.options = options; | ||
this.test = options.test; | ||
this.debug = options.debug; | ||
this.disabled = !telemetryEnabled(options); | ||
if (this.disabled) { | ||
console.warn('Telemetry Disabled'); | ||
} | ||
var user = ((_a = options.portal) === null || _a === void 0 ? void 0 : _a.user) || options.user; | ||
if (user) { | ||
this.setUser(user, (_c = (_b = options.portal) === null || _b === void 0 ? void 0 : _b.subscriptionInfo) === null || _c === void 0 ? void 0 : _c.type); | ||
} | ||
if (!this.disabled) { | ||
this.initializeTrackers(); | ||
} | ||
} | ||
createClass(Telemetry, [{ | ||
key: 'initializeTrackers', | ||
value: function initializeTrackers() { | ||
if (this.options.plugins) { | ||
var _trackers; | ||
(_trackers = this.trackers).push.apply(_trackers, toConsumableArray(this.options.plugins)); | ||
} | ||
if (!this.trackers.length) { | ||
console.error(new Error('No trackers configured')); | ||
} | ||
} | ||
}, { | ||
key: 'setUser', | ||
value: function setUser() { | ||
var user = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var orgType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Public'; | ||
user = typeof user === 'string' ? { username: user } : user; | ||
this.user = user; | ||
this.user.accountType = orgType; | ||
var internalDomain = void 0; | ||
if (user.email && user.email.split) { | ||
var domain = user.email.split('@')[1]; | ||
internalDomain = INTERNAL_ORGS.filter(function (org) { | ||
return domain === org; | ||
}).length > 0; | ||
} | ||
if (internalDomain || ['In House', 'Demo and Marketing'].indexOf(orgType) > -1) { | ||
this.user.internalUser = true; | ||
} | ||
} | ||
}, { | ||
key: 'logPageView', | ||
value: function logPageView(page) { | ||
var event = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var attributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking page view', JSON.stringify(attributes)); | ||
} | ||
if (this.test && !this.disabled) { | ||
return attributes; | ||
} | ||
var trackers = this.trackers.filter(function (_ref) { | ||
var disabled = _ref.disabled; | ||
return !disabled; | ||
}); | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Page view was not logged because no trackers are configured.')); | ||
} | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
}); | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logEvent', | ||
value: function logEvent(event) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
event = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking event', JSON.stringify(event)); | ||
} | ||
if (this.test) { | ||
return event; | ||
} | ||
var trackers = void 0; | ||
if (this.trackers.length) { | ||
trackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
} | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Event was not logged because no trackers are configured.')); | ||
} | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
}); | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logError', | ||
value: function logError() { | ||
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
event = _extends({ eventType: 'error' }, event); | ||
this.logEvent(event); | ||
} | ||
}, { | ||
key: 'startWorkflow', | ||
value: function startWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflow = { | ||
name: name, | ||
start: Date.now(), | ||
steps: [], | ||
workflowId: Math.floor((1 + Math.random()) * 0x100000000000).toString(16) | ||
}; | ||
this.saveWorkflow(workflow); | ||
var workflowObj = _extends({ name: name, step: 'start' }, attributes); | ||
this.logWorkflow(workflowObj); | ||
return workflow; | ||
} | ||
}, { | ||
key: 'stepWorkflow', | ||
value: function stepWorkflow(name, step) { | ||
var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
//TODO: check if the check for attributes being a string is useful or can be removed | ||
var details = typeof attributes === 'string' ? attributes : attributes.details; | ||
var workflowObj = _extends({ name: name, step: step, details: details }, attributes); | ||
this.logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'endWorkflow', | ||
value: function endWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflowObj = _extends({ name: name, step: 'finish' }, attributes); | ||
this.logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'cancelWorkflow', | ||
value: function cancelWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflowObj = _extends({ name: name, step: 'cancel' }, attributes); | ||
this.logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'getWorkflow', | ||
value: function getWorkflow(name) { | ||
var workflow = storage.get('TELEMETRY-WORKFLOW:' + name); | ||
// do not let old workflows be returned | ||
if (workflow) { | ||
var workflowAge = Date.now() - workflow.start; | ||
var timeout = 30 * 60 * 1000; | ||
if (workflowAge < timeout) { | ||
return workflow; | ||
} else { | ||
this.deleteWorkflow(workflow); | ||
} | ||
} | ||
} | ||
}, { | ||
key: 'saveWorkflow', | ||
value: function saveWorkflow(workflow) { | ||
storage.set('TELEMETRY-WORKFLOW:' + workflow.name, workflow); | ||
} | ||
}, { | ||
key: 'deleteWorkflow', | ||
value: function deleteWorkflow(workflow) { | ||
storage.delete('TELEMETRY-WORKFLOW:' + workflow.name); | ||
} | ||
}, { | ||
key: 'logWorkflow', | ||
value: function logWorkflow() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
/* | ||
const workflow = { | ||
name: 'add layer to map', | ||
step: 'start', | ||
details: 'some details about the step' | ||
} | ||
*/ | ||
options = this.preProcess(options); | ||
var workflow = this.getWorkflow(options.name); | ||
if (!workflow) { | ||
this.startWorkflow(options.name); | ||
workflow = this.getWorkflow(options.name); | ||
} | ||
workflow.steps.push(options.step); | ||
workflow.duration = (Date.now() - workflow.start) / 1000; | ||
if (['cancel', 'finish'].indexOf(options.step) > -1) { | ||
this.deleteWorkflow(workflow); | ||
} else { | ||
this.saveWorkflow(workflow); | ||
} | ||
var track = _extends(options, { | ||
eventType: 'workflow', | ||
category: options.name, | ||
action: options.step, | ||
label: options.details, | ||
duration: workflow.duration, | ||
workflowId: workflow.workflowId | ||
}); | ||
this.logEvent(track); | ||
} | ||
}, { | ||
key: 'preProcess', | ||
value: function preProcess() { | ||
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var userMetadata = {}; | ||
if (this.user) { | ||
userMetadata = { | ||
user: anonymize(this.user.username), | ||
org: anonymize(this.user.orgId), | ||
lastLogin: this.user.lastLogin, | ||
userSince: this.user.created, | ||
internalUser: this.user.internalUser || false, | ||
accountType: this.user.accountType | ||
}; | ||
} | ||
return Object.entries(_extends(_extends({}, event), userMetadata)).reduce(makeEventPayload(options.omitComplexData), {}); | ||
} | ||
}, { | ||
key: 'disableTracker', | ||
value: function disableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref3) { | ||
var name = _ref3.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = true; | ||
} | ||
} | ||
}, { | ||
key: 'enableTracker', | ||
value: function enableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref4) { | ||
var name = _ref4.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = false; | ||
} | ||
} | ||
}]); | ||
return Telemetry; | ||
}(); | ||
Telemetry.storage = storage; | ||
function anonymize(user) { | ||
if (!user) return; | ||
return sha256(user).toString(hex); | ||
} | ||
function makeEventPayload(omitComplexData) { | ||
return function (acc, _ref5) { | ||
var _ref6 = slicedToArray(_ref5, 2), | ||
key = _ref6[0], | ||
val = _ref6[1]; | ||
if (isPrimitive(val)) { | ||
acc[key] = val; | ||
} else if (!omitComplexData) { | ||
console.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
acc[key] = val; | ||
} | ||
return acc; | ||
}; | ||
} | ||
function isPrimitive(val) { | ||
var primitives = ['string', 'number', 'boolean', 'undefined']; | ||
return primitives.includes(typeof val === 'undefined' ? 'undefined' : _typeof(val)) || val && typeof val.valueOf() === 'string'; | ||
} | ||
return Telemetry; | ||
})); | ||
//# sourceMappingURL=telemetry.dojo.js.map |
define((function () { 'use strict'; | ||
function anonymize(user) { | ||
if (!user) return undefined; | ||
return CryptoJS.SHA256(user).toString(CryptoJS.enc.Hex); | ||
} | ||
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
var internalOrgs = ['esri.com', 'esriuk.com', 'esri.de', 'esri.ca', 'esrifrance.fr', 'esri.nl', 'esri-portugal.pt', 'esribulgaria.com', 'esri.fi', 'esri.kr', 'esrimalaysia.com.my', 'esri.es', 'esriaustralia.com.au', 'esri-southafrica.com', 'esri.cl', 'esrichina.com.cn', 'esri.co', 'esriturkey.com.tr', 'geodata.no', 'esriitalia.it', 'esri.pl']; | ||
function commonjsRequire (path) { | ||
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.'); | ||
} | ||
var storage = { | ||
storage: {}, | ||
memory: true, | ||
get: function get(key) { | ||
var stored = void 0; | ||
try { | ||
stored = window.localStorage && window.localStorage.getItem(key) || this.storage[key]; | ||
} catch (e) { | ||
stored = this.storage[key]; | ||
} | ||
if (stored) { | ||
try { | ||
return JSON.parse(stored); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
}, | ||
set: function set(key, value) { | ||
// handle Safari private mode (setItem is not allowed) | ||
value = JSON.stringify(value); | ||
try { | ||
window.localStorage.setItem(key, value); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
this.storage[key] = value; | ||
} | ||
}, | ||
delete: function _delete(key) { | ||
try { | ||
window.localStorage.removeItem(key); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
delete this.storage[key]; | ||
} | ||
} | ||
}; | ||
var sha256$1 = {exports: {}}; | ||
/* | ||
* Determines whether or not the telemetry library should be enabled based on passed in options | ||
*/ | ||
function telemetryEnabled() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var core = {exports: {}}; | ||
var portal = options.portal || {}; | ||
(function (module, exports) { | ||
(function (root, factory) { | ||
{ | ||
// CommonJS | ||
module.exports = factory(); | ||
} | ||
}(commonjsGlobal, function () { | ||
if (options.disabled) { | ||
// Tracking is manually disabled | ||
return false; | ||
} | ||
/*globals window, global, require*/ | ||
if (_hasDoNotTrackEnabled()) { | ||
// user's browser has turned off tracking | ||
return false; | ||
} | ||
/** | ||
* CryptoJS core components. | ||
*/ | ||
var CryptoJS = CryptoJS || (function (Math, undefined$1) { | ||
if (typeof portal.eueiEnabled !== 'undefined' && portal.eueiEnabled === false) { | ||
// Portal does not allow tracking | ||
return false; | ||
} | ||
var crypto; | ||
if (portal.eueiEnabled && portal.user && portal.user.orgId === portal.id) { | ||
// Portal allows tracking; except when user is anonymous or doesn't belong to portal's org | ||
return true; | ||
} | ||
// Native crypto from window (Browser) | ||
if (typeof window !== 'undefined' && window.crypto) { | ||
crypto = window.crypto; | ||
} | ||
if (portal.user && !portal.user.orgId && portal.ipCntryCode === 'US') { | ||
// Public user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
// Native crypto in web worker (Browser) | ||
if (typeof self !== 'undefined' && self.crypto) { | ||
crypto = self.crypto; | ||
} | ||
if (!portal.user && portal.ipCntryCode === 'US') { | ||
// Anonymous user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
// Native crypto from worker | ||
if (typeof globalThis !== 'undefined' && globalThis.crypto) { | ||
crypto = globalThis.crypto; | ||
} | ||
if (Object.keys(portal).length > 0) { | ||
// Initialized with a Portal object but does not meet tracking conditions | ||
return false; | ||
} | ||
// Native (experimental IE 11) crypto from window (Browser) | ||
if (!crypto && typeof window !== 'undefined' && window.msCrypto) { | ||
crypto = window.msCrypto; | ||
} | ||
// Default condition not initialized with a Portal-Self object | ||
return true; | ||
} | ||
// Native crypto from global (NodeJS) | ||
if (!crypto && typeof commonjsGlobal !== 'undefined' && commonjsGlobal.crypto) { | ||
crypto = commonjsGlobal.crypto; | ||
} | ||
function _hasDoNotTrackEnabled() { | ||
return (typeof navigator !== 'undefined' && navigator.doNotTrack) === '1' || typeof window !== 'undefined' && window.doNotTrack === '1'; | ||
} | ||
// Native crypto import via require (NodeJS) | ||
if (!crypto && typeof commonjsRequire === 'function') { | ||
try { | ||
crypto = require('crypto'); | ||
} catch (err) {} | ||
} | ||
/* | ||
(c) 2009-2013 by Jeff Mott. All rights reserved. | ||
/* | ||
* Cryptographically secure pseudorandom number generator | ||
* | ||
* As Math.random() is cryptographically not safe to use | ||
*/ | ||
var cryptoSecureRandomInt = function () { | ||
if (crypto) { | ||
// Use getRandomValues method (Browser) | ||
if (typeof crypto.getRandomValues === 'function') { | ||
try { | ||
return crypto.getRandomValues(new Uint32Array(1))[0]; | ||
} catch (err) {} | ||
} | ||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
// Use randomBytes method (NodeJS) | ||
if (typeof crypto.randomBytes === 'function') { | ||
try { | ||
return crypto.randomBytes(4).readInt32LE(); | ||
} catch (err) {} | ||
} | ||
} | ||
Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer. | ||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation or other materials provided with the distribution. | ||
Neither the name CryptoJS nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS," AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
var CryptoJS = function (h, s) { | ||
var f = {}, | ||
g = f.lib = {}, | ||
q = function q() {}, | ||
m = g.Base = { | ||
extend: function extend(a) { | ||
q.prototype = this; | ||
var c = new q(); | ||
a && c.mixIn(a); | ||
c.hasOwnProperty('init') || (c.init = function () { | ||
c.$super.init.apply(this, arguments); | ||
}); | ||
c.init.prototype = c; | ||
c.$super = this; | ||
return c; | ||
}, | ||
create: function create() { | ||
var a = this.extend(); | ||
a.init.apply(a, arguments); | ||
return a; | ||
}, | ||
init: function init() {}, | ||
mixIn: function mixIn(a) { | ||
for (var c in a) { | ||
a.hasOwnProperty(c) && (this[c] = a[c]); | ||
}a.hasOwnProperty('toString') && (this.toString = a.toString); | ||
}, | ||
clone: function clone() { | ||
return this.init.prototype.extend(this); | ||
} | ||
}, | ||
r = g.WordArray = m.extend({ | ||
init: function init(a, c) { | ||
a = this.words = a || []; | ||
this.sigBytes = c != s ? c : 4 * a.length; | ||
}, | ||
toString: function toString(a) { | ||
return (a || k).stringify(this); | ||
}, | ||
concat: function concat(a) { | ||
var c = this.words, | ||
d = a.words, | ||
b = this.sigBytes; | ||
a = a.sigBytes; | ||
this.clamp(); | ||
if (b % 4) for (var e = 0; e < a; e++) { | ||
c[b + e >>> 2] |= (d[e >>> 2] >>> 24 - 8 * (e % 4) & 255) << 24 - 8 * ((b + e) % 4); | ||
} else if (d.length > 65535) for (e = 0; e < a; e += 4) { | ||
c[b + e >>> 2] = d[e >>> 2]; | ||
} else c.push.apply(c, d); | ||
this.sigBytes += a; | ||
return this; | ||
}, | ||
clamp: function clamp() { | ||
var a = this.words, | ||
c = this.sigBytes; | ||
a[c >>> 2] &= 4294967295 << 32 - 8 * (c % 4); | ||
a.length = h.ceil(c / 4); | ||
}, | ||
clone: function clone() { | ||
var a = m.clone.call(this); | ||
a.words = this.words.slice(0); | ||
return a; | ||
}, | ||
random: function random(a) { | ||
for (var c = [], d = 0; d < a; d += 4) { | ||
c.push(4294967296 * h.random() | 0); | ||
}return new r.init(c, a); | ||
} | ||
}), | ||
l = f.enc = {}, | ||
k = l.Hex = { | ||
stringify: function stringify(a) { | ||
var c = a.words; | ||
a = a.sigBytes; | ||
for (var d = [], b = 0; b < a; b++) { | ||
var e = c[b >>> 2] >>> 24 - 8 * (b % 4) & 255; | ||
d.push((e >>> 4).toString(16)); | ||
d.push((e & 15).toString(16)); | ||
} | ||
return d.join(''); | ||
}, | ||
parse: function parse(a) { | ||
for (var c = a.length, d = [], b = 0; b < c; b += 2) { | ||
d[b >>> 3] |= parseInt(a.substr(b, 2), 16) << 24 - 4 * (b % 8); | ||
} | ||
return new r.init(d, c / 2); | ||
} | ||
}, | ||
n = l.Latin1 = { | ||
stringify: function stringify(a) { | ||
var c = a.words; | ||
a = a.sigBytes; | ||
for (var d = [], b = 0; b < a; b++) { | ||
d.push(String.fromCharCode(c[b >>> 2] >>> 24 - 8 * (b % 4) & 255)); | ||
}return d.join(''); | ||
}, | ||
parse: function parse(a) { | ||
for (var c = a.length, d = [], b = 0; b < c; b++) { | ||
d[b >>> 2] |= (a.charCodeAt(b) & 255) << 24 - 8 * (b % 4); | ||
}return new r.init(d, c); | ||
} | ||
}, | ||
j = l.Utf8 = { | ||
stringify: function stringify(a) { | ||
try { | ||
return decodeURIComponent(escape(n.stringify(a))); | ||
} catch (c) { | ||
throw Error('Malformed UTF-8 data'); | ||
} | ||
}, | ||
parse: function parse(a) { | ||
return n.parse(unescape(encodeURIComponent(a))); | ||
} | ||
}, | ||
u = g.BufferedBlockAlgorithm = m.extend({ | ||
reset: function reset() { | ||
this._data = new r.init(); | ||
this._nDataBytes = 0; | ||
}, | ||
_append: function _append(a) { | ||
typeof a === 'string' && (a = j.parse(a)); | ||
this._data.concat(a); | ||
this._nDataBytes += a.sigBytes; | ||
}, | ||
_process: function _process(a) { | ||
var c = this._data, | ||
d = c.words, | ||
b = c.sigBytes, | ||
e = this.blockSize, | ||
f = b / (4 * e), | ||
f = a ? h.ceil(f) : h.max((f | 0) - this._minBufferSize, 0); | ||
a = f * e; | ||
b = h.min(4 * a, b); | ||
if (a) { | ||
for (var g = 0; g < a; g += e) { | ||
this._doProcessBlock(d, g); | ||
}g = d.splice(0, a); | ||
c.sigBytes -= b; | ||
} | ||
return new r.init(g, b); | ||
}, | ||
clone: function clone() { | ||
var a = m.clone.call(this); | ||
a._data = this._data.clone(); | ||
return a; | ||
}, | ||
_minBufferSize: 0 | ||
}); | ||
g.Hasher = u.extend({ | ||
cfg: m.extend(), | ||
init: function init(a) { | ||
this.cfg = this.cfg.extend(a); | ||
this.reset(); | ||
}, | ||
reset: function reset() { | ||
u.reset.call(this); | ||
this._doReset(); | ||
}, | ||
update: function update(a) { | ||
this._append(a); | ||
this._process(); | ||
return this; | ||
}, | ||
finalize: function finalize(a) { | ||
a && this._append(a); | ||
return this._doFinalize(); | ||
}, | ||
blockSize: 16, | ||
_createHelper: function _createHelper(a) { | ||
return function (c, d) { | ||
return new a.init(d).finalize(c); | ||
}; | ||
}, | ||
_createHmacHelper: function _createHmacHelper(a) { | ||
return function (c, d) { | ||
return new t.HMAC.init(a, d).finalize(c); | ||
}; | ||
} | ||
}); | ||
var t = f.algo = {}; | ||
return f; | ||
}(Math); | ||
(function (h) { | ||
for (var s = CryptoJS, f = s.lib, g = f.WordArray, q = f.Hasher, f = s.algo, m = [], r = [], l = function l(a) { | ||
return 4294967296 * (a - (a | 0)) | 0; | ||
}, k = 2, n = 0; n < 64;) { | ||
var j; | ||
a: { | ||
j = k; | ||
for (var u = h.sqrt(j), t = 2; t <= u; t++) { | ||
if (!(j % t)) { | ||
j = !1; | ||
break a; | ||
} | ||
}j = !0; | ||
} | ||
j && (n < 8 && (m[n] = l(h.pow(k, 0.5))), r[n] = l(h.pow(k, 1 / 3)), n++); | ||
k++; | ||
} | ||
var a = [], | ||
f = f.SHA256 = q.extend({ | ||
_doReset: function _doReset() { | ||
this._hash = new g.init(m.slice(0)); | ||
}, | ||
_doProcessBlock: function _doProcessBlock(c, d) { | ||
for (var b = this._hash.words, e = b[0], f = b[1], g = b[2], j = b[3], h = b[4], m = b[5], n = b[6], q = b[7], p = 0; p < 64; p++) { | ||
if (p < 16) { | ||
a[p] = c[d + p] | 0; | ||
} else { | ||
var k = a[p - 15], | ||
l = a[p - 2]; | ||
a[p] = ((k << 25 | k >>> 7) ^ (k << 14 | k >>> 18) ^ k >>> 3) + a[p - 7] + ((l << 15 | l >>> 17) ^ (l << 13 | l >>> 19) ^ l >>> 10) + a[p - 16]; | ||
} | ||
k = q + ((h << 26 | h >>> 6) ^ (h << 21 | h >>> 11) ^ (h << 7 | h >>> 25)) + (h & m ^ ~h & n) + r[p] + a[p]; | ||
l = ((e << 30 | e >>> 2) ^ (e << 19 | e >>> 13) ^ (e << 10 | e >>> 22)) + (e & f ^ e & g ^ f & g); | ||
q = n; | ||
n = m; | ||
m = h; | ||
h = j + k | 0; | ||
j = g; | ||
g = f; | ||
f = e; | ||
e = k + l | 0; | ||
} | ||
b[0] = b[0] + e | 0; | ||
b[1] = b[1] + f | 0; | ||
b[2] = b[2] + g | 0; | ||
b[3] = b[3] + j | 0; | ||
b[4] = b[4] + h | 0; | ||
b[5] = b[5] + m | 0; | ||
b[6] = b[6] + n | 0; | ||
b[7] = b[7] + q | 0; | ||
}, | ||
_doFinalize: function _doFinalize() { | ||
var a = this._data, | ||
d = a.words, | ||
b = 8 * this._nDataBytes, | ||
e = 8 * a.sigBytes; | ||
d[e >>> 5] |= 128 << 24 - e % 32; | ||
d[(e + 64 >>> 9 << 4) + 14] = h.floor(b / 4294967296); | ||
d[(e + 64 >>> 9 << 4) + 15] = b; | ||
a.sigBytes = 4 * d.length; | ||
this._process(); | ||
return this._hash; | ||
}, | ||
clone: function clone() { | ||
var a = q.clone.call(this); | ||
a._hash = this._hash.clone(); | ||
return a; | ||
} | ||
}); | ||
s.SHA256 = q._createHelper(f); | ||
s.HmacSHA256 = q._createHmacHelper(f); | ||
})(Math); | ||
(function () { | ||
var h = CryptoJS, | ||
s = h.enc.Utf8; | ||
h.algo.HMAC = h.lib.Base.extend({ | ||
init: function init(f, g) { | ||
f = this._hasher = new f.init(); | ||
typeof g === 'string' && (g = s.parse(g)); | ||
var h = f.blockSize, | ||
m = 4 * h; | ||
g.sigBytes > m && (g = f.finalize(g)); | ||
g.clamp(); | ||
for (var r = this._oKey = g.clone(), l = this._iKey = g.clone(), k = r.words, n = l.words, j = 0; j < h; j++) { | ||
k[j] ^= 1549556828, n[j] ^= 909522486; | ||
}r.sigBytes = l.sigBytes = m; | ||
this.reset(); | ||
}, | ||
reset: function reset() { | ||
var f = this._hasher; | ||
f.reset(); | ||
f.update(this._iKey); | ||
}, | ||
update: function update(f) { | ||
this._hasher.update(f); | ||
return this; | ||
}, | ||
finalize: function finalize(f) { | ||
var g = this._hasher; | ||
f = g.finalize(f); | ||
g.reset(); | ||
return g.finalize(this._oKey.clone().concat(f)); | ||
} | ||
}); | ||
})(); | ||
throw new Error('Native crypto module could not be used to get secure random number.'); | ||
}; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
/* | ||
* Local polyfill of Object.create | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
*/ | ||
var create = Object.create || (function () { | ||
function F() {} | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (obj) { | ||
var subtype; | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
F.prototype = obj; | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
subtype = new F(); | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
F.prototype = null; | ||
return target; | ||
}; | ||
return subtype; | ||
}; | ||
}()); | ||
var slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
/** | ||
* CryptoJS namespace. | ||
*/ | ||
var C = {}; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
/** | ||
* Library namespace. | ||
*/ | ||
var C_lib = C.lib = {}; | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
/** | ||
* Base object for prototypal inheritance. | ||
*/ | ||
var Base = C_lib.Base = (function () { | ||
return _arr; | ||
} | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
return { | ||
/** | ||
* Creates a new object that inherits from this object. | ||
* | ||
* @param {Object} overrides Properties to copy into the new object. | ||
* | ||
* @return {Object} The new object. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var MyType = CryptoJS.lib.Base.extend({ | ||
* field: 'value', | ||
* | ||
* method: function () { | ||
* } | ||
* }); | ||
*/ | ||
extend: function (overrides) { | ||
// Spawn | ||
var subtype = create(this); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
// Augment | ||
if (overrides) { | ||
subtype.mixIn(overrides); | ||
} | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
// Create default initializer | ||
if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { | ||
subtype.init = function () { | ||
subtype.$super.init.apply(this, arguments); | ||
}; | ||
} | ||
var Telemetry = function () { | ||
function Telemetry(options) { | ||
classCallCheck(this, Telemetry); | ||
// Initializer's prototype is the subtype object | ||
subtype.init.prototype = subtype; | ||
// Make sure failure to init this library cannot have side-effects | ||
try { | ||
this.trackers = []; | ||
this.workflows = {}; | ||
this.test = options.test; | ||
this.debug = options.debug; | ||
this.disabled = !telemetryEnabled(options); | ||
// Reference supertype | ||
subtype.$super = this; | ||
if (this.disabled) { | ||
console.log('Telemetry Disabled'); | ||
} | ||
return subtype; | ||
}, | ||
if (options.portal && options.portal.user) { | ||
var subscriptionInfo = options.portal.subscriptionInfo || {}; | ||
this.setUser(options.portal.user, subscriptionInfo.type); | ||
} else if (options.user) { | ||
this.setUser(options.user); | ||
} | ||
/** | ||
* Extends this object and runs the init method. | ||
* Arguments to create() will be passed to init(). | ||
* | ||
* @return {Object} The new object. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var instance = MyType.create(); | ||
*/ | ||
create: function () { | ||
var instance = this.extend(); | ||
instance.init.apply(instance, arguments); | ||
if (!this.disabled) { | ||
this._initializeTrackers(options); | ||
} | ||
} catch (e) { | ||
console.error('Telemetry Disabled'); | ||
console.error(e); | ||
this.disabled = true; | ||
} | ||
} | ||
return instance; | ||
}, | ||
createClass(Telemetry, [{ | ||
key: '_initializeTrackers', | ||
value: function _initializeTrackers(options) { | ||
if (options.plugins) { | ||
var _trackers; | ||
/** | ||
* Initializes a newly created object. | ||
* Override this method to add some logic when your objects are created. | ||
* | ||
* @example | ||
* | ||
* var MyType = CryptoJS.lib.Base.extend({ | ||
* init: function () { | ||
* // ... | ||
* } | ||
* }); | ||
*/ | ||
init: function () { | ||
}, | ||
(_trackers = this.trackers).push.apply(_trackers, toConsumableArray(options.plugins)); | ||
} | ||
/** | ||
* Copies properties into this object. | ||
* | ||
* @param {Object} properties The properties to mix in. | ||
* | ||
* @example | ||
* | ||
* MyType.mixIn({ | ||
* field: 'value' | ||
* }); | ||
*/ | ||
mixIn: function (properties) { | ||
for (var propertyName in properties) { | ||
if (properties.hasOwnProperty(propertyName)) { | ||
this[propertyName] = properties[propertyName]; | ||
} | ||
} | ||
if (!this.trackers.length) { | ||
console.error(new Error('No trackers configured')); | ||
} | ||
} | ||
}, { | ||
key: 'setUser', | ||
value: function setUser() { | ||
var user = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var orgType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Public'; | ||
// IE won't copy toString using the loop above | ||
if (properties.hasOwnProperty('toString')) { | ||
this.toString = properties.toString; | ||
} | ||
}, | ||
user = typeof user === 'string' ? { username: user } : user; | ||
this.user = user; | ||
this.user.accountType = orgType; | ||
var internalDomain = void 0; | ||
/** | ||
* Creates a copy of this object. | ||
* | ||
* @return {Object} The clone. | ||
* | ||
* @example | ||
* | ||
* var clone = instance.clone(); | ||
*/ | ||
clone: function () { | ||
return this.init.prototype.extend(this); | ||
} | ||
}; | ||
}()); | ||
if (user.email && user.email.split) { | ||
var domain = user.email.split('@')[1]; | ||
internalDomain = internalOrgs.filter(function (org) { | ||
return domain === org; | ||
}).length > 0; | ||
} | ||
/** | ||
* An array of 32-bit words. | ||
* | ||
* @property {Array} words The array of 32-bit words. | ||
* @property {number} sigBytes The number of significant bytes in this word array. | ||
*/ | ||
var WordArray = C_lib.WordArray = Base.extend({ | ||
/** | ||
* Initializes a newly created word array. | ||
* | ||
* @param {Array} words (Optional) An array of 32-bit words. | ||
* @param {number} sigBytes (Optional) The number of significant bytes in the words. | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.lib.WordArray.create(); | ||
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); | ||
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); | ||
*/ | ||
init: function (words, sigBytes) { | ||
words = this.words = words || []; | ||
if (internalDomain || ['In House', 'Demo and Marketing'].indexOf(orgType) > -1) { | ||
this.user.internalUser = true; | ||
} | ||
} | ||
}, { | ||
key: 'logPageView', | ||
value: function logPageView(page) { | ||
var event = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
if (sigBytes != undefined$1) { | ||
this.sigBytes = sigBytes; | ||
} else { | ||
this.sigBytes = words.length * 4; | ||
} | ||
}, | ||
var attributes = this.preProcess(event, options); | ||
/** | ||
* Converts this word array to a string. | ||
* | ||
* @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex | ||
* | ||
* @return {string} The stringified word array. | ||
* | ||
* @example | ||
* | ||
* var string = wordArray + ''; | ||
* var string = wordArray.toString(); | ||
* var string = wordArray.toString(CryptoJS.enc.Utf8); | ||
*/ | ||
toString: function (encoder) { | ||
return (encoder || Hex).stringify(this); | ||
}, | ||
if (this.debug) { | ||
console.log('Tracking page view', JSON.stringify(attributes)); | ||
} | ||
/** | ||
* Concatenates a word array to this word array. | ||
* | ||
* @param {WordArray} wordArray The word array to append. | ||
* | ||
* @return {WordArray} This word array. | ||
* | ||
* @example | ||
* | ||
* wordArray1.concat(wordArray2); | ||
*/ | ||
concat: function (wordArray) { | ||
// Shortcuts | ||
var thisWords = this.words; | ||
var thatWords = wordArray.words; | ||
var thisSigBytes = this.sigBytes; | ||
var thatSigBytes = wordArray.sigBytes; | ||
if (this.test && !this.disabled) { | ||
return attributes; | ||
} | ||
// Clamp excess bits | ||
this.clamp(); | ||
var trackers = this.trackers.filter(function (_ref) { | ||
var disabled = _ref.disabled; | ||
return !disabled; | ||
}); | ||
// Concat | ||
if (thisSigBytes % 4) { | ||
// Copy one byte at a time | ||
for (var i = 0; i < thatSigBytes; i++) { | ||
var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); | ||
} | ||
} else { | ||
// Copy one word at a time | ||
for (var j = 0; j < thatSigBytes; j += 4) { | ||
thisWords[(thisSigBytes + j) >>> 2] = thatWords[j >>> 2]; | ||
} | ||
} | ||
this.sigBytes += thatSigBytes; | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Page view was not logged because no trackers are configured.')); | ||
} | ||
// Chainable | ||
return this; | ||
}, | ||
return false; | ||
} | ||
/** | ||
* Removes insignificant bits. | ||
* | ||
* @example | ||
* | ||
* wordArray.clamp(); | ||
*/ | ||
clamp: function () { | ||
// Shortcuts | ||
var words = this.words; | ||
var sigBytes = this.sigBytes; | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
}); | ||
// Clamp | ||
words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); | ||
words.length = Math.ceil(sigBytes / 4); | ||
}, | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logEvent', | ||
value: function logEvent(event) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* Creates a copy of this word array. | ||
* | ||
* @return {WordArray} The clone. | ||
* | ||
* @example | ||
* | ||
* var clone = wordArray.clone(); | ||
*/ | ||
clone: function () { | ||
var clone = Base.clone.call(this); | ||
clone.words = this.words.slice(0); | ||
event = this.preProcess(event, options); | ||
return clone; | ||
}, | ||
if (this.debug) { | ||
console.log('Tracking event', JSON.stringify(event)); | ||
} | ||
/** | ||
* Creates a word array filled with random bytes. | ||
* | ||
* @param {number} nBytes The number of random bytes to generate. | ||
* | ||
* @return {WordArray} The random word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.lib.WordArray.random(16); | ||
*/ | ||
random: function (nBytes) { | ||
var words = []; | ||
if (this.test) { | ||
return event; | ||
} | ||
for (var i = 0; i < nBytes; i += 4) { | ||
words.push(cryptoSecureRandomInt()); | ||
} | ||
var trackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
return new WordArray.init(words, nBytes); | ||
} | ||
}); | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Event was not logged because no trackers are configured.')); | ||
} | ||
/** | ||
* Encoder namespace. | ||
*/ | ||
var C_enc = C.enc = {}; | ||
return false; | ||
} | ||
/** | ||
* Hex encoding strategy. | ||
*/ | ||
var Hex = C_enc.Hex = { | ||
/** | ||
* Converts a word array to a hex string. | ||
* | ||
* @param {WordArray} wordArray The word array. | ||
* | ||
* @return {string} The hex string. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var hexString = CryptoJS.enc.Hex.stringify(wordArray); | ||
*/ | ||
stringify: function (wordArray) { | ||
// Shortcuts | ||
var words = wordArray.words; | ||
var sigBytes = wordArray.sigBytes; | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
}); | ||
// Convert | ||
var hexChars = []; | ||
for (var i = 0; i < sigBytes; i++) { | ||
var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
hexChars.push((bite >>> 4).toString(16)); | ||
hexChars.push((bite & 0x0f).toString(16)); | ||
} | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logError', | ||
value: function logError() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return hexChars.join(''); | ||
}, | ||
var event = _extends({ eventType: 'error' }, options); | ||
this.logEvent(event); | ||
} | ||
}, { | ||
key: 'startWorkflow', | ||
value: function startWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* Converts a hex string to a word array. | ||
* | ||
* @param {string} hexStr The hex string. | ||
* | ||
* @return {WordArray} The word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.enc.Hex.parse(hexString); | ||
*/ | ||
parse: function (hexStr) { | ||
// Shortcut | ||
var hexStrLength = hexStr.length; | ||
var workflow = { | ||
name: name, | ||
start: Date.now(), | ||
steps: [], | ||
workflowId: Math.floor((1 + Math.random()) * 0x100000000000).toString(16) | ||
}; | ||
this._saveWorkflow(workflow); | ||
var workflowObj = _extends({ name: name, step: 'start' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
return workflow; | ||
} | ||
}, { | ||
key: 'stepWorkflow', | ||
value: function stepWorkflow(name, step) { | ||
var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
// Convert | ||
var words = []; | ||
for (var i = 0; i < hexStrLength; i += 2) { | ||
words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); | ||
} | ||
//TODO: check if the check for attributes being a string is useful or can be removed | ||
var details = typeof attributes === 'string' ? attributes : attributes.details; | ||
var workflowObj = _extends({ name: name, step: step, details: details }, attributes); | ||
this._logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'endWorkflow', | ||
value: function endWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return new WordArray.init(words, hexStrLength / 2); | ||
} | ||
}; | ||
var workflowObj = _extends({ name: name, step: 'finish' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'cancelWorkflow', | ||
value: function cancelWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* Latin1 encoding strategy. | ||
*/ | ||
var Latin1 = C_enc.Latin1 = { | ||
/** | ||
* Converts a word array to a Latin1 string. | ||
* | ||
* @param {WordArray} wordArray The word array. | ||
* | ||
* @return {string} The Latin1 string. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); | ||
*/ | ||
stringify: function (wordArray) { | ||
// Shortcuts | ||
var words = wordArray.words; | ||
var sigBytes = wordArray.sigBytes; | ||
var workflowObj = _extends({ name: name, step: 'cancel' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'getWorkflow', | ||
value: function getWorkflow(name) { | ||
var workflow = storage.get('TELEMETRY-WORKFLOW:' + name); | ||
// do not let old workflows be returned | ||
if (workflow) { | ||
var workflowAge = Date.now() - workflow.start; | ||
var timeout = 30 * 60 * 1000; | ||
if (workflowAge < timeout) { | ||
return workflow; | ||
} else { | ||
this._deleteWorkflow(workflow); | ||
} | ||
} | ||
} | ||
}, { | ||
key: '_saveWorkflow', | ||
value: function _saveWorkflow(workflow) { | ||
storage.set('TELEMETRY-WORKFLOW:' + workflow.name, workflow); | ||
} | ||
}, { | ||
key: '_deleteWorkflow', | ||
value: function _deleteWorkflow(workflow) { | ||
storage.delete('TELEMETRY-WORKFLOW:' + workflow.name); | ||
} | ||
}, { | ||
key: '_logWorkflow', | ||
value: function _logWorkflow() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
// Convert | ||
var latin1Chars = []; | ||
for (var i = 0; i < sigBytes; i++) { | ||
var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
latin1Chars.push(String.fromCharCode(bite)); | ||
} | ||
/* | ||
const workflow = { | ||
name: 'add layer to map', | ||
step: 'start', | ||
details: 'some details about the step' | ||
} | ||
*/ | ||
options = this.preProcess(options); | ||
var workflow = this.getWorkflow(options.name); | ||
return latin1Chars.join(''); | ||
}, | ||
if (!workflow) { | ||
this.startWorkflow(options.name); | ||
workflow = this.getWorkflow(options.name); | ||
} | ||
workflow.steps.push(options.step); | ||
workflow.duration = (Date.now() - workflow.start) / 1000; | ||
/** | ||
* Converts a Latin1 string to a word array. | ||
* | ||
* @param {string} latin1Str The Latin1 string. | ||
* | ||
* @return {WordArray} The word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.enc.Latin1.parse(latin1String); | ||
*/ | ||
parse: function (latin1Str) { | ||
// Shortcut | ||
var latin1StrLength = latin1Str.length; | ||
if (['cancel', 'finish'].indexOf(options.step) > -1) { | ||
this._deleteWorkflow(workflow); | ||
} else { | ||
this._saveWorkflow(workflow); | ||
} | ||
// Convert | ||
var words = []; | ||
for (var i = 0; i < latin1StrLength; i++) { | ||
words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); | ||
} | ||
var track = _extends(options, { | ||
eventType: 'workflow', | ||
category: options.name, | ||
action: options.step, | ||
label: options.details, | ||
duration: workflow.duration, | ||
workflowId: workflow.workflowId | ||
}); | ||
return new WordArray.init(words, latin1StrLength); | ||
} | ||
}; | ||
this.logEvent(track); | ||
} | ||
}, { | ||
key: 'preProcess', | ||
value: function preProcess() { | ||
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* UTF-8 encoding strategy. | ||
*/ | ||
var Utf8 = C_enc.Utf8 = { | ||
/** | ||
* Converts a word array to a UTF-8 string. | ||
* | ||
* @param {WordArray} wordArray The word array. | ||
* | ||
* @return {string} The UTF-8 string. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); | ||
*/ | ||
stringify: function (wordArray) { | ||
try { | ||
return decodeURIComponent(escape(Latin1.stringify(wordArray))); | ||
} catch (e) { | ||
throw new Error('Malformed UTF-8 data'); | ||
} | ||
}, | ||
var userMetadata = {}; | ||
/** | ||
* Converts a UTF-8 string to a word array. | ||
* | ||
* @param {string} utf8Str The UTF-8 string. | ||
* | ||
* @return {WordArray} The word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.enc.Utf8.parse(utf8String); | ||
*/ | ||
parse: function (utf8Str) { | ||
return Latin1.parse(unescape(encodeURIComponent(utf8Str))); | ||
} | ||
}; | ||
if (this.user) { | ||
userMetadata = { | ||
user: anonymize(this.user.username), | ||
org: anonymize(this.user.orgId), | ||
lastLogin: this.user.lastLogin, | ||
userSince: this.user.created, | ||
internalUser: this.user.internalUser || false, | ||
accountType: this.user.accountType | ||
}; | ||
} | ||
/** | ||
* Abstract buffered block algorithm template. | ||
* | ||
* The property blockSize must be implemented in a concrete subtype. | ||
* | ||
* @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 | ||
*/ | ||
var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ | ||
/** | ||
* Resets this block algorithm's data buffer to its initial state. | ||
* | ||
* @example | ||
* | ||
* bufferedBlockAlgorithm.reset(); | ||
*/ | ||
reset: function () { | ||
// Initial values | ||
this._data = new WordArray.init(); | ||
this._nDataBytes = 0; | ||
}, | ||
return Object.entries(_extends({}, event, userMetadata)).reduce(_makeEventPayload(options.omitComplexData), {}); | ||
} | ||
}, { | ||
key: 'disableTracker', | ||
value: function disableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref3) { | ||
var name = _ref3.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = true; | ||
} | ||
} | ||
}, { | ||
key: 'enableTracker', | ||
value: function enableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref4) { | ||
var name = _ref4.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = false; | ||
} | ||
} | ||
}]); | ||
return Telemetry; | ||
}(); | ||
/** | ||
* Adds new data to this block algorithm's buffer. | ||
* | ||
* @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. | ||
* | ||
* @example | ||
* | ||
* bufferedBlockAlgorithm._append('data'); | ||
* bufferedBlockAlgorithm._append(wordArray); | ||
*/ | ||
_append: function (data) { | ||
// Convert string to WordArray, else assume WordArray already | ||
if (typeof data == 'string') { | ||
data = Utf8.parse(data); | ||
} | ||
Telemetry.anonymize = anonymize; | ||
Telemetry.internalOrgs = internalOrgs; | ||
Telemetry.telemetryEnabled = telemetryEnabled; | ||
Telemetry.storage = storage; | ||
// Append | ||
this._data.concat(data); | ||
this._nDataBytes += data.sigBytes; | ||
}, | ||
/** | ||
* Processes available data blocks. | ||
* | ||
* This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. | ||
* | ||
* @param {boolean} doFlush Whether all blocks and partial blocks should be processed. | ||
* | ||
* @return {WordArray} The processed data. | ||
* | ||
* @example | ||
* | ||
* var processedData = bufferedBlockAlgorithm._process(); | ||
* var processedData = bufferedBlockAlgorithm._process(!!'flush'); | ||
*/ | ||
_process: function (doFlush) { | ||
var processedWords; | ||
function _makeEventPayload(omitComplexData) { | ||
return function (acc, _ref5) { | ||
var _ref6 = slicedToArray(_ref5, 2), | ||
key = _ref6[0], | ||
val = _ref6[1]; | ||
// Shortcuts | ||
var data = this._data; | ||
var dataWords = data.words; | ||
var dataSigBytes = data.sigBytes; | ||
var blockSize = this.blockSize; | ||
var blockSizeBytes = blockSize * 4; | ||
if (_isPrimitive(val)) { | ||
acc[key] = val; | ||
} else if (!omitComplexData) { | ||
console.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
acc[key] = val; | ||
} | ||
return acc; | ||
}; | ||
} | ||
// Count blocks ready | ||
var nBlocksReady = dataSigBytes / blockSizeBytes; | ||
if (doFlush) { | ||
// Round up to include partial blocks | ||
nBlocksReady = Math.ceil(nBlocksReady); | ||
} else { | ||
// Round down to include only full blocks, | ||
// less the number of blocks that must remain in the buffer | ||
nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); | ||
} | ||
function _isPrimitive(val) { | ||
var primitives = ['string', 'number', 'boolean', 'undefined']; | ||
return primitives.includes(typeof val === 'undefined' ? 'undefined' : _typeof(val)) || val && typeof val.valueOf() === 'string'; | ||
} | ||
// Count words ready | ||
var nWordsReady = nBlocksReady * blockSize; | ||
return Telemetry; | ||
// Count bytes ready | ||
var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); | ||
// Process blocks | ||
if (nWordsReady) { | ||
for (var offset = 0; offset < nWordsReady; offset += blockSize) { | ||
// Perform concrete-algorithm logic | ||
this._doProcessBlock(dataWords, offset); | ||
} | ||
// Remove processed words | ||
processedWords = dataWords.splice(0, nWordsReady); | ||
data.sigBytes -= nBytesReady; | ||
} | ||
// Return processed words | ||
return new WordArray.init(processedWords, nBytesReady); | ||
}, | ||
/** | ||
* Creates a copy of this object. | ||
* | ||
* @return {Object} The clone. | ||
* | ||
* @example | ||
* | ||
* var clone = bufferedBlockAlgorithm.clone(); | ||
*/ | ||
clone: function () { | ||
var clone = Base.clone.call(this); | ||
clone._data = this._data.clone(); | ||
return clone; | ||
}, | ||
_minBufferSize: 0 | ||
}); | ||
/** | ||
* Abstract hasher template. | ||
* | ||
* @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) | ||
*/ | ||
C_lib.Hasher = BufferedBlockAlgorithm.extend({ | ||
/** | ||
* Configuration options. | ||
*/ | ||
cfg: Base.extend(), | ||
/** | ||
* Initializes a newly created hasher. | ||
* | ||
* @param {Object} cfg (Optional) The configuration options to use for this hash computation. | ||
* | ||
* @example | ||
* | ||
* var hasher = CryptoJS.algo.SHA256.create(); | ||
*/ | ||
init: function (cfg) { | ||
// Apply config defaults | ||
this.cfg = this.cfg.extend(cfg); | ||
// Set initial values | ||
this.reset(); | ||
}, | ||
/** | ||
* Resets this hasher to its initial state. | ||
* | ||
* @example | ||
* | ||
* hasher.reset(); | ||
*/ | ||
reset: function () { | ||
// Reset data buffer | ||
BufferedBlockAlgorithm.reset.call(this); | ||
// Perform concrete-hasher logic | ||
this._doReset(); | ||
}, | ||
/** | ||
* Updates this hasher with a message. | ||
* | ||
* @param {WordArray|string} messageUpdate The message to append. | ||
* | ||
* @return {Hasher} This hasher. | ||
* | ||
* @example | ||
* | ||
* hasher.update('message'); | ||
* hasher.update(wordArray); | ||
*/ | ||
update: function (messageUpdate) { | ||
// Append | ||
this._append(messageUpdate); | ||
// Update the hash | ||
this._process(); | ||
// Chainable | ||
return this; | ||
}, | ||
/** | ||
* Finalizes the hash computation. | ||
* Note that the finalize operation is effectively a destructive, read-once operation. | ||
* | ||
* @param {WordArray|string} messageUpdate (Optional) A final message update. | ||
* | ||
* @return {WordArray} The hash. | ||
* | ||
* @example | ||
* | ||
* var hash = hasher.finalize(); | ||
* var hash = hasher.finalize('message'); | ||
* var hash = hasher.finalize(wordArray); | ||
*/ | ||
finalize: function (messageUpdate) { | ||
// Final message update | ||
if (messageUpdate) { | ||
this._append(messageUpdate); | ||
} | ||
// Perform concrete-hasher logic | ||
var hash = this._doFinalize(); | ||
return hash; | ||
}, | ||
blockSize: 512/32, | ||
/** | ||
* Creates a shortcut function to a hasher's object interface. | ||
* | ||
* @param {Hasher} hasher The hasher to create a helper for. | ||
* | ||
* @return {Function} The shortcut function. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); | ||
*/ | ||
_createHelper: function (hasher) { | ||
return function (message, cfg) { | ||
return new hasher.init(cfg).finalize(message); | ||
}; | ||
}, | ||
/** | ||
* Creates a shortcut function to the HMAC's object interface. | ||
* | ||
* @param {Hasher} hasher The hasher to use in this HMAC helper. | ||
* | ||
* @return {Function} The shortcut function. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); | ||
*/ | ||
_createHmacHelper: function (hasher) { | ||
return function (message, key) { | ||
return new C_algo.HMAC.init(hasher, key).finalize(message); | ||
}; | ||
} | ||
}); | ||
/** | ||
* Algorithm namespace. | ||
*/ | ||
var C_algo = C.algo = {}; | ||
return C; | ||
}(Math)); | ||
return CryptoJS; | ||
})); | ||
}(core)); | ||
(function (module, exports) { | ||
(function (root, factory) { | ||
{ | ||
// CommonJS | ||
module.exports = factory(core.exports); | ||
} | ||
}(commonjsGlobal, function (CryptoJS) { | ||
(function (Math) { | ||
// Shortcuts | ||
var C = CryptoJS; | ||
var C_lib = C.lib; | ||
var WordArray = C_lib.WordArray; | ||
var Hasher = C_lib.Hasher; | ||
var C_algo = C.algo; | ||
// Initialization and round constants tables | ||
var H = []; | ||
var K = []; | ||
// Compute constants | ||
(function () { | ||
function isPrime(n) { | ||
var sqrtN = Math.sqrt(n); | ||
for (var factor = 2; factor <= sqrtN; factor++) { | ||
if (!(n % factor)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function getFractionalBits(n) { | ||
return ((n - (n | 0)) * 0x100000000) | 0; | ||
} | ||
var n = 2; | ||
var nPrime = 0; | ||
while (nPrime < 64) { | ||
if (isPrime(n)) { | ||
if (nPrime < 8) { | ||
H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); | ||
} | ||
K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); | ||
nPrime++; | ||
} | ||
n++; | ||
} | ||
}()); | ||
// Reusable object | ||
var W = []; | ||
/** | ||
* SHA-256 hash algorithm. | ||
*/ | ||
var SHA256 = C_algo.SHA256 = Hasher.extend({ | ||
_doReset: function () { | ||
this._hash = new WordArray.init(H.slice(0)); | ||
}, | ||
_doProcessBlock: function (M, offset) { | ||
// Shortcut | ||
var H = this._hash.words; | ||
// Working variables | ||
var a = H[0]; | ||
var b = H[1]; | ||
var c = H[2]; | ||
var d = H[3]; | ||
var e = H[4]; | ||
var f = H[5]; | ||
var g = H[6]; | ||
var h = H[7]; | ||
// Computation | ||
for (var i = 0; i < 64; i++) { | ||
if (i < 16) { | ||
W[i] = M[offset + i] | 0; | ||
} else { | ||
var gamma0x = W[i - 15]; | ||
var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ | ||
((gamma0x << 14) | (gamma0x >>> 18)) ^ | ||
(gamma0x >>> 3); | ||
var gamma1x = W[i - 2]; | ||
var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ | ||
((gamma1x << 13) | (gamma1x >>> 19)) ^ | ||
(gamma1x >>> 10); | ||
W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; | ||
} | ||
var ch = (e & f) ^ (~e & g); | ||
var maj = (a & b) ^ (a & c) ^ (b & c); | ||
var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); | ||
var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); | ||
var t1 = h + sigma1 + ch + K[i] + W[i]; | ||
var t2 = sigma0 + maj; | ||
h = g; | ||
g = f; | ||
f = e; | ||
e = (d + t1) | 0; | ||
d = c; | ||
c = b; | ||
b = a; | ||
a = (t1 + t2) | 0; | ||
} | ||
// Intermediate hash value | ||
H[0] = (H[0] + a) | 0; | ||
H[1] = (H[1] + b) | 0; | ||
H[2] = (H[2] + c) | 0; | ||
H[3] = (H[3] + d) | 0; | ||
H[4] = (H[4] + e) | 0; | ||
H[5] = (H[5] + f) | 0; | ||
H[6] = (H[6] + g) | 0; | ||
H[7] = (H[7] + h) | 0; | ||
}, | ||
_doFinalize: function () { | ||
// Shortcuts | ||
var data = this._data; | ||
var dataWords = data.words; | ||
var nBitsTotal = this._nDataBytes * 8; | ||
var nBitsLeft = data.sigBytes * 8; | ||
// Add padding | ||
dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); | ||
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); | ||
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; | ||
data.sigBytes = dataWords.length * 4; | ||
// Hash final blocks | ||
this._process(); | ||
// Return final computed hash | ||
return this._hash; | ||
}, | ||
clone: function () { | ||
var clone = Hasher.clone.call(this); | ||
clone._hash = this._hash.clone(); | ||
return clone; | ||
} | ||
}); | ||
/** | ||
* Shortcut function to the hasher's object interface. | ||
* | ||
* @param {WordArray|string} message The message to hash. | ||
* | ||
* @return {WordArray} The hash. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var hash = CryptoJS.SHA256('message'); | ||
* var hash = CryptoJS.SHA256(wordArray); | ||
*/ | ||
C.SHA256 = Hasher._createHelper(SHA256); | ||
/** | ||
* Shortcut function to the HMAC's object interface. | ||
* | ||
* @param {WordArray|string} message The message to hash. | ||
* @param {WordArray|string} key The secret key. | ||
* | ||
* @return {WordArray} The HMAC. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var hmac = CryptoJS.HmacSHA256(message, key); | ||
*/ | ||
C.HmacSHA256 = Hasher._createHmacHelper(SHA256); | ||
}(Math)); | ||
return CryptoJS.SHA256; | ||
})); | ||
}(sha256$1)); | ||
var sha256 = sha256$1.exports; | ||
var encHex = {exports: {}}; | ||
(function (module, exports) { | ||
(function (root, factory) { | ||
{ | ||
// CommonJS | ||
module.exports = factory(core.exports); | ||
} | ||
}(commonjsGlobal, function (CryptoJS) { | ||
return CryptoJS.enc.Hex; | ||
})); | ||
}(encHex)); | ||
var hex = encHex.exports; | ||
var storage = { | ||
storage: {}, | ||
memory: true, | ||
get: function get(key) { | ||
var stored = void 0; | ||
try { | ||
stored = window.localStorage && window.localStorage.getItem(key) || this.storage[key]; | ||
} catch (e) { | ||
stored = this.storage[key]; | ||
} | ||
if (stored) { | ||
try { | ||
return JSON.parse(stored); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
}, | ||
set: function set(key, value) { | ||
// handle Safari private mode (setItem is not allowed) | ||
var valueToString = JSON.stringify(value); | ||
try { | ||
window.localStorage.setItem(key, valueToString); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
this.storage[key] = value; | ||
} | ||
}, | ||
delete: function _delete(key) { | ||
try { | ||
window.localStorage.removeItem(key); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
delete this.storage[key]; | ||
} | ||
} | ||
}; | ||
function telemetryEnabled() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var portal = options.portal || {}; | ||
if (options.disabled) { | ||
return false; | ||
} | ||
if (_hasDoNotTrackEnabled()) { | ||
return false; | ||
} | ||
if (typeof portal.eueiEnabled !== 'undefined' && portal.eueiEnabled === false) { | ||
// Portal does not allow tracking | ||
return false; | ||
} | ||
if (portal.eueiEnabled && portal.user && portal.user.orgId === portal.id) { | ||
// Portal allows tracking; except when user is anonymous or doesn't belong to portal's org | ||
return true; | ||
} | ||
if (portal.user && !portal.user.orgId && portal.ipCntryCode === 'US') { | ||
// Public user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (!portal.user && portal.ipCntryCode === 'US') { | ||
// Anonymous user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (Object.keys(portal).length > 0) { | ||
// Initialized with a Portal object but does not meet tracking conditions | ||
return false; | ||
} | ||
// Default condition not initialized with a Portal-Self object | ||
return true; | ||
} | ||
function _hasDoNotTrackEnabled() { | ||
return (typeof navigator !== 'undefined' && navigator.doNotTrack) === '1' || typeof window !== 'undefined' && window.doNotTrack === '1'; | ||
} | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
var slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
var INTERNAL_ORGS = ['esri.com', 'esriuk.com', 'esri.de', 'esri.ca', 'esrifrance.fr', 'esri.nl', 'esri-portugal.pt', 'esribulgaria.com', 'esri.fi', 'esri.kr', 'esrimalaysia.com.my', 'esri.es', 'esriaustralia.com.au', 'esri-southafrica.com', 'esri.cl', 'esrichina.com.cn', 'esri.co', 'esriturkey.com.tr', 'geodata.no', 'esriitalia.it', 'esri.pl']; | ||
var Telemetry = function () { | ||
function Telemetry(options) { | ||
classCallCheck(this, Telemetry); | ||
var _a, _b, _c; | ||
this.trackers = []; | ||
this.options = options; | ||
this.test = options.test; | ||
this.debug = options.debug; | ||
this.disabled = !telemetryEnabled(options); | ||
if (this.disabled) { | ||
console.warn('Telemetry Disabled'); | ||
} | ||
var user = ((_a = options.portal) === null || _a === void 0 ? void 0 : _a.user) || options.user; | ||
if (user) { | ||
this.setUser(user, (_c = (_b = options.portal) === null || _b === void 0 ? void 0 : _b.subscriptionInfo) === null || _c === void 0 ? void 0 : _c.type); | ||
} | ||
if (!this.disabled) { | ||
this.initializeTrackers(); | ||
} | ||
} | ||
createClass(Telemetry, [{ | ||
key: 'initializeTrackers', | ||
value: function initializeTrackers() { | ||
if (this.options.plugins) { | ||
var _trackers; | ||
(_trackers = this.trackers).push.apply(_trackers, toConsumableArray(this.options.plugins)); | ||
} | ||
if (!this.trackers.length) { | ||
console.error(new Error('No trackers configured')); | ||
} | ||
} | ||
}, { | ||
key: 'setUser', | ||
value: function setUser() { | ||
var user = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var orgType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Public'; | ||
user = typeof user === 'string' ? { username: user } : user; | ||
this.user = user; | ||
this.user.accountType = orgType; | ||
var internalDomain = void 0; | ||
if (user.email && user.email.split) { | ||
var domain = user.email.split('@')[1]; | ||
internalDomain = INTERNAL_ORGS.filter(function (org) { | ||
return domain === org; | ||
}).length > 0; | ||
} | ||
if (internalDomain || ['In House', 'Demo and Marketing'].indexOf(orgType) > -1) { | ||
this.user.internalUser = true; | ||
} | ||
} | ||
}, { | ||
key: 'logPageView', | ||
value: function logPageView(page) { | ||
var event = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var attributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking page view', JSON.stringify(attributes)); | ||
} | ||
if (this.test && !this.disabled) { | ||
return attributes; | ||
} | ||
var trackers = this.trackers.filter(function (_ref) { | ||
var disabled = _ref.disabled; | ||
return !disabled; | ||
}); | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Page view was not logged because no trackers are configured.')); | ||
} | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
}); | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logEvent', | ||
value: function logEvent(event) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
event = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking event', JSON.stringify(event)); | ||
} | ||
if (this.test) { | ||
return event; | ||
} | ||
var trackers = void 0; | ||
if (this.trackers.length) { | ||
trackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
} | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Event was not logged because no trackers are configured.')); | ||
} | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
}); | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logError', | ||
value: function logError() { | ||
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
event = _extends({ eventType: 'error' }, event); | ||
this.logEvent(event); | ||
} | ||
}, { | ||
key: 'startWorkflow', | ||
value: function startWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflow = { | ||
name: name, | ||
start: Date.now(), | ||
steps: [], | ||
workflowId: Math.floor((1 + Math.random()) * 0x100000000000).toString(16) | ||
}; | ||
this.saveWorkflow(workflow); | ||
var workflowObj = _extends({ name: name, step: 'start' }, attributes); | ||
this.logWorkflow(workflowObj); | ||
return workflow; | ||
} | ||
}, { | ||
key: 'stepWorkflow', | ||
value: function stepWorkflow(name, step) { | ||
var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
//TODO: check if the check for attributes being a string is useful or can be removed | ||
var details = typeof attributes === 'string' ? attributes : attributes.details; | ||
var workflowObj = _extends({ name: name, step: step, details: details }, attributes); | ||
this.logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'endWorkflow', | ||
value: function endWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflowObj = _extends({ name: name, step: 'finish' }, attributes); | ||
this.logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'cancelWorkflow', | ||
value: function cancelWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflowObj = _extends({ name: name, step: 'cancel' }, attributes); | ||
this.logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'getWorkflow', | ||
value: function getWorkflow(name) { | ||
var workflow = storage.get('TELEMETRY-WORKFLOW:' + name); | ||
// do not let old workflows be returned | ||
if (workflow) { | ||
var workflowAge = Date.now() - workflow.start; | ||
var timeout = 30 * 60 * 1000; | ||
if (workflowAge < timeout) { | ||
return workflow; | ||
} else { | ||
this.deleteWorkflow(workflow); | ||
} | ||
} | ||
} | ||
}, { | ||
key: 'saveWorkflow', | ||
value: function saveWorkflow(workflow) { | ||
storage.set('TELEMETRY-WORKFLOW:' + workflow.name, workflow); | ||
} | ||
}, { | ||
key: 'deleteWorkflow', | ||
value: function deleteWorkflow(workflow) { | ||
storage.delete('TELEMETRY-WORKFLOW:' + workflow.name); | ||
} | ||
}, { | ||
key: 'logWorkflow', | ||
value: function logWorkflow() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
/* | ||
const workflow = { | ||
name: 'add layer to map', | ||
step: 'start', | ||
details: 'some details about the step' | ||
} | ||
*/ | ||
options = this.preProcess(options); | ||
var workflow = this.getWorkflow(options.name); | ||
if (!workflow) { | ||
this.startWorkflow(options.name); | ||
workflow = this.getWorkflow(options.name); | ||
} | ||
workflow.steps.push(options.step); | ||
workflow.duration = (Date.now() - workflow.start) / 1000; | ||
if (['cancel', 'finish'].indexOf(options.step) > -1) { | ||
this.deleteWorkflow(workflow); | ||
} else { | ||
this.saveWorkflow(workflow); | ||
} | ||
var track = _extends(options, { | ||
eventType: 'workflow', | ||
category: options.name, | ||
action: options.step, | ||
label: options.details, | ||
duration: workflow.duration, | ||
workflowId: workflow.workflowId | ||
}); | ||
this.logEvent(track); | ||
} | ||
}, { | ||
key: 'preProcess', | ||
value: function preProcess() { | ||
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var userMetadata = {}; | ||
if (this.user) { | ||
userMetadata = { | ||
user: anonymize(this.user.username), | ||
org: anonymize(this.user.orgId), | ||
lastLogin: this.user.lastLogin, | ||
userSince: this.user.created, | ||
internalUser: this.user.internalUser || false, | ||
accountType: this.user.accountType | ||
}; | ||
} | ||
return Object.entries(_extends(_extends({}, event), userMetadata)).reduce(makeEventPayload(options.omitComplexData), {}); | ||
} | ||
}, { | ||
key: 'disableTracker', | ||
value: function disableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref3) { | ||
var name = _ref3.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = true; | ||
} | ||
} | ||
}, { | ||
key: 'enableTracker', | ||
value: function enableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref4) { | ||
var name = _ref4.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = false; | ||
} | ||
} | ||
}]); | ||
return Telemetry; | ||
}(); | ||
Telemetry.storage = storage; | ||
function anonymize(user) { | ||
if (!user) return; | ||
return sha256(user).toString(hex); | ||
} | ||
function makeEventPayload(omitComplexData) { | ||
return function (acc, _ref5) { | ||
var _ref6 = slicedToArray(_ref5, 2), | ||
key = _ref6[0], | ||
val = _ref6[1]; | ||
if (isPrimitive(val)) { | ||
acc[key] = val; | ||
} else if (!omitComplexData) { | ||
console.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
acc[key] = val; | ||
} | ||
return acc; | ||
}; | ||
} | ||
function isPrimitive(val) { | ||
var primitives = ['string', 'number', 'boolean', 'undefined']; | ||
return primitives.includes(typeof val === 'undefined' ? 'undefined' : _typeof(val)) || val && typeof val.valueOf() === 'string'; | ||
} | ||
return Telemetry; | ||
})); | ||
//# sourceMappingURL=telemetry.dojo.min.js.map |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.telemetry = factory()); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.telemetry = factory()); | ||
})(this, (function () { 'use strict'; | ||
function anonymize(user) { | ||
if (!user) return undefined; | ||
return CryptoJS.SHA256(user).toString(CryptoJS.enc.Hex); | ||
} | ||
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
var internalOrgs = ['esri.com', 'esriuk.com', 'esri.de', 'esri.ca', 'esrifrance.fr', 'esri.nl', 'esri-portugal.pt', 'esribulgaria.com', 'esri.fi', 'esri.kr', 'esrimalaysia.com.my', 'esri.es', 'esriaustralia.com.au', 'esri-southafrica.com', 'esri.cl', 'esrichina.com.cn', 'esri.co', 'esriturkey.com.tr', 'geodata.no', 'esriitalia.it', 'esri.pl']; | ||
function commonjsRequire (path) { | ||
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.'); | ||
} | ||
var storage = { | ||
storage: {}, | ||
memory: true, | ||
get: function get(key) { | ||
var stored = void 0; | ||
try { | ||
stored = window.localStorage && window.localStorage.getItem(key) || this.storage[key]; | ||
} catch (e) { | ||
stored = this.storage[key]; | ||
} | ||
if (stored) { | ||
try { | ||
return JSON.parse(stored); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
}, | ||
set: function set(key, value) { | ||
// handle Safari private mode (setItem is not allowed) | ||
value = JSON.stringify(value); | ||
try { | ||
window.localStorage.setItem(key, value); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
this.storage[key] = value; | ||
} | ||
}, | ||
delete: function _delete(key) { | ||
try { | ||
window.localStorage.removeItem(key); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
delete this.storage[key]; | ||
} | ||
} | ||
}; | ||
var sha256$1 = {exports: {}}; | ||
/* | ||
* Determines whether or not the telemetry library should be enabled based on passed in options | ||
*/ | ||
function telemetryEnabled() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var core = {exports: {}}; | ||
var portal = options.portal || {}; | ||
(function (module, exports) { | ||
(function (root, factory) { | ||
{ | ||
// CommonJS | ||
module.exports = factory(); | ||
} | ||
}(commonjsGlobal, function () { | ||
if (options.disabled) { | ||
// Tracking is manually disabled | ||
return false; | ||
} | ||
/*globals window, global, require*/ | ||
if (_hasDoNotTrackEnabled()) { | ||
// user's browser has turned off tracking | ||
return false; | ||
} | ||
/** | ||
* CryptoJS core components. | ||
*/ | ||
var CryptoJS = CryptoJS || (function (Math, undefined$1) { | ||
if (typeof portal.eueiEnabled !== 'undefined' && portal.eueiEnabled === false) { | ||
// Portal does not allow tracking | ||
return false; | ||
} | ||
var crypto; | ||
if (portal.eueiEnabled && portal.user && portal.user.orgId === portal.id) { | ||
// Portal allows tracking; except when user is anonymous or doesn't belong to portal's org | ||
return true; | ||
} | ||
// Native crypto from window (Browser) | ||
if (typeof window !== 'undefined' && window.crypto) { | ||
crypto = window.crypto; | ||
} | ||
if (portal.user && !portal.user.orgId && portal.ipCntryCode === 'US') { | ||
// Public user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
// Native crypto in web worker (Browser) | ||
if (typeof self !== 'undefined' && self.crypto) { | ||
crypto = self.crypto; | ||
} | ||
if (!portal.user && portal.ipCntryCode === 'US') { | ||
// Anonymous user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
// Native crypto from worker | ||
if (typeof globalThis !== 'undefined' && globalThis.crypto) { | ||
crypto = globalThis.crypto; | ||
} | ||
if (Object.keys(portal).length > 0) { | ||
// Initialized with a Portal object but does not meet tracking conditions | ||
return false; | ||
} | ||
// Native (experimental IE 11) crypto from window (Browser) | ||
if (!crypto && typeof window !== 'undefined' && window.msCrypto) { | ||
crypto = window.msCrypto; | ||
} | ||
// Default condition not initialized with a Portal-Self object | ||
return true; | ||
} | ||
// Native crypto from global (NodeJS) | ||
if (!crypto && typeof commonjsGlobal !== 'undefined' && commonjsGlobal.crypto) { | ||
crypto = commonjsGlobal.crypto; | ||
} | ||
function _hasDoNotTrackEnabled() { | ||
return (typeof navigator !== 'undefined' && navigator.doNotTrack) === '1' || typeof window !== 'undefined' && window.doNotTrack === '1'; | ||
} | ||
// Native crypto import via require (NodeJS) | ||
if (!crypto && typeof commonjsRequire === 'function') { | ||
try { | ||
crypto = require('crypto'); | ||
} catch (err) {} | ||
} | ||
/* | ||
(c) 2009-2013 by Jeff Mott. All rights reserved. | ||
/* | ||
* Cryptographically secure pseudorandom number generator | ||
* | ||
* As Math.random() is cryptographically not safe to use | ||
*/ | ||
var cryptoSecureRandomInt = function () { | ||
if (crypto) { | ||
// Use getRandomValues method (Browser) | ||
if (typeof crypto.getRandomValues === 'function') { | ||
try { | ||
return crypto.getRandomValues(new Uint32Array(1))[0]; | ||
} catch (err) {} | ||
} | ||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
// Use randomBytes method (NodeJS) | ||
if (typeof crypto.randomBytes === 'function') { | ||
try { | ||
return crypto.randomBytes(4).readInt32LE(); | ||
} catch (err) {} | ||
} | ||
} | ||
Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer. | ||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation or other materials provided with the distribution. | ||
Neither the name CryptoJS nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS," AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
var CryptoJS = function (h, s) { | ||
var f = {}, | ||
g = f.lib = {}, | ||
q = function q() {}, | ||
m = g.Base = { | ||
extend: function extend(a) { | ||
q.prototype = this; | ||
var c = new q(); | ||
a && c.mixIn(a); | ||
c.hasOwnProperty('init') || (c.init = function () { | ||
c.$super.init.apply(this, arguments); | ||
}); | ||
c.init.prototype = c; | ||
c.$super = this; | ||
return c; | ||
}, | ||
create: function create() { | ||
var a = this.extend(); | ||
a.init.apply(a, arguments); | ||
return a; | ||
}, | ||
init: function init() {}, | ||
mixIn: function mixIn(a) { | ||
for (var c in a) { | ||
a.hasOwnProperty(c) && (this[c] = a[c]); | ||
}a.hasOwnProperty('toString') && (this.toString = a.toString); | ||
}, | ||
clone: function clone() { | ||
return this.init.prototype.extend(this); | ||
} | ||
}, | ||
r = g.WordArray = m.extend({ | ||
init: function init(a, c) { | ||
a = this.words = a || []; | ||
this.sigBytes = c != s ? c : 4 * a.length; | ||
}, | ||
toString: function toString(a) { | ||
return (a || k).stringify(this); | ||
}, | ||
concat: function concat(a) { | ||
var c = this.words, | ||
d = a.words, | ||
b = this.sigBytes; | ||
a = a.sigBytes; | ||
this.clamp(); | ||
if (b % 4) for (var e = 0; e < a; e++) { | ||
c[b + e >>> 2] |= (d[e >>> 2] >>> 24 - 8 * (e % 4) & 255) << 24 - 8 * ((b + e) % 4); | ||
} else if (d.length > 65535) for (e = 0; e < a; e += 4) { | ||
c[b + e >>> 2] = d[e >>> 2]; | ||
} else c.push.apply(c, d); | ||
this.sigBytes += a; | ||
return this; | ||
}, | ||
clamp: function clamp() { | ||
var a = this.words, | ||
c = this.sigBytes; | ||
a[c >>> 2] &= 4294967295 << 32 - 8 * (c % 4); | ||
a.length = h.ceil(c / 4); | ||
}, | ||
clone: function clone() { | ||
var a = m.clone.call(this); | ||
a.words = this.words.slice(0); | ||
return a; | ||
}, | ||
random: function random(a) { | ||
for (var c = [], d = 0; d < a; d += 4) { | ||
c.push(4294967296 * h.random() | 0); | ||
}return new r.init(c, a); | ||
} | ||
}), | ||
l = f.enc = {}, | ||
k = l.Hex = { | ||
stringify: function stringify(a) { | ||
var c = a.words; | ||
a = a.sigBytes; | ||
for (var d = [], b = 0; b < a; b++) { | ||
var e = c[b >>> 2] >>> 24 - 8 * (b % 4) & 255; | ||
d.push((e >>> 4).toString(16)); | ||
d.push((e & 15).toString(16)); | ||
} | ||
return d.join(''); | ||
}, | ||
parse: function parse(a) { | ||
for (var c = a.length, d = [], b = 0; b < c; b += 2) { | ||
d[b >>> 3] |= parseInt(a.substr(b, 2), 16) << 24 - 4 * (b % 8); | ||
} | ||
return new r.init(d, c / 2); | ||
} | ||
}, | ||
n = l.Latin1 = { | ||
stringify: function stringify(a) { | ||
var c = a.words; | ||
a = a.sigBytes; | ||
for (var d = [], b = 0; b < a; b++) { | ||
d.push(String.fromCharCode(c[b >>> 2] >>> 24 - 8 * (b % 4) & 255)); | ||
}return d.join(''); | ||
}, | ||
parse: function parse(a) { | ||
for (var c = a.length, d = [], b = 0; b < c; b++) { | ||
d[b >>> 2] |= (a.charCodeAt(b) & 255) << 24 - 8 * (b % 4); | ||
}return new r.init(d, c); | ||
} | ||
}, | ||
j = l.Utf8 = { | ||
stringify: function stringify(a) { | ||
try { | ||
return decodeURIComponent(escape(n.stringify(a))); | ||
} catch (c) { | ||
throw Error('Malformed UTF-8 data'); | ||
} | ||
}, | ||
parse: function parse(a) { | ||
return n.parse(unescape(encodeURIComponent(a))); | ||
} | ||
}, | ||
u = g.BufferedBlockAlgorithm = m.extend({ | ||
reset: function reset() { | ||
this._data = new r.init(); | ||
this._nDataBytes = 0; | ||
}, | ||
_append: function _append(a) { | ||
typeof a === 'string' && (a = j.parse(a)); | ||
this._data.concat(a); | ||
this._nDataBytes += a.sigBytes; | ||
}, | ||
_process: function _process(a) { | ||
var c = this._data, | ||
d = c.words, | ||
b = c.sigBytes, | ||
e = this.blockSize, | ||
f = b / (4 * e), | ||
f = a ? h.ceil(f) : h.max((f | 0) - this._minBufferSize, 0); | ||
a = f * e; | ||
b = h.min(4 * a, b); | ||
if (a) { | ||
for (var g = 0; g < a; g += e) { | ||
this._doProcessBlock(d, g); | ||
}g = d.splice(0, a); | ||
c.sigBytes -= b; | ||
} | ||
return new r.init(g, b); | ||
}, | ||
clone: function clone() { | ||
var a = m.clone.call(this); | ||
a._data = this._data.clone(); | ||
return a; | ||
}, | ||
_minBufferSize: 0 | ||
}); | ||
g.Hasher = u.extend({ | ||
cfg: m.extend(), | ||
init: function init(a) { | ||
this.cfg = this.cfg.extend(a); | ||
this.reset(); | ||
}, | ||
reset: function reset() { | ||
u.reset.call(this); | ||
this._doReset(); | ||
}, | ||
update: function update(a) { | ||
this._append(a); | ||
this._process(); | ||
return this; | ||
}, | ||
finalize: function finalize(a) { | ||
a && this._append(a); | ||
return this._doFinalize(); | ||
}, | ||
blockSize: 16, | ||
_createHelper: function _createHelper(a) { | ||
return function (c, d) { | ||
return new a.init(d).finalize(c); | ||
}; | ||
}, | ||
_createHmacHelper: function _createHmacHelper(a) { | ||
return function (c, d) { | ||
return new t.HMAC.init(a, d).finalize(c); | ||
}; | ||
} | ||
}); | ||
var t = f.algo = {}; | ||
return f; | ||
}(Math); | ||
(function (h) { | ||
for (var s = CryptoJS, f = s.lib, g = f.WordArray, q = f.Hasher, f = s.algo, m = [], r = [], l = function l(a) { | ||
return 4294967296 * (a - (a | 0)) | 0; | ||
}, k = 2, n = 0; n < 64;) { | ||
var j; | ||
a: { | ||
j = k; | ||
for (var u = h.sqrt(j), t = 2; t <= u; t++) { | ||
if (!(j % t)) { | ||
j = !1; | ||
break a; | ||
} | ||
}j = !0; | ||
} | ||
j && (n < 8 && (m[n] = l(h.pow(k, 0.5))), r[n] = l(h.pow(k, 1 / 3)), n++); | ||
k++; | ||
} | ||
var a = [], | ||
f = f.SHA256 = q.extend({ | ||
_doReset: function _doReset() { | ||
this._hash = new g.init(m.slice(0)); | ||
}, | ||
_doProcessBlock: function _doProcessBlock(c, d) { | ||
for (var b = this._hash.words, e = b[0], f = b[1], g = b[2], j = b[3], h = b[4], m = b[5], n = b[6], q = b[7], p = 0; p < 64; p++) { | ||
if (p < 16) { | ||
a[p] = c[d + p] | 0; | ||
} else { | ||
var k = a[p - 15], | ||
l = a[p - 2]; | ||
a[p] = ((k << 25 | k >>> 7) ^ (k << 14 | k >>> 18) ^ k >>> 3) + a[p - 7] + ((l << 15 | l >>> 17) ^ (l << 13 | l >>> 19) ^ l >>> 10) + a[p - 16]; | ||
} | ||
k = q + ((h << 26 | h >>> 6) ^ (h << 21 | h >>> 11) ^ (h << 7 | h >>> 25)) + (h & m ^ ~h & n) + r[p] + a[p]; | ||
l = ((e << 30 | e >>> 2) ^ (e << 19 | e >>> 13) ^ (e << 10 | e >>> 22)) + (e & f ^ e & g ^ f & g); | ||
q = n; | ||
n = m; | ||
m = h; | ||
h = j + k | 0; | ||
j = g; | ||
g = f; | ||
f = e; | ||
e = k + l | 0; | ||
} | ||
b[0] = b[0] + e | 0; | ||
b[1] = b[1] + f | 0; | ||
b[2] = b[2] + g | 0; | ||
b[3] = b[3] + j | 0; | ||
b[4] = b[4] + h | 0; | ||
b[5] = b[5] + m | 0; | ||
b[6] = b[6] + n | 0; | ||
b[7] = b[7] + q | 0; | ||
}, | ||
_doFinalize: function _doFinalize() { | ||
var a = this._data, | ||
d = a.words, | ||
b = 8 * this._nDataBytes, | ||
e = 8 * a.sigBytes; | ||
d[e >>> 5] |= 128 << 24 - e % 32; | ||
d[(e + 64 >>> 9 << 4) + 14] = h.floor(b / 4294967296); | ||
d[(e + 64 >>> 9 << 4) + 15] = b; | ||
a.sigBytes = 4 * d.length; | ||
this._process(); | ||
return this._hash; | ||
}, | ||
clone: function clone() { | ||
var a = q.clone.call(this); | ||
a._hash = this._hash.clone(); | ||
return a; | ||
} | ||
}); | ||
s.SHA256 = q._createHelper(f); | ||
s.HmacSHA256 = q._createHmacHelper(f); | ||
})(Math); | ||
(function () { | ||
var h = CryptoJS, | ||
s = h.enc.Utf8; | ||
h.algo.HMAC = h.lib.Base.extend({ | ||
init: function init(f, g) { | ||
f = this._hasher = new f.init(); | ||
typeof g === 'string' && (g = s.parse(g)); | ||
var h = f.blockSize, | ||
m = 4 * h; | ||
g.sigBytes > m && (g = f.finalize(g)); | ||
g.clamp(); | ||
for (var r = this._oKey = g.clone(), l = this._iKey = g.clone(), k = r.words, n = l.words, j = 0; j < h; j++) { | ||
k[j] ^= 1549556828, n[j] ^= 909522486; | ||
}r.sigBytes = l.sigBytes = m; | ||
this.reset(); | ||
}, | ||
reset: function reset() { | ||
var f = this._hasher; | ||
f.reset(); | ||
f.update(this._iKey); | ||
}, | ||
update: function update(f) { | ||
this._hasher.update(f); | ||
return this; | ||
}, | ||
finalize: function finalize(f) { | ||
var g = this._hasher; | ||
f = g.finalize(f); | ||
g.reset(); | ||
return g.finalize(this._oKey.clone().concat(f)); | ||
} | ||
}); | ||
})(); | ||
throw new Error('Native crypto module could not be used to get secure random number.'); | ||
}; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
/* | ||
* Local polyfill of Object.create | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
*/ | ||
var create = Object.create || (function () { | ||
function F() {} | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (obj) { | ||
var subtype; | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
F.prototype = obj; | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
subtype = new F(); | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
F.prototype = null; | ||
return target; | ||
}; | ||
return subtype; | ||
}; | ||
}()); | ||
var slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
/** | ||
* CryptoJS namespace. | ||
*/ | ||
var C = {}; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
/** | ||
* Library namespace. | ||
*/ | ||
var C_lib = C.lib = {}; | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
/** | ||
* Base object for prototypal inheritance. | ||
*/ | ||
var Base = C_lib.Base = (function () { | ||
return _arr; | ||
} | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
return { | ||
/** | ||
* Creates a new object that inherits from this object. | ||
* | ||
* @param {Object} overrides Properties to copy into the new object. | ||
* | ||
* @return {Object} The new object. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var MyType = CryptoJS.lib.Base.extend({ | ||
* field: 'value', | ||
* | ||
* method: function () { | ||
* } | ||
* }); | ||
*/ | ||
extend: function (overrides) { | ||
// Spawn | ||
var subtype = create(this); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
// Augment | ||
if (overrides) { | ||
subtype.mixIn(overrides); | ||
} | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
// Create default initializer | ||
if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { | ||
subtype.init = function () { | ||
subtype.$super.init.apply(this, arguments); | ||
}; | ||
} | ||
var Telemetry = function () { | ||
function Telemetry(options) { | ||
classCallCheck(this, Telemetry); | ||
// Initializer's prototype is the subtype object | ||
subtype.init.prototype = subtype; | ||
// Make sure failure to init this library cannot have side-effects | ||
try { | ||
this.trackers = []; | ||
this.workflows = {}; | ||
this.test = options.test; | ||
this.debug = options.debug; | ||
this.disabled = !telemetryEnabled(options); | ||
// Reference supertype | ||
subtype.$super = this; | ||
if (this.disabled) { | ||
console.log('Telemetry Disabled'); | ||
} | ||
return subtype; | ||
}, | ||
if (options.portal && options.portal.user) { | ||
var subscriptionInfo = options.portal.subscriptionInfo || {}; | ||
this.setUser(options.portal.user, subscriptionInfo.type); | ||
} else if (options.user) { | ||
this.setUser(options.user); | ||
} | ||
/** | ||
* Extends this object and runs the init method. | ||
* Arguments to create() will be passed to init(). | ||
* | ||
* @return {Object} The new object. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var instance = MyType.create(); | ||
*/ | ||
create: function () { | ||
var instance = this.extend(); | ||
instance.init.apply(instance, arguments); | ||
if (!this.disabled) { | ||
this._initializeTrackers(options); | ||
} | ||
} catch (e) { | ||
console.error('Telemetry Disabled'); | ||
console.error(e); | ||
this.disabled = true; | ||
} | ||
} | ||
return instance; | ||
}, | ||
createClass(Telemetry, [{ | ||
key: '_initializeTrackers', | ||
value: function _initializeTrackers(options) { | ||
if (options.plugins) { | ||
var _trackers; | ||
/** | ||
* Initializes a newly created object. | ||
* Override this method to add some logic when your objects are created. | ||
* | ||
* @example | ||
* | ||
* var MyType = CryptoJS.lib.Base.extend({ | ||
* init: function () { | ||
* // ... | ||
* } | ||
* }); | ||
*/ | ||
init: function () { | ||
}, | ||
(_trackers = this.trackers).push.apply(_trackers, toConsumableArray(options.plugins)); | ||
} | ||
/** | ||
* Copies properties into this object. | ||
* | ||
* @param {Object} properties The properties to mix in. | ||
* | ||
* @example | ||
* | ||
* MyType.mixIn({ | ||
* field: 'value' | ||
* }); | ||
*/ | ||
mixIn: function (properties) { | ||
for (var propertyName in properties) { | ||
if (properties.hasOwnProperty(propertyName)) { | ||
this[propertyName] = properties[propertyName]; | ||
} | ||
} | ||
if (!this.trackers.length) { | ||
console.error(new Error('No trackers configured')); | ||
} | ||
} | ||
}, { | ||
key: 'setUser', | ||
value: function setUser() { | ||
var user = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var orgType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Public'; | ||
// IE won't copy toString using the loop above | ||
if (properties.hasOwnProperty('toString')) { | ||
this.toString = properties.toString; | ||
} | ||
}, | ||
user = typeof user === 'string' ? { username: user } : user; | ||
this.user = user; | ||
this.user.accountType = orgType; | ||
var internalDomain = void 0; | ||
/** | ||
* Creates a copy of this object. | ||
* | ||
* @return {Object} The clone. | ||
* | ||
* @example | ||
* | ||
* var clone = instance.clone(); | ||
*/ | ||
clone: function () { | ||
return this.init.prototype.extend(this); | ||
} | ||
}; | ||
}()); | ||
if (user.email && user.email.split) { | ||
var domain = user.email.split('@')[1]; | ||
internalDomain = internalOrgs.filter(function (org) { | ||
return domain === org; | ||
}).length > 0; | ||
} | ||
/** | ||
* An array of 32-bit words. | ||
* | ||
* @property {Array} words The array of 32-bit words. | ||
* @property {number} sigBytes The number of significant bytes in this word array. | ||
*/ | ||
var WordArray = C_lib.WordArray = Base.extend({ | ||
/** | ||
* Initializes a newly created word array. | ||
* | ||
* @param {Array} words (Optional) An array of 32-bit words. | ||
* @param {number} sigBytes (Optional) The number of significant bytes in the words. | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.lib.WordArray.create(); | ||
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); | ||
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); | ||
*/ | ||
init: function (words, sigBytes) { | ||
words = this.words = words || []; | ||
if (internalDomain || ['In House', 'Demo and Marketing'].indexOf(orgType) > -1) { | ||
this.user.internalUser = true; | ||
} | ||
} | ||
}, { | ||
key: 'logPageView', | ||
value: function logPageView(page) { | ||
var event = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
if (sigBytes != undefined$1) { | ||
this.sigBytes = sigBytes; | ||
} else { | ||
this.sigBytes = words.length * 4; | ||
} | ||
}, | ||
var attributes = this.preProcess(event, options); | ||
/** | ||
* Converts this word array to a string. | ||
* | ||
* @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex | ||
* | ||
* @return {string} The stringified word array. | ||
* | ||
* @example | ||
* | ||
* var string = wordArray + ''; | ||
* var string = wordArray.toString(); | ||
* var string = wordArray.toString(CryptoJS.enc.Utf8); | ||
*/ | ||
toString: function (encoder) { | ||
return (encoder || Hex).stringify(this); | ||
}, | ||
if (this.debug) { | ||
console.log('Tracking page view', JSON.stringify(attributes)); | ||
} | ||
/** | ||
* Concatenates a word array to this word array. | ||
* | ||
* @param {WordArray} wordArray The word array to append. | ||
* | ||
* @return {WordArray} This word array. | ||
* | ||
* @example | ||
* | ||
* wordArray1.concat(wordArray2); | ||
*/ | ||
concat: function (wordArray) { | ||
// Shortcuts | ||
var thisWords = this.words; | ||
var thatWords = wordArray.words; | ||
var thisSigBytes = this.sigBytes; | ||
var thatSigBytes = wordArray.sigBytes; | ||
if (this.test && !this.disabled) { | ||
return attributes; | ||
} | ||
// Clamp excess bits | ||
this.clamp(); | ||
var trackers = this.trackers.filter(function (_ref) { | ||
var disabled = _ref.disabled; | ||
return !disabled; | ||
}); | ||
// Concat | ||
if (thisSigBytes % 4) { | ||
// Copy one byte at a time | ||
for (var i = 0; i < thatSigBytes; i++) { | ||
var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); | ||
} | ||
} else { | ||
// Copy one word at a time | ||
for (var j = 0; j < thatSigBytes; j += 4) { | ||
thisWords[(thisSigBytes + j) >>> 2] = thatWords[j >>> 2]; | ||
} | ||
} | ||
this.sigBytes += thatSigBytes; | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Page view was not logged because no trackers are configured.')); | ||
} | ||
// Chainable | ||
return this; | ||
}, | ||
return false; | ||
} | ||
/** | ||
* Removes insignificant bits. | ||
* | ||
* @example | ||
* | ||
* wordArray.clamp(); | ||
*/ | ||
clamp: function () { | ||
// Shortcuts | ||
var words = this.words; | ||
var sigBytes = this.sigBytes; | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
}); | ||
// Clamp | ||
words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); | ||
words.length = Math.ceil(sigBytes / 4); | ||
}, | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logEvent', | ||
value: function logEvent(event) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* Creates a copy of this word array. | ||
* | ||
* @return {WordArray} The clone. | ||
* | ||
* @example | ||
* | ||
* var clone = wordArray.clone(); | ||
*/ | ||
clone: function () { | ||
var clone = Base.clone.call(this); | ||
clone.words = this.words.slice(0); | ||
event = this.preProcess(event, options); | ||
return clone; | ||
}, | ||
if (this.debug) { | ||
console.log('Tracking event', JSON.stringify(event)); | ||
} | ||
/** | ||
* Creates a word array filled with random bytes. | ||
* | ||
* @param {number} nBytes The number of random bytes to generate. | ||
* | ||
* @return {WordArray} The random word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.lib.WordArray.random(16); | ||
*/ | ||
random: function (nBytes) { | ||
var words = []; | ||
if (this.test) { | ||
return event; | ||
} | ||
for (var i = 0; i < nBytes; i += 4) { | ||
words.push(cryptoSecureRandomInt()); | ||
} | ||
var trackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
return new WordArray.init(words, nBytes); | ||
} | ||
}); | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Event was not logged because no trackers are configured.')); | ||
} | ||
/** | ||
* Encoder namespace. | ||
*/ | ||
var C_enc = C.enc = {}; | ||
return false; | ||
} | ||
/** | ||
* Hex encoding strategy. | ||
*/ | ||
var Hex = C_enc.Hex = { | ||
/** | ||
* Converts a word array to a hex string. | ||
* | ||
* @param {WordArray} wordArray The word array. | ||
* | ||
* @return {string} The hex string. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var hexString = CryptoJS.enc.Hex.stringify(wordArray); | ||
*/ | ||
stringify: function (wordArray) { | ||
// Shortcuts | ||
var words = wordArray.words; | ||
var sigBytes = wordArray.sigBytes; | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
}); | ||
// Convert | ||
var hexChars = []; | ||
for (var i = 0; i < sigBytes; i++) { | ||
var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
hexChars.push((bite >>> 4).toString(16)); | ||
hexChars.push((bite & 0x0f).toString(16)); | ||
} | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logError', | ||
value: function logError() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return hexChars.join(''); | ||
}, | ||
var event = _extends({ eventType: 'error' }, options); | ||
this.logEvent(event); | ||
} | ||
}, { | ||
key: 'startWorkflow', | ||
value: function startWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* Converts a hex string to a word array. | ||
* | ||
* @param {string} hexStr The hex string. | ||
* | ||
* @return {WordArray} The word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.enc.Hex.parse(hexString); | ||
*/ | ||
parse: function (hexStr) { | ||
// Shortcut | ||
var hexStrLength = hexStr.length; | ||
var workflow = { | ||
name: name, | ||
start: Date.now(), | ||
steps: [], | ||
workflowId: Math.floor((1 + Math.random()) * 0x100000000000).toString(16) | ||
}; | ||
this._saveWorkflow(workflow); | ||
var workflowObj = _extends({ name: name, step: 'start' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
return workflow; | ||
} | ||
}, { | ||
key: 'stepWorkflow', | ||
value: function stepWorkflow(name, step) { | ||
var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
// Convert | ||
var words = []; | ||
for (var i = 0; i < hexStrLength; i += 2) { | ||
words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); | ||
} | ||
//TODO: check if the check for attributes being a string is useful or can be removed | ||
var details = typeof attributes === 'string' ? attributes : attributes.details; | ||
var workflowObj = _extends({ name: name, step: step, details: details }, attributes); | ||
this._logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'endWorkflow', | ||
value: function endWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return new WordArray.init(words, hexStrLength / 2); | ||
} | ||
}; | ||
var workflowObj = _extends({ name: name, step: 'finish' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'cancelWorkflow', | ||
value: function cancelWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* Latin1 encoding strategy. | ||
*/ | ||
var Latin1 = C_enc.Latin1 = { | ||
/** | ||
* Converts a word array to a Latin1 string. | ||
* | ||
* @param {WordArray} wordArray The word array. | ||
* | ||
* @return {string} The Latin1 string. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); | ||
*/ | ||
stringify: function (wordArray) { | ||
// Shortcuts | ||
var words = wordArray.words; | ||
var sigBytes = wordArray.sigBytes; | ||
var workflowObj = _extends({ name: name, step: 'cancel' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'getWorkflow', | ||
value: function getWorkflow(name) { | ||
var workflow = storage.get('TELEMETRY-WORKFLOW:' + name); | ||
// do not let old workflows be returned | ||
if (workflow) { | ||
var workflowAge = Date.now() - workflow.start; | ||
var timeout = 30 * 60 * 1000; | ||
if (workflowAge < timeout) { | ||
return workflow; | ||
} else { | ||
this._deleteWorkflow(workflow); | ||
} | ||
} | ||
} | ||
}, { | ||
key: '_saveWorkflow', | ||
value: function _saveWorkflow(workflow) { | ||
storage.set('TELEMETRY-WORKFLOW:' + workflow.name, workflow); | ||
} | ||
}, { | ||
key: '_deleteWorkflow', | ||
value: function _deleteWorkflow(workflow) { | ||
storage.delete('TELEMETRY-WORKFLOW:' + workflow.name); | ||
} | ||
}, { | ||
key: '_logWorkflow', | ||
value: function _logWorkflow() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
// Convert | ||
var latin1Chars = []; | ||
for (var i = 0; i < sigBytes; i++) { | ||
var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
latin1Chars.push(String.fromCharCode(bite)); | ||
} | ||
/* | ||
const workflow = { | ||
name: 'add layer to map', | ||
step: 'start', | ||
details: 'some details about the step' | ||
} | ||
*/ | ||
options = this.preProcess(options); | ||
var workflow = this.getWorkflow(options.name); | ||
return latin1Chars.join(''); | ||
}, | ||
if (!workflow) { | ||
this.startWorkflow(options.name); | ||
workflow = this.getWorkflow(options.name); | ||
} | ||
workflow.steps.push(options.step); | ||
workflow.duration = (Date.now() - workflow.start) / 1000; | ||
/** | ||
* Converts a Latin1 string to a word array. | ||
* | ||
* @param {string} latin1Str The Latin1 string. | ||
* | ||
* @return {WordArray} The word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.enc.Latin1.parse(latin1String); | ||
*/ | ||
parse: function (latin1Str) { | ||
// Shortcut | ||
var latin1StrLength = latin1Str.length; | ||
if (['cancel', 'finish'].indexOf(options.step) > -1) { | ||
this._deleteWorkflow(workflow); | ||
} else { | ||
this._saveWorkflow(workflow); | ||
} | ||
// Convert | ||
var words = []; | ||
for (var i = 0; i < latin1StrLength; i++) { | ||
words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); | ||
} | ||
var track = _extends(options, { | ||
eventType: 'workflow', | ||
category: options.name, | ||
action: options.step, | ||
label: options.details, | ||
duration: workflow.duration, | ||
workflowId: workflow.workflowId | ||
}); | ||
return new WordArray.init(words, latin1StrLength); | ||
} | ||
}; | ||
this.logEvent(track); | ||
} | ||
}, { | ||
key: 'preProcess', | ||
value: function preProcess() { | ||
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* UTF-8 encoding strategy. | ||
*/ | ||
var Utf8 = C_enc.Utf8 = { | ||
/** | ||
* Converts a word array to a UTF-8 string. | ||
* | ||
* @param {WordArray} wordArray The word array. | ||
* | ||
* @return {string} The UTF-8 string. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); | ||
*/ | ||
stringify: function (wordArray) { | ||
try { | ||
return decodeURIComponent(escape(Latin1.stringify(wordArray))); | ||
} catch (e) { | ||
throw new Error('Malformed UTF-8 data'); | ||
} | ||
}, | ||
var userMetadata = {}; | ||
/** | ||
* Converts a UTF-8 string to a word array. | ||
* | ||
* @param {string} utf8Str The UTF-8 string. | ||
* | ||
* @return {WordArray} The word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.enc.Utf8.parse(utf8String); | ||
*/ | ||
parse: function (utf8Str) { | ||
return Latin1.parse(unescape(encodeURIComponent(utf8Str))); | ||
} | ||
}; | ||
if (this.user) { | ||
userMetadata = { | ||
user: anonymize(this.user.username), | ||
org: anonymize(this.user.orgId), | ||
lastLogin: this.user.lastLogin, | ||
userSince: this.user.created, | ||
internalUser: this.user.internalUser || false, | ||
accountType: this.user.accountType | ||
}; | ||
} | ||
/** | ||
* Abstract buffered block algorithm template. | ||
* | ||
* The property blockSize must be implemented in a concrete subtype. | ||
* | ||
* @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 | ||
*/ | ||
var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ | ||
/** | ||
* Resets this block algorithm's data buffer to its initial state. | ||
* | ||
* @example | ||
* | ||
* bufferedBlockAlgorithm.reset(); | ||
*/ | ||
reset: function () { | ||
// Initial values | ||
this._data = new WordArray.init(); | ||
this._nDataBytes = 0; | ||
}, | ||
return Object.entries(_extends({}, event, userMetadata)).reduce(_makeEventPayload(options.omitComplexData), {}); | ||
} | ||
}, { | ||
key: 'disableTracker', | ||
value: function disableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref3) { | ||
var name = _ref3.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = true; | ||
} | ||
} | ||
}, { | ||
key: 'enableTracker', | ||
value: function enableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref4) { | ||
var name = _ref4.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = false; | ||
} | ||
} | ||
}]); | ||
return Telemetry; | ||
}(); | ||
/** | ||
* Adds new data to this block algorithm's buffer. | ||
* | ||
* @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. | ||
* | ||
* @example | ||
* | ||
* bufferedBlockAlgorithm._append('data'); | ||
* bufferedBlockAlgorithm._append(wordArray); | ||
*/ | ||
_append: function (data) { | ||
// Convert string to WordArray, else assume WordArray already | ||
if (typeof data == 'string') { | ||
data = Utf8.parse(data); | ||
} | ||
Telemetry.anonymize = anonymize; | ||
Telemetry.internalOrgs = internalOrgs; | ||
Telemetry.telemetryEnabled = telemetryEnabled; | ||
Telemetry.storage = storage; | ||
// Append | ||
this._data.concat(data); | ||
this._nDataBytes += data.sigBytes; | ||
}, | ||
/** | ||
* Processes available data blocks. | ||
* | ||
* This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. | ||
* | ||
* @param {boolean} doFlush Whether all blocks and partial blocks should be processed. | ||
* | ||
* @return {WordArray} The processed data. | ||
* | ||
* @example | ||
* | ||
* var processedData = bufferedBlockAlgorithm._process(); | ||
* var processedData = bufferedBlockAlgorithm._process(!!'flush'); | ||
*/ | ||
_process: function (doFlush) { | ||
var processedWords; | ||
function _makeEventPayload(omitComplexData) { | ||
return function (acc, _ref5) { | ||
var _ref6 = slicedToArray(_ref5, 2), | ||
key = _ref6[0], | ||
val = _ref6[1]; | ||
// Shortcuts | ||
var data = this._data; | ||
var dataWords = data.words; | ||
var dataSigBytes = data.sigBytes; | ||
var blockSize = this.blockSize; | ||
var blockSizeBytes = blockSize * 4; | ||
if (_isPrimitive(val)) { | ||
acc[key] = val; | ||
} else if (!omitComplexData) { | ||
console.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
acc[key] = val; | ||
} | ||
return acc; | ||
}; | ||
} | ||
// Count blocks ready | ||
var nBlocksReady = dataSigBytes / blockSizeBytes; | ||
if (doFlush) { | ||
// Round up to include partial blocks | ||
nBlocksReady = Math.ceil(nBlocksReady); | ||
} else { | ||
// Round down to include only full blocks, | ||
// less the number of blocks that must remain in the buffer | ||
nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); | ||
} | ||
function _isPrimitive(val) { | ||
var primitives = ['string', 'number', 'boolean', 'undefined']; | ||
return primitives.includes(typeof val === 'undefined' ? 'undefined' : _typeof(val)) || val && typeof val.valueOf() === 'string'; | ||
} | ||
// Count words ready | ||
var nWordsReady = nBlocksReady * blockSize; | ||
return Telemetry; | ||
// Count bytes ready | ||
var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); | ||
// Process blocks | ||
if (nWordsReady) { | ||
for (var offset = 0; offset < nWordsReady; offset += blockSize) { | ||
// Perform concrete-algorithm logic | ||
this._doProcessBlock(dataWords, offset); | ||
} | ||
// Remove processed words | ||
processedWords = dataWords.splice(0, nWordsReady); | ||
data.sigBytes -= nBytesReady; | ||
} | ||
// Return processed words | ||
return new WordArray.init(processedWords, nBytesReady); | ||
}, | ||
/** | ||
* Creates a copy of this object. | ||
* | ||
* @return {Object} The clone. | ||
* | ||
* @example | ||
* | ||
* var clone = bufferedBlockAlgorithm.clone(); | ||
*/ | ||
clone: function () { | ||
var clone = Base.clone.call(this); | ||
clone._data = this._data.clone(); | ||
return clone; | ||
}, | ||
_minBufferSize: 0 | ||
}); | ||
/** | ||
* Abstract hasher template. | ||
* | ||
* @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) | ||
*/ | ||
C_lib.Hasher = BufferedBlockAlgorithm.extend({ | ||
/** | ||
* Configuration options. | ||
*/ | ||
cfg: Base.extend(), | ||
/** | ||
* Initializes a newly created hasher. | ||
* | ||
* @param {Object} cfg (Optional) The configuration options to use for this hash computation. | ||
* | ||
* @example | ||
* | ||
* var hasher = CryptoJS.algo.SHA256.create(); | ||
*/ | ||
init: function (cfg) { | ||
// Apply config defaults | ||
this.cfg = this.cfg.extend(cfg); | ||
// Set initial values | ||
this.reset(); | ||
}, | ||
/** | ||
* Resets this hasher to its initial state. | ||
* | ||
* @example | ||
* | ||
* hasher.reset(); | ||
*/ | ||
reset: function () { | ||
// Reset data buffer | ||
BufferedBlockAlgorithm.reset.call(this); | ||
// Perform concrete-hasher logic | ||
this._doReset(); | ||
}, | ||
/** | ||
* Updates this hasher with a message. | ||
* | ||
* @param {WordArray|string} messageUpdate The message to append. | ||
* | ||
* @return {Hasher} This hasher. | ||
* | ||
* @example | ||
* | ||
* hasher.update('message'); | ||
* hasher.update(wordArray); | ||
*/ | ||
update: function (messageUpdate) { | ||
// Append | ||
this._append(messageUpdate); | ||
// Update the hash | ||
this._process(); | ||
// Chainable | ||
return this; | ||
}, | ||
/** | ||
* Finalizes the hash computation. | ||
* Note that the finalize operation is effectively a destructive, read-once operation. | ||
* | ||
* @param {WordArray|string} messageUpdate (Optional) A final message update. | ||
* | ||
* @return {WordArray} The hash. | ||
* | ||
* @example | ||
* | ||
* var hash = hasher.finalize(); | ||
* var hash = hasher.finalize('message'); | ||
* var hash = hasher.finalize(wordArray); | ||
*/ | ||
finalize: function (messageUpdate) { | ||
// Final message update | ||
if (messageUpdate) { | ||
this._append(messageUpdate); | ||
} | ||
// Perform concrete-hasher logic | ||
var hash = this._doFinalize(); | ||
return hash; | ||
}, | ||
blockSize: 512/32, | ||
/** | ||
* Creates a shortcut function to a hasher's object interface. | ||
* | ||
* @param {Hasher} hasher The hasher to create a helper for. | ||
* | ||
* @return {Function} The shortcut function. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); | ||
*/ | ||
_createHelper: function (hasher) { | ||
return function (message, cfg) { | ||
return new hasher.init(cfg).finalize(message); | ||
}; | ||
}, | ||
/** | ||
* Creates a shortcut function to the HMAC's object interface. | ||
* | ||
* @param {Hasher} hasher The hasher to use in this HMAC helper. | ||
* | ||
* @return {Function} The shortcut function. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); | ||
*/ | ||
_createHmacHelper: function (hasher) { | ||
return function (message, key) { | ||
return new C_algo.HMAC.init(hasher, key).finalize(message); | ||
}; | ||
} | ||
}); | ||
/** | ||
* Algorithm namespace. | ||
*/ | ||
var C_algo = C.algo = {}; | ||
return C; | ||
}(Math)); | ||
return CryptoJS; | ||
})); | ||
}(core)); | ||
(function (module, exports) { | ||
(function (root, factory) { | ||
{ | ||
// CommonJS | ||
module.exports = factory(core.exports); | ||
} | ||
}(commonjsGlobal, function (CryptoJS) { | ||
(function (Math) { | ||
// Shortcuts | ||
var C = CryptoJS; | ||
var C_lib = C.lib; | ||
var WordArray = C_lib.WordArray; | ||
var Hasher = C_lib.Hasher; | ||
var C_algo = C.algo; | ||
// Initialization and round constants tables | ||
var H = []; | ||
var K = []; | ||
// Compute constants | ||
(function () { | ||
function isPrime(n) { | ||
var sqrtN = Math.sqrt(n); | ||
for (var factor = 2; factor <= sqrtN; factor++) { | ||
if (!(n % factor)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function getFractionalBits(n) { | ||
return ((n - (n | 0)) * 0x100000000) | 0; | ||
} | ||
var n = 2; | ||
var nPrime = 0; | ||
while (nPrime < 64) { | ||
if (isPrime(n)) { | ||
if (nPrime < 8) { | ||
H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); | ||
} | ||
K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); | ||
nPrime++; | ||
} | ||
n++; | ||
} | ||
}()); | ||
// Reusable object | ||
var W = []; | ||
/** | ||
* SHA-256 hash algorithm. | ||
*/ | ||
var SHA256 = C_algo.SHA256 = Hasher.extend({ | ||
_doReset: function () { | ||
this._hash = new WordArray.init(H.slice(0)); | ||
}, | ||
_doProcessBlock: function (M, offset) { | ||
// Shortcut | ||
var H = this._hash.words; | ||
// Working variables | ||
var a = H[0]; | ||
var b = H[1]; | ||
var c = H[2]; | ||
var d = H[3]; | ||
var e = H[4]; | ||
var f = H[5]; | ||
var g = H[6]; | ||
var h = H[7]; | ||
// Computation | ||
for (var i = 0; i < 64; i++) { | ||
if (i < 16) { | ||
W[i] = M[offset + i] | 0; | ||
} else { | ||
var gamma0x = W[i - 15]; | ||
var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ | ||
((gamma0x << 14) | (gamma0x >>> 18)) ^ | ||
(gamma0x >>> 3); | ||
var gamma1x = W[i - 2]; | ||
var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ | ||
((gamma1x << 13) | (gamma1x >>> 19)) ^ | ||
(gamma1x >>> 10); | ||
W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; | ||
} | ||
var ch = (e & f) ^ (~e & g); | ||
var maj = (a & b) ^ (a & c) ^ (b & c); | ||
var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); | ||
var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); | ||
var t1 = h + sigma1 + ch + K[i] + W[i]; | ||
var t2 = sigma0 + maj; | ||
h = g; | ||
g = f; | ||
f = e; | ||
e = (d + t1) | 0; | ||
d = c; | ||
c = b; | ||
b = a; | ||
a = (t1 + t2) | 0; | ||
} | ||
// Intermediate hash value | ||
H[0] = (H[0] + a) | 0; | ||
H[1] = (H[1] + b) | 0; | ||
H[2] = (H[2] + c) | 0; | ||
H[3] = (H[3] + d) | 0; | ||
H[4] = (H[4] + e) | 0; | ||
H[5] = (H[5] + f) | 0; | ||
H[6] = (H[6] + g) | 0; | ||
H[7] = (H[7] + h) | 0; | ||
}, | ||
_doFinalize: function () { | ||
// Shortcuts | ||
var data = this._data; | ||
var dataWords = data.words; | ||
var nBitsTotal = this._nDataBytes * 8; | ||
var nBitsLeft = data.sigBytes * 8; | ||
// Add padding | ||
dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); | ||
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); | ||
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; | ||
data.sigBytes = dataWords.length * 4; | ||
// Hash final blocks | ||
this._process(); | ||
// Return final computed hash | ||
return this._hash; | ||
}, | ||
clone: function () { | ||
var clone = Hasher.clone.call(this); | ||
clone._hash = this._hash.clone(); | ||
return clone; | ||
} | ||
}); | ||
/** | ||
* Shortcut function to the hasher's object interface. | ||
* | ||
* @param {WordArray|string} message The message to hash. | ||
* | ||
* @return {WordArray} The hash. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var hash = CryptoJS.SHA256('message'); | ||
* var hash = CryptoJS.SHA256(wordArray); | ||
*/ | ||
C.SHA256 = Hasher._createHelper(SHA256); | ||
/** | ||
* Shortcut function to the HMAC's object interface. | ||
* | ||
* @param {WordArray|string} message The message to hash. | ||
* @param {WordArray|string} key The secret key. | ||
* | ||
* @return {WordArray} The HMAC. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var hmac = CryptoJS.HmacSHA256(message, key); | ||
*/ | ||
C.HmacSHA256 = Hasher._createHmacHelper(SHA256); | ||
}(Math)); | ||
return CryptoJS.SHA256; | ||
})); | ||
}(sha256$1)); | ||
var sha256 = sha256$1.exports; | ||
var encHex = {exports: {}}; | ||
(function (module, exports) { | ||
(function (root, factory) { | ||
{ | ||
// CommonJS | ||
module.exports = factory(core.exports); | ||
} | ||
}(commonjsGlobal, function (CryptoJS) { | ||
return CryptoJS.enc.Hex; | ||
})); | ||
}(encHex)); | ||
var hex = encHex.exports; | ||
var storage = { | ||
storage: {}, | ||
memory: true, | ||
get: function get(key) { | ||
var stored = void 0; | ||
try { | ||
stored = window.localStorage && window.localStorage.getItem(key) || this.storage[key]; | ||
} catch (e) { | ||
stored = this.storage[key]; | ||
} | ||
if (stored) { | ||
try { | ||
return JSON.parse(stored); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
}, | ||
set: function set(key, value) { | ||
// handle Safari private mode (setItem is not allowed) | ||
var valueToString = JSON.stringify(value); | ||
try { | ||
window.localStorage.setItem(key, valueToString); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
this.storage[key] = value; | ||
} | ||
}, | ||
delete: function _delete(key) { | ||
try { | ||
window.localStorage.removeItem(key); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
delete this.storage[key]; | ||
} | ||
} | ||
}; | ||
function telemetryEnabled() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var portal = options.portal || {}; | ||
if (options.disabled) { | ||
return false; | ||
} | ||
if (_hasDoNotTrackEnabled()) { | ||
return false; | ||
} | ||
if (typeof portal.eueiEnabled !== 'undefined' && portal.eueiEnabled === false) { | ||
// Portal does not allow tracking | ||
return false; | ||
} | ||
if (portal.eueiEnabled && portal.user && portal.user.orgId === portal.id) { | ||
// Portal allows tracking; except when user is anonymous or doesn't belong to portal's org | ||
return true; | ||
} | ||
if (portal.user && !portal.user.orgId && portal.ipCntryCode === 'US') { | ||
// Public user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (!portal.user && portal.ipCntryCode === 'US') { | ||
// Anonymous user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (Object.keys(portal).length > 0) { | ||
// Initialized with a Portal object but does not meet tracking conditions | ||
return false; | ||
} | ||
// Default condition not initialized with a Portal-Self object | ||
return true; | ||
} | ||
function _hasDoNotTrackEnabled() { | ||
return (typeof navigator !== 'undefined' && navigator.doNotTrack) === '1' || typeof window !== 'undefined' && window.doNotTrack === '1'; | ||
} | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
var slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
var INTERNAL_ORGS = ['esri.com', 'esriuk.com', 'esri.de', 'esri.ca', 'esrifrance.fr', 'esri.nl', 'esri-portugal.pt', 'esribulgaria.com', 'esri.fi', 'esri.kr', 'esrimalaysia.com.my', 'esri.es', 'esriaustralia.com.au', 'esri-southafrica.com', 'esri.cl', 'esrichina.com.cn', 'esri.co', 'esriturkey.com.tr', 'geodata.no', 'esriitalia.it', 'esri.pl']; | ||
var Telemetry = function () { | ||
function Telemetry(options) { | ||
classCallCheck(this, Telemetry); | ||
var _a, _b, _c; | ||
this.trackers = []; | ||
this.options = options; | ||
this.test = options.test; | ||
this.debug = options.debug; | ||
this.disabled = !telemetryEnabled(options); | ||
if (this.disabled) { | ||
console.warn('Telemetry Disabled'); | ||
} | ||
var user = ((_a = options.portal) === null || _a === void 0 ? void 0 : _a.user) || options.user; | ||
if (user) { | ||
this.setUser(user, (_c = (_b = options.portal) === null || _b === void 0 ? void 0 : _b.subscriptionInfo) === null || _c === void 0 ? void 0 : _c.type); | ||
} | ||
if (!this.disabled) { | ||
this.initializeTrackers(); | ||
} | ||
} | ||
createClass(Telemetry, [{ | ||
key: 'initializeTrackers', | ||
value: function initializeTrackers() { | ||
if (this.options.plugins) { | ||
var _trackers; | ||
(_trackers = this.trackers).push.apply(_trackers, toConsumableArray(this.options.plugins)); | ||
} | ||
if (!this.trackers.length) { | ||
console.error(new Error('No trackers configured')); | ||
} | ||
} | ||
}, { | ||
key: 'setUser', | ||
value: function setUser() { | ||
var user = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var orgType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Public'; | ||
user = typeof user === 'string' ? { username: user } : user; | ||
this.user = user; | ||
this.user.accountType = orgType; | ||
var internalDomain = void 0; | ||
if (user.email && user.email.split) { | ||
var domain = user.email.split('@')[1]; | ||
internalDomain = INTERNAL_ORGS.filter(function (org) { | ||
return domain === org; | ||
}).length > 0; | ||
} | ||
if (internalDomain || ['In House', 'Demo and Marketing'].indexOf(orgType) > -1) { | ||
this.user.internalUser = true; | ||
} | ||
} | ||
}, { | ||
key: 'logPageView', | ||
value: function logPageView(page) { | ||
var event = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var attributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking page view', JSON.stringify(attributes)); | ||
} | ||
if (this.test && !this.disabled) { | ||
return attributes; | ||
} | ||
var trackers = this.trackers.filter(function (_ref) { | ||
var disabled = _ref.disabled; | ||
return !disabled; | ||
}); | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Page view was not logged because no trackers are configured.')); | ||
} | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
}); | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logEvent', | ||
value: function logEvent(event) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
event = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking event', JSON.stringify(event)); | ||
} | ||
if (this.test) { | ||
return event; | ||
} | ||
var trackers = void 0; | ||
if (this.trackers.length) { | ||
trackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
} | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Event was not logged because no trackers are configured.')); | ||
} | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
}); | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logError', | ||
value: function logError() { | ||
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
event = _extends({ eventType: 'error' }, event); | ||
this.logEvent(event); | ||
} | ||
}, { | ||
key: 'startWorkflow', | ||
value: function startWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflow = { | ||
name: name, | ||
start: Date.now(), | ||
steps: [], | ||
workflowId: Math.floor((1 + Math.random()) * 0x100000000000).toString(16) | ||
}; | ||
this.saveWorkflow(workflow); | ||
var workflowObj = _extends({ name: name, step: 'start' }, attributes); | ||
this.logWorkflow(workflowObj); | ||
return workflow; | ||
} | ||
}, { | ||
key: 'stepWorkflow', | ||
value: function stepWorkflow(name, step) { | ||
var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
//TODO: check if the check for attributes being a string is useful or can be removed | ||
var details = typeof attributes === 'string' ? attributes : attributes.details; | ||
var workflowObj = _extends({ name: name, step: step, details: details }, attributes); | ||
this.logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'endWorkflow', | ||
value: function endWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflowObj = _extends({ name: name, step: 'finish' }, attributes); | ||
this.logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'cancelWorkflow', | ||
value: function cancelWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflowObj = _extends({ name: name, step: 'cancel' }, attributes); | ||
this.logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'getWorkflow', | ||
value: function getWorkflow(name) { | ||
var workflow = storage.get('TELEMETRY-WORKFLOW:' + name); | ||
// do not let old workflows be returned | ||
if (workflow) { | ||
var workflowAge = Date.now() - workflow.start; | ||
var timeout = 30 * 60 * 1000; | ||
if (workflowAge < timeout) { | ||
return workflow; | ||
} else { | ||
this.deleteWorkflow(workflow); | ||
} | ||
} | ||
} | ||
}, { | ||
key: 'saveWorkflow', | ||
value: function saveWorkflow(workflow) { | ||
storage.set('TELEMETRY-WORKFLOW:' + workflow.name, workflow); | ||
} | ||
}, { | ||
key: 'deleteWorkflow', | ||
value: function deleteWorkflow(workflow) { | ||
storage.delete('TELEMETRY-WORKFLOW:' + workflow.name); | ||
} | ||
}, { | ||
key: 'logWorkflow', | ||
value: function logWorkflow() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
/* | ||
const workflow = { | ||
name: 'add layer to map', | ||
step: 'start', | ||
details: 'some details about the step' | ||
} | ||
*/ | ||
options = this.preProcess(options); | ||
var workflow = this.getWorkflow(options.name); | ||
if (!workflow) { | ||
this.startWorkflow(options.name); | ||
workflow = this.getWorkflow(options.name); | ||
} | ||
workflow.steps.push(options.step); | ||
workflow.duration = (Date.now() - workflow.start) / 1000; | ||
if (['cancel', 'finish'].indexOf(options.step) > -1) { | ||
this.deleteWorkflow(workflow); | ||
} else { | ||
this.saveWorkflow(workflow); | ||
} | ||
var track = _extends(options, { | ||
eventType: 'workflow', | ||
category: options.name, | ||
action: options.step, | ||
label: options.details, | ||
duration: workflow.duration, | ||
workflowId: workflow.workflowId | ||
}); | ||
this.logEvent(track); | ||
} | ||
}, { | ||
key: 'preProcess', | ||
value: function preProcess() { | ||
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var userMetadata = {}; | ||
if (this.user) { | ||
userMetadata = { | ||
user: anonymize(this.user.username), | ||
org: anonymize(this.user.orgId), | ||
lastLogin: this.user.lastLogin, | ||
userSince: this.user.created, | ||
internalUser: this.user.internalUser || false, | ||
accountType: this.user.accountType | ||
}; | ||
} | ||
return Object.entries(_extends(_extends({}, event), userMetadata)).reduce(makeEventPayload(options.omitComplexData), {}); | ||
} | ||
}, { | ||
key: 'disableTracker', | ||
value: function disableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref3) { | ||
var name = _ref3.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = true; | ||
} | ||
} | ||
}, { | ||
key: 'enableTracker', | ||
value: function enableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref4) { | ||
var name = _ref4.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = false; | ||
} | ||
} | ||
}]); | ||
return Telemetry; | ||
}(); | ||
Telemetry.storage = storage; | ||
function anonymize(user) { | ||
if (!user) return; | ||
return sha256(user).toString(hex); | ||
} | ||
function makeEventPayload(omitComplexData) { | ||
return function (acc, _ref5) { | ||
var _ref6 = slicedToArray(_ref5, 2), | ||
key = _ref6[0], | ||
val = _ref6[1]; | ||
if (isPrimitive(val)) { | ||
acc[key] = val; | ||
} else if (!omitComplexData) { | ||
console.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
acc[key] = val; | ||
} | ||
return acc; | ||
}; | ||
} | ||
function isPrimitive(val) { | ||
var primitives = ['string', 'number', 'boolean', 'undefined']; | ||
return primitives.includes(typeof val === 'undefined' ? 'undefined' : _typeof(val)) || val && typeof val.valueOf() === 'string'; | ||
} | ||
return Telemetry; | ||
})); | ||
//# sourceMappingURL=telemetry.js.map |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.telemetry = factory()); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.telemetry = factory()); | ||
})(this, (function () { 'use strict'; | ||
function anonymize(user) { | ||
if (!user) return undefined; | ||
return CryptoJS.SHA256(user).toString(CryptoJS.enc.Hex); | ||
} | ||
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
var internalOrgs = ['esri.com', 'esriuk.com', 'esri.de', 'esri.ca', 'esrifrance.fr', 'esri.nl', 'esri-portugal.pt', 'esribulgaria.com', 'esri.fi', 'esri.kr', 'esrimalaysia.com.my', 'esri.es', 'esriaustralia.com.au', 'esri-southafrica.com', 'esri.cl', 'esrichina.com.cn', 'esri.co', 'esriturkey.com.tr', 'geodata.no', 'esriitalia.it', 'esri.pl']; | ||
function commonjsRequire (path) { | ||
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.'); | ||
} | ||
var storage = { | ||
storage: {}, | ||
memory: true, | ||
get: function get(key) { | ||
var stored = void 0; | ||
try { | ||
stored = window.localStorage && window.localStorage.getItem(key) || this.storage[key]; | ||
} catch (e) { | ||
stored = this.storage[key]; | ||
} | ||
if (stored) { | ||
try { | ||
return JSON.parse(stored); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
}, | ||
set: function set(key, value) { | ||
// handle Safari private mode (setItem is not allowed) | ||
value = JSON.stringify(value); | ||
try { | ||
window.localStorage.setItem(key, value); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
this.storage[key] = value; | ||
} | ||
}, | ||
delete: function _delete(key) { | ||
try { | ||
window.localStorage.removeItem(key); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
delete this.storage[key]; | ||
} | ||
} | ||
}; | ||
var sha256$1 = {exports: {}}; | ||
/* | ||
* Determines whether or not the telemetry library should be enabled based on passed in options | ||
*/ | ||
function telemetryEnabled() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var core = {exports: {}}; | ||
var portal = options.portal || {}; | ||
(function (module, exports) { | ||
(function (root, factory) { | ||
{ | ||
// CommonJS | ||
module.exports = factory(); | ||
} | ||
}(commonjsGlobal, function () { | ||
if (options.disabled) { | ||
// Tracking is manually disabled | ||
return false; | ||
} | ||
/*globals window, global, require*/ | ||
if (_hasDoNotTrackEnabled()) { | ||
// user's browser has turned off tracking | ||
return false; | ||
} | ||
/** | ||
* CryptoJS core components. | ||
*/ | ||
var CryptoJS = CryptoJS || (function (Math, undefined$1) { | ||
if (typeof portal.eueiEnabled !== 'undefined' && portal.eueiEnabled === false) { | ||
// Portal does not allow tracking | ||
return false; | ||
} | ||
var crypto; | ||
if (portal.eueiEnabled && portal.user && portal.user.orgId === portal.id) { | ||
// Portal allows tracking; except when user is anonymous or doesn't belong to portal's org | ||
return true; | ||
} | ||
// Native crypto from window (Browser) | ||
if (typeof window !== 'undefined' && window.crypto) { | ||
crypto = window.crypto; | ||
} | ||
if (portal.user && !portal.user.orgId && portal.ipCntryCode === 'US') { | ||
// Public user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
// Native crypto in web worker (Browser) | ||
if (typeof self !== 'undefined' && self.crypto) { | ||
crypto = self.crypto; | ||
} | ||
if (!portal.user && portal.ipCntryCode === 'US') { | ||
// Anonymous user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
// Native crypto from worker | ||
if (typeof globalThis !== 'undefined' && globalThis.crypto) { | ||
crypto = globalThis.crypto; | ||
} | ||
if (Object.keys(portal).length > 0) { | ||
// Initialized with a Portal object but does not meet tracking conditions | ||
return false; | ||
} | ||
// Native (experimental IE 11) crypto from window (Browser) | ||
if (!crypto && typeof window !== 'undefined' && window.msCrypto) { | ||
crypto = window.msCrypto; | ||
} | ||
// Default condition not initialized with a Portal-Self object | ||
return true; | ||
} | ||
// Native crypto from global (NodeJS) | ||
if (!crypto && typeof commonjsGlobal !== 'undefined' && commonjsGlobal.crypto) { | ||
crypto = commonjsGlobal.crypto; | ||
} | ||
function _hasDoNotTrackEnabled() { | ||
return (typeof navigator !== 'undefined' && navigator.doNotTrack) === '1' || typeof window !== 'undefined' && window.doNotTrack === '1'; | ||
} | ||
// Native crypto import via require (NodeJS) | ||
if (!crypto && typeof commonjsRequire === 'function') { | ||
try { | ||
crypto = require('crypto'); | ||
} catch (err) {} | ||
} | ||
/* | ||
(c) 2009-2013 by Jeff Mott. All rights reserved. | ||
/* | ||
* Cryptographically secure pseudorandom number generator | ||
* | ||
* As Math.random() is cryptographically not safe to use | ||
*/ | ||
var cryptoSecureRandomInt = function () { | ||
if (crypto) { | ||
// Use getRandomValues method (Browser) | ||
if (typeof crypto.getRandomValues === 'function') { | ||
try { | ||
return crypto.getRandomValues(new Uint32Array(1))[0]; | ||
} catch (err) {} | ||
} | ||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
// Use randomBytes method (NodeJS) | ||
if (typeof crypto.randomBytes === 'function') { | ||
try { | ||
return crypto.randomBytes(4).readInt32LE(); | ||
} catch (err) {} | ||
} | ||
} | ||
Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer. | ||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation or other materials provided with the distribution. | ||
Neither the name CryptoJS nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS," AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
var CryptoJS = function (h, s) { | ||
var f = {}, | ||
g = f.lib = {}, | ||
q = function q() {}, | ||
m = g.Base = { | ||
extend: function extend(a) { | ||
q.prototype = this; | ||
var c = new q(); | ||
a && c.mixIn(a); | ||
c.hasOwnProperty('init') || (c.init = function () { | ||
c.$super.init.apply(this, arguments); | ||
}); | ||
c.init.prototype = c; | ||
c.$super = this; | ||
return c; | ||
}, | ||
create: function create() { | ||
var a = this.extend(); | ||
a.init.apply(a, arguments); | ||
return a; | ||
}, | ||
init: function init() {}, | ||
mixIn: function mixIn(a) { | ||
for (var c in a) { | ||
a.hasOwnProperty(c) && (this[c] = a[c]); | ||
}a.hasOwnProperty('toString') && (this.toString = a.toString); | ||
}, | ||
clone: function clone() { | ||
return this.init.prototype.extend(this); | ||
} | ||
}, | ||
r = g.WordArray = m.extend({ | ||
init: function init(a, c) { | ||
a = this.words = a || []; | ||
this.sigBytes = c != s ? c : 4 * a.length; | ||
}, | ||
toString: function toString(a) { | ||
return (a || k).stringify(this); | ||
}, | ||
concat: function concat(a) { | ||
var c = this.words, | ||
d = a.words, | ||
b = this.sigBytes; | ||
a = a.sigBytes; | ||
this.clamp(); | ||
if (b % 4) for (var e = 0; e < a; e++) { | ||
c[b + e >>> 2] |= (d[e >>> 2] >>> 24 - 8 * (e % 4) & 255) << 24 - 8 * ((b + e) % 4); | ||
} else if (d.length > 65535) for (e = 0; e < a; e += 4) { | ||
c[b + e >>> 2] = d[e >>> 2]; | ||
} else c.push.apply(c, d); | ||
this.sigBytes += a; | ||
return this; | ||
}, | ||
clamp: function clamp() { | ||
var a = this.words, | ||
c = this.sigBytes; | ||
a[c >>> 2] &= 4294967295 << 32 - 8 * (c % 4); | ||
a.length = h.ceil(c / 4); | ||
}, | ||
clone: function clone() { | ||
var a = m.clone.call(this); | ||
a.words = this.words.slice(0); | ||
return a; | ||
}, | ||
random: function random(a) { | ||
for (var c = [], d = 0; d < a; d += 4) { | ||
c.push(4294967296 * h.random() | 0); | ||
}return new r.init(c, a); | ||
} | ||
}), | ||
l = f.enc = {}, | ||
k = l.Hex = { | ||
stringify: function stringify(a) { | ||
var c = a.words; | ||
a = a.sigBytes; | ||
for (var d = [], b = 0; b < a; b++) { | ||
var e = c[b >>> 2] >>> 24 - 8 * (b % 4) & 255; | ||
d.push((e >>> 4).toString(16)); | ||
d.push((e & 15).toString(16)); | ||
} | ||
return d.join(''); | ||
}, | ||
parse: function parse(a) { | ||
for (var c = a.length, d = [], b = 0; b < c; b += 2) { | ||
d[b >>> 3] |= parseInt(a.substr(b, 2), 16) << 24 - 4 * (b % 8); | ||
} | ||
return new r.init(d, c / 2); | ||
} | ||
}, | ||
n = l.Latin1 = { | ||
stringify: function stringify(a) { | ||
var c = a.words; | ||
a = a.sigBytes; | ||
for (var d = [], b = 0; b < a; b++) { | ||
d.push(String.fromCharCode(c[b >>> 2] >>> 24 - 8 * (b % 4) & 255)); | ||
}return d.join(''); | ||
}, | ||
parse: function parse(a) { | ||
for (var c = a.length, d = [], b = 0; b < c; b++) { | ||
d[b >>> 2] |= (a.charCodeAt(b) & 255) << 24 - 8 * (b % 4); | ||
}return new r.init(d, c); | ||
} | ||
}, | ||
j = l.Utf8 = { | ||
stringify: function stringify(a) { | ||
try { | ||
return decodeURIComponent(escape(n.stringify(a))); | ||
} catch (c) { | ||
throw Error('Malformed UTF-8 data'); | ||
} | ||
}, | ||
parse: function parse(a) { | ||
return n.parse(unescape(encodeURIComponent(a))); | ||
} | ||
}, | ||
u = g.BufferedBlockAlgorithm = m.extend({ | ||
reset: function reset() { | ||
this._data = new r.init(); | ||
this._nDataBytes = 0; | ||
}, | ||
_append: function _append(a) { | ||
typeof a === 'string' && (a = j.parse(a)); | ||
this._data.concat(a); | ||
this._nDataBytes += a.sigBytes; | ||
}, | ||
_process: function _process(a) { | ||
var c = this._data, | ||
d = c.words, | ||
b = c.sigBytes, | ||
e = this.blockSize, | ||
f = b / (4 * e), | ||
f = a ? h.ceil(f) : h.max((f | 0) - this._minBufferSize, 0); | ||
a = f * e; | ||
b = h.min(4 * a, b); | ||
if (a) { | ||
for (var g = 0; g < a; g += e) { | ||
this._doProcessBlock(d, g); | ||
}g = d.splice(0, a); | ||
c.sigBytes -= b; | ||
} | ||
return new r.init(g, b); | ||
}, | ||
clone: function clone() { | ||
var a = m.clone.call(this); | ||
a._data = this._data.clone(); | ||
return a; | ||
}, | ||
_minBufferSize: 0 | ||
}); | ||
g.Hasher = u.extend({ | ||
cfg: m.extend(), | ||
init: function init(a) { | ||
this.cfg = this.cfg.extend(a); | ||
this.reset(); | ||
}, | ||
reset: function reset() { | ||
u.reset.call(this); | ||
this._doReset(); | ||
}, | ||
update: function update(a) { | ||
this._append(a); | ||
this._process(); | ||
return this; | ||
}, | ||
finalize: function finalize(a) { | ||
a && this._append(a); | ||
return this._doFinalize(); | ||
}, | ||
blockSize: 16, | ||
_createHelper: function _createHelper(a) { | ||
return function (c, d) { | ||
return new a.init(d).finalize(c); | ||
}; | ||
}, | ||
_createHmacHelper: function _createHmacHelper(a) { | ||
return function (c, d) { | ||
return new t.HMAC.init(a, d).finalize(c); | ||
}; | ||
} | ||
}); | ||
var t = f.algo = {}; | ||
return f; | ||
}(Math); | ||
(function (h) { | ||
for (var s = CryptoJS, f = s.lib, g = f.WordArray, q = f.Hasher, f = s.algo, m = [], r = [], l = function l(a) { | ||
return 4294967296 * (a - (a | 0)) | 0; | ||
}, k = 2, n = 0; n < 64;) { | ||
var j; | ||
a: { | ||
j = k; | ||
for (var u = h.sqrt(j), t = 2; t <= u; t++) { | ||
if (!(j % t)) { | ||
j = !1; | ||
break a; | ||
} | ||
}j = !0; | ||
} | ||
j && (n < 8 && (m[n] = l(h.pow(k, 0.5))), r[n] = l(h.pow(k, 1 / 3)), n++); | ||
k++; | ||
} | ||
var a = [], | ||
f = f.SHA256 = q.extend({ | ||
_doReset: function _doReset() { | ||
this._hash = new g.init(m.slice(0)); | ||
}, | ||
_doProcessBlock: function _doProcessBlock(c, d) { | ||
for (var b = this._hash.words, e = b[0], f = b[1], g = b[2], j = b[3], h = b[4], m = b[5], n = b[6], q = b[7], p = 0; p < 64; p++) { | ||
if (p < 16) { | ||
a[p] = c[d + p] | 0; | ||
} else { | ||
var k = a[p - 15], | ||
l = a[p - 2]; | ||
a[p] = ((k << 25 | k >>> 7) ^ (k << 14 | k >>> 18) ^ k >>> 3) + a[p - 7] + ((l << 15 | l >>> 17) ^ (l << 13 | l >>> 19) ^ l >>> 10) + a[p - 16]; | ||
} | ||
k = q + ((h << 26 | h >>> 6) ^ (h << 21 | h >>> 11) ^ (h << 7 | h >>> 25)) + (h & m ^ ~h & n) + r[p] + a[p]; | ||
l = ((e << 30 | e >>> 2) ^ (e << 19 | e >>> 13) ^ (e << 10 | e >>> 22)) + (e & f ^ e & g ^ f & g); | ||
q = n; | ||
n = m; | ||
m = h; | ||
h = j + k | 0; | ||
j = g; | ||
g = f; | ||
f = e; | ||
e = k + l | 0; | ||
} | ||
b[0] = b[0] + e | 0; | ||
b[1] = b[1] + f | 0; | ||
b[2] = b[2] + g | 0; | ||
b[3] = b[3] + j | 0; | ||
b[4] = b[4] + h | 0; | ||
b[5] = b[5] + m | 0; | ||
b[6] = b[6] + n | 0; | ||
b[7] = b[7] + q | 0; | ||
}, | ||
_doFinalize: function _doFinalize() { | ||
var a = this._data, | ||
d = a.words, | ||
b = 8 * this._nDataBytes, | ||
e = 8 * a.sigBytes; | ||
d[e >>> 5] |= 128 << 24 - e % 32; | ||
d[(e + 64 >>> 9 << 4) + 14] = h.floor(b / 4294967296); | ||
d[(e + 64 >>> 9 << 4) + 15] = b; | ||
a.sigBytes = 4 * d.length; | ||
this._process(); | ||
return this._hash; | ||
}, | ||
clone: function clone() { | ||
var a = q.clone.call(this); | ||
a._hash = this._hash.clone(); | ||
return a; | ||
} | ||
}); | ||
s.SHA256 = q._createHelper(f); | ||
s.HmacSHA256 = q._createHmacHelper(f); | ||
})(Math); | ||
(function () { | ||
var h = CryptoJS, | ||
s = h.enc.Utf8; | ||
h.algo.HMAC = h.lib.Base.extend({ | ||
init: function init(f, g) { | ||
f = this._hasher = new f.init(); | ||
typeof g === 'string' && (g = s.parse(g)); | ||
var h = f.blockSize, | ||
m = 4 * h; | ||
g.sigBytes > m && (g = f.finalize(g)); | ||
g.clamp(); | ||
for (var r = this._oKey = g.clone(), l = this._iKey = g.clone(), k = r.words, n = l.words, j = 0; j < h; j++) { | ||
k[j] ^= 1549556828, n[j] ^= 909522486; | ||
}r.sigBytes = l.sigBytes = m; | ||
this.reset(); | ||
}, | ||
reset: function reset() { | ||
var f = this._hasher; | ||
f.reset(); | ||
f.update(this._iKey); | ||
}, | ||
update: function update(f) { | ||
this._hasher.update(f); | ||
return this; | ||
}, | ||
finalize: function finalize(f) { | ||
var g = this._hasher; | ||
f = g.finalize(f); | ||
g.reset(); | ||
return g.finalize(this._oKey.clone().concat(f)); | ||
} | ||
}); | ||
})(); | ||
throw new Error('Native crypto module could not be used to get secure random number.'); | ||
}; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
/* | ||
* Local polyfill of Object.create | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
*/ | ||
var create = Object.create || (function () { | ||
function F() {} | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (obj) { | ||
var subtype; | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
F.prototype = obj; | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
subtype = new F(); | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
F.prototype = null; | ||
return target; | ||
}; | ||
return subtype; | ||
}; | ||
}()); | ||
var slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
/** | ||
* CryptoJS namespace. | ||
*/ | ||
var C = {}; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
/** | ||
* Library namespace. | ||
*/ | ||
var C_lib = C.lib = {}; | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
/** | ||
* Base object for prototypal inheritance. | ||
*/ | ||
var Base = C_lib.Base = (function () { | ||
return _arr; | ||
} | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
return { | ||
/** | ||
* Creates a new object that inherits from this object. | ||
* | ||
* @param {Object} overrides Properties to copy into the new object. | ||
* | ||
* @return {Object} The new object. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var MyType = CryptoJS.lib.Base.extend({ | ||
* field: 'value', | ||
* | ||
* method: function () { | ||
* } | ||
* }); | ||
*/ | ||
extend: function (overrides) { | ||
// Spawn | ||
var subtype = create(this); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
// Augment | ||
if (overrides) { | ||
subtype.mixIn(overrides); | ||
} | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
// Create default initializer | ||
if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { | ||
subtype.init = function () { | ||
subtype.$super.init.apply(this, arguments); | ||
}; | ||
} | ||
var Telemetry = function () { | ||
function Telemetry(options) { | ||
classCallCheck(this, Telemetry); | ||
// Initializer's prototype is the subtype object | ||
subtype.init.prototype = subtype; | ||
// Make sure failure to init this library cannot have side-effects | ||
try { | ||
this.trackers = []; | ||
this.workflows = {}; | ||
this.test = options.test; | ||
this.debug = options.debug; | ||
this.disabled = !telemetryEnabled(options); | ||
// Reference supertype | ||
subtype.$super = this; | ||
if (this.disabled) { | ||
console.log('Telemetry Disabled'); | ||
} | ||
return subtype; | ||
}, | ||
if (options.portal && options.portal.user) { | ||
var subscriptionInfo = options.portal.subscriptionInfo || {}; | ||
this.setUser(options.portal.user, subscriptionInfo.type); | ||
} else if (options.user) { | ||
this.setUser(options.user); | ||
} | ||
/** | ||
* Extends this object and runs the init method. | ||
* Arguments to create() will be passed to init(). | ||
* | ||
* @return {Object} The new object. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var instance = MyType.create(); | ||
*/ | ||
create: function () { | ||
var instance = this.extend(); | ||
instance.init.apply(instance, arguments); | ||
if (!this.disabled) { | ||
this._initializeTrackers(options); | ||
} | ||
} catch (e) { | ||
console.error('Telemetry Disabled'); | ||
console.error(e); | ||
this.disabled = true; | ||
} | ||
} | ||
return instance; | ||
}, | ||
createClass(Telemetry, [{ | ||
key: '_initializeTrackers', | ||
value: function _initializeTrackers(options) { | ||
if (options.plugins) { | ||
var _trackers; | ||
/** | ||
* Initializes a newly created object. | ||
* Override this method to add some logic when your objects are created. | ||
* | ||
* @example | ||
* | ||
* var MyType = CryptoJS.lib.Base.extend({ | ||
* init: function () { | ||
* // ... | ||
* } | ||
* }); | ||
*/ | ||
init: function () { | ||
}, | ||
(_trackers = this.trackers).push.apply(_trackers, toConsumableArray(options.plugins)); | ||
} | ||
/** | ||
* Copies properties into this object. | ||
* | ||
* @param {Object} properties The properties to mix in. | ||
* | ||
* @example | ||
* | ||
* MyType.mixIn({ | ||
* field: 'value' | ||
* }); | ||
*/ | ||
mixIn: function (properties) { | ||
for (var propertyName in properties) { | ||
if (properties.hasOwnProperty(propertyName)) { | ||
this[propertyName] = properties[propertyName]; | ||
} | ||
} | ||
if (!this.trackers.length) { | ||
console.error(new Error('No trackers configured')); | ||
} | ||
} | ||
}, { | ||
key: 'setUser', | ||
value: function setUser() { | ||
var user = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var orgType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Public'; | ||
// IE won't copy toString using the loop above | ||
if (properties.hasOwnProperty('toString')) { | ||
this.toString = properties.toString; | ||
} | ||
}, | ||
user = typeof user === 'string' ? { username: user } : user; | ||
this.user = user; | ||
this.user.accountType = orgType; | ||
var internalDomain = void 0; | ||
/** | ||
* Creates a copy of this object. | ||
* | ||
* @return {Object} The clone. | ||
* | ||
* @example | ||
* | ||
* var clone = instance.clone(); | ||
*/ | ||
clone: function () { | ||
return this.init.prototype.extend(this); | ||
} | ||
}; | ||
}()); | ||
if (user.email && user.email.split) { | ||
var domain = user.email.split('@')[1]; | ||
internalDomain = internalOrgs.filter(function (org) { | ||
return domain === org; | ||
}).length > 0; | ||
} | ||
/** | ||
* An array of 32-bit words. | ||
* | ||
* @property {Array} words The array of 32-bit words. | ||
* @property {number} sigBytes The number of significant bytes in this word array. | ||
*/ | ||
var WordArray = C_lib.WordArray = Base.extend({ | ||
/** | ||
* Initializes a newly created word array. | ||
* | ||
* @param {Array} words (Optional) An array of 32-bit words. | ||
* @param {number} sigBytes (Optional) The number of significant bytes in the words. | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.lib.WordArray.create(); | ||
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); | ||
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); | ||
*/ | ||
init: function (words, sigBytes) { | ||
words = this.words = words || []; | ||
if (internalDomain || ['In House', 'Demo and Marketing'].indexOf(orgType) > -1) { | ||
this.user.internalUser = true; | ||
} | ||
} | ||
}, { | ||
key: 'logPageView', | ||
value: function logPageView(page) { | ||
var event = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
if (sigBytes != undefined$1) { | ||
this.sigBytes = sigBytes; | ||
} else { | ||
this.sigBytes = words.length * 4; | ||
} | ||
}, | ||
var attributes = this.preProcess(event, options); | ||
/** | ||
* Converts this word array to a string. | ||
* | ||
* @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex | ||
* | ||
* @return {string} The stringified word array. | ||
* | ||
* @example | ||
* | ||
* var string = wordArray + ''; | ||
* var string = wordArray.toString(); | ||
* var string = wordArray.toString(CryptoJS.enc.Utf8); | ||
*/ | ||
toString: function (encoder) { | ||
return (encoder || Hex).stringify(this); | ||
}, | ||
if (this.debug) { | ||
console.log('Tracking page view', JSON.stringify(attributes)); | ||
} | ||
/** | ||
* Concatenates a word array to this word array. | ||
* | ||
* @param {WordArray} wordArray The word array to append. | ||
* | ||
* @return {WordArray} This word array. | ||
* | ||
* @example | ||
* | ||
* wordArray1.concat(wordArray2); | ||
*/ | ||
concat: function (wordArray) { | ||
// Shortcuts | ||
var thisWords = this.words; | ||
var thatWords = wordArray.words; | ||
var thisSigBytes = this.sigBytes; | ||
var thatSigBytes = wordArray.sigBytes; | ||
if (this.test && !this.disabled) { | ||
return attributes; | ||
} | ||
// Clamp excess bits | ||
this.clamp(); | ||
var trackers = this.trackers.filter(function (_ref) { | ||
var disabled = _ref.disabled; | ||
return !disabled; | ||
}); | ||
// Concat | ||
if (thisSigBytes % 4) { | ||
// Copy one byte at a time | ||
for (var i = 0; i < thatSigBytes; i++) { | ||
var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); | ||
} | ||
} else { | ||
// Copy one word at a time | ||
for (var j = 0; j < thatSigBytes; j += 4) { | ||
thisWords[(thisSigBytes + j) >>> 2] = thatWords[j >>> 2]; | ||
} | ||
} | ||
this.sigBytes += thatSigBytes; | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Page view was not logged because no trackers are configured.')); | ||
} | ||
// Chainable | ||
return this; | ||
}, | ||
return false; | ||
} | ||
/** | ||
* Removes insignificant bits. | ||
* | ||
* @example | ||
* | ||
* wordArray.clamp(); | ||
*/ | ||
clamp: function () { | ||
// Shortcuts | ||
var words = this.words; | ||
var sigBytes = this.sigBytes; | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
}); | ||
// Clamp | ||
words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); | ||
words.length = Math.ceil(sigBytes / 4); | ||
}, | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logEvent', | ||
value: function logEvent(event) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* Creates a copy of this word array. | ||
* | ||
* @return {WordArray} The clone. | ||
* | ||
* @example | ||
* | ||
* var clone = wordArray.clone(); | ||
*/ | ||
clone: function () { | ||
var clone = Base.clone.call(this); | ||
clone.words = this.words.slice(0); | ||
event = this.preProcess(event, options); | ||
return clone; | ||
}, | ||
if (this.debug) { | ||
console.log('Tracking event', JSON.stringify(event)); | ||
} | ||
/** | ||
* Creates a word array filled with random bytes. | ||
* | ||
* @param {number} nBytes The number of random bytes to generate. | ||
* | ||
* @return {WordArray} The random word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.lib.WordArray.random(16); | ||
*/ | ||
random: function (nBytes) { | ||
var words = []; | ||
if (this.test) { | ||
return event; | ||
} | ||
for (var i = 0; i < nBytes; i += 4) { | ||
words.push(cryptoSecureRandomInt()); | ||
} | ||
var trackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
return new WordArray.init(words, nBytes); | ||
} | ||
}); | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Event was not logged because no trackers are configured.')); | ||
} | ||
/** | ||
* Encoder namespace. | ||
*/ | ||
var C_enc = C.enc = {}; | ||
return false; | ||
} | ||
/** | ||
* Hex encoding strategy. | ||
*/ | ||
var Hex = C_enc.Hex = { | ||
/** | ||
* Converts a word array to a hex string. | ||
* | ||
* @param {WordArray} wordArray The word array. | ||
* | ||
* @return {string} The hex string. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var hexString = CryptoJS.enc.Hex.stringify(wordArray); | ||
*/ | ||
stringify: function (wordArray) { | ||
// Shortcuts | ||
var words = wordArray.words; | ||
var sigBytes = wordArray.sigBytes; | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
}); | ||
// Convert | ||
var hexChars = []; | ||
for (var i = 0; i < sigBytes; i++) { | ||
var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
hexChars.push((bite >>> 4).toString(16)); | ||
hexChars.push((bite & 0x0f).toString(16)); | ||
} | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logError', | ||
value: function logError() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return hexChars.join(''); | ||
}, | ||
var event = _extends({ eventType: 'error' }, options); | ||
this.logEvent(event); | ||
} | ||
}, { | ||
key: 'startWorkflow', | ||
value: function startWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* Converts a hex string to a word array. | ||
* | ||
* @param {string} hexStr The hex string. | ||
* | ||
* @return {WordArray} The word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.enc.Hex.parse(hexString); | ||
*/ | ||
parse: function (hexStr) { | ||
// Shortcut | ||
var hexStrLength = hexStr.length; | ||
var workflow = { | ||
name: name, | ||
start: Date.now(), | ||
steps: [], | ||
workflowId: Math.floor((1 + Math.random()) * 0x100000000000).toString(16) | ||
}; | ||
this._saveWorkflow(workflow); | ||
var workflowObj = _extends({ name: name, step: 'start' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
return workflow; | ||
} | ||
}, { | ||
key: 'stepWorkflow', | ||
value: function stepWorkflow(name, step) { | ||
var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
// Convert | ||
var words = []; | ||
for (var i = 0; i < hexStrLength; i += 2) { | ||
words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); | ||
} | ||
//TODO: check if the check for attributes being a string is useful or can be removed | ||
var details = typeof attributes === 'string' ? attributes : attributes.details; | ||
var workflowObj = _extends({ name: name, step: step, details: details }, attributes); | ||
this._logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'endWorkflow', | ||
value: function endWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return new WordArray.init(words, hexStrLength / 2); | ||
} | ||
}; | ||
var workflowObj = _extends({ name: name, step: 'finish' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'cancelWorkflow', | ||
value: function cancelWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* Latin1 encoding strategy. | ||
*/ | ||
var Latin1 = C_enc.Latin1 = { | ||
/** | ||
* Converts a word array to a Latin1 string. | ||
* | ||
* @param {WordArray} wordArray The word array. | ||
* | ||
* @return {string} The Latin1 string. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); | ||
*/ | ||
stringify: function (wordArray) { | ||
// Shortcuts | ||
var words = wordArray.words; | ||
var sigBytes = wordArray.sigBytes; | ||
var workflowObj = _extends({ name: name, step: 'cancel' }, attributes); | ||
this._logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'getWorkflow', | ||
value: function getWorkflow(name) { | ||
var workflow = storage.get('TELEMETRY-WORKFLOW:' + name); | ||
// do not let old workflows be returned | ||
if (workflow) { | ||
var workflowAge = Date.now() - workflow.start; | ||
var timeout = 30 * 60 * 1000; | ||
if (workflowAge < timeout) { | ||
return workflow; | ||
} else { | ||
this._deleteWorkflow(workflow); | ||
} | ||
} | ||
} | ||
}, { | ||
key: '_saveWorkflow', | ||
value: function _saveWorkflow(workflow) { | ||
storage.set('TELEMETRY-WORKFLOW:' + workflow.name, workflow); | ||
} | ||
}, { | ||
key: '_deleteWorkflow', | ||
value: function _deleteWorkflow(workflow) { | ||
storage.delete('TELEMETRY-WORKFLOW:' + workflow.name); | ||
} | ||
}, { | ||
key: '_logWorkflow', | ||
value: function _logWorkflow() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
// Convert | ||
var latin1Chars = []; | ||
for (var i = 0; i < sigBytes; i++) { | ||
var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; | ||
latin1Chars.push(String.fromCharCode(bite)); | ||
} | ||
/* | ||
const workflow = { | ||
name: 'add layer to map', | ||
step: 'start', | ||
details: 'some details about the step' | ||
} | ||
*/ | ||
options = this.preProcess(options); | ||
var workflow = this.getWorkflow(options.name); | ||
return latin1Chars.join(''); | ||
}, | ||
if (!workflow) { | ||
this.startWorkflow(options.name); | ||
workflow = this.getWorkflow(options.name); | ||
} | ||
workflow.steps.push(options.step); | ||
workflow.duration = (Date.now() - workflow.start) / 1000; | ||
/** | ||
* Converts a Latin1 string to a word array. | ||
* | ||
* @param {string} latin1Str The Latin1 string. | ||
* | ||
* @return {WordArray} The word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.enc.Latin1.parse(latin1String); | ||
*/ | ||
parse: function (latin1Str) { | ||
// Shortcut | ||
var latin1StrLength = latin1Str.length; | ||
if (['cancel', 'finish'].indexOf(options.step) > -1) { | ||
this._deleteWorkflow(workflow); | ||
} else { | ||
this._saveWorkflow(workflow); | ||
} | ||
// Convert | ||
var words = []; | ||
for (var i = 0; i < latin1StrLength; i++) { | ||
words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); | ||
} | ||
var track = _extends(options, { | ||
eventType: 'workflow', | ||
category: options.name, | ||
action: options.step, | ||
label: options.details, | ||
duration: workflow.duration, | ||
workflowId: workflow.workflowId | ||
}); | ||
return new WordArray.init(words, latin1StrLength); | ||
} | ||
}; | ||
this.logEvent(track); | ||
} | ||
}, { | ||
key: 'preProcess', | ||
value: function preProcess() { | ||
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
/** | ||
* UTF-8 encoding strategy. | ||
*/ | ||
var Utf8 = C_enc.Utf8 = { | ||
/** | ||
* Converts a word array to a UTF-8 string. | ||
* | ||
* @param {WordArray} wordArray The word array. | ||
* | ||
* @return {string} The UTF-8 string. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); | ||
*/ | ||
stringify: function (wordArray) { | ||
try { | ||
return decodeURIComponent(escape(Latin1.stringify(wordArray))); | ||
} catch (e) { | ||
throw new Error('Malformed UTF-8 data'); | ||
} | ||
}, | ||
var userMetadata = {}; | ||
/** | ||
* Converts a UTF-8 string to a word array. | ||
* | ||
* @param {string} utf8Str The UTF-8 string. | ||
* | ||
* @return {WordArray} The word array. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var wordArray = CryptoJS.enc.Utf8.parse(utf8String); | ||
*/ | ||
parse: function (utf8Str) { | ||
return Latin1.parse(unescape(encodeURIComponent(utf8Str))); | ||
} | ||
}; | ||
if (this.user) { | ||
userMetadata = { | ||
user: anonymize(this.user.username), | ||
org: anonymize(this.user.orgId), | ||
lastLogin: this.user.lastLogin, | ||
userSince: this.user.created, | ||
internalUser: this.user.internalUser || false, | ||
accountType: this.user.accountType | ||
}; | ||
} | ||
/** | ||
* Abstract buffered block algorithm template. | ||
* | ||
* The property blockSize must be implemented in a concrete subtype. | ||
* | ||
* @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 | ||
*/ | ||
var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ | ||
/** | ||
* Resets this block algorithm's data buffer to its initial state. | ||
* | ||
* @example | ||
* | ||
* bufferedBlockAlgorithm.reset(); | ||
*/ | ||
reset: function () { | ||
// Initial values | ||
this._data = new WordArray.init(); | ||
this._nDataBytes = 0; | ||
}, | ||
return Object.entries(_extends({}, event, userMetadata)).reduce(_makeEventPayload(options.omitComplexData), {}); | ||
} | ||
}, { | ||
key: 'disableTracker', | ||
value: function disableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref3) { | ||
var name = _ref3.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = true; | ||
} | ||
} | ||
}, { | ||
key: 'enableTracker', | ||
value: function enableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref4) { | ||
var name = _ref4.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = false; | ||
} | ||
} | ||
}]); | ||
return Telemetry; | ||
}(); | ||
/** | ||
* Adds new data to this block algorithm's buffer. | ||
* | ||
* @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. | ||
* | ||
* @example | ||
* | ||
* bufferedBlockAlgorithm._append('data'); | ||
* bufferedBlockAlgorithm._append(wordArray); | ||
*/ | ||
_append: function (data) { | ||
// Convert string to WordArray, else assume WordArray already | ||
if (typeof data == 'string') { | ||
data = Utf8.parse(data); | ||
} | ||
Telemetry.anonymize = anonymize; | ||
Telemetry.internalOrgs = internalOrgs; | ||
Telemetry.telemetryEnabled = telemetryEnabled; | ||
Telemetry.storage = storage; | ||
// Append | ||
this._data.concat(data); | ||
this._nDataBytes += data.sigBytes; | ||
}, | ||
/** | ||
* Processes available data blocks. | ||
* | ||
* This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. | ||
* | ||
* @param {boolean} doFlush Whether all blocks and partial blocks should be processed. | ||
* | ||
* @return {WordArray} The processed data. | ||
* | ||
* @example | ||
* | ||
* var processedData = bufferedBlockAlgorithm._process(); | ||
* var processedData = bufferedBlockAlgorithm._process(!!'flush'); | ||
*/ | ||
_process: function (doFlush) { | ||
var processedWords; | ||
function _makeEventPayload(omitComplexData) { | ||
return function (acc, _ref5) { | ||
var _ref6 = slicedToArray(_ref5, 2), | ||
key = _ref6[0], | ||
val = _ref6[1]; | ||
// Shortcuts | ||
var data = this._data; | ||
var dataWords = data.words; | ||
var dataSigBytes = data.sigBytes; | ||
var blockSize = this.blockSize; | ||
var blockSizeBytes = blockSize * 4; | ||
if (_isPrimitive(val)) { | ||
acc[key] = val; | ||
} else if (!omitComplexData) { | ||
console.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
acc[key] = val; | ||
} | ||
return acc; | ||
}; | ||
} | ||
// Count blocks ready | ||
var nBlocksReady = dataSigBytes / blockSizeBytes; | ||
if (doFlush) { | ||
// Round up to include partial blocks | ||
nBlocksReady = Math.ceil(nBlocksReady); | ||
} else { | ||
// Round down to include only full blocks, | ||
// less the number of blocks that must remain in the buffer | ||
nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); | ||
} | ||
function _isPrimitive(val) { | ||
var primitives = ['string', 'number', 'boolean', 'undefined']; | ||
return primitives.includes(typeof val === 'undefined' ? 'undefined' : _typeof(val)) || val && typeof val.valueOf() === 'string'; | ||
} | ||
// Count words ready | ||
var nWordsReady = nBlocksReady * blockSize; | ||
return Telemetry; | ||
// Count bytes ready | ||
var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); | ||
// Process blocks | ||
if (nWordsReady) { | ||
for (var offset = 0; offset < nWordsReady; offset += blockSize) { | ||
// Perform concrete-algorithm logic | ||
this._doProcessBlock(dataWords, offset); | ||
} | ||
// Remove processed words | ||
processedWords = dataWords.splice(0, nWordsReady); | ||
data.sigBytes -= nBytesReady; | ||
} | ||
// Return processed words | ||
return new WordArray.init(processedWords, nBytesReady); | ||
}, | ||
/** | ||
* Creates a copy of this object. | ||
* | ||
* @return {Object} The clone. | ||
* | ||
* @example | ||
* | ||
* var clone = bufferedBlockAlgorithm.clone(); | ||
*/ | ||
clone: function () { | ||
var clone = Base.clone.call(this); | ||
clone._data = this._data.clone(); | ||
return clone; | ||
}, | ||
_minBufferSize: 0 | ||
}); | ||
/** | ||
* Abstract hasher template. | ||
* | ||
* @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) | ||
*/ | ||
C_lib.Hasher = BufferedBlockAlgorithm.extend({ | ||
/** | ||
* Configuration options. | ||
*/ | ||
cfg: Base.extend(), | ||
/** | ||
* Initializes a newly created hasher. | ||
* | ||
* @param {Object} cfg (Optional) The configuration options to use for this hash computation. | ||
* | ||
* @example | ||
* | ||
* var hasher = CryptoJS.algo.SHA256.create(); | ||
*/ | ||
init: function (cfg) { | ||
// Apply config defaults | ||
this.cfg = this.cfg.extend(cfg); | ||
// Set initial values | ||
this.reset(); | ||
}, | ||
/** | ||
* Resets this hasher to its initial state. | ||
* | ||
* @example | ||
* | ||
* hasher.reset(); | ||
*/ | ||
reset: function () { | ||
// Reset data buffer | ||
BufferedBlockAlgorithm.reset.call(this); | ||
// Perform concrete-hasher logic | ||
this._doReset(); | ||
}, | ||
/** | ||
* Updates this hasher with a message. | ||
* | ||
* @param {WordArray|string} messageUpdate The message to append. | ||
* | ||
* @return {Hasher} This hasher. | ||
* | ||
* @example | ||
* | ||
* hasher.update('message'); | ||
* hasher.update(wordArray); | ||
*/ | ||
update: function (messageUpdate) { | ||
// Append | ||
this._append(messageUpdate); | ||
// Update the hash | ||
this._process(); | ||
// Chainable | ||
return this; | ||
}, | ||
/** | ||
* Finalizes the hash computation. | ||
* Note that the finalize operation is effectively a destructive, read-once operation. | ||
* | ||
* @param {WordArray|string} messageUpdate (Optional) A final message update. | ||
* | ||
* @return {WordArray} The hash. | ||
* | ||
* @example | ||
* | ||
* var hash = hasher.finalize(); | ||
* var hash = hasher.finalize('message'); | ||
* var hash = hasher.finalize(wordArray); | ||
*/ | ||
finalize: function (messageUpdate) { | ||
// Final message update | ||
if (messageUpdate) { | ||
this._append(messageUpdate); | ||
} | ||
// Perform concrete-hasher logic | ||
var hash = this._doFinalize(); | ||
return hash; | ||
}, | ||
blockSize: 512/32, | ||
/** | ||
* Creates a shortcut function to a hasher's object interface. | ||
* | ||
* @param {Hasher} hasher The hasher to create a helper for. | ||
* | ||
* @return {Function} The shortcut function. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); | ||
*/ | ||
_createHelper: function (hasher) { | ||
return function (message, cfg) { | ||
return new hasher.init(cfg).finalize(message); | ||
}; | ||
}, | ||
/** | ||
* Creates a shortcut function to the HMAC's object interface. | ||
* | ||
* @param {Hasher} hasher The hasher to use in this HMAC helper. | ||
* | ||
* @return {Function} The shortcut function. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); | ||
*/ | ||
_createHmacHelper: function (hasher) { | ||
return function (message, key) { | ||
return new C_algo.HMAC.init(hasher, key).finalize(message); | ||
}; | ||
} | ||
}); | ||
/** | ||
* Algorithm namespace. | ||
*/ | ||
var C_algo = C.algo = {}; | ||
return C; | ||
}(Math)); | ||
return CryptoJS; | ||
})); | ||
}(core)); | ||
(function (module, exports) { | ||
(function (root, factory) { | ||
{ | ||
// CommonJS | ||
module.exports = factory(core.exports); | ||
} | ||
}(commonjsGlobal, function (CryptoJS) { | ||
(function (Math) { | ||
// Shortcuts | ||
var C = CryptoJS; | ||
var C_lib = C.lib; | ||
var WordArray = C_lib.WordArray; | ||
var Hasher = C_lib.Hasher; | ||
var C_algo = C.algo; | ||
// Initialization and round constants tables | ||
var H = []; | ||
var K = []; | ||
// Compute constants | ||
(function () { | ||
function isPrime(n) { | ||
var sqrtN = Math.sqrt(n); | ||
for (var factor = 2; factor <= sqrtN; factor++) { | ||
if (!(n % factor)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function getFractionalBits(n) { | ||
return ((n - (n | 0)) * 0x100000000) | 0; | ||
} | ||
var n = 2; | ||
var nPrime = 0; | ||
while (nPrime < 64) { | ||
if (isPrime(n)) { | ||
if (nPrime < 8) { | ||
H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); | ||
} | ||
K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); | ||
nPrime++; | ||
} | ||
n++; | ||
} | ||
}()); | ||
// Reusable object | ||
var W = []; | ||
/** | ||
* SHA-256 hash algorithm. | ||
*/ | ||
var SHA256 = C_algo.SHA256 = Hasher.extend({ | ||
_doReset: function () { | ||
this._hash = new WordArray.init(H.slice(0)); | ||
}, | ||
_doProcessBlock: function (M, offset) { | ||
// Shortcut | ||
var H = this._hash.words; | ||
// Working variables | ||
var a = H[0]; | ||
var b = H[1]; | ||
var c = H[2]; | ||
var d = H[3]; | ||
var e = H[4]; | ||
var f = H[5]; | ||
var g = H[6]; | ||
var h = H[7]; | ||
// Computation | ||
for (var i = 0; i < 64; i++) { | ||
if (i < 16) { | ||
W[i] = M[offset + i] | 0; | ||
} else { | ||
var gamma0x = W[i - 15]; | ||
var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ | ||
((gamma0x << 14) | (gamma0x >>> 18)) ^ | ||
(gamma0x >>> 3); | ||
var gamma1x = W[i - 2]; | ||
var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ | ||
((gamma1x << 13) | (gamma1x >>> 19)) ^ | ||
(gamma1x >>> 10); | ||
W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; | ||
} | ||
var ch = (e & f) ^ (~e & g); | ||
var maj = (a & b) ^ (a & c) ^ (b & c); | ||
var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); | ||
var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); | ||
var t1 = h + sigma1 + ch + K[i] + W[i]; | ||
var t2 = sigma0 + maj; | ||
h = g; | ||
g = f; | ||
f = e; | ||
e = (d + t1) | 0; | ||
d = c; | ||
c = b; | ||
b = a; | ||
a = (t1 + t2) | 0; | ||
} | ||
// Intermediate hash value | ||
H[0] = (H[0] + a) | 0; | ||
H[1] = (H[1] + b) | 0; | ||
H[2] = (H[2] + c) | 0; | ||
H[3] = (H[3] + d) | 0; | ||
H[4] = (H[4] + e) | 0; | ||
H[5] = (H[5] + f) | 0; | ||
H[6] = (H[6] + g) | 0; | ||
H[7] = (H[7] + h) | 0; | ||
}, | ||
_doFinalize: function () { | ||
// Shortcuts | ||
var data = this._data; | ||
var dataWords = data.words; | ||
var nBitsTotal = this._nDataBytes * 8; | ||
var nBitsLeft = data.sigBytes * 8; | ||
// Add padding | ||
dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); | ||
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); | ||
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; | ||
data.sigBytes = dataWords.length * 4; | ||
// Hash final blocks | ||
this._process(); | ||
// Return final computed hash | ||
return this._hash; | ||
}, | ||
clone: function () { | ||
var clone = Hasher.clone.call(this); | ||
clone._hash = this._hash.clone(); | ||
return clone; | ||
} | ||
}); | ||
/** | ||
* Shortcut function to the hasher's object interface. | ||
* | ||
* @param {WordArray|string} message The message to hash. | ||
* | ||
* @return {WordArray} The hash. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var hash = CryptoJS.SHA256('message'); | ||
* var hash = CryptoJS.SHA256(wordArray); | ||
*/ | ||
C.SHA256 = Hasher._createHelper(SHA256); | ||
/** | ||
* Shortcut function to the HMAC's object interface. | ||
* | ||
* @param {WordArray|string} message The message to hash. | ||
* @param {WordArray|string} key The secret key. | ||
* | ||
* @return {WordArray} The HMAC. | ||
* | ||
* @static | ||
* | ||
* @example | ||
* | ||
* var hmac = CryptoJS.HmacSHA256(message, key); | ||
*/ | ||
C.HmacSHA256 = Hasher._createHmacHelper(SHA256); | ||
}(Math)); | ||
return CryptoJS.SHA256; | ||
})); | ||
}(sha256$1)); | ||
var sha256 = sha256$1.exports; | ||
var encHex = {exports: {}}; | ||
(function (module, exports) { | ||
(function (root, factory) { | ||
{ | ||
// CommonJS | ||
module.exports = factory(core.exports); | ||
} | ||
}(commonjsGlobal, function (CryptoJS) { | ||
return CryptoJS.enc.Hex; | ||
})); | ||
}(encHex)); | ||
var hex = encHex.exports; | ||
var storage = { | ||
storage: {}, | ||
memory: true, | ||
get: function get(key) { | ||
var stored = void 0; | ||
try { | ||
stored = window.localStorage && window.localStorage.getItem(key) || this.storage[key]; | ||
} catch (e) { | ||
stored = this.storage[key]; | ||
} | ||
if (stored) { | ||
try { | ||
return JSON.parse(stored); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
}, | ||
set: function set(key, value) { | ||
// handle Safari private mode (setItem is not allowed) | ||
var valueToString = JSON.stringify(value); | ||
try { | ||
window.localStorage.setItem(key, valueToString); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
this.storage[key] = value; | ||
} | ||
}, | ||
delete: function _delete(key) { | ||
try { | ||
window.localStorage.removeItem(key); | ||
} catch (e) { | ||
if (!this.memory) { | ||
console.error('setting local storage failed, falling back to in-memory storage'); | ||
this.memory = true; | ||
} | ||
delete this.storage[key]; | ||
} | ||
} | ||
}; | ||
function telemetryEnabled() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var portal = options.portal || {}; | ||
if (options.disabled) { | ||
return false; | ||
} | ||
if (_hasDoNotTrackEnabled()) { | ||
return false; | ||
} | ||
if (typeof portal.eueiEnabled !== 'undefined' && portal.eueiEnabled === false) { | ||
// Portal does not allow tracking | ||
return false; | ||
} | ||
if (portal.eueiEnabled && portal.user && portal.user.orgId === portal.id) { | ||
// Portal allows tracking; except when user is anonymous or doesn't belong to portal's org | ||
return true; | ||
} | ||
if (portal.user && !portal.user.orgId && portal.ipCntryCode === 'US') { | ||
// Public user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (!portal.user && portal.ipCntryCode === 'US') { | ||
// Anonymous user in the United States on a portal that allows tracking | ||
return true; | ||
} | ||
if (Object.keys(portal).length > 0) { | ||
// Initialized with a Portal object but does not meet tracking conditions | ||
return false; | ||
} | ||
// Default condition not initialized with a Portal-Self object | ||
return true; | ||
} | ||
function _hasDoNotTrackEnabled() { | ||
return (typeof navigator !== 'undefined' && navigator.doNotTrack) === '1' || typeof window !== 'undefined' && window.doNotTrack === '1'; | ||
} | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
var slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
var INTERNAL_ORGS = ['esri.com', 'esriuk.com', 'esri.de', 'esri.ca', 'esrifrance.fr', 'esri.nl', 'esri-portugal.pt', 'esribulgaria.com', 'esri.fi', 'esri.kr', 'esrimalaysia.com.my', 'esri.es', 'esriaustralia.com.au', 'esri-southafrica.com', 'esri.cl', 'esrichina.com.cn', 'esri.co', 'esriturkey.com.tr', 'geodata.no', 'esriitalia.it', 'esri.pl']; | ||
var Telemetry = function () { | ||
function Telemetry(options) { | ||
classCallCheck(this, Telemetry); | ||
var _a, _b, _c; | ||
this.trackers = []; | ||
this.options = options; | ||
this.test = options.test; | ||
this.debug = options.debug; | ||
this.disabled = !telemetryEnabled(options); | ||
if (this.disabled) { | ||
console.warn('Telemetry Disabled'); | ||
} | ||
var user = ((_a = options.portal) === null || _a === void 0 ? void 0 : _a.user) || options.user; | ||
if (user) { | ||
this.setUser(user, (_c = (_b = options.portal) === null || _b === void 0 ? void 0 : _b.subscriptionInfo) === null || _c === void 0 ? void 0 : _c.type); | ||
} | ||
if (!this.disabled) { | ||
this.initializeTrackers(); | ||
} | ||
} | ||
createClass(Telemetry, [{ | ||
key: 'initializeTrackers', | ||
value: function initializeTrackers() { | ||
if (this.options.plugins) { | ||
var _trackers; | ||
(_trackers = this.trackers).push.apply(_trackers, toConsumableArray(this.options.plugins)); | ||
} | ||
if (!this.trackers.length) { | ||
console.error(new Error('No trackers configured')); | ||
} | ||
} | ||
}, { | ||
key: 'setUser', | ||
value: function setUser() { | ||
var user = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var orgType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Public'; | ||
user = typeof user === 'string' ? { username: user } : user; | ||
this.user = user; | ||
this.user.accountType = orgType; | ||
var internalDomain = void 0; | ||
if (user.email && user.email.split) { | ||
var domain = user.email.split('@')[1]; | ||
internalDomain = INTERNAL_ORGS.filter(function (org) { | ||
return domain === org; | ||
}).length > 0; | ||
} | ||
if (internalDomain || ['In House', 'Demo and Marketing'].indexOf(orgType) > -1) { | ||
this.user.internalUser = true; | ||
} | ||
} | ||
}, { | ||
key: 'logPageView', | ||
value: function logPageView(page) { | ||
var event = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var attributes = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking page view', JSON.stringify(attributes)); | ||
} | ||
if (this.test && !this.disabled) { | ||
return attributes; | ||
} | ||
var trackers = this.trackers.filter(function (_ref) { | ||
var disabled = _ref.disabled; | ||
return !disabled; | ||
}); | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Page view was not logged because no trackers are configured.')); | ||
} | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logPageView(page, attributes); | ||
}); | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logEvent', | ||
value: function logEvent(event) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
event = this.preProcess(event, options); | ||
if (this.debug) { | ||
console.log('Tracking event', JSON.stringify(event)); | ||
} | ||
if (this.test) { | ||
return event; | ||
} | ||
var trackers = void 0; | ||
if (this.trackers.length) { | ||
trackers = this.trackers.filter(function (_ref2) { | ||
var disabled = _ref2.disabled; | ||
return !disabled; | ||
}); | ||
} | ||
// TODO: Refactor nested conditionals | ||
if (!trackers.length || this.disabled) { | ||
if (!this.disabled) { | ||
console.error(new Error('Event was not logged because no trackers are configured.')); | ||
} | ||
return false; | ||
} | ||
var promises = trackers.map(function (tracker) { | ||
return tracker.logEvent(event); | ||
}); | ||
Promise.all(promises).then(); | ||
return true; | ||
} | ||
}, { | ||
key: 'logError', | ||
value: function logError() { | ||
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
event = _extends({ eventType: 'error' }, event); | ||
this.logEvent(event); | ||
} | ||
}, { | ||
key: 'startWorkflow', | ||
value: function startWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflow = { | ||
name: name, | ||
start: Date.now(), | ||
steps: [], | ||
workflowId: Math.floor((1 + Math.random()) * 0x100000000000).toString(16) | ||
}; | ||
this.saveWorkflow(workflow); | ||
var workflowObj = _extends({ name: name, step: 'start' }, attributes); | ||
this.logWorkflow(workflowObj); | ||
return workflow; | ||
} | ||
}, { | ||
key: 'stepWorkflow', | ||
value: function stepWorkflow(name, step) { | ||
var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
//TODO: check if the check for attributes being a string is useful or can be removed | ||
var details = typeof attributes === 'string' ? attributes : attributes.details; | ||
var workflowObj = _extends({ name: name, step: step, details: details }, attributes); | ||
this.logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'endWorkflow', | ||
value: function endWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflowObj = _extends({ name: name, step: 'finish' }, attributes); | ||
this.logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'cancelWorkflow', | ||
value: function cancelWorkflow(name) { | ||
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workflowObj = _extends({ name: name, step: 'cancel' }, attributes); | ||
this.logWorkflow(workflowObj); | ||
} | ||
}, { | ||
key: 'getWorkflow', | ||
value: function getWorkflow(name) { | ||
var workflow = storage.get('TELEMETRY-WORKFLOW:' + name); | ||
// do not let old workflows be returned | ||
if (workflow) { | ||
var workflowAge = Date.now() - workflow.start; | ||
var timeout = 30 * 60 * 1000; | ||
if (workflowAge < timeout) { | ||
return workflow; | ||
} else { | ||
this.deleteWorkflow(workflow); | ||
} | ||
} | ||
} | ||
}, { | ||
key: 'saveWorkflow', | ||
value: function saveWorkflow(workflow) { | ||
storage.set('TELEMETRY-WORKFLOW:' + workflow.name, workflow); | ||
} | ||
}, { | ||
key: 'deleteWorkflow', | ||
value: function deleteWorkflow(workflow) { | ||
storage.delete('TELEMETRY-WORKFLOW:' + workflow.name); | ||
} | ||
}, { | ||
key: 'logWorkflow', | ||
value: function logWorkflow() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
/* | ||
const workflow = { | ||
name: 'add layer to map', | ||
step: 'start', | ||
details: 'some details about the step' | ||
} | ||
*/ | ||
options = this.preProcess(options); | ||
var workflow = this.getWorkflow(options.name); | ||
if (!workflow) { | ||
this.startWorkflow(options.name); | ||
workflow = this.getWorkflow(options.name); | ||
} | ||
workflow.steps.push(options.step); | ||
workflow.duration = (Date.now() - workflow.start) / 1000; | ||
if (['cancel', 'finish'].indexOf(options.step) > -1) { | ||
this.deleteWorkflow(workflow); | ||
} else { | ||
this.saveWorkflow(workflow); | ||
} | ||
var track = _extends(options, { | ||
eventType: 'workflow', | ||
category: options.name, | ||
action: options.step, | ||
label: options.details, | ||
duration: workflow.duration, | ||
workflowId: workflow.workflowId | ||
}); | ||
this.logEvent(track); | ||
} | ||
}, { | ||
key: 'preProcess', | ||
value: function preProcess() { | ||
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var userMetadata = {}; | ||
if (this.user) { | ||
userMetadata = { | ||
user: anonymize(this.user.username), | ||
org: anonymize(this.user.orgId), | ||
lastLogin: this.user.lastLogin, | ||
userSince: this.user.created, | ||
internalUser: this.user.internalUser || false, | ||
accountType: this.user.accountType | ||
}; | ||
} | ||
return Object.entries(_extends(_extends({}, event), userMetadata)).reduce(makeEventPayload(options.omitComplexData), {}); | ||
} | ||
}, { | ||
key: 'disableTracker', | ||
value: function disableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref3) { | ||
var name = _ref3.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = true; | ||
} | ||
} | ||
}, { | ||
key: 'enableTracker', | ||
value: function enableTracker(trackerName) { | ||
var tracker = this.trackers.find(function (_ref4) { | ||
var name = _ref4.name; | ||
return name === trackerName; | ||
}); | ||
if (tracker) { | ||
tracker.disabled = false; | ||
} | ||
} | ||
}]); | ||
return Telemetry; | ||
}(); | ||
Telemetry.storage = storage; | ||
function anonymize(user) { | ||
if (!user) return; | ||
return sha256(user).toString(hex); | ||
} | ||
function makeEventPayload(omitComplexData) { | ||
return function (acc, _ref5) { | ||
var _ref6 = slicedToArray(_ref5, 2), | ||
key = _ref6[0], | ||
val = _ref6[1]; | ||
if (isPrimitive(val)) { | ||
acc[key] = val; | ||
} else if (!omitComplexData) { | ||
console.warn('You are trying to log a non-primitive value, ' + key + ':' + JSON.stringify(val) + '. This will get logged as [object Object]'); | ||
acc[key] = val; | ||
} | ||
return acc; | ||
}; | ||
} | ||
function isPrimitive(val) { | ||
var primitives = ['string', 'number', 'boolean', 'undefined']; | ||
return primitives.includes(typeof val === 'undefined' ? 'undefined' : _typeof(val)) || val && typeof val.valueOf() === 'string'; | ||
} | ||
return Telemetry; | ||
})); | ||
//# sourceMappingURL=telemetry.min.js.map |
{ | ||
"name": "@esri/telemetry", | ||
"version": "4.1.3", | ||
"version": "4.2.0", | ||
"description": "A JavaScript Implementation of the ArcGIS Telemetry Specification", | ||
@@ -20,6 +20,6 @@ "main": "dist/telemetry", | ||
"scripts": { | ||
"build": "rimraf dist && INPUT_FILE=./src/index.js rollup -c ../../rollup.config.js", | ||
"build": "rimraf dist && INPUT_FILE=./src/index.ts rollup -c ../../rollup.config.js", | ||
"lint": "standard src", | ||
"test": "jest \".*\\.test\\.js\" --notify", | ||
"test:watch": "jest \".*\\.test\\.js\" --notify --watch", | ||
"test": "jest \".*\\.test\\.ts\" --notify", | ||
"test:watch": "jest \".*\\.test\\.ts\" --notify --watch", | ||
"package": "npm install && npm run build && npm publish --access public", | ||
@@ -42,3 +42,10 @@ "package-beta": "npm run build && npm publish --tag beta --access public" | ||
], | ||
"gitHead": "a41c0bf7427c207bb7b2158289a36ae42639522e" | ||
"devDependencies": { | ||
"@types/crypto-js": "^4.1.1", | ||
"@types/node": "^17.0.21" | ||
}, | ||
"dependencies": { | ||
"crypto-js": "^4.1.1" | ||
}, | ||
"gitHead": "c99a7fccf688671dccbfc486b25d8ea026f8025f" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
663918
7976
1
2
+ Addedcrypto-js@^4.1.1
+ Addedcrypto-js@4.2.0(transitive)