@formant/data-sdk 1.3.0 → 1.3.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 +3 -0
- package/dist/data-sdk.es.js +519 -583
- package/dist/data-sdk.umd.js +9 -9
- package/dist/types/data-sdk/src/main.d.ts +20 -15
- package/package.json +4 -2
package/dist/data-sdk.es.js
CHANGED
|
@@ -900,11 +900,6 @@ function isFastBuffer(e) {
|
|
|
900
900
|
function isSlowBuffer(e) {
|
|
901
901
|
return typeof e.readFloatLE == "function" && typeof e.slice == "function" && isFastBuffer(e.slice(0, 0));
|
|
902
902
|
}
|
|
903
|
-
function defined(e, t) {
|
|
904
|
-
if (e !== void 0)
|
|
905
|
-
return e;
|
|
906
|
-
throw new Error(t || "Value is undefined");
|
|
907
|
-
}
|
|
908
903
|
const DEFAULT_FORMANT_API_URL = "https://api.formant.io";
|
|
909
904
|
function whichFormantApiUrl(e, t) {
|
|
910
905
|
if (t.get("formant_stage"))
|
|
@@ -931,507 +926,153 @@ const FORMANT_API_URL = whichFormantApiUrl(
|
|
|
931
926
|
new URLSearchParams(
|
|
932
927
|
typeof window < "u" ? window.location.search : void 0
|
|
933
928
|
)
|
|
934
|
-
)
|
|
935
|
-
|
|
936
|
-
second,
|
|
937
|
-
minute,
|
|
938
|
-
hour,
|
|
939
|
-
day,
|
|
940
|
-
week,
|
|
941
|
-
month,
|
|
942
|
-
year
|
|
943
|
-
};
|
|
944
|
-
function filterDataByType(e, t) {
|
|
945
|
-
return e.filter((n) => t.includes(n.type));
|
|
946
|
-
}
|
|
947
|
-
function filterDataByTime(e, t, n) {
|
|
948
|
-
const r = t.getTime(), i = n.getTime();
|
|
949
|
-
return e.map((s) => ({
|
|
950
|
-
...s,
|
|
951
|
-
points: s.points.filter(
|
|
952
|
-
([l]) => l >= r && l < i
|
|
953
|
-
)
|
|
954
|
-
})).filter(({ points: s }) => s.length > 0);
|
|
955
|
-
}
|
|
956
|
-
function fork(e) {
|
|
957
|
-
}
|
|
958
|
-
class StoreCache {
|
|
929
|
+
);
|
|
930
|
+
class AuthenticationStore {
|
|
959
931
|
constructor({
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
Te(this, "
|
|
965
|
-
Te(this, "
|
|
966
|
-
Te(this, "
|
|
967
|
-
this
|
|
932
|
+
apiUrl: t,
|
|
933
|
+
refreshAuthToken: n,
|
|
934
|
+
addAccessTokenRefreshListener: r
|
|
935
|
+
}) {
|
|
936
|
+
Te(this, "_refreshToken");
|
|
937
|
+
Te(this, "_isShareToken", !1);
|
|
938
|
+
Te(this, "_currentOrganization");
|
|
939
|
+
Te(this, "_currentUser");
|
|
940
|
+
Te(this, "_defaultDeviceId");
|
|
941
|
+
Te(this, "_token");
|
|
942
|
+
Te(this, "_waitingForAuth", /* @__PURE__ */ new Set());
|
|
943
|
+
Te(this, "_refreshTimer");
|
|
944
|
+
Te(this, "_apiUrl");
|
|
945
|
+
Te(this, "_refreshAuthToken");
|
|
946
|
+
Te(this, "_addAccessTokenRefreshListener");
|
|
947
|
+
this._apiUrl = t, this._refreshAuthToken = n, this._addAccessTokenRefreshListener = r;
|
|
968
948
|
}
|
|
969
|
-
get(
|
|
970
|
-
|
|
971
|
-
return (i === void 0 || s && (s == null ? void 0 : s.expiration.getTime()) < Date.now()) && !(s != null && s.generating) && n && this.generate(t, n()), i === void 0 && s && s.lastValue !== void 0 ? s.lastValue : i;
|
|
949
|
+
get token() {
|
|
950
|
+
return this._token;
|
|
972
951
|
}
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
this.metadata.set(r, {
|
|
976
|
-
generating: !1,
|
|
977
|
-
expiration: new Date(Date.now() + this.timeout),
|
|
978
|
-
lastValue: n
|
|
979
|
-
}), this.entries.set(r, n), this.metadata.size > this.capacity && this.deleteOldestEntry();
|
|
952
|
+
get currentUser() {
|
|
953
|
+
return this._currentUser;
|
|
980
954
|
}
|
|
981
|
-
|
|
982
|
-
|
|
955
|
+
get currentOrganization() {
|
|
956
|
+
return this._currentOrganization;
|
|
983
957
|
}
|
|
984
|
-
|
|
985
|
-
|
|
958
|
+
get defaultDeviceId() {
|
|
959
|
+
return this._defaultDeviceId;
|
|
986
960
|
}
|
|
987
|
-
|
|
988
|
-
|
|
961
|
+
/**
|
|
962
|
+
* @deprecated Do not use directly. This will be removed in future versions of the API
|
|
963
|
+
*/
|
|
964
|
+
get refreshToken() {
|
|
965
|
+
return this._refreshToken;
|
|
989
966
|
}
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
);
|
|
996
|
-
this.clearKey(t);
|
|
967
|
+
/**
|
|
968
|
+
* @deprecated Do not use directly. This will be removed in future versions of the API
|
|
969
|
+
*/
|
|
970
|
+
get isShareToken() {
|
|
971
|
+
return this._isShareToken;
|
|
997
972
|
}
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
973
|
+
async login(t, n) {
|
|
974
|
+
try {
|
|
975
|
+
const r = await fetch(`${this._apiUrl}/v1/admin/auth/login`, {
|
|
976
|
+
method: "POST",
|
|
977
|
+
body: JSON.stringify({ email: t, password: n }),
|
|
978
|
+
headers: {
|
|
979
|
+
"Content-Type": "application/json"
|
|
980
|
+
}
|
|
981
|
+
}), i = await r.json();
|
|
982
|
+
if (r.status !== 200)
|
|
983
|
+
throw new Error(i.message);
|
|
984
|
+
return await this.loginWithToken(
|
|
985
|
+
i.authentication.accessToken,
|
|
986
|
+
i.authentication.refreshToken
|
|
987
|
+
), i.authentication;
|
|
988
|
+
} catch (r) {
|
|
989
|
+
return console.error("login() failed", { err: r }), this._waitingForAuth.forEach((i) => i(!1)), this._waitingForAuth.clear(), Promise.reject(r);
|
|
990
|
+
}
|
|
1010
991
|
}
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
992
|
+
async loginWithToken(t, n) {
|
|
993
|
+
var i;
|
|
994
|
+
const r = JSON.parse(atob(t.split(".")[1]));
|
|
995
|
+
try {
|
|
996
|
+
let s;
|
|
997
|
+
if (this._isShareToken = r["formant:claims"] && r["formant:claims"].type == "share", r["formant:claims"] && (this._currentOrganization = r["formant:claims"].organizationId), r["custom:organization_id"] && (this._currentOrganization = r["custom:organization_id"]), this._isShareToken || (s = r.sub), r["formant:claims"] && r["formant:claims"].userId && (s = r["formant:claims"].userId), s && ((i = this._currentUser) == null ? void 0 : i.id) !== s) {
|
|
998
|
+
const l = await fetch(`${this._apiUrl}/v1/admin/users/${s}`, {
|
|
999
|
+
method: "GET",
|
|
1000
|
+
headers: {
|
|
1001
|
+
"Content-Type": "application/json",
|
|
1002
|
+
Authorization: "Bearer " + t
|
|
1003
|
+
}
|
|
1004
|
+
}), o = await l.json();
|
|
1005
|
+
if (l.status !== 200)
|
|
1006
|
+
throw new Error(o.message);
|
|
1007
|
+
this._currentUser = o;
|
|
1008
|
+
}
|
|
1009
|
+
this._token = t, this._waitingForAuth.forEach((l) => l(!0));
|
|
1010
|
+
} catch (s) {
|
|
1011
|
+
console.error("loginWithToken() failed", { err: s }), this._waitingForAuth.forEach((l) => l(!1));
|
|
1012
|
+
} finally {
|
|
1013
|
+
this._waitingForAuth.clear();
|
|
1014
|
+
}
|
|
1015
|
+
n && (this._refreshToken = n, setInterval(async () => {
|
|
1016
|
+
if (this._refreshToken) {
|
|
1017
|
+
const l = await (await fetch(`${this._apiUrl}/v1/admin/auth/refresh`, {
|
|
1018
|
+
method: "POST",
|
|
1019
|
+
headers: {
|
|
1020
|
+
"Content-Type": "application/json"
|
|
1021
|
+
},
|
|
1022
|
+
body: JSON.stringify({
|
|
1023
|
+
refreshToken: this._refreshToken
|
|
1024
|
+
})
|
|
1025
|
+
})).json();
|
|
1026
|
+
this._token = l.authentication.accessToken;
|
|
1027
|
+
}
|
|
1028
|
+
}, 1e3 * 60 * 60));
|
|
1022
1029
|
}
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
...t,
|
|
1026
|
-
names: [...n],
|
|
1027
|
-
types: [...r]
|
|
1028
|
-
}, c = this.query(o, i, s, l);
|
|
1029
|
-
return c === void 0 || c === "too much data" ? c : filterDataByType(c, r);
|
|
1030
|
+
isAuthenticated() {
|
|
1031
|
+
return this._token !== void 0;
|
|
1030
1032
|
}
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
latestOnly: i
|
|
1037
|
-
}, l = r > addSeconds(/* @__PURE__ */ new Date(), -20);
|
|
1038
|
-
let o;
|
|
1039
|
-
return l ? o = this.liveQueryCache(s) : o = this.queryCache(s), !o || o === "too much data" || i ? o : filterDataByTime(o, n, r);
|
|
1033
|
+
/**
|
|
1034
|
+
* @deprecated use currentUser property instead.
|
|
1035
|
+
*/
|
|
1036
|
+
getCurrentUser() {
|
|
1037
|
+
return this._currentUser;
|
|
1040
1038
|
}
|
|
1041
|
-
|
|
1042
|
-
return this.
|
|
1043
|
-
|
|
1044
|
-
return await Fleet.queryTelemetry(t);
|
|
1045
|
-
} catch (n) {
|
|
1046
|
-
throw n;
|
|
1047
|
-
}
|
|
1039
|
+
async waitTilAuthenticated() {
|
|
1040
|
+
return this.token !== void 0 ? !0 : new Promise((t) => {
|
|
1041
|
+
this._waitingForAuth.add(t);
|
|
1048
1042
|
});
|
|
1049
1043
|
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1044
|
+
async listenForRefresh() {
|
|
1045
|
+
const n = () => {
|
|
1046
|
+
this._refreshTimer = void 0, this._refreshAuthToken();
|
|
1047
|
+
};
|
|
1048
|
+
this._addAccessTokenRefreshListener((r) => {
|
|
1049
|
+
this._refreshTimer && clearTimeout(this._refreshTimer), this._refreshTimer = setTimeout(n, 36e5), this.loginWithToken(r);
|
|
1050
|
+
}), this._refreshTimer = setTimeout(n, 36e5);
|
|
1051
|
+
}
|
|
1052
|
+
async forgotPassword(t) {
|
|
1053
|
+
await fetch(`${this._apiUrl}/v1/admin/auth/forgot-password`, {
|
|
1054
|
+
method: "POST",
|
|
1055
|
+
body: JSON.stringify({ email: t }),
|
|
1056
|
+
headers: {
|
|
1057
|
+
"Content-Type": "application/json"
|
|
1056
1058
|
}
|
|
1057
1059
|
});
|
|
1058
1060
|
}
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
const n = t.get("configuration");
|
|
1072
|
-
return n === null || n.trim() === "" ? void 0 : (await (await fetch(
|
|
1073
|
-
`${FORMANT_API_URL}/v1/admin/module-configurations/` + n,
|
|
1061
|
+
/**
|
|
1062
|
+
* @example
|
|
1063
|
+
* // Body
|
|
1064
|
+
* await this.confirmForgotPassword({
|
|
1065
|
+
* email: "joe@gmail.com"
|
|
1066
|
+
* confirmationCode: "1",
|
|
1067
|
+
* newPassword: "NewPassword"
|
|
1068
|
+
* });
|
|
1069
|
+
*/
|
|
1070
|
+
async confirmForgotPassword(t) {
|
|
1071
|
+
return (await fetch(
|
|
1072
|
+
`${this._apiUrl}/v1/admin/auth/confirm-forgot-password`,
|
|
1074
1073
|
{
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
Authorization: "Bearer " + Authentication.token
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
)).json()).configuration;
|
|
1081
|
-
}
|
|
1082
|
-
static isModule() {
|
|
1083
|
-
return this.getCurrentModuleContext() !== null;
|
|
1084
|
-
}
|
|
1085
|
-
static goToTime(t) {
|
|
1086
|
-
this.sendAppMessage({
|
|
1087
|
-
type: "go_to_time",
|
|
1088
|
-
time: t.getTime()
|
|
1089
|
-
});
|
|
1090
|
-
}
|
|
1091
|
-
static goToDevice(t) {
|
|
1092
|
-
this.sendAppMessage({
|
|
1093
|
-
type: "go_to_device",
|
|
1094
|
-
deviceId: t
|
|
1095
|
-
});
|
|
1096
|
-
}
|
|
1097
|
-
static showMessage(t) {
|
|
1098
|
-
this.sendAppMessage({ type: "show_message", message: t });
|
|
1099
|
-
}
|
|
1100
|
-
static requestModuleData() {
|
|
1101
|
-
const t = this.getCurrentModuleContext();
|
|
1102
|
-
if (!t)
|
|
1103
|
-
throw new Error("No module context");
|
|
1104
|
-
this.sendAppMessage({
|
|
1105
|
-
type: "request_module_data",
|
|
1106
|
-
module: t
|
|
1107
|
-
});
|
|
1108
|
-
}
|
|
1109
|
-
static setModuleDateTimeRange(t, n) {
|
|
1110
|
-
const r = this.getCurrentModuleContext();
|
|
1111
|
-
if (!r)
|
|
1112
|
-
throw new Error("No module context");
|
|
1113
|
-
this.sendAppMessage({
|
|
1114
|
-
type: "set_module_data_time_range",
|
|
1115
|
-
module: r,
|
|
1116
|
-
before: t,
|
|
1117
|
-
after: n || 0
|
|
1118
|
-
});
|
|
1119
|
-
}
|
|
1120
|
-
static refreshAuthToken() {
|
|
1121
|
-
const t = this.getCurrentModuleContext();
|
|
1122
|
-
if (!t)
|
|
1123
|
-
throw new Error("No module context");
|
|
1124
|
-
this.sendAppMessage({
|
|
1125
|
-
type: "refresh_auth_token",
|
|
1126
|
-
module: t
|
|
1127
|
-
});
|
|
1128
|
-
}
|
|
1129
|
-
static sendChannelData(t, n) {
|
|
1130
|
-
const r = this.getCurrentModuleContext();
|
|
1131
|
-
if (!r)
|
|
1132
|
-
throw new Error("No module context");
|
|
1133
|
-
this.sendAppMessage({
|
|
1134
|
-
type: "send_channel_data",
|
|
1135
|
-
source: r,
|
|
1136
|
-
channel: t,
|
|
1137
|
-
data: n
|
|
1138
|
-
});
|
|
1139
|
-
}
|
|
1140
|
-
static setupModuleMenus(t) {
|
|
1141
|
-
const n = this.getCurrentModuleContext();
|
|
1142
|
-
if (!n)
|
|
1143
|
-
throw new Error("No module context");
|
|
1144
|
-
this.sendAppMessage({
|
|
1145
|
-
type: "setup_module_menus",
|
|
1146
|
-
module: n,
|
|
1147
|
-
menus: t
|
|
1148
|
-
});
|
|
1149
|
-
}
|
|
1150
|
-
static addMenuListener(t) {
|
|
1151
|
-
window.addEventListener("message", (n) => {
|
|
1152
|
-
const r = n.data;
|
|
1153
|
-
r.type === "module_menu_item_clicked" && t(r.menu);
|
|
1154
|
-
});
|
|
1155
|
-
}
|
|
1156
|
-
static addAccessTokenRefreshListener(t) {
|
|
1157
|
-
window.addEventListener("message", (n) => {
|
|
1158
|
-
const r = n.data;
|
|
1159
|
-
r.type === "auth_token" && t(r.token);
|
|
1160
|
-
});
|
|
1161
|
-
}
|
|
1162
|
-
static addModuleDataListener(t) {
|
|
1163
|
-
const n = this.getCurrentModuleContext();
|
|
1164
|
-
n && this.sendAppMessage({ type: "request_module_data", module: n }), window.addEventListener("message", (r) => {
|
|
1165
|
-
const i = r.data;
|
|
1166
|
-
i.type === "module_data" && t({
|
|
1167
|
-
streams: i.streams,
|
|
1168
|
-
time: i.time,
|
|
1169
|
-
queryRange: i.queryRange
|
|
1170
|
-
});
|
|
1171
|
-
});
|
|
1172
|
-
}
|
|
1173
|
-
static addOverviewDeviceListener(t) {
|
|
1174
|
-
this.sendAppMessage({ type: "request_devices" });
|
|
1175
|
-
const n = (r) => {
|
|
1176
|
-
const i = r.data;
|
|
1177
|
-
i.type === "overview_devices" && t(i.data);
|
|
1178
|
-
};
|
|
1179
|
-
return window.addEventListener("message", n), () => window.removeEventListener("message", n);
|
|
1180
|
-
}
|
|
1181
|
-
static addStreamListener(t, n, r) {
|
|
1182
|
-
const i = (s) => {
|
|
1183
|
-
const l = s.data;
|
|
1184
|
-
if (l.type === "module_data") {
|
|
1185
|
-
const { start: o, end: c } = l.queryRange;
|
|
1186
|
-
r(
|
|
1187
|
-
queryStore.moduleQuery(
|
|
1188
|
-
{},
|
|
1189
|
-
t,
|
|
1190
|
-
n,
|
|
1191
|
-
new Date(o),
|
|
1192
|
-
new Date(c),
|
|
1193
|
-
!1
|
|
1194
|
-
)
|
|
1195
|
-
);
|
|
1196
|
-
}
|
|
1197
|
-
};
|
|
1198
|
-
return window.addEventListener("message", i), () => window.removeEventListener("message", i);
|
|
1199
|
-
}
|
|
1200
|
-
static addModuleConfigurationListener(t) {
|
|
1201
|
-
window.addEventListener("message", (n) => {
|
|
1202
|
-
const r = n.data;
|
|
1203
|
-
r.type === "module_configuration" && t(r);
|
|
1204
|
-
});
|
|
1205
|
-
}
|
|
1206
|
-
static addChannelDataListener(t, n) {
|
|
1207
|
-
window.addEventListener("message", (r) => {
|
|
1208
|
-
const i = r.data;
|
|
1209
|
-
i.type === "channel_data" && i.channel === t && n({
|
|
1210
|
-
source: i.source,
|
|
1211
|
-
data: i.data
|
|
1212
|
-
});
|
|
1213
|
-
});
|
|
1214
|
-
}
|
|
1215
|
-
static async prompt(t, n) {
|
|
1216
|
-
return new Promise((r) => {
|
|
1217
|
-
const i = Math.random().toString();
|
|
1218
|
-
this.sendAppMessage({
|
|
1219
|
-
type: "prompt",
|
|
1220
|
-
promptId: i,
|
|
1221
|
-
schema: t,
|
|
1222
|
-
okText: n == null ? void 0 : n.okText,
|
|
1223
|
-
cancelText: n == null ? void 0 : n.cancelText
|
|
1224
|
-
});
|
|
1225
|
-
const s = (l) => {
|
|
1226
|
-
const o = l.data;
|
|
1227
|
-
o.type === "prompt_response" && o.promptId === i && r(o.data), window.removeEventListener("message", s);
|
|
1228
|
-
};
|
|
1229
|
-
window.addEventListener("message", s);
|
|
1230
|
-
});
|
|
1231
|
-
}
|
|
1232
|
-
static async getDate(t, n, r) {
|
|
1233
|
-
return new Promise((i) => {
|
|
1234
|
-
this.sendAppMessage({
|
|
1235
|
-
type: "request_date",
|
|
1236
|
-
minTime: n,
|
|
1237
|
-
maxTime: r,
|
|
1238
|
-
time: t
|
|
1239
|
-
});
|
|
1240
|
-
const s = (l) => {
|
|
1241
|
-
const o = l.data;
|
|
1242
|
-
o.type === "date_response" && (window.removeEventListener("message", s), i(o.data));
|
|
1243
|
-
};
|
|
1244
|
-
window.addEventListener("message", s);
|
|
1245
|
-
});
|
|
1246
|
-
}
|
|
1247
|
-
static async disableAnalyticsBottomBar() {
|
|
1248
|
-
this.sendAppMessage({
|
|
1249
|
-
type: "hide_analytics_date_picker"
|
|
1250
|
-
});
|
|
1251
|
-
}
|
|
1252
|
-
static get isOnline() {
|
|
1253
|
-
return Mt._isOnline;
|
|
1254
|
-
}
|
|
1255
|
-
static listenForConnectionEvents() {
|
|
1256
|
-
window.addEventListener("message", this._handleOnlineEvent);
|
|
1257
|
-
}
|
|
1258
|
-
static checkConnection(t = 1e3) {
|
|
1259
|
-
return new Promise((n, r) => {
|
|
1260
|
-
const i = setTimeout(
|
|
1261
|
-
() => r(new Error("deadline expired: took too long")),
|
|
1262
|
-
t
|
|
1263
|
-
), s = (l) => {
|
|
1264
|
-
window.removeEventListener("message", s), clearTimeout(i);
|
|
1265
|
-
const { data: o } = l;
|
|
1266
|
-
o.type === "formant_online" && (this._isOnline = o.online, n(o.online));
|
|
1267
|
-
};
|
|
1268
|
-
window.addEventListener("message", s), this.sendAppMessage({ type: "formant_online" });
|
|
1269
|
-
});
|
|
1270
|
-
}
|
|
1271
|
-
static waitForConnection(t = 5e3) {
|
|
1272
|
-
let n = !1;
|
|
1273
|
-
const r = new Promise((l, o) => {
|
|
1274
|
-
setTimeout(() => {
|
|
1275
|
-
n = !0, o(new Error("deadline expired: took too long"));
|
|
1276
|
-
}, t);
|
|
1277
|
-
}), i = (l) => new Promise((o) => setTimeout(o, l)), s = async () => {
|
|
1278
|
-
for (await i(50); !n && !(this.isOnline || await this.checkConnection); )
|
|
1279
|
-
await i(500);
|
|
1280
|
-
};
|
|
1281
|
-
return Promise.race([r, s()]);
|
|
1282
|
-
}
|
|
1283
|
-
};
|
|
1284
|
-
let App = Mt;
|
|
1285
|
-
Te(App, "_isOnline", null), Te(App, "_handleOnlineEvent", (t) => {
|
|
1286
|
-
const { data: n } = t;
|
|
1287
|
-
n.type === "formant_online" && (Mt._isOnline = n.online);
|
|
1288
|
-
});
|
|
1289
|
-
class AuthenticationStore {
|
|
1290
|
-
constructor({
|
|
1291
|
-
apiUrl: t,
|
|
1292
|
-
refreshAuthToken: n,
|
|
1293
|
-
addAccessTokenRefreshListener: r
|
|
1294
|
-
}) {
|
|
1295
|
-
Te(this, "_refreshToken");
|
|
1296
|
-
Te(this, "_isShareToken", !1);
|
|
1297
|
-
Te(this, "_currentOrganization");
|
|
1298
|
-
Te(this, "_currentUser");
|
|
1299
|
-
Te(this, "_defaultDeviceId");
|
|
1300
|
-
Te(this, "_token");
|
|
1301
|
-
Te(this, "_waitingForAuth", /* @__PURE__ */ new Set());
|
|
1302
|
-
Te(this, "_refreshTimer");
|
|
1303
|
-
Te(this, "_apiUrl");
|
|
1304
|
-
Te(this, "_refreshAuthToken");
|
|
1305
|
-
Te(this, "_addAccessTokenRefreshListener");
|
|
1306
|
-
this._apiUrl = t, this._refreshAuthToken = n, this._addAccessTokenRefreshListener = r;
|
|
1307
|
-
}
|
|
1308
|
-
get token() {
|
|
1309
|
-
return this._token;
|
|
1310
|
-
}
|
|
1311
|
-
get currentUser() {
|
|
1312
|
-
return this._currentUser;
|
|
1313
|
-
}
|
|
1314
|
-
get currentOrganization() {
|
|
1315
|
-
return this._currentOrganization;
|
|
1316
|
-
}
|
|
1317
|
-
get defaultDeviceId() {
|
|
1318
|
-
return this._defaultDeviceId;
|
|
1319
|
-
}
|
|
1320
|
-
/**
|
|
1321
|
-
* @deprecated Do not use directly. This will be removed in future versions of the API
|
|
1322
|
-
*/
|
|
1323
|
-
get refreshToken() {
|
|
1324
|
-
return this._refreshToken;
|
|
1325
|
-
}
|
|
1326
|
-
/**
|
|
1327
|
-
* @deprecated Do not use directly. This will be removed in future versions of the API
|
|
1328
|
-
*/
|
|
1329
|
-
get isShareToken() {
|
|
1330
|
-
return this._isShareToken;
|
|
1331
|
-
}
|
|
1332
|
-
async login(t, n) {
|
|
1333
|
-
try {
|
|
1334
|
-
const r = await fetch(`${this._apiUrl}/v1/admin/auth/login`, {
|
|
1335
|
-
method: "POST",
|
|
1336
|
-
body: JSON.stringify({ email: t, password: n }),
|
|
1337
|
-
headers: {
|
|
1338
|
-
"Content-Type": "application/json"
|
|
1339
|
-
}
|
|
1340
|
-
}), i = await r.json();
|
|
1341
|
-
if (r.status !== 200)
|
|
1342
|
-
throw new Error(i.message);
|
|
1343
|
-
return await this.loginWithToken(
|
|
1344
|
-
i.authentication.accessToken,
|
|
1345
|
-
i.authentication.refreshToken
|
|
1346
|
-
), i.authentication;
|
|
1347
|
-
} catch (r) {
|
|
1348
|
-
return console.error("login() failed", { err: r }), this._waitingForAuth.forEach((i) => i(!1)), this._waitingForAuth.clear(), Promise.reject(r);
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
async loginWithToken(t, n) {
|
|
1352
|
-
var i;
|
|
1353
|
-
const r = JSON.parse(atob(t.split(".")[1]));
|
|
1354
|
-
try {
|
|
1355
|
-
let s;
|
|
1356
|
-
if (this._isShareToken = r["formant:claims"] && r["formant:claims"].type == "share", r["formant:claims"] && (this._currentOrganization = r["formant:claims"].organizationId), r["custom:organization_id"] && (this._currentOrganization = r["custom:organization_id"]), this._isShareToken || (s = r.sub), r["formant:claims"] && r["formant:claims"].userId && (s = r["formant:claims"].userId), s && ((i = this._currentUser) == null ? void 0 : i.id) !== s) {
|
|
1357
|
-
const l = await fetch(`${this._apiUrl}/v1/admin/users/${s}`, {
|
|
1358
|
-
method: "GET",
|
|
1359
|
-
headers: {
|
|
1360
|
-
"Content-Type": "application/json",
|
|
1361
|
-
Authorization: "Bearer " + t
|
|
1362
|
-
}
|
|
1363
|
-
}), o = await l.json();
|
|
1364
|
-
if (l.status !== 200)
|
|
1365
|
-
throw new Error(o.message);
|
|
1366
|
-
this._currentUser = o;
|
|
1367
|
-
}
|
|
1368
|
-
this._token = t, this._waitingForAuth.forEach((l) => l(!0));
|
|
1369
|
-
} catch (s) {
|
|
1370
|
-
console.error("loginWithToken() failed", { err: s }), this._waitingForAuth.forEach((l) => l(!1));
|
|
1371
|
-
} finally {
|
|
1372
|
-
this._waitingForAuth.clear();
|
|
1373
|
-
}
|
|
1374
|
-
n && (this._refreshToken = n, setInterval(async () => {
|
|
1375
|
-
if (this._refreshToken) {
|
|
1376
|
-
const l = await (await fetch(`${this._apiUrl}/v1/admin/auth/refresh`, {
|
|
1377
|
-
method: "POST",
|
|
1378
|
-
headers: {
|
|
1379
|
-
"Content-Type": "application/json"
|
|
1380
|
-
},
|
|
1381
|
-
body: JSON.stringify({
|
|
1382
|
-
refreshToken: this._refreshToken
|
|
1383
|
-
})
|
|
1384
|
-
})).json();
|
|
1385
|
-
this._token = l.authentication.accessToken;
|
|
1386
|
-
}
|
|
1387
|
-
}, 1e3 * 60 * 60));
|
|
1388
|
-
}
|
|
1389
|
-
isAuthenticated() {
|
|
1390
|
-
return this._token !== void 0;
|
|
1391
|
-
}
|
|
1392
|
-
/**
|
|
1393
|
-
* @deprecated use currentUser property instead.
|
|
1394
|
-
*/
|
|
1395
|
-
getCurrentUser() {
|
|
1396
|
-
return this._currentUser;
|
|
1397
|
-
}
|
|
1398
|
-
async waitTilAuthenticated() {
|
|
1399
|
-
return this.token !== void 0 ? !0 : new Promise((t) => {
|
|
1400
|
-
this._waitingForAuth.add(t);
|
|
1401
|
-
});
|
|
1402
|
-
}
|
|
1403
|
-
async listenForRefresh() {
|
|
1404
|
-
const n = () => {
|
|
1405
|
-
this._refreshTimer = void 0, this._refreshAuthToken();
|
|
1406
|
-
};
|
|
1407
|
-
this._addAccessTokenRefreshListener((r) => {
|
|
1408
|
-
this._refreshTimer && clearTimeout(this._refreshTimer), this._refreshTimer = setTimeout(n, 36e5), this.loginWithToken(r);
|
|
1409
|
-
}), this._refreshTimer = setTimeout(n, 36e5);
|
|
1410
|
-
}
|
|
1411
|
-
async forgotPassword(t) {
|
|
1412
|
-
await fetch(`${this._apiUrl}/v1/admin/auth/forgot-password`, {
|
|
1413
|
-
method: "POST",
|
|
1414
|
-
body: JSON.stringify({ email: t }),
|
|
1415
|
-
headers: {
|
|
1416
|
-
"Content-Type": "application/json"
|
|
1417
|
-
}
|
|
1418
|
-
});
|
|
1419
|
-
}
|
|
1420
|
-
/**
|
|
1421
|
-
* @example
|
|
1422
|
-
* // Body
|
|
1423
|
-
* await this.confirmForgotPassword({
|
|
1424
|
-
* email: "joe@gmail.com"
|
|
1425
|
-
* confirmationCode: "1",
|
|
1426
|
-
* newPassword: "NewPassword"
|
|
1427
|
-
* });
|
|
1428
|
-
*/
|
|
1429
|
-
async confirmForgotPassword(t) {
|
|
1430
|
-
return (await fetch(
|
|
1431
|
-
`${this._apiUrl}/v1/admin/auth/confirm-forgot-password`,
|
|
1432
|
-
{
|
|
1433
|
-
method: "POST",
|
|
1434
|
-
body: JSON.stringify(t),
|
|
1074
|
+
method: "POST",
|
|
1075
|
+
body: JSON.stringify(t),
|
|
1435
1076
|
headers: {
|
|
1436
1077
|
"Content-Type": "application/json"
|
|
1437
1078
|
}
|
|
@@ -1477,6 +1118,11 @@ const Authentication = new AuthenticationStore({
|
|
|
1477
1118
|
refreshAuthToken: App.refreshAuthToken,
|
|
1478
1119
|
addAccessTokenRefreshListener: App.addAccessTokenRefreshListener
|
|
1479
1120
|
});
|
|
1121
|
+
function defined(e, t) {
|
|
1122
|
+
if (e !== void 0)
|
|
1123
|
+
return e;
|
|
1124
|
+
throw new Error(t || "Value is undefined");
|
|
1125
|
+
}
|
|
1480
1126
|
var dist = { exports: {} };
|
|
1481
1127
|
/*! For license information please see index.js.LICENSE.txt */
|
|
1482
1128
|
(function(module, exports) {
|
|
@@ -20843,56 +20489,6 @@ const aggregateFunctionMap = {
|
|
|
20843
20489
|
// bg-BG: 'dd.mm.YYYY'
|
|
20844
20490
|
e.split("/")[0] + "/" + e.split("/")[1] + "–" + t.split("/")[0] + "/" + t.split("/")[1]
|
|
20845
20491
|
);
|
|
20846
|
-
function getZeroINumericSet() {
|
|
20847
|
-
return {
|
|
20848
|
-
min: Number.MAX_SAFE_INTEGER,
|
|
20849
|
-
max: 0,
|
|
20850
|
-
sum: 0,
|
|
20851
|
-
count: 0,
|
|
20852
|
-
sumOfSquares: 0
|
|
20853
|
-
};
|
|
20854
|
-
}
|
|
20855
|
-
function reduceNumericStreamAggregates(e) {
|
|
20856
|
-
return e.aggregates.reduce((t, n) => {
|
|
20857
|
-
const r = n[1];
|
|
20858
|
-
return combineNumericAggregates(r, t);
|
|
20859
|
-
}, getZeroINumericSet());
|
|
20860
|
-
}
|
|
20861
|
-
function reduceNumericSetStreamAggregates(e, t) {
|
|
20862
|
-
var n;
|
|
20863
|
-
return (n = e.aggregates.reduce((r, i) => {
|
|
20864
|
-
const s = i[1];
|
|
20865
|
-
return combineNumericSetAggregates(
|
|
20866
|
-
s,
|
|
20867
|
-
r
|
|
20868
|
-
);
|
|
20869
|
-
}, {})[t]) == null ? void 0 : n.value;
|
|
20870
|
-
}
|
|
20871
|
-
function combineNumericAggregates(e, t) {
|
|
20872
|
-
return {
|
|
20873
|
-
min: Math.min(e.min, t.min),
|
|
20874
|
-
max: Math.max(e.max, t.max),
|
|
20875
|
-
sum: e.sum + t.sum,
|
|
20876
|
-
count: e.count + t.count,
|
|
20877
|
-
sumOfSquares: e.sumOfSquares + t.sumOfSquares
|
|
20878
|
-
};
|
|
20879
|
-
}
|
|
20880
|
-
function combineNumericSetAggregates(e, t) {
|
|
20881
|
-
return Object.keys(e).reduce((n, r) => {
|
|
20882
|
-
var i;
|
|
20883
|
-
return {
|
|
20884
|
-
...n,
|
|
20885
|
-
[r]: {
|
|
20886
|
-
value: combineNumericAggregates(
|
|
20887
|
-
e[r].value,
|
|
20888
|
-
((i = t[r]) == null ? void 0 : i.value) ?? getZeroINumericSet()
|
|
20889
|
-
),
|
|
20890
|
-
unit: e[r].unit
|
|
20891
|
-
}
|
|
20892
|
-
};
|
|
20893
|
-
}, {});
|
|
20894
|
-
}
|
|
20895
|
-
const timeout = (e) => new Promise((t) => setTimeout(t, e * 1e3));
|
|
20896
20492
|
function defaultSetTimout() {
|
|
20897
20493
|
throw new Error("setTimeout has not been defined");
|
|
20898
20494
|
}
|
|
@@ -23753,9 +23349,6 @@ Object.keys(codes).forEach(function(e) {
|
|
|
23753
23349
|
function deflateSync(e, t) {
|
|
23754
23350
|
return zlibBufferSync(new Deflate(t), e);
|
|
23755
23351
|
}
|
|
23756
|
-
function inflateSync(e, t) {
|
|
23757
|
-
return zlibBufferSync(new Inflate(t), e);
|
|
23758
|
-
}
|
|
23759
23352
|
function zlibBufferSync(e, t) {
|
|
23760
23353
|
if (typeof t == "string" && (t = new Buffer(t)), !Buffer.isBuffer(t))
|
|
23761
23354
|
throw new TypeError("Not a string or buffer");
|
|
@@ -23962,9 +23555,6 @@ function serializeHash(e) {
|
|
|
23962
23555
|
"base64"
|
|
23963
23556
|
);
|
|
23964
23557
|
}
|
|
23965
|
-
function deserializeHash(e) {
|
|
23966
|
-
return JSON.parse(inflateSync(Buffer.from(e, "base64")).toString("utf8"));
|
|
23967
|
-
}
|
|
23968
23558
|
const isRtcPeer = (e) => e !== void 0 && e.capabilities !== void 0 && e.capabilitySet !== void 0;
|
|
23969
23559
|
class DataChannel {
|
|
23970
23560
|
constructor(t) {
|
|
@@ -25404,49 +24994,404 @@ const at = class {
|
|
|
25404
24994
|
}
|
|
25405
24995
|
})).json();
|
|
25406
24996
|
}
|
|
25407
|
-
static async deleteFleet(t) {
|
|
25408
|
-
if (!Authentication.token)
|
|
25409
|
-
throw new Error("Not authenticated");
|
|
25410
|
-
await fetch(`${FORMANT_API_URL}/v1/admin/fleets/${t}`, {
|
|
25411
|
-
method: "DELETE",
|
|
25412
|
-
headers: {
|
|
25413
|
-
"Content-Type": "application/json",
|
|
25414
|
-
Authorization: "Bearer " + Authentication.token
|
|
24997
|
+
static async deleteFleet(t) {
|
|
24998
|
+
if (!Authentication.token)
|
|
24999
|
+
throw new Error("Not authenticated");
|
|
25000
|
+
await fetch(`${FORMANT_API_URL}/v1/admin/fleets/${t}`, {
|
|
25001
|
+
method: "DELETE",
|
|
25002
|
+
headers: {
|
|
25003
|
+
"Content-Type": "application/json",
|
|
25004
|
+
Authorization: "Bearer " + Authentication.token
|
|
25005
|
+
}
|
|
25006
|
+
});
|
|
25007
|
+
}
|
|
25008
|
+
static async addDeviceToFleet(t, n) {
|
|
25009
|
+
if (!Authentication.token)
|
|
25010
|
+
throw new Error("Not authenticated");
|
|
25011
|
+
return await (await fetch(
|
|
25012
|
+
`${FORMANT_API_URL}/v1/admin/devices/${t}`,
|
|
25013
|
+
{
|
|
25014
|
+
method: "PATCH",
|
|
25015
|
+
body: JSON.stringify({ fleetId: n }),
|
|
25016
|
+
headers: {
|
|
25017
|
+
"Content-Type": "application/json",
|
|
25018
|
+
Authorization: "Bearer " + Authentication.token
|
|
25019
|
+
}
|
|
25020
|
+
}
|
|
25021
|
+
)).json();
|
|
25022
|
+
}
|
|
25023
|
+
static async getFleetDevices(t) {
|
|
25024
|
+
if (!Authentication.token)
|
|
25025
|
+
throw new Error("Not authenticated");
|
|
25026
|
+
return (await (await fetch(
|
|
25027
|
+
`${FORMANT_API_URL}/v1/admin/fleets/${t}/devices`,
|
|
25028
|
+
{
|
|
25029
|
+
method: "GET",
|
|
25030
|
+
headers: {
|
|
25031
|
+
"Content-Type": "application/json",
|
|
25032
|
+
Authorization: "Bearer " + Authentication.token
|
|
25033
|
+
}
|
|
25034
|
+
}
|
|
25035
|
+
)).json()).items;
|
|
25036
|
+
}
|
|
25037
|
+
};
|
|
25038
|
+
let Fleet = at;
|
|
25039
|
+
Te(Fleet, "defaultDeviceId"), Te(Fleet, "knownContext", []);
|
|
25040
|
+
const millisecond = 1, second = 1e3, minute = 60 * second, hour = 60 * minute, day = 24 * hour, week = 7 * day, month = 30 * day, year = 365 * day, duration = {
|
|
25041
|
+
millisecond,
|
|
25042
|
+
second,
|
|
25043
|
+
minute,
|
|
25044
|
+
hour,
|
|
25045
|
+
day,
|
|
25046
|
+
week,
|
|
25047
|
+
month,
|
|
25048
|
+
year
|
|
25049
|
+
};
|
|
25050
|
+
function filterDataByType(e, t) {
|
|
25051
|
+
return e.filter((n) => t.includes(n.type));
|
|
25052
|
+
}
|
|
25053
|
+
function filterDataByTime(e, t, n) {
|
|
25054
|
+
const r = t.getTime(), i = n.getTime();
|
|
25055
|
+
return e.map((s) => ({
|
|
25056
|
+
...s,
|
|
25057
|
+
points: s.points.filter(
|
|
25058
|
+
([l]) => l >= r && l < i
|
|
25059
|
+
)
|
|
25060
|
+
})).filter(({ points: s }) => s.length > 0);
|
|
25061
|
+
}
|
|
25062
|
+
function fork(e) {
|
|
25063
|
+
}
|
|
25064
|
+
class StoreCache {
|
|
25065
|
+
constructor({
|
|
25066
|
+
capacity: t,
|
|
25067
|
+
timeout: n
|
|
25068
|
+
} = {}) {
|
|
25069
|
+
Te(this, "entries", /* @__PURE__ */ new Map());
|
|
25070
|
+
Te(this, "metadata", /* @__PURE__ */ new Map());
|
|
25071
|
+
Te(this, "capacity");
|
|
25072
|
+
Te(this, "timeout");
|
|
25073
|
+
this.capacity = t || 1e4, this.timeout = n || duration.minute;
|
|
25074
|
+
}
|
|
25075
|
+
get(t, n) {
|
|
25076
|
+
const r = this.keyToCacheKey(t), i = this.entries.get(r), s = this.metadata.get(r);
|
|
25077
|
+
return (i === void 0 || s && (s == null ? void 0 : s.expiration.getTime()) < Date.now()) && !(s != null && s.generating) && n && this.generate(t, n()), i === void 0 && s && s.lastValue !== void 0 ? s.lastValue : i;
|
|
25078
|
+
}
|
|
25079
|
+
set(t, n) {
|
|
25080
|
+
const r = this.keyToCacheKey(t);
|
|
25081
|
+
this.metadata.set(r, {
|
|
25082
|
+
generating: !1,
|
|
25083
|
+
expiration: new Date(Date.now() + this.timeout),
|
|
25084
|
+
lastValue: n
|
|
25085
|
+
}), this.entries.set(r, n), this.metadata.size > this.capacity && this.deleteOldestEntry();
|
|
25086
|
+
}
|
|
25087
|
+
clear() {
|
|
25088
|
+
this.entries.clear(), [...this.metadata.values()].forEach((t) => t.generating = !1);
|
|
25089
|
+
}
|
|
25090
|
+
clearKey(t) {
|
|
25091
|
+
this.metadata.delete(t), this.entries.delete(t);
|
|
25092
|
+
}
|
|
25093
|
+
keyToCacheKey(t) {
|
|
25094
|
+
return JSON.stringify(t);
|
|
25095
|
+
}
|
|
25096
|
+
deleteOldestEntry() {
|
|
25097
|
+
if (this.metadata.size < 1)
|
|
25098
|
+
return;
|
|
25099
|
+
const [t] = [...this.metadata.entries()].reduce(
|
|
25100
|
+
([n, r], [i, s]) => s.expiration.getTime() < r.expiration.getTime() ? [i, s] : [n, r]
|
|
25101
|
+
);
|
|
25102
|
+
this.clearKey(t);
|
|
25103
|
+
}
|
|
25104
|
+
generate(t, n) {
|
|
25105
|
+
const r = this.keyToCacheKey(t), i = this.metadata.get(r) || {};
|
|
25106
|
+
this.metadata.set(r, {
|
|
25107
|
+
...i,
|
|
25108
|
+
generating: !0,
|
|
25109
|
+
expiration: new Date(Date.now() + this.timeout)
|
|
25110
|
+
}), setTimeout(() => {
|
|
25111
|
+
n.then((s) => {
|
|
25112
|
+
const l = this.metadata.get(r);
|
|
25113
|
+
!(l != null && l.generating) || this.set(t, s);
|
|
25114
|
+
});
|
|
25115
|
+
}, 0);
|
|
25116
|
+
}
|
|
25117
|
+
}
|
|
25118
|
+
class QueryStore {
|
|
25119
|
+
constructor() {
|
|
25120
|
+
Te(this, "queryStoreCache", new StoreCache({
|
|
25121
|
+
capacity: 1e4,
|
|
25122
|
+
timeout: 20 * duration.second
|
|
25123
|
+
}));
|
|
25124
|
+
Te(this, "liveQueryStoreCache", new StoreCache({
|
|
25125
|
+
capacity: 1e4,
|
|
25126
|
+
timeout: 200 * duration.millisecond
|
|
25127
|
+
}));
|
|
25128
|
+
}
|
|
25129
|
+
moduleQuery(t, n, r, i, s, l = !1) {
|
|
25130
|
+
const o = {
|
|
25131
|
+
...t,
|
|
25132
|
+
names: [...n],
|
|
25133
|
+
types: [...r]
|
|
25134
|
+
}, c = this.query(o, i, s, l);
|
|
25135
|
+
return c === void 0 || c === "too much data" ? c : filterDataByType(c, r);
|
|
25136
|
+
}
|
|
25137
|
+
query(t, n, r, i = !1) {
|
|
25138
|
+
const s = {
|
|
25139
|
+
...t,
|
|
25140
|
+
start: startOfMinute(n).toISOString(),
|
|
25141
|
+
end: i ? r.toISOString() : addMinutes(roundToNearestMinutes(r), 1).toISOString(),
|
|
25142
|
+
latestOnly: i
|
|
25143
|
+
}, l = r > addSeconds(/* @__PURE__ */ new Date(), -20);
|
|
25144
|
+
let o;
|
|
25145
|
+
return l ? o = this.liveQueryCache(s) : o = this.queryCache(s), !o || o === "too much data" || i ? o : filterDataByTime(o, n, r);
|
|
25146
|
+
}
|
|
25147
|
+
queryCache(t) {
|
|
25148
|
+
return this.queryStoreCache.get(t, async () => {
|
|
25149
|
+
try {
|
|
25150
|
+
return await Fleet.queryTelemetry(t);
|
|
25151
|
+
} catch (n) {
|
|
25152
|
+
throw n;
|
|
25153
|
+
}
|
|
25154
|
+
});
|
|
25155
|
+
}
|
|
25156
|
+
liveQueryCache(t) {
|
|
25157
|
+
return this.liveQueryStoreCache.get(t, async () => {
|
|
25158
|
+
try {
|
|
25159
|
+
return await Fleet.queryTelemetry(t);
|
|
25160
|
+
} catch (n) {
|
|
25161
|
+
throw n;
|
|
25415
25162
|
}
|
|
25416
25163
|
});
|
|
25417
25164
|
}
|
|
25418
|
-
|
|
25419
|
-
|
|
25420
|
-
|
|
25421
|
-
|
|
25422
|
-
|
|
25165
|
+
}
|
|
25166
|
+
const queryStore = new QueryStore(), Mt = class {
|
|
25167
|
+
static sendAppMessage(t) {
|
|
25168
|
+
window.parent.postMessage(t, "*");
|
|
25169
|
+
}
|
|
25170
|
+
static getCurrentModuleContext() {
|
|
25171
|
+
let t = new URLSearchParams("");
|
|
25172
|
+
return typeof window < "u" && (t = new URLSearchParams(window.location.search)), t.get("module");
|
|
25173
|
+
}
|
|
25174
|
+
static async getCurrentModuleConfiguration() {
|
|
25175
|
+
let t = new URLSearchParams("");
|
|
25176
|
+
typeof window < "u" && (t = new URLSearchParams(window.location.search));
|
|
25177
|
+
const n = t.get("configuration");
|
|
25178
|
+
return n === null || n.trim() === "" ? void 0 : (await (await fetch(
|
|
25179
|
+
`${FORMANT_API_URL}/v1/admin/module-configurations/` + n,
|
|
25423
25180
|
{
|
|
25424
|
-
method: "PATCH",
|
|
25425
|
-
body: JSON.stringify({ fleetId: n }),
|
|
25426
25181
|
headers: {
|
|
25427
25182
|
"Content-Type": "application/json",
|
|
25428
25183
|
Authorization: "Bearer " + Authentication.token
|
|
25429
25184
|
}
|
|
25430
25185
|
}
|
|
25431
|
-
)).json();
|
|
25186
|
+
)).json()).configuration;
|
|
25432
25187
|
}
|
|
25433
|
-
static
|
|
25434
|
-
|
|
25435
|
-
|
|
25436
|
-
|
|
25437
|
-
|
|
25438
|
-
|
|
25439
|
-
|
|
25440
|
-
|
|
25441
|
-
|
|
25442
|
-
|
|
25443
|
-
|
|
25188
|
+
static isModule() {
|
|
25189
|
+
return this.getCurrentModuleContext() !== null;
|
|
25190
|
+
}
|
|
25191
|
+
static goToTime(t) {
|
|
25192
|
+
this.sendAppMessage({
|
|
25193
|
+
type: "go_to_time",
|
|
25194
|
+
time: t.getTime()
|
|
25195
|
+
});
|
|
25196
|
+
}
|
|
25197
|
+
static goToDevice(t) {
|
|
25198
|
+
this.sendAppMessage({
|
|
25199
|
+
type: "go_to_device",
|
|
25200
|
+
deviceId: t
|
|
25201
|
+
});
|
|
25202
|
+
}
|
|
25203
|
+
static showMessage(t) {
|
|
25204
|
+
this.sendAppMessage({ type: "show_message", message: t });
|
|
25205
|
+
}
|
|
25206
|
+
static requestModuleData() {
|
|
25207
|
+
const t = this.getCurrentModuleContext();
|
|
25208
|
+
if (!t)
|
|
25209
|
+
throw new Error("No module context");
|
|
25210
|
+
this.sendAppMessage({
|
|
25211
|
+
type: "request_module_data",
|
|
25212
|
+
module: t
|
|
25213
|
+
});
|
|
25214
|
+
}
|
|
25215
|
+
static setModuleDateTimeRange(t, n) {
|
|
25216
|
+
const r = this.getCurrentModuleContext();
|
|
25217
|
+
if (!r)
|
|
25218
|
+
throw new Error("No module context");
|
|
25219
|
+
this.sendAppMessage({
|
|
25220
|
+
type: "set_module_data_time_range",
|
|
25221
|
+
module: r,
|
|
25222
|
+
before: t,
|
|
25223
|
+
after: n || 0
|
|
25224
|
+
});
|
|
25225
|
+
}
|
|
25226
|
+
static refreshAuthToken() {
|
|
25227
|
+
const t = this.getCurrentModuleContext();
|
|
25228
|
+
if (!t)
|
|
25229
|
+
throw new Error("No module context");
|
|
25230
|
+
this.sendAppMessage({
|
|
25231
|
+
type: "refresh_auth_token",
|
|
25232
|
+
module: t
|
|
25233
|
+
});
|
|
25234
|
+
}
|
|
25235
|
+
static sendChannelData(t, n) {
|
|
25236
|
+
const r = this.getCurrentModuleContext();
|
|
25237
|
+
if (!r)
|
|
25238
|
+
throw new Error("No module context");
|
|
25239
|
+
this.sendAppMessage({
|
|
25240
|
+
type: "send_channel_data",
|
|
25241
|
+
source: r,
|
|
25242
|
+
channel: t,
|
|
25243
|
+
data: n
|
|
25244
|
+
});
|
|
25245
|
+
}
|
|
25246
|
+
static setupModuleMenus(t) {
|
|
25247
|
+
const n = this.getCurrentModuleContext();
|
|
25248
|
+
if (!n)
|
|
25249
|
+
throw new Error("No module context");
|
|
25250
|
+
this.sendAppMessage({
|
|
25251
|
+
type: "setup_module_menus",
|
|
25252
|
+
module: n,
|
|
25253
|
+
menus: t
|
|
25254
|
+
});
|
|
25255
|
+
}
|
|
25256
|
+
static addMenuListener(t) {
|
|
25257
|
+
window.addEventListener("message", (n) => {
|
|
25258
|
+
const r = n.data;
|
|
25259
|
+
r.type === "module_menu_item_clicked" && t(r.menu);
|
|
25260
|
+
});
|
|
25261
|
+
}
|
|
25262
|
+
static addAccessTokenRefreshListener(t) {
|
|
25263
|
+
window.addEventListener("message", (n) => {
|
|
25264
|
+
const r = n.data;
|
|
25265
|
+
r.type === "auth_token" && t(r.token);
|
|
25266
|
+
});
|
|
25267
|
+
}
|
|
25268
|
+
static addModuleDataListener(t) {
|
|
25269
|
+
const n = this.getCurrentModuleContext();
|
|
25270
|
+
n && this.sendAppMessage({ type: "request_module_data", module: n }), window.addEventListener("message", (r) => {
|
|
25271
|
+
const i = r.data;
|
|
25272
|
+
i.type === "module_data" && t({
|
|
25273
|
+
streams: i.streams,
|
|
25274
|
+
time: i.time,
|
|
25275
|
+
queryRange: i.queryRange
|
|
25276
|
+
});
|
|
25277
|
+
});
|
|
25278
|
+
}
|
|
25279
|
+
static addOverviewDeviceListener(t) {
|
|
25280
|
+
this.sendAppMessage({ type: "request_devices" });
|
|
25281
|
+
const n = (r) => {
|
|
25282
|
+
const i = r.data;
|
|
25283
|
+
i.type === "overview_devices" && t(i.data);
|
|
25284
|
+
};
|
|
25285
|
+
return window.addEventListener("message", n), () => window.removeEventListener("message", n);
|
|
25286
|
+
}
|
|
25287
|
+
static addStreamListener(t, n, r) {
|
|
25288
|
+
const i = (s) => {
|
|
25289
|
+
const l = s.data;
|
|
25290
|
+
if (l.type === "module_data") {
|
|
25291
|
+
const { start: o, end: c } = l.queryRange;
|
|
25292
|
+
r(
|
|
25293
|
+
queryStore.moduleQuery(
|
|
25294
|
+
{},
|
|
25295
|
+
t,
|
|
25296
|
+
n,
|
|
25297
|
+
new Date(o),
|
|
25298
|
+
new Date(c),
|
|
25299
|
+
!1
|
|
25300
|
+
)
|
|
25301
|
+
);
|
|
25444
25302
|
}
|
|
25445
|
-
|
|
25303
|
+
};
|
|
25304
|
+
return window.addEventListener("message", i), () => window.removeEventListener("message", i);
|
|
25305
|
+
}
|
|
25306
|
+
static addModuleConfigurationListener(t) {
|
|
25307
|
+
window.addEventListener("message", (n) => {
|
|
25308
|
+
const r = n.data;
|
|
25309
|
+
r.type === "module_configuration" && t(r);
|
|
25310
|
+
});
|
|
25311
|
+
}
|
|
25312
|
+
static addChannelDataListener(t, n) {
|
|
25313
|
+
window.addEventListener("message", (r) => {
|
|
25314
|
+
const i = r.data;
|
|
25315
|
+
i.type === "channel_data" && i.channel === t && n({
|
|
25316
|
+
source: i.source,
|
|
25317
|
+
data: i.data
|
|
25318
|
+
});
|
|
25319
|
+
});
|
|
25320
|
+
}
|
|
25321
|
+
static async prompt(t, n) {
|
|
25322
|
+
return new Promise((r) => {
|
|
25323
|
+
const i = Math.random().toString();
|
|
25324
|
+
this.sendAppMessage({
|
|
25325
|
+
type: "prompt",
|
|
25326
|
+
promptId: i,
|
|
25327
|
+
schema: t,
|
|
25328
|
+
okText: n == null ? void 0 : n.okText,
|
|
25329
|
+
cancelText: n == null ? void 0 : n.cancelText
|
|
25330
|
+
});
|
|
25331
|
+
const s = (l) => {
|
|
25332
|
+
const o = l.data;
|
|
25333
|
+
o.type === "prompt_response" && o.promptId === i && r(o.data), window.removeEventListener("message", s);
|
|
25334
|
+
};
|
|
25335
|
+
window.addEventListener("message", s);
|
|
25336
|
+
});
|
|
25337
|
+
}
|
|
25338
|
+
static async getDate(t, n, r) {
|
|
25339
|
+
return new Promise((i) => {
|
|
25340
|
+
this.sendAppMessage({
|
|
25341
|
+
type: "request_date",
|
|
25342
|
+
minTime: n,
|
|
25343
|
+
maxTime: r,
|
|
25344
|
+
time: t
|
|
25345
|
+
});
|
|
25346
|
+
const s = (l) => {
|
|
25347
|
+
const o = l.data;
|
|
25348
|
+
o.type === "date_response" && (window.removeEventListener("message", s), i(o.data));
|
|
25349
|
+
};
|
|
25350
|
+
window.addEventListener("message", s);
|
|
25351
|
+
});
|
|
25352
|
+
}
|
|
25353
|
+
static async disableAnalyticsBottomBar() {
|
|
25354
|
+
this.sendAppMessage({
|
|
25355
|
+
type: "hide_analytics_date_picker"
|
|
25356
|
+
});
|
|
25357
|
+
}
|
|
25358
|
+
static get isOnline() {
|
|
25359
|
+
return Mt._isOnline;
|
|
25360
|
+
}
|
|
25361
|
+
static listenForConnectionEvents() {
|
|
25362
|
+
window.addEventListener("message", this._handleOnlineEvent);
|
|
25363
|
+
}
|
|
25364
|
+
static checkConnection(t = 1e3) {
|
|
25365
|
+
return new Promise((n, r) => {
|
|
25366
|
+
const i = setTimeout(
|
|
25367
|
+
() => r(new Error("deadline expired: took too long")),
|
|
25368
|
+
t
|
|
25369
|
+
), s = (l) => {
|
|
25370
|
+
window.removeEventListener("message", s), clearTimeout(i);
|
|
25371
|
+
const { data: o } = l;
|
|
25372
|
+
o.type === "formant_online" && (this._isOnline = o.online, n(o.online));
|
|
25373
|
+
};
|
|
25374
|
+
window.addEventListener("message", s), this.sendAppMessage({ type: "formant_online" });
|
|
25375
|
+
});
|
|
25376
|
+
}
|
|
25377
|
+
static waitForConnection(t = 5e3) {
|
|
25378
|
+
let n = !1;
|
|
25379
|
+
const r = new Promise((l, o) => {
|
|
25380
|
+
setTimeout(() => {
|
|
25381
|
+
n = !0, o(new Error("deadline expired: took too long"));
|
|
25382
|
+
}, t);
|
|
25383
|
+
}), i = (l) => new Promise((o) => setTimeout(o, l)), s = async () => {
|
|
25384
|
+
for (await i(50); !n && !(this.isOnline || await this.checkConnection); )
|
|
25385
|
+
await i(500);
|
|
25386
|
+
};
|
|
25387
|
+
return Promise.race([r, s()]);
|
|
25446
25388
|
}
|
|
25447
25389
|
};
|
|
25448
|
-
let
|
|
25449
|
-
Te(
|
|
25390
|
+
let App = Mt;
|
|
25391
|
+
Te(App, "_isOnline", null), Te(App, "_handleOnlineEvent", (t) => {
|
|
25392
|
+
const { data: n } = t;
|
|
25393
|
+
n.type === "formant_online" && (Mt._isOnline = n.online);
|
|
25394
|
+
});
|
|
25450
25395
|
class RequestDataChannel {
|
|
25451
25396
|
constructor(t, n, r) {
|
|
25452
25397
|
Te(this, "channel");
|
|
@@ -25991,9 +25936,6 @@ export {
|
|
|
25991
25936
|
aggregateFunctions,
|
|
25992
25937
|
aggregateLevels,
|
|
25993
25938
|
annotationTypes,
|
|
25994
|
-
combineNumericAggregates,
|
|
25995
|
-
combineNumericSetAggregates,
|
|
25996
|
-
deserializeHash,
|
|
25997
25939
|
eventTypes,
|
|
25998
25940
|
formatTimeFrameText,
|
|
25999
25941
|
getAverage,
|
|
@@ -26003,16 +25945,10 @@ export {
|
|
|
26003
25945
|
getStandardDeviation,
|
|
26004
25946
|
getSum,
|
|
26005
25947
|
getVariance,
|
|
26006
|
-
getZeroINumericSet,
|
|
26007
25948
|
healthStatuses,
|
|
26008
25949
|
interventionTypes,
|
|
26009
|
-
isRtcPeer,
|
|
26010
25950
|
operator,
|
|
26011
|
-
reduceNumericSetStreamAggregates,
|
|
26012
|
-
reduceNumericStreamAggregates,
|
|
26013
|
-
serializeHash,
|
|
26014
25951
|
severities,
|
|
26015
|
-
timeout,
|
|
26016
25952
|
vailableAggregationIntervals,
|
|
26017
25953
|
videoMimeTypes,
|
|
26018
25954
|
viewer
|