@lark-sentry/core 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ var types = require('@lark-sentry/types');
3
4
  var utils = require('@lark-sentry/utils');
4
5
  var constants = require('@lark-sentry/constants');
5
- var types = require('@lark-sentry/types');
6
6
  var reporter = require('@lark-sentry/reporter');
7
+ var index_cjs = require('@lark-sentry/types/dist/index.cjs');
7
8
 
8
9
  var __typeError = (msg) => {
9
10
  throw TypeError(msg);
@@ -98,12 +99,12 @@ function checkWhiteScreen(onReport) {
98
99
  };
99
100
  const report = () => {
100
101
  const whiteScreenData = {
101
- ...utils.getTime(),
102
+ ...utils.getBaseData(),
102
103
  type: types.EventType.WhiteScreen,
103
104
  status: types.Status.Error,
104
- id: crypto.randomUUID(),
105
105
  name: "WhiteScreen",
106
- message: `sample count ${sampleCount}`
106
+ message: `sample count ${sampleCount}`,
107
+ extra: "WhiteScreen"
107
108
  };
108
109
  onReport(whiteScreenData);
109
110
  stopSample();
@@ -146,7 +147,7 @@ const handleHttp = (data) => {
146
147
  const { id, name, time, timestamp, message, status, type } = data;
147
148
  if (!data.api.includes(utils.sentry.options.dsn)) {
148
149
  breadcrumb.push({
149
- id: id ?? crypto.randomUUID(),
150
+ id,
150
151
  name,
151
152
  time,
152
153
  timestamp,
@@ -160,7 +161,10 @@ const handleHttp = (data) => {
160
161
  reporter.send(data);
161
162
  }
162
163
  };
163
- const handleError$1 = (err) => {
164
+ const handleError$1 = ({
165
+ extra: err,
166
+ ...rest
167
+ }) => {
164
168
  if (utils.isErrorEvent(err)) {
165
169
  handleCodeError(err);
166
170
  }
@@ -168,10 +172,9 @@ const handleError$1 = (err) => {
168
172
  const { localName, src, href } = err.target;
169
173
  const { message } = err;
170
174
  const resourceError = {
171
- id: crypto.randomUUID(),
175
+ ...rest,
172
176
  type: types.EventType.Resource,
173
177
  status: types.Status.Error,
174
- ...utils.getTime(),
175
178
  name: localName,
176
179
  src,
177
180
  href,
@@ -187,12 +190,12 @@ const handleError$1 = (err) => {
187
190
  if (utils.isError(err)) {
188
191
  const { name, message } = err;
189
192
  const data2 = {
190
- id: crypto.randomUUID(),
193
+ ...rest,
191
194
  type: types.EventType.Error,
192
195
  name,
193
196
  message,
194
197
  status: types.Status.Error,
195
- ...utils.getTime()
198
+ extra: err
196
199
  };
197
200
  breadcrumb.push({
198
201
  ...data2,
@@ -202,12 +205,12 @@ const handleError$1 = (err) => {
202
205
  return;
203
206
  }
204
207
  const data = {
205
- id: crypto.randomUUID(),
208
+ ...rest,
206
209
  type: types.EventType.Error,
207
210
  name: "Unknown Error",
208
211
  message: JSON.stringify(err),
209
212
  status: types.Status.Error,
210
- ...utils.getTime()
213
+ extra: err
211
214
  };
212
215
  breadcrumb.push({
213
216
  ...data,
@@ -215,78 +218,79 @@ const handleError$1 = (err) => {
215
218
  });
216
219
  reporter.send(data);
217
220
  };
218
- const handleHistory = (routeChange) => {
219
- const id = crypto.randomUUID();
220
- const { from, to } = routeChange;
221
- const pathChange = `${from} => ${to}`;
221
+ const handleHistory = ({
222
+ from,
223
+ to,
224
+ ...rest
225
+ }) => {
226
+ const routeChange = `${from} => ${to}`;
222
227
  const routeData = {
223
- id,
224
- name: pathChange,
225
- message: pathChange,
228
+ ...rest,
229
+ name: routeChange,
230
+ message: routeChange,
226
231
  type: types.EventType.History,
227
232
  from,
228
- to,
229
- ...utils.getTime(),
230
- status: types.Status.OK
233
+ to
231
234
  };
232
235
  breadcrumb.push({
233
236
  ...routeData,
234
237
  userAction: utils.event2breadcrumb(types.EventType.History)
235
238
  });
236
239
  };
237
- const handleHashChange = (e) => {
238
- const id = crypto.randomUUID();
239
- const { oldURL: from, newURL: to } = e;
240
+ const handleHashChange = ({
241
+ extra,
242
+ ...rest
243
+ }) => {
244
+ const { oldURL: from = constants.UNKNOWN, newURL: to = constants.UNKNOWN } = extra;
240
245
  const pathChange = `${from} => ${to}`;
241
246
  const routeData = {
242
- id,
247
+ ...rest,
243
248
  name: pathChange,
244
249
  message: pathChange,
245
250
  type: types.EventType.HashChange,
246
251
  from,
247
- to,
248
- ...utils.getTime(),
249
- status: types.Status.OK
252
+ to
250
253
  };
251
254
  breadcrumb.push({
252
255
  ...routeData,
253
256
  userAction: utils.event2breadcrumb(types.EventType.HashChange)
254
257
  });
255
258
  };
256
- const handleUnhandledRejection = (e) => {
257
- if (!utils.isIExtendedErrorEvent(e)) {
258
- handleError$1(e);
259
+ const handleUnhandledRejection = (data) => {
260
+ if (!utils.isIExtendedErrorEvent(data.extra)) {
261
+ handleError$1(data);
259
262
  return;
260
263
  }
261
- handleCodeError(e);
264
+ handleCodeError(data.extra);
262
265
  };
263
- const handleWhiteScreen = () => {
264
- checkWhiteScreen((data) => {
266
+ const handleWhiteScreen = (data) => {
267
+ checkWhiteScreen(() => {
265
268
  reporter.send(data);
266
269
  });
267
270
  return;
268
271
  };
269
- const handleClick = (e) => {
270
- const str = e.target instanceof HTMLElement ? utils.dom2str(e.target) : "";
272
+ const handleClick = ({
273
+ extra,
274
+ ...rest
275
+ }) => {
276
+ const typedEvent = extra;
277
+ const str = typedEvent.target instanceof HTMLElement ? utils.dom2str(typedEvent.target) : "";
271
278
  breadcrumb.push({
272
- id: crypto.randomUUID(),
279
+ ...rest,
273
280
  type: types.EventType.Click,
274
281
  name: str,
275
282
  message: str,
276
- status: types.Status.OK,
277
- ...utils.getTime(),
278
283
  userAction: utils.event2breadcrumb(types.EventType.Click)
279
284
  });
280
285
  };
281
286
  const handleCodeError = (err) => {
282
287
  const { filename, colno: column, lineno: line, message } = err;
283
288
  const data = {
284
- id: crypto.randomUUID(),
289
+ ...utils.getBaseData(),
285
290
  type: types.EventType.Error,
286
291
  name: filename,
287
292
  message,
288
- status: types.Status.Error,
289
- ...utils.getTime()
293
+ status: types.Status.Error
290
294
  };
291
295
  const codeError = {
292
296
  ...data,
@@ -368,12 +372,20 @@ function decoratePublish(type) {
368
372
  function pubClick() {
369
373
  const throttledPub = utils.throttle(pub, utils.sentry.options.clickThrottleDelay);
370
374
  document.addEventListener("click", function(ctx) {
371
- throttledPub(types.EventType.Click, ctx);
375
+ throttledPub(types.EventType.Click, {
376
+ ...utils.getBaseData(),
377
+ type: types.EventType.Click,
378
+ extra: ctx
379
+ });
372
380
  });
373
381
  }
374
382
  function pubError() {
375
383
  globalThis.addEventListener("error", function(ctx) {
376
- pub(types.EventType.Error, ctx);
384
+ pub(types.EventType.Error, {
385
+ ...utils.getBaseData(),
386
+ type: types.EventType.Error,
387
+ extra: ctx
388
+ });
377
389
  });
378
390
  }
379
391
  function pubXhr() {
@@ -381,15 +393,12 @@ function pubXhr() {
381
393
  utils.decorateProp(xhrProto, "open", (oldPropVal) => {
382
394
  return function(method, url, async, ...rest) {
383
395
  const httpData = {
384
- id: crypto.randomUUID(),
396
+ ...utils.getBaseData(),
385
397
  name: "XMLHttpRequest",
386
- status: types.Status.OK,
387
398
  type: types.EventType.Xhr,
388
- ...utils.getTime(),
389
399
  method: method.toUpperCase(),
390
400
  api: url,
391
401
  elapsedTime: 0,
392
- message: "",
393
402
  statusCode: types.HttpStatusCode.OK
394
403
  };
395
404
  this.__sentry__ = httpData;
@@ -405,11 +414,11 @@ function pubXhr() {
405
414
  }
406
415
  const { status, responseType, response } = this;
407
416
  this.__sentry__.statusCode = status;
408
- this.__sentry__.requestData = body;
409
- this.__sentry__.responseData = JSON.stringify({
417
+ this.__sentry__.requestData = { body };
418
+ this.__sentry__.responseData = {
410
419
  responseType,
411
420
  response
412
- });
421
+ };
413
422
  const endTime = Date.now();
414
423
  this.__sentry__.elapsedTime = endTime - this.__sentry__.timestamp;
415
424
  pub(types.EventType.Xhr, this.__sentry__);
@@ -423,16 +432,13 @@ function pubFetch() {
423
432
  return async function(url, options) {
424
433
  const method = options?.method?.toUpperCase() ?? types.HttpMethod.Get;
425
434
  const httpData = {
426
- id: crypto.randomUUID(),
427
- ...utils.getTime(),
435
+ ...utils.getBaseData(),
428
436
  type: types.EventType.Fetch,
429
437
  method,
430
- requestData: options?.body,
438
+ requestData: { body: options?.body },
431
439
  name: "Fetch",
432
- status: types.Status.OK,
433
440
  api: url.toString(),
434
441
  elapsedTime: 0,
435
- message: "",
436
442
  statusCode: types.HttpStatusCode.OK
437
443
  };
438
444
  return oldPropVal.call(globalThis, url, options).then((res) => {
@@ -462,7 +468,12 @@ function pubHistory() {
462
468
  const from = latestHref;
463
469
  const to = document.location.href;
464
470
  latestHref = to;
465
- pub(types.EventType.History, { from, to });
471
+ pub(types.EventType.History, {
472
+ ...utils.getBaseData(),
473
+ type: types.EventType.History,
474
+ from,
475
+ to
476
+ });
466
477
  return oldOnpopstate.call(this, ev);
467
478
  };
468
479
  const historyDecorator = (oldPropsVal) => {
@@ -471,7 +482,12 @@ function pubHistory() {
471
482
  const from = latestHref;
472
483
  const to = url.toString();
473
484
  latestHref = to;
474
- pub(types.EventType.History, { from, to });
485
+ pub(types.EventType.History, {
486
+ ...utils.getBaseData(),
487
+ type: types.EventType.History,
488
+ from,
489
+ to
490
+ });
475
491
  }
476
492
  return oldPropsVal.call(this, data, unused, url);
477
493
  };
@@ -483,17 +499,29 @@ function pubUnhandledRejection() {
483
499
  globalThis.addEventListener(
484
500
  "unhandledrejection",
485
501
  function(ctx) {
486
- pub(types.EventType.UnhandledRejection, ctx);
502
+ pub(types.EventType.UnhandledRejection, {
503
+ ...utils.getBaseData(),
504
+ type: types.EventType.UnhandledRejection,
505
+ extra: ctx
506
+ });
487
507
  }
488
508
  );
489
509
  }
490
510
  function pubHashChange() {
491
511
  globalThis.addEventListener("hashchange", function(ctx) {
492
- pub(types.EventType.HashChange, ctx);
512
+ pub(types.EventType.HashChange, {
513
+ ...utils.getBaseData(),
514
+ type: types.EventType.HashChange,
515
+ extra: ctx
516
+ });
493
517
  });
494
518
  }
495
519
  function pubWhiteScreen() {
496
- pub(types.EventType.WhiteScreen);
520
+ pub(types.EventType.WhiteScreen, {
521
+ ...utils.getBaseData(),
522
+ type: types.EventType.WhiteScreen,
523
+ extra: "WhiteScreen"
524
+ });
497
525
  }
498
526
 
499
527
  function setup() {
@@ -3536,7 +3564,12 @@ function init(options) {
3536
3564
  const vuePlugin = (app, options) => {
3537
3565
  const handler = app.config.errorHandler;
3538
3566
  app.config.errorHandler = (err, vueInstance, info) => {
3539
- handleError$1(err);
3567
+ handleError$1({
3568
+ ...utils.getBaseData(),
3569
+ type: index_cjs.EventType.Vue,
3570
+ status: types.Status.Error,
3571
+ extra: err
3572
+ });
3540
3573
  if (handler) {
3541
3574
  handler.call(null, err, vueInstance, info);
3542
3575
  }
@@ -3545,9 +3578,14 @@ const vuePlugin = (app, options) => {
3545
3578
  };
3546
3579
  class ReactErrorBoundary extends reactExports.Component {
3547
3580
  componentDidCatch(error, errorInfo) {
3548
- handleError$1(error);
3549
- requestIdleCallback(() => {
3550
- handleError$1(errorInfo);
3581
+ handleError$1({
3582
+ ...utils.getBaseData(),
3583
+ type: index_cjs.EventType.React,
3584
+ status: types.Status.Error,
3585
+ extra: {
3586
+ error,
3587
+ errorInfo
3588
+ }
3551
3589
  });
3552
3590
  }
3553
3591
  }