myio-js-library 0.1.582 → 0.1.584

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.cjs CHANGED
@@ -989,7 +989,7 @@ module.exports = __toCommonJS(src_exports);
989
989
  // package.json
990
990
  var package_default = {
991
991
  name: "myio-js-library",
992
- version: "0.1.582",
992
+ version: "0.1.584",
993
993
  description: "A clean, standalone JS SDK for MYIO projects",
994
994
  license: "MIT",
995
995
  repository: "github:gh-myio/myio-js-library",
@@ -42688,7 +42688,7 @@ var WaterTankModalView = class {
42688
42688
  const d = new Date(ts);
42689
42689
  return `${pad3(d.getDate())}/${pad3(d.getMonth() + 1)} ${pad3(d.getHours())}:${pad3(d.getMinutes())}`;
42690
42690
  };
42691
- const fmtDay2 = (ts) => {
42691
+ const fmtDay3 = (ts) => {
42692
42692
  const d = new Date(ts);
42693
42693
  return `${pad3(d.getDate())}/${pad3(d.getMonth() + 1)}`;
42694
42694
  };
@@ -42725,7 +42725,7 @@ var WaterTankModalView = class {
42725
42725
  <div id="myio-water-tank-kpis" style="display: flex; gap: 12px; margin-top: 12px; flex-wrap: wrap;">
42726
42726
  ${kpiCard("M\xE9dia do per\xEDodo", `<div style="font-size: 22px; font-weight: 700; color: #2c3e50;">${fmtVal(avg)}</div>`)}
42727
42727
  ${kpiCard("Top 3 picos", peaks.map((p) => listRow(fmtTs(p.ts), fmtVal(p.value))).join(""))}
42728
- ${kpiCard("Top 3 dias mais baixos", lowestDays.map((d) => listRow(fmtDay2(d.ts), fmtVal(d.avg))).join(""))}
42728
+ ${kpiCard("Top 3 dias mais baixos", lowestDays.map((d) => listRow(fmtDay3(d.ts), fmtVal(d.avg))).join(""))}
42729
42729
  </div>`;
42730
42730
  }
42731
42731
  /**
@@ -65786,13 +65786,6 @@ var INCIDENT_STATUS_LABELS = {
65786
65786
  RESOLVED: "Resolvido",
65787
65787
  CLOSED: "Fechado"
65788
65788
  };
65789
- var SEVERITY_COLORS = {
65790
- CRITICAL: "#dc2626",
65791
- HIGH: "#f59e0b",
65792
- MEDIUM: "#3b82f6",
65793
- LOW: "#6b7280",
65794
- INFO: "#6b7280"
65795
- };
65796
65789
  var STYLES_ID4 = "myio-dops-styles";
65797
65790
  function esc5(value) {
65798
65791
  return String(value ?? "").replace(
@@ -65833,32 +65826,76 @@ async function fetchDeviceWorkOrders(config2) {
65833
65826
  const items = Array.isArray(data) ? data : Array.isArray(data?.items) ? data.items : [];
65834
65827
  return items;
65835
65828
  }
65829
+ function isOpenCritical(i) {
65830
+ return String(i.severity) === "CRITICAL" && !["RESOLVED", "CLOSED"].includes(String(i.status));
65831
+ }
65832
+ var WEEKDAYS_PT = ["dom", "seg", "ter", "qua", "qui", "sex", "s\xE1b"];
65833
+ function fmtDay(day) {
65834
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(day || ""));
65835
+ if (!m) return day ? String(day) : "\u2014";
65836
+ const wd = WEEKDAYS_PT[new Date(Date.UTC(+m[1], +m[2] - 1, +m[3])).getUTCDay()];
65837
+ return `${m[3]}/${m[2]}/${m[1]} \xB7 ${wd}`;
65838
+ }
65839
+ function relativeAgo(ts, now) {
65840
+ const min = Math.max(0, Math.round((now - ts) / 6e4));
65841
+ if (min < 60) return `h\xE1 ${min} min`;
65842
+ if (min < 48 * 60) return `h\xE1 ${Math.round(min / 60)} h`;
65843
+ return `h\xE1 ${Math.round(min / 1440)} dias`;
65844
+ }
65836
65845
  async function fetchDeviceIncidents(config2) {
65837
65846
  const api = resolveApi(config2);
65838
- if (!api.gcdrDeviceId) return [];
65839
- const url = `${api.alarmsBase}/incidents?device=${encodeURIComponent(api.gcdrDeviceId)}&sortBy=firstDetectedAt&sortDir=desc&limit=100`;
65847
+ const deviceKey = String(config2.ingestionId || api.gcdrDeviceId || "");
65848
+ if (!deviceKey) return [];
65849
+ const url = `${api.alarmsBase}/incidents?device=${encodeURIComponent(deviceKey)}&severity=CRITICAL&sortBy=firstDetectedAt&sortDir=desc&limit=100`;
65840
65850
  const res = await fetch(url, { headers: api.headers });
65841
65851
  if (!res.ok) throw Object.assign(new Error(`Alarms incidents HTTP ${res.status}`), { status: res.status });
65842
65852
  const body = await res.json();
65843
65853
  return Array.isArray(body?.data) ? body.data : [];
65844
65854
  }
65845
- function countDeviceFreshdeskTickets(identifier) {
65846
- const tso = globalThis.window?.TicketServiceOrchestrator;
65847
- if (!identifier || typeof tso?.getTicketCountForDevice !== "function") return 0;
65848
- return Number(tso.getTicketCountForDevice(identifier)) || 0;
65855
+ async function fetchWorkOrderUsers(config2) {
65856
+ const api = resolveApi(config2);
65857
+ const map = /* @__PURE__ */ new Map();
65858
+ try {
65859
+ const res = await fetch(`${api.alarmsBase}/incidents/work-order-users`, { headers: api.headers });
65860
+ if (!res.ok) return map;
65861
+ const body = await res.json();
65862
+ const list = Array.isArray(body) ? body : Array.isArray(body?.data) ? body.data : Array.isArray(body?.items) ? body.items : [];
65863
+ list.forEach((u) => u?.id && map.set(String(u.id), u));
65864
+ } catch {
65865
+ }
65866
+ return map;
65867
+ }
65868
+ function assigneeHTML(id, users) {
65869
+ if (!id) return '<span class="dops-muted">\u2014</span>';
65870
+ const u = users.get(String(id));
65871
+ if (u && (u.name || u.email)) {
65872
+ return `<div class="dops-person" title="${esc5(id)}"><b>${esc5(u.name || u.email)}</b>${u.name && u.email ? `<small>${esc5(u.email)}</small>` : ""}</div>`;
65873
+ }
65874
+ return `<span class="dops-muted dops-mono" title="${esc5(id)}">usu\xE1rio ${esc5(String(id).slice(0, 8))}\u2026</span>`;
65849
65875
  }
65850
65876
  function injectStyles9() {
65851
65877
  if (document.getElementById(STYLES_ID4)) return;
65852
65878
  const style = document.createElement("style");
65853
65879
  style.id = STYLES_ID4;
65854
65880
  style.textContent = `
65855
- .dops-tab { padding: 4px 2px 20px; font-family: 'Nunito', system-ui, sans-serif; }
65881
+ .dops-tab { padding: 4px 2px 20px; }
65882
+ .dops-tab, .dops-tab table, .dops-tab th, .dops-tab td, .dops-tab b, .dops-tab small, .dops-tab span {
65883
+ font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
65884
+ }
65885
+ .dops-day { white-space:nowrap; font-variant-numeric: tabular-nums; }
65886
+ /* o modal define td/th em 16px \u2014 fixa o tamanho nas pr\xF3prias c\xE9lulas (OSs e Incidentes) */
65887
+ .dops-tab .dops-table td { font-size:12px; line-height:1.45; }
65888
+ .dops-tab .dops-table th { font-size:11px; text-transform:uppercase; letter-spacing:.04em; }
65889
+ .dops-tab .dops-table td.dops-muted { font-size:11.5px; }
65890
+ .dops-tab .dops-chip { font-size:11px; }
65891
+ .dops-tab .dops-table th.dops-col-date { width:140px; min-width:140px; }
65856
65892
  .dops-notice { background:#f1ecfa; color:#3e1a7d; border-radius:8px; padding:8px 12px; font-size:12px; margin-bottom:14px; }
65857
65893
  .dops-state { padding:28px 16px; text-align:center; color:#6b7280; font-size:13px; }
65858
65894
  .dops-error { color:#b91c1c; }
65859
65895
  .dops-summary { display:flex; gap:10px; flex-wrap:wrap; margin-bottom:12px; }
65860
65896
  .dops-kpi { border:1px solid #e5e7eb; border-radius:8px; padding:8px 12px; min-width:110px; background:#fff; }
65861
65897
  .dops-kpi b { display:block; font-size:18px; color:#111827; }
65898
+ .dops-kpi--crit b { color:#dc2626; }
65862
65899
  .dops-kpi span { font-size:11px; color:#6b7280; text-transform:uppercase; letter-spacing:.4px; }
65863
65900
  .dops-table { width:100%; border-collapse:collapse; font-size:12px; background:#fff; border:1px solid #e5e7eb; border-radius:8px; overflow:hidden; }
65864
65901
  .dops-table th { text-align:left; background:#f9fafb; color:#6b7280; font-weight:700; padding:8px 10px; border-bottom:1px solid #e5e7eb; white-space:nowrap; }
@@ -65867,6 +65904,9 @@ function injectStyles9() {
65867
65904
  .dops-chip { display:inline-block; padding:2px 8px; border-radius:999px; font-size:11px; font-weight:700; background:#f3f4f6; color:#374151; white-space:nowrap; }
65868
65905
  .dops-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
65869
65906
  .dops-muted { color:#9ca3af; }
65907
+ .dops-person { display:flex; flex-direction:column; gap:1px; min-width:0; }
65908
+ .dops-person b { font-weight:700; }
65909
+ .dops-person small { font-size:11px; color:#6b7280; }
65870
65910
  .theme-dark .dops-table, .theme-dark .dops-kpi { background:#111827; border-color:#374151; }
65871
65911
  .theme-dark .dops-table th { background:#1f2937; color:#9ca3af; border-color:#374151; }
65872
65912
  .theme-dark .dops-table td { color:#e5e7eb; border-color:#1f2937; }
@@ -65879,83 +65919,86 @@ function noDeviceHTML(what) {
65879
65919
  }
65880
65920
  async function renderDeviceWorkOrdersTab(container, config2) {
65881
65921
  injectStyles9();
65882
- const tickets = countDeviceFreshdeskTickets(config2.identifier);
65883
65922
  if (!config2.gcdrDeviceId) {
65884
65923
  container.innerHTML = `<div class="dops-tab">${noDeviceHTML("OSs")}</div>`;
65885
- return tickets;
65924
+ return 0;
65886
65925
  }
65887
65926
  container.innerHTML = `<div class="dops-tab"><div class="dops-state">Carregando ordens de servi\xE7o\u2026</div></div>`;
65888
65927
  let orders = [];
65889
65928
  let errorHtml = "";
65929
+ const usersPromise = fetchWorkOrderUsers(config2);
65890
65930
  try {
65891
65931
  orders = await fetchDeviceWorkOrders(config2);
65892
65932
  } catch (e) {
65893
- errorHtml = e?.status === 401 || e?.status === 403 ? "O GCDR ainda n\xE3o libera a leitura de OSs com a chave do customer (as rotas /wo/work-orders exigem login de usu\xE1rio GCDR)." : `Erro ao carregar OSs: ${esc5(e?.message || e)}`;
65933
+ errorHtml = e?.status === 401 || e?.status === 403 ? "O GCDR recusou a leitura das OSs com a chave deste customer (falta o escopo wo:read na chave)." : `Erro ao carregar OSs: ${esc5(e?.message || e)}`;
65894
65934
  }
65895
65935
  const open = orders.filter((o) => !["FINALIZADA", "CANCELADA"].includes(String(o.status))).length;
65936
+ const users = await usersPromise;
65896
65937
  const rows = orders.slice().sort((a, b) => String(b.createdAt || "").localeCompare(String(a.createdAt || ""))).map(
65897
65938
  (o) => `<tr>
65898
65939
  <td class="dops-mono">${esc5(o.code || o.id)}</td>
65899
65940
  <td>${esc5(o.title || "\u2014")}</td>
65900
65941
  <td>${esc5(WO_TYPE_LABELS[String(o.type)] || o.type || "\u2014")}</td>
65901
65942
  <td><span class="dops-chip">${esc5(WO_STATUS_LABELS[String(o.status)] || o.status || "\u2014")}</span></td>
65902
- <td>${esc5(o.assignedTo || "\u2014")}</td>
65943
+ <td>${assigneeHTML(o.assignedTo, users)}</td>
65903
65944
  <td>${fmtDate(o.scheduledAt)}</td>
65904
65945
  <td>${fmtDate(o.createdAt)}</td>
65905
65946
  </tr>`
65906
65947
  ).join("");
65907
65948
  container.innerHTML = `
65908
65949
  <div class="dops-tab">
65909
- <div class="dops-notice">\u{1F512} Vis\xEDvel s\xF3 para usu\xE1rios MyIO. A contagem da aba soma OSs e chamados (FreshDesk) do dispositivo.</div>
65950
+ <div class="dops-notice">\u{1F512} Vis\xEDvel s\xF3 para usu\xE1rios MyIO. Ordens de servi\xE7o do GCDR que incluem este dispositivo.</div>
65910
65951
  <div class="dops-summary">
65911
65952
  <div class="dops-kpi"><b>${errorHtml ? "\u2014" : orders.length}</b><span>OSs</span></div>
65912
65953
  <div class="dops-kpi"><b>${errorHtml ? "\u2014" : open}</b><span>OSs em aberto</span></div>
65913
- <div class="dops-kpi"><b>${tickets}</b><span>Chamados</span></div>
65914
65954
  </div>
65915
65955
  ${errorHtml ? `<div class="dops-state dops-error">${errorHtml}</div>` : orders.length ? `<table class="dops-table"><thead><tr><th>C\xF3digo</th><th>T\xEDtulo</th><th>Tipo</th><th>Status</th><th>Respons\xE1vel</th><th>Agendada</th><th>Criada</th></tr></thead><tbody>${rows}</tbody></table>` : `<div class="dops-state">Nenhuma OS para este dispositivo.</div>`}
65916
65956
  </div>`;
65917
- return (errorHtml ? 0 : orders.length) + tickets;
65957
+ return errorHtml ? 0 : open;
65918
65958
  }
65919
65959
  async function renderDeviceIncidentsTab(container, config2) {
65920
65960
  injectStyles9();
65921
- if (!config2.gcdrDeviceId) {
65961
+ if (!config2.ingestionId && !config2.gcdrDeviceId) {
65922
65962
  container.innerHTML = `<div class="dops-tab">${noDeviceHTML("Incidentes")}</div>`;
65923
65963
  return 0;
65924
65964
  }
65925
- container.innerHTML = `<div class="dops-tab"><div class="dops-state">Carregando incidentes\u2026</div></div>`;
65965
+ container.innerHTML = `<div class="dops-tab"><div class="dops-state">Carregando incidentes cr\xEDticos\u2026</div></div>`;
65926
65966
  let incidents = [];
65927
65967
  try {
65928
- incidents = await fetchDeviceIncidents(config2);
65968
+ incidents = (await fetchDeviceIncidents(config2)).filter(isOpenCritical);
65929
65969
  } catch (e) {
65930
65970
  container.innerHTML = `<div class="dops-tab"><div class="dops-state dops-error">Erro ao carregar incidentes: ${esc5(
65931
65971
  e?.message || e
65932
65972
  )}</div></div>`;
65933
65973
  return 0;
65934
65974
  }
65935
- const active = incidents.filter((i) => !["RESOLVED", "CLOSED"].includes(String(i.status))).length;
65936
- const rows = incidents.map((i) => {
65937
- const sev = String(i.severity || "");
65938
- return `<tr>
65939
- <td><span class="dops-chip" style="background:${SEVERITY_COLORS[sev] || "#6b7280"};color:#fff">${esc5(sev || "\u2014")}</span></td>
65940
- <td>${esc5(i.kind || "\u2014")}</td>
65975
+ const now = Date.now();
65976
+ const unacked = incidents.filter((i) => String(i.status) === "OPEN").length;
65977
+ const detected = incidents.map((i) => Date.parse(i.firstDetectedAt || "")).filter((t) => Number.isFinite(t));
65978
+ const oldest = detected.length ? Math.min(...detected) : null;
65979
+ const newest = detected.length ? Math.max(...detected) : null;
65980
+ const daysOpen = oldest !== null ? Math.max(1, Math.round((now - oldest) / 864e5)) : null;
65981
+ const rows = incidents.map(
65982
+ (i) => `<tr>
65983
+ <td class="dops-day">${esc5(fmtDay(i.day))}</td>
65941
65984
  <td><span class="dops-chip">${esc5(INCIDENT_STATUS_LABELS[String(i.status)] || i.status || "\u2014")}</span></td>
65942
- <td>${esc5(i.day || "\u2014")}</td>
65943
- <td>${esc5(i.centralName || "\u2014")}</td>
65944
- <td>${fmtDate(i.firstDetectedAt)}</td>
65945
- <td>${fmtDate(i.lastEvaluatedAt)}</td>
65985
+ <td class="dops-day">${fmtDate(i.firstDetectedAt)}</td>
65986
+ <td class="dops-day">${fmtDate(i.lastEvaluatedAt)}</td>
65946
65987
  <td class="dops-muted">${esc5(i.description || "")}</td>
65947
- </tr>`;
65948
- }).join("");
65988
+ </tr>`
65989
+ ).join("");
65949
65990
  container.innerHTML = `
65950
65991
  <div class="dops-tab">
65951
- <div class="dops-notice">\u{1F512} Vis\xEDvel s\xF3 para usu\xE1rios MyIO. Incidentes do alarms-backend que envolvem este dispositivo.</div>
65992
+ <div class="dops-notice">\u{1F512} Vis\xEDvel s\xF3 para usu\xE1rios MyIO. Incidentes <b>cr\xEDticos em aberto</b> do alarms-backend que envolvem este dispositivo.</div>
65952
65993
  <div class="dops-summary">
65953
- <div class="dops-kpi"><b>${incidents.length}</b><span>Incidentes</span></div>
65954
- <div class="dops-kpi"><b>${active}</b><span>N\xE3o resolvidos</span></div>
65994
+ <div class="dops-kpi dops-kpi--crit"><b>${incidents.length}</b><span>Cr\xEDticos abertos</span></div>
65995
+ <div class="dops-kpi"><b>${unacked}</b><span>Sem reconhecimento</span></div>
65996
+ <div class="dops-kpi"><b>${daysOpen === null ? "\u2014" : daysOpen + (daysOpen === 1 ? " dia" : " dias")}</b><span>Aberto h\xE1 (mais antigo)</span></div>
65997
+ <div class="dops-kpi"><b>${newest === null ? "\u2014" : esc5(relativeAgo(newest, now))}</b><span>\xDAltima detec\xE7\xE3o</span></div>
65955
65998
  </div>
65956
- ${incidents.length ? `<table class="dops-table"><thead><tr><th>Severidade</th><th>Tipo</th><th>Status</th><th>Dia</th><th>Central</th><th>Detectado</th><th>\xDAltima avalia\xE7\xE3o</th><th>Descri\xE7\xE3o</th></tr></thead><tbody>${rows}</tbody></table>` : `<div class="dops-state">Nenhum incidente para este dispositivo.</div>`}
65999
+ ${incidents.length ? `<table class="dops-table"><thead><tr><th>Dia</th><th>Status</th><th class="dops-col-date">Detectado</th><th class="dops-col-date">\xDAltima avalia\xE7\xE3o</th><th>Descri\xE7\xE3o</th></tr></thead><tbody>${rows}</tbody></table>` : `<div class="dops-state">Nenhum incidente cr\xEDtico em aberto para este dispositivo.</div>`}
65957
66000
  </div>`;
65958
- return active;
66001
+ return incidents.length;
65959
66002
  }
65960
66003
 
65961
66004
  // src/components/premium-modals/settings/commercialCatalog.ts
@@ -66451,10 +66494,21 @@ var SettingsModalView = class _SettingsModalView {
66451
66494
  const email = String(this.config.userEmail || "").toLowerCase().trim();
66452
66495
  return !!email && email.endsWith(ALLOWED_EMAIL_DOMAIN.toLowerCase());
66453
66496
  }
66497
+ /** ingestionId do dispositivo pelo estado do dashboard (host antigo que não o envia). */
66498
+ lookupIngestionId() {
66499
+ const id = String(this.config.deviceId || "");
66500
+ const state6 = window.STATE || {};
66501
+ for (const d of ["energy", "water", "temperature"]) {
66502
+ const hit = (state6[d]?._raw || []).find((it) => String(it?.tbId || it?.id) === id);
66503
+ if (hit?.ingestionId) return String(hit.ingestionId);
66504
+ }
66505
+ return null;
66506
+ }
66454
66507
  /** Abas OSs + Incidentes do dispositivo (GCDR work-orders / alarms-backend incidents). */
66455
66508
  initDeviceOpsTabs() {
66456
66509
  const cfg = {
66457
66510
  gcdrDeviceId: this.config.gcdrDeviceId,
66511
+ ingestionId: this.config.ingestionId || this.lookupIngestionId(),
66458
66512
  identifier: this.config.identifier,
66459
66513
  gcdrApiBaseUrl: this.config.gcdrApiBaseUrl
66460
66514
  };
@@ -80828,6 +80882,7 @@ var SettingsController = class {
80828
80882
  // RFC-0180: Raw device name + GCDR identifiers for Alarms tab
80829
80883
  deviceName: params.deviceName,
80830
80884
  gcdrDeviceId: params.gcdrDeviceId,
80885
+ ingestionId: params.ingestionId ?? null,
80831
80886
  gcdrCustomerId: params.gcdrCustomerId,
80832
80887
  gcdrTenantId: params.gcdrTenantId,
80833
80888
  gcdrApiBaseUrl: params.gcdrApiBaseUrl,
@@ -84373,7 +84428,7 @@ var esc6 = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<
84373
84428
  var norm = (s) => String(s ?? "").normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase();
84374
84429
  var fmtN = (n) => n.toLocaleString("pt-BR");
84375
84430
  var pad = (n) => String(n).padStart(2, "0");
84376
- var fmtDay = (ms) => {
84431
+ var fmtDay2 = (ms) => {
84377
84432
  const p = spParts(ms);
84378
84433
  return `${pad(p.d)}/${pad(p.m + 1)}`;
84379
84434
  };
@@ -84921,7 +84976,7 @@ var DemandPanelV2 = class {
84921
84976
  }
84922
84977
  jobTitle(e) {
84923
84978
  const r = e.request;
84924
- return `${r.devices.length} medidor(es) \xB7 ${fmtDay(Date.parse(r.period.start))}\u2013${fmtDay(Date.parse(r.period.end) - 1)} \xB7 ${this.resolutionLabel(r.resolution)}`;
84979
+ return `${r.devices.length} medidor(es) \xB7 ${fmtDay2(Date.parse(r.period.start))}\u2013${fmtDay2(Date.parse(r.period.end) - 1)} \xB7 ${this.resolutionLabel(r.resolution)}`;
84925
84980
  }
84926
84981
  renderJobs() {
84927
84982
  const s = this.s;
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  // package.json
11
11
  var package_default = {
12
12
  name: "myio-js-library",
13
- version: "0.1.582",
13
+ version: "0.1.584",
14
14
  description: "A clean, standalone JS SDK for MYIO projects",
15
15
  license: "MIT",
16
16
  repository: "github:gh-myio/myio-js-library",
@@ -40984,7 +40984,7 @@ var WaterTankModalView = class {
40984
40984
  const d = new Date(ts);
40985
40985
  return `${pad3(d.getDate())}/${pad3(d.getMonth() + 1)} ${pad3(d.getHours())}:${pad3(d.getMinutes())}`;
40986
40986
  };
40987
- const fmtDay2 = (ts) => {
40987
+ const fmtDay3 = (ts) => {
40988
40988
  const d = new Date(ts);
40989
40989
  return `${pad3(d.getDate())}/${pad3(d.getMonth() + 1)}`;
40990
40990
  };
@@ -41021,7 +41021,7 @@ var WaterTankModalView = class {
41021
41021
  <div id="myio-water-tank-kpis" style="display: flex; gap: 12px; margin-top: 12px; flex-wrap: wrap;">
41022
41022
  ${kpiCard("M\xE9dia do per\xEDodo", `<div style="font-size: 22px; font-weight: 700; color: #2c3e50;">${fmtVal(avg)}</div>`)}
41023
41023
  ${kpiCard("Top 3 picos", peaks.map((p) => listRow(fmtTs(p.ts), fmtVal(p.value))).join(""))}
41024
- ${kpiCard("Top 3 dias mais baixos", lowestDays.map((d) => listRow(fmtDay2(d.ts), fmtVal(d.avg))).join(""))}
41024
+ ${kpiCard("Top 3 dias mais baixos", lowestDays.map((d) => listRow(fmtDay3(d.ts), fmtVal(d.avg))).join(""))}
41025
41025
  </div>`;
41026
41026
  }
41027
41027
  /**
@@ -64082,13 +64082,6 @@ var INCIDENT_STATUS_LABELS = {
64082
64082
  RESOLVED: "Resolvido",
64083
64083
  CLOSED: "Fechado"
64084
64084
  };
64085
- var SEVERITY_COLORS = {
64086
- CRITICAL: "#dc2626",
64087
- HIGH: "#f59e0b",
64088
- MEDIUM: "#3b82f6",
64089
- LOW: "#6b7280",
64090
- INFO: "#6b7280"
64091
- };
64092
64085
  var STYLES_ID4 = "myio-dops-styles";
64093
64086
  function esc5(value) {
64094
64087
  return String(value ?? "").replace(
@@ -64129,32 +64122,76 @@ async function fetchDeviceWorkOrders(config) {
64129
64122
  const items = Array.isArray(data) ? data : Array.isArray(data?.items) ? data.items : [];
64130
64123
  return items;
64131
64124
  }
64125
+ function isOpenCritical(i) {
64126
+ return String(i.severity) === "CRITICAL" && !["RESOLVED", "CLOSED"].includes(String(i.status));
64127
+ }
64128
+ var WEEKDAYS_PT = ["dom", "seg", "ter", "qua", "qui", "sex", "s\xE1b"];
64129
+ function fmtDay(day) {
64130
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(day || ""));
64131
+ if (!m) return day ? String(day) : "\u2014";
64132
+ const wd = WEEKDAYS_PT[new Date(Date.UTC(+m[1], +m[2] - 1, +m[3])).getUTCDay()];
64133
+ return `${m[3]}/${m[2]}/${m[1]} \xB7 ${wd}`;
64134
+ }
64135
+ function relativeAgo(ts, now) {
64136
+ const min = Math.max(0, Math.round((now - ts) / 6e4));
64137
+ if (min < 60) return `h\xE1 ${min} min`;
64138
+ if (min < 48 * 60) return `h\xE1 ${Math.round(min / 60)} h`;
64139
+ return `h\xE1 ${Math.round(min / 1440)} dias`;
64140
+ }
64132
64141
  async function fetchDeviceIncidents(config) {
64133
64142
  const api = resolveApi(config);
64134
- if (!api.gcdrDeviceId) return [];
64135
- const url = `${api.alarmsBase}/incidents?device=${encodeURIComponent(api.gcdrDeviceId)}&sortBy=firstDetectedAt&sortDir=desc&limit=100`;
64143
+ const deviceKey = String(config.ingestionId || api.gcdrDeviceId || "");
64144
+ if (!deviceKey) return [];
64145
+ const url = `${api.alarmsBase}/incidents?device=${encodeURIComponent(deviceKey)}&severity=CRITICAL&sortBy=firstDetectedAt&sortDir=desc&limit=100`;
64136
64146
  const res = await fetch(url, { headers: api.headers });
64137
64147
  if (!res.ok) throw Object.assign(new Error(`Alarms incidents HTTP ${res.status}`), { status: res.status });
64138
64148
  const body = await res.json();
64139
64149
  return Array.isArray(body?.data) ? body.data : [];
64140
64150
  }
64141
- function countDeviceFreshdeskTickets(identifier) {
64142
- const tso = globalThis.window?.TicketServiceOrchestrator;
64143
- if (!identifier || typeof tso?.getTicketCountForDevice !== "function") return 0;
64144
- return Number(tso.getTicketCountForDevice(identifier)) || 0;
64151
+ async function fetchWorkOrderUsers(config) {
64152
+ const api = resolveApi(config);
64153
+ const map = /* @__PURE__ */ new Map();
64154
+ try {
64155
+ const res = await fetch(`${api.alarmsBase}/incidents/work-order-users`, { headers: api.headers });
64156
+ if (!res.ok) return map;
64157
+ const body = await res.json();
64158
+ const list = Array.isArray(body) ? body : Array.isArray(body?.data) ? body.data : Array.isArray(body?.items) ? body.items : [];
64159
+ list.forEach((u) => u?.id && map.set(String(u.id), u));
64160
+ } catch {
64161
+ }
64162
+ return map;
64163
+ }
64164
+ function assigneeHTML(id, users) {
64165
+ if (!id) return '<span class="dops-muted">\u2014</span>';
64166
+ const u = users.get(String(id));
64167
+ if (u && (u.name || u.email)) {
64168
+ return `<div class="dops-person" title="${esc5(id)}"><b>${esc5(u.name || u.email)}</b>${u.name && u.email ? `<small>${esc5(u.email)}</small>` : ""}</div>`;
64169
+ }
64170
+ return `<span class="dops-muted dops-mono" title="${esc5(id)}">usu\xE1rio ${esc5(String(id).slice(0, 8))}\u2026</span>`;
64145
64171
  }
64146
64172
  function injectStyles9() {
64147
64173
  if (document.getElementById(STYLES_ID4)) return;
64148
64174
  const style = document.createElement("style");
64149
64175
  style.id = STYLES_ID4;
64150
64176
  style.textContent = `
64151
- .dops-tab { padding: 4px 2px 20px; font-family: 'Nunito', system-ui, sans-serif; }
64177
+ .dops-tab { padding: 4px 2px 20px; }
64178
+ .dops-tab, .dops-tab table, .dops-tab th, .dops-tab td, .dops-tab b, .dops-tab small, .dops-tab span {
64179
+ font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
64180
+ }
64181
+ .dops-day { white-space:nowrap; font-variant-numeric: tabular-nums; }
64182
+ /* o modal define td/th em 16px \u2014 fixa o tamanho nas pr\xF3prias c\xE9lulas (OSs e Incidentes) */
64183
+ .dops-tab .dops-table td { font-size:12px; line-height:1.45; }
64184
+ .dops-tab .dops-table th { font-size:11px; text-transform:uppercase; letter-spacing:.04em; }
64185
+ .dops-tab .dops-table td.dops-muted { font-size:11.5px; }
64186
+ .dops-tab .dops-chip { font-size:11px; }
64187
+ .dops-tab .dops-table th.dops-col-date { width:140px; min-width:140px; }
64152
64188
  .dops-notice { background:#f1ecfa; color:#3e1a7d; border-radius:8px; padding:8px 12px; font-size:12px; margin-bottom:14px; }
64153
64189
  .dops-state { padding:28px 16px; text-align:center; color:#6b7280; font-size:13px; }
64154
64190
  .dops-error { color:#b91c1c; }
64155
64191
  .dops-summary { display:flex; gap:10px; flex-wrap:wrap; margin-bottom:12px; }
64156
64192
  .dops-kpi { border:1px solid #e5e7eb; border-radius:8px; padding:8px 12px; min-width:110px; background:#fff; }
64157
64193
  .dops-kpi b { display:block; font-size:18px; color:#111827; }
64194
+ .dops-kpi--crit b { color:#dc2626; }
64158
64195
  .dops-kpi span { font-size:11px; color:#6b7280; text-transform:uppercase; letter-spacing:.4px; }
64159
64196
  .dops-table { width:100%; border-collapse:collapse; font-size:12px; background:#fff; border:1px solid #e5e7eb; border-radius:8px; overflow:hidden; }
64160
64197
  .dops-table th { text-align:left; background:#f9fafb; color:#6b7280; font-weight:700; padding:8px 10px; border-bottom:1px solid #e5e7eb; white-space:nowrap; }
@@ -64163,6 +64200,9 @@ function injectStyles9() {
64163
64200
  .dops-chip { display:inline-block; padding:2px 8px; border-radius:999px; font-size:11px; font-weight:700; background:#f3f4f6; color:#374151; white-space:nowrap; }
64164
64201
  .dops-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
64165
64202
  .dops-muted { color:#9ca3af; }
64203
+ .dops-person { display:flex; flex-direction:column; gap:1px; min-width:0; }
64204
+ .dops-person b { font-weight:700; }
64205
+ .dops-person small { font-size:11px; color:#6b7280; }
64166
64206
  .theme-dark .dops-table, .theme-dark .dops-kpi { background:#111827; border-color:#374151; }
64167
64207
  .theme-dark .dops-table th { background:#1f2937; color:#9ca3af; border-color:#374151; }
64168
64208
  .theme-dark .dops-table td { color:#e5e7eb; border-color:#1f2937; }
@@ -64175,83 +64215,86 @@ function noDeviceHTML(what) {
64175
64215
  }
64176
64216
  async function renderDeviceWorkOrdersTab(container, config) {
64177
64217
  injectStyles9();
64178
- const tickets = countDeviceFreshdeskTickets(config.identifier);
64179
64218
  if (!config.gcdrDeviceId) {
64180
64219
  container.innerHTML = `<div class="dops-tab">${noDeviceHTML("OSs")}</div>`;
64181
- return tickets;
64220
+ return 0;
64182
64221
  }
64183
64222
  container.innerHTML = `<div class="dops-tab"><div class="dops-state">Carregando ordens de servi\xE7o\u2026</div></div>`;
64184
64223
  let orders = [];
64185
64224
  let errorHtml = "";
64225
+ const usersPromise = fetchWorkOrderUsers(config);
64186
64226
  try {
64187
64227
  orders = await fetchDeviceWorkOrders(config);
64188
64228
  } catch (e) {
64189
- errorHtml = e?.status === 401 || e?.status === 403 ? "O GCDR ainda n\xE3o libera a leitura de OSs com a chave do customer (as rotas /wo/work-orders exigem login de usu\xE1rio GCDR)." : `Erro ao carregar OSs: ${esc5(e?.message || e)}`;
64229
+ errorHtml = e?.status === 401 || e?.status === 403 ? "O GCDR recusou a leitura das OSs com a chave deste customer (falta o escopo wo:read na chave)." : `Erro ao carregar OSs: ${esc5(e?.message || e)}`;
64190
64230
  }
64191
64231
  const open = orders.filter((o) => !["FINALIZADA", "CANCELADA"].includes(String(o.status))).length;
64232
+ const users = await usersPromise;
64192
64233
  const rows = orders.slice().sort((a, b) => String(b.createdAt || "").localeCompare(String(a.createdAt || ""))).map(
64193
64234
  (o) => `<tr>
64194
64235
  <td class="dops-mono">${esc5(o.code || o.id)}</td>
64195
64236
  <td>${esc5(o.title || "\u2014")}</td>
64196
64237
  <td>${esc5(WO_TYPE_LABELS[String(o.type)] || o.type || "\u2014")}</td>
64197
64238
  <td><span class="dops-chip">${esc5(WO_STATUS_LABELS[String(o.status)] || o.status || "\u2014")}</span></td>
64198
- <td>${esc5(o.assignedTo || "\u2014")}</td>
64239
+ <td>${assigneeHTML(o.assignedTo, users)}</td>
64199
64240
  <td>${fmtDate(o.scheduledAt)}</td>
64200
64241
  <td>${fmtDate(o.createdAt)}</td>
64201
64242
  </tr>`
64202
64243
  ).join("");
64203
64244
  container.innerHTML = `
64204
64245
  <div class="dops-tab">
64205
- <div class="dops-notice">\u{1F512} Vis\xEDvel s\xF3 para usu\xE1rios MyIO. A contagem da aba soma OSs e chamados (FreshDesk) do dispositivo.</div>
64246
+ <div class="dops-notice">\u{1F512} Vis\xEDvel s\xF3 para usu\xE1rios MyIO. Ordens de servi\xE7o do GCDR que incluem este dispositivo.</div>
64206
64247
  <div class="dops-summary">
64207
64248
  <div class="dops-kpi"><b>${errorHtml ? "\u2014" : orders.length}</b><span>OSs</span></div>
64208
64249
  <div class="dops-kpi"><b>${errorHtml ? "\u2014" : open}</b><span>OSs em aberto</span></div>
64209
- <div class="dops-kpi"><b>${tickets}</b><span>Chamados</span></div>
64210
64250
  </div>
64211
64251
  ${errorHtml ? `<div class="dops-state dops-error">${errorHtml}</div>` : orders.length ? `<table class="dops-table"><thead><tr><th>C\xF3digo</th><th>T\xEDtulo</th><th>Tipo</th><th>Status</th><th>Respons\xE1vel</th><th>Agendada</th><th>Criada</th></tr></thead><tbody>${rows}</tbody></table>` : `<div class="dops-state">Nenhuma OS para este dispositivo.</div>`}
64212
64252
  </div>`;
64213
- return (errorHtml ? 0 : orders.length) + tickets;
64253
+ return errorHtml ? 0 : open;
64214
64254
  }
64215
64255
  async function renderDeviceIncidentsTab(container, config) {
64216
64256
  injectStyles9();
64217
- if (!config.gcdrDeviceId) {
64257
+ if (!config.ingestionId && !config.gcdrDeviceId) {
64218
64258
  container.innerHTML = `<div class="dops-tab">${noDeviceHTML("Incidentes")}</div>`;
64219
64259
  return 0;
64220
64260
  }
64221
- container.innerHTML = `<div class="dops-tab"><div class="dops-state">Carregando incidentes\u2026</div></div>`;
64261
+ container.innerHTML = `<div class="dops-tab"><div class="dops-state">Carregando incidentes cr\xEDticos\u2026</div></div>`;
64222
64262
  let incidents = [];
64223
64263
  try {
64224
- incidents = await fetchDeviceIncidents(config);
64264
+ incidents = (await fetchDeviceIncidents(config)).filter(isOpenCritical);
64225
64265
  } catch (e) {
64226
64266
  container.innerHTML = `<div class="dops-tab"><div class="dops-state dops-error">Erro ao carregar incidentes: ${esc5(
64227
64267
  e?.message || e
64228
64268
  )}</div></div>`;
64229
64269
  return 0;
64230
64270
  }
64231
- const active = incidents.filter((i) => !["RESOLVED", "CLOSED"].includes(String(i.status))).length;
64232
- const rows = incidents.map((i) => {
64233
- const sev = String(i.severity || "");
64234
- return `<tr>
64235
- <td><span class="dops-chip" style="background:${SEVERITY_COLORS[sev] || "#6b7280"};color:#fff">${esc5(sev || "\u2014")}</span></td>
64236
- <td>${esc5(i.kind || "\u2014")}</td>
64271
+ const now = Date.now();
64272
+ const unacked = incidents.filter((i) => String(i.status) === "OPEN").length;
64273
+ const detected = incidents.map((i) => Date.parse(i.firstDetectedAt || "")).filter((t) => Number.isFinite(t));
64274
+ const oldest = detected.length ? Math.min(...detected) : null;
64275
+ const newest = detected.length ? Math.max(...detected) : null;
64276
+ const daysOpen = oldest !== null ? Math.max(1, Math.round((now - oldest) / 864e5)) : null;
64277
+ const rows = incidents.map(
64278
+ (i) => `<tr>
64279
+ <td class="dops-day">${esc5(fmtDay(i.day))}</td>
64237
64280
  <td><span class="dops-chip">${esc5(INCIDENT_STATUS_LABELS[String(i.status)] || i.status || "\u2014")}</span></td>
64238
- <td>${esc5(i.day || "\u2014")}</td>
64239
- <td>${esc5(i.centralName || "\u2014")}</td>
64240
- <td>${fmtDate(i.firstDetectedAt)}</td>
64241
- <td>${fmtDate(i.lastEvaluatedAt)}</td>
64281
+ <td class="dops-day">${fmtDate(i.firstDetectedAt)}</td>
64282
+ <td class="dops-day">${fmtDate(i.lastEvaluatedAt)}</td>
64242
64283
  <td class="dops-muted">${esc5(i.description || "")}</td>
64243
- </tr>`;
64244
- }).join("");
64284
+ </tr>`
64285
+ ).join("");
64245
64286
  container.innerHTML = `
64246
64287
  <div class="dops-tab">
64247
- <div class="dops-notice">\u{1F512} Vis\xEDvel s\xF3 para usu\xE1rios MyIO. Incidentes do alarms-backend que envolvem este dispositivo.</div>
64288
+ <div class="dops-notice">\u{1F512} Vis\xEDvel s\xF3 para usu\xE1rios MyIO. Incidentes <b>cr\xEDticos em aberto</b> do alarms-backend que envolvem este dispositivo.</div>
64248
64289
  <div class="dops-summary">
64249
- <div class="dops-kpi"><b>${incidents.length}</b><span>Incidentes</span></div>
64250
- <div class="dops-kpi"><b>${active}</b><span>N\xE3o resolvidos</span></div>
64290
+ <div class="dops-kpi dops-kpi--crit"><b>${incidents.length}</b><span>Cr\xEDticos abertos</span></div>
64291
+ <div class="dops-kpi"><b>${unacked}</b><span>Sem reconhecimento</span></div>
64292
+ <div class="dops-kpi"><b>${daysOpen === null ? "\u2014" : daysOpen + (daysOpen === 1 ? " dia" : " dias")}</b><span>Aberto h\xE1 (mais antigo)</span></div>
64293
+ <div class="dops-kpi"><b>${newest === null ? "\u2014" : esc5(relativeAgo(newest, now))}</b><span>\xDAltima detec\xE7\xE3o</span></div>
64251
64294
  </div>
64252
- ${incidents.length ? `<table class="dops-table"><thead><tr><th>Severidade</th><th>Tipo</th><th>Status</th><th>Dia</th><th>Central</th><th>Detectado</th><th>\xDAltima avalia\xE7\xE3o</th><th>Descri\xE7\xE3o</th></tr></thead><tbody>${rows}</tbody></table>` : `<div class="dops-state">Nenhum incidente para este dispositivo.</div>`}
64295
+ ${incidents.length ? `<table class="dops-table"><thead><tr><th>Dia</th><th>Status</th><th class="dops-col-date">Detectado</th><th class="dops-col-date">\xDAltima avalia\xE7\xE3o</th><th>Descri\xE7\xE3o</th></tr></thead><tbody>${rows}</tbody></table>` : `<div class="dops-state">Nenhum incidente cr\xEDtico em aberto para este dispositivo.</div>`}
64253
64296
  </div>`;
64254
- return active;
64297
+ return incidents.length;
64255
64298
  }
64256
64299
 
64257
64300
  // src/components/premium-modals/settings/commercialCatalog.ts
@@ -64747,10 +64790,21 @@ var SettingsModalView = class _SettingsModalView {
64747
64790
  const email = String(this.config.userEmail || "").toLowerCase().trim();
64748
64791
  return !!email && email.endsWith(ALLOWED_EMAIL_DOMAIN.toLowerCase());
64749
64792
  }
64793
+ /** ingestionId do dispositivo pelo estado do dashboard (host antigo que não o envia). */
64794
+ lookupIngestionId() {
64795
+ const id = String(this.config.deviceId || "");
64796
+ const state5 = window.STATE || {};
64797
+ for (const d of ["energy", "water", "temperature"]) {
64798
+ const hit = (state5[d]?._raw || []).find((it) => String(it?.tbId || it?.id) === id);
64799
+ if (hit?.ingestionId) return String(hit.ingestionId);
64800
+ }
64801
+ return null;
64802
+ }
64750
64803
  /** Abas OSs + Incidentes do dispositivo (GCDR work-orders / alarms-backend incidents). */
64751
64804
  initDeviceOpsTabs() {
64752
64805
  const cfg = {
64753
64806
  gcdrDeviceId: this.config.gcdrDeviceId,
64807
+ ingestionId: this.config.ingestionId || this.lookupIngestionId(),
64754
64808
  identifier: this.config.identifier,
64755
64809
  gcdrApiBaseUrl: this.config.gcdrApiBaseUrl
64756
64810
  };
@@ -79124,6 +79178,7 @@ var SettingsController = class {
79124
79178
  // RFC-0180: Raw device name + GCDR identifiers for Alarms tab
79125
79179
  deviceName: params.deviceName,
79126
79180
  gcdrDeviceId: params.gcdrDeviceId,
79181
+ ingestionId: params.ingestionId ?? null,
79127
79182
  gcdrCustomerId: params.gcdrCustomerId,
79128
79183
  gcdrTenantId: params.gcdrTenantId,
79129
79184
  gcdrApiBaseUrl: params.gcdrApiBaseUrl,
@@ -82669,7 +82724,7 @@ var esc6 = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<
82669
82724
  var norm = (s) => String(s ?? "").normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase();
82670
82725
  var fmtN = (n) => n.toLocaleString("pt-BR");
82671
82726
  var pad = (n) => String(n).padStart(2, "0");
82672
- var fmtDay = (ms) => {
82727
+ var fmtDay2 = (ms) => {
82673
82728
  const p = spParts(ms);
82674
82729
  return `${pad(p.d)}/${pad(p.m + 1)}`;
82675
82730
  };
@@ -83217,7 +83272,7 @@ var DemandPanelV2 = class {
83217
83272
  }
83218
83273
  jobTitle(e) {
83219
83274
  const r = e.request;
83220
- return `${r.devices.length} medidor(es) \xB7 ${fmtDay(Date.parse(r.period.start))}\u2013${fmtDay(Date.parse(r.period.end) - 1)} \xB7 ${this.resolutionLabel(r.resolution)}`;
83275
+ return `${r.devices.length} medidor(es) \xB7 ${fmtDay2(Date.parse(r.period.start))}\u2013${fmtDay2(Date.parse(r.period.end) - 1)} \xB7 ${this.resolutionLabel(r.resolution)}`;
83221
83276
  }
83222
83277
  renderJobs() {
83223
83278
  const s = this.s;