miaoda-react-devkit 0.1.1-beta.12 → 0.1.1-beta.14
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.cjs +118 -47
- package/dist/index.d.cts +60 -1
- package/dist/index.d.ts +60 -1
- package/dist/index.js +116 -47
- package/dist/stubs/sentry-react-stub.js +182 -48
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -28,6 +28,8 @@ __export(src_exports, {
|
|
|
28
28
|
DEFAULT_IGNORE_URLS: () => DEFAULT_IGNORE_URLS,
|
|
29
29
|
DEFAULT_PGREST_URL_PATTERNS: () => DEFAULT_PGREST_URL_PATTERNS,
|
|
30
30
|
DEFAULT_PGREST_WHITELIST_CODES: () => DEFAULT_PGREST_WHITELIST_CODES,
|
|
31
|
+
DEFAULT_STORAGE_URL_PATTERNS: () => DEFAULT_STORAGE_URL_PATTERNS,
|
|
32
|
+
DEFAULT_STORAGE_WHITELIST_ERRORS: () => DEFAULT_STORAGE_WHITELIST_ERRORS,
|
|
31
33
|
SentryCapture: () => SentryCapture,
|
|
32
34
|
createNoopSubscriber: () => createNoopSubscriber,
|
|
33
35
|
createPostMessageSubscriber: () => createPostMessageSubscriber,
|
|
@@ -217,11 +219,37 @@ function parseAuthErrorBody(body) {
|
|
|
217
219
|
};
|
|
218
220
|
}
|
|
219
221
|
|
|
222
|
+
// src/capture/storage.ts
|
|
223
|
+
var DEFAULT_STORAGE_URL_PATTERNS = [/\/storage\/v1\//];
|
|
224
|
+
var DEFAULT_STORAGE_WHITELIST_ERRORS = ["new row violates row-level security policy"];
|
|
225
|
+
function isStorageRequest(url, patterns) {
|
|
226
|
+
return patterns.some((p) => (typeof p === "string" ? new RegExp(p) : p).test(url));
|
|
227
|
+
}
|
|
228
|
+
function parseStorageErrorBody(body) {
|
|
229
|
+
if (!body) return null;
|
|
230
|
+
let parsed;
|
|
231
|
+
try {
|
|
232
|
+
parsed = JSON.parse(body);
|
|
233
|
+
} catch {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
if (typeof parsed !== "object" || parsed === null) return null;
|
|
237
|
+
const p = parsed;
|
|
238
|
+
if (typeof p["statusCode"] !== "string") return null;
|
|
239
|
+
if (typeof p["error"] !== "string") return null;
|
|
240
|
+
if (typeof p["message"] !== "string") return null;
|
|
241
|
+
return {
|
|
242
|
+
statusCode: p["statusCode"],
|
|
243
|
+
error: p["error"],
|
|
244
|
+
message: p["message"]
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
220
248
|
// src/capture/network.ts
|
|
221
249
|
var BODY_TRUNCATE_LIMIT = 2e3;
|
|
222
250
|
function calcDuration(hint) {
|
|
223
251
|
if (hint?.startTimestamp == null || hint?.endTimestamp == null) return void 0;
|
|
224
|
-
return Math.round(
|
|
252
|
+
return Math.round(hint.endTimestamp - hint.startTimestamp);
|
|
225
253
|
}
|
|
226
254
|
var DEFAULT_IGNORE_URLS = [
|
|
227
255
|
/\.(js|css|png|jpg|jpeg|gif|svg|ico|woff|woff2|ttf|eot|map)(\?.*)?$/,
|
|
@@ -330,64 +358,74 @@ async function handleFetchBreadcrumb(breadcrumb, hint, handler) {
|
|
|
330
358
|
await handler({ type: "fetch", method, url, statusCode, requestBody, responseBody, isError, cause, duration });
|
|
331
359
|
}
|
|
332
360
|
function createNetworkObserver(opts, subscribers) {
|
|
333
|
-
const
|
|
361
|
+
const isIgnored = createUrlMatcher(opts.ignoreUrls);
|
|
334
362
|
const pgRestPatterns = opts.pgRestUrlPatterns ?? DEFAULT_PGREST_URL_PATTERNS;
|
|
335
363
|
const pgRestWhitelistCodes = opts.pgRestWhitelistCodes ?? DEFAULT_PGREST_WHITELIST_CODES;
|
|
336
364
|
const precedingBreadcrumbsLimit = opts.precedingBreadcrumbsLimit;
|
|
337
365
|
const authPatterns = opts.authUrlPatterns ?? DEFAULT_AUTH_URL_PATTERNS;
|
|
338
366
|
const authWhitelistCodes = opts.authWhitelistCodes ?? DEFAULT_AUTH_WHITELIST_CODES;
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
const allBreadcrumbs = (0, import_core3.getIsolationScope)().getScopeData().breadcrumbs;
|
|
346
|
-
const precedingBreadcrumbs = precedingBreadcrumbsLimit != null ? allBreadcrumbs.slice(-precedingBreadcrumbsLimit) : allBreadcrumbs.slice();
|
|
347
|
-
const info = {
|
|
348
|
-
type: requestType,
|
|
349
|
-
method,
|
|
350
|
-
url,
|
|
351
|
-
statusCode,
|
|
352
|
-
pgRestError,
|
|
353
|
-
requestBody,
|
|
354
|
-
responseBody,
|
|
355
|
-
precedingBreadcrumbs
|
|
356
|
-
};
|
|
357
|
-
for (const sub of subscribers) sub.onPgRestWhitelistError(info);
|
|
358
|
-
}
|
|
359
|
-
function tryDispatchAuthWhitelistError(requestType, method, url, statusCode, requestBody, responseBody) {
|
|
367
|
+
const storagePatterns = opts.storageUrlPatterns ?? DEFAULT_STORAGE_URL_PATTERNS;
|
|
368
|
+
const storageWhitelistErrors = opts.storageWhitelistErrors ?? DEFAULT_STORAGE_WHITELIST_ERRORS;
|
|
369
|
+
const shouldIgnore = (url) => {
|
|
370
|
+
return isIgnored(url) && !isPgRestRequest(url, pgRestPatterns) && !isAuthRequest(url, authPatterns) && !isStorageRequest(url, storagePatterns);
|
|
371
|
+
};
|
|
372
|
+
function tryDispatchError(requestType, method, url, statusCode, requestBody, responseBody) {
|
|
360
373
|
if (statusCode == null) return;
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
if (!authError) return;
|
|
364
|
-
if (authWhitelistCodes.length > 0 && !authWhitelistCodes.includes(authError.code)) return;
|
|
374
|
+
const errorRequestType = isPgRestRequest(url, pgRestPatterns) ? "pgrest" : isAuthRequest(url, authPatterns) ? "auth" : isStorageRequest(url, storagePatterns) ? "storage" : null;
|
|
375
|
+
if (!errorRequestType) return;
|
|
365
376
|
const allBreadcrumbs = (0, import_core3.getIsolationScope)().getScopeData().breadcrumbs;
|
|
366
377
|
const precedingBreadcrumbs = precedingBreadcrumbsLimit != null ? allBreadcrumbs.slice(-precedingBreadcrumbsLimit) : allBreadcrumbs.slice();
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
+
if (errorRequestType === "pgrest") {
|
|
379
|
+
const pgRestError = parsePgRestErrorBody(responseBody);
|
|
380
|
+
if (!pgRestError) return;
|
|
381
|
+
if (pgRestWhitelistCodes.length > 0 && !pgRestWhitelistCodes.includes(pgRestError.code)) return;
|
|
382
|
+
const info = {
|
|
383
|
+
type: requestType,
|
|
384
|
+
method,
|
|
385
|
+
url,
|
|
386
|
+
statusCode,
|
|
387
|
+
pgRestError,
|
|
388
|
+
requestBody,
|
|
389
|
+
responseBody,
|
|
390
|
+
precedingBreadcrumbs
|
|
391
|
+
};
|
|
392
|
+
for (const sub of subscribers) sub.onPgRestWhitelistError(info);
|
|
393
|
+
} else if (errorRequestType === "auth") {
|
|
394
|
+
const authError = parseAuthErrorBody(responseBody);
|
|
395
|
+
if (!authError) return;
|
|
396
|
+
if (authWhitelistCodes.length > 0 && !authWhitelistCodes.includes(authError.code)) return;
|
|
397
|
+
const info = {
|
|
398
|
+
type: requestType,
|
|
399
|
+
method,
|
|
400
|
+
url,
|
|
401
|
+
statusCode,
|
|
402
|
+
authError,
|
|
403
|
+
requestBody,
|
|
404
|
+
responseBody,
|
|
405
|
+
precedingBreadcrumbs
|
|
406
|
+
};
|
|
407
|
+
for (const sub of subscribers) sub.onAuthWhitelistError(info);
|
|
408
|
+
} else if (errorRequestType === "storage") {
|
|
409
|
+
const storageError = parseStorageErrorBody(responseBody);
|
|
410
|
+
if (!storageError) return;
|
|
411
|
+
if (storageWhitelistErrors.length > 0 && !storageWhitelistErrors.includes(storageError.message)) return;
|
|
412
|
+
const info = {
|
|
413
|
+
type: requestType,
|
|
414
|
+
method,
|
|
415
|
+
url,
|
|
416
|
+
statusCode,
|
|
417
|
+
storageError,
|
|
418
|
+
requestBody,
|
|
419
|
+
responseBody,
|
|
420
|
+
precedingBreadcrumbs
|
|
421
|
+
};
|
|
422
|
+
for (const sub of subscribers) sub.onStorageWhitelistError(info);
|
|
423
|
+
}
|
|
378
424
|
}
|
|
379
425
|
function makeHandler(requestType) {
|
|
380
426
|
return (info) => {
|
|
381
427
|
for (const sub of subscribers) void sub.onNetworkRequest(info);
|
|
382
|
-
|
|
383
|
-
requestType,
|
|
384
|
-
info.method,
|
|
385
|
-
info.url,
|
|
386
|
-
info.statusCode,
|
|
387
|
-
info.requestBody,
|
|
388
|
-
info.responseBody
|
|
389
|
-
);
|
|
390
|
-
tryDispatchAuthWhitelistError(
|
|
428
|
+
tryDispatchError(
|
|
391
429
|
requestType,
|
|
392
430
|
info.method,
|
|
393
431
|
info.url,
|
|
@@ -564,6 +602,33 @@ var PostMessageSubscriber = class {
|
|
|
564
602
|
};
|
|
565
603
|
this.send(msg, "*");
|
|
566
604
|
}
|
|
605
|
+
onStorageWhitelistError({ type, method, url, statusCode, storageError, requestBody, responseBody, precedingBreadcrumbs }) {
|
|
606
|
+
const urlPath = extractUrlPath(url);
|
|
607
|
+
const errorMessage = `${method} ${urlPath} -> ${statusCode} [Storage:${storageError.error}]`;
|
|
608
|
+
const msg = {
|
|
609
|
+
type: "GLOBAL_ERROR",
|
|
610
|
+
message: errorMessage,
|
|
611
|
+
error: null,
|
|
612
|
+
errorData: {
|
|
613
|
+
name: "StorageWhitelistError",
|
|
614
|
+
message: storageError.message,
|
|
615
|
+
stack: null,
|
|
616
|
+
fileName: url,
|
|
617
|
+
lineNumber: 0,
|
|
618
|
+
columnNumber: 0,
|
|
619
|
+
httpPath: urlPath,
|
|
620
|
+
httpStatus: statusCode,
|
|
621
|
+
httpMethod: method,
|
|
622
|
+
requestBody: requestBody ?? "",
|
|
623
|
+
responseBody,
|
|
624
|
+
storageError: storageError.error,
|
|
625
|
+
storageStatusCode: storageError.statusCode,
|
|
626
|
+
requestType: type,
|
|
627
|
+
precedingBreadcrumbs
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
this.send(msg, "*");
|
|
631
|
+
}
|
|
567
632
|
};
|
|
568
633
|
function createPostMessageSubscriber(send) {
|
|
569
634
|
return new PostMessageSubscriber(send);
|
|
@@ -581,6 +646,8 @@ function createNoopSubscriber() {
|
|
|
581
646
|
onPgRestWhitelistError() {
|
|
582
647
|
},
|
|
583
648
|
onAuthWhitelistError() {
|
|
649
|
+
},
|
|
650
|
+
onStorageWhitelistError() {
|
|
584
651
|
}
|
|
585
652
|
};
|
|
586
653
|
}
|
|
@@ -649,6 +716,8 @@ var SentryEventSubscriber = class {
|
|
|
649
716
|
}
|
|
650
717
|
onAuthWhitelistError(_info) {
|
|
651
718
|
}
|
|
719
|
+
onStorageWhitelistError(_info) {
|
|
720
|
+
}
|
|
652
721
|
};
|
|
653
722
|
function createSentryEventSubscriber(opts) {
|
|
654
723
|
return new SentryEventSubscriber(opts);
|
|
@@ -661,6 +730,8 @@ function createSentryEventSubscriber(opts) {
|
|
|
661
730
|
DEFAULT_IGNORE_URLS,
|
|
662
731
|
DEFAULT_PGREST_URL_PATTERNS,
|
|
663
732
|
DEFAULT_PGREST_WHITELIST_CODES,
|
|
733
|
+
DEFAULT_STORAGE_URL_PATTERNS,
|
|
734
|
+
DEFAULT_STORAGE_WHITELIST_ERRORS,
|
|
664
735
|
SentryCapture,
|
|
665
736
|
createNoopSubscriber,
|
|
666
737
|
createPostMessageSubscriber,
|
package/dist/index.d.cts
CHANGED
|
@@ -47,6 +47,28 @@ interface IAuthErrorBody {
|
|
|
47
47
|
message: string;
|
|
48
48
|
}
|
|
49
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
|
+
|
|
50
72
|
/** Sentry 捕获模块共享类型定义。 */
|
|
51
73
|
|
|
52
74
|
interface IErrorCaptureInfo {
|
|
@@ -139,6 +161,25 @@ interface IAuthWhitelistErrorInfo {
|
|
|
139
161
|
/** 本次请求触发前 scope 中已积累的 breadcrumb 链路,用于还原用户操作路径。 */
|
|
140
162
|
precedingBreadcrumbs: Breadcrumb[];
|
|
141
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
|
+
}
|
|
142
183
|
/** SentryCapture 的初始化选项,仅包含过滤与端点配置;事件处理通过 subscribers 注入。 */
|
|
143
184
|
interface ISentryCaptureOptions {
|
|
144
185
|
/**
|
|
@@ -182,6 +223,16 @@ interface ISentryCaptureOptions {
|
|
|
182
223
|
* Auth error 白名单 error code 列表(可选,默认为 `DEFAULT_AUTH_WHITELIST_CODES`)。
|
|
183
224
|
*/
|
|
184
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[];
|
|
185
236
|
}
|
|
186
237
|
|
|
187
238
|
/** 捕获事件订阅者接口与消息类型定义。 */
|
|
@@ -212,6 +263,11 @@ interface ICaptureSubscriber {
|
|
|
212
263
|
* 适用于需要对特定认证错误(如邮箱未确认、格式无效)做专项处理的场景。
|
|
213
264
|
*/
|
|
214
265
|
onAuthWhitelistError(info: IAuthWhitelistErrorInfo): void;
|
|
266
|
+
/**
|
|
267
|
+
* 请求命中 Storage 端点,且响应体 error 字段在白名单中时触发。
|
|
268
|
+
* 适用于需要对特定存储错误(如行级安全策略拒绝)做专项处理的场景。
|
|
269
|
+
*/
|
|
270
|
+
onStorageWhitelistError(info: IStorageWhitelistErrorInfo): void;
|
|
215
271
|
}
|
|
216
272
|
/** postMessage 发送函数,可注入替换(便于测试)。 */
|
|
217
273
|
interface GlobalErrorMessage {
|
|
@@ -242,6 +298,9 @@ interface GlobalErrorMessage {
|
|
|
242
298
|
/** AuthWhitelistError 专属字段 */
|
|
243
299
|
authCode?: string;
|
|
244
300
|
authRequestId?: string;
|
|
301
|
+
/** StorageWhitelistError 专属字段 */
|
|
302
|
+
storageError?: string;
|
|
303
|
+
storageStatusCode?: string;
|
|
245
304
|
precedingBreadcrumbs?: Breadcrumb[];
|
|
246
305
|
};
|
|
247
306
|
}
|
|
@@ -332,4 +391,4 @@ interface ISentryEventSubscriberOptions {
|
|
|
332
391
|
*/
|
|
333
392
|
declare function createSentryEventSubscriber(opts?: ISentryEventSubscriberOptions): ICaptureSubscriber;
|
|
334
393
|
|
|
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 };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -47,6 +47,28 @@ interface IAuthErrorBody {
|
|
|
47
47
|
message: string;
|
|
48
48
|
}
|
|
49
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
|
+
|
|
50
72
|
/** Sentry 捕获模块共享类型定义。 */
|
|
51
73
|
|
|
52
74
|
interface IErrorCaptureInfo {
|
|
@@ -139,6 +161,25 @@ interface IAuthWhitelistErrorInfo {
|
|
|
139
161
|
/** 本次请求触发前 scope 中已积累的 breadcrumb 链路,用于还原用户操作路径。 */
|
|
140
162
|
precedingBreadcrumbs: Breadcrumb[];
|
|
141
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
|
+
}
|
|
142
183
|
/** SentryCapture 的初始化选项,仅包含过滤与端点配置;事件处理通过 subscribers 注入。 */
|
|
143
184
|
interface ISentryCaptureOptions {
|
|
144
185
|
/**
|
|
@@ -182,6 +223,16 @@ interface ISentryCaptureOptions {
|
|
|
182
223
|
* Auth error 白名单 error code 列表(可选,默认为 `DEFAULT_AUTH_WHITELIST_CODES`)。
|
|
183
224
|
*/
|
|
184
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[];
|
|
185
236
|
}
|
|
186
237
|
|
|
187
238
|
/** 捕获事件订阅者接口与消息类型定义。 */
|
|
@@ -212,6 +263,11 @@ interface ICaptureSubscriber {
|
|
|
212
263
|
* 适用于需要对特定认证错误(如邮箱未确认、格式无效)做专项处理的场景。
|
|
213
264
|
*/
|
|
214
265
|
onAuthWhitelistError(info: IAuthWhitelistErrorInfo): void;
|
|
266
|
+
/**
|
|
267
|
+
* 请求命中 Storage 端点,且响应体 error 字段在白名单中时触发。
|
|
268
|
+
* 适用于需要对特定存储错误(如行级安全策略拒绝)做专项处理的场景。
|
|
269
|
+
*/
|
|
270
|
+
onStorageWhitelistError(info: IStorageWhitelistErrorInfo): void;
|
|
215
271
|
}
|
|
216
272
|
/** postMessage 发送函数,可注入替换(便于测试)。 */
|
|
217
273
|
interface GlobalErrorMessage {
|
|
@@ -242,6 +298,9 @@ interface GlobalErrorMessage {
|
|
|
242
298
|
/** AuthWhitelistError 专属字段 */
|
|
243
299
|
authCode?: string;
|
|
244
300
|
authRequestId?: string;
|
|
301
|
+
/** StorageWhitelistError 专属字段 */
|
|
302
|
+
storageError?: string;
|
|
303
|
+
storageStatusCode?: string;
|
|
245
304
|
precedingBreadcrumbs?: Breadcrumb[];
|
|
246
305
|
};
|
|
247
306
|
}
|
|
@@ -332,4 +391,4 @@ interface ISentryEventSubscriberOptions {
|
|
|
332
391
|
*/
|
|
333
392
|
declare function createSentryEventSubscriber(opts?: ISentryEventSubscriberOptions): ICaptureSubscriber;
|
|
334
393
|
|
|
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 };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -184,11 +184,37 @@ function parseAuthErrorBody(body) {
|
|
|
184
184
|
};
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
+
// src/capture/storage.ts
|
|
188
|
+
var DEFAULT_STORAGE_URL_PATTERNS = [/\/storage\/v1\//];
|
|
189
|
+
var DEFAULT_STORAGE_WHITELIST_ERRORS = ["new row violates row-level security policy"];
|
|
190
|
+
function isStorageRequest(url, patterns) {
|
|
191
|
+
return patterns.some((p) => (typeof p === "string" ? new RegExp(p) : p).test(url));
|
|
192
|
+
}
|
|
193
|
+
function parseStorageErrorBody(body) {
|
|
194
|
+
if (!body) return null;
|
|
195
|
+
let parsed;
|
|
196
|
+
try {
|
|
197
|
+
parsed = JSON.parse(body);
|
|
198
|
+
} catch {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
if (typeof parsed !== "object" || parsed === null) return null;
|
|
202
|
+
const p = parsed;
|
|
203
|
+
if (typeof p["statusCode"] !== "string") return null;
|
|
204
|
+
if (typeof p["error"] !== "string") return null;
|
|
205
|
+
if (typeof p["message"] !== "string") return null;
|
|
206
|
+
return {
|
|
207
|
+
statusCode: p["statusCode"],
|
|
208
|
+
error: p["error"],
|
|
209
|
+
message: p["message"]
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
187
213
|
// src/capture/network.ts
|
|
188
214
|
var BODY_TRUNCATE_LIMIT = 2e3;
|
|
189
215
|
function calcDuration(hint) {
|
|
190
216
|
if (hint?.startTimestamp == null || hint?.endTimestamp == null) return void 0;
|
|
191
|
-
return Math.round(
|
|
217
|
+
return Math.round(hint.endTimestamp - hint.startTimestamp);
|
|
192
218
|
}
|
|
193
219
|
var DEFAULT_IGNORE_URLS = [
|
|
194
220
|
/\.(js|css|png|jpg|jpeg|gif|svg|ico|woff|woff2|ttf|eot|map)(\?.*)?$/,
|
|
@@ -297,64 +323,74 @@ async function handleFetchBreadcrumb(breadcrumb, hint, handler) {
|
|
|
297
323
|
await handler({ type: "fetch", method, url, statusCode, requestBody, responseBody, isError, cause, duration });
|
|
298
324
|
}
|
|
299
325
|
function createNetworkObserver(opts, subscribers) {
|
|
300
|
-
const
|
|
326
|
+
const isIgnored = createUrlMatcher(opts.ignoreUrls);
|
|
301
327
|
const pgRestPatterns = opts.pgRestUrlPatterns ?? DEFAULT_PGREST_URL_PATTERNS;
|
|
302
328
|
const pgRestWhitelistCodes = opts.pgRestWhitelistCodes ?? DEFAULT_PGREST_WHITELIST_CODES;
|
|
303
329
|
const precedingBreadcrumbsLimit = opts.precedingBreadcrumbsLimit;
|
|
304
330
|
const authPatterns = opts.authUrlPatterns ?? DEFAULT_AUTH_URL_PATTERNS;
|
|
305
331
|
const authWhitelistCodes = opts.authWhitelistCodes ?? DEFAULT_AUTH_WHITELIST_CODES;
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
const allBreadcrumbs = getIsolationScope().getScopeData().breadcrumbs;
|
|
313
|
-
const precedingBreadcrumbs = precedingBreadcrumbsLimit != null ? allBreadcrumbs.slice(-precedingBreadcrumbsLimit) : allBreadcrumbs.slice();
|
|
314
|
-
const info = {
|
|
315
|
-
type: requestType,
|
|
316
|
-
method,
|
|
317
|
-
url,
|
|
318
|
-
statusCode,
|
|
319
|
-
pgRestError,
|
|
320
|
-
requestBody,
|
|
321
|
-
responseBody,
|
|
322
|
-
precedingBreadcrumbs
|
|
323
|
-
};
|
|
324
|
-
for (const sub of subscribers) sub.onPgRestWhitelistError(info);
|
|
325
|
-
}
|
|
326
|
-
function tryDispatchAuthWhitelistError(requestType, method, url, statusCode, requestBody, responseBody) {
|
|
332
|
+
const storagePatterns = opts.storageUrlPatterns ?? DEFAULT_STORAGE_URL_PATTERNS;
|
|
333
|
+
const storageWhitelistErrors = opts.storageWhitelistErrors ?? DEFAULT_STORAGE_WHITELIST_ERRORS;
|
|
334
|
+
const shouldIgnore = (url) => {
|
|
335
|
+
return isIgnored(url) && !isPgRestRequest(url, pgRestPatterns) && !isAuthRequest(url, authPatterns) && !isStorageRequest(url, storagePatterns);
|
|
336
|
+
};
|
|
337
|
+
function tryDispatchError(requestType, method, url, statusCode, requestBody, responseBody) {
|
|
327
338
|
if (statusCode == null) return;
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
if (!authError) return;
|
|
331
|
-
if (authWhitelistCodes.length > 0 && !authWhitelistCodes.includes(authError.code)) return;
|
|
339
|
+
const errorRequestType = isPgRestRequest(url, pgRestPatterns) ? "pgrest" : isAuthRequest(url, authPatterns) ? "auth" : isStorageRequest(url, storagePatterns) ? "storage" : null;
|
|
340
|
+
if (!errorRequestType) return;
|
|
332
341
|
const allBreadcrumbs = getIsolationScope().getScopeData().breadcrumbs;
|
|
333
342
|
const precedingBreadcrumbs = precedingBreadcrumbsLimit != null ? allBreadcrumbs.slice(-precedingBreadcrumbsLimit) : allBreadcrumbs.slice();
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
343
|
+
if (errorRequestType === "pgrest") {
|
|
344
|
+
const pgRestError = parsePgRestErrorBody(responseBody);
|
|
345
|
+
if (!pgRestError) return;
|
|
346
|
+
if (pgRestWhitelistCodes.length > 0 && !pgRestWhitelistCodes.includes(pgRestError.code)) return;
|
|
347
|
+
const info = {
|
|
348
|
+
type: requestType,
|
|
349
|
+
method,
|
|
350
|
+
url,
|
|
351
|
+
statusCode,
|
|
352
|
+
pgRestError,
|
|
353
|
+
requestBody,
|
|
354
|
+
responseBody,
|
|
355
|
+
precedingBreadcrumbs
|
|
356
|
+
};
|
|
357
|
+
for (const sub of subscribers) sub.onPgRestWhitelistError(info);
|
|
358
|
+
} else if (errorRequestType === "auth") {
|
|
359
|
+
const authError = parseAuthErrorBody(responseBody);
|
|
360
|
+
if (!authError) return;
|
|
361
|
+
if (authWhitelistCodes.length > 0 && !authWhitelistCodes.includes(authError.code)) return;
|
|
362
|
+
const info = {
|
|
363
|
+
type: requestType,
|
|
364
|
+
method,
|
|
365
|
+
url,
|
|
366
|
+
statusCode,
|
|
367
|
+
authError,
|
|
368
|
+
requestBody,
|
|
369
|
+
responseBody,
|
|
370
|
+
precedingBreadcrumbs
|
|
371
|
+
};
|
|
372
|
+
for (const sub of subscribers) sub.onAuthWhitelistError(info);
|
|
373
|
+
} else if (errorRequestType === "storage") {
|
|
374
|
+
const storageError = parseStorageErrorBody(responseBody);
|
|
375
|
+
if (!storageError) return;
|
|
376
|
+
if (storageWhitelistErrors.length > 0 && !storageWhitelistErrors.includes(storageError.message)) return;
|
|
377
|
+
const info = {
|
|
378
|
+
type: requestType,
|
|
379
|
+
method,
|
|
380
|
+
url,
|
|
381
|
+
statusCode,
|
|
382
|
+
storageError,
|
|
383
|
+
requestBody,
|
|
384
|
+
responseBody,
|
|
385
|
+
precedingBreadcrumbs
|
|
386
|
+
};
|
|
387
|
+
for (const sub of subscribers) sub.onStorageWhitelistError(info);
|
|
388
|
+
}
|
|
345
389
|
}
|
|
346
390
|
function makeHandler(requestType) {
|
|
347
391
|
return (info) => {
|
|
348
392
|
for (const sub of subscribers) void sub.onNetworkRequest(info);
|
|
349
|
-
|
|
350
|
-
requestType,
|
|
351
|
-
info.method,
|
|
352
|
-
info.url,
|
|
353
|
-
info.statusCode,
|
|
354
|
-
info.requestBody,
|
|
355
|
-
info.responseBody
|
|
356
|
-
);
|
|
357
|
-
tryDispatchAuthWhitelistError(
|
|
393
|
+
tryDispatchError(
|
|
358
394
|
requestType,
|
|
359
395
|
info.method,
|
|
360
396
|
info.url,
|
|
@@ -531,6 +567,33 @@ var PostMessageSubscriber = class {
|
|
|
531
567
|
};
|
|
532
568
|
this.send(msg, "*");
|
|
533
569
|
}
|
|
570
|
+
onStorageWhitelistError({ type, method, url, statusCode, storageError, requestBody, responseBody, precedingBreadcrumbs }) {
|
|
571
|
+
const urlPath = extractUrlPath(url);
|
|
572
|
+
const errorMessage = `${method} ${urlPath} -> ${statusCode} [Storage:${storageError.error}]`;
|
|
573
|
+
const msg = {
|
|
574
|
+
type: "GLOBAL_ERROR",
|
|
575
|
+
message: errorMessage,
|
|
576
|
+
error: null,
|
|
577
|
+
errorData: {
|
|
578
|
+
name: "StorageWhitelistError",
|
|
579
|
+
message: storageError.message,
|
|
580
|
+
stack: null,
|
|
581
|
+
fileName: url,
|
|
582
|
+
lineNumber: 0,
|
|
583
|
+
columnNumber: 0,
|
|
584
|
+
httpPath: urlPath,
|
|
585
|
+
httpStatus: statusCode,
|
|
586
|
+
httpMethod: method,
|
|
587
|
+
requestBody: requestBody ?? "",
|
|
588
|
+
responseBody,
|
|
589
|
+
storageError: storageError.error,
|
|
590
|
+
storageStatusCode: storageError.statusCode,
|
|
591
|
+
requestType: type,
|
|
592
|
+
precedingBreadcrumbs
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
this.send(msg, "*");
|
|
596
|
+
}
|
|
534
597
|
};
|
|
535
598
|
function createPostMessageSubscriber(send) {
|
|
536
599
|
return new PostMessageSubscriber(send);
|
|
@@ -548,6 +611,8 @@ function createNoopSubscriber() {
|
|
|
548
611
|
onPgRestWhitelistError() {
|
|
549
612
|
},
|
|
550
613
|
onAuthWhitelistError() {
|
|
614
|
+
},
|
|
615
|
+
onStorageWhitelistError() {
|
|
551
616
|
}
|
|
552
617
|
};
|
|
553
618
|
}
|
|
@@ -616,6 +681,8 @@ var SentryEventSubscriber = class {
|
|
|
616
681
|
}
|
|
617
682
|
onAuthWhitelistError(_info) {
|
|
618
683
|
}
|
|
684
|
+
onStorageWhitelistError(_info) {
|
|
685
|
+
}
|
|
619
686
|
};
|
|
620
687
|
function createSentryEventSubscriber(opts) {
|
|
621
688
|
return new SentryEventSubscriber(opts);
|
|
@@ -627,6 +694,8 @@ export {
|
|
|
627
694
|
DEFAULT_IGNORE_URLS,
|
|
628
695
|
DEFAULT_PGREST_URL_PATTERNS,
|
|
629
696
|
DEFAULT_PGREST_WHITELIST_CODES,
|
|
697
|
+
DEFAULT_STORAGE_URL_PATTERNS,
|
|
698
|
+
DEFAULT_STORAGE_WHITELIST_ERRORS,
|
|
630
699
|
SentryCapture,
|
|
631
700
|
createNoopSubscriber,
|
|
632
701
|
createPostMessageSubscriber,
|
|
@@ -187,11 +187,37 @@ function parseAuthErrorBody(body) {
|
|
|
187
187
|
};
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
// src/capture/storage.ts
|
|
191
|
+
var DEFAULT_STORAGE_URL_PATTERNS = [/\/storage\/v1\//];
|
|
192
|
+
var DEFAULT_STORAGE_WHITELIST_ERRORS = ["new row violates row-level security policy"];
|
|
193
|
+
function isStorageRequest(url, patterns) {
|
|
194
|
+
return patterns.some((p) => (typeof p === "string" ? new RegExp(p) : p).test(url));
|
|
195
|
+
}
|
|
196
|
+
function parseStorageErrorBody(body) {
|
|
197
|
+
if (!body) return null;
|
|
198
|
+
let parsed;
|
|
199
|
+
try {
|
|
200
|
+
parsed = JSON.parse(body);
|
|
201
|
+
} catch {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
if (typeof parsed !== "object" || parsed === null) return null;
|
|
205
|
+
const p = parsed;
|
|
206
|
+
if (typeof p["statusCode"] !== "string") return null;
|
|
207
|
+
if (typeof p["error"] !== "string") return null;
|
|
208
|
+
if (typeof p["message"] !== "string") return null;
|
|
209
|
+
return {
|
|
210
|
+
statusCode: p["statusCode"],
|
|
211
|
+
error: p["error"],
|
|
212
|
+
message: p["message"]
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
190
216
|
// src/capture/network.ts
|
|
191
217
|
var BODY_TRUNCATE_LIMIT = 2e3;
|
|
192
218
|
function calcDuration(hint) {
|
|
193
219
|
if (hint?.startTimestamp == null || hint?.endTimestamp == null) return void 0;
|
|
194
|
-
return Math.round(
|
|
220
|
+
return Math.round(hint.endTimestamp - hint.startTimestamp);
|
|
195
221
|
}
|
|
196
222
|
var DEFAULT_IGNORE_URLS = [
|
|
197
223
|
/\.(js|css|png|jpg|jpeg|gif|svg|ico|woff|woff2|ttf|eot|map)(\?.*)?$/,
|
|
@@ -300,64 +326,74 @@ async function handleFetchBreadcrumb(breadcrumb, hint, handler) {
|
|
|
300
326
|
await handler({ type: "fetch", method, url, statusCode, requestBody, responseBody, isError, cause, duration });
|
|
301
327
|
}
|
|
302
328
|
function createNetworkObserver(opts, subscribers) {
|
|
303
|
-
const
|
|
329
|
+
const isIgnored = createUrlMatcher(opts.ignoreUrls);
|
|
304
330
|
const pgRestPatterns = opts.pgRestUrlPatterns ?? DEFAULT_PGREST_URL_PATTERNS;
|
|
305
331
|
const pgRestWhitelistCodes = opts.pgRestWhitelistCodes ?? DEFAULT_PGREST_WHITELIST_CODES;
|
|
306
332
|
const precedingBreadcrumbsLimit = opts.precedingBreadcrumbsLimit;
|
|
307
333
|
const authPatterns = opts.authUrlPatterns ?? DEFAULT_AUTH_URL_PATTERNS;
|
|
308
334
|
const authWhitelistCodes = opts.authWhitelistCodes ?? DEFAULT_AUTH_WHITELIST_CODES;
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
const allBreadcrumbs = getIsolationScope().getScopeData().breadcrumbs;
|
|
316
|
-
const precedingBreadcrumbs = precedingBreadcrumbsLimit != null ? allBreadcrumbs.slice(-precedingBreadcrumbsLimit) : allBreadcrumbs.slice();
|
|
317
|
-
const info = {
|
|
318
|
-
type: requestType,
|
|
319
|
-
method,
|
|
320
|
-
url,
|
|
321
|
-
statusCode,
|
|
322
|
-
pgRestError,
|
|
323
|
-
requestBody,
|
|
324
|
-
responseBody,
|
|
325
|
-
precedingBreadcrumbs
|
|
326
|
-
};
|
|
327
|
-
for (const sub of subscribers) sub.onPgRestWhitelistError(info);
|
|
328
|
-
}
|
|
329
|
-
function tryDispatchAuthWhitelistError(requestType, method, url, statusCode, requestBody, responseBody) {
|
|
335
|
+
const storagePatterns = opts.storageUrlPatterns ?? DEFAULT_STORAGE_URL_PATTERNS;
|
|
336
|
+
const storageWhitelistErrors = opts.storageWhitelistErrors ?? DEFAULT_STORAGE_WHITELIST_ERRORS;
|
|
337
|
+
const shouldIgnore = (url) => {
|
|
338
|
+
return isIgnored(url) && !isPgRestRequest(url, pgRestPatterns) && !isAuthRequest(url, authPatterns) && !isStorageRequest(url, storagePatterns);
|
|
339
|
+
};
|
|
340
|
+
function tryDispatchError(requestType, method, url, statusCode, requestBody, responseBody) {
|
|
330
341
|
if (statusCode == null) return;
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
if (!authError) return;
|
|
334
|
-
if (authWhitelistCodes.length > 0 && !authWhitelistCodes.includes(authError.code)) return;
|
|
342
|
+
const errorRequestType = isPgRestRequest(url, pgRestPatterns) ? "pgrest" : isAuthRequest(url, authPatterns) ? "auth" : isStorageRequest(url, storagePatterns) ? "storage" : null;
|
|
343
|
+
if (!errorRequestType) return;
|
|
335
344
|
const allBreadcrumbs = getIsolationScope().getScopeData().breadcrumbs;
|
|
336
345
|
const precedingBreadcrumbs = precedingBreadcrumbsLimit != null ? allBreadcrumbs.slice(-precedingBreadcrumbsLimit) : allBreadcrumbs.slice();
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
346
|
+
if (errorRequestType === "pgrest") {
|
|
347
|
+
const pgRestError = parsePgRestErrorBody(responseBody);
|
|
348
|
+
if (!pgRestError) return;
|
|
349
|
+
if (pgRestWhitelistCodes.length > 0 && !pgRestWhitelistCodes.includes(pgRestError.code)) return;
|
|
350
|
+
const info = {
|
|
351
|
+
type: requestType,
|
|
352
|
+
method,
|
|
353
|
+
url,
|
|
354
|
+
statusCode,
|
|
355
|
+
pgRestError,
|
|
356
|
+
requestBody,
|
|
357
|
+
responseBody,
|
|
358
|
+
precedingBreadcrumbs
|
|
359
|
+
};
|
|
360
|
+
for (const sub of subscribers) sub.onPgRestWhitelistError(info);
|
|
361
|
+
} else if (errorRequestType === "auth") {
|
|
362
|
+
const authError = parseAuthErrorBody(responseBody);
|
|
363
|
+
if (!authError) return;
|
|
364
|
+
if (authWhitelistCodes.length > 0 && !authWhitelistCodes.includes(authError.code)) return;
|
|
365
|
+
const info = {
|
|
366
|
+
type: requestType,
|
|
367
|
+
method,
|
|
368
|
+
url,
|
|
369
|
+
statusCode,
|
|
370
|
+
authError,
|
|
371
|
+
requestBody,
|
|
372
|
+
responseBody,
|
|
373
|
+
precedingBreadcrumbs
|
|
374
|
+
};
|
|
375
|
+
for (const sub of subscribers) sub.onAuthWhitelistError(info);
|
|
376
|
+
} else if (errorRequestType === "storage") {
|
|
377
|
+
const storageError = parseStorageErrorBody(responseBody);
|
|
378
|
+
if (!storageError) return;
|
|
379
|
+
if (storageWhitelistErrors.length > 0 && !storageWhitelistErrors.includes(storageError.message)) return;
|
|
380
|
+
const info = {
|
|
381
|
+
type: requestType,
|
|
382
|
+
method,
|
|
383
|
+
url,
|
|
384
|
+
statusCode,
|
|
385
|
+
storageError,
|
|
386
|
+
requestBody,
|
|
387
|
+
responseBody,
|
|
388
|
+
precedingBreadcrumbs
|
|
389
|
+
};
|
|
390
|
+
for (const sub of subscribers) sub.onStorageWhitelistError(info);
|
|
391
|
+
}
|
|
348
392
|
}
|
|
349
393
|
function makeHandler(requestType) {
|
|
350
394
|
return (info) => {
|
|
351
395
|
for (const sub of subscribers) void sub.onNetworkRequest(info);
|
|
352
|
-
|
|
353
|
-
requestType,
|
|
354
|
-
info.method,
|
|
355
|
-
info.url,
|
|
356
|
-
info.statusCode,
|
|
357
|
-
info.requestBody,
|
|
358
|
-
info.responseBody
|
|
359
|
-
);
|
|
360
|
-
tryDispatchAuthWhitelistError(
|
|
396
|
+
tryDispatchError(
|
|
361
397
|
requestType,
|
|
362
398
|
info.method,
|
|
363
399
|
info.url,
|
|
@@ -534,17 +570,115 @@ var PostMessageSubscriber = class {
|
|
|
534
570
|
};
|
|
535
571
|
this.send(msg, "*");
|
|
536
572
|
}
|
|
573
|
+
onStorageWhitelistError({ type, method, url, statusCode, storageError, requestBody, responseBody, precedingBreadcrumbs }) {
|
|
574
|
+
const urlPath = extractUrlPath(url);
|
|
575
|
+
const errorMessage = `${method} ${urlPath} -> ${statusCode} [Storage:${storageError.error}]`;
|
|
576
|
+
const msg = {
|
|
577
|
+
type: "GLOBAL_ERROR",
|
|
578
|
+
message: errorMessage,
|
|
579
|
+
error: null,
|
|
580
|
+
errorData: {
|
|
581
|
+
name: "StorageWhitelistError",
|
|
582
|
+
message: storageError.message,
|
|
583
|
+
stack: null,
|
|
584
|
+
fileName: url,
|
|
585
|
+
lineNumber: 0,
|
|
586
|
+
columnNumber: 0,
|
|
587
|
+
httpPath: urlPath,
|
|
588
|
+
httpStatus: statusCode,
|
|
589
|
+
httpMethod: method,
|
|
590
|
+
requestBody: requestBody ?? "",
|
|
591
|
+
responseBody,
|
|
592
|
+
storageError: storageError.error,
|
|
593
|
+
storageStatusCode: storageError.statusCode,
|
|
594
|
+
requestType: type,
|
|
595
|
+
precedingBreadcrumbs
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
this.send(msg, "*");
|
|
599
|
+
}
|
|
537
600
|
};
|
|
538
601
|
function createPostMessageSubscriber(send) {
|
|
539
602
|
return new PostMessageSubscriber(send);
|
|
540
603
|
}
|
|
541
604
|
|
|
605
|
+
// src/subscribers/sentryEventSubscriber.ts
|
|
606
|
+
import { captureEvent } from "@sentry/core";
|
|
607
|
+
function toSentryLevel(consoleLevel) {
|
|
608
|
+
switch (consoleLevel) {
|
|
609
|
+
case "error":
|
|
610
|
+
return "error";
|
|
611
|
+
case "warn":
|
|
612
|
+
return "warning";
|
|
613
|
+
case "debug":
|
|
614
|
+
return "debug";
|
|
615
|
+
case "info":
|
|
616
|
+
return "info";
|
|
617
|
+
default:
|
|
618
|
+
return "log";
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
var SentryEventSubscriber = class {
|
|
622
|
+
constructor(opts = {}) {
|
|
623
|
+
__publicField(this, "captureAllNetworkRequests");
|
|
624
|
+
this.captureAllNetworkRequests = opts.captureAllNetworkRequests ?? true;
|
|
625
|
+
}
|
|
626
|
+
onConsole(info) {
|
|
627
|
+
const { level, args } = info;
|
|
628
|
+
const formattedMessage = formatConsoleArgs(args);
|
|
629
|
+
const sentryLevel = toSentryLevel(level);
|
|
630
|
+
captureEvent({
|
|
631
|
+
message: `[${level}]${formattedMessage}`,
|
|
632
|
+
level: sentryLevel,
|
|
633
|
+
// 按 level + 消息内容前 100 字符分组,同一类日志聚合为同一个 Issue
|
|
634
|
+
fingerprint: ["console", level, formattedMessage.slice(0, 100)],
|
|
635
|
+
tags: {
|
|
636
|
+
type: "console"
|
|
637
|
+
},
|
|
638
|
+
extra: { consoleType: level, args }
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
// Sentry 已自动捕获 JS 错误,不重复上报
|
|
642
|
+
onError(_info) {
|
|
643
|
+
}
|
|
644
|
+
onNetworkRequest(info) {
|
|
645
|
+
const { type, method, url, statusCode, requestBody, responseBody, isError, duration } = info;
|
|
646
|
+
const shouldCapture = this.captureAllNetworkRequests || isError || statusCode != null && statusCode >= 400;
|
|
647
|
+
if (!shouldCapture) return;
|
|
648
|
+
const urlPath = stripUrlOrigin(url);
|
|
649
|
+
const requestTypeLabel = type === "xhr" ? "XHR" : "Fetch";
|
|
650
|
+
const statusStr = statusCode != null ? String(statusCode) : "failed";
|
|
651
|
+
const durationStr = duration != null ? ` (${duration}ms)` : "";
|
|
652
|
+
const message = `${requestTypeLabel} ${method} ${urlPath} -> ${statusStr}${durationStr}`;
|
|
653
|
+
const level = isError ? "error" : statusCode != null && statusCode >= 400 ? "warning" : "info";
|
|
654
|
+
captureEvent({
|
|
655
|
+
message,
|
|
656
|
+
level,
|
|
657
|
+
// 按 method + url 路径固定分组,同一接口的多次报错聚合为同一个 Issue
|
|
658
|
+
fingerprint: ["network", method, urlPath],
|
|
659
|
+
tags: {
|
|
660
|
+
type: "network"
|
|
661
|
+
},
|
|
662
|
+
extra: { url, method, statusCode, duration, requestBody, responseBody }
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
onPgRestWhitelistError(_info) {
|
|
666
|
+
}
|
|
667
|
+
onAuthWhitelistError(_info) {
|
|
668
|
+
}
|
|
669
|
+
onStorageWhitelistError(_info) {
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
function createSentryEventSubscriber(opts) {
|
|
673
|
+
return new SentryEventSubscriber(opts);
|
|
674
|
+
}
|
|
675
|
+
|
|
542
676
|
// src/stubs/sentry-react-stub.ts
|
|
543
677
|
export * from "@sentry/react";
|
|
544
678
|
var STUB_DSN = "https://stubPublicKey@o0.ingest.sentry.io/0";
|
|
545
679
|
var OVERRIDE_DSN = import.meta.env.VITE_SENTRY_DSN || STUB_DSN;
|
|
546
680
|
var OVERRIDE_ENVIRONMENT = import.meta.env.VITE_SENTRY_ENV;
|
|
547
|
-
var _subscribers = [createPostMessageSubscriber()];
|
|
681
|
+
var _subscribers = [createPostMessageSubscriber(), createSentryEventSubscriber()];
|
|
548
682
|
function configureStubSubscribers(subscribers) {
|
|
549
683
|
_subscribers = subscribers;
|
|
550
684
|
}
|