@zhongxiaobing/monitor 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/dist/index.d.mts +129 -0
- package/dist/index.d.ts +129 -0
- package/dist/index.js +690 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +661 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +39 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
type MonitorEventType = 'exception' | 'resource_error' | 'http_error' | 'blank_screen';
|
|
2
|
+
interface Breadcrumb {
|
|
3
|
+
type: string;
|
|
4
|
+
category?: string;
|
|
5
|
+
message?: string;
|
|
6
|
+
timestamp: number;
|
|
7
|
+
data?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
interface BaseEvent {
|
|
10
|
+
eventId: string;
|
|
11
|
+
eventType: MonitorEventType;
|
|
12
|
+
appId: string;
|
|
13
|
+
appName?: string;
|
|
14
|
+
env: string;
|
|
15
|
+
release?: string;
|
|
16
|
+
url: string;
|
|
17
|
+
pathname: string;
|
|
18
|
+
title: string;
|
|
19
|
+
timestamp: number;
|
|
20
|
+
userAgent: string;
|
|
21
|
+
userId?: string;
|
|
22
|
+
deviceId?: string;
|
|
23
|
+
breadcrumbs?: Breadcrumb[];
|
|
24
|
+
tags?: Record<string, string>;
|
|
25
|
+
extra?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
interface ExceptionEvent extends BaseEvent {
|
|
28
|
+
eventType: 'exception';
|
|
29
|
+
error: {
|
|
30
|
+
name?: string;
|
|
31
|
+
message: string;
|
|
32
|
+
stack?: string;
|
|
33
|
+
source?: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
interface HttpErrorEvent extends BaseEvent {
|
|
37
|
+
eventType: 'http_error';
|
|
38
|
+
request: {
|
|
39
|
+
url: string;
|
|
40
|
+
method: string;
|
|
41
|
+
status?: number;
|
|
42
|
+
duration?: number;
|
|
43
|
+
success: boolean;
|
|
44
|
+
source?: 'fetch' | 'xhr';
|
|
45
|
+
};
|
|
46
|
+
response?: {
|
|
47
|
+
code?: string | number;
|
|
48
|
+
message?: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
interface BlankScreenEvent extends BaseEvent {
|
|
52
|
+
eventType: 'blank_screen';
|
|
53
|
+
blankScreen: {
|
|
54
|
+
score: number;
|
|
55
|
+
rootSelector?: string;
|
|
56
|
+
domSummary?: string[];
|
|
57
|
+
readyState?: string;
|
|
58
|
+
trigger?: 'initial' | 'route_change' | 'manual';
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
type MonitorEvent = ExceptionEvent | HttpErrorEvent | BlankScreenEvent;
|
|
62
|
+
|
|
63
|
+
interface MonitorApi {
|
|
64
|
+
emit(event: MonitorEvent): void;
|
|
65
|
+
captureException(error: unknown, extra?: Record<string, unknown>): void;
|
|
66
|
+
}
|
|
67
|
+
interface PluginSetupContext {
|
|
68
|
+
api: MonitorApi;
|
|
69
|
+
options: MonitorInitOptions;
|
|
70
|
+
}
|
|
71
|
+
interface MonitorPlugin {
|
|
72
|
+
name: string;
|
|
73
|
+
setup(context: PluginSetupContext): void | (() => void);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface MonitorInitOptions {
|
|
77
|
+
appId: string;
|
|
78
|
+
appName?: string;
|
|
79
|
+
env: string;
|
|
80
|
+
release?: string;
|
|
81
|
+
dsn: string;
|
|
82
|
+
sampleRate?: number;
|
|
83
|
+
plugins?: MonitorPlugin[];
|
|
84
|
+
beforeSend?: (event: MonitorEvent) => MonitorEvent | null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
declare class Monitor implements MonitorApi {
|
|
88
|
+
private queue;
|
|
89
|
+
private options;
|
|
90
|
+
private context;
|
|
91
|
+
private disposePlugins;
|
|
92
|
+
constructor(options: MonitorInitOptions);
|
|
93
|
+
emit(event: MonitorEvent): void;
|
|
94
|
+
captureException(error: unknown, extra?: Record<string, unknown>): void;
|
|
95
|
+
flush(): Promise<void>;
|
|
96
|
+
destroy(): void;
|
|
97
|
+
}
|
|
98
|
+
declare function initMonitor(options: MonitorInitOptions): Monitor;
|
|
99
|
+
|
|
100
|
+
interface ErrorPluginOptions {
|
|
101
|
+
captureOnError?: boolean;
|
|
102
|
+
captureUnhandledRejection?: boolean;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
declare function errorPlugin(options?: ErrorPluginOptions): MonitorPlugin;
|
|
106
|
+
|
|
107
|
+
interface NetworkPluginOptions {
|
|
108
|
+
timeoutMs?: number;
|
|
109
|
+
capture5xx?: boolean;
|
|
110
|
+
captureTimeout?: boolean;
|
|
111
|
+
captureNetworkError?: boolean;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
declare function networkPlugin(options?: NetworkPluginOptions): MonitorPlugin;
|
|
115
|
+
|
|
116
|
+
interface BlankScreenPluginOptions {
|
|
117
|
+
rootSelector?: string;
|
|
118
|
+
delayMs?: number;
|
|
119
|
+
scoreThreshold?: number;
|
|
120
|
+
samplePoints?: Array<[number, number]>;
|
|
121
|
+
ignoreSelectors?: string[];
|
|
122
|
+
detectOnRouteChange?: boolean;
|
|
123
|
+
routeChangeDelayMs?: number;
|
|
124
|
+
dedupeWindowMs?: number;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
declare function blankScreenPlugin(options?: BlankScreenPluginOptions): MonitorPlugin;
|
|
128
|
+
|
|
129
|
+
export { type BaseEvent, type BlankScreenEvent, type BlankScreenPluginOptions, type Breadcrumb, type ErrorPluginOptions, type ExceptionEvent, type HttpErrorEvent, Monitor, type MonitorApi, type MonitorEvent, type MonitorEventType, type MonitorInitOptions, type MonitorPlugin, type NetworkPluginOptions, type PluginSetupContext, blankScreenPlugin, errorPlugin, initMonitor, networkPlugin };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
type MonitorEventType = 'exception' | 'resource_error' | 'http_error' | 'blank_screen';
|
|
2
|
+
interface Breadcrumb {
|
|
3
|
+
type: string;
|
|
4
|
+
category?: string;
|
|
5
|
+
message?: string;
|
|
6
|
+
timestamp: number;
|
|
7
|
+
data?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
interface BaseEvent {
|
|
10
|
+
eventId: string;
|
|
11
|
+
eventType: MonitorEventType;
|
|
12
|
+
appId: string;
|
|
13
|
+
appName?: string;
|
|
14
|
+
env: string;
|
|
15
|
+
release?: string;
|
|
16
|
+
url: string;
|
|
17
|
+
pathname: string;
|
|
18
|
+
title: string;
|
|
19
|
+
timestamp: number;
|
|
20
|
+
userAgent: string;
|
|
21
|
+
userId?: string;
|
|
22
|
+
deviceId?: string;
|
|
23
|
+
breadcrumbs?: Breadcrumb[];
|
|
24
|
+
tags?: Record<string, string>;
|
|
25
|
+
extra?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
interface ExceptionEvent extends BaseEvent {
|
|
28
|
+
eventType: 'exception';
|
|
29
|
+
error: {
|
|
30
|
+
name?: string;
|
|
31
|
+
message: string;
|
|
32
|
+
stack?: string;
|
|
33
|
+
source?: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
interface HttpErrorEvent extends BaseEvent {
|
|
37
|
+
eventType: 'http_error';
|
|
38
|
+
request: {
|
|
39
|
+
url: string;
|
|
40
|
+
method: string;
|
|
41
|
+
status?: number;
|
|
42
|
+
duration?: number;
|
|
43
|
+
success: boolean;
|
|
44
|
+
source?: 'fetch' | 'xhr';
|
|
45
|
+
};
|
|
46
|
+
response?: {
|
|
47
|
+
code?: string | number;
|
|
48
|
+
message?: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
interface BlankScreenEvent extends BaseEvent {
|
|
52
|
+
eventType: 'blank_screen';
|
|
53
|
+
blankScreen: {
|
|
54
|
+
score: number;
|
|
55
|
+
rootSelector?: string;
|
|
56
|
+
domSummary?: string[];
|
|
57
|
+
readyState?: string;
|
|
58
|
+
trigger?: 'initial' | 'route_change' | 'manual';
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
type MonitorEvent = ExceptionEvent | HttpErrorEvent | BlankScreenEvent;
|
|
62
|
+
|
|
63
|
+
interface MonitorApi {
|
|
64
|
+
emit(event: MonitorEvent): void;
|
|
65
|
+
captureException(error: unknown, extra?: Record<string, unknown>): void;
|
|
66
|
+
}
|
|
67
|
+
interface PluginSetupContext {
|
|
68
|
+
api: MonitorApi;
|
|
69
|
+
options: MonitorInitOptions;
|
|
70
|
+
}
|
|
71
|
+
interface MonitorPlugin {
|
|
72
|
+
name: string;
|
|
73
|
+
setup(context: PluginSetupContext): void | (() => void);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface MonitorInitOptions {
|
|
77
|
+
appId: string;
|
|
78
|
+
appName?: string;
|
|
79
|
+
env: string;
|
|
80
|
+
release?: string;
|
|
81
|
+
dsn: string;
|
|
82
|
+
sampleRate?: number;
|
|
83
|
+
plugins?: MonitorPlugin[];
|
|
84
|
+
beforeSend?: (event: MonitorEvent) => MonitorEvent | null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
declare class Monitor implements MonitorApi {
|
|
88
|
+
private queue;
|
|
89
|
+
private options;
|
|
90
|
+
private context;
|
|
91
|
+
private disposePlugins;
|
|
92
|
+
constructor(options: MonitorInitOptions);
|
|
93
|
+
emit(event: MonitorEvent): void;
|
|
94
|
+
captureException(error: unknown, extra?: Record<string, unknown>): void;
|
|
95
|
+
flush(): Promise<void>;
|
|
96
|
+
destroy(): void;
|
|
97
|
+
}
|
|
98
|
+
declare function initMonitor(options: MonitorInitOptions): Monitor;
|
|
99
|
+
|
|
100
|
+
interface ErrorPluginOptions {
|
|
101
|
+
captureOnError?: boolean;
|
|
102
|
+
captureUnhandledRejection?: boolean;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
declare function errorPlugin(options?: ErrorPluginOptions): MonitorPlugin;
|
|
106
|
+
|
|
107
|
+
interface NetworkPluginOptions {
|
|
108
|
+
timeoutMs?: number;
|
|
109
|
+
capture5xx?: boolean;
|
|
110
|
+
captureTimeout?: boolean;
|
|
111
|
+
captureNetworkError?: boolean;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
declare function networkPlugin(options?: NetworkPluginOptions): MonitorPlugin;
|
|
115
|
+
|
|
116
|
+
interface BlankScreenPluginOptions {
|
|
117
|
+
rootSelector?: string;
|
|
118
|
+
delayMs?: number;
|
|
119
|
+
scoreThreshold?: number;
|
|
120
|
+
samplePoints?: Array<[number, number]>;
|
|
121
|
+
ignoreSelectors?: string[];
|
|
122
|
+
detectOnRouteChange?: boolean;
|
|
123
|
+
routeChangeDelayMs?: number;
|
|
124
|
+
dedupeWindowMs?: number;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
declare function blankScreenPlugin(options?: BlankScreenPluginOptions): MonitorPlugin;
|
|
128
|
+
|
|
129
|
+
export { type BaseEvent, type BlankScreenEvent, type BlankScreenPluginOptions, type Breadcrumb, type ErrorPluginOptions, type ExceptionEvent, type HttpErrorEvent, Monitor, type MonitorApi, type MonitorEvent, type MonitorEventType, type MonitorInitOptions, type MonitorPlugin, type NetworkPluginOptions, type PluginSetupContext, blankScreenPlugin, errorPlugin, initMonitor, networkPlugin };
|