glitchgrab 1.62.0 → 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/README.md +30 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +385 -193
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +385 -193
- package/dist/index.mjs.map +1 -1
- package/dist/server.d.mts +121 -3
- package/dist/server.d.ts +121 -3
- package/dist/server.js +119 -7
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +112 -6
- package/dist/server.mjs.map +1 -1
- package/dist/{types-BlMF6wzX.d.mts → types-Dp5Sh_hd.d.mts} +1 -1
- package/dist/{types-BlMF6wzX.d.ts → types-Dp5Sh_hd.d.ts} +1 -1
- package/package.json +1 -1
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 {
|
|
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,104 @@ 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
|
+
const op = isRecord(data.operator) ? data.operator : {};
|
|
819
|
+
return {
|
|
820
|
+
ok: true,
|
|
821
|
+
operator: { name: stringOrNull(op.name) },
|
|
822
|
+
numbers: Array.isArray(data.numbers) ? data.numbers.filter(isRecord).filter((n) => typeof n.phone === "string").map((n) => {
|
|
823
|
+
var _a;
|
|
824
|
+
return {
|
|
825
|
+
phone: n.phone,
|
|
826
|
+
label: stringOrNull(n.label),
|
|
827
|
+
isDefault: n.isDefault === true,
|
|
828
|
+
order: (_a = numberOrNull(n.order)) != null ? _a : 0
|
|
829
|
+
};
|
|
830
|
+
}) : []
|
|
831
|
+
};
|
|
832
|
+
} catch (e) {
|
|
833
|
+
return { ok: false, error: "Could not reach Glitchgrab" };
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
function ringNumbersPath(rest = "") {
|
|
837
|
+
return `/api/v1/sdk/phone-lines/operator/numbers${rest}`;
|
|
838
|
+
}
|
|
839
|
+
async function ringNumberWrite(path, method, body, options, pick) {
|
|
840
|
+
try {
|
|
841
|
+
const key = callsKey(options);
|
|
842
|
+
if (!key) return { ok: false, error: NO_KEY_ERROR };
|
|
843
|
+
const { data, error, code } = await callSdkApi(path, key, options, { method, body, cache: "no-store" });
|
|
844
|
+
if (error !== null || !isRecord(data)) return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
|
|
845
|
+
return { ok: true, ...pick(data) };
|
|
846
|
+
} catch (e) {
|
|
847
|
+
return { ok: false, error: "Could not reach Glitchgrab" };
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
async function listRingNumbers(operator, options = {}) {
|
|
851
|
+
try {
|
|
852
|
+
const key = callsKey(options);
|
|
853
|
+
if (!key) return { ok: false, error: NO_KEY_ERROR };
|
|
854
|
+
const query = new URLSearchParams("email" in operator ? { email: operator.email } : { phone: operator.phone });
|
|
855
|
+
const { data, error, code } = await callSdkApi(ringNumbersPath(`?${query.toString()}`), key, options, {
|
|
856
|
+
cache: "no-store"
|
|
857
|
+
});
|
|
858
|
+
if (error !== null || !isRecord(data)) return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
|
|
859
|
+
const op = isRecord(data.operator) ? data.operator : {};
|
|
860
|
+
return {
|
|
861
|
+
ok: true,
|
|
862
|
+
operator: { name: stringOrNull(op.name) },
|
|
863
|
+
accountPhone: stringOrNull(data.accountPhone),
|
|
864
|
+
usingAccount: data.usingAccount === true,
|
|
865
|
+
numbers: Array.isArray(data.numbers) ? data.numbers.filter(isRecord).filter((n) => typeof n.id === "string" && typeof n.phone === "string").map((n) => {
|
|
866
|
+
var _a;
|
|
867
|
+
return {
|
|
868
|
+
id: n.id,
|
|
869
|
+
phone: n.phone,
|
|
870
|
+
label: stringOrNull(n.label),
|
|
871
|
+
position: (_a = numberOrNull(n.position)) != null ? _a : 0,
|
|
872
|
+
verified: n.verified === true,
|
|
873
|
+
verifying: n.verifying === true,
|
|
874
|
+
isDefault: n.isDefault === true
|
|
875
|
+
};
|
|
876
|
+
}) : []
|
|
877
|
+
};
|
|
878
|
+
} catch (e) {
|
|
879
|
+
return { ok: false, error: "Could not reach Glitchgrab" };
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
function addRingNumber(operator, number, options = {}) {
|
|
883
|
+
return ringNumberWrite(ringNumbersPath(), "POST", { operator, ...number }, options, (d) => ({
|
|
884
|
+
id: typeof d.id === "string" ? d.id : "",
|
|
885
|
+
testRing: d.testRing === "failed" ? "failed" : "ringing",
|
|
886
|
+
verifyError: stringOrNull(d.verifyError)
|
|
887
|
+
}));
|
|
888
|
+
}
|
|
889
|
+
function updateRingNumber(id, change, options = {}) {
|
|
890
|
+
return ringNumberWrite(ringNumbersPath(`/${encodeURIComponent(id)}`), "PATCH", change, options, () => ({}));
|
|
891
|
+
}
|
|
892
|
+
function removeRingNumber(id, options = {}) {
|
|
893
|
+
return ringNumberWrite(ringNumbersPath(`/${encodeURIComponent(id)}`), "DELETE", void 0, options, () => ({}));
|
|
894
|
+
}
|
|
895
|
+
function testRingNumber(id, options = {}) {
|
|
896
|
+
return ringNumberWrite(ringNumbersPath(`/${encodeURIComponent(id)}/verify`), "POST", void 0, options, (d) => ({
|
|
897
|
+
verified: d.verified === true
|
|
798
898
|
}));
|
|
799
899
|
}
|
|
800
900
|
export {
|
|
801
901
|
addFollowUpNote,
|
|
902
|
+
addRingNumber,
|
|
802
903
|
cancelBooking,
|
|
803
904
|
captureServerErrors,
|
|
804
905
|
configureServerReporter,
|
|
@@ -810,17 +911,22 @@ export {
|
|
|
810
911
|
getCall,
|
|
811
912
|
getFollowUp,
|
|
812
913
|
getGuide,
|
|
914
|
+
getOperatorRingNumbers,
|
|
813
915
|
listBookings,
|
|
814
916
|
listCalls,
|
|
815
917
|
listFollowUps,
|
|
816
918
|
listGuides,
|
|
817
919
|
listLeads,
|
|
920
|
+
listRingNumbers,
|
|
818
921
|
publishBookingQuestions,
|
|
922
|
+
removeRingNumber,
|
|
819
923
|
reportServerError,
|
|
820
924
|
rescheduleBooking,
|
|
821
925
|
resetServerReporter,
|
|
822
926
|
setFollowUpBooking,
|
|
823
927
|
signSession,
|
|
824
|
-
|
|
928
|
+
testRingNumber,
|
|
929
|
+
updateBookingSettings,
|
|
930
|
+
updateRingNumber
|
|
825
931
|
};
|
|
826
932
|
//# sourceMappingURL=server.mjs.map
|