From 0291d5b5d1d966cb8ef69f05dd045d850b21ac25 Mon Sep 17 00:00:00 2001 From: Julien Ramboz Date: Fri, 19 Jul 2024 17:23:52 -0700 Subject: [PATCH] chore: fix linting issues --- .eslintignore | 3 +- scripts/alloy.js | 11658 ----------------------------------------- scripts/alloy.min.js | 13 - 3 files changed, 2 insertions(+), 11672 deletions(-) delete mode 100644 scripts/alloy.js delete mode 100644 scripts/alloy.min.js diff --git a/.eslintignore b/.eslintignore index 259ff537..3196e116 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,5 @@ helix-importer-ui -/scripts/alloy*.js +/plugins/* /tools/actions/ +*.min.js diff --git a/scripts/alloy.js b/scripts/alloy.js deleted file mode 100644 index 65279cb0..00000000 --- a/scripts/alloy.js +++ /dev/null @@ -1,11658 +0,0 @@ -/** - * Copyright 2019 Adobe. All rights reserved. - * This file is licensed to you under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy - * of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - * OF ANY KIND, either express or implied. See the License for the specific language - * governing permissions and limitations under the License. - */ - -(function () { - 'use strict'; - - if (document.documentMode && document.documentMode < 11) { - console.warn('The Adobe Experience Cloud Web SDK does not support IE 10 and below.'); - return; - } - - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createInstanceFunction = (function (executeCommand) { - return function (args) { - // Would use destructuring, but destructuring doesn't work on IE - // without polyfilling Symbol. - // https://github.com/babel/babel/issues/7597 - var resolve = args[0]; - var reject = args[1]; - var userProvidedArgs = args[2]; - var commandName = userProvidedArgs[0]; - var options = userProvidedArgs[1]; - executeCommand(commandName, options).then(resolve, reject); - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var CHROME = "Chrome"; - var EDGE$1 = "Edge"; - var EDGE_CHROMIUM = "EdgeChromium"; - var FIREFOX = "Firefox"; - var IE = "IE"; - var SAFARI = "Safari"; - var UNKNOWN = "Unknown"; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Determines whether an array includes a certain value. - * @param {Array} arr Array to search. - * @param {*} item The item for which to search. - * @returns {boolean} - */ - var includes = (function (arr, item) { - return arr.indexOf(item) !== -1; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - // we don't know. We also assume "unknown" browsers support third-party cookies, - // though we don't really know that either. We're making best guesses. - - var browsersSupportingThirdPartyCookie = [CHROME, EDGE$1, EDGE_CHROMIUM, IE, UNKNOWN]; - var areThirdPartyCookiesSupportedByDefault = (function (browser) { - return includes(browsersSupportingThirdPartyCookie, browser); - }); - - /* - object-assign - (c) Sindre Sorhus - @license MIT - */ - /* eslint-disable no-unused-vars */ - - var getOwnPropertySymbols = Object.getOwnPropertySymbols; - var hasOwnProperty$1 = Object.prototype.hasOwnProperty; - var propIsEnumerable = Object.prototype.propertyIsEnumerable; - - function toObject(val) { - if (val === null || val === undefined) { - throw new TypeError('Object.assign cannot be called with null or undefined'); - } - - return Object(val); - } - - function shouldUseNative() { - try { - if (!Object.assign) { - return false; - } // Detect buggy property enumeration order in older V8 versions. - // https://bugs.chromium.org/p/v8/issues/detail?id=4118 - - - var test1 = new String('abc'); // eslint-disable-line no-new-wrappers - - test1[5] = 'de'; - - if (Object.getOwnPropertyNames(test1)[0] === '5') { - return false; - } // https://bugs.chromium.org/p/v8/issues/detail?id=3056 - - - var test2 = {}; - - for (var i = 0; i < 10; i++) { - test2['_' + String.fromCharCode(i)] = i; - } - - var order2 = Object.getOwnPropertyNames(test2).map(function (n) { - return test2[n]; - }); - - if (order2.join('') !== '0123456789') { - return false; - } // https://bugs.chromium.org/p/v8/issues/detail?id=3056 - - - var test3 = {}; - 'abcdefghijklmnopqrst'.split('').forEach(function (letter) { - test3[letter] = letter; - }); - - if (Object.keys(Object.assign({}, test3)).join('') !== 'abcdefghijklmnopqrst') { - return false; - } - - return true; - } catch (err) { - // We don't expect any of the above to throw, but better to be safe. - return false; - } - } - - var objectAssign = shouldUseNative() ? Object.assign : function (target, source) { - var from; - var to = toObject(target); - var symbols; - - for (var s = 1; s < arguments.length; s++) { - from = Object(arguments[s]); - - for (var key in from) { - if (hasOwnProperty$1.call(from, key)) { - to[key] = from[key]; - } - } - - if (getOwnPropertySymbols) { - symbols = getOwnPropertySymbols(from); - - for (var i = 0; i < symbols.length; i++) { - if (propIsEnumerable.call(from, symbols[i])) { - to[symbols[i]] = from[symbols[i]]; - } - } - } - } - - return to; - }; - - var reactorObjectAssign = objectAssign; - - var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; - - function createCommonjsModule(fn, module) { - return module = { exports: {} }, fn(module, module.exports), module.exports; - } - - var js_cookie = createCommonjsModule(function (module, exports) { - - (function (factory) { - var registeredInModuleLoader; - - { - module.exports = factory(); - registeredInModuleLoader = true; - } - - if (!registeredInModuleLoader) { - var OldCookies = window.Cookies; - var api = window.Cookies = factory(); - - api.noConflict = function () { - window.Cookies = OldCookies; - return api; - }; - } - })(function () { - function extend() { - var i = 0; - var result = {}; - - for (; i < arguments.length; i++) { - var attributes = arguments[i]; - - for (var key in attributes) { - result[key] = attributes[key]; - } - } - - return result; - } - - function decode(s) { - return s.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent); - } - - function init(converter) { - function api() {} - - function set(key, value, attributes) { - if (typeof document === 'undefined') { - return; - } - - attributes = extend({ - path: '/' - }, api.defaults, attributes); - - if (typeof attributes.expires === 'number') { - attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e+5); - } // We're using "expires" because "max-age" is not supported by IE - - - attributes.expires = attributes.expires ? attributes.expires.toUTCString() : ''; - - try { - var result = JSON.stringify(value); - - if (/^[\{\[]/.test(result)) { - value = result; - } - } catch (e) {} - - value = converter.write ? converter.write(value, key) : encodeURIComponent(String(value)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent); - key = encodeURIComponent(String(key)).replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent).replace(/[\(\)]/g, escape); - var stringifiedAttributes = ''; - - for (var attributeName in attributes) { - if (!attributes[attributeName]) { - continue; - } - - stringifiedAttributes += '; ' + attributeName; - - if (attributes[attributeName] === true) { - continue; - } // Considers RFC 6265 section 5.2: - // ... - // 3. If the remaining unparsed-attributes contains a %x3B (";") - // character: - // Consume the characters of the unparsed-attributes up to, - // not including, the first %x3B (";") character. - // ... - - - stringifiedAttributes += '=' + attributes[attributeName].split(';')[0]; - } - - return document.cookie = key + '=' + value + stringifiedAttributes; - } - - function get(key, json) { - if (typeof document === 'undefined') { - return; - } - - var jar = {}; // To prevent the for loop in the first place assign an empty array - // in case there are no cookies at all. - - var cookies = document.cookie ? document.cookie.split('; ') : []; - var i = 0; - - for (; i < cookies.length; i++) { - var parts = cookies[i].split('='); - var cookie = parts.slice(1).join('='); - - if (!json && cookie.charAt(0) === '"') { - cookie = cookie.slice(1, -1); - } - - try { - var name = decode(parts[0]); - cookie = (converter.read || converter)(cookie, name) || decode(cookie); - - if (json) { - try { - cookie = JSON.parse(cookie); - } catch (e) {} - } - - jar[name] = cookie; - - if (key === name) { - break; - } - } catch (e) {} - } - - return key ? jar[key] : jar; - } - - api.set = set; - - api.get = function (key) { - return get(key, false - /* read as raw */ - ); - }; - - api.getJSON = function (key) { - return get(key, true - /* read as json */ - ); - }; - - api.remove = function (key, attributes) { - set(key, '', extend(attributes, { - expires: -1 - })); - }; - - api.defaults = {}; - api.withConverter = init; - return api; - } - - return init(function () {}); - }); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var cookieJar = { - get: js_cookie.get, - set: js_cookie.set, - remove: js_cookie.remove, - withConverter: js_cookie.withConverter - }; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Returns true when the value is null. - * @param {*} value - * @returns {boolean} - */ - var isNil = (function (value) { - return value == null; - }); - - function ownKeys(object, enumerableOnly) { - var keys = Object.keys(object); - - if (Object.getOwnPropertySymbols) { - var symbols = Object.getOwnPropertySymbols(object); - enumerableOnly && (symbols = symbols.filter(function (sym) { - return Object.getOwnPropertyDescriptor(object, sym).enumerable; - })), keys.push.apply(keys, symbols); - } - - return keys; - } - - function _objectSpread2(target) { - for (var i = 1; i < arguments.length; i++) { - var source = null != arguments[i] ? arguments[i] : {}; - i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { - _defineProperty(target, key, source[key]); - }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { - Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); - }); - } - - return target; - } - - function _typeof(obj) { - "@babel/helpers - typeof"; - - return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { - return typeof obj; - } : function (obj) { - return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; - }, _typeof(obj); - } - - function _defineProperty(obj, key, value) { - if (key in obj) { - Object.defineProperty(obj, key, { - value: value, - enumerable: true, - configurable: true, - writable: true - }); - } else { - obj[key] = value; - } - - return obj; - } - - function _objectWithoutPropertiesLoose(source, excluded) { - if (source == null) return {}; - var target = {}; - var sourceKeys = Object.keys(source); - var key, i; - - for (i = 0; i < sourceKeys.length; i++) { - key = sourceKeys[i]; - if (excluded.indexOf(key) >= 0) continue; - target[key] = source[key]; - } - - return target; - } - - function _objectWithoutProperties(source, excluded) { - if (source == null) return {}; - - var target = _objectWithoutPropertiesLoose(source, excluded); - - var key, i; - - if (Object.getOwnPropertySymbols) { - var sourceSymbolKeys = Object.getOwnPropertySymbols(source); - - for (i = 0; i < sourceSymbolKeys.length; i++) { - key = sourceSymbolKeys[i]; - if (excluded.indexOf(key) >= 0) continue; - if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; - target[key] = source[key]; - } - } - - return target; - } - - function _slicedToArray(arr, i) { - return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); - } - - function _toConsumableArray(arr) { - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); - } - - function _arrayWithoutHoles(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); - } - - function _arrayWithHoles(arr) { - if (Array.isArray(arr)) return arr; - } - - function _iterableToArray(iter) { - if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); - } - - function _iterableToArrayLimit(arr, i) { - var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; - - if (_i == null) return; - var _arr = []; - var _n = true; - var _d = false; - - var _s, _e; - - try { - for (_i = _i.call(arr); !(_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"] != null) _i["return"](); - } finally { - if (_d) throw _e; - } - } - - return _arr; - } - - function _unsupportedIterableToArray(o, minLen) { - if (!o) return; - if (typeof o === "string") return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if (n === "Object" && o.constructor) n = o.constructor.name; - if (n === "Map" || n === "Set") return Array.from(o); - if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } - - function _arrayLikeToArray(arr, len) { - if (len == null || len > arr.length) len = arr.length; - - for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; - - return arr2; - } - - function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); - } - - function _nonIterableRest() { - throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); - } - - /** - * Returns whether the value is an object. - * @param {*} value - * @returns {boolean} - */ - - var isObject = (function (value) { - return !isNil(value) && !Array.isArray(value) && _typeof(value) === "object"; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var deepAssignObject = function deepAssignObject(target, source) { - Object.keys(source).forEach(function (key) { - if (isObject(target[key]) && isObject(source[key])) { - deepAssignObject(target[key], source[key]); - return; - } - - target[key] = source[key]; - }); - }; - /** - * Recursively copy the values of all enumerable own properties from a source item to a target item if the both items are objects - * @param {Object} target - a target object - * @param {...Object} source - an array of source objects - * @example - * deepAssign({ a: 'a', b: 'b' }, { b: 'B', c: 'c' }); - * // { a: 'a', b: 'B', c: 'c' } - */ - - - var deepAssign = (function (target) { - if (isNil(target)) { - throw new TypeError('deepAssign "target" cannot be null or undefined'); - } - - var result = Object(target); - - for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - sources[_key - 1] = arguments[_key]; - } - - sources.forEach(function (source) { - return deepAssignObject(result, Object(source)); - }); - return result; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - /** - * Creates a function that, when passed an object of updates, will merge - * the updates onto the current value of a payload property. - * @param {Object} content The base object to modify - * @param {String } key The property to merge updates into. This - * can be a dot-notation property path. - * @returns {Function} - */ - - var createMerger = (function (content, key) { - return function (updates) { - var propertyPath = key.split("."); - var hostObjectForUpdates = propertyPath.reduce(function (obj, propertyName) { - obj[propertyName] = obj[propertyName] || {}; - return obj[propertyName]; - }, content); - deepAssign(hostObjectForUpdates, updates); - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Allows callbacks to be registered and then later called. When the - * callbacks are called, their responses are combined into a single promise. - */ - var createCallbackAggregator = (function () { - var callbacks = []; - return { - add: function add(callback) { - callbacks.push(callback); - }, - call: function call() { - for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - // While this utility doesn't necessarily need to be doing the - // Promise.all, it's currently useful everywhere this is used and - // reduces repetitive code. We can factor it out later if we want - // to make this utility more "pure". - return Promise.all(callbacks.map(function (callback) { - return callback.apply(void 0, args); - })); - } - }; - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createLoggingCookieJar = (function (_ref) { - var logger = _ref.logger, - cookieJar = _ref.cookieJar; - return _objectSpread2(_objectSpread2({}, cookieJar), {}, { - set: function set(key, value, options) { - logger.info("Setting cookie", _objectSpread2({ - name: key, - value: value - }, options)); - cookieJar.set(key, value, options); - } - }); - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Sequences tasks. - */ - var createTaskQueue = (function () { - var queueLength = 0; - var lastPromiseInQueue = Promise.resolve(); - return { - /** - * Add a task to the queue. If no task is currenty running, - * the task will begin immediately. - * @param {Function} task A function that will be called when - * the task should be run. If the task it asynchronous, it should - * return a promise. - * @returns {Promise} A promise that will be resolved or rejected - * with whatever value the task resolved or rejects its promise. - */ - addTask: function addTask(task) { - queueLength += 1; - - var lastPromiseFulfilledHandler = function lastPromiseFulfilledHandler() { - return task().finally(function () { - queueLength -= 1; - }); - }; - - lastPromiseInQueue = lastPromiseInQueue.then(lastPromiseFulfilledHandler, lastPromiseFulfilledHandler); - return lastPromiseInQueue; - }, - - /** - * How many tasks are in the queue. This includes the task - * that's currently running. - * @returns {number} - */ - get length() { - return queueLength; - } - - }; - }); - - /* eslint-disable */ - - /* - crc32 · JavaScript Function to Calculate CRC32 of a String - Description - Below is a JavaScript function to calculate CRC32 of a string. - The string can be either ASCII or Unicode. - Unicode strings will be encoded in UTF-8. - The polynomial used in calculation is 0xedb88320. - This polynomial is used in Ethernet, Gzip, PNG, SATA and many other technologies. - */ - var crc32 = function () { - var table = []; - - for (var i = 0; i < 256; i++) { - var c = i; - - for (var j = 0; j < 8; j++) { - c = c & 1 ? 0xedb88320 ^ c >>> 1 : c >>> 1; - } - - table.push(c); - } - - return function (str, crc) { - str = unescape(encodeURIComponent(str)); - if (!crc) crc = 0; - crc = crc ^ -1; - - for (var _i = 0; _i < str.length; _i++) { - var y = (crc ^ str.charCodeAt(_i)) & 0xff; - crc = crc >>> 8 ^ table[y]; - } - - crc = crc ^ -1; - return crc >>> 0; - }; - }(); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * A simple utility for managing a promise's state outside of - * the promise's "executor" (the function passed into the constructor). - */ - var defer = (function () { - var deferred = {}; - deferred.promise = new Promise(function (resolve, reject) { - deferred.resolve = resolve; - deferred.reject = reject; - }); - return deferred; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Whether a string ends with the characters of a specified string - * @param {String} str The string to search within. - * @param {String} suffix The string to search for. - * @returns {boolean} - */ - var endsWith = (function (str, suffix) { - return str.substr(-suffix.length) === suffix; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Returns the first item in the array that satisfies the provided testing function. - * @param {Array} arr The array to search. - * @param {Function} predicate Function that will be called for each item. Arguments - * will be the item, the item index, then the array itself. - * @returns {*} - */ - var find = (function (arr, predicate) { - for (var i = 0; i < arr.length; i += 1) { - var item = arr[i]; - - if (predicate(item, i, arr)) { - return item; - } - } - - return undefined; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var appendNode = (function (parent, node) { - return parent.appendChild(node); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var populateElementProperties = function populateElementProperties(element, props) { - Object.keys(props).forEach(function (key) { - // The following is to support setting style properties to avoid CSP errors. - if (key === "style" && isObject(props[key])) { - var styleProps = props[key]; - Object.keys(styleProps).forEach(function (styleKey) { - element.style[styleKey] = styleProps[styleKey]; - }); - } else { - element[key] = props[key]; - } - }); - }; - - var createNode = (function (tag) { - var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - var children = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : []; - var doc = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : document; - var result = doc.createElement(tag); - Object.keys(attrs).forEach(function (key) { - // TODO: To highlight CSP problems consider throwing a descriptive error - // if nonce is available and key is style. - result.setAttribute(key, attrs[key]); - }); - populateElementProperties(result, props); - children.forEach(function (child) { - return appendNode(result, child); - }); - return result; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var BODY = "BODY"; - var IFRAME = "IFRAME"; - var IMG = "IMG"; - var DIV = "DIV"; - var STYLE = "STYLE"; - var SCRIPT = "SCRIPT"; - var HEAD = "HEAD"; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - /** - * Fires an image pixel from the current document's window. - * @param {object} currentDocument - * @param {string} src - * @returns {Promise} - */ - - var fireImageInDocument = (function (_ref) { - var src = _ref.src, - _ref$currentDocument = _ref.currentDocument, - currentDocument = _ref$currentDocument === void 0 ? document : _ref$currentDocument; - return new Promise(function (resolve, reject) { - var attrs = { - src: src - }; - var props = { - onload: resolve, - onerror: reject, - onabort: reject - }; - createNode(IMG, attrs, props, [], currentDocument); - }); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Returns whether the value is a function. - * @param {*} value - * @returns {boolean} - */ - var isFunction = (function (value) { - return typeof value === "function"; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Returns whether the value is a non-empty array. - * @param {*} value - * @returns {boolean} - */ - var isNonEmptyArray = (function (value) { - return Array.isArray(value) && value.length > 0; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var toArray = (function (value) { - if (Array.isArray(value)) { - return value; - } - - if (value == null) { - return []; - } - - return [].slice.call(value); - }); - - /* - Copyright 2021 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var SIBLING_PATTERN = /^\s*>/; - var querySelectorAll = (function (context, selector) { - if (!SIBLING_PATTERN.test(selector)) { - return toArray(context.querySelectorAll(selector)); - } - - var tag = "alloy-" + Date.now(); // We could use a :scope selector here, but we want to be IE compliant - // so we add a dummy css class to be able to select the children - - try { - context.classList.add(tag); - return toArray(context.querySelectorAll("." + tag + " " + selector)); - } finally { - context.classList.remove(tag); - } - }); - - /* - Copyright 2021 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Whether a string starts with the characters of a specified string - * @param {String} str The string to search within. - * @param {String} prefix The string to search for. - * @returns {boolean} - */ - var startsWith = (function (str, prefix) { - return str.substr(0, prefix.length) === prefix; - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var SHADOW_SEPARATOR = ":shadow"; - - /* - Copyright 2021 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var splitWithShadow = function splitWithShadow(selector) { - return selector.split(SHADOW_SEPARATOR); - }; - - var transformPrefix = function transformPrefix(parent, selector) { - var result = selector.trim(); - var hasChildCombinatorPrefix = startsWith(result, ">"); - - if (!hasChildCombinatorPrefix) { - return result; - } // IE doesn't support :scope - - - if (window.document.documentMode) { - return result.substring(1).trim(); - } - - var prefix = parent instanceof Element || parent instanceof HTMLDocument ? ":scope" : ":host"; // see https://bugs.webkit.org/show_bug.cgi?id=233380 - - return prefix + " " + result; - }; - - var selectNodesWithShadow = (function (context, selector) { - // Shadow DOM should be supported - if (!window.document.documentElement.attachShadow) { - return querySelectorAll(context, selector.replace(SHADOW_SEPARATOR, "")); - } - - var parts = splitWithShadow(selector); - - if (parts.length < 2) { - return querySelectorAll(context, selector); - } // split the selector into parts separated by :shadow pseudo-selectors - // find each subselector element based on the previously selected node's shadowRoot - - - var parent = context; - - for (var i = 0; i < parts.length; i += 1) { - var part = transformPrefix(parent, parts[i]); - var partNode = querySelectorAll(parent, part); - - if (partNode.length === 0 || !partNode[0] || !partNode[0].shadowRoot) { - return partNode; - } - - parent = partNode[0].shadowRoot; - } - - return undefined; - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var isShadowSelector = (function (str) { - return str.indexOf(SHADOW_SEPARATOR) !== -1; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - /** - * Returns an array of matched DOM nodes. - * @param {String} selector - * @param {Node} [context=document] defaults to document - * @returns {Array} an array of DOM nodes - */ - - var selectNodes = (function (selector) { - var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document; - - if (!isShadowSelector(selector)) { - return querySelectorAll(context, selector); - } - - return selectNodesWithShadow(context, selector); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var MUTATION_OBSERVER = "MutationObserver"; - var RAF = "requestAnimationFrame"; - var MUTATION_OBSERVER_CONFIG = { - childList: true, - subtree: true - }; - var VISIBILITY_STATE = "visibilityState"; - var VISIBLE = "visible"; - var DELAY = 100; - var MAX_POLLING_TIMEOUT = 5000; - - var createError = function createError(selector) { - return new Error("Could not find: " + selector); - }; - - var createPromise = function createPromise(executor) { - return new Promise(executor); - }; - - var canUseMutationObserver = function canUseMutationObserver(win) { - return isFunction(win[MUTATION_OBSERVER]); - }; - var awaitUsingMutationObserver = function awaitUsingMutationObserver(win, doc, selector, timeout, selectFunc) { - return createPromise(function (resolve, reject) { - var mutationObserver = new win[MUTATION_OBSERVER](function () { - var nodes = selectFunc(selector); - - if (isNonEmptyArray(nodes)) { - mutationObserver.disconnect(); - resolve(nodes); - } - }); - setTimeout(function () { - mutationObserver.disconnect(); - reject(createError(selector)); - }, timeout); - mutationObserver.observe(doc, MUTATION_OBSERVER_CONFIG); - }); - }; - var canUseRequestAnimationFrame = function canUseRequestAnimationFrame(doc) { - return doc[VISIBILITY_STATE] === VISIBLE; - }; - var awaitUsingRequestAnimation = function awaitUsingRequestAnimation(win, selector, timeout, selectFunc) { - return createPromise(function (resolve, reject) { - var execute = function execute() { - var nodes = selectFunc(selector); - - if (isNonEmptyArray(nodes)) { - resolve(nodes); - return; - } - - win[RAF](execute); - }; - - execute(); - setTimeout(function () { - reject(createError(selector)); - }, timeout); - }); - }; - var awaitUsingTimer = function awaitUsingTimer(selector, timeout, selectFunc) { - return createPromise(function (resolve, reject) { - var execute = function execute() { - var nodes = selectFunc(selector); - - if (isNonEmptyArray(nodes)) { - resolve(nodes); - return; - } - - setTimeout(execute, DELAY); - }; - - execute(); - setTimeout(function () { - reject(createError(selector)); - }, timeout); - }); - }; - var awaitSelector = (function (selector) { - var selectFunc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : selectNodes; - var timeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : MAX_POLLING_TIMEOUT; - var win = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : window; - var doc = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : document; - var nodes = selectFunc(selector); - - if (isNonEmptyArray(nodes)) { - return Promise.resolve(nodes); - } - - if (canUseMutationObserver(win)) { - return awaitUsingMutationObserver(win, doc, selector, timeout, selectFunc); - } - - if (canUseRequestAnimationFrame(doc)) { - return awaitUsingRequestAnimation(win, selector, timeout, selectFunc); - } - - return awaitUsingTimer(selector, timeout, selectFunc); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Returns true if element matches the selector. - * @param {String} selector - * @param {Node} [element] - * @returns {Boolean} - */ - var matchesSelector = (function (selector, element) { - if (element.matches) { - return element.matches(selector); - } // Making IE 11 happy - - - return element.msMatchesSelector(selector); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var removeNode = (function (node) { - var parent = node.parentNode; - - if (parent) { - return parent.removeChild(node); - } - - return null; - }); - - var IFRAME_ATTRS = { - name: "Adobe Alloy" - }; - var IFRAME_PROPS = { - style: { - display: "none", - width: 0, - height: 0 - } - }; - var injectFireReferrerHideableImage = (function () { - var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, - _ref$appendNode = _ref.appendNode, - appendNode$1 = _ref$appendNode === void 0 ? appendNode : _ref$appendNode, - _ref$awaitSelector = _ref.awaitSelector, - awaitSelector$1 = _ref$awaitSelector === void 0 ? awaitSelector : _ref$awaitSelector, - _ref$createNode = _ref.createNode, - createNode$1 = _ref$createNode === void 0 ? createNode : _ref$createNode, - _ref$fireImage = _ref.fireImage, - fireImage = _ref$fireImage === void 0 ? fireImageInDocument : _ref$fireImage; - - var fireOnPage = fireImage; - var hiddenIframe; - - var createIframe = function createIframe() { - return awaitSelector$1(BODY).then(function (_ref2) { - var _ref3 = _slicedToArray(_ref2, 1), - body = _ref3[0]; - - if (hiddenIframe) { - return hiddenIframe; - } - - hiddenIframe = createNode$1(IFRAME, IFRAME_ATTRS, IFRAME_PROPS); - return appendNode$1(body, hiddenIframe); - }); - }; - - var fireInIframe = function fireInIframe(_ref4) { - var src = _ref4.src; - return createIframe().then(function (iframe) { - var currentDocument = iframe.contentWindow.document; - return fireImage({ - src: src, - currentDocument: currentDocument - }); - }); - }; - - return function (request) { - var hideReferrer = request.hideReferrer, - url = request.url; - return hideReferrer ? fireInIframe({ - src: url - }) : fireOnPage({ - src: url - }); - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - /** - * Returns whether the value is an empty object. - * @param {*} value - * @returns {boolean} - */ - - var isEmptyObject = (function (value) { - return isObject(value) && Object.keys(value).length === 0; - }); - - /** - * Given an object and a function that takes a value and returns a predicate, filter out - * all non-object deeply nested values that do not pass the predicate. - * - * Example: filterObject({ a: 2, b: { c: 6 } }, (val) => val > 5) returns { b { c: 6 } } - * - * @param {*} obj - * @param {* => boolean} predicate a function that takes a value and return a boolean, - * representing if it should be included in the result object or not. - * @returns A copy of the original object with the values that fail the predicate, filtered out. - */ - - var filterObject = function filterObject(obj, predicate) { - if (isNil(obj) || !isObject(obj)) { - return obj; - } - - return Object.keys(obj).reduce(function (result, key) { - var value = obj[key]; - - if (isObject(value)) { - // value is object, go deeper - var filteredValue = filterObject(value, predicate); - - if (isEmptyObject(filteredValue)) { - return result; - } - - return _objectSpread2(_objectSpread2({}, result), {}, _defineProperty({}, key, filteredValue)); - } // value is not an object, test predicate - - - if (predicate(value)) { - return _objectSpread2(_objectSpread2({}, result), {}, _defineProperty({}, key, value)); - } - - return result; - }, {}); - }; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var flatMap = (function (array, mapFunction) { - return Array.prototype.concat.apply([], array.map(mapFunction)); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var baseNamespace = "com.adobe.alloy."; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Returns the last N number of items from an array. - * @param {Array} arr - * @param {number} itemCount - * @returns {Array} - */ - var getLastArrayItems = (function (arr, itemCount) { - return arr.slice(-itemCount); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var cookieName = baseNamespace + "getTld"; - /** - * Of the current web page's hostname, this is the top-most domain that is - * not a "public suffix" as outlined in https://publicsuffix.org/. In other - * words, this is top-most domain that is able to accept cookies. - * @param {Object} window - * @param {Object} cookieJar - * @returns {string} - */ - - var getApexDomain = (function (window, cookieJar) { - var topLevelCookieDomain = ""; // If hostParts.length === 1, we may be on localhost. - - var hostParts = window.location.hostname.toLowerCase().split("."); - var i = 1; - - while (i < hostParts.length && !cookieJar.get(cookieName)) { - i += 1; - topLevelCookieDomain = getLastArrayItems(hostParts, i).join("."); - cookieJar.set(cookieName, cookieName, { - domain: topLevelCookieDomain - }); - } - - cookieJar.remove(cookieName, { - domain: topLevelCookieDomain - }); - return topLevelCookieDomain; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - // Remember to also incorporate the org ID wherever cookies are read or written. - var COOKIE_NAME_PREFIX = "kndctr"; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var sanitizeOrgIdForCookieName = (function (orgId) { - return orgId.replace("@", "_"); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var getNamespacedCookieName = (function (orgId, key) { - return COOKIE_NAME_PREFIX + "_" + sanitizeOrgIdForCookieName(orgId) + "_" + key; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var IDENTITY = "identity"; - var CONSENT = "consent"; - var CLUSTER = "cluster"; - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectDoesIdentityCookieExist = (function (_ref) { - var orgId = _ref.orgId; - var identityCookieName = getNamespacedCookieName(orgId, IDENTITY); - /** - * Returns whether the identity cookie exists. - */ - - return function () { - return Boolean(cookieJar.get(identityCookieName)); - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var getStorageByType = function getStorageByType(context, storageType, namespace) { - // When storage is disabled on Safari, the mere act of referencing - // window.localStorage or window.sessionStorage throws an error. - // For this reason, we wrap in a try-catch. - return { - /** - * Reads a value from storage. - * @param {string} name The name of the item to be read. - * @returns {string} - */ - getItem: function getItem(name) { - try { - return context[storageType].getItem(namespace + name); - } catch (e) { - return null; - } - }, - - /** - * Saves a value to storage. - * @param {string} name The name of the item to be saved. - * @param {string} value The value of the item to be saved. - * @returns {boolean} Whether the item was successfully saved to storage. - */ - setItem: function setItem(name, value) { - try { - context[storageType].setItem(namespace + name, value); - return true; - } catch (e) { - return false; - } - }, - - /** - * Clear all values in storage that match the namespace. - */ - clear: function clear() { - try { - Object.keys(context[storageType]).forEach(function (key) { - if (startsWith(key, namespace)) { - context[storageType].removeItem(key); - } - }); - return true; - } catch (e) { - return false; - } - } - }; - }; - - var injectStorage = (function (context) { - return function (additionalNamespace) { - var finalNamespace = baseNamespace + additionalNamespace; - return { - session: getStorageByType(context, "sessionStorage", finalNamespace), - persistent: getStorageByType(context, "localStorage", finalNamespace) - }; - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - /** - * Returns items that are found within both arrays. - * @param {Array} a - * @param {Array} b - * @returns {Array} - */ - - var intersection = (function (a, b) { - return a.filter(function (x) { - return includes(b, x); - }); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Returns whether the value is a boolean. - * @param {*} value - * @returns {boolean} - */ - var isBoolean = (function (value) { - return typeof value === "boolean"; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Returns whether the value is a number. - * @param {*} value - * @returns {boolean} - */ - // eslint-disable-next-line no-restricted-globals - var isNumber = (function (value) { - return typeof value === "number" && !isNaN(value); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - /** - * Returns whether the value is an integer. - * @param {*} value - * @returns {boolean} - */ - - var isInteger = (function (value) { - var parsed = parseInt(value, 10); - return isNumber(parsed) && value === parsed; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - /** - * Determines whether a cookie name is namespaced according to the contract - * defined by the server. - * @param {String} orgId The org ID configured for the Alloy instance. - * @param {String} name The cookie name. - * @returns {boolean} - */ - - var isNamespacedCookieName = (function (orgId, name) { - return name.indexOf(COOKIE_NAME_PREFIX + "_" + sanitizeOrgIdForCookieName(orgId) + "_") === 0; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Returns whether the value is a string. - * @param {*} value - * @returns {boolean} - */ - var isString = (function (value) { - return typeof value === "string"; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - /** - * Returns whether the value is a populated string. - * @param {*} value - * @returns {boolean} - */ - - var isNonEmptyString = (function (value) { - return isString(value) && value.length > 0; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Creates a function that memoizes the result of `fn`. If `keyResolver` is - * provided, it determines the cache key for storing the result based on the - * arguments provided to the memoized function. By default, the first argument - * provided to the memoized function is used as the map cache key. - * - * @param {Function} fn The function to have its output memoized. - * @param {Function} [keyResolver] The function to resolve the cache key. - * @returns {Function} The new memoized function. - */ - var memoize = (function (fn, keyResolver) { - var map = new Map(); - return function () { - var key = keyResolver ? keyResolver.apply(void 0, arguments) : arguments.length <= 0 ? undefined : arguments[0]; - - if (map.has(key)) { - return map.get(key); - } - - var result = fn.apply(void 0, arguments); - map.set(key, result); - return result; - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * A function that performs no operations. - */ - var noop$1 = (function () {}); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - // adapted from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart - var padStart = (function (string, targetLength, padString) { - var originalString = String(string); - var repeatedPadString = String(padString); - - if (originalString.length >= targetLength || repeatedPadString.length === 0) { - return originalString; - } - - var lengthToAdd = targetLength - originalString.length; - - while (lengthToAdd > repeatedPadString.length) { - repeatedPadString += repeatedPadString; - } - - return repeatedPadString.slice(0, lengthToAdd) + originalString; - }); - - // to be able to add overrides in the future without us needing to make - // any changes to the Web SDK - - var prepareConfigOverridesForEdge = (function (configuration) { - if (isNil(configuration) || _typeof(configuration) !== "object") { - return null; - } // remove entries that are empty strings or arrays - - - var configOverrides = filterObject(configuration, function (value) { - if (isNil(value)) { - return false; - } - - if (isBoolean(value)) { - return true; - } - - if (isNumber(value)) { - return true; - } - - if (isNonEmptyString(value)) { - return true; - } - - if (isNonEmptyArray(value)) { - return true; - } - - return false; - }); - - if (isEmptyObject(configOverrides)) { - return null; - } - - return configOverrides; - }); - - // Copyright Joyent, Inc. and other Node contributors. - // obj.hasOwnProperty(prop) will break. - // See: https://github.com/joyent/node/issues/1707 - - function hasOwnProperty(obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); - } - - var decode = function decode(qs, sep, eq, options) { - sep = sep || '&'; - eq = eq || '='; - var obj = {}; - - if (typeof qs !== 'string' || qs.length === 0) { - return obj; - } - - var regexp = /\+/g; - qs = qs.split(sep); - var maxKeys = 1000; - - if (options && typeof options.maxKeys === 'number') { - maxKeys = options.maxKeys; - } - - var len = qs.length; // maxKeys <= 0 means that we should not limit keys count - - if (maxKeys > 0 && len > maxKeys) { - len = maxKeys; - } - - for (var i = 0; i < len; ++i) { - var x = qs[i].replace(regexp, '%20'), - idx = x.indexOf(eq), - kstr, - vstr, - k, - v; - - if (idx >= 0) { - kstr = x.substr(0, idx); - vstr = x.substr(idx + 1); - } else { - kstr = x; - vstr = ''; - } - - k = decodeURIComponent(kstr); - v = decodeURIComponent(vstr); - - if (!hasOwnProperty(obj, k)) { - obj[k] = v; - } else if (Array.isArray(obj[k])) { - obj[k].push(v); - } else { - obj[k] = [obj[k], v]; - } - } - - return obj; - }; - - // Copyright Joyent, Inc. and other Node contributors. - - var stringifyPrimitive = function stringifyPrimitive(v) { - switch (_typeof(v)) { - case 'string': - return v; - - case 'boolean': - return v ? 'true' : 'false'; - - case 'number': - return isFinite(v) ? v : ''; - - default: - return ''; - } - }; - - var encode = function encode(obj, sep, eq, name) { - sep = sep || '&'; - eq = eq || '='; - - if (obj === null) { - obj = undefined; - } - - if (_typeof(obj) === 'object') { - return Object.keys(obj).map(function (k) { - var ks = encodeURIComponent(stringifyPrimitive(k)) + eq; - - if (Array.isArray(obj[k])) { - return obj[k].map(function (v) { - return ks + encodeURIComponent(stringifyPrimitive(v)); - }).join(sep); - } else { - return ks + encodeURIComponent(stringifyPrimitive(obj[k])); - } - }).join(sep); - } - - if (!name) return ''; - return encodeURIComponent(stringifyPrimitive(name)) + eq + encodeURIComponent(stringifyPrimitive(obj)); - }; - - var querystring = createCommonjsModule(function (module, exports) { - - exports.decode = exports.parse = decode; - exports.encode = exports.stringify = encode; - }); - querystring.decode; - querystring.parse; - querystring.encode; - querystring.stringify; - - // This allows us to more easily make changes to the underlying implementation later without - // having to worry about breaking extensions. If extensions demand additional functionality, we - // can make adjustments as needed. - - - var reactorQueryString = { - parse: function parse(string) { - // - if (typeof string === 'string') { - // Remove leading ?, #, & for some leniency so you can pass in location.search or - // location.hash directly. - string = string.trim().replace(/^[?#&]/, ''); - } - - return querystring.parse(string); - }, - stringify: function stringify(object) { - return querystring.stringify(object); - } - }; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Creates and returns a new error using the provided value as a message. - * If the provided value is already an Error, it will be returned unmodified. - * @param {*} value - * @returns {Error} - */ - var toError = (function (value) { - return value instanceof Error ? value : new Error(value); - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var updateErrorMessage = (function (_ref) { - var error = _ref.error, - message = _ref.message; - - try { - error.message = message; - } catch (e) {// We'll set a new message when we can, but some errors, like DOMException, - // have a read-only message property, which limits our options. - } - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - /** - * Augments an error's message with additional context as it bubbles up the call stack. - * @param {String} message The message to be added to the error. - * @param {*} error Optimally, this is an instance of Error. If it is not, - * this is used as the basis for the message of a newly created Error instance. - * @returns {*} - */ - - var stackError = (function (_ref) { - var error = _ref.error, - message = _ref.message; - var errorToStack = toError(error); - var newMessage = message + "\nCaused by: " + errorToStack.message; - updateErrorMessage({ - error: errorToStack, - message: newMessage - }); - return errorToStack; - }); - - /* - Copyright 2023 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var stringToBoolean = (function (str) { - return isString(str) && str.toLowerCase() === "true"; - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - /* - * coerce `value` to a number or return `defaultValue` if it cannot be. - * - * The coersion is attempted if value is a number or string. - */ - - var toInteger = (function (value, defaultValue) { - if (isNumber(value) || isString(value)) { - var n = Math.round(Number(value)); // eslint-disable-next-line no-restricted-globals - - if (!isNaN(n)) { - return n; - } - } - - return defaultValue; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - /** - * Formats the date into an ISO date-time string in the local timezone - * @param {Date} date - * @returns {string} - */ - - var toISOStringLocal = (function (date) { - var YYYY = date.getFullYear(); - var MM = padStart(date.getMonth() + 1, 2, "0"); - var DD = padStart(date.getDate(), 2, "0"); - var hh = padStart(date.getHours(), 2, "0"); - var mm = padStart(date.getMinutes(), 2, "0"); - var ss = padStart(date.getSeconds(), 2, "0"); - var mmm = padStart(date.getMilliseconds(), 3, "0"); // The time-zone offset is the difference, in minutes, from local time to UTC. Note that this - // means that the offset is positive if the local timezone is behind UTC and negative if it is - // ahead. For example, for time zone UTC+10:00, -600 will be returned. - - var timezoneOffset = toInteger(date.getTimezoneOffset(), 0); - var ts = timezoneOffset > 0 ? "-" : "+"; - var th = padStart(Math.floor(Math.abs(timezoneOffset) / 60), 2, "0"); - var tm = padStart(Math.abs(timezoneOffset) % 60, 2, "0"); - return YYYY + "-" + MM + "-" + DD + "T" + hh + ":" + mm + ":" + ss + "." + mmm + ts + th + ":" + tm; - }); - - var rngBrowser = createCommonjsModule(function (module) { - // Unique ID creation requires a high quality random # generator. In the - // browser this is a little complicated due to unknown quality of Math.random() - // and inconsistent support for the `crypto` API. We do the best we can via - // feature-detection - // getRandomValues needs to be invoked in a context where "this" is a Crypto - // implementation. Also, find the complete implementation of crypto on IE11. - var getRandomValues = typeof crypto != 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto != 'undefined' && typeof window.msCrypto.getRandomValues == 'function' && msCrypto.getRandomValues.bind(msCrypto); - - if (getRandomValues) { - // WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto - var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef - - module.exports = function whatwgRNG() { - getRandomValues(rnds8); - return rnds8; - }; - } else { - // Math.random()-based (RNG) - // - // If all else fails, use Math.random(). It's fast, but is of unspecified - // quality. - var rnds = new Array(16); - - module.exports = function mathRNG() { - for (var i = 0, r; i < 16; i++) { - if ((i & 0x03) === 0) r = Math.random() * 0x100000000; - rnds[i] = r >>> ((i & 0x03) << 3) & 0xff; - } - - return rnds; - }; - } - }); - - /** - * Convert array of 16 byte values to UUID string format of the form: - * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX - */ - var byteToHex = []; - - for (var i = 0; i < 256; ++i) { - byteToHex[i] = (i + 0x100).toString(16).substr(1); - } - - function bytesToUuid(buf, offset) { - var i = offset || 0; - var bth = byteToHex; // join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4 - - return [bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]]].join(''); - } - - var bytesToUuid_1 = bytesToUuid; - - function v4(options, buf, offset) { - var i = buf && offset || 0; - - if (typeof options == 'string') { - buf = options === 'binary' ? new Array(16) : null; - options = null; - } - - options = options || {}; - var rnds = options.random || (options.rng || rngBrowser)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved` - - rnds[6] = rnds[6] & 0x0f | 0x40; - rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided - - if (buf) { - for (var ii = 0; ii < 16; ++ii) { - buf[i + ii] = rnds[ii]; - } - } - - return buf || bytesToUuid_1(rnds); - } - - var v4_1 = v4; - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - /** - * Chains two validators together. - * - * Validators are functions of two parameters (value and path) that return the computed value if - * the input is valid, or throw an exception if the input is invalid. In most cases the returned - * value is the same as the input value; however, reference createDefaultValidator.js - * to see an example where the computed value is different from the input. Additionally, if we ever - * wanted to coerce types (i.e. parse string values into integers) as part of the validation process - * we could use the computed value to accomplish that. - * - * The path parameter is used to generate informative error messages. It is created by the objectOf, and - * arrayOf validators so that any error message can describe which key within the object or array is - * invalid. - * - * The validators also have methods to chain additional validation logic. For example, when you call - * `string()` to start a validator chain, it returns a validator function but it also has methods - * like `required` and `nonEmpty`. In index.js you can see that these methods are actually calling `chain`. - * Specifically in this function, the leftValidator is called first and then the return value of that is - * sent to the rightValidator. For example, when calling `string().nonEmpty().required()` the following - * chain is built up: - * ``` - * * - * / \ - * * required - * / \ - * * nonEmpty - * / \ - * base string - * ``` - * Where every * is a call to chain where the two are combined. The individual validators are called from - * left to right in the above tree. The base validator is simply the identity function `value => value`, - * representing an optional value. - * - * After combining the validators, the new validator function is then augmented with the methods from the - * leftValidator and from the additionalMethods parameter. For example, when the string() function is called - * it chains to the base validator, but also adds additional methods like (`regexp`, `domain`, `nonEmpty`, - * and `unique`). When `nonEmpty` is called, which calls chain again, the additional methods are carried - * forward because they are already defined on the leftValidator. - * - * The base validator also contains the two methods `required` and `default`, so these can be used anywhere - * after any of the exposed validator functions are called. - */ - - var chain = (function (leftValidator, rightValidator) { - var additionalMethods = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - - // combine the two validators, calling left first and then right. - // pass the return value from left into right. - var combinedValidator = function combinedValidator(value, path) { - return rightValidator(leftValidator(value, path), path); - }; // add the methods already defined on the left validator, and the additionalMethods - // to the new combined validator function. - - - reactorObjectAssign(combinedValidator, leftValidator, additionalMethods); - return combinedValidator; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - /** - * This augments `chain` with a null check done before running the rightValidator. - * See chain for more info. - * - * For most validators, we want the validation to be optional (i.e. allow null or - * undefined values). To accomplish this, the validator needs to have a check - * at the begining of the function, short circuiting the validation logic and - * returning value if value is null or undefined. `default` and `required` do not - * want this null check though. Indeed, `default` should return the default value - * if value is null, and `required` should throw an error if value is null. - * - * So to keep from having to have a null check in front of most validators, this - * function allows you to chain a rightValidator that needs to have a null check. - */ - - var nullSafeChain = (function (leftValidator, rightValidator, additionalMethods) { - var rightValidatorWithNullCheck = function rightValidatorWithNullCheck(value, path) { - return value == null ? value : rightValidator(value, path); - }; - - return chain(leftValidator, rightValidatorWithNullCheck, additionalMethods); - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var assertValid = (function (isValid, value, path, message) { - if (!isValid) { - throw new Error("'" + path + "': Expected " + message + ", but got " + JSON.stringify(value) + "."); - } - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var booleanValidator = (function (value, path) { - assertValid(isBoolean(value), value, path, "true or false"); - return value; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var callbackValidator = (function (value, path) { - assertValid(isFunction(value), value, path, "a function"); - return value; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createArrayOfValidator = (function (elementValidator) { - return function (value, path) { - assertValid(Array.isArray(value), value, path, "an array"); - var errors = []; - var validatedArray = value.map(function (subValue, i) { - try { - return elementValidator(subValue, path + "[" + i + "]"); - } catch (e) { - errors.push(e.message); - return undefined; - } - }); - - if (errors.length) { - throw new Error(errors.join("\n")); - } - - return validatedArray; - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createDefaultValidator = (function (defaultValue) { - return function (value) { - if (value == null) { - return defaultValue; - } - - return value; - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createLiteralValidator = (function (literalValue) { - return function (value, path) { - assertValid(value === literalValue, value, path, "" + literalValue); - return value; - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createMapOfValuesValidator = (function (valueValidator) { - return function (value, path) { - assertValid(isObject(value), value, path, "an object"); - var errors = []; - var validatedObject = {}; - Object.keys(value).forEach(function (subKey) { - var subValue = value[subKey]; - var subPath = path ? path + "." + subKey : subKey; - - try { - var validatedValue = valueValidator(subValue, subPath); - - if (validatedValue !== undefined) { - validatedObject[subKey] = validatedValue; - } - } catch (e) { - errors.push(e.message); - } - }); - - if (errors.length) { - throw new Error(errors.join("\n")); - } - - return validatedObject; - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createMinimumValidator = (function (typeName, minimum) { - return function (value, path) { - assertValid(value >= minimum, value, path, typeName + " greater than or equal to " + minimum); - return value; - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createNoUnknownFieldsValidator = (function (schema) { - return function (value, path) { - var errors = []; - Object.keys(value).forEach(function (subKey) { - if (!schema[subKey]) { - var subPath = path ? path + "." + subKey : subKey; - errors.push("'" + subPath + "': Unknown field."); - } - }); - - if (errors.length) { - throw new Error(errors.join("\n")); - } - - return value; - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createNonEmptyValidator = (function (message) { - return function (value, path) { - if (isObject(value)) { - assertValid(!isEmptyObject(value), value, path, message); - } else { - assertValid(value.length > 0, value, path, message); - } - - return value; - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createObjectOfValidator = (function (schema) { - return function (value, path) { - assertValid(isObject(value), value, path, "an object"); - var errors = []; - var validatedObject = {}; - Object.keys(schema).forEach(function (subKey) { - var subValue = value[subKey]; - var subSchema = schema[subKey]; - var subPath = path ? path + "." + subKey : subKey; - - try { - var validatedValue = subSchema(subValue, subPath); - - if (validatedValue !== undefined) { - validatedObject[subKey] = validatedValue; - } - } catch (e) { - errors.push(e.message); - } - }); // copy over unknown properties - - Object.keys(value).forEach(function (subKey) { - if (!Object.prototype.hasOwnProperty.call(validatedObject, subKey)) { - validatedObject[subKey] = value[subKey]; - } - }); - - if (errors.length) { - throw new Error(errors.join("\n")); - } - - return validatedObject; - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createAnyOfValidator = (function (validators, message) { - return function (value, path) { - var valid = find(validators, function (validator) { - try { - validator(value, path); - return true; - } catch (e) { - return false; - } - }); - assertValid(valid, value, path, message); - return value; - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createUniqueValidator = (function () { - var values = []; - return function (value, path) { - assertValid(values.indexOf(value) === -1, value, path, "a unique value across instances"); - values.push(value); - return value; - }; - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Returns whether an array contains unique values. - * @param {*} value - * @returns {boolean} - */ - var isUnique = (function (values) { - var storedVals = Object.create(null); - - for (var i = 0; i < values.length; i += 1) { - var item = values[i]; - - if (item in storedVals) { - return false; - } - - storedVals[item] = true; - } - - return true; - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createUniqueItemsValidator = (function () { - return function (value, path) { - assertValid(isUnique(value), value, path, "array values to be unique"); - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var DOMAIN_REGEX = /^[a-z0-9.-]{1,}$/i; - var domainValidator = (function (value, path) { - assertValid(DOMAIN_REGEX.test(value), value, path, "a valid domain"); - return value; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var integerValidator = (function (value, path) { - assertValid(isInteger(value), value, path, "an integer"); - return value; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var numberValidator = (function (value, path) { - assertValid(isNumber(value), value, path, "a number"); - return value; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Determines whether the value is a valid regular expression. - * @param {*} value - * @returns {boolean} - */ - var isValidRegExp = (function (value) { - try { - return new RegExp(value) !== null; - } catch (e) { - return false; - } - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var regexpValidator = (function (value, path) { - assertValid(isValidRegExp(value), value, path, "a regular expression"); - return value; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var requiredValidator = (function (value, path) { - if (value == null) { - throw new Error("'" + path + "' is a required option"); - } - - return value; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var stringValidator = (function (value, path) { - assertValid(isString(value), value, path, "a string"); - return value; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var base = function base(value) { - return value; - }; // The 'default' and 'required' methods are available after any data-type method - // Don't use the nullSafeChain because they need to handle the null or undefined case - - - base.default = function _default(defaultValue) { - return chain(this, createDefaultValidator(defaultValue)); - }; - - base.required = function required() { - return chain(this, requiredValidator); - }; // helper validators - - - var domain = function domain() { - return nullSafeChain(this, domainValidator); - }; - - var minimumInteger = function minimumInteger(minValue) { - return nullSafeChain(this, createMinimumValidator("an integer", minValue)); - }; - - var minimumNumber = function minimumNumber(minValue) { - return nullSafeChain(this, createMinimumValidator("a number", minValue)); - }; - - var integer = function integer() { - return nullSafeChain(this, integerValidator, { - minimum: minimumInteger - }); - }; - - var nonEmptyString = function nonEmptyString() { - return nullSafeChain(this, createNonEmptyValidator("a non-empty string")); - }; - - var nonEmptyArray = function nonEmptyArray() { - return nullSafeChain(this, createNonEmptyValidator("a non-empty array")); - }; - - var nonEmptyObject = function nonEmptyObject() { - return nullSafeChain(this, createNonEmptyValidator("a non-empty object")); - }; - - var regexp = function regexp() { - return nullSafeChain(this, regexpValidator); - }; - - var unique = function createUnique() { - return nullSafeChain(this, createUniqueValidator()); - }; - - var uniqueItems = function createUniqueItems() { - return nullSafeChain(this, createUniqueItemsValidator()); - }; // top-level validators. These are the first functions that are called to create a validator. - - - var anyOf = function anyOf(validators, message) { - // use chain here because we don't want to accept null or undefined unless at least - // one of the validators accept null or undefined. - return chain(this, createAnyOfValidator(validators, message)); - }; - - var anything = function anything() { - return nullSafeChain(this, base); - }; - - var arrayOf = function arrayOf(elementValidator) { - return nullSafeChain(this, createArrayOfValidator(elementValidator), { - nonEmpty: nonEmptyArray, - uniqueItems: uniqueItems - }); - }; - - var boolean = function boolean() { - return nullSafeChain(this, booleanValidator); - }; - - var callback = function callback() { - return nullSafeChain(this, callbackValidator); - }; - - var literal = function literal(literalValue) { - return nullSafeChain(this, createLiteralValidator(literalValue)); - }; - - var number = function number() { - return nullSafeChain(this, numberValidator, { - minimum: minimumNumber, - integer: integer, - unique: unique - }); - }; - - var mapOfValues = function mapOfValues(valuesValidator) { - return nullSafeChain(this, createMapOfValuesValidator(valuesValidator), { - nonEmpty: nonEmptyObject - }); - }; - - var objectOf = function objectOf(schema) { - var noUnknownFields = function noUnknownFields() { - return nullSafeChain(this, createNoUnknownFieldsValidator(schema)); - }; - - return nullSafeChain(this, createObjectOfValidator(schema), { - noUnknownFields: noUnknownFields, - nonEmpty: nonEmptyObject - }); - }; - - var string = function string() { - return nullSafeChain(this, stringValidator, { - regexp: regexp, - domain: domain, - nonEmpty: nonEmptyString, - unique: unique - }); - }; - - var boundAnyOf = anyOf.bind(base); - var boundAnything = anything.bind(base); - var boundArrayOf = arrayOf.bind(base); - var boundBoolean = boolean.bind(base); - var boundCallback = callback.bind(base); - var boundLiteral = literal.bind(base); - number.bind(base); - var boundMapOfValues = mapOfValues.bind(base); - var boundObjectOf = objectOf.bind(base); - var boundString = string.bind(base); // compound validators - - var boundEnumOf = function boundEnumOf() { - for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) { - values[_key] = arguments[_key]; - } - - return boundAnyOf(values.map(boundLiteral), "one of these values: [" + JSON.stringify(values) + "]"); - }; - - /* - Copyright 2023 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var AMBIGUOUS = "ambiguous"; - var AUTHENTICATED = "authenticated"; - var LOGGED_OUT = "loggedOut"; - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var validateIdentityMap = boundMapOfValues(boundArrayOf(boundObjectOf({ - authenticatedState: boundEnumOf(AMBIGUOUS, AUTHENTICATED, LOGGED_OUT), - id: boundString(), - namespace: boundObjectOf({ - code: boundString() - }).noUnknownFields(), - primary: boundBoolean(), - xid: boundString() - }).noUnknownFields()).required()); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var validateConfigOverride = boundObjectOf({}); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var debugQueryParam = "alloy_debug"; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createLogController = (function (_ref) { - var console = _ref.console, - locationSearch = _ref.locationSearch, - createLogger = _ref.createLogger, - instanceName = _ref.instanceName, - createNamespacedStorage = _ref.createNamespacedStorage, - getMonitors = _ref.getMonitors; - var parsedQueryString = reactorQueryString.parse(locationSearch); - var storage = createNamespacedStorage("instance." + instanceName + "."); - var debugSessionValue = storage.session.getItem("debug"); - var debugEnabled = debugSessionValue === "true"; - var debugEnabledWritableFromConfig = debugSessionValue === null; - - var getDebugEnabled = function getDebugEnabled() { - return debugEnabled; - }; - - var setDebugEnabled = function setDebugEnabled(value, _ref2) { - var fromConfig = _ref2.fromConfig; - - if (!fromConfig || debugEnabledWritableFromConfig) { - debugEnabled = value; - } - - if (!fromConfig) { - // Web storage only allows strings, so we explicitly convert to string. - storage.session.setItem("debug", value.toString()); - debugEnabledWritableFromConfig = false; - } - }; - - if (parsedQueryString[debugQueryParam] !== undefined) { - setDebugEnabled(stringToBoolean(parsedQueryString[debugQueryParam]), { - fromConfig: false - }); - } - - return { - setDebugEnabled: setDebugEnabled, - logger: createLogger({ - getDebugEnabled: getDebugEnabled, - context: { - instanceName: instanceName - }, - getMonitors: getMonitors, - console: console - }), - createComponentLogger: function createComponentLogger(componentName) { - return createLogger({ - getDebugEnabled: getDebugEnabled, - context: { - instanceName: instanceName, - componentName: componentName - }, - getMonitors: getMonitors, - console: console - }); - } - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - // TO-DOCUMENT: Lifecycle hooks and their params. - var hookNames = [// Called after all components have been registered. - "onComponentsRegistered", // Called before an event is sent on a data collection request - "onBeforeEvent", // Called before each request is made to the edge. - "onBeforeRequest", // Called after each response is returned from the edge with a successful - // status code - "onResponse", // Called after a network request to the edge fails. Either the request - // didn't make it to the edge, didn't make it to Konductor, or Konductor - // failed to return a regularly-structured response. (In this case { error } - // is passed as the parameter) - // Also called when the respone returns a 400 or 500 error. (In this case - // { response } is passed as the parameter) - "onRequestFailure", // A user clicked on an element. - "onClick"]; - - var createHook = function createHook(componentRegistry, hookName) { - return function () { - for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - return Promise.all(componentRegistry.getLifecycleCallbacks(hookName).map(function (callback) { - return new Promise(function (resolve) { - resolve(callback.apply(void 0, args)); - }); - })); - }; - }; - /** - * This ensures that if a component's lifecycle method X - * attempts to execute lifecycle method Y, that all X methods on all components - * will have been called before any of their Y methods are called. It does - * this by kicking the call to the Y method to the next JavaScript tick. - * @returns {function} - */ - - - var guardHook = function guardHook(fn) { - return function () { - for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { - args[_key2] = arguments[_key2]; - } - - return Promise.resolve().then(function () { - return fn.apply(void 0, args); - }); - }; - }; - - var createLifecycle = (function (componentRegistry) { - return hookNames.reduce(function (memo, hookName) { - memo[hookName] = guardHook(createHook(componentRegistry, hookName)); - return memo; - }, {}); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var wrapForErrorHandling = function wrapForErrorHandling(fn, stackMessage) { - return function () { - var result; - - try { - result = fn.apply(void 0, arguments); - } catch (error) { - throw stackError({ - error: error, - message: stackMessage - }); - } - - if (result instanceof Promise) { - result = result.catch(function (error) { - throw stackError({ - error: error, - message: stackMessage - }); - }); - } - - return result; - }; - }; // TO-DOCUMENT: All public commands and their signatures. - - - var createComponentRegistry = (function () { - var componentsByNamespace = {}; - var commandsByName = {}; - var lifecycleCallbacksByName = {}; - - var registerComponentCommands = function registerComponentCommands(namespace) { - var componentCommandsByName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var conflictingCommandNames = intersection(Object.keys(commandsByName), Object.keys(componentCommandsByName)); - - if (conflictingCommandNames.length) { - throw new Error("[ComponentRegistry] Could not register " + namespace + " " + ("because it has existing command(s): " + conflictingCommandNames.join(","))); - } - - Object.keys(componentCommandsByName).forEach(function (commandName) { - var command = componentCommandsByName[commandName]; - command.commandName = commandName; - command.run = wrapForErrorHandling(command.run, "[" + namespace + "] An error occurred while executing the " + commandName + " command."); - commandsByName[commandName] = command; - }); - }; - - var registerLifecycleCallbacks = function registerLifecycleCallbacks(namespace) { - var componentLifecycleCallbacksByName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - Object.keys(componentLifecycleCallbacksByName).forEach(function (hookName) { - lifecycleCallbacksByName[hookName] = lifecycleCallbacksByName[hookName] || []; - lifecycleCallbacksByName[hookName].push(wrapForErrorHandling(componentLifecycleCallbacksByName[hookName], "[" + namespace + "] An error occurred while executing the " + hookName + " lifecycle hook.")); - }); - }; - - return { - register: function register(namespace, component) { - var commands = component.commands, - lifecycle = component.lifecycle; - registerComponentCommands(namespace, commands); - registerLifecycleCallbacks(namespace, lifecycle); - componentsByNamespace[namespace] = component; - }, - getCommand: function getCommand(commandName) { - return commandsByName[commandName]; - }, - getCommandNames: function getCommandNames() { - return Object.keys(commandsByName); - }, - getLifecycleCallbacks: function getLifecycleCallbacks(hookName) { - return lifecycleCallbacksByName[hookName] || []; - } - }; - }); - - var injectSendNetworkRequest = (function (_ref) { - var logger = _ref.logger, - sendFetchRequest = _ref.sendFetchRequest, - sendBeaconRequest = _ref.sendBeaconRequest, - isRequestRetryable = _ref.isRequestRetryable, - getRequestRetryDelay = _ref.getRequestRetryDelay; - - /** - * Send a network request and returns details about the response. - */ - return function (_ref2) { - var requestId = _ref2.requestId, - url = _ref2.url, - payload = _ref2.payload, - useSendBeacon = _ref2.useSendBeacon; - // We want to log raw payload and event data rather than - // our fancy wrapper objects. Calling payload.toJSON() is - // insufficient to get all the nested raw data, because it's - // not recursive (it doesn't call toJSON() on the event objects). - // Parsing the result of JSON.stringify(), however, gives the - // fully recursive raw data. - var stringifiedPayload = JSON.stringify(payload); - var parsedPayload = JSON.parse(stringifiedPayload); - logger.logOnBeforeNetworkRequest({ - url: url, - requestId: requestId, - payload: parsedPayload - }); - - var executeRequest = function executeRequest() { - var retriesAttempted = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; - var requestMethod = useSendBeacon ? sendBeaconRequest : sendFetchRequest; - return requestMethod(url, stringifiedPayload).then(function (response) { - var requestIsRetryable = isRequestRetryable({ - response: response, - retriesAttempted: retriesAttempted - }); - - if (requestIsRetryable) { - var requestRetryDelay = getRequestRetryDelay({ - response: response, - retriesAttempted: retriesAttempted - }); - return new Promise(function (resolve) { - setTimeout(function () { - resolve(executeRequest(retriesAttempted + 1)); - }, requestRetryDelay); - }); - } - - var parsedBody; - - try { - parsedBody = JSON.parse(response.body); - } catch (e) {// Non-JSON. Something went wrong. - } - - logger.logOnNetworkResponse(_objectSpread2(_objectSpread2({ - requestId: requestId, - url: url, - payload: parsedPayload - }, response), {}, { - parsedBody: parsedBody, - retriesAttempted: retriesAttempted - })); - return { - statusCode: response.statusCode, - body: response.body, - parsedBody: parsedBody, - getHeader: response.getHeader - }; - }); - }; - - return executeRequest().catch(function (error) { - logger.logOnNetworkError({ - requestId: requestId, - url: url, - payload: parsedPayload, - error: error - }); - throw stackError({ - error: error, - message: "Network request failed." - }); - }); - }; - }); - - /* - Copyright 2021 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectExtractEdgeInfo = (function (_ref) { - var logger = _ref.logger; - return function (adobeEdgeHeader) { - if (adobeEdgeHeader) { - var headerParts = adobeEdgeHeader.split(";"); - - if (headerParts.length >= 2 && headerParts[1].length > 0) { - try { - var regionId = parseInt(headerParts[1], 10); // eslint recommends using Number.isNaN instead, but this function is - // not available in Internet Explorer. Number.isNaN is more robust to - // non-numeric parameters. Since we already know regionId will be an - // integer, using isNaN is okay. - // https://github.com/airbnb/javascript#standard-library--isnan - // eslint-disable-next-line no-restricted-globals - - if (!isNaN(regionId)) { - return { - regionId: regionId - }; - } - } catch (e) {// No need to do anything. The log statement below will log an error - } - } - - logger.warn("Invalid adobe edge: \"" + adobeEdgeHeader + "\""); - } - - return {}; - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var IN = "in"; - var OUT = "out"; - var PENDING = "pending"; - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var GENERAL = "general"; - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var DECLINED_CONSENT_ERROR_CODE = "declinedConsent"; - var CONSENT_SOURCE_DEFAULT = "default"; - var CONSENT_SOURCE_INITIAL = "initial"; - var CONSENT_SOURCE_NEW = "new"; - - var createDeclinedConsentError = function createDeclinedConsentError(errorMessage) { - var error = new Error(errorMessage); - error.code = DECLINED_CONSENT_ERROR_CODE; - error.message = errorMessage; - return error; - }; - - var createConsentStateMachine = (function (_ref) { - var logger = _ref.logger; - var deferreds = []; - - var runAll = function runAll() { - while (deferreds.length) { - deferreds.shift().resolve(); - } - }; - - var discardAll = function discardAll() { - while (deferreds.length) { - deferreds.shift().reject(createDeclinedConsentError("The user declined consent.")); - } - }; - - var awaitInitial = function awaitInitial() { - return Promise.reject(new Error("Consent has not been initialized.")); - }; - - var awaitInDefault = function awaitInDefault() { - return Promise.resolve(); - }; - - var awaitIn = function awaitIn() { - return Promise.resolve(); - }; - - var awaitOutDefault = function awaitOutDefault() { - return Promise.reject(createDeclinedConsentError("No consent preferences have been set.")); - }; - - var awaitOut = function awaitOut() { - return Promise.reject(createDeclinedConsentError("The user declined consent.")); - }; - - var awaitPending = function awaitPending(returnImmediately) { - if (returnImmediately) { - return Promise.reject(new Error("Consent is pending.")); - } - - var deferred = defer(); - deferreds.push(deferred); - return deferred.promise; - }; - - return { - in: function _in(source) { - if (source === CONSENT_SOURCE_DEFAULT) { - this.awaitConsent = awaitInDefault; - } else { - if (source === CONSENT_SOURCE_INITIAL) { - logger.info("Loaded user consent preferences. The user previously consented."); - } else if (source === CONSENT_SOURCE_NEW && this.awaitConsent !== awaitIn) { - logger.info("User consented."); - } - - runAll(); - this.awaitConsent = awaitIn; - } - }, - out: function out(source) { - if (source === CONSENT_SOURCE_DEFAULT) { - logger.warn("User consent preferences not found. Default consent of out will be used."); - this.awaitConsent = awaitOutDefault; - } else { - if (source === CONSENT_SOURCE_INITIAL) { - logger.warn("Loaded user consent preferences. The user previously declined consent."); - } else if (source === CONSENT_SOURCE_NEW && this.awaitConsent !== awaitOut) { - logger.warn("User declined consent."); - } - - discardAll(); - this.awaitConsent = awaitOut; - } - }, - pending: function pending(source) { - if (source === CONSENT_SOURCE_DEFAULT) { - logger.info("User consent preferences not found. Default consent of pending will be used. Some commands may be delayed."); - } - - this.awaitConsent = awaitPending; - }, - awaitConsent: awaitInitial, - withConsent: function withConsent() { - return this.awaitConsent(true); - } - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createConsent = (function (_ref) { - var generalConsentState = _ref.generalConsentState, - logger = _ref.logger; - - var _setConsent = function setConsent(consentByPurpose, source) { - switch (consentByPurpose[GENERAL]) { - case IN: - generalConsentState.in(source); - break; - - case OUT: - generalConsentState.out(source); - break; - - case PENDING: - generalConsentState.pending(source); - break; - - default: - logger.warn("Unknown consent value: " + consentByPurpose[GENERAL]); - break; - } - }; - - return { - initializeConsent: function initializeConsent(defaultConsentByPurpose, storedConsentByPurpose) { - if (storedConsentByPurpose[GENERAL]) { - _setConsent(storedConsentByPurpose, CONSENT_SOURCE_INITIAL); - } else { - _setConsent(defaultConsentByPurpose, CONSENT_SOURCE_DEFAULT); - } - }, - setConsent: function setConsent(consentByPurpose) { - _setConsent(consentByPurpose, CONSENT_SOURCE_NEW); - }, - suspend: function suspend() { - generalConsentState.pending(); - }, - awaitConsent: function awaitConsent() { - return generalConsentState.awaitConsent(); - }, - withConsent: function withConsent() { - return generalConsentState.withConsent(); - } - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createEvent = (function () { - var content = {}; - var userXdm; - var userData; - var _documentMayUnload = false; - var isFinalized = false; - var shouldSendEvent = true; - - var throwIfEventFinalized = function throwIfEventFinalized(methodName) { - if (isFinalized) { - throw new Error(methodName + " cannot be called after event is finalized."); - } - }; - - var event = { - setUserXdm: function setUserXdm(value) { - throwIfEventFinalized("setUserXdm"); - userXdm = value; - }, - setUserData: function setUserData(value) { - throwIfEventFinalized("setUserData"); - userData = value; - }, - mergeXdm: function mergeXdm(xdm) { - throwIfEventFinalized("mergeXdm"); - - if (xdm) { - deepAssign(content, { - xdm: xdm - }); - } - }, - mergeMeta: function mergeMeta(meta) { - throwIfEventFinalized("mergeMeta"); - - if (meta) { - deepAssign(content, { - meta: meta - }); - } - }, - mergeQuery: function mergeQuery(query) { - throwIfEventFinalized("mergeQuery"); - - if (query) { - deepAssign(content, { - query: query - }); - } - }, - documentMayUnload: function documentMayUnload() { - _documentMayUnload = true; - }, - finalize: function finalize(onBeforeEventSend) { - if (isFinalized) { - return; - } - - if (userXdm) { - event.mergeXdm(userXdm); - } - - if (userData) { - content.data = userData; - } // the event should already be considered finalized in case onBeforeEventSend throws an error - - - isFinalized = true; - - if (onBeforeEventSend) { - // assume that the onBeforeEventSend callback will fail (in-case of an error) - shouldSendEvent = false; // this allows the user to replace the xdm and data properties - // on the object passed to the callback - - var tempContent = { - xdm: content.xdm || {}, - data: content.data || {} - }; - var result = onBeforeEventSend(tempContent); - shouldSendEvent = result !== false; - content.xdm = tempContent.xdm || {}; - content.data = tempContent.data || {}; - - if (isEmptyObject(content.xdm)) { - delete content.xdm; - } - - if (isEmptyObject(content.data)) { - delete content.data; - } - } - }, - getDocumentMayUnload: function getDocumentMayUnload() { - return _documentMayUnload; - }, - isEmpty: function isEmpty() { - return isEmptyObject(content) && (!userXdm || isEmptyObject(userXdm)) && (!userData || isEmptyObject(userData)); - }, - shouldSend: function shouldSend() { - return shouldSendEvent; - }, - getViewName: function getViewName() { - if (!userXdm || !userXdm.web || !userXdm.web.webPageDetails) { - return undefined; - } - - return userXdm.web.webPageDetails.viewName; - }, - toJSON: function toJSON() { - if (!isFinalized) { - throw new Error("toJSON called before finalize"); - } - - return content; - } - }; - return event; - }); - - /* - Copyright 2021 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var RETRY_AFTER = "Retry-After"; - var ADOBE_EDGE = "x-adobe-edge"; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - /** - * Creates a representation of a gateway response with the addition of - * helper methods. - * @returns Response - */ - - var injectCreateResponse = (function (_ref) { - var extractEdgeInfo = _ref.extractEdgeInfo; - return function (_ref2) { - var _ref2$content = _ref2.content, - content = _ref2$content === void 0 ? {} : _ref2$content, - getHeader = _ref2.getHeader; - var _content$handle = content.handle, - handle = _content$handle === void 0 ? [] : _content$handle, - _content$errors = content.errors, - errors = _content$errors === void 0 ? [] : _content$errors, - _content$warnings = content.warnings, - warnings = _content$warnings === void 0 ? [] : _content$warnings; - /** - * Response object. - * @typedef {Object} Response - */ - - return { - /** - * Returns matching fragments of the response by type. - * @param {String} type A string with the current format: - * - * @example - * getPayloadsByType("identity:persist") - */ - getPayloadsByType: function getPayloadsByType(type) { - return flatMap(handle.filter(function (fragment) { - return fragment.type === type; - }), function (fragment) { - return fragment.payload; - }); - }, - - /** - * Returns all errors. - */ - getErrors: function getErrors() { - return errors; - }, - - /** - * Returns all warnings. - */ - getWarnings: function getWarnings() { - return warnings; - }, - - /** - * Returns an object containing the regionId from the x-adobe-edge header - */ - getEdge: function getEdge() { - return extractEdgeInfo(getHeader(ADOBE_EDGE)); - }, - toJSON: function toJSON() { - return content; - } - }; - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var CONFIGURE = "configure"; - var SET_DEBUG = "setDebug"; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectExecuteCommand = (function (_ref) { - var logger = _ref.logger, - configureCommand = _ref.configureCommand, - setDebugCommand = _ref.setDebugCommand, - handleError = _ref.handleError, - validateCommandOptions = _ref.validateCommandOptions; - var configurePromise; - - var getExecutor = function getExecutor(commandName, options) { - var executor; - - if (commandName === CONFIGURE) { - if (configurePromise) { - throw new Error("The library has already been configured and may only be configured once."); - } - - executor = function executor() { - configurePromise = configureCommand(options); - return configurePromise.then(function () {// Don't expose internals to the user. - }); - }; - } else { - if (!configurePromise) { - throw new Error("The library must be configured first. Please do so by executing the configure command."); - } - - if (commandName === SET_DEBUG) { - executor = function executor() { - return setDebugCommand(options); - }; - } else { - executor = function executor() { - return configurePromise.then(function (componentRegistry) { - var command = componentRegistry.getCommand(commandName); - - if (!command || !isFunction(command.run)) { - var commandNames = [CONFIGURE, SET_DEBUG].concat(componentRegistry.getCommandNames()).join(", "); - throw new Error("The " + commandName + " command does not exist. List of available commands: " + commandNames + "."); - } - - var validatedOptions = validateCommandOptions({ - command: command, - options: options - }); - return command.run(validatedOptions); - }, function () { - logger.warn("An error during configuration is preventing the " + commandName + " command from executing."); // If configuration failed, we prevent the configuration - // error from bubbling here because we don't want the - // configuration error to be reported in the console every - // time any command is executed. Only having it bubble - // once when the configure command runs is sufficient. - // Instead, for this command, we'll just return a promise - // that never gets resolved. - - return new Promise(function () {}); - }); - }; - } - } - - return executor; - }; - - return function (commandName) { - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - return new Promise(function (resolve) { - // We have to wrap the getExecutor() call in the promise so the promise - // will be rejected if getExecutor() throws errors. - var executor = getExecutor(commandName, options); - logger.logOnBeforeCommand({ - commandName: commandName, - options: options - }); - resolve(executor()); - }).catch(function (error) { - return handleError(error, commandName + " command"); - }).catch(function (error) { - logger.logOnCommandRejected({ - commandName: commandName, - options: options, - error: error - }); - throw error; - }).then(function (rawResult) { - // We should always be returning an object from every command. - var result = isObject(rawResult) ? rawResult : {}; - logger.logOnCommandResolved({ - commandName: commandName, - options: options, - result: result - }); - return result; - }); - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var COMMAND_DOC_URI = "https://adobe.ly/3sHgQHb"; - var validateCommandOptions = (function (_ref) { - var command = _ref.command, - options = _ref.options; - var commandName = command.commandName, - _command$documentatio = command.documentationUri, - documentationUri = _command$documentatio === void 0 ? COMMAND_DOC_URI : _command$documentatio, - optionsValidator = command.optionsValidator; - var validatedOptions = options; - - if (optionsValidator) { - try { - validatedOptions = optionsValidator(options); - } catch (validationError) { - var invalidOptionsMessage = "Invalid " + commandName + " command options:\n\t - " + validationError + " For command documentation see: " + documentationUri; - throw new Error(invalidOptionsMessage); - } - } - - return validatedOptions; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - /** - * Verifies user provided event options. - * @param {*} options The user event options to validate - * @returns {*} Validated options - */ - - var validateUserEventOptions = (function (_ref) { - var options = _ref.options; - var eventOptionsValidator = boundObjectOf({ - type: boundString(), - xdm: boundObjectOf({ - eventType: boundString(), - identityMap: validateIdentityMap - }), - data: boundObjectOf({}), - documentUnloading: boundBoolean(), - renderDecisions: boundBoolean(), - decisionScopes: boundArrayOf(boundString()).uniqueItems(), - personalization: boundObjectOf({ - decisionScopes: boundArrayOf(boundString()).uniqueItems(), - surfaces: boundArrayOf(boundString()).uniqueItems() - }), - datasetId: boundString(), - mergeId: boundString(), - edgeConfigOverrides: validateConfigOverride - }).required().noUnknownFields(); - return eventOptionsValidator(options); - }); - - /* - Copyright 2023 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var validateApplyResponse = (function (_ref) { - var options = _ref.options; - var validator = boundObjectOf({ - renderDecisions: boundBoolean(), - responseHeaders: boundMapOfValues(boundString().required()), - responseBody: boundObjectOf({ - handle: boundArrayOf(boundObjectOf({ - type: boundString().required(), - payload: boundAnything().required() - })).required() - }).required() - }).noUnknownFields(); - return validator(options); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var createDataCollector = function createDataCollector(_ref) { - var eventManager = _ref.eventManager, - logger = _ref.logger; - return { - commands: { - sendEvent: { - documentationUri: "https://adobe.ly/3GQ3Q7t", - optionsValidator: function optionsValidator(options) { - return validateUserEventOptions({ - options: options - }); - }, - run: function run(options) { - var xdm = options.xdm, - data = options.data, - _options$documentUnlo = options.documentUnloading, - documentUnloading = _options$documentUnlo === void 0 ? false : _options$documentUnlo, - type = options.type, - mergeId = options.mergeId, - _options$renderDecisi = options.renderDecisions, - renderDecisions = _options$renderDecisi === void 0 ? false : _options$renderDecisi, - _options$decisionScop = options.decisionScopes, - decisionScopes = _options$decisionScop === void 0 ? [] : _options$decisionScop, - _options$personalizat = options.personalization, - personalization = _options$personalizat === void 0 ? {} : _options$personalizat, - datasetId = options.datasetId, - edgeConfigOverrides = options.edgeConfigOverrides; - var event = eventManager.createEvent(); - - if (documentUnloading) { - event.documentMayUnload(); - } - - event.setUserXdm(xdm); - event.setUserData(data); - - if (type) { - event.mergeXdm({ - eventType: type - }); - } - - if (mergeId) { - event.mergeXdm({ - eventMergeId: mergeId - }); - } - - var sendEventOptions = { - renderDecisions: renderDecisions, - decisionScopes: decisionScopes, - personalization: personalization - }; - - if (edgeConfigOverrides) { - sendEventOptions.edgeConfigOverrides = edgeConfigOverrides; - } - - if (datasetId) { - logger.warn("The 'datasetId' option has been deprecated. Please use 'edgeConfigOverrides.experience_platform.datasets.event' instead."); - sendEventOptions.edgeConfigOverrides = edgeConfigOverrides || {}; - deepAssign(sendEventOptions.edgeConfigOverrides, { - com_adobe_experience_platform: { - datasets: { - event: { - datasetId: datasetId - } - } - } - }); - } - - return eventManager.sendEvent(event, sendEventOptions); - } - }, - applyResponse: { - documentationUri: "", - optionsValidator: function optionsValidator(options) { - return validateApplyResponse({ - options: options - }); - }, - run: function run(options) { - var _options$renderDecisi2 = options.renderDecisions, - renderDecisions = _options$renderDecisi2 === void 0 ? false : _options$renderDecisi2, - _options$responseHead = options.responseHeaders, - responseHeaders = _options$responseHead === void 0 ? {} : _options$responseHead, - _options$responseBody = options.responseBody, - responseBody = _options$responseBody === void 0 ? { - handle: [] - } : _options$responseBody; - var event = eventManager.createEvent(); - return eventManager.applyResponse(event, { - renderDecisions: renderDecisions, - responseHeaders: responseHeaders, - responseBody: responseBody - }); - } - } - } - }; - }; - - createDataCollector.namespace = "DataCollector"; - createDataCollector.configValidators = {}; - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var createClickHandler = function createClickHandler(_ref) { - var eventManager = _ref.eventManager, - lifecycle = _ref.lifecycle, - handleError = _ref.handleError; - return function (clickEvent) { - // TODO: Consider safeguarding from the same object being clicked multiple times in rapid succession? - var clickedElement = clickEvent.target; - var event = eventManager.createEvent(); // this is to make sure a exit link personalization metric use send beacon - - event.documentMayUnload(); - return lifecycle.onClick({ - event: event, - clickedElement: clickedElement - }).then(function () { - if (event.isEmpty()) { - return Promise.resolve(); - } - - return eventManager.sendEvent(event); - }) // eventManager.sendEvent() will return a promise resolved to an - // object and we want to avoid returning any value to the customer - .then(noop$1).catch(function (error) { - handleError(error, "click collection"); - }); - }; - }; - - var attachClickActivityCollector = (function (_ref2) { - var eventManager = _ref2.eventManager, - lifecycle = _ref2.lifecycle, - handleError = _ref2.handleError; - var clickHandler = createClickHandler({ - eventManager: eventManager, - lifecycle: lifecycle, - handleError: handleError - }); - document.addEventListener("click", clickHandler, true); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var configValidators$1 = { - clickCollectionEnabled: boundBoolean().default(true), - downloadLinkQualifier: boundString().regexp().default("\\.(exe|zip|wav|mp3|mov|mpg|avi|wmv|pdf|doc|docx|xls|xlsx|ppt|pptx)$"), - onBeforeLinkClickSend: boundCallback() - }; - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createLinkClick = (function (_ref) { - var getLinkDetails = _ref.getLinkDetails, - config = _ref.config, - logger = _ref.logger; - var clickCollectionEnabled = config.clickCollectionEnabled; - - if (!clickCollectionEnabled) { - return function () { - return undefined; - }; - } - - return function (_ref2) { - var targetElement = _ref2.targetElement, - event = _ref2.event; - var linkDetails = getLinkDetails({ - targetElement: targetElement, - config: config, - logger: logger - }); - - if (linkDetails) { - event.mergeXdm(linkDetails.xdm); - event.setUserData(linkDetails.data); - } - }; - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createGetLinkDetails = (function (_ref) { - var window = _ref.window, - getLinkName = _ref.getLinkName, - getLinkRegion = _ref.getLinkRegion, - getAbsoluteUrlFromAnchorElement = _ref.getAbsoluteUrlFromAnchorElement, - findSupportedAnchorElement = _ref.findSupportedAnchorElement, - determineLinkType = _ref.determineLinkType; - return function (_ref2) { - var targetElement = _ref2.targetElement, - config = _ref2.config, - logger = _ref2.logger; - var anchorElement = findSupportedAnchorElement(targetElement); - - if (!anchorElement) { - logger.info("This link click event is not triggered because the HTML element is not an anchor."); - return undefined; - } - - var linkUrl = getAbsoluteUrlFromAnchorElement(window, anchorElement); - - if (!linkUrl) { - logger.info("This link click event is not triggered because the HTML element doesn't have an URL."); - return undefined; - } - - var linkType = determineLinkType(window, config, linkUrl, anchorElement); - var linkRegion = getLinkRegion(anchorElement); - var linkName = getLinkName(anchorElement); - var onBeforeLinkClickSend = config.onBeforeLinkClickSend; - var options = { - xdm: { - eventType: "web.webinteraction.linkClicks", - web: { - webInteraction: { - name: linkName, - region: linkRegion, - type: linkType, - URL: linkUrl, - linkClicks: { - value: 1 - } - } - } - }, - data: {}, - clickedElement: targetElement - }; - - if (!onBeforeLinkClickSend) { - return options; - } - - var shouldEventBeTracked = onBeforeLinkClickSend(options); - - if (shouldEventBeTracked !== false) { - return options; - } - - logger.info("This link click event is not triggered because it was canceled in onBeforeLinkClickSend."); - return undefined; - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var urlStartsWithScheme = function urlStartsWithScheme(url) { - return url && /^[a-z0-9]+:\/\//i.test(url); - }; - - var getAbsoluteUrlFromAnchorElement = function getAbsoluteUrlFromAnchorElement(window, element) { - var loc = window.location; - var url = element.href ? element.href : ""; - var protocol = element.protocol, - host = element.host; - - if (!urlStartsWithScheme(url)) { - if (!protocol) { - protocol = loc.protocol ? loc.protocol : ""; - } - - protocol = protocol ? protocol + "//" : ""; - - if (!host) { - host = loc.host ? loc.host : ""; - } - - var path = ""; - - if (url.substring(0, 1) !== "/") { - var indx = loc.pathname.lastIndexOf("/"); - indx = indx < 0 ? 0 : indx; - path = loc.pathname.substring(0, indx); - } - - url = "" + protocol + host + path + "/" + url; - } - - return url; - }; - - var isSupportedAnchorElement = function isSupportedAnchorElement(element) { - if (element.href && (element.tagName === "A" || element.tagName === "AREA") && (!element.onclick || !element.protocol || element.protocol.toLowerCase().indexOf("javascript") < 0)) { - return true; - } - - return false; - }; - - var isDownloadLink = function isDownloadLink(downloadLinkQualifier, linkUrl, clickedObj) { - var re = new RegExp(downloadLinkQualifier); - return clickedObj.download ? true : re.test(linkUrl.toLowerCase()); - }; - - var isExitLink = function isExitLink(window, linkUrl) { - var currentHostname = window.location.hostname.toLowerCase(); - - if (linkUrl.toLowerCase().indexOf(currentHostname) >= 0) { - return false; - } - - return true; - }; - /** - * Reduces repeated whitespace within a string. Whitespace surrounding the string - * is trimmed and any occurrence of whitespace within the string is replaced with - * a single space. - * @param {string} str String to be formatted. - * @returns {string} Formatted string. - */ - - - var truncateWhiteSpace = function truncateWhiteSpace(str) { - return str && str.replace(/\s+/g, " ").trim(); - }; - - var determineLinkType = function determineLinkType(window, config, linkUrl, clickedObj) { - var linkType = "other"; - - if (isDownloadLink(config.downloadLinkQualifier, linkUrl, clickedObj)) { - linkType = "download"; - } else if (isExitLink(window, linkUrl)) { - linkType = "exit"; - } - - return linkType; - }; - - var findSupportedAnchorElement = function findSupportedAnchorElement(targetElement) { - var node = targetElement; - - while (node) { - if (isSupportedAnchorElement(node)) { - return node; - } - - node = node.parentNode; - } - - return null; - }; - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var unsupportedNodeNames = /^(SCRIPT|STYLE|LINK|CANVAS|NOSCRIPT|#COMMENT)$/i; - /** - * Determines if a node qualifies as a supported link text node. - * @param {*} node Node to determine support for. - * @returns {boolean} - */ - - var isSupportedTextNode = function isSupportedTextNode(node) { - if (node && node.nodeName) { - if (node.nodeName.match(unsupportedNodeNames)) { - return false; - } - } - - return true; - }; - /** - * Orders and returns specified node and its child nodes in arrays of supported - * and unsupported nodes. - * @param {*} node The node to extract supported and unsupported nodes from. - * @returns {{supportedNodes: Array, includesUnsupportedNodes: boolean}} Node support object. - */ - - - var extractSupportedNodes = function extractSupportedNodes(node) { - var supportedNodes = []; - var includesUnsupportedNodes = false; - - if (isSupportedTextNode(node)) { - supportedNodes.push(node); - - if (node.childNodes) { - var childNodes = Array.prototype.slice.call(node.childNodes); - childNodes.forEach(function (childNode) { - var nodes = extractSupportedNodes(childNode); - supportedNodes = supportedNodes.concat(nodes.supportedNodes); - includesUnsupportedNodes = includesUnsupportedNodes || nodes.includesUnsupportedNodes; - }); - } - } else { - includesUnsupportedNodes = true; - } - - return { - supportedNodes: supportedNodes, - includesUnsupportedNodes: includesUnsupportedNodes - }; - }; - /** - * Returns the value of a node attribute. - * @param {*} node The node holding the attribute. - * @param {string} attributeName The name of the attribute. - * @param {string} nodeName Optional node name constraint. - * @returns {string} Attribute value or undefined. - */ - - - var getNodeAttributeValue = function getNodeAttributeValue(node, attributeName, nodeName) { - var attributeValue; - - if (!nodeName || nodeName === node.nodeName.toUpperCase()) { - attributeValue = node.getAttribute(attributeName); - } - - return attributeValue; - }; - /** - * Extracts the children supported nodes attributes map - * @param {*} nodes The nodes array holding the children nodes. - * The returned map contains the supported not empty children attributes values. - * */ - - - var getChildrenAttributes = function getChildrenAttributes(nodes) { - var attributes = { - texts: [] - }; - nodes.supportedNodes.forEach(function (supportedNode) { - if (supportedNode.getAttribute) { - if (!attributes.alt) { - attributes.alt = truncateWhiteSpace(supportedNode.getAttribute("alt")); - } - - if (!attributes.title) { - attributes.title = truncateWhiteSpace(supportedNode.getAttribute("title")); - } - - if (!attributes.inputValue) { - attributes.inputValue = truncateWhiteSpace(getNodeAttributeValue(supportedNode, "value", "INPUT")); - } - - if (!attributes.imgSrc) { - attributes.imgSrc = truncateWhiteSpace(getNodeAttributeValue(supportedNode, "src", "IMG")); - } - } - - if (supportedNode.nodeValue) { - attributes.texts.push(supportedNode.nodeValue); - } - }); - return attributes; - }; - /** - * Extracts a link-name from a given node. - * - * The returned link-name is set to one of the following (in order of priority): - * - * 1. Clicked node innerText - * 2. Clicked node textContent - * 3. Clicked node and its child nodes nodeValue appended together. - * 4. Clicked node alt attribute or node descendant alt attribute. - * Whichever is found first. - * 5. Clicked node text attribute or node descendant text attribute. - * Whichever is found first. - * 6. Clicked node INPUT descendant value attribute. - * Whichever is found first. - * 7. Clicked node IMG descendant src attribute. - * Whichever is found first. - * - * @param {*} node The node to find link text for. - * @returns {string} link-name or an empty string if not link-name is found. - */ - - - var getLinkName = (function (node) { - var nodeText = truncateWhiteSpace(node.innerText || node.textContent); - var nodes = extractSupportedNodes(node); // if contains unsupported nodes we want children node attributes - - if (!nodeText || nodes.includesUnsupportedNodes) { - var attributesMap = getChildrenAttributes(nodes); - nodeText = truncateWhiteSpace(attributesMap.texts.join("")); - - if (!nodeText) { - nodeText = attributesMap.alt || attributesMap.title || attributesMap.inputValue || attributesMap.imgSrc; - } - } - - return nodeText || ""; - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var semanticElements = /^(HEADER|MAIN|FOOTER|NAV)$/i; - - var getAriaRegionLabel = function getAriaRegionLabel(node) { - var regionLabel; - - if (node.role === "region" && isNonEmptyString(node["aria-label"])) { - regionLabel = node["aria-label"]; - } - - return regionLabel; - }; - - var getSectionNodeName = function getSectionNodeName(node) { - var nodeName; - - if (node && node.nodeName) { - if (node.nodeName.match(semanticElements)) { - nodeName = node.nodeName; - } - } - - return nodeName; - }; - /** - * Extracts a node link-region. - * - * The link-region is determined by traversing up the DOM - * looking for a region that is determined in order of priority: - * - * 1. element.id - * 2. Aria region label - * 3. Semantic element name - * 4. BODY (if no other link-region is found). - * - * @param {*} node The node to find link region for. - * @returns {string} link-region. - */ - - - var getLinkRegion = (function (node) { - var linkParentNode = node.parentNode; - var regionName; - - while (linkParentNode) { - regionName = truncateWhiteSpace(linkParentNode.id || getAriaRegionLabel(linkParentNode) || getSectionNodeName(linkParentNode)); - - if (regionName) { - return regionName; - } - - linkParentNode = linkParentNode.parentNode; - } - - return "BODY"; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var _getLinkDetails = createGetLinkDetails({ - window: window, - getLinkName: getLinkName, - getLinkRegion: getLinkRegion, - getAbsoluteUrlFromAnchorElement: getAbsoluteUrlFromAnchorElement, - findSupportedAnchorElement: findSupportedAnchorElement, - determineLinkType: determineLinkType - }); - - var createActivityCollector = function createActivityCollector(_ref) { - var config = _ref.config, - eventManager = _ref.eventManager, - handleError = _ref.handleError, - logger = _ref.logger; - var linkClick = createLinkClick({ - getLinkDetails: _getLinkDetails, - config: config, - logger: logger - }); - return { - lifecycle: { - onComponentsRegistered: function onComponentsRegistered(tools) { - var lifecycle = tools.lifecycle; - attachClickActivityCollector({ - eventManager: eventManager, - lifecycle: lifecycle, - handleError: handleError - }); // TODO: createScrollActivityCollector ... - }, - onClick: function onClick(_ref2) { - var event = _ref2.event, - clickedElement = _ref2.clickedElement; - linkClick({ - targetElement: clickedElement, - event: event - }); - } - } - }; - }; - - createActivityCollector.namespace = "ActivityCollector"; - createActivityCollector.configValidators = configValidators$1; - - createActivityCollector.buildOnInstanceConfiguredExtraParams = function (_ref3) { - var config = _ref3.config, - logger = _ref3.logger; - return { - getLinkDetails: function getLinkDetails(targetElement) { - return _getLinkDetails({ - targetElement: targetElement, - config: config, - logger: logger - }); - } - }; - }; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var createResultLogMessage$1 = function createResultLogMessage(idSync, success) { - return "ID sync " + (success ? "succeeded" : "failed") + ": " + idSync.spec.url; - }; - - var injectProcessIdSyncs = (function (_ref) { - var fireReferrerHideableImage = _ref.fireReferrerHideableImage, - logger = _ref.logger; - return function (idSyncs) { - var urlIdSyncs = idSyncs.filter(function (idSync) { - return idSync.type === "url"; - }); - - if (!urlIdSyncs.length) { - return Promise.resolve(); - } - - return Promise.all(urlIdSyncs.map(function (idSync) { - return fireReferrerHideableImage(idSync.spec).then(function () { - logger.info(createResultLogMessage$1(idSync, true)); - }).catch(function () { - // We intentionally do not throw an error if id syncs fail. We - // consider it a non-critical failure and therefore do not want it to - // reject the promise handed back to the customer. - logger.error(createResultLogMessage$1(idSync, false)); - }); - })).then(noop$1); - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var configValidators = { - thirdPartyCookiesEnabled: boundBoolean().default(true), - idMigrationEnabled: boundBoolean().default(true) - }; - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - /** - * Verifies user provided event options. - * @param {*} options The user event options to validate - * @returns {*} Validated options - */ - - var getIdentityOptionsValidator = boundObjectOf({ - namespaces: boundArrayOf(boundLiteral("ECID")).nonEmpty().uniqueItems().default(["ECID"]), - edgeConfigOverrides: validateConfigOverride - }).noUnknownFields().default({ - namespaces: ["ECID"] - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - /** - * Verifies user provided event options. - * @param {*} options The user event options to validate - * @returns {*} Validated options - */ - - var appendIdentityToUrlOptionsValidator = boundObjectOf({ - url: boundString().required().nonEmpty(), - edgeConfigOverrides: validateConfigOverride - }).required().noUnknownFields(); - - /* - Copyright 2023 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createComponent$4 = (function (_ref) { - var addEcidQueryToPayload = _ref.addEcidQueryToPayload, - addQueryStringIdentityToPayload = _ref.addQueryStringIdentityToPayload, - ensureSingleIdentity = _ref.ensureSingleIdentity, - setLegacyEcid = _ref.setLegacyEcid, - handleResponseForIdSyncs = _ref.handleResponseForIdSyncs, - getEcidFromResponse = _ref.getEcidFromResponse, - getIdentity = _ref.getIdentity, - consent = _ref.consent, - appendIdentityToUrl = _ref.appendIdentityToUrl, - logger = _ref.logger; - var ecid; - var edge = {}; - return { - lifecycle: { - onBeforeRequest: function onBeforeRequest(_ref2) { - var request = _ref2.request, - onResponse = _ref2.onResponse, - onRequestFailure = _ref2.onRequestFailure; - // Querying the ECID on every request to be able to set the legacy cookie, and make it - // available for the `getIdentity` command. - addEcidQueryToPayload(request.getPayload()); - addQueryStringIdentityToPayload(request.getPayload()); - return ensureSingleIdentity({ - request: request, - onResponse: onResponse, - onRequestFailure: onRequestFailure - }); - }, - onResponse: function onResponse(_ref3) { - var response = _ref3.response; - - if (!ecid) { - ecid = getEcidFromResponse(response); // Only data collection calls will have an ECID in the response. - // https://jira.corp.adobe.com/browse/EXEG-1234 - - if (ecid) { - setLegacyEcid(ecid); - } - } // For sendBeacon requests, getEdge() will return {}, so we are using assign here - // so that sendBeacon requests don't override the edge info from before. - - - edge = reactorObjectAssign(edge, response.getEdge()); - return handleResponseForIdSyncs(response); - } - }, - commands: { - getIdentity: { - optionsValidator: getIdentityOptionsValidator, - run: function run(options) { - return consent.awaitConsent().then(function () { - return ecid ? undefined : getIdentity(options); - }).then(function () { - return { - identity: { - ECID: ecid - }, - edge: edge - }; - }); - } - }, - appendIdentityToUrl: { - optionsValidator: appendIdentityToUrlOptionsValidator, - run: function run(options) { - return consent.withConsent().then(function () { - return ecid ? undefined : getIdentity(options); - }).then(function () { - return { - url: appendIdentityToUrl(ecid, options.url) - }; - }).catch(function (error) { - logger.warn("Unable to append identity to url. " + error.message); - return options; - }); - } - } - } - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Handles migration of ECID to and from Visitor.js. - */ - var createLegacyIdentity = (function (_ref) { - var config = _ref.config, - getEcidFromVisitor = _ref.getEcidFromVisitor, - apexDomain = _ref.apexDomain, - isPageSsl = _ref.isPageSsl, - cookieJar = _ref.cookieJar; - var idMigrationEnabled = config.idMigrationEnabled, - orgId = config.orgId; - var amcvCookieName = "AMCV_" + orgId; - - var getEcidFromLegacyCookies = function getEcidFromLegacyCookies() { - var ecid = null; - var secidCookieName = "s_ecid"; - var legacyEcidCookieValue = cookieJar.get(secidCookieName) || cookieJar.get(amcvCookieName); - - if (legacyEcidCookieValue) { - var reg = /(^|\|)MCMID\|(\d+)($|\|)/; - var matches = legacyEcidCookieValue.match(reg); - - if (matches) { - // Destructuring arrays breaks in IE - ecid = matches[2]; - } - } - - return ecid; - }; - - return { - getEcid: function getEcid() { - if (idMigrationEnabled) { - var ecid = getEcidFromLegacyCookies(); - - if (ecid) { - return Promise.resolve(ecid); - } - - return getEcidFromVisitor(); - } - - return Promise.resolve(); - }, - setEcid: function setEcid(ecid) { - if (idMigrationEnabled && getEcidFromLegacyCookies() !== ecid) { - var extraOptions = isPageSsl ? { - sameSite: "none", - secure: true - } : {}; - cookieJar.set(amcvCookieName, "MCMID|" + ecid, _objectSpread2({ - domain: apexDomain, - // Without `expires` this will be a session cookie. - expires: 390 - }, extraOptions)); - } - } - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var awaitVisitorOptIn = (function (_ref) { - var logger = _ref.logger; - return new Promise(function (resolve, reject) { - if (isObject(window.adobe) && isObject(window.adobe.optIn)) { - var optInOld = window.adobe.optIn; - logger.info("Delaying request while waiting for legacy opt-in to let Visitor retrieve ECID from server."); - optInOld.fetchPermissions(function () { - if (optInOld.isApproved([optInOld.Categories.ECID])) { - logger.info("Received legacy opt-in approval to let Visitor retrieve ECID from server."); - resolve(); - } else { - reject(new Error("Legacy opt-in was declined.")); - } - }, true); - } else { - resolve(); - } - }); - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var getVisitor = (function (window) { - var Visitor = window.Visitor; - return isFunction(Visitor) && isFunction(Visitor.getInstance) && Visitor; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectGetEcidFromVisitor = (function (_ref) { - var logger = _ref.logger, - orgId = _ref.orgId, - awaitVisitorOptIn = _ref.awaitVisitorOptIn; - return function () { - var Visitor = getVisitor(window); - - if (Visitor) { - // Need to explicitly wait for optIn because visitor will call callback - // with invalid values prior to optIn being approved - return awaitVisitorOptIn({ - logger: logger - }).then(function () { - logger.info("Delaying request while using Visitor to retrieve ECID from server."); - return new Promise(function (resolve) { - var visitor = Visitor.getInstance(orgId, {}); - visitor.getMarketingCloudVisitorID(function (ecid) { - logger.info("Resuming previously delayed request that was waiting for ECID from Visitor."); - resolve(ecid); - }, true); - }); - }).catch(function (error) { - // If consent was denied, get the ECID from experience edge. OptIn and AEP Web SDK - // consent should operate independently, but during id migration AEP Web SDK needs - // to wait for optIn object consent resolution so that only one ECID is generated. - if (error) { - logger.info(error.message + ", retrieving ECID from experience edge"); - } else { - logger.info("An error occurred while obtaining the ECID from Visitor."); - } - }); - } - - return Promise.resolve(); - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectHandleResponseForIdSyncs = (function (_ref) { - var processIdSyncs = _ref.processIdSyncs; - return function (response) { - return processIdSyncs(response.getPayloadsByType("identity:exchange")); - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - // TO-DOCUMENT: We queue subsequent requests until we have an identity cookie. - var injectEnsureSingleIdentity = (function (_ref) { - var doesIdentityCookieExist = _ref.doesIdentityCookieExist, - setDomainForInitialIdentityPayload = _ref.setDomainForInitialIdentityPayload, - addLegacyEcidToPayload = _ref.addLegacyEcidToPayload, - awaitIdentityCookie = _ref.awaitIdentityCookie, - logger = _ref.logger; - var obtainedIdentityPromise; - - var allowRequestToGoWithoutIdentity = function allowRequestToGoWithoutIdentity(request) { - setDomainForInitialIdentityPayload(request); - return addLegacyEcidToPayload(request.getPayload()); - }; - /** - * Ensures that if no identity cookie exists, we only let one request at a - * time without an identity until its response returns. In the meantime, - * we queue all other requests, otherwise the requests could result in - * multiple ECIDs being minted for the user. Once we get an identity - * cookie, we can let the queued requests be sent all at once, since they - * will have the newly minted ECID. - * - * Konductor should make every effort to return an identity, but in - * certain scenarios it may not. For example, in cases where the - * request does not match what Konductor is expecting (ie 400s). - * In cases where Konductor does not set an identity, there should be - * no events recorded so we don't need to worry about multiple ECIDs - * being minted for each user. - * - * The reason we allow for multiple sequential requests to be sent without - * an identity is to prevent a single malformed request causing all other - * requests to never send. - */ - - - return function (_ref2) { - var request = _ref2.request, - onResponse = _ref2.onResponse, - onRequestFailure = _ref2.onRequestFailure; - - if (doesIdentityCookieExist()) { - request.setIsIdentityEstablished(); - return Promise.resolve(); - } - - if (obtainedIdentityPromise) { - // We don't have an identity cookie, but at least one request has - // been sent to get it. Konductor may set the identity cookie in the - // response. We will hold up this request until the last request - // requiring identity returns and awaitIdentityCookie confirms the - // identity was set. - logger.info("Delaying request while retrieving ECID from server."); - var previousObtainedIdentityPromise = obtainedIdentityPromise; // This promise resolves when we have an identity cookie. Additional - // requests are chained together so that only one is sent at a time - // until we have the identity cookie. - - obtainedIdentityPromise = previousObtainedIdentityPromise.catch(function () { - return awaitIdentityCookie({ - onResponse: onResponse, - onRequestFailure: onRequestFailure - }); - }); // When this returned promise resolves, the request will go out. - - return previousObtainedIdentityPromise.then(function () { - logger.info("Resuming previously delayed request."); - request.setIsIdentityEstablished(); - }) // If Konductor did not set the identity cookie on the previous - // request, then awaitIdentityCookie will reject its promise. - // Catch the rejection here and allow this request to go out. - .catch(function () { - return allowRequestToGoWithoutIdentity(request); - }); - } // For Alloy+Konductor communication to be as robust as possible and - // to ensure we don't mint new ECIDs for requests that would otherwise - // be sent in parallel, we'll let this request go out to fetch the - // cookie - - - obtainedIdentityPromise = awaitIdentityCookie({ - onResponse: onResponse, - onRequestFailure: onRequestFailure - }); - return allowRequestToGoWithoutIdentity(request); - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var ecidNamespace = "ECID"; - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var addEcidQueryToPayload = (function (payload) { - payload.mergeQuery({ - identity: { - fetch: [ecidNamespace] - } - }); - }); - - var matchUserAgent = function matchUserAgent(regexs) { - return function (userAgent) { - var keys = Object.keys(regexs); - - for (var i = 0; i < keys.length; i += 1) { - var key = keys[i]; - var regex = regexs[key]; - - if (regex.test(userAgent)) { - return key; - } - } - - return UNKNOWN; - }; - }; - - var getBrowser = memoize(function (window) { - var _matchUserAgent; - - return matchUserAgent((_matchUserAgent = {}, _defineProperty(_matchUserAgent, EDGE$1, /Edge\/([0-9\._]+)/), _defineProperty(_matchUserAgent, EDGE_CHROMIUM, /Edg\/([0-9\.]+)/), _defineProperty(_matchUserAgent, CHROME, /(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/), _defineProperty(_matchUserAgent, FIREFOX, /Firefox\/([0-9\.]+)(?:\s|$)/), _defineProperty(_matchUserAgent, IE, /Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/), _defineProperty(_matchUserAgent, SAFARI, /Version\/([0-9\._]+).*Safari/), _matchUserAgent))(window.navigator.userAgent); - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectSetDomainForInitialIdentityPayload = (function (_ref) { - var thirdPartyCookiesEnabled = _ref.thirdPartyCookiesEnabled, - areThirdPartyCookiesSupportedByDefault = _ref.areThirdPartyCookiesSupportedByDefault; - return function (request) { - if (thirdPartyCookiesEnabled && areThirdPartyCookiesSupportedByDefault(getBrowser(window))) { - // If third-party cookies are enabled by the customer and - // supported by the browser, we will send the request to a - // a third-party identification domain that allows for more accurate - // identification of the user through use of a third-party cookie. - // If we have an identity to migrate, we still want to hit the - // third-party identification domain because the third-party identification - // domain will use our ECID to set the third-party cookie if the third-party - // cookie isn't already set, which provides for better cross-domain - // identification for future requests. - request.setUseIdThirdPartyDomain(); - } - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectAddLegacyEcidToPayload = (function (_ref) { - var getLegacyEcid = _ref.getLegacyEcid, - addEcidToPayload = _ref.addEcidToPayload; - return function (payload) { - if (payload.hasIdentity(ecidNamespace)) { - // don't get the legacy identity if we already have the query string identity or if - // the user specified it in the identity map - return Promise.resolve(); - } - - return getLegacyEcid().then(function (ecidToMigrate) { - if (ecidToMigrate) { - addEcidToPayload(payload, ecidToMigrate); - } - }); - }; - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var queryStringIdentityParam = "adobe_mc"; - - var LINK_TTL_SECONDS = 300; // 5 minute link time to live - - var injectAddQueryStringIdentityToPayload = (function (_ref) { - var locationSearch = _ref.locationSearch, - dateProvider = _ref.dateProvider, - orgId = _ref.orgId, - logger = _ref.logger; - return function (payload) { - if (payload.hasIdentity(ecidNamespace)) { - // don't overwrite a user provided ecid identity - return; - } - - var parsedQueryString = reactorQueryString.parse(locationSearch); - var queryStringValue = parsedQueryString[queryStringIdentityParam]; - - if (queryStringValue === undefined) { - return; - } - - var properties = queryStringValue.split("|").reduce(function (memo, keyValue) { - var _keyValue$split = keyValue.split("="), - _keyValue$split2 = _slicedToArray(_keyValue$split, 2), - key = _keyValue$split2[0], - value = _keyValue$split2[1]; - - memo[key] = value; - return memo; - }, {}); // We are using MCMID and MCORGID to be compatible with Visitor. - - var ts = parseInt(properties.TS, 10); - var mcmid = properties.MCMID; - var mcorgid = decodeURIComponent(properties.MCORGID); - - if ( // When TS is not specified or not a number, the following inequality returns false. - // All inequalities with NaN variables are false. - dateProvider().getTime() / 1000 <= ts + LINK_TTL_SECONDS && mcorgid === orgId && mcmid) { - logger.info("Found valid ECID identity " + mcmid + " from the adobe_mc query string parameter."); - payload.addIdentity(ecidNamespace, { - id: mcmid - }); - } else { - logger.info("Detected invalid or expired adobe_mc query string parameter."); - } - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var addEcidToPayload = (function (payload, ecid) { - payload.addIdentity(ecidNamespace, { - id: ecid - }); - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectAwaitIdentityCookie = (function (_ref) { - var doesIdentityCookieExist = _ref.doesIdentityCookieExist, - orgId = _ref.orgId; - - /** - * Returns a promise that will be resolved once an identity cookie exists. - * If an identity cookie doesn't already exist, it should always exist after - * the first response. - */ - return function (_ref2) { - var onResponse = _ref2.onResponse, - onRequestFailure = _ref2.onRequestFailure; - return new Promise(function (resolve, reject) { - onResponse(function () { - if (doesIdentityCookieExist()) { - resolve(); - } else { - // This logic assumes that the code setting the cookie is working as expected and that - // the cookie was missing from the response. - var noIdentityCookieError = new Error("An identity was not set properly. Please verify that the org ID " + orgId + " configured in Alloy matches the org ID specified in the edge configuration."); // Rejecting the promise will reject commands that were queued - // by the Identity component while waiting on the response to - // the initial request. - - reject(noIdentityCookieError); // Throwing an error will reject the event command that initiated - // the request. - - throw noIdentityCookieError; - } - }); - onRequestFailure(function () { - if (doesIdentityCookieExist()) { - resolve(); - } else { - // The error from the request failure will be logged separately. Rejecting this here - // will tell ensureSingleIdentity to send the next request without identity - reject(new Error("No identity was set on response.")); - } - }); - }); - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var getEcidFromResponse = (function (response) { - var identityResultPayloads = response.getPayloadsByType("identity:result"); - var ecidPayload = find(identityResultPayloads, function (payload) { - return payload.namespace && payload.namespace.code === ecidNamespace; - }); - return ecidPayload ? ecidPayload.id : undefined; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createGetIdentity = (function (_ref) { - var sendEdgeNetworkRequest = _ref.sendEdgeNetworkRequest, - createIdentityRequestPayload = _ref.createIdentityRequestPayload, - createIdentityRequest = _ref.createIdentityRequest, - globalConfigOverrides = _ref.globalConfigOverrides; - return function () { - var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, - namespaces = _ref2.namespaces, - localConfigOverrides = _ref2.edgeConfigOverrides; - - var payload = createIdentityRequestPayload(namespaces); - var request = createIdentityRequest(payload); // merge the configurations, but give preference to the command-local configs - - payload.mergeConfigOverride(globalConfigOverrides); - payload.mergeConfigOverride(localConfigOverrides); - return sendEdgeNetworkRequest({ - request: request - }); - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createAddIdentity = (function (content) { - return function (namespaceCode, identity) { - content.xdm = content.xdm || {}; - content.xdm.identityMap = content.xdm.identityMap || {}; - content.xdm.identityMap[namespaceCode] = content.xdm.identityMap[namespaceCode] || []; - content.xdm.identityMap[namespaceCode].push(identity); - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var createRequest = (function (options) { - var payload = options.payload, - _getAction = options.getAction, - _getUseSendBeacon = options.getUseSendBeacon; - var id = v4_1(); - var shouldUseThirdPartyDomain = false; - var isIdentityEstablished = false; - return { - getId: function getId() { - return id; - }, - getPayload: function getPayload() { - return payload; - }, - getAction: function getAction() { - return _getAction({ - isIdentityEstablished: isIdentityEstablished - }); - }, - getUseSendBeacon: function getUseSendBeacon() { - return _getUseSendBeacon({ - isIdentityEstablished: isIdentityEstablished - }); - }, - getUseIdThirdPartyDomain: function getUseIdThirdPartyDomain() { - return shouldUseThirdPartyDomain; - }, - setUseIdThirdPartyDomain: function setUseIdThirdPartyDomain() { - shouldUseThirdPartyDomain = true; - }, - setIsIdentityEstablished: function setIsIdentityEstablished() { - isIdentityEstablished = true; - } - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createDataCollectionRequest = (function (dataCollectionRequestPayload) { - var getUseSendBeacon = function getUseSendBeacon(_ref) { - var isIdentityEstablished = _ref.isIdentityEstablished; - // When the document may be unloading, we still hit the interact endpoint - // using fetch if an identity has not been established. If we were instead - // to hit the collect endpoint using sendBeacon in this case, one of three - // things would occur: - // - // 1. The document ultimately isn't unloaded and Alloy receives an empty - // response back from the collect endpoint, resulting in an error being - // thrown by Alloy because we weren't able to establish an identity. - // This is bad. - // 2. The document is unloaded, but Alloy receives the empty - // response back from the collect endpoint before navigation is completed, - // resulting in an error being thrown by Alloy because we weren't able to - // establish an identity. This is bad. - // 3. The document is unloaded and Alloy does not receive the empty response - // back from the collect endpoint before navigation is completed. No error - // will be thrown, but no identity was established either. This is okay, - // though no identity was established. - // - // By hitting the interact endpoint using fetch, one of the three things - // would occur: - // - // 1. The document ultimately isn't unloaded and Alloy receives a - // response with an identity back from the interact endpoint. No - // error will be thrown and an identity is established. This is good. - // 2. The document is unloaded and Alloy receives a response with an - // identity back from the interact endpoint before navigation is completed. - // No error will be thrown and an identity is established. This is good. - // 3. The document is unloaded and Alloy does not receive the empty response - // back from the collect endpoint before navigation is completed. In this - // case, no error is thrown, but no identity was established and it's - // more likely that the request never makes it to the server because we're - // using fetch instead of sendBeacon. - // - // The second approach seemed preferable. - return dataCollectionRequestPayload.getDocumentMayUnload() && isIdentityEstablished; - }; - - return createRequest({ - payload: dataCollectionRequestPayload, - getAction: function getAction(_ref2) { - var isIdentityEstablished = _ref2.isIdentityEstablished; - return getUseSendBeacon({ - isIdentityEstablished: isIdentityEstablished - }) ? "collect" : "interact"; - }, - getUseSendBeacon: getUseSendBeacon - }); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - // request payloads share. - - var createRequestPayload = (function (options) { - var content = options.content, - addIdentity = options.addIdentity, - hasIdentity = options.hasIdentity; - - var _mergeConfigOverride = createMerger(content, "meta.configOverrides"); - - return { - mergeMeta: createMerger(content, "meta"), - mergeState: createMerger(content, "meta.state"), - mergeQuery: createMerger(content, "query"), - mergeConfigOverride: function mergeConfigOverride(updates) { - return _mergeConfigOverride(prepareConfigOverridesForEdge(updates)); - }, - addIdentity: addIdentity, - hasIdentity: hasIdentity, - toJSON: function toJSON() { - return content; - } - }; - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createHasIdentity = (function (content) { - return function (namespaceCode) { - return (content.xdm && content.xdm.identityMap && content.xdm.identityMap[namespaceCode]) !== undefined; - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createDataCollectionRequestPayload = (function () { - var content = {}; - var payload = createRequestPayload({ - content: content, - addIdentity: createAddIdentity(content), - hasIdentity: createHasIdentity(content) - }); - - payload.addEvent = function (event) { - content.events = content.events || []; - content.events.push(event); - }; - - payload.getDocumentMayUnload = function () { - return (content.events || []).some(function (event) { - return event.getDocumentMayUnload(); - }); - }; - - return payload; - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var ASSURANCE_VALIDATION_SESSION_URL_PARAM = "adb_validation_sessionid"; - var ASSURANCE_VALIDATION_NAMESPACE = "validation."; - var CLIENT_ID = "clientId"; - - var getOrCreateAssuranceClientId = function getOrCreateAssuranceClientId(storage) { - var clientId = storage.persistent.getItem(CLIENT_ID); - - if (!clientId) { - clientId = v4_1(); - storage.persistent.setItem(CLIENT_ID, clientId); - } - - return clientId; - }; - - var createGetAssuranceValidationTokenParams = (function (_ref) { - var window = _ref.window, - createNamespacedStorage = _ref.createNamespacedStorage; - var storage = createNamespacedStorage(ASSURANCE_VALIDATION_NAMESPACE); - return function () { - var parsedQuery = reactorQueryString.parse(window.location.search); - var validationSessionId = parsedQuery[ASSURANCE_VALIDATION_SESSION_URL_PARAM]; - - if (!validationSessionId) { - return ""; - } - - var clientId = getOrCreateAssuranceClientId(storage); - var validationToken = validationSessionId + "|" + clientId; - return "&" + reactorQueryString.stringify({ - adobeAepValidationToken: validationToken - }); - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createIdentityRequest = (function (identityRequestPayload) { - return createRequest({ - payload: identityRequestPayload, - getAction: function getAction() { - return "identity/acquire"; - }, - getUseSendBeacon: function getUseSendBeacon() { - return false; - } - }); - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createIdentityRequestPayload = (function (namespaces) { - var content = { - query: { - identity: { - fetch: namespaces - } - } - }; - return createRequestPayload({ - content: content, - addIdentity: createAddIdentity(content), - hasIdentity: createHasIdentity(content) - }); - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var URL_REGEX = /^([^?#]*)(\??[^#]*)(#?.*)$/; - - var getSeparator = function getSeparator(queryString) { - if (queryString === "") { - return "?"; - } - - if (queryString === "?") { - return ""; - } - - return "&"; - }; - - var injectAppendIdentityToUrl = (function (_ref) { - var dateProvider = _ref.dateProvider, - orgId = _ref.orgId; - return function (ecid, url) { - var ts = Math.round(dateProvider().getTime() / 1000); - var adobemc = encodeURIComponent("TS=" + ts + "|MCMID=" + ecid + "|MCORGID=" + encodeURIComponent(orgId)); - - var _url$match = url.match(URL_REGEX), - _url$match2 = _slicedToArray(_url$match, 4), - location = _url$match2[1], - queryString = _url$match2[2], - fragment = _url$match2[3]; - - var separator = getSeparator(queryString); - return "" + location + queryString + separator + "adobe_mc=" + adobemc + fragment; - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var createIdentity = function createIdentity(_ref) { - var config = _ref.config, - logger = _ref.logger, - consent = _ref.consent, - fireReferrerHideableImage = _ref.fireReferrerHideableImage, - sendEdgeNetworkRequest = _ref.sendEdgeNetworkRequest, - apexDomain = _ref.apexDomain; - var orgId = config.orgId, - thirdPartyCookiesEnabled = config.thirdPartyCookiesEnabled, - globalConfigOverrides = config.edgeConfigOverrides; - var getEcidFromVisitor = injectGetEcidFromVisitor({ - logger: logger, - orgId: orgId, - awaitVisitorOptIn: awaitVisitorOptIn - }); - var loggingCookieJar = createLoggingCookieJar({ - logger: logger, - cookieJar: cookieJar - }); - var legacyIdentity = createLegacyIdentity({ - config: config, - getEcidFromVisitor: getEcidFromVisitor, - apexDomain: apexDomain, - cookieJar: loggingCookieJar, - isPageSsl: window.location.protocol === "https:" - }); - var doesIdentityCookieExist = injectDoesIdentityCookieExist({ - orgId: orgId - }); - var getIdentity = createGetIdentity({ - sendEdgeNetworkRequest: sendEdgeNetworkRequest, - createIdentityRequestPayload: createIdentityRequestPayload, - createIdentityRequest: createIdentityRequest, - globalConfigOverrides: globalConfigOverrides - }); - var setDomainForInitialIdentityPayload = injectSetDomainForInitialIdentityPayload({ - thirdPartyCookiesEnabled: thirdPartyCookiesEnabled, - areThirdPartyCookiesSupportedByDefault: areThirdPartyCookiesSupportedByDefault - }); - var addLegacyEcidToPayload = injectAddLegacyEcidToPayload({ - getLegacyEcid: legacyIdentity.getEcid, - addEcidToPayload: addEcidToPayload - }); - var addQueryStringIdentityToPayload = injectAddQueryStringIdentityToPayload({ - locationSearch: window.document.location.search, - dateProvider: function dateProvider() { - return new Date(); - }, - orgId: orgId, - logger: logger - }); - var awaitIdentityCookie = injectAwaitIdentityCookie({ - doesIdentityCookieExist: doesIdentityCookieExist, - orgId: orgId - }); - var ensureSingleIdentity = injectEnsureSingleIdentity({ - doesIdentityCookieExist: doesIdentityCookieExist, - setDomainForInitialIdentityPayload: setDomainForInitialIdentityPayload, - addLegacyEcidToPayload: addLegacyEcidToPayload, - awaitIdentityCookie: awaitIdentityCookie, - logger: logger - }); - var processIdSyncs = injectProcessIdSyncs({ - fireReferrerHideableImage: fireReferrerHideableImage, - logger: logger - }); - var handleResponseForIdSyncs = injectHandleResponseForIdSyncs({ - processIdSyncs: processIdSyncs - }); - var appendIdentityToUrl = injectAppendIdentityToUrl({ - dateProvider: function dateProvider() { - return new Date(); - }, - orgId: orgId, - globalConfigOverrides: globalConfigOverrides - }); - return createComponent$4({ - addEcidQueryToPayload: addEcidQueryToPayload, - addQueryStringIdentityToPayload: addQueryStringIdentityToPayload, - ensureSingleIdentity: ensureSingleIdentity, - setLegacyEcid: legacyIdentity.setEcid, - handleResponseForIdSyncs: handleResponseForIdSyncs, - getEcidFromResponse: getEcidFromResponse, - getIdentity: getIdentity, - consent: consent, - appendIdentityToUrl: appendIdentityToUrl, - logger: logger, - config: config - }); - }; - - createIdentity.namespace = "Identity"; - createIdentity.configValidators = configValidators; - - var createResultLogMessage = function createResultLogMessage(urlDestination, success) { - return "URL destination " + (success ? "succeeded" : "failed") + ": " + urlDestination.spec.url; - }; - - var injectProcessDestinations = (function (_ref) { - var fireReferrerHideableImage = _ref.fireReferrerHideableImage, - logger = _ref.logger, - cookieJar = _ref.cookieJar, - isPageSsl = _ref.isPageSsl; - var extraCookieOptions = isPageSsl ? { - sameSite: "none", - secure: true - } : {}; - - var processCookies = function processCookies(destinations) { - var cookieDestinations = destinations.filter(function (dest) { - return dest.type === "cookie"; - }); - cookieDestinations.forEach(function (dest) { - var _dest$spec = dest.spec, - name = _dest$spec.name, - value = _dest$spec.value, - domain = _dest$spec.domain, - ttlDays = _dest$spec.ttlDays; - cookieJar.set(name, value || "", _objectSpread2({ - domain: domain || "", - expires: ttlDays || 10 - }, extraCookieOptions)); - }); - }; - - var processUrls = function processUrls(destinations) { - var urlDestinations = destinations.filter(function (dest) { - return dest.type === "url"; - }); - return Promise.all(urlDestinations.map(function (urlDestination) { - return fireReferrerHideableImage(urlDestination.spec).then(function () { - logger.info(createResultLogMessage(urlDestination, true)); - }).catch(function () {// We intentionally do not throw an error if destinations fail. We - // consider it a non-critical failure and therefore do not want it to - // reject the promise handed back to the customer. - }); - })).then(noop$1); - }; - - return function (destinations) { - processCookies(destinations); - return processUrls(destinations); - }; - }); - - /* - Copyright 2021 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectProcessResponse = (function (_ref) { - var processDestinations = _ref.processDestinations; - - var processPushDestinations = function processPushDestinations(_ref2) { - var response = _ref2.response; - var destinations = response.getPayloadsByType("activation:push"); - return processDestinations(destinations); - }; - - var retrievePullDestinations = function retrievePullDestinations(_ref3) { - var response = _ref3.response; - return { - destinations: response.getPayloadsByType("activation:pull") - }; - }; - - return function (_ref4) { - var response = _ref4.response; - return processPushDestinations({ - response: response - }).then(function () { - return retrievePullDestinations({ - response: response - }); - }); - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var createAudiences = function createAudiences(_ref) { - var logger = _ref.logger, - fireReferrerHideableImage = _ref.fireReferrerHideableImage; - // we override the js-cookie converter to encode the cookie value similar on how it is in DIL (PDCL-10238) - var cookieJarWithEncoding = cookieJar.withConverter({ - write: function write(value) { - return encodeURIComponent(value); - } - }); - var loggingCookieJar = createLoggingCookieJar({ - logger: logger, - cookieJar: cookieJarWithEncoding - }); - var processDestinations = injectProcessDestinations({ - fireReferrerHideableImage: fireReferrerHideableImage, - logger: logger, - cookieJar: loggingCookieJar, - isPageSsl: window.location.protocol === "https:" - }); - var processResponse = injectProcessResponse({ - processDestinations: processDestinations - }); - return { - lifecycle: { - onResponse: processResponse - }, - commands: {} - }; - }; - - createAudiences.namespace = "Audiences"; - createAudiences.configValidators = {}; - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var WEB = "web"; - var WEBAPP = "webapp"; - var SURFACE_TYPE_DELIMITER = "://"; - var FRAGMENT_DELIMITER = "#"; - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var SURFACE_REGEX = /^(\w+):\/\/([^/#]+)(\/[^#]*)?(#.*)?$/; - var AUTHORITY_REGEX = /^(?:.*@)?(?:[a-z\d\u00a1-\uffff.-]+|\[[a-f\d:]+])(?::\d+)?$/; - var PATH_REGEX = /^\/(?:[/\w\u00a1-\uffff-.~]|%[a-fA-F\d]{2})*$/; - var FRAGMENT_REGEX = /^#(?:[/\w\u00a1-\uffff-.~]|%[a-fA-F\d]{2})+$/; - - var normalizePath = function normalizePath() { - var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "/"; - var end = path.length; - - while (end > 0 && "/".indexOf(path.charAt(end - 1)) !== -1) { - end -= 1; - } - - return path.substring(0, end) || "/"; - }; - - var getSurfaceType = function getSurfaceType(surfaceTypeMatch) { - return isNonEmptyString(surfaceTypeMatch) ? surfaceTypeMatch.toLowerCase() : ""; - }; - - var getAuthority = function getAuthority(authorityMatch) { - return isNonEmptyString(authorityMatch) ? authorityMatch.toLowerCase() : ""; - }; - - var getPath = function getPath(pathMatch) { - return isNonEmptyString(pathMatch) ? normalizePath(pathMatch) : "/"; - }; - - var parseSurface = function parseSurface(surfaceString) { - var matched = surfaceString.match(SURFACE_REGEX); - return matched ? { - surfaceType: getSurfaceType(matched[1]), - authority: getAuthority(matched[2]), - path: getPath(matched[3]), - fragment: matched[4] - } : null; - }; - - var stringifySurface = function stringifySurface(surface) { - return "" + surface.surfaceType + SURFACE_TYPE_DELIMITER + surface.authority + (surface.path || "") + (surface.fragment || ""); - }; - - var buildPageSurface = function buildPageSurface(getPageLocation) { - var location = getPageLocation(); - var host = location.host.toLowerCase(); - var path = location.pathname; - return WEB + SURFACE_TYPE_DELIMITER + host + normalizePath(path); - }; - - var expandFragmentSurface = function expandFragmentSurface(surface, getPageLocation) { - return startsWith(surface, FRAGMENT_DELIMITER) ? buildPageSurface(getPageLocation) + surface : surface; - }; - - var validateSurface = function validateSurface(surface, getPageLocation, logger) { - var invalidateSurface = function invalidateSurface(validationError) { - logger.warn(validationError); - return null; - }; - - if (!isNonEmptyString(surface)) { - return invalidateSurface("Invalid surface: " + surface); - } - - var expanded = expandFragmentSurface(surface, getPageLocation); - var parsed = parseSurface(expanded); - - if (parsed === null) { - return invalidateSurface("Invalid surface: " + surface); - } - - if (!includes([WEB, WEBAPP], parsed.surfaceType)) { - return invalidateSurface("Unsupported surface type " + parsed.surfaceType + " in surface: " + surface); - } - - if (!parsed.authority || !AUTHORITY_REGEX.test(parsed.authority)) { - return invalidateSurface("Invalid authority " + parsed.authority + " in surface: " + surface); - } - - if (parsed.path && !PATH_REGEX.test(parsed.path)) { - return invalidateSurface("Invalid path " + parsed.path + " in surface: " + surface); - } - - if (parsed.fragment && !FRAGMENT_REGEX.test(parsed.fragment)) { - return invalidateSurface("Invalid fragment " + parsed.fragment + " in surface: " + surface); - } - - return parsed; - }; - - var isPageWideSurface = function isPageWideSurface(scope) { - return !!scope && scope.indexOf(WEB + SURFACE_TYPE_DELIMITER) === 0 && scope.indexOf(FRAGMENT_DELIMITER) === -1; - }; - var normalizeSurfaces = function normalizeSurfaces() { - var surfaces = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - var getPageLocation = arguments.length > 1 ? arguments[1] : undefined; - var logger = arguments.length > 2 ? arguments[2] : undefined; - return surfaces.map(function (surface) { - return validateSurface(surface, getPageLocation, logger); - }).filter(function (surface) { - return !isNil(surface); - }).map(stringifySurface); - }; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var PAGE_WIDE_SCOPE = "__view__"; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var DEFAULT_CONTENT_ITEM = "https://ns.adobe.com/personalization/default-content-item"; - var DOM_ACTION = "https://ns.adobe.com/personalization/dom-action"; - var HTML_CONTENT_ITEM = "https://ns.adobe.com/personalization/html-content-item"; - var JSON_CONTENT_ITEM = "https://ns.adobe.com/personalization/json-content-item"; - var REDIRECT_ITEM = "https://ns.adobe.com/personalization/redirect-item"; - var MEASUREMENT_SCHEMA = "https://ns.adobe.com/personalization/measurement"; - - var addPageWideScope = function addPageWideScope(scopes) { - if (!includes(scopes, PAGE_WIDE_SCOPE)) { - scopes.push(PAGE_WIDE_SCOPE); - } - }; - - var addPageSurface = function addPageSurface(surfaces, getPageLocation) { - var pageSurface = buildPageSurface(getPageLocation); - - if (!includes(surfaces, pageSurface)) { - surfaces.push(pageSurface); - } - }; - - var dedupe = function dedupe(array) { - return array.filter(function (item, pos) { - return array.indexOf(item) === pos; - }); - }; - - var createPersonalizationDetails = (function (_ref) { - var getPageLocation = _ref.getPageLocation, - renderDecisions = _ref.renderDecisions, - decisionScopes = _ref.decisionScopes, - personalization = _ref.personalization, - event = _ref.event, - viewCache = _ref.viewCache, - logger = _ref.logger; - var viewName = event.getViewName(); - return { - isRenderDecisions: function isRenderDecisions() { - return renderDecisions; - }, - getViewName: function getViewName() { - return viewName; - }, - hasScopes: function hasScopes() { - return decisionScopes.length > 0 || isNonEmptyArray(personalization.decisionScopes); - }, - hasSurfaces: function hasSurfaces() { - return isNonEmptyArray(personalization.surfaces); - }, - hasViewName: function hasViewName() { - return isNonEmptyString(viewName); - }, - createQueryDetails: function createQueryDetails() { - var scopes = _toConsumableArray(decisionScopes); - - if (isNonEmptyArray(personalization.decisionScopes)) { - scopes.push.apply(scopes, _toConsumableArray(personalization.decisionScopes)); - } - - var eventSurfaces = normalizeSurfaces(personalization.surfaces, getPageLocation, logger); - - if (!this.isCacheInitialized()) { - addPageWideScope(scopes); - addPageSurface(eventSurfaces, getPageLocation); - } - - var schemas = [DEFAULT_CONTENT_ITEM, HTML_CONTENT_ITEM, JSON_CONTENT_ITEM, REDIRECT_ITEM]; - - if (includes(scopes, PAGE_WIDE_SCOPE)) { - schemas.push(DOM_ACTION); - } - - return { - schemas: schemas, - decisionScopes: dedupe(scopes), - surfaces: dedupe(eventSurfaces) - }; - }, - isCacheInitialized: function isCacheInitialized() { - return viewCache.isInitialized(); - }, - shouldFetchData: function shouldFetchData() { - return this.hasScopes() || this.hasSurfaces() || !this.isCacheInitialized(); - }, - shouldUseCachedData: function shouldUseCachedData() { - return this.hasViewName() && this.isCacheInitialized(); - } - }; - }); - - /* - Copyright 2023 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var AUTHORING_ENABLED = "Rendering is disabled for authoring mode."; - var REDIRECT_EXECUTION_ERROR = "An error occurred while executing the redirect offer."; - - /* - Copyright 2023 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var EMPTY_PROPOSITIONS = { - propositions: [] - }; - var validateApplyPropositionsOptions = (function (_ref) { - var logger = _ref.logger, - options = _ref.options; - var applyPropositionsOptionsValidator = boundObjectOf({ - propositions: boundArrayOf(boundObjectOf(boundAnything())).nonEmpty(), - metadata: boundObjectOf(boundAnything()) - }).required(); - - try { - return applyPropositionsOptionsValidator(options); - } catch (e) { - logger.warn("Invalid options for applyPropositions. No propositions will be applied.", e); - return EMPTY_PROPOSITIONS; - } - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createComponent$3 = (function (_ref) { - var getPageLocation = _ref.getPageLocation, - logger = _ref.logger, - fetchDataHandler = _ref.fetchDataHandler, - viewChangeHandler = _ref.viewChangeHandler, - onClickHandler = _ref.onClickHandler, - isAuthoringModeEnabled = _ref.isAuthoringModeEnabled, - mergeQuery = _ref.mergeQuery, - viewCache = _ref.viewCache, - showContainers = _ref.showContainers, - applyPropositions = _ref.applyPropositions, - setTargetMigration = _ref.setTargetMigration; - return { - lifecycle: { - onBeforeRequest: function onBeforeRequest(_ref2) { - var request = _ref2.request; - setTargetMigration(request); - return Promise.resolve(); - }, - onBeforeEvent: function onBeforeEvent(_ref3) { - var event = _ref3.event, - renderDecisions = _ref3.renderDecisions, - _ref3$decisionScopes = _ref3.decisionScopes, - decisionScopes = _ref3$decisionScopes === void 0 ? [] : _ref3$decisionScopes, - _ref3$personalization = _ref3.personalization, - personalization = _ref3$personalization === void 0 ? {} : _ref3$personalization, - _ref3$onResponse = _ref3.onResponse, - onResponse = _ref3$onResponse === void 0 ? noop$1 : _ref3$onResponse, - _ref3$onRequestFailur = _ref3.onRequestFailure, - onRequestFailure = _ref3$onRequestFailur === void 0 ? noop$1 : _ref3$onRequestFailur; - // Include propositions on all responses, overridden with data as needed - onResponse(function () { - return { - propositions: [] - }; - }); - onRequestFailure(function () { - return showContainers(); - }); - - if (isAuthoringModeEnabled()) { - logger.warn(AUTHORING_ENABLED); // If we are in authoring mode we disable personalization - - mergeQuery(event, { - enabled: false - }); - return; - } - - var personalizationDetails = createPersonalizationDetails({ - getPageLocation: getPageLocation, - renderDecisions: renderDecisions, - decisionScopes: decisionScopes, - personalization: personalization, - event: event, - viewCache: viewCache, - logger: logger - }); - - if (personalizationDetails.shouldFetchData()) { - var decisionsDeferred = defer(); - viewCache.storeViews(decisionsDeferred.promise); - onRequestFailure(function () { - return decisionsDeferred.reject(); - }); - fetchDataHandler({ - decisionsDeferred: decisionsDeferred, - personalizationDetails: personalizationDetails, - event: event, - onResponse: onResponse - }); - return; - } - - if (personalizationDetails.shouldUseCachedData()) { - // eslint-disable-next-line consistent-return - return viewChangeHandler({ - personalizationDetails: personalizationDetails, - event: event, - onResponse: onResponse, - onRequestFailure: onRequestFailure - }); - } - }, - onClick: function onClick(_ref4) { - var event = _ref4.event, - clickedElement = _ref4.clickedElement; - onClickHandler({ - event: event, - clickedElement: clickedElement - }); - } - }, - commands: { - applyPropositions: { - optionsValidator: function optionsValidator(options) { - return validateApplyPropositionsOptions({ - logger: logger, - options: options - }); - }, - run: applyPropositions - } - } - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createFragment = (function (content) { - return createNode(DIV, {}, { - innerHTML: content - }); - }); - - var css_escape = createCommonjsModule(function (module, exports) { - - (function (root, factory) { - // https://github.com/umdjs/umd/blob/master/returnExports.js - { - // For Node.js. - module.exports = factory(root); - } - })(typeof commonjsGlobal != 'undefined' ? commonjsGlobal : commonjsGlobal, function (root) { - if (root.CSS && root.CSS.escape) { - return root.CSS.escape; - } // https://drafts.csswg.org/cssom/#serialize-an-identifier - - - var cssEscape = function cssEscape(value) { - if (arguments.length == 0) { - throw new TypeError('`CSS.escape` requires an argument.'); - } - - var string = String(value); - var length = string.length; - var index = -1; - var codeUnit; - var result = ''; - var firstCodeUnit = string.charCodeAt(0); - - while (++index < length) { - codeUnit = string.charCodeAt(index); // Note: there’s no need to special-case astral symbols, surrogate - // pairs, or lone surrogates. - // If the character is NULL (U+0000), then the REPLACEMENT CHARACTER - // (U+FFFD). - - if (codeUnit == 0x0000) { - result += "\uFFFD"; - continue; - } - - if ( // If the character is in the range [\1-\1F] (U+0001 to U+001F) or is - // U+007F, […] - codeUnit >= 0x0001 && codeUnit <= 0x001F || codeUnit == 0x007F || // If the character is the first character and is in the range [0-9] - // (U+0030 to U+0039), […] - index == 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039 || // If the character is the second character and is in the range [0-9] - // (U+0030 to U+0039) and the first character is a `-` (U+002D), […] - index == 1 && codeUnit >= 0x0030 && codeUnit <= 0x0039 && firstCodeUnit == 0x002D) { - // https://drafts.csswg.org/cssom/#escape-a-character-as-code-point - result += '\\' + codeUnit.toString(16) + ' '; - continue; - } - - if ( // If the character is the first character and is a `-` (U+002D), and - // there is no second character, […] - index == 0 && length == 1 && codeUnit == 0x002D) { - result += '\\' + string.charAt(index); - continue; - } // If the character is not handled by one of the above rules and is - // greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or - // is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to - // U+005A), or [a-z] (U+0061 to U+007A), […] - - - if (codeUnit >= 0x0080 || codeUnit == 0x002D || codeUnit == 0x005F || codeUnit >= 0x0030 && codeUnit <= 0x0039 || codeUnit >= 0x0041 && codeUnit <= 0x005A || codeUnit >= 0x0061 && codeUnit <= 0x007A) { - // the character itself - result += string.charAt(index); - continue; - } // Otherwise, the escaped character. - // https://drafts.csswg.org/cssom/#escape-a-character - - - result += '\\' + string.charAt(index); - } - - return result; - }; - - if (!root.CSS) { - root.CSS = {}; - } - - root.CSS.escape = cssEscape; - return cssEscape; - }); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var EQ_START = ":eq("; - var EQ_PATTERN = /:eq\((\d+)\)/g; - var isNotEqSelector = function isNotEqSelector(str) { - return str.indexOf(EQ_START) === -1; - }; - var splitWithEq = function splitWithEq(selector) { - return selector.split(EQ_PATTERN).filter(isNonEmptyString); - }; - - var CSS_IDENTIFIER_PATTERN = /(#|\.)(-?\w+)/g; // Here we use CSS.escape() to make sure we get - // correct values for ID and CSS class - // Please check: https://www.w3.org/TR/css-syntax-3/#escaping - // CSS.escape() polyfill can be found here: https://github.com/mathiasbynens/CSS.escape - - var replaceIdentifier = function replaceIdentifier(_, $1, $2) { - return "" + $1 + css_escape($2); - }; - - var escapeIdentifiersInSelector = function escapeIdentifiersInSelector(selector) { - return selector.replace(CSS_IDENTIFIER_PATTERN, replaceIdentifier); - }; - var parseSelector = function parseSelector(rawSelector) { - var result = []; - var selector = escapeIdentifiersInSelector(rawSelector.trim()); - var parts = splitWithEq(selector); - var length = parts.length; - var i = 0; - - while (i < length) { - var sel = parts[i]; - var eq = parts[i + 1]; - - if (eq) { - result.push({ - sel: sel, - eq: Number(eq) - }); - } else { - result.push({ - sel: sel - }); - } - - i += 2; - } - - return result; - }; - /** - * Returns an array of matched DOM nodes. - * @param {String} selector that contains Sizzle "eq(...)" pseudo selector - * @returns {Array} an array of DOM nodes - */ - - var selectNodesWithEq = function selectNodesWithEq(selector) { - var doc = document; - - if (isNotEqSelector(selector)) { - return selectNodes(selector, doc); - } - - var parts = parseSelector(selector); - var length = parts.length; - var result = []; - var context = doc; - var i = 0; - - while (i < length) { - var _parts$i = parts[i], - sel = _parts$i.sel, - eq = _parts$i.eq; - var nodes = selectNodes(sel, context); - var nodesCount = nodes.length; - - if (nodesCount === 0) { - break; - } - - if (eq != null && eq > nodesCount - 1) { - break; - } - - if (i < length - 1) { - if (eq == null) { - var _nodes = _slicedToArray(nodes, 1); - - context = _nodes[0]; - } else { - context = nodes[eq]; - } - } - - if (i === length - 1) { - if (eq == null) { - result = nodes; - } else { - result = [nodes[eq]]; - } - } - - i += 1; - } - - return result; - }; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Returns an array of matched DOM nodes. - * @param {String} id - * @param {Node} [context=document] defaults to document - * @returns {HTMLElement} an element of null - */ - var getElementById = (function (id) { - var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document; - return context.getElementById(id); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var setAttribute = (function (element, name, value) { - element.setAttribute(name, value); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var getAttribute = (function (element, name) { - return element.getAttribute(name); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var removeAttribute = (function (element, name) { - element.removeAttribute(name); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var setStyle = (function (element, name, value, priority) { - var css; - - if (priority) { - css = name + ":" + value + " !" + priority + ";"; - } else { - css = name + ":" + value + ";"; - } - - element.style.cssText += ";" + css; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var getParent = (function (element) { - return element.parentNode; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var getNextSibling = (function (element) { - return element.nextElementSibling; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var insertAfter = (function (container, element) { - if (!container) { - return; - } - - var parent = getParent(container); - - if (parent) { - parent.insertBefore(element, getNextSibling(container)); - } - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var insertBefore = (function (container, element) { - if (!container) { - return; - } - - var parent = getParent(container); - - if (parent) { - parent.insertBefore(element, container); - } - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var getChildren = (function (element) { - var children = element.children; - - if (children) { - return toArray(children); - } - - return []; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var getChildNodes = (function (element) { - var childNodes = element.childNodes; - - if (childNodes) { - return toArray(childNodes); - } - - return []; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var getFirstChild = (function (element) { - return element.firstElementChild; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var nonce; - /** - * Returns the nonce if available. - * @param {Node} [context=document] defaults to document - * @returns {(String|undefined)} the nonce or undefined if not available - */ - - var getNonce = (function () { - var context = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document; - - if (nonce === undefined) { - var n = context.querySelector("[nonce]"); // NOTE: We're keeping n.getAttribute("nonce") until it is safe to remove: - // ref: https://github.com/whatwg/html/issues/2369#issuecomment-280853946 - - nonce = n && (n.nonce || n.getAttribute("nonce")); - } - - return nonce; - }); // This function is only used for testing and removed when library is built (tree-shaking) - - var PREHIDING_ID = "alloy-prehiding"; - var HIDING_STYLE_DEFINITION = "{ visibility: hidden }"; // Using global is OK since we have a single DOM - // so storing nodes even for multiple Alloy instances is fine - - var styleNodes = {}; - var hideElements = function hideElements(prehidingSelector) { - // if we have different events with the same - // prehiding selector we don't want to recreate - // the style tag - if (styleNodes[prehidingSelector]) { - return; - } - - var nonce = getNonce(); - - var attrs = _objectSpread2({}, nonce && { - nonce: nonce - }); - - var props = { - textContent: prehidingSelector + " " + HIDING_STYLE_DEFINITION - }; - var node = createNode(STYLE, attrs, props); - appendNode(document.head, node); - styleNodes[prehidingSelector] = node; - }; - var showElements = function showElements(prehidingSelector) { - var node = styleNodes[prehidingSelector]; - - if (node) { - removeNode(node); - delete styleNodes[prehidingSelector]; - } - }; - var hideContainers = function hideContainers(prehidingStyle) { - if (!prehidingStyle) { - return; - } // If containers prehiding style has been added - // by customer's prehiding snippet we don't - // want to add the same node - - - var node = getElementById(PREHIDING_ID); - - if (node) { - return; - } - - var nonce = getNonce(); - - var attrs = _objectSpread2({ - id: PREHIDING_ID - }, nonce && { - nonce: nonce - }); - - var props = { - textContent: prehidingStyle - }; - var styleNode = createNode(STYLE, attrs, props); - appendNode(document.head, styleNode); - }; - var showContainers = function showContainers() { - // If containers prehiding style exists - // we will remove it - var node = getElementById(PREHIDING_ID); - - if (!node) { - return; - } - - removeNode(node); - }; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var setText = (function (container, text) { - container.textContent = text; - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var SRC = "src"; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var isImage = function isImage(element) { - return element.tagName === IMG; - }; - var loadImage = function loadImage(url) { - return createNode(IMG, { - src: url - }); - }; - var loadImages = function loadImages(fragment) { - var images = selectNodes(IMG, fragment); - images.forEach(function (image) { - var url = getAttribute(image, SRC); - - if (url) { - loadImage(url); - } - }); - }; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var is$1 = function is(element, tagName) { - return element.tagName === tagName; - }; - - var isInlineStyleElement = function isInlineStyleElement(element) { - return is$1(element, STYLE) && !getAttribute(element, SRC); - }; - - var addNonceToInlineStyleElements = (function (fragment) { - var styleNodes = selectNodes(STYLE, fragment); - var length = styleNodes.length; - var nonce = getNonce(); - - if (!nonce) { - return; - } - /* eslint-disable no-continue */ - - - for (var i = 0; i < length; i += 1) { - var element = styleNodes[i]; - - if (!isInlineStyleElement(element)) { - continue; - } - - element.nonce = nonce; - } - }); - - /** - * @this {Promise} - */ - function finallyConstructor(callback) { - var constructor = this.constructor; - return this.then(function (value) { - // @ts-ignore - return constructor.resolve(callback()).then(function () { - return value; - }); - }, function (reason) { - // @ts-ignore - return constructor.resolve(callback()).then(function () { - // @ts-ignore - return constructor.reject(reason); - }); - }); - } - - // other code modifying setTimeout (like sinon.useFakeTimers()) - - var setTimeoutFunc = setTimeout; - - function isArray(x) { - return Boolean(x && typeof x.length !== 'undefined'); - } - - function noop() {} // Polyfill for Function.prototype.bind - - - function bind(fn, thisArg) { - return function () { - fn.apply(thisArg, arguments); - }; - } - /** - * @constructor - * @param {Function} fn - */ - - - function Promise$1(fn) { - if (!(this instanceof Promise$1)) throw new TypeError('Promises must be constructed via new'); - if (typeof fn !== 'function') throw new TypeError('not a function'); - /** @type {!number} */ - - this._state = 0; - /** @type {!boolean} */ - - this._handled = false; - /** @type {Promise|undefined} */ - - this._value = undefined; - /** @type {!Array} */ - - this._deferreds = []; - doResolve(fn, this); - } - - function handle(self, deferred) { - while (self._state === 3) { - self = self._value; - } - - if (self._state === 0) { - self._deferreds.push(deferred); - - return; - } - - self._handled = true; - - Promise$1._immediateFn(function () { - var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected; - - if (cb === null) { - (self._state === 1 ? resolve : reject)(deferred.promise, self._value); - return; - } - - var ret; - - try { - ret = cb(self._value); - } catch (e) { - reject(deferred.promise, e); - return; - } - - resolve(deferred.promise, ret); - }); - } - - function resolve(self, newValue) { - try { - // Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure - if (newValue === self) throw new TypeError('A promise cannot be resolved with itself.'); - - if (newValue && (_typeof(newValue) === 'object' || typeof newValue === 'function')) { - var then = newValue.then; - - if (newValue instanceof Promise$1) { - self._state = 3; - self._value = newValue; - finale(self); - return; - } else if (typeof then === 'function') { - doResolve(bind(then, newValue), self); - return; - } - } - - self._state = 1; - self._value = newValue; - finale(self); - } catch (e) { - reject(self, e); - } - } - - function reject(self, newValue) { - self._state = 2; - self._value = newValue; - finale(self); - } - - function finale(self) { - if (self._state === 2 && self._deferreds.length === 0) { - Promise$1._immediateFn(function () { - if (!self._handled) { - Promise$1._unhandledRejectionFn(self._value); - } - }); - } - - for (var i = 0, len = self._deferreds.length; i < len; i++) { - handle(self, self._deferreds[i]); - } - - self._deferreds = null; - } - /** - * @constructor - */ - - - function Handler(onFulfilled, onRejected, promise) { - this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null; - this.onRejected = typeof onRejected === 'function' ? onRejected : null; - this.promise = promise; - } - /** - * Take a potentially misbehaving resolver function and make sure - * onFulfilled and onRejected are only called once. - * - * Makes no guarantees about asynchrony. - */ - - - function doResolve(fn, self) { - var done = false; - - try { - fn(function (value) { - if (done) return; - done = true; - resolve(self, value); - }, function (reason) { - if (done) return; - done = true; - reject(self, reason); - }); - } catch (ex) { - if (done) return; - done = true; - reject(self, ex); - } - } - - Promise$1.prototype['catch'] = function (onRejected) { - return this.then(null, onRejected); - }; - - Promise$1.prototype.then = function (onFulfilled, onRejected) { - // @ts-ignore - var prom = new this.constructor(noop); - handle(this, new Handler(onFulfilled, onRejected, prom)); - return prom; - }; - - Promise$1.prototype['finally'] = finallyConstructor; - - Promise$1.all = function (arr) { - return new Promise$1(function (resolve, reject) { - if (!isArray(arr)) { - return reject(new TypeError('Promise.all accepts an array')); - } - - var args = Array.prototype.slice.call(arr); - if (args.length === 0) return resolve([]); - var remaining = args.length; - - function res(i, val) { - try { - if (val && (_typeof(val) === 'object' || typeof val === 'function')) { - var then = val.then; - - if (typeof then === 'function') { - then.call(val, function (val) { - res(i, val); - }, reject); - return; - } - } - - args[i] = val; - - if (--remaining === 0) { - resolve(args); - } - } catch (ex) { - reject(ex); - } - } - - for (var i = 0; i < args.length; i++) { - res(i, args[i]); - } - }); - }; - - Promise$1.resolve = function (value) { - if (value && _typeof(value) === 'object' && value.constructor === Promise$1) { - return value; - } - - return new Promise$1(function (resolve) { - resolve(value); - }); - }; - - Promise$1.reject = function (value) { - return new Promise$1(function (resolve, reject) { - reject(value); - }); - }; - - Promise$1.race = function (arr) { - return new Promise$1(function (resolve, reject) { - if (!isArray(arr)) { - return reject(new TypeError('Promise.race accepts an array')); - } - - for (var i = 0, len = arr.length; i < len; i++) { - Promise$1.resolve(arr[i]).then(resolve, reject); - } - }); - }; // Use polyfill for setImmediate for performance gains - - - Promise$1._immediateFn = // @ts-ignore - typeof setImmediate === 'function' && function (fn) { - // @ts-ignore - setImmediate(fn); - } || function (fn) { - setTimeoutFunc(fn, 0); - }; - - Promise$1._unhandledRejectionFn = function _unhandledRejectionFn(err) { - if (typeof console !== 'undefined' && console) { - console.warn('Possible Unhandled Promise Rejection:', err); // eslint-disable-line no-console - } - }; - - // Karma + Webpack. You need to specify the default import when using promise-polyfill` - // with Webpack 2+. We need `require('promise-polyfill').default` for running the tests - // and `require('promise-polyfill')` for building Turbine. - - - var reactorPromise = typeof window !== 'undefined' && window.Promise || typeof commonjsGlobal !== 'undefined' && commonjsGlobal.Promise || Promise$1.default || Promise$1; - - var getPromise = function getPromise(url, script) { - return new reactorPromise(function (resolve, reject) { - script.onload = function () { - resolve(script); - }; - - script.onerror = function () { - reject(new Error('Failed to load script ' + url)); - }; - }); - }; - - var reactorLoadScript = function reactorLoadScript(url) { - var script = document.createElement('script'); - script.src = url; - script.async = true; - var promise = getPromise(url, script); - document.getElementsByTagName('head')[0].appendChild(script); - return promise; - }; - - var is = function is(element, tagName) { - return !!element && element.tagName === tagName; - }; - - var isInlineScript = function isInlineScript(element) { - return is(element, SCRIPT) && !getAttribute(element, SRC); - }; - - var isRemoteScript = function isRemoteScript(element) { - return is(element, SCRIPT) && getAttribute(element, SRC); - }; - - var getInlineScripts = function getInlineScripts(fragment) { - var scripts = selectNodes(SCRIPT, fragment); - var result = []; - var length = scripts.length; - var nonce = getNonce(); - - var attributes = _objectSpread2({}, nonce && { - nonce: nonce - }); - /* eslint-disable no-continue */ - - - for (var i = 0; i < length; i += 1) { - var element = scripts[i]; - - if (!isInlineScript(element)) { - continue; - } - - var textContent = element.textContent; - - if (!textContent) { - continue; - } - - result.push(createNode(SCRIPT, attributes, { - textContent: textContent - })); - } - /* eslint-enable no-continue */ - - - return result; - }; - var getRemoteScriptsUrls = function getRemoteScriptsUrls(fragment) { - var scripts = selectNodes(SCRIPT, fragment); - var result = []; - var length = scripts.length; - /* eslint-disable no-continue */ - - for (var i = 0; i < length; i += 1) { - var element = scripts[i]; - - if (!isRemoteScript(element)) { - continue; - } - - var url = getAttribute(element, SRC); - - if (!url) { - continue; - } - - result.push(url); - } - /* eslint-enable no-continue */ - - - return result; - }; - var executeInlineScripts = function executeInlineScripts(parent, scripts) { - scripts.forEach(function (script) { - parent.appendChild(script); - parent.removeChild(script); - }); - }; - var executeRemoteScripts = function executeRemoteScripts(urls) { - return Promise.all(urls.map(reactorLoadScript)); - }; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var appendHtml = (function (container, html) { - var fragment = createFragment(html); - addNonceToInlineStyleElements(fragment); - var elements = getChildNodes(fragment); - var scripts = getInlineScripts(fragment); - var scriptsUrls = getRemoteScriptsUrls(fragment); - loadImages(fragment); - elements.forEach(function (element) { - appendNode(container, element); - }); - executeInlineScripts(container, scripts); - return executeRemoteScripts(scriptsUrls); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var clear = function clear(container) { - // We want to remove ALL nodes, text, comments etc - var childNodes = getChildNodes(container); - childNodes.forEach(removeNode); - }; - - var setHtml = (function (container, html) { - clear(container); - appendHtml(container, html); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var prependHtml = (function (container, html) { - var fragment = createFragment(html); - addNonceToInlineStyleElements(fragment); - var elements = getChildNodes(fragment); - var scripts = getInlineScripts(fragment); - var scriptsUrls = getRemoteScriptsUrls(fragment); - var length = elements.length; - var i = length - 1; // We have to proactively load images to avoid flicker - - loadImages(fragment); // We are inserting elements in reverse order - - while (i >= 0) { - var element = elements[i]; - var firstChild = getFirstChild(container); - - if (firstChild) { - insertBefore(firstChild, element); - } else { - appendNode(container, element); - } - - i -= 1; - } - - executeInlineScripts(container, scripts); - return executeRemoteScripts(scriptsUrls); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var insertHtmlBefore = (function (container, html) { - var fragment = createFragment(html); - addNonceToInlineStyleElements(fragment); - var elements = getChildNodes(fragment); - var scripts = getInlineScripts(fragment); - var scriptsUrls = getRemoteScriptsUrls(fragment); - loadImages(fragment); - elements.forEach(function (element) { - insertBefore(container, element); - }); - executeInlineScripts(container, scripts); - return executeRemoteScripts(scriptsUrls); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var replaceHtml = (function (container, html) { - insertHtmlBefore(container, html); - removeNode(container); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var insertHtmlAfter = (function (container, html) { - var fragment = createFragment(html); - addNonceToInlineStyleElements(fragment); - var elements = getChildNodes(fragment); - var scripts = getInlineScripts(fragment); - var scriptsUrls = getRemoteScriptsUrls(fragment); - loadImages(fragment); - elements.forEach(function (element) { - insertAfter(container, element); - }); - executeInlineScripts(container, scripts); - return executeRemoteScripts(scriptsUrls); - }); - - var _excluded$1 = ["priority"]; - var setStyles = (function (container, styles) { - var priority = styles.priority, - style = _objectWithoutProperties(styles, _excluded$1); - - Object.keys(style).forEach(function (key) { - setStyle(container, key, style[key], priority); - }); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var setAttributes = (function (container, attributes) { - Object.keys(attributes).forEach(function (key) { - setAttribute(container, key, attributes[key]); - }); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var swapImage = (function (container, url) { - if (!isImage(container)) { - return; - } // Start downloading the image - - - loadImage(url); // Remove "src" so there is no flicker - - removeAttribute(container, SRC); // Replace the image "src" - - setAttribute(container, SRC, url); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var rearrangeChildren = (function (container, _ref) { - var from = _ref.from, - to = _ref.to; - var children = getChildren(container); - var elementFrom = children[from]; - var elementTo = children[to]; - - if (!elementFrom || !elementTo) { - // TODO: We will need to add logging - // to ease troubleshooting - return; - } - - if (from < to) { - insertAfter(elementTo, elementFrom); - } else { - insertBefore(elementTo, elementFrom); - } - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var _click = (function (settings, store) { - var selector = settings.selector, - meta = settings.meta; - store({ - selector: selector, - meta: meta - }); - return Promise.resolve(); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var renderContent = function renderContent(elements, content, renderFunc) { - var executions = elements.map(function (element) { - return renderFunc(element, content); - }); - return Promise.all(executions); - }; - - var createAction = function createAction(renderFunc) { - return function (settings) { - var selector = settings.selector, - prehidingSelector = settings.prehidingSelector, - content = settings.content, - meta = settings.meta; - hideElements(prehidingSelector); - return awaitSelector(selector, selectNodesWithEq).then(function (elements) { - return renderContent(elements, content, renderFunc); - }).then(function () { - // if everything is OK, show elements - showElements(prehidingSelector); - return { - meta: meta - }; - }, function (error) { - // in case of awaiting timing or error, we need to remove the style tag - // hence showing the pre-hidden elements - showElements(prehidingSelector); - return { - meta: meta, - error: error - }; - }); - }; - }; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var initDomActionsModules = (function (store) { - return { - setHtml: createAction(setHtml), - customCode: createAction(prependHtml), - setText: createAction(setText), - setAttribute: createAction(setAttributes), - setImageSource: createAction(swapImage), - setStyle: createAction(setStyles), - move: createAction(setStyles), - resize: createAction(setStyles), - rearrange: createAction(rearrangeChildren), - remove: createAction(removeNode), - insertAfter: createAction(insertHtmlAfter), - insertBefore: createAction(insertHtmlBefore), - replaceHtml: createAction(replaceHtml), - prependHtml: createAction(prependHtml), - appendHtml: createAction(appendHtml), - click: function click(settings) { - return _click(settings, store); - }, - defaultContent: function defaultContent(settings) { - return Promise.resolve({ - meta: settings.meta - }); - } - }; - }); - - /* - Copyright 2021 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - /** - * Returns whether a string value is blank. Also returns true if the value is not a string. - * @param {*} value - * @returns {boolean} - */ - - var isBlankString = (function (value) { - return isString(value) ? !value.trim() : true; - }); - - /* - Copyright 2021 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var APPEND_HTML = "appendHtml"; - var HEAD_TAGS_SELECTOR = "SCRIPT,LINK,STYLE"; - - var filterHeadContent = function filterHeadContent(content) { - var container = createFragment(content); - var headNodes = selectNodes(HEAD_TAGS_SELECTOR, container); - return headNodes.map(function (node) { - return node.outerHTML; - }).join(""); - }; - - var remapHeadOffers = (function (action) { - var result = reactorObjectAssign({}, action); - var content = result.content, - selector = result.selector; - - if (isBlankString(content)) { - return result; - } - - var container = selectNodesWithEq(selector); - - if (!is(container[0], HEAD)) { - return result; - } - - result.type = APPEND_HTML; - result.content = filterHeadContent(content); - return result; - }); - - /* - Copyright 2021 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var ACTION_CUSTOM_CODE = "customCode"; - var TARGET_BODY_SELECTOR = "BODY > *:eq(0)"; - var remapCustomCodeOffers = (function (action) { - var selector = action.selector, - type = action.type; - - if (type !== ACTION_CUSTOM_CODE) { - return action; - } - - if (selector !== TARGET_BODY_SELECTOR) { - return action; - } - - return reactorObjectAssign({}, action, { - selector: "BODY" - }); - }); - - var logActionError = function logActionError(logger, action, error) { - if (logger.enabled) { - var details = JSON.stringify(action); - var message = error.message, - stack = error.stack; - var errorMessage = "Failed to execute action " + details + ". " + message + " " + (stack ? "\n " + stack : ""); - logger.error(errorMessage); - } - }; - - var logActionCompleted = function logActionCompleted(logger, action) { - if (logger.enabled) { - var details = JSON.stringify(action); - logger.info("Action " + details + " executed."); - } - }; - - var executeAction = function executeAction(logger, modules, type, args) { - var execute = modules[type]; - - if (!execute) { - var error = new Error("DOM action \"" + type + "\" not found"); - logActionError(logger, args[0], error); - throw error; - } - - return execute.apply(void 0, _toConsumableArray(args)); - }; - - var PREPROCESSORS = [remapHeadOffers, remapCustomCodeOffers]; - - var preprocess = function preprocess(action) { - return PREPROCESSORS.reduce(function (processed, fn) { - return reactorObjectAssign(processed, fn(processed)); - }, action); - }; - - var executeActions = (function (actions, modules, logger) { - var actionPromises = actions.map(function (action) { - var processedAction = preprocess(action); - var type = processedAction.type; - return executeAction(logger, modules, type, [processedAction]).then(function (result) { - logActionCompleted(logger, processedAction); - return result; - }).catch(function (error) { - logActionError(logger, processedAction, error); - throw error; - }); - }); - return Promise.all(actionPromises); - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var DISPLAY = "decisioning.propositionDisplay"; - var INTERACT = "decisioning.propositionInteract"; - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var PropositionEventType = { - DISPLAY: "display", - INTERACT: "interact" - }; - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createCollect = (function (_ref) { - var eventManager = _ref.eventManager, - mergeDecisionsMeta = _ref.mergeDecisionsMeta; - // Called when a decision is auto-rendered for the __view__ scope or a SPA view(display and empty display notification) - return function (_ref2) { - var _ref2$decisionsMeta = _ref2.decisionsMeta, - decisionsMeta = _ref2$decisionsMeta === void 0 ? [] : _ref2$decisionsMeta, - _ref2$documentMayUnlo = _ref2.documentMayUnload, - documentMayUnload = _ref2$documentMayUnlo === void 0 ? false : _ref2$documentMayUnlo, - viewName = _ref2.viewName; - var event = eventManager.createEvent(); - var data = { - eventType: DISPLAY - }; - - if (viewName) { - data.web = { - webPageDetails: { - viewName: viewName - } - }; - } - - if (isNonEmptyArray(decisionsMeta)) { - mergeDecisionsMeta(event, decisionsMeta, PropositionEventType.DISPLAY); - } - - event.mergeXdm(data); - - if (documentMayUnload) { - event.documentMayUnload(); - } - - return eventManager.sendEvent(event); - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var DEFAULT_ACTION_TYPE = "defaultContent"; - - var identity = function identity(item) { - return item; - }; - - var getItemMeta = function getItemMeta(item, decisionMeta) { - return item.characteristics && item.characteristics.trackingLabel ? reactorObjectAssign({ - trackingLabel: item.characteristics.trackingLabel - }, decisionMeta) : decisionMeta; - }; - - var buildActions = function buildActions(decision) { - var decisionMeta = { - id: decision.id, - scope: decision.scope, - scopeDetails: decision.scopeDetails - }; - return decision.items.map(function (item) { - return reactorObjectAssign({ - type: DEFAULT_ACTION_TYPE - }, item.data, { - meta: getItemMeta(item, decisionMeta) - }); - }); - }; - - var processMetas = function processMetas(logger, actionResults) { - var results = flatMap(actionResults, identity); - var finalMetas = []; - var set = new Set(); - results.forEach(function (item) { - // for click actions we don't return an item - if (!item) { - return; - } - - if (item.error) { - logger.warn(item); - return; - } - - var meta = item.meta; - - if (set.has(meta.id)) { - return; - } - - set.add(meta.id); - finalMetas.push(meta); - }); - return finalMetas; - }; - - var createExecuteDecisions = (function (_ref) { - var modules = _ref.modules, - logger = _ref.logger, - executeActions = _ref.executeActions; - return function (decisions) { - var actionResultsPromises = decisions.map(function (decision) { - var actions = buildActions(decision); - return executeActions(actions, modules, logger); - }); - return Promise.all(actionResultsPromises).then(function (results) { - return processMetas(logger, results); - }).catch(function (error) { - logger.error(error); - }); - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createFetchDataHandler = (function (_ref) { - var prehidingStyle = _ref.prehidingStyle, - responseHandler = _ref.responseHandler, - hideContainers = _ref.hideContainers, - mergeQuery = _ref.mergeQuery; - return function (_ref2) { - var decisionsDeferred = _ref2.decisionsDeferred, - personalizationDetails = _ref2.personalizationDetails, - event = _ref2.event, - onResponse = _ref2.onResponse; - - if (personalizationDetails.isRenderDecisions()) { - hideContainers(prehidingStyle); - } - - mergeQuery(event, personalizationDetails.createQueryDetails()); - onResponse(function (_ref3) { - var response = _ref3.response; - return responseHandler({ - decisionsDeferred: decisionsDeferred, - personalizationDetails: personalizationDetails, - response: response - }); - }); - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var matchesSelectorWithEq = (function (selector, element) { - if (isNotEqSelector(selector)) { - return matchesSelector(selector, element); - } // Using node selection vs matches selector, because of :eq() - // Find all nodes using document as context - - - var nodes = selectNodesWithEq(selector); - var result = false; // Iterate through all the identified elements - // and reference compare with element - - for (var i = 0; i < nodes.length; i += 1) { - if (nodes[i] === element) { - result = true; - break; - } - } - - return result; - }); - - var getMetasIfMatches = function getMetasIfMatches(clickedElement, selector, getClickMetasBySelector) { - var _document = document, - documentElement = _document.documentElement; - var element = clickedElement; - var i = 0; - - while (element && element !== documentElement) { - if (matchesSelectorWithEq(selector, element)) { - var matchedMetas = getClickMetasBySelector(selector); - var foundMetaWithLabel = matchedMetas.find(function (meta) { - return meta.trackingLabel; - }); - - if (foundMetaWithLabel) { - return { - metas: matchedMetas, - label: foundMetaWithLabel.trackingLabel, - weight: i - }; - } - - return { - metas: matchedMetas - }; - } - - element = element.parentNode; - i += 1; - } - - return { - metas: null - }; - }; - - var cleanMetas = function cleanMetas(metas) { - return metas.map(function (meta) { - delete meta.trackingLabel; - return meta; - }); - }; - - var dedupMetas = function dedupMetas(metas) { - return metas.filter(function (meta, index) { - var stringifiedMeta = JSON.stringify(meta); - return index === metas.findIndex(function (innerMeta) { - return JSON.stringify(innerMeta) === stringifiedMeta; - }); - }); - }; - - var collectClicks = (function (clickedElement, selectors, getClickMetasBySelector) { - var result = []; - var resultLabel = ""; - var resultLabelWeight = Number.MAX_SAFE_INTEGER; - /* eslint-disable no-continue */ - - for (var i = 0; i < selectors.length; i += 1) { - var _getMetasIfMatches = getMetasIfMatches(clickedElement, selectors[i], getClickMetasBySelector), - metas = _getMetasIfMatches.metas, - label = _getMetasIfMatches.label, - weight = _getMetasIfMatches.weight; - - if (!metas) { - continue; - } - - if (label && weight <= resultLabelWeight) { - resultLabel = label; - resultLabelWeight = weight; - } - - result.push.apply(result, _toConsumableArray(cleanMetas(metas))); - } - - return { - decisionsMeta: dedupMetas(result), - eventLabel: resultLabel - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var isAuthoringModeEnabled = (function () { - var doc = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document; - return doc.location.href.indexOf("adobe_authoring_enabled") !== -1; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var EVENT_TYPE_TRUE = 1; - /* eslint-disable no-underscore-dangle */ - - var mergeDecisionsMeta = function mergeDecisionsMeta(event, decisionsMeta, eventType) { - var eventLabel = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ""; - var xdm = { - _experience: { - decisioning: { - propositions: decisionsMeta, - propositionEventType: _defineProperty({}, eventType, EVENT_TYPE_TRUE) - } - } - }; - - if (eventLabel) { - xdm._experience.decisioning.propositionAction = { - label: eventLabel - }; - } - - event.mergeXdm(xdm); - }; - var mergeQuery = function mergeQuery(event, details) { - event.mergeQuery({ - personalization: _objectSpread2({}, details) - }); - }; - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createOnClickHandler = (function (_ref) { - var mergeDecisionsMeta = _ref.mergeDecisionsMeta, - collectClicks = _ref.collectClicks, - getClickSelectors = _ref.getClickSelectors, - getClickMetasBySelector = _ref.getClickMetasBySelector; - // Called when an element qualifying for conversion within an offer is clicked. - return function (_ref2) { - var event = _ref2.event, - clickedElement = _ref2.clickedElement; - var selectors = getClickSelectors(); - - if (isNonEmptyArray(selectors)) { - var _collectClicks = collectClicks(clickedElement, selectors, getClickMetasBySelector), - decisionsMeta = _collectClicks.decisionsMeta, - eventLabel = _collectClicks.eventLabel; - - if (isNonEmptyArray(decisionsMeta)) { - var xdm = { - eventType: INTERACT - }; - var scope = decisionsMeta[0].scope; - - if (scope !== PAGE_WIDE_SCOPE) { - xdm.web = { - webPageDetails: { - viewName: scope - } - }; - } - - event.mergeXdm(xdm); - mergeDecisionsMeta(event, decisionsMeta, PropositionEventType.INTERACT, eventLabel); - } - } - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createViewCacheManager = (function () { - var viewStorage; - var viewStorageDeferred = defer(); - - var storeViews = function storeViews(decisionsPromise) { - decisionsPromise.then(function (decisions) { - if (viewStorage === undefined) { - viewStorage = {}; - } - - reactorObjectAssign(viewStorage, decisions); - viewStorageDeferred.resolve(); - }).catch(function () { - if (viewStorage === undefined) { - viewStorage = {}; - } - - viewStorageDeferred.resolve(); - }); - }; - - var getView = function getView(viewName) { - return viewStorageDeferred.promise.then(function () { - return viewStorage[viewName] || []; - }); - }; - - var isInitialized = function isInitialized() { - return !(viewStorage === undefined); - }; - - return { - storeViews: storeViews, - getView: getView, - isInitialized: isInitialized - }; - }); - - /* - Copyright 2021 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var addRenderAttemptedToDecisions = (function (_ref) { - var decisions = _ref.decisions, - renderAttempted = _ref.renderAttempted; - return decisions.map(function (decision) { - return reactorObjectAssign({ - renderAttempted: renderAttempted - }, decision); - }); - }); - - /* - Copyright 2023 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var composePersonalizationResultingObject = (function () { - var decisions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - var renderDecisions = arguments.length > 1 ? arguments[1] : undefined; - var resultingObject = { - propositions: addRenderAttemptedToDecisions({ - decisions: decisions, - renderAttempted: renderDecisions - }) - }; - - if (!renderDecisions) { - resultingObject.decisions = decisions; - } - - return resultingObject; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createViewChangeHandler = (function (_ref) { - var mergeDecisionsMeta = _ref.mergeDecisionsMeta, - collect = _ref.collect, - executeDecisions = _ref.executeDecisions, - viewCache = _ref.viewCache; - return function (_ref2) { - var personalizationDetails = _ref2.personalizationDetails, - event = _ref2.event, - onResponse = _ref2.onResponse; - var viewName = personalizationDetails.getViewName(); - return viewCache.getView(viewName).then(function (viewDecisions) { - if (personalizationDetails.isRenderDecisions()) { - return executeDecisions(viewDecisions).then(function (decisionsMeta) { - // if there are decisions to be rendered we render them and attach the result in experience.decisions.propositions - if (isNonEmptyArray(decisionsMeta)) { - mergeDecisionsMeta(event, decisionsMeta, PropositionEventType.DISPLAY); - onResponse(function () { - return composePersonalizationResultingObject(viewDecisions, true); - }); - return; - } // if there are no decisions in cache for this view, we will send a empty notification - - - onResponse(function () { - collect({ - decisionsMeta: [], - viewName: viewName - }); - return composePersonalizationResultingObject(viewDecisions, true); - }); - }); - } - - onResponse(function () { - return composePersonalizationResultingObject(viewDecisions, false); - }); - return {}; - }); - }; - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var isPageWideScope = (function (scope) { - return scope === PAGE_WIDE_SCOPE || isPageWideSurface(scope); - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var VIEW_SCOPE_TYPE = "view"; - - var splitItems = function splitItems(items, schemas) { - var matched = []; - var nonMatched = []; - items.forEach(function (item) { - if (includes(schemas, item.schema)) { - matched.push(item); - } else { - nonMatched.push(item); - } - }); - return [matched, nonMatched]; - }; - - var createDecision = function createDecision(decision, items) { - return { - id: decision.id, - scope: decision.scope, - items: items, - scopeDetails: decision.scopeDetails - }; - }; - - var splitMergedMetricDecisions = function splitMergedMetricDecisions(decisions) { - var matchedDecisions = decisions.filter(function (decision) { - var _decision$items = decision.items, - items = _decision$items === void 0 ? [] : _decision$items; - return items.some(function (item) { - return item.schema === MEASUREMENT_SCHEMA; - }); - }); - var unmatchedDecisions = decisions.filter(function (decision) { - return !includes(matchedDecisions, decision); - }); - return { - matchedDecisions: matchedDecisions, - unmatchedDecisions: unmatchedDecisions - }; - }; - - var splitDecisions = function splitDecisions(decisions) { - for (var _len = arguments.length, schemas = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - schemas[_key - 1] = arguments[_key]; - } - - var matchedDecisions = []; - var unmatchedDecisions = []; - decisions.forEach(function (decision) { - var _decision$items2 = decision.items, - items = _decision$items2 === void 0 ? [] : _decision$items2; - - var _splitItems = splitItems(items, schemas), - _splitItems2 = _slicedToArray(_splitItems, 2), - matchedItems = _splitItems2[0], - nonMatchedItems = _splitItems2[1]; - - if (isNonEmptyArray(matchedItems)) { - matchedDecisions.push(createDecision(decision, matchedItems)); - } - - if (isNonEmptyArray(nonMatchedItems)) { - unmatchedDecisions.push(createDecision(decision, nonMatchedItems)); - } - }); - return { - matchedDecisions: matchedDecisions, - unmatchedDecisions: unmatchedDecisions - }; - }; - - var appendScopeDecision = function appendScopeDecision(scopeDecisions, decision) { - if (!scopeDecisions[decision.scope]) { - scopeDecisions[decision.scope] = []; - } - - scopeDecisions[decision.scope].push(decision); - }; - - var isViewScope = function isViewScope(scopeDetails) { - return scopeDetails.characteristics && scopeDetails.characteristics.scopeType && scopeDetails.characteristics.scopeType === VIEW_SCOPE_TYPE; - }; - - var extractDecisionsByScope = function extractDecisionsByScope(decisions) { - var pageWideScopeDecisions = []; - var nonPageWideScopeDecisions = []; - var viewScopeDecisions = {}; - - if (isNonEmptyArray(decisions)) { - decisions.forEach(function (decision) { - if (isPageWideScope(decision.scope)) { - pageWideScopeDecisions.push(decision); - } else if (isViewScope(decision.scopeDetails)) { - appendScopeDecision(viewScopeDecisions, decision); - } else { - nonPageWideScopeDecisions.push(decision); - } - }); - } - - return { - pageWideScopeDecisions: pageWideScopeDecisions, - nonPageWideScopeDecisions: nonPageWideScopeDecisions, - viewScopeDecisions: viewScopeDecisions - }; - }; - - var groupDecisions = function groupDecisions(unprocessedDecisions) { - // split redirect decisions - var decisionsGroupedByRedirectItemSchema = splitDecisions(unprocessedDecisions, REDIRECT_ITEM); // split merged measurement decisions - - var mergedMetricDecisions = splitMergedMetricDecisions(decisionsGroupedByRedirectItemSchema.unmatchedDecisions); // split renderable decisions - - var decisionsGroupedByRenderableSchemas = splitDecisions(mergedMetricDecisions.unmatchedDecisions, DOM_ACTION, DEFAULT_CONTENT_ITEM); // group renderable decisions by scope - - var _extractDecisionsBySc = extractDecisionsByScope(decisionsGroupedByRenderableSchemas.matchedDecisions), - pageWideScopeDecisions = _extractDecisionsBySc.pageWideScopeDecisions, - nonPageWideScopeDecisions = _extractDecisionsBySc.nonPageWideScopeDecisions, - viewScopeDecisions = _extractDecisionsBySc.viewScopeDecisions; - - return { - redirectDecisions: decisionsGroupedByRedirectItemSchema.matchedDecisions, - pageWideScopeDecisions: pageWideScopeDecisions, - viewDecisions: viewScopeDecisions, - nonAutoRenderableDecisions: [].concat(_toConsumableArray(mergedMetricDecisions.matchedDecisions), _toConsumableArray(decisionsGroupedByRenderableSchemas.unmatchedDecisions), _toConsumableArray(nonPageWideScopeDecisions)) - }; - }; - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var DECISIONS_HANDLE = "personalization:decisions"; - var createOnResponseHandler = (function (_ref) { - var autoRenderingHandler = _ref.autoRenderingHandler, - nonRenderingHandler = _ref.nonRenderingHandler, - groupDecisions = _ref.groupDecisions, - handleRedirectDecisions = _ref.handleRedirectDecisions, - showContainers = _ref.showContainers; - return function (_ref2) { - var decisionsDeferred = _ref2.decisionsDeferred, - personalizationDetails = _ref2.personalizationDetails, - response = _ref2.response; - var unprocessedDecisions = response.getPayloadsByType(DECISIONS_HANDLE); - var viewName = personalizationDetails.getViewName(); // if personalization payload is empty return empty decisions array - - if (unprocessedDecisions.length === 0) { - showContainers(); - decisionsDeferred.resolve({}); - return { - decisions: [], - propositions: [] - }; - } - - var _groupDecisions = groupDecisions(unprocessedDecisions), - redirectDecisions = _groupDecisions.redirectDecisions, - pageWideScopeDecisions = _groupDecisions.pageWideScopeDecisions, - viewDecisions = _groupDecisions.viewDecisions, - nonAutoRenderableDecisions = _groupDecisions.nonAutoRenderableDecisions; - - if (personalizationDetails.isRenderDecisions() && isNonEmptyArray(redirectDecisions)) { - decisionsDeferred.resolve({}); - return handleRedirectDecisions(redirectDecisions); - } // save decisions for views in local cache - - - decisionsDeferred.resolve(viewDecisions); - - if (personalizationDetails.isRenderDecisions()) { - return autoRenderingHandler({ - viewName: viewName, - pageWideScopeDecisions: pageWideScopeDecisions, - nonAutoRenderableDecisions: nonAutoRenderableDecisions - }); - } - - return nonRenderingHandler({ - viewName: viewName, - redirectDecisions: redirectDecisions, - pageWideScopeDecisions: pageWideScopeDecisions, - nonAutoRenderableDecisions: nonAutoRenderableDecisions - }); - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var metasToArray = function metasToArray(metas) { - return Object.keys(metas).map(function (key) { - return { - id: key, - scope: metas[key].scope, - scopeDetails: metas[key].scopeDetails, - trackingLabel: metas[key].trackingLabel - }; - }); - }; - - var createClickStorage = (function () { - var clickStorage = {}; - - var storeClickMetrics = function storeClickMetrics(value) { - if (!clickStorage[value.selector]) { - clickStorage[value.selector] = {}; - } - - clickStorage[value.selector][value.meta.id] = { - scope: value.meta.scope, - scopeDetails: value.meta.scopeDetails, - trackingLabel: value.meta.trackingLabel - }; - }; - - var getClickSelectors = function getClickSelectors() { - return Object.keys(clickStorage); - }; - - var getClickMetasBySelector = function getClickMetasBySelector(selector) { - var metas = clickStorage[selector]; - - if (!metas) { - return {}; - } - - return metasToArray(clickStorage[selector]); - }; - - return { - storeClickMetrics: storeClickMetrics, - getClickSelectors: getClickSelectors, - getClickMetasBySelector: getClickMetasBySelector - }; - }); - - /* - Copyright 2021 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var getRedirectDetails = function getRedirectDetails(redirectDecisions) { - var decision = redirectDecisions[0]; - var items = decision.items, - id = decision.id, - scope = decision.scope, - scopeDetails = decision.scopeDetails; - var content = items[0].data.content; - return { - content: content, - decisions: [{ - id: id, - scope: scope, - scopeDetails: scopeDetails - }] - }; - }; - - var createRedirectHandler = (function (_ref) { - var collect = _ref.collect, - window = _ref.window, - logger = _ref.logger, - showContainers = _ref.showContainers; - return function (redirectDecisions) { - var _getRedirectDetails = getRedirectDetails(redirectDecisions), - content = _getRedirectDetails.content, - decisions = _getRedirectDetails.decisions; - - var documentMayUnload = true; - return collect({ - decisionsMeta: decisions, - documentMayUnload: documentMayUnload - }).then(function () { - window.location.replace(content); - }).catch(function () { - showContainers(); - logger.warn(REDIRECT_EXECUTION_ERROR); - }); - }; - }); - - var getPropositions = function getPropositions(_ref) { - var viewCache = _ref.viewCache, - viewName = _ref.viewName, - pageWideScopeDecisions = _ref.pageWideScopeDecisions; - - if (!viewName) { - return { - pageWideScopeDecisions: pageWideScopeDecisions, - viewPropositions: [] - }; - } - - return viewCache.getView(viewName).then(function (viewPropositions) { - return { - pageWideScopeDecisions: pageWideScopeDecisions, - viewPropositions: viewPropositions - }; - }); - }; - - var createAutorenderingHandler = (function (_ref2) { - var viewCache = _ref2.viewCache, - executeDecisions = _ref2.executeDecisions, - showContainers = _ref2.showContainers, - collect = _ref2.collect; - return function (_ref3) { - var viewName = _ref3.viewName, - pageWideScopeDecisions = _ref3.pageWideScopeDecisions, - nonAutoRenderableDecisions = _ref3.nonAutoRenderableDecisions; - return Promise.resolve(pageWideScopeDecisions).then(function (propositions) { - return getPropositions({ - viewCache: viewCache, - viewName: viewName, - executeDecisions: executeDecisions, - pageWideScopeDecisions: propositions - }); - }).then(function (propositions) { - executeDecisions(propositions.pageWideScopeDecisions).then(function (decisionsMeta) { - if (isNonEmptyArray(decisionsMeta)) { - collect({ - decisionsMeta: decisionsMeta - }); - } - }); - - if (viewName) { - executeDecisions(propositions.viewPropositions).then(function (decisionsMeta) { - collect({ - decisionsMeta: decisionsMeta, - viewName: viewName - }); - }); - } - - showContainers(); - return [].concat(_toConsumableArray(propositions.pageWideScopeDecisions), _toConsumableArray(propositions.viewPropositions)); - }).then(function (renderablePropositions) { - return { - decisions: _toConsumableArray(nonAutoRenderableDecisions), - propositions: [].concat(_toConsumableArray(addRenderAttemptedToDecisions({ - decisions: renderablePropositions, - renderAttempted: true - })), _toConsumableArray(addRenderAttemptedToDecisions({ - decisions: nonAutoRenderableDecisions, - renderAttempted: false - }))) - }; - }); - }; - }); - - var getViewPropositions = function getViewPropositions(_ref) { - var viewCache = _ref.viewCache, - viewName = _ref.viewName, - propositions = _ref.propositions; - - if (!viewName) { - return propositions; - } - - return viewCache.getView(viewName).then(function (viewPropositions) { - return [].concat(_toConsumableArray(viewPropositions), _toConsumableArray(propositions)); - }); - }; - - var buildFinalResult = function buildFinalResult(_ref2) { - var propositions = _ref2.propositions; - return { - decisions: propositions, - propositions: addRenderAttemptedToDecisions({ - decisions: propositions, - renderAttempted: false - }) - }; - }; - - var createNonRenderingHandler = (function (_ref3) { - var viewCache = _ref3.viewCache; - return function (_ref4) { - var viewName = _ref4.viewName, - redirectDecisions = _ref4.redirectDecisions, - pageWideScopeDecisions = _ref4.pageWideScopeDecisions, - nonAutoRenderableDecisions = _ref4.nonAutoRenderableDecisions; - var propositions = [].concat(_toConsumableArray(redirectDecisions), _toConsumableArray(pageWideScopeDecisions), _toConsumableArray(nonAutoRenderableDecisions)); - return Promise.resolve(propositions).then(function (items) { - return getViewPropositions({ - viewCache: viewCache, - viewName: viewName, - propositions: items - }); - }).then(function (items) { - return buildFinalResult({ - propositions: items - }); - }); - }; - }); - - var SUPPORTED_SCHEMAS = [DOM_ACTION, HTML_CONTENT_ITEM]; - var createApplyPropositions = (function (_ref) { - var executeDecisions = _ref.executeDecisions; - - var filterItemsPredicate = function filterItemsPredicate(item) { - return SUPPORTED_SCHEMAS.indexOf(item.schema) > -1; - }; - - var updatePropositionItems = function updatePropositionItems(_ref2) { - var items = _ref2.items, - metadataForScope = _ref2.metadataForScope; - return items.filter(filterItemsPredicate).map(function (item) { - if (item.schema !== HTML_CONTENT_ITEM) { - return _objectSpread2({}, item); - } - - if (isObject(metadataForScope)) { - return _objectSpread2(_objectSpread2({}, item), {}, { - data: _objectSpread2(_objectSpread2({}, item.data), {}, { - selector: metadataForScope.selector, - type: metadataForScope.actionType - }) - }); - } - - return undefined; - }).filter(function (item) { - return item; - }); - }; - - var filterPropositionsPredicate = function filterPropositionsPredicate(proposition) { - return !(proposition.scope === PAGE_WIDE_SCOPE && proposition.renderAttempted); - }; - - var preparePropositions = function preparePropositions(_ref3) { - var propositions = _ref3.propositions, - metadata = _ref3.metadata; - return propositions.filter(filterPropositionsPredicate).map(function (proposition) { - if (isNonEmptyArray(proposition.items)) { - var id = proposition.id, - scope = proposition.scope, - scopeDetails = proposition.scopeDetails; - return { - id: id, - scope: scope, - scopeDetails: scopeDetails, - items: updatePropositionItems({ - items: proposition.items, - metadataForScope: metadata[proposition.scope] - }) - }; - } - - return proposition; - }).filter(function (proposition) { - return isNonEmptyArray(proposition.items); - }); - }; - - var applyPropositions = function applyPropositions(_ref4) { - var propositions = _ref4.propositions, - metadata = _ref4.metadata; - var propositionsToExecute = preparePropositions({ - propositions: propositions, - metadata: metadata - }); - return executeDecisions(propositionsToExecute).then(function () { - return composePersonalizationResultingObject(propositionsToExecute, true); - }); - }; - - return function (_ref5) { - var propositions = _ref5.propositions, - _ref5$metadata = _ref5.metadata, - metadata = _ref5$metadata === void 0 ? {} : _ref5$metadata; - - if (isNonEmptyArray(propositions)) { - return applyPropositions({ - propositions: propositions, - metadata: metadata - }); - } - - return Promise.resolve(EMPTY_PROPOSITIONS); - }; - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createGetPageLocation = (function (_ref) { - var window = _ref.window; - return function () { - return window.location; - }; - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createSetTargetMigration = (function (_ref) { - var targetMigrationEnabled = _ref.targetMigrationEnabled; - - if (targetMigrationEnabled) { - return function (request) { - request.getPayload().mergeMeta({ - target: { - migration: true - } - }); - }; - } - - return noop$1; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var createPersonalization = function createPersonalization(_ref) { - var config = _ref.config, - logger = _ref.logger, - eventManager = _ref.eventManager; - var targetMigrationEnabled = config.targetMigrationEnabled, - prehidingStyle = config.prehidingStyle; - var collect = createCollect({ - eventManager: eventManager, - mergeDecisionsMeta: mergeDecisionsMeta - }); - - var _createClickStorage = createClickStorage(), - getClickMetasBySelector = _createClickStorage.getClickMetasBySelector, - getClickSelectors = _createClickStorage.getClickSelectors, - storeClickMetrics = _createClickStorage.storeClickMetrics; - - var getPageLocation = createGetPageLocation({ - window: window - }); - var viewCache = createViewCacheManager(); - var modules = initDomActionsModules(storeClickMetrics); - var executeDecisions = createExecuteDecisions({ - modules: modules, - logger: logger, - executeActions: executeActions - }); - var handleRedirectDecisions = createRedirectHandler({ - collect: collect, - window: window, - logger: logger, - showContainers: showContainers - }); - var autoRenderingHandler = createAutorenderingHandler({ - viewCache: viewCache, - executeDecisions: executeDecisions, - showContainers: showContainers, - collect: collect - }); - var applyPropositions = createApplyPropositions({ - executeDecisions: executeDecisions - }); - var nonRenderingHandler = createNonRenderingHandler({ - viewCache: viewCache - }); - var responseHandler = createOnResponseHandler({ - autoRenderingHandler: autoRenderingHandler, - nonRenderingHandler: nonRenderingHandler, - groupDecisions: groupDecisions, - handleRedirectDecisions: handleRedirectDecisions, - showContainers: showContainers - }); - var fetchDataHandler = createFetchDataHandler({ - prehidingStyle: prehidingStyle, - responseHandler: responseHandler, - hideContainers: hideContainers, - mergeQuery: mergeQuery - }); - var onClickHandler = createOnClickHandler({ - mergeDecisionsMeta: mergeDecisionsMeta, - collectClicks: collectClicks, - getClickSelectors: getClickSelectors, - getClickMetasBySelector: getClickMetasBySelector - }); - var viewChangeHandler = createViewChangeHandler({ - mergeDecisionsMeta: mergeDecisionsMeta, - collect: collect, - executeDecisions: executeDecisions, - viewCache: viewCache - }); - var setTargetMigration = createSetTargetMigration({ - targetMigrationEnabled: targetMigrationEnabled - }); - return createComponent$3({ - getPageLocation: getPageLocation, - logger: logger, - fetchDataHandler: fetchDataHandler, - viewChangeHandler: viewChangeHandler, - onClickHandler: onClickHandler, - isAuthoringModeEnabled: isAuthoringModeEnabled, - mergeQuery: mergeQuery, - viewCache: viewCache, - showContainers: showContainers, - applyPropositions: applyPropositions, - setTargetMigration: setTargetMigration - }); - }; - - createPersonalization.namespace = "Personalization"; - createPersonalization.configValidators = { - prehidingStyle: boundString().nonEmpty(), - targetMigrationEnabled: boundBoolean().default(false) - }; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectWeb = (function (window) { - return function (xdm) { - var web = { - webPageDetails: { - URL: window.location.href || window.location - }, - webReferrer: { - URL: window.document.referrer - } - }; - deepAssign(xdm, { - web: web - }); - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var getScreenOrientationViaProperty = function getScreenOrientationViaProperty(window) { - var orientation = window.screen.orientation; - - if (orientation == null || orientation.type == null) { - return null; - } - - var parts = orientation.type.split("-"); - - if (parts.length === 0) { - return null; - } - - if (parts[0] !== "portrait" && parts[0] !== "landscape") { - return null; - } - - return parts[0]; - }; - - var getScreenOrientationViaMediaQuery = function getScreenOrientationViaMediaQuery(window) { - if (isFunction(window.matchMedia)) { - if (window.matchMedia("(orientation: portrait)").matches) { - return "portrait"; - } - - if (window.matchMedia("(orientation: landscape)").matches) { - return "landscape"; - } - } - - return null; - }; - - var injectDevice = (function (window) { - return function (xdm) { - var _window$screen = window.screen, - width = _window$screen.width, - height = _window$screen.height; - var device = {}; - var screenHeight = toInteger(height); - - if (screenHeight >= 0) { - device.screenHeight = screenHeight; - } - - var screenWidth = toInteger(width); - - if (screenWidth >= 0) { - device.screenWidth = screenWidth; - } - - var orientation = getScreenOrientationViaProperty(window) || getScreenOrientationViaMediaQuery(window); - - if (orientation) { - device.screenOrientation = orientation; - } - - if (Object.keys(device).length > 0) { - deepAssign(xdm, { - device: device - }); - } - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectEnvironment = (function (window) { - return function (xdm) { - var _window$document$docu = window.document.documentElement; - _window$document$docu = _window$document$docu === void 0 ? {} : _window$document$docu; - var clientWidth = _window$document$docu.clientWidth, - clientHeight = _window$document$docu.clientHeight; - var environment = { - type: "browser" - }; - var viewportWidth = toInteger(clientWidth); - - if (viewportWidth >= 0) { - environment.browserDetails = { - viewportWidth: viewportWidth - }; - } - - var viewportHeight = toInteger(clientHeight); - - if (viewportHeight >= 0) { - environment.browserDetails = environment.browserDetails || {}; - environment.browserDetails.viewportHeight = viewportHeight; - } - - deepAssign(xdm, { - environment: environment - }); - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectPlaceContext = (function (dateProvider) { - return function (xdm) { - var date = dateProvider(); - var placeContext = {}; - var localTimezoneOffset = toInteger(date.getTimezoneOffset()); - - if (localTimezoneOffset !== undefined) { - placeContext.localTimezoneOffset = localTimezoneOffset; - } // make sure the timezone offset only uses two digits - - - if (localTimezoneOffset === undefined || Math.abs(localTimezoneOffset) < 6000) { - placeContext.localTime = toISOStringLocal(date); - } - - deepAssign(xdm, { - placeContext: placeContext - }); - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectTimestamp = (function (dateProvider) { - return function (xdm) { - var timestamp = dateProvider().toISOString(); - deepAssign(xdm, { - timestamp: timestamp - }); - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var libraryName = "https://ns.adobe.com/experience/alloy"; - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - // The __VERSION__ keyword will be replace at alloy build time with the package.json version. - // see babel-plugin-version - var libraryVersion = "2.17.0"; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var implementationDetails = (function (xdm) { - var implementationDetails = { - name: libraryName, - version: libraryVersion, - environment: "browser" - }; - deepAssign(xdm, { - implementationDetails: implementationDetails - }); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createComponent$2 = (function (config, logger, optionalContexts, requiredContexts) { - var configuredContexts = config.context; - var contexts = flatMap(configuredContexts, function (context, i) { - if (optionalContexts[context]) { - return [optionalContexts[context]]; - } - - logger.warn("Invalid context[" + i + "]: '" + context + "' is not available."); - return []; - }).concat(requiredContexts); - return { - namespace: "Context", - lifecycle: { - onBeforeEvent: function onBeforeEvent(_ref) { - var event = _ref.event; - var xdm = {}; - return Promise.all(contexts.map(function (context) { - return Promise.resolve(context(xdm, logger)); - })).then(function () { - return event.mergeXdm(xdm); - }); - } - } - }; - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var highEntropyUserAgentHints$1 = [["architecture", "string"], ["bitness", "string"], ["model", "string"], ["platformVersion", "string"], ["wow64", "boolean"]]; - - var browserSupportsUserAgentClientHints = function browserSupportsUserAgentClientHints(navigator) { - return typeof navigator.userAgentData !== "undefined"; - }; - - var injectHighEntropyUserAgentHints = (function (navigator) { - if (!browserSupportsUserAgentClientHints(navigator)) { - return noop$1; - } - - return function (xdm, logger) { - try { - return navigator.userAgentData.getHighEntropyValues(highEntropyUserAgentHints$1.map(function (hint) { - return hint[0]; - })).then(function (hints) { - var userAgentClientHints = {}; - highEntropyUserAgentHints$1.forEach(function (_ref) { - var _ref2 = _slicedToArray(_ref, 2), - hintName = _ref2[0], - hintType = _ref2[1]; - - if (Object.prototype.hasOwnProperty.call(hints, hintName) && - /* eslint-disable-next-line valid-typeof */ - _typeof(hints[hintName]) === hintType) { - userAgentClientHints[hintName] = hints[hintName]; - } - }); - deepAssign(xdm, { - environment: { - browserDetails: { - userAgentClientHints: userAgentClientHints - } - } - }); - }); - } catch (error) { - logger.warn("Unable to collect user-agent client hints. " + error.message); - return noop$1; - } - }; - }); - - var web = injectWeb(window); - var device = injectDevice(window); - var environment = injectEnvironment(window); - var placeContext = injectPlaceContext(function () { - return new Date(); - }); - var timestamp = injectTimestamp(function () { - return new Date(); - }); - var highEntropyUserAgentHints = injectHighEntropyUserAgentHints(navigator); - var defaultEnabledContexts = { - web: web, - device: device, - environment: environment, - placeContext: placeContext - }; - var defaultDisabledContexts = { - highEntropyUserAgentHints: highEntropyUserAgentHints - }; - - var optionalContexts = _objectSpread2(_objectSpread2({}, defaultEnabledContexts), defaultDisabledContexts); - - var requiredContexts = [timestamp, implementationDetails]; - - var createContext = function createContext(_ref) { - var config = _ref.config, - logger = _ref.logger; - return createComponent$2(config, logger, optionalContexts, requiredContexts); - }; - - createContext.namespace = "Context"; - createContext.configValidators = { - context: boundArrayOf(boundString()).default(Object.keys(defaultEnabledContexts)) - }; - - var createComponent$1 = (function (_ref) { - var storedConsent = _ref.storedConsent, - taskQueue = _ref.taskQueue, - defaultConsent = _ref.defaultConsent, - consent = _ref.consent, - sendSetConsentRequest = _ref.sendSetConsentRequest, - validateSetConsentOptions = _ref.validateSetConsentOptions, - consentHashStore = _ref.consentHashStore, - doesIdentityCookieExist = _ref.doesIdentityCookieExist; - - var defaultConsentByPurpose = _defineProperty({}, GENERAL, defaultConsent); - - var storedConsentByPurpose = storedConsent.read(); - var identityCookieExists = doesIdentityCookieExist(); - var consentCookieExists = storedConsentByPurpose[GENERAL] !== undefined; - - if (!identityCookieExists || !consentCookieExists) { - consentHashStore.clear(); - } // If the identity cookie is gone, remove the consent cookie because the - // consent info is tied to the identity. - - - if (!identityCookieExists) { - storedConsent.clear(); - storedConsentByPurpose = {}; - } - - consent.initializeConsent(defaultConsentByPurpose, storedConsentByPurpose); - - var readCookieIfQueueEmpty = function readCookieIfQueueEmpty() { - if (taskQueue.length === 0) { - var storedConsentObject = storedConsent.read(); // Only read cookies when there are no outstanding setConsent - // requests. This helps with race conditions. - - if (storedConsentObject[GENERAL] !== undefined) { - consent.setConsent(storedConsentObject); - } - } - }; - - return { - commands: { - setConsent: { - optionsValidator: validateSetConsentOptions, - run: function run(_ref2) { - var consentOptions = _ref2.consent, - identityMap = _ref2.identityMap, - edgeConfigOverrides = _ref2.edgeConfigOverrides; - consent.suspend(); - var consentHashes = consentHashStore.lookup(consentOptions); - return taskQueue.addTask(function () { - if (consentHashes.isNew()) { - return sendSetConsentRequest({ - consentOptions: consentOptions, - identityMap: identityMap, - edgeConfigOverrides: edgeConfigOverrides - }); - } - - return Promise.resolve(); - }).then(function () { - return consentHashes.save(); - }).finally(readCookieIfQueueEmpty); - } - } - }, - lifecycle: { - // Read the cookie here too because the consent cookie may change on any request - onResponse: readCookieIfQueueEmpty, - // Even when we get a failure HTTP status code, the consent cookie can - // still get updated. This could happen, for example, if the user is - // opted out in AudienceManager, but no consent cookie exists on the - // client. The request will be sent and the server will respond with a - // 403 Forbidden and a consent cookie. - onRequestFailure: readCookieIfQueueEmpty - } - }; - }); - - var serialize = function serialize(obj) { - if (Array.isArray(obj)) { - return obj.map(function (i) { - return serialize(i); - }); - } - - if (_typeof(obj) === "object" && obj !== null) { - return Object.keys(obj).sort().reduce(function (memo, key) { - memo[key] = serialize(obj[key]); - return memo; - }, {}); - } - - return obj; - }; - - var computeConsentHash = (function (obj) { - return crc32(JSON.stringify(serialize(obj))); - }); - - var _excluded = ["standard", "version"]; - - var getKey = function getKey(_ref) { - var standard = _ref.standard, - version = _ref.version; - return standard + "." + version; - }; - - var createConsentHashStore = (function (_ref2) { - var storage = _ref2.storage; - return { - clear: function clear() { - storage.clear(); - }, - lookup: function lookup(consentObjects) { - var currentHashes = {}; - - var getCurrentHash = function getCurrentHash(consentObject) { - var key = getKey(consentObject); - - consentObject.standard; - consentObject.version; - var rest = _objectWithoutProperties(consentObject, _excluded); - - if (!currentHashes[key]) { - currentHashes[key] = computeConsentHash(rest).toString(); - } - - return currentHashes[key]; - }; - - return { - isNew: function isNew() { - return consentObjects.some(function (consentObject) { - var key = getKey(consentObject); - var previousHash = storage.getItem(key); - return previousHash === null || previousHash !== getCurrentHash(consentObject); - }); - }, - save: function save() { - consentObjects.forEach(function (consentObject) { - var key = getKey(consentObject); - storage.setItem(key, getCurrentHash(consentObject)); - }); - } - }; - } - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createConsentRequestPayload = (function () { - var content = {}; - var payload = createRequestPayload({ - content: content, - addIdentity: function addIdentity(namespaceCode, identity) { - content.identityMap = content.identityMap || {}; - content.identityMap[namespaceCode] = content.identityMap[namespaceCode] || []; - content.identityMap[namespaceCode].push(identity); - }, - hasIdentity: function hasIdentity(namespaceCode) { - return (content.identityMap && content.identityMap[namespaceCode]) !== undefined; - } - }); - - payload.setConsent = function (consent) { - content.consent = consent; - }; - - return payload; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createConsentRequest = (function (consentRequestPayload) { - return createRequest({ - payload: consentRequestPayload, - getAction: function getAction() { - return "privacy/set-consent"; - }, - getUseSendBeacon: function getUseSendBeacon() { - return false; - } - }); - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createStoredConsent = (function (_ref) { - var parseConsentCookie = _ref.parseConsentCookie, - orgId = _ref.orgId, - cookieJar = _ref.cookieJar; - var consentCookieName = getNamespacedCookieName(orgId, CONSENT); - return { - read: function read() { - var cookieValue = cookieJar.get(consentCookieName); - return cookieValue ? parseConsentCookie(cookieValue) : {}; - }, - clear: function clear() { - cookieJar.remove(consentCookieName); - } - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectSendSetConsentRequest = (function (_ref) { - var createConsentRequestPayload = _ref.createConsentRequestPayload, - createConsentRequest = _ref.createConsentRequest, - sendEdgeNetworkRequest = _ref.sendEdgeNetworkRequest, - globalConfigOverrides = _ref.edgeConfigOverrides; - return function (_ref2) { - var consentOptions = _ref2.consentOptions, - identityMap = _ref2.identityMap, - localConfigOverrides = _ref2.edgeConfigOverrides; - var payload = createConsentRequestPayload(); - payload.setConsent(consentOptions); - payload.mergeConfigOverride(globalConfigOverrides); - payload.mergeConfigOverride(localConfigOverrides); - - if (isObject(identityMap)) { - Object.keys(identityMap).forEach(function (key) { - identityMap[key].forEach(function (identity) { - payload.addIdentity(key, identity); - }); - }); - } - - var request = createConsentRequest(payload); - return sendEdgeNetworkRequest({ - request: request - }).then(function () {// Don't let response data disseminate beyond this - // point unless necessary. - }); - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - /** - * Parses a consent cookie. - * @param {string} cookieValue Must be in the format a=b;c=d - * @returns {Object} An object where the keys are purpose names and the values - * are the consent status for the purpose. - */ - var parseConsentCookie = (function (cookieValue) { - var categoryPairs = cookieValue.split(";"); - return categoryPairs.reduce(function (consentByPurpose, categoryPair) { - var _categoryPair$split = categoryPair.split("="), - _categoryPair$split2 = _slicedToArray(_categoryPair$split, 2), - name = _categoryPair$split2[0], - value = _categoryPair$split2[1]; - - consentByPurpose[name] = value; - return consentByPurpose; - }, {}); - }); - - /* - Copyright 2023 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var validateSetConsentOptions = boundObjectOf({ - consent: boundArrayOf(boundAnything()).required().nonEmpty(), - identityMap: validateIdentityMap, - edgeConfigOverrides: validateConfigOverride - }).noUnknownFields().required(); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var createPrivacy = function createPrivacy(_ref) { - var config = _ref.config, - consent = _ref.consent, - sendEdgeNetworkRequest = _ref.sendEdgeNetworkRequest, - createNamespacedStorage = _ref.createNamespacedStorage; - var orgId = config.orgId, - defaultConsent = config.defaultConsent; - var storedConsent = createStoredConsent({ - parseConsentCookie: parseConsentCookie, - orgId: orgId, - cookieJar: cookieJar - }); - var taskQueue = createTaskQueue(); - var sendSetConsentRequest = injectSendSetConsentRequest({ - createConsentRequestPayload: createConsentRequestPayload, - createConsentRequest: createConsentRequest, - sendEdgeNetworkRequest: sendEdgeNetworkRequest, - edgeConfigOverrides: config.edgeConfigOverrides - }); - var storage = createNamespacedStorage(sanitizeOrgIdForCookieName(orgId) + ".consentHashes."); - var consentHashStore = createConsentHashStore({ - storage: storage.persistent - }); - var doesIdentityCookieExist = injectDoesIdentityCookieExist({ - orgId: orgId - }); - return createComponent$1({ - storedConsent: storedConsent, - taskQueue: taskQueue, - defaultConsent: defaultConsent, - consent: consent, - sendSetConsentRequest: sendSetConsentRequest, - validateSetConsentOptions: validateSetConsentOptions, - consentHashStore: consentHashStore, - doesIdentityCookieExist: doesIdentityCookieExist - }); - }; - - createPrivacy.namespace = "Privacy"; - - /* - Copyright 20219 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createEventMergeId = (function () { - return { - eventMergeId: v4_1() - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createComponent = (function (_ref) { - var createEventMergeId = _ref.createEventMergeId; - return { - commands: { - createEventMergeId: { - run: createEventMergeId - } - } - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var createEventMerge = function createEventMerge() { - return createComponent({ - createEventMergeId: createEventMergeId - }); - }; - - createEventMerge.namespace = "EventMerge"; - createEventMerge.configValidators = {}; - - var prepareLibraryInfo = function prepareLibraryInfo(_ref) { - var config = _ref.config, - componentRegistry = _ref.componentRegistry; - var allCommands = [].concat(_toConsumableArray(componentRegistry.getCommandNames()), [CONFIGURE, SET_DEBUG]).sort(); - - var resultConfig = _objectSpread2({}, config); - - Object.keys(config).forEach(function (key) { - var value = config[key]; - - if (typeof value !== "function") { - return; - } - - resultConfig[key] = value.toString(); - }); - return { - version: libraryVersion, - configs: resultConfig, - commands: allCommands - }; - }; - - var createLibraryInfo = function createLibraryInfo(_ref2) { - var config = _ref2.config, - componentRegistry = _ref2.componentRegistry; - var libraryInfo = prepareLibraryInfo({ - config: config, - componentRegistry: componentRegistry - }); - return { - commands: { - getLibraryInfo: { - run: function run() { - return { - libraryInfo: libraryInfo - }; - } - } - } - }; - }; - - createLibraryInfo.namespace = "LibraryInfo"; - - /* - Copyright 2021 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var processResponse = (function (_ref) { - var response = _ref.response; - return { - inferences: response.getPayloadsByType("rtml:inferences") - }; - }); - - /* - Copyright 2021 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var createMachineLearning = function createMachineLearning() { - return { - lifecycle: { - onResponse: processResponse - }, - commands: {} - }; - }; - - createMachineLearning.namespace = "MachineLearning"; - createMachineLearning.configValidators = {}; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - // TODO: Figure out how sub-components will be made available/registered - - var componentCreators = [createDataCollector, createActivityCollector, createIdentity, createAudiences, createPersonalization, createContext, createPrivacy, createEventMerge, createLibraryInfo, createMachineLearning]; - - var CONFIG_DOC_URI = "https://adobe.ly/3sHh553"; - - var buildSchema = function buildSchema(coreConfigValidators, componentCreators) { - var schema = {}; - reactorObjectAssign(schema, coreConfigValidators); - componentCreators.forEach(function (createComponent) { - var configValidators = createComponent.configValidators; - reactorObjectAssign(schema, configValidators); - }); - return schema; - }; - - var transformOptions = function transformOptions(schema, options) { - try { - var validator = boundObjectOf(schema).noUnknownFields().required(); - return validator(options); - } catch (e) { - throw new Error("Resolve these configuration problems:\n\t - " + e.message.split("\n").join("\n\t - ") + "\nFor configuration documentation see: " + CONFIG_DOC_URI); - } - }; - - var buildAllOnInstanceConfiguredExtraParams = function buildAllOnInstanceConfiguredExtraParams(config, logger, componentCreators) { - return componentCreators.reduce(function (memo, _ref) { - var buildOnInstanceConfiguredExtraParams = _ref.buildOnInstanceConfiguredExtraParams; - - if (buildOnInstanceConfiguredExtraParams) { - reactorObjectAssign(memo, buildOnInstanceConfiguredExtraParams({ - config: config, - logger: logger - })); - } - - return memo; - }, {}); - }; - - var buildAndValidateConfig = (function (_ref2) { - var options = _ref2.options, - componentCreators = _ref2.componentCreators, - coreConfigValidators = _ref2.coreConfigValidators, - createConfig = _ref2.createConfig, - logger = _ref2.logger, - setDebugEnabled = _ref2.setDebugEnabled; - var schema = buildSchema(coreConfigValidators, componentCreators); - var config = createConfig(transformOptions(schema, options)); - setDebugEnabled(config.debugEnabled, { - fromConfig: true - }); // eslint-disable-next-line no-underscore-dangle - - var extraParams = buildAllOnInstanceConfiguredExtraParams(config, logger, componentCreators); - logger.logOnInstanceConfigured(_objectSpread2(_objectSpread2({}, extraParams), {}, { - config: config - })); - return config; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var initializeComponents = (function (_ref) { - var componentCreators = _ref.componentCreators, - lifecycle = _ref.lifecycle, - componentRegistry = _ref.componentRegistry, - getImmediatelyAvailableTools = _ref.getImmediatelyAvailableTools; - componentCreators.forEach(function (createComponent) { - var namespace = createComponent.namespace; // TO-DOCUMENT: Helpers that we inject into factories. - - var tools = getImmediatelyAvailableTools(namespace); - var component; - - try { - component = createComponent(tools); - } catch (error) { - throw stackError({ - error: error, - message: "[" + namespace + "] An error occurred during component creation." - }); - } - - componentRegistry.register(namespace, component); - }); - return lifecycle.onComponentsRegistered({ - lifecycle: lifecycle - }).then(function () { - return componentRegistry; - }); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var createConfig = function createConfig(options) { - return reactorObjectAssign({}, options); - }; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var EDGE = "edge.adobedc.net"; - var ID_THIRD_PARTY = "adobedc.demdex.net"; - - /* - Copyright 2023 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var EDGE_BASE_PATH = "ee"; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createCoreConfigs = (function () { - return { - debugEnabled: boundBoolean().default(false), - defaultConsent: boundEnumOf(IN, OUT, PENDING).default(IN), - edgeConfigId: boundString().unique().required(), - edgeDomain: boundString().domain().default(EDGE), - edgeBasePath: boundString().nonEmpty().default(EDGE_BASE_PATH), - orgId: boundString().unique().required(), - onBeforeEventSend: boundCallback().default(noop$1), - edgeConfigOverrides: validateConfigOverride - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectHandleError = (function (_ref) { - var errorPrefix = _ref.errorPrefix, - logger = _ref.logger; - return function (error, operation) { - var err = toError(error); // In the case of declined consent, we've opted to not reject the promise - // returned to the customer, but instead resolve the promise with an - // empty result object. - - if (err.code === DECLINED_CONSENT_ERROR_CODE) { - logger.warn("The " + operation + " could not fully complete. " + err.message); - return {}; - } - - updateErrorMessage({ - error: err, - message: errorPrefix + " " + err.message - }); - throw err; - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectSendFetchRequest = (function (_ref) { - var fetch = _ref.fetch; - return function (url, body) { - return fetch(url, { - method: "POST", - cache: "no-cache", - credentials: "include", - // To set the cookie header in the request. - headers: { - "Content-Type": "text/plain; charset=UTF-8" - }, - referrerPolicy: "no-referrer-when-downgrade", - body: body - }).then(function (response) { - return response.text().then(function (responseBody) { - return { - statusCode: response.status, - // We expose headers through a function instead of creating an object - // with all the headers up front largely because the native - // request.getResponseHeader method is case-insensitive but also because it prevents - // us from having to add header parsing logic when using XHR to make requests. - getHeader: function getHeader(name) { - return response.headers.get(name); - }, - body: responseBody - }; - }); - }); - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectSendXhrRequest = (function (_ref) { - var XMLHttpRequest = _ref.XMLHttpRequest; - return function (url, body) { - return new Promise(function (resolve, reject) { - var request = new XMLHttpRequest(); - - request.onreadystatechange = function () { - if (request.readyState === 4) { - if (request.status === 0) { - reject(new Error("Request aborted.")); - } else { - resolve({ - statusCode: request.status, - // We expose headers through a function instead of creating an object - // with all the headers up front because: - // 1. It avoids having to add header parsing code to get all headers. - // 2. The native request.getResponseHeader method is case-insensitive. - getHeader: function getHeader(name) { - return request.getResponseHeader(name); - }, - body: request.responseText - }); - } - } - }; - - request.onloadstart = function () { - request.responseType = "text"; - }; - - request.open("POST", url, true); - request.setRequestHeader("Content-Type", "text/plain; charset=UTF-8"); - request.withCredentials = true; - request.onerror = reject; - request.onabort = reject; - request.send(body); - }); - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectSendBeaconRequest = (function (_ref) { - var sendBeacon = _ref.sendBeacon, - sendFetchRequest = _ref.sendFetchRequest, - logger = _ref.logger; - return function (url, body) { - var blob = new Blob([body], { - type: "text/plain; charset=UTF-8" - }); - - if (!sendBeacon(url, blob)) { - logger.info("Unable to use `sendBeacon`; falling back to `fetch`."); - return sendFetchRequest(url, body); - } // Using sendBeacon, we technically don't get a response back from - // the server, but we'll resolve the promise with an object to maintain - // consistency with other network strategies. - - - return Promise.resolve({ - statusCode: 204, - getHeader: function getHeader() { - return null; - }, - body: "" - }); - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createLogger = (function (_ref) { - var getDebugEnabled = _ref.getDebugEnabled, - console = _ref.console, - getMonitors = _ref.getMonitors, - context = _ref.context; - var prefix = "[" + context.instanceName + "]"; - - if (context.componentName) { - prefix += " [" + context.componentName + "]"; - } - - var notifyMonitors = function notifyMonitors(method, data) { - var monitors = getMonitors(); - - if (monitors.length > 0) { - var dataWithContext = reactorObjectAssign({}, context, data); - monitors.forEach(function (monitor) { - if (monitor[method]) { - monitor[method](dataWithContext); - } - }); - } - }; - - var log = function log(level) { - for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - rest[_key - 1] = arguments[_key]; - } - - notifyMonitors("onBeforeLog", { - level: level, - arguments: rest - }); - - if (getDebugEnabled()) { - console[level].apply(console, [prefix].concat(rest)); - } - }; - - return { - get enabled() { - return getMonitors().length > 0 || getDebugEnabled(); - }, - - logOnInstanceCreated: function logOnInstanceCreated(data) { - notifyMonitors("onInstanceCreated", data); - log("info", "Instance initialized."); - }, - logOnInstanceConfigured: function logOnInstanceConfigured(data) { - notifyMonitors("onInstanceConfigured", data); - log("info", "Instance configured. Computed configuration:", data.config); - }, - logOnBeforeCommand: function logOnBeforeCommand(data) { - notifyMonitors("onBeforeCommand", data); - log("info", "Executing " + data.commandName + " command. Options:", data.options); - }, - logOnCommandResolved: function logOnCommandResolved(data) { - notifyMonitors("onCommandResolved", data); - log("info", data.commandName + " command resolved. Result:", data.result); - }, - logOnCommandRejected: function logOnCommandRejected(data) { - notifyMonitors("onCommandRejected", data); - log("error", data.commandName + " command was rejected. Error:", data.error); - }, - logOnBeforeNetworkRequest: function logOnBeforeNetworkRequest(data) { - notifyMonitors("onBeforeNetworkRequest", data); - log("info", "Request " + data.requestId + ": Sending request.", data.payload); - }, - logOnNetworkResponse: function logOnNetworkResponse(data) { - notifyMonitors("onNetworkResponse", data); - var messagesSuffix = data.parsedBody || data.body ? "response body:" : "no response body."; - log("info", "Request " + data.requestId + ": Received response with status code " + data.statusCode + " and " + messagesSuffix, data.parsedBody || data.body); - }, - logOnNetworkError: function logOnNetworkError(data) { - notifyMonitors("onNetworkError", data); - log("error", "Request " + data.requestId + ": Network request failed.", data.error); - }, - - /** - * Outputs informational message to the web console. In some - * browsers a small "i" icon is displayed next to these items - * in the web console's log. - * @param {...*} arg Any argument to be logged. - */ - info: log.bind(null, "info"), - - /** - * Outputs a warning message to the web console. - * @param {...*} arg Any argument to be logged. - */ - warn: log.bind(null, "warn"), - - /** - * Outputs an error message to the web console. - * @param {...*} arg Any argument to be logged. - */ - error: log.bind(null, "error") - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var EVENT_CANCELLATION_MESSAGE = "Event was canceled because the onBeforeEventSend callback returned false."; - var createEventManager = (function (_ref) { - var config = _ref.config, - logger = _ref.logger, - lifecycle = _ref.lifecycle, - consent = _ref.consent, - createEvent = _ref.createEvent, - createDataCollectionRequestPayload = _ref.createDataCollectionRequestPayload, - createDataCollectionRequest = _ref.createDataCollectionRequest, - sendEdgeNetworkRequest = _ref.sendEdgeNetworkRequest, - _applyResponse = _ref.applyResponse; - var onBeforeEventSend = config.onBeforeEventSend, - globalConfigOverrides = config.edgeConfigOverrides; - return { - createEvent: createEvent, - - /** - * Sends an event. This includes running the event and payload through - * the appropriate lifecycle hooks, sending the request to the server, - * and handling the response. - * @param {Object} event This will be JSON stringified and used inside - * the request payload. - * @param {Object} [options] - * @param {boolean} [options.renderDecisions=false] - * @param {Array} [options.decisionScopes] Note: this option will soon - * be deprecated, please use *personalization.decisionScopes* instead - * @param {Object} [options.personalization] - * @param {Object} [options.serverState] - * This will be passed to components - * so they can take appropriate action. - * @returns {*} - */ - sendEvent: function sendEvent(event) { - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var _options$renderDecisi = options.renderDecisions, - renderDecisions = _options$renderDecisi === void 0 ? false : _options$renderDecisi, - decisionScopes = options.decisionScopes, - localConfigOverrides = options.edgeConfigOverrides, - personalization = options.personalization; - var payload = createDataCollectionRequestPayload(); - var request = createDataCollectionRequest(payload); - var onResponseCallbackAggregator = createCallbackAggregator(); - var onRequestFailureCallbackAggregator = createCallbackAggregator(); - payload.mergeConfigOverride(globalConfigOverrides); - payload.mergeConfigOverride(localConfigOverrides); - return lifecycle.onBeforeEvent({ - event: event, - renderDecisions: renderDecisions, - decisionScopes: decisionScopes, - personalization: personalization, - onResponse: onResponseCallbackAggregator.add, - onRequestFailure: onRequestFailureCallbackAggregator.add - }).then(function () { - payload.addEvent(event); - return consent.awaitConsent(); - }).then(function () { - try { - // NOTE: this calls onBeforeEventSend callback (if configured) - event.finalize(onBeforeEventSend); - } catch (error) { - var throwError = function throwError() { - throw error; - }; - - onRequestFailureCallbackAggregator.add(lifecycle.onRequestFailure); - return onRequestFailureCallbackAggregator.call({ - error: error - }).then(throwError, throwError); - } // if the callback returns false, the event should not be sent - - - if (!event.shouldSend()) { - onRequestFailureCallbackAggregator.add(lifecycle.onRequestFailure); - logger.info(EVENT_CANCELLATION_MESSAGE); - var error = new Error(EVENT_CANCELLATION_MESSAGE); - return onRequestFailureCallbackAggregator.call({ - error: error - }).then(function () {// Ensure the promise gets resolved with undefined instead - // of an array of return values from the callbacks. - }); - } - - return sendEdgeNetworkRequest({ - request: request, - runOnResponseCallbacks: onResponseCallbackAggregator.call, - runOnRequestFailureCallbacks: onRequestFailureCallbackAggregator.call - }); - }); - }, - applyResponse: function applyResponse(event) { - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var _options$renderDecisi2 = options.renderDecisions, - renderDecisions = _options$renderDecisi2 === void 0 ? false : _options$renderDecisi2, - _options$responseHead = options.responseHeaders, - responseHeaders = _options$responseHead === void 0 ? {} : _options$responseHead, - _options$responseBody = options.responseBody, - responseBody = _options$responseBody === void 0 ? { - handle: [] - } : _options$responseBody; - var payload = createDataCollectionRequestPayload(); - var request = createDataCollectionRequest(payload); - var onResponseCallbackAggregator = createCallbackAggregator(); - return lifecycle.onBeforeEvent({ - event: event, - renderDecisions: renderDecisions, - decisionScopes: [PAGE_WIDE_SCOPE], - personalization: {}, - onResponse: onResponseCallbackAggregator.add, - onRequestFailure: noop$1 - }).then(function () { - payload.addEvent(event); - return _applyResponse({ - request: request, - responseHeaders: responseHeaders, - responseBody: responseBody, - runOnResponseCallbacks: onResponseCallbackAggregator.call - }); - }); - } - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var STATE_STORE_HANDLE_TYPE = "state:store"; - var createCookieTransfer = (function (_ref) { - var cookieJar = _ref.cookieJar, - shouldTransferCookie = _ref.shouldTransferCookie, - apexDomain = _ref.apexDomain, - dateProvider = _ref.dateProvider; - return { - /** - * When sending to a third-party endpoint, the endpoint won't be able to - * access first-party cookies, therefore we transfer cookies into - * the request body so they can be read by the server. - */ - cookiesToPayload: function cookiesToPayload(payload, endpointDomain) { - var isEndpointFirstParty = endsWith(endpointDomain, apexDomain); - var state = { - domain: apexDomain, - cookiesEnabled: true - }; // If the endpoint is first-party, there's no need to transfer cookies - // to the payload since they'll be automatically passed through cookie - // headers. - - if (!isEndpointFirstParty) { - var cookies = cookieJar.get(); - var entries = Object.keys(cookies).filter(shouldTransferCookie).map(function (qualifyingCookieName) { - return { - key: qualifyingCookieName, - value: cookies[qualifyingCookieName] - }; - }); - - if (entries.length) { - state.entries = entries; - } - } - - payload.mergeState(state); - }, - - /** - * When receiving from a third-party endpoint, the endpoint won't be able to - * write first-party cookies, therefore we write first-party cookies - * as directed in the response body. - */ - responseToCookies: function responseToCookies(response) { - response.getPayloadsByType(STATE_STORE_HANDLE_TYPE).forEach(function (stateItem) { - var options = { - domain: apexDomain - }; - var sameSite = stateItem.attrs && stateItem.attrs.SameSite && stateItem.attrs.SameSite.toLowerCase(); - - if (stateItem.maxAge !== undefined) { - // cookieJar expects "expires" as a date object - options.expires = new Date(dateProvider().getTime() + stateItem.maxAge * 1000); - } - - if (sameSite !== undefined) { - options.sameSite = sameSite; - } // When sameSite is set to none, the secure flag must be set. - // Experience edge will not set the secure flag in these cases. - - - if (sameSite === "none") { - options.secure = true; - } - - cookieJar.set(stateItem.key, stateItem.value, options); - }); - } - }; - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var MBOX_EDGE_CLUSTER = "mboxEdgeCluster"; - var AT_QA_MODE = "at_qa_mode"; - var MBOX = "mbox"; - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectShouldTransferCookie = (function (_ref) { - var orgId = _ref.orgId, - targetMigrationEnabled = _ref.targetMigrationEnabled; - return function (name) { - // We have a contract with the server that we will pass - // all cookies whose names are namespaced according to the - // logic in isNamespacedCookieName as well as any legacy - // cookie names (so that the server can handle migrating - // identities on websites previously using Visitor.js) - return isNamespacedCookieName(orgId, name) || name === AT_QA_MODE || targetMigrationEnabled && name === MBOX; - }; - }); - - /* - Copyright 2023 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var apiVersion = "v1"; - - var mergeLifecycleResponses = (function (returnValues) { - // Merges all returned objects from all `onResponse` callbacks into - // a single object that can later be returned to the customer. - var lifecycleOnResponseReturnValues = returnValues.shift() || []; - var consumerOnResponseReturnValues = returnValues.shift() || []; - var lifecycleOnBeforeRequestReturnValues = returnValues; - return reactorObjectAssign.apply(void 0, [{}].concat(_toConsumableArray(lifecycleOnResponseReturnValues), _toConsumableArray(consumerOnResponseReturnValues), _toConsumableArray(lifecycleOnBeforeRequestReturnValues))); - }); - - /* - Copyright 2023 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var handleRequestFailure = (function (onRequestFailureCallbackAggregator) { - return function (error) { - // Regardless of whether the network call failed, an unexpected status - // code was returned, or the response body was malformed, we want to call - // the onRequestFailure callbacks, but still throw the exception. - var throwError = function throwError() { - throw error; - }; - - return onRequestFailureCallbackAggregator.call({ - error: error - }).then(throwError, throwError); - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectSendEdgeNetworkRequest = (function (_ref) { - var config = _ref.config, - lifecycle = _ref.lifecycle, - cookieTransfer = _ref.cookieTransfer, - sendNetworkRequest = _ref.sendNetworkRequest, - createResponse = _ref.createResponse, - processWarningsAndErrors = _ref.processWarningsAndErrors, - getLocationHint = _ref.getLocationHint, - getAssuranceValidationTokenParams = _ref.getAssuranceValidationTokenParams; - var edgeDomain = config.edgeDomain, - edgeBasePath = config.edgeBasePath, - edgeConfigId = config.edgeConfigId; - /** - * Sends a network request that is aware of payload interfaces, - * lifecycle methods, configured edge domains, response structures, etc. - */ - - return function (_ref2) { - var request = _ref2.request, - _ref2$runOnResponseCa = _ref2.runOnResponseCallbacks, - runOnResponseCallbacks = _ref2$runOnResponseCa === void 0 ? noop$1 : _ref2$runOnResponseCa, - _ref2$runOnRequestFai = _ref2.runOnRequestFailureCallbacks, - runOnRequestFailureCallbacks = _ref2$runOnRequestFai === void 0 ? noop$1 : _ref2$runOnRequestFai; - var onResponseCallbackAggregator = createCallbackAggregator(); - onResponseCallbackAggregator.add(lifecycle.onResponse); - onResponseCallbackAggregator.add(runOnResponseCallbacks); - var onRequestFailureCallbackAggregator = createCallbackAggregator(); - onRequestFailureCallbackAggregator.add(lifecycle.onRequestFailure); - onRequestFailureCallbackAggregator.add(runOnRequestFailureCallbacks); - return lifecycle.onBeforeRequest({ - request: request, - onResponse: onResponseCallbackAggregator.add, - onRequestFailure: onRequestFailureCallbackAggregator.add - }).then(function () { - var endpointDomain = request.getUseIdThirdPartyDomain() ? ID_THIRD_PARTY : edgeDomain; - var locationHint = getLocationHint(); - var edgeBasePathWithLocationHint = locationHint ? edgeBasePath + "/" + locationHint : edgeBasePath; - var url = "https://" + endpointDomain + "/" + edgeBasePathWithLocationHint + "/" + apiVersion + "/" + request.getAction() + "?configId=" + edgeConfigId + "&requestId=" + request.getId() + getAssuranceValidationTokenParams(); - cookieTransfer.cookiesToPayload(request.getPayload(), endpointDomain); - return sendNetworkRequest({ - requestId: request.getId(), - url: url, - payload: request.getPayload(), - useSendBeacon: request.getUseSendBeacon() - }); - }).then(function (networkResponse) { - processWarningsAndErrors(networkResponse); - return networkResponse; - }).catch(handleRequestFailure(onRequestFailureCallbackAggregator)).then(function (_ref3) { - var parsedBody = _ref3.parsedBody, - getHeader = _ref3.getHeader; - // Note that networkResponse.parsedBody may be undefined if it was a - // 204 No Content response. That's fine. - var response = createResponse({ - content: parsedBody, - getHeader: getHeader - }); - cookieTransfer.responseToCookies(response); // Notice we're calling the onResponse lifecycle method even if there are errors - // inside the response body. This is because the full request didn't actually fail-- - // only portions of it that are considered non-fatal (a specific, non-critical - // Konductor plugin, for example). - - return onResponseCallbackAggregator.call({ - response: response - }).then(mergeLifecycleResponses); - }); - }; - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var NO_CONTENT = 204; - var TOO_MANY_REQUESTS = 429; - var BAD_GATEWAY = 502; - var SERVICE_UNAVAILABLE = 503; - var GATEWAY_TIMEOUT = 504; - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var MESSAGE_PREFIX = "The server responded with a"; - var injectProcessWarningsAndErrors = (function (_ref) { - var logger = _ref.logger; - return function (networkResponse) { - var statusCode = networkResponse.statusCode, - body = networkResponse.body, - parsedBody = networkResponse.parsedBody; - - if (statusCode < 200 || statusCode >= 300 || !parsedBody && statusCode !== NO_CONTENT || parsedBody && !Array.isArray(parsedBody.handle)) { - var bodyToLog = parsedBody ? JSON.stringify(parsedBody, null, 2) : body; - var messageSuffix = bodyToLog ? "response body:\n" + bodyToLog : "no response body."; - throw new Error(MESSAGE_PREFIX + " status code " + statusCode + " and " + messageSuffix); - } - - if (parsedBody) { - var _parsedBody$warnings = parsedBody.warnings, - warnings = _parsedBody$warnings === void 0 ? [] : _parsedBody$warnings, - _parsedBody$errors = parsedBody.errors, - errors = _parsedBody$errors === void 0 ? [] : _parsedBody$errors; - warnings.forEach(function (warning) { - logger.warn(MESSAGE_PREFIX + " warning:", warning); - }); - errors.forEach(function (error) { - logger.error(MESSAGE_PREFIX + " non-fatal error:", error); - }); - } - }; - }); - - /* - Copyright 2022 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var injectGetLocationHint = (function (_ref) { - var orgId = _ref.orgId, - cookieJar = _ref.cookieJar; - var clusterCookieName = getNamespacedCookieName(orgId, CLUSTER); - - var fromClusterCookie = function fromClusterCookie() { - return cookieJar.get(clusterCookieName); - }; - - var fromTarget = function fromTarget() { - var mboxEdgeCluster = cookieJar.get(MBOX_EDGE_CLUSTER); - - if (mboxEdgeCluster) { - return "t" + mboxEdgeCluster; - } - - return undefined; - }; - - return function () { - return fromClusterCookie() || fromTarget(); - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var MAX_RETRIES = 3; - var RETRYABLE_STATUS_CODES = [TOO_MANY_REQUESTS, SERVICE_UNAVAILABLE, BAD_GATEWAY, GATEWAY_TIMEOUT]; // These rules are in accordance with - // https://git.corp.adobe.com/pages/experience-edge/konductor/#/apis/errors?id=handling-4xx-and-5xx-responses - - var isRequestRetryable = (function (_ref) { - var response = _ref.response, - retriesAttempted = _ref.retriesAttempted; - return retriesAttempted < MAX_RETRIES && includes(RETRYABLE_STATUS_CODES, response.statusCode); - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - - var FIRST_DELAY_MILLIS = 1000; - var INCREMENTAL_DELAY_MILLIS = 1000; // When the target delay is randomized, make it within the range of this percentage above or below the target delay. - - var MAX_RANDOM_VARIANCE_PERCENTAGE = 0.3; - - var calculateRetryDelay = function calculateRetryDelay(retriesAttempted) { - var targetDelay = FIRST_DELAY_MILLIS + retriesAttempted * INCREMENTAL_DELAY_MILLIS; - var maxVariance = targetDelay * MAX_RANDOM_VARIANCE_PERCENTAGE; - var minDelay = targetDelay - maxVariance; - var maxDelay = targetDelay + maxVariance; - var randomizedDelayWithinRange = Math.round(minDelay + Math.random() * (maxDelay - minDelay)); - return randomizedDelayWithinRange; - }; - - var getDelayFromHeader = function getDelayFromHeader(response) { - // According to the HTTP spec, if the header is defined, its value will be a string that - // represents either: - // * An integer indicating the number of seconds to delay. - // * A date after which a retry may occur. The date would be in HTTP-date - // format (https://tools.ietf.org/html/rfc7231#section-7.1.1.1). When debugging, it can - // be helpful to know that this is the same format that a JavaScript date's - // toGMTString() returns. - var headerValue = response.getHeader(RETRY_AFTER); - var delayInMillis; - - if (headerValue) { - var headerValueInt = parseInt(headerValue, 10); - - if (isInteger(headerValueInt)) { - delayInMillis = headerValueInt * 1000; - } else { - delayInMillis = Math.max(0, new Date(headerValue).getTime() - new Date().getTime()); - } - } - - return delayInMillis; - }; // These rules are in accordance with - // https://git.corp.adobe.com/pages/experience-edge/konductor/#/apis/errors?id=handling-4xx-and-5xx-responses - // For retry delays that don't come from a Retry-After response header, we try to stick with the following best - // practices outlined in https://docs.microsoft.com/en-us/azure/architecture/best-practices/transient-faults: - // * Incremental retry - // * Random interval - - - var getRequestRetryDelay = (function (_ref) { - var response = _ref.response, - retriesAttempted = _ref.retriesAttempted; - // Technically, only 429 or 503 responses should have a Retry-After header, but we'll respect the - // header if we find it on any response. - var delayInMillis = getDelayFromHeader(response); // Note that the value of delay may be 0 at this point, which would be a valid delay we want to use - // and not override, which is why we don't do: - // if (!delay) { ... } - - if (delayInMillis === undefined) { - delayInMillis = calculateRetryDelay(retriesAttempted); - } - - return delayInMillis; - }); - - /* - Copyright 2023 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var HTTP_STATUS_OK = 200; - var injectApplyResponse = (function (_ref) { - var cookieTransfer = _ref.cookieTransfer, - lifecycle = _ref.lifecycle, - createResponse = _ref.createResponse, - processWarningsAndErrors = _ref.processWarningsAndErrors; - return function (_ref2) { - var request = _ref2.request, - responseHeaders = _ref2.responseHeaders, - responseBody = _ref2.responseBody, - _ref2$runOnResponseCa = _ref2.runOnResponseCallbacks, - runOnResponseCallbacks = _ref2$runOnResponseCa === void 0 ? noop$1 : _ref2$runOnResponseCa, - _ref2$runOnRequestFai = _ref2.runOnRequestFailureCallbacks, - runOnRequestFailureCallbacks = _ref2$runOnRequestFai === void 0 ? noop$1 : _ref2$runOnRequestFai; - var onResponseCallbackAggregator = createCallbackAggregator(); - onResponseCallbackAggregator.add(lifecycle.onResponse); - onResponseCallbackAggregator.add(runOnResponseCallbacks); - var onRequestFailureCallbackAggregator = createCallbackAggregator(); - onRequestFailureCallbackAggregator.add(lifecycle.onRequestFailure); - onRequestFailureCallbackAggregator.add(runOnRequestFailureCallbacks); - - var getHeader = function getHeader(key) { - return responseHeaders[key]; - }; - - return lifecycle.onBeforeRequest({ - request: request, - onResponse: onResponseCallbackAggregator.add, - onRequestFailure: onRequestFailureCallbackAggregator.add - }).then(function () { - return processWarningsAndErrors({ - statusCode: HTTP_STATUS_OK, - getHeader: getHeader, - body: JSON.stringify(responseBody), - parsedBody: responseBody - }); - }).catch(handleRequestFailure(onRequestFailureCallbackAggregator)).then(function () { - var response = createResponse({ - content: responseBody, - getHeader: getHeader - }); // This will clobber any cookies set via HTTP from the server. So care should be given to remove any state:store handles if that is not desirable - - cookieTransfer.responseToCookies(response); - return onResponseCallbackAggregator.call({ - response: response - }).then(mergeLifecycleResponses); - }); - }; - }); - - /* - Copyright 2019 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - var createNamespacedStorage = injectStorage(window); - var _window = window, - console$1 = _window.console, - fetch = _window.fetch, - navigator$1 = _window.navigator, - XMLHttpRequest = _window.XMLHttpRequest; // set this up as a function so that monitors can be added at anytime - // eslint-disable-next-line no-underscore-dangle - - var getMonitors = function getMonitors() { - return window.__alloyMonitors || []; - }; - - var coreConfigValidators = createCoreConfigs(); - var apexDomain = getApexDomain(window, cookieJar); - var sendFetchRequest = isFunction(fetch) ? injectSendFetchRequest({ - fetch: fetch - }) : injectSendXhrRequest({ - XMLHttpRequest: XMLHttpRequest - }); - var fireReferrerHideableImage = injectFireReferrerHideableImage(); - var getAssuranceValidationTokenParams = createGetAssuranceValidationTokenParams({ - window: window, - createNamespacedStorage: createNamespacedStorage - }); - var createExecuteCommand = function createExecuteCommand(_ref) { - var instanceName = _ref.instanceName, - _ref$logController = _ref.logController, - setDebugEnabled = _ref$logController.setDebugEnabled, - logger = _ref$logController.logger, - createComponentLogger = _ref$logController.createComponentLogger; - var componentRegistry = createComponentRegistry(); - var lifecycle = createLifecycle(componentRegistry); - - var setDebugCommand = function setDebugCommand(options) { - setDebugEnabled(options.enabled, { - fromConfig: false - }); - }; - - var loggingCookieJar = createLoggingCookieJar({ - logger: logger, - cookieJar: cookieJar - }); - - var configureCommand = function configureCommand(options) { - var config = buildAndValidateConfig({ - options: options, - componentCreators: componentCreators, - coreConfigValidators: coreConfigValidators, - createConfig: createConfig, - logger: logger, - setDebugEnabled: setDebugEnabled - }); - var orgId = config.orgId, - targetMigrationEnabled = config.targetMigrationEnabled; - var shouldTransferCookie = injectShouldTransferCookie({ - orgId: orgId, - targetMigrationEnabled: targetMigrationEnabled - }); - var cookieTransfer = createCookieTransfer({ - cookieJar: loggingCookieJar, - shouldTransferCookie: shouldTransferCookie, - apexDomain: apexDomain, - dateProvider: function dateProvider() { - return new Date(); - } - }); - var sendBeaconRequest = isFunction(navigator$1.sendBeacon) ? injectSendBeaconRequest({ - // Without the bind(), the browser will complain about an - // illegal invocation. - sendBeacon: navigator$1.sendBeacon.bind(navigator$1), - sendFetchRequest: sendFetchRequest, - logger: logger - }) : sendFetchRequest; - var sendNetworkRequest = injectSendNetworkRequest({ - logger: logger, - sendFetchRequest: sendFetchRequest, - sendBeaconRequest: sendBeaconRequest, - isRequestRetryable: isRequestRetryable, - getRequestRetryDelay: getRequestRetryDelay - }); - var processWarningsAndErrors = injectProcessWarningsAndErrors({ - logger: logger - }); - var extractEdgeInfo = injectExtractEdgeInfo({ - logger: logger - }); - var createResponse = injectCreateResponse({ - extractEdgeInfo: extractEdgeInfo - }); - var getLocationHint = injectGetLocationHint({ - orgId: orgId, - cookieJar: cookieJar - }); - var sendEdgeNetworkRequest = injectSendEdgeNetworkRequest({ - config: config, - lifecycle: lifecycle, - cookieTransfer: cookieTransfer, - sendNetworkRequest: sendNetworkRequest, - createResponse: createResponse, - processWarningsAndErrors: processWarningsAndErrors, - getLocationHint: getLocationHint, - getAssuranceValidationTokenParams: getAssuranceValidationTokenParams - }); - var applyResponse = injectApplyResponse({ - lifecycle: lifecycle, - cookieTransfer: cookieTransfer, - createResponse: createResponse, - processWarningsAndErrors: processWarningsAndErrors - }); - var generalConsentState = createConsentStateMachine({ - logger: logger - }); - var consent = createConsent({ - generalConsentState: generalConsentState, - logger: logger - }); - var eventManager = createEventManager({ - config: config, - logger: logger, - lifecycle: lifecycle, - consent: consent, - createEvent: createEvent, - createDataCollectionRequestPayload: createDataCollectionRequestPayload, - createDataCollectionRequest: createDataCollectionRequest, - sendEdgeNetworkRequest: sendEdgeNetworkRequest, - applyResponse: applyResponse - }); - return initializeComponents({ - componentCreators: componentCreators, - lifecycle: lifecycle, - componentRegistry: componentRegistry, - getImmediatelyAvailableTools: function getImmediatelyAvailableTools(componentName) { - var componentLogger = createComponentLogger(componentName); - return { - config: config, - componentRegistry: componentRegistry, - consent: consent, - eventManager: eventManager, - fireReferrerHideableImage: fireReferrerHideableImage, - logger: componentLogger, - lifecycle: lifecycle, - sendEdgeNetworkRequest: sendEdgeNetworkRequest, - handleError: injectHandleError({ - errorPrefix: "[" + instanceName + "] [" + componentName + "]", - logger: componentLogger - }), - createNamespacedStorage: createNamespacedStorage, - apexDomain: apexDomain - }; - } - }); - }; - - var handleError = injectHandleError({ - errorPrefix: "[" + instanceName + "]", - logger: logger - }); - var executeCommand = injectExecuteCommand({ - logger: logger, - configureCommand: configureCommand, - setDebugCommand: setDebugCommand, - handleError: handleError, - validateCommandOptions: validateCommandOptions - }); - return executeCommand; - }; - var core = (function () { - // eslint-disable-next-line no-underscore-dangle - var instanceNames = window.__alloyNS; - - if (instanceNames) { - instanceNames.forEach(function (instanceName) { - var logController = createLogController({ - console: console$1, - locationSearch: window.location.search, - createLogger: createLogger, - instanceName: instanceName, - createNamespacedStorage: createNamespacedStorage, - getMonitors: getMonitors - }); - var executeCommand = createExecuteCommand({ - instanceName: instanceName, - logController: logController - }); - var instance = createInstanceFunction(executeCommand); - var queue = window[instanceName].q; - queue.push = instance; - logController.logger.logOnInstanceCreated({ - instance: instance - }); - queue.forEach(instance); - }); - } - }); - - /* - Copyright 2020 Adobe. All rights reserved. - This file is licensed to you under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. You may obtain a copy - of the License at http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software distributed under - the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - OF ANY KIND, either express or implied. See the License for the specific language - governing permissions and limitations under the License. - */ - core(); - -})(); diff --git a/scripts/alloy.min.js b/scripts/alloy.min.js deleted file mode 100644 index aacf2bf3..00000000 --- a/scripts/alloy.min.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Copyright 2019 Adobe. All rights reserved. - * This file is licensed to you under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy - * of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under - * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS - * OF ANY KIND, either express or implied. See the License for the specific language - * governing permissions and limitations under the License. - */ - -!function(){"use strict";if(document.documentMode&&document.documentMode<11)console.warn("The Adobe Experience Cloud Web SDK does not support IE 10 and below.");else{var e="Chrome",n="Edge",t="EdgeChromium",r="Unknown",o=function(e,n){return-1!==e.indexOf(n)},i=[e,n,t,"IE",r],a=function(e){return o(i,e)},c=Object.getOwnPropertySymbols,u=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,d=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var n={},t=0;t<10;t++)n["_"+String.fromCharCode(t)]=t;if("0123456789"!==Object.getOwnPropertyNames(n).map((function(e){return n[e]})).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach((function(e){r[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}()?Object.assign:function(e,n){for(var t,r,o=Ci(e),i=1;i1?t-1:0),o=1;o>>1:t>>>1;e.push(t)}return function(n,t){n=unescape(encodeURIComponent(n)),t||(t=0),t^=-1;for(var r=0;r>>8^e[o]}return(t^=-1)>>>0}}(),I=function(){var e={};return e.promise=new Promise((function(n,t){e.resolve=n,e.reject=t})),e},D=function(e,n){for(var t=0;t1&&void 0!==arguments[1]?arguments[1]:{},t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:document,i=o.createElement(e);return Object.keys(n).forEach((function(e){i.setAttribute(e,n[e])})),k(i,t),r.forEach((function(e){return R(i,e)})),i},O="BODY",P="IFRAME",x="IMG",q="STYLE",N="SCRIPT",A=function(e){var n=e.src,t=e.currentDocument,r=void 0===t?document:t;return new Promise((function(e,t){S(x,{src:n},{onload:e,onerror:t,onabort:t},[],r)}))},M=function(e){return"function"==typeof e},T=function(e){return Array.isArray(e)&&e.length>0},j=function(e){return Array.isArray(e)?e:null==e?[]:[].slice.call(e)},U=/^\s*>/,L=function(e,n){if(!U.test(n))return j(e.querySelectorAll(n));var t="alloy-"+Date.now();try{return e.classList.add(t),j(e.querySelectorAll("."+t+" "+n))}finally{e.classList.remove(t)}},B=function(e,n){return e.substr(0,n.length)===n},F=":shadow",_=function(e,n){var t=n.trim();return B(t,">")?window.document.documentMode?t.substring(1).trim():(e instanceof Element||e instanceof HTMLDocument?":scope":":host")+" "+t:t},H=function(e,n){if(!window.document.documentElement.attachShadow)return L(e,n.replace(F,""));var t=function(e){return e.split(F)}(n);if(t.length<2)return L(e,n);for(var r=e,o=0;o1&&void 0!==arguments[1]?arguments[1]:document;return V(e)?H(n,e):L(n,e)},J={childList:!0,subtree:!0},W=function(e){return new Error("Could not find: "+e)},Q=function(e){return new Promise(e)},X=function(e){return M(e.MutationObserver)},$=function(e,n,t,r,o){return Q((function(i,a){var c=new e.MutationObserver((function(){var e=o(t);T(e)&&(c.disconnect(),i(e))}));setTimeout((function(){c.disconnect(),a(W(t))}),r),c.observe(n,J)}))},Y=function(e){return"visible"===e.visibilityState},G=function(e,n,t,r){return Q((function(o,i){!function t(){var i=r(n);T(i)?o(i):e.requestAnimationFrame(t)}(),setTimeout((function(){i(W(n))}),t)}))},K=function(e,n,t){return Q((function(r,o){!function n(){var o=t(e);T(o)?r(o):setTimeout(n,100)}(),setTimeout((function(){o(W(e))}),n)}))},Z=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:z,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:5e3,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:window,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:document,i=n(e);return T(i)?Promise.resolve(i):X(r)?$(r,o,e,t,n):Y(o)?G(r,e,t,n):K(e,t,n)},ee=function(e){var n=e.parentNode;return n?n.removeChild(e):null},ne={name:"Adobe Alloy"},te={style:{display:"none",width:0,height:0}},re=function(e){return m(e)&&0===Object.keys(e).length},oe=function e(n,t){return v(n)||!m(n)?n:Object.keys(n).reduce((function(r,o){var i=n[o];if(m(i)){var a=e(i,t);return re(a)?r:Di(Di({},r),{},ki({},o,a))}return t(i)?Di(Di({},r),{},ki({},o,i)):r}),{})},ie=function(e,n){return Array.prototype.concat.apply([],e.map(n))},ae="com.adobe.alloy.",ce=ae+"getTld",ue=function(e){return e.replace("@","_")},se=function(e,n){return"kndctr_"+ue(e)+"_"+n},de=function(e){var n=e.orgId,t=se(n,"identity");return function(){return Boolean(p.get(t))}},fe=function(e,n,t){return{getItem:function(r){try{return e[n].getItem(t+r)}catch(e){return null}},setItem:function(r,o){try{return e[n].setItem(t+r,o),!0}catch(e){return!1}},clear:function(){try{return Object.keys(e[n]).forEach((function(r){B(r,t)&&e[n].removeItem(r)})),!0}catch(e){return!1}}}},le=function(e,n){return e.filter((function(e){return o(n,e)}))},ge=function(e){return"boolean"==typeof e},pe=function(e){return"number"==typeof e&&!isNaN(e)},ve=function(e){var n=parseInt(e,10);return pe(n)&&e===n},me=function(e){return"string"==typeof e},he=function(e){return me(e)&&e.length>0},ye=function(){},we=function(e,n,t){var r=String(e),o=String(t);if(r.length>=n||0===o.length)return r;for(var i=n-r.length;i>o.length;)o+=o;return o.slice(0,i)+r},be=function(e){if(v(e)||"object"!==Ri(e))return null;var n=oe(e,(function(e){return!v(e)&&(!!ge(e)||(!!pe(e)||(!!he(e)||!!T(e))))}));return re(n)?null:n},Ce=function(e,n,t,r){n=n||"&",t=t||"=";var o={};if("string"!=typeof e||0===e.length)return o;var i=/\+/g;e=e.split(n);var a=1e3;r&&"number"==typeof r.maxKeys&&(a=r.maxKeys);var c=e.length;a>0&&c>a&&(c=a);for(var u=0;u=0?(s=g.substr(0,p),d=g.substr(p+1)):(s=g,d=""),f=decodeURIComponent(s),l=decodeURIComponent(d),Ni(o,f)?Array.isArray(o[f])?o[f].push(l):o[f]=[o[f],l]:o[f]=l}return o},Ee=function(e){switch(Ri(e)){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}},Ie=function(e,n,t,r){return n=n||"&",t=t||"=",null===e&&(e=void 0),"object"===Ri(e)?Object.keys(e).map((function(r){var o=encodeURIComponent(Ee(r))+t;return Array.isArray(e[r])?e[r].map((function(e){return o+encodeURIComponent(Ee(e))})).join(n):o+encodeURIComponent(Ee(e[r]))})).join(n):r?encodeURIComponent(Ee(r))+t+encodeURIComponent(Ee(e)):""},De=Ei((function(e,n){n.decode=n.parse=Ce,n.encode=n.stringify=Ie}));De.decode,De.parse,De.encode,De.stringify;for(var Re=function(e){return"string"==typeof e&&(e=e.trim().replace(/^[?#&]/,"")),De.parse(e)},ke=function(e){return De.stringify(e)},Se=function(e){return e instanceof Error?e:new Error(e)},Oe=function(e){var n=e.error,t=e.message;try{n.message=t}catch(e){}},Pe=function(e){var n=e.error,t=e.message,r=Se(n),o=t+"\nCaused by: "+r.message;return Oe({error:r,message:o}),r},xe=function(e,n){if(pe(e)||me(e)){var t=Math.round(Number(e));if(!isNaN(t))return t}return n},qe=Ei((function(e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var t=new Uint8Array(16);e.exports=function(){return n(t),t}}else{var r=new Array(16);e.exports=function(){for(var e,n=0;n<16;n++)0==(3&n)&&(e=4294967296*Math.random()),r[n]=e>>>((3&n)<<3)&255;return r}}})),Ne=[],Ae=0;Ae<256;++Ae)Ne[Ae]=(Ae+256).toString(16).substr(1);var Me=function(e,n){var t=n||0,r=Ne;return[r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]]].join("")},Te=function(e,n,t){var r=n&&t||0;"string"==typeof e&&(n="binary"===e?new Array(16):null,e=null);var o=(e=e||{}).random||(e.rng||qe)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,n)for(var i=0;i<16;++i)n[r+i]=o[i];return n||Me(o)},je=function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=function(t,r){return n(e(t,r),r)};return f(r,e,t),r},Ue=function(e,n,t){return je(e,(function(e,t){return null==e?e:n(e,t)}),t)},Le=function(e,n,t,r){if(!e)throw new Error("'"+t+"': Expected "+r+", but got "+JSON.stringify(n)+".")},Be=function(e,n){return Le(ge(e),e,n,"true or false"),e},Fe=function(e,n){return Le(M(e),e,n,"a function"),e},_e=function(e,n){return function(t,r){return Le(t>=n,t,r,e+" greater than or equal to "+n),t}},He=function(e){return function(n,t){return m(n)?Le(!re(n),n,t,e):Le(n.length>0,n,t,e),n}},Ve=function(){return function(e,n){Le(function(e){for(var n=Object.create(null),t=0;t1&&void 0!==arguments[1]?arguments[1]:{},r=le(Object.keys(n),Object.keys(t));if(r.length)throw new Error("[ComponentRegistry] Could not register "+e+" because it has existing command(s): "+r.join(","));Object.keys(t).forEach((function(r){var o=t[r];o.commandName=r,o.run=Dn(o.run,"["+e+"] An error occurred while executing the "+r+" command."),n[r]=o}))}(r,i),function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Object.keys(n).forEach((function(r){t[r]=t[r]||[],t[r].push(Dn(n[r],"["+e+"] An error occurred while executing the "+r+" lifecycle hook."))}))}(r,a),e[r]=o},getCommand:function(e){return n[e]},getCommandNames:function(){return Object.keys(n)},getLifecycleCallbacks:function(e){return t[e]||[]}}},kn="in",Sn="pending",On="general",Pn="declinedConsent",xn="default",qn="initial",Nn="new",An=function(e){var n=new Error(e);return n.code=Pn,n.message=e,n},Mn=function(e){var n=e.logger,t=[],r=function(){return Promise.resolve()},o=function(){return Promise.resolve()},i=function(){return Promise.reject(An("No consent preferences have been set."))},a=function(){return Promise.reject(An("The user declined consent."))},c=function(e){if(e)return Promise.reject(new Error("Consent is pending."));var n=I();return t.push(n),n.promise};return{in:function(e){e===xn?this.awaitConsent=r:(e===qn?n.info("Loaded user consent preferences. The user previously consented."):e===Nn&&this.awaitConsent!==o&&n.info("User consented."),function(){for(;t.length;)t.shift().resolve()}(),this.awaitConsent=o)},out:function(e){e===xn?(n.warn("User consent preferences not found. Default consent of out will be used."),this.awaitConsent=i):(e===qn?n.warn("Loaded user consent preferences. The user previously declined consent."):e===Nn&&this.awaitConsent!==a&&n.warn("User declined consent."),function(){for(;t.length;)t.shift().reject(An("The user declined consent."))}(),this.awaitConsent=a)},pending:function(e){e===xn&&n.info("User consent preferences not found. Default consent of pending will be used. Some commands may be delayed."),this.awaitConsent=c},awaitConsent:function(){return Promise.reject(new Error("Consent has not been initialized."))},withConsent:function(){return this.awaitConsent(!0)}}},Tn=function(){var e,n,t={},r=!1,o=!1,i=!0,a=function(e){if(o)throw new Error(e+" cannot be called after event is finalized.")},c={setUserXdm:function(n){a("setUserXdm"),e=n},setUserData:function(e){a("setUserData"),n=e},mergeXdm:function(e){a("mergeXdm"),e&&y(t,{xdm:e})},mergeMeta:function(e){a("mergeMeta"),e&&y(t,{meta:e})},mergeQuery:function(e){a("mergeQuery"),e&&y(t,{query:e})},documentMayUnload:function(){r=!0},finalize:function(r){if(!o&&(e&&c.mergeXdm(e),n&&(t.data=n),o=!0,r)){i=!1;var a={xdm:t.xdm||{},data:t.data||{}},u=r(a);i=!1!==u,t.xdm=a.xdm||{},t.data=a.data||{},re(t.xdm)&&delete t.xdm,re(t.data)&&delete t.data}},getDocumentMayUnload:function(){return r},isEmpty:function(){return re(t)&&(!e||re(e))&&(!n||re(n))},shouldSend:function(){return i},getViewName:function(){if(e&&e.web&&e.web.webPageDetails)return e.web.webPageDetails.viewName},toJSON:function(){if(!o)throw new Error("toJSON called before finalize");return t}};return c},jn="configure",Un="setDebug",Ln=function(e){var n=e.command,t=e.options,r=n.commandName,o=n.documentationUri,i=void 0===o?"https://adobe.ly/3sHgQHb":o,a=n.optionsValidator,c=t;if(a)try{c=a(t)}catch(e){throw new Error("Invalid "+r+" command options:\n\t - "+e+" For command documentation see: "+i)}return c},Bn=function(e){var n=e.eventManager,t=e.logger;return{commands:{sendEvent:{documentationUri:"https://adobe.ly/3GQ3Q7t",optionsValidator:function(e){return function(e){var n=e.options;return mn({type:hn(),xdm:mn({eventType:hn(),identityMap:wn}),data:mn({}),documentUnloading:ln(),renderDecisions:ln(),decisionScopes:fn(hn()).uniqueItems(),personalization:mn({decisionScopes:fn(hn()).uniqueItems(),surfaces:fn(hn()).uniqueItems()}),datasetId:hn(),mergeId:hn(),edgeConfigOverrides:bn}).required().noUnknownFields()(n)}({options:e})},run:function(e){var r=e.xdm,o=e.data,i=e.documentUnloading,a=void 0!==i&&i,c=e.type,u=e.mergeId,s=e.renderDecisions,d=void 0!==s&&s,f=e.decisionScopes,l=void 0===f?[]:f,g=e.personalization,p=void 0===g?{}:g,v=e.datasetId,m=e.edgeConfigOverrides,h=n.createEvent();a&&h.documentMayUnload(),h.setUserXdm(r),h.setUserData(o),c&&h.mergeXdm({eventType:c}),u&&h.mergeXdm({eventMergeId:u});var w={renderDecisions:d,decisionScopes:l,personalization:p};return m&&(w.edgeConfigOverrides=m),v&&(t.warn("The 'datasetId' option has been deprecated. Please use 'edgeConfigOverrides.experience_platform.datasets.event' instead."),w.edgeConfigOverrides=m||{},y(w.edgeConfigOverrides,{com_adobe_experience_platform:{datasets:{event:{datasetId:v}}}})),n.sendEvent(h,w)}},applyResponse:{documentationUri:"",optionsValidator:function(e){return function(e){var n=e.options;return mn({renderDecisions:ln(),responseHeaders:vn(hn().required()),responseBody:mn({handle:fn(mn({type:hn().required(),payload:dn().required()})).required()}).required()}).noUnknownFields()(n)}({options:e})},run:function(e){var t=e.renderDecisions,r=void 0!==t&&t,o=e.responseHeaders,i=void 0===o?{}:o,a=e.responseBody,c=void 0===a?{handle:[]}:a,u=n.createEvent();return n.applyResponse(u,{renderDecisions:r,responseHeaders:i,responseBody:c})}}}}};Bn.namespace="DataCollector",Bn.configValidators={};var Fn=function(e){var n=function(e){var n=e.eventManager,t=e.lifecycle,r=e.handleError;return function(e){var o=e.target,i=n.createEvent();return i.documentMayUnload(),t.onClick({event:i,clickedElement:o}).then((function(){return i.isEmpty()?Promise.resolve():n.sendEvent(i)})).then(ye).catch((function(e){r(e,"click collection")}))}}({eventManager:e.eventManager,lifecycle:e.lifecycle,handleError:e.handleError});document.addEventListener("click",n,!0)},_n={clickCollectionEnabled:ln().default(!0),downloadLinkQualifier:hn().regexp().default("\\.(exe|zip|wav|mp3|mov|mpg|avi|wmv|pdf|doc|docx|xls|xlsx|ppt|pptx)$"),onBeforeLinkClickSend:gn()},Hn=function(e){return e&&e.replace(/\s+/g," ").trim()},Vn=/^(SCRIPT|STYLE|LINK|CANVAS|NOSCRIPT|#COMMENT)$/i,zn=function e(n){var t=[],r=!1;(function(e){return!(e&&e.nodeName&&e.nodeName.match(Vn))})(n)?(t.push(n),n.childNodes&&Array.prototype.slice.call(n.childNodes).forEach((function(n){var o=e(n);t=t.concat(o.supportedNodes),r=r||o.includesUnsupportedNodes}))):r=!0;return{supportedNodes:t,includesUnsupportedNodes:r}},Jn=function(e,n,t){var r;return t&&t!==e.nodeName.toUpperCase()||(r=e.getAttribute(n)),r},Wn=/^(HEADER|MAIN|FOOTER|NAV)$/i,Qn=function(e){var n;return"region"===e.role&&he(e["aria-label"])&&(n=e["aria-label"]),n},Xn=function(e){var n;return e&&e.nodeName&&e.nodeName.match(Wn)&&(n=e.nodeName),n},$n=function(e){var n=e.window,t=e.getLinkName,r=e.getLinkRegion,o=e.getAbsoluteUrlFromAnchorElement,i=e.findSupportedAnchorElement,a=e.determineLinkType;return function(e){var c=e.targetElement,u=e.config,s=e.logger,d=i(c);if(d){var f=o(n,d);if(f){var l=a(n,u,f,d),g=r(d),p=t(d),v=u.onBeforeLinkClickSend,m={xdm:{eventType:"web.webinteraction.linkClicks",web:{webInteraction:{name:p,region:g,type:l,URL:f,linkClicks:{value:1}}}},data:{},clickedElement:c};if(!v)return m;if(!1!==v(m))return m;s.info("This link click event is not triggered because it was canceled in onBeforeLinkClickSend.")}else s.info("This link click event is not triggered because the HTML element doesn't have an URL.")}else s.info("This link click event is not triggered because the HTML element is not an anchor.")}}({window:window,getLinkName:function(e){var n=Hn(e.innerText||e.textContent),t=zn(e);if(!n||t.includesUnsupportedNodes){var r=function(e){var n={texts:[]};return e.supportedNodes.forEach((function(e){e.getAttribute&&(n.alt||(n.alt=Hn(e.getAttribute("alt"))),n.title||(n.title=Hn(e.getAttribute("title"))),n.inputValue||(n.inputValue=Hn(Jn(e,"value","INPUT"))),n.imgSrc||(n.imgSrc=Hn(Jn(e,"src","IMG")))),e.nodeValue&&n.texts.push(e.nodeValue)})),n}(t);(n=Hn(r.texts.join("")))||(n=r.alt||r.title||r.inputValue||r.imgSrc)}return n||""},getLinkRegion:function(e){for(var n,t=e.parentNode;t;){if(n=Hn(t.id||Qn(t)||Xn(t)))return n;t=t.parentNode}return"BODY"},getAbsoluteUrlFromAnchorElement:function(e,n){var t=e.location,r=n.href?n.href:"",o=n.protocol,i=n.host;if(!function(e){return e&&/^[a-z0-9]+:\/\//i.test(e)}(r)){o||(o=t.protocol?t.protocol:""),o=o?o+"//":"",i||(i=t.host?t.host:"");var a="";if("/"!==r.substring(0,1)){var c=t.pathname.lastIndexOf("/");c=c<0?0:c,a=t.pathname.substring(0,c)}r=""+o+i+a+"/"+r}return r},findSupportedAnchorElement:function(e){for(var n,t=e;t;){if((n=t).href&&("A"===n.tagName||"AREA"===n.tagName)&&(!n.onclick||!n.protocol||n.protocol.toLowerCase().indexOf("javascript")<0))return t;t=t.parentNode}return null},determineLinkType:function(e,n,t,r){var o="other";return!function(e,n,t){var r=new RegExp(e);return!!t.download||r.test(n.toLowerCase())}(n.downloadLinkQualifier,t,r)?function(e,n){var t=e.location.hostname.toLowerCase();return!(n.toLowerCase().indexOf(t)>=0)}(e,t)&&(o="exit"):o="download",o}}),Yn=function(e){var n=e.config,t=e.eventManager,r=e.handleError,o=e.logger,i=function(e){var n=e.getLinkDetails,t=e.config,r=e.logger;return t.clickCollectionEnabled?function(e){var o=e.targetElement,i=e.event,a=n({targetElement:o,config:t,logger:r});a&&(i.mergeXdm(a.xdm),i.setUserData(a.data))}:function(){}}({getLinkDetails:$n,config:n,logger:o});return{lifecycle:{onComponentsRegistered:function(e){var n=e.lifecycle;Fn({eventManager:t,lifecycle:n,handleError:r})},onClick:function(e){var n=e.event,t=e.clickedElement;i({targetElement:t,event:n})}}}};Yn.namespace="ActivityCollector",Yn.configValidators=_n,Yn.buildOnInstanceConfiguredExtraParams=function(e){var n=e.config,t=e.logger;return{getLinkDetails:function(e){return $n({targetElement:e,config:n,logger:t})}}};var Gn,Kn,Zn,et=function(e,n){return"ID sync "+(n?"succeeded":"failed")+": "+e.spec.url},nt={thirdPartyCookiesEnabled:ln().default(!0),idMigrationEnabled:ln().default(!0)},tt=mn({namespaces:fn(pn("ECID")).nonEmpty().uniqueItems().default(["ECID"]),edgeConfigOverrides:bn}).noUnknownFields().default({namespaces:["ECID"]}),rt=mn({url:hn().required().nonEmpty(),edgeConfigOverrides:bn}).required().noUnknownFields(),ot=function(e){var n=e.logger;return new Promise((function(e,t){if(m(window.adobe)&&m(window.adobe.optIn)){var r=window.adobe.optIn;n.info("Delaying request while waiting for legacy opt-in to let Visitor retrieve ECID from server."),r.fetchPermissions((function(){r.isApproved([r.Categories.ECID])?(n.info("Received legacy opt-in approval to let Visitor retrieve ECID from server."),e()):t(new Error("Legacy opt-in was declined."))}),!0)}else e()}))},it=function(e){var n=e.logger,t=e.orgId,r=e.awaitVisitorOptIn;return function(){var e=function(e){var n=e.Visitor;return M(n)&&M(n.getInstance)&&n}(window);return e?r({logger:n}).then((function(){return n.info("Delaying request while using Visitor to retrieve ECID from server."),new Promise((function(r){e.getInstance(t,{}).getMarketingCloudVisitorID((function(e){n.info("Resuming previously delayed request that was waiting for ECID from Visitor."),r(e)}),!0)}))})).catch((function(e){e?n.info(e.message+", retrieving ECID from experience edge"):n.info("An error occurred while obtaining the ECID from Visitor.")})):Promise.resolve()}},at="ECID",ct=function(e){e.mergeQuery({identity:{fetch:[at]}})},ut=(Gn=function(o){var i,a;return(ki(i={},n,/Edge\/([0-9\._]+)/),ki(i,t,/Edg\/([0-9\.]+)/),ki(i,e,/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/),ki(i,"Firefox",/Firefox\/([0-9\.]+)(?:\s|$)/),ki(i,"IE",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/),ki(i,"Safari",/Version\/([0-9\._]+).*Safari/),a=i,function(e){for(var n=Object.keys(a),t=0;t0&&void 0!==arguments[0]?arguments[0]:{},i=e.namespaces,a=e.edgeConfigOverrides,c=t(i),u=r(c);return c.mergeConfigOverride(o),c.mergeConfigOverride(a),n({request:u})}}({sendEdgeNetworkRequest:i,createIdentityRequestPayload:wt,createIdentityRequest:yt,globalConfigOverrides:d}),m=function(e){var n=e.thirdPartyCookiesEnabled,t=e.areThirdPartyCookiesSupportedByDefault;return function(e){n&&t(ut(window))&&e.setUseIdThirdPartyDomain()}}({thirdPartyCookiesEnabled:s,areThirdPartyCookiesSupportedByDefault:a}),h=function(e){var n=e.getLegacyEcid,t=e.addEcidToPayload;return function(e){return e.hasIdentity(at)?Promise.resolve():n().then((function(n){n&&t(e,n)}))}}({getLegacyEcid:l.getEcid,addEcidToPayload:st}),y=function(e){var n=e.locationSearch,t=e.dateProvider,r=e.orgId,o=e.logger;return function(e){if(!e.hasIdentity(at)){var i=Re(n).adobe_mc;if(void 0!==i){var a=i.split("|").reduce((function(e,n){var t=Oi(n.split("="),2),r=t[0],o=t[1];return e[r]=o,e}),{}),c=parseInt(a.TS,10),u=a.MCMID,s=decodeURIComponent(a.MCORGID);t().getTime()/1e3<=c+300&&s===r&&u?(o.info("Found valid ECID identity "+u+" from the adobe_mc query string parameter."),e.addIdentity(at,{id:u})):o.info("Detected invalid or expired adobe_mc query string parameter.")}}}}({locationSearch:window.document.location.search,dateProvider:function(){return new Date},orgId:u,logger:t}),w=function(e){var n=e.doesIdentityCookieExist,t=e.orgId;return function(e){var r=e.onResponse,o=e.onRequestFailure;return new Promise((function(e,i){r((function(){if(!n()){var r=new Error("An identity was not set properly. Please verify that the org ID "+t+" configured in Alloy matches the org ID specified in the edge configuration.");throw i(r),r}e()})),o((function(){n()?e():i(new Error("No identity was set on response."))}))}))}}({doesIdentityCookieExist:g,orgId:u}),b=function(e){var n,t=e.doesIdentityCookieExist,r=e.setDomainForInitialIdentityPayload,o=e.addLegacyEcidToPayload,i=e.awaitIdentityCookie,a=e.logger,c=function(e){return r(e),o(e.getPayload())};return function(e){var r=e.request,o=e.onResponse,u=e.onRequestFailure;if(t())return r.setIsIdentityEstablished(),Promise.resolve();if(n){a.info("Delaying request while retrieving ECID from server.");var s=n;return n=s.catch((function(){return i({onResponse:o,onRequestFailure:u})})),s.then((function(){a.info("Resuming previously delayed request."),r.setIsIdentityEstablished()})).catch((function(){return c(r)}))}return n=i({onResponse:o,onRequestFailure:u}),c(r)}}({doesIdentityCookieExist:g,setDomainForInitialIdentityPayload:m,addLegacyEcidToPayload:h,awaitIdentityCookie:w,logger:t}),E=function(e){var n=e.fireReferrerHideableImage,t=e.logger;return function(e){var r=e.filter((function(e){return"url"===e.type}));return r.length?Promise.all(r.map((function(e){return n(e.spec).then((function(){t.info(et(e,!0))})).catch((function(){t.error(et(e,!1))}))}))).then(ye):Promise.resolve()}}({fireReferrerHideableImage:o,logger:t}),I=function(e){var n=e.processIdSyncs;return function(e){return n(e.getPayloadsByType("identity:exchange"))}}({processIdSyncs:E}),D=function(e){var n=e.dateProvider,t=e.orgId;return function(e,r){var o=Math.round(n().getTime()/1e3),i=encodeURIComponent("TS="+o+"|MCMID="+e+"|MCORGID="+encodeURIComponent(t)),a=Oi(r.match(bt),4),c=a[1],u=a[2],s=a[3],d=function(e){return""===e?"?":"?"===e?"":"&"}(u);return""+c+u+d+"adobe_mc="+i+s}}({dateProvider:function(){return new Date},orgId:u,globalConfigOverrides:d});return function(e){var n,t=e.addEcidQueryToPayload,r=e.addQueryStringIdentityToPayload,o=e.ensureSingleIdentity,i=e.setLegacyEcid,a=e.handleResponseForIdSyncs,c=e.getEcidFromResponse,u=e.getIdentity,s=e.consent,d=e.appendIdentityToUrl,l=e.logger,g={};return{lifecycle:{onBeforeRequest:function(e){var n=e.request,i=e.onResponse,a=e.onRequestFailure;return t(n.getPayload()),r(n.getPayload()),o({request:n,onResponse:i,onRequestFailure:a})},onResponse:function(e){var t=e.response;return n||(n=c(t))&&i(n),g=f(g,t.getEdge()),a(t)}},commands:{getIdentity:{optionsValidator:tt,run:function(e){return s.awaitConsent().then((function(){return n?void 0:u(e)})).then((function(){return{identity:{ECID:n},edge:g}}))}},appendIdentityToUrl:{optionsValidator:rt,run:function(e){return s.withConsent().then((function(){return n?void 0:u(e)})).then((function(){return{url:d(n,e.url)}})).catch((function(n){return l.warn("Unable to append identity to url. "+n.message),e}))}}}}}({addEcidQueryToPayload:ct,addQueryStringIdentityToPayload:y,ensureSingleIdentity:b,setLegacyEcid:l.setEcid,handleResponseForIdSyncs:I,getEcidFromResponse:dt,getIdentity:v,consent:r,appendIdentityToUrl:D,logger:t,config:n})};Ct.namespace="Identity",Ct.configValidators=nt;var Et=function(e){var n=e.fireReferrerHideableImage,t=e.logger,r=e.cookieJar,o=e.isPageSsl?{sameSite:"none",secure:!0}:{};return function(e){return function(e){e.filter((function(e){return"cookie"===e.type})).forEach((function(e){var n=e.spec,t=n.name,i=n.value,a=n.domain,c=n.ttlDays;r.set(t,i||"",Di({domain:a||"",expires:c||10},o))}))}(e),function(e){var r=e.filter((function(e){return"url"===e.type}));return Promise.all(r.map((function(e){return n(e.spec).then((function(){t.info(function(e,n){return"URL destination "+(!0?"succeeded":"failed")+": "+e.spec.url}(e))})).catch((function(){}))}))).then(ye)}(e)}},It=function(e){var n=e.processDestinations;return function(e){var t,r,o=e.response;return(t={response:o},r=t.response.getPayloadsByType("activation:push"),n(r)).then((function(){return{destinations:{response:o}.response.getPayloadsByType("activation:pull")}}))}},Dt=function(e){var n=e.logger,t=e.fireReferrerHideableImage,r=p.withConverter({write:function(e){return encodeURIComponent(e)}}),o=C({logger:n,cookieJar:r}),i=Et({fireReferrerHideableImage:t,logger:n,cookieJar:o,isPageSsl:"https:"===window.location.protocol});return{lifecycle:{onResponse:It({processDestinations:i})},commands:{}}};Dt.namespace="Audiences",Dt.configValidators={};var Rt,kt="web",St="://",Ot=/^(\w+):\/\/([^/#]+)(\/[^#]*)?(#.*)?$/,Pt=/^(?:.*@)?(?:[a-z\d\u00a1-\uffff.-]+|\[[a-f\d:]+])(?::\d+)?$/,xt=/^\/(?:[/\w\u00a1-\uffff-.~]|%[a-fA-F\d]{2})*$/,qt=/^#(?:[/\w\u00a1-\uffff-.~]|%[a-fA-F\d]{2})+$/,Nt=function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"/",n=e.length;n>0&&-1!=="/".indexOf(e.charAt(n-1));)n-=1;return e.substring(0,n)||"/"},At=function(e){return""+e.surfaceType+St+e.authority+(e.path||"")+(e.fragment||"")},Mt=function(e){var n=e(),t=n.host.toLowerCase(),r=n.pathname;return"web://"+t+Nt(r)},Tt=function(e,n,t){var r=function(e){return t.warn(e),null};if(!he(e))return r("Invalid surface: "+e);var i,a,c,u,s=function(e,n){return B(e,"#")?Mt(n)+e:e}(e,n),d=(u=s.match(Ot))?{surfaceType:(c=u[1],he(c)?c.toLowerCase():""),authority:(a=u[2],he(a)?a.toLowerCase():""),path:(i=u[3],he(i)?Nt(i):"/"),fragment:u[4]}:null;return null===d?r("Invalid surface: "+e):o([kt,"webapp"],d.surfaceType)?d.authority&&Pt.test(d.authority)?d.path&&!xt.test(d.path)?r("Invalid path "+d.path+" in surface: "+e):d.fragment&&!qt.test(d.fragment)?r("Invalid fragment "+d.fragment+" in surface: "+e):d:r("Invalid authority "+d.authority+" in surface: "+e):r("Unsupported surface type "+d.surfaceType+" in surface: "+e)},jt="__view__",Ut="https://ns.adobe.com/personalization/default-content-item",Lt="https://ns.adobe.com/personalization/dom-action",Bt="https://ns.adobe.com/personalization/html-content-item",Ft="https://ns.adobe.com/personalization/redirect-item",_t=function(e){return e.filter((function(n,t){return e.indexOf(n)===t}))},Ht=function(e){var n=e.getPageLocation,t=e.renderDecisions,r=e.decisionScopes,i=e.personalization,a=e.event,c=e.viewCache,u=e.logger,s=a.getViewName();return{isRenderDecisions:function(){return t},getViewName:function(){return s},hasScopes:function(){return r.length>0||T(i.decisionScopes)},hasSurfaces:function(){return T(i.surfaces)},hasViewName:function(){return he(s)},createQueryDetails:function(){var e=Pi(r);T(i.decisionScopes)&&e.push.apply(e,Pi(i.decisionScopes));var t=function(){var e=arguments.length>1?arguments[1]:void 0,n=arguments.length>2?arguments[2]:void 0;return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).map((function(t){return Tt(t,e,n)})).filter((function(e){return!v(e)})).map(At)}(i.surfaces,n,u);this.isCacheInitialized()||(function(e){o(e,jt)||e.push(jt)}(e),function(e,n){var t=Mt(n);o(e,t)||e.push(t)}(t,n));var a=[Ut,Bt,"https://ns.adobe.com/personalization/json-content-item",Ft];return o(e,jt)&&a.push(Lt),{schemas:a,decisionScopes:_t(e),surfaces:_t(t)}},isCacheInitialized:function(){return c.isInitialized()},shouldFetchData:function(){return this.hasScopes()||this.hasSurfaces()||!this.isCacheInitialized()},shouldUseCachedData:function(){return this.hasViewName()&&this.isCacheInitialized()}}},Vt={propositions:[]},zt=function(e){var n=e.getPageLocation,t=e.logger,r=e.fetchDataHandler,o=e.viewChangeHandler,i=e.onClickHandler,a=e.isAuthoringModeEnabled,c=e.mergeQuery,u=e.viewCache,s=e.showContainers,d=e.applyPropositions,f=e.setTargetMigration;return{lifecycle:{onBeforeRequest:function(e){var n=e.request;return f(n),Promise.resolve()},onBeforeEvent:function(e){var i=e.event,d=e.renderDecisions,f=e.decisionScopes,l=void 0===f?[]:f,g=e.personalization,p=void 0===g?{}:g,v=e.onResponse,m=void 0===v?ye:v,h=e.onRequestFailure,y=void 0===h?ye:h;if(m((function(){return{propositions:[]}})),y((function(){return s()})),a())return t.warn("Rendering is disabled for authoring mode."),void c(i,{enabled:!1});var w=Ht({getPageLocation:n,renderDecisions:d,decisionScopes:l,personalization:p,event:i,viewCache:u,logger:t});if(w.shouldFetchData()){var b=I();return u.storeViews(b.promise),y((function(){return b.reject()})),void r({decisionsDeferred:b,personalizationDetails:w,event:i,onResponse:m})}return w.shouldUseCachedData()?o({personalizationDetails:w,event:i,onResponse:m,onRequestFailure:y}):void 0},onClick:function(e){var n=e.event,t=e.clickedElement;i({event:n,clickedElement:t})}},commands:{applyPropositions:{optionsValidator:function(e){return function(e){var n=e.logger,t=e.options,r=mn({propositions:fn(mn(dn())).nonEmpty(),metadata:mn(dn())}).required();try{return r(t)}catch(e){return n.warn("Invalid options for applyPropositions. No propositions will be applied.",e),Vt}}({logger:t,options:e})},run:d}}}},Jt=function(e){return S("DIV",{},{innerHTML:e})},Wt=Ei((function(e,n){var t;t=l,e.exports=function(e){if(e.CSS&&e.CSS.escape)return e.CSS.escape;var n=function(e){if(0==arguments.length)throw new TypeError("`CSS.escape` requires an argument.");for(var n,t=String(e),r=t.length,o=-1,i="",a=t.charCodeAt(0);++o=1&&n<=31||127==n||0==o&&n>=48&&n<=57||1==o&&n>=48&&n<=57&&45==a?"\\"+n.toString(16)+" ":0==o&&1==r&&45==n||!(n>=128||45==n||95==n||n>=48&&n<=57||n>=65&&n<=90||n>=97&&n<=122)?"\\"+t.charAt(o):t.charAt(o):i+="�";return i};return e.CSS||(e.CSS={}),e.CSS.escape=n,n}(t)})),Qt=/:eq\((\d+)\)/g,Xt=function(e){return-1===e.indexOf(":eq(")},$t=/(#|\.)(-?\w+)/g,Yt=function(e,n,t){return""+n+Wt(t)},Gt=function(e){for(var n=[],t=function(e){return e.split(Qt).filter(he)}(function(e){return e.replace($t,Yt)}(e.trim())),r=t.length,o=0;of-1)break;if(a1&&void 0!==arguments[1]?arguments[1]:document;return n.getElementById(e)},er=function(e,n,t){e.setAttribute(n,t)},nr=function(e,n){return e.getAttribute(n)},tr=function(e){return e.parentNode},rr=function(e,n){if(e){var t=tr(e);t&&t.insertBefore(n,function(e){return e.nextElementSibling}(e))}},or=function(e,n){if(e){var t=tr(e);t&&t.insertBefore(n,e)}},ir=function(e){var n=e.childNodes;return n?j(n):[]},ar=function(e){return e.firstElementChild},cr=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document;if(void 0===Rt){var n=e.querySelector("[nonce]");Rt=n&&(n.nonce||n.getAttribute("nonce"))}return Rt},ur="alloy-prehiding",sr={},dr=function(e){var n=sr[e];n&&(ee(n),delete sr[e])},fr=function(e){if(e&&!Zt(ur)){var n=cr(),t=Di({id:ur},n&&{nonce:n}),r=S(q,t,{textContent:e});R(document.head,r)}},lr=function(){var e=Zt(ur);e&&ee(e)},gr=function(e,n){e.textContent=n},pr="src",vr=function(e){return S(x,{src:e})},mr=function(e){z(x,e).forEach((function(e){var n=nr(e,pr);n&&vr(n)}))},hr=function(e){return function(e,n){return e.tagName===n}(e,q)&&!nr(e,pr)},yr=function(e){var n=z(q,e),t=n.length,r=cr();if(r)for(var o=0;o=0;){var c=r[a],u=ar(e);u?or(u,c):R(e,c),a-=1}return Pr(e,o),xr(i)},Mr=function(e,n){var t=Jt(n);yr(t);var r=ir(t),o=Sr(t),i=Or(t);return mr(t),r.forEach((function(n){or(e,n)})),Pr(e,o),xr(i)},Tr=function(e,n){Mr(e,n),ee(e)},jr=function(e,n){var t=Jt(n);yr(t);var r=ir(t),o=Sr(t),i=Or(t);return mr(t),r.forEach((function(n){rr(e,n)})),Pr(e,o),xr(i)},Ur=["priority"],Lr=function(e,n){var t=n.priority,r=Si(n,Ur);Object.keys(r).forEach((function(n){!function(e,n,t,r){var o;o=r?n+":"+t+" !"+r+";":n+":"+t+";",e.style.cssText+=";"+o}(e,n,r[n],t)}))},Br=function(e,n){Object.keys(n).forEach((function(t){er(e,t,n[t])}))},Fr=function(e,n){e.tagName===x&&(vr(n),function(e,n){e.removeAttribute(n)}(e,pr),er(e,pr,n))},_r=function(e,n){var t=n.from,r=n.to,o=function(e){var n=e.children;return n?j(n):[]}(e),i=o[t],a=o[r];i&&a&&(t