UNPKG

rollbar

Version:

Effortlessly track and debug errors in your JavaScript applications with Rollbar. This package includes advanced error tracking features and an intuitive interface to help you identify and fix issues more quickly.

1,476 lines (1,442 loc) 294 kB
/******/ (function() { // webpackBootstrap /******/ "use strict"; /******/ // The require scope /******/ var __webpack_require__ = {}; /******/ /************************************************************************/ /******/ /* webpack/runtime/define property getters */ /******/ !function() { /******/ // define getter functions for harmony exports /******/ __webpack_require__.d = function(exports, definition) { /******/ for(var key in definition) { /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ }(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ !function() { /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } /******/ }(); /******/ /******/ /* webpack/runtime/make namespace object */ /******/ !function() { /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ }(); /******/ /************************************************************************/ // UNUSED EXPORTS: default // NAMESPACE OBJECT: ./src/browser/url.js var url_namespaceObject = {}; __webpack_require__.r(url_namespaceObject); __webpack_require__.d(url_namespaceObject, { parse: function() { return url_parse; } }); ;// ./src/utility.js function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } /* * isType - Given a Javascript value and a string, returns true if the type of the value matches the * given string. * * @param x - any value * @param t - a lowercase string containing one of the following type names: * - undefined * - null * - error * - number * - boolean * - string * - symbol * - function * - object * - array * @returns true if x is of type t, otherwise false */ function isType(x, t) { return t === typeName(x); } /* * typeName - Given a Javascript value, returns the type of the object as a string */ function typeName(x) { var name = _typeof(x); if (name !== 'object') { return name; } if (!x) { return 'null'; } if (x instanceof Error) { return 'error'; } return {}.toString.call(x).match(/\s([a-zA-Z]+)/)[1].toLowerCase(); } /* isFunction - a convenience function for checking if a value is a function * * @param f - any value * @returns true if f is a function, otherwise false */ function isFunction(f) { return isType(f, 'function'); } /* isNativeFunction - a convenience function for checking if a value is a native JS function * * @param f - any value * @returns true if f is a native JS function, otherwise false */ function isNativeFunction(f) { var reRegExpChar = /[\\^$.*+?()[\]{}|]/g; var funcMatchString = Function.prototype.toString.call(Object.prototype.hasOwnProperty).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?'); var reIsNative = RegExp('^' + funcMatchString + '$'); return isObject(f) && reIsNative.test(f); } /* isObject - Checks if the argument is an object * * @param value - any value * @returns true is value is an object function is an object) */ function isObject(value) { return value != null && (_typeof(value) == 'object' || typeof value == 'function'); } /* hasOwn - safe helper around Object.hasOwnProperty */ function hasOwn(obj, prop) { if (obj == null) { return false; } if (Object.hasOwn) { return Object.hasOwn(obj, prop); } return Object.prototype.hasOwnProperty.call(obj, prop); } /* isString - Checks if the argument is a string * * @param value - any value * @returns true if value is a string */ function isString(value) { return typeof value === 'string' || value instanceof String; } /** * isFiniteNumber - determines whether the passed value is a finite number * * @param {*} n - any value * @returns true if value is a finite number */ function isFiniteNumber(n) { return Number.isFinite(n); } /* * isIterable - convenience function for checking if a value can be iterated, essentially * whether it is an object or an array. * * @param i - any value * @returns true if i is an object or an array as determined by `typeName` */ function isIterable(i) { var type = typeName(i); return type === 'object' || type === 'array'; } /* * isError - convenience function for checking if a value is of an error type * * @param e - any value * @returns true if e is an error */ function isError(e) { // Detect both Error and Firefox Exception type return isType(e, 'error') || isType(e, 'exception'); } /* isPromise - a convenience function for checking if a value is a promise * * @param p - any value * @returns true if f is a function, otherwise false */ function isPromise(p) { return isObject(p) && isType(p.then, 'function'); } /** * isBrowser - a convenience function for checking if the code is running in a browser * * @returns true if the code is running in a browser environment */ function isBrowser() { return typeof window !== 'undefined'; } function isRequestObject(input) { return typeof Request !== 'undefined' && input instanceof Request; } function redact() { return '********'; } // from http://stackoverflow.com/a/8809472/1138191 function uuid4() { var d = now(); var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = (d + Math.random() * 16) % 16 | 0; d = Math.floor(d / 16); return (c === 'x' ? r : r & 0x7 | 0x8).toString(16); }); return uuid; } var LEVELS = { debug: 0, info: 1, warning: 2, error: 3, critical: 4 }; function sanitizeHref(url) { try { var urlObject = new URL(url); if (urlObject.password) { urlObject.password = redact(); } if (urlObject.search) { urlObject.search = redact(); } return urlObject.toString(); } catch (_) { return url; // Return original URL if parsing fails } } function sanitizeUrl(url) { var baseUrlParts = parseUri(url); if (!baseUrlParts) { return '(unknown)'; } // remove a trailing # if there is no anchor if (baseUrlParts.anchor === '') { baseUrlParts.source = baseUrlParts.source.replace('#', ''); } url = baseUrlParts.source.replace('?' + baseUrlParts.query, ''); return url; } var parseUriOptions = { strictMode: false, key: ['source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'], q: { name: 'queryKey', parser: /(?:^|&)([^&=]*)=?([^&]*)/g }, parser: { strict: /^(?:([^:/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:/?#]*)(?::(\d*))?))?((((?:[^?#/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, loose: /^(?:(?![^:@]+:[^:@/]*@)([^:/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#/]*\.[^?#/.]+(?:[?#]|$)))*\/?)?([^?#/]*))(?:\?([^#]*))?(?:#(.*))?)/ } }; function parseUri(str) { if (!isType(str, 'string')) { return undefined; } var o = parseUriOptions; var m = o.parser[o.strictMode ? 'strict' : 'loose'].exec(str); var uri = {}; for (var i = 0, l = o.key.length; i < l; ++i) { uri[o.key[i]] = m[i] || ''; } uri[o.q.name] = {}; uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) { if ($1) { uri[o.q.name][$1] = $2; } }); return uri; } function addParamsAndAccessTokenToPath(accessToken, options, params) { params = params || {}; params.access_token = accessToken; var paramsArray = []; var k; for (k in params) { if (Object.prototype.hasOwnProperty.call(params, k)) { paramsArray.push([k, params[k]].join('=')); } } var query = '?' + paramsArray.sort().join('&'); options = options || {}; options.path = options.path || ''; var qs = options.path.indexOf('?'); var h = options.path.indexOf('#'); var p; if (qs !== -1 && (h === -1 || h > qs)) { p = options.path; options.path = p.substring(0, qs) + query + '&' + p.substring(qs + 1); } else { if (h !== -1) { p = options.path; options.path = p.substring(0, h) + query + p.substring(h); } else { options.path = options.path + query; } } } function formatUrl(u, protocol) { protocol = protocol || u.protocol; if (!protocol && u.port) { if (u.port === 80) { protocol = 'http:'; } else if (u.port === 443) { protocol = 'https:'; } } protocol = protocol || 'https:'; if (!u.hostname) { return null; } var result = protocol + '//' + u.hostname; if (u.port) { result = result + ':' + u.port; } if (u.path) { result = result + u.path; } return result; } function stringify(obj, backup) { var value, error; try { value = JSON.stringify(obj); } catch (jsonError) { if (backup && isFunction(backup)) { try { value = backup(obj); } catch (backupError) { error = backupError; } } else { error = jsonError; } } return { error: error, value: value }; } function maxByteSize(string) { // The transport will use utf-8, so assume utf-8 encoding. // // This minimal implementation will accurately count bytes for all UCS-2 and // single code point UTF-16. If presented with multi code point UTF-16, // which should be rare, it will safely overcount, not undercount. // // While robust utf-8 encoders exist, this is far smaller and far more performant. // For quickly counting payload size for truncation, smaller is better. var count = 0; var length = string.length; for (var i = 0; i < length; i++) { var code = string.charCodeAt(i); if (code < 128) { // up to 7 bits count = count + 1; } else if (code < 2048) { // up to 11 bits count = count + 2; } else if (code < 65536) { // up to 16 bits count = count + 3; } } return count; } function jsonParse(s) { var value, error; try { value = JSON.parse(s); } catch (e) { error = e; } return { error: error, value: value }; } function makeUnhandledStackInfo(message, url, lineno, colno, error, mode, backupMessage, errorParser) { var location = { url: url || '', line: lineno, column: colno }; location.func = errorParser.guessFunctionName(location.url, location.line); location.context = errorParser.gatherContext(location.url, location.line); var href = typeof document !== 'undefined' && document && document.location && document.location.href; var useragent = typeof window !== 'undefined' && window && window.navigator && window.navigator.userAgent; return { mode: mode, message: error ? String(error) : message || backupMessage, url: href, stack: [location], useragent: useragent }; } function wrapCallback(logger, f) { return function (err, resp) { try { f(err, resp); } catch (e) { logger.error(e); } }; } function nonCircularClone(obj) { var seen = [obj]; function clone(obj, seen) { var value, name, newSeen, result = {}; try { for (name in obj) { value = obj[name]; if (value && (isType(value, 'object') || isType(value, 'array'))) { if (seen.includes(value)) { result[name] = 'Removed circular reference: ' + typeName(value); } else { newSeen = seen.slice(); newSeen.push(value); result[name] = clone(value, newSeen); } continue; } result[name] = value; } } catch (e) { result = 'Failed cloning custom data: ' + e.message; } return result; } return clone(obj, seen); } function createItem(args, logger, notifier, requestKeys, lambdaContext) { var message, err, custom, callback, request; var arg; var extraArgs = []; var diagnostic = {}; var argTypes = []; for (var i = 0, l = args.length; i < l; ++i) { arg = args[i]; var typ = typeName(arg); argTypes.push(typ); switch (typ) { case 'undefined': break; case 'string': if (message) { extraArgs.push(arg); } else { message = arg; } break; case 'function': callback = wrapCallback(logger, arg); break; case 'date': extraArgs.push(arg); break; case 'error': case 'domexception': case 'exception': // Firefox Exception type if (err) { extraArgs.push(arg); } else { err = arg; } break; case 'object': case 'array': if (arg instanceof Error || typeof DOMException !== 'undefined' && arg instanceof DOMException) { if (err) { extraArgs.push(arg); } else { err = arg; } break; } if (requestKeys && typ === 'object' && !request) { for (var j = 0, len = requestKeys.length; j < len; ++j) { if (arg[requestKeys[j]] !== undefined) { request = arg; break; } } if (request) { break; } } if (custom) { extraArgs.push(arg); } else { custom = arg; } break; default: if (arg instanceof Error || typeof DOMException !== 'undefined' && arg instanceof DOMException) { if (err) { extraArgs.push(arg); } else { err = arg; } break; } extraArgs.push(arg); } } // if custom is an array this turns it into an object with integer keys if (custom) custom = nonCircularClone(custom); if (extraArgs.length > 0) { if (!custom) custom = nonCircularClone({}); custom.extraArgs = nonCircularClone(extraArgs); } var item = { message: message, err: err, custom: custom, timestamp: now(), callback: callback, notifier: notifier, diagnostic: diagnostic, uuid: uuid4() }; item.data = item.data || {}; setCustomItemKeys(item, custom); if (requestKeys && request) { item.request = request; } if (lambdaContext) { item.lambdaContext = lambdaContext; } item._originalArgs = args; item.diagnostic.original_arg_types = argTypes; return item; } function setCustomItemKeys(item, custom) { if (custom && custom.level !== undefined) { item.level = custom.level; delete custom.level; } if (custom && custom.skipFrames !== undefined) { item.skipFrames = custom.skipFrames; delete custom.skipFrames; } } function addErrorContext(item, errors) { var custom = item.data.custom || {}; var contextAdded = false; try { var _iterator = _createForOfIteratorHelper(errors), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var error = _step.value; if (hasOwn(error, 'rollbarContext')) { custom = merge(custom, nonCircularClone(error.rollbarContext)); contextAdded = true; } } // Avoid adding an empty object to the data. } catch (err) { _iterator.e(err); } finally { _iterator.f(); } if (contextAdded) { item.data.custom = custom; } } catch (e) { item.diagnostic.error_context = 'Failed: ' + e.message; } } var TELEMETRY_TYPES = ['log', 'network', 'dom', 'navigation', 'error', 'manual']; var TELEMETRY_LEVELS = ['critical', 'error', 'warning', 'info', 'debug']; function arrayIncludes(arr, val) { var _iterator2 = _createForOfIteratorHelper(arr), _step2; try { for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { var entry = _step2.value; if (entry === val) { return true; } } } catch (err) { _iterator2.e(err); } finally { _iterator2.f(); } return false; } function createTelemetryEvent(args) { var type, metadata, level; var arg; for (var i = 0, l = args.length; i < l; ++i) { arg = args[i]; var typ = typeName(arg); switch (typ) { case 'string': if (!type && arrayIncludes(TELEMETRY_TYPES, arg)) { type = arg; } else if (!level && arrayIncludes(TELEMETRY_LEVELS, arg)) { level = arg; } break; case 'object': metadata = arg; break; default: break; } } var event = { type: type || 'manual', metadata: metadata || {}, level: level }; return event; } function addItemAttributes(itemData, attributes) { itemData.attributes = itemData.attributes || []; var _iterator3 = _createForOfIteratorHelper(attributes), _step3; try { for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { var a = _step3.value; if (a.value === undefined) { continue; } itemData.attributes.push(a); } } catch (err) { _iterator3.e(err); } finally { _iterator3.f(); } } /* * get - given an obj/array and a keypath, return the value at that keypath or * undefined if not possible. * * @param obj - an object or array * @param path - a string of keys separated by '.' such as 'plugin.jquery.0.message' * which would correspond to 42 in `{plugin: {jquery: [{message: 42}]}}` */ function get(obj, path) { if (!obj) { return undefined; } var keys = path.split('.'); var result = obj; try { for (var i = 0, len = keys.length; i < len; ++i) { result = result[keys[i]]; } } catch (_e) { result = undefined; } return result; } function set(obj, path, value) { if (!obj) { return; } // Prevent prototype pollution by setting the prototype to null. Object.setPrototypeOf(obj, null); var keys = path.split('.'); var len = keys.length; if (len < 1) { return; } if (len === 1) { obj[keys[0]] = value; return; } try { var temp = obj[keys[0]] || {}; var replacement = temp; for (var i = 1; i < len - 1; ++i) { temp[keys[i]] = temp[keys[i]] || {}; temp = temp[keys[i]]; } temp[keys[len - 1]] = value; obj[keys[0]] = replacement; } catch (_e) { return; } } function formatArgsAsString(args) { var i, len, arg; var result = []; for (i = 0, len = args.length; i < len; ++i) { arg = args[i]; switch (typeName(arg)) { case 'object': arg = stringify(arg); arg = arg.error || arg.value; if (arg.length > 500) { arg = arg.substr(0, 497) + '...'; } break; case 'null': arg = 'null'; break; case 'undefined': arg = 'undefined'; break; case 'symbol': arg = arg.toString(); break; } result.push(arg); } return result.join(' '); } function now() { if (Date.now) { return Date.now(); } return Number(new Date()); } function filterIp(requestData, captureIp) { if (!requestData || !requestData['user_ip'] || captureIp === true) { return; } var newIp = requestData['user_ip']; if (!captureIp) { newIp = null; } else { try { var parts; if (newIp.indexOf('.') !== -1) { parts = newIp.split('.'); parts.pop(); parts.push('0'); newIp = parts.join('.'); } else if (newIp.indexOf(':') !== -1) { parts = newIp.split(':'); if (parts.length > 2) { var beginning = parts.slice(0, 3); var slashIdx = beginning[2].indexOf('/'); if (slashIdx !== -1) { beginning[2] = beginning[2].substring(0, slashIdx); } var terminal = '0000:0000:0000:0000:0000'; newIp = beginning.concat(terminal).join(':'); } } else { newIp = null; } } catch (_e) { newIp = null; } } requestData['user_ip'] = newIp; } function handleOptions(current, input, payload, logger) { var result = merge(current, input, payload); result = updateDeprecatedOptions(result, logger); if (!input || input.overwriteScrubFields) { return result; } if (input.scrubFields) { result.scrubFields = (current.scrubFields || []).concat(input.scrubFields); } return result; } function updateDeprecatedOptions(options, logger) { if (options.hostWhiteList && !options.hostSafeList) { options.hostSafeList = options.hostWhiteList; options.hostWhiteList = undefined; logger && logger.log('hostWhiteList is deprecated. Use hostSafeList.'); } if (options.hostBlackList && !options.hostBlockList) { options.hostBlockList = options.hostBlackList; options.hostBlackList = undefined; logger && logger.log('hostBlackList is deprecated. Use hostBlockList.'); } return options; } function merge() { function isPlainObject(obj) { if (!obj || Object.prototype.toString.call(obj) !== '[object Object]') { return false; } var hasOwnConstructor = hasOwn(obj, 'constructor'); var hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn(obj.constructor.prototype, 'isPrototypeOf'); // Not own constructor property must be Object if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) { return false; } // Own properties are enumerated firstly, so to speed up, // if last one is own, then all properties are own. var key; for (key in obj) { /**/ } return typeof key === 'undefined' || hasOwn(obj, key); } var i, src, copy, clone, name, result = Object.create(null), // no prototype pollution on Object current = null, length = arguments.length; for (i = 0; i < length; i++) { current = arguments[i]; if (current === null || current === undefined) { continue; } for (name in current) { src = result[name]; copy = current[name]; if (result !== copy) { if (copy && isPlainObject(copy)) { clone = src && isPlainObject(src) ? src : {}; result[name] = merge(clone, copy); } else if (typeof copy !== 'undefined') { result[name] = copy; } } } } return result; } function shouldAddBaggageHeader(options, tracing, url) { var _options$tracing; if (!(tracing !== null && tracing !== void 0 && tracing.sessionId) || !url) { return false; } var propagation = options === null || options === void 0 || (_options$tracing = options.tracing) === null || _options$tracing === void 0 ? void 0 : _options$tracing.propagation; var enabledHeaders = propagation === null || propagation === void 0 ? void 0 : propagation.enabledHeaders; if (!Array.isArray(enabledHeaders) || !enabledHeaders.includes('baggage')) { return false; } var enabledCorsUrls = propagation === null || propagation === void 0 ? void 0 : propagation.enabledCorsUrls; if (!Array.isArray(enabledCorsUrls) || enabledCorsUrls.length === 0) { return false; } return enabledCorsUrls.some(function (pattern) { if (isType(pattern, 'string')) { return url === pattern; } if (isType(pattern, 'regexp')) { return pattern.test(url); } return false; }); } function addHeadersToFetch(args, newHeaders) { var _init; // Headers may be in the request object or the init object. // If present in both places, the init object must be used. // var init = args[1]; var initHeaders = (_init = init) === null || _init === void 0 ? void 0 : _init.headers; var reqHeaders = isRequestObject(args[0]) && args[0].headers; var headers = initHeaders || reqHeaders; // If headers are not present in either place, they are added to the init object. // If there is no init object, one must be created and added to args. if (!headers) { if (!init) { args[1] = init = {}; } headers = init.headers = {}; } // `headers` may be a Headers object or a plain object. if (headers instanceof Headers) { for (var _i = 0, _Object$keys = Object.keys(newHeaders); _i < _Object$keys.length; _i++) { var key = _Object$keys[_i]; headers.append(key, newHeaders[key]); } } else if (isObject(headers)) { for (var _i2 = 0, _Object$keys2 = Object.keys(newHeaders); _i2 < _Object$keys2.length; _i2++) { var _key = _Object$keys2[_i2]; headers[_key] = newHeaders[_key]; } } } function getSessionIdFromAsyncLocalStorage(client) { var storage = client.asyncLocalStorage; if (!storage || typeof storage.getStore !== 'function') { return null; } var store = storage.getStore(); return (store === null || store === void 0 ? void 0 : store.sessionId) || null; } ;// ./src/utility/traverse.js function traverse(obj, func, seen) { var k, v, i; var isObj = isType(obj, 'object'); var isArray = isType(obj, 'array'); var keys = []; var seenIndex; // Best might be to use Map here with `obj` as the keys, but we want to support IE < 11. seen = seen || { obj: [], mapped: [] }; if (isObj) { seenIndex = seen.obj.indexOf(obj); if (isObj && seenIndex !== -1) { // Prefer the mapped object if there is one. return seen.mapped[seenIndex] || seen.obj[seenIndex]; } seen.obj.push(obj); seenIndex = seen.obj.length - 1; } if (isObj) { for (k in obj) { if (hasOwn(obj, k)) { keys.push(k); } } } else if (isArray) { for (i = 0; i < obj.length; ++i) { keys.push(i); } } var result = isObj ? {} : []; var same = true; for (i = 0; i < keys.length; ++i) { k = keys[i]; v = obj[k]; result[k] = func(k, v, seen); same = same && result[k] === obj[k]; } if (isObj && !same) { seen.mapped[seenIndex] = result; } return !same ? result : obj; } /* harmony default export */ var utility_traverse = (traverse); ;// ./src/scrub.js function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || scrub_unsupportedIterableToArray(r, e) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } function scrub_createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = scrub_unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; } function scrub_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return scrub_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? scrub_arrayLikeToArray(r, a) : void 0; } } function scrub_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function scrub(data, scrubFields, scrubPaths) { scrubFields = scrubFields || []; if (scrubPaths) { var _iterator = scrub_createForOfIteratorHelper(scrubPaths), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var path = _step.value; scrubPath(data, path); } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } } var paramRes = _getScrubFieldRegexs(scrubFields); var queryRes = _getScrubQueryParamRegexs(scrubFields); function redactQueryParam(dummy0, paramPart) { return paramPart + redact(); } function paramScrubber(v) { if (isType(v, 'string')) { var _iterator2 = scrub_createForOfIteratorHelper(queryRes), _step2; try { for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { var regex = _step2.value; v = v.replace(regex, redactQueryParam); } } catch (err) { _iterator2.e(err); } finally { _iterator2.f(); } } return v; } function valScrubber(k, v) { var _iterator3 = scrub_createForOfIteratorHelper(paramRes), _step3; try { for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { var regex = _step3.value; if (regex.test(k)) { v = redact(); break; } } } catch (err) { _iterator3.e(err); } finally { _iterator3.f(); } return v; } function scrubber(k, v, seen) { var tmpV = valScrubber(k, v); if (tmpV === v) { if (isType(v, 'object') || isType(v, 'array')) { return utility_traverse(v, scrubber, seen); } return paramScrubber(tmpV); } else { return tmpV; } } return utility_traverse(data, scrubber); } function scrubPath(obj, path) { var keys = path.split('.'); var last = keys.length - 1; try { var _iterator4 = scrub_createForOfIteratorHelper(keys.entries()), _step4; try { for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { var _step4$value = _slicedToArray(_step4.value, 2), index = _step4$value[0], key = _step4$value[1]; if (index < last) { obj = obj[key]; } else { obj[key] = redact(); } } } catch (err) { _iterator4.e(err); } finally { _iterator4.f(); } } catch (_e) { // Missing key is OK; } } function _getScrubFieldRegexs(scrubFields) { var ret = []; var _iterator5 = scrub_createForOfIteratorHelper(scrubFields), _step5; try { for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { var field = _step5.value; var pat = '^\\[?(%5[bB])?' + field + '\\[?(%5[bB])?\\]?(%5[dD])?$'; ret.push(new RegExp(pat, 'i')); } } catch (err) { _iterator5.e(err); } finally { _iterator5.f(); } return ret; } function _getScrubQueryParamRegexs(scrubFields) { var ret = []; var _iterator6 = scrub_createForOfIteratorHelper(scrubFields), _step6; try { for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { var field = _step6.value; var pat = '\\[?(%5[bB])?' + field + '\\[?(%5[bB])?\\]?(%5[dD])?'; ret.push(new RegExp('(' + pat + '=)([^&\\n]+)', 'igm')); } } catch (err) { _iterator6.e(err); } finally { _iterator6.f(); } return ret; } /* harmony default export */ var src_scrub = (scrub); ;// ./src/telemetry.js var _excluded = ["otelAttributes"]; function telemetry_typeof(o) { "@babel/helpers - typeof"; return telemetry_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, telemetry_typeof(o); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == telemetry_typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != telemetry_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != telemetry_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var MAX_EVENTS = 100; // Temporary workaround while solving commonjs -> esm issues in Node 18 - 20. function fromMillis(millis) { return [Math.trunc(millis / 1000), Math.round(millis % 1000 * 1e6)]; } var Telemeter = /*#__PURE__*/function () { function Telemeter(options, tracing) { var _this$tracing; _classCallCheck(this, Telemeter); this.queue = []; this.options = merge(options); var maxTelemetryEvents = this.options.maxTelemetryEvents || MAX_EVENTS; this.maxQueueSize = Math.max(0, Math.min(maxTelemetryEvents, MAX_EVENTS)); this.tracing = tracing; this.telemetrySpan = (_this$tracing = this.tracing) === null || _this$tracing === void 0 ? void 0 : _this$tracing.startSpan('rollbar-telemetry', {}); } return _createClass(Telemeter, [{ key: "configure", value: function configure(options) { var oldOptions = this.options; this.options = merge(oldOptions, options); var maxTelemetryEvents = this.options.maxTelemetryEvents || MAX_EVENTS; var newMaxEvents = Math.max(0, Math.min(maxTelemetryEvents, MAX_EVENTS)); var deleteCount = 0; if (this.queue.length > newMaxEvents) { deleteCount = this.queue.length - newMaxEvents; } this.maxQueueSize = newMaxEvents; this.queue.splice(0, deleteCount); } }, { key: "copyEvents", value: function copyEvents() { var events = Array.prototype.slice.call(this.queue, 0); if (isFunction(this.options.filterTelemetry)) { try { var i = events.length; while (i--) { if (this.options.filterTelemetry(events[i])) { events.splice(i, 1); } } } catch (_e) { this.options.filterTelemetry = null; } } // Filter until supported in legacy telemetry events = events.filter(function (e) { return e.type !== 'connectivity'; }); // Remove internal keys from output events = events.map(function (_ref) { var _otelAttributes = _ref.otelAttributes, event = _objectWithoutProperties(_ref, _excluded); return event; }); return events; } }, { key: "exportTelemetrySpan", value: function exportTelemetrySpan() { var attributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; if (this.telemetrySpan) { this.telemetrySpan.end(attributes); this.telemetrySpan = this.tracing.startSpan('rollbar-telemetry', {}); } } }, { key: "capture", value: function capture(type, metadata, level, rollbarUUID) { var timestamp = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null; var otelAttributes = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null; var e = { level: getLevel(type, level), type: type, timestamp_ms: timestamp || now(), body: metadata, source: 'client' }; if (rollbarUUID) { e.uuid = rollbarUUID; } if (otelAttributes) { e.otelAttributes = otelAttributes; } try { if (isFunction(this.options.filterTelemetry) && this.options.filterTelemetry(e)) { return false; } } catch (_exc) { this.options.filterTelemetry = null; } this.push(e); return e; } }, { key: "captureEvent", value: function captureEvent(type, metadata, level, rollbarUUID) { return this.capture(type, metadata, level, rollbarUUID); } }, { key: "captureError", value: function captureError(err, level, rollbarUUID, timestamp) { var _this$telemetrySpan; var message = err.message || String(err); var metadata = { message: message }; if (err.stack) { metadata.stack = err.stack; } var otelAttributes = { message: message, level: level, type: 'error', uuid: rollbarUUID }; (_this$telemetrySpan = this.telemetrySpan) === null || _this$telemetrySpan === void 0 || _this$telemetrySpan.addEvent('rollbar-occurrence-event', otelAttributes, fromMillis(timestamp)); return this.capture('error', metadata, level, rollbarUUID, timestamp, otelAttributes); } }, { key: "captureLog", value: function captureLog(message, level, rollbarUUID, timestamp) { var _this$telemetrySpan2; var event = rollbarUUID ? 'rollbar-occurrence-event' : 'rollbar-log-event'; var otelAttributes = _objectSpread({ message: message, level: level }, rollbarUUID ? { type: 'message', uuid: rollbarUUID } : {}); (_this$telemetrySpan2 = this.telemetrySpan) === null || _this$telemetrySpan2 === void 0 || _this$telemetrySpan2.addEvent(event, otelAttributes, fromMillis(timestamp)); return this.capture('log', { message: message }, level, rollbarUUID, timestamp, otelAttributes); } }, { key: "captureNetwork", value: function captureNetwork(metadata, subtype, rollbarUUID, requestData) { var _metadata$response, _metadata$response2, _this$telemetrySpan3; subtype = subtype || 'xhr'; metadata.subtype = metadata.subtype || subtype; if (requestData) { metadata.request = requestData; } var level = this.levelFromStatus(metadata.status_code); var endTimeNano = (metadata.end_time_ms || 0) * 1e6; var otelAttributes = { type: metadata.subtype, method: metadata.method, url: metadata.url, statusCode: metadata.status_code, 'request.headers': JSON.stringify(metadata.request_headers || {}), 'response.headers': JSON.stringify(((_metadata$response = metadata.response) === null || _metadata$response === void 0 ? void 0 : _metadata$response.headers) || {}), 'response.timeUnixNano': endTimeNano.toString() }; var requestBody = metadata.request; var responseBody = (_metadata$response2 = metadata.response) === null || _metadata$response2 === void 0 ? void 0 : _metadata$response2.body; if (requestBody) { otelAttributes['request.body'] = JSON.stringify(requestBody); } if (responseBody) { otelAttributes['response.body'] = JSON.stringify(responseBody); } (_this$telemetrySpan3 = this.telemetrySpan) === null || _this$telemetrySpan3 === void 0 || _this$telemetrySpan3.addEvent('rollbar-network-event', otelAttributes, fromMillis(metadata.start_time_ms)); return this.capture('network', metadata, level, rollbarUUID, metadata.start_time_ms, otelAttributes); } }, { key: "levelFromStatus", value: function levelFromStatus(statusCode) { if (statusCode >= 200 && statusCode < 400) { return 'info'; } if (statusCode === 0 || statusCode >= 400) { return 'error'; } return 'info'; } }, { key: "captureDom", value: function captureDom(subtype, element, value, checked, rollbarUUID) { var metadata = { subtype: subtype, element: element }; if (value !== undefined) { metadata.value = value; } if (checked !== undefined) { metadata.checked = checked; } return this.capture('dom', metadata, 'info', rollbarUUID); } }, { key: "captureInput", value: function captureInput(_ref2) { var _this$telemetrySpan4; var type = _ref2.type, isSynthetic = _ref2.isSynthetic, element = _ref2.element, value = _ref2.value, timestamp = _ref2.timestamp; var name = 'rollbar-input-event'; var metadata = { type: name, subtype: type, element: element, value: value }; var otelAttributes = { type: type, isSynthetic: isSynthetic, element: element, value: value, endTimeUnixNano: fromMillis(timestamp) }; var event = this._getRepeatedEvent(name, otelAttributes); if (event) { return this._updateRepeatedEvent(event, otelAttributes, timestamp); } (_this$telemetrySpan4 = this.telemetrySpan) === null || _this$telemetrySpan4 === void 0 || _this$telemetrySpan4.addEvent(name, otelAttributes, fromMillis(timestamp)); return this.capture('dom', metadata, 'info', null, timestamp, otelAttributes); } }, { key: "captureClick", value: function captureClick(_ref3) { var _this$telemetrySpan5; var type = _ref3.type, isSynthetic = _ref3.isSynthetic, element = _ref3.element, timestamp = _ref3.timestamp; var name = 'rollbar-click-event'; var metadata = { type: name, subtype: type, element: element }; var otelAttributes = { type: type, isSynthetic: isSynthetic, element: element, endTimeUnixNano: fromMillis(timestamp) }; var event = this._getRepeatedEvent(name, otelAttributes); if (event) { return this._updateRepeatedEvent(event, otelAttributes, timestamp); } (_this$telemetrySpan5 = this.telemetrySpan) === null || _this$telemetrySpan5 === void 0 || _this$telemetrySpan5.addEvent(name, otelAttributes, fromMillis(timestamp)); return this.capture('dom', metadata, 'info', null, timestamp, otelAttributes); } }, { key: "_getRepeatedEvent", value: function _getRepeatedEvent(name, attributes) { var lastEvent = this._lastEvent(this.queue); if (lastEvent && lastEvent.body.type === name && lastEvent.otelAttributes.target === attributes.target) { return lastEvent; } } }, { key: "_updateRepeatedEvent", value: function _updateRepeatedEvent(event, attributes, timestamp) { var duration = Math.max(timestamp - event.timestamp_ms, 1); event.body.value = attributes.value; event.otelAttributes.value = attributes.value; event.otelAttributes.height = attributes.height; event.otelAttributes.width = attributes.width; event.otelAttributes.textZoomRatio = attributes.textZoomRatio; event.otelAttributes['endTimeUnixNano'] = fromMillis(timestamp); event.otelAttributes['durationUnixNano'] = fromMillis(duration); event.otelAttributes.count = (event.otelAttributes.count || 1) + 1; event.otelAttributes.rate = event.otelAttributes.count / (duration / 1000); } }, { key: "_lastEvent", value: function _lastEvent(list) { return list.length > 0 ? list[list.length - 1] : null; } }, { key: "captureFocus", value: function captureFocus(_ref4) { var _this$telemetrySpan6; var type = _ref4.type, isSynthetic = _ref4.isSynthetic, element = _ref4.element, timestamp = _ref4.timestamp; var name = 'rollbar-focus-event'; var metadata = { type: name, subtype: type, element: element }; var otelAttributes = { type: type, isSynthetic: isSynthetic, element: element }; (_this$telemetrySpan6 = this.telemetrySpan) === null || _this$telemetrySpan6 === void 0 || _this$telemetrySpan6.addEvent(name, otelAttributes, fromMillis(timestamp)); return this.capture('dom', metadata, 'info', null, timestamp, otelAttributes); } }, { key: "captureResize", value: function captureResize(_ref5) { var _this$telemetrySpan7; var type = _ref5.type, isSynthetic = _ref5.isSynthetic, width = _ref5.width, height = _ref5.height, textZoomRatio = _ref5.textZoomRatio, timestamp = _ref5.timestamp; var name = 'rollbar-resize-event'; var metadata = { type: name, subtype: type, width: width, height: height, textZoomRatio: textZoomRatio }; var otelAttributes = { type: type, isSynthetic: isSynthetic, width: width, height: height, textZoomRatio: textZoomRatio }; var event = this._getRepeatedEvent(name, otelAttributes); if (event) { return this._updateRepeatedEvent(event, otelAttributes, timestamp); } (_this$telemetrySpan7 = this.telemetrySpan) === null || _this$telemetrySpan7 === void 0 || _this$telemetrySpan7.addEvent(name, otelAttributes, fromMillis(timestamp)); return this.capture('dom', metadata, 'info', null, timestamp, otelAttributes); } }, { key: "captureDragDrop", value: function captureDragDrop(_ref6) { var _this$telemetrySpan8; var type = _ref6.type, isSynthetic = _ref6.isSynthetic, element = _ref6.element, dropEffect = _ref6.dropEffect, effectAllowed = _ref6.effectAllowed, kinds = _ref6.kinds, mediaTypes = _ref6.mediaTypes, timestamp = _ref6.timestamp; var name = 'rollbar-dragdrop-event'; var metadata = { type: name, subtype: type, isSynthetic: isSynthetic }; var otelAttributes = { type: type, isSynthetic: isSynthetic }; if (type === 'dragstart') { metadata = _objectSpread(_objectSpread({}, metadata), {}, { element: element, dropEffect: dropEffect, effectAllowed: effectAllowed }); otelAttributes = _objectSpread(_objectSpread({}, otelAttributes), {}, { element: element, dropEffect: dropEffect, effectAllowed: effectAllowed }); } if (type === 'drop') { metadata = _objectSpread(_objectSpread({}, metadata), {}, { element: element,