miaoda-react-devkit 0.1.1-beta.1 → 0.1.1-beta.11

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,4 +1,4 @@
1
- import { ErrorEvent, EventHint, Breadcrumb, BreadcrumbHint } from '@sentry/react';
1
+ import { Breadcrumb, ErrorEvent, EventHint, BreadcrumbHint } from '@sentry/react';
2
2
 
3
3
  /** PostgREST 响应检测与错误体解析。 */
4
4
  /**
@@ -24,6 +24,29 @@ interface IPgRestErrorBody {
24
24
  hint: string | null;
25
25
  }
26
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
+
27
50
  /** Sentry 捕获模块共享类型定义。 */
28
51
 
29
52
  interface IErrorCaptureInfo {
@@ -68,6 +91,11 @@ interface INetworkRequestInfo {
68
91
  * XHR 网络失败时 Sentry hint 中不携带 Error 对象,此字段为 undefined。
69
92
  */
70
93
  cause?: Error;
94
+ /**
95
+ * 请求持续时间(毫秒),由 hint.startTimestamp / hint.endTimestamp 计算。
96
+ * 无法获取时间信息时为 undefined。
97
+ */
98
+ duration?: number;
71
99
  }
72
100
  /**
73
101
  * 捕获到 PostgREST 白名单错误时的事件数据。
@@ -85,6 +113,31 @@ interface IPgRestWhitelistErrorInfo {
85
113
  requestBody: string | undefined;
86
114
  /** 原始响应体文本 */
87
115
  responseBody: string;
116
+ /**
117
+ * 本次请求触发前 scope 中已积累的 breadcrumb 链路,用于还原用户操作路径。
118
+ * 包含导航(navigation)、点击(ui.click)、历史网络请求(fetch/xhr)、控制台日志等。
119
+ * 取自 Sentry isolation scope,时序上早于当前这条 pgrest 请求。
120
+ */
121
+ precedingBreadcrumbs: Breadcrumb[];
122
+ }
123
+ /**
124
+ * 捕获到 Auth 白名单错误时的事件数据。
125
+ * 由 network observer 在响应体符合 Auth 结构且 code 命中白名单时构造并派发。
126
+ */
127
+ interface IAuthWhitelistErrorInfo {
128
+ /** 请求类型 */
129
+ type: 'fetch' | 'xhr';
130
+ method: string;
131
+ url: string;
132
+ statusCode: number;
133
+ /** 解析后的 Auth 标准错误体 */
134
+ authError: IAuthErrorBody;
135
+ /** 原始请求体文本 */
136
+ requestBody: string | undefined;
137
+ /** 原始响应体文本 */
138
+ responseBody: string;
139
+ /** 本次请求触发前 scope 中已积累的 breadcrumb 链路,用于还原用户操作路径。 */
140
+ precedingBreadcrumbs: Breadcrumb[];
88
141
  }
89
142
  /** SentryCapture 的初始化选项,仅包含过滤与端点配置;事件处理通过 subscribers 注入。 */
90
143
  interface ISentryCaptureOptions {
@@ -114,6 +167,21 @@ interface ISentryCaptureOptions {
114
167
  * '23505'(唯一键冲突)、'23503'(外键约束失败)
115
168
  */
116
169
  pgRestWhitelistCodes?: string[];
170
+ /**
171
+ * `onPgRestWhitelistError` 回调中 `precedingBreadcrumbs` 的最大条数(可选)。
172
+ * 取 scope 中最新的 N 条,超出部分(更早的操作)被丢弃。
173
+ * 未配置时取全部(受 Sentry `maxBreadcrumbs` 上限约束,默认最多 100 条)。
174
+ */
175
+ precedingBreadcrumbsLimit?: number;
176
+ /**
177
+ * 匹配 Auth 服务端点的 URL 模式(可选)。
178
+ * 命中模式的请求会额外做 Auth 响应体解析,检查是否触发白名单错误事件。
179
+ */
180
+ authUrlPatterns?: Array<string | RegExp>;
181
+ /**
182
+ * Auth error 白名单 error code 列表(可选,默认为 `DEFAULT_AUTH_WHITELIST_CODES`)。
183
+ */
184
+ authWhitelistCodes?: string[];
117
185
  }
118
186
 
119
187
  /** 捕获事件订阅者接口与消息类型定义。 */
@@ -139,6 +207,11 @@ interface ICaptureSubscriber {
139
207
  * 适用于需要对特定数据库业务错误(如唯一键冲突、JWT 过期)做专项处理的场景。
140
208
  */
141
209
  onPgRestWhitelistError(info: IPgRestWhitelistErrorInfo): void;
210
+ /**
211
+ * 请求命中 Auth 端点,且响应体 code 字段在白名单中时触发。
212
+ * 适用于需要对特定认证错误(如邮箱未确认、格式无效)做专项处理的场景。
213
+ */
214
+ onAuthWhitelistError(info: IAuthWhitelistErrorInfo): void;
142
215
  }
143
216
  /** postMessage 发送函数,可注入替换(便于测试)。 */
144
217
  interface GlobalErrorMessage {
@@ -166,6 +239,10 @@ interface GlobalErrorMessage {
166
239
  pgRestDetails?: string;
167
240
  pgRestHint?: string;
168
241
  requestType?: 'fetch' | 'xhr';
242
+ /** AuthWhitelistError 专属字段 */
243
+ authCode?: string;
244
+ authRequestId?: string;
245
+ precedingBreadcrumbs?: Breadcrumb[];
169
246
  };
170
247
  }
171
248
  type PostMessageFn = (message: GlobalErrorMessage, targetOrigin: string) => void;
@@ -223,4 +300,36 @@ declare function createPostMessageSubscriber(send?: PostMessageFn): ICaptureSubs
223
300
  /** 创建一个什么都不做的订阅者,方便测试时按需 spy 或替换单个方法。 */
224
301
  declare function createNoopSubscriber(): ICaptureSubscriber;
225
302
 
226
- export { DEFAULT_CONSOLE_FILTER_KEYWORDS, DEFAULT_IGNORE_URLS, DEFAULT_PGREST_URL_PATTERNS, DEFAULT_PGREST_WHITELIST_CODES, type GlobalErrorMessage, type ICaptureSubscriber, type IConsoleCaptureInfo, type IErrorCaptureInfo, type INetworkRequestInfo, type IPgRestErrorBody, type IPgRestWhitelistErrorInfo, type ISentryCaptureOptions, type PostMessageFn, SentryCapture, createNoopSubscriber, createPostMessageSubscriber };
303
+ /**
304
+ * 通过 Sentry.captureEvent 为每条 console 日志和网络请求创建独立 Sentry Event 的订阅者。
305
+ *
306
+ * - console.* → 一条 Sentry Event,level 与 console 级别对应
307
+ * - 网络请求 → 一条 Sentry Event,message 格式为 "Fetch POST /path -> 409 (32ms)"
308
+ *
309
+ * onError 不处理,Sentry 已自动捕获并上报 JS 错误,无需重复 captureEvent。
310
+ */
311
+
312
+ interface ISentryEventSubscriberOptions {
313
+ /**
314
+ * 是否为所有网络请求(包括 2xx/3xx)创建 Sentry Event。
315
+ * 默认 true(与 vite-plugin-monitor 旧版行为一致)。
316
+ * 设为 false 时仅为 4xx、5xx 以及网络层失败创建 Event。
317
+ */
318
+ captureAllNetworkRequests?: boolean;
319
+ }
320
+ /**
321
+ * 为每条 console 日志和网络请求创建独立 Sentry Event 的订阅者。
322
+ *
323
+ * @example
324
+ * ```ts
325
+ * const capture = new SentryCapture({
326
+ * consoleFilterKeywords: DEFAULT_CONSOLE_FILTER_KEYWORDS,
327
+ * ignoreUrls: DEFAULT_IGNORE_URLS,
328
+ * });
329
+ * capture.addSubscriber(createSentryEventSubscriber());
330
+ * capture.addSubscriber(createPostMessageSubscriber());
331
+ * ```
332
+ */
333
+ declare function createSentryEventSubscriber(opts?: ISentryEventSubscriberOptions): ICaptureSubscriber;
334
+
335
+ export { DEFAULT_AUTH_URL_PATTERNS, DEFAULT_AUTH_WHITELIST_CODES, DEFAULT_CONSOLE_FILTER_KEYWORDS, DEFAULT_IGNORE_URLS, DEFAULT_PGREST_URL_PATTERNS, DEFAULT_PGREST_WHITELIST_CODES, type GlobalErrorMessage, type IAuthErrorBody, type IAuthWhitelistErrorInfo, type ICaptureSubscriber, type IConsoleCaptureInfo, type IErrorCaptureInfo, type INetworkRequestInfo, type IPgRestErrorBody, type IPgRestWhitelistErrorInfo, type ISentryCaptureOptions, type ISentryEventSubscriberOptions, type PostMessageFn, SentryCapture, createNoopSubscriber, createPostMessageSubscriber, createSentryEventSubscriber };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ErrorEvent, EventHint, Breadcrumb, BreadcrumbHint } from '@sentry/react';
1
+ import { Breadcrumb, ErrorEvent, EventHint, BreadcrumbHint } from '@sentry/react';
2
2
 
3
3
  /** PostgREST 响应检测与错误体解析。 */
4
4
  /**
@@ -24,6 +24,29 @@ interface IPgRestErrorBody {
24
24
  hint: string | null;
25
25
  }
26
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
+
27
50
  /** Sentry 捕获模块共享类型定义。 */
28
51
 
29
52
  interface IErrorCaptureInfo {
@@ -68,6 +91,11 @@ interface INetworkRequestInfo {
68
91
  * XHR 网络失败时 Sentry hint 中不携带 Error 对象,此字段为 undefined。
69
92
  */
70
93
  cause?: Error;
94
+ /**
95
+ * 请求持续时间(毫秒),由 hint.startTimestamp / hint.endTimestamp 计算。
96
+ * 无法获取时间信息时为 undefined。
97
+ */
98
+ duration?: number;
71
99
  }
72
100
  /**
73
101
  * 捕获到 PostgREST 白名单错误时的事件数据。
@@ -85,6 +113,31 @@ interface IPgRestWhitelistErrorInfo {
85
113
  requestBody: string | undefined;
86
114
  /** 原始响应体文本 */
87
115
  responseBody: string;
116
+ /**
117
+ * 本次请求触发前 scope 中已积累的 breadcrumb 链路,用于还原用户操作路径。
118
+ * 包含导航(navigation)、点击(ui.click)、历史网络请求(fetch/xhr)、控制台日志等。
119
+ * 取自 Sentry isolation scope,时序上早于当前这条 pgrest 请求。
120
+ */
121
+ precedingBreadcrumbs: Breadcrumb[];
122
+ }
123
+ /**
124
+ * 捕获到 Auth 白名单错误时的事件数据。
125
+ * 由 network observer 在响应体符合 Auth 结构且 code 命中白名单时构造并派发。
126
+ */
127
+ interface IAuthWhitelistErrorInfo {
128
+ /** 请求类型 */
129
+ type: 'fetch' | 'xhr';
130
+ method: string;
131
+ url: string;
132
+ statusCode: number;
133
+ /** 解析后的 Auth 标准错误体 */
134
+ authError: IAuthErrorBody;
135
+ /** 原始请求体文本 */
136
+ requestBody: string | undefined;
137
+ /** 原始响应体文本 */
138
+ responseBody: string;
139
+ /** 本次请求触发前 scope 中已积累的 breadcrumb 链路,用于还原用户操作路径。 */
140
+ precedingBreadcrumbs: Breadcrumb[];
88
141
  }
89
142
  /** SentryCapture 的初始化选项,仅包含过滤与端点配置;事件处理通过 subscribers 注入。 */
90
143
  interface ISentryCaptureOptions {
@@ -114,6 +167,21 @@ interface ISentryCaptureOptions {
114
167
  * '23505'(唯一键冲突)、'23503'(外键约束失败)
115
168
  */
116
169
  pgRestWhitelistCodes?: string[];
170
+ /**
171
+ * `onPgRestWhitelistError` 回调中 `precedingBreadcrumbs` 的最大条数(可选)。
172
+ * 取 scope 中最新的 N 条,超出部分(更早的操作)被丢弃。
173
+ * 未配置时取全部(受 Sentry `maxBreadcrumbs` 上限约束,默认最多 100 条)。
174
+ */
175
+ precedingBreadcrumbsLimit?: number;
176
+ /**
177
+ * 匹配 Auth 服务端点的 URL 模式(可选)。
178
+ * 命中模式的请求会额外做 Auth 响应体解析,检查是否触发白名单错误事件。
179
+ */
180
+ authUrlPatterns?: Array<string | RegExp>;
181
+ /**
182
+ * Auth error 白名单 error code 列表(可选,默认为 `DEFAULT_AUTH_WHITELIST_CODES`)。
183
+ */
184
+ authWhitelistCodes?: string[];
117
185
  }
118
186
 
119
187
  /** 捕获事件订阅者接口与消息类型定义。 */
@@ -139,6 +207,11 @@ interface ICaptureSubscriber {
139
207
  * 适用于需要对特定数据库业务错误(如唯一键冲突、JWT 过期)做专项处理的场景。
140
208
  */
141
209
  onPgRestWhitelistError(info: IPgRestWhitelistErrorInfo): void;
210
+ /**
211
+ * 请求命中 Auth 端点,且响应体 code 字段在白名单中时触发。
212
+ * 适用于需要对特定认证错误(如邮箱未确认、格式无效)做专项处理的场景。
213
+ */
214
+ onAuthWhitelistError(info: IAuthWhitelistErrorInfo): void;
142
215
  }
143
216
  /** postMessage 发送函数,可注入替换(便于测试)。 */
144
217
  interface GlobalErrorMessage {
@@ -166,6 +239,10 @@ interface GlobalErrorMessage {
166
239
  pgRestDetails?: string;
167
240
  pgRestHint?: string;
168
241
  requestType?: 'fetch' | 'xhr';
242
+ /** AuthWhitelistError 专属字段 */
243
+ authCode?: string;
244
+ authRequestId?: string;
245
+ precedingBreadcrumbs?: Breadcrumb[];
169
246
  };
170
247
  }
171
248
  type PostMessageFn = (message: GlobalErrorMessage, targetOrigin: string) => void;
@@ -223,4 +300,36 @@ declare function createPostMessageSubscriber(send?: PostMessageFn): ICaptureSubs
223
300
  /** 创建一个什么都不做的订阅者,方便测试时按需 spy 或替换单个方法。 */
224
301
  declare function createNoopSubscriber(): ICaptureSubscriber;
225
302
 
226
- export { DEFAULT_CONSOLE_FILTER_KEYWORDS, DEFAULT_IGNORE_URLS, DEFAULT_PGREST_URL_PATTERNS, DEFAULT_PGREST_WHITELIST_CODES, type GlobalErrorMessage, type ICaptureSubscriber, type IConsoleCaptureInfo, type IErrorCaptureInfo, type INetworkRequestInfo, type IPgRestErrorBody, type IPgRestWhitelistErrorInfo, type ISentryCaptureOptions, type PostMessageFn, SentryCapture, createNoopSubscriber, createPostMessageSubscriber };
303
+ /**
304
+ * 通过 Sentry.captureEvent 为每条 console 日志和网络请求创建独立 Sentry Event 的订阅者。
305
+ *
306
+ * - console.* → 一条 Sentry Event,level 与 console 级别对应
307
+ * - 网络请求 → 一条 Sentry Event,message 格式为 "Fetch POST /path -> 409 (32ms)"
308
+ *
309
+ * onError 不处理,Sentry 已自动捕获并上报 JS 错误,无需重复 captureEvent。
310
+ */
311
+
312
+ interface ISentryEventSubscriberOptions {
313
+ /**
314
+ * 是否为所有网络请求(包括 2xx/3xx)创建 Sentry Event。
315
+ * 默认 true(与 vite-plugin-monitor 旧版行为一致)。
316
+ * 设为 false 时仅为 4xx、5xx 以及网络层失败创建 Event。
317
+ */
318
+ captureAllNetworkRequests?: boolean;
319
+ }
320
+ /**
321
+ * 为每条 console 日志和网络请求创建独立 Sentry Event 的订阅者。
322
+ *
323
+ * @example
324
+ * ```ts
325
+ * const capture = new SentryCapture({
326
+ * consoleFilterKeywords: DEFAULT_CONSOLE_FILTER_KEYWORDS,
327
+ * ignoreUrls: DEFAULT_IGNORE_URLS,
328
+ * });
329
+ * capture.addSubscriber(createSentryEventSubscriber());
330
+ * capture.addSubscriber(createPostMessageSubscriber());
331
+ * ```
332
+ */
333
+ declare function createSentryEventSubscriber(opts?: ISentryEventSubscriberOptions): ICaptureSubscriber;
334
+
335
+ export { DEFAULT_AUTH_URL_PATTERNS, DEFAULT_AUTH_WHITELIST_CODES, DEFAULT_CONSOLE_FILTER_KEYWORDS, DEFAULT_IGNORE_URLS, DEFAULT_PGREST_URL_PATTERNS, DEFAULT_PGREST_WHITELIST_CODES, type GlobalErrorMessage, type IAuthErrorBody, type IAuthWhitelistErrorInfo, type ICaptureSubscriber, type IConsoleCaptureInfo, type IErrorCaptureInfo, type INetworkRequestInfo, type IPgRestErrorBody, type IPgRestWhitelistErrorInfo, type ISentryCaptureOptions, type ISentryEventSubscriberOptions, type PostMessageFn, SentryCapture, createNoopSubscriber, createPostMessageSubscriber, createSentryEventSubscriber };