miaoda-react-devkit 0.1.1-beta.21 → 0.1.1-beta.22

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.cts CHANGED
@@ -1,394 +1,2 @@
1
- import { Breadcrumb, ErrorEvent, EventHint, BreadcrumbHint } from '@sentry/react';
2
1
 
3
- /** PostgREST 响应检测与错误体解析。 */
4
- /**
5
- * 默认匹配 Supabase / 自托管 PostgREST 的标准路径前缀。
6
- * 可通过 ISentryCaptureOptions.pgRestUrlPatterns 覆盖。
7
- */
8
- declare const DEFAULT_PGREST_URL_PATTERNS: Array<string | RegExp>;
9
- /**
10
- * 白名单 PostgREST/PostgreSQL error code 列表。
11
- * 命中白名单的响应才触发 onPgRestWhitelistError。
12
- *
13
- * TODO: 根据业务需要补充具体 code。格式示例:
14
- * - PostgREST 内部码:'PGRST301'(JWT 过期)、'PGRST116'(期望单行但返回多行)
15
- * - PostgreSQL 错误码:'23505'(唯一键冲突)、'23503'(外键约束失败)
16
- */
17
- declare const DEFAULT_PGREST_WHITELIST_CODES: string[];
18
- /** PostgREST 标准错误响应体结构(HTTP 4xx/5xx 时返回)。 */
19
- interface IPgRestErrorBody {
20
- /** PostgREST 或 PostgreSQL 错误码,如 'PGRST301'、'23505' */
21
- code: string;
22
- message: string;
23
- details: string | null;
24
- hint: string | null;
25
- }
26
-
27
- /** Supabase Auth 响应检测与错误体解析。 */
28
- /**
29
- * 默认匹配 Supabase Auth 的标准路径前缀。
30
- * 可通过 ISentryCaptureOptions.authUrlPatterns 覆盖。
31
- */
32
- declare const DEFAULT_AUTH_URL_PATTERNS: Array<string | RegExp>;
33
- /**
34
- * 白名单 Auth error code 列表。
35
- * 命中白名单的响应才触发 onAuthWhitelistError。
36
- *
37
- * TODO: 根据业务需要补充具体 code。格式示例:
38
- * - 'email_not_confirmed'(邮箱未确认)
39
- * - 'invalid_email'(邮箱格式无效)
40
- * - 'unexpected_failure'(未知失败)
41
- */
42
- declare const DEFAULT_AUTH_WHITELIST_CODES: string[];
43
- /** Supabase Auth 标准错误响应体结构(HTTP 4xx/5xx 时返回)。 */
44
- interface IAuthErrorBody {
45
- requestId: string | null;
46
- code: string;
47
- message: string;
48
- }
49
-
50
- /** Supabase Storage 响应检测与错误体解析。 */
51
- /**
52
- * 默认匹配 Supabase Storage 的标准路径前缀。
53
- * 可通过 ISentryCaptureOptions.storageUrlPatterns 覆盖。
54
- */
55
- declare const DEFAULT_STORAGE_URL_PATTERNS: Array<string | RegExp>;
56
- /**
57
- * 白名单 Storage error 列表(匹配 error 字段)。
58
- * 命中白名单的响应才触发 onStorageWhitelistError。
59
- *
60
- * TODO: 根据业务需要补充具体 message。格式示例:
61
- * - 'new row violates row-level security policy'(行级安全策略拒绝)
62
- */
63
- declare const DEFAULT_STORAGE_WHITELIST_ERRORS: string[];
64
- /** Supabase Storage 标准错误响应体结构(HTTP 4xx/5xx 时返回)。 */
65
- interface IStorageErrorBody {
66
- /** HTTP 状态码字符串,如 '400'、'403' */
67
- statusCode: string;
68
- error: string;
69
- message: string;
70
- }
71
-
72
- /** Sentry 捕获模块共享类型定义。 */
73
-
74
- interface IErrorCaptureInfo {
75
- message: string;
76
- stack?: string;
77
- /** React 组件调用栈,由 ErrorBoundary 提供 */
78
- componentStack?: string;
79
- /** 错误捕获方式,如 'instrument'、'onerror' 等 */
80
- mechanismType?: string | null;
81
- /** 错误类型名,如 'TypeError'、'RangeError',来自 error.name */
82
- errorName?: string;
83
- /** 抛出错误的文件路径,来自最内层 stack frame 的 filename */
84
- fileName?: string;
85
- /** 抛出错误的行号,来自最内层 stack frame 的 lineno */
86
- lineNumber?: number;
87
- /** 抛出错误的列号,来自最内层 stack frame 的 colno */
88
- columnNumber?: number;
89
- }
90
- interface IConsoleCaptureInfo {
91
- /** 日志级别:debug / info / warn / error / log / assert / trace */
92
- level: string;
93
- /** 原始参数列表,与调用 console.xxx(...args) 时的 args 完全一致 */
94
- args: unknown[];
95
- }
96
- interface INetworkRequestInfo {
97
- type: 'fetch' | 'xhr';
98
- method: string;
99
- url: string;
100
- statusCode: number | null;
101
- /** 请求体文本,无法序列化(如 Blob/ArrayBuffer)时为 undefined */
102
- requestBody: string | undefined;
103
- /**
104
- * 响应体文本。
105
- * - XHR:同步读取,总是同步可用
106
- * - fetch:异步读取,在 Promise resolve 后才有值;网络层失败时为 undefined
107
- */
108
- responseBody: string | undefined;
109
- /** 网络层失败(未收到 HTTP 响应)时为 true */
110
- isError: boolean;
111
- /**
112
- * 网络层失败时的原始 Error 对象(仅 fetch 可用,来自 hint.data)。
113
- * XHR 网络失败时 Sentry hint 中不携带 Error 对象,此字段为 undefined。
114
- */
115
- cause?: Error;
116
- /**
117
- * 请求持续时间(毫秒),由 hint.startTimestamp / hint.endTimestamp 计算。
118
- * 无法获取时间信息时为 undefined。
119
- */
120
- duration?: number;
121
- }
122
- /**
123
- * 捕获到 PostgREST 白名单错误时的事件数据。
124
- * 由 network observer 在响应体符合 PostgREST 结构且 code 命中白名单时构造并派发。
125
- */
126
- interface IPgRestWhitelistErrorInfo {
127
- /** 请求类型 */
128
- type: 'fetch' | 'xhr';
129
- method: string;
130
- url: string;
131
- statusCode: number;
132
- /** 解析后的 PostgREST 标准错误体 */
133
- pgRestError: IPgRestErrorBody;
134
- /** 原始请求体文本 */
135
- requestBody: string | undefined;
136
- /** 原始响应体文本 */
137
- responseBody: string;
138
- /**
139
- * 本次请求触发前 scope 中已积累的 breadcrumb 链路,用于还原用户操作路径。
140
- * 包含导航(navigation)、点击(ui.click)、历史网络请求(fetch/xhr)、控制台日志等。
141
- * 取自 Sentry isolation scope,时序上早于当前这条 pgrest 请求。
142
- */
143
- precedingBreadcrumbs: Breadcrumb[];
144
- }
145
- /**
146
- * 捕获到 Auth 白名单错误时的事件数据。
147
- * 由 network observer 在响应体符合 Auth 结构且 code 命中白名单时构造并派发。
148
- */
149
- interface IAuthWhitelistErrorInfo {
150
- /** 请求类型 */
151
- type: 'fetch' | 'xhr';
152
- method: string;
153
- url: string;
154
- statusCode: number;
155
- /** 解析后的 Auth 标准错误体 */
156
- authError: IAuthErrorBody;
157
- /** 原始请求体文本 */
158
- requestBody: string | undefined;
159
- /** 原始响应体文本 */
160
- responseBody: string;
161
- /** 本次请求触发前 scope 中已积累的 breadcrumb 链路,用于还原用户操作路径。 */
162
- precedingBreadcrumbs: Breadcrumb[];
163
- }
164
- /**
165
- * 捕获到 Storage 白名单错误时的事件数据。
166
- * 由 network observer 在响应体符合 Storage 结构且 error 字段命中白名单时构造并派发。
167
- */
168
- interface IStorageWhitelistErrorInfo {
169
- /** 请求类型 */
170
- type: 'fetch' | 'xhr';
171
- method: string;
172
- url: string;
173
- statusCode: number;
174
- /** 解析后的 Storage 标准错误体 */
175
- storageError: IStorageErrorBody;
176
- /** 原始请求体文本 */
177
- requestBody: string | undefined;
178
- /** 原始响应体文本 */
179
- responseBody: string;
180
- /** 本次请求触发前 scope 中已积累的 breadcrumb 链路,用于还原用户操作路径。 */
181
- precedingBreadcrumbs: Breadcrumb[];
182
- }
183
- /** SentryCapture 的初始化选项,仅包含过滤与端点配置;事件处理通过 subscribers 注入。 */
184
- interface ISentryCaptureOptions {
185
- /**
186
- * 需要过滤的控制台日志关键词列表(必填,不过滤时传 `[]`)。
187
- * 所有参数序列化合并后包含任意关键词则跳过——不触发 onConsole,也不记录 breadcrumb。
188
- * 推荐以 `DEFAULT_CONSOLE_FILTER_KEYWORDS` 为基础按需追加。
189
- */
190
- consoleFilterKeywords: string[];
191
- /**
192
- * 需要忽略的请求 URL 模式(必填,不过滤时传 `[]`)。
193
- * 字符串会被编译为 `RegExp`;命中的请求不触发 onNetworkRequest,也不记录 fetch/xhr breadcrumb。
194
- * 推荐以 `DEFAULT_IGNORE_URLS` 为基础按需追加。
195
- */
196
- ignoreUrls: Array<string | RegExp>;
197
- /**
198
- * 匹配 PostgREST 端点的 URL 模式(可选,默认为 `DEFAULT_PGREST_URL_PATTERNS`)。
199
- * 命中模式的请求会额外做 PostgREST 响应体解析,检查是否触发白名单错误事件。
200
- */
201
- pgRestUrlPatterns?: Array<string | RegExp>;
202
- /**
203
- * PostgREST / PostgreSQL 白名单 error code 列表(可选,默认为 `DEFAULT_PGREST_WHITELIST_CODES`)。
204
- * 响应体的 `code` 字段命中此列表时触发 subscriber 的 `onPgRestWhitelistError`。
205
- *
206
- * TODO: 根据业务补充具体 code,例如:
207
- * 'PGRST301'(JWT 过期)、'PGRST116'(期望单行返回多行)、
208
- * '23505'(唯一键冲突)、'23503'(外键约束失败)
209
- */
210
- pgRestWhitelistCodes?: string[];
211
- /**
212
- * `onPgRestWhitelistError` 回调中 `precedingBreadcrumbs` 的最大条数(可选)。
213
- * 取 scope 中最新的 N 条,超出部分(更早的操作)被丢弃。
214
- * 未配置时取全部(受 Sentry `maxBreadcrumbs` 上限约束,默认最多 100 条)。
215
- */
216
- precedingBreadcrumbsLimit?: number;
217
- /**
218
- * 匹配 Auth 服务端点的 URL 模式(可选)。
219
- * 命中模式的请求会额外做 Auth 响应体解析,检查是否触发白名单错误事件。
220
- */
221
- authUrlPatterns?: Array<string | RegExp>;
222
- /**
223
- * Auth error 白名单 error code 列表(可选,默认为 `DEFAULT_AUTH_WHITELIST_CODES`)。
224
- */
225
- authWhitelistCodes?: string[];
226
- /**
227
- * 匹配 Storage 服务端点的 URL 模式(可选,默认为 `DEFAULT_STORAGE_URL_PATTERNS`)。
228
- * 命中模式的请求会额外做 Storage 响应体解析,检查是否触发白名单错误事件。
229
- */
230
- storageUrlPatterns?: Array<string | RegExp>;
231
- /**
232
- * Storage error 白名单列表(可选,默认为 `DEFAULT_STORAGE_WHITELIST_ERRORS`)。
233
- * 响应体的 `error` 字段命中此列表时触发 subscriber 的 `onStorageWhitelistError`。
234
- */
235
- storageWhitelistErrors?: string[];
236
- }
237
-
238
- /** 捕获事件订阅者接口与消息类型定义。 */
239
-
240
- /**
241
- * 捕获事件订阅者。
242
- * SentryCapture 捕获到事件后,逐个通知所有已注册的订阅者。
243
- * postMessage、日志输出、测试断言等均是不同的实现。
244
- */
245
- interface ICaptureSubscriber {
246
- onConsole(info: IConsoleCaptureInfo): void;
247
- onError(info: IErrorCaptureInfo): void;
248
- /**
249
- * 仅在以下情况触发:
250
- * - isError 为 true(网络层失败)
251
- * - HTTP 4xx 客户端错误
252
- *
253
- * 2xx / 3xx / 5xx 不触发。
254
- */
255
- onNetworkRequest(info: INetworkRequestInfo): void;
256
- /**
257
- * 请求命中 PostgREST 端点,且响应体 code 字段在白名单中时触发。
258
- * 适用于需要对特定数据库业务错误(如唯一键冲突、JWT 过期)做专项处理的场景。
259
- */
260
- onPgRestWhitelistError(info: IPgRestWhitelistErrorInfo): void;
261
- /**
262
- * 请求命中 Auth 端点,且响应体 code 字段在白名单中时触发。
263
- * 适用于需要对特定认证错误(如邮箱未确认、格式无效)做专项处理的场景。
264
- */
265
- onAuthWhitelistError(info: IAuthWhitelistErrorInfo): void;
266
- /**
267
- * 请求命中 Storage 端点,且响应体 error 字段在白名单中时触发。
268
- * 适用于需要对特定存储错误(如行级安全策略拒绝)做专项处理的场景。
269
- */
270
- onStorageWhitelistError(info: IStorageWhitelistErrorInfo): void;
271
- }
272
- /** postMessage 发送函数,可注入替换(便于测试)。 */
273
- interface GlobalErrorMessage {
274
- type: 'GLOBAL_ERROR';
275
- message: string;
276
- error: {
277
- name: string;
278
- message: string;
279
- stack?: string;
280
- } | null;
281
- errorData: {
282
- name: string;
283
- message: string;
284
- stack: string | null | undefined;
285
- fileName: string;
286
- lineNumber: number;
287
- columnNumber: number;
288
- httpPath?: string;
289
- httpStatus?: number;
290
- httpMethod?: string;
291
- requestBody?: string;
292
- responseBody?: string;
293
- /** PgRestWhitelistError 专属字段 */
294
- pgRestCode?: string;
295
- pgRestDetails?: string;
296
- pgRestHint?: string;
297
- requestType?: 'fetch' | 'xhr';
298
- /** AuthWhitelistError 专属字段 */
299
- authCode?: string;
300
- authRequestId?: string;
301
- /** StorageWhitelistError 专属字段 */
302
- storageError?: string;
303
- storageStatusCode?: string;
304
- precedingBreadcrumbs?: Breadcrumb[];
305
- };
306
- }
307
- type PostMessageFn = (message: GlobalErrorMessage, targetOrigin: string) => void;
308
-
309
- /**
310
- * Sentry 事件捕获封装。
311
- *
312
- * 提供三类观测能力:
313
- * - 错误捕获:通过 beforeSend 钩子提取异常信息
314
- * - 网络请求观测:通过 client.on('beforeAddBreadcrumb') 拦截,同时获取请求体和响应体
315
- * - 控制台观测:复用 Sentry console patch,支持关键词过滤
316
- *
317
- * 典型用法:实例化后将 beforeSend / beforeBreadcrumb 传入 Sentry.init(),
318
- * 并在 init 完成后调用 installNetworkObserver(),任意时机调用 installConsoleObserver()。
319
- */
320
-
321
- declare class SentryCapture {
322
- private readonly subscribers;
323
- private readonly console;
324
- private readonly network;
325
- constructor(opts: ISentryCaptureOptions, subscribers?: readonly ICaptureSubscriber[]);
326
- /** 在 Sentry.init() 完成后调用一次,注册网络请求观测器。 */
327
- installNetworkObserver(): void;
328
- /** 注册控制台日志观测器,可在 Sentry.init() 前后调用均可。 */
329
- installConsoleObserver(): void;
330
- /** 传入 Sentry.init({ beforeSend }) —— 提取错误信息触发 onError 回调。 */
331
- beforeSend(event: ErrorEvent, hint: EventHint): ErrorEvent;
332
- /**
333
- * 传入 Sentry.init({ beforeBreadcrumb })。
334
- * - console:过滤噪音关键词
335
- * - fetch/xhr:过滤 ignoreUrls 匹配的静态资源请求
336
- */
337
- beforeBreadcrumb(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): Breadcrumb | null;
338
- }
339
-
340
- /** 控制台日志捕获与过滤,复用 Sentry 已安装的 console patch。 */
341
-
342
- declare const DEFAULT_CONSOLE_FILTER_KEYWORDS: string[];
343
-
344
- /** 网络请求捕获,通过 Sentry beforeAddBreadcrumb 钩子同时获取请求体与响应体。 */
345
-
346
- /**
347
- * 默认忽略的请求 URL 模式,与 sc-plugin 的 ignoreUrls 默认值保持一致。
348
- * 覆盖范围:静态资源(js/css/字体/图片/map)、chunk 文件、/static/、/assets/ 路径。
349
- * 可直接传入 `ignoreUrls`,也可在其基础上追加自定义规则。
350
- */
351
- declare const DEFAULT_IGNORE_URLS: Array<string | RegExp>;
352
-
353
- /** 通过 window.parent.postMessage 向父窗口上报捕获事件的订阅者实现。 */
354
-
355
- declare function createPostMessageSubscriber(send?: PostMessageFn): ICaptureSubscriber;
356
-
357
- /** 空操作订阅者,用于测试或不需要副作用的场景。 */
358
-
359
- /** 创建一个什么都不做的订阅者,方便测试时按需 spy 或替换单个方法。 */
360
- declare function createNoopSubscriber(): ICaptureSubscriber;
361
-
362
- /**
363
- * 通过 Sentry.captureEvent 为每条 console 日志和网络请求创建独立 Sentry Event 的订阅者。
364
- *
365
- * - console.* → 一条 Sentry Event,level 与 console 级别对应
366
- * - 网络请求 → 一条 Sentry Event,message 格式为 "Fetch POST /path -> 409 (32ms)"
367
- *
368
- * onError 不处理,Sentry 已自动捕获并上报 JS 错误,无需重复 captureEvent。
369
- */
370
-
371
- interface ISentryEventSubscriberOptions {
372
- /**
373
- * 是否为所有网络请求(包括 2xx/3xx)创建 Sentry Event。
374
- * 默认 true(与 vite-plugin-monitor 旧版行为一致)。
375
- * 设为 false 时仅为 4xx、5xx 以及网络层失败创建 Event。
376
- */
377
- captureAllNetworkRequests?: boolean;
378
- }
379
- /**
380
- * 为每条 console 日志和网络请求创建独立 Sentry Event 的订阅者。
381
- *
382
- * @example
383
- * ```ts
384
- * const capture = new SentryCapture({
385
- * consoleFilterKeywords: DEFAULT_CONSOLE_FILTER_KEYWORDS,
386
- * ignoreUrls: DEFAULT_IGNORE_URLS,
387
- * });
388
- * capture.addSubscriber(createSentryEventSubscriber());
389
- * capture.addSubscriber(createPostMessageSubscriber());
390
- * ```
391
- */
392
- declare function createSentryEventSubscriber(opts?: ISentryEventSubscriberOptions): ICaptureSubscriber;
393
-
394
- export { DEFAULT_AUTH_URL_PATTERNS, DEFAULT_AUTH_WHITELIST_CODES, DEFAULT_CONSOLE_FILTER_KEYWORDS, DEFAULT_IGNORE_URLS, DEFAULT_PGREST_URL_PATTERNS, DEFAULT_PGREST_WHITELIST_CODES, DEFAULT_STORAGE_URL_PATTERNS, DEFAULT_STORAGE_WHITELIST_ERRORS, type GlobalErrorMessage, type IAuthErrorBody, type IAuthWhitelistErrorInfo, type ICaptureSubscriber, type IConsoleCaptureInfo, type IErrorCaptureInfo, type INetworkRequestInfo, type IPgRestErrorBody, type IPgRestWhitelistErrorInfo, type ISentryCaptureOptions, type ISentryEventSubscriberOptions, type IStorageErrorBody, type IStorageWhitelistErrorInfo, type PostMessageFn, SentryCapture, createNoopSubscriber, createPostMessageSubscriber, createSentryEventSubscriber };
2
+ export { }