glitchgrab 1.63.1 → 1.65.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/README.md +36 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +43 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -10
- package/dist/index.mjs.map +1 -1
- package/dist/server.d.mts +281 -16
- package/dist/server.d.ts +281 -16
- package/dist/server.js +175 -11
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +167 -11
- package/dist/server.mjs.map +1 -1
- package/dist/{types-Dp5Sh_hd.d.mts → types-Dw587jLi.d.mts} +5 -1
- package/dist/{types-Dp5Sh_hd.d.ts → types-Dw587jLi.d.ts} +5 -1
- package/package.json +1 -1
package/dist/server.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as ReportType, m as ReportSeverity, l as ReportResult } from './types-
|
|
1
|
+
import { n as ReportType, m as ReportSeverity, l as ReportResult } from './types-Dw587jLi.js';
|
|
2
2
|
import 'react';
|
|
3
3
|
|
|
4
4
|
/** Who to attribute the report to. A server has no signed-in user, so this is the job or service. */
|
|
@@ -322,7 +322,8 @@ type DeleteCallResult = {
|
|
|
322
322
|
};
|
|
323
323
|
/**
|
|
324
324
|
* Calls shared with the client on the key's project, newest first. No links —
|
|
325
|
-
* open one with {@link getCall}.
|
|
325
|
+
* open one with {@link getCall}. Every {@link placeCall} call is shared from
|
|
326
|
+
* the start, firm lines (`ownerId`) included.
|
|
326
327
|
*
|
|
327
328
|
* ```ts
|
|
328
329
|
* // app/admin/calls/page.tsx — server component
|
|
@@ -342,6 +343,11 @@ declare function listCalls(options?: ListCallsOptions): Promise<CallListItem[]>;
|
|
|
342
343
|
* Links expire after `linksExpireInSeconds` — read the call when the page
|
|
343
344
|
* renders and never store them.
|
|
344
345
|
*
|
|
346
|
+
* A {@link placeCall} call is shared from the start, so `getCall(callId)` with
|
|
347
|
+
* the `callId` from `placeCall` or any `call.*` webhook plays its recording —
|
|
348
|
+
* firm lines (`ownerId`) included (#723). `call.recording_ready` carries no
|
|
349
|
+
* link on purpose: fetch a fresh one here when someone presses play.
|
|
350
|
+
*
|
|
345
351
|
* Returns `null` when the call does not exist, is not shared, and on any
|
|
346
352
|
* failure — call `notFound()` on it. Never throws.
|
|
347
353
|
*/
|
|
@@ -863,18 +869,28 @@ type OperatorRingNumbersResult = {
|
|
|
863
869
|
error: string;
|
|
864
870
|
code?: string;
|
|
865
871
|
};
|
|
872
|
+
/**
|
|
873
|
+
* Options for calls about one person on a line. `ownerId` = that customer's own
|
|
874
|
+
* line (#723 — one line per PracticeStacks firm, the same id you pass to
|
|
875
|
+
* {@link addLineCaller}): the person must sit on it, and test rings come from
|
|
876
|
+
* its number. Omitted = any of the project's lines.
|
|
877
|
+
*/
|
|
878
|
+
interface LineCallsOptions extends CallsOptions {
|
|
879
|
+
ownerId?: string;
|
|
880
|
+
}
|
|
866
881
|
/**
|
|
867
882
|
* The phones Glitchgrab can ring for one person on the project's phone line —
|
|
868
883
|
* for a "Ring me on: [Default ▾]" picker beside your Call button. Verified
|
|
869
884
|
* numbers only. `numbers: []` = dial will refuse with `NO_VERIFIED_NUMBER`;
|
|
870
|
-
* not on the line = `{ ok: false, code: "NOT_ON_LINE" }`.
|
|
885
|
+
* not on the line = `{ ok: false, code: "NOT_ON_LINE" }`. Pass `{ ownerId }`
|
|
886
|
+
* for someone on a customer's line. Never throws.
|
|
871
887
|
*
|
|
872
888
|
* ```ts
|
|
873
889
|
* const r = await getOperatorRingNumbers({ email: admin.email }); // GLITCHGRAB_CALLS_KEY=ggc_…
|
|
874
890
|
* if (r.ok) render(r.numbers); // pass the chosen phone to dialFollowUp(…, { ringPhone })
|
|
875
891
|
* ```
|
|
876
892
|
*/
|
|
877
|
-
declare function getOperatorRingNumbers(operator: FollowUpOperator, options?:
|
|
893
|
+
declare function getOperatorRingNumbers(operator: FollowUpOperator, options?: LineCallsOptions): Promise<OperatorRingNumbersResult>;
|
|
878
894
|
type LineCallerResult = {
|
|
879
895
|
ok: true;
|
|
880
896
|
created: boolean;
|
|
@@ -898,6 +914,9 @@ type LineCallerResult = {
|
|
|
898
914
|
* `CALLERS_OFF` (the line's owner switched it off), `CALLER_CAP` (10 per line).
|
|
899
915
|
* Never throws.
|
|
900
916
|
*
|
|
917
|
+
* `ownerId` = seat them on that customer's own line (#716 — one line per
|
|
918
|
+
* PracticeStacks firm). Omitted = the project's line.
|
|
919
|
+
*
|
|
901
920
|
* ```ts
|
|
902
921
|
* const r = await addLineCaller({ email: admin.email, name: admin.name });
|
|
903
922
|
* if (r.ok) openMyPhones(r.numbers);
|
|
@@ -907,13 +926,255 @@ declare function addLineCaller(caller: {
|
|
|
907
926
|
email: string;
|
|
908
927
|
name: string;
|
|
909
928
|
phone?: string;
|
|
929
|
+
ownerId?: string;
|
|
910
930
|
}, options?: CallsOptions): Promise<LineCallerResult>;
|
|
931
|
+
/** Fields every `call.*` webhook carries (#716). `refKey`/`ownerId` are null when not set. */
|
|
932
|
+
interface CallWebhookBase {
|
|
933
|
+
callId: string;
|
|
934
|
+
repoId: string | null;
|
|
935
|
+
lineId: string | null;
|
|
936
|
+
direction: "outbound" | "inbound" | null;
|
|
937
|
+
/** The other party, E.164. */
|
|
938
|
+
peer: string | null;
|
|
939
|
+
/** What you passed to {@link placeCall}. */
|
|
940
|
+
refKey: string | null;
|
|
941
|
+
/** The customer whose line carried the call. */
|
|
942
|
+
ownerId: string | null;
|
|
943
|
+
}
|
|
944
|
+
/**
|
|
945
|
+
* The body Glitchgrab POSTs to your webhook for a phone call, signed with
|
|
946
|
+
* `X-Glitchgrab-Signature: sha256=<hex HMAC of the raw body>`. Narrow on `event`.
|
|
947
|
+
*/
|
|
948
|
+
type CallWebhook = {
|
|
949
|
+
event: "call.started";
|
|
950
|
+
timestamp: string;
|
|
951
|
+
data: CallWebhookBase & {
|
|
952
|
+
ringing: string;
|
|
953
|
+
};
|
|
954
|
+
} | {
|
|
955
|
+
event: "call.answered";
|
|
956
|
+
timestamp: string;
|
|
957
|
+
data: CallWebhookBase & {
|
|
958
|
+
answeredAt: string;
|
|
959
|
+
};
|
|
960
|
+
} | {
|
|
961
|
+
event: "call.completed";
|
|
962
|
+
timestamp: string;
|
|
963
|
+
data: CallWebhookBase & {
|
|
964
|
+
/** RECORDED = they talked; NO_ANSWER (+ missedBy); FAILED. */
|
|
965
|
+
status: string;
|
|
966
|
+
missedBy: "operator" | "customer" | null;
|
|
967
|
+
durationSec: number | null;
|
|
968
|
+
hangupCause: string | null;
|
|
969
|
+
};
|
|
970
|
+
} | {
|
|
971
|
+
event: "call.recording_ready";
|
|
972
|
+
timestamp: string;
|
|
973
|
+
data: Omit<CallWebhookBase, "lineId"> & {
|
|
974
|
+
durationSec: number | null;
|
|
975
|
+
};
|
|
976
|
+
} | {
|
|
977
|
+
event: "call.summary_ready";
|
|
978
|
+
timestamp: string;
|
|
979
|
+
data: Pick<CallWebhookBase, "callId" | "repoId" | "refKey" | "ownerId"> & {
|
|
980
|
+
/** "phone", "bot" or "extension". */
|
|
981
|
+
recorder: string;
|
|
982
|
+
title: string | null;
|
|
983
|
+
summary: string | null;
|
|
984
|
+
};
|
|
985
|
+
};
|
|
986
|
+
/** `phone.*` webhooks for a customer's automatic line (#716). Same signing as {@link CallWebhook}. */
|
|
987
|
+
type PhoneLineWebhook = {
|
|
988
|
+
event: "phone.kyc_status";
|
|
989
|
+
timestamp: string;
|
|
990
|
+
data: {
|
|
991
|
+
ownerId: string;
|
|
992
|
+
status: string;
|
|
993
|
+
reason: string | null;
|
|
994
|
+
};
|
|
995
|
+
} | {
|
|
996
|
+
event: "phone.line_ready";
|
|
997
|
+
timestamp: string;
|
|
998
|
+
data: {
|
|
999
|
+
ownerId: string;
|
|
1000
|
+
number: string;
|
|
1001
|
+
lineId: string;
|
|
1002
|
+
};
|
|
1003
|
+
};
|
|
1004
|
+
type PlaceCallResult = {
|
|
1005
|
+
ok: true;
|
|
1006
|
+
callId: string;
|
|
1007
|
+
ringing: string;
|
|
1008
|
+
ringNumbers: string[];
|
|
1009
|
+
from: string;
|
|
1010
|
+
} | {
|
|
1011
|
+
ok: false;
|
|
1012
|
+
error: string;
|
|
1013
|
+
code?: string;
|
|
1014
|
+
};
|
|
1015
|
+
/**
|
|
1016
|
+
* Start a recorded call from your own screen (#716) — Glitchgrab rings
|
|
1017
|
+
* `operator`'s verified phone from the line, then bridges to `to`. No
|
|
1018
|
+
* follow-up is created; use {@link dialFollowUp} for that.
|
|
1019
|
+
*
|
|
1020
|
+
* `ownerId` = call from that customer's own line (one line per PracticeStacks
|
|
1021
|
+
* firm); the operator must be seated on it ({@link addLineCaller} with the
|
|
1022
|
+
* same `ownerId`). `refKey` = your own key for what the call is about — every
|
|
1023
|
+
* `call.*` webhook (`call.started`, `call.answered`, `call.completed`,
|
|
1024
|
+
* `call.recording_ready`, `call.summary_ready`) carries it back with `ownerId`.
|
|
1025
|
+
* The recording plays through {@link getCall}(`callId`).
|
|
1026
|
+
* Check your own permissions before calling this. Refusals carry `code`:
|
|
1027
|
+
* `NOT_ON_LINE`, `NO_VERIFIED_NUMBER`, `RING_PHONE_NOT_YOURS`. Never throws.
|
|
1028
|
+
*
|
|
1029
|
+
* ```ts
|
|
1030
|
+
* const r = await placeCall({
|
|
1031
|
+
* operator: { email: staff.email },
|
|
1032
|
+
* to: client.phone,
|
|
1033
|
+
* ownerId: firm.id,
|
|
1034
|
+
* refKey: client.id,
|
|
1035
|
+
* }); // GLITCHGRAB_CALLS_KEY=ggc_…
|
|
1036
|
+
* ```
|
|
1037
|
+
*/
|
|
1038
|
+
declare function placeCall(call: {
|
|
1039
|
+
operator: FollowUpOperator;
|
|
1040
|
+
to: string;
|
|
1041
|
+
ownerId?: string;
|
|
1042
|
+
refKey?: string;
|
|
1043
|
+
title?: string;
|
|
1044
|
+
ringPhone?: string;
|
|
1045
|
+
}, options?: CallsOptions): Promise<PlaceCallResult>;
|
|
1046
|
+
interface PhoneLineInfo {
|
|
1047
|
+
number: string;
|
|
1048
|
+
label: string | null;
|
|
1049
|
+
active: boolean;
|
|
1050
|
+
/** People seated on it; anyone else gets `NOT_ON_LINE`. */
|
|
1051
|
+
callers: number;
|
|
1052
|
+
}
|
|
1053
|
+
/** Where a customer's automatic line is up to (#716). */
|
|
1054
|
+
interface PhoneLineRequest {
|
|
1055
|
+
/** Plivo's KYC status: submitted | accepted | rejected | suspended | expired. */
|
|
1056
|
+
kycStatus: string;
|
|
1057
|
+
/** Why Plivo rejected it — show it to the firm so they can fix and resubmit. */
|
|
1058
|
+
kycReason: string | null;
|
|
1059
|
+
/** The firm agreed to the monthly charge ({@link enableCalling}). */
|
|
1060
|
+
enabled: boolean;
|
|
1061
|
+
/** NONE | BUYING | BOUGHT | FAILED (retried automatically). */
|
|
1062
|
+
buyState: string;
|
|
1063
|
+
buyError: string | null;
|
|
1064
|
+
number: string | null;
|
|
1065
|
+
}
|
|
1066
|
+
interface PhoneLineStatus {
|
|
1067
|
+
line: PhoneLineInfo | null;
|
|
1068
|
+
/** Null when no KYC was submitted for this customer. */
|
|
1069
|
+
request: PhoneLineRequest | null;
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* A customer's phone line and, when you submitted their KYC, how far the
|
|
1073
|
+
* automatic purchase has got (#716) — for the firm's "Calling" settings:
|
|
1074
|
+
* no request → "Submit KYC"; `kycStatus: "rejected"` → show `kycReason`;
|
|
1075
|
+
* accepted but `enabled: false` → "Turn on calling (₹… /month)"; `line` set →
|
|
1076
|
+
* ready. `ownerId` omitted = the project's own line. `null` only on failure
|
|
1077
|
+
* (no key, network). Never throws.
|
|
1078
|
+
*/
|
|
1079
|
+
declare function getPhoneLine(params?: {
|
|
1080
|
+
ownerId?: string;
|
|
1081
|
+
}, options?: CallsOptions): Promise<PhoneLineStatus | null>;
|
|
1082
|
+
type LineRequestResult = {
|
|
1083
|
+
ok: true;
|
|
1084
|
+
request: PhoneLineRequest;
|
|
1085
|
+
} | {
|
|
1086
|
+
ok: false;
|
|
1087
|
+
error: string;
|
|
1088
|
+
code?: string;
|
|
1089
|
+
};
|
|
1090
|
+
/**
|
|
1091
|
+
* Submit a customer's KYC so they get their own phone number (#716). Plivo
|
|
1092
|
+
* reviews it (usually minutes, sometimes a day); the `phone.kyc_status`
|
|
1093
|
+
* webhook says when. Rejected → fix and call again. Certificates: PDF, JPG or
|
|
1094
|
+
* PNG, under 4 MB together; they go straight to Plivo, Glitchgrab keeps no
|
|
1095
|
+
* copy. Refusals carry `code`: `KYC_PENDING`, `KYC_DONE`, `BAD_FILE`,
|
|
1096
|
+
* `PROVIDER`. Nothing is bought until {@link enableCalling}. Never throws.
|
|
1097
|
+
*/
|
|
1098
|
+
declare function submitPhoneKyc(kyc: {
|
|
1099
|
+
ownerId: string;
|
|
1100
|
+
/** Legal name, as on the certificates. */
|
|
1101
|
+
businessName: string;
|
|
1102
|
+
email: string;
|
|
1103
|
+
addressLine1: string;
|
|
1104
|
+
city: string;
|
|
1105
|
+
state: string;
|
|
1106
|
+
/** 6-digit PIN code. */
|
|
1107
|
+
postalCode: string;
|
|
1108
|
+
registrationCertificate: Blob;
|
|
1109
|
+
gstCertificate: Blob;
|
|
1110
|
+
}, options?: CallsOptions): Promise<LineRequestResult>;
|
|
1111
|
+
/**
|
|
1112
|
+
* The firm turned calling on and agreed to the monthly charge for its own
|
|
1113
|
+
* number (#716). `agreedBy` (who agreed) and the time are kept as the billing
|
|
1114
|
+
* record. Once the KYC is accepted — now or later — Glitchgrab rents the
|
|
1115
|
+
* number and creates the line (`phone.line_ready` webhook); then seat staff
|
|
1116
|
+
* with {@link addLineCaller} and the same `ownerId`. `areaCode` = STD code to
|
|
1117
|
+
* search under ("20" Pune), else any free Indian number. Never throws.
|
|
1118
|
+
*/
|
|
1119
|
+
declare function enableCalling(params: {
|
|
1120
|
+
ownerId: string;
|
|
1121
|
+
agreedBy: string;
|
|
1122
|
+
areaCode?: string;
|
|
1123
|
+
}, options?: CallsOptions): Promise<LineRequestResult>;
|
|
1124
|
+
/**
|
|
1125
|
+
* The firm turned calling off (#716): its line stops ringing and calling at
|
|
1126
|
+
* once, consent is cleared, and Navibyte is told to release the number.
|
|
1127
|
+
* {@link enableCalling} again switches the same line back on. Never throws.
|
|
1128
|
+
*/
|
|
1129
|
+
declare function disableCalling(params: {
|
|
1130
|
+
ownerId: string;
|
|
1131
|
+
}, options?: CallsOptions): Promise<LineRequestResult>;
|
|
1132
|
+
interface RegisteredWebhook {
|
|
1133
|
+
id: string;
|
|
1134
|
+
url: string;
|
|
1135
|
+
events: string[];
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
* Register your backend's webhook from code (#716) — scoped to this project,
|
|
1139
|
+
* no Settings clicks. https and a public host only. The `secret` comes back
|
|
1140
|
+
* once: verify every delivery's `X-Glitchgrab-Signature` (`sha256=` HMAC of the
|
|
1141
|
+
* raw body) with it. Same URL twice → refused; remove it first to rotate.
|
|
1142
|
+
* Never throws.
|
|
1143
|
+
*/
|
|
1144
|
+
declare function registerWebhook(webhook: {
|
|
1145
|
+
url: string;
|
|
1146
|
+
events: string[];
|
|
1147
|
+
}, options?: CallsOptions): Promise<{
|
|
1148
|
+
ok: true;
|
|
1149
|
+
webhook: RegisteredWebhook;
|
|
1150
|
+
secret: string;
|
|
1151
|
+
} | {
|
|
1152
|
+
ok: false;
|
|
1153
|
+
error: string;
|
|
1154
|
+
}>;
|
|
1155
|
+
/** This project's webhooks, without secrets. `[]` on any failure. Never throws. */
|
|
1156
|
+
declare function listWebhooks(options?: CallsOptions): Promise<RegisteredWebhook[]>;
|
|
1157
|
+
/** Remove one of this project's webhooks. Never throws. */
|
|
1158
|
+
declare function removeWebhook(id: string, options?: CallsOptions): Promise<{
|
|
1159
|
+
ok: true;
|
|
1160
|
+
} | {
|
|
1161
|
+
ok: false;
|
|
1162
|
+
error: string;
|
|
1163
|
+
}>;
|
|
911
1164
|
/**
|
|
912
1165
|
* Take a caller your key added off the line, with the phones kept for them —
|
|
913
1166
|
* e.g. when they leave your admin team. Someone the line's owner added →
|
|
914
|
-
* `code: "NOT_KEY_CALLER"`. Never throws.
|
|
1167
|
+
* `code: "NOT_KEY_CALLER"`; not on it → `code: "NOT_ON_LINE"`. Never throws.
|
|
1168
|
+
*
|
|
1169
|
+
* `{ ownerId }` = only their seat on that customer's line (#723): staff of two
|
|
1170
|
+
* firms keep the other one, and access + phones go with their last seat.
|
|
1171
|
+
* Omitted = off every line of the project.
|
|
1172
|
+
*
|
|
1173
|
+
* ```ts
|
|
1174
|
+
* await removeLineCaller(staff.email, { ownerId: firm.id });
|
|
1175
|
+
* ```
|
|
915
1176
|
*/
|
|
916
|
-
declare function removeLineCaller(email: string, options?:
|
|
1177
|
+
declare function removeLineCaller(email: string, options?: LineCallsOptions): Promise<RingNumberWriteResult>;
|
|
917
1178
|
/** One saved ring number, verified or not — the management view (#654). */
|
|
918
1179
|
interface RingNumber {
|
|
919
1180
|
id: string;
|
|
@@ -948,34 +1209,38 @@ type RingNumberWriteResult<T = object> = ({
|
|
|
948
1209
|
* — for your "manage my phones" screen. Ring numbers are managed only from
|
|
949
1210
|
* your product; Glitchgrab shows them read-only. A refusal carries `code`
|
|
950
1211
|
* (`NOT_ON_LINE`), so "not on the line" reads differently from "network down".
|
|
951
|
-
* Never throws.
|
|
1212
|
+
* `{ ownerId }` for someone on a customer's line. Never throws.
|
|
952
1213
|
*/
|
|
953
|
-
declare function listRingNumbers(operator: FollowUpOperator, options?:
|
|
1214
|
+
declare function listRingNumbers(operator: FollowUpOperator, options?: LineCallsOptions): Promise<RingNumberWriteResult<RingNumberList>>;
|
|
954
1215
|
/**
|
|
955
1216
|
* Save a phone for `operator` and place its test ring at once: the project's
|
|
956
1217
|
* line calls it and whoever holds it presses 1. Never rung for a call until
|
|
957
1218
|
* then; the line's owner is alerted when it is verified. Max 5 per person.
|
|
958
1219
|
* `testRing: "failed"` = saved but not rung — retry with {@link testRingNumber}.
|
|
1220
|
+
* `{ ownerId }` = they sit on that customer's line, and its number test-rings.
|
|
959
1221
|
*/
|
|
960
1222
|
declare function addRingNumber(operator: FollowUpOperator, number: {
|
|
961
1223
|
phone: string;
|
|
962
1224
|
label?: string;
|
|
963
|
-
}, options?:
|
|
1225
|
+
}, options?: LineCallsOptions): Promise<RingNumberWriteResult<{
|
|
964
1226
|
id: string;
|
|
965
1227
|
testRing: "ringing" | "failed";
|
|
966
1228
|
verifyError: string | null;
|
|
967
1229
|
}>>;
|
|
968
|
-
/** Rename, make Default (verified only) or move one place up/down. Never throws. */
|
|
1230
|
+
/** Rename, make Default (verified only) or move one place up/down. `{ ownerId }` as in {@link LineCallsOptions}. Never throws. */
|
|
969
1231
|
declare function updateRingNumber(id: string, change: {
|
|
970
1232
|
label?: string | null;
|
|
971
1233
|
makeDefault?: true;
|
|
972
1234
|
move?: "up" | "down";
|
|
973
|
-
}, options?:
|
|
974
|
-
/** Remove one; the next verified number becomes Default. Never throws. */
|
|
975
|
-
declare function removeRingNumber(id: string, options?:
|
|
976
|
-
/**
|
|
977
|
-
|
|
1235
|
+
}, options?: LineCallsOptions): Promise<RingNumberWriteResult>;
|
|
1236
|
+
/** Remove one; the next verified number becomes Default. `{ ownerId }` as in {@link LineCallsOptions}. Never throws. */
|
|
1237
|
+
declare function removeRingNumber(id: string, options?: LineCallsOptions): Promise<RingNumberWriteResult>;
|
|
1238
|
+
/**
|
|
1239
|
+
* Place the test ring again (6 per person, 30 per project an hour). `{ ownerId }`
|
|
1240
|
+
* = rings from that customer's line, e.g. retrying a firm caller's failed ring. Never throws.
|
|
1241
|
+
*/
|
|
1242
|
+
declare function testRingNumber(id: string, options?: LineCallsOptions): Promise<RingNumberWriteResult<{
|
|
978
1243
|
verified: boolean;
|
|
979
1244
|
}>>;
|
|
980
1245
|
|
|
981
|
-
export { type Booking, type BookingAnswer, type BookingClientNotice, type BookingMutationResult, type BookingNotifyRecipient, type BookingQuestion, type BookingQuestionInput, type BookingSettings, type BookingSettingsChanges, type BookingSettingsResult, type BookingSettingsState, type BookingWorkingHours, type Call, type CallAudio, type CallListItem, type CallMoment, type CallParticipant, type CallsOptions, type CaptureServerErrorsOptions, type DeleteCallResult, type FollowUp, type FollowUpBooking, type FollowUpCall, type FollowUpDetail, type FollowUpDue, type FollowUpNote, type FollowUpOperator, type FollowUpWriteResult, type GetCallOptions, type Guide, type GuideReadOptions, type GuideSummary, type Lead, type LineCallerResult, type ListBookingsOptions, type ListCallsOptions, type ListLeadsOptions, type OperatorRingNumber, type OperatorRingNumbersResult, ReportResult, ReportSeverity, ReportType, type RingErrorCode, type RingNumber, type RingNumberList, type RingNumberWriteResult, type ServerReportOptions, type ServerReporterConfig, type ServerReporterIdentity, type SignSessionOptions, addFollowUpNote, addLineCaller, addRingNumber, cancelBooking, captureServerErrors, configureServerReporter, deleteCall, dialFollowUp, discardBookingQuestionsDraft, editFollowUpNote, escapeJsonForScript, getBookingSettings, getCall, getFollowUp, getGuide, getOperatorRingNumbers, listBookings, listCalls, listFollowUps, listGuides, listLeads, listRingNumbers, publishBookingQuestions, removeLineCaller, removeRingNumber, reportServerError, rescheduleBooking, resetServerReporter, setFollowUpBooking, signSession, testRingNumber, updateBookingSettings, updateRingNumber };
|
|
1246
|
+
export { type Booking, type BookingAnswer, type BookingClientNotice, type BookingMutationResult, type BookingNotifyRecipient, type BookingQuestion, type BookingQuestionInput, type BookingSettings, type BookingSettingsChanges, type BookingSettingsResult, type BookingSettingsState, type BookingWorkingHours, type Call, type CallAudio, type CallListItem, type CallMoment, type CallParticipant, type CallWebhook, type CallsOptions, type CaptureServerErrorsOptions, type DeleteCallResult, type FollowUp, type FollowUpBooking, type FollowUpCall, type FollowUpDetail, type FollowUpDue, type FollowUpNote, type FollowUpOperator, type FollowUpWriteResult, type GetCallOptions, type Guide, type GuideReadOptions, type GuideSummary, type Lead, type LineCallerResult, type LineCallsOptions, type LineRequestResult, type ListBookingsOptions, type ListCallsOptions, type ListLeadsOptions, type OperatorRingNumber, type OperatorRingNumbersResult, type PhoneLineInfo, type PhoneLineRequest, type PhoneLineStatus, type PhoneLineWebhook, type PlaceCallResult, type RegisteredWebhook, ReportResult, ReportSeverity, ReportType, type RingErrorCode, type RingNumber, type RingNumberList, type RingNumberWriteResult, type ServerReportOptions, type ServerReporterConfig, type ServerReporterIdentity, type SignSessionOptions, addFollowUpNote, addLineCaller, addRingNumber, cancelBooking, captureServerErrors, configureServerReporter, deleteCall, dialFollowUp, disableCalling, discardBookingQuestionsDraft, editFollowUpNote, enableCalling, escapeJsonForScript, getBookingSettings, getCall, getFollowUp, getGuide, getOperatorRingNumbers, getPhoneLine, listBookings, listCalls, listFollowUps, listGuides, listLeads, listRingNumbers, listWebhooks, placeCall, publishBookingQuestions, registerWebhook, removeLineCaller, removeRingNumber, removeWebhook, reportServerError, rescheduleBooking, resetServerReporter, setFollowUpBooking, signSession, submitPhoneKyc, testRingNumber, updateBookingSettings, updateRingNumber };
|
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
|
};
|
|
@@ -887,12 +896,19 @@ function dialFollowUp(externalId, call, options = {}) {
|
|
|
887
896
|
ringNumbers: Array.isArray(d.ringNumbers) ? d.ringNumbers.filter((n) => typeof n === "string") : []
|
|
888
897
|
}));
|
|
889
898
|
}
|
|
899
|
+
function ownerQuery(options) {
|
|
900
|
+
return options.ownerId ? `?ownerId=${encodeURIComponent(options.ownerId)}` : "";
|
|
901
|
+
}
|
|
902
|
+
function operatorQuery(operator, options) {
|
|
903
|
+
const query = new URLSearchParams("email" in operator ? { email: operator.email } : { phone: operator.phone });
|
|
904
|
+
if (options.ownerId) query.set("ownerId", options.ownerId);
|
|
905
|
+
return query.toString();
|
|
906
|
+
}
|
|
890
907
|
async function getOperatorRingNumbers(operator, options = {}) {
|
|
891
908
|
try {
|
|
892
909
|
const key = callsKey(options);
|
|
893
910
|
if (!key) return { ok: false, error: NO_KEY_ERROR };
|
|
894
|
-
const
|
|
895
|
-
const { data, error, code } = await callSdkApi(`/api/v1/sdk/phone-lines/operator?${query.toString()}`, key, options, {
|
|
911
|
+
const { data, error, code } = await callSdkApi(`/api/v1/sdk/phone-lines/operator?${operatorQuery(operator, options)}`, key, options, {
|
|
896
912
|
cache: "no-store"
|
|
897
913
|
});
|
|
898
914
|
if (error !== null || !isRecord(data)) return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
|
|
@@ -931,9 +947,143 @@ async function addLineCaller(caller, options = {}) {
|
|
|
931
947
|
return { ok: false, error: "Could not reach Glitchgrab" };
|
|
932
948
|
}
|
|
933
949
|
}
|
|
950
|
+
async function placeCall(call, options = {}) {
|
|
951
|
+
try {
|
|
952
|
+
const key = callsKey(options);
|
|
953
|
+
if (!key) return { ok: false, error: NO_KEY_ERROR };
|
|
954
|
+
const { data, error, code } = await callSdkApi("/api/v1/sdk/phone-lines/call", key, options, {
|
|
955
|
+
method: "POST",
|
|
956
|
+
body: call,
|
|
957
|
+
cache: "no-store"
|
|
958
|
+
});
|
|
959
|
+
if (error !== null || !isRecord(data) || typeof data.callId !== "string") {
|
|
960
|
+
return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
|
|
961
|
+
}
|
|
962
|
+
return {
|
|
963
|
+
ok: true,
|
|
964
|
+
callId: data.callId,
|
|
965
|
+
ringing: typeof data.ringing === "string" ? data.ringing : "",
|
|
966
|
+
ringNumbers: Array.isArray(data.ringNumbers) ? data.ringNumbers.filter((n) => typeof n === "string") : [],
|
|
967
|
+
from: typeof data.from === "string" ? data.from : ""
|
|
968
|
+
};
|
|
969
|
+
} catch (e) {
|
|
970
|
+
return { ok: false, error: "Could not reach Glitchgrab" };
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
function lineRequestOf(value) {
|
|
974
|
+
if (!isRecord(value) || typeof value.kycStatus !== "string") return null;
|
|
975
|
+
return {
|
|
976
|
+
kycStatus: value.kycStatus,
|
|
977
|
+
kycReason: stringOrNull(value.kycReason),
|
|
978
|
+
enabled: value.enabled === true,
|
|
979
|
+
buyState: typeof value.buyState === "string" ? value.buyState : "NONE",
|
|
980
|
+
buyError: stringOrNull(value.buyError),
|
|
981
|
+
number: stringOrNull(value.number)
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
async function getPhoneLine(params = {}, options = {}) {
|
|
985
|
+
var _a;
|
|
986
|
+
try {
|
|
987
|
+
const key = callsKey(options);
|
|
988
|
+
if (!key) return null;
|
|
989
|
+
const query = params.ownerId ? `?ownerId=${encodeURIComponent(params.ownerId)}` : "";
|
|
990
|
+
const { data, error } = await callSdkApi(`/api/v1/sdk/phone-lines${query}`, key, options, { cache: "no-store" });
|
|
991
|
+
if (error !== null || !isRecord(data)) return null;
|
|
992
|
+
const line = isRecord(data.line) && typeof data.line.number === "string" ? data.line : null;
|
|
993
|
+
return {
|
|
994
|
+
line: line ? {
|
|
995
|
+
number: line.number,
|
|
996
|
+
label: stringOrNull(line.label),
|
|
997
|
+
active: line.active === true,
|
|
998
|
+
callers: (_a = numberOrNull(line.callers)) != null ? _a : 0
|
|
999
|
+
} : null,
|
|
1000
|
+
request: lineRequestOf(data.request)
|
|
1001
|
+
};
|
|
1002
|
+
} catch (e) {
|
|
1003
|
+
return null;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
async function lineRequestCall(path, body, options) {
|
|
1007
|
+
try {
|
|
1008
|
+
const key = callsKey(options);
|
|
1009
|
+
if (!key) return { ok: false, error: NO_KEY_ERROR };
|
|
1010
|
+
const { data, error, code } = await callSdkApi(path, key, options, { method: "POST", body, cache: "no-store" });
|
|
1011
|
+
const request = isRecord(data) ? lineRequestOf(data.request) : null;
|
|
1012
|
+
if (error !== null || !request) return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
|
|
1013
|
+
return { ok: true, request };
|
|
1014
|
+
} catch (e) {
|
|
1015
|
+
return { ok: false, error: "Could not reach Glitchgrab" };
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
function submitPhoneKyc(kyc, options = {}) {
|
|
1019
|
+
const form = new FormData();
|
|
1020
|
+
for (const k of ["ownerId", "businessName", "email", "addressLine1", "city", "state", "postalCode"]) {
|
|
1021
|
+
form.set(k, kyc[k]);
|
|
1022
|
+
}
|
|
1023
|
+
form.set("registrationCertificate", kyc.registrationCertificate, "registration-certificate");
|
|
1024
|
+
form.set("gstCertificate", kyc.gstCertificate, "gst-certificate");
|
|
1025
|
+
return lineRequestCall("/api/v1/sdk/phone-lines/kyc", form, options);
|
|
1026
|
+
}
|
|
1027
|
+
function enableCalling(params, options = {}) {
|
|
1028
|
+
return lineRequestCall("/api/v1/sdk/phone-lines/enable", { ...params, agreedToCharge: true }, options);
|
|
1029
|
+
}
|
|
1030
|
+
function disableCalling(params, options = {}) {
|
|
1031
|
+
return lineRequestCall("/api/v1/sdk/phone-lines/disable", params, options);
|
|
1032
|
+
}
|
|
1033
|
+
async function registerWebhook(webhook, options = {}) {
|
|
1034
|
+
try {
|
|
1035
|
+
const key = callsKey(options);
|
|
1036
|
+
if (!key) return { ok: false, error: NO_KEY_ERROR };
|
|
1037
|
+
const { data, error } = await callSdkApi("/api/v1/sdk/webhooks", key, options, {
|
|
1038
|
+
method: "POST",
|
|
1039
|
+
body: webhook,
|
|
1040
|
+
cache: "no-store"
|
|
1041
|
+
});
|
|
1042
|
+
if (error !== null || !isRecord(data) || typeof data.id !== "string" || typeof data.secret !== "string") {
|
|
1043
|
+
return { ok: false, error: error != null ? error : "Unexpected response" };
|
|
1044
|
+
}
|
|
1045
|
+
return {
|
|
1046
|
+
ok: true,
|
|
1047
|
+
secret: data.secret,
|
|
1048
|
+
webhook: {
|
|
1049
|
+
id: data.id,
|
|
1050
|
+
url: typeof data.url === "string" ? data.url : webhook.url,
|
|
1051
|
+
events: Array.isArray(data.events) ? data.events.filter((e) => typeof e === "string") : []
|
|
1052
|
+
}
|
|
1053
|
+
};
|
|
1054
|
+
} catch (e) {
|
|
1055
|
+
return { ok: false, error: "Could not reach Glitchgrab" };
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
async function listWebhooks(options = {}) {
|
|
1059
|
+
try {
|
|
1060
|
+
const key = callsKey(options);
|
|
1061
|
+
if (!key) return [];
|
|
1062
|
+
const { data, error } = await callSdkApi("/api/v1/sdk/webhooks", key, options, { cache: "no-store" });
|
|
1063
|
+
if (error !== null || !isRecord(data) || !Array.isArray(data.webhooks)) return [];
|
|
1064
|
+
return data.webhooks.filter(isRecord).flatMap(
|
|
1065
|
+
(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") : [] }] : []
|
|
1066
|
+
);
|
|
1067
|
+
} catch (e) {
|
|
1068
|
+
return [];
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
async function removeWebhook(id, options = {}) {
|
|
1072
|
+
try {
|
|
1073
|
+
const key = callsKey(options);
|
|
1074
|
+
if (!key) return { ok: false, error: NO_KEY_ERROR };
|
|
1075
|
+
const { error } = await callSdkApi(`/api/v1/sdk/webhooks/${encodeURIComponent(id)}`, key, options, {
|
|
1076
|
+
method: "DELETE",
|
|
1077
|
+
cache: "no-store"
|
|
1078
|
+
});
|
|
1079
|
+
return error === null ? { ok: true } : { ok: false, error };
|
|
1080
|
+
} catch (e) {
|
|
1081
|
+
return { ok: false, error: "Could not reach Glitchgrab" };
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
934
1084
|
function removeLineCaller(email, options = {}) {
|
|
935
1085
|
return ringNumberWrite(
|
|
936
|
-
`/api/v1/sdk/phone-lines/callers/${encodeURIComponent(email)}`,
|
|
1086
|
+
`/api/v1/sdk/phone-lines/callers/${encodeURIComponent(email)}${ownerQuery(options)}`,
|
|
937
1087
|
"DELETE",
|
|
938
1088
|
void 0,
|
|
939
1089
|
options,
|
|
@@ -958,8 +1108,7 @@ async function listRingNumbers(operator, options = {}) {
|
|
|
958
1108
|
try {
|
|
959
1109
|
const key = callsKey(options);
|
|
960
1110
|
if (!key) return { ok: false, error: NO_KEY_ERROR };
|
|
961
|
-
const
|
|
962
|
-
const { data, error, code } = await callSdkApi(ringNumbersPath(`?${query.toString()}`), key, options, {
|
|
1111
|
+
const { data, error, code } = await callSdkApi(ringNumbersPath(`?${operatorQuery(operator, options)}`), key, options, {
|
|
963
1112
|
cache: "no-store"
|
|
964
1113
|
});
|
|
965
1114
|
if (error !== null || !isRecord(data)) return { ok: false, error: error != null ? error : "Unexpected response", ...code ? { code } : {} };
|
|
@@ -987,20 +1136,27 @@ async function listRingNumbers(operator, options = {}) {
|
|
|
987
1136
|
}
|
|
988
1137
|
}
|
|
989
1138
|
function addRingNumber(operator, number, options = {}) {
|
|
990
|
-
|
|
1139
|
+
const body = { operator, ...number, ...options.ownerId ? { ownerId: options.ownerId } : {} };
|
|
1140
|
+
return ringNumberWrite(ringNumbersPath(), "POST", body, options, (d) => ({
|
|
991
1141
|
id: typeof d.id === "string" ? d.id : "",
|
|
992
1142
|
testRing: d.testRing === "failed" ? "failed" : "ringing",
|
|
993
1143
|
verifyError: stringOrNull(d.verifyError)
|
|
994
1144
|
}));
|
|
995
1145
|
}
|
|
996
1146
|
function updateRingNumber(id, change, options = {}) {
|
|
997
|
-
return ringNumberWrite(ringNumbersPath(`/${encodeURIComponent(id)}`), "PATCH", change, options, () => ({}));
|
|
1147
|
+
return ringNumberWrite(ringNumbersPath(`/${encodeURIComponent(id)}${ownerQuery(options)}`), "PATCH", change, options, () => ({}));
|
|
998
1148
|
}
|
|
999
1149
|
function removeRingNumber(id, options = {}) {
|
|
1000
|
-
return ringNumberWrite(
|
|
1150
|
+
return ringNumberWrite(
|
|
1151
|
+
ringNumbersPath(`/${encodeURIComponent(id)}${ownerQuery(options)}`),
|
|
1152
|
+
"DELETE",
|
|
1153
|
+
void 0,
|
|
1154
|
+
options,
|
|
1155
|
+
() => ({})
|
|
1156
|
+
);
|
|
1001
1157
|
}
|
|
1002
1158
|
function testRingNumber(id, options = {}) {
|
|
1003
|
-
return ringNumberWrite(ringNumbersPath(`/${encodeURIComponent(id)}/verify`), "POST", void 0, options, (d) => ({
|
|
1159
|
+
return ringNumberWrite(ringNumbersPath(`/${encodeURIComponent(id)}/verify${ownerQuery(options)}`), "POST", void 0, options, (d) => ({
|
|
1004
1160
|
verified: d.verified === true
|
|
1005
1161
|
}));
|
|
1006
1162
|
}
|
|
@@ -1014,28 +1170,36 @@ function testRingNumber(id, options = {}) {
|
|
|
1014
1170
|
configureServerReporter,
|
|
1015
1171
|
deleteCall,
|
|
1016
1172
|
dialFollowUp,
|
|
1173
|
+
disableCalling,
|
|
1017
1174
|
discardBookingQuestionsDraft,
|
|
1018
1175
|
editFollowUpNote,
|
|
1176
|
+
enableCalling,
|
|
1019
1177
|
escapeJsonForScript,
|
|
1020
1178
|
getBookingSettings,
|
|
1021
1179
|
getCall,
|
|
1022
1180
|
getFollowUp,
|
|
1023
1181
|
getGuide,
|
|
1024
1182
|
getOperatorRingNumbers,
|
|
1183
|
+
getPhoneLine,
|
|
1025
1184
|
listBookings,
|
|
1026
1185
|
listCalls,
|
|
1027
1186
|
listFollowUps,
|
|
1028
1187
|
listGuides,
|
|
1029
1188
|
listLeads,
|
|
1030
1189
|
listRingNumbers,
|
|
1190
|
+
listWebhooks,
|
|
1191
|
+
placeCall,
|
|
1031
1192
|
publishBookingQuestions,
|
|
1193
|
+
registerWebhook,
|
|
1032
1194
|
removeLineCaller,
|
|
1033
1195
|
removeRingNumber,
|
|
1196
|
+
removeWebhook,
|
|
1034
1197
|
reportServerError,
|
|
1035
1198
|
rescheduleBooking,
|
|
1036
1199
|
resetServerReporter,
|
|
1037
1200
|
setFollowUpBooking,
|
|
1038
1201
|
signSession,
|
|
1202
|
+
submitPhoneKyc,
|
|
1039
1203
|
testRingNumber,
|
|
1040
1204
|
updateBookingSettings,
|
|
1041
1205
|
updateRingNumber
|