@snowplow/javascript-tracker
Version:
Web analytics for Snowplow
1 lines • 391 kB
Source Map (JSON)
{"version":3,"file":"sp.js","sources":["../../../common/temp/node_modules/.pnpm/tslib@2.1.0/node_modules/tslib/tslib.es6.js","../../../libraries/tracker-core/dist/index.module.js","../../../libraries/browser-tracker-core/dist/index.module.js","../../../plugins/browser-plugin-client-hints/dist/index.module.js","../../../plugins/browser-plugin-optimizely-x/dist/index.module.js","../../../plugins/browser-plugin-performance-timing/dist/index.module.js","../../../plugins/browser-plugin-consent/dist/index.module.js","../../../plugins/browser-plugin-geolocation/dist/index.module.js","../../../plugins/browser-plugin-ga-cookies/dist/index.module.js","../../../plugins/browser-plugin-link-click-tracking/dist/index.module.js","../../../plugins/browser-plugin-form-tracking/dist/index.module.js","../../../plugins/browser-plugin-error-tracking/dist/index.module.js","../../../plugins/browser-plugin-timezone/dist/index.module.js","../../../plugins/browser-plugin-ecommerce/dist/index.module.js","../../../plugins/browser-plugin-enhanced-ecommerce/dist/index.module.js","../../../plugins/browser-plugin-ad-tracking/dist/index.module.js","../../../plugins/browser-plugin-site-tracking/dist/index.module.js","../../../common/temp/node_modules/.pnpm/uuid@3.4.0/node_modules/uuid/lib/bytesToUuid.js","../../../common/temp/node_modules/.pnpm/uuid@3.4.0/node_modules/uuid/lib/rng-browser.js","../../../common/temp/node_modules/.pnpm/uuid@3.4.0/node_modules/uuid/v1.js","../../../common/temp/node_modules/.pnpm/uuid@3.4.0/node_modules/uuid/v4.js","../../../common/temp/node_modules/.pnpm/uuid@3.4.0/node_modules/uuid/index.js","../../../common/temp/node_modules/.pnpm/crypt@0.0.2/node_modules/crypt/crypt.js","../../../common/temp/node_modules/.pnpm/charenc@0.0.2/node_modules/charenc/charenc.js","../../../common/temp/node_modules/.pnpm/sha1@1.1.1/node_modules/sha1/sha1.js","../../browser-tracker/dist/index.module.js","../../../common/temp/node_modules/.pnpm/jstimezonedetect@1.0.7/node_modules/jstimezonedetect/dist/jstz.min.js","../src/index.ts","../src/in_queue.ts","../src/features.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from) {\r\n for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)\r\n to[j] = from[i];\r\n return to;\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, privateMap) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to get private field on non-instance\");\r\n }\r\n return privateMap.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, privateMap, value) {\r\n if (!privateMap.has(receiver)) {\r\n throw new TypeError(\"attempted to set private field on non-instance\");\r\n }\r\n privateMap.set(receiver, value);\r\n return value;\r\n}\r\n","/*!\n * Core functionality for Snowplow JavaScript trackers v3.0.0-beta.1 (http://bit.ly/sp-js)\n * Copyright 2021 Snowplow Analytics Ltd, 2010 Anthon Pang\n * Licensed under BSD-3-Clause\n */\n\nimport { __spreadArray, __assign } from 'tslib';\nimport { v4 } from 'uuid';\n\n/*\n * Copyright (c) 2013 Kevin van Zonneveld (http://kvz.io)\n * and Contributors (http://phpjs.org/authors)\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\n * of the Software, and to permit persons to whom the Software is furnished to do\n * so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n/**\n * Encodes a string into a url safe Base 64 encoded string\n * @remark See: {@link http://tools.ietf.org/html/rfc4648#page-7}\n * @param data String to encode\n * @returns The url safe Base 64 string\n */\nfunction base64urlencode(data) {\n if (!data) {\n return data;\n }\n var enc = base64encode(data);\n return enc.replace(/=/g, '').replace(/\\+/g, '-').replace(/\\//g, '_');\n}\nvar b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';\n/**\n * Encode string as base64.\n * Any type can be passed, but will be stringified\n *\n * @param data string to encode\n * @returns base64-encoded string\n */\nfunction base64encode(data) {\n // discuss at: http://phpjs.org/functions/base64_encode/\n // original by: Tyler Akins (http://rumkin.com)\n // improved by: Bayron Guevara\n // improved by: Thunder.m\n // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)\n // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)\n // improved by: Rafał Kukawski (http://kukawski.pl)\n // bugfixed by: Pellentesque Malesuada\n // example 1: base64_encode('Kevin van Zonneveld');\n // returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='\n // example 2: base64_encode('a');\n // returns 2: 'YQ=='\n // example 3: base64_encode('✓ à la mode');\n // returns 3: '4pyTIMOgIGxhIG1vZGU='\n var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0;\n var tmp_arr = [];\n if (!data) {\n return data;\n }\n data = unescape(encodeURIComponent(data));\n do {\n // pack three octets into four hexets\n o1 = data.charCodeAt(i++);\n o2 = data.charCodeAt(i++);\n o3 = data.charCodeAt(i++);\n bits = (o1 << 16) | (o2 << 8) | o3;\n h1 = (bits >> 18) & 0x3f;\n h2 = (bits >> 12) & 0x3f;\n h3 = (bits >> 6) & 0x3f;\n h4 = bits & 0x3f;\n // use hexets to index into b64, and append result to encoded string\n tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);\n } while (i < data.length);\n var enc = tmp_arr.join('');\n var r = data.length % 3;\n return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);\n}\n\n/*\n * Copyright (c) 2021 Snowplow Analytics Ltd, 2010 Anthon Pang\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are met:\n *\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n *\n * 2. Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation\n * and/or other materials provided with the distribution.\n *\n * 3. Neither the name of the copyright holder nor the names of its\n * contributors may be used to endorse or promote products derived from\n * this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\nfunction payloadBuilder() {\n var dict = {}, allJson = [], jsonForProcessing = [];\n var processor;\n var add = function (key, value) {\n if (value != null && value !== '') {\n // null also checks undefined\n dict[key] = value;\n }\n };\n var addDict = function (dict) {\n for (var key in dict) {\n if (Object.prototype.hasOwnProperty.call(dict, key)) {\n add(key, dict[key]);\n }\n }\n };\n var addJson = function (keyIfEncoded, keyIfNotEncoded, json) {\n if (json && isNonEmptyJson(json)) {\n var jsonWithKeys = [keyIfEncoded, keyIfNotEncoded, json];\n jsonForProcessing.push(jsonWithKeys);\n allJson.push(jsonWithKeys);\n }\n };\n return {\n add: add,\n addDict: addDict,\n addJson: addJson,\n getPayload: function () { return dict; },\n getJson: function () { return allJson; },\n withJsonProcessor: function (jsonProcessor) {\n processor = jsonProcessor;\n },\n build: function () {\n processor === null || processor === void 0 ? void 0 : processor(this, jsonForProcessing);\n return dict;\n }\n };\n}\n/**\n * A helper to build a Snowplow request from a set of name-value pairs, provided using the add methods.\n * Will base64 encode JSON, if desired, on build\n *\n * @return The request builder, with add and build methods\n */\nfunction payloadJsonProcessor(encodeBase64) {\n return function (payloadBuilder, jsonForProcessing) {\n for (var _i = 0, jsonForProcessing_1 = jsonForProcessing; _i < jsonForProcessing_1.length; _i++) {\n var json = jsonForProcessing_1[_i];\n var str = JSON.stringify(json[2]);\n if (encodeBase64) {\n payloadBuilder.add(json[0], base64urlencode(str));\n }\n else {\n payloadBuilder.add(json[1], str);\n }\n }\n jsonForProcessing.length = 0;\n };\n}\n/**\n * Is property a non-empty JSON?\n * @param property Checks if object is non-empty json\n */\nfunction isNonEmptyJson(property) {\n if (!isJson(property)) {\n return false;\n }\n for (var key in property) {\n if (Object.prototype.hasOwnProperty.call(property, key)) {\n return true;\n }\n }\n return false;\n}\n/**\n * Is property a JSON?\n * @param property Checks if object is json\n */\nfunction isJson(property) {\n return (typeof property !== 'undefined' &&\n property !== null &&\n (property.constructor === {}.constructor || property.constructor === [].constructor));\n}\n\n/*\n * Copyright (c) 2021 Snowplow Analytics Ltd, 2010 Anthon Pang\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are met:\n *\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n *\n * 2. Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation\n * and/or other materials provided with the distribution.\n *\n * 3. Neither the name of the copyright holder nor the names of its\n * contributors may be used to endorse or promote products derived from\n * this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\nvar label = 'Snowplow: ';\nvar LOG_LEVEL;\n(function (LOG_LEVEL) {\n LOG_LEVEL[LOG_LEVEL[\"none\"] = 0] = \"none\";\n LOG_LEVEL[LOG_LEVEL[\"error\"] = 1] = \"error\";\n LOG_LEVEL[LOG_LEVEL[\"warn\"] = 2] = \"warn\";\n LOG_LEVEL[LOG_LEVEL[\"debug\"] = 3] = \"debug\";\n LOG_LEVEL[LOG_LEVEL[\"info\"] = 4] = \"info\";\n})(LOG_LEVEL || (LOG_LEVEL = {}));\nvar LOG = logger();\nfunction logger(logLevel) {\n if (logLevel === void 0) { logLevel = LOG_LEVEL.warn; }\n function setLogLevel(level) {\n if (LOG_LEVEL[level]) {\n logLevel = level;\n }\n else {\n logLevel = LOG_LEVEL.warn;\n }\n }\n /**\n * Log errors, with or without error object\n */\n function error(message, error) {\n var extraParams = [];\n for (var _i = 2; _i < arguments.length; _i++) {\n extraParams[_i - 2] = arguments[_i];\n }\n if (logLevel >= LOG_LEVEL.error && typeof console !== 'undefined') {\n var logMsg = label + message + '\\n';\n if (error) {\n console.error.apply(console, __spreadArray([logMsg + '\\n', error], extraParams));\n }\n else {\n console.error.apply(console, __spreadArray([logMsg], extraParams));\n }\n }\n }\n /**\n * Log warnings, with or without error object\n */\n function warn(message, error) {\n var extraParams = [];\n for (var _i = 2; _i < arguments.length; _i++) {\n extraParams[_i - 2] = arguments[_i];\n }\n if (logLevel >= LOG_LEVEL.warn && typeof console !== 'undefined') {\n if (typeof console !== 'undefined') {\n var logMsg = label + message;\n if (error) {\n console.warn.apply(console, __spreadArray([logMsg + '\\n', error], extraParams));\n }\n else {\n console.warn.apply(console, __spreadArray([logMsg], extraParams));\n }\n }\n }\n }\n /**\n * Log debug messages\n */\n function debug(message) {\n var extraParams = [];\n for (var _i = 1; _i < arguments.length; _i++) {\n extraParams[_i - 1] = arguments[_i];\n }\n if (logLevel >= LOG_LEVEL.debug && typeof console !== 'undefined') {\n if (typeof console !== 'undefined') {\n console.warn.apply(console, __spreadArray([label + message], extraParams));\n }\n }\n }\n /**\n * Log info messages\n */\n function info(message) {\n var extraParams = [];\n for (var _i = 1; _i < arguments.length; _i++) {\n extraParams[_i - 1] = arguments[_i];\n }\n if (logLevel >= LOG_LEVEL.info && typeof console !== 'undefined') {\n if (typeof console !== 'undefined') {\n console.info.apply(console, __spreadArray([label + message], extraParams));\n }\n }\n }\n return { setLogLevel: setLogLevel, warn: warn, error: error, debug: debug, info: info };\n}\n\n/*\n * Copyright (c) 2021 Snowplow Analytics Ltd, 2010 Anthon Pang\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are met:\n *\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n *\n * 2. Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation\n * and/or other materials provided with the distribution.\n *\n * 3. Neither the name of the copyright holder nor the names of its\n * contributors may be used to endorse or promote products derived from\n * this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * Contains helper functions to aid in the addition and removal of Global Contexts\n */\nfunction globalContexts() {\n var globalPrimitives = [];\n var conditionalProviders = [];\n /**\n * Returns all applicable global contexts for a specified event\n * @param event The event to check for applicable global contexts for\n * @returns An array of contexts\n */\n var assembleAllContexts = function (event) {\n var eventSchema = getUsefulSchema(event);\n var eventType = getEventType(event);\n var contexts = [];\n var generatedPrimitives = generatePrimitives(globalPrimitives, event, eventType, eventSchema);\n contexts.push.apply(contexts, generatedPrimitives);\n var generatedConditionals = generateConditionals(conditionalProviders, event, eventType, eventSchema);\n contexts.push.apply(contexts, generatedConditionals);\n return contexts;\n };\n return {\n getGlobalPrimitives: function () {\n return globalPrimitives;\n },\n getConditionalProviders: function () {\n return conditionalProviders;\n },\n addGlobalContexts: function (contexts) {\n var acceptedConditionalContexts = [];\n var acceptedContextPrimitives = [];\n for (var _i = 0, contexts_1 = contexts; _i < contexts_1.length; _i++) {\n var context = contexts_1[_i];\n if (isConditionalContextProvider(context)) {\n acceptedConditionalContexts.push(context);\n }\n else if (isContextPrimitive(context)) {\n acceptedContextPrimitives.push(context);\n }\n }\n globalPrimitives = globalPrimitives.concat(acceptedContextPrimitives);\n conditionalProviders = conditionalProviders.concat(acceptedConditionalContexts);\n },\n clearGlobalContexts: function () {\n conditionalProviders = [];\n globalPrimitives = [];\n },\n removeGlobalContexts: function (contexts) {\n var _loop_1 = function (context) {\n if (isConditionalContextProvider(context)) {\n conditionalProviders = conditionalProviders.filter(function (item) { return JSON.stringify(item) === JSON.stringify(context); });\n }\n else if (isContextPrimitive(context)) {\n globalPrimitives = globalPrimitives.filter(function (item) { return JSON.stringify(item) === JSON.stringify(context); });\n }\n };\n for (var _i = 0, contexts_2 = contexts; _i < contexts_2.length; _i++) {\n var context = contexts_2[_i];\n _loop_1(context);\n }\n },\n getApplicableContexts: function (event) {\n return assembleAllContexts(event);\n }\n };\n}\nfunction pluginContexts(plugins) {\n /**\n * Add common contexts to every event\n *\n * @param array additionalContexts List of user-defined contexts\n * @return userContexts combined with commonContexts\n */\n return {\n addPluginContexts: function (additionalContexts) {\n var combinedContexts = additionalContexts !== null && additionalContexts !== void 0 ? additionalContexts : [];\n plugins.forEach(function (plugin) {\n try {\n if (plugin.contexts) {\n combinedContexts.push.apply(combinedContexts, plugin.contexts());\n }\n }\n catch (ex) {\n LOG.error('Error adding plugin contexts', ex);\n }\n });\n return combinedContexts;\n }\n };\n}\n/**\n * Find dynamic context generating functions and return their results to be merged into the static contexts\n * Combine an array of unchanging contexts with the result of a context-creating function\n *\n * @param dynamicOrStaticContexts Array of custom context Objects or custom context generating functions\n * @param Parameters to pass to dynamic context callbacks\n * @returns An array of Self Describing JSON context\n */\nfunction resolveDynamicContext(dynamicOrStaticContexts) {\n var _a;\n var extraParams = [];\n for (var _i = 1; _i < arguments.length; _i++) {\n extraParams[_i - 1] = arguments[_i];\n }\n return ((_a = dynamicOrStaticContexts === null || dynamicOrStaticContexts === void 0 ? void 0 : dynamicOrStaticContexts.map(function (context) {\n if (typeof context === 'function') {\n try {\n return context.apply(void 0, extraParams);\n }\n catch (e) {\n //TODO: provide warning\n return undefined;\n }\n }\n else {\n return context;\n }\n }).filter(Boolean)) !== null && _a !== void 0 ? _a : []);\n}\n/**\n * Slices a schema into its composite parts. Useful for ruleset filtering.\n * @param input A schema string\n * @returns The vendor, schema name, major, minor and patch information of a schema string\n */\nfunction getSchemaParts(input) {\n var re = new RegExp('^iglu:([a-zA-Z0-9-_.]+)/([a-zA-Z0-9-_]+)/jsonschema/([1-9][0-9]*)-(0|[1-9][0-9]*)-(0|[1-9][0-9]*)$');\n var matches = re.exec(input);\n if (matches !== null)\n return matches.slice(1, 6);\n return undefined;\n}\n/**\n * Validates the vendor section of a schema string contains allowed wildcard values\n * @param parts Array of parts from a schema string\n * @returns Whether the vendor validation parts are a valid combination\n */\nfunction validateVendorParts(parts) {\n if (parts[0] === '*' || parts[1] === '*') {\n return false; // no wildcard in first or second part\n }\n if (parts.slice(2).length > 0) {\n var asterisk = false;\n for (var _i = 0, _a = parts.slice(2); _i < _a.length; _i++) {\n var part = _a[_i];\n if (part === '*')\n // mark when we've found a wildcard\n asterisk = true;\n else if (asterisk)\n // invalid if alpha parts come after wildcard\n return false;\n }\n return true;\n }\n else if (parts.length == 2)\n return true;\n return false;\n}\n/**\n * Validates the vendor part of a schema string is valid for a rule set\n * @param input Vendor part of a schema string\n * @returns Whether the vendor validation string is valid\n */\nfunction validateVendor(input) {\n var parts = input.split('.');\n if (parts && parts.length > 1)\n return validateVendorParts(parts);\n return false;\n}\n/**\n * Checks for validity of input and returns all the sections of a schema string that are used to match rules in a ruleset\n * @param input A Schema string\n * @returns The sections of a schema string that are used to match rules in a ruleset\n */\nfunction getRuleParts(input) {\n var re = new RegExp('^iglu:((?:(?:[a-zA-Z0-9-_]+|\\\\*).)+(?:[a-zA-Z0-9-_]+|\\\\*))/([a-zA-Z0-9-_.]+|\\\\*)/jsonschema/([1-9][0-9]*|\\\\*)-(0|[1-9][0-9]*|\\\\*)-(0|[1-9][0-9]*|\\\\*)$');\n var matches = re.exec(input);\n if (matches !== null && validateVendor(matches[1]))\n return matches.slice(1, 6);\n return undefined;\n}\n/**\n * Ensures the rules specified in a schema string of a ruleset are valid\n * @param input A Schema string\n * @returns if there rule is valid\n */\nfunction isValidRule(input) {\n var ruleParts = getRuleParts(input);\n if (ruleParts) {\n var vendor = ruleParts[0];\n return ruleParts.length === 5 && validateVendor(vendor);\n }\n return false;\n}\n/**\n * Check if a variable is an Array containing only strings\n * @param input The variable to validate\n * @returns True if the input is an array containing only strings\n */\nfunction isStringArray(input) {\n return (Array.isArray(input) &&\n input.every(function (x) {\n return typeof x === 'string';\n }));\n}\n/**\n * Validates whether a rule set is an array of valid ruleset strings\n * @param input The Array of rule set arguments\n * @returns True is the input is an array of valid rules\n */\nfunction isValidRuleSetArg(input) {\n if (isStringArray(input))\n return input.every(function (x) {\n return isValidRule(x);\n });\n else if (typeof input === 'string')\n return isValidRule(input);\n return false;\n}\n/**\n * Check if a variable is a valid, non-empty Self Describing JSON\n * @param input The variable to validate\n * @returns True if a valid Self Describing JSON\n */\nfunction isSelfDescribingJson(input) {\n var sdj = input;\n if (isNonEmptyJson(sdj))\n if ('schema' in sdj && 'data' in sdj)\n return typeof sdj.schema === 'string' && typeof sdj.data === 'object';\n return false;\n}\n/**\n * Validates if the input object contains the expected properties of a ruleset\n * @param input The object containing a rule set\n * @returns True if a valid rule set\n */\nfunction isRuleSet(input) {\n var ruleSet = input;\n var ruleCount = 0;\n if (input != null && typeof input === 'object' && !Array.isArray(input)) {\n if (Object.prototype.hasOwnProperty.call(ruleSet, 'accept')) {\n if (isValidRuleSetArg(ruleSet['accept'])) {\n ruleCount += 1;\n }\n else {\n return false;\n }\n }\n if (Object.prototype.hasOwnProperty.call(ruleSet, 'reject')) {\n if (isValidRuleSetArg(ruleSet['reject'])) {\n ruleCount += 1;\n }\n else {\n return false;\n }\n }\n // if either 'reject' or 'accept' or both exists,\n // we have a valid ruleset\n return ruleCount > 0 && ruleCount <= 2;\n }\n return false;\n}\n/**\n * Validates if the function can be a valid context generator function\n * @param input The function to be validated\n */\nfunction isContextCallbackFunction(input) {\n return typeof input === 'function' && input.length <= 1;\n}\n/**\n * Validates if the function can be a valid context primitive function or self describing json\n * @param input The function or orbject to be validated\n * @returns True if either a Context Generator or Self Describing JSON\n */\nfunction isContextPrimitive(input) {\n return isContextCallbackFunction(input) || isSelfDescribingJson(input);\n}\n/**\n * Validates if an array is a valid shape to be a Filter Provider\n * @param input The Array of Context filter callbacks\n */\nfunction isFilterProvider(input) {\n if (Array.isArray(input)) {\n if (input.length === 2) {\n if (Array.isArray(input[1])) {\n return isContextCallbackFunction(input[0]) && input[1].every(isContextPrimitive);\n }\n return isContextCallbackFunction(input[0]) && isContextPrimitive(input[1]);\n }\n }\n return false;\n}\n/**\n * Validates if an array is a valid shape to be an array of rule sets\n * @param input The Array of Rule Sets\n */\nfunction isRuleSetProvider(input) {\n if (Array.isArray(input) && input.length === 2) {\n if (!isRuleSet(input[0]))\n return false;\n if (Array.isArray(input[1]))\n return input[1].every(isContextPrimitive);\n return isContextPrimitive(input[1]);\n }\n return false;\n}\n/**\n * Checks if an input array is either a filter provider or a rule set provider\n * @param input An array of filter providers or rule set providers\n * @returns Whether the array is a valid {@link ConditionalContextProvider}\n */\nfunction isConditionalContextProvider(input) {\n return isFilterProvider(input) || isRuleSetProvider(input);\n}\n/**\n * Checks if a given schema matches any rules within the provided rule set\n * @param ruleSet The rule set containing rules to match schema against\n * @param schema The schema to be matched against the rule set\n */\nfunction matchSchemaAgainstRuleSet(ruleSet, schema) {\n var rejectCount = 0;\n var acceptCount = 0;\n var acceptRules = ruleSet['accept'];\n if (Array.isArray(acceptRules)) {\n if (ruleSet.accept.some(function (rule) { return matchSchemaAgainstRule(rule, schema); })) {\n acceptCount++;\n }\n }\n else if (typeof acceptRules === 'string') {\n if (matchSchemaAgainstRule(acceptRules, schema)) {\n acceptCount++;\n }\n }\n var rejectRules = ruleSet['reject'];\n if (Array.isArray(rejectRules)) {\n if (ruleSet.reject.some(function (rule) { return matchSchemaAgainstRule(rule, schema); })) {\n rejectCount++;\n }\n }\n else if (typeof rejectRules === 'string') {\n if (matchSchemaAgainstRule(rejectRules, schema)) {\n rejectCount++;\n }\n }\n if (acceptCount > 0 && rejectCount === 0) {\n return true;\n }\n else if (acceptCount === 0 && rejectCount > 0) {\n return false;\n }\n return false;\n}\n/**\n * Checks if a given schema matches a specific rule from a rule set\n * @param rule The rule to match schema against\n * @param schema The schema to be matched against the rule\n */\nfunction matchSchemaAgainstRule(rule, schema) {\n if (!isValidRule(rule))\n return false;\n var ruleParts = getRuleParts(rule);\n var schemaParts = getSchemaParts(schema);\n if (ruleParts && schemaParts) {\n if (!matchVendor(ruleParts[0], schemaParts[0]))\n return false;\n for (var i = 1; i < 5; i++) {\n if (!matchPart(ruleParts[i], schemaParts[i]))\n return false;\n }\n return true; // if it hasn't failed, it passes\n }\n return false;\n}\nfunction matchVendor(rule, vendor) {\n // rule and vendor must have same number of elements\n var vendorParts = vendor.split('.');\n var ruleParts = rule.split('.');\n if (vendorParts && ruleParts) {\n if (vendorParts.length !== ruleParts.length)\n return false;\n for (var i = 0; i < ruleParts.length; i++) {\n if (!matchPart(vendorParts[i], ruleParts[i]))\n return false;\n }\n return true;\n }\n return false;\n}\nfunction matchPart(rule, schema) {\n // parts should be the string nested between slashes in the URI: /example/\n return (rule && schema && rule === '*') || rule === schema;\n}\n// Returns the \"useful\" schema, i.e. what would someone want to use to identify events.\n// For some events this is the 'e' property but for unstructured events, this is the\n// 'schema' from the 'ue_px' field.\nfunction getUsefulSchema(sb) {\n var eventJson = sb.getJson();\n for (var _i = 0, eventJson_1 = eventJson; _i < eventJson_1.length; _i++) {\n var json = eventJson_1[_i];\n if (json.length === 3 && json[0] === 'ue_px' && typeof json[2]['data'] === 'object') {\n var schema = json[2]['data']['schema'];\n if (typeof schema == 'string') {\n return schema;\n }\n }\n }\n return '';\n}\nfunction getEventType(payloadBuilder) {\n var eventType = payloadBuilder.getPayload()['e'];\n return typeof eventType === 'string' ? eventType : '';\n}\nfunction buildGenerator(generator, event, eventType, eventSchema) {\n var contextGeneratorResult = undefined;\n try {\n // try to evaluate context generator\n var args = {\n event: event.getPayload(),\n eventType: eventType,\n eventSchema: eventSchema\n };\n contextGeneratorResult = generator(args);\n // determine if the produced result is a valid SDJ\n if (Array.isArray(contextGeneratorResult) && contextGeneratorResult.every(isSelfDescribingJson)) {\n return contextGeneratorResult;\n }\n else if (isSelfDescribingJson(contextGeneratorResult)) {\n return contextGeneratorResult;\n }\n else {\n return undefined;\n }\n }\n catch (error) {\n contextGeneratorResult = undefined;\n }\n return contextGeneratorResult;\n}\nfunction normalizeToArray(input) {\n if (Array.isArray(input)) {\n return input;\n }\n return Array.of(input);\n}\nfunction generatePrimitives(contextPrimitives, event, eventType, eventSchema) {\n var _a;\n var normalizedInputs = normalizeToArray(contextPrimitives);\n var partialEvaluate = function (primitive) {\n var result = evaluatePrimitive(primitive, event, eventType, eventSchema);\n if (result && result.length !== 0) {\n return result;\n }\n return undefined;\n };\n var generatedContexts = normalizedInputs.map(partialEvaluate);\n return (_a = []).concat.apply(_a, generatedContexts.filter(function (c) { return c != null && c.filter(Boolean); }));\n}\nfunction evaluatePrimitive(contextPrimitive, event, eventType, eventSchema) {\n if (isSelfDescribingJson(contextPrimitive)) {\n return [contextPrimitive];\n }\n else if (isContextCallbackFunction(contextPrimitive)) {\n var generatorOutput = buildGenerator(contextPrimitive, event, eventType, eventSchema);\n if (isSelfDescribingJson(generatorOutput)) {\n return [generatorOutput];\n }\n else if (Array.isArray(generatorOutput)) {\n return generatorOutput;\n }\n }\n return undefined;\n}\nfunction evaluateProvider(provider, event, eventType, eventSchema) {\n if (isFilterProvider(provider)) {\n var filter = provider[0];\n var filterResult = false;\n try {\n var args = {\n event: event.getPayload(),\n eventType: eventType,\n eventSchema: eventSchema\n };\n filterResult = filter(args);\n }\n catch (error) {\n filterResult = false;\n }\n if (filterResult === true) {\n return generatePrimitives(provider[1], event, eventType, eventSchema);\n }\n }\n else if (isRuleSetProvider(provider)) {\n if (matchSchemaAgainstRuleSet(provider[0], eventSchema)) {\n return generatePrimitives(provider[1], event, eventType, eventSchema);\n }\n }\n return [];\n}\nfunction generateConditionals(providers, event, eventType, eventSchema) {\n var _a;\n var normalizedInput = normalizeToArray(providers);\n var partialEvaluate = function (provider) {\n var result = evaluateProvider(provider, event, eventType, eventSchema);\n if (result && result.length !== 0) {\n return result;\n }\n return undefined;\n };\n var generatedContexts = normalizedInput.map(partialEvaluate);\n return (_a = []).concat.apply(_a, generatedContexts.filter(function (c) { return c != null && c.filter(Boolean); }));\n}\n\n/*\n * Copyright (c) 2021 Snowplow Analytics Ltd, 2010 Anthon Pang\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are met:\n *\n * 1. Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n *\n * 2. Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation\n * and/or other materials provided with the distribution.\n *\n * 3. Neither the name of the copyright holder nor the names of its\n * contributors may be used to endorse or promote products derived from\n * this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n/**\n * Transform optional/old-behavior number timestamp into`Timestamp` ADT\n *\n * @param timestamp optional number or timestamp object\n * @returns correct timestamp object\n */\nfunction getTimestamp(timestamp) {\n if (timestamp == null) {\n return { type: 'dtm', value: new Date().getTime() };\n }\n else if (typeof timestamp === 'number') {\n return { type: 'dtm', value: timestamp };\n }\n else if (timestamp.type === 'ttm') {\n // We can return timestamp here, but this is safer fallback\n return { type: 'ttm', value: timestamp.value };\n }\n else {\n return { type: 'dtm', value: timestamp.value || new Date().getTime() };\n }\n}\n/**\n * Create a tracker core object\n *\n * @param base64 Whether to base 64 encode contexts and self describing event JSONs\n * @param corePlugins The core plugins to be processed with each event\n * @param callback Function applied to every payload dictionary object\n * @return Tracker core\n */\nfunction trackerCore(configuration) {\n if (configuratio