1 | Object.defineProperty(exports, "__esModule", { value: true });
|
2 | var tslib_1 = require("tslib");
|
3 | var browser_1 = require("./browser");
|
4 | var is_1 = require("./is");
|
5 | var memo_1 = require("./memo");
|
6 | var stacktrace_1 = require("./stacktrace");
|
7 | var string_1 = require("./string");
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | function fill(source, name, replacementFactory) {
|
20 | if (!(name in source)) {
|
21 | return;
|
22 | }
|
23 | var original = source[name];
|
24 | var wrapped = replacementFactory(original);
|
25 |
|
26 |
|
27 | if (typeof wrapped === 'function') {
|
28 | try {
|
29 | wrapped.prototype = wrapped.prototype || {};
|
30 | Object.defineProperties(wrapped, {
|
31 | __sentry_original__: {
|
32 | enumerable: false,
|
33 | value: original,
|
34 | },
|
35 | });
|
36 | }
|
37 | catch (_Oo) {
|
38 |
|
39 |
|
40 | }
|
41 | }
|
42 | source[name] = wrapped;
|
43 | }
|
44 | exports.fill = fill;
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | function urlEncode(object) {
|
52 | return Object.keys(object)
|
53 | .map(function (key) { return encodeURIComponent(key) + "=" + encodeURIComponent(object[key]); })
|
54 | .join('&');
|
55 | }
|
56 | exports.urlEncode = urlEncode;
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | function getWalkSource(value) {
|
64 | if (is_1.isError(value)) {
|
65 | var error = value;
|
66 | var err = {
|
67 | message: error.message,
|
68 | name: error.name,
|
69 | stack: error.stack,
|
70 | };
|
71 | for (var i in error) {
|
72 | if (Object.prototype.hasOwnProperty.call(error, i)) {
|
73 | err[i] = error[i];
|
74 | }
|
75 | }
|
76 | return err;
|
77 | }
|
78 | if (is_1.isEvent(value)) {
|
79 | var event_1 = value;
|
80 | var source = {};
|
81 | source.type = event_1.type;
|
82 |
|
83 | try {
|
84 | source.target = is_1.isElement(event_1.target)
|
85 | ? browser_1.htmlTreeAsString(event_1.target)
|
86 | : Object.prototype.toString.call(event_1.target);
|
87 | }
|
88 | catch (_oO) {
|
89 | source.target = '<unknown>';
|
90 | }
|
91 | try {
|
92 | source.currentTarget = is_1.isElement(event_1.currentTarget)
|
93 | ? browser_1.htmlTreeAsString(event_1.currentTarget)
|
94 | : Object.prototype.toString.call(event_1.currentTarget);
|
95 | }
|
96 | catch (_oO) {
|
97 | source.currentTarget = '<unknown>';
|
98 | }
|
99 | if (typeof CustomEvent !== 'undefined' && is_1.isInstanceOf(value, CustomEvent)) {
|
100 | source.detail = event_1.detail;
|
101 | }
|
102 | for (var i in event_1) {
|
103 | if (Object.prototype.hasOwnProperty.call(event_1, i)) {
|
104 | source[i] = event_1;
|
105 | }
|
106 | }
|
107 | return source;
|
108 | }
|
109 | return value;
|
110 | }
|
111 |
|
112 | function utf8Length(value) {
|
113 |
|
114 | return ~-encodeURI(value).split(/%..|./).length;
|
115 | }
|
116 |
|
117 | function jsonSize(value) {
|
118 | return utf8Length(JSON.stringify(value));
|
119 | }
|
120 |
|
121 | function normalizeToSize(object,
|
122 | // Default Node.js REPL depth
|
123 | depth,
|
124 | // 100kB, as 200kB is max payload size, so half sounds reasonable
|
125 | maxSize) {
|
126 | if (depth === void 0) { depth = 3; }
|
127 | if (maxSize === void 0) { maxSize = 100 * 1024; }
|
128 | var serialized = normalize(object, depth);
|
129 | if (jsonSize(serialized) > maxSize) {
|
130 | return normalizeToSize(object, depth - 1, maxSize);
|
131 | }
|
132 | return serialized;
|
133 | }
|
134 | exports.normalizeToSize = normalizeToSize;
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 | function serializeValue(value) {
|
145 | var type = Object.prototype.toString.call(value);
|
146 |
|
147 | if (typeof value === 'string') {
|
148 | return value;
|
149 | }
|
150 | if (type === '[object Object]') {
|
151 | return '[Object]';
|
152 | }
|
153 | if (type === '[object Array]') {
|
154 | return '[Array]';
|
155 | }
|
156 | var normalized = normalizeValue(value);
|
157 | return is_1.isPrimitive(normalized) ? normalized : type;
|
158 | }
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 | function normalizeValue(value, key) {
|
169 | if (key === 'domain' && value && typeof value === 'object' && value._events) {
|
170 | return '[Domain]';
|
171 | }
|
172 | if (key === 'domainEmitter') {
|
173 | return '[DomainEmitter]';
|
174 | }
|
175 | if (typeof global !== 'undefined' && value === global) {
|
176 | return '[Global]';
|
177 | }
|
178 | if (typeof window !== 'undefined' && value === window) {
|
179 | return '[Window]';
|
180 | }
|
181 | if (typeof document !== 'undefined' && value === document) {
|
182 | return '[Document]';
|
183 | }
|
184 |
|
185 | if (is_1.isSyntheticEvent(value)) {
|
186 | return '[SyntheticEvent]';
|
187 | }
|
188 | if (typeof value === 'number' && value !== value) {
|
189 | return '[NaN]';
|
190 | }
|
191 | if (value === void 0) {
|
192 | return '[undefined]';
|
193 | }
|
194 | if (typeof value === 'function') {
|
195 | return "[Function: " + stacktrace_1.getFunctionName(value) + "]";
|
196 | }
|
197 |
|
198 | if (typeof value === 'symbol') {
|
199 | return "[" + String(value) + "]";
|
200 | }
|
201 | if (typeof value === 'bigint') {
|
202 | return "[BigInt: " + String(value) + "]";
|
203 | }
|
204 | return value;
|
205 | }
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 | function walk(key, value, depth, memo) {
|
216 | if (depth === void 0) { depth = +Infinity; }
|
217 | if (memo === void 0) { memo = new memo_1.Memo(); }
|
218 |
|
219 | if (depth === 0) {
|
220 | return serializeValue(value);
|
221 | }
|
222 |
|
223 |
|
224 | if (value !== null && value !== undefined && typeof value.toJSON === 'function') {
|
225 | return value.toJSON();
|
226 | }
|
227 |
|
228 |
|
229 | var normalized = normalizeValue(value, key);
|
230 | if (is_1.isPrimitive(normalized)) {
|
231 | return normalized;
|
232 | }
|
233 |
|
234 | var source = getWalkSource(value);
|
235 |
|
236 | var acc = Array.isArray(value) ? [] : {};
|
237 |
|
238 | if (memo.memoize(value)) {
|
239 | return '[Circular ~]';
|
240 | }
|
241 |
|
242 | for (var innerKey in source) {
|
243 |
|
244 | if (!Object.prototype.hasOwnProperty.call(source, innerKey)) {
|
245 | continue;
|
246 | }
|
247 |
|
248 | acc[innerKey] = walk(innerKey, source[innerKey], depth - 1, memo);
|
249 | }
|
250 |
|
251 | memo.unmemoize(value);
|
252 |
|
253 | return acc;
|
254 | }
|
255 | exports.walk = walk;
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 | function normalize(input, depth) {
|
270 | try {
|
271 | return JSON.parse(JSON.stringify(input, function (key, value) { return walk(key, value, depth); }));
|
272 | }
|
273 | catch (_oO) {
|
274 | return '**non-serializable**';
|
275 | }
|
276 | }
|
277 | exports.normalize = normalize;
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 | function extractExceptionKeysForMessage(exception, maxLength) {
|
285 | if (maxLength === void 0) { maxLength = 40; }
|
286 | var keys = Object.keys(getWalkSource(exception));
|
287 | keys.sort();
|
288 | if (!keys.length) {
|
289 | return '[object has no keys]';
|
290 | }
|
291 | if (keys[0].length >= maxLength) {
|
292 | return string_1.truncate(keys[0], maxLength);
|
293 | }
|
294 | for (var includedKeys = keys.length; includedKeys > 0; includedKeys--) {
|
295 | var serialized = keys.slice(0, includedKeys).join(', ');
|
296 | if (serialized.length > maxLength) {
|
297 | continue;
|
298 | }
|
299 | if (includedKeys === keys.length) {
|
300 | return serialized;
|
301 | }
|
302 | return string_1.truncate(serialized, maxLength);
|
303 | }
|
304 | return '';
|
305 | }
|
306 | exports.extractExceptionKeysForMessage = extractExceptionKeysForMessage;
|
307 |
|
308 |
|
309 |
|
310 |
|
311 | function dropUndefinedKeys(val) {
|
312 | var e_1, _a;
|
313 | if (is_1.isPlainObject(val)) {
|
314 | var obj = val;
|
315 | var rv = {};
|
316 | try {
|
317 | for (var _b = tslib_1.__values(Object.keys(obj)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
318 | var key = _c.value;
|
319 | if (typeof obj[key] !== 'undefined') {
|
320 | rv[key] = dropUndefinedKeys(obj[key]);
|
321 | }
|
322 | }
|
323 | }
|
324 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
325 | finally {
|
326 | try {
|
327 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
328 | }
|
329 | finally { if (e_1) throw e_1.error; }
|
330 | }
|
331 | return rv;
|
332 | }
|
333 | if (Array.isArray(val)) {
|
334 | return val.map(dropUndefinedKeys);
|
335 | }
|
336 | return val;
|
337 | }
|
338 | exports.dropUndefinedKeys = dropUndefinedKeys;
|
339 |
|
\ | No newline at end of file |