@formant/data-sdk 1.74.0 → 1.76.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.
@@ -43,13 +43,42 @@ function whichFormantApiUrl(e, t, n) {
43
43
  }
44
44
  return typeof e != "undefined" && "FORMANT_API_URL" in e && typeof e.FORMANT_API_URL == "string" ? e.FORMANT_API_URL : DEFAULT_FORMANT_API_URL;
45
45
  }
46
- const FORMANT_API_URL = whichFormantApiUrl(
46
+ let FORMANT_API_URL = whichFormantApiUrl(
47
47
  typeof window != "undefined" ? window : globalThis,
48
48
  new URLSearchParams(
49
49
  typeof window != "undefined" && window.location ? window.location.search : void 0
50
50
  ),
51
51
  typeof window != "undefined" && window.location ? window.location.host : void 0
52
52
  );
53
+ const setFormantApiUrl = (e) => {
54
+ FORMANT_API_URL = e;
55
+ };
56
+ function addAccessTokenRefreshListener(e) {
57
+ function t(n) {
58
+ const r = n.data;
59
+ r.type === "auth_token" && e(r.token);
60
+ }
61
+ return window.addEventListener("message", t), () => {
62
+ window.removeEventListener("message", t);
63
+ };
64
+ }
65
+ function getCurrentModuleContext() {
66
+ return typeof window != "undefined" && window.location ? new URLSearchParams(window.location.search).get("module") : null;
67
+ }
68
+ function sendAppMessage(e) {
69
+ if (!(window && window.parent))
70
+ throw new Error("cannot send message to non-existent parent");
71
+ window.parent.postMessage(e, "*");
72
+ }
73
+ function refreshAuthToken() {
74
+ const e = getCurrentModuleContext();
75
+ if (!e)
76
+ throw new Error("No module context");
77
+ sendAppMessage({
78
+ type: "refresh_auth_token",
79
+ module: e
80
+ });
81
+ }
53
82
  var commonjsGlobal = typeof globalThis != "undefined" ? globalThis : typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : {};
54
83
  function getDefaultExportFromCjs(e) {
55
84
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
@@ -136,7 +165,7 @@ class AuthenticationStore {
136
165
  this._apiUrl = t, this._refreshAuthToken = n, this._addAccessTokenRefreshListener = r;
137
166
  }
138
167
  set apiUrl(t) {
139
- this._apiUrl = t;
168
+ this._apiUrl = t, setFormantApiUrl(t);
140
169
  }
141
170
  get apiUrl() {
142
171
  return this._apiUrl;
@@ -165,9 +194,6 @@ class AuthenticationStore {
165
194
  get isShareToken() {
166
195
  return this._isShareToken;
167
196
  }
168
- setEnvironment(t) {
169
- t === "prod" ? this.apiUrl = "https://api.formant.io" : t === "stage" ? this.apiUrl = "https://api-stage.formant.io" : t === "dev" ? this.apiUrl = "https://api-dev.formant.io" : t === "local" && (this.apiUrl = "https://api.formant.local");
170
- }
171
197
  async login(t, n, r = {}) {
172
198
  const { advanced: o = !1 } = r;
173
199
  try {
@@ -363,32 +389,6 @@ class AuthenticationStore {
363
389
  );
364
390
  }
365
391
  }
366
- function getCurrentModuleContext() {
367
- return typeof window != "undefined" && window.location ? new URLSearchParams(window.location.search).get("module") : null;
368
- }
369
- function sendAppMessage(e) {
370
- if (!(window && window.parent))
371
- throw new Error("cannot send message to non-existent parent");
372
- window.parent.postMessage(e, "*");
373
- }
374
- function refreshAuthToken() {
375
- const e = getCurrentModuleContext();
376
- if (!e)
377
- throw new Error("No module context");
378
- sendAppMessage({
379
- type: "refresh_auth_token",
380
- module: e
381
- });
382
- }
383
- function addAccessTokenRefreshListener(e) {
384
- function t(n) {
385
- const r = n.data;
386
- r.type === "auth_token" && e(r.token);
387
- }
388
- return window.addEventListener("message", t), () => {
389
- window.removeEventListener("message", t);
390
- };
391
- }
392
392
  const Authentication = new AuthenticationStore({
393
393
  apiUrl: FORMANT_API_URL,
394
394
  refreshAuthToken,
@@ -25444,6 +25444,49 @@ class User {
25444
25444
  });
25445
25445
  }
25446
25446
  }
25447
+ async function request(e, t) {
25448
+ if (!Authentication.token)
25449
+ throw new Error("Not authenticated");
25450
+ const n = await fetch(`${FORMANT_API_URL}/v1${e}`, {
25451
+ ...t,
25452
+ headers: {
25453
+ "Content-Type": "application/json",
25454
+ Authorization: `Bearer ${Authentication.token}`,
25455
+ ...t == null ? void 0 : t.headers
25456
+ }
25457
+ });
25458
+ if (!n.ok)
25459
+ throw new Error(`Error: ${n.statusText}`);
25460
+ return n.status === 204 || n.headers.get("content-length") === "0" ? null : await n.json();
25461
+ }
25462
+ async function fetchTeleopViews() {
25463
+ return (await request("/admin/teleop-views")).items;
25464
+ }
25465
+ async function getTeleopView(e) {
25466
+ return await request(`/admin/teleop-views/${e}`);
25467
+ }
25468
+ async function createTeleopView(e) {
25469
+ return await request("/admin/teleop-views", {
25470
+ method: "POST",
25471
+ body: JSON.stringify(e)
25472
+ });
25473
+ }
25474
+ async function updateTeleopView(e, t) {
25475
+ return await request(`/admin/teleop-views/${e}`, {
25476
+ method: "PATCH",
25477
+ body: JSON.stringify(t)
25478
+ });
25479
+ }
25480
+ async function deleteTeleopView(e) {
25481
+ await request(`/admin/teleop-views/${e}`, {
25482
+ method: "DELETE"
25483
+ });
25484
+ }
25485
+ class Views {
25486
+ constructor() {
25487
+ }
25488
+ }
25489
+ he(Views, "createTeleopView", createTeleopView), he(Views, "updateTeleopView", updateTeleopView), he(Views, "deleteTeleopView", deleteTeleopView), he(Views, "getTeleopView", getTeleopView), he(Views, "fetchTeleopViews", fetchTeleopViews);
25447
25490
  const viewer = "viewer", operator = "operator", administrator = "administrator", accessLevels = ["viewer", "operator", "administrator"], aggregateLevels = [
25448
25491
  "year",
25449
25492
  "month",
@@ -32876,6 +32919,7 @@ export {
32876
32919
  TelemetryUniverseData,
32877
32920
  TextRequestDataChannel,
32878
32921
  User,
32922
+ Views,
32879
32923
  accessLevels,
32880
32924
  administrator,
32881
32925
  aggregateByDateFunctions,