@xifan0/monitor-rn 0.0.2-beta.16 → 0.0.2-beta.18

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.d.mts CHANGED
@@ -1,9 +1,34 @@
1
- import * as _xifan0_monitor_core from '@xifan0/monitor-core';
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$1 {
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
+ }
2
27
 
3
- declare const Monitor: _xifan0_monitor_core.Monitor;
28
+ declare const Monitor: Monitor$1;
4
29
  declare const init: (options: any) => any;
5
- declare const captureException: (error: Error, ctx?: _xifan0_monitor_core.CaptureContext) => any;
6
- declare const captureMessage: (message: string, ctx?: _xifan0_monitor_core.CaptureContext) => any;
7
- declare const setUser: (user: _xifan0_monitor_core.MonitorUser) => any;
30
+ declare const captureException: (error: Error, ctx?: CaptureContext) => any;
31
+ declare const captureMessage: (message: string, ctx?: CaptureContext) => any;
32
+ declare const setUser: (user: MonitorUser) => any;
8
33
 
9
34
  export { captureException, captureMessage, Monitor as default, init, setUser };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,34 @@
1
- import * as _xifan0_monitor_core from '@xifan0/monitor-core';
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$1 {
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
+ }
2
27
 
3
- declare const Monitor: _xifan0_monitor_core.Monitor;
28
+ declare const Monitor: Monitor$1;
4
29
  declare const init: (options: any) => any;
5
- declare const captureException: (error: Error, ctx?: _xifan0_monitor_core.CaptureContext) => any;
6
- declare const captureMessage: (message: string, ctx?: _xifan0_monitor_core.CaptureContext) => any;
7
- declare const setUser: (user: _xifan0_monitor_core.MonitorUser) => any;
30
+ declare const captureException: (error: Error, ctx?: CaptureContext) => any;
31
+ declare const captureMessage: (message: string, ctx?: CaptureContext) => any;
32
+ declare const setUser: (user: MonitorUser) => any;
8
33
 
9
34
  export { captureException, captureMessage, Monitor as default, init, setUser };
package/dist/index.js CHANGED
@@ -38,8 +38,60 @@ __export(index_exports, {
38
38
  });
39
39
  module.exports = __toCommonJS(index_exports);
40
40
  var Sentry = __toESM(require("@sentry/react-native"));
41
- var import_monitor_core = require("@xifan0/monitor-core");
42
- var Monitor = (0, import_monitor_core.createMonitor)(Sentry);
41
+
42
+ // ../monitor-core/src/createMonitor.ts
43
+ function createMonitor(sentry) {
44
+ const sentryInstance = (sentry == null ? void 0 : sentry.default) || sentry;
45
+ const monitor = {
46
+ init(options) {
47
+ if (!sentryInstance || typeof sentryInstance.init !== "function") {
48
+ throw new Error("Sentry.init is not a function");
49
+ }
50
+ return sentryInstance.init(options);
51
+ },
52
+ /** 上报异常 */
53
+ captureException(error, ctx) {
54
+ return sentryInstance.captureException(error, (scope) => {
55
+ (ctx == null ? void 0 : ctx.tags) && scope.setTags(ctx.tags);
56
+ (ctx == null ? void 0 : ctx.extra) && scope.setExtras(ctx.extra);
57
+ return scope;
58
+ });
59
+ },
60
+ /** 发送消息/提醒/日志 */
61
+ captureMessage(message, ctx) {
62
+ return sentryInstance.captureMessage(message, (scope) => {
63
+ (ctx == null ? void 0 : ctx.tags) && scope.setTags(ctx.tags);
64
+ (ctx == null ? void 0 : ctx.extra) && scope.setExtras(ctx.extra);
65
+ return scope;
66
+ });
67
+ },
68
+ /** 设置用户信息 */
69
+ setUser(user) {
70
+ return sentryInstance.setUser(user);
71
+ },
72
+ ErrorBoundary: sentryInstance.ErrorBoundary
73
+ };
74
+ const proxy = new Proxy(monitor, {
75
+ get(target, key, receiver) {
76
+ if (key in target) {
77
+ return Reflect.get(target, key, receiver);
78
+ }
79
+ const sentryFn = sentryInstance[key];
80
+ if (typeof sentryFn === "function") {
81
+ const isClass = sentryFn.prototype && sentryFn.prototype.constructor === sentryFn && Object.getOwnPropertyNames(sentryFn.prototype).length > 1;
82
+ if (isClass) {
83
+ return sentryFn;
84
+ }
85
+ return sentryFn.bind(sentryInstance);
86
+ }
87
+ return sentryFn;
88
+ }
89
+ });
90
+ return proxy;
91
+ }
92
+
93
+ // src/index.ts
94
+ var Monitor = createMonitor(Sentry);
43
95
  var { init, captureException, captureMessage, setUser } = Monitor;
44
96
  var index_default = Monitor;
45
97
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.mjs CHANGED
@@ -1,6 +1,58 @@
1
1
  // src/index.ts
2
2
  import * as Sentry from "@sentry/react-native";
3
- import { createMonitor } from "@xifan0/monitor-core";
3
+
4
+ // ../monitor-core/src/createMonitor.ts
5
+ function createMonitor(sentry) {
6
+ const sentryInstance = (sentry == null ? void 0 : sentry.default) || sentry;
7
+ const monitor = {
8
+ init(options) {
9
+ if (!sentryInstance || typeof sentryInstance.init !== "function") {
10
+ throw new Error("Sentry.init is not a function");
11
+ }
12
+ return sentryInstance.init(options);
13
+ },
14
+ /** 上报异常 */
15
+ captureException(error, ctx) {
16
+ return sentryInstance.captureException(error, (scope) => {
17
+ (ctx == null ? void 0 : ctx.tags) && scope.setTags(ctx.tags);
18
+ (ctx == null ? void 0 : ctx.extra) && scope.setExtras(ctx.extra);
19
+ return scope;
20
+ });
21
+ },
22
+ /** 发送消息/提醒/日志 */
23
+ captureMessage(message, ctx) {
24
+ return sentryInstance.captureMessage(message, (scope) => {
25
+ (ctx == null ? void 0 : ctx.tags) && scope.setTags(ctx.tags);
26
+ (ctx == null ? void 0 : ctx.extra) && scope.setExtras(ctx.extra);
27
+ return scope;
28
+ });
29
+ },
30
+ /** 设置用户信息 */
31
+ setUser(user) {
32
+ return sentryInstance.setUser(user);
33
+ },
34
+ ErrorBoundary: sentryInstance.ErrorBoundary
35
+ };
36
+ const proxy = new Proxy(monitor, {
37
+ get(target, key, receiver) {
38
+ if (key in target) {
39
+ return Reflect.get(target, key, receiver);
40
+ }
41
+ const sentryFn = sentryInstance[key];
42
+ if (typeof sentryFn === "function") {
43
+ const isClass = sentryFn.prototype && sentryFn.prototype.constructor === sentryFn && Object.getOwnPropertyNames(sentryFn.prototype).length > 1;
44
+ if (isClass) {
45
+ return sentryFn;
46
+ }
47
+ return sentryFn.bind(sentryInstance);
48
+ }
49
+ return sentryFn;
50
+ }
51
+ });
52
+ return proxy;
53
+ }
54
+
55
+ // src/index.ts
4
56
  var Monitor = createMonitor(Sentry);
5
57
  var { init, captureException, captureMessage, setUser } = Monitor;
6
58
  var index_default = Monitor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xifan0/monitor-rn",
3
- "version": "0.0.2-beta.16",
3
+ "version": "0.0.2-beta.18",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -24,13 +24,12 @@
24
24
  "@sentry/react-native": "^5"
25
25
  },
26
26
  "dependencies": {
27
- "@sentry/react-native": "^5",
28
- "@xifan0/monitor-core": "0.0.2-beta.16"
27
+ "@sentry/react-native": "^5"
29
28
  },
30
29
  "devDependencies": {
31
- "@sentry/react-native": "^5",
32
30
  "typescript": "^5",
33
- "tsup": "^8.5.1"
31
+ "tsup": "^8.5.1",
32
+ "@xifan0/monitor-core": "0.0.2-beta.18"
34
33
  },
35
34
  "scripts": {
36
35
  "build": "tsup --dts"