@xysfe/bug-tap 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/CHANGELOG.md +69 -0
- package/LICENSE +21 -0
- package/README.md +461 -2
- package/THIRD_PARTY_NOTICES.md +39 -0
- package/dist/bug-tap-screenshot.min.js +10 -0
- package/dist/bug-tap-screenshot.min.js.map +1 -0
- package/dist/bug-tap-vue.cjs +2 -0
- package/dist/bug-tap-vue.cjs.map +1 -0
- package/dist/bug-tap-vue.js +106 -0
- package/dist/bug-tap-vue.js.map +1 -0
- package/dist/bug-tap-vue.min.js +2 -0
- package/dist/bug-tap-vue.min.js.map +1 -0
- package/dist/bug-tap.cjs +2 -0
- package/dist/bug-tap.cjs.map +1 -0
- package/dist/bug-tap.js +13 -0
- package/dist/bug-tap.js.map +1 -0
- package/dist/bug-tap.min.js +508 -0
- package/dist/bug-tap.min.js.map +1 -0
- package/dist/config.d.ts +14 -0
- package/dist/core/body.d.ts +30 -0
- package/dist/core/breadcrumbs.d.ts +85 -0
- package/dist/core/browser-api-errors.d.ts +55 -0
- package/dist/core/byte-buffer.d.ts +43 -0
- package/dist/core/collector.d.ts +34 -0
- package/dist/core/console-collector.d.ts +23 -0
- package/dist/core/env-collector.d.ts +16 -0
- package/dist/core/error-collector.d.ts +48 -0
- package/dist/core/error-noise.d.ts +43 -0
- package/dist/core/network-collector.d.ts +97 -0
- package/dist/core/network-record.d.ts +19 -0
- package/dist/core/resource-timing.d.ts +28 -0
- package/dist/core/ring-buffer.d.ts +22 -0
- package/dist/core/selector.d.ts +3 -0
- package/dist/core/serialize.d.ts +5 -0
- package/dist/core/tongji.d.ts +14 -0
- package/dist/core/user.d.ts +9 -0
- package/dist/index-BBRuTNvo.js +4685 -0
- package/dist/index-BBRuTNvo.js.map +1 -0
- package/dist/index-DCLLRJxX.cjs +488 -0
- package/dist/index-DCLLRJxX.cjs.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/integrations.d.ts +26 -0
- package/dist/panel-mount-Dia21VuZ.cjs +2 -0
- package/dist/panel-mount-Dia21VuZ.cjs.map +1 -0
- package/dist/panel-mount-mAOg572s.js +499 -0
- package/dist/panel-mount-mAOg572s.js.map +1 -0
- package/dist/screenshot-global.d.ts +14 -0
- package/dist/sdk.d.ts +76 -0
- package/dist/transport/log-item.d.ts +2 -0
- package/dist/transport/offline-queue.d.ts +48 -0
- package/dist/transport/payload.d.ts +15 -0
- package/dist/transport/transport.d.ts +57 -0
- package/dist/transport/upload.d.ts +8 -0
- package/dist/types.d.ts +459 -0
- package/dist/ui/element-picker.d.ts +51 -0
- package/dist/ui/floating-button.d.ts +43 -0
- package/dist/ui/icons.d.ts +1 -0
- package/dist/ui/panel-mount.d.ts +20 -0
- package/dist/ui/panel.vue.d.ts +15 -0
- package/dist/ui/screenshot-loader-shared.d.ts +2 -0
- package/dist/ui/screenshot-loader.d.ts +14 -0
- package/dist/ui/screenshot-loader.iife.d.ts +16 -0
- package/dist/ui/screenshot.d.ts +20 -0
- package/dist/ui/shadow-host.d.ts +16 -0
- package/dist/ui/styles.css.d.ts +1 -0
- package/dist/ui/visibility.d.ts +25 -0
- package/dist/utils/match.d.ts +2 -0
- package/dist/utils/ua.d.ts +6 -0
- package/dist/utils/url.d.ts +2 -0
- package/dist/vue-global.d.ts +21 -0
- package/dist/vue.d.ts +49 -0
- package/docs/api.md +257 -0
- package/docs/backend-api.md +401 -0
- package/docs/bundler.md +122 -0
- package/docs/config.md +396 -0
- package/package.json +97 -4
package/dist/sdk.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Breadcrumb, BugTapApi, BugTapConfig, BugReport, ReactErrorHandlers, UserInfoInput, VueAppLike } from './types';
|
|
2
|
+
export declare class BugTap implements BugTapApi {
|
|
3
|
+
private rawConfig;
|
|
4
|
+
private config;
|
|
5
|
+
private collector;
|
|
6
|
+
private transport;
|
|
7
|
+
private host;
|
|
8
|
+
private fab;
|
|
9
|
+
private panel;
|
|
10
|
+
private panelLoading;
|
|
11
|
+
private openCancelled;
|
|
12
|
+
private picker;
|
|
13
|
+
private lastClientReportId;
|
|
14
|
+
private pendingMount;
|
|
15
|
+
private configErrors;
|
|
16
|
+
private tags;
|
|
17
|
+
private extras;
|
|
18
|
+
private contexts;
|
|
19
|
+
private initialized;
|
|
20
|
+
private routeCaptureOwned;
|
|
21
|
+
constructor(input: BugTapConfig);
|
|
22
|
+
init(): void;
|
|
23
|
+
open(): void;
|
|
24
|
+
close(): void;
|
|
25
|
+
openReporter(): void;
|
|
26
|
+
private cancelPendingMount;
|
|
27
|
+
closeReporter(): void;
|
|
28
|
+
setConfig(patch: Partial<BugTapConfig>): void;
|
|
29
|
+
/**
|
|
30
|
+
* 运行时更新登录用户信息。
|
|
31
|
+
* 不走 setConfig:deep merge 会把 undefined 当作「没传」而保留旧值,
|
|
32
|
+
* 这里需要能把用户信息真正清空,所以直接改 rawConfig 再重新归一化。
|
|
33
|
+
*/
|
|
34
|
+
setUser(user: UserInfoInput | null): void;
|
|
35
|
+
setTag(key: string, value: string | number | boolean): void;
|
|
36
|
+
setExtra(key: string, value: unknown): void;
|
|
37
|
+
setContext(name: string, context: Record<string, unknown>): void;
|
|
38
|
+
addBreadcrumb(breadcrumb: Omit<Breadcrumb, 't' | 'type'> & {
|
|
39
|
+
type?: Breadcrumb['type'];
|
|
40
|
+
message?: string;
|
|
41
|
+
}): void;
|
|
42
|
+
captureException(error: unknown, context?: Record<string, unknown>): void;
|
|
43
|
+
captureMessage(message: string, context?: Record<string, unknown>): void;
|
|
44
|
+
/**
|
|
45
|
+
* 交给框架路由接管导航记录(vue-router 插件调用)。
|
|
46
|
+
* 摘掉主包的 history 补丁后,路由变化改由 router.afterEach 显式写入,
|
|
47
|
+
* 避免同一次导航被记两遍。
|
|
48
|
+
*/
|
|
49
|
+
disableRouteCapture(): void;
|
|
50
|
+
installVueErrorHandler(app: VueAppLike): () => void;
|
|
51
|
+
reactErrorHandlers(): ReactErrorHandlers;
|
|
52
|
+
flush(): Promise<number>;
|
|
53
|
+
destroy(): void;
|
|
54
|
+
getReport(): BugReport;
|
|
55
|
+
/**
|
|
56
|
+
* buildReport + beforeSend(对应 Sentry 的 beforeSend):
|
|
57
|
+
* 返回 null 表示放弃这条报告(例如用户只是想看一眼,不希望上报),
|
|
58
|
+
* 钩子抛错时按「不修改」放行,不能因为业务 bug 丢掉整条反馈。
|
|
59
|
+
* beforeSend 允许返回 Promise:提交路径会等待,getReport 会明确报错。
|
|
60
|
+
*/
|
|
61
|
+
private buildWithHooks;
|
|
62
|
+
/** 业务通过 setTag / setExtra / setContext 写入的上下文,每次组装报告时快照 */
|
|
63
|
+
private runtimeContext;
|
|
64
|
+
private mountFab;
|
|
65
|
+
private mountPanel;
|
|
66
|
+
private applyFabVisibility;
|
|
67
|
+
private unmountUi;
|
|
68
|
+
private capture;
|
|
69
|
+
private upload;
|
|
70
|
+
private submit;
|
|
71
|
+
private pickElement;
|
|
72
|
+
private prepareScreenshots;
|
|
73
|
+
private prepareScreenshot;
|
|
74
|
+
private isConfigured;
|
|
75
|
+
private warn;
|
|
76
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 离线待发队列。
|
|
3
|
+
*
|
|
4
|
+
* 用户主动反馈不是可丢弃的埋点:提交失败(断网、网关 5xx、超时)后
|
|
5
|
+
* 必须留一份在本地,下次进入页面时重新投递,否则用户填了半天的描述直接消失。
|
|
6
|
+
*
|
|
7
|
+
* 存储优先 IndexedDB(容量大、异步、不阻塞主线程),不可用时退化为内存数组,
|
|
8
|
+
* 至少能覆盖「同一次页面生命周期内的重试」。
|
|
9
|
+
*/
|
|
10
|
+
export interface QueuedPayload {
|
|
11
|
+
id: string;
|
|
12
|
+
endpoint: string;
|
|
13
|
+
body: string;
|
|
14
|
+
size?: number;
|
|
15
|
+
createdAt: number;
|
|
16
|
+
}
|
|
17
|
+
export interface OfflineQueueOptions {
|
|
18
|
+
ttlMs: number;
|
|
19
|
+
maxItems: number;
|
|
20
|
+
}
|
|
21
|
+
export declare class OfflineQueue {
|
|
22
|
+
private readonly options;
|
|
23
|
+
private readonly memory;
|
|
24
|
+
private db;
|
|
25
|
+
constructor(options: OfflineQueueOptions);
|
|
26
|
+
private database;
|
|
27
|
+
/** 写入一条待发记录;超出容量或过期的旧记录会被清掉 */
|
|
28
|
+
enqueue(item: QueuedPayload): Promise<void>;
|
|
29
|
+
/** 返回是否真正写入了 DB;失败时由调用方退回内存 */
|
|
30
|
+
private put;
|
|
31
|
+
/**
|
|
32
|
+
* 清理过期与超出容量的记录。
|
|
33
|
+
* 单独一个事务:在 getAll 的 onsuccess 里直接 delete,避免事务在微任务之间被提交。
|
|
34
|
+
*/
|
|
35
|
+
private prune;
|
|
36
|
+
/**
|
|
37
|
+
* 按入队顺序取出未过期的记录。
|
|
38
|
+
* 内存兜底里的条目也要一起返回:DB 写入失败时它们只存在于内存,
|
|
39
|
+
* 只看 DB 会让这些「已保存」的记录永远发不出去。
|
|
40
|
+
*/
|
|
41
|
+
peek(): Promise<QueuedPayload[]>;
|
|
42
|
+
private memoryItems;
|
|
43
|
+
remove(id: string): Promise<void>;
|
|
44
|
+
size(): Promise<number>;
|
|
45
|
+
private isExpired;
|
|
46
|
+
private trimMemory;
|
|
47
|
+
private putMemory;
|
|
48
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BugReport, ElementSnapshot, ResolvedBugTapConfig, ReporterFormValues, Screenshot } from '../types';
|
|
2
|
+
import type { CollectedData } from '../core/collector';
|
|
3
|
+
export declare function deriveTitle(description: string): string;
|
|
4
|
+
export declare function createClientReportId(): string;
|
|
5
|
+
export declare function buildReport(options: {
|
|
6
|
+
values: ReporterFormValues;
|
|
7
|
+
data: CollectedData;
|
|
8
|
+
config: ResolvedBugTapConfig;
|
|
9
|
+
clientReportId?: string;
|
|
10
|
+
screenshots?: Screenshot[];
|
|
11
|
+
elements?: ElementSnapshot[];
|
|
12
|
+
tags?: Record<string, string | number | boolean>;
|
|
13
|
+
extra?: Record<string, unknown>;
|
|
14
|
+
contexts?: Record<string, Record<string, unknown>>;
|
|
15
|
+
}): BugReport;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { BugReport, ResolvedBugTapConfig, SubmitResponse } from '../types';
|
|
2
|
+
export type TransportFailure = 'network' | 'timeout' | 'http' | 'protocol' | 'busy' | 'limited';
|
|
3
|
+
export declare class TransportError extends Error {
|
|
4
|
+
readonly failure: TransportFailure;
|
|
5
|
+
readonly status?: number;
|
|
6
|
+
readonly retryable: boolean;
|
|
7
|
+
readonly details?: unknown;
|
|
8
|
+
readonly retryAfterMs?: number;
|
|
9
|
+
readonly queued?: boolean;
|
|
10
|
+
constructor(message: string, options: {
|
|
11
|
+
failure: TransportFailure;
|
|
12
|
+
status?: number;
|
|
13
|
+
retryable: boolean;
|
|
14
|
+
details?: unknown;
|
|
15
|
+
retryAfterMs?: number;
|
|
16
|
+
queued?: boolean;
|
|
17
|
+
});
|
|
18
|
+
/** 失败已写入本地补偿队列:只多一个布尔,其余字段原样继承 */
|
|
19
|
+
asQueued(): TransportError;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 解析 Retry-After(Sentry 的 parseRetryAfterHeader 同款):
|
|
23
|
+
* 可以是秒数,也可以是 HTTP 日期;解析不了按 60s 处理。
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseRetryAfter(value: string | null, now?: number): number | undefined;
|
|
26
|
+
export declare class Transport {
|
|
27
|
+
private readonly config;
|
|
28
|
+
private pendingCount;
|
|
29
|
+
private pendingBytes;
|
|
30
|
+
private successCount;
|
|
31
|
+
private readonly queue;
|
|
32
|
+
private flushing;
|
|
33
|
+
private started;
|
|
34
|
+
private readonly onOnline;
|
|
35
|
+
private readonly onVisibility;
|
|
36
|
+
private readonly onPageHide;
|
|
37
|
+
constructor(config: ResolvedBugTapConfig);
|
|
38
|
+
/** 注册网络恢复 / 页面隐藏时的补偿逻辑;可重复调用 */
|
|
39
|
+
start(): void;
|
|
40
|
+
stop(): void;
|
|
41
|
+
send(report: BugReport): Promise<SubmitResponse>;
|
|
42
|
+
/**
|
|
43
|
+
* 重放本地补偿队列,返回本次成功发出的条数。
|
|
44
|
+
* 遇到网络仍不可用时立即停下,避免在弱网下反复打网关。
|
|
45
|
+
*/
|
|
46
|
+
flush(): Promise<number>;
|
|
47
|
+
private flushItems;
|
|
48
|
+
/** 页面隐藏时用 sendBeacon 兜底,不依赖 fetch 能否在卸载阶段完成 */
|
|
49
|
+
private beacon;
|
|
50
|
+
private enqueue;
|
|
51
|
+
private shouldQueue;
|
|
52
|
+
private attempt;
|
|
53
|
+
private deadlineError;
|
|
54
|
+
private once;
|
|
55
|
+
private toTransportError;
|
|
56
|
+
private extractMessage;
|
|
57
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ResolvedUploadConfig, Screenshot } from '../types';
|
|
2
|
+
export declare function messageOf(error: unknown): string;
|
|
3
|
+
/**
|
|
4
|
+
* 上传截图到公司图片服务,返回可访问 URL。
|
|
5
|
+
* 契约参考 actui2 FileUpload/src/upload.js:
|
|
6
|
+
* POST form-urlencoded imgdata/bizid/name -> { ret: 0, data: { url } | "url" }
|
|
7
|
+
*/
|
|
8
|
+
export declare function uploadScreenshot(screenshot: Screenshot, config: ResolvedUploadConfig): Promise<string>;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
export type LogLevel = 'log' | 'info' | 'warn' | 'error' | 'debug' | 'trace' | 'assert';
|
|
2
|
+
export interface ConsoleLog {
|
|
3
|
+
level: LogLevel;
|
|
4
|
+
timestamp: number;
|
|
5
|
+
args: string[];
|
|
6
|
+
text: string;
|
|
7
|
+
count?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface JavaScriptError {
|
|
10
|
+
type: 'error' | 'unhandledrejection' | 'resource';
|
|
11
|
+
message: string;
|
|
12
|
+
filename?: string;
|
|
13
|
+
lineno?: number;
|
|
14
|
+
colno?: number;
|
|
15
|
+
stack?: string;
|
|
16
|
+
cause?: string;
|
|
17
|
+
context?: Record<string, unknown>;
|
|
18
|
+
timestamp: number;
|
|
19
|
+
count: number;
|
|
20
|
+
}
|
|
21
|
+
export interface Breadcrumb {
|
|
22
|
+
t: number;
|
|
23
|
+
type: 'click' | 'route' | 'visibility' | 'input' | 'http' | 'error' | 'manual';
|
|
24
|
+
selector?: string;
|
|
25
|
+
text?: string;
|
|
26
|
+
from?: string;
|
|
27
|
+
to?: string;
|
|
28
|
+
state?: string;
|
|
29
|
+
method?: string;
|
|
30
|
+
url?: string;
|
|
31
|
+
status?: number;
|
|
32
|
+
durationMs?: number;
|
|
33
|
+
ref?: string;
|
|
34
|
+
repeat?: number;
|
|
35
|
+
message?: string;
|
|
36
|
+
count?: number;
|
|
37
|
+
httpError?: string;
|
|
38
|
+
data?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
export interface CollectorHealth {
|
|
41
|
+
startedAt: number;
|
|
42
|
+
earlyGapMs: number;
|
|
43
|
+
patched: {
|
|
44
|
+
console: boolean;
|
|
45
|
+
fetch: boolean;
|
|
46
|
+
xhr: boolean;
|
|
47
|
+
error: boolean;
|
|
48
|
+
websocket?: boolean;
|
|
49
|
+
eventsource?: boolean;
|
|
50
|
+
};
|
|
51
|
+
counts: {
|
|
52
|
+
logs: number;
|
|
53
|
+
errors: number;
|
|
54
|
+
network: number;
|
|
55
|
+
breadcrumbs: number;
|
|
56
|
+
};
|
|
57
|
+
breadcrumbLimit?: number;
|
|
58
|
+
breadcrumbEvicted?: number;
|
|
59
|
+
}
|
|
60
|
+
export interface AppInfo {
|
|
61
|
+
version?: string;
|
|
62
|
+
buildId?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface NetworkRecord {
|
|
65
|
+
id: string;
|
|
66
|
+
type: 'fetch' | 'xhr' | 'websocket' | 'eventsource';
|
|
67
|
+
method: string;
|
|
68
|
+
url: string;
|
|
69
|
+
status?: number;
|
|
70
|
+
ok?: boolean;
|
|
71
|
+
durationMs?: number;
|
|
72
|
+
error?: string;
|
|
73
|
+
reqBody?: string;
|
|
74
|
+
resBody?: string;
|
|
75
|
+
contentType?: string;
|
|
76
|
+
reqHeaders?: Record<string, string>;
|
|
77
|
+
resHeaders?: Record<string, string>;
|
|
78
|
+
timing?: NetworkTiming;
|
|
79
|
+
timestamp: number;
|
|
80
|
+
}
|
|
81
|
+
export interface NetworkTiming {
|
|
82
|
+
dns: number;
|
|
83
|
+
connect: number;
|
|
84
|
+
ttfb: number;
|
|
85
|
+
download: number;
|
|
86
|
+
total: number;
|
|
87
|
+
}
|
|
88
|
+
export interface Screenshot {
|
|
89
|
+
mime: string;
|
|
90
|
+
dataBase64?: string;
|
|
91
|
+
url?: string;
|
|
92
|
+
width: number;
|
|
93
|
+
height: number;
|
|
94
|
+
size: number;
|
|
95
|
+
source: 'auto' | 'manual';
|
|
96
|
+
capturedAt?: number;
|
|
97
|
+
}
|
|
98
|
+
export interface BrowserInfo {
|
|
99
|
+
userAgent: string;
|
|
100
|
+
platform?: string;
|
|
101
|
+
browser?: string;
|
|
102
|
+
browserVersion?: string;
|
|
103
|
+
os?: string;
|
|
104
|
+
screenWidth: number;
|
|
105
|
+
screenHeight: number;
|
|
106
|
+
viewportWidth: number;
|
|
107
|
+
viewportHeight: number;
|
|
108
|
+
dpr: number;
|
|
109
|
+
device?: string;
|
|
110
|
+
language: string;
|
|
111
|
+
timezone: string;
|
|
112
|
+
}
|
|
113
|
+
export interface PageInfo {
|
|
114
|
+
url: string;
|
|
115
|
+
referrer?: string;
|
|
116
|
+
title?: string;
|
|
117
|
+
}
|
|
118
|
+
export interface LogItem {
|
|
119
|
+
timestamp: number;
|
|
120
|
+
logLevel: 1 | 2 | 3;
|
|
121
|
+
userAgent: string;
|
|
122
|
+
url: string;
|
|
123
|
+
content: string;
|
|
124
|
+
traceId: string;
|
|
125
|
+
ext: string;
|
|
126
|
+
}
|
|
127
|
+
export interface LogReportResponse {
|
|
128
|
+
errCode: number;
|
|
129
|
+
errMsg?: string;
|
|
130
|
+
}
|
|
131
|
+
export interface ElementSnapshot {
|
|
132
|
+
selector: string;
|
|
133
|
+
tag: string;
|
|
134
|
+
text?: string;
|
|
135
|
+
attributes: Record<string, string>;
|
|
136
|
+
rect: {
|
|
137
|
+
x: number;
|
|
138
|
+
y: number;
|
|
139
|
+
width: number;
|
|
140
|
+
height: number;
|
|
141
|
+
};
|
|
142
|
+
path: string;
|
|
143
|
+
}
|
|
144
|
+
export interface NetworkDropped {
|
|
145
|
+
droppedCount: number;
|
|
146
|
+
droppedBytes: number;
|
|
147
|
+
evictedCount: number;
|
|
148
|
+
evictedBytes: number;
|
|
149
|
+
trimmedCount?: number;
|
|
150
|
+
totalCount: number | null;
|
|
151
|
+
sentCount: number;
|
|
152
|
+
}
|
|
153
|
+
export interface TrackIds {
|
|
154
|
+
xid?: string;
|
|
155
|
+
subId?: string;
|
|
156
|
+
sessionId?: string;
|
|
157
|
+
}
|
|
158
|
+
export interface BugReport {
|
|
159
|
+
project: string;
|
|
160
|
+
environment: string;
|
|
161
|
+
title: string;
|
|
162
|
+
description: string;
|
|
163
|
+
category?: string;
|
|
164
|
+
severity?: string;
|
|
165
|
+
contact?: string;
|
|
166
|
+
user?: UserInfo;
|
|
167
|
+
track?: TrackIds;
|
|
168
|
+
page: PageInfo;
|
|
169
|
+
browser: BrowserInfo;
|
|
170
|
+
logs: ConsoleLog[];
|
|
171
|
+
errors: JavaScriptError[];
|
|
172
|
+
network: NetworkRecord[];
|
|
173
|
+
screenshots?: Screenshot[];
|
|
174
|
+
elements?: ElementSnapshot[];
|
|
175
|
+
networkDropped?: NetworkDropped;
|
|
176
|
+
breadcrumbs?: Breadcrumb[];
|
|
177
|
+
collector?: CollectorHealth;
|
|
178
|
+
app?: AppInfo;
|
|
179
|
+
release?: string;
|
|
180
|
+
tags?: Record<string, string | number | boolean>;
|
|
181
|
+
extra?: Record<string, unknown>;
|
|
182
|
+
contexts?: Record<string, Record<string, unknown>>;
|
|
183
|
+
timestamp: number;
|
|
184
|
+
sdkVersion: string;
|
|
185
|
+
clientReportId: string;
|
|
186
|
+
}
|
|
187
|
+
export interface ReporterFormValues {
|
|
188
|
+
title: string;
|
|
189
|
+
description: string;
|
|
190
|
+
category?: string;
|
|
191
|
+
severity?: string;
|
|
192
|
+
contact?: string;
|
|
193
|
+
}
|
|
194
|
+
export interface SubmitResponse {
|
|
195
|
+
success: boolean;
|
|
196
|
+
reportId?: string;
|
|
197
|
+
message?: string;
|
|
198
|
+
queued?: boolean;
|
|
199
|
+
}
|
|
200
|
+
export interface AttachmentRef {
|
|
201
|
+
id: string;
|
|
202
|
+
url?: string;
|
|
203
|
+
}
|
|
204
|
+
export interface UserInfo {
|
|
205
|
+
id?: string;
|
|
206
|
+
name?: string;
|
|
207
|
+
[key: string]: string | number | boolean | undefined;
|
|
208
|
+
}
|
|
209
|
+
export type UserInfoInput = UserInfo | (() => UserInfo | null | undefined);
|
|
210
|
+
export interface ReporterUiConfig {
|
|
211
|
+
enabled?: boolean;
|
|
212
|
+
position?: 'bottom-right' | 'bottom-left';
|
|
213
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
214
|
+
text?: string;
|
|
215
|
+
zIndex?: number;
|
|
216
|
+
visibility?: {
|
|
217
|
+
mode?: 'always' | 'triggered';
|
|
218
|
+
queryParam?: string;
|
|
219
|
+
queryValue?: string;
|
|
220
|
+
closable?: boolean;
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
export interface CollectConfig {
|
|
224
|
+
console?: boolean;
|
|
225
|
+
error?: boolean;
|
|
226
|
+
network?: boolean;
|
|
227
|
+
networkBody?: boolean;
|
|
228
|
+
realtime?: boolean;
|
|
229
|
+
resourceErrors?: boolean;
|
|
230
|
+
environment?: boolean;
|
|
231
|
+
trackIds?: boolean;
|
|
232
|
+
breadcrumbs?: boolean;
|
|
233
|
+
maxBreadcrumbs?: number;
|
|
234
|
+
maxConsoleLogs?: number;
|
|
235
|
+
maxNetworkRecords?: number;
|
|
236
|
+
maxErrors?: number;
|
|
237
|
+
maxNetworkBytes?: number;
|
|
238
|
+
maxCloneBytes?: number;
|
|
239
|
+
requestHeaders?: string[] | boolean;
|
|
240
|
+
responseHeaders?: string[] | boolean;
|
|
241
|
+
maxElements?: number;
|
|
242
|
+
eventListenerErrors?: boolean;
|
|
243
|
+
}
|
|
244
|
+
export interface PrivacyConfig {
|
|
245
|
+
excludeUrls?: Array<string | RegExp>;
|
|
246
|
+
excludeConsolePatterns?: Array<string | RegExp>;
|
|
247
|
+
excludeBreadcrumbUrls?: Array<string | RegExp>;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* 错误噪声过滤,语义对齐 Sentry 的 eventFilters:
|
|
251
|
+
* - ignoreErrors:消息命中即不采(字符串按包含,正则按 test)
|
|
252
|
+
* - denyUrls / allowUrls:按异常栈里**抛出点脚本的地址**过滤,不是页面地址
|
|
253
|
+
*/
|
|
254
|
+
export interface FilteringConfig {
|
|
255
|
+
ignoreErrors?: Array<string | RegExp>;
|
|
256
|
+
denyUrls?: Array<string | RegExp>;
|
|
257
|
+
allowUrls?: Array<string | RegExp>;
|
|
258
|
+
disableErrorDefaults?: boolean;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* 业务侧介入点,语义对齐 Sentry 的 beforeSend / beforeBreadcrumb:
|
|
262
|
+
* 返回 null 表示丢弃这条数据,返回值替换原数据。
|
|
263
|
+
* 抛错时按「不修改」处理,绝不阻断上报。
|
|
264
|
+
*/
|
|
265
|
+
export interface HooksConfig {
|
|
266
|
+
beforeSend?: (report: BugReport) => BugReport | null | Promise<BugReport | null>;
|
|
267
|
+
beforeBreadcrumb?: (breadcrumb: Breadcrumb) => Breadcrumb | null;
|
|
268
|
+
}
|
|
269
|
+
/** 网络响应头白名单:这些头能让前端报告与后端日志对上号 */
|
|
270
|
+
export declare const TRACE_HEADER_NAMES: readonly ["x-request-id", "x-trace-id", "traceparent", "tracestate", "x-b3-traceid", "x-b3-spanid", "server-timing", "content-length"];
|
|
271
|
+
export interface ScreenshotConfig {
|
|
272
|
+
enabled?: boolean;
|
|
273
|
+
auto?: boolean;
|
|
274
|
+
quality?: number;
|
|
275
|
+
maxWidth?: number;
|
|
276
|
+
maxSizeKB?: number;
|
|
277
|
+
/**
|
|
278
|
+
* CDN 场景下 `bug-tap-screenshot.min.js` 的地址。
|
|
279
|
+
*
|
|
280
|
+
* 不填时按「与主包同目录」推断,适用于整包一起部署到 CDN 的情况。
|
|
281
|
+
* 以下场景必须显式指定:
|
|
282
|
+
* - 主包与截图库不在同一目录(如截图库单独走另一条 CDN / 版本号路径)
|
|
283
|
+
* - 主包经内联或 `/assets/xxx.js` 之类的动态文件名加载,推断不到原始 URL
|
|
284
|
+
* - 主包由打包器打进业务 chunk,`document.currentScript` 指向业务入口
|
|
285
|
+
*
|
|
286
|
+
* 支持相对路径(按当前页面解析)与绝对 URL。
|
|
287
|
+
* 两种产物都生效:ESM 下配了它就不再 `import('html2canvas-pro')`,改为注入外部脚本。
|
|
288
|
+
*/
|
|
289
|
+
scriptUrl?: string;
|
|
290
|
+
}
|
|
291
|
+
export interface TransportConfig {
|
|
292
|
+
timeoutMs?: number;
|
|
293
|
+
retries?: number;
|
|
294
|
+
headers?: Record<string, string>;
|
|
295
|
+
maxItemBytes?: number;
|
|
296
|
+
totalTimeoutMs?: number;
|
|
297
|
+
maxConcurrent?: number;
|
|
298
|
+
logLevel?: 1 | 2 | 3;
|
|
299
|
+
offline?: {
|
|
300
|
+
enabled?: boolean;
|
|
301
|
+
ttlMs?: number;
|
|
302
|
+
maxItems?: number;
|
|
303
|
+
};
|
|
304
|
+
maxReportsPerSession?: number;
|
|
305
|
+
}
|
|
306
|
+
export interface UploadConfig {
|
|
307
|
+
enabled?: boolean;
|
|
308
|
+
url?: string;
|
|
309
|
+
bizId?: string;
|
|
310
|
+
timeoutMs?: number;
|
|
311
|
+
}
|
|
312
|
+
export interface BugTapConfig {
|
|
313
|
+
project: string;
|
|
314
|
+
endpoint?: string;
|
|
315
|
+
environment?: string;
|
|
316
|
+
appVersion?: string;
|
|
317
|
+
buildId?: string;
|
|
318
|
+
release?: string;
|
|
319
|
+
debug?: boolean;
|
|
320
|
+
user?: UserInfoInput;
|
|
321
|
+
reporter?: ReporterUiConfig;
|
|
322
|
+
collect?: CollectConfig;
|
|
323
|
+
privacy?: PrivacyConfig;
|
|
324
|
+
filtering?: FilteringConfig;
|
|
325
|
+
hooks?: HooksConfig;
|
|
326
|
+
screenshot?: ScreenshotConfig;
|
|
327
|
+
transport?: TransportConfig;
|
|
328
|
+
upload?: UploadConfig;
|
|
329
|
+
}
|
|
330
|
+
export interface ResolvedReporterUiConfig {
|
|
331
|
+
enabled: boolean;
|
|
332
|
+
position: 'bottom-right' | 'bottom-left';
|
|
333
|
+
theme: 'light' | 'dark' | 'auto';
|
|
334
|
+
text: string;
|
|
335
|
+
zIndex: number;
|
|
336
|
+
visibility: {
|
|
337
|
+
mode: 'always' | 'triggered';
|
|
338
|
+
queryParam: string;
|
|
339
|
+
queryValue: string;
|
|
340
|
+
closable: boolean;
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
export interface ResolvedCollectConfig {
|
|
344
|
+
console: boolean;
|
|
345
|
+
error: boolean;
|
|
346
|
+
network: boolean;
|
|
347
|
+
networkBody: boolean;
|
|
348
|
+
realtime: boolean;
|
|
349
|
+
resourceErrors: boolean;
|
|
350
|
+
environment: boolean;
|
|
351
|
+
trackIds: boolean;
|
|
352
|
+
breadcrumbs: boolean;
|
|
353
|
+
maxBreadcrumbs: number;
|
|
354
|
+
maxConsoleLogs: number;
|
|
355
|
+
maxNetworkRecords: number;
|
|
356
|
+
maxErrors: number;
|
|
357
|
+
maxNetworkBytes: number;
|
|
358
|
+
maxCloneBytes: number;
|
|
359
|
+
requestHeaders: string[] | true;
|
|
360
|
+
responseHeaders: string[] | true;
|
|
361
|
+
maxElements: number;
|
|
362
|
+
eventListenerErrors: boolean;
|
|
363
|
+
}
|
|
364
|
+
export interface ResolvedPrivacyConfig {
|
|
365
|
+
excludeUrls: Array<string | RegExp>;
|
|
366
|
+
excludeConsolePatterns: Array<string | RegExp>;
|
|
367
|
+
excludeBreadcrumbUrls: Array<string | RegExp>;
|
|
368
|
+
}
|
|
369
|
+
export interface ResolvedScreenshotConfig {
|
|
370
|
+
enabled: boolean;
|
|
371
|
+
auto: boolean;
|
|
372
|
+
quality: number;
|
|
373
|
+
maxWidth: number;
|
|
374
|
+
maxSizeKB: number;
|
|
375
|
+
scriptUrl: string;
|
|
376
|
+
}
|
|
377
|
+
export interface ResolvedTransportConfig {
|
|
378
|
+
timeoutMs: number;
|
|
379
|
+
retries: number;
|
|
380
|
+
headers: Record<string, string>;
|
|
381
|
+
maxItemBytes: number;
|
|
382
|
+
totalTimeoutMs: number;
|
|
383
|
+
maxConcurrent: number;
|
|
384
|
+
logLevel?: 1 | 2 | 3;
|
|
385
|
+
offline: {
|
|
386
|
+
enabled: boolean;
|
|
387
|
+
ttlMs: number;
|
|
388
|
+
maxItems: number;
|
|
389
|
+
};
|
|
390
|
+
maxReportsPerSession: number;
|
|
391
|
+
}
|
|
392
|
+
export interface ResolvedUploadConfig {
|
|
393
|
+
enabled: boolean;
|
|
394
|
+
url: string;
|
|
395
|
+
bizId: string;
|
|
396
|
+
timeoutMs: number;
|
|
397
|
+
}
|
|
398
|
+
export interface ResolvedFilteringConfig {
|
|
399
|
+
ignoreErrors: Array<string | RegExp>;
|
|
400
|
+
denyUrls: Array<string | RegExp>;
|
|
401
|
+
allowUrls: Array<string | RegExp>;
|
|
402
|
+
}
|
|
403
|
+
export interface ResolvedBugTapConfig {
|
|
404
|
+
project: string;
|
|
405
|
+
endpoint: string;
|
|
406
|
+
environment: string;
|
|
407
|
+
debug: boolean;
|
|
408
|
+
appVersion: string;
|
|
409
|
+
buildId: string;
|
|
410
|
+
release: string;
|
|
411
|
+
user: UserInfoInput | undefined;
|
|
412
|
+
reporter: ResolvedReporterUiConfig;
|
|
413
|
+
collect: ResolvedCollectConfig;
|
|
414
|
+
privacy: ResolvedPrivacyConfig;
|
|
415
|
+
filtering: ResolvedFilteringConfig;
|
|
416
|
+
hooks: HooksConfig;
|
|
417
|
+
screenshot: ResolvedScreenshotConfig;
|
|
418
|
+
transport: ResolvedTransportConfig;
|
|
419
|
+
upload: ResolvedUploadConfig;
|
|
420
|
+
}
|
|
421
|
+
export interface VueErrorHandler {
|
|
422
|
+
(error: unknown, instance: unknown, info: string): void;
|
|
423
|
+
}
|
|
424
|
+
export interface VueAppLike {
|
|
425
|
+
config?: {
|
|
426
|
+
errorHandler?: VueErrorHandler | null;
|
|
427
|
+
} | null;
|
|
428
|
+
}
|
|
429
|
+
export interface ReactErrorInfo {
|
|
430
|
+
componentStack?: string;
|
|
431
|
+
}
|
|
432
|
+
export interface ReactErrorHandlers {
|
|
433
|
+
onUncaughtError(error: unknown, info: ReactErrorInfo): void;
|
|
434
|
+
onCaughtError(error: unknown, info: ReactErrorInfo): void;
|
|
435
|
+
onRecoverableError(error: unknown, info: ReactErrorInfo): void;
|
|
436
|
+
}
|
|
437
|
+
export interface BugTapApi {
|
|
438
|
+
open(): void;
|
|
439
|
+
close(): void;
|
|
440
|
+
openReporter(): void;
|
|
441
|
+
closeReporter(): void;
|
|
442
|
+
setConfig(patch: Partial<BugTapConfig>): void;
|
|
443
|
+
setUser(user: UserInfoInput | null): void;
|
|
444
|
+
setTag(key: string, value: string | number | boolean): void;
|
|
445
|
+
setExtra(key: string, value: unknown): void;
|
|
446
|
+
setContext(name: string, context: Record<string, unknown>): void;
|
|
447
|
+
addBreadcrumb(breadcrumb: Omit<Breadcrumb, 't' | 'type'> & {
|
|
448
|
+
type?: Breadcrumb['type'];
|
|
449
|
+
message?: string;
|
|
450
|
+
}): void;
|
|
451
|
+
captureException(error: unknown, context?: Record<string, unknown>): void;
|
|
452
|
+
captureMessage(message: string, context?: Record<string, unknown>): void;
|
|
453
|
+
disableRouteCapture(): void;
|
|
454
|
+
installVueErrorHandler(app: VueAppLike): () => void;
|
|
455
|
+
reactErrorHandlers(): ReactErrorHandlers;
|
|
456
|
+
destroy(): void;
|
|
457
|
+
getReport(): BugReport;
|
|
458
|
+
flush(): Promise<number>;
|
|
459
|
+
}
|