glitchgrab 1.61.2 → 1.62.0

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.mjs CHANGED
@@ -675,24 +675,151 @@ async function listLeads(options = {}) {
675
675
  return [];
676
676
  }
677
677
  }
678
+ var DUES = /* @__PURE__ */ new Set(["none", "upcoming", "today", "overdue"]);
679
+ function readFollowUp(value) {
680
+ var _a, _b;
681
+ if (!isRecord(value)) return null;
682
+ const call = isRecord(value.lastCall) && typeof value.lastCall.id === "string" ? value.lastCall : null;
683
+ return {
684
+ id: stringOrNull(value.id),
685
+ externalId: stringOrNull(value.externalId),
686
+ phone: stringOrNull(value.phone),
687
+ name: stringOrNull(value.name),
688
+ nextCallAt: stringOrNull(value.nextCallAt),
689
+ nextCallBookedBy: stringOrNull(value.nextCallBookedBy),
690
+ due: typeof value.due === "string" && DUES.has(value.due) ? value.due : "none",
691
+ suggestedNextCallAt: stringOrNull(value.suggestedNextCallAt),
692
+ suggestedNextCallReason: stringOrNull(value.suggestedNextCallReason),
693
+ lastNote: stringOrNull(value.lastNote),
694
+ lastNoteAt: stringOrNull(value.lastNoteAt),
695
+ lastNoteBy: stringOrNull(value.lastNoteBy),
696
+ noteCount: (_a = numberOrNull(value.noteCount)) != null ? _a : 0,
697
+ lastCall: call ? {
698
+ id: call.id,
699
+ status: stringOrNull(call.status),
700
+ at: (_b = stringOrNull(call.at)) != null ? _b : "",
701
+ durationSec: numberOrNull(call.durationSec)
702
+ } : null
703
+ };
704
+ }
705
+ function readFollowUpDetail(value) {
706
+ var _a;
707
+ const base = readFollowUp(value);
708
+ if (!base || !isRecord(value)) return null;
709
+ return {
710
+ ...base,
711
+ linksExpireInSeconds: (_a = numberOrNull(value.linksExpireInSeconds)) != null ? _a : 0,
712
+ notes: Array.isArray(value.notes) ? value.notes.filter(isRecord).filter((n) => typeof n.id === "string" && typeof n.body === "string").map((n) => {
713
+ var _a2, _b;
714
+ return {
715
+ id: n.id,
716
+ body: n.body,
717
+ source: (_a2 = stringOrNull(n.source)) != null ? _a2 : "manual",
718
+ author: stringOrNull(n.author),
719
+ callId: stringOrNull(n.callId),
720
+ editedAt: stringOrNull(n.editedAt),
721
+ createdAt: (_b = stringOrNull(n.createdAt)) != null ? _b : ""
722
+ };
723
+ }) : [],
724
+ calls: Array.isArray(value.calls) ? value.calls.filter(isRecord).filter((c) => typeof c.id === "string").map((c) => {
725
+ var _a2;
726
+ return {
727
+ id: c.id,
728
+ status: stringOrNull(c.status),
729
+ direction: stringOrNull(c.direction),
730
+ at: (_a2 = stringOrNull(c.at)) != null ? _a2 : "",
731
+ durationSec: numberOrNull(c.durationSec),
732
+ shared: c.shared === true,
733
+ overview: stringOrNull(c.overview),
734
+ recordingUrl: stringOrNull(c.recordingUrl)
735
+ };
736
+ }) : []
737
+ };
738
+ }
739
+ function followUpPath(externalId, rest = "") {
740
+ const id = typeof externalId === "string" ? externalId.trim() : "";
741
+ return id ? `/api/v1/sdk/follow-ups/${encodeURIComponent(id)}${rest}` : null;
742
+ }
743
+ async function writeFollowUp(path, method, body, options, pick) {
744
+ try {
745
+ if (!path) return { ok: false, error: "No externalId" };
746
+ const key = callsKey(options);
747
+ if (!key) return { ok: false, error: NO_KEY_ERROR };
748
+ const { data, error } = await callSdkApi(path, key, options, { method, body, cache: "no-store" });
749
+ if (error !== null || !isRecord(data) || typeof data.followUpId !== "string") {
750
+ return { ok: false, error: error != null ? error : "Unexpected response" };
751
+ }
752
+ return { ok: true, followUpId: data.followUpId, ...pick(data) };
753
+ } catch (e) {
754
+ return { ok: false, error: "Could not reach Glitchgrab" };
755
+ }
756
+ }
757
+ async function listFollowUps(externalIds, options = {}) {
758
+ try {
759
+ const key = callsKey(options);
760
+ const ids = Array.isArray(externalIds) ? externalIds.filter((id) => typeof id === "string" && id.trim()) : [];
761
+ if (!key || ids.length === 0) return [];
762
+ const query = new URLSearchParams({ externalIds: ids.join(",") });
763
+ const { data } = await callSdkApi(`/api/v1/sdk/follow-ups?${query.toString()}`, key, options, {
764
+ cache: "no-store"
765
+ });
766
+ if (!Array.isArray(data)) return [];
767
+ return data.map(readFollowUp).filter((f) => f !== null);
768
+ } catch (e) {
769
+ return [];
770
+ }
771
+ }
772
+ async function getFollowUp(externalId, options = {}) {
773
+ try {
774
+ const path = followUpPath(externalId);
775
+ const key = callsKey(options);
776
+ if (!path || !key) return null;
777
+ const { data } = await callSdkApi(path, key, options, { cache: "no-store" });
778
+ return readFollowUpDetail(data);
779
+ } catch (e) {
780
+ return null;
781
+ }
782
+ }
783
+ function addFollowUpNote(externalId, note, options = {}) {
784
+ return writeFollowUp(followUpPath(externalId, "/notes"), "POST", note, options, (d) => ({
785
+ id: typeof d.id === "string" ? d.id : ""
786
+ }));
787
+ }
788
+ function setFollowUpBooking(externalId, booking, options = {}) {
789
+ const at = booking.nextCallAt instanceof Date ? booking.nextCallAt.toISOString() : booking.nextCallAt;
790
+ return writeFollowUp(followUpPath(externalId, "/booking"), "PUT", { ...booking, nextCallAt: at }, options, (d) => ({
791
+ nextCallAt: stringOrNull(d.nextCallAt)
792
+ }));
793
+ }
794
+ function dialFollowUp(externalId, call, options = {}) {
795
+ return writeFollowUp(followUpPath(externalId, "/dial"), "POST", call, options, (d) => ({
796
+ callId: typeof d.callId === "string" ? d.callId : "",
797
+ ringing: typeof d.ringing === "string" ? d.ringing : ""
798
+ }));
799
+ }
678
800
  export {
801
+ addFollowUpNote,
679
802
  cancelBooking,
680
803
  captureServerErrors,
681
804
  configureServerReporter,
682
805
  deleteCall,
806
+ dialFollowUp,
683
807
  discardBookingQuestionsDraft,
684
808
  escapeJsonForScript,
685
809
  getBookingSettings,
686
810
  getCall,
811
+ getFollowUp,
687
812
  getGuide,
688
813
  listBookings,
689
814
  listCalls,
815
+ listFollowUps,
690
816
  listGuides,
691
817
  listLeads,
692
818
  publishBookingQuestions,
693
819
  reportServerError,
694
820
  rescheduleBooking,
695
821
  resetServerReporter,
822
+ setFollowUpBooking,
696
823
  signSession,
697
824
  updateBookingSettings
698
825
  };