@formant/data-sdk 1.14.0 → 1.15.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.
@@ -4,7 +4,7 @@ var s = (a, e, t) => (de(a, typeof e != "symbol" ? e + "" : e, t), t);
4
4
  import { decode as G } from "base-64";
5
5
  import * as u from "date-fns";
6
6
  import { startOfMinute as he, addMinutes as le, roundToNearestMinutes as ue, addSeconds as me } from "date-fns";
7
- import { RtcClient as b, SignalingPromiseClient as j } from "@formant/realtime-sdk";
7
+ import { RtcClient as A, SignalingPromiseClient as D } from "@formant/realtime-sdk";
8
8
  import { EventEmitter as fe } from "eventemitter3";
9
9
  import { deflate as we } from "pako";
10
10
  import { fromByteArray as pe } from "base64-js";
@@ -303,13 +303,13 @@ function Ce() {
303
303
  type: "hide_analytics_date_picker"
304
304
  });
305
305
  }
306
- function Se(a) {
306
+ function Ee(a) {
307
307
  T({
308
308
  type: "go_to_device",
309
309
  deviceId: a
310
310
  });
311
311
  }
312
- function Ee(a) {
312
+ function Se(a) {
313
313
  T({
314
314
  type: "go_to_time",
315
315
  time: a.getTime()
@@ -346,7 +346,7 @@ function Re(a, e) {
346
346
  after: e || 0
347
347
  });
348
348
  }
349
- function be(a) {
349
+ function Ae(a) {
350
350
  const e = k();
351
351
  if (!e)
352
352
  throw new Error("No module context");
@@ -356,10 +356,10 @@ function be(a) {
356
356
  menus: a
357
357
  });
358
358
  }
359
- function Ae(a) {
359
+ function be(a) {
360
360
  T({ type: "show_message", message: a });
361
361
  }
362
- function De(a, e) {
362
+ function je(a, e) {
363
363
  const t = (n) => {
364
364
  const i = n.data;
365
365
  i.type === "channel_data" && i.channel === a && e({
@@ -369,7 +369,7 @@ function De(a, e) {
369
369
  };
370
370
  return window.addEventListener("message", t), () => window.removeEventListener("message", t);
371
371
  }
372
- function je(a) {
372
+ function De(a) {
373
373
  const e = (t) => {
374
374
  const n = t.data;
375
375
  n.type === "module_menu_item_clicked" && a(n.menu);
@@ -641,8 +641,8 @@ const q = class {
641
641
  };
642
642
  let g = q;
643
643
  s(g, "getCurrentModuleContext", k), // senders
644
- s(g, "disableAnalyticsBottomBar", Ce), s(g, "goToDevice", Se), s(g, "goToTime", Ee), s(g, "refreshAuthToken", H), s(g, "requestModuleData", ke), s(g, "sendChannelData", Oe), s(g, "setModuleDateTimeRange", Re), s(g, "setupModuleMenus", be), s(g, "showMessage", Ae), // listeners
645
- s(g, "addAccessTokenRefreshListener", F), s(g, "addChannelDataListener", De), s(g, "addMenuListener", je), s(g, "addModuleConfigurationListener", Ne), s(g, "addModuleDataListener", Pe), s(g, "addOverviewDeviceListener", Le), s(g, "addStreamListener", Ue), // bidirectional
644
+ s(g, "disableAnalyticsBottomBar", Ce), s(g, "goToDevice", Ee), s(g, "goToTime", Se), s(g, "refreshAuthToken", H), s(g, "requestModuleData", ke), s(g, "sendChannelData", Oe), s(g, "setModuleDateTimeRange", Re), s(g, "setupModuleMenus", Ae), s(g, "showMessage", be), // listeners
645
+ s(g, "addAccessTokenRefreshListener", F), s(g, "addChannelDataListener", je), s(g, "addMenuListener", De), s(g, "addModuleConfigurationListener", Ne), s(g, "addModuleDataListener", Pe), s(g, "addOverviewDeviceListener", Le), s(g, "addStreamListener", Ue), // bidirectional
646
646
  s(g, "getDate", Je), s(g, "prompt", Ve), s(g, "_isOnline", null);
647
647
  function f(a, e) {
648
648
  if (a !== void 0)
@@ -730,8 +730,8 @@ Gt = O;
730
730
  const P = async () => f(r.token, "Realtime when user isn't authorized"), R = {
731
731
  [p.UNKNOWN]: new N({
732
732
  ttlMs: 2500,
733
- createClient: (a) => new b({
734
- signalingClient: new j(h),
733
+ createClient: (a) => new A({
734
+ signalingClient: new D(h),
735
735
  getToken: P,
736
736
  sessionType: p.UNKNOWN,
737
737
  receive: a
@@ -739,8 +739,8 @@ const P = async () => f(r.token, "Realtime when user isn't authorized"), R = {
739
739
  }),
740
740
  [p.TELEOP]: new N({
741
741
  ttlMs: 2500,
742
- createClient: (a) => new b({
743
- signalingClient: new j(h),
742
+ createClient: (a) => new A({
743
+ signalingClient: new D(h),
744
744
  getToken: P,
745
745
  sessionType: p.TELEOP,
746
746
  receive: a
@@ -748,8 +748,8 @@ const P = async () => f(r.token, "Realtime when user isn't authorized"), R = {
748
748
  }),
749
749
  [p.PORT_FORWARD]: new N({
750
750
  ttlMs: 2500,
751
- createClient: (a) => new b({
752
- signalingClient: new j(h),
751
+ createClient: (a) => new A({
752
+ signalingClient: new D(h),
753
753
  getToken: P,
754
754
  sessionType: p.PORT_FORWARD,
755
755
  receive: a
@@ -757,8 +757,8 @@ const P = async () => f(r.token, "Realtime when user isn't authorized"), R = {
757
757
  }),
758
758
  [p.OBSERVE]: new N({
759
759
  ttlMs: 2500,
760
- createClient: (a) => new b({
761
- signalingClient: new j(h),
760
+ createClient: (a) => new A({
761
+ signalingClient: new D(h),
762
762
  getToken: P,
763
763
  sessionType: p.OBSERVE,
764
764
  receive: a
@@ -766,8 +766,8 @@ const P = async () => f(r.token, "Realtime when user isn't authorized"), R = {
766
766
  }),
767
767
  [p.HEADLESS]: new N({
768
768
  ttlMs: 2500,
769
- createClient: (a) => new b({
770
- signalingClient: new j(h),
769
+ createClient: (a) => new A({
770
+ signalingClient: new D(h),
771
771
  getToken: P,
772
772
  sessionType: p.HEADLESS,
773
773
  receive: a
@@ -814,7 +814,7 @@ class Fe {
814
814
  });
815
815
  }
816
816
  }
817
- function A(a) {
817
+ function b(a) {
818
818
  return new Promise((e) => setTimeout(e, a));
819
819
  }
820
820
  const We = (a) => a !== void 0 && a.capabilities !== void 0 && a.capabilitySet !== void 0;
@@ -1000,7 +1000,7 @@ class Xe extends X {
1000
1000
  i.set(d, !0), n.sendBinary(new Uint8Array([...c, ...t]));
1001
1001
  const y = (/* @__PURE__ */ new Date()).getTime();
1002
1002
  for (; (/* @__PURE__ */ new Date()).getTime() < y + o; )
1003
- if (await A(50), i.has(d)) {
1003
+ if (await b(50), i.has(d)) {
1004
1004
  const m = i.get(d);
1005
1005
  if (m !== !0) {
1006
1006
  i.delete(d);
@@ -1047,7 +1047,7 @@ class Ye extends X {
1047
1047
  );
1048
1048
  const c = (/* @__PURE__ */ new Date()).getTime();
1049
1049
  for (; (/* @__PURE__ */ new Date()).getTime() < c + i; )
1050
- if (await A(50), n.has(o)) {
1050
+ if (await b(50), n.has(o)) {
1051
1051
  const d = n.get(o);
1052
1052
  if (d !== !0) {
1053
1053
  n.delete(o);
@@ -1571,7 +1571,7 @@ async function mt(a) {
1571
1571
  }
1572
1572
  )).json();
1573
1573
  }
1574
- class S extends Y {
1574
+ class E extends Y {
1575
1575
  constructor(e, t, n, i) {
1576
1576
  super(), this.id = e, this.name = t, this.organizationId = n, this.tags = i;
1577
1577
  }
@@ -1590,22 +1590,29 @@ class S extends Y {
1590
1590
  }
1591
1591
  )).json()).items;
1592
1592
  }
1593
- async getConfiguration() {
1594
- let e = await fetch(`${h}/v1/admin/devices/${this.id}`, {
1593
+ /**
1594
+ * Asynchronously retrieves the configuration document for a device.
1595
+ *
1596
+ * @param {boolean} getDesiredConfigurationVersion - Whether to retrieve the desired configuration version
1597
+ * @returns {Promise<ConfigurationDocument>} A promise that resolves to the configuration document
1598
+ * @throws {Error} Throws an error if the device has no configuration or has never been turned on
1599
+ */
1600
+ async getConfiguration(e = !1) {
1601
+ let t = await fetch(`${h}/v1/admin/devices/${this.id}`, {
1595
1602
  method: "GET",
1596
1603
  headers: {
1597
1604
  "Content-Type": "application/json",
1598
1605
  Authorization: "Bearer " + r.token
1599
1606
  }
1600
1607
  });
1601
- const t = await e.json();
1602
- if (!t.state.reportedConfiguration)
1608
+ const n = await t.json();
1609
+ if (!n.state.reportedConfiguration)
1603
1610
  throw new Error(
1604
1611
  "Device has no configuration, has it ever been turned on?"
1605
1612
  );
1606
- const n = t.state.reportedConfiguration.version;
1607
- return e = await fetch(
1608
- `${h}/v1/admin/devices/${this.id}/configurations/${n}`,
1613
+ const i = e ? n.desiredConfigurationVersion : n.state.reportedConfiguration.version;
1614
+ return t = await fetch(
1615
+ `${h}/v1/admin/devices/${this.id}/configurations/${i}`,
1609
1616
  {
1610
1617
  method: "GET",
1611
1618
  headers: {
@@ -1613,7 +1620,24 @@ class S extends Y {
1613
1620
  Authorization: "Bearer " + r.token
1614
1621
  }
1615
1622
  }
1616
- ), (await e.json()).document;
1623
+ ), (await t.json()).document;
1624
+ }
1625
+ /**
1626
+ * Asynchronously retrieves the device's agent version string
1627
+ *
1628
+ * @returns {Promise<string | undefined | null>} A promise that resolves to the agent version
1629
+ * @throws {Error} Throws an error if the device info cannot be fetched
1630
+ */
1631
+ async getAgentVersion() {
1632
+ var n;
1633
+ const t = await (await fetch(`${h}/v1/admin/devices/${this.id}`, {
1634
+ method: "GET",
1635
+ headers: {
1636
+ "Content-Type": "application/json",
1637
+ Authorization: "Bearer " + r.token
1638
+ }
1639
+ })).json();
1640
+ return (n = t == null ? void 0 : t.state) == null ? void 0 : n.agentVersion;
1617
1641
  }
1618
1642
  async getFileUrl(e) {
1619
1643
  return (await (await fetch(`${h}/v1/admin/files/query`, {
@@ -1660,19 +1684,19 @@ class S extends Y {
1660
1684
  ), m = async () => {
1661
1685
  if ("isReady" in c)
1662
1686
  for (; !c.isReady(); )
1663
- this.assertNotCancelled(d), await A(100);
1687
+ this.assertNotCancelled(d), await b(100);
1664
1688
  const w = await this.getRemoteDevicePeerId(c);
1665
1689
  this.assertNotCancelled(d);
1666
1690
  let v;
1667
- for (let D = 0; D < i && (v = await c.connect(w), !v); D++)
1668
- A(100), this.assertNotCancelled(d);
1691
+ for (let j = 0; j < i && (v = await c.connect(w), !v); j++)
1692
+ b(100), this.assertNotCancelled(d);
1669
1693
  if (!v)
1670
1694
  throw new Error(
1671
1695
  `Session could not be created: exhausted ${i} retries`
1672
1696
  );
1673
1697
  let C = 0;
1674
1698
  for (; !d && c.getConnectionStatus(w) !== "connected"; )
1675
- await A(100), C += 1;
1699
+ await b(100), C += 1;
1676
1700
  return this.assertNotCancelled(d), console.debug(
1677
1701
  `${(/* @__PURE__ */ new Date()).toISOString()} :: Connection completed after ${C} retries`
1678
1702
  ), w;
@@ -1899,7 +1923,7 @@ class S extends Y {
1899
1923
  return e.scope.deviceIds = [this.id], await ee(e, t);
1900
1924
  }
1901
1925
  }
1902
- s(S, "createDevice", dt), s(S, "patchDevice", ht), s(S, "getDevicesData", lt), s(S, "queryDevicesData", ut), s(S, "disableDevice", mt);
1926
+ s(E, "createDevice", dt), s(E, "patchDevice", ht), s(E, "getDevicesData", lt), s(E, "queryDevicesData", ut), s(E, "disableDevice", mt);
1903
1927
  class ft extends Y {
1904
1928
  constructor(t) {
1905
1929
  super();
@@ -1940,8 +1964,8 @@ class ft extends Y {
1940
1964
  if (m.length > 0) {
1941
1965
  const v = JSON.parse(m);
1942
1966
  if ((w = v.result) != null && w.datapoint) {
1943
- const C = v.result.datapoint, D = C.stream;
1944
- delete C.stream, this.streamTelemetry[D] = C;
1967
+ const C = v.result.datapoint, j = C.stream;
1968
+ delete C.stream, this.streamTelemetry[j] = C;
1945
1969
  }
1946
1970
  }
1947
1971
  });
@@ -1964,13 +1988,13 @@ class ft extends Y {
1964
1988
  this.rtcClient && console.warn(
1965
1989
  "overwriting existing rtcClient due to missing connectionMonitorInterval"
1966
1990
  );
1967
- const n = new b({
1991
+ const n = new A({
1968
1992
  lanOnlyMode: !0,
1969
1993
  receive: this.handleMessage,
1970
1994
  sessionType: t
1971
1995
  });
1972
1996
  for (await n.connectLan(this.peerUrl); n.getConnectionStatus(this.peerUrl) !== "connected"; )
1973
- await A(100);
1997
+ await b(100);
1974
1998
  this.rtcClient = n, this.initConnectionMonitoring();
1975
1999
  }
1976
2000
  initConnectionMonitoring() {
@@ -2107,7 +2131,7 @@ async function se(a) {
2107
2131
  Authorization: "Bearer " + r.token
2108
2132
  }
2109
2133
  })).json()).items.map(
2110
- (n) => new S(n.id, n.name, n.organizationId, n.tags)
2134
+ (n) => new E(n.id, n.name, n.organizationId, n.tags)
2111
2135
  );
2112
2136
  }
2113
2137
  async function Ct() {
@@ -2133,7 +2157,7 @@ async function Ct() {
2133
2157
  type: "default"
2134
2158
  });
2135
2159
  }
2136
- async function St(a) {
2160
+ async function Et(a) {
2137
2161
  if (!r.token)
2138
2162
  throw new Error("Not authenticated");
2139
2163
  const t = await (await fetch(`${h}/v1/admin/devices/${a}`, {
@@ -2143,7 +2167,7 @@ async function St(a) {
2143
2167
  Authorization: "Bearer " + r.token
2144
2168
  }
2145
2169
  })).json(), n = t.name;
2146
- return new S(a, n, t.organizationId, t.tags);
2170
+ return new E(a, n, t.organizationId, t.tags);
2147
2171
  }
2148
2172
  async function M() {
2149
2173
  if (!r.token)
@@ -2157,7 +2181,7 @@ async function M() {
2157
2181
  }
2158
2182
  })).json();
2159
2183
  return e.items, e.items.map(
2160
- (t) => new S(
2184
+ (t) => new E(
2161
2185
  t.id,
2162
2186
  t.name,
2163
2187
  t.organizationId,
@@ -2165,7 +2189,7 @@ async function M() {
2165
2189
  )
2166
2190
  );
2167
2191
  }
2168
- async function Et(a) {
2192
+ async function St(a) {
2169
2193
  if (!r.token)
2170
2194
  throw new Error("Not authenticated");
2171
2195
  return (await (await fetch(
@@ -2216,7 +2240,7 @@ async function Rt(a) {
2216
2240
  }
2217
2241
  })).json()).items;
2218
2242
  }
2219
- async function bt() {
2243
+ async function At() {
2220
2244
  if (!r.token)
2221
2245
  throw new Error("Not authenticated");
2222
2246
  return (await (await fetch(
@@ -2230,7 +2254,7 @@ async function bt() {
2230
2254
  }
2231
2255
  )).json()).items;
2232
2256
  }
2233
- async function At(...a) {
2257
+ async function bt(...a) {
2234
2258
  const e = a.flat().filter((i) => !!i);
2235
2259
  return e.length === 0 ? [] : (await (await fetch(
2236
2260
  `${h}/v1/queries/stream-current-value`,
@@ -2246,7 +2270,7 @@ async function At(...a) {
2246
2270
  }
2247
2271
  )).json()).items;
2248
2272
  }
2249
- async function Dt() {
2273
+ async function jt() {
2250
2274
  if (!r.token)
2251
2275
  throw new Error("Not authenticated");
2252
2276
  const t = (await (await fetch(`${h}/v1/queries/online-devices`, {
@@ -2258,7 +2282,7 @@ async function Dt() {
2258
2282
  })).json()).items;
2259
2283
  return (await M()).filter((i) => t.includes(i.id));
2260
2284
  }
2261
- async function jt() {
2285
+ async function Dt() {
2262
2286
  if (!r.token)
2263
2287
  throw new Error("Not authenticated");
2264
2288
  const t = (await (await fetch(`${h}/v1/signaling/peers`, {
@@ -2428,14 +2452,14 @@ async function Ut(a, e) {
2428
2452
  }
2429
2453
  )).json();
2430
2454
  }
2431
- const E = class {
2455
+ const S = class {
2432
2456
  static async setDefaultDevice(e) {
2433
- E.defaultDeviceId = e;
2457
+ S.defaultDeviceId = e;
2434
2458
  }
2435
2459
  static async getCurrentDevice() {
2436
2460
  if (!r.token)
2437
2461
  throw new Error("Not authenticated");
2438
- if (!E.defaultDeviceId)
2462
+ if (!S.defaultDeviceId)
2439
2463
  throw new Error("No known default device");
2440
2464
  const n = (await (await fetch(
2441
2465
  `${h}/v1/admin/device-details/query`,
@@ -2447,26 +2471,26 @@ const E = class {
2447
2471
  }
2448
2472
  }
2449
2473
  )).json()).items.find(
2450
- (c) => c.id === E.defaultDeviceId
2451
- ), i = n.name, o = new S(
2452
- E.defaultDeviceId,
2474
+ (c) => c.id === S.defaultDeviceId
2475
+ ), i = n.name, o = new E(
2476
+ S.defaultDeviceId,
2453
2477
  i,
2454
2478
  f(r.currentOrganization),
2455
2479
  n.tags
2456
2480
  );
2457
- return E.knownContext.push(new WeakRef(o)), o;
2481
+ return S.knownContext.push(new WeakRef(o)), o;
2458
2482
  }
2459
2483
  static async getPeerDevice(e) {
2460
2484
  const t = new ft(e);
2461
2485
  return t.id = await t.getDeviceId(), t;
2462
2486
  }
2463
2487
  static async getDevice(e) {
2464
- const t = await St(e);
2465
- return E.knownContext.push(new WeakRef(t)), t;
2488
+ const t = await Et(e);
2489
+ return S.knownContext.push(new WeakRef(t)), t;
2466
2490
  }
2467
2491
  };
2468
- let l = E;
2469
- s(l, "defaultDeviceId"), s(l, "knownContext", []), s(l, "createFleet", Mt), s(l, "listFleets", It), s(l, "getFleet", Ot), s(l, "patchFleet", _t), s(l, "deleteFleet", yt), s(l, "addDeviceToFleet", wt), s(l, "getFleetDevices", Rt), s(l, "aggregateTelemetry", pt), s(l, "createShareLink", ee), s(l, "eventsCounter", ne), s(l, "getAnalyticStreams", gt), s(l, "getAnalyticsModules", vt), s(l, "getAnalyticsRows", Tt), s(l, "getAnnotationCount", B), s(l, "getAnnotationCountByIntervals", ae), s(l, "getCurrentGroup", Ct), s(l, "getDevices", M), s(l, "getEvent", Et), s(l, "getFileUrl", kt), s(l, "getInterventions", bt), s(l, "getLatestTelemetry", At), s(l, "getOnlineDevices", Dt), s(l, "getPeers", re), s(l, "getRealtimeDevices", jt), s(l, "getRealtimeSessions", oe), s(l, "getStreams", Nt), s(l, "getTaskReportRows", Pt), s(l, "getTaskReportTables", Lt), s(l, "getTelemetry", ie), s(l, "getViews", Z), s(l, "patchStream", $t), s(l, "patchView", zt), s(l, "queryAnalytics", Bt), s(l, "queryDevices", se), s(l, "queryEvents", z), s(l, "queryTelemetry", _), s(l, "getAllEventTriggerGroup", qt), s(l, "getEventTriggerGroup", xt), s(l, "patchEventTriggergroup", Ut);
2492
+ let l = S;
2493
+ s(l, "defaultDeviceId"), s(l, "knownContext", []), s(l, "createFleet", Mt), s(l, "listFleets", It), s(l, "getFleet", Ot), s(l, "patchFleet", _t), s(l, "deleteFleet", yt), s(l, "addDeviceToFleet", wt), s(l, "getFleetDevices", Rt), s(l, "aggregateTelemetry", pt), s(l, "createShareLink", ee), s(l, "eventsCounter", ne), s(l, "getAnalyticStreams", gt), s(l, "getAnalyticsModules", vt), s(l, "getAnalyticsRows", Tt), s(l, "getAnnotationCount", B), s(l, "getAnnotationCountByIntervals", ae), s(l, "getCurrentGroup", Ct), s(l, "getDevices", M), s(l, "getEvent", St), s(l, "getFileUrl", kt), s(l, "getInterventions", At), s(l, "getLatestTelemetry", bt), s(l, "getOnlineDevices", jt), s(l, "getPeers", re), s(l, "getRealtimeDevices", Dt), s(l, "getRealtimeSessions", oe), s(l, "getStreams", Nt), s(l, "getTaskReportRows", Pt), s(l, "getTaskReportTables", Lt), s(l, "getTelemetry", ie), s(l, "getViews", Z), s(l, "patchStream", $t), s(l, "patchView", zt), s(l, "queryAnalytics", Bt), s(l, "queryDevices", se), s(l, "queryEvents", z), s(l, "queryTelemetry", _), s(l, "getAllEventTriggerGroup", qt), s(l, "getEventTriggerGroup", xt), s(l, "patchEventTriggergroup", Ut);
2470
2494
  class an {
2471
2495
  static async set(e, t, n) {
2472
2496
  try {
@@ -2876,7 +2900,7 @@ export {
2876
2900
  Xe as BinaryRequestDataChannel,
2877
2901
  Fe as CaptureStream,
2878
2902
  Ke as DataChannel,
2879
- S as Device,
2903
+ E as Device,
2880
2904
  l as Fleet,
2881
2905
  an as KeyValue,
2882
2906
  Qe as Manipulator,