@formant/data-sdk 0.0.50 → 0.0.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-sdk.es.js +94 -17
- package/dist/data-sdk.umd.js +6 -6
- package/dist/types/data-sdk/src/App.d.ts +26 -7
- package/dist/types/data-sdk/src/Authentication.d.ts +9 -2
- package/dist/types/data-sdk/src/KeyValue.d.ts +4 -0
- package/dist/types/data-sdk/src/main.d.ts +1 -0
- package/package.json +1 -1
package/dist/data-sdk.es.js
CHANGED
|
@@ -18246,8 +18246,8 @@ class App {
|
|
|
18246
18246
|
if (typeof window !== "undefined") {
|
|
18247
18247
|
urlParams2 = new URLSearchParams(window.location.search);
|
|
18248
18248
|
}
|
|
18249
|
-
const
|
|
18250
|
-
return
|
|
18249
|
+
const moduleName2 = urlParams2.get("module");
|
|
18250
|
+
return moduleName2;
|
|
18251
18251
|
}
|
|
18252
18252
|
static isModule() {
|
|
18253
18253
|
return this.getCurrentModuleContext() !== null;
|
|
@@ -18262,33 +18262,45 @@ class App {
|
|
|
18262
18262
|
this.sendAppMessage({ type: "show_message", message });
|
|
18263
18263
|
}
|
|
18264
18264
|
static requestModuleData() {
|
|
18265
|
-
const
|
|
18266
|
-
if (!
|
|
18265
|
+
const moduleName2 = this.getCurrentModuleContext();
|
|
18266
|
+
if (!moduleName2) {
|
|
18267
18267
|
throw new Error("No module context");
|
|
18268
18268
|
}
|
|
18269
18269
|
this.sendAppMessage({
|
|
18270
18270
|
type: "request_module_data",
|
|
18271
|
-
module:
|
|
18271
|
+
module: moduleName2
|
|
18272
|
+
});
|
|
18273
|
+
}
|
|
18274
|
+
static setModuleDateTimeRange(beforeInMilliseconds, afterInMilliseconds) {
|
|
18275
|
+
const moduleName2 = this.getCurrentModuleContext();
|
|
18276
|
+
if (!moduleName2) {
|
|
18277
|
+
throw new Error("No module context");
|
|
18278
|
+
}
|
|
18279
|
+
this.sendAppMessage({
|
|
18280
|
+
type: "set_module_data_time_range",
|
|
18281
|
+
module: moduleName2,
|
|
18282
|
+
before: beforeInMilliseconds,
|
|
18283
|
+
after: afterInMilliseconds || 0
|
|
18272
18284
|
});
|
|
18273
18285
|
}
|
|
18274
18286
|
static refreshAuthToken() {
|
|
18275
|
-
const
|
|
18276
|
-
if (!
|
|
18287
|
+
const moduleName2 = this.getCurrentModuleContext();
|
|
18288
|
+
if (!moduleName2) {
|
|
18277
18289
|
throw new Error("No module context");
|
|
18278
18290
|
}
|
|
18279
18291
|
this.sendAppMessage({
|
|
18280
18292
|
type: "refresh_auth_token",
|
|
18281
|
-
module:
|
|
18293
|
+
module: moduleName2
|
|
18282
18294
|
});
|
|
18283
18295
|
}
|
|
18284
18296
|
static setupModuleMenus(menus) {
|
|
18285
|
-
const
|
|
18286
|
-
if (!
|
|
18297
|
+
const moduleName2 = this.getCurrentModuleContext();
|
|
18298
|
+
if (!moduleName2) {
|
|
18287
18299
|
throw new Error("No module context");
|
|
18288
18300
|
}
|
|
18289
18301
|
this.sendAppMessage({
|
|
18290
18302
|
type: "setup_module_menus",
|
|
18291
|
-
module:
|
|
18303
|
+
module: moduleName2,
|
|
18292
18304
|
menus
|
|
18293
18305
|
});
|
|
18294
18306
|
}
|
|
@@ -18335,14 +18347,15 @@ const _Authentication = class {
|
|
|
18335
18347
|
if (result.status !== 200) {
|
|
18336
18348
|
throw new Error(auth.message);
|
|
18337
18349
|
}
|
|
18338
|
-
await _Authentication.loginWithToken(auth.authentication.accessToken);
|
|
18350
|
+
await _Authentication.loginWithToken(auth.authentication.accessToken, auth.authentication.refreshToken);
|
|
18351
|
+
return auth.authentication;
|
|
18339
18352
|
} catch (e) {
|
|
18340
18353
|
_Authentication.waitingForAuth.forEach((_) => _(false));
|
|
18341
18354
|
_Authentication.waitingForAuth = [];
|
|
18342
|
-
|
|
18355
|
+
return Promise.reject(e);
|
|
18343
18356
|
}
|
|
18344
18357
|
}
|
|
18345
|
-
static async loginWithToken(token) {
|
|
18358
|
+
static async loginWithToken(token, refreshToken) {
|
|
18346
18359
|
const tokenData = JSON.parse(atob(token.split(".")[1]));
|
|
18347
18360
|
try {
|
|
18348
18361
|
let userId = tokenData.sub;
|
|
@@ -18368,6 +18381,24 @@ const _Authentication = class {
|
|
|
18368
18381
|
_Authentication.waitingForAuth.forEach((_) => _(false));
|
|
18369
18382
|
}
|
|
18370
18383
|
_Authentication.waitingForAuth = [];
|
|
18384
|
+
if (refreshToken) {
|
|
18385
|
+
_Authentication.refreshToken = refreshToken;
|
|
18386
|
+
setInterval(async () => {
|
|
18387
|
+
if (_Authentication.refreshToken) {
|
|
18388
|
+
const result = await fetch(`${FORMANT_API_URL}/v1/admin/auth/refresh`, {
|
|
18389
|
+
method: "POST",
|
|
18390
|
+
headers: {
|
|
18391
|
+
"Content-Type": "application/json"
|
|
18392
|
+
},
|
|
18393
|
+
body: JSON.stringify({
|
|
18394
|
+
refreshToken: _Authentication.refreshToken
|
|
18395
|
+
})
|
|
18396
|
+
});
|
|
18397
|
+
const refreshData = await result.json();
|
|
18398
|
+
_Authentication.token = refreshData.authentication.accessToken;
|
|
18399
|
+
}
|
|
18400
|
+
}, 1e3 * 60 * 60);
|
|
18401
|
+
}
|
|
18371
18402
|
}
|
|
18372
18403
|
static isAuthenticated() {
|
|
18373
18404
|
return _Authentication.token !== void 0;
|
|
@@ -18397,6 +18428,7 @@ const _Authentication = class {
|
|
|
18397
18428
|
};
|
|
18398
18429
|
let Authentication = _Authentication;
|
|
18399
18430
|
__publicField(Authentication, "token");
|
|
18431
|
+
__publicField(Authentication, "refreshToken");
|
|
18400
18432
|
__publicField(Authentication, "currentUser");
|
|
18401
18433
|
__publicField(Authentication, "defaultDeviceId");
|
|
18402
18434
|
__publicField(Authentication, "waitingForAuth", []);
|
|
@@ -19141,6 +19173,51 @@ const _Fleet = class {
|
|
|
19141
19173
|
let Fleet = _Fleet;
|
|
19142
19174
|
__publicField(Fleet, "defaultDeviceId");
|
|
19143
19175
|
__publicField(Fleet, "knownContext", []);
|
|
19176
|
+
class KeyValue {
|
|
19177
|
+
static async set(key, value) {
|
|
19178
|
+
try {
|
|
19179
|
+
const result = await fetch(FORMANT_API_URL + "/v1/admin/key-value", {
|
|
19180
|
+
method: "POST",
|
|
19181
|
+
body: JSON.stringify({
|
|
19182
|
+
organizationId: defined(Authentication.currentUser).organizationId,
|
|
19183
|
+
key,
|
|
19184
|
+
value
|
|
19185
|
+
}),
|
|
19186
|
+
headers: {
|
|
19187
|
+
"Content-Type": "application/json",
|
|
19188
|
+
Authorization: "Bearer " + Authentication.token
|
|
19189
|
+
}
|
|
19190
|
+
});
|
|
19191
|
+
const keyValue = await result.json();
|
|
19192
|
+
if (result.status !== 200) {
|
|
19193
|
+
throw new Error(keyValue.message);
|
|
19194
|
+
}
|
|
19195
|
+
} catch (e) {
|
|
19196
|
+
throw e;
|
|
19197
|
+
}
|
|
19198
|
+
}
|
|
19199
|
+
static async get(key) {
|
|
19200
|
+
try {
|
|
19201
|
+
const result = await fetch(FORMANT_API_URL + `/v1/admin/key-value/${key}`, {
|
|
19202
|
+
method: "GET",
|
|
19203
|
+
body: JSON.stringify({
|
|
19204
|
+
organizationId: defined(Authentication.currentUser).organizationId
|
|
19205
|
+
}),
|
|
19206
|
+
headers: {
|
|
19207
|
+
"Content-Type": "application/json",
|
|
19208
|
+
Authorization: "Bearer " + Authentication.token
|
|
19209
|
+
}
|
|
19210
|
+
});
|
|
19211
|
+
const keyValue = await result.json();
|
|
19212
|
+
if (result.status !== 200) {
|
|
19213
|
+
throw new Error(keyValue.message);
|
|
19214
|
+
}
|
|
19215
|
+
return keyValue.value;
|
|
19216
|
+
} catch (e) {
|
|
19217
|
+
throw e;
|
|
19218
|
+
}
|
|
19219
|
+
}
|
|
19220
|
+
}
|
|
19144
19221
|
let urlParams = new URLSearchParams("");
|
|
19145
19222
|
if (typeof window !== "undefined") {
|
|
19146
19223
|
urlParams = new URLSearchParams(window.location.search);
|
|
@@ -19153,8 +19230,8 @@ const urlAuth = urlParams.get("auth");
|
|
|
19153
19230
|
if (urlAuth) {
|
|
19154
19231
|
Authentication.loginWithToken(urlAuth);
|
|
19155
19232
|
}
|
|
19156
|
-
const
|
|
19157
|
-
if (
|
|
19233
|
+
const moduleName = urlParams.get("module");
|
|
19234
|
+
if (moduleName) {
|
|
19158
19235
|
Authentication.listenForRefresh();
|
|
19159
19236
|
}
|
|
19160
|
-
export { App, Authentication, BinaryRequestDataChannel, CaptureStream, DataChannel, Device, Fleet, Manipulator, TextRequestDataChannel };
|
|
19237
|
+
export { App, Authentication, BinaryRequestDataChannel, CaptureStream, DataChannel, Device, Fleet, KeyValue, Manipulator, TextRequestDataChannel };
|