glitchgrab 1.67.0 → 1.68.1
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 +60 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +249 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +249 -18
- package/dist/index.mjs.map +1 -1
- package/dist/server.d.mts +95 -10
- package/dist/server.d.ts +95 -10
- package/dist/server.js +244 -2
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +241 -2
- package/dist/server.mjs.map +1 -1
- package/dist/{types-Dw587jLi.d.mts → types-Dadt801V.d.mts} +13 -0
- package/dist/{types-Dw587jLi.d.ts → types-Dadt801V.d.ts} +13 -0
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -24,7 +24,9 @@ __export(server_exports, {
|
|
|
24
24
|
addLineCaller: () => addLineCaller,
|
|
25
25
|
addRingNumber: () => addRingNumber,
|
|
26
26
|
cancelBooking: () => cancelBooking,
|
|
27
|
+
captureServerConsole: () => captureServerConsole,
|
|
27
28
|
captureServerErrors: () => captureServerErrors,
|
|
29
|
+
changeLineNumber: () => changeLineNumber,
|
|
28
30
|
configureServerReporter: () => configureServerReporter,
|
|
29
31
|
createCallIssueSession: () => createCallIssueSession,
|
|
30
32
|
deleteCall: () => deleteCall,
|
|
@@ -53,6 +55,7 @@ __export(server_exports, {
|
|
|
53
55
|
removeLineCaller: () => removeLineCaller,
|
|
54
56
|
removeRingNumber: () => removeRingNumber,
|
|
55
57
|
removeWebhook: () => removeWebhook,
|
|
58
|
+
reportRequestError: () => reportRequestError,
|
|
56
59
|
reportServerError: () => reportServerError,
|
|
57
60
|
rescheduleBooking: () => rescheduleBooking,
|
|
58
61
|
resetServerReporter: () => resetServerReporter,
|
|
@@ -66,6 +69,16 @@ __export(server_exports, {
|
|
|
66
69
|
module.exports = __toCommonJS(server_exports);
|
|
67
70
|
var import_node_crypto = require("crypto");
|
|
68
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
|
+
|
|
69
82
|
// src/runtime.ts
|
|
70
83
|
var pageLoadedAt = Date.now();
|
|
71
84
|
|
|
@@ -128,6 +141,71 @@ async function sendReport(payload, baseUrl) {
|
|
|
128
141
|
}
|
|
129
142
|
}
|
|
130
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
|
+
|
|
131
209
|
// src/server.ts
|
|
132
210
|
var MAX_LOG_CHARS = 2e5;
|
|
133
211
|
var DEV_BLOCKED_MESSAGE = "development";
|
|
@@ -222,7 +300,9 @@ async function reportServerError(error, options = {}) {
|
|
|
222
300
|
if (!token) return null;
|
|
223
301
|
const enableInDevelopment = (_d = (_c = options.enableInDevelopment) != null ? _c : defaults.enableInDevelopment) != null ? _d : false;
|
|
224
302
|
if (!enableInDevelopment && readEnv("NODE_ENV") === DEV_BLOCKED_MESSAGE) return null;
|
|
225
|
-
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;
|
|
226
306
|
const context = (_e = options.context) != null ? _e : defaults.context;
|
|
227
307
|
const reporter = { ...defaults.reporter, ...options.reporter };
|
|
228
308
|
const payload = {
|
|
@@ -275,12 +355,15 @@ function captureServerErrors(options = {}) {
|
|
|
275
355
|
}
|
|
276
356
|
};
|
|
277
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;
|
|
278
360
|
const captureRejections = (_a = options.captureUnhandledRejections) != null ? _a : true;
|
|
279
361
|
if (captureRejections) proc.on("unhandledRejection", onRejection);
|
|
280
362
|
return () => {
|
|
281
363
|
var _a2, _b;
|
|
282
364
|
try {
|
|
283
365
|
(_a2 = proc.off) == null ? void 0 : _a2.call(proc, "uncaughtExceptionMonitor", onException);
|
|
366
|
+
restoreConsole == null ? void 0 : restoreConsole();
|
|
284
367
|
if (captureRejections) {
|
|
285
368
|
(_b = proc.off) == null ? void 0 : _b.call(proc, "unhandledRejection", onRejection);
|
|
286
369
|
}
|
|
@@ -292,6 +375,155 @@ function captureServerErrors(options = {}) {
|
|
|
292
375
|
};
|
|
293
376
|
}
|
|
294
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
|
+
}
|
|
295
527
|
function signSession(options) {
|
|
296
528
|
var _a, _b, _c;
|
|
297
529
|
const userId = options == null ? void 0 : options.userId;
|
|
@@ -803,6 +1035,9 @@ function readFollowUp(value) {
|
|
|
803
1035
|
lastNoteAt: stringOrNull(value.lastNoteAt),
|
|
804
1036
|
lastNoteBy: stringOrNull(value.lastNoteBy),
|
|
805
1037
|
noteCount: (_a = numberOrNull(value.noteCount)) != null ? _a : 0,
|
|
1038
|
+
callCount: numberOrNull(value.callCount),
|
|
1039
|
+
talkedCount: numberOrNull(value.talkedCount),
|
|
1040
|
+
talkSec: numberOrNull(value.talkSec),
|
|
806
1041
|
lastCall: call ? {
|
|
807
1042
|
id: call.id,
|
|
808
1043
|
status: stringOrNull(call.status),
|
|
@@ -850,7 +1085,8 @@ function readFollowUpDetail(value) {
|
|
|
850
1085
|
operatorName: stringOrNull(c.operatorName),
|
|
851
1086
|
shared: c.shared === true,
|
|
852
1087
|
overview: stringOrNull(c.overview),
|
|
853
|
-
recordingUrl: stringOrNull(c.recordingUrl)
|
|
1088
|
+
recordingUrl: stringOrNull(c.recordingUrl),
|
|
1089
|
+
fromCallNoteAt: stringOrNull(c.fromCallNoteAt)
|
|
854
1090
|
};
|
|
855
1091
|
}) : []
|
|
856
1092
|
};
|
|
@@ -1069,6 +1305,9 @@ function enableCalling(params, options = {}) {
|
|
|
1069
1305
|
function disableCalling(params, options = {}) {
|
|
1070
1306
|
return lineRequestCall("/api/v1/sdk/phone-lines/disable", params, options);
|
|
1071
1307
|
}
|
|
1308
|
+
function changeLineNumber(params, options = {}) {
|
|
1309
|
+
return lineRequestCall("/api/v1/sdk/phone-lines/change", params, options);
|
|
1310
|
+
}
|
|
1072
1311
|
async function registerWebhook(webhook, options = {}) {
|
|
1073
1312
|
try {
|
|
1074
1313
|
const key = callsKey(options);
|
|
@@ -1205,7 +1444,9 @@ function testRingNumber(id, options = {}) {
|
|
|
1205
1444
|
addLineCaller,
|
|
1206
1445
|
addRingNumber,
|
|
1207
1446
|
cancelBooking,
|
|
1447
|
+
captureServerConsole,
|
|
1208
1448
|
captureServerErrors,
|
|
1449
|
+
changeLineNumber,
|
|
1209
1450
|
configureServerReporter,
|
|
1210
1451
|
createCallIssueSession,
|
|
1211
1452
|
deleteCall,
|
|
@@ -1234,6 +1475,7 @@ function testRingNumber(id, options = {}) {
|
|
|
1234
1475
|
removeLineCaller,
|
|
1235
1476
|
removeRingNumber,
|
|
1236
1477
|
removeWebhook,
|
|
1478
|
+
reportRequestError,
|
|
1237
1479
|
reportServerError,
|
|
1238
1480
|
rescheduleBooking,
|
|
1239
1481
|
resetServerReporter,
|