@error-reporting/node 0.0.0-stage → 0.1.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/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { CaptureContext, Options } from '@error-reporting/core'
2
+
3
+ export type { CaptureContext, Options, ReportEvent } from '@error-reporting/core'
4
+ export function init(options?: Options): void
5
+ export function captureException(error: unknown, context?: CaptureContext): string
6
+ export function flush(timeout?: number): PromiseLike<boolean>
package/package.json CHANGED
@@ -1,6 +1,12 @@
1
1
  {
2
2
  "name": "@error-reporting/node",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Error Reporting Platform SDK for Node.js",
5
+ "type": "module",
6
+ "engines": { "node": ">=22.12.0 <23 || >=23.2.0" },
7
+ "exports": { ".": { "types": "./index.d.ts", "default": "./src/index.js" } },
8
+ "files": ["src", "index.d.ts"],
9
+ "dependencies": { "@error-reporting/core": "0.1.0", "@sentry/node": "^11.17.0" },
10
+ "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" },
11
+ "repository": { "type": "git", "url": "git+https://gitee.com/qglove/error-reporting-platform.git", "directory": "packages/javascript/node" }
12
+ }
package/src/index.js ADDED
@@ -0,0 +1,40 @@
1
+ import * as Sentry from '@sentry/node'
2
+ import { createReportOptions } from '@error-reporting/core'
3
+
4
+ let initialized = false
5
+
6
+ /** 在 Node.js 业务入口加载前安装默认异常监听。
7
+ * @param {import('@error-reporting/core').Options} options 显式配置优先于服务器环境变量。
8
+ */
9
+ export function init(options = {}) {
10
+ const config = createReportOptions({
11
+ dsn: process.env.ERROR_REPORTING_DSN,
12
+ environment: process.env.NODE_ENV ?? 'development',
13
+ release: process.env.ERROR_REPORTING_RELEASE,
14
+ service: process.env.ERROR_REPORTING_SERVICE,
15
+ ...options,
16
+ }, 'node')
17
+
18
+ if (initialized) {
19
+ throw new Error('Node.js error reporting is already initialized')
20
+ }
21
+
22
+ Sentry.init(config)
23
+
24
+ initialized = true
25
+ }
26
+
27
+ /** 上报已被业务接住的错误。
28
+ * @param {unknown} error 原始异常或拒绝原因。
29
+ * @param {import('@error-reporting/core').CaptureContext} context 诊断用请求编号。
30
+ */
31
+ export function captureException(error, context = {}) {
32
+ return Sentry.captureException(error, context.requestId ? { tags: { request_id: context.requestId } } : undefined)
33
+ }
34
+
35
+ /** 等待待发送队列,适用于进程优雅退出和短脚本。
36
+ * @param {number} timeout 等待毫秒数。
37
+ */
38
+ export function flush(timeout = 2000) {
39
+ return Sentry.flush(timeout)
40
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.