UNPKG

@platformos/pos-cli

Version:

Manage your platformOS application

1,278 lines (1,243 loc) 227 kB
/*! @sentry/browser 5.14.2 (455ebad2) | https://github.com/getsentry/sentry-javascript */ var Sentry = (function (exports) { /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = function() { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __rest(s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]]; return t; } function __decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } function __param(paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } } function __metadata(metadataKey, metadataValue) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); } function __awaiter(thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } function __exportStar(m, exports) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } function __values(o) { var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; if (m) return m.call(o); return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } function __await(v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } function __asyncGenerator(thisArg, _arguments, generator) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var g = generator.apply(thisArg, _arguments || []), i, q = []; return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } function fulfill(value) { resume("next", value); } function reject(value) { resume("throw", value); } function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } } function __asyncDelegator(o) { var i, p; return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; } } function __asyncValues(o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } } function __makeTemplateObject(cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; } function __importStar(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result.default = mod; return result; } function __importDefault(mod) { return (mod && mod.__esModule) ? mod : { default: mod }; } var tslib_1 = /*#__PURE__*/Object.freeze({ __extends: __extends, get __assign () { return __assign; }, __rest: __rest, __decorate: __decorate, __param: __param, __metadata: __metadata, __awaiter: __awaiter, __generator: __generator, __exportStar: __exportStar, __values: __values, __read: __read, __spread: __spread, __await: __await, __asyncGenerator: __asyncGenerator, __asyncDelegator: __asyncDelegator, __asyncValues: __asyncValues, __makeTemplateObject: __makeTemplateObject, __importStar: __importStar, __importDefault: __importDefault }); /** Console logging verbosity for the SDK. */ var LogLevel; (function (LogLevel) { /** No logs will be generated. */ LogLevel[LogLevel["None"] = 0] = "None"; /** Only SDK internal errors will be logged. */ LogLevel[LogLevel["Error"] = 1] = "Error"; /** Information useful for debugging the SDK will be logged. */ LogLevel[LogLevel["Debug"] = 2] = "Debug"; /** All SDK actions will be logged. */ LogLevel[LogLevel["Verbose"] = 3] = "Verbose"; })(LogLevel || (LogLevel = {})); /** JSDoc */ (function (Severity) { /** JSDoc */ Severity["Fatal"] = "fatal"; /** JSDoc */ Severity["Error"] = "error"; /** JSDoc */ Severity["Warning"] = "warning"; /** JSDoc */ Severity["Log"] = "log"; /** JSDoc */ Severity["Info"] = "info"; /** JSDoc */ Severity["Debug"] = "debug"; /** JSDoc */ Severity["Critical"] = "critical"; })(exports.Severity || (exports.Severity = {})); // tslint:disable:completed-docs // tslint:disable:no-unnecessary-qualifier no-namespace (function (Severity) { /** * Converts a string-based level into a {@link Severity}. * * @param level string representation of Severity * @returns Severity */ function fromString(level) { switch (level) { case 'debug': return Severity.Debug; case 'info': return Severity.Info; case 'warn': case 'warning': return Severity.Warning; case 'error': return Severity.Error; case 'fatal': return Severity.Fatal; case 'critical': return Severity.Critical; case 'log': default: return Severity.Log; } } Severity.fromString = fromString; })(exports.Severity || (exports.Severity = {})); /** The status of an Span. */ var SpanStatus; (function (SpanStatus) { /** The operation completed successfully. */ SpanStatus["Ok"] = "ok"; /** Deadline expired before operation could complete. */ SpanStatus["DeadlineExceeded"] = "deadline_exceeded"; /** 401 Unauthorized (actually does mean unauthenticated according to RFC 7235) */ SpanStatus["Unauthenticated"] = "unauthenticated"; /** 403 Forbidden */ SpanStatus["PermissionDenied"] = "permission_denied"; /** 404 Not Found. Some requested entity (file or directory) was not found. */ SpanStatus["NotFound"] = "not_found"; /** 429 Too Many Requests */ SpanStatus["ResourceExhausted"] = "resource_exhausted"; /** Client specified an invalid argument. 4xx. */ SpanStatus["InvalidArgument"] = "invalid_argument"; /** 501 Not Implemented */ SpanStatus["Unimplemented"] = "unimplemented"; /** 503 Service Unavailable */ SpanStatus["Unavailable"] = "unavailable"; /** Other/generic 5xx. */ SpanStatus["InternalError"] = "internal_error"; /** Unknown. Any non-standard HTTP status code. */ SpanStatus["UnknownError"] = "unknown_error"; /** The operation was cancelled (typically by the user). */ SpanStatus["Cancelled"] = "cancelled"; /** Already exists (409) */ SpanStatus["AlreadyExists"] = "already_exists"; /** Operation was rejected because the system is not in a state required for the operation's */ SpanStatus["FailedPrecondition"] = "failed_precondition"; /** The operation was aborted, typically due to a concurrency issue. */ SpanStatus["Aborted"] = "aborted"; /** Operation was attempted past the valid range. */ SpanStatus["OutOfRange"] = "out_of_range"; /** Unrecoverable data loss or corruption */ SpanStatus["DataLoss"] = "data_loss"; })(SpanStatus || (SpanStatus = {})); // tslint:disable:no-unnecessary-qualifier no-namespace (function (SpanStatus) { /** * Converts a HTTP status code into a {@link SpanStatus}. * * @param httpStatus The HTTP response status code. * @returns The span status or {@link SpanStatus.UnknownError}. */ // tslint:disable-next-line:completed-docs function fromHttpCode(httpStatus) { if (httpStatus < 400) { return SpanStatus.Ok; } if (httpStatus >= 400 && httpStatus < 500) { switch (httpStatus) { case 401: return SpanStatus.Unauthenticated; case 403: return SpanStatus.PermissionDenied; case 404: return SpanStatus.NotFound; case 409: return SpanStatus.AlreadyExists; case 413: return SpanStatus.FailedPrecondition; case 429: return SpanStatus.ResourceExhausted; default: return SpanStatus.InvalidArgument; } } if (httpStatus >= 500 && httpStatus < 600) { switch (httpStatus) { case 501: return SpanStatus.Unimplemented; case 503: return SpanStatus.Unavailable; case 504: return SpanStatus.DeadlineExceeded; default: return SpanStatus.InternalError; } } return SpanStatus.UnknownError; } SpanStatus.fromHttpCode = fromHttpCode; })(SpanStatus || (SpanStatus = {})); /** The status of an event. */ (function (Status) { /** The status could not be determined. */ Status["Unknown"] = "unknown"; /** The event was skipped due to configuration or callbacks. */ Status["Skipped"] = "skipped"; /** The event was sent to Sentry successfully. */ Status["Success"] = "success"; /** The client is currently rate limited and will try again later. */ Status["RateLimit"] = "rate_limit"; /** The event could not be processed. */ Status["Invalid"] = "invalid"; /** A server-side error ocurred during submission. */ Status["Failed"] = "failed"; })(exports.Status || (exports.Status = {})); // tslint:disable:completed-docs // tslint:disable:no-unnecessary-qualifier no-namespace (function (Status) { /** * Converts a HTTP status code into a {@link Status}. * * @param code The HTTP response status code. * @returns The send status or {@link Status.Unknown}. */ function fromHttpCode(code) { if (code >= 200 && code < 300) { return Status.Success; } if (code === 429) { return Status.RateLimit; } if (code >= 400 && code < 500) { return Status.Invalid; } if (code >= 500) { return Status.Failed; } return Status.Unknown; } Status.fromHttpCode = fromHttpCode; })(exports.Status || (exports.Status = {})); /** * Consumes the promise and logs the error when it rejects. * @param promise A promise to forget. */ var setPrototypeOf = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array ? setProtoOf : mixinProperties); // tslint:disable-line:no-unbound-method /** * setPrototypeOf polyfill using __proto__ */ function setProtoOf(obj, proto) { // @ts-ignore obj.__proto__ = proto; return obj; } /** * setPrototypeOf polyfill using mixin */ function mixinProperties(obj, proto) { for (var prop in proto) { if (!obj.hasOwnProperty(prop)) { // @ts-ignore obj[prop] = proto[prop]; } } return obj; } /** An error emitted by Sentry SDKs and related utilities. */ var SentryError = /** @class */ (function (_super) { __extends(SentryError, _super); function SentryError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; _this.message = message; // tslint:disable:no-unsafe-any _this.name = _newTarget.prototype.constructor.name; setPrototypeOf(_this, _newTarget.prototype); return _this; } return SentryError; }(Error)); /** * Checks whether given value's type is one of a few Error or Error-like * {@link isError}. * * @param wat A value to be checked. * @returns A boolean representing the result. */ function isError(wat) { switch (Object.prototype.toString.call(wat)) { case '[object Error]': return true; case '[object Exception]': return true; case '[object DOMException]': return true; default: return isInstanceOf(wat, Error); } } /** * Checks whether given value's type is ErrorEvent * {@link isErrorEvent}. * * @param wat A value to be checked. * @returns A boolean representing the result. */ function isErrorEvent(wat) { return Object.prototype.toString.call(wat) === '[object ErrorEvent]'; } /** * Checks whether given value's type is DOMError * {@link isDOMError}. * * @param wat A value to be checked. * @returns A boolean representing the result. */ function isDOMError(wat) { return Object.prototype.toString.call(wat) === '[object DOMError]'; } /** * Checks whether given value's type is DOMException * {@link isDOMException}. * * @param wat A value to be checked. * @returns A boolean representing the result. */ function isDOMException(wat) { return Object.prototype.toString.call(wat) === '[object DOMException]'; } /** * Checks whether given value's type is a string * {@link isString}. * * @param wat A value to be checked. * @returns A boolean representing the result. */ function isString(wat) { return Object.prototype.toString.call(wat) === '[object String]'; } /** * Checks whether given value's is a primitive (undefined, null, number, boolean, string) * {@link isPrimitive}. * * @param wat A value to be checked. * @returns A boolean representing the result. */ function isPrimitive(wat) { return wat === null || (typeof wat !== 'object' && typeof wat !== 'function'); } /** * Checks whether given value's type is an object literal * {@link isPlainObject}. * * @param wat A value to be checked. * @returns A boolean representing the result. */ function isPlainObject(wat) { return Object.prototype.toString.call(wat) === '[object Object]'; } /** * Checks whether given value's type is an Event instance * {@link isEvent}. * * @param wat A value to be checked. * @returns A boolean representing the result. */ function isEvent(wat) { // tslint:disable-next-line:strict-type-predicates return typeof Event !== 'undefined' && isInstanceOf(wat, Event); } /** * Checks whether given value's type is an Element instance * {@link isElement}. * * @param wat A value to be checked. * @returns A boolean representing the result. */ function isElement(wat) { // tslint:disable-next-line:strict-type-predicates return typeof Element !== 'undefined' && isInstanceOf(wat, Element); } /** * Checks whether given value's type is an regexp * {@link isRegExp}. * * @param wat A value to be checked. * @returns A boolean representing the result. */ function isRegExp(wat) { return Object.prototype.toString.call(wat) === '[object RegExp]'; } /** * Checks whether given value has a then function. * @param wat A value to be checked. */ function isThenable(wat) { // tslint:disable:no-unsafe-any return Boolean(wat && wat.then && typeof wat.then === 'function'); // tslint:enable:no-unsafe-any } /** * Checks whether given value's type is a SyntheticEvent * {@link isSyntheticEvent}. * * @param wat A value to be checked. * @returns A boolean representing the result. */ function isSyntheticEvent(wat) { // tslint:disable-next-line:no-unsafe-any return isPlainObject(wat) && 'nativeEvent' in wat && 'preventDefault' in wat && 'stopPropagation' in wat; } /** * Checks whether given value's type is an instance of provided constructor. * {@link isInstanceOf}. * * @param wat A value to be checked. * @param base A constructor to be used in a check. * @returns A boolean representing the result. */ function isInstanceOf(wat, base) { try { // tslint:disable-next-line:no-unsafe-any return wat instanceof base; } catch (_e) { return false; } } /** * Truncates given string to the maximum characters count * * @param str An object that contains serializable values * @param max Maximum number of characters in truncated string * @returns string Encoded */ function truncate(str, max) { if (max === void 0) { max = 0; } // tslint:disable-next-line:strict-type-predicates if (typeof str !== 'string' || max === 0) { return str; } return str.length <= max ? str : str.substr(0, max) + "..."; } /** * Join values in array * @param input array of values to be joined together * @param delimiter string to be placed in-between values * @returns Joined values */ function safeJoin(input, delimiter) { if (!Array.isArray(input)) { return ''; } var output = []; // tslint:disable-next-line:prefer-for-of for (var i = 0; i < input.length; i++) { var value = input[i]; try { output.push(String(value)); } catch (e) { output.push('[value cannot be serialized]'); } } return output.join(delimiter); } /** * Checks if the value matches a regex or includes the string * @param value The string value to be checked against * @param pattern Either a regex or a string that must be contained in value */ function isMatchingPattern(value, pattern) { if (isRegExp(pattern)) { return pattern.test(value); } if (typeof pattern === 'string') { return value.indexOf(pattern) !== -1; } return false; } /** * Requires a module which is protected _against bundler minification. * * @param request The module path to resolve */ function dynamicRequire(mod, request) { // tslint:disable-next-line: no-unsafe-any return mod.require(request); } /** * Checks whether we're in the Node.js or Browser environment * * @returns Answer to given question */ function isNodeEnv() { // tslint:disable:strict-type-predicates return Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]'; } var fallbackGlobalObject = {}; /** * Safely get global scope object * * @returns Global scope object */ function getGlobalObject() { return (isNodeEnv() ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : fallbackGlobalObject); } /** * UUID4 generator * * @returns string Generated UUID4. */ function uuid4() { var global = getGlobalObject(); var crypto = global.crypto || global.msCrypto; if (!(crypto === void 0) && crypto.getRandomValues) { // Use window.crypto API if available var arr = new Uint16Array(8); crypto.getRandomValues(arr); // set 4 in byte 7 // tslint:disable-next-line:no-bitwise arr[3] = (arr[3] & 0xfff) | 0x4000; // set 2 most significant bits of byte 9 to '10' // tslint:disable-next-line:no-bitwise arr[4] = (arr[4] & 0x3fff) | 0x8000; var pad = function (num) { var v = num.toString(16); while (v.length < 4) { v = "0" + v; } return v; }; return (pad(arr[0]) + pad(arr[1]) + pad(arr[2]) + pad(arr[3]) + pad(arr[4]) + pad(arr[5]) + pad(arr[6]) + pad(arr[7])); } // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523 return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) { // tslint:disable-next-line:no-bitwise var r = (Math.random() * 16) | 0; // tslint:disable-next-line:no-bitwise var v = c === 'x' ? r : (r & 0x3) | 0x8; return v.toString(16); }); } /** * Parses string form of URL into an object * // borrowed from https://tools.ietf.org/html/rfc3986#appendix-B * // intentionally using regex and not <a/> href parsing trick because React Native and other * // environments where DOM might not be available * @returns parsed URL object */ function parseUrl(url) { if (!url) { return {}; } var match = url.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/); if (!match) { return {}; } // coerce to undefined values to empty string so we don't get 'undefined' var query = match[6] || ''; var fragment = match[8] || ''; return { host: match[4], path: match[5], protocol: match[2], relative: match[5] + query + fragment, }; } /** * Extracts either message or type+value from an event that can be used for user-facing logs * @returns event's description */ function getEventDescription(event) { if (event.message) { return event.message; } if (event.exception && event.exception.values && event.exception.values[0]) { var exception = event.exception.values[0]; if (exception.type && exception.value) { return exception.type + ": " + exception.value; } return exception.type || exception.value || event.event_id || '<unknown>'; } return event.event_id || '<unknown>'; } /** JSDoc */ function consoleSandbox(callback) { var global = getGlobalObject(); var levels = ['debug', 'info', 'warn', 'error', 'log', 'assert']; if (!('console' in global)) { return callback(); } var originalConsole = global.console; var wrappedLevels = {}; // Restore all wrapped console methods levels.forEach(function (level) { if (level in global.console && originalConsole[level].__sentry_original__) { wrappedLevels[level] = originalConsole[level]; originalConsole[level] = originalConsole[level].__sentry_original__; } }); // Perform callback manipulations var result = callback(); // Revert restoration to wrapped state Object.keys(wrappedLevels).forEach(function (level) { originalConsole[level] = wrappedLevels[level]; }); return result; } /** * Adds exception values, type and value to an synthetic Exception. * @param event The event to modify. * @param value Value of the exception. * @param type Type of the exception. * @hidden */ function addExceptionTypeValue(event, value, type) { event.exception = event.exception || {}; event.exception.values = event.exception.values || []; event.exception.values[0] = event.exception.values[0] || {}; event.exception.values[0].value = event.exception.values[0].value || value || ''; event.exception.values[0].type = event.exception.values[0].type || type || 'Error'; } /** * Adds exception mechanism to a given event. * @param event The event to modify. * @param mechanism Mechanism of the mechanism. * @hidden */ function addExceptionMechanism(event, mechanism) { if (mechanism === void 0) { mechanism = {}; } // TODO: Use real type with `keyof Mechanism` thingy and maybe make it better? try { // @ts-ignore // tslint:disable:no-non-null-assertion event.exception.values[0].mechanism = event.exception.values[0].mechanism || {}; Object.keys(mechanism).forEach(function (key) { // @ts-ignore event.exception.values[0].mechanism[key] = mechanism[key]; }); } catch (_oO) { // no-empty } } /** * A safe form of location.href */ function getLocationHref() { try { return document.location.href; } catch (oO) { return ''; } } /** * Given a child DOM element, returns a query-selector statement describing that * and its ancestors * e.g. [HTMLElement] => body > div > input#foo.btn[name=baz] * @returns generated DOM path */ function htmlTreeAsString(elem) { // try/catch both: // - accessing event.target (see getsentry/raven-js#838, #768) // - `htmlTreeAsString` because it's complex, and just accessing the DOM incorrectly // - can throw an exception in some circumstances. try { var currentElem = elem; var MAX_TRAVERSE_HEIGHT = 5; var MAX_OUTPUT_LEN = 80; var out = []; var height = 0; var len = 0; var separator = ' > '; var sepLength = separator.length; var nextStr = void 0; while (currentElem && height++ < MAX_TRAVERSE_HEIGHT) { nextStr = _htmlElementAsString(currentElem); // bail out if // - nextStr is the 'html' element // - the length of the string that would be created exceeds MAX_OUTPUT_LEN // (ignore this limit if we are on the first iteration) if (nextStr === 'html' || (height > 1 && len + out.length * sepLength + nextStr.length >= MAX_OUTPUT_LEN)) { break; } out.push(nextStr); len += nextStr.length; currentElem = currentElem.parentNode; } return out.reverse().join(separator); } catch (_oO) { return '<unknown>'; } } /** * Returns a simple, query-selector representation of a DOM element * e.g. [HTMLElement] => input#foo.btn[name=baz] * @returns generated DOM path */ function _htmlElementAsString(el) { var elem = el; var out = []; var className; var classes; var key; var attr; var i; if (!elem || !elem.tagName) { return ''; } out.push(elem.tagName.toLowerCase()); if (elem.id) { out.push("#" + elem.id); } className = elem.className; if (className && isString(className)) { classes = className.split(/\s+/); for (i = 0; i < classes.length; i++) { out.push("." + classes[i]); } } var attrWhitelist = ['type', 'name', 'title', 'alt']; for (i = 0; i < attrWhitelist.length; i++) { key = attrWhitelist[i]; attr = elem.getAttribute(key); if (attr) { out.push("[" + key + "=\"" + attr + "\"]"); } } return out.join(''); } var INITIAL_TIME = Date.now(); var prevNow = 0; var performanceFallback = { now: function () { var now = Date.now() - INITIAL_TIME; if (now < prevNow) { now = prevNow; } prevNow = now; return now; }, timeOrigin: INITIAL_TIME, }; var crossPlatformPerformance = (function () { if (isNodeEnv()) { try { var perfHooks = dynamicRequire(module, 'perf_hooks'); return perfHooks.performance; } catch (_) { return performanceFallback; } } if (getGlobalObject().performance) { // Polyfill for performance.timeOrigin. // // While performance.timing.navigationStart is deprecated in favor of performance.timeOrigin, performance.timeOrigin // is not as widely supported. Namely, performance.timeOrigin is undefined in Safari as of writing. // tslint:disable-next-line:strict-type-predicates if (performance.timeOrigin === undefined) { // As of writing, performance.timing is not available in Web Workers in mainstream browsers, so it is not always a // valid fallback. In the absence of a initial time provided by the browser, fallback to INITIAL_TIME. // @ts-ignore // tslint:disable-next-line:deprecation performance.timeOrigin = (performance.timing && performance.timing.navigationStart) || INITIAL_TIME; } } return getGlobalObject().performance || performanceFallback; })(); /** * Returns a timestamp in seconds with milliseconds precision since the UNIX epoch calculated with the monotonic clock. */ function timestampWithMs() { return (crossPlatformPerformance.timeOrigin + crossPlatformPerformance.now()) / 1000; } var defaultRetryAfter = 60 * 1000; // 60 seconds /** * Extracts Retry-After value from the request header or returns default value * @param now current unix timestamp * @param header string representation of 'Retry-After' header */ function parseRetryAfterHeader(now, header) { if (!header) { return defaultRetryAfter; } var headerDelay = parseInt("" + header, 10); if (!isNaN(headerDelay)) { return headerDelay * 1000; } var headerDate = Date.parse("" + header); if (!isNaN(headerDate)) { return headerDate - now; } return defaultRetryAfter; } var defaultFunctionName = '<anonymous>'; /** * Safely extract function name from itself */ function getFunctionName(fn) { try { if (!fn || typeof fn !== 'function') { return defaultFunctionName; } return fn.name || defaultFunctionName; } catch (e) { // Just accessing custom props in some Selenium environments // can cause a "Permission denied" exception (see raven-js#495). return defaultFunctionName; } } // TODO: Implement different loggers for different environments var global$1 = getGlobalObject(); /** Prefix for logging strings */ var PREFIX = 'Sentry Logger '; /** JSDoc */ var Logger = /** @class */ (function () { /** JSDoc */ function Logger() { this._enabled = false; } /** JSDoc */ Logger.prototype.disable = function () { this._enabled = false; }; /** JSDoc */ Logger.prototype.enable = function () { this._enabled = true; }; /** JSDoc */ Logger.prototype.log = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } if (!this._enabled) { return; } consoleSandbox(function () { global$1.console.log(PREFIX + "[Log]: " + args.join(' ')); // tslint:disable-line:no-console }); }; /** JSDoc */ Logger.prototype.warn = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } if (!this._enabled) { return; } consoleSandbox(function () { global$1.console.warn(PREFIX + "[Warn]: " + args.join(' ')); // tslint:disable-line:no-console }); }; /** JSDoc */ Logger.prototype.error = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } if (!this._enabled) { return; } consoleSandbox(function () { global$1.console.error(PREFIX + "[Error]: " + args.join(' ')); // tslint:disable-line:no-console }); }; return Logger; }()); // Ensure we only have a single logger instance, even if multiple versions of @sentry/utils are being used global$1.__SENTRY__ = global$1.__SENTRY__ || {}; var logger = global$1.__SENTRY__.logger || (global$1.__SENTRY__.logger = new Logger()); // tslint:disable:no-unsafe-any /** * Memo class used for decycle json objects. Uses WeakSet if available otherwise array. */ var Memo = /** @class */ (function () { function Memo() { // tslint:disable-next-line this._hasWeakSet = typeof WeakSet === 'function'; this._inner = this._hasWeakSet ? new WeakSet() : []; } /** * Sets obj to remember. * @param obj Object to remember */ Memo.prototype.memoize = function (obj) { if (this._hasWeakSet) { if (this._inner.has(obj)) { return true; } this._inner.add(obj); return false; } // tslint:disable-next-line:prefer-for-of for (var i = 0; i < this._inner.length; i++) { var value = this._inner[i]; if (value === obj) { return true; } } this._inner.push(obj); return false; }; /** * Removes object from internal storage. * @param obj Object to forget */ Memo.prototype.unmemoize = function (obj) { if (this._hasWeakSet) { this._inner.delete(obj); } else { for (var i = 0; i < this._inner.length; i++) { if (this._inner[i] === obj) { this._inner.splice(i, 1); break; } } } }; return Memo; }()); /** * Wrap a given object method with a higher-order function * * @param source An object that contains a method to be wrapped. * @param name A name of method to be wrapped. * @param replacement A function that should be used to wrap a given method. * @returns void */ function fill(source, name, replacement) { if (!(name in source)) { return; } var original = source[name]; var wrapped = replacement(original); // Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work // otherwise it'll throw "TypeError: Object.defineProperties called on non-object" // tslint:disable-next-line:strict-type-predicates if (typeof wrapped === 'function') { try { wrapped.prototype = wrapped.prototype || {}; Object.defineProperties(wrapped, { __sentry_original__: { enumerable: false, value: original, }, }); } catch (_Oo) { // This can throw if multiple fill happens on a global object like XMLHttpRequest // Fixes https://github.com/getsentry/sentry-javascript/issues/2043 } } source[name] = wrapped; } /** * Encodes given object into url-friendly format * * @param object An object that contains serializable values * @returns string Encoded */ function urlEncode(object) { return Object.keys(object) .map( // tslint:disable-next-line:no-unsafe-any function (key) { return encodeURIComponent(key) + "=" + encodeURIComponent(object[key]); }) .join('&'); } /** * Transforms any object into an object literal with all it's attributes * attached to it. * * @param value Initial source that we have to transform in order to be usable by the serializer */ function getWalkSource(value) { if (isError(value)) { var error = value; var err = { message: error.message, name: error.name, stack: error.stack, }; for (var i in error) { if (Object.prototype.hasOwnProperty.call(error, i)) { err[i] = error[i]; } } return err; } if (isEvent(value)) { var event_1 = value; var source = {}; source.type = event_1.type; // Accessing event.target can throw (see getsentry/raven-js#838, #768) try { source.target = isElement(event_1.target) ? htmlTreeAsString(event_1.target) : Object.prototype.toString.call(event_1.target); } catch (_oO) { source.target = '<unknown>'; } try { source.currentTarget = isElement(event_1.currentTarget) ? htmlTreeAsString(event_1.currentTarget) : Object.prototype.toString.call(event_1.currentTarget); } catch (_oO) { source.currentTarget = '<unknown>'; } // tslint:disable-next-line:strict-type-predicates if (typeof CustomEvent !== 'undefined' && isInstanceOf(value, CustomEvent)) { source.detail = event_1.detail; } for (var i in event_1) { if (Object.prototype.hasOwnProperty.call(event_1, i)) { source[i] = event_1; } } return source; } return value; } /** Calculates bytes size of input string */ function utf8Length(value) { // tslint:disable-next-line:no-bitwise return ~-encodeURI(value).split(/%..|./).length; } /** Calculates bytes size of input object */ function jsonSize(value) { return utf8Length(JSON.stringify(value)); } /** JSDoc */ function normalizeToSize(object, // Default Node.js REPL depth depth, // 100kB, as 200kB is max payload size, so half sounds reasonable maxSize) { if (depth === void 0) { depth = 3; } if (maxSize === void 0) { maxSize = 100 * 1024; } var serialized = normalize(object, depth); if (jsonSize(serialized) > maxSize) { return normalizeToSize(object, depth - 1, maxSize); } return serialized; } /** Transforms any input value into a string form, either primitive value or a type of the input */ function serializeValue(value) { var type = Object.prototype.toString.call(value); // Node.js REPL notation if (typeof value === 'string') { return value; } if (type === '[object Object]') { return '[Object]'; } if (type === '[object Array]') { return '[Array]'; } var normalized = normalizeValue(value); return isPrimitive(normalized) ? normalized : type; } /** * normalizeValue() * * Takes unserializable input and make it serializable friendly * * - translates undefined/NaN values to "[undefined]"/"[NaN]" respectively, * - serializes Error objects * - filter global objects */ // tslint:disable-next-line:cyclomatic-complexity function normalizeValue(value, key) { if (key === 'domain' && value && typeof value === 'object' && value._events) { return '[Domain]'; } if (key === 'domainEmitter') { return '[DomainEmitter]'; } if (typeof global !== 'undefined' && value === global) { return '[Global]'; } if (typeof window !== 'undefined' && value === window) { return '[Window]'; } if (typeof document !== 'undefined' && value === document) { return '[Document]'; } // React's SyntheticEvent thingy if (isSyntheticEvent(value)) { return '[SyntheticEvent]'; } // tslint:disable-next-line:no-tautology-expression if (typeof value === 'number' && value !== value) { return '[NaN]'; } if (value === void 0) { retur