@devicechain/dashboards 0.27.0 → 1.0.0-rc.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/dist/index.js CHANGED
@@ -858,7 +858,13 @@ function parseCandidates(raw) {
858
858
  const token = (v) => typeof v === "string" && v ? v : void 0;
859
859
  const areaType = token(raw.areaType);
860
860
  const assetType = token(raw.assetType);
861
- return areaType || assetType ? { areaType, assetType } : void 0;
861
+ const deviceType = token(raw.deviceType);
862
+ if (!areaType && !assetType && !deviceType) return void 0;
863
+ return {
864
+ ...areaType ? { areaType } : {},
865
+ ...assetType ? { assetType } : {},
866
+ ...deviceType ? { deviceType } : {}
867
+ };
862
868
  }
863
869
  function parseScope(raw) {
864
870
  if (!isRecord(raw)) return void 0;
@@ -1419,7 +1425,7 @@ async function resolveSlotCandidates(definition, slot, bindings, resolver, liste
1419
1425
  if (def.type === "device") {
1420
1426
  let rows2;
1421
1427
  try {
1422
- rows2 = await lister("device");
1428
+ rows2 = await listEntities(lister, "device", def.candidates?.deviceType);
1423
1429
  } catch {
1424
1430
  return [];
1425
1431
  }
@@ -1770,12 +1776,18 @@ function setSlotScope(def, slotName, scope) {
1770
1776
  function setSlotCandidates(def, slotName, candidates) {
1771
1777
  if (!def.slots || !Object.prototype.hasOwnProperty.call(def.slots, slotName)) return def;
1772
1778
  const current = def.slots[slotName];
1773
- if (current.type !== "anchor" || current.scope) return def;
1779
+ if (current.scope) return def;
1774
1780
  const next = {};
1775
- if (candidates?.areaType) next.areaType = candidates.areaType;
1776
- if (candidates?.assetType) next.assetType = candidates.assetType;
1781
+ if (current.type === "anchor") {
1782
+ if (candidates?.areaType) next.areaType = candidates.areaType;
1783
+ if (candidates?.assetType) next.assetType = candidates.assetType;
1784
+ } else if (candidates?.deviceType) {
1785
+ next.deviceType = candidates.deviceType;
1786
+ }
1787
+ const asked = !!(candidates?.areaType || candidates?.assetType || candidates?.deviceType);
1788
+ if (asked && !next.areaType && !next.assetType && !next.deviceType) return def;
1777
1789
  const { candidates: _drop, ...rest } = current;
1778
- const slot = next.areaType || next.assetType ? { ...rest, candidates: next } : rest;
1790
+ const slot = next.areaType || next.assetType || next.deviceType ? { ...rest, candidates: next } : rest;
1779
1791
  return { ...def, slots: { ...def.slots, [slotName]: slot } };
1780
1792
  }
1781
1793
  function widgetBinding(def, widget) {
@@ -1928,7 +1940,7 @@ function createEntityLister() {
1928
1940
  function fetchKind(kind, criteria, typeToken) {
1929
1941
  switch (kind) {
1930
1942
  case "device":
1931
- return gql("device-management", LIST_DEVICES, { criteria }).then((r) => r.devices.results);
1943
+ return gql("device-management", LIST_DEVICES, { criteria: { ...criteria, deviceType: typeToken } }).then((r) => r.devices.results);
1932
1944
  case "customer":
1933
1945
  return gql("device-management", LIST_CUSTOMERS, { criteria }).then((r) => r.customers.results);
1934
1946
  case "area":
@@ -2128,7 +2140,7 @@ var ALARM_SEVERITY_COUNTS = `
2128
2140
  var ALARM_STREAM = `
2129
2141
  subscription DashboardAlarmStream(
2130
2142
  $originatorType: String
2131
- $originator: String
2143
+ $originatorToken: String
2132
2144
  $state: String
2133
2145
  $severity: String
2134
2146
  $alarmKey: String
@@ -2136,7 +2148,7 @@ var ALARM_STREAM = `
2136
2148
  ) {
2137
2149
  alarmStream(
2138
2150
  originatorType: $originatorType
2139
- originator: $originator
2151
+ originatorToken: $originatorToken
2140
2152
  state: $state
2141
2153
  severity: $severity
2142
2154
  alarmKey: $alarmKey
@@ -2579,7 +2591,7 @@ var DashboardHub = class {
2579
2591
  severity: sub.severity ?? null,
2580
2592
  acknowledged: sub.acknowledged ?? null
2581
2593
  };
2582
- const originators = tenantWide || anchor ? [{ originatorType: null, originator: null, anchor }] : tokens.map((token) => ({ originatorType: "device", originator: token }));
2594
+ const originators = tenantWide || anchor ? [{ originatorType: null, originatorToken: null, anchor }] : tokens.map((token) => ({ originatorType: "device", originatorToken: token }));
2583
2595
  if (sub.countBySeverity) {
2584
2596
  const pages2 = await Promise.all(
2585
2597
  originators.map(
@@ -5319,11 +5331,23 @@ function duplicateWidget(def, id) {
5319
5331
  }
5320
5332
 
5321
5333
  // src/resolver.ts
5322
- import { gql as gql3, isScopeUnsupportedError as isScopeUnsupportedError2 } from "@devicechain/client";
5334
+ import { decodeToken, gql as gql3, isScoped, isScopeUnsupportedError as isScopeUnsupportedError2, resolveAuthToken } from "@devicechain/client";
5323
5335
  var ANCHOR_PAGE_SIZE = 500;
5324
5336
  var DECLARED_BATCH_SIZE = 100;
5325
5337
  var trueSize = (reported, page) => Math.max(reported ?? page, page);
5326
- function readAnchorPage(anchor) {
5338
+ async function viewerIsScoped(viewer) {
5339
+ if (viewer.scoped !== null) return viewer.scoped;
5340
+ let token = null;
5341
+ try {
5342
+ token = await resolveAuthToken();
5343
+ } catch {
5344
+ token = null;
5345
+ }
5346
+ if (!token) return false;
5347
+ viewer.scoped = isScoped(decodeToken(token));
5348
+ return viewer.scoped;
5349
+ }
5350
+ function readAnchorPage(anchor, viewer) {
5327
5351
  if (anchor.targetType === "customer") {
5328
5352
  return gql3("device-management", CUSTOMER_DEVICES, {
5329
5353
  criteria: {
@@ -5342,9 +5366,9 @@ function readAnchorPage(anchor) {
5342
5366
  };
5343
5367
  });
5344
5368
  }
5345
- return readAreaOrAssetPage(anchor);
5369
+ return readAreaOrAssetPage(anchor, viewer);
5346
5370
  }
5347
- function readAreaOrAssetPage(anchor) {
5371
+ async function readAreaOrAssetPage(anchor, viewer) {
5348
5372
  const read = (relationshipType) => gql3("device-management", ANCHOR_DEVICES, {
5349
5373
  criteria: {
5350
5374
  pageNumber: 1,
@@ -5354,8 +5378,10 @@ function readAreaOrAssetPage(anchor) {
5354
5378
  relationshipType
5355
5379
  }
5356
5380
  });
5357
- return read(anchor.relationship).catch((err) => {
5358
- if (!isScopeUnsupportedError2(err)) throw err;
5381
+ const first = await viewerIsScoped(viewer) ? read() : read(anchor.relationship);
5382
+ return first.catch((err) => {
5383
+ if (!isScopeUnsupportedError2(err) || viewer.scoped === true) throw err;
5384
+ viewer.scoped = true;
5359
5385
  return read();
5360
5386
  }).then((r) => {
5361
5387
  const rows = r.anchorDevices.results;
@@ -5368,6 +5394,7 @@ function readAreaOrAssetPage(anchor) {
5368
5394
  });
5369
5395
  }
5370
5396
  function createDeviceResolver() {
5397
+ const viewer = { scoped: null };
5371
5398
  const anchorCache = /* @__PURE__ */ new Map();
5372
5399
  const memberCache = /* @__PURE__ */ new Map();
5373
5400
  const existsCache = /* @__PURE__ */ new Map();
@@ -5380,7 +5407,7 @@ function createDeviceResolver() {
5380
5407
  const key = anchorKey(anchor);
5381
5408
  let pending = anchorCache.get(key);
5382
5409
  if (!pending) {
5383
- pending = readAnchorPage(anchor).catch((err) => {
5410
+ pending = readAnchorPage(anchor, viewer).catch((err) => {
5384
5411
  anchorCache.delete(key);
5385
5412
  throw err;
5386
5413
  });