glitchgrab 1.58.1 → 1.58.3
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 +32 -0
- package/dist/index.d.mts +21 -3
- package/dist/index.d.ts +21 -3
- package/dist/index.js +2205 -1281
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2204 -1281
- package/dist/index.mjs.map +1 -1
- package/dist/server.d.mts +41 -3
- package/dist/server.d.ts +41 -3
- package/dist/server.js +49 -15
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +47 -15
- package/dist/server.mjs.map +1 -1
- package/dist/{types-DfVtKZcp.d.mts → types-BpTLWJ1y.d.mts} +8 -0
- package/dist/{types-DfVtKZcp.d.ts → types-BpTLWJ1y.d.ts} +8 -0
- package/package.json +1 -1
package/dist/server.mjs
CHANGED
|
@@ -8,6 +8,9 @@ var pageLoadedAt = Date.now();
|
|
|
8
8
|
var DEFAULT_BASE_URL = "https://glitchgrab.dev";
|
|
9
9
|
var MAX_RETRIES = 3;
|
|
10
10
|
var RETRY_BASE_MS = 500;
|
|
11
|
+
function reportAttemptTimeoutMs(bodyLength) {
|
|
12
|
+
return 1e4 + Math.ceil(bodyLength / 1e5) * 1e3;
|
|
13
|
+
}
|
|
11
14
|
async function sendReport(payload, baseUrl) {
|
|
12
15
|
var _a;
|
|
13
16
|
try {
|
|
@@ -18,13 +21,18 @@ async function sendReport(payload, baseUrl) {
|
|
|
18
21
|
Authorization: `Bearer ${payload.token}`
|
|
19
22
|
};
|
|
20
23
|
const useKeepalive = body.length < 6e4;
|
|
24
|
+
const timeoutMs = reportAttemptTimeoutMs(body.length);
|
|
21
25
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
|
26
|
+
const isLast = attempt === MAX_RETRIES - 1;
|
|
27
|
+
const controller = !isLast && typeof AbortController === "function" ? new AbortController() : null;
|
|
28
|
+
const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : null;
|
|
22
29
|
try {
|
|
23
30
|
const response = await fetch(url, {
|
|
24
31
|
method: "POST",
|
|
25
32
|
headers,
|
|
26
33
|
body,
|
|
27
|
-
...useKeepalive ? { keepalive: true } : {}
|
|
34
|
+
...useKeepalive ? { keepalive: true } : {},
|
|
35
|
+
...controller ? { signal: controller.signal } : {}
|
|
28
36
|
});
|
|
29
37
|
if (response.ok) {
|
|
30
38
|
const envelope = await response.json();
|
|
@@ -34,6 +42,8 @@ async function sendReport(payload, baseUrl) {
|
|
|
34
42
|
return null;
|
|
35
43
|
}
|
|
36
44
|
} catch (e) {
|
|
45
|
+
} finally {
|
|
46
|
+
if (timer) clearTimeout(timer);
|
|
37
47
|
}
|
|
38
48
|
if (attempt < MAX_RETRIES - 1) {
|
|
39
49
|
await new Promise(
|
|
@@ -289,14 +299,19 @@ function readGuideSummary(value) {
|
|
|
289
299
|
category: typeof guide.category === "string" ? guide.category : null,
|
|
290
300
|
orderIndex: typeof guide.orderIndex === "number" ? guide.orderIndex : 0,
|
|
291
301
|
status: guide.status === "DRAFT" ? "DRAFT" : "PUBLISHED",
|
|
302
|
+
audience: guide.audience === "INTERNAL" ? "INTERNAL" : "PUBLIC",
|
|
292
303
|
lastVerifiedAt: typeof guide.lastVerifiedAt === "string" ? guide.lastVerifiedAt : null,
|
|
293
304
|
updatedAt: typeof guide.updatedAt === "string" ? guide.updatedAt : "",
|
|
294
305
|
link: typeof guide.link === "string" ? guide.link : null
|
|
295
306
|
};
|
|
296
307
|
}
|
|
308
|
+
function audienceQuery(options, joiner) {
|
|
309
|
+
const audience = options.audience;
|
|
310
|
+
return audience === "internal" || audience === "all" ? `${joiner}audience=${audience}` : "";
|
|
311
|
+
}
|
|
297
312
|
async function listGuides(options = {}) {
|
|
298
313
|
try {
|
|
299
|
-
const data = await readGuidesApi("", options);
|
|
314
|
+
const data = await readGuidesApi(audienceQuery(options, "?"), options);
|
|
300
315
|
if (!Array.isArray(data)) return [];
|
|
301
316
|
return data.map(readGuideSummary).filter((guide) => guide !== null);
|
|
302
317
|
} catch (e) {
|
|
@@ -307,7 +322,7 @@ async function getGuide(slug, options = {}) {
|
|
|
307
322
|
try {
|
|
308
323
|
const wanted = typeof slug === "string" ? slug.trim() : "";
|
|
309
324
|
if (!wanted) return null;
|
|
310
|
-
const data = await readGuidesApi(`?slug=${encodeURIComponent(wanted)}`, options);
|
|
325
|
+
const data = await readGuidesApi(`?slug=${encodeURIComponent(wanted)}${audienceQuery(options, "&")}`, options);
|
|
311
326
|
const summary = readGuideSummary(data);
|
|
312
327
|
const body = data;
|
|
313
328
|
if (!summary || typeof (body == null ? void 0 : body.html) !== "string") return null;
|
|
@@ -426,8 +441,20 @@ async function deleteCall(id, options = {}) {
|
|
|
426
441
|
}
|
|
427
442
|
}
|
|
428
443
|
var WEEKDAY = /^[1-7]$/;
|
|
444
|
+
function readQuestionList(value) {
|
|
445
|
+
if (!Array.isArray(value)) return null;
|
|
446
|
+
return value.filter(isRecord).map((row) => {
|
|
447
|
+
var _a, _b;
|
|
448
|
+
return {
|
|
449
|
+
id: (_a = stringOrNull(row.id)) != null ? _a : "",
|
|
450
|
+
label: (_b = stringOrNull(row.label)) != null ? _b : "",
|
|
451
|
+
options: Array.isArray(row.options) ? row.options.filter((option) => typeof option === "string") : [],
|
|
452
|
+
required: row.required !== false
|
|
453
|
+
};
|
|
454
|
+
}).filter((row) => row.id !== "" && row.label !== "");
|
|
455
|
+
}
|
|
429
456
|
function readBookingSettingsState(value) {
|
|
430
|
-
var _a, _b, _c, _d;
|
|
457
|
+
var _a, _b, _c, _d, _e;
|
|
431
458
|
if (!isRecord(value) || !isRecord(value.settings)) return null;
|
|
432
459
|
const s = value.settings;
|
|
433
460
|
const hours = {};
|
|
@@ -461,15 +488,9 @@ function readBookingSettingsState(value) {
|
|
|
461
488
|
phone: (_b2 = stringOrNull(row.phone)) != null ? _b2 : ""
|
|
462
489
|
};
|
|
463
490
|
}).filter((row) => row.phone !== "") : [],
|
|
464
|
-
questions:
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
id: (_a2 = stringOrNull(row.id)) != null ? _a2 : "",
|
|
468
|
-
label: (_b2 = stringOrNull(row.label)) != null ? _b2 : "",
|
|
469
|
-
options: Array.isArray(row.options) ? row.options.filter((option) => typeof option === "string") : [],
|
|
470
|
-
required: row.required !== false
|
|
471
|
-
};
|
|
472
|
-
}).filter((row) => row.id !== "" && row.label !== "") : [],
|
|
491
|
+
questions: (_e = readQuestionList(s.questions)) != null ? _e : [],
|
|
492
|
+
// A server from before drafts sends no key: no draft.
|
|
493
|
+
draftQuestions: readQuestionList(s.draftQuestions),
|
|
473
494
|
// Missing means a server from before the switch, which always asked.
|
|
474
495
|
requireOtp: s.requireOtp !== false
|
|
475
496
|
},
|
|
@@ -488,13 +509,16 @@ async function getBookingSettings(options = {}) {
|
|
|
488
509
|
return { ok: false, error: "Could not read booking settings" };
|
|
489
510
|
}
|
|
490
511
|
}
|
|
491
|
-
|
|
512
|
+
function updateBookingSettings(changes, options = {}) {
|
|
513
|
+
return putBookingSettings(changes != null ? changes : {}, options);
|
|
514
|
+
}
|
|
515
|
+
async function putBookingSettings(body, options) {
|
|
492
516
|
try {
|
|
493
517
|
const key = callsKey(options);
|
|
494
518
|
if (!key) return { ok: false, error: NO_KEY_ERROR };
|
|
495
519
|
const { data, error } = await callSdkApi("/api/v1/sdk/booking-settings", key, options, {
|
|
496
520
|
method: "PUT",
|
|
497
|
-
body
|
|
521
|
+
body,
|
|
498
522
|
cache: "no-store"
|
|
499
523
|
});
|
|
500
524
|
const state = error === null ? readBookingSettingsState(data) : null;
|
|
@@ -503,6 +527,12 @@ async function updateBookingSettings(changes, options = {}) {
|
|
|
503
527
|
return { ok: false, error: "Could not save booking settings" };
|
|
504
528
|
}
|
|
505
529
|
}
|
|
530
|
+
function publishBookingQuestions(options = {}) {
|
|
531
|
+
return putBookingSettings({ publishDraft: true }, options);
|
|
532
|
+
}
|
|
533
|
+
function discardBookingQuestionsDraft(options = {}) {
|
|
534
|
+
return putBookingSettings({ discardDraft: true }, options);
|
|
535
|
+
}
|
|
506
536
|
function readBooking(value) {
|
|
507
537
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
508
538
|
if (!isRecord(value) || typeof value.id !== "string") return null;
|
|
@@ -650,6 +680,7 @@ export {
|
|
|
650
680
|
captureServerErrors,
|
|
651
681
|
configureServerReporter,
|
|
652
682
|
deleteCall,
|
|
683
|
+
discardBookingQuestionsDraft,
|
|
653
684
|
escapeJsonForScript,
|
|
654
685
|
getBookingSettings,
|
|
655
686
|
getCall,
|
|
@@ -658,6 +689,7 @@ export {
|
|
|
658
689
|
listCalls,
|
|
659
690
|
listGuides,
|
|
660
691
|
listLeads,
|
|
692
|
+
publishBookingQuestions,
|
|
661
693
|
reportServerError,
|
|
662
694
|
rescheduleBooking,
|
|
663
695
|
resetServerReporter,
|