glitchgrab 1.68.0 → 1.68.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 +59 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +249 -269
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +249 -269
- package/dist/index.mjs.map +1 -1
- package/dist/server.d.mts +63 -2
- package/dist/server.d.ts +63 -2
- package/dist/server.js +234 -1
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +232 -1
- package/dist/server.mjs.map +1 -1
- package/dist/{types-Dw587jLi.d.mts → types-CN-BjNB6.d.mts} +14 -1
- package/dist/{types-Dw587jLi.d.ts → types-CN-BjNB6.d.ts} +14 -1
- package/package.json +1 -1
package/dist/server.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as ReportType, m as ReportSeverity, l as ReportResult } from './types-
|
|
1
|
+
import { n as ReportType, m as ReportSeverity, l as ReportResult } from './types-CN-BjNB6.mjs';
|
|
2
2
|
import 'react';
|
|
3
3
|
|
|
4
4
|
/** Who to attribute the report to. A server has no signed-in user, so this is the job or service. */
|
|
@@ -97,6 +97,12 @@ interface CaptureServerErrorsOptions extends ServerReportOptions {
|
|
|
97
97
|
* to decide).
|
|
98
98
|
*/
|
|
99
99
|
captureUnhandledRejections?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Also file the server's `console.error` / `console.warn` lines (see
|
|
102
|
+
* {@link captureServerConsole}). Default `["error", "warn"]`; `false` turns
|
|
103
|
+
* it off.
|
|
104
|
+
*/
|
|
105
|
+
console?: ("error" | "warn")[] | false;
|
|
100
106
|
}
|
|
101
107
|
/**
|
|
102
108
|
* Report every uncaught exception and unhandled rejection in this process.
|
|
@@ -109,6 +115,61 @@ interface CaptureServerErrorsOptions extends ServerReportOptions {
|
|
|
109
115
|
* that keeps a broken process alive is worse than no reporter.
|
|
110
116
|
*/
|
|
111
117
|
declare function captureServerErrors(options?: CaptureServerErrorsOptions): () => void;
|
|
118
|
+
/** The request as Next.js passes it to `onRequestError`. */
|
|
119
|
+
interface NextRequestErrorRequest {
|
|
120
|
+
path: string;
|
|
121
|
+
method: string;
|
|
122
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
123
|
+
}
|
|
124
|
+
/** The route as Next.js passes it to `onRequestError`. */
|
|
125
|
+
interface NextRequestErrorContext {
|
|
126
|
+
routerKind?: "Pages Router" | "App Router" | string;
|
|
127
|
+
/** The route file, e.g. `/app/api/users/[id]/route`. Ids are not filled in. */
|
|
128
|
+
routePath?: string;
|
|
129
|
+
routeType?: "render" | "route" | "action" | "middleware" | "proxy" | string;
|
|
130
|
+
renderSource?: string;
|
|
131
|
+
revalidateReason?: string;
|
|
132
|
+
renderType?: string;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* File an error Next.js caught in a page, route handler, server action or
|
|
136
|
+
* proxy/middleware. Next catches these itself and only prints them, so neither
|
|
137
|
+
* `window.onerror` nor {@link captureServerErrors} ever sees them.
|
|
138
|
+
*
|
|
139
|
+
* ```ts
|
|
140
|
+
* // instrumentation.ts
|
|
141
|
+
* export async function onRequestError(...args: Parameters<typeof import("glitchgrab/server").reportRequestError>) {
|
|
142
|
+
* if (process.env.NEXT_RUNTIME !== "nodejs") return;
|
|
143
|
+
* const { reportRequestError } = await import("glitchgrab/server");
|
|
144
|
+
* await reportRequestError(...args);
|
|
145
|
+
* }
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* Grouped per route FILE (`routePath`), not per URL, so `/api/users/42` and
|
|
149
|
+
* `/api/users/97` throwing the same error are one issue. Client hang-ups
|
|
150
|
+
* (`ECONNRESET`, `aborted`) are skipped. Never throws.
|
|
151
|
+
*/
|
|
152
|
+
declare function reportRequestError(error: unknown, request: NextRequestErrorRequest, context?: NextRequestErrorContext, options?: ServerReportOptions): Promise<ReportResult | null>;
|
|
153
|
+
/** Options for {@link captureServerConsole}. */
|
|
154
|
+
interface CaptureServerConsoleOptions extends ServerReportOptions {
|
|
155
|
+
/** Which console levels become issues. Default `["error"]`. */
|
|
156
|
+
levels?: ("error" | "warn")[];
|
|
157
|
+
/** Skip lines matching any of these. String = substring, RegExp = `.test()`. */
|
|
158
|
+
ignore?: (string | RegExp)[];
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* File `console.error` (and optionally `console.warn`) lines printed by the
|
|
162
|
+
* server as issues — the "something failed but nothing threw" lines a team
|
|
163
|
+
* only ever sees by tailing logs. Call once at boot, from `register()` in
|
|
164
|
+
* `instrumentation.ts`. Returns a function that puts the console back.
|
|
165
|
+
*
|
|
166
|
+
* Production only unless `enableInDevelopment`. One issue per distinct message
|
|
167
|
+
* and context: repeats within 5 minutes are dropped here, and the API comments
|
|
168
|
+
* later repeats onto the open issue. Errors `onRequestError` already filed and
|
|
169
|
+
* client hang-ups (`ECONNRESET`) are skipped. Never throws, and the original
|
|
170
|
+
* line is always printed first.
|
|
171
|
+
*/
|
|
172
|
+
declare function captureServerConsole(options?: CaptureServerConsoleOptions): () => void;
|
|
112
173
|
/** Options for {@link signSession}. */
|
|
113
174
|
interface SignSessionOptions {
|
|
114
175
|
/** Your user's id — the same value you pass as `session.userId`. */
|
|
@@ -1314,4 +1375,4 @@ declare function testRingNumber(id: string, options?: LineCallsOptions): Promise
|
|
|
1314
1375
|
verified: boolean;
|
|
1315
1376
|
}>>;
|
|
1316
1377
|
|
|
1317
|
-
export { type Booking, type BookingAnswer, type BookingClientNotice, type BookingMutationResult, type BookingNotifyRecipient, type BookingQuestion, type BookingQuestionInput, type BookingSettings, type BookingSettingsChanges, type BookingSettingsResult, type BookingSettingsState, type BookingWorkingHours, type Call, type CallAudio, type CallIssueSessionOptions, type CallIssueSessionResult, type CallListItem, type CallMoment, type CallParticipant, type CallWebhook, type CallsOptions, type CaptureServerErrorsOptions, type DeleteCallResult, type FollowUp, type FollowUpBooking, type FollowUpCall, type FollowUpDetail, type FollowUpDue, type FollowUpNote, type FollowUpOperator, type FollowUpWriteResult, type GetCallOptions, type Guide, type GuideReadOptions, type GuideSummary, type Lead, type LineCallerResult, type LineCallsOptions, type LineRequestResult, type ListBookingsOptions, type ListCallsOptions, type ListLeadsOptions, type OperatorRingNumber, type OperatorRingNumbersResult, type PhoneLineInfo, type PhoneLineRequest, type PhoneLineStatus, type PhoneLineWebhook, type PlaceCallResult, type RegisteredWebhook, ReportResult, ReportSeverity, ReportType, type RingErrorCode, type RingNumber, type RingNumberList, type RingNumberWriteResult, type ServerReportOptions, type ServerReporterConfig, type ServerReporterIdentity, type SignSessionOptions, addFollowUpNote, addLineCaller, addRingNumber, cancelBooking, captureServerErrors, changeLineNumber, configureServerReporter, createCallIssueSession, deleteCall, dialFollowUp, disableCalling, discardBookingQuestionsDraft, editFollowUpNote, enableCalling, escapeJsonForScript, getBookingSettings, getCall, getFollowUp, getGuide, getOperatorRingNumbers, getPhoneLine, listBookings, listCalls, listFollowUps, listGuides, listLeads, listRingNumbers, listWebhooks, placeCall, publishBookingQuestions, registerWebhook, removeLineCaller, removeRingNumber, removeWebhook, reportServerError, rescheduleBooking, resetServerReporter, setFollowUpBooking, signSession, submitPhoneKyc, testRingNumber, updateBookingSettings, updateRingNumber };
|
|
1378
|
+
export { type Booking, type BookingAnswer, type BookingClientNotice, type BookingMutationResult, type BookingNotifyRecipient, type BookingQuestion, type BookingQuestionInput, type BookingSettings, type BookingSettingsChanges, type BookingSettingsResult, type BookingSettingsState, type BookingWorkingHours, type Call, type CallAudio, type CallIssueSessionOptions, type CallIssueSessionResult, type CallListItem, type CallMoment, type CallParticipant, type CallWebhook, type CallsOptions, type CaptureServerConsoleOptions, type CaptureServerErrorsOptions, type DeleteCallResult, type FollowUp, type FollowUpBooking, type FollowUpCall, type FollowUpDetail, type FollowUpDue, type FollowUpNote, type FollowUpOperator, type FollowUpWriteResult, type GetCallOptions, type Guide, type GuideReadOptions, type GuideSummary, type Lead, type LineCallerResult, type LineCallsOptions, type LineRequestResult, type ListBookingsOptions, type ListCallsOptions, type ListLeadsOptions, type NextRequestErrorContext, type NextRequestErrorRequest, type OperatorRingNumber, type OperatorRingNumbersResult, type PhoneLineInfo, type PhoneLineRequest, type PhoneLineStatus, type PhoneLineWebhook, type PlaceCallResult, type RegisteredWebhook, ReportResult, ReportSeverity, ReportType, type RingErrorCode, type RingNumber, type RingNumberList, type RingNumberWriteResult, type ServerReportOptions, type ServerReporterConfig, type ServerReporterIdentity, type SignSessionOptions, addFollowUpNote, addLineCaller, addRingNumber, cancelBooking, captureServerConsole, captureServerErrors, changeLineNumber, configureServerReporter, createCallIssueSession, deleteCall, dialFollowUp, disableCalling, discardBookingQuestionsDraft, editFollowUpNote, enableCalling, escapeJsonForScript, getBookingSettings, getCall, getFollowUp, getGuide, getOperatorRingNumbers, getPhoneLine, listBookings, listCalls, listFollowUps, listGuides, listLeads, listRingNumbers, listWebhooks, placeCall, publishBookingQuestions, registerWebhook, removeLineCaller, removeRingNumber, removeWebhook, reportRequestError, reportServerError, rescheduleBooking, resetServerReporter, setFollowUpBooking, signSession, submitPhoneKyc, testRingNumber, updateBookingSettings, updateRingNumber };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as ReportType, m as ReportSeverity, l as ReportResult } from './types-
|
|
1
|
+
import { n as ReportType, m as ReportSeverity, l as ReportResult } from './types-CN-BjNB6.js';
|
|
2
2
|
import 'react';
|
|
3
3
|
|
|
4
4
|
/** Who to attribute the report to. A server has no signed-in user, so this is the job or service. */
|
|
@@ -97,6 +97,12 @@ interface CaptureServerErrorsOptions extends ServerReportOptions {
|
|
|
97
97
|
* to decide).
|
|
98
98
|
*/
|
|
99
99
|
captureUnhandledRejections?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Also file the server's `console.error` / `console.warn` lines (see
|
|
102
|
+
* {@link captureServerConsole}). Default `["error", "warn"]`; `false` turns
|
|
103
|
+
* it off.
|
|
104
|
+
*/
|
|
105
|
+
console?: ("error" | "warn")[] | false;
|
|
100
106
|
}
|
|
101
107
|
/**
|
|
102
108
|
* Report every uncaught exception and unhandled rejection in this process.
|
|
@@ -109,6 +115,61 @@ interface CaptureServerErrorsOptions extends ServerReportOptions {
|
|
|
109
115
|
* that keeps a broken process alive is worse than no reporter.
|
|
110
116
|
*/
|
|
111
117
|
declare function captureServerErrors(options?: CaptureServerErrorsOptions): () => void;
|
|
118
|
+
/** The request as Next.js passes it to `onRequestError`. */
|
|
119
|
+
interface NextRequestErrorRequest {
|
|
120
|
+
path: string;
|
|
121
|
+
method: string;
|
|
122
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
123
|
+
}
|
|
124
|
+
/** The route as Next.js passes it to `onRequestError`. */
|
|
125
|
+
interface NextRequestErrorContext {
|
|
126
|
+
routerKind?: "Pages Router" | "App Router" | string;
|
|
127
|
+
/** The route file, e.g. `/app/api/users/[id]/route`. Ids are not filled in. */
|
|
128
|
+
routePath?: string;
|
|
129
|
+
routeType?: "render" | "route" | "action" | "middleware" | "proxy" | string;
|
|
130
|
+
renderSource?: string;
|
|
131
|
+
revalidateReason?: string;
|
|
132
|
+
renderType?: string;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* File an error Next.js caught in a page, route handler, server action or
|
|
136
|
+
* proxy/middleware. Next catches these itself and only prints them, so neither
|
|
137
|
+
* `window.onerror` nor {@link captureServerErrors} ever sees them.
|
|
138
|
+
*
|
|
139
|
+
* ```ts
|
|
140
|
+
* // instrumentation.ts
|
|
141
|
+
* export async function onRequestError(...args: Parameters<typeof import("glitchgrab/server").reportRequestError>) {
|
|
142
|
+
* if (process.env.NEXT_RUNTIME !== "nodejs") return;
|
|
143
|
+
* const { reportRequestError } = await import("glitchgrab/server");
|
|
144
|
+
* await reportRequestError(...args);
|
|
145
|
+
* }
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* Grouped per route FILE (`routePath`), not per URL, so `/api/users/42` and
|
|
149
|
+
* `/api/users/97` throwing the same error are one issue. Client hang-ups
|
|
150
|
+
* (`ECONNRESET`, `aborted`) are skipped. Never throws.
|
|
151
|
+
*/
|
|
152
|
+
declare function reportRequestError(error: unknown, request: NextRequestErrorRequest, context?: NextRequestErrorContext, options?: ServerReportOptions): Promise<ReportResult | null>;
|
|
153
|
+
/** Options for {@link captureServerConsole}. */
|
|
154
|
+
interface CaptureServerConsoleOptions extends ServerReportOptions {
|
|
155
|
+
/** Which console levels become issues. Default `["error"]`. */
|
|
156
|
+
levels?: ("error" | "warn")[];
|
|
157
|
+
/** Skip lines matching any of these. String = substring, RegExp = `.test()`. */
|
|
158
|
+
ignore?: (string | RegExp)[];
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* File `console.error` (and optionally `console.warn`) lines printed by the
|
|
162
|
+
* server as issues — the "something failed but nothing threw" lines a team
|
|
163
|
+
* only ever sees by tailing logs. Call once at boot, from `register()` in
|
|
164
|
+
* `instrumentation.ts`. Returns a function that puts the console back.
|
|
165
|
+
*
|
|
166
|
+
* Production only unless `enableInDevelopment`. One issue per distinct message
|
|
167
|
+
* and context: repeats within 5 minutes are dropped here, and the API comments
|
|
168
|
+
* later repeats onto the open issue. Errors `onRequestError` already filed and
|
|
169
|
+
* client hang-ups (`ECONNRESET`) are skipped. Never throws, and the original
|
|
170
|
+
* line is always printed first.
|
|
171
|
+
*/
|
|
172
|
+
declare function captureServerConsole(options?: CaptureServerConsoleOptions): () => void;
|
|
112
173
|
/** Options for {@link signSession}. */
|
|
113
174
|
interface SignSessionOptions {
|
|
114
175
|
/** Your user's id — the same value you pass as `session.userId`. */
|
|
@@ -1314,4 +1375,4 @@ declare function testRingNumber(id: string, options?: LineCallsOptions): Promise
|
|
|
1314
1375
|
verified: boolean;
|
|
1315
1376
|
}>>;
|
|
1316
1377
|
|
|
1317
|
-
export { type Booking, type BookingAnswer, type BookingClientNotice, type BookingMutationResult, type BookingNotifyRecipient, type BookingQuestion, type BookingQuestionInput, type BookingSettings, type BookingSettingsChanges, type BookingSettingsResult, type BookingSettingsState, type BookingWorkingHours, type Call, type CallAudio, type CallIssueSessionOptions, type CallIssueSessionResult, type CallListItem, type CallMoment, type CallParticipant, type CallWebhook, type CallsOptions, type CaptureServerErrorsOptions, type DeleteCallResult, type FollowUp, type FollowUpBooking, type FollowUpCall, type FollowUpDetail, type FollowUpDue, type FollowUpNote, type FollowUpOperator, type FollowUpWriteResult, type GetCallOptions, type Guide, type GuideReadOptions, type GuideSummary, type Lead, type LineCallerResult, type LineCallsOptions, type LineRequestResult, type ListBookingsOptions, type ListCallsOptions, type ListLeadsOptions, type OperatorRingNumber, type OperatorRingNumbersResult, type PhoneLineInfo, type PhoneLineRequest, type PhoneLineStatus, type PhoneLineWebhook, type PlaceCallResult, type RegisteredWebhook, ReportResult, ReportSeverity, ReportType, type RingErrorCode, type RingNumber, type RingNumberList, type RingNumberWriteResult, type ServerReportOptions, type ServerReporterConfig, type ServerReporterIdentity, type SignSessionOptions, addFollowUpNote, addLineCaller, addRingNumber, cancelBooking, captureServerErrors, changeLineNumber, configureServerReporter, createCallIssueSession, deleteCall, dialFollowUp, disableCalling, discardBookingQuestionsDraft, editFollowUpNote, enableCalling, escapeJsonForScript, getBookingSettings, getCall, getFollowUp, getGuide, getOperatorRingNumbers, getPhoneLine, listBookings, listCalls, listFollowUps, listGuides, listLeads, listRingNumbers, listWebhooks, placeCall, publishBookingQuestions, registerWebhook, removeLineCaller, removeRingNumber, removeWebhook, reportServerError, rescheduleBooking, resetServerReporter, setFollowUpBooking, signSession, submitPhoneKyc, testRingNumber, updateBookingSettings, updateRingNumber };
|
|
1378
|
+
export { type Booking, type BookingAnswer, type BookingClientNotice, type BookingMutationResult, type BookingNotifyRecipient, type BookingQuestion, type BookingQuestionInput, type BookingSettings, type BookingSettingsChanges, type BookingSettingsResult, type BookingSettingsState, type BookingWorkingHours, type Call, type CallAudio, type CallIssueSessionOptions, type CallIssueSessionResult, type CallListItem, type CallMoment, type CallParticipant, type CallWebhook, type CallsOptions, type CaptureServerConsoleOptions, type CaptureServerErrorsOptions, type DeleteCallResult, type FollowUp, type FollowUpBooking, type FollowUpCall, type FollowUpDetail, type FollowUpDue, type FollowUpNote, type FollowUpOperator, type FollowUpWriteResult, type GetCallOptions, type Guide, type GuideReadOptions, type GuideSummary, type Lead, type LineCallerResult, type LineCallsOptions, type LineRequestResult, type ListBookingsOptions, type ListCallsOptions, type ListLeadsOptions, type NextRequestErrorContext, type NextRequestErrorRequest, type OperatorRingNumber, type OperatorRingNumbersResult, type PhoneLineInfo, type PhoneLineRequest, type PhoneLineStatus, type PhoneLineWebhook, type PlaceCallResult, type RegisteredWebhook, ReportResult, ReportSeverity, ReportType, type RingErrorCode, type RingNumber, type RingNumberList, type RingNumberWriteResult, type ServerReportOptions, type ServerReporterConfig, type ServerReporterIdentity, type SignSessionOptions, addFollowUpNote, addLineCaller, addRingNumber, cancelBooking, captureServerConsole, captureServerErrors, changeLineNumber, configureServerReporter, createCallIssueSession, deleteCall, dialFollowUp, disableCalling, discardBookingQuestionsDraft, editFollowUpNote, enableCalling, escapeJsonForScript, getBookingSettings, getCall, getFollowUp, getGuide, getOperatorRingNumbers, getPhoneLine, listBookings, listCalls, listFollowUps, listGuides, listLeads, listRingNumbers, listWebhooks, placeCall, publishBookingQuestions, registerWebhook, removeLineCaller, removeRingNumber, removeWebhook, reportRequestError, reportServerError, rescheduleBooking, resetServerReporter, setFollowUpBooking, signSession, submitPhoneKyc, testRingNumber, updateBookingSettings, updateRingNumber };
|
package/dist/server.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(server_exports, {
|
|
|
24
24
|
addLineCaller: () => addLineCaller,
|
|
25
25
|
addRingNumber: () => addRingNumber,
|
|
26
26
|
cancelBooking: () => cancelBooking,
|
|
27
|
+
captureServerConsole: () => captureServerConsole,
|
|
27
28
|
captureServerErrors: () => captureServerErrors,
|
|
28
29
|
changeLineNumber: () => changeLineNumber,
|
|
29
30
|
configureServerReporter: () => configureServerReporter,
|
|
@@ -54,6 +55,7 @@ __export(server_exports, {
|
|
|
54
55
|
removeLineCaller: () => removeLineCaller,
|
|
55
56
|
removeRingNumber: () => removeRingNumber,
|
|
56
57
|
removeWebhook: () => removeWebhook,
|
|
58
|
+
reportRequestError: () => reportRequestError,
|
|
57
59
|
reportServerError: () => reportServerError,
|
|
58
60
|
rescheduleBooking: () => rescheduleBooking,
|
|
59
61
|
resetServerReporter: () => resetServerReporter,
|
|
@@ -67,6 +69,16 @@ __export(server_exports, {
|
|
|
67
69
|
module.exports = __toCommonJS(server_exports);
|
|
68
70
|
var import_node_crypto = require("crypto");
|
|
69
71
|
|
|
72
|
+
// src/redact.ts
|
|
73
|
+
var EMAIL_RE = /[\w.+-]+@[\w-]+\.[\w.-]+/g;
|
|
74
|
+
var JWT_RE = /\beyJ[\w-]{8,}\.[\w-]{8,}\.[\w-]{8,}\b/g;
|
|
75
|
+
var BEARER_RE = /\b(bearer\s+)[\w-.~+/]{12,}=*/gi;
|
|
76
|
+
var KEY_PREFIX_RE = /\b(?:(?:sk|rk|pk)_(?:live|test)_[A-Za-z0-9]{10,}|sk-[A-Za-z0-9_-]{16,}|gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}|AKIA[0-9A-Z]{16}|xox[abposr]-[A-Za-z0-9-]{10,}|gg[cswi]?_[A-Za-z0-9]{20,})\b/g;
|
|
77
|
+
var URL_CREDENTIALS_RE = /\b([a-z][a-z0-9+.-]*:\/\/[^\s:@/]+):[^\s@/]+@/gi;
|
|
78
|
+
function redactString(value) {
|
|
79
|
+
return value.replace(URL_CREDENTIALS_RE, "$1:[REDACTED]@").replace(KEY_PREFIX_RE, "[REDACTED]").replace(JWT_RE, "[REDACTED]").replace(BEARER_RE, "$1[REDACTED]").replace(EMAIL_RE, "[REDACTED_EMAIL]");
|
|
80
|
+
}
|
|
81
|
+
|
|
70
82
|
// src/runtime.ts
|
|
71
83
|
var pageLoadedAt = Date.now();
|
|
72
84
|
|
|
@@ -129,6 +141,71 @@ async function sendReport(payload, baseUrl) {
|
|
|
129
141
|
}
|
|
130
142
|
}
|
|
131
143
|
|
|
144
|
+
// src/dedup.ts
|
|
145
|
+
var DEFAULT_WINDOW_MS = 5 * 60 * 1e3;
|
|
146
|
+
var MAX_ENTRIES = 100;
|
|
147
|
+
var seen = /* @__PURE__ */ new Map();
|
|
148
|
+
function hashString(input) {
|
|
149
|
+
let h1 = 3735928559 ^ 0;
|
|
150
|
+
let h2 = 1103547991 ^ 0;
|
|
151
|
+
for (let i = 0; i < input.length; i++) {
|
|
152
|
+
const ch = input.charCodeAt(i);
|
|
153
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
154
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
155
|
+
}
|
|
156
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
157
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
158
|
+
return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(36);
|
|
159
|
+
}
|
|
160
|
+
function topStackFrame(stack) {
|
|
161
|
+
if (!stack) return "";
|
|
162
|
+
const lines = stack.split("\n");
|
|
163
|
+
for (const line of lines) {
|
|
164
|
+
const t = line.trim();
|
|
165
|
+
if (t.startsWith("at ") || t.includes("@")) {
|
|
166
|
+
return t;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return "";
|
|
170
|
+
}
|
|
171
|
+
function stripUrlQuery(url) {
|
|
172
|
+
if (!url) return "";
|
|
173
|
+
try {
|
|
174
|
+
const u = new URL(url);
|
|
175
|
+
return `${u.origin}${u.pathname}`;
|
|
176
|
+
} catch (e) {
|
|
177
|
+
const q = url.indexOf("?");
|
|
178
|
+
return q === -1 ? url : url.slice(0, q);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function computeSignature(params) {
|
|
182
|
+
var _a, _b, _c, _d;
|
|
183
|
+
const msg = (_b = (_a = params.errorMessage) == null ? void 0 : _a.trim()) != null ? _b : "";
|
|
184
|
+
const page = stripUrlQuery(params.pageUrl);
|
|
185
|
+
const frame = topStackFrame(params.errorStack);
|
|
186
|
+
const digest = (_d = (_c = params.digest) == null ? void 0 : _c.trim()) != null ? _d : "";
|
|
187
|
+
return hashString(digest ? `${msg}|${page}|${frame}|${digest}` : `${msg}|${page}|${frame}`);
|
|
188
|
+
}
|
|
189
|
+
function shouldSkipDuplicate(signature, windowMs = DEFAULT_WINDOW_MS, now = Date.now()) {
|
|
190
|
+
const last = seen.get(signature);
|
|
191
|
+
if (last !== void 0 && now - last < windowMs) {
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
seen.set(signature, now);
|
|
195
|
+
if (seen.size > MAX_ENTRIES) {
|
|
196
|
+
const cutoff = now - windowMs;
|
|
197
|
+
for (const [sig, ts] of seen) {
|
|
198
|
+
if (ts < cutoff) seen.delete(sig);
|
|
199
|
+
}
|
|
200
|
+
if (seen.size > MAX_ENTRIES) {
|
|
201
|
+
const excess = seen.size - MAX_ENTRIES;
|
|
202
|
+
const keys = Array.from(seen.keys()).slice(0, excess);
|
|
203
|
+
for (const k of keys) seen.delete(k);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
|
|
132
209
|
// src/server.ts
|
|
133
210
|
var MAX_LOG_CHARS = 2e5;
|
|
134
211
|
var DEV_BLOCKED_MESSAGE = "development";
|
|
@@ -223,7 +300,9 @@ async function reportServerError(error, options = {}) {
|
|
|
223
300
|
if (!token) return null;
|
|
224
301
|
const enableInDevelopment = (_d = (_c = options.enableInDevelopment) != null ? _c : defaults.enableInDevelopment) != null ? _d : false;
|
|
225
302
|
if (!enableInDevelopment && readEnv("NODE_ENV") === DEV_BLOCKED_MESSAGE) return null;
|
|
226
|
-
const
|
|
303
|
+
const described = describeError(error);
|
|
304
|
+
const message = redactString(described.message) || "Unknown server error";
|
|
305
|
+
const stack = described.stack ? redactString(described.stack) : void 0;
|
|
227
306
|
const context = (_e = options.context) != null ? _e : defaults.context;
|
|
228
307
|
const reporter = { ...defaults.reporter, ...options.reporter };
|
|
229
308
|
const payload = {
|
|
@@ -276,12 +355,15 @@ function captureServerErrors(options = {}) {
|
|
|
276
355
|
}
|
|
277
356
|
};
|
|
278
357
|
proc.on("uncaughtExceptionMonitor", onException);
|
|
358
|
+
const consoleLevels = options.console === void 0 ? DEFAULT_SERVER_CONSOLE : options.console;
|
|
359
|
+
const restoreConsole = consoleLevels && consoleLevels.length ? captureServerConsole({ ...options, levels: consoleLevels, context: options.context }) : null;
|
|
279
360
|
const captureRejections = (_a = options.captureUnhandledRejections) != null ? _a : true;
|
|
280
361
|
if (captureRejections) proc.on("unhandledRejection", onRejection);
|
|
281
362
|
return () => {
|
|
282
363
|
var _a2, _b;
|
|
283
364
|
try {
|
|
284
365
|
(_a2 = proc.off) == null ? void 0 : _a2.call(proc, "uncaughtExceptionMonitor", onException);
|
|
366
|
+
restoreConsole == null ? void 0 : restoreConsole();
|
|
285
367
|
if (captureRejections) {
|
|
286
368
|
(_b = proc.off) == null ? void 0 : _b.call(proc, "unhandledRejection", onRejection);
|
|
287
369
|
}
|
|
@@ -293,6 +375,155 @@ function captureServerErrors(options = {}) {
|
|
|
293
375
|
};
|
|
294
376
|
}
|
|
295
377
|
}
|
|
378
|
+
var reportedServerErrors = /* @__PURE__ */ new WeakSet();
|
|
379
|
+
function markServerErrorReported(error) {
|
|
380
|
+
try {
|
|
381
|
+
if (error && typeof error === "object") reportedServerErrors.add(error);
|
|
382
|
+
} catch (e) {
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
function isClientAbort(error) {
|
|
386
|
+
try {
|
|
387
|
+
const e = error;
|
|
388
|
+
if ((e == null ? void 0 : e.name) === "ResponseAborted") return true;
|
|
389
|
+
return (e == null ? void 0 : e.code) === "ECONNRESET" && typeof (e == null ? void 0 : e.message) === "string" && e.message.trim() === "aborted";
|
|
390
|
+
} catch (e) {
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
function isClientAbortLine(text) {
|
|
395
|
+
return /\bError: aborted\b/.test(text) && /\bECONNRESET\b/.test(text);
|
|
396
|
+
}
|
|
397
|
+
function keepAlive(work) {
|
|
398
|
+
var _a, _b, _c;
|
|
399
|
+
try {
|
|
400
|
+
const store = globalThis[/* @__PURE__ */ Symbol.for("@vercel/request-context")];
|
|
401
|
+
(_c = (_b = (_a = store == null ? void 0 : store.get) == null ? void 0 : _a.call(store)) == null ? void 0 : _b.waitUntil) == null ? void 0 : _c.call(_b, work.catch(() => {
|
|
402
|
+
}));
|
|
403
|
+
} catch (e) {
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
async function reportRequestError(error, request, context = {}, options = {}) {
|
|
407
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
408
|
+
try {
|
|
409
|
+
if (isClientAbort(error)) return null;
|
|
410
|
+
markServerErrorReported(error);
|
|
411
|
+
const method = ((_a = request == null ? void 0 : request.method) != null ? _a : "GET").toUpperCase();
|
|
412
|
+
const route = (_d = (_c = context.routePath) != null ? _c : (_b = request == null ? void 0 : request.path) == null ? void 0 : _b.split("?")[0]) != null ? _d : "unknown";
|
|
413
|
+
const digest = typeof (error == null ? void 0 : error.digest) === "string" ? error.digest : void 0;
|
|
414
|
+
return await reportServerError(error, {
|
|
415
|
+
...options,
|
|
416
|
+
context: (_e = options.context) != null ? _e : `route${route.startsWith("/") ? "" : "/"}${route}`,
|
|
417
|
+
description: (_h = options.description) != null ? _h : `${method} ${(_g = (_f = request == null ? void 0 : request.path) == null ? void 0 : _f.split("?")[0]) != null ? _g : route} failed on the server${context.routeType ? ` (${context.routeType}${context.routerKind ? `, ${context.routerKind}` : ""})` : ""}.`,
|
|
418
|
+
metadata: {
|
|
419
|
+
...options.metadata,
|
|
420
|
+
capturedBy: "onRequestError",
|
|
421
|
+
requestMethod: method,
|
|
422
|
+
...(request == null ? void 0 : request.path) ? { requestPath: request.path.split("?")[0] } : {},
|
|
423
|
+
...context.routePath ? { routePath: context.routePath } : {},
|
|
424
|
+
...context.routeType ? { routeType: context.routeType } : {},
|
|
425
|
+
...context.routerKind ? { routerKind: context.routerKind } : {},
|
|
426
|
+
...context.renderSource ? { renderSource: context.renderSource } : {},
|
|
427
|
+
...digest ? { digest } : {}
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
} catch (e) {
|
|
431
|
+
return null;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
var DEFAULT_SERVER_CONSOLE = ["error", "warn"];
|
|
435
|
+
var SERVER_CONSOLE_NOISE = [/^\[glitchgrab\]/i, /ExperimentalWarning/, /DeprecationWarning/];
|
|
436
|
+
var SERVER_CONSOLE_MAX = 2e3;
|
|
437
|
+
var SERVER_ERROR_ARG_DELAY_MS = 1500;
|
|
438
|
+
function consoleText(args) {
|
|
439
|
+
try {
|
|
440
|
+
return args.map((a) => {
|
|
441
|
+
if (typeof a === "string") return a;
|
|
442
|
+
if (a instanceof Error) return a.message;
|
|
443
|
+
try {
|
|
444
|
+
return JSON.stringify(a);
|
|
445
|
+
} catch (e) {
|
|
446
|
+
return String(a);
|
|
447
|
+
}
|
|
448
|
+
}).join(" ").slice(0, SERVER_CONSOLE_MAX);
|
|
449
|
+
} catch (e) {
|
|
450
|
+
return "";
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
var restoreServerConsole = null;
|
|
454
|
+
function captureServerConsole(options = {}) {
|
|
455
|
+
var _a;
|
|
456
|
+
try {
|
|
457
|
+
if (restoreServerConsole) restoreServerConsole();
|
|
458
|
+
const levels = new Set((_a = options.levels) != null ? _a : ["error"]);
|
|
459
|
+
const original = { error: console.error, warn: console.warn };
|
|
460
|
+
let filing = false;
|
|
461
|
+
const file = (level, args) => {
|
|
462
|
+
var _a2, _b, _c;
|
|
463
|
+
try {
|
|
464
|
+
const err = args.find((a) => a instanceof Error);
|
|
465
|
+
if (err && (reportedServerErrors.has(err) || isClientAbort(err))) return Promise.resolve();
|
|
466
|
+
const text = redactString(consoleText(args)).trim();
|
|
467
|
+
if (!text) return Promise.resolve();
|
|
468
|
+
if (isClientAbortLine(text)) return Promise.resolve();
|
|
469
|
+
if (SERVER_CONSOLE_NOISE.some((re) => re.test(text))) return Promise.resolve();
|
|
470
|
+
if ((_a2 = options.ignore) == null ? void 0 : _a2.some((p) => p instanceof RegExp ? p.test(text) : text.includes(p))) {
|
|
471
|
+
return Promise.resolve();
|
|
472
|
+
}
|
|
473
|
+
const context = (_c = (_b = options.context) != null ? _b : defaults.context) != null ? _c : `console.${level}`;
|
|
474
|
+
const errorMessage = `console.${level}: ${err && args.length === 1 ? err.message : text}`;
|
|
475
|
+
const sig = computeSignature({ errorMessage, pageUrl: contextUrl(context), errorStack: err == null ? void 0 : err.stack });
|
|
476
|
+
if (shouldSkipDuplicate(sig)) return Promise.resolve();
|
|
477
|
+
if (err) markServerErrorReported(err);
|
|
478
|
+
filing = true;
|
|
479
|
+
try {
|
|
480
|
+
return reportServerError(err && args.length === 1 ? err : errorMessage, {
|
|
481
|
+
...options,
|
|
482
|
+
context,
|
|
483
|
+
metadata: {
|
|
484
|
+
...options.metadata,
|
|
485
|
+
capturedBy: `console.${level}`,
|
|
486
|
+
autoKind: "console",
|
|
487
|
+
consoleLevel: level
|
|
488
|
+
},
|
|
489
|
+
...err && args.length > 1 ? { description: text } : {}
|
|
490
|
+
});
|
|
491
|
+
} finally {
|
|
492
|
+
filing = false;
|
|
493
|
+
}
|
|
494
|
+
} catch (e) {
|
|
495
|
+
return Promise.resolve();
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
const wrap = (level) => function(...args) {
|
|
499
|
+
original[level].apply(console, args);
|
|
500
|
+
if (filing || !levels.has(level)) return;
|
|
501
|
+
try {
|
|
502
|
+
keepAlive(
|
|
503
|
+
args.some((a) => a instanceof Error) ? new Promise((resolve) => setTimeout(resolve, SERVER_ERROR_ARG_DELAY_MS)).then(
|
|
504
|
+
() => file(level, args)
|
|
505
|
+
) : file(level, args)
|
|
506
|
+
);
|
|
507
|
+
} catch (e) {
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
console.error = wrap("error");
|
|
511
|
+
console.warn = wrap("warn");
|
|
512
|
+
const restore = () => {
|
|
513
|
+
try {
|
|
514
|
+
console.error = original.error;
|
|
515
|
+
console.warn = original.warn;
|
|
516
|
+
} catch (e) {
|
|
517
|
+
}
|
|
518
|
+
if (restoreServerConsole === restore) restoreServerConsole = null;
|
|
519
|
+
};
|
|
520
|
+
restoreServerConsole = restore;
|
|
521
|
+
return restore;
|
|
522
|
+
} catch (e) {
|
|
523
|
+
return () => {
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
}
|
|
296
527
|
function signSession(options) {
|
|
297
528
|
var _a, _b, _c;
|
|
298
529
|
const userId = options == null ? void 0 : options.userId;
|
|
@@ -1213,6 +1444,7 @@ function testRingNumber(id, options = {}) {
|
|
|
1213
1444
|
addLineCaller,
|
|
1214
1445
|
addRingNumber,
|
|
1215
1446
|
cancelBooking,
|
|
1447
|
+
captureServerConsole,
|
|
1216
1448
|
captureServerErrors,
|
|
1217
1449
|
changeLineNumber,
|
|
1218
1450
|
configureServerReporter,
|
|
@@ -1243,6 +1475,7 @@ function testRingNumber(id, options = {}) {
|
|
|
1243
1475
|
removeLineCaller,
|
|
1244
1476
|
removeRingNumber,
|
|
1245
1477
|
removeWebhook,
|
|
1478
|
+
reportRequestError,
|
|
1246
1479
|
reportServerError,
|
|
1247
1480
|
rescheduleBooking,
|
|
1248
1481
|
resetServerReporter,
|