glitchgrab 1.61.2 → 1.62.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 +50 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +415 -219
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +415 -219
- package/dist/index.mjs.map +1 -1
- package/dist/server.d.mts +243 -2
- package/dist/server.d.ts +243 -2
- package/dist/server.js +247 -3
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +235 -2
- package/dist/server.mjs.map +1 -1
- package/dist/{types-BlMF6wzX.d.mts → types-Dp5Sh_hd.d.mts} +1 -1
- package/dist/{types-BlMF6wzX.d.ts → types-Dp5Sh_hd.d.ts} +1 -1
- package/package.json +1 -1
package/dist/server.mjs
CHANGED
|
@@ -269,7 +269,11 @@ async function callSdkApi(path, token, options, init) {
|
|
|
269
269
|
const response = await fetch(`${baseUrl}${path}`, request);
|
|
270
270
|
const body = await response.json().catch(() => null);
|
|
271
271
|
if (!response.ok || (body == null ? void 0 : body.success) !== true) {
|
|
272
|
-
return {
|
|
272
|
+
return {
|
|
273
|
+
data: null,
|
|
274
|
+
error: typeof (body == null ? void 0 : body.error) === "string" ? body.error : `HTTP ${response.status}`,
|
|
275
|
+
...typeof (body == null ? void 0 : body.code) === "string" ? { code: body.code } : {}
|
|
276
|
+
};
|
|
273
277
|
}
|
|
274
278
|
return { data: (_f = body.data) != null ? _f : null, error: null };
|
|
275
279
|
} catch (e) {
|
|
@@ -675,25 +679,254 @@ async function listLeads(options = {}) {
|
|
|
675
679
|
return [];
|
|
676
680
|
}
|
|
677
681
|
}
|
|
682
|
+
var DUES = /* @__PURE__ */ new Set(["none", "upcoming", "today", "overdue"]);
|
|
683
|
+
function readFollowUp(value) {
|
|
684
|
+
var _a, _b;
|
|
685
|
+
if (!isRecord(value)) return null;
|
|
686
|
+
const call = isRecord(value.lastCall) && typeof value.lastCall.id === "string" ? value.lastCall : null;
|
|
687
|
+
return {
|
|
688
|
+
id: stringOrNull(value.id),
|
|
689
|
+
externalId: stringOrNull(value.externalId),
|
|
690
|
+
phone: stringOrNull(value.phone),
|
|
691
|
+
name: stringOrNull(value.name),
|
|
692
|
+
nextCallAt: stringOrNull(value.nextCallAt),
|
|
693
|
+
nextCallBookedBy: stringOrNull(value.nextCallBookedBy),
|
|
694
|
+
due: typeof value.due === "string" && DUES.has(value.due) ? value.due : "none",
|
|
695
|
+
suggestedNextCallAt: stringOrNull(value.suggestedNextCallAt),
|
|
696
|
+
suggestedNextCallReason: stringOrNull(value.suggestedNextCallReason),
|
|
697
|
+
lastNote: stringOrNull(value.lastNote),
|
|
698
|
+
lastNoteAt: stringOrNull(value.lastNoteAt),
|
|
699
|
+
lastNoteBy: stringOrNull(value.lastNoteBy),
|
|
700
|
+
noteCount: (_a = numberOrNull(value.noteCount)) != null ? _a : 0,
|
|
701
|
+
lastCall: call ? {
|
|
702
|
+
id: call.id,
|
|
703
|
+
status: stringOrNull(call.status),
|
|
704
|
+
at: (_b = stringOrNull(call.at)) != null ? _b : "",
|
|
705
|
+
durationSec: numberOrNull(call.durationSec),
|
|
706
|
+
ringingIndex: numberOrNull(call.ringingIndex),
|
|
707
|
+
ringingPhone: stringOrNull(call.ringingPhone)
|
|
708
|
+
} : null
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
function readFollowUpDetail(value) {
|
|
712
|
+
var _a;
|
|
713
|
+
const base = readFollowUp(value);
|
|
714
|
+
if (!base || !isRecord(value)) return null;
|
|
715
|
+
return {
|
|
716
|
+
...base,
|
|
717
|
+
linksExpireInSeconds: (_a = numberOrNull(value.linksExpireInSeconds)) != null ? _a : 0,
|
|
718
|
+
notes: Array.isArray(value.notes) ? value.notes.filter(isRecord).filter((n) => typeof n.id === "string" && typeof n.body === "string").map((n) => {
|
|
719
|
+
var _a2, _b;
|
|
720
|
+
return {
|
|
721
|
+
id: n.id,
|
|
722
|
+
body: n.body,
|
|
723
|
+
source: (_a2 = stringOrNull(n.source)) != null ? _a2 : "manual",
|
|
724
|
+
author: stringOrNull(n.author),
|
|
725
|
+
callId: stringOrNull(n.callId),
|
|
726
|
+
editedAt: stringOrNull(n.editedAt),
|
|
727
|
+
createdAt: (_b = stringOrNull(n.createdAt)) != null ? _b : ""
|
|
728
|
+
};
|
|
729
|
+
}) : [],
|
|
730
|
+
calls: Array.isArray(value.calls) ? value.calls.filter(isRecord).filter((c) => typeof c.id === "string").map((c) => {
|
|
731
|
+
var _a2;
|
|
732
|
+
return {
|
|
733
|
+
id: c.id,
|
|
734
|
+
status: stringOrNull(c.status),
|
|
735
|
+
direction: stringOrNull(c.direction),
|
|
736
|
+
at: (_a2 = stringOrNull(c.at)) != null ? _a2 : "",
|
|
737
|
+
durationSec: numberOrNull(c.durationSec),
|
|
738
|
+
ringingIndex: numberOrNull(c.ringingIndex),
|
|
739
|
+
ringingPhone: stringOrNull(c.ringingPhone),
|
|
740
|
+
shared: c.shared === true,
|
|
741
|
+
overview: stringOrNull(c.overview),
|
|
742
|
+
recordingUrl: stringOrNull(c.recordingUrl)
|
|
743
|
+
};
|
|
744
|
+
}) : []
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
function followUpPath(externalId, rest = "") {
|
|
748
|
+
const id = typeof externalId === "string" ? externalId.trim() : "";
|
|
749
|
+
return id ? `/api/v1/sdk/follow-ups/${encodeURIComponent(id)}${rest}` : null;
|
|
750
|
+
}
|
|
751
|
+
async function writeFollowUp(path, method, body, options, pick) {
|
|
752
|
+
try {
|
|
753
|
+
if (!path) return { ok: false, error: "No externalId" };
|
|
754
|
+
const key = callsKey(options);
|
|
755
|
+
if (!key) return { ok: false, error: NO_KEY_ERROR };
|
|
756
|
+
const { data, error, code } = await callSdkApi(path, key, options, { method, body, cache: "no-store" });
|
|
757
|
+
if (error !== null || !isRecord(data) || typeof data.followUpId !== "string") {
|
|
758
|
+
return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
|
|
759
|
+
}
|
|
760
|
+
return { ok: true, followUpId: data.followUpId, ...pick(data) };
|
|
761
|
+
} catch (e) {
|
|
762
|
+
return { ok: false, error: "Could not reach Glitchgrab" };
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
async function listFollowUps(externalIds, options = {}) {
|
|
766
|
+
try {
|
|
767
|
+
const key = callsKey(options);
|
|
768
|
+
const ids = Array.isArray(externalIds) ? externalIds.filter((id) => typeof id === "string" && id.trim()) : [];
|
|
769
|
+
if (!key || ids.length === 0) return [];
|
|
770
|
+
const query = new URLSearchParams({ externalIds: ids.join(",") });
|
|
771
|
+
const { data } = await callSdkApi(`/api/v1/sdk/follow-ups?${query.toString()}`, key, options, {
|
|
772
|
+
cache: "no-store"
|
|
773
|
+
});
|
|
774
|
+
if (!Array.isArray(data)) return [];
|
|
775
|
+
return data.map(readFollowUp).filter((f) => f !== null);
|
|
776
|
+
} catch (e) {
|
|
777
|
+
return [];
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
async function getFollowUp(externalId, options = {}) {
|
|
781
|
+
try {
|
|
782
|
+
const path = followUpPath(externalId);
|
|
783
|
+
const key = callsKey(options);
|
|
784
|
+
if (!path || !key) return null;
|
|
785
|
+
const { data } = await callSdkApi(path, key, options, { cache: "no-store" });
|
|
786
|
+
return readFollowUpDetail(data);
|
|
787
|
+
} catch (e) {
|
|
788
|
+
return null;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
function addFollowUpNote(externalId, note, options = {}) {
|
|
792
|
+
return writeFollowUp(followUpPath(externalId, "/notes"), "POST", note, options, (d) => ({
|
|
793
|
+
id: typeof d.id === "string" ? d.id : ""
|
|
794
|
+
}));
|
|
795
|
+
}
|
|
796
|
+
function setFollowUpBooking(externalId, booking, options = {}) {
|
|
797
|
+
const at = booking.nextCallAt instanceof Date ? booking.nextCallAt.toISOString() : booking.nextCallAt;
|
|
798
|
+
return writeFollowUp(followUpPath(externalId, "/booking"), "PUT", { ...booking, nextCallAt: at }, options, (d) => ({
|
|
799
|
+
nextCallAt: stringOrNull(d.nextCallAt)
|
|
800
|
+
}));
|
|
801
|
+
}
|
|
802
|
+
function dialFollowUp(externalId, call, options = {}) {
|
|
803
|
+
return writeFollowUp(followUpPath(externalId, "/dial"), "POST", call, options, (d) => ({
|
|
804
|
+
callId: typeof d.callId === "string" ? d.callId : "",
|
|
805
|
+
ringing: typeof d.ringing === "string" ? d.ringing : "",
|
|
806
|
+
ringNumbers: Array.isArray(d.ringNumbers) ? d.ringNumbers.filter((n) => typeof n === "string") : []
|
|
807
|
+
}));
|
|
808
|
+
}
|
|
809
|
+
async function getOperatorRingNumbers(operator, options = {}) {
|
|
810
|
+
try {
|
|
811
|
+
const key = callsKey(options);
|
|
812
|
+
if (!key) return { ok: false, error: NO_KEY_ERROR };
|
|
813
|
+
const query = new URLSearchParams("email" in operator ? { email: operator.email } : { phone: operator.phone });
|
|
814
|
+
const { data, error, code } = await callSdkApi(`/api/v1/sdk/phone-lines/operator?${query.toString()}`, key, options, {
|
|
815
|
+
cache: "no-store"
|
|
816
|
+
});
|
|
817
|
+
if (error !== null || !isRecord(data)) return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
|
|
818
|
+
const op = isRecord(data.operator) ? data.operator : {};
|
|
819
|
+
return {
|
|
820
|
+
ok: true,
|
|
821
|
+
operator: { name: stringOrNull(op.name) },
|
|
822
|
+
numbers: Array.isArray(data.numbers) ? data.numbers.filter(isRecord).filter((n) => typeof n.phone === "string").map((n) => {
|
|
823
|
+
var _a;
|
|
824
|
+
return {
|
|
825
|
+
phone: n.phone,
|
|
826
|
+
label: stringOrNull(n.label),
|
|
827
|
+
isDefault: n.isDefault === true,
|
|
828
|
+
order: (_a = numberOrNull(n.order)) != null ? _a : 0
|
|
829
|
+
};
|
|
830
|
+
}) : []
|
|
831
|
+
};
|
|
832
|
+
} catch (e) {
|
|
833
|
+
return { ok: false, error: "Could not reach Glitchgrab" };
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
function ringNumbersPath(rest = "") {
|
|
837
|
+
return `/api/v1/sdk/phone-lines/operator/numbers${rest}`;
|
|
838
|
+
}
|
|
839
|
+
async function ringNumberWrite(path, method, body, options, pick) {
|
|
840
|
+
try {
|
|
841
|
+
const key = callsKey(options);
|
|
842
|
+
if (!key) return { ok: false, error: NO_KEY_ERROR };
|
|
843
|
+
const { data, error, code } = await callSdkApi(path, key, options, { method, body, cache: "no-store" });
|
|
844
|
+
if (error !== null || !isRecord(data)) return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
|
|
845
|
+
return { ok: true, ...pick(data) };
|
|
846
|
+
} catch (e) {
|
|
847
|
+
return { ok: false, error: "Could not reach Glitchgrab" };
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
async function listRingNumbers(operator, options = {}) {
|
|
851
|
+
try {
|
|
852
|
+
const key = callsKey(options);
|
|
853
|
+
if (!key) return { ok: false, error: NO_KEY_ERROR };
|
|
854
|
+
const query = new URLSearchParams("email" in operator ? { email: operator.email } : { phone: operator.phone });
|
|
855
|
+
const { data, error, code } = await callSdkApi(ringNumbersPath(`?${query.toString()}`), key, options, {
|
|
856
|
+
cache: "no-store"
|
|
857
|
+
});
|
|
858
|
+
if (error !== null || !isRecord(data)) return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
|
|
859
|
+
const op = isRecord(data.operator) ? data.operator : {};
|
|
860
|
+
return {
|
|
861
|
+
ok: true,
|
|
862
|
+
operator: { name: stringOrNull(op.name) },
|
|
863
|
+
accountPhone: stringOrNull(data.accountPhone),
|
|
864
|
+
usingAccount: data.usingAccount === true,
|
|
865
|
+
numbers: Array.isArray(data.numbers) ? data.numbers.filter(isRecord).filter((n) => typeof n.id === "string" && typeof n.phone === "string").map((n) => {
|
|
866
|
+
var _a;
|
|
867
|
+
return {
|
|
868
|
+
id: n.id,
|
|
869
|
+
phone: n.phone,
|
|
870
|
+
label: stringOrNull(n.label),
|
|
871
|
+
position: (_a = numberOrNull(n.position)) != null ? _a : 0,
|
|
872
|
+
verified: n.verified === true,
|
|
873
|
+
verifying: n.verifying === true,
|
|
874
|
+
isDefault: n.isDefault === true
|
|
875
|
+
};
|
|
876
|
+
}) : []
|
|
877
|
+
};
|
|
878
|
+
} catch (e) {
|
|
879
|
+
return { ok: false, error: "Could not reach Glitchgrab" };
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
function addRingNumber(operator, number, options = {}) {
|
|
883
|
+
return ringNumberWrite(ringNumbersPath(), "POST", { operator, ...number }, options, (d) => ({
|
|
884
|
+
id: typeof d.id === "string" ? d.id : "",
|
|
885
|
+
testRing: d.testRing === "failed" ? "failed" : "ringing",
|
|
886
|
+
verifyError: stringOrNull(d.verifyError)
|
|
887
|
+
}));
|
|
888
|
+
}
|
|
889
|
+
function updateRingNumber(id, change, options = {}) {
|
|
890
|
+
return ringNumberWrite(ringNumbersPath(`/${encodeURIComponent(id)}`), "PATCH", change, options, () => ({}));
|
|
891
|
+
}
|
|
892
|
+
function removeRingNumber(id, options = {}) {
|
|
893
|
+
return ringNumberWrite(ringNumbersPath(`/${encodeURIComponent(id)}`), "DELETE", void 0, options, () => ({}));
|
|
894
|
+
}
|
|
895
|
+
function testRingNumber(id, options = {}) {
|
|
896
|
+
return ringNumberWrite(ringNumbersPath(`/${encodeURIComponent(id)}/verify`), "POST", void 0, options, (d) => ({
|
|
897
|
+
verified: d.verified === true
|
|
898
|
+
}));
|
|
899
|
+
}
|
|
678
900
|
export {
|
|
901
|
+
addFollowUpNote,
|
|
902
|
+
addRingNumber,
|
|
679
903
|
cancelBooking,
|
|
680
904
|
captureServerErrors,
|
|
681
905
|
configureServerReporter,
|
|
682
906
|
deleteCall,
|
|
907
|
+
dialFollowUp,
|
|
683
908
|
discardBookingQuestionsDraft,
|
|
684
909
|
escapeJsonForScript,
|
|
685
910
|
getBookingSettings,
|
|
686
911
|
getCall,
|
|
912
|
+
getFollowUp,
|
|
687
913
|
getGuide,
|
|
914
|
+
getOperatorRingNumbers,
|
|
688
915
|
listBookings,
|
|
689
916
|
listCalls,
|
|
917
|
+
listFollowUps,
|
|
690
918
|
listGuides,
|
|
691
919
|
listLeads,
|
|
920
|
+
listRingNumbers,
|
|
692
921
|
publishBookingQuestions,
|
|
922
|
+
removeRingNumber,
|
|
693
923
|
reportServerError,
|
|
694
924
|
rescheduleBooking,
|
|
695
925
|
resetServerReporter,
|
|
926
|
+
setFollowUpBooking,
|
|
696
927
|
signSession,
|
|
697
|
-
|
|
928
|
+
testRingNumber,
|
|
929
|
+
updateBookingSettings,
|
|
930
|
+
updateRingNumber
|
|
698
931
|
};
|
|
699
932
|
//# sourceMappingURL=server.mjs.map
|