glitchgrab 1.63.0 → 1.64.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
@@ -256,13 +256,14 @@ async function callSdkApi(path, token, options, init) {
256
256
  const controller = typeof AbortController === "function" ? new AbortController() : void 0;
257
257
  const timer = controller ? setTimeout(() => controller.abort(), (_d = options.timeoutMs) != null ? _d : SDK_API_TIMEOUT_MS) : void 0;
258
258
  try {
259
+ const multipart = typeof FormData !== "undefined" && init.body instanceof FormData;
259
260
  const request = {
260
261
  method: (_e = init.method) != null ? _e : "GET",
261
262
  headers: {
262
263
  Authorization: `Bearer ${token}`,
263
- ...init.body === void 0 ? {} : { "Content-Type": "application/json" }
264
+ ...init.body === void 0 || multipart ? {} : { "Content-Type": "application/json" }
264
265
  },
265
- ...init.body === void 0 ? {} : { body: JSON.stringify(init.body) },
266
+ ...init.body === void 0 ? {} : { body: multipart ? init.body : JSON.stringify(init.body) },
266
267
  ...init.cache === "no-store" ? { cache: "no-store" } : { next: { revalidate: init.cache.revalidate } },
267
268
  ...controller ? { signal: controller.signal } : {}
268
269
  };
@@ -875,6 +876,140 @@ async function addLineCaller(caller, options = {}) {
875
876
  return { ok: false, error: "Could not reach Glitchgrab" };
876
877
  }
877
878
  }
879
+ async function placeCall(call, options = {}) {
880
+ try {
881
+ const key = callsKey(options);
882
+ if (!key) return { ok: false, error: NO_KEY_ERROR };
883
+ const { data, error, code } = await callSdkApi("/api/v1/sdk/phone-lines/call", key, options, {
884
+ method: "POST",
885
+ body: call,
886
+ cache: "no-store"
887
+ });
888
+ if (error !== null || !isRecord(data) || typeof data.callId !== "string") {
889
+ return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
890
+ }
891
+ return {
892
+ ok: true,
893
+ callId: data.callId,
894
+ ringing: typeof data.ringing === "string" ? data.ringing : "",
895
+ ringNumbers: Array.isArray(data.ringNumbers) ? data.ringNumbers.filter((n) => typeof n === "string") : [],
896
+ from: typeof data.from === "string" ? data.from : ""
897
+ };
898
+ } catch (e) {
899
+ return { ok: false, error: "Could not reach Glitchgrab" };
900
+ }
901
+ }
902
+ function lineRequestOf(value) {
903
+ if (!isRecord(value) || typeof value.kycStatus !== "string") return null;
904
+ return {
905
+ kycStatus: value.kycStatus,
906
+ kycReason: stringOrNull(value.kycReason),
907
+ enabled: value.enabled === true,
908
+ buyState: typeof value.buyState === "string" ? value.buyState : "NONE",
909
+ buyError: stringOrNull(value.buyError),
910
+ number: stringOrNull(value.number)
911
+ };
912
+ }
913
+ async function getPhoneLine(params = {}, options = {}) {
914
+ var _a;
915
+ try {
916
+ const key = callsKey(options);
917
+ if (!key) return null;
918
+ const query = params.ownerId ? `?ownerId=${encodeURIComponent(params.ownerId)}` : "";
919
+ const { data, error } = await callSdkApi(`/api/v1/sdk/phone-lines${query}`, key, options, { cache: "no-store" });
920
+ if (error !== null || !isRecord(data)) return null;
921
+ const line = isRecord(data.line) && typeof data.line.number === "string" ? data.line : null;
922
+ return {
923
+ line: line ? {
924
+ number: line.number,
925
+ label: stringOrNull(line.label),
926
+ active: line.active === true,
927
+ callers: (_a = numberOrNull(line.callers)) != null ? _a : 0
928
+ } : null,
929
+ request: lineRequestOf(data.request)
930
+ };
931
+ } catch (e) {
932
+ return null;
933
+ }
934
+ }
935
+ async function lineRequestCall(path, body, options) {
936
+ try {
937
+ const key = callsKey(options);
938
+ if (!key) return { ok: false, error: NO_KEY_ERROR };
939
+ const { data, error, code } = await callSdkApi(path, key, options, { method: "POST", body, cache: "no-store" });
940
+ const request = isRecord(data) ? lineRequestOf(data.request) : null;
941
+ if (error !== null || !request) return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
942
+ return { ok: true, request };
943
+ } catch (e) {
944
+ return { ok: false, error: "Could not reach Glitchgrab" };
945
+ }
946
+ }
947
+ function submitPhoneKyc(kyc, options = {}) {
948
+ const form = new FormData();
949
+ for (const k of ["ownerId", "businessName", "email", "addressLine1", "city", "state", "postalCode"]) {
950
+ form.set(k, kyc[k]);
951
+ }
952
+ form.set("registrationCertificate", kyc.registrationCertificate, "registration-certificate");
953
+ form.set("gstCertificate", kyc.gstCertificate, "gst-certificate");
954
+ return lineRequestCall("/api/v1/sdk/phone-lines/kyc", form, options);
955
+ }
956
+ function enableCalling(params, options = {}) {
957
+ return lineRequestCall("/api/v1/sdk/phone-lines/enable", { ...params, agreedToCharge: true }, options);
958
+ }
959
+ function disableCalling(params, options = {}) {
960
+ return lineRequestCall("/api/v1/sdk/phone-lines/disable", params, options);
961
+ }
962
+ async function registerWebhook(webhook, options = {}) {
963
+ try {
964
+ const key = callsKey(options);
965
+ if (!key) return { ok: false, error: NO_KEY_ERROR };
966
+ const { data, error } = await callSdkApi("/api/v1/sdk/webhooks", key, options, {
967
+ method: "POST",
968
+ body: webhook,
969
+ cache: "no-store"
970
+ });
971
+ if (error !== null || !isRecord(data) || typeof data.id !== "string" || typeof data.secret !== "string") {
972
+ return { ok: false, error: error != null ? error : "Unexpected response" };
973
+ }
974
+ return {
975
+ ok: true,
976
+ secret: data.secret,
977
+ webhook: {
978
+ id: data.id,
979
+ url: typeof data.url === "string" ? data.url : webhook.url,
980
+ events: Array.isArray(data.events) ? data.events.filter((e) => typeof e === "string") : []
981
+ }
982
+ };
983
+ } catch (e) {
984
+ return { ok: false, error: "Could not reach Glitchgrab" };
985
+ }
986
+ }
987
+ async function listWebhooks(options = {}) {
988
+ try {
989
+ const key = callsKey(options);
990
+ if (!key) return [];
991
+ const { data, error } = await callSdkApi("/api/v1/sdk/webhooks", key, options, { cache: "no-store" });
992
+ if (error !== null || !isRecord(data) || !Array.isArray(data.webhooks)) return [];
993
+ return data.webhooks.filter(isRecord).flatMap(
994
+ (w) => typeof w.id === "string" && typeof w.url === "string" ? [{ id: w.id, url: w.url, events: Array.isArray(w.events) ? w.events.filter((e) => typeof e === "string") : [] }] : []
995
+ );
996
+ } catch (e) {
997
+ return [];
998
+ }
999
+ }
1000
+ async function removeWebhook(id, options = {}) {
1001
+ try {
1002
+ const key = callsKey(options);
1003
+ if (!key) return { ok: false, error: NO_KEY_ERROR };
1004
+ const { error } = await callSdkApi(`/api/v1/sdk/webhooks/${encodeURIComponent(id)}`, key, options, {
1005
+ method: "DELETE",
1006
+ cache: "no-store"
1007
+ });
1008
+ return error === null ? { ok: true } : { ok: false, error };
1009
+ } catch (e) {
1010
+ return { ok: false, error: "Could not reach Glitchgrab" };
1011
+ }
1012
+ }
878
1013
  function removeLineCaller(email, options = {}) {
879
1014
  return ringNumberWrite(
880
1015
  `/api/v1/sdk/phone-lines/callers/${encodeURIComponent(email)}`,
@@ -957,28 +1092,36 @@ export {
957
1092
  configureServerReporter,
958
1093
  deleteCall,
959
1094
  dialFollowUp,
1095
+ disableCalling,
960
1096
  discardBookingQuestionsDraft,
961
1097
  editFollowUpNote,
1098
+ enableCalling,
962
1099
  escapeJsonForScript,
963
1100
  getBookingSettings,
964
1101
  getCall,
965
1102
  getFollowUp,
966
1103
  getGuide,
967
1104
  getOperatorRingNumbers,
1105
+ getPhoneLine,
968
1106
  listBookings,
969
1107
  listCalls,
970
1108
  listFollowUps,
971
1109
  listGuides,
972
1110
  listLeads,
973
1111
  listRingNumbers,
1112
+ listWebhooks,
1113
+ placeCall,
974
1114
  publishBookingQuestions,
1115
+ registerWebhook,
975
1116
  removeLineCaller,
976
1117
  removeRingNumber,
1118
+ removeWebhook,
977
1119
  reportServerError,
978
1120
  rescheduleBooking,
979
1121
  resetServerReporter,
980
1122
  setFollowUpBooking,
981
1123
  signSession,
1124
+ submitPhoneKyc,
982
1125
  testRingNumber,
983
1126
  updateBookingSettings,
984
1127
  updateRingNumber