miaoda-react-devkit 0.1.1-beta.0 → 0.1.1-beta.2
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/README.md +145 -5
- package/cloud/vite.config.ts +156 -0
- package/dist/index.cjs +437 -47
- package/dist/index.d.cts +196 -41
- package/dist/index.d.ts +196 -41
- package/dist/index.js +431 -49
- package/dist/stubs/sentry-react-stub.js +427 -85
- package/dist/vite/index.cjs +60 -1
- package/dist/vite/index.d.cts +13 -1
- package/dist/vite/index.d.ts +13 -1
- package/dist/vite/index.js +59 -1
- package/package.json +6 -1
package/dist/index.cjs
CHANGED
|
@@ -22,72 +22,462 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
22
22
|
// src/index.ts
|
|
23
23
|
var src_exports = {};
|
|
24
24
|
__export(src_exports, {
|
|
25
|
-
|
|
25
|
+
DEFAULT_CONSOLE_FILTER_KEYWORDS: () => DEFAULT_CONSOLE_FILTER_KEYWORDS,
|
|
26
|
+
DEFAULT_IGNORE_URLS: () => DEFAULT_IGNORE_URLS,
|
|
27
|
+
DEFAULT_PGREST_URL_PATTERNS: () => DEFAULT_PGREST_URL_PATTERNS,
|
|
28
|
+
DEFAULT_PGREST_WHITELIST_CODES: () => DEFAULT_PGREST_WHITELIST_CODES,
|
|
29
|
+
SentryCapture: () => SentryCapture,
|
|
30
|
+
createNoopSubscriber: () => createNoopSubscriber,
|
|
31
|
+
createPostMessageSubscriber: () => createPostMessageSubscriber
|
|
26
32
|
});
|
|
27
33
|
module.exports = __toCommonJS(src_exports);
|
|
28
34
|
|
|
29
|
-
// src/capture.ts
|
|
35
|
+
// src/capture/console.ts
|
|
30
36
|
var import_core = require("@sentry/core");
|
|
37
|
+
var DEFAULT_CONSOLE_FILTER_KEYWORDS = [
|
|
38
|
+
"Sentry initialized successfully",
|
|
39
|
+
"[vite] ",
|
|
40
|
+
"Download the React DevTools for a better development experience"
|
|
41
|
+
];
|
|
42
|
+
function serializeArg(arg) {
|
|
43
|
+
if (typeof arg === "string") return arg;
|
|
44
|
+
if (arg instanceof Error) return arg.message;
|
|
45
|
+
try {
|
|
46
|
+
return JSON.stringify(arg);
|
|
47
|
+
} catch {
|
|
48
|
+
return String(arg);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function shouldFilterConsole(args, keywords) {
|
|
52
|
+
if (keywords.length === 0) return false;
|
|
53
|
+
const text = args.map(serializeArg).join(" ");
|
|
54
|
+
return keywords.some((kw) => text.includes(kw));
|
|
55
|
+
}
|
|
56
|
+
function shouldFilterConsoleMessage(message, keywords) {
|
|
57
|
+
return keywords.some((kw) => message.includes(kw));
|
|
58
|
+
}
|
|
59
|
+
function createConsoleObserver(keywords, subscribers) {
|
|
60
|
+
return {
|
|
61
|
+
install() {
|
|
62
|
+
if (subscribers.length === 0) return;
|
|
63
|
+
(0, import_core.addConsoleInstrumentationHandler)(({ args, level }) => {
|
|
64
|
+
if (shouldFilterConsole(args, keywords)) return;
|
|
65
|
+
const info = { level, args };
|
|
66
|
+
for (const sub of subscribers) sub.onConsole(info);
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
beforeBreadcrumb(breadcrumb, _hint) {
|
|
70
|
+
if (breadcrumb.category === "console" && breadcrumb.message != null) {
|
|
71
|
+
if (shouldFilterConsoleMessage(breadcrumb.message, keywords)) return null;
|
|
72
|
+
}
|
|
73
|
+
return breadcrumb;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/capture/network.ts
|
|
79
|
+
var import_core3 = require("@sentry/core");
|
|
80
|
+
|
|
81
|
+
// ../../node_modules/.pnpm/@sentry-internal+browser-utils@9.47.1/node_modules/@sentry-internal/browser-utils/build/esm/debug-build.js
|
|
82
|
+
var DEBUG_BUILD = typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__;
|
|
83
|
+
|
|
84
|
+
// ../../node_modules/.pnpm/@sentry-internal+browser-utils@9.47.1/node_modules/@sentry-internal/browser-utils/build/esm/networkUtils.js
|
|
85
|
+
var import_core2 = require("@sentry/core");
|
|
86
|
+
function serializeFormData(formData) {
|
|
87
|
+
return new URLSearchParams(formData).toString();
|
|
88
|
+
}
|
|
89
|
+
function getBodyString(body, _debug = import_core2.debug) {
|
|
90
|
+
try {
|
|
91
|
+
if (typeof body === "string") {
|
|
92
|
+
return [body];
|
|
93
|
+
}
|
|
94
|
+
if (body instanceof URLSearchParams) {
|
|
95
|
+
return [body.toString()];
|
|
96
|
+
}
|
|
97
|
+
if (body instanceof FormData) {
|
|
98
|
+
return [serializeFormData(body)];
|
|
99
|
+
}
|
|
100
|
+
if (!body) {
|
|
101
|
+
return [void 0];
|
|
102
|
+
}
|
|
103
|
+
} catch (error) {
|
|
104
|
+
DEBUG_BUILD && _debug.error(error, "Failed to serialize body", body);
|
|
105
|
+
return [void 0, "BODY_PARSE_ERROR"];
|
|
106
|
+
}
|
|
107
|
+
DEBUG_BUILD && _debug.log("Skipping network body because of body type", body);
|
|
108
|
+
return [void 0, "UNPARSEABLE_BODY_TYPE"];
|
|
109
|
+
}
|
|
110
|
+
function getFetchRequestArgBody(fetchArgs = []) {
|
|
111
|
+
if (fetchArgs.length !== 2 || typeof fetchArgs[1] !== "object") {
|
|
112
|
+
return void 0;
|
|
113
|
+
}
|
|
114
|
+
return fetchArgs[1].body;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/capture/pgrest.ts
|
|
118
|
+
var DEFAULT_PGREST_URL_PATTERNS = [/\/rest\/v1\//];
|
|
119
|
+
var DEFAULT_PGREST_WHITELIST_CODES = [];
|
|
120
|
+
function isPgRestRequest(url, patterns) {
|
|
121
|
+
return patterns.some((p) => (typeof p === "string" ? new RegExp(p) : p).test(url));
|
|
122
|
+
}
|
|
123
|
+
function parsePgRestErrorBody(body) {
|
|
124
|
+
if (!body) return null;
|
|
125
|
+
let parsed;
|
|
126
|
+
try {
|
|
127
|
+
parsed = JSON.parse(body);
|
|
128
|
+
} catch {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
if (typeof parsed !== "object") return null;
|
|
132
|
+
if (parsed === null) return null;
|
|
133
|
+
const p = parsed;
|
|
134
|
+
if (typeof p["code"] !== "string") return null;
|
|
135
|
+
if (typeof p["message"] !== "string") return null;
|
|
136
|
+
return {
|
|
137
|
+
code: p["code"],
|
|
138
|
+
message: p["message"],
|
|
139
|
+
details: typeof p["details"] === "string" ? p["details"] : null,
|
|
140
|
+
hint: typeof p["hint"] === "string" ? p["hint"] : null
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/capture/network.ts
|
|
145
|
+
var BODY_TRUNCATE_LIMIT = 2e3;
|
|
146
|
+
var DEFAULT_IGNORE_URLS = [
|
|
147
|
+
/\.(js|css|png|jpg|jpeg|gif|svg|ico|woff|woff2|ttf|eot|map)(\?.*)?$/,
|
|
148
|
+
/\.chunk\./,
|
|
149
|
+
/\/static\//,
|
|
150
|
+
/\/assets\//
|
|
151
|
+
];
|
|
152
|
+
function createUrlMatcher(patterns) {
|
|
153
|
+
const regexes = patterns.map((p) => typeof p === "string" ? new RegExp(p) : p);
|
|
154
|
+
return (url) => regexes.some((re) => re.test(url));
|
|
155
|
+
}
|
|
156
|
+
function truncateBody(body) {
|
|
157
|
+
return body.length > BODY_TRUNCATE_LIMIT ? body.slice(0, BODY_TRUNCATE_LIMIT) + "... (truncated)" : body;
|
|
158
|
+
}
|
|
159
|
+
function isStreamByContentType(contentType) {
|
|
160
|
+
return contentType.includes("text/event-stream") || contentType.includes("application/stream+json");
|
|
161
|
+
}
|
|
162
|
+
function handleXhrBreadcrumb(breadcrumb, hint, handler) {
|
|
163
|
+
const data = breadcrumb.data;
|
|
164
|
+
const method = data?.method ?? "GET";
|
|
165
|
+
const url = data?.url ?? "";
|
|
166
|
+
const statusCode = data?.status_code != null && data.status_code > 0 ? data.status_code : null;
|
|
167
|
+
const isError = statusCode === null;
|
|
168
|
+
const xhr = hint?.xhr;
|
|
169
|
+
const [rawRequestBody] = getBodyString(hint?.input);
|
|
170
|
+
const requestBody = rawRequestBody != null ? truncateBody(rawRequestBody) : void 0;
|
|
171
|
+
let responseBody;
|
|
172
|
+
if (xhr) {
|
|
173
|
+
const contentType = xhr.getResponseHeader("content-type") ?? "";
|
|
174
|
+
if (isStreamByContentType(contentType)) {
|
|
175
|
+
responseBody = "[streaming response - not captured]";
|
|
176
|
+
} else if (xhr.responseType === "" || xhr.responseType === "text") {
|
|
177
|
+
try {
|
|
178
|
+
responseBody = xhr.responseText != null ? truncateBody(xhr.responseText) : void 0;
|
|
179
|
+
} catch {
|
|
180
|
+
}
|
|
181
|
+
} else if (xhr.responseType === "json") {
|
|
182
|
+
try {
|
|
183
|
+
responseBody = truncateBody(JSON.stringify(xhr.response));
|
|
184
|
+
} catch {
|
|
185
|
+
responseBody = "[json response parse failed]";
|
|
186
|
+
}
|
|
187
|
+
} else {
|
|
188
|
+
responseBody = "[non-text response]";
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (breadcrumb.data) {
|
|
192
|
+
breadcrumb.data["requestBody"] = requestBody;
|
|
193
|
+
breadcrumb.data["responseBody"] = responseBody;
|
|
194
|
+
}
|
|
195
|
+
void handler({ type: "xhr", method, url, statusCode, requestBody, responseBody, isError });
|
|
196
|
+
}
|
|
197
|
+
async function handleFetchBreadcrumb(breadcrumb, hint, handler) {
|
|
198
|
+
const data = breadcrumb.data;
|
|
199
|
+
const method = data?.method ?? "GET";
|
|
200
|
+
const url = data?.url ?? "";
|
|
201
|
+
const statusCode = data?.status_code ?? null;
|
|
202
|
+
const isError = hint?.data != null;
|
|
203
|
+
const response = hint?.response;
|
|
204
|
+
const cause = hint?.data instanceof Error ? hint.data : void 0;
|
|
205
|
+
const fetchArgs = hint?.input;
|
|
206
|
+
const reqBody = getFetchRequestArgBody(fetchArgs ?? []);
|
|
207
|
+
const [rawRequestBody] = getBodyString(reqBody);
|
|
208
|
+
const requestBody = rawRequestBody != null ? truncateBody(rawRequestBody) : void 0;
|
|
209
|
+
if (breadcrumb.data) {
|
|
210
|
+
breadcrumb.data["requestBody"] = requestBody;
|
|
211
|
+
}
|
|
212
|
+
const contentType = response?.headers?.get("content-type") ?? "";
|
|
213
|
+
if (isStreamByContentType(contentType)) {
|
|
214
|
+
if (breadcrumb.data) {
|
|
215
|
+
breadcrumb.data["responseBody"] = "[streaming response - not captured]";
|
|
216
|
+
}
|
|
217
|
+
await handler({ type: "fetch", method, url, statusCode, requestBody, responseBody: "[streaming response - not captured]", isError, cause });
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
let responseBody;
|
|
221
|
+
if (response) {
|
|
222
|
+
try {
|
|
223
|
+
const text = await Promise.race([
|
|
224
|
+
response.clone().text(),
|
|
225
|
+
new Promise(
|
|
226
|
+
(_, reject) => setTimeout(() => reject(new Error("timeout")), 500)
|
|
227
|
+
)
|
|
228
|
+
]);
|
|
229
|
+
responseBody = truncateBody(text);
|
|
230
|
+
} catch {
|
|
231
|
+
responseBody = void 0;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (breadcrumb.data) {
|
|
235
|
+
breadcrumb.data["responseBody"] = responseBody;
|
|
236
|
+
}
|
|
237
|
+
await handler({ type: "fetch", method, url, statusCode, requestBody, responseBody, isError, cause });
|
|
238
|
+
}
|
|
239
|
+
function createNetworkObserver(opts, subscribers) {
|
|
240
|
+
const shouldIgnore = createUrlMatcher(opts.ignoreUrls);
|
|
241
|
+
const pgRestPatterns = opts.pgRestUrlPatterns ?? DEFAULT_PGREST_URL_PATTERNS;
|
|
242
|
+
const pgRestWhitelistCodes = opts.pgRestWhitelistCodes ?? DEFAULT_PGREST_WHITELIST_CODES;
|
|
243
|
+
function tryDispatchPgRestWhitelistError(requestType, method, url, statusCode, requestBody, responseBody) {
|
|
244
|
+
if (statusCode == null) return;
|
|
245
|
+
if (!isPgRestRequest(url, pgRestPatterns)) return;
|
|
246
|
+
const pgRestError = parsePgRestErrorBody(responseBody);
|
|
247
|
+
if (!pgRestError) return;
|
|
248
|
+
if (pgRestWhitelistCodes.length > 0 && !pgRestWhitelistCodes.includes(pgRestError.code)) return;
|
|
249
|
+
const info = {
|
|
250
|
+
type: requestType,
|
|
251
|
+
method,
|
|
252
|
+
url,
|
|
253
|
+
statusCode,
|
|
254
|
+
pgRestError,
|
|
255
|
+
requestBody,
|
|
256
|
+
responseBody
|
|
257
|
+
};
|
|
258
|
+
for (const sub of subscribers) sub.onPgRestWhitelistError(info);
|
|
259
|
+
}
|
|
260
|
+
function makeHandler(requestType) {
|
|
261
|
+
return (info) => {
|
|
262
|
+
for (const sub of subscribers) void sub.onNetworkRequest(info);
|
|
263
|
+
tryDispatchPgRestWhitelistError(
|
|
264
|
+
requestType,
|
|
265
|
+
info.method,
|
|
266
|
+
info.url,
|
|
267
|
+
info.statusCode,
|
|
268
|
+
info.requestBody,
|
|
269
|
+
info.responseBody
|
|
270
|
+
);
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
shouldIgnore,
|
|
275
|
+
install() {
|
|
276
|
+
if (subscribers.length === 0) return;
|
|
277
|
+
const client = (0, import_core3.getClient)();
|
|
278
|
+
if (!client) return;
|
|
279
|
+
const xhrHandler = makeHandler("xhr");
|
|
280
|
+
const fetchHandler = makeHandler("fetch");
|
|
281
|
+
client.on("beforeAddBreadcrumb", (breadcrumb, hint) => {
|
|
282
|
+
const url = breadcrumb.data?.url ?? "";
|
|
283
|
+
if (shouldIgnore(url)) return;
|
|
284
|
+
if (breadcrumb.category === "xhr") {
|
|
285
|
+
handleXhrBreadcrumb(breadcrumb, hint, xhrHandler);
|
|
286
|
+
} else if (breadcrumb.category === "fetch") {
|
|
287
|
+
void handleFetchBreadcrumb(breadcrumb, hint, fetchHandler);
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// src/capture/capture.ts
|
|
31
295
|
var SentryCapture = class {
|
|
32
|
-
constructor(
|
|
33
|
-
__publicField(this, "
|
|
34
|
-
__publicField(this, "
|
|
35
|
-
__publicField(this, "
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
38
|
-
this.
|
|
296
|
+
constructor(opts, subscribers = []) {
|
|
297
|
+
__publicField(this, "subscribers");
|
|
298
|
+
__publicField(this, "console");
|
|
299
|
+
__publicField(this, "network");
|
|
300
|
+
this.subscribers = subscribers;
|
|
301
|
+
this.console = createConsoleObserver(opts.consoleFilterKeywords, subscribers);
|
|
302
|
+
this.network = createNetworkObserver(opts, subscribers);
|
|
39
303
|
this.beforeSend = this.beforeSend.bind(this);
|
|
40
304
|
this.beforeBreadcrumb = this.beforeBreadcrumb.bind(this);
|
|
41
305
|
}
|
|
42
|
-
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*/
|
|
46
|
-
installFetchObserver() {
|
|
47
|
-
if (!this.onRequest) return;
|
|
48
|
-
const handler = this.onRequest;
|
|
49
|
-
(0, import_core.addFetchInstrumentationHandler)((data) => {
|
|
50
|
-
const { method, url } = data.fetchData;
|
|
51
|
-
const responseContentType = data.response?.headers?.get?.("content-type") ?? "";
|
|
52
|
-
if (responseContentType.includes("text/event-stream")) return;
|
|
53
|
-
if (!data.endTimestamp) {
|
|
54
|
-
handler({ method, url, statusCode: null, isEnd: false, isError: false });
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const statusCode = data.response?.status ?? null;
|
|
58
|
-
const isError = data.error != null;
|
|
59
|
-
handler({ method, url, statusCode, isEnd: true, isError });
|
|
60
|
-
});
|
|
306
|
+
/** 在 Sentry.init() 完成后调用一次,注册网络请求观测器。 */
|
|
307
|
+
installNetworkObserver() {
|
|
308
|
+
this.network.install();
|
|
61
309
|
}
|
|
62
|
-
/**
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
310
|
+
/** 注册控制台日志观测器,可在 Sentry.init() 前后调用均可。 */
|
|
311
|
+
installConsoleObserver() {
|
|
312
|
+
this.console.install();
|
|
313
|
+
}
|
|
314
|
+
/** 传入 Sentry.init({ beforeSend }) —— 提取错误信息触发 onError 回调。 */
|
|
66
315
|
beforeSend(event, hint) {
|
|
67
|
-
const
|
|
316
|
+
const exceptionValue = event.exception?.values?.[0];
|
|
317
|
+
const message = exceptionValue?.value ?? event.message ?? "(unknown)";
|
|
68
318
|
const componentStack = event.contexts?.["react"]?.["componentStack"] ?? void 0;
|
|
69
|
-
const mechanismType =
|
|
319
|
+
const mechanismType = exceptionValue?.mechanism?.type ?? null;
|
|
70
320
|
const stack = hint.originalException instanceof Error ? hint.originalException.stack : void 0;
|
|
71
|
-
|
|
321
|
+
const errorName = exceptionValue?.type ?? (hint.originalException instanceof Error ? hint.originalException.name : void 0);
|
|
322
|
+
const frames = exceptionValue?.stacktrace?.frames;
|
|
323
|
+
const innerFrame = frames?.length ? frames[frames.length - 1] : void 0;
|
|
324
|
+
const fileName = innerFrame?.filename ?? innerFrame?.abs_path;
|
|
325
|
+
const lineNumber = innerFrame?.lineno;
|
|
326
|
+
const columnNumber = innerFrame?.colno;
|
|
327
|
+
const info = { message, stack, componentStack, mechanismType, errorName, fileName, lineNumber, columnNumber };
|
|
328
|
+
for (const sub of this.subscribers) sub.onError(info);
|
|
72
329
|
return event;
|
|
73
330
|
}
|
|
74
331
|
/**
|
|
75
|
-
*
|
|
332
|
+
* 传入 Sentry.init({ beforeBreadcrumb })。
|
|
333
|
+
* - console:过滤噪音关键词
|
|
334
|
+
* - fetch/xhr:过滤 ignoreUrls 匹配的静态资源请求
|
|
76
335
|
*/
|
|
77
|
-
beforeBreadcrumb(breadcrumb,
|
|
78
|
-
if (breadcrumb.
|
|
79
|
-
const
|
|
80
|
-
this.
|
|
81
|
-
method: data?.method ?? null,
|
|
82
|
-
url: data?.url ?? null,
|
|
83
|
-
statusCode: data?.status_code ?? null
|
|
84
|
-
});
|
|
336
|
+
beforeBreadcrumb(breadcrumb, hint) {
|
|
337
|
+
if (breadcrumb.category === "fetch" || breadcrumb.category === "xhr") {
|
|
338
|
+
const url = breadcrumb.data?.url ?? "";
|
|
339
|
+
if (this.network.shouldIgnore(url)) return null;
|
|
85
340
|
}
|
|
86
|
-
return breadcrumb;
|
|
341
|
+
return this.console.beforeBreadcrumb(breadcrumb, hint);
|
|
87
342
|
}
|
|
88
343
|
};
|
|
344
|
+
|
|
345
|
+
// src/subscribers/postMessageSubscriber.ts
|
|
346
|
+
function extractUrlPath(url) {
|
|
347
|
+
try {
|
|
348
|
+
const u = new URL(url);
|
|
349
|
+
return u.pathname + u.search + u.hash;
|
|
350
|
+
} catch {
|
|
351
|
+
return url;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
var PostMessageSubscriber = class {
|
|
355
|
+
constructor(send = (msg, origin) => window.parent.postMessage(msg, origin)) {
|
|
356
|
+
__publicField(this, "send");
|
|
357
|
+
this.send = send;
|
|
358
|
+
}
|
|
359
|
+
// postMessage 场景不需要上报 console 日志
|
|
360
|
+
onConsole(_info) {
|
|
361
|
+
}
|
|
362
|
+
onError({ message, stack, errorName, fileName, lineNumber, columnNumber }) {
|
|
363
|
+
const name = errorName ?? "Error";
|
|
364
|
+
const msg = {
|
|
365
|
+
type: "GLOBAL_ERROR",
|
|
366
|
+
message,
|
|
367
|
+
error: stack != null ? { name, message, stack } : null,
|
|
368
|
+
errorData: {
|
|
369
|
+
name,
|
|
370
|
+
message,
|
|
371
|
+
stack,
|
|
372
|
+
fileName: fileName ?? "unknown",
|
|
373
|
+
lineNumber: lineNumber ?? 0,
|
|
374
|
+
columnNumber: columnNumber ?? 0
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
this.send(msg, "*");
|
|
378
|
+
}
|
|
379
|
+
onNetworkRequest({ method, url, statusCode, requestBody, responseBody, isError, cause }) {
|
|
380
|
+
const isClientError = statusCode != null && statusCode >= 400 && statusCode < 500;
|
|
381
|
+
if (!isError && !isClientError) return;
|
|
382
|
+
const urlPath = extractUrlPath(url);
|
|
383
|
+
if (isError) {
|
|
384
|
+
const causeDesc = cause != null ? String(cause) : "NetworkError";
|
|
385
|
+
const errorMessage = `${method} ${urlPath} failed: ${causeDesc}`;
|
|
386
|
+
const msg = {
|
|
387
|
+
type: "GLOBAL_ERROR",
|
|
388
|
+
message: errorMessage,
|
|
389
|
+
error: cause != null ? { name: cause.name, message: cause.message, stack: cause.stack } : null,
|
|
390
|
+
errorData: {
|
|
391
|
+
name: cause?.name ?? "NetworkError",
|
|
392
|
+
message: cause?.message ?? causeDesc,
|
|
393
|
+
stack: cause?.stack ?? null,
|
|
394
|
+
fileName: url,
|
|
395
|
+
lineNumber: 0,
|
|
396
|
+
columnNumber: 0,
|
|
397
|
+
httpPath: urlPath,
|
|
398
|
+
httpStatus: 0,
|
|
399
|
+
httpMethod: method,
|
|
400
|
+
requestBody: requestBody ?? "",
|
|
401
|
+
responseBody: ""
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
this.send(msg, "*");
|
|
405
|
+
} else {
|
|
406
|
+
const errorMessage = `${method} ${urlPath} -> ${statusCode}`;
|
|
407
|
+
const msg = {
|
|
408
|
+
type: "GLOBAL_ERROR",
|
|
409
|
+
message: errorMessage,
|
|
410
|
+
error: null,
|
|
411
|
+
errorData: {
|
|
412
|
+
name: "HTTPClientError",
|
|
413
|
+
message: errorMessage,
|
|
414
|
+
stack: null,
|
|
415
|
+
fileName: url,
|
|
416
|
+
lineNumber: 0,
|
|
417
|
+
columnNumber: 0,
|
|
418
|
+
httpPath: urlPath,
|
|
419
|
+
httpStatus: statusCode,
|
|
420
|
+
httpMethod: method,
|
|
421
|
+
requestBody: requestBody ?? "",
|
|
422
|
+
responseBody: responseBody ?? ""
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
this.send(msg, "*");
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
onPgRestWhitelistError({ type, method, url, statusCode, pgRestError, requestBody, responseBody }) {
|
|
429
|
+
const urlPath = extractUrlPath(url);
|
|
430
|
+
const code = pgRestError.code;
|
|
431
|
+
const errorMessage = `${method} ${urlPath} -> ${statusCode} [PgRest:${code}]`;
|
|
432
|
+
const msg = {
|
|
433
|
+
type: "GLOBAL_ERROR",
|
|
434
|
+
message: errorMessage,
|
|
435
|
+
error: null,
|
|
436
|
+
errorData: {
|
|
437
|
+
name: "PgRestWhitelistError",
|
|
438
|
+
message: pgRestError.message,
|
|
439
|
+
stack: null,
|
|
440
|
+
fileName: url,
|
|
441
|
+
lineNumber: 0,
|
|
442
|
+
columnNumber: 0,
|
|
443
|
+
httpPath: urlPath,
|
|
444
|
+
httpStatus: statusCode,
|
|
445
|
+
httpMethod: method,
|
|
446
|
+
requestBody: requestBody ?? "",
|
|
447
|
+
responseBody,
|
|
448
|
+
pgRestCode: code,
|
|
449
|
+
pgRestDetails: pgRestError.details ?? void 0,
|
|
450
|
+
pgRestHint: pgRestError.hint ?? void 0,
|
|
451
|
+
requestType: type
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
this.send(msg, "*");
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
function createPostMessageSubscriber(send) {
|
|
458
|
+
return new PostMessageSubscriber(send);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// src/subscribers/noopSubscriber.ts
|
|
462
|
+
function createNoopSubscriber() {
|
|
463
|
+
return {
|
|
464
|
+
onConsole() {
|
|
465
|
+
},
|
|
466
|
+
onError() {
|
|
467
|
+
},
|
|
468
|
+
onNetworkRequest() {
|
|
469
|
+
},
|
|
470
|
+
onPgRestWhitelistError() {
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
}
|
|
89
474
|
// Annotate the CommonJS export names for ESM import in node:
|
|
90
475
|
0 && (module.exports = {
|
|
91
|
-
|
|
476
|
+
DEFAULT_CONSOLE_FILTER_KEYWORDS,
|
|
477
|
+
DEFAULT_IGNORE_URLS,
|
|
478
|
+
DEFAULT_PGREST_URL_PATTERNS,
|
|
479
|
+
DEFAULT_PGREST_WHITELIST_CODES,
|
|
480
|
+
SentryCapture,
|
|
481
|
+
createNoopSubscriber,
|
|
482
|
+
createPostMessageSubscriber
|
|
92
483
|
});
|
|
93
|
-
//# sourceMappingURL=index.cjs.map
|