@formant/data-sdk 1.36.0 → 1.38.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.
@@ -23868,18 +23868,19 @@ async function getAnnotationCountByIntervals(e, t, n) {
23868
23868
  annotations: d[U]
23869
23869
  }));
23870
23870
  }
23871
- async function getTelemetry(e, t, n, r, l) {
23872
- let s = e;
23873
- Array.isArray(e) || (s = [e]);
23874
- let c = t;
23875
- return Array.isArray(t) || (c = [t]), (await (await fetch(`${FORMANT_API_URL}/v1/queries/queries`, {
23871
+ async function getTelemetry(e, t, n, r, l, s) {
23872
+ let c = e;
23873
+ Array.isArray(e) || (c = [e]);
23874
+ let o = t;
23875
+ return Array.isArray(t) || (o = [t]), (await (await fetch(`${FORMANT_API_URL}/v1/queries/queries`, {
23876
23876
  method: "POST",
23877
23877
  body: JSON.stringify({
23878
- deviceIds: s,
23878
+ deviceIds: c,
23879
23879
  end: r.toISOString(),
23880
- names: c,
23880
+ names: o,
23881
23881
  start: n.toISOString(),
23882
- tags: l
23882
+ tags: l,
23883
+ latestOnly: s
23883
23884
  }),
23884
23885
  headers: {
23885
23886
  "Content-Type": "application/json",
@@ -24236,7 +24237,7 @@ class Device extends BaseDevice {
24236
24237
  })).json();
24237
24238
  return new CaptureStream(r);
24238
24239
  }
24239
- async getTelemetry(t, n, r, l, s, c) {
24240
+ async getTelemetry(t, n, r, l, s, c, o) {
24240
24241
  if (s !== void 0 || c !== void 0)
24241
24242
  throw new Error("Limit and offset are not supported in this method");
24242
24243
  return await getTelemetry(
@@ -24244,9 +24245,15 @@ class Device extends BaseDevice {
24244
24245
  t,
24245
24246
  n,
24246
24247
  r,
24247
- l
24248
+ l,
24249
+ o
24248
24250
  );
24249
24251
  }
24252
+ async queryEvents(t) {
24253
+ if (t.deviceIds)
24254
+ throw new Error("Cannot filter multiple devices via Device class");
24255
+ return t.deviceIds = [this.id], queryEvents(t);
24256
+ }
24250
24257
  async getTelemetryStreams() {
24251
24258
  var o, d;
24252
24259
  const t = await this.getConfiguration(), n = await fetch(
@@ -24344,13 +24351,98 @@ class PeerDevice extends BaseDevice {
24344
24351
  tags: {}
24345
24352
  }));
24346
24353
  }
24347
- async getTelemetry(n, r, l, s, c, o) {
24354
+ async getTelemetry(n, r, l, s, c, o, d) {
24348
24355
  if (Array.isArray(n))
24349
24356
  throw new Error("Multiple stream names not supported");
24350
24357
  if (s)
24351
24358
  throw new Error("Tags not supported");
24352
- let d = `${this.peerUrl}/v1/querydatapoints?stream_name=${n}&start=${r.toISOString()}&end=${l.toISOString()}`;
24353
- return c != null && c > 0 && (d += `&limit=${c}`), o != null && o >= 0 && (d += `&offset=${o}`), (await (await fetch(d)).json()).results;
24359
+ if (d && c === void 0)
24360
+ c = 1;
24361
+ else if (d && c !== void 0)
24362
+ throw new Error("latestOnly and limit cannot be used together");
24363
+ let u = `${this.peerUrl}/v1/querydatapoints?stream_name=${n}&start=${r.toISOString()}&end=${l.toISOString()}`;
24364
+ c != null && c > 0 && (u += `&limit=${c}`), o != null && o >= 0 && (u += `&offset=${o}`);
24365
+ const B = await (await fetch(u)).json(), R = [];
24366
+ for (const p of B.results) {
24367
+ const g = parseInt(p.timestamp), h = p.tags.data_type;
24368
+ delete p.tags.data_type, R.push({
24369
+ deviceId: this.id,
24370
+ name: p.stream,
24371
+ points: [[g, this.getPointPayload(h, p)]],
24372
+ tags: p.tags,
24373
+ type: h
24374
+ });
24375
+ }
24376
+ return R.reverse();
24377
+ }
24378
+ async queryEvents(n) {
24379
+ const r = [
24380
+ "id",
24381
+ "viewed",
24382
+ "keyword",
24383
+ "message",
24384
+ "sort",
24385
+ "eventTypes",
24386
+ "notificationEnabled",
24387
+ "userIds",
24388
+ "annotationTemplateIds",
24389
+ "disableNullMatches",
24390
+ "severities",
24391
+ "deviceIds",
24392
+ "names",
24393
+ "types",
24394
+ "tags",
24395
+ "notNames"
24396
+ ];
24397
+ this.checkKeysAndThrow(n, r);
24398
+ let l = `${this.peerUrl}/v1/queryevents?start=${n.start}&end=${n.end}`;
24399
+ n.count != null && n.count > 0 && (l += `&limit=${n.count}`), n.offset != null && n.offset >= 0 && (l += `&offset=${n.offset}`);
24400
+ const c = await (await fetch(l)).json(), o = [];
24401
+ for (const d of c.results) {
24402
+ const u = parseInt(d.timestamp), U = {
24403
+ deviceId: this.id,
24404
+ time: new Date(u).toISOString(),
24405
+ message: d.message,
24406
+ notificationEnabled: d.notificationEnabled
24407
+ };
24408
+ d.id !== "" && (U.id = d.id), d.type !== "" && (U.type = d.type), d.streamName !== "" && (U.streamName = d.streamName), d.streamType !== "" && (U.streamType = d.streamType), d.severity !== "" && (U.severity = d.severity.toLowerCase()), d.tags && (U.tags = d.tags), d.endTimestamp !== "0" && (U.endTime = new Date(parseInt(d.endTimestamp)).toISOString()), o.push(U);
24409
+ }
24410
+ return o.reverse();
24411
+ }
24412
+ checkKeysAndThrow(n, r) {
24413
+ const l = r.filter((s) => s in n);
24414
+ if (l.length > 0)
24415
+ throw new Error(
24416
+ `Filters not currently supported: ${l.join(", ")}.`
24417
+ );
24418
+ }
24419
+ getPointPayload(n, r) {
24420
+ switch (n) {
24421
+ case "numeric":
24422
+ return r.numeric.value;
24423
+ case "numeric set":
24424
+ return r.numericSet.numerics;
24425
+ case "text":
24426
+ return r.text.value;
24427
+ case "json":
24428
+ return r.json.value;
24429
+ case "bitset":
24430
+ const l = [], s = [];
24431
+ for (const c of r.bitset.bits)
24432
+ l.push(c.key), s.push(c.value);
24433
+ return {
24434
+ keys: l,
24435
+ values: s
24436
+ };
24437
+ case "location":
24438
+ return r.location;
24439
+ case "health":
24440
+ return r.health;
24441
+ case "battery":
24442
+ return r.battery;
24443
+ default:
24444
+ return {};
24445
+ }
24354
24446
  }
24355
24447
  subscribeToTelemetry() {
24356
24448
  this.telemetryStreamActive = !0;