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/dist/server.js CHANGED
@@ -20,25 +20,36 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/server.ts
21
21
  var server_exports = {};
22
22
  __export(server_exports, {
23
+ addFollowUpNote: () => addFollowUpNote,
24
+ addRingNumber: () => addRingNumber,
23
25
  cancelBooking: () => cancelBooking,
24
26
  captureServerErrors: () => captureServerErrors,
25
27
  configureServerReporter: () => configureServerReporter,
26
28
  deleteCall: () => deleteCall,
29
+ dialFollowUp: () => dialFollowUp,
27
30
  discardBookingQuestionsDraft: () => discardBookingQuestionsDraft,
28
31
  escapeJsonForScript: () => escapeJsonForScript,
29
32
  getBookingSettings: () => getBookingSettings,
30
33
  getCall: () => getCall,
34
+ getFollowUp: () => getFollowUp,
31
35
  getGuide: () => getGuide,
36
+ getOperatorRingNumbers: () => getOperatorRingNumbers,
32
37
  listBookings: () => listBookings,
33
38
  listCalls: () => listCalls,
39
+ listFollowUps: () => listFollowUps,
34
40
  listGuides: () => listGuides,
35
41
  listLeads: () => listLeads,
42
+ listRingNumbers: () => listRingNumbers,
36
43
  publishBookingQuestions: () => publishBookingQuestions,
44
+ removeRingNumber: () => removeRingNumber,
37
45
  reportServerError: () => reportServerError,
38
46
  rescheduleBooking: () => rescheduleBooking,
39
47
  resetServerReporter: () => resetServerReporter,
48
+ setFollowUpBooking: () => setFollowUpBooking,
40
49
  signSession: () => signSession,
41
- updateBookingSettings: () => updateBookingSettings
50
+ testRingNumber: () => testRingNumber,
51
+ updateBookingSettings: () => updateBookingSettings,
52
+ updateRingNumber: () => updateRingNumber
42
53
  });
43
54
  module.exports = __toCommonJS(server_exports);
44
55
  var import_node_crypto = require("crypto");
@@ -311,7 +322,11 @@ async function callSdkApi(path, token, options, init) {
311
322
  const response = await fetch(`${baseUrl}${path}`, request);
312
323
  const body = await response.json().catch(() => null);
313
324
  if (!response.ok || (body == null ? void 0 : body.success) !== true) {
314
- return { data: null, error: typeof (body == null ? void 0 : body.error) === "string" ? body.error : `HTTP ${response.status}` };
325
+ return {
326
+ data: null,
327
+ error: typeof (body == null ? void 0 : body.error) === "string" ? body.error : `HTTP ${response.status}`,
328
+ ...typeof (body == null ? void 0 : body.code) === "string" ? { code: body.code } : {}
329
+ };
315
330
  }
316
331
  return { data: (_f = body.data) != null ? _f : null, error: null };
317
332
  } catch (e) {
@@ -717,26 +732,255 @@ async function listLeads(options = {}) {
717
732
  return [];
718
733
  }
719
734
  }
735
+ var DUES = /* @__PURE__ */ new Set(["none", "upcoming", "today", "overdue"]);
736
+ function readFollowUp(value) {
737
+ var _a, _b;
738
+ if (!isRecord(value)) return null;
739
+ const call = isRecord(value.lastCall) && typeof value.lastCall.id === "string" ? value.lastCall : null;
740
+ return {
741
+ id: stringOrNull(value.id),
742
+ externalId: stringOrNull(value.externalId),
743
+ phone: stringOrNull(value.phone),
744
+ name: stringOrNull(value.name),
745
+ nextCallAt: stringOrNull(value.nextCallAt),
746
+ nextCallBookedBy: stringOrNull(value.nextCallBookedBy),
747
+ due: typeof value.due === "string" && DUES.has(value.due) ? value.due : "none",
748
+ suggestedNextCallAt: stringOrNull(value.suggestedNextCallAt),
749
+ suggestedNextCallReason: stringOrNull(value.suggestedNextCallReason),
750
+ lastNote: stringOrNull(value.lastNote),
751
+ lastNoteAt: stringOrNull(value.lastNoteAt),
752
+ lastNoteBy: stringOrNull(value.lastNoteBy),
753
+ noteCount: (_a = numberOrNull(value.noteCount)) != null ? _a : 0,
754
+ lastCall: call ? {
755
+ id: call.id,
756
+ status: stringOrNull(call.status),
757
+ at: (_b = stringOrNull(call.at)) != null ? _b : "",
758
+ durationSec: numberOrNull(call.durationSec),
759
+ ringingIndex: numberOrNull(call.ringingIndex),
760
+ ringingPhone: stringOrNull(call.ringingPhone)
761
+ } : null
762
+ };
763
+ }
764
+ function readFollowUpDetail(value) {
765
+ var _a;
766
+ const base = readFollowUp(value);
767
+ if (!base || !isRecord(value)) return null;
768
+ return {
769
+ ...base,
770
+ linksExpireInSeconds: (_a = numberOrNull(value.linksExpireInSeconds)) != null ? _a : 0,
771
+ notes: Array.isArray(value.notes) ? value.notes.filter(isRecord).filter((n) => typeof n.id === "string" && typeof n.body === "string").map((n) => {
772
+ var _a2, _b;
773
+ return {
774
+ id: n.id,
775
+ body: n.body,
776
+ source: (_a2 = stringOrNull(n.source)) != null ? _a2 : "manual",
777
+ author: stringOrNull(n.author),
778
+ callId: stringOrNull(n.callId),
779
+ editedAt: stringOrNull(n.editedAt),
780
+ createdAt: (_b = stringOrNull(n.createdAt)) != null ? _b : ""
781
+ };
782
+ }) : [],
783
+ calls: Array.isArray(value.calls) ? value.calls.filter(isRecord).filter((c) => typeof c.id === "string").map((c) => {
784
+ var _a2;
785
+ return {
786
+ id: c.id,
787
+ status: stringOrNull(c.status),
788
+ direction: stringOrNull(c.direction),
789
+ at: (_a2 = stringOrNull(c.at)) != null ? _a2 : "",
790
+ durationSec: numberOrNull(c.durationSec),
791
+ ringingIndex: numberOrNull(c.ringingIndex),
792
+ ringingPhone: stringOrNull(c.ringingPhone),
793
+ shared: c.shared === true,
794
+ overview: stringOrNull(c.overview),
795
+ recordingUrl: stringOrNull(c.recordingUrl)
796
+ };
797
+ }) : []
798
+ };
799
+ }
800
+ function followUpPath(externalId, rest = "") {
801
+ const id = typeof externalId === "string" ? externalId.trim() : "";
802
+ return id ? `/api/v1/sdk/follow-ups/${encodeURIComponent(id)}${rest}` : null;
803
+ }
804
+ async function writeFollowUp(path, method, body, options, pick) {
805
+ try {
806
+ if (!path) return { ok: false, error: "No externalId" };
807
+ const key = callsKey(options);
808
+ if (!key) return { ok: false, error: NO_KEY_ERROR };
809
+ const { data, error, code } = await callSdkApi(path, key, options, { method, body, cache: "no-store" });
810
+ if (error !== null || !isRecord(data) || typeof data.followUpId !== "string") {
811
+ return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
812
+ }
813
+ return { ok: true, followUpId: data.followUpId, ...pick(data) };
814
+ } catch (e) {
815
+ return { ok: false, error: "Could not reach Glitchgrab" };
816
+ }
817
+ }
818
+ async function listFollowUps(externalIds, options = {}) {
819
+ try {
820
+ const key = callsKey(options);
821
+ const ids = Array.isArray(externalIds) ? externalIds.filter((id) => typeof id === "string" && id.trim()) : [];
822
+ if (!key || ids.length === 0) return [];
823
+ const query = new URLSearchParams({ externalIds: ids.join(",") });
824
+ const { data } = await callSdkApi(`/api/v1/sdk/follow-ups?${query.toString()}`, key, options, {
825
+ cache: "no-store"
826
+ });
827
+ if (!Array.isArray(data)) return [];
828
+ return data.map(readFollowUp).filter((f) => f !== null);
829
+ } catch (e) {
830
+ return [];
831
+ }
832
+ }
833
+ async function getFollowUp(externalId, options = {}) {
834
+ try {
835
+ const path = followUpPath(externalId);
836
+ const key = callsKey(options);
837
+ if (!path || !key) return null;
838
+ const { data } = await callSdkApi(path, key, options, { cache: "no-store" });
839
+ return readFollowUpDetail(data);
840
+ } catch (e) {
841
+ return null;
842
+ }
843
+ }
844
+ function addFollowUpNote(externalId, note, options = {}) {
845
+ return writeFollowUp(followUpPath(externalId, "/notes"), "POST", note, options, (d) => ({
846
+ id: typeof d.id === "string" ? d.id : ""
847
+ }));
848
+ }
849
+ function setFollowUpBooking(externalId, booking, options = {}) {
850
+ const at = booking.nextCallAt instanceof Date ? booking.nextCallAt.toISOString() : booking.nextCallAt;
851
+ return writeFollowUp(followUpPath(externalId, "/booking"), "PUT", { ...booking, nextCallAt: at }, options, (d) => ({
852
+ nextCallAt: stringOrNull(d.nextCallAt)
853
+ }));
854
+ }
855
+ function dialFollowUp(externalId, call, options = {}) {
856
+ return writeFollowUp(followUpPath(externalId, "/dial"), "POST", call, options, (d) => ({
857
+ callId: typeof d.callId === "string" ? d.callId : "",
858
+ ringing: typeof d.ringing === "string" ? d.ringing : "",
859
+ ringNumbers: Array.isArray(d.ringNumbers) ? d.ringNumbers.filter((n) => typeof n === "string") : []
860
+ }));
861
+ }
862
+ async function getOperatorRingNumbers(operator, options = {}) {
863
+ try {
864
+ const key = callsKey(options);
865
+ if (!key) return { ok: false, error: NO_KEY_ERROR };
866
+ const query = new URLSearchParams("email" in operator ? { email: operator.email } : { phone: operator.phone });
867
+ const { data, error, code } = await callSdkApi(`/api/v1/sdk/phone-lines/operator?${query.toString()}`, key, options, {
868
+ cache: "no-store"
869
+ });
870
+ if (error !== null || !isRecord(data)) return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
871
+ const op = isRecord(data.operator) ? data.operator : {};
872
+ return {
873
+ ok: true,
874
+ operator: { name: stringOrNull(op.name) },
875
+ numbers: Array.isArray(data.numbers) ? data.numbers.filter(isRecord).filter((n) => typeof n.phone === "string").map((n) => {
876
+ var _a;
877
+ return {
878
+ phone: n.phone,
879
+ label: stringOrNull(n.label),
880
+ isDefault: n.isDefault === true,
881
+ order: (_a = numberOrNull(n.order)) != null ? _a : 0
882
+ };
883
+ }) : []
884
+ };
885
+ } catch (e) {
886
+ return { ok: false, error: "Could not reach Glitchgrab" };
887
+ }
888
+ }
889
+ function ringNumbersPath(rest = "") {
890
+ return `/api/v1/sdk/phone-lines/operator/numbers${rest}`;
891
+ }
892
+ async function ringNumberWrite(path, method, body, options, pick) {
893
+ try {
894
+ const key = callsKey(options);
895
+ if (!key) return { ok: false, error: NO_KEY_ERROR };
896
+ const { data, error, code } = await callSdkApi(path, key, options, { method, body, cache: "no-store" });
897
+ if (error !== null || !isRecord(data)) return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
898
+ return { ok: true, ...pick(data) };
899
+ } catch (e) {
900
+ return { ok: false, error: "Could not reach Glitchgrab" };
901
+ }
902
+ }
903
+ async function listRingNumbers(operator, options = {}) {
904
+ try {
905
+ const key = callsKey(options);
906
+ if (!key) return { ok: false, error: NO_KEY_ERROR };
907
+ const query = new URLSearchParams("email" in operator ? { email: operator.email } : { phone: operator.phone });
908
+ const { data, error, code } = await callSdkApi(ringNumbersPath(`?${query.toString()}`), key, options, {
909
+ cache: "no-store"
910
+ });
911
+ if (error !== null || !isRecord(data)) return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
912
+ const op = isRecord(data.operator) ? data.operator : {};
913
+ return {
914
+ ok: true,
915
+ operator: { name: stringOrNull(op.name) },
916
+ accountPhone: stringOrNull(data.accountPhone),
917
+ usingAccount: data.usingAccount === true,
918
+ numbers: Array.isArray(data.numbers) ? data.numbers.filter(isRecord).filter((n) => typeof n.id === "string" && typeof n.phone === "string").map((n) => {
919
+ var _a;
920
+ return {
921
+ id: n.id,
922
+ phone: n.phone,
923
+ label: stringOrNull(n.label),
924
+ position: (_a = numberOrNull(n.position)) != null ? _a : 0,
925
+ verified: n.verified === true,
926
+ verifying: n.verifying === true,
927
+ isDefault: n.isDefault === true
928
+ };
929
+ }) : []
930
+ };
931
+ } catch (e) {
932
+ return { ok: false, error: "Could not reach Glitchgrab" };
933
+ }
934
+ }
935
+ function addRingNumber(operator, number, options = {}) {
936
+ return ringNumberWrite(ringNumbersPath(), "POST", { operator, ...number }, options, (d) => ({
937
+ id: typeof d.id === "string" ? d.id : "",
938
+ testRing: d.testRing === "failed" ? "failed" : "ringing",
939
+ verifyError: stringOrNull(d.verifyError)
940
+ }));
941
+ }
942
+ function updateRingNumber(id, change, options = {}) {
943
+ return ringNumberWrite(ringNumbersPath(`/${encodeURIComponent(id)}`), "PATCH", change, options, () => ({}));
944
+ }
945
+ function removeRingNumber(id, options = {}) {
946
+ return ringNumberWrite(ringNumbersPath(`/${encodeURIComponent(id)}`), "DELETE", void 0, options, () => ({}));
947
+ }
948
+ function testRingNumber(id, options = {}) {
949
+ return ringNumberWrite(ringNumbersPath(`/${encodeURIComponent(id)}/verify`), "POST", void 0, options, (d) => ({
950
+ verified: d.verified === true
951
+ }));
952
+ }
720
953
  // Annotate the CommonJS export names for ESM import in node:
721
954
  0 && (module.exports = {
955
+ addFollowUpNote,
956
+ addRingNumber,
722
957
  cancelBooking,
723
958
  captureServerErrors,
724
959
  configureServerReporter,
725
960
  deleteCall,
961
+ dialFollowUp,
726
962
  discardBookingQuestionsDraft,
727
963
  escapeJsonForScript,
728
964
  getBookingSettings,
729
965
  getCall,
966
+ getFollowUp,
730
967
  getGuide,
968
+ getOperatorRingNumbers,
731
969
  listBookings,
732
970
  listCalls,
971
+ listFollowUps,
733
972
  listGuides,
734
973
  listLeads,
974
+ listRingNumbers,
735
975
  publishBookingQuestions,
976
+ removeRingNumber,
736
977
  reportServerError,
737
978
  rescheduleBooking,
738
979
  resetServerReporter,
980
+ setFollowUpBooking,
739
981
  signSession,
740
- updateBookingSettings
982
+ testRingNumber,
983
+ updateBookingSettings,
984
+ updateRingNumber
741
985
  });
742
986
  //# sourceMappingURL=server.js.map