@error-reporting/browser 0.1.0 → 0.2.0

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/README.md CHANGED
@@ -11,10 +11,10 @@ npm install @error-reporting/browser
11
11
  ```
12
12
 
13
13
  ```js
14
- import { init, captureException } from '@error-reporting/browser'
14
+ import { Init, CaptureException } from '@error-reporting/browser'
15
15
 
16
- init({ dsn: '粘贴 web DSN', environment: 'production' })
17
- captureException(new Error('上报接入测试'))
16
+ Init({ dsn: '粘贴 web DSN', environment: 'production' })
17
+ CaptureException(new Error('上报接入测试'))
18
18
  ```
19
19
 
20
20
  ## 普通 HTML
@@ -22,11 +22,11 @@ captureException(new Error('上报接入测试'))
22
22
  从 npm 包中复制 `dist/error-reporting.js` 到静态站点,再在业务脚本之前加载。也可以从 npm CDN 引用固定版本。
23
23
 
24
24
  ```html
25
- <script src="https://cdn.jsdelivr.net/npm/@error-reporting/browser@0.1.0/dist/error-reporting.js"></script>
25
+ <script src="https://cdn.jsdelivr.net/npm/@error-reporting/browser@0.2.0/dist/error-reporting.js"></script>
26
26
  <script>
27
- ErrorReporting.init({ dsn: '粘贴 web DSN', environment: 'production' });
28
- ErrorReporting.captureException(new Error('上报接入测试'));
27
+ ErrorReporting.Init({ dsn: '粘贴 web DSN', environment: 'production' });
28
+ ErrorReporting.CaptureException(new Error('上报接入测试'));
29
29
  </script>
30
30
  ```
31
31
 
32
- 初始化一次即可,生产页面移除测试异常。若需等待发送队列,可调用 `flush(timeout)`,超时返回 `false`。
32
+ 初始化一次即可,生产页面移除测试异常。若需等待发送队列,可调用 `Flush(timeout)`,超时返回 `false`。
@@ -1,4 +1,4 @@
1
- "use strict";var ErrorReporting=(()=>{var Kt=Object.defineProperty;var Na=Object.getOwnPropertyDescriptor;var Ca=Object.getOwnPropertyNames;var La=Object.prototype.hasOwnProperty;var Pa=(e,t)=>{for(var i in t)Kt(e,i,{get:t[i],enumerable:!0})},Da=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ca(t))!La.call(e,n)&&n!==i&&Kt(e,n,{get:()=>t[n],enumerable:!(r=Na(t,n))||r.enumerable});return e};var Ma=e=>Da(Kt({},"__esModule",{value:!0}),e);var wc={};Pa(wc,{captureException:()=>Ac,flush:()=>Oc,init:()=>Ic});var u=typeof __SENTRY_DEBUG__>"u"||__SENTRY_DEBUG__;var b=globalThis;var se="11.17.0";function K(){return ee(b),b}function ee(e){let t=e.__SENTRY__=e.__SENTRY__||{};return t.version=t.version||"11.17.0",t[se]=t["11.17.0"]||{}}function de(e,t,i=b){let r=i.__SENTRY__=i.__SENTRY__||{},n=r[se]=r["11.17.0"]||{};return n[e]||(n[e]=t())}var Fe=["debug","info","warn","error","log","assert","trace"],Ua="Sentry Logger ",we={};function C(e){if(!("console"in b))return e();let t=b.console,i={},r=Object.keys(we);r.forEach(n=>{let s=we[n];i[n]=t[n],t[n]=s});try{return e()}finally{r.forEach(n=>{t[n]=i[n]})}}function qa(){Vt().enabled=!0}function Ba(){Vt().enabled=!1}function Sr(){return Vt().enabled}function Ga(...e){Wt("log",...e)}function Fa(...e){Wt("warn",...e)}function Ha(...e){Wt("error",...e)}function Wt(e,...t){u&&Sr()&&C(()=>{b.console[e](`${Ua}[${e}]:`,...t)})}function Vt(){return u?de("loggerSettings",()=>({enabled:!1})):{enabled:!1}}var d={enable:qa,disable:Ba,isEnabled:Sr,log:Ga,warn:Fa,error:Ha};var kr=/\(error: (.*)\)/,Er=/captureMessage|captureException/;function gt(...e){let t=e.sort((i,r)=>i[0]-r[0]).map(i=>i[1]);return(i,r=0,n=0)=>{let s=[],a=i.split(`
1
+ "use strict";var ErrorReporting=(()=>{var Kt=Object.defineProperty;var Na=Object.getOwnPropertyDescriptor;var Ca=Object.getOwnPropertyNames;var La=Object.prototype.hasOwnProperty;var Pa=(e,t)=>{for(var i in t)Kt(e,i,{get:t[i],enumerable:!0})},Da=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ca(t))!La.call(e,n)&&n!==i&&Kt(e,n,{get:()=>t[n],enumerable:!(r=Na(t,n))||r.enumerable});return e};var Ma=e=>Da(Kt({},"__esModule",{value:!0}),e);var wc={};Pa(wc,{CaptureException:()=>Ac,Flush:()=>Oc,Init:()=>Ic});var u=typeof __SENTRY_DEBUG__>"u"||__SENTRY_DEBUG__;var b=globalThis;var se="11.17.0";function K(){return ee(b),b}function ee(e){let t=e.__SENTRY__=e.__SENTRY__||{};return t.version=t.version||"11.17.0",t[se]=t["11.17.0"]||{}}function de(e,t,i=b){let r=i.__SENTRY__=i.__SENTRY__||{},n=r[se]=r["11.17.0"]||{};return n[e]||(n[e]=t())}var Fe=["debug","info","warn","error","log","assert","trace"],Ua="Sentry Logger ",we={};function C(e){if(!("console"in b))return e();let t=b.console,i={},r=Object.keys(we);r.forEach(n=>{let s=we[n];i[n]=t[n],t[n]=s});try{return e()}finally{r.forEach(n=>{t[n]=i[n]})}}function qa(){Vt().enabled=!0}function Ba(){Vt().enabled=!1}function Sr(){return Vt().enabled}function Ga(...e){Wt("log",...e)}function Fa(...e){Wt("warn",...e)}function Ha(...e){Wt("error",...e)}function Wt(e,...t){u&&Sr()&&C(()=>{b.console[e](`${Ua}[${e}]:`,...t)})}function Vt(){return u?de("loggerSettings",()=>({enabled:!1})):{enabled:!1}}var d={enable:qa,disable:Ba,isEnabled:Sr,log:Ga,warn:Fa,error:Ha};var kr=/\(error: (.*)\)/,Er=/captureMessage|captureException/;function gt(...e){let t=e.sort((i,r)=>i[0]-r[0]).map(i=>i[1]);return(i,r=0,n=0)=>{let s=[],a=i.split(`
2
2
  `);for(let o=r;o<a.length;o++){let l=a[o];l.length>1024&&(l=l.slice(0,1024));let p=kr.test(l)?l.replace(kr,"$1"):l;if(!p.includes("Error: ")){for(let c of t){let g=c(p);if(g){s.push(g);break}}if(s.length>=50+n)break}}return Tr(s.slice(n))}}function $t(e){return Array.isArray(e)?gt(...e):e}function Tr(e){if(!e.length)return[];let t=Array.from(e);return/sentryWrapped/.test(mt(t).function||"")&&t.pop(),t.reverse(),Er.test(mt(t).function||"")&&(t.pop(),Er.test(mt(t).function||"")&&t.pop()),t.slice(0,50).map(i=>({...i,filename:i.filename||mt(t).filename,function:i.function||"?"}))}function mt(e){return e[e.length-1]||{}}var Qt="<anonymous>";function G(e){try{return!e||typeof e!="function"?Qt:e.name||Qt}catch{return Qt}}function bt(e){let t=e.exception;if(t){let i=[];try{return t.values.forEach(r=>{r.stacktrace.frames&&i.push(...r.stacktrace.frames)}),i}catch{return}}}var He={},Ir={};function L(e,t){return He[e]=He[e]||[],He[e].push(t),()=>{let i=He[e];if(i){let r=i.indexOf(t);r!==-1&&i.splice(r,1)}}}function P(e,t){if(!Ir[e]){Ir[e]=!0;try{t()}catch(i){u&&d.error(`Error while instrumenting ${e}`,i)}}}function E(e,t){let i=e&&He[e];if(i)for(let r of i)try{r(t)}catch(n){u&&d.error(`Error while triggering instrumentation handler.
3
3
  Type: ${e}
4
4
  Name: ${G(r)}
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { CaptureContext, Options } from '@error-reporting/core'
2
2
 
3
3
  export type { CaptureContext, Options, ReportEvent } from '@error-reporting/core'
4
- export function init(options: Options & { dsn: string }): void
5
- export function captureException(error: unknown, context?: CaptureContext): string
6
- export function flush(timeout?: number): Promise<boolean>
4
+ export function Init(options: Options & { dsn: string }): void
5
+ export function CaptureException(error: unknown, context?: CaptureContext): string
6
+ export function Flush(timeout?: number): Promise<boolean>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@error-reporting/browser",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Framework-free Error Reporting Platform SDK for browsers",
5
5
  "type": "module",
6
6
  "exports": { ".": { "types": "./index.d.ts", "default": "./src/index.js" } },
@@ -10,7 +10,7 @@
10
10
  "scripts": {
11
11
  "prepack": "esbuild src/index.js --bundle --minify --platform=browser --target=es2022 --format=iife --global-name=ErrorReporting --outfile=dist/error-reporting.js"
12
12
  },
13
- "dependencies": { "@error-reporting/core": "0.1.0", "@sentry/browser": "^11.17.0" },
13
+ "dependencies": { "@error-reporting/core": "0.2.0", "@sentry/browser": "^11.17.0" },
14
14
  "devDependencies": { "esbuild": "^0.28.2" },
15
15
  "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" },
16
16
  "repository": { "type": "git", "url": "git+https://gitee.com/qglove/error-reporting-platform.git", "directory": "packages/javascript/browser" }
package/src/index.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import * as Sentry from '@sentry/browser'
2
- import { createReportOptions } from '@error-reporting/core'
2
+ import { CreateReportOptions } from '@error-reporting/core'
3
3
 
4
4
  let initialized = false
5
5
 
6
6
  /** 安装浏览器全局异常监听。
7
7
  * @param {import('@error-reporting/core').Options & { dsn: string }} options 项目 DSN 和诊断配置。
8
8
  */
9
- export function init(options) {
9
+ export function Init(options) {
10
10
  if (initialized) {
11
11
  throw new Error('Browser error reporting is already initialized')
12
12
  }
13
13
 
14
- Sentry.init(createReportOptions(options, 'browser'))
14
+ Sentry.init(CreateReportOptions(options, 'browser'))
15
15
  initialized = true
16
16
  }
17
17
 
@@ -19,13 +19,13 @@ export function init(options) {
19
19
  * @param {unknown} error 原始异常或拒绝原因。
20
20
  * @param {import('@error-reporting/core').CaptureContext} context 可选的业务请求编号。
21
21
  */
22
- export function captureException(error, context = {}) {
22
+ export function CaptureException(error, context = {}) {
23
23
  return Sentry.captureException(error, context.requestId ? { tags: { request_id: context.requestId } } : undefined)
24
24
  }
25
25
 
26
26
  /** 等待当前上报队列发送完毕。
27
27
  * @param {number} timeout 等待毫秒数。
28
28
  */
29
- export function flush(timeout = 2000) {
29
+ export function Flush(timeout = 2000) {
30
30
  return Sentry.flush(timeout)
31
31
  }