diff --git a/dist/rudder-sdk-js/index.js b/dist/rudder-sdk-js/index.js index 8be0c7442..ab6fd9bde 100644 --- a/dist/rudder-sdk-js/index.js +++ b/dist/rudder-sdk-js/index.js @@ -11991,1715 +11991,1841 @@ var deep = defaultsDeep; defaults_1.deep = deep; - var json3 = createCommonjsModule(function (module, exports) { - (function () { - // Detect the `define` function exposed by asynchronous module loaders. The - // strict `define` check is necessary for compatibility with `r.js`. - var isLoader = typeof undefined === "function" ; // A set of types used to distinguish objects from primitives. + /** + * Helpers. + */ + var s$1 = 1000; + var m$1 = s$1 * 60; + var h$1 = m$1 * 60; + var d$1 = h$1 * 24; + var y$1 = d$1 * 365.25; + /** + * Parse or format the given `val`. + * + * Options: + * + * - `long` verbose formatting [false] + * + * @param {String|Number} val + * @param {Object} options + * @return {String|Number} + * @api public + */ - var objectTypes = { - "function": true, - "object": true - }; // Detect the `exports` object exposed by CommonJS implementations. + var ms$1 = function ms(val, options) { + options = options || {}; + if ('string' == typeof val) return parse$4(val); + return options["long"] ? _long$1(val) : _short$1(val); + }; + /** + * Parse the given `str` and return milliseconds. + * + * @param {String} str + * @return {Number} + * @api private + */ - var freeExports = objectTypes['object'] && exports && !exports.nodeType && exports; // Use the `global` object exposed by Node (including Browserify via - // `insert-module-globals`), Narwhal, and Ringo as the default context, - // and the `window` object in browsers. Rhino exports a `global` function - // instead. - var root = objectTypes[typeof window === "undefined" ? "undefined" : _typeof(window)] && window || this, - freeGlobal = freeExports && objectTypes['object'] && module && !module.nodeType && _typeof(commonjsGlobal) == "object" && commonjsGlobal; + function parse$4(str) { + str = '' + str; + if (str.length > 10000) return; + var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str); + if (!match) return; + var n = parseFloat(match[1]); + var type = (match[2] || 'ms').toLowerCase(); - if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) { - root = freeGlobal; - } // Public: Initializes JSON 3 using the given `context` object, attaching the - // `stringify` and `parse` functions to the specified `exports` object. + switch (type) { + case 'years': + case 'year': + case 'yrs': + case 'yr': + case 'y': + return n * y$1; + case 'days': + case 'day': + case 'd': + return n * d$1; - function runInContext(context, exports) { - context || (context = root.Object()); - exports || (exports = root.Object()); // Native constructor aliases. + case 'hours': + case 'hour': + case 'hrs': + case 'hr': + case 'h': + return n * h$1; - var Number = context.Number || root.Number, - String = context.String || root.String, - Object = context.Object || root.Object, - Date = context.Date || root.Date, - SyntaxError = context.SyntaxError || root.SyntaxError, - TypeError = context.TypeError || root.TypeError, - Math = context.Math || root.Math, - nativeJSON = context.JSON || root.JSON; // Delegate to the native `stringify` and `parse` implementations. + case 'minutes': + case 'minute': + case 'mins': + case 'min': + case 'm': + return n * m$1; - if (_typeof(nativeJSON) == "object" && nativeJSON) { - exports.stringify = nativeJSON.stringify; - exports.parse = nativeJSON.parse; - } // Convenience aliases. + case 'seconds': + case 'second': + case 'secs': + case 'sec': + case 's': + return n * s$1; + case 'milliseconds': + case 'millisecond': + case 'msecs': + case 'msec': + case 'ms': + return n; + } + } + /** + * Short format for `ms`. + * + * @param {Number} ms + * @return {String} + * @api private + */ - var objectProto = Object.prototype, - getClass = objectProto.toString, - isProperty = objectProto.hasOwnProperty, - undefined$1; // Internal: Contains `try...catch` logic used by other functions. - // This prevents other functions from being deoptimized. - function attempt(func, errorFunc) { - try { - func(); - } catch (exception) { - if (errorFunc) { - errorFunc(); - } - } - } // Test the `Date#getUTC*` methods. Based on work by @Yaffle. + function _short$1(ms) { + if (ms >= d$1) return Math.round(ms / d$1) + 'd'; + if (ms >= h$1) return Math.round(ms / h$1) + 'h'; + if (ms >= m$1) return Math.round(ms / m$1) + 'm'; + if (ms >= s$1) return Math.round(ms / s$1) + 's'; + return ms + 'ms'; + } + /** + * Long format for `ms`. + * + * @param {Number} ms + * @return {String} + * @api private + */ - var isExtended = new Date(-3509827334573292); - attempt(function () { - // The `getUTCFullYear`, `Month`, and `Date` methods return nonsensical - // results for certain dates in Opera >= 10.53. - isExtended = isExtended.getUTCFullYear() == -109252 && isExtended.getUTCMonth() === 0 && isExtended.getUTCDate() === 1 && isExtended.getUTCHours() == 10 && isExtended.getUTCMinutes() == 37 && isExtended.getUTCSeconds() == 6 && isExtended.getUTCMilliseconds() == 708; - }); // Internal: Determines whether the native `JSON.stringify` and `parse` - // implementations are spec-compliant. Based on work by Ken Snyder. + function _long$1(ms) { + return plural$1(ms, d$1, 'day') || plural$1(ms, h$1, 'hour') || plural$1(ms, m$1, 'minute') || plural$1(ms, s$1, 'second') || ms + ' ms'; + } + /** + * Pluralization helper. + */ - function has(name) { - if (has[name] != null) { - // Return cached feature test result. - return has[name]; - } - var isSupported; + function plural$1(ms, n, name) { + if (ms < n) return; + if (ms < n * 1.5) return Math.floor(ms / n) + ' ' + name; + return Math.ceil(ms / n) + ' ' + name + 's'; + } - if (name == "bug-string-char-index") { - // IE <= 7 doesn't support accessing string characters using square - // bracket notation. IE 8 only supports this for primitives. - isSupported = "a"[0] != "a"; - } else if (name == "json") { - // Indicates whether both `JSON.stringify` and `JSON.parse` are - // supported. - isSupported = has("json-stringify") && has("date-serialization") && has("json-parse"); - } else if (name == "date-serialization") { - // Indicates whether `Date`s can be serialized accurately by `JSON.stringify`. - isSupported = has("json-stringify") && isExtended; + var debug_1$1 = createCommonjsModule(function (module, exports) { + /** + * This is the common logic for both the Node.js and web browser + * implementations of `debug()`. + * + * Expose `debug()` as the module. + */ + exports = module.exports = debug; + exports.coerce = coerce; + exports.disable = disable; + exports.enable = enable; + exports.enabled = enabled; + exports.humanize = ms$1; + /** + * The currently active debug mode names, and names to skip. + */ - if (isSupported) { - var stringify = exports.stringify; - attempt(function () { - isSupported = // JSON 2, Prototype <= 1.7, and older WebKit builds incorrectly - // serialize extended years. - stringify(new Date(-8.64e15)) == '"-271821-04-20T00:00:00.000Z"' && // The milliseconds are optional in ES 5, but required in 5.1. - stringify(new Date(8.64e15)) == '"+275760-09-13T00:00:00.000Z"' && // Firefox <= 11.0 incorrectly serializes years prior to 0 as negative - // four-digit years instead of six-digit years. Credits: @Yaffle. - stringify(new Date(-621987552e5)) == '"-000001-01-01T00:00:00.000Z"' && // Safari <= 5.1.5 and Opera >= 10.53 incorrectly serialize millisecond - // values less than 1000. Credits: @Yaffle. - stringify(new Date(-1)) == '"1969-12-31T23:59:59.999Z"'; - }); - } - } else { - var value, - serialized = "{\"a\":[1,true,false,null,\"\\u0000\\b\\n\\f\\r\\t\"]}"; // Test `JSON.stringify`. + exports.names = []; + exports.skips = []; + /** + * Map of special "%n" handling functions, for the debug "format" argument. + * + * Valid key names are a single, lowercased letter, i.e. "n". + */ - if (name == "json-stringify") { - var stringify = exports.stringify, - stringifySupported = typeof stringify == "function"; + exports.formatters = {}; + /** + * Previously assigned color. + */ - if (stringifySupported) { - // A test function object with a custom `toJSON` method. - (value = function value() { - return 1; - }).toJSON = value; - attempt(function () { - stringifySupported = // Firefox 3.1b1 and b2 serialize string, number, and boolean - // primitives as object literals. - stringify(0) === "0" && // FF 3.1b1, b2, and JSON 2 serialize wrapped primitives as object - // literals. - stringify(new Number()) === "0" && stringify(new String()) == '""' && // FF 3.1b1, 2 throw an error if the value is `null`, `undefined`, or - // does not define a canonical JSON representation (this applies to - // objects with `toJSON` properties as well, *unless* they are nested - // within an object or array). - stringify(getClass) === undefined$1 && // IE 8 serializes `undefined` as `"undefined"`. Safari <= 5.1.7 and - // FF 3.1b3 pass this test. - stringify(undefined$1) === undefined$1 && // Safari <= 5.1.7 and FF 3.1b3 throw `Error`s and `TypeError`s, - // respectively, if the value is omitted entirely. - stringify() === undefined$1 && // FF 3.1b1, 2 throw an error if the given value is not a number, - // string, array, object, Boolean, or `null` literal. This applies to - // objects with custom `toJSON` methods as well, unless they are nested - // inside object or array literals. YUI 3.0.0b1 ignores custom `toJSON` - // methods entirely. - stringify(value) === "1" && stringify([value]) == "[1]" && // Prototype <= 1.6.1 serializes `[undefined]` as `"[]"` instead of - // `"[null]"`. - stringify([undefined$1]) == "[null]" && // YUI 3.0.0b1 fails to serialize `null` literals. - stringify(null) == "null" && // FF 3.1b1, 2 halts serialization if an array contains a function: - // `[1, true, getClass, 1]` serializes as "[1,true,],". FF 3.1b3 - // elides non-JSON values from objects and arrays, unless they - // define custom `toJSON` methods. - stringify([undefined$1, getClass, null]) == "[null,null,null]" && // Simple serialization test. FF 3.1b1 uses Unicode escape sequences - // where character escape codes are expected (e.g., `\b` => `\u0008`). - stringify({ - "a": [value, true, false, null, "\x00\b\n\f\r\t"] - }) == serialized && // FF 3.1b1 and b2 ignore the `filter` and `width` arguments. - stringify(null, value) === "1" && stringify([1, 2], null, 1) == "[\n 1,\n 2\n]"; - }, function () { - stringifySupported = false; - }); - } + var prevColor = 0; + /** + * Previous log timestamp. + */ - isSupported = stringifySupported; - } // Test `JSON.parse`. + var prevTime; + /** + * Select a color. + * + * @return {Number} + * @api private + */ + function selectColor() { + return exports.colors[prevColor++ % exports.colors.length]; + } + /** + * Create a debugger with the given `namespace`. + * + * @param {String} namespace + * @return {Function} + * @api public + */ - if (name == "json-parse") { - var parse = exports.parse, - parseSupported; - if (typeof parse == "function") { - attempt(function () { - // FF 3.1b1, b2 will throw an exception if a bare literal is provided. - // Conforming implementations should also coerce the initial argument to - // a string prior to parsing. - if (parse("0") === 0 && !parse(false)) { - // Simple parsing test. - value = parse(serialized); - parseSupported = value["a"].length == 5 && value["a"][0] === 1; + function debug(namespace) { + // define the `disabled` version + function disabled() {} - if (parseSupported) { - attempt(function () { - // Safari <= 5.1.2 and FF 3.1b1 allow unescaped tabs in strings. - parseSupported = !parse('"\t"'); - }); + disabled.enabled = false; // define the `enabled` version - if (parseSupported) { - attempt(function () { - // FF 4.0 and 4.0.1 allow leading `+` signs and leading - // decimal points. FF 4.0, 4.0.1, and IE 9-10 also allow - // certain octal literals. - parseSupported = parse("01") !== 1; - }); - } + function enabled() { + var self = enabled; // set `diff` timestamp - if (parseSupported) { - attempt(function () { - // FF 4.0, 4.0.1, and Rhino 1.7R3-R4 allow trailing decimal - // points. These environments, along with FF 3.1b1 and 2, - // also allow trailing commas in JSON objects and arrays. - parseSupported = parse("1.") !== 1; - }); - } - } - } - }, function () { - parseSupported = false; - }); - } + var curr = +new Date(); + var ms = curr - (prevTime || curr); + self.diff = ms; + self.prev = prevTime; + self.curr = curr; + prevTime = curr; // add the `color` if not set - isSupported = parseSupported; - } + if (null == self.useColors) self.useColors = exports.useColors(); + if (null == self.color && self.useColors) self.color = selectColor(); + var args = Array.prototype.slice.call(arguments); + args[0] = exports.coerce(args[0]); + + if ('string' !== typeof args[0]) { + // anything else let's inspect with %o + args = ['%o'].concat(args); + } // apply any `formatters` transformations + + + var index = 0; + args[0] = args[0].replace(/%([a-z%])/g, function (match, format) { + // if we encounter an escaped % then don't increase the array index + if (match === '%%') return match; + index++; + var formatter = exports.formatters[format]; + + if ('function' === typeof formatter) { + var val = args[index]; + match = formatter.call(self, val); // now we need to remove `args[index]` since it's inlined in the `format` + + args.splice(index, 1); + index--; } - return has[name] = !!isSupported; + return match; + }); + + if ('function' === typeof exports.formatArgs) { + args = exports.formatArgs.apply(self, args); } - has["bug-string-char-index"] = has["date-serialization"] = has["json"] = has["json-stringify"] = has["json-parse"] = null; + var logFn = enabled.log || exports.log || console.log.bind(console); + logFn.apply(self, args); + } - if (!has("json")) { - // Common `[[Class]]` name aliases. - var functionClass = "[object Function]", - dateClass = "[object Date]", - numberClass = "[object Number]", - stringClass = "[object String]", - arrayClass = "[object Array]", - booleanClass = "[object Boolean]"; // Detect incomplete support for accessing string characters by index. + enabled.enabled = true; + var fn = exports.enabled(namespace) ? enabled : disabled; + fn.namespace = namespace; + return fn; + } + /** + * Enables a debug mode by namespaces. This can include modes + * separated by a colon and wildcards. + * + * @param {String} namespaces + * @api public + */ - var charIndexBuggy = has("bug-string-char-index"); // Internal: Normalizes the `for...in` iteration algorithm across - // environments. Each enumerated key is yielded to a `callback` function. - var _forOwn = function forOwn(object, callback) { - var size = 0, - Properties, - dontEnums, - property; // Tests for bugs in the current environment's `for...in` algorithm. The - // `valueOf` property inherits the non-enumerable flag from - // `Object.prototype` in older versions of IE, Netscape, and Mozilla. + function enable(namespaces) { + exports.save(namespaces); + var split = (namespaces || '').split(/[\s,]+/); + var len = split.length; - (Properties = function Properties() { - this.valueOf = 0; - }).prototype.valueOf = 0; // Iterate over a new instance of the `Properties` class. + for (var i = 0; i < len; i++) { + if (!split[i]) continue; // ignore empty strings - dontEnums = new Properties(); + namespaces = split[i].replace(/\*/g, '.*?'); - for (property in dontEnums) { - // Ignore all properties inherited from `Object.prototype`. - if (isProperty.call(dontEnums, property)) { - size++; - } - } + if (namespaces[0] === '-') { + exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$')); + } else { + exports.names.push(new RegExp('^' + namespaces + '$')); + } + } + } + /** + * Disable debug output. + * + * @api public + */ - Properties = dontEnums = null; // Normalize the iteration algorithm. - if (!size) { - // A list of non-enumerable properties inherited from `Object.prototype`. - dontEnums = ["valueOf", "toString", "toLocaleString", "propertyIsEnumerable", "isPrototypeOf", "hasOwnProperty", "constructor"]; // IE <= 8, Mozilla 1.0, and Netscape 6.2 ignore shadowed non-enumerable - // properties. + function disable() { + exports.enable(''); + } + /** + * Returns true if the given mode name is enabled, false otherwise. + * + * @param {String} name + * @return {Boolean} + * @api public + */ + + + function enabled(name) { + var i, len; + + for (i = 0, len = exports.skips.length; i < len; i++) { + if (exports.skips[i].test(name)) { + return false; + } + } - _forOwn = function forOwn(object, callback) { - var isFunction = getClass.call(object) == functionClass, - property, - length; - var hasProperty = !isFunction && typeof object.constructor != "function" && objectTypes[_typeof(object.hasOwnProperty)] && object.hasOwnProperty || isProperty; + for (i = 0, len = exports.names.length; i < len; i++) { + if (exports.names[i].test(name)) { + return true; + } + } - for (property in object) { - // Gecko <= 1.0 enumerates the `prototype` property of functions under - // certain conditions; IE does not. - if (!(isFunction && property == "prototype") && hasProperty.call(object, property)) { - callback(property); - } - } // Manually invoke the callback for each non-enumerable property. + return false; + } + /** + * Coerce `val`. + * + * @param {Mixed} val + * @return {Mixed} + * @api private + */ - for (length = dontEnums.length; property = dontEnums[--length];) { - if (hasProperty.call(object, property)) { - callback(property); - } - } - }; - } else { - // No bugs detected; use the standard `for...in` algorithm. - _forOwn = function forOwn(object, callback) { - var isFunction = getClass.call(object) == functionClass, - property, - isConstructor; + function coerce(val) { + if (val instanceof Error) return val.stack || val.message; + return val; + } + }); + var debug_2$1 = debug_1$1.coerce; + var debug_3$1 = debug_1$1.disable; + var debug_4$1 = debug_1$1.enable; + var debug_5$1 = debug_1$1.enabled; + var debug_6$1 = debug_1$1.humanize; + var debug_7$1 = debug_1$1.names; + var debug_8$1 = debug_1$1.skips; + var debug_9$1 = debug_1$1.formatters; - for (property in object) { - if (!(isFunction && property == "prototype") && isProperty.call(object, property) && !(isConstructor = property === "constructor")) { - callback(property); - } - } // Manually invoke the callback for the `constructor` property due to - // cross-environment inconsistencies. + var browser$1 = createCommonjsModule(function (module, exports) { + /** + * This is the web browser implementation of `debug()`. + * + * Expose `debug()` as the module. + */ + exports = module.exports = debug_1$1; + exports.log = log; + exports.formatArgs = formatArgs; + exports.save = save; + exports.load = load; + exports.useColors = useColors; + exports.storage = 'undefined' != typeof chrome && 'undefined' != typeof chrome.storage ? chrome.storage.local : localstorage(); + /** + * Colors. + */ + exports.colors = ['lightseagreen', 'forestgreen', 'goldenrod', 'dodgerblue', 'darkorchid', 'crimson']; + /** + * Currently only WebKit-based Web Inspectors, Firefox >= v31, + * and the Firebug extension (any Firefox version) are known + * to support "%c" CSS customizations. + * + * TODO: add a `localStorage` variable to explicitly enable/disable colors + */ - if (isConstructor || isProperty.call(object, property = "constructor")) { - callback(property); - } - }; - } + function useColors() { + // is webkit? http://stackoverflow.com/a/16459606/376773 + return 'WebkitAppearance' in document.documentElement.style || // is firebug? http://stackoverflow.com/a/398120/376773 + window.console && (console.firebug || console.exception && console.table) || // is firefox >= v31? + // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages + navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31; + } + /** + * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default. + */ - return _forOwn(object, callback); - }; // Public: Serializes a JavaScript `value` as a JSON string. The optional - // `filter` argument may specify either a function that alters how object and - // array members are serialized, or an array of strings and numbers that - // indicates which properties should be serialized. The optional `width` - // argument may be either a string or number that specifies the indentation - // level of the output. + exports.formatters.j = function (v) { + return JSON.stringify(v); + }; + /** + * Colorize log arguments if enabled. + * + * @api public + */ - if (!has("json-stringify") && !has("date-serialization")) { - // Internal: A map of control characters and their escaped equivalents. - var Escapes = { - 92: "\\\\", - 34: '\\"', - 8: "\\b", - 12: "\\f", - 10: "\\n", - 13: "\\r", - 9: "\\t" - }; // Internal: Converts `value` into a zero-padded string such that its - // length is at least equal to `width`. The `width` must be <= 6. - var leadingZeroes = "000000"; + function formatArgs() { + var args = arguments; + var useColors = this.useColors; + args[0] = (useColors ? '%c' : '') + this.namespace + (useColors ? ' %c' : ' ') + args[0] + (useColors ? '%c ' : ' ') + '+' + exports.humanize(this.diff); + if (!useColors) return args; + var c = 'color: ' + this.color; + args = [args[0], c, 'color: inherit'].concat(Array.prototype.slice.call(args, 1)); // the final "%c" is somewhat tricky, because there could be other + // arguments passed either before or after the %c, so we need to + // figure out the correct index to insert the CSS into - var toPaddedString = function toPaddedString(width, value) { - // The `|| 0` expression is necessary to work around a bug in - // Opera <= 7.54u2 where `0 == -0`, but `String(-0) !== "0"`. - return (leadingZeroes + (value || 0)).slice(-width); - }; // Internal: Serializes a date object. + var index = 0; + var lastC = 0; + args[0].replace(/%[a-z%]/g, function (match) { + if ('%%' === match) return; + index++; + if ('%c' === match) { + // we only are interested in the *last* %c + // (the user may have provided their own) + lastC = index; + } + }); + args.splice(lastC, 0, c); + return args; + } + /** + * Invokes `console.log()` when available. + * No-op when `console.log` is not a "function". + * + * @api public + */ - var _serializeDate = function serializeDate(value) { - var getData, year, month, date, time, hours, minutes, seconds, milliseconds; // Define additional utility methods if the `Date` methods are buggy. - if (!isExtended) { - var floor = Math.floor; // A mapping between the months of the year and the number of days between - // January 1st and the first of the respective month. + function log() { + // this hackery is required for IE8/9, where + // the `console.log` function doesn't have 'apply' + return 'object' === (typeof console === "undefined" ? "undefined" : _typeof(console)) && console.log && Function.prototype.apply.call(console.log, console, arguments); + } + /** + * Save `namespaces`. + * + * @param {String} namespaces + * @api private + */ - var Months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]; // Internal: Calculates the number of days between the Unix epoch and the - // first day of the given month. - var getDay = function getDay(year, month) { - return Months[month] + 365 * (year - 1970) + floor((year - 1969 + (month = +(month > 1))) / 4) - floor((year - 1901 + month) / 100) + floor((year - 1601 + month) / 400); - }; + function save(namespaces) { + try { + if (null == namespaces) { + exports.storage.removeItem('debug'); + } else { + exports.storage.debug = namespaces; + } + } catch (e) {} + } + /** + * Load `namespaces`. + * + * @return {String} returns the previously persisted debug modes + * @api private + */ - getData = function getData(value) { - // Manually compute the year, month, date, hours, minutes, - // seconds, and milliseconds if the `getUTC*` methods are - // buggy. Adapted from @Yaffle's `date-shim` project. - date = floor(value / 864e5); - for (year = floor(date / 365.2425) + 1970 - 1; getDay(year + 1, 0) <= date; year++) { - } + function load() { + var r; - for (month = floor((date - getDay(year, 0)) / 30.42); getDay(year, month + 1) <= date; month++) { - } + try { + r = exports.storage.debug; + } catch (e) {} - date = 1 + date - getDay(year, month); // The `time` value specifies the time within the day (see ES - // 5.1 section 15.9.1.2). The formula `(A % B + B) % B` is used - // to compute `A modulo B`, as the `%` operator does not - // correspond to the `modulo` operation for negative numbers. + return r; + } + /** + * Enable namespaces listed in `localStorage.debug` initially. + */ - time = (value % 864e5 + 864e5) % 864e5; // The hours, minutes, seconds, and milliseconds are obtained by - // decomposing the time within the day. See section 15.9.1.10. - hours = floor(time / 36e5) % 24; - minutes = floor(time / 6e4) % 60; - seconds = floor(time / 1e3) % 60; - milliseconds = time % 1e3; - }; - } else { - getData = function getData(value) { - year = value.getUTCFullYear(); - month = value.getUTCMonth(); - date = value.getUTCDate(); - hours = value.getUTCHours(); - minutes = value.getUTCMinutes(); - seconds = value.getUTCSeconds(); - milliseconds = value.getUTCMilliseconds(); - }; - } + exports.enable(load()); + /** + * Localstorage attempts to return the localstorage. + * + * This is necessary because safari throws + * when a user disables cookies/localstorage + * and you attempt to access it. + * + * @return {LocalStorage} + * @api private + */ - _serializeDate = function serializeDate(value) { - if (value > -1 / 0 && value < 1 / 0) { - // Dates are serialized according to the `Date#toJSON` method - // specified in ES 5.1 section 15.9.5.44. See section 15.9.1.15 - // for the ISO 8601 date time string format. - getData(value); // Serialize extended years correctly. + function localstorage() { + try { + return window.localStorage; + } catch (e) {} + } + }); + var browser_1$1 = browser$1.log; + var browser_2$1 = browser$1.formatArgs; + var browser_3$1 = browser$1.save; + var browser_4$1 = browser$1.load; + var browser_5$1 = browser$1.useColors; + var browser_6$1 = browser$1.storage; + var browser_7$1 = browser$1.colors; - value = (year <= 0 || year >= 1e4 ? (year < 0 ? "-" : "+") + toPaddedString(6, year < 0 ? -year : year) : toPaddedString(4, year)) + "-" + toPaddedString(2, month + 1) + "-" + toPaddedString(2, date) + // Months, dates, hours, minutes, and seconds should have two - // digits; milliseconds should have three. - "T" + toPaddedString(2, hours) + ":" + toPaddedString(2, minutes) + ":" + toPaddedString(2, seconds) + // Milliseconds are optional in ES 5.0, but required in 5.1. - "." + toPaddedString(3, milliseconds) + "Z"; - year = month = date = hours = minutes = seconds = milliseconds = null; - } else { - value = null; - } + /** + * Module dependencies. + */ - return value; - }; + var debug$1 = browser$1('cookie'); + /** + * Set or get cookie `name` with `value` and `options` object. + * + * @param {String} name + * @param {String} value + * @param {Object} options + * @return {Mixed} + * @api public + */ - return _serializeDate(value); - }; // For environments with `JSON.stringify` but buggy date serialization, - // we override the native `Date#toJSON` implementation with a - // spec-compliant one. + var componentCookie = function componentCookie(name, value, options) { + switch (arguments.length) { + case 3: + case 2: + return set$1(name, value, options); + case 1: + return get$2(name); - if (has("json-stringify") && !has("date-serialization")) { - // Internal: the `Date#toJSON` implementation used to override the native one. - var dateToJSON = function dateToJSON(key) { - return _serializeDate(this); - }; // Public: `JSON.stringify`. See ES 5.1 section 15.12.3. + default: + return all$1(); + } + }; + /** + * Set cookie `name` to `value`. + * + * @param {String} name + * @param {String} value + * @param {Object} options + * @api private + */ - var nativeStringify = exports.stringify; + function set$1(name, value, options) { + options = options || {}; + var str = encode$2(name) + '=' + encode$2(value); + if (null == value) options.maxage = -1; - exports.stringify = function (source, filter, width) { - var nativeToJSON = Date.prototype.toJSON; - Date.prototype.toJSON = dateToJSON; - var result = nativeStringify(source, filter, width); - Date.prototype.toJSON = nativeToJSON; - return result; - }; - } else { - // Internal: Double-quotes a string `value`, replacing all ASCII control - // characters (characters with code unit values between 0 and 31) with - // their escaped equivalents. This is an implementation of the - // `Quote(value)` operation defined in ES 5.1 section 15.12.3. - var unicodePrefix = "\\u00"; + if (options.maxage) { + options.expires = new Date(+new Date() + options.maxage); + } - var escapeChar = function escapeChar(character) { - var charCode = character.charCodeAt(0), - escaped = Escapes[charCode]; + if (options.path) str += '; path=' + options.path; + if (options.domain) str += '; domain=' + options.domain; + if (options.expires) str += '; expires=' + options.expires.toUTCString(); + if (options.secure) str += '; secure'; + document.cookie = str; + } + /** + * Return all cookies. + * + * @return {Object} + * @api private + */ - if (escaped) { - return escaped; - } - return unicodePrefix + toPaddedString(2, charCode.toString(16)); - }; + function all$1() { + var str; - var reEscape = /[\x00-\x1f\x22\x5c]/g; + try { + str = document.cookie; + } catch (err) { + if (typeof console !== 'undefined' && typeof console.error === 'function') { + console.error(err.stack || err); + } - var quote = function quote(value) { - reEscape.lastIndex = 0; - return '"' + (reEscape.test(value) ? value.replace(reEscape, escapeChar) : value) + '"'; - }; // Internal: Recursively serializes an object. Implements the - // `Str(key, holder)`, `JO(value)`, and `JA(value)` operations. + return {}; + } + return parse$5(str); + } + /** + * Get cookie `name`. + * + * @param {String} name + * @return {String} + * @api private + */ - var serialize = function serialize(property, object, callback, properties, whitespace, indentation, stack) { - var value, type, className, results, element, index, length, prefix, result; - attempt(function () { - // Necessary for host object support. - value = object[property]; - }); - if (_typeof(value) == "object" && value) { - if (value.getUTCFullYear && getClass.call(value) == dateClass && value.toJSON === Date.prototype.toJSON) { - value = _serializeDate(value); - } else if (typeof value.toJSON == "function") { - value = value.toJSON(property); - } - } + function get$2(name) { + return all$1()[name]; + } + /** + * Parse cookie `str`. + * + * @param {String} str + * @return {Object} + * @api private + */ - if (callback) { - // If a replacement function was provided, call it to obtain the value - // for serialization. - value = callback.call(object, property, value); - } // Exit early if value is `undefined` or `null`. + function parse$5(str) { + var obj = {}; + var pairs = str.split(/ *; */); + var pair; + if ('' == pairs[0]) return obj; - if (value == undefined$1) { - return value === undefined$1 ? value : "null"; - } + for (var i = 0; i < pairs.length; ++i) { + pair = pairs[i].split('='); + obj[decode$2(pair[0])] = decode$2(pair[1]); + } - type = _typeof(value); // Only call `getClass` if the value is an object. + return obj; + } + /** + * Encode. + */ - if (type == "object") { - className = getClass.call(value); - } - switch (className || type) { - case "boolean": - case booleanClass: - // Booleans are represented literally. - return "" + value; + function encode$2(value) { + try { + return encodeURIComponent(value); + } catch (e) { + debug$1('error `encode(%o)` - %o', value, e); + } + } + /** + * Decode. + */ - case "number": - case numberClass: - // JSON numbers must be finite. `Infinity` and `NaN` are serialized as - // `"null"`. - return value > -1 / 0 && value < 1 / 0 ? "" + value : "null"; - case "string": - case stringClass: - // Strings are double-quoted and escaped. - return quote("" + value); - } // Recursively serialize objects and arrays. + function decode$2(value) { + try { + return decodeURIComponent(value); + } catch (e) { + debug$1('error `decode(%o)` - %o', value, e); + } + } + var lib$1 = createCommonjsModule(function (module, exports) { + /** + * Module dependencies. + */ - if (_typeof(value) == "object") { - // Check for cyclic structures. This is a linear search; performance - // is inversely proportional to the number of unique nested objects. - for (length = stack.length; length--;) { - if (stack[length] === value) { - // Cyclic structures cannot be serialized by `JSON.stringify`. - throw TypeError(); - } - } // Add the object to the stack of traversed objects. + var parse = componentUrl.parse; + /** + * Get the top domain. + * + * The function constructs the levels of domain and attempts to set a global + * cookie on each one when it succeeds it returns the top level domain. + * + * The method returns an empty string when the hostname is an ip or `localhost`. + * + * Example levels: + * + * domain.levels('http://www.google.co.uk'); + * // => ["co.uk", "google.co.uk", "www.google.co.uk"] + * + * Example: + * + * domain('http://localhost:3000/baz'); + * // => '' + * domain('http://dev:3000/baz'); + * // => '' + * domain('http://127.0.0.1:3000/baz'); + * // => '' + * domain('http://segment.io/baz'); + * // => 'segment.io' + * + * @param {string} url + * @return {string} + * @api public + */ + function domain(url) { + var cookie = exports.cookie; + var levels = exports.levels(url); // Lookup the real top level one. - stack.push(value); - results = []; // Save the current indentation level and indent one additional level. + for (var i = 0; i < levels.length; ++i) { + var cname = '__tld__'; + var domain = levels[i]; + var opts = { + domain: '.' + domain + }; + cookie(cname, 1, opts); - prefix = indentation; - indentation += whitespace; + if (cookie(cname)) { + cookie(cname, null, opts); + return domain; + } + } - if (className == arrayClass) { - // Recursively serialize array elements. - for (index = 0, length = value.length; index < length; index++) { - element = serialize(index, value, callback, properties, whitespace, indentation, stack); - results.push(element === undefined$1 ? "null" : element); - } + return ''; + } + /** + * Levels returns all levels of the given url. + * + * @param {string} url + * @return {Array} + * @api public + */ - result = results.length ? whitespace ? "[\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "]" : "[" + results.join(",") + "]" : "[]"; - } else { - // Recursively serialize object members. Members are selected from - // either a user-specified list of property names, or the object - // itself. - _forOwn(properties || value, function (property) { - var element = serialize(property, value, callback, properties, whitespace, indentation, stack); - if (element !== undefined$1) { - // According to ES 5.1 section 15.12.3: "If `gap` {whitespace} - // is not the empty string, let `member` {quote(property) + ":"} - // be the concatenation of `member` and the `space` character." - // The "`space` character" refers to the literal space - // character, not the `space` {width} argument provided to - // `JSON.stringify`. - results.push(quote(property) + ":" + (whitespace ? " " : "") + element); - } - }); + domain.levels = function (url) { + var host = parse(url).hostname; + var parts = host.split('.'); + var last = parts[parts.length - 1]; + var levels = []; // Ip address. - result = results.length ? whitespace ? "{\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "}" : "{" + results.join(",") + "}" : "{}"; - } // Remove the object from the traversed object stack. + if (parts.length === 4 && last === parseInt(last, 10)) { + return levels; + } // Localhost. - stack.pop(); - return result; - } - }; // Public: `JSON.stringify`. See ES 5.1 section 15.12.3. + if (parts.length <= 1) { + return levels; + } // Create levels. - exports.stringify = function (source, filter, width) { - var whitespace, callback, properties, className; + for (var i = parts.length - 2; i >= 0; --i) { + levels.push(parts.slice(i).join('.')); + } - if (objectTypes[_typeof(filter)] && filter) { - className = getClass.call(filter); + return levels; + }; + /** + * Expose cookie on domain. + */ - if (className == functionClass) { - callback = filter; - } else if (className == arrayClass) { - // Convert the property names array into a makeshift set. - properties = {}; - for (var index = 0, length = filter.length, value; index < length;) { - value = filter[index++]; - className = getClass.call(value); + domain.cookie = componentCookie; + /* + * Exports. + */ - if (className == "[object String]" || className == "[object Number]") { - properties[value] = 1; - } - } - } - } + exports = module.exports = domain; + }); - if (width) { - className = getClass.call(width); + /** + * An object utility to persist values in cookies + */ - if (className == numberClass) { - // Convert the `width` to an integer and create a string containing - // `width` number of space characters. - if ((width -= width % 1) > 0) { - if (width > 10) { - width = 10; - } + var CookieLocal = /*#__PURE__*/function () { + function CookieLocal(options) { + _classCallCheck(this, CookieLocal); - for (whitespace = ""; whitespace.length < width;) { - whitespace += " "; - } - } - } else if (className == stringClass) { - whitespace = width.length <= 10 ? width : width.slice(0, 10); - } - } // Opera <= 7.54u2 discards the values associated with empty string keys - // (`""`) only if they are used directly within an object member list - // (e.g., `!("" in { "": 1})`). + this._options = {}; + this.options(options); + } + /** + * + * @param {*} options + */ - return serialize("", (value = {}, value[""] = source, value), callback, properties, whitespace, "", []); - }; - } - } // Public: Parses a JSON source string. + _createClass(CookieLocal, [{ + key: "options", + value: function options() { + var _options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + if (arguments.length === 0) return this._options; + var domain = ".".concat(lib$1(window.location.href)); + if (domain === ".") domain = null; // the default maxage and path - if (!has("json-parse")) { - var fromCharCode = String.fromCharCode; // Internal: A map of escaped control characters and their unescaped - // equivalents. + this._options = defaults_1(_options, { + maxage: 60 * 30, + // Expiry after 30 minutes + secure: true, + path: "/", + domain: domain, + samesite: "Lax" + }); // try setting a cookie first - var Unescapes = { - 92: "\\", - 34: '"', - 47: "/", - 98: "\b", - 116: "\t", - 110: "\n", - 102: "\f", - 114: "\r" - }; // Internal: Stores the parser state. + this.set("test_rudder", true); - var Index, Source; // Internal: Resets the parser state and throws a `SyntaxError`. + if (!this.get("test_rudder")) { + this._options.domain = null; + } - var abort = function abort() { - Index = Source = null; - throw SyntaxError(); - }; // Internal: Returns the next token, or `"$"` if the parser has reached - // the end of the source string. A token may be a string, number, `null` - // literal, or Boolean literal. + this.remove("test_rudder"); + } + /** + * + * @param {*} key + * @param {*} value + */ + }, { + key: "set", + value: function set(key, value) { + try { + rudderComponentCookie(key, value, clone_1(this._options)); + return true; + } catch (e) { + logger.error(e); + return false; + } + } + /** + * + * @param {*} key + */ - var lex = function lex() { - var source = Source, - length = source.length, - value, - begin, - position, - isSigned, - charCode; + }, { + key: "get", + value: function get(key) { + return rudderComponentCookie(key); + } + /** + * + * @param {*} key + */ - while (Index < length) { - charCode = source.charCodeAt(Index); + }, { + key: "remove", + value: function remove(key) { + try { + rudderComponentCookie(key, null, clone_1(this._options)); + return true; + } catch (e) { + return false; + } + } + }]); - switch (charCode) { - case 9: - case 10: - case 13: - case 32: - // Skip whitespace tokens, including tabs, carriage returns, line - // feeds, and space characters. - Index++; - break; + return CookieLocal; + }(); // Exporting only the instance - case 123: - case 125: - case 91: - case 93: - case 58: - case 44: - // Parse a punctuator token (`{`, `}`, `[`, `]`, `:`, or `,`) at - // the current position. - value = charIndexBuggy ? source.charAt(Index) : source[Index]; - Index++; - return value; - case 34: - // `"` delimits a JSON string; advance to the next character and - // begin parsing the string. String tokens are prefixed with the - // sentinel `@` character to distinguish them from punctuators and - // end-of-string tokens. - for (value = "@", Index++; Index < length;) { - charCode = source.charCodeAt(Index); + var Cookie = new CookieLocal({}); - if (charCode < 32) { - // Unescaped ASCII control characters (those with a code unit - // less than the space character) are not permitted. - abort(); - } else if (charCode == 92) { - // A reverse solidus (`\`) marks the beginning of an escaped - // control character (including `"`, `\`, and `/`) or Unicode - // escape sequence. - charCode = source.charCodeAt(++Index); + var json3 = createCommonjsModule(function (module, exports) { + (function () { + // Detect the `define` function exposed by asynchronous module loaders. The + // strict `define` check is necessary for compatibility with `r.js`. + var isLoader = typeof undefined === "function" ; // A set of types used to distinguish objects from primitives. - switch (charCode) { - case 92: - case 34: - case 47: - case 98: - case 116: - case 110: - case 102: - case 114: - // Revive escaped control characters. - value += Unescapes[charCode]; - Index++; - break; + var objectTypes = { + "function": true, + "object": true + }; // Detect the `exports` object exposed by CommonJS implementations. - case 117: - // `\u` marks the beginning of a Unicode escape sequence. - // Advance to the first character and validate the - // four-digit code point. - begin = ++Index; + var freeExports = objectTypes['object'] && exports && !exports.nodeType && exports; // Use the `global` object exposed by Node (including Browserify via + // `insert-module-globals`), Narwhal, and Ringo as the default context, + // and the `window` object in browsers. Rhino exports a `global` function + // instead. - for (position = Index + 4; Index < position; Index++) { - charCode = source.charCodeAt(Index); // A valid sequence comprises four hexdigits (case- - // insensitive) that form a single hexadecimal value. + var root = objectTypes[typeof window === "undefined" ? "undefined" : _typeof(window)] && window || this, + freeGlobal = freeExports && objectTypes['object'] && module && !module.nodeType && _typeof(commonjsGlobal) == "object" && commonjsGlobal; - if (!(charCode >= 48 && charCode <= 57 || charCode >= 97 && charCode <= 102 || charCode >= 65 && charCode <= 70)) { - // Invalid Unicode escape sequence. - abort(); - } - } // Revive the escaped character. + if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) { + root = freeGlobal; + } // Public: Initializes JSON 3 using the given `context` object, attaching the + // `stringify` and `parse` functions to the specified `exports` object. - value += fromCharCode("0x" + source.slice(begin, Index)); - break; + function runInContext(context, exports) { + context || (context = root.Object()); + exports || (exports = root.Object()); // Native constructor aliases. - default: - // Invalid escape sequence. - abort(); - } - } else { - if (charCode == 34) { - // An unescaped double-quote character marks the end of the - // string. - break; - } + var Number = context.Number || root.Number, + String = context.String || root.String, + Object = context.Object || root.Object, + Date = context.Date || root.Date, + SyntaxError = context.SyntaxError || root.SyntaxError, + TypeError = context.TypeError || root.TypeError, + Math = context.Math || root.Math, + nativeJSON = context.JSON || root.JSON; // Delegate to the native `stringify` and `parse` implementations. - charCode = source.charCodeAt(Index); - begin = Index; // Optimize for the common case where a string is valid. + if (_typeof(nativeJSON) == "object" && nativeJSON) { + exports.stringify = nativeJSON.stringify; + exports.parse = nativeJSON.parse; + } // Convenience aliases. - while (charCode >= 32 && charCode != 92 && charCode != 34) { - charCode = source.charCodeAt(++Index); - } // Append the string as-is. + var objectProto = Object.prototype, + getClass = objectProto.toString, + isProperty = objectProto.hasOwnProperty, + undefined$1; // Internal: Contains `try...catch` logic used by other functions. + // This prevents other functions from being deoptimized. - value += source.slice(begin, Index); - } - } + function attempt(func, errorFunc) { + try { + func(); + } catch (exception) { + if (errorFunc) { + errorFunc(); + } + } + } // Test the `Date#getUTC*` methods. Based on work by @Yaffle. - if (source.charCodeAt(Index) == 34) { - // Advance to the next character and return the revived string. - Index++; - return value; - } // Unterminated string. + var isExtended = new Date(-3509827334573292); + attempt(function () { + // The `getUTCFullYear`, `Month`, and `Date` methods return nonsensical + // results for certain dates in Opera >= 10.53. + isExtended = isExtended.getUTCFullYear() == -109252 && isExtended.getUTCMonth() === 0 && isExtended.getUTCDate() === 1 && isExtended.getUTCHours() == 10 && isExtended.getUTCMinutes() == 37 && isExtended.getUTCSeconds() == 6 && isExtended.getUTCMilliseconds() == 708; + }); // Internal: Determines whether the native `JSON.stringify` and `parse` + // implementations are spec-compliant. Based on work by Ken Snyder. - abort(); + function has(name) { + if (has[name] != null) { + // Return cached feature test result. + return has[name]; + } - default: - // Parse numbers and literals. - begin = Index; // Advance past the negative sign, if one is specified. + var isSupported; - if (charCode == 45) { - isSigned = true; - charCode = source.charCodeAt(++Index); - } // Parse an integer or floating-point value. + if (name == "bug-string-char-index") { + // IE <= 7 doesn't support accessing string characters using square + // bracket notation. IE 8 only supports this for primitives. + isSupported = "a"[0] != "a"; + } else if (name == "json") { + // Indicates whether both `JSON.stringify` and `JSON.parse` are + // supported. + isSupported = has("json-stringify") && has("date-serialization") && has("json-parse"); + } else if (name == "date-serialization") { + // Indicates whether `Date`s can be serialized accurately by `JSON.stringify`. + isSupported = has("json-stringify") && isExtended; + if (isSupported) { + var stringify = exports.stringify; + attempt(function () { + isSupported = // JSON 2, Prototype <= 1.7, and older WebKit builds incorrectly + // serialize extended years. + stringify(new Date(-8.64e15)) == '"-271821-04-20T00:00:00.000Z"' && // The milliseconds are optional in ES 5, but required in 5.1. + stringify(new Date(8.64e15)) == '"+275760-09-13T00:00:00.000Z"' && // Firefox <= 11.0 incorrectly serializes years prior to 0 as negative + // four-digit years instead of six-digit years. Credits: @Yaffle. + stringify(new Date(-621987552e5)) == '"-000001-01-01T00:00:00.000Z"' && // Safari <= 5.1.5 and Opera >= 10.53 incorrectly serialize millisecond + // values less than 1000. Credits: @Yaffle. + stringify(new Date(-1)) == '"1969-12-31T23:59:59.999Z"'; + }); + } + } else { + var value, + serialized = "{\"a\":[1,true,false,null,\"\\u0000\\b\\n\\f\\r\\t\"]}"; // Test `JSON.stringify`. - if (charCode >= 48 && charCode <= 57) { - // Leading zeroes are interpreted as octal literals. - if (charCode == 48 && (charCode = source.charCodeAt(Index + 1), charCode >= 48 && charCode <= 57)) { - // Illegal octal literal. - abort(); - } + if (name == "json-stringify") { + var stringify = exports.stringify, + stringifySupported = typeof stringify == "function"; - isSigned = false; // Parse the integer component. + if (stringifySupported) { + // A test function object with a custom `toJSON` method. + (value = function value() { + return 1; + }).toJSON = value; + attempt(function () { + stringifySupported = // Firefox 3.1b1 and b2 serialize string, number, and boolean + // primitives as object literals. + stringify(0) === "0" && // FF 3.1b1, b2, and JSON 2 serialize wrapped primitives as object + // literals. + stringify(new Number()) === "0" && stringify(new String()) == '""' && // FF 3.1b1, 2 throw an error if the value is `null`, `undefined`, or + // does not define a canonical JSON representation (this applies to + // objects with `toJSON` properties as well, *unless* they are nested + // within an object or array). + stringify(getClass) === undefined$1 && // IE 8 serializes `undefined` as `"undefined"`. Safari <= 5.1.7 and + // FF 3.1b3 pass this test. + stringify(undefined$1) === undefined$1 && // Safari <= 5.1.7 and FF 3.1b3 throw `Error`s and `TypeError`s, + // respectively, if the value is omitted entirely. + stringify() === undefined$1 && // FF 3.1b1, 2 throw an error if the given value is not a number, + // string, array, object, Boolean, or `null` literal. This applies to + // objects with custom `toJSON` methods as well, unless they are nested + // inside object or array literals. YUI 3.0.0b1 ignores custom `toJSON` + // methods entirely. + stringify(value) === "1" && stringify([value]) == "[1]" && // Prototype <= 1.6.1 serializes `[undefined]` as `"[]"` instead of + // `"[null]"`. + stringify([undefined$1]) == "[null]" && // YUI 3.0.0b1 fails to serialize `null` literals. + stringify(null) == "null" && // FF 3.1b1, 2 halts serialization if an array contains a function: + // `[1, true, getClass, 1]` serializes as "[1,true,],". FF 3.1b3 + // elides non-JSON values from objects and arrays, unless they + // define custom `toJSON` methods. + stringify([undefined$1, getClass, null]) == "[null,null,null]" && // Simple serialization test. FF 3.1b1 uses Unicode escape sequences + // where character escape codes are expected (e.g., `\b` => `\u0008`). + stringify({ + "a": [value, true, false, null, "\x00\b\n\f\r\t"] + }) == serialized && // FF 3.1b1 and b2 ignore the `filter` and `width` arguments. + stringify(null, value) === "1" && stringify([1, 2], null, 1) == "[\n 1,\n 2\n]"; + }, function () { + stringifySupported = false; + }); + } - for (; Index < length && (charCode = source.charCodeAt(Index), charCode >= 48 && charCode <= 57); Index++) { - } // Floats cannot contain a leading decimal point; however, this - // case is already accounted for by the parser. + isSupported = stringifySupported; + } // Test `JSON.parse`. - if (source.charCodeAt(Index) == 46) { - position = ++Index; // Parse the decimal component. + if (name == "json-parse") { + var parse = exports.parse, + parseSupported; - for (; position < length; position++) { - charCode = source.charCodeAt(position); + if (typeof parse == "function") { + attempt(function () { + // FF 3.1b1, b2 will throw an exception if a bare literal is provided. + // Conforming implementations should also coerce the initial argument to + // a string prior to parsing. + if (parse("0") === 0 && !parse(false)) { + // Simple parsing test. + value = parse(serialized); + parseSupported = value["a"].length == 5 && value["a"][0] === 1; - if (charCode < 48 || charCode > 57) { - break; - } - } + if (parseSupported) { + attempt(function () { + // Safari <= 5.1.2 and FF 3.1b1 allow unescaped tabs in strings. + parseSupported = !parse('"\t"'); + }); - if (position == Index) { - // Illegal trailing decimal. - abort(); - } + if (parseSupported) { + attempt(function () { + // FF 4.0 and 4.0.1 allow leading `+` signs and leading + // decimal points. FF 4.0, 4.0.1, and IE 9-10 also allow + // certain octal literals. + parseSupported = parse("01") !== 1; + }); + } - Index = position; - } // Parse exponents. The `e` denoting the exponent is - // case-insensitive. + if (parseSupported) { + attempt(function () { + // FF 4.0, 4.0.1, and Rhino 1.7R3-R4 allow trailing decimal + // points. These environments, along with FF 3.1b1 and 2, + // also allow trailing commas in JSON objects and arrays. + parseSupported = parse("1.") !== 1; + }); + } + } + } + }, function () { + parseSupported = false; + }); + } + isSupported = parseSupported; + } + } - charCode = source.charCodeAt(Index); + return has[name] = !!isSupported; + } - if (charCode == 101 || charCode == 69) { - charCode = source.charCodeAt(++Index); // Skip past the sign following the exponent, if one is - // specified. + has["bug-string-char-index"] = has["date-serialization"] = has["json"] = has["json-stringify"] = has["json-parse"] = null; - if (charCode == 43 || charCode == 45) { - Index++; - } // Parse the exponential component. + if (!has("json")) { + // Common `[[Class]]` name aliases. + var functionClass = "[object Function]", + dateClass = "[object Date]", + numberClass = "[object Number]", + stringClass = "[object String]", + arrayClass = "[object Array]", + booleanClass = "[object Boolean]"; // Detect incomplete support for accessing string characters by index. + var charIndexBuggy = has("bug-string-char-index"); // Internal: Normalizes the `for...in` iteration algorithm across + // environments. Each enumerated key is yielded to a `callback` function. - for (position = Index; position < length; position++) { - charCode = source.charCodeAt(position); + var _forOwn = function forOwn(object, callback) { + var size = 0, + Properties, + dontEnums, + property; // Tests for bugs in the current environment's `for...in` algorithm. The + // `valueOf` property inherits the non-enumerable flag from + // `Object.prototype` in older versions of IE, Netscape, and Mozilla. - if (charCode < 48 || charCode > 57) { - break; - } - } + (Properties = function Properties() { + this.valueOf = 0; + }).prototype.valueOf = 0; // Iterate over a new instance of the `Properties` class. - if (position == Index) { - // Illegal empty exponent. - abort(); - } + dontEnums = new Properties(); - Index = position; - } // Coerce the parsed value to a JavaScript number. + for (property in dontEnums) { + // Ignore all properties inherited from `Object.prototype`. + if (isProperty.call(dontEnums, property)) { + size++; + } + } + Properties = dontEnums = null; // Normalize the iteration algorithm. - return +source.slice(begin, Index); - } // A negative sign may only precede numbers. + if (!size) { + // A list of non-enumerable properties inherited from `Object.prototype`. + dontEnums = ["valueOf", "toString", "toLocaleString", "propertyIsEnumerable", "isPrototypeOf", "hasOwnProperty", "constructor"]; // IE <= 8, Mozilla 1.0, and Netscape 6.2 ignore shadowed non-enumerable + // properties. + _forOwn = function forOwn(object, callback) { + var isFunction = getClass.call(object) == functionClass, + property, + length; + var hasProperty = !isFunction && typeof object.constructor != "function" && objectTypes[_typeof(object.hasOwnProperty)] && object.hasOwnProperty || isProperty; - if (isSigned) { - abort(); - } // `true`, `false`, and `null` literals. + for (property in object) { + // Gecko <= 1.0 enumerates the `prototype` property of functions under + // certain conditions; IE does not. + if (!(isFunction && property == "prototype") && hasProperty.call(object, property)) { + callback(property); + } + } // Manually invoke the callback for each non-enumerable property. - var temp = source.slice(Index, Index + 4); + for (length = dontEnums.length; property = dontEnums[--length];) { + if (hasProperty.call(object, property)) { + callback(property); + } + } + }; + } else { + // No bugs detected; use the standard `for...in` algorithm. + _forOwn = function forOwn(object, callback) { + var isFunction = getClass.call(object) == functionClass, + property, + isConstructor; - if (temp == "true") { - Index += 4; - return true; - } else if (temp == "fals" && source.charCodeAt(Index + 4) == 101) { - Index += 5; - return false; - } else if (temp == "null") { - Index += 4; - return null; - } // Unrecognized token. + for (property in object) { + if (!(isFunction && property == "prototype") && isProperty.call(object, property) && !(isConstructor = property === "constructor")) { + callback(property); + } + } // Manually invoke the callback for the `constructor` property due to + // cross-environment inconsistencies. - abort(); + if (isConstructor || isProperty.call(object, property = "constructor")) { + callback(property); } - } // Return the sentinel `$` character if the parser has reached the end - // of the source string. + }; + } + + return _forOwn(object, callback); + }; // Public: Serializes a JavaScript `value` as a JSON string. The optional + // `filter` argument may specify either a function that alters how object and + // array members are serialized, or an array of strings and numbers that + // indicates which properties should be serialized. The optional `width` + // argument may be either a string or number that specifies the indentation + // level of the output. - return "$"; - }; // Internal: Parses a JSON `value` token. + if (!has("json-stringify") && !has("date-serialization")) { + // Internal: A map of control characters and their escaped equivalents. + var Escapes = { + 92: "\\\\", + 34: '\\"', + 8: "\\b", + 12: "\\f", + 10: "\\n", + 13: "\\r", + 9: "\\t" + }; // Internal: Converts `value` into a zero-padded string such that its + // length is at least equal to `width`. The `width` must be <= 6. + var leadingZeroes = "000000"; - var get = function get(value) { - var results, hasMembers; + var toPaddedString = function toPaddedString(width, value) { + // The `|| 0` expression is necessary to work around a bug in + // Opera <= 7.54u2 where `0 == -0`, but `String(-0) !== "0"`. + return (leadingZeroes + (value || 0)).slice(-width); + }; // Internal: Serializes a date object. - if (value == "$") { - // Unexpected end of input. - abort(); - } - if (typeof value == "string") { - if ((charIndexBuggy ? value.charAt(0) : value[0]) == "@") { - // Remove the sentinel `@` character. - return value.slice(1); - } // Parse object and array literals. + var _serializeDate = function serializeDate(value) { + var getData, year, month, date, time, hours, minutes, seconds, milliseconds; // Define additional utility methods if the `Date` methods are buggy. + if (!isExtended) { + var floor = Math.floor; // A mapping between the months of the year and the number of days between + // January 1st and the first of the respective month. - if (value == "[") { - // Parses a JSON array, returning a new JavaScript array. - results = []; + var Months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]; // Internal: Calculates the number of days between the Unix epoch and the + // first day of the given month. - for (;;) { - value = lex(); // A closing square bracket marks the end of the array literal. + var getDay = function getDay(year, month) { + return Months[month] + 365 * (year - 1970) + floor((year - 1969 + (month = +(month > 1))) / 4) - floor((year - 1901 + month) / 100) + floor((year - 1601 + month) / 400); + }; - if (value == "]") { - break; - } // If the array literal contains elements, the current token - // should be a comma separating the previous element from the - // next. + getData = function getData(value) { + // Manually compute the year, month, date, hours, minutes, + // seconds, and milliseconds if the `getUTC*` methods are + // buggy. Adapted from @Yaffle's `date-shim` project. + date = floor(value / 864e5); + for (year = floor(date / 365.2425) + 1970 - 1; getDay(year + 1, 0) <= date; year++) { + } - if (hasMembers) { - if (value == ",") { - value = lex(); + for (month = floor((date - getDay(year, 0)) / 30.42); getDay(year, month + 1) <= date; month++) { + } - if (value == "]") { - // Unexpected trailing `,` in array literal. - abort(); - } - } else { - // A `,` must separate each array element. - abort(); - } - } else { - hasMembers = true; - } // Elisions and leading commas are not permitted. + date = 1 + date - getDay(year, month); // The `time` value specifies the time within the day (see ES + // 5.1 section 15.9.1.2). The formula `(A % B + B) % B` is used + // to compute `A modulo B`, as the `%` operator does not + // correspond to the `modulo` operation for negative numbers. + time = (value % 864e5 + 864e5) % 864e5; // The hours, minutes, seconds, and milliseconds are obtained by + // decomposing the time within the day. See section 15.9.1.10. - if (value == ",") { - abort(); - } + hours = floor(time / 36e5) % 24; + minutes = floor(time / 6e4) % 60; + seconds = floor(time / 1e3) % 60; + milliseconds = time % 1e3; + }; + } else { + getData = function getData(value) { + year = value.getUTCFullYear(); + month = value.getUTCMonth(); + date = value.getUTCDate(); + hours = value.getUTCHours(); + minutes = value.getUTCMinutes(); + seconds = value.getUTCSeconds(); + milliseconds = value.getUTCMilliseconds(); + }; + } - results.push(get(value)); - } + _serializeDate = function serializeDate(value) { + if (value > -1 / 0 && value < 1 / 0) { + // Dates are serialized according to the `Date#toJSON` method + // specified in ES 5.1 section 15.9.5.44. See section 15.9.1.15 + // for the ISO 8601 date time string format. + getData(value); // Serialize extended years correctly. - return results; - } else if (value == "{") { - // Parses a JSON object, returning a new JavaScript object. - results = {}; + value = (year <= 0 || year >= 1e4 ? (year < 0 ? "-" : "+") + toPaddedString(6, year < 0 ? -year : year) : toPaddedString(4, year)) + "-" + toPaddedString(2, month + 1) + "-" + toPaddedString(2, date) + // Months, dates, hours, minutes, and seconds should have two + // digits; milliseconds should have three. + "T" + toPaddedString(2, hours) + ":" + toPaddedString(2, minutes) + ":" + toPaddedString(2, seconds) + // Milliseconds are optional in ES 5.0, but required in 5.1. + "." + toPaddedString(3, milliseconds) + "Z"; + year = month = date = hours = minutes = seconds = milliseconds = null; + } else { + value = null; + } - for (;;) { - value = lex(); // A closing curly brace marks the end of the object literal. + return value; + }; - if (value == "}") { - break; - } // If the object literal contains members, the current token - // should be a comma separator. + return _serializeDate(value); + }; // For environments with `JSON.stringify` but buggy date serialization, + // we override the native `Date#toJSON` implementation with a + // spec-compliant one. + + + if (has("json-stringify") && !has("date-serialization")) { + // Internal: the `Date#toJSON` implementation used to override the native one. + var dateToJSON = function dateToJSON(key) { + return _serializeDate(this); + }; // Public: `JSON.stringify`. See ES 5.1 section 15.12.3. - if (hasMembers) { - if (value == ",") { - value = lex(); + var nativeStringify = exports.stringify; - if (value == "}") { - // Unexpected trailing `,` in object literal. - abort(); - } - } else { - // A `,` must separate each object member. - abort(); - } - } else { - hasMembers = true; - } // Leading commas are not permitted, object property names must be - // double-quoted strings, and a `:` must separate each property - // name and value. + exports.stringify = function (source, filter, width) { + var nativeToJSON = Date.prototype.toJSON; + Date.prototype.toJSON = dateToJSON; + var result = nativeStringify(source, filter, width); + Date.prototype.toJSON = nativeToJSON; + return result; + }; + } else { + // Internal: Double-quotes a string `value`, replacing all ASCII control + // characters (characters with code unit values between 0 and 31) with + // their escaped equivalents. This is an implementation of the + // `Quote(value)` operation defined in ES 5.1 section 15.12.3. + var unicodePrefix = "\\u00"; + var escapeChar = function escapeChar(character) { + var charCode = character.charCodeAt(0), + escaped = Escapes[charCode]; - if (value == "," || typeof value != "string" || (charIndexBuggy ? value.charAt(0) : value[0]) != "@" || lex() != ":") { - abort(); - } + if (escaped) { + return escaped; + } - results[value.slice(1)] = get(lex()); - } + return unicodePrefix + toPaddedString(2, charCode.toString(16)); + }; - return results; - } // Unexpected token encountered. + var reEscape = /[\x00-\x1f\x22\x5c]/g; + var quote = function quote(value) { + reEscape.lastIndex = 0; + return '"' + (reEscape.test(value) ? value.replace(reEscape, escapeChar) : value) + '"'; + }; // Internal: Recursively serializes an object. Implements the + // `Str(key, holder)`, `JO(value)`, and `JA(value)` operations. - abort(); - } - return value; - }; // Internal: Updates a traversed object member. + var serialize = function serialize(property, object, callback, properties, whitespace, indentation, stack) { + var value, type, className, results, element, index, length, prefix, result; + attempt(function () { + // Necessary for host object support. + value = object[property]; + }); + if (_typeof(value) == "object" && value) { + if (value.getUTCFullYear && getClass.call(value) == dateClass && value.toJSON === Date.prototype.toJSON) { + value = _serializeDate(value); + } else if (typeof value.toJSON == "function") { + value = value.toJSON(property); + } + } - var update = function update(source, property, callback) { - var element = walk(source, property, callback); + if (callback) { + // If a replacement function was provided, call it to obtain the value + // for serialization. + value = callback.call(object, property, value); + } // Exit early if value is `undefined` or `null`. - if (element === undefined$1) { - delete source[property]; - } else { - source[property] = element; - } - }; // Internal: Recursively traverses a parsed JSON object, invoking the - // `callback` function for each value. This is an implementation of the - // `Walk(holder, name)` operation defined in ES 5.1 section 15.12.2. + if (value == undefined$1) { + return value === undefined$1 ? value : "null"; + } - var walk = function walk(source, property, callback) { - var value = source[property], - length; + type = _typeof(value); // Only call `getClass` if the value is an object. - if (_typeof(value) == "object" && value) { - // `forOwn` can't be used to traverse an array in Opera <= 8.54 - // because its `Object#hasOwnProperty` implementation returns `false` - // for array indices (e.g., `![1, 2, 3].hasOwnProperty("0")`). - if (getClass.call(value) == arrayClass) { - for (length = value.length; length--;) { - update(getClass, _forOwn, value, length, callback); - } - } else { - _forOwn(value, function (property) { - update(value, property, callback); - }); + if (type == "object") { + className = getClass.call(value); } - } - - return callback.call(source, property, value); - }; // Public: `JSON.parse`. See ES 5.1 section 15.12.2. + switch (className || type) { + case "boolean": + case booleanClass: + // Booleans are represented literally. + return "" + value; - exports.parse = function (source, callback) { - var result, value; - Index = 0; - Source = "" + source; - result = get(lex()); // If a JSON string contains multiple tokens, it is invalid. + case "number": + case numberClass: + // JSON numbers must be finite. `Infinity` and `NaN` are serialized as + // `"null"`. + return value > -1 / 0 && value < 1 / 0 ? "" + value : "null"; - if (lex() != "$") { - abort(); - } // Reset the parser state. + case "string": + case stringClass: + // Strings are double-quoted and escaped. + return quote("" + value); + } // Recursively serialize objects and arrays. - Index = Source = null; - return callback && getClass.call(callback) == functionClass ? walk((value = {}, value[""] = result, value), "", callback) : result; - }; - } - } + if (_typeof(value) == "object") { + // Check for cyclic structures. This is a linear search; performance + // is inversely proportional to the number of unique nested objects. + for (length = stack.length; length--;) { + if (stack[length] === value) { + // Cyclic structures cannot be serialized by `JSON.stringify`. + throw TypeError(); + } + } // Add the object to the stack of traversed objects. - exports.runInContext = runInContext; - return exports; - } - if (freeExports && !isLoader) { - // Export for CommonJS environments. - runInContext(root, freeExports); - } else { - // Export for web browsers and JavaScript engines. - var nativeJSON = root.JSON, - previousJSON = root.JSON3, - isRestored = false; - var JSON3 = runInContext(root, root.JSON3 = { - // Public: Restores the original value of the global `JSON` object and - // returns a reference to the `JSON3` object. - "noConflict": function noConflict() { - if (!isRestored) { - isRestored = true; - root.JSON = nativeJSON; - root.JSON3 = previousJSON; - nativeJSON = previousJSON = null; - } + stack.push(value); + results = []; // Save the current indentation level and indent one additional level. - return JSON3; - } - }); - root.JSON = { - "parse": JSON3.parse, - "stringify": JSON3.stringify - }; - } // Export for asynchronous module loaders. - }).call(commonjsGlobal); - }); + prefix = indentation; + indentation += whitespace; - var debug_1$1 = createCommonjsModule(function (module, exports) { - /** - * This is the common logic for both the Node.js and web browser - * implementations of `debug()`. - * - * Expose `debug()` as the module. - */ - exports = module.exports = debug; - exports.coerce = coerce; - exports.disable = disable; - exports.enable = enable; - exports.enabled = enabled; - exports.humanize = ms; - /** - * The currently active debug mode names, and names to skip. - */ + if (className == arrayClass) { + // Recursively serialize array elements. + for (index = 0, length = value.length; index < length; index++) { + element = serialize(index, value, callback, properties, whitespace, indentation, stack); + results.push(element === undefined$1 ? "null" : element); + } - exports.names = []; - exports.skips = []; - /** - * Map of special "%n" handling functions, for the debug "format" argument. - * - * Valid key names are a single, lowercased letter, i.e. "n". - */ + result = results.length ? whitespace ? "[\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "]" : "[" + results.join(",") + "]" : "[]"; + } else { + // Recursively serialize object members. Members are selected from + // either a user-specified list of property names, or the object + // itself. + _forOwn(properties || value, function (property) { + var element = serialize(property, value, callback, properties, whitespace, indentation, stack); - exports.formatters = {}; - /** - * Previously assigned color. - */ + if (element !== undefined$1) { + // According to ES 5.1 section 15.12.3: "If `gap` {whitespace} + // is not the empty string, let `member` {quote(property) + ":"} + // be the concatenation of `member` and the `space` character." + // The "`space` character" refers to the literal space + // character, not the `space` {width} argument provided to + // `JSON.stringify`. + results.push(quote(property) + ":" + (whitespace ? " " : "") + element); + } + }); - var prevColor = 0; - /** - * Previous log timestamp. - */ + result = results.length ? whitespace ? "{\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "}" : "{" + results.join(",") + "}" : "{}"; + } // Remove the object from the traversed object stack. - var prevTime; - /** - * Select a color. - * - * @return {Number} - * @api private - */ - function selectColor() { - return exports.colors[prevColor++ % exports.colors.length]; - } - /** - * Create a debugger with the given `namespace`. - * - * @param {String} namespace - * @return {Function} - * @api public - */ + stack.pop(); + return result; + } + }; // Public: `JSON.stringify`. See ES 5.1 section 15.12.3. - function debug(namespace) { - // define the `disabled` version - function disabled() {} + exports.stringify = function (source, filter, width) { + var whitespace, callback, properties, className; - disabled.enabled = false; // define the `enabled` version + if (objectTypes[_typeof(filter)] && filter) { + className = getClass.call(filter); - function enabled() { - var self = enabled; // set `diff` timestamp + if (className == functionClass) { + callback = filter; + } else if (className == arrayClass) { + // Convert the property names array into a makeshift set. + properties = {}; - var curr = +new Date(); - var ms = curr - (prevTime || curr); - self.diff = ms; - self.prev = prevTime; - self.curr = curr; - prevTime = curr; // add the `color` if not set + for (var index = 0, length = filter.length, value; index < length;) { + value = filter[index++]; + className = getClass.call(value); - if (null == self.useColors) self.useColors = exports.useColors(); - if (null == self.color && self.useColors) self.color = selectColor(); - var args = Array.prototype.slice.call(arguments); - args[0] = exports.coerce(args[0]); + if (className == "[object String]" || className == "[object Number]") { + properties[value] = 1; + } + } + } + } - if ('string' !== typeof args[0]) { - // anything else let's inspect with %o - args = ['%o'].concat(args); - } // apply any `formatters` transformations + if (width) { + className = getClass.call(width); + if (className == numberClass) { + // Convert the `width` to an integer and create a string containing + // `width` number of space characters. + if ((width -= width % 1) > 0) { + if (width > 10) { + width = 10; + } - var index = 0; - args[0] = args[0].replace(/%([a-z%])/g, function (match, format) { - // if we encounter an escaped % then don't increase the array index - if (match === '%%') return match; - index++; - var formatter = exports.formatters[format]; + for (whitespace = ""; whitespace.length < width;) { + whitespace += " "; + } + } + } else if (className == stringClass) { + whitespace = width.length <= 10 ? width : width.slice(0, 10); + } + } // Opera <= 7.54u2 discards the values associated with empty string keys + // (`""`) only if they are used directly within an object member list + // (e.g., `!("" in { "": 1})`). - if ('function' === typeof formatter) { - var val = args[index]; - match = formatter.call(self, val); // now we need to remove `args[index]` since it's inlined in the `format` - args.splice(index, 1); - index--; - } + return serialize("", (value = {}, value[""] = source, value), callback, properties, whitespace, "", []); + }; + } + } // Public: Parses a JSON source string. - return match; - }); - if ('function' === typeof exports.formatArgs) { - args = exports.formatArgs.apply(self, args); - } + if (!has("json-parse")) { + var fromCharCode = String.fromCharCode; // Internal: A map of escaped control characters and their unescaped + // equivalents. - var logFn = enabled.log || exports.log || console.log.bind(console); - logFn.apply(self, args); - } + var Unescapes = { + 92: "\\", + 34: '"', + 47: "/", + 98: "\b", + 116: "\t", + 110: "\n", + 102: "\f", + 114: "\r" + }; // Internal: Stores the parser state. - enabled.enabled = true; - var fn = exports.enabled(namespace) ? enabled : disabled; - fn.namespace = namespace; - return fn; - } - /** - * Enables a debug mode by namespaces. This can include modes - * separated by a colon and wildcards. - * - * @param {String} namespaces - * @api public - */ + var Index, Source; // Internal: Resets the parser state and throws a `SyntaxError`. + var abort = function abort() { + Index = Source = null; + throw SyntaxError(); + }; // Internal: Returns the next token, or `"$"` if the parser has reached + // the end of the source string. A token may be a string, number, `null` + // literal, or Boolean literal. - function enable(namespaces) { - exports.save(namespaces); - var split = (namespaces || '').split(/[\s,]+/); - var len = split.length; - for (var i = 0; i < len; i++) { - if (!split[i]) continue; // ignore empty strings + var lex = function lex() { + var source = Source, + length = source.length, + value, + begin, + position, + isSigned, + charCode; - namespaces = split[i].replace(/\*/g, '.*?'); + while (Index < length) { + charCode = source.charCodeAt(Index); - if (namespaces[0] === '-') { - exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$')); - } else { - exports.names.push(new RegExp('^' + namespaces + '$')); - } - } - } - /** - * Disable debug output. - * - * @api public - */ + switch (charCode) { + case 9: + case 10: + case 13: + case 32: + // Skip whitespace tokens, including tabs, carriage returns, line + // feeds, and space characters. + Index++; + break; + case 123: + case 125: + case 91: + case 93: + case 58: + case 44: + // Parse a punctuator token (`{`, `}`, `[`, `]`, `:`, or `,`) at + // the current position. + value = charIndexBuggy ? source.charAt(Index) : source[Index]; + Index++; + return value; - function disable() { - exports.enable(''); - } - /** - * Returns true if the given mode name is enabled, false otherwise. - * - * @param {String} name - * @return {Boolean} - * @api public - */ + case 34: + // `"` delimits a JSON string; advance to the next character and + // begin parsing the string. String tokens are prefixed with the + // sentinel `@` character to distinguish them from punctuators and + // end-of-string tokens. + for (value = "@", Index++; Index < length;) { + charCode = source.charCodeAt(Index); + if (charCode < 32) { + // Unescaped ASCII control characters (those with a code unit + // less than the space character) are not permitted. + abort(); + } else if (charCode == 92) { + // A reverse solidus (`\`) marks the beginning of an escaped + // control character (including `"`, `\`, and `/`) or Unicode + // escape sequence. + charCode = source.charCodeAt(++Index); - function enabled(name) { - var i, len; + switch (charCode) { + case 92: + case 34: + case 47: + case 98: + case 116: + case 110: + case 102: + case 114: + // Revive escaped control characters. + value += Unescapes[charCode]; + Index++; + break; - for (i = 0, len = exports.skips.length; i < len; i++) { - if (exports.skips[i].test(name)) { - return false; - } - } + case 117: + // `\u` marks the beginning of a Unicode escape sequence. + // Advance to the first character and validate the + // four-digit code point. + begin = ++Index; - for (i = 0, len = exports.names.length; i < len; i++) { - if (exports.names[i].test(name)) { - return true; - } - } + for (position = Index + 4; Index < position; Index++) { + charCode = source.charCodeAt(Index); // A valid sequence comprises four hexdigits (case- + // insensitive) that form a single hexadecimal value. - return false; - } - /** - * Coerce `val`. - * - * @param {Mixed} val - * @return {Mixed} - * @api private - */ + if (!(charCode >= 48 && charCode <= 57 || charCode >= 97 && charCode <= 102 || charCode >= 65 && charCode <= 70)) { + // Invalid Unicode escape sequence. + abort(); + } + } // Revive the escaped character. - function coerce(val) { - if (val instanceof Error) return val.stack || val.message; - return val; - } - }); - var debug_2$1 = debug_1$1.coerce; - var debug_3$1 = debug_1$1.disable; - var debug_4$1 = debug_1$1.enable; - var debug_5$1 = debug_1$1.enabled; - var debug_6$1 = debug_1$1.humanize; - var debug_7$1 = debug_1$1.names; - var debug_8$1 = debug_1$1.skips; - var debug_9$1 = debug_1$1.formatters; + value += fromCharCode("0x" + source.slice(begin, Index)); + break; + + default: + // Invalid escape sequence. + abort(); + } + } else { + if (charCode == 34) { + // An unescaped double-quote character marks the end of the + // string. + break; + } - var browser$1 = createCommonjsModule(function (module, exports) { - /** - * This is the web browser implementation of `debug()`. - * - * Expose `debug()` as the module. - */ - exports = module.exports = debug_1$1; - exports.log = log; - exports.formatArgs = formatArgs; - exports.save = save; - exports.load = load; - exports.useColors = useColors; - exports.storage = 'undefined' != typeof chrome && 'undefined' != typeof chrome.storage ? chrome.storage.local : localstorage(); - /** - * Colors. - */ + charCode = source.charCodeAt(Index); + begin = Index; // Optimize for the common case where a string is valid. - exports.colors = ['lightseagreen', 'forestgreen', 'goldenrod', 'dodgerblue', 'darkorchid', 'crimson']; - /** - * Currently only WebKit-based Web Inspectors, Firefox >= v31, - * and the Firebug extension (any Firefox version) are known - * to support "%c" CSS customizations. - * - * TODO: add a `localStorage` variable to explicitly enable/disable colors - */ + while (charCode >= 32 && charCode != 92 && charCode != 34) { + charCode = source.charCodeAt(++Index); + } // Append the string as-is. - function useColors() { - // is webkit? http://stackoverflow.com/a/16459606/376773 - return 'WebkitAppearance' in document.documentElement.style || // is firebug? http://stackoverflow.com/a/398120/376773 - window.console && (console.firebug || console.exception && console.table) || // is firefox >= v31? - // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages - navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31; - } - /** - * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default. - */ + value += source.slice(begin, Index); + } + } - exports.formatters.j = function (v) { - return JSON.stringify(v); - }; - /** - * Colorize log arguments if enabled. - * - * @api public - */ + if (source.charCodeAt(Index) == 34) { + // Advance to the next character and return the revived string. + Index++; + return value; + } // Unterminated string. - function formatArgs() { - var args = arguments; - var useColors = this.useColors; - args[0] = (useColors ? '%c' : '') + this.namespace + (useColors ? ' %c' : ' ') + args[0] + (useColors ? '%c ' : ' ') + '+' + exports.humanize(this.diff); - if (!useColors) return args; - var c = 'color: ' + this.color; - args = [args[0], c, 'color: inherit'].concat(Array.prototype.slice.call(args, 1)); // the final "%c" is somewhat tricky, because there could be other - // arguments passed either before or after the %c, so we need to - // figure out the correct index to insert the CSS into + abort(); - var index = 0; - var lastC = 0; - args[0].replace(/%[a-z%]/g, function (match) { - if ('%%' === match) return; - index++; + default: + // Parse numbers and literals. + begin = Index; // Advance past the negative sign, if one is specified. - if ('%c' === match) { - // we only are interested in the *last* %c - // (the user may have provided their own) - lastC = index; - } - }); - args.splice(lastC, 0, c); - return args; - } - /** - * Invokes `console.log()` when available. - * No-op when `console.log` is not a "function". - * - * @api public - */ + if (charCode == 45) { + isSigned = true; + charCode = source.charCodeAt(++Index); + } // Parse an integer or floating-point value. - function log() { - // this hackery is required for IE8/9, where - // the `console.log` function doesn't have 'apply' - return 'object' === (typeof console === "undefined" ? "undefined" : _typeof(console)) && console.log && Function.prototype.apply.call(console.log, console, arguments); - } - /** - * Save `namespaces`. - * - * @param {String} namespaces - * @api private - */ + if (charCode >= 48 && charCode <= 57) { + // Leading zeroes are interpreted as octal literals. + if (charCode == 48 && (charCode = source.charCodeAt(Index + 1), charCode >= 48 && charCode <= 57)) { + // Illegal octal literal. + abort(); + } + isSigned = false; // Parse the integer component. - function save(namespaces) { - try { - if (null == namespaces) { - exports.storage.removeItem('debug'); - } else { - exports.storage.debug = namespaces; - } - } catch (e) {} - } - /** - * Load `namespaces`. - * - * @return {String} returns the previously persisted debug modes - * @api private - */ + for (; Index < length && (charCode = source.charCodeAt(Index), charCode >= 48 && charCode <= 57); Index++) { + } // Floats cannot contain a leading decimal point; however, this + // case is already accounted for by the parser. - function load() { - var r; + if (source.charCodeAt(Index) == 46) { + position = ++Index; // Parse the decimal component. - try { - r = exports.storage.debug; - } catch (e) {} + for (; position < length; position++) { + charCode = source.charCodeAt(position); - return r; - } - /** - * Enable namespaces listed in `localStorage.debug` initially. - */ + if (charCode < 48 || charCode > 57) { + break; + } + } + if (position == Index) { + // Illegal trailing decimal. + abort(); + } - exports.enable(load()); - /** - * Localstorage attempts to return the localstorage. - * - * This is necessary because safari throws - * when a user disables cookies/localstorage - * and you attempt to access it. - * - * @return {LocalStorage} - * @api private - */ + Index = position; + } // Parse exponents. The `e` denoting the exponent is + // case-insensitive. - function localstorage() { - try { - return window.localStorage; - } catch (e) {} - } - }); - var browser_1$1 = browser$1.log; - var browser_2$1 = browser$1.formatArgs; - var browser_3$1 = browser$1.save; - var browser_4$1 = browser$1.load; - var browser_5$1 = browser$1.useColors; - var browser_6$1 = browser$1.storage; - var browser_7$1 = browser$1.colors; - /** - * Module dependencies. - */ + charCode = source.charCodeAt(Index); - var debug$1 = browser$1('cookie'); - /** - * Set or get cookie `name` with `value` and `options` object. - * - * @param {String} name - * @param {String} value - * @param {Object} options - * @return {Mixed} - * @api public - */ + if (charCode == 101 || charCode == 69) { + charCode = source.charCodeAt(++Index); // Skip past the sign following the exponent, if one is + // specified. - var componentCookie = function componentCookie(name, value, options) { - switch (arguments.length) { - case 3: - case 2: - return set$1(name, value, options); + if (charCode == 43 || charCode == 45) { + Index++; + } // Parse the exponential component. - case 1: - return get$2(name); - default: - return all$1(); - } - }; - /** - * Set cookie `name` to `value`. - * - * @param {String} name - * @param {String} value - * @param {Object} options - * @api private - */ + for (position = Index; position < length; position++) { + charCode = source.charCodeAt(position); + if (charCode < 48 || charCode > 57) { + break; + } + } - function set$1(name, value, options) { - options = options || {}; - var str = encode$2(name) + '=' + encode$2(value); - if (null == value) options.maxage = -1; + if (position == Index) { + // Illegal empty exponent. + abort(); + } - if (options.maxage) { - options.expires = new Date(+new Date() + options.maxage); - } + Index = position; + } // Coerce the parsed value to a JavaScript number. - if (options.path) str += '; path=' + options.path; - if (options.domain) str += '; domain=' + options.domain; - if (options.expires) str += '; expires=' + options.expires.toUTCString(); - if (options.secure) str += '; secure'; - document.cookie = str; - } - /** - * Return all cookies. - * - * @return {Object} - * @api private - */ + + return +source.slice(begin, Index); + } // A negative sign may only precede numbers. - function all$1() { - var str; + if (isSigned) { + abort(); + } // `true`, `false`, and `null` literals. - try { - str = document.cookie; - } catch (err) { - if (typeof console !== 'undefined' && typeof console.error === 'function') { - console.error(err.stack || err); - } - return {}; - } + var temp = source.slice(Index, Index + 4); - return parse$4(str); - } - /** - * Get cookie `name`. - * - * @param {String} name - * @return {String} - * @api private - */ + if (temp == "true") { + Index += 4; + return true; + } else if (temp == "fals" && source.charCodeAt(Index + 4) == 101) { + Index += 5; + return false; + } else if (temp == "null") { + Index += 4; + return null; + } // Unrecognized token. - function get$2(name) { - return all$1()[name]; - } - /** - * Parse cookie `str`. - * - * @param {String} str - * @return {Object} - * @api private - */ + abort(); + } + } // Return the sentinel `$` character if the parser has reached the end + // of the source string. - function parse$4(str) { - var obj = {}; - var pairs = str.split(/ *; */); - var pair; - if ('' == pairs[0]) return obj; + return "$"; + }; // Internal: Parses a JSON `value` token. - for (var i = 0; i < pairs.length; ++i) { - pair = pairs[i].split('='); - obj[decode$2(pair[0])] = decode$2(pair[1]); - } - return obj; - } - /** - * Encode. - */ + var get = function get(value) { + var results, hasMembers; + if (value == "$") { + // Unexpected end of input. + abort(); + } - function encode$2(value) { - try { - return encodeURIComponent(value); - } catch (e) { - debug$1('error `encode(%o)` - %o', value, e); - } - } - /** - * Decode. - */ + if (typeof value == "string") { + if ((charIndexBuggy ? value.charAt(0) : value[0]) == "@") { + // Remove the sentinel `@` character. + return value.slice(1); + } // Parse object and array literals. - function decode$2(value) { - try { - return decodeURIComponent(value); - } catch (e) { - debug$1('error `decode(%o)` - %o', value, e); - } - } + if (value == "[") { + // Parses a JSON array, returning a new JavaScript array. + results = []; - var lib$1 = createCommonjsModule(function (module, exports) { - /** - * Module dependencies. - */ + for (;;) { + value = lex(); // A closing square bracket marks the end of the array literal. - var parse = componentUrl.parse; - /** - * Get the top domain. - * - * The function constructs the levels of domain and attempts to set a global - * cookie on each one when it succeeds it returns the top level domain. - * - * The method returns an empty string when the hostname is an ip or `localhost`. - * - * Example levels: - * - * domain.levels('http://www.google.co.uk'); - * // => ["co.uk", "google.co.uk", "www.google.co.uk"] - * - * Example: - * - * domain('http://localhost:3000/baz'); - * // => '' - * domain('http://dev:3000/baz'); - * // => '' - * domain('http://127.0.0.1:3000/baz'); - * // => '' - * domain('http://segment.io/baz'); - * // => 'segment.io' - * - * @param {string} url - * @return {string} - * @api public - */ + if (value == "]") { + break; + } // If the array literal contains elements, the current token + // should be a comma separating the previous element from the + // next. - function domain(url) { - var cookie = exports.cookie; - var levels = exports.levels(url); // Lookup the real top level one. - for (var i = 0; i < levels.length; ++i) { - var cname = '__tld__'; - var domain = levels[i]; - var opts = { - domain: '.' + domain - }; - cookie(cname, 1, opts); + if (hasMembers) { + if (value == ",") { + value = lex(); - if (cookie(cname)) { - cookie(cname, null, opts); - return domain; - } - } + if (value == "]") { + // Unexpected trailing `,` in array literal. + abort(); + } + } else { + // A `,` must separate each array element. + abort(); + } + } else { + hasMembers = true; + } // Elisions and leading commas are not permitted. - return ''; - } - /** - * Levels returns all levels of the given url. - * - * @param {string} url - * @return {Array} - * @api public - */ + if (value == ",") { + abort(); + } - domain.levels = function (url) { - var host = parse(url).hostname; - var parts = host.split('.'); - var last = parts[parts.length - 1]; - var levels = []; // Ip address. + results.push(get(value)); + } - if (parts.length === 4 && last === parseInt(last, 10)) { - return levels; - } // Localhost. + return results; + } else if (value == "{") { + // Parses a JSON object, returning a new JavaScript object. + results = {}; + for (;;) { + value = lex(); // A closing curly brace marks the end of the object literal. - if (parts.length <= 1) { - return levels; - } // Create levels. + if (value == "}") { + break; + } // If the object literal contains members, the current token + // should be a comma separator. - for (var i = parts.length - 2; i >= 0; --i) { - levels.push(parts.slice(i).join('.')); - } + if (hasMembers) { + if (value == ",") { + value = lex(); - return levels; - }; - /** - * Expose cookie on domain. - */ + if (value == "}") { + // Unexpected trailing `,` in object literal. + abort(); + } + } else { + // A `,` must separate each object member. + abort(); + } + } else { + hasMembers = true; + } // Leading commas are not permitted, object property names must be + // double-quoted strings, and a `:` must separate each property + // name and value. - domain.cookie = componentCookie; - /* - * Exports. - */ + if (value == "," || typeof value != "string" || (charIndexBuggy ? value.charAt(0) : value[0]) != "@" || lex() != ":") { + abort(); + } - exports = module.exports = domain; - }); + results[value.slice(1)] = get(lex()); + } - /** - * An object utility to persist values in cookies - */ + return results; + } // Unexpected token encountered. - var CookieLocal = /*#__PURE__*/function () { - function CookieLocal(options) { - _classCallCheck(this, CookieLocal); - this._options = {}; - this.options(options); - } - /** - * - * @param {*} options - */ + abort(); + } + + return value; + }; // Internal: Updates a traversed object member. + + + var update = function update(source, property, callback) { + var element = walk(source, property, callback); + if (element === undefined$1) { + delete source[property]; + } else { + source[property] = element; + } + }; // Internal: Recursively traverses a parsed JSON object, invoking the + // `callback` function for each value. This is an implementation of the + // `Walk(holder, name)` operation defined in ES 5.1 section 15.12.2. - _createClass(CookieLocal, [{ - key: "options", - value: function options() { - var _options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - if (arguments.length === 0) return this._options; - var domain = ".".concat(lib$1(window.location.href)); - if (domain === ".") domain = null; // the default maxage and path + var walk = function walk(source, property, callback) { + var value = source[property], + length; - this._options = defaults_1(_options, { - maxage: 31536000000, - path: "/", - domain: domain, - samesite: "Lax" - }); // try setting a cookie first + if (_typeof(value) == "object" && value) { + // `forOwn` can't be used to traverse an array in Opera <= 8.54 + // because its `Object#hasOwnProperty` implementation returns `false` + // for array indices (e.g., `![1, 2, 3].hasOwnProperty("0")`). + if (getClass.call(value) == arrayClass) { + for (length = value.length; length--;) { + update(getClass, _forOwn, value, length, callback); + } + } else { + _forOwn(value, function (property) { + update(value, property, callback); + }); + } + } - this.set("test_rudder", true); + return callback.call(source, property, value); + }; // Public: `JSON.parse`. See ES 5.1 section 15.12.2. - if (!this.get("test_rudder")) { - this._options.domain = null; - } - this.remove("test_rudder"); - } - /** - * - * @param {*} key - * @param {*} value - */ + exports.parse = function (source, callback) { + var result, value; + Index = 0; + Source = "" + source; + result = get(lex()); // If a JSON string contains multiple tokens, it is invalid. - }, { - key: "set", - value: function set(key, value) { - try { - rudderComponentCookie(key, value, clone_1(this._options)); - return true; - } catch (e) { - logger.error(e); - return false; - } - } - /** - * - * @param {*} key - */ + if (lex() != "$") { + abort(); + } // Reset the parser state. - }, { - key: "get", - value: function get(key) { - return rudderComponentCookie(key); - } - /** - * - * @param {*} key - */ - }, { - key: "remove", - value: function remove(key) { - try { - rudderComponentCookie(key, null, clone_1(this._options)); - return true; - } catch (e) { - return false; + Index = Source = null; + return callback && getClass.call(callback) == functionClass ? walk((value = {}, value[""] = result, value), "", callback) : result; + }; + } } - } - }]); - return CookieLocal; - }(); // Exporting only the instance + exports.runInContext = runInContext; + return exports; + } + if (freeExports && !isLoader) { + // Export for CommonJS environments. + runInContext(root, freeExports); + } else { + // Export for web browsers and JavaScript engines. + var nativeJSON = root.JSON, + previousJSON = root.JSON3, + isRestored = false; + var JSON3 = runInContext(root, root.JSON3 = { + // Public: Restores the original value of the global `JSON` object and + // returns a reference to the `JSON3` object. + "noConflict": function noConflict() { + if (!isRestored) { + isRestored = true; + root.JSON = nativeJSON; + root.JSON3 = previousJSON; + nativeJSON = previousJSON = null; + } - var Cookie = new CookieLocal({}); + return JSON3; + } + }); + root.JSON = { + "parse": JSON3.parse, + "stringify": JSON3.stringify + }; + } // Export for asynchronous module loaders. + }).call(commonjsGlobal); + }); var store = function () { // Store.js @@ -13987,13 +14113,13 @@ var Store = new StoreLocal({}); var defaults$1 = { - user_storage_key: "rl_user_id", - user_storage_trait: "rl_trait", - user_storage_anonymousId: "rl_anonymous_id", - group_storage_key: "rl_group_id", - group_storage_trait: "rl_group_trait", - prefix: "RudderEncrypt:", - key: "Rudder" + user_storage_key: "session_user_id", + user_storage_trait: "session_trait", + user_storage_anonymousId: "session_anonymous_id", + group_storage_key: "session_group_id", + group_storage_trait: "session_group_trait", + prefix: "LF:", + key: "Landfolk" }; /** * An object that handles persisting key-val from Analytics @@ -14004,10 +14130,10 @@ _classCallCheck(this, Storage); // First try setting the storage to cookie else to localstorage - Cookie.set("rudder_cookies", true); + Cookie.set("landfolk_insights", true); - if (Cookie.get("rudder_cookies")) { - Cookie.remove("rudder_cookies"); + if (Cookie.get("landfolk_insights")) { + Cookie.remove("landfolk_insights"); this.storage = Cookie; return; } // localStorage is enabled. @@ -17796,53 +17922,224 @@ */ - debug$2.humanize = function (ms) { - var sec = 1000, - min = 60 * 1000, - hour = 60 * min; - if (ms >= hour) return (ms / hour).toFixed(1) + 'h'; - if (ms >= min) return (ms / min).toFixed(1) + 'm'; - if (ms >= sec) return (ms / sec | 0) + 's'; - return ms + 'ms'; - }; - /** - * Returns true if the given mode name is enabled, false otherwise. - * - * @param {String} name - * @return {Boolean} - * @api public - */ + debug$2.humanize = function (ms) { + var sec = 1000, + min = 60 * 1000, + hour = 60 * min; + if (ms >= hour) return (ms / hour).toFixed(1) + 'h'; + if (ms >= min) return (ms / min).toFixed(1) + 'm'; + if (ms >= sec) return (ms / sec | 0) + 's'; + return ms + 'ms'; + }; + /** + * Returns true if the given mode name is enabled, false otherwise. + * + * @param {String} name + * @return {Boolean} + * @api public + */ + + + debug$2.enabled = function (name) { + for (var i = 0, len = debug$2.skips.length; i < len; i++) { + if (debug$2.skips[i].test(name)) { + return false; + } + } + + for (var i = 0, len = debug$2.names.length; i < len; i++) { + if (debug$2.names[i].test(name)) { + return true; + } + } + + return false; + }; + /** + * Coerce `val`. + */ + + + function coerce(val) { + if (val instanceof Error) return val.stack || val.message; + return val; + } // persist + + + try { + if (window.localStorage) debug$2.enable(localStorage.debug); + } catch (e) {} + + var componentEmitter$1 = createCommonjsModule(function (module) { + /** + * Expose `Emitter`. + */ + { + module.exports = Emitter; + } + /** + * Initialize a new `Emitter`. + * + * @api public + */ + + + function Emitter(obj) { + if (obj) return mixin(obj); + } + /** + * Mixin the emitter properties. + * + * @param {Object} obj + * @return {Object} + * @api private + */ + + function mixin(obj) { + for (var key in Emitter.prototype) { + obj[key] = Emitter.prototype[key]; + } + + return obj; + } + /** + * Listen on the given `event` with `fn`. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + + + Emitter.prototype.on = Emitter.prototype.addEventListener = function (event, fn) { + this._callbacks = this._callbacks || {}; + (this._callbacks['$' + event] = this._callbacks['$' + event] || []).push(fn); + return this; + }; + /** + * Adds an `event` listener that will be invoked a single + * time then automatically removed. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + + + Emitter.prototype.once = function (event, fn) { + function on() { + this.off(event, on); + fn.apply(this, arguments); + } + + on.fn = fn; + this.on(event, on); + return this; + }; + /** + * Remove the given callback for `event` or all + * registered callbacks. + * + * @param {String} event + * @param {Function} fn + * @return {Emitter} + * @api public + */ + + + Emitter.prototype.off = Emitter.prototype.removeListener = Emitter.prototype.removeAllListeners = Emitter.prototype.removeEventListener = function (event, fn) { + this._callbacks = this._callbacks || {}; // all + + if (0 == arguments.length) { + this._callbacks = {}; + return this; + } // specific event + + + var callbacks = this._callbacks['$' + event]; + if (!callbacks) return this; // remove all handlers + + if (1 == arguments.length) { + delete this._callbacks['$' + event]; + return this; + } // remove specific handler + + + var cb; + + for (var i = 0; i < callbacks.length; i++) { + cb = callbacks[i]; + + if (cb === fn || cb.fn === fn) { + callbacks.splice(i, 1); + break; + } + } // Remove event specific arrays for event types that no + // one is subscribed for to avoid memory leak. + + + if (callbacks.length === 0) { + delete this._callbacks['$' + event]; + } + + return this; + }; + /** + * Emit `event` with the given args. + * + * @param {String} event + * @param {Mixed} ... + * @return {Emitter} + */ + + Emitter.prototype.emit = function (event) { + this._callbacks = this._callbacks || {}; + var args = new Array(arguments.length - 1), + callbacks = this._callbacks['$' + event]; - debug$2.enabled = function (name) { - for (var i = 0, len = debug$2.skips.length; i < len; i++) { - if (debug$2.skips[i].test(name)) { - return false; + for (var i = 1; i < arguments.length; i++) { + args[i - 1] = arguments[i]; } - } - for (var i = 0, len = debug$2.names.length; i < len; i++) { - if (debug$2.names[i].test(name)) { - return true; + if (callbacks) { + callbacks = callbacks.slice(0); + + for (var i = 0, len = callbacks.length; i < len; ++i) { + callbacks[i].apply(this, args); + } } - } - return false; - }; - /** - * Coerce `val`. - */ + return this; + }; + /** + * Return array of callbacks for `event`. + * + * @param {String} event + * @return {Array} + * @api public + */ - function coerce(val) { - if (val instanceof Error) return val.stack || val.message; - return val; - } // persist + Emitter.prototype.listeners = function (event) { + this._callbacks = this._callbacks || {}; + return this._callbacks['$' + event] || []; + }; + /** + * Check if this emitter has `event` handlers. + * + * @param {String} event + * @return {Boolean} + * @api public + */ - try { - if (window.localStorage) debug$2.enable(localStorage.debug); - } catch (e) {} + Emitter.prototype.hasListeners = function (event) { + return !!this.listeners(event).length; + }; + }); var require$$0 = getCjsExportFromNamespace(dist); @@ -17918,7 +18215,7 @@ */ - componentEmitter(Queue.prototype); + componentEmitter$1(Queue.prototype); /** * Starts processing the queue */ @@ -18405,387 +18702,7 @@ var eventRepository = new EventRepository(); function addDomEventHandlers(rudderanalytics) { - var handler = function handler(e) { - e = e || window.event; - var target = e.target || e.srcElement; - - if (isTextNode(target)) { - target = target.parentNode; - } - - if (shouldTrackDomEvent(target, e)) { - logger.debug("to be tracked ", e.type); - } else { - logger.debug("not to be tracked ", e.type); - } - - trackWindowEvent(e, rudderanalytics); - }; - - register_event(document, "submit", handler, true); - register_event(document, "change", handler, true); - register_event(document, "click", handler, true); - rudderanalytics.page(); - } - - function register_event(element, type, handler, useCapture) { - if (!element) { - logger.error("[Autotrack] register_event:: No valid element provided to register_event"); - return; - } - - element.addEventListener(type, handler, !!useCapture); - } - - function shouldTrackDomEvent(el, event) { - if (!el || isTag(el, "html") || !isElementNode(el)) { - return false; - } - - var tag = el.tagName.toLowerCase(); - - switch (tag) { - case "html": - return false; - - case "form": - return event.type === "submit"; - - case "input": - if (["button", "submit"].indexOf(el.getAttribute("type")) === -1) { - return event.type === "change"; - } - - return event.type === "click"; - - case "select": - case "textarea": - return event.type === "change"; - - default: - return event.type === "click"; - } - } - - function isTag(el, tag) { - return el && el.tagName && el.tagName.toLowerCase() === tag.toLowerCase(); - } - - function isElementNode(el) { - return el && el.nodeType === 1; // Node.ELEMENT_NODE - use integer constant for browser portability - } - - function isTextNode(el) { - return el && el.nodeType === 3; // Node.TEXT_NODE - use integer constant for browser portability - } // excerpt from https://github.com/mixpanel/mixpanel-js/blob/master/src/autotrack-utils.js - - - function shouldTrackElement(el) { - if (!el.parentNode || isTag(el, "body")) return false; - var curEl = el; - - while (curEl.parentNode && !isTag(curEl, "body")) { - var _classes = getClassName(el).split(" "); // if explicitly specified "rudder-no-track", even at parent level, dont track the child nodes too. - - - if (_classes.indexOf("rudder-no-track") >= 0) { - return false; - } - - curEl = curEl.parentNode; - } // if explicitly set "rudder-include", at element level, then track the element even if the element is hidden or sensitive. - - - var classes = getClassName(el).split(" "); - - if (classes.indexOf("rudder-include") >= 0) { - return true; - } // for general elements, do not track input/select/textarea(s) - - - if (isTag(el, "input") || isTag(el, "select") || isTag(el, "textarea") || el.getAttribute("contenteditable") === "true") { - return false; - } else if (el.getAttribute("contenteditable") === "inherit") { - for (curEl = el.parentNode; curEl.parentNode && !isTag(curEl, "body"); curEl = curEl.parentNode) { - if (curEl.getAttribute("contenteditable") === "true") { - return false; - } - } - } // do not track hidden/password elements - - - var type = el.type || ""; - - if (typeof type === "string") { - // it's possible for el.type to be a DOM element if el is a form with a child input[name="type"] - switch (type.toLowerCase()) { - case "hidden": - return false; - - case "password": - return false; - } - } // filter out data from fields that look like sensitive field - - // safeguard - match with regex with possible strings as id or name of an element for creditcard, password, ssn, pan, adhar - - - var name = el.name || el.id || ""; - - if (typeof name === "string") { - // it's possible for el.name or el.id to be a DOM element if el is a form with a child input[name="name"] - var sensitiveNameRegex = /^adhar|cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pan|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i; - - if (sensitiveNameRegex.test(name.replace(/[^a-zA-Z0-9]/g, ""))) { - return false; - } - } - - return true; - } - - function getClassName(el) { - switch (_typeof(el.className)) { - case "string": - return el.className; - - case "object": - // handle cases where className might be SVGAnimatedString or some other type - return el.className.baseVal || el.getAttribute("class") || ""; - - default: - // future proof - return ""; - } - } - - function trackWindowEvent(e, rudderanalytics) { - var target = e.target || e.srcElement; - var formValues; - - if (isTextNode(target)) { - target = target.parentNode; - } - - if (shouldTrackDomEvent(target, e)) { - if (target.tagName.toLowerCase() == "form") { - formValues = {}; - - for (var i = 0; i < target.elements.length; i++) { - var formElement = target.elements[i]; - - if (shouldTrackElement(formElement) && isValueToBeTrackedFromTrackingList(formElement, rudderanalytics.trackValues)) { - var name = formElement.id ? formElement.id : formElement.name; - - if (name && typeof name === "string") { - var key = formElement.id ? formElement.id : formElement.name; // formElement.value gives the same thing - - var value = formElement.id ? document.getElementById(formElement.id).value : document.getElementsByName(formElement.name)[0].value; - - if (formElement.type === "checkbox" || formElement.type === "radio") { - value = formElement.checked; - } - - if (key.trim() !== "") { - formValues[encodeURIComponent(key)] = encodeURIComponent(value); - } - } - } - } - } - - var targetElementList = []; - var curEl = target; - - if (isExplicitNoTrack(curEl)) { - return false; - } - - while (curEl.parentNode && !isTag(curEl, "body")) { - if (shouldTrackElement(curEl)) { - targetElementList.push(curEl); - } - - curEl = curEl.parentNode; - } - - var elementsJson = []; - var href; - targetElementList.forEach(function (el) { - // if the element or a parent element is an anchor tag - // include the href as a property - if (el.tagName.toLowerCase() === "a") { - href = el.getAttribute("href"); - href = isValueToBeTracked(href) && href; - } - - elementsJson.push(getPropertiesFromElement(el, rudderanalytics)); - }); - - if (targetElementList && targetElementList.length == 0) { - return false; - } - - var elementText = ""; - var text = getText(target); - - if (text && text.length) { - elementText = text; - } - - var props = { - event_type: e.type, - page: getDefaultPageProperties(), - elements: elementsJson, - el_attr_href: href, - el_text: elementText - }; - - if (formValues) { - props.form_values = formValues; - } - - logger.debug("web_event", props); - rudderanalytics.track("autotrack", props); - return true; - } - } - - function isExplicitNoTrack(el) { - var classes = getClassName(el).split(" "); - - if (classes.indexOf("rudder-no-track") >= 0) { - return true; - } - - return false; - } // excerpt from https://github.com/mixpanel/mixpanel-js/blob/master/src/autotrack-utils.js - - - function isValueToBeTracked(value) { - if (value === null || value === undefined) { - return false; - } - - if (typeof value === "string") { - value = value.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ""); // check to see if input value looks like a credit card number - // see: https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9781449327453/ch04s20.html - - var ccRegex = /^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/; - - if (ccRegex.test((value || "").replace(/[- ]/g, ""))) { - return false; - } // check to see if input value looks like a social security number - - - var ssnRegex = /(^\d{3}-?\d{2}-?\d{4}$)/; - - if (ssnRegex.test(value)) { - return false; - } // check to see if input value looks like a adhar number - - - var adharRegex = /(^\d{4}-?\d{4}-?\d{4}$)/; - - if (adharRegex.test(value)) { - return false; - } // check to see if input value looks like a PAN number - - - var panRegex = /(^\w{5}-?\d{4}-?\w{1}$)/; - - if (panRegex.test(value)) { - return false; - } - } - - return true; - } // if the element name is provided in the valTrackingList while loading rudderanalytics, track the value. - - /** - * - * @param {*} el - * @param {*} includeList - valTrackingList provided in rudderanalytics.load() - */ - - - function isValueToBeTrackedFromTrackingList(el, includeList) { - var elAttributesLength = el.attributes.length; - - for (var i = 0; i < elAttributesLength; i++) { - var value = el.attributes[i].value; - - if (includeList.indexOf(value) > -1) { - return true; - } - } - - return false; - } - - function getText(el) { - var text = ""; - el.childNodes.forEach(function (value) { - if (value.nodeType === Node.TEXT_NODE) { - var textContent = value.nodeValue.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ""); // take each word from the text content and check whether the value should be tracked. Also, replace the whitespaces. - - var textValue = textContent.split(/(\s+)/).filter(isValueToBeTracked).join("").replace(/[\r\n]/g, " "); - text += textValue; - } - }); - return text.trim(); - } - - function getPropertiesFromElement(elem, rudderanalytics) { - var props = { - classes: getClassName(elem).split(" "), - tag_name: elem.tagName.toLowerCase() - }; - var attrLength = elem.attributes.length; - - for (var i = 0; i < attrLength; i++) { - var name = elem.attributes[i].name; - var value = elem.attributes[i].value; - - if (value && isValueToBeTracked(value)) { - props["attr__".concat(name)] = value; - } - - if ((name == "name" || name == "id") && isValueToBeTrackedFromTrackingList(elem, rudderanalytics.trackValues)) { - props.field_value = name == "id" ? document.getElementById(value).value : document.getElementsByName(value)[0].value; - - if (elem.type === "checkbox" || elem.type === "radio") { - props.field_value = elem.checked; - } - } - } - - var nthChild = 1; - var nthOfType = 1; - var currentElem = elem; - - while (currentElem = previousElementSibling(currentElem)) { - nthChild++; - - if (currentElem.tagName === elem.tagName) { - nthOfType++; - } - } - - props.nth_child = nthChild; - props.nth_of_type = nthOfType; - return props; - } - - function previousElementSibling(el) { - if (el.previousElementSibling) { - return el.previousElementSibling; - } - - do { - el = el.previousSibling; - } while (el && !isElementNode(el)); - - return el; + logger.error("[AutoTrack]: This functionality has been moved to a different deployment"); } /** @@ -19155,7 +19072,7 @@ logger.debug("autoTrackHandlersRegistered", this.autoTrackHandlersRegistered); if (this.autoTrackFeatureEnabled && !this.autoTrackHandlersRegistered) { - addDomEventHandlers(this); + addDomEventHandlers(); this.autoTrackHandlersRegistered = true; } } @@ -19871,7 +19788,7 @@ this.autoTrackFeatureEnabled = true; if (this.autoTrackFeatureEnabled && !this.autoTrackHandlersRegistered) { - addDomEventHandlers(this); + addDomEventHandlers(); this.autoTrackHandlersRegistered = true; logger.debug("autoTrackHandlersRegistered", this.autoTrackHandlersRegistered); } @@ -19883,7 +19800,7 @@ handleError(error); if (this.autoTrackFeatureEnabled && !this.autoTrackHandlersRegistered) { - addDomEventHandlers(this); + addDomEventHandlers(); } } diff --git a/package.json b/package.json index 12cdf7572..3ff0a14e3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "rudder-analytics", "version": "1.1.11", "description": "", - "main": "./dist/browser.min.js", + "main": "dist/rudder-analytics.min.js", "size-limit": [ { "path": "dist/rudder-analytics.min.js",