myio-js-library 0.1.583 → 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.583",
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,11 +65826,27 @@ 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
65847
  const deviceKey = String(config2.ingestionId || api.gcdrDeviceId || "");
65839
65848
  if (!deviceKey) return [];
65840
- const url = `${api.alarmsBase}/incidents?device=${encodeURIComponent(deviceKey)}&sortBy=firstDetectedAt&sortDir=desc&limit=100`;
65849
+ const url = `${api.alarmsBase}/incidents?device=${encodeURIComponent(deviceKey)}&severity=CRITICAL&sortBy=firstDetectedAt&sortDir=desc&limit=100`;
65841
65850
  const res = await fetch(url, { headers: api.headers });
65842
65851
  if (!res.ok) throw Object.assign(new Error(`Alarms incidents HTTP ${res.status}`), { status: res.status });
65843
65852
  const body = await res.json();
@@ -65869,13 +65878,24 @@ function injectStyles9() {
65869
65878
  const style = document.createElement("style");
65870
65879
  style.id = STYLES_ID4;
65871
65880
  style.textContent = `
65872
- .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; }
65873
65892
  .dops-notice { background:#f1ecfa; color:#3e1a7d; border-radius:8px; padding:8px 12px; font-size:12px; margin-bottom:14px; }
65874
65893
  .dops-state { padding:28px 16px; text-align:center; color:#6b7280; font-size:13px; }
65875
65894
  .dops-error { color:#b91c1c; }
65876
65895
  .dops-summary { display:flex; gap:10px; flex-wrap:wrap; margin-bottom:12px; }
65877
65896
  .dops-kpi { border:1px solid #e5e7eb; border-radius:8px; padding:8px 12px; min-width:110px; background:#fff; }
65878
65897
  .dops-kpi b { display:block; font-size:18px; color:#111827; }
65898
+ .dops-kpi--crit b { color:#dc2626; }
65879
65899
  .dops-kpi span { font-size:11px; color:#6b7280; text-transform:uppercase; letter-spacing:.4px; }
65880
65900
  .dops-table { width:100%; border-collapse:collapse; font-size:12px; background:#fff; border:1px solid #e5e7eb; border-radius:8px; overflow:hidden; }
65881
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; }
@@ -65942,44 +65962,43 @@ async function renderDeviceIncidentsTab(container, config2) {
65942
65962
  container.innerHTML = `<div class="dops-tab">${noDeviceHTML("Incidentes")}</div>`;
65943
65963
  return 0;
65944
65964
  }
65945
- 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>`;
65946
65966
  let incidents = [];
65947
65967
  try {
65948
- incidents = await fetchDeviceIncidents(config2);
65968
+ incidents = (await fetchDeviceIncidents(config2)).filter(isOpenCritical);
65949
65969
  } catch (e) {
65950
65970
  container.innerHTML = `<div class="dops-tab"><div class="dops-state dops-error">Erro ao carregar incidentes: ${esc5(
65951
65971
  e?.message || e
65952
65972
  )}</div></div>`;
65953
65973
  return 0;
65954
65974
  }
65955
- const active = incidents.filter((i) => !["RESOLVED", "CLOSED"].includes(String(i.status))).length;
65956
- const critical = incidents.filter(
65957
- (i) => String(i.severity) === "CRITICAL" && !["RESOLVED", "CLOSED"].includes(String(i.status))
65958
- ).length;
65959
- const rows = incidents.map((i) => {
65960
- const sev = String(i.severity || "");
65961
- return `<tr>
65962
- <td><span class="dops-chip" style="background:${SEVERITY_COLORS[sev] || "#6b7280"};color:#fff">${esc5(sev || "\u2014")}</span></td>
65963
- <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>
65964
65984
  <td><span class="dops-chip">${esc5(INCIDENT_STATUS_LABELS[String(i.status)] || i.status || "\u2014")}</span></td>
65965
- <td>${esc5(i.day || "\u2014")}</td>
65966
- <td>${esc5(i.centralName || "\u2014")}</td>
65967
- <td>${fmtDate(i.firstDetectedAt)}</td>
65968
- <td>${fmtDate(i.lastEvaluatedAt)}</td>
65985
+ <td class="dops-day">${fmtDate(i.firstDetectedAt)}</td>
65986
+ <td class="dops-day">${fmtDate(i.lastEvaluatedAt)}</td>
65969
65987
  <td class="dops-muted">${esc5(i.description || "")}</td>
65970
- </tr>`;
65971
- }).join("");
65988
+ </tr>`
65989
+ ).join("");
65972
65990
  container.innerHTML = `
65973
65991
  <div class="dops-tab">
65974
- <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>
65975
65993
  <div class="dops-summary">
65976
- <div class="dops-kpi"><b>${incidents.length}</b><span>Incidentes</span></div>
65977
- <div class="dops-kpi"><b>${active}</b><span>N\xE3o resolvidos</span></div>
65978
- <div class="dops-kpi"><b>${critical}</b><span>Cr\xEDticos abertos</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>
65979
65998
  </div>
65980
- ${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>`}
65981
66000
  </div>`;
65982
- return critical;
66001
+ return incidents.length;
65983
66002
  }
65984
66003
 
65985
66004
  // src/components/premium-modals/settings/commercialCatalog.ts
@@ -84409,7 +84428,7 @@ var esc6 = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<
84409
84428
  var norm = (s) => String(s ?? "").normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase();
84410
84429
  var fmtN = (n) => n.toLocaleString("pt-BR");
84411
84430
  var pad = (n) => String(n).padStart(2, "0");
84412
- var fmtDay = (ms) => {
84431
+ var fmtDay2 = (ms) => {
84413
84432
  const p = spParts(ms);
84414
84433
  return `${pad(p.d)}/${pad(p.m + 1)}`;
84415
84434
  };
@@ -84957,7 +84976,7 @@ var DemandPanelV2 = class {
84957
84976
  }
84958
84977
  jobTitle(e) {
84959
84978
  const r = e.request;
84960
- 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)}`;
84961
84980
  }
84962
84981
  renderJobs() {
84963
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.583",
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,11 +64122,27 @@ 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
64143
  const deviceKey = String(config.ingestionId || api.gcdrDeviceId || "");
64135
64144
  if (!deviceKey) return [];
64136
- const url = `${api.alarmsBase}/incidents?device=${encodeURIComponent(deviceKey)}&sortBy=firstDetectedAt&sortDir=desc&limit=100`;
64145
+ const url = `${api.alarmsBase}/incidents?device=${encodeURIComponent(deviceKey)}&severity=CRITICAL&sortBy=firstDetectedAt&sortDir=desc&limit=100`;
64137
64146
  const res = await fetch(url, { headers: api.headers });
64138
64147
  if (!res.ok) throw Object.assign(new Error(`Alarms incidents HTTP ${res.status}`), { status: res.status });
64139
64148
  const body = await res.json();
@@ -64165,13 +64174,24 @@ function injectStyles9() {
64165
64174
  const style = document.createElement("style");
64166
64175
  style.id = STYLES_ID4;
64167
64176
  style.textContent = `
64168
- .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; }
64169
64188
  .dops-notice { background:#f1ecfa; color:#3e1a7d; border-radius:8px; padding:8px 12px; font-size:12px; margin-bottom:14px; }
64170
64189
  .dops-state { padding:28px 16px; text-align:center; color:#6b7280; font-size:13px; }
64171
64190
  .dops-error { color:#b91c1c; }
64172
64191
  .dops-summary { display:flex; gap:10px; flex-wrap:wrap; margin-bottom:12px; }
64173
64192
  .dops-kpi { border:1px solid #e5e7eb; border-radius:8px; padding:8px 12px; min-width:110px; background:#fff; }
64174
64193
  .dops-kpi b { display:block; font-size:18px; color:#111827; }
64194
+ .dops-kpi--crit b { color:#dc2626; }
64175
64195
  .dops-kpi span { font-size:11px; color:#6b7280; text-transform:uppercase; letter-spacing:.4px; }
64176
64196
  .dops-table { width:100%; border-collapse:collapse; font-size:12px; background:#fff; border:1px solid #e5e7eb; border-radius:8px; overflow:hidden; }
64177
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; }
@@ -64238,44 +64258,43 @@ async function renderDeviceIncidentsTab(container, config) {
64238
64258
  container.innerHTML = `<div class="dops-tab">${noDeviceHTML("Incidentes")}</div>`;
64239
64259
  return 0;
64240
64260
  }
64241
- 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>`;
64242
64262
  let incidents = [];
64243
64263
  try {
64244
- incidents = await fetchDeviceIncidents(config);
64264
+ incidents = (await fetchDeviceIncidents(config)).filter(isOpenCritical);
64245
64265
  } catch (e) {
64246
64266
  container.innerHTML = `<div class="dops-tab"><div class="dops-state dops-error">Erro ao carregar incidentes: ${esc5(
64247
64267
  e?.message || e
64248
64268
  )}</div></div>`;
64249
64269
  return 0;
64250
64270
  }
64251
- const active = incidents.filter((i) => !["RESOLVED", "CLOSED"].includes(String(i.status))).length;
64252
- const critical = incidents.filter(
64253
- (i) => String(i.severity) === "CRITICAL" && !["RESOLVED", "CLOSED"].includes(String(i.status))
64254
- ).length;
64255
- const rows = incidents.map((i) => {
64256
- const sev = String(i.severity || "");
64257
- return `<tr>
64258
- <td><span class="dops-chip" style="background:${SEVERITY_COLORS[sev] || "#6b7280"};color:#fff">${esc5(sev || "\u2014")}</span></td>
64259
- <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>
64260
64280
  <td><span class="dops-chip">${esc5(INCIDENT_STATUS_LABELS[String(i.status)] || i.status || "\u2014")}</span></td>
64261
- <td>${esc5(i.day || "\u2014")}</td>
64262
- <td>${esc5(i.centralName || "\u2014")}</td>
64263
- <td>${fmtDate(i.firstDetectedAt)}</td>
64264
- <td>${fmtDate(i.lastEvaluatedAt)}</td>
64281
+ <td class="dops-day">${fmtDate(i.firstDetectedAt)}</td>
64282
+ <td class="dops-day">${fmtDate(i.lastEvaluatedAt)}</td>
64265
64283
  <td class="dops-muted">${esc5(i.description || "")}</td>
64266
- </tr>`;
64267
- }).join("");
64284
+ </tr>`
64285
+ ).join("");
64268
64286
  container.innerHTML = `
64269
64287
  <div class="dops-tab">
64270
- <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>
64271
64289
  <div class="dops-summary">
64272
- <div class="dops-kpi"><b>${incidents.length}</b><span>Incidentes</span></div>
64273
- <div class="dops-kpi"><b>${active}</b><span>N\xE3o resolvidos</span></div>
64274
- <div class="dops-kpi"><b>${critical}</b><span>Cr\xEDticos abertos</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>
64275
64294
  </div>
64276
- ${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>`}
64277
64296
  </div>`;
64278
- return critical;
64297
+ return incidents.length;
64279
64298
  }
64280
64299
 
64281
64300
  // src/components/premium-modals/settings/commercialCatalog.ts
@@ -82705,7 +82724,7 @@ var esc6 = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<
82705
82724
  var norm = (s) => String(s ?? "").normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase();
82706
82725
  var fmtN = (n) => n.toLocaleString("pt-BR");
82707
82726
  var pad = (n) => String(n).padStart(2, "0");
82708
- var fmtDay = (ms) => {
82727
+ var fmtDay2 = (ms) => {
82709
82728
  const p = spParts(ms);
82710
82729
  return `${pad(p.d)}/${pad(p.m + 1)}`;
82711
82730
  };
@@ -83253,7 +83272,7 @@ var DemandPanelV2 = class {
83253
83272
  }
83254
83273
  jobTitle(e) {
83255
83274
  const r = e.request;
83256
- 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)}`;
83257
83276
  }
83258
83277
  renderJobs() {
83259
83278
  const s = this.s;
@@ -5524,7 +5524,7 @@
5524
5524
 
5525
5525
  // package.json
5526
5526
  var package_default = {
5527
- version: "0.1.583"};
5527
+ version: "0.1.584"};
5528
5528
 
5529
5529
  // src/utils/format/energy.ts
5530
5530
  function formatPower(value, decimals = 2) {
@@ -46372,7 +46372,7 @@ ${kpiRows}` : ""}
46372
46372
  const d = new Date(ts);
46373
46373
  return `${pad3(d.getDate())}/${pad3(d.getMonth() + 1)} ${pad3(d.getHours())}:${pad3(d.getMinutes())}`;
46374
46374
  };
46375
- const fmtDay2 = (ts) => {
46375
+ const fmtDay3 = (ts) => {
46376
46376
  const d = new Date(ts);
46377
46377
  return `${pad3(d.getDate())}/${pad3(d.getMonth() + 1)}`;
46378
46378
  };
@@ -46409,7 +46409,7 @@ ${kpiRows}` : ""}
46409
46409
  <div id="myio-water-tank-kpis" style="display: flex; gap: 12px; margin-top: 12px; flex-wrap: wrap;">
46410
46410
  ${kpiCard("M\xE9dia do per\xEDodo", `<div style="font-size: 22px; font-weight: 700; color: #2c3e50;">${fmtVal(avg)}</div>`)}
46411
46411
  ${kpiCard("Top 3 picos", peaks.map((p) => listRow(fmtTs(p.ts), fmtVal(p.value))).join(""))}
46412
- ${kpiCard("Top 3 dias mais baixos", lowestDays.map((d) => listRow(fmtDay2(d.ts), fmtVal(d.avg))).join(""))}
46412
+ ${kpiCard("Top 3 dias mais baixos", lowestDays.map((d) => listRow(fmtDay3(d.ts), fmtVal(d.avg))).join(""))}
46413
46413
  </div>`;
46414
46414
  }
46415
46415
  /**
@@ -69440,13 +69440,6 @@ ${this._formatFileSize(f.size)} \xB7 ${f.type || "arquivo"}`;
69440
69440
  RESOLVED: "Resolvido",
69441
69441
  CLOSED: "Fechado"
69442
69442
  };
69443
- var SEVERITY_COLORS = {
69444
- CRITICAL: "#dc2626",
69445
- HIGH: "#f59e0b",
69446
- MEDIUM: "#3b82f6",
69447
- LOW: "#6b7280",
69448
- INFO: "#6b7280"
69449
- };
69450
69443
  var STYLES_ID4 = "myio-dops-styles";
69451
69444
  function esc5(value) {
69452
69445
  return String(value ?? "").replace(
@@ -69487,11 +69480,27 @@ ${this._formatFileSize(f.size)} \xB7 ${f.type || "arquivo"}`;
69487
69480
  const items = Array.isArray(data) ? data : Array.isArray(data?.items) ? data.items : [];
69488
69481
  return items;
69489
69482
  }
69483
+ function isOpenCritical(i) {
69484
+ return String(i.severity) === "CRITICAL" && !["RESOLVED", "CLOSED"].includes(String(i.status));
69485
+ }
69486
+ var WEEKDAYS_PT = ["dom", "seg", "ter", "qua", "qui", "sex", "s\xE1b"];
69487
+ function fmtDay(day) {
69488
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(day || ""));
69489
+ if (!m) return day ? String(day) : "\u2014";
69490
+ const wd = WEEKDAYS_PT[new Date(Date.UTC(+m[1], +m[2] - 1, +m[3])).getUTCDay()];
69491
+ return `${m[3]}/${m[2]}/${m[1]} \xB7 ${wd}`;
69492
+ }
69493
+ function relativeAgo(ts, now) {
69494
+ const min = Math.max(0, Math.round((now - ts) / 6e4));
69495
+ if (min < 60) return `h\xE1 ${min} min`;
69496
+ if (min < 48 * 60) return `h\xE1 ${Math.round(min / 60)} h`;
69497
+ return `h\xE1 ${Math.round(min / 1440)} dias`;
69498
+ }
69490
69499
  async function fetchDeviceIncidents(config) {
69491
69500
  const api = resolveApi(config);
69492
69501
  const deviceKey = String(config.ingestionId || api.gcdrDeviceId || "");
69493
69502
  if (!deviceKey) return [];
69494
- const url = `${api.alarmsBase}/incidents?device=${encodeURIComponent(deviceKey)}&sortBy=firstDetectedAt&sortDir=desc&limit=100`;
69503
+ const url = `${api.alarmsBase}/incidents?device=${encodeURIComponent(deviceKey)}&severity=CRITICAL&sortBy=firstDetectedAt&sortDir=desc&limit=100`;
69495
69504
  const res = await fetch(url, { headers: api.headers });
69496
69505
  if (!res.ok) throw Object.assign(new Error(`Alarms incidents HTTP ${res.status}`), { status: res.status });
69497
69506
  const body = await res.json();
@@ -69523,13 +69532,24 @@ ${this._formatFileSize(f.size)} \xB7 ${f.type || "arquivo"}`;
69523
69532
  const style = document.createElement("style");
69524
69533
  style.id = STYLES_ID4;
69525
69534
  style.textContent = `
69526
- .dops-tab { padding: 4px 2px 20px; font-family: 'Nunito', system-ui, sans-serif; }
69535
+ .dops-tab { padding: 4px 2px 20px; }
69536
+ .dops-tab, .dops-tab table, .dops-tab th, .dops-tab td, .dops-tab b, .dops-tab small, .dops-tab span {
69537
+ font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
69538
+ }
69539
+ .dops-day { white-space:nowrap; font-variant-numeric: tabular-nums; }
69540
+ /* o modal define td/th em 16px \u2014 fixa o tamanho nas pr\xF3prias c\xE9lulas (OSs e Incidentes) */
69541
+ .dops-tab .dops-table td { font-size:12px; line-height:1.45; }
69542
+ .dops-tab .dops-table th { font-size:11px; text-transform:uppercase; letter-spacing:.04em; }
69543
+ .dops-tab .dops-table td.dops-muted { font-size:11.5px; }
69544
+ .dops-tab .dops-chip { font-size:11px; }
69545
+ .dops-tab .dops-table th.dops-col-date { width:140px; min-width:140px; }
69527
69546
  .dops-notice { background:#f1ecfa; color:#3e1a7d; border-radius:8px; padding:8px 12px; font-size:12px; margin-bottom:14px; }
69528
69547
  .dops-state { padding:28px 16px; text-align:center; color:#6b7280; font-size:13px; }
69529
69548
  .dops-error { color:#b91c1c; }
69530
69549
  .dops-summary { display:flex; gap:10px; flex-wrap:wrap; margin-bottom:12px; }
69531
69550
  .dops-kpi { border:1px solid #e5e7eb; border-radius:8px; padding:8px 12px; min-width:110px; background:#fff; }
69532
69551
  .dops-kpi b { display:block; font-size:18px; color:#111827; }
69552
+ .dops-kpi--crit b { color:#dc2626; }
69533
69553
  .dops-kpi span { font-size:11px; color:#6b7280; text-transform:uppercase; letter-spacing:.4px; }
69534
69554
  .dops-table { width:100%; border-collapse:collapse; font-size:12px; background:#fff; border:1px solid #e5e7eb; border-radius:8px; overflow:hidden; }
69535
69555
  .dops-table th { text-align:left; background:#f9fafb; color:#6b7280; font-weight:700; padding:8px 10px; border-bottom:1px solid #e5e7eb; white-space:nowrap; }
@@ -69596,44 +69616,43 @@ ${this._formatFileSize(f.size)} \xB7 ${f.type || "arquivo"}`;
69596
69616
  container.innerHTML = `<div class="dops-tab">${noDeviceHTML("Incidentes")}</div>`;
69597
69617
  return 0;
69598
69618
  }
69599
- container.innerHTML = `<div class="dops-tab"><div class="dops-state">Carregando incidentes\u2026</div></div>`;
69619
+ container.innerHTML = `<div class="dops-tab"><div class="dops-state">Carregando incidentes cr\xEDticos\u2026</div></div>`;
69600
69620
  let incidents = [];
69601
69621
  try {
69602
- incidents = await fetchDeviceIncidents(config);
69622
+ incidents = (await fetchDeviceIncidents(config)).filter(isOpenCritical);
69603
69623
  } catch (e) {
69604
69624
  container.innerHTML = `<div class="dops-tab"><div class="dops-state dops-error">Erro ao carregar incidentes: ${esc5(
69605
69625
  e?.message || e
69606
69626
  )}</div></div>`;
69607
69627
  return 0;
69608
69628
  }
69609
- const active = incidents.filter((i) => !["RESOLVED", "CLOSED"].includes(String(i.status))).length;
69610
- const critical = incidents.filter(
69611
- (i) => String(i.severity) === "CRITICAL" && !["RESOLVED", "CLOSED"].includes(String(i.status))
69612
- ).length;
69613
- const rows = incidents.map((i) => {
69614
- const sev = String(i.severity || "");
69615
- return `<tr>
69616
- <td><span class="dops-chip" style="background:${SEVERITY_COLORS[sev] || "#6b7280"};color:#fff">${esc5(sev || "\u2014")}</span></td>
69617
- <td>${esc5(i.kind || "\u2014")}</td>
69629
+ const now = Date.now();
69630
+ const unacked = incidents.filter((i) => String(i.status) === "OPEN").length;
69631
+ const detected = incidents.map((i) => Date.parse(i.firstDetectedAt || "")).filter((t) => Number.isFinite(t));
69632
+ const oldest = detected.length ? Math.min(...detected) : null;
69633
+ const newest = detected.length ? Math.max(...detected) : null;
69634
+ const daysOpen = oldest !== null ? Math.max(1, Math.round((now - oldest) / 864e5)) : null;
69635
+ const rows = incidents.map(
69636
+ (i) => `<tr>
69637
+ <td class="dops-day">${esc5(fmtDay(i.day))}</td>
69618
69638
  <td><span class="dops-chip">${esc5(INCIDENT_STATUS_LABELS[String(i.status)] || i.status || "\u2014")}</span></td>
69619
- <td>${esc5(i.day || "\u2014")}</td>
69620
- <td>${esc5(i.centralName || "\u2014")}</td>
69621
- <td>${fmtDate(i.firstDetectedAt)}</td>
69622
- <td>${fmtDate(i.lastEvaluatedAt)}</td>
69639
+ <td class="dops-day">${fmtDate(i.firstDetectedAt)}</td>
69640
+ <td class="dops-day">${fmtDate(i.lastEvaluatedAt)}</td>
69623
69641
  <td class="dops-muted">${esc5(i.description || "")}</td>
69624
- </tr>`;
69625
- }).join("");
69642
+ </tr>`
69643
+ ).join("");
69626
69644
  container.innerHTML = `
69627
69645
  <div class="dops-tab">
69628
- <div class="dops-notice">\u{1F512} Vis\xEDvel s\xF3 para usu\xE1rios MyIO. Incidentes do alarms-backend que envolvem este dispositivo.</div>
69646
+ <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>
69629
69647
  <div class="dops-summary">
69630
- <div class="dops-kpi"><b>${incidents.length}</b><span>Incidentes</span></div>
69631
- <div class="dops-kpi"><b>${active}</b><span>N\xE3o resolvidos</span></div>
69632
- <div class="dops-kpi"><b>${critical}</b><span>Cr\xEDticos abertos</span></div>
69648
+ <div class="dops-kpi dops-kpi--crit"><b>${incidents.length}</b><span>Cr\xEDticos abertos</span></div>
69649
+ <div class="dops-kpi"><b>${unacked}</b><span>Sem reconhecimento</span></div>
69650
+ <div class="dops-kpi"><b>${daysOpen === null ? "\u2014" : daysOpen + (daysOpen === 1 ? " dia" : " dias")}</b><span>Aberto h\xE1 (mais antigo)</span></div>
69651
+ <div class="dops-kpi"><b>${newest === null ? "\u2014" : esc5(relativeAgo(newest, now))}</b><span>\xDAltima detec\xE7\xE3o</span></div>
69633
69652
  </div>
69634
- ${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>`}
69653
+ ${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>`}
69635
69654
  </div>`;
69636
- return critical;
69655
+ return incidents.length;
69637
69656
  }
69638
69657
 
69639
69658
  // src/components/premium-modals/settings/commercialCatalog.ts
@@ -87930,7 +87949,7 @@ ${this._formatFileSize(f.size)} \xB7 ${f.type || "arquivo"}`;
87930
87949
  var norm = (s) => String(s ?? "").normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase();
87931
87950
  var fmtN = (n) => n.toLocaleString("pt-BR");
87932
87951
  var pad = (n) => String(n).padStart(2, "0");
87933
- var fmtDay = (ms) => {
87952
+ var fmtDay2 = (ms) => {
87934
87953
  const p = spParts(ms);
87935
87954
  return `${pad(p.d)}/${pad(p.m + 1)}`;
87936
87955
  };
@@ -88478,7 +88497,7 @@ ${this._formatFileSize(f.size)} \xB7 ${f.type || "arquivo"}`;
88478
88497
  }
88479
88498
  jobTitle(e) {
88480
88499
  const r = e.request;
88481
- 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)}`;
88500
+ 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)}`;
88482
88501
  }
88483
88502
  renderJobs() {
88484
88503
  const s = this.s;