1 | Object.defineProperty(exports, "__esModule", { value: true });
|
2 | var node_1 = require("./node");
|
3 | var string_1 = require("./string");
|
4 | var fallbackGlobalObject = {};
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | function getGlobalObject() {
|
11 | return (node_1.isNodeEnv()
|
12 | ? global
|
13 | : typeof window !== 'undefined'
|
14 | ? window
|
15 | : typeof self !== 'undefined'
|
16 | ? self
|
17 | : fallbackGlobalObject);
|
18 | }
|
19 | exports.getGlobalObject = getGlobalObject;
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | function uuid4() {
|
26 | var global = getGlobalObject();
|
27 | var crypto = global.crypto || global.msCrypto;
|
28 | if (!(crypto === void 0) && crypto.getRandomValues) {
|
29 |
|
30 | var arr = new Uint16Array(8);
|
31 | crypto.getRandomValues(arr);
|
32 |
|
33 |
|
34 | arr[3] = (arr[3] & 0xfff) | 0x4000;
|
35 |
|
36 |
|
37 | arr[4] = (arr[4] & 0x3fff) | 0x8000;
|
38 | var pad = function (num) {
|
39 | var v = num.toString(16);
|
40 | while (v.length < 4) {
|
41 | v = "0" + v;
|
42 | }
|
43 | return v;
|
44 | };
|
45 | 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]));
|
46 | }
|
47 |
|
48 | return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
49 |
|
50 | var r = (Math.random() * 16) | 0;
|
51 |
|
52 | var v = c === 'x' ? r : (r & 0x3) | 0x8;
|
53 | return v.toString(16);
|
54 | });
|
55 | }
|
56 | exports.uuid4 = uuid4;
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | function parseUrl(url) {
|
65 | if (!url) {
|
66 | return {};
|
67 | }
|
68 | var match = url.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);
|
69 | if (!match) {
|
70 | return {};
|
71 | }
|
72 |
|
73 | var query = match[6] || '';
|
74 | var fragment = match[8] || '';
|
75 | return {
|
76 | host: match[4],
|
77 | path: match[5],
|
78 | protocol: match[2],
|
79 | relative: match[5] + query + fragment,
|
80 | };
|
81 | }
|
82 | exports.parseUrl = parseUrl;
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | function getEventDescription(event) {
|
88 | if (event.message) {
|
89 | return event.message;
|
90 | }
|
91 | if (event.exception && event.exception.values && event.exception.values[0]) {
|
92 | var exception = event.exception.values[0];
|
93 | if (exception.type && exception.value) {
|
94 | return exception.type + ": " + exception.value;
|
95 | }
|
96 | return exception.type || exception.value || event.event_id || '<unknown>';
|
97 | }
|
98 | return event.event_id || '<unknown>';
|
99 | }
|
100 | exports.getEventDescription = getEventDescription;
|
101 |
|
102 | function consoleSandbox(callback) {
|
103 | var global = getGlobalObject();
|
104 | var levels = ['debug', 'info', 'warn', 'error', 'log', 'assert'];
|
105 | if (!('console' in global)) {
|
106 | return callback();
|
107 | }
|
108 |
|
109 | var originalConsole = global.console;
|
110 | var wrappedLevels = {};
|
111 |
|
112 | levels.forEach(function (level) {
|
113 |
|
114 | if (level in global.console && originalConsole[level].__sentry_original__) {
|
115 | wrappedLevels[level] = originalConsole[level];
|
116 | originalConsole[level] = originalConsole[level].__sentry_original__;
|
117 | }
|
118 | });
|
119 |
|
120 | var result = callback();
|
121 |
|
122 | Object.keys(wrappedLevels).forEach(function (level) {
|
123 | originalConsole[level] = wrappedLevels[level];
|
124 | });
|
125 | return result;
|
126 | }
|
127 | exports.consoleSandbox = consoleSandbox;
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 | function addExceptionTypeValue(event, value, type) {
|
136 | event.exception = event.exception || {};
|
137 | event.exception.values = event.exception.values || [];
|
138 | event.exception.values[0] = event.exception.values[0] || {};
|
139 | event.exception.values[0].value = event.exception.values[0].value || value || '';
|
140 | event.exception.values[0].type = event.exception.values[0].type || type || 'Error';
|
141 | }
|
142 | exports.addExceptionTypeValue = addExceptionTypeValue;
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 | function addExceptionMechanism(event, mechanism) {
|
150 | if (mechanism === void 0) { mechanism = {}; }
|
151 |
|
152 | try {
|
153 |
|
154 |
|
155 | event.exception.values[0].mechanism = event.exception.values[0].mechanism || {};
|
156 | Object.keys(mechanism).forEach(function (key) {
|
157 |
|
158 |
|
159 | event.exception.values[0].mechanism[key] = mechanism[key];
|
160 | });
|
161 | }
|
162 | catch (_oO) {
|
163 |
|
164 | }
|
165 | }
|
166 | exports.addExceptionMechanism = addExceptionMechanism;
|
167 |
|
168 |
|
169 |
|
170 | function getLocationHref() {
|
171 | try {
|
172 | return document.location.href;
|
173 | }
|
174 | catch (oO) {
|
175 | return '';
|
176 | }
|
177 | }
|
178 | exports.getLocationHref = getLocationHref;
|
179 |
|
180 | var SEMVER_REGEXP = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
181 |
|
182 |
|
183 |
|
184 |
|
185 | function parseSemver(input) {
|
186 | var match = input.match(SEMVER_REGEXP) || [];
|
187 | var major = parseInt(match[1], 10);
|
188 | var minor = parseInt(match[2], 10);
|
189 | var patch = parseInt(match[3], 10);
|
190 | return {
|
191 | buildmetadata: match[5],
|
192 | major: isNaN(major) ? undefined : major,
|
193 | minor: isNaN(minor) ? undefined : minor,
|
194 | patch: isNaN(patch) ? undefined : patch,
|
195 | prerelease: match[4],
|
196 | };
|
197 | }
|
198 | exports.parseSemver = parseSemver;
|
199 | var defaultRetryAfter = 60 * 1000;
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 | function parseRetryAfterHeader(now, header) {
|
206 | if (!header) {
|
207 | return defaultRetryAfter;
|
208 | }
|
209 | var headerDelay = parseInt("" + header, 10);
|
210 | if (!isNaN(headerDelay)) {
|
211 | return headerDelay * 1000;
|
212 | }
|
213 | var headerDate = Date.parse("" + header);
|
214 | if (!isNaN(headerDate)) {
|
215 | return headerDate - now;
|
216 | }
|
217 | return defaultRetryAfter;
|
218 | }
|
219 | exports.parseRetryAfterHeader = parseRetryAfterHeader;
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 | function addContextToFrame(lines, frame, linesOfContext) {
|
228 | if (linesOfContext === void 0) { linesOfContext = 5; }
|
229 | var lineno = frame.lineno || 0;
|
230 | var maxLines = lines.length;
|
231 | var sourceLine = Math.max(Math.min(maxLines, lineno - 1), 0);
|
232 | frame.pre_context = lines
|
233 | .slice(Math.max(0, sourceLine - linesOfContext), sourceLine)
|
234 | .map(function (line) { return string_1.snipLine(line, 0); });
|
235 | frame.context_line = string_1.snipLine(lines[Math.min(maxLines - 1, sourceLine)], frame.colno || 0);
|
236 | frame.post_context = lines
|
237 | .slice(Math.min(sourceLine + 1, maxLines), sourceLine + 1 + linesOfContext)
|
238 | .map(function (line) { return string_1.snipLine(line, 0); });
|
239 | }
|
240 | exports.addContextToFrame = addContextToFrame;
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 | function stripUrlQueryAndFragment(urlPath) {
|
248 |
|
249 | return urlPath.split(/[\?#]/, 1)[0];
|
250 | }
|
251 | exports.stripUrlQueryAndFragment = stripUrlQueryAndFragment;
|
252 |
|
\ | No newline at end of file |