glitchgrab 1.62.0 → 1.62.2

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
@@ -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 { data: null, error: typeof (body == null ? void 0 : body.error) === "string" ? body.error : `HTTP ${response.status}` };
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) {
@@ -698,7 +702,9 @@ function readFollowUp(value) {
698
702
  id: call.id,
699
703
  status: stringOrNull(call.status),
700
704
  at: (_b = stringOrNull(call.at)) != null ? _b : "",
701
- durationSec: numberOrNull(call.durationSec)
705
+ durationSec: numberOrNull(call.durationSec),
706
+ ringingIndex: numberOrNull(call.ringingIndex),
707
+ ringingPhone: stringOrNull(call.ringingPhone)
702
708
  } : null
703
709
  };
704
710
  }
@@ -729,6 +735,8 @@ function readFollowUpDetail(value) {
729
735
  direction: stringOrNull(c.direction),
730
736
  at: (_a2 = stringOrNull(c.at)) != null ? _a2 : "",
731
737
  durationSec: numberOrNull(c.durationSec),
738
+ ringingIndex: numberOrNull(c.ringingIndex),
739
+ ringingPhone: stringOrNull(c.ringingPhone),
732
740
  shared: c.shared === true,
733
741
  overview: stringOrNull(c.overview),
734
742
  recordingUrl: stringOrNull(c.recordingUrl)
@@ -745,9 +753,9 @@ async function writeFollowUp(path, method, body, options, pick) {
745
753
  if (!path) return { ok: false, error: "No externalId" };
746
754
  const key = callsKey(options);
747
755
  if (!key) return { ok: false, error: NO_KEY_ERROR };
748
- const { data, error } = await callSdkApi(path, key, options, { method, body, cache: "no-store" });
756
+ const { data, error, code } = await callSdkApi(path, key, options, { method, body, cache: "no-store" });
749
757
  if (error !== null || !isRecord(data) || typeof data.followUpId !== "string") {
750
- return { ok: false, error: error != null ? error : "Unexpected response" };
758
+ return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
751
759
  }
752
760
  return { ok: true, followUpId: data.followUpId, ...pick(data) };
753
761
  } catch (e) {
@@ -794,11 +802,131 @@ function setFollowUpBooking(externalId, booking, options = {}) {
794
802
  function dialFollowUp(externalId, call, options = {}) {
795
803
  return writeFollowUp(followUpPath(externalId, "/dial"), "POST", call, options, (d) => ({
796
804
  callId: typeof d.callId === "string" ? d.callId : "",
797
- ringing: typeof d.ringing === "string" ? d.ringing : ""
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
+ return { ok: true, ...operatorNumbersOf(data) };
819
+ } catch (e) {
820
+ return { ok: false, error: "Could not reach Glitchgrab" };
821
+ }
822
+ }
823
+ function operatorNumbersOf(data) {
824
+ const op = isRecord(data.operator) ? data.operator : {};
825
+ return {
826
+ operator: { name: stringOrNull(op.name) },
827
+ numbers: Array.isArray(data.numbers) ? data.numbers.filter(isRecord).filter((n) => typeof n.phone === "string").map((n) => {
828
+ var _a;
829
+ return {
830
+ phone: n.phone,
831
+ label: stringOrNull(n.label),
832
+ isDefault: n.isDefault === true,
833
+ order: (_a = numberOrNull(n.order)) != null ? _a : 0
834
+ };
835
+ }) : []
836
+ };
837
+ }
838
+ async function addLineCaller(caller, options = {}) {
839
+ try {
840
+ const key = callsKey(options);
841
+ if (!key) return { ok: false, error: NO_KEY_ERROR };
842
+ const { data, error, code } = await callSdkApi("/api/v1/sdk/phone-lines/callers", key, options, {
843
+ method: "POST",
844
+ body: caller,
845
+ cache: "no-store"
846
+ });
847
+ if (error !== null || !isRecord(data)) return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
848
+ return { ok: true, created: data.created === true, ...operatorNumbersOf(data) };
849
+ } catch (e) {
850
+ return { ok: false, error: "Could not reach Glitchgrab" };
851
+ }
852
+ }
853
+ function removeLineCaller(email, options = {}) {
854
+ return ringNumberWrite(
855
+ `/api/v1/sdk/phone-lines/callers/${encodeURIComponent(email)}`,
856
+ "DELETE",
857
+ void 0,
858
+ options,
859
+ () => ({})
860
+ );
861
+ }
862
+ function ringNumbersPath(rest = "") {
863
+ return `/api/v1/sdk/phone-lines/operator/numbers${rest}`;
864
+ }
865
+ async function ringNumberWrite(path, method, body, options, pick) {
866
+ try {
867
+ const key = callsKey(options);
868
+ if (!key) return { ok: false, error: NO_KEY_ERROR };
869
+ const { data, error, code } = await callSdkApi(path, key, options, { method, body, cache: "no-store" });
870
+ if (error !== null || !isRecord(data)) return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
871
+ return { ok: true, ...pick(data) };
872
+ } catch (e) {
873
+ return { ok: false, error: "Could not reach Glitchgrab" };
874
+ }
875
+ }
876
+ async function listRingNumbers(operator, options = {}) {
877
+ try {
878
+ const key = callsKey(options);
879
+ if (!key) return { ok: false, error: NO_KEY_ERROR };
880
+ const query = new URLSearchParams("email" in operator ? { email: operator.email } : { phone: operator.phone });
881
+ const { data, error, code } = await callSdkApi(ringNumbersPath(`?${query.toString()}`), key, options, {
882
+ cache: "no-store"
883
+ });
884
+ if (error !== null || !isRecord(data)) return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
885
+ const op = isRecord(data.operator) ? data.operator : {};
886
+ return {
887
+ ok: true,
888
+ operator: { name: stringOrNull(op.name) },
889
+ accountPhone: stringOrNull(data.accountPhone),
890
+ usingAccount: data.usingAccount === true,
891
+ numbers: Array.isArray(data.numbers) ? data.numbers.filter(isRecord).filter((n) => typeof n.id === "string" && typeof n.phone === "string").map((n) => {
892
+ var _a;
893
+ return {
894
+ id: n.id,
895
+ phone: n.phone,
896
+ label: stringOrNull(n.label),
897
+ position: (_a = numberOrNull(n.position)) != null ? _a : 0,
898
+ verified: n.verified === true,
899
+ verifying: n.verifying === true,
900
+ isDefault: n.isDefault === true
901
+ };
902
+ }) : []
903
+ };
904
+ } catch (e) {
905
+ return { ok: false, error: "Could not reach Glitchgrab" };
906
+ }
907
+ }
908
+ function addRingNumber(operator, number, options = {}) {
909
+ return ringNumberWrite(ringNumbersPath(), "POST", { operator, ...number }, options, (d) => ({
910
+ id: typeof d.id === "string" ? d.id : "",
911
+ testRing: d.testRing === "failed" ? "failed" : "ringing",
912
+ verifyError: stringOrNull(d.verifyError)
913
+ }));
914
+ }
915
+ function updateRingNumber(id, change, options = {}) {
916
+ return ringNumberWrite(ringNumbersPath(`/${encodeURIComponent(id)}`), "PATCH", change, options, () => ({}));
917
+ }
918
+ function removeRingNumber(id, options = {}) {
919
+ return ringNumberWrite(ringNumbersPath(`/${encodeURIComponent(id)}`), "DELETE", void 0, options, () => ({}));
920
+ }
921
+ function testRingNumber(id, options = {}) {
922
+ return ringNumberWrite(ringNumbersPath(`/${encodeURIComponent(id)}/verify`), "POST", void 0, options, (d) => ({
923
+ verified: d.verified === true
798
924
  }));
799
925
  }
800
926
  export {
801
927
  addFollowUpNote,
928
+ addLineCaller,
929
+ addRingNumber,
802
930
  cancelBooking,
803
931
  captureServerErrors,
804
932
  configureServerReporter,
@@ -810,17 +938,23 @@ export {
810
938
  getCall,
811
939
  getFollowUp,
812
940
  getGuide,
941
+ getOperatorRingNumbers,
813
942
  listBookings,
814
943
  listCalls,
815
944
  listFollowUps,
816
945
  listGuides,
817
946
  listLeads,
947
+ listRingNumbers,
818
948
  publishBookingQuestions,
949
+ removeLineCaller,
950
+ removeRingNumber,
819
951
  reportServerError,
820
952
  rescheduleBooking,
821
953
  resetServerReporter,
822
954
  setFollowUpBooking,
823
955
  signSession,
824
- updateBookingSettings
956
+ testRingNumber,
957
+ updateBookingSettings,
958
+ updateRingNumber
825
959
  };
826
960
  //# sourceMappingURL=server.mjs.map