@xifan0/monitor-core 0.0.1 → 0.0.2-beta.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.
@@ -0,0 +1,30 @@
1
+ interface MonitorUser {
2
+ id?: string;
3
+ email?: string;
4
+ username?: string;
5
+ [key: string]: string | undefined;
6
+ }
7
+ interface CaptureContext {
8
+ tags?: Record<string, string>;
9
+ extra?: Record<string, any>;
10
+ }
11
+ interface Monitor {
12
+ init(options: any): any;
13
+ /** 上报异常 */
14
+ captureException(error: Error, ctx?: CaptureContext): any;
15
+ /** 发送消息/提醒/日志 */
16
+ captureMessage(message: string, ctx?: CaptureContext): any;
17
+ /** 设置用户信息 */
18
+ setUser(user: MonitorUser): any;
19
+ /** sentry事件 */
20
+ addBreadcrumb?(crumb: any): any;
21
+ setTag?(key: string, value: string): any;
22
+ setContext?(key: string, ctx: any): any;
23
+ withScope?(cb: (scope: any) => void): any;
24
+ /** 未声明事件的调用 */
25
+ [key: string]: any;
26
+ }
27
+
28
+ declare function createMonitor<TOptions = any>(sentry: any): Monitor;
29
+
30
+ export { type CaptureContext, type Monitor, type MonitorUser, createMonitor };
@@ -0,0 +1,30 @@
1
+ interface MonitorUser {
2
+ id?: string;
3
+ email?: string;
4
+ username?: string;
5
+ [key: string]: string | undefined;
6
+ }
7
+ interface CaptureContext {
8
+ tags?: Record<string, string>;
9
+ extra?: Record<string, any>;
10
+ }
11
+ interface Monitor {
12
+ init(options: any): any;
13
+ /** 上报异常 */
14
+ captureException(error: Error, ctx?: CaptureContext): any;
15
+ /** 发送消息/提醒/日志 */
16
+ captureMessage(message: string, ctx?: CaptureContext): any;
17
+ /** 设置用户信息 */
18
+ setUser(user: MonitorUser): any;
19
+ /** sentry事件 */
20
+ addBreadcrumb?(crumb: any): any;
21
+ setTag?(key: string, value: string): any;
22
+ setContext?(key: string, ctx: any): any;
23
+ withScope?(cb: (scope: any) => void): any;
24
+ /** 未声明事件的调用 */
25
+ [key: string]: any;
26
+ }
27
+
28
+ declare function createMonitor<TOptions = any>(sentry: any): Monitor;
29
+
30
+ export { type CaptureContext, type Monitor, type MonitorUser, createMonitor };
package/dist/index.js ADDED
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ createMonitor: () => createMonitor
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/createMonitor.ts
28
+ function createMonitor(sentry) {
29
+ const monitor = {
30
+ init(options) {
31
+ return sentry.init(options);
32
+ },
33
+ /** 上报异常 */
34
+ captureException(error, ctx) {
35
+ return sentry.captureException(error, (scope) => {
36
+ (ctx == null ? void 0 : ctx.tags) && scope.setTags(ctx.tags);
37
+ (ctx == null ? void 0 : ctx.extra) && scope.setExtras(ctx.extra);
38
+ return scope;
39
+ });
40
+ },
41
+ /** 发送消息/提醒/日志 */
42
+ captureMessage(message, ctx) {
43
+ return sentry.captureMessage(message, (scope) => {
44
+ (ctx == null ? void 0 : ctx.tags) && scope.setTags(ctx.tags);
45
+ (ctx == null ? void 0 : ctx.extra) && scope.setExtras(ctx.extra);
46
+ return scope;
47
+ });
48
+ },
49
+ /** 设置用户信息 */
50
+ setUser(user) {
51
+ return sentry.setUser(user);
52
+ }
53
+ };
54
+ const proxy = new Proxy(monitor, {
55
+ get(target, key, receiver) {
56
+ if (key in target) {
57
+ return Reflect.get(target, key, receiver);
58
+ }
59
+ const sentryFn = sentry[key];
60
+ if (typeof sentryFn === "function") {
61
+ const isClass = sentryFn.prototype && sentryFn.prototype.constructor === sentryFn && Object.getOwnPropertyNames(sentryFn.prototype).length > 1;
62
+ if (isClass) {
63
+ return sentryFn;
64
+ }
65
+ return sentryFn.bind(sentry);
66
+ }
67
+ return sentryFn;
68
+ }
69
+ });
70
+ return proxy;
71
+ }
72
+ // Annotate the CommonJS export names for ESM import in node:
73
+ 0 && (module.exports = {
74
+ createMonitor
75
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,48 @@
1
+ // src/createMonitor.ts
2
+ function createMonitor(sentry) {
3
+ const monitor = {
4
+ init(options) {
5
+ return sentry.init(options);
6
+ },
7
+ /** 上报异常 */
8
+ captureException(error, ctx) {
9
+ return sentry.captureException(error, (scope) => {
10
+ (ctx == null ? void 0 : ctx.tags) && scope.setTags(ctx.tags);
11
+ (ctx == null ? void 0 : ctx.extra) && scope.setExtras(ctx.extra);
12
+ return scope;
13
+ });
14
+ },
15
+ /** 发送消息/提醒/日志 */
16
+ captureMessage(message, ctx) {
17
+ return sentry.captureMessage(message, (scope) => {
18
+ (ctx == null ? void 0 : ctx.tags) && scope.setTags(ctx.tags);
19
+ (ctx == null ? void 0 : ctx.extra) && scope.setExtras(ctx.extra);
20
+ return scope;
21
+ });
22
+ },
23
+ /** 设置用户信息 */
24
+ setUser(user) {
25
+ return sentry.setUser(user);
26
+ }
27
+ };
28
+ const proxy = new Proxy(monitor, {
29
+ get(target, key, receiver) {
30
+ if (key in target) {
31
+ return Reflect.get(target, key, receiver);
32
+ }
33
+ const sentryFn = sentry[key];
34
+ if (typeof sentryFn === "function") {
35
+ const isClass = sentryFn.prototype && sentryFn.prototype.constructor === sentryFn && Object.getOwnPropertyNames(sentryFn.prototype).length > 1;
36
+ if (isClass) {
37
+ return sentryFn;
38
+ }
39
+ return sentryFn.bind(sentry);
40
+ }
41
+ return sentryFn;
42
+ }
43
+ });
44
+ return proxy;
45
+ }
46
+ export {
47
+ createMonitor
48
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xifan0/monitor-core",
3
- "version": "0.0.1",
3
+ "version": "0.0.2-beta.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",