@error-reporting/vue 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 ADDED
@@ -0,0 +1,21 @@
1
+ # @error-reporting/vue
2
+
3
+ ```sh
4
+ npm install @error-reporting/vue
5
+ ```
6
+
7
+ ```js
8
+ import { createApp } from 'vue'
9
+ import { Init, CaptureException } from '@error-reporting/vue'
10
+ import App from './App.vue'
11
+
12
+ const app = createApp(App)
13
+ Init({ app, dsn: import.meta.env.VITE_ERROR_REPORTING_DSN, environment: import.meta.env.MODE })
14
+ app.mount('#app')
15
+
16
+ CaptureException(new Error('上报接入测试'), { requestId: 'request-42' })
17
+ ```
18
+
19
+ 在挂载前初始化一次,并在工作台配置页面的实际 Origin。SDK 会捕获 Vue 组件未处理异常,业务捕获的异常可调用 `CaptureException` 补报。可用 `Flush(timeoutMs)` 等待当前发送队列。
20
+
21
+ 从 0.1.x 升级时,把入口替换成示例中的大写开头写法。
package/index.d.ts CHANGED
@@ -2,5 +2,6 @@ import type { App } from 'vue'
2
2
  import type { CaptureContext, Options } from '@error-reporting/core'
3
3
 
4
4
  export type { CaptureContext, Options, ReportEvent } from '@error-reporting/core'
5
- export function init(options: Options & { app: App }): void
6
- export function captureException(error: unknown, context?: CaptureContext): string
5
+ export function Init(options: Options & { app: App }): void
6
+ export function CaptureException(error: unknown, context?: CaptureContext): string
7
+ export function Flush(timeout?: number): PromiseLike<boolean>
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@error-reporting/vue",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Error Reporting Platform SDK for Vue 3",
5
5
  "type": "module",
6
6
  "exports": { ".": { "types": "./index.d.ts", "default": "./src/index.js" } },
7
7
  "files": ["src", "index.d.ts"],
8
- "dependencies": { "@error-reporting/core": "0.1.0", "@sentry/vue": "^11.17.0" },
8
+ "dependencies": { "@error-reporting/core": "0.2.0", "@sentry/vue": "^11.17.0" },
9
9
  "peerDependencies": { "vue": "^3.0.0" },
10
10
  "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" },
11
11
  "repository": { "type": "git", "url": "git+https://gitee.com/qglove/error-reporting-platform.git", "directory": "packages/javascript/vue" }
package/src/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import * as Sentry from '@sentry/vue'
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
  /** 在 Vue 3 应用挂载前安装组件和浏览器全局异常监听。
7
7
  * @param {import('@error-reporting/core').Options & { app: import('vue').App }} options Vue 应用及错误上报配置。
8
8
  */
9
- export function init({ app, ...options }) {
9
+ export function Init({ app, ...options }) {
10
10
  if (!app?.config) {
11
11
  throw new Error('A Vue 3 app is required')
12
12
  }
@@ -15,7 +15,7 @@ export function init({ app, ...options }) {
15
15
  throw new Error('Vue error reporting is already initialized')
16
16
  }
17
17
 
18
- Sentry.init({ app, attachProps: false, ...createReportOptions(options, 'vue') })
18
+ Sentry.init({ app, attachProps: false, ...CreateReportOptions(options, 'vue') })
19
19
 
20
20
  initialized = true
21
21
  }
@@ -24,6 +24,13 @@ export function init({ app, ...options }) {
24
24
  * @param {unknown} error 原始异常或拒绝原因。
25
25
  * @param {import('@error-reporting/core').CaptureContext} context 诊断用请求编号。
26
26
  */
27
- export function captureException(error, context = {}) {
27
+ export function CaptureException(error, context = {}) {
28
28
  return Sentry.captureException(error, context.requestId ? { tags: { request_id: context.requestId } } : undefined)
29
29
  }
30
+
31
+ /** 等待当前上报队列发送完毕。
32
+ * @param {number} timeout 等待毫秒数。
33
+ */
34
+ export function Flush(timeout = 2000) {
35
+ return Sentry.flush(timeout)
36
+ }