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.js CHANGED
@@ -28,28 +28,36 @@ __export(server_exports, {
28
28
  configureServerReporter: () => configureServerReporter,
29
29
  deleteCall: () => deleteCall,
30
30
  dialFollowUp: () => dialFollowUp,
31
+ disableCalling: () => disableCalling,
31
32
  discardBookingQuestionsDraft: () => discardBookingQuestionsDraft,
32
33
  editFollowUpNote: () => editFollowUpNote,
34
+ enableCalling: () => enableCalling,
33
35
  escapeJsonForScript: () => escapeJsonForScript,
34
36
  getBookingSettings: () => getBookingSettings,
35
37
  getCall: () => getCall,
36
38
  getFollowUp: () => getFollowUp,
37
39
  getGuide: () => getGuide,
38
40
  getOperatorRingNumbers: () => getOperatorRingNumbers,
41
+ getPhoneLine: () => getPhoneLine,
39
42
  listBookings: () => listBookings,
40
43
  listCalls: () => listCalls,
41
44
  listFollowUps: () => listFollowUps,
42
45
  listGuides: () => listGuides,
43
46
  listLeads: () => listLeads,
44
47
  listRingNumbers: () => listRingNumbers,
48
+ listWebhooks: () => listWebhooks,
49
+ placeCall: () => placeCall,
45
50
  publishBookingQuestions: () => publishBookingQuestions,
51
+ registerWebhook: () => registerWebhook,
46
52
  removeLineCaller: () => removeLineCaller,
47
53
  removeRingNumber: () => removeRingNumber,
54
+ removeWebhook: () => removeWebhook,
48
55
  reportServerError: () => reportServerError,
49
56
  rescheduleBooking: () => rescheduleBooking,
50
57
  resetServerReporter: () => resetServerReporter,
51
58
  setFollowUpBooking: () => setFollowUpBooking,
52
59
  signSession: () => signSession,
60
+ submitPhoneKyc: () => submitPhoneKyc,
53
61
  testRingNumber: () => testRingNumber,
54
62
  updateBookingSettings: () => updateBookingSettings,
55
63
  updateRingNumber: () => updateRingNumber
@@ -312,13 +320,14 @@ async function callSdkApi(path, token, options, init) {
312
320
  const controller = typeof AbortController === "function" ? new AbortController() : void 0;
313
321
  const timer = controller ? setTimeout(() => controller.abort(), (_d = options.timeoutMs) != null ? _d : SDK_API_TIMEOUT_MS) : void 0;
314
322
  try {
323
+ const multipart = typeof FormData !== "undefined" && init.body instanceof FormData;
315
324
  const request = {
316
325
  method: (_e = init.method) != null ? _e : "GET",
317
326
  headers: {
318
327
  Authorization: `Bearer ${token}`,
319
- ...init.body === void 0 ? {} : { "Content-Type": "application/json" }
328
+ ...init.body === void 0 || multipart ? {} : { "Content-Type": "application/json" }
320
329
  },
321
- ...init.body === void 0 ? {} : { body: JSON.stringify(init.body) },
330
+ ...init.body === void 0 ? {} : { body: multipart ? init.body : JSON.stringify(init.body) },
322
331
  ...init.cache === "no-store" ? { cache: "no-store" } : { next: { revalidate: init.cache.revalidate } },
323
332
  ...controller ? { signal: controller.signal } : {}
324
333
  };
@@ -931,6 +940,140 @@ async function addLineCaller(caller, options = {}) {
931
940
  return { ok: false, error: "Could not reach Glitchgrab" };
932
941
  }
933
942
  }
943
+ async function placeCall(call, options = {}) {
944
+ try {
945
+ const key = callsKey(options);
946
+ if (!key) return { ok: false, error: NO_KEY_ERROR };
947
+ const { data, error, code } = await callSdkApi("/api/v1/sdk/phone-lines/call", key, options, {
948
+ method: "POST",
949
+ body: call,
950
+ cache: "no-store"
951
+ });
952
+ if (error !== null || !isRecord(data) || typeof data.callId !== "string") {
953
+ return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
954
+ }
955
+ return {
956
+ ok: true,
957
+ callId: data.callId,
958
+ ringing: typeof data.ringing === "string" ? data.ringing : "",
959
+ ringNumbers: Array.isArray(data.ringNumbers) ? data.ringNumbers.filter((n) => typeof n === "string") : [],
960
+ from: typeof data.from === "string" ? data.from : ""
961
+ };
962
+ } catch (e) {
963
+ return { ok: false, error: "Could not reach Glitchgrab" };
964
+ }
965
+ }
966
+ function lineRequestOf(value) {
967
+ if (!isRecord(value) || typeof value.kycStatus !== "string") return null;
968
+ return {
969
+ kycStatus: value.kycStatus,
970
+ kycReason: stringOrNull(value.kycReason),
971
+ enabled: value.enabled === true,
972
+ buyState: typeof value.buyState === "string" ? value.buyState : "NONE",
973
+ buyError: stringOrNull(value.buyError),
974
+ number: stringOrNull(value.number)
975
+ };
976
+ }
977
+ async function getPhoneLine(params = {}, options = {}) {
978
+ var _a;
979
+ try {
980
+ const key = callsKey(options);
981
+ if (!key) return null;
982
+ const query = params.ownerId ? `?ownerId=${encodeURIComponent(params.ownerId)}` : "";
983
+ const { data, error } = await callSdkApi(`/api/v1/sdk/phone-lines${query}`, key, options, { cache: "no-store" });
984
+ if (error !== null || !isRecord(data)) return null;
985
+ const line = isRecord(data.line) && typeof data.line.number === "string" ? data.line : null;
986
+ return {
987
+ line: line ? {
988
+ number: line.number,
989
+ label: stringOrNull(line.label),
990
+ active: line.active === true,
991
+ callers: (_a = numberOrNull(line.callers)) != null ? _a : 0
992
+ } : null,
993
+ request: lineRequestOf(data.request)
994
+ };
995
+ } catch (e) {
996
+ return null;
997
+ }
998
+ }
999
+ async function lineRequestCall(path, body, options) {
1000
+ try {
1001
+ const key = callsKey(options);
1002
+ if (!key) return { ok: false, error: NO_KEY_ERROR };
1003
+ const { data, error, code } = await callSdkApi(path, key, options, { method: "POST", body, cache: "no-store" });
1004
+ const request = isRecord(data) ? lineRequestOf(data.request) : null;
1005
+ if (error !== null || !request) return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
1006
+ return { ok: true, request };
1007
+ } catch (e) {
1008
+ return { ok: false, error: "Could not reach Glitchgrab" };
1009
+ }
1010
+ }
1011
+ function submitPhoneKyc(kyc, options = {}) {
1012
+ const form = new FormData();
1013
+ for (const k of ["ownerId", "businessName", "email", "addressLine1", "city", "state", "postalCode"]) {
1014
+ form.set(k, kyc[k]);
1015
+ }
1016
+ form.set("registrationCertificate", kyc.registrationCertificate, "registration-certificate");
1017
+ form.set("gstCertificate", kyc.gstCertificate, "gst-certificate");
1018
+ return lineRequestCall("/api/v1/sdk/phone-lines/kyc", form, options);
1019
+ }
1020
+ function enableCalling(params, options = {}) {
1021
+ return lineRequestCall("/api/v1/sdk/phone-lines/enable", { ...params, agreedToCharge: true }, options);
1022
+ }
1023
+ function disableCalling(params, options = {}) {
1024
+ return lineRequestCall("/api/v1/sdk/phone-lines/disable", params, options);
1025
+ }
1026
+ async function registerWebhook(webhook, options = {}) {
1027
+ try {
1028
+ const key = callsKey(options);
1029
+ if (!key) return { ok: false, error: NO_KEY_ERROR };
1030
+ const { data, error } = await callSdkApi("/api/v1/sdk/webhooks", key, options, {
1031
+ method: "POST",
1032
+ body: webhook,
1033
+ cache: "no-store"
1034
+ });
1035
+ if (error !== null || !isRecord(data) || typeof data.id !== "string" || typeof data.secret !== "string") {
1036
+ return { ok: false, error: error != null ? error : "Unexpected response" };
1037
+ }
1038
+ return {
1039
+ ok: true,
1040
+ secret: data.secret,
1041
+ webhook: {
1042
+ id: data.id,
1043
+ url: typeof data.url === "string" ? data.url : webhook.url,
1044
+ events: Array.isArray(data.events) ? data.events.filter((e) => typeof e === "string") : []
1045
+ }
1046
+ };
1047
+ } catch (e) {
1048
+ return { ok: false, error: "Could not reach Glitchgrab" };
1049
+ }
1050
+ }
1051
+ async function listWebhooks(options = {}) {
1052
+ try {
1053
+ const key = callsKey(options);
1054
+ if (!key) return [];
1055
+ const { data, error } = await callSdkApi("/api/v1/sdk/webhooks", key, options, { cache: "no-store" });
1056
+ if (error !== null || !isRecord(data) || !Array.isArray(data.webhooks)) return [];
1057
+ return data.webhooks.filter(isRecord).flatMap(
1058
+ (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") : [] }] : []
1059
+ );
1060
+ } catch (e) {
1061
+ return [];
1062
+ }
1063
+ }
1064
+ async function removeWebhook(id, options = {}) {
1065
+ try {
1066
+ const key = callsKey(options);
1067
+ if (!key) return { ok: false, error: NO_KEY_ERROR };
1068
+ const { error } = await callSdkApi(`/api/v1/sdk/webhooks/${encodeURIComponent(id)}`, key, options, {
1069
+ method: "DELETE",
1070
+ cache: "no-store"
1071
+ });
1072
+ return error === null ? { ok: true } : { ok: false, error };
1073
+ } catch (e) {
1074
+ return { ok: false, error: "Could not reach Glitchgrab" };
1075
+ }
1076
+ }
934
1077
  function removeLineCaller(email, options = {}) {
935
1078
  return ringNumberWrite(
936
1079
  `/api/v1/sdk/phone-lines/callers/${encodeURIComponent(email)}`,
@@ -1014,28 +1157,36 @@ function testRingNumber(id, options = {}) {
1014
1157
  configureServerReporter,
1015
1158
  deleteCall,
1016
1159
  dialFollowUp,
1160
+ disableCalling,
1017
1161
  discardBookingQuestionsDraft,
1018
1162
  editFollowUpNote,
1163
+ enableCalling,
1019
1164
  escapeJsonForScript,
1020
1165
  getBookingSettings,
1021
1166
  getCall,
1022
1167
  getFollowUp,
1023
1168
  getGuide,
1024
1169
  getOperatorRingNumbers,
1170
+ getPhoneLine,
1025
1171
  listBookings,
1026
1172
  listCalls,
1027
1173
  listFollowUps,
1028
1174
  listGuides,
1029
1175
  listLeads,
1030
1176
  listRingNumbers,
1177
+ listWebhooks,
1178
+ placeCall,
1031
1179
  publishBookingQuestions,
1180
+ registerWebhook,
1032
1181
  removeLineCaller,
1033
1182
  removeRingNumber,
1183
+ removeWebhook,
1034
1184
  reportServerError,
1035
1185
  rescheduleBooking,
1036
1186
  resetServerReporter,
1037
1187
  setFollowUpBooking,
1038
1188
  signSession,
1189
+ submitPhoneKyc,
1039
1190
  testRingNumber,
1040
1191
  updateBookingSettings,
1041
1192
  updateRingNumber