myio-js-library 0.1.582 → 0.1.583

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.583",
993
993
  description: "A clean, standalone JS SDK for MYIO projects",
994
994
  license: "MIT",
995
995
  repository: "github:gh-myio/myio-js-library",
@@ -65835,17 +65835,34 @@ async function fetchDeviceWorkOrders(config2) {
65835
65835
  }
65836
65836
  async function fetchDeviceIncidents(config2) {
65837
65837
  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`;
65838
+ const deviceKey = String(config2.ingestionId || api.gcdrDeviceId || "");
65839
+ if (!deviceKey) return [];
65840
+ const url = `${api.alarmsBase}/incidents?device=${encodeURIComponent(deviceKey)}&sortBy=firstDetectedAt&sortDir=desc&limit=100`;
65840
65841
  const res = await fetch(url, { headers: api.headers });
65841
65842
  if (!res.ok) throw Object.assign(new Error(`Alarms incidents HTTP ${res.status}`), { status: res.status });
65842
65843
  const body = await res.json();
65843
65844
  return Array.isArray(body?.data) ? body.data : [];
65844
65845
  }
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;
65846
+ async function fetchWorkOrderUsers(config2) {
65847
+ const api = resolveApi(config2);
65848
+ const map = /* @__PURE__ */ new Map();
65849
+ try {
65850
+ const res = await fetch(`${api.alarmsBase}/incidents/work-order-users`, { headers: api.headers });
65851
+ if (!res.ok) return map;
65852
+ const body = await res.json();
65853
+ const list = Array.isArray(body) ? body : Array.isArray(body?.data) ? body.data : Array.isArray(body?.items) ? body.items : [];
65854
+ list.forEach((u) => u?.id && map.set(String(u.id), u));
65855
+ } catch {
65856
+ }
65857
+ return map;
65858
+ }
65859
+ function assigneeHTML(id, users) {
65860
+ if (!id) return '<span class="dops-muted">\u2014</span>';
65861
+ const u = users.get(String(id));
65862
+ if (u && (u.name || u.email)) {
65863
+ 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>`;
65864
+ }
65865
+ return `<span class="dops-muted dops-mono" title="${esc5(id)}">usu\xE1rio ${esc5(String(id).slice(0, 8))}\u2026</span>`;
65849
65866
  }
65850
65867
  function injectStyles9() {
65851
65868
  if (document.getElementById(STYLES_ID4)) return;
@@ -65867,6 +65884,9 @@ function injectStyles9() {
65867
65884
  .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
65885
  .dops-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
65869
65886
  .dops-muted { color:#9ca3af; }
65887
+ .dops-person { display:flex; flex-direction:column; gap:1px; min-width:0; }
65888
+ .dops-person b { font-weight:700; }
65889
+ .dops-person small { font-size:11px; color:#6b7280; }
65870
65890
  .theme-dark .dops-table, .theme-dark .dops-kpi { background:#111827; border-color:#374151; }
65871
65891
  .theme-dark .dops-table th { background:#1f2937; color:#9ca3af; border-color:#374151; }
65872
65892
  .theme-dark .dops-table td { color:#e5e7eb; border-color:#1f2937; }
@@ -65879,46 +65899,46 @@ function noDeviceHTML(what) {
65879
65899
  }
65880
65900
  async function renderDeviceWorkOrdersTab(container, config2) {
65881
65901
  injectStyles9();
65882
- const tickets = countDeviceFreshdeskTickets(config2.identifier);
65883
65902
  if (!config2.gcdrDeviceId) {
65884
65903
  container.innerHTML = `<div class="dops-tab">${noDeviceHTML("OSs")}</div>`;
65885
- return tickets;
65904
+ return 0;
65886
65905
  }
65887
65906
  container.innerHTML = `<div class="dops-tab"><div class="dops-state">Carregando ordens de servi\xE7o\u2026</div></div>`;
65888
65907
  let orders = [];
65889
65908
  let errorHtml = "";
65909
+ const usersPromise = fetchWorkOrderUsers(config2);
65890
65910
  try {
65891
65911
  orders = await fetchDeviceWorkOrders(config2);
65892
65912
  } 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)}`;
65913
+ 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
65914
  }
65895
65915
  const open = orders.filter((o) => !["FINALIZADA", "CANCELADA"].includes(String(o.status))).length;
65916
+ const users = await usersPromise;
65896
65917
  const rows = orders.slice().sort((a, b) => String(b.createdAt || "").localeCompare(String(a.createdAt || ""))).map(
65897
65918
  (o) => `<tr>
65898
65919
  <td class="dops-mono">${esc5(o.code || o.id)}</td>
65899
65920
  <td>${esc5(o.title || "\u2014")}</td>
65900
65921
  <td>${esc5(WO_TYPE_LABELS[String(o.type)] || o.type || "\u2014")}</td>
65901
65922
  <td><span class="dops-chip">${esc5(WO_STATUS_LABELS[String(o.status)] || o.status || "\u2014")}</span></td>
65902
- <td>${esc5(o.assignedTo || "\u2014")}</td>
65923
+ <td>${assigneeHTML(o.assignedTo, users)}</td>
65903
65924
  <td>${fmtDate(o.scheduledAt)}</td>
65904
65925
  <td>${fmtDate(o.createdAt)}</td>
65905
65926
  </tr>`
65906
65927
  ).join("");
65907
65928
  container.innerHTML = `
65908
65929
  <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>
65930
+ <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
65931
  <div class="dops-summary">
65911
65932
  <div class="dops-kpi"><b>${errorHtml ? "\u2014" : orders.length}</b><span>OSs</span></div>
65912
65933
  <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
65934
  </div>
65915
65935
  ${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
65936
  </div>`;
65917
- return (errorHtml ? 0 : orders.length) + tickets;
65937
+ return errorHtml ? 0 : open;
65918
65938
  }
65919
65939
  async function renderDeviceIncidentsTab(container, config2) {
65920
65940
  injectStyles9();
65921
- if (!config2.gcdrDeviceId) {
65941
+ if (!config2.ingestionId && !config2.gcdrDeviceId) {
65922
65942
  container.innerHTML = `<div class="dops-tab">${noDeviceHTML("Incidentes")}</div>`;
65923
65943
  return 0;
65924
65944
  }
@@ -65933,6 +65953,9 @@ async function renderDeviceIncidentsTab(container, config2) {
65933
65953
  return 0;
65934
65954
  }
65935
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;
65936
65959
  const rows = incidents.map((i) => {
65937
65960
  const sev = String(i.severity || "");
65938
65961
  return `<tr>
@@ -65952,10 +65975,11 @@ async function renderDeviceIncidentsTab(container, config2) {
65952
65975
  <div class="dops-summary">
65953
65976
  <div class="dops-kpi"><b>${incidents.length}</b><span>Incidentes</span></div>
65954
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>
65955
65979
  </div>
65956
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>`}
65957
65981
  </div>`;
65958
- return active;
65982
+ return critical;
65959
65983
  }
65960
65984
 
65961
65985
  // src/components/premium-modals/settings/commercialCatalog.ts
@@ -66451,10 +66475,21 @@ var SettingsModalView = class _SettingsModalView {
66451
66475
  const email = String(this.config.userEmail || "").toLowerCase().trim();
66452
66476
  return !!email && email.endsWith(ALLOWED_EMAIL_DOMAIN.toLowerCase());
66453
66477
  }
66478
+ /** ingestionId do dispositivo pelo estado do dashboard (host antigo que não o envia). */
66479
+ lookupIngestionId() {
66480
+ const id = String(this.config.deviceId || "");
66481
+ const state6 = window.STATE || {};
66482
+ for (const d of ["energy", "water", "temperature"]) {
66483
+ const hit = (state6[d]?._raw || []).find((it) => String(it?.tbId || it?.id) === id);
66484
+ if (hit?.ingestionId) return String(hit.ingestionId);
66485
+ }
66486
+ return null;
66487
+ }
66454
66488
  /** Abas OSs + Incidentes do dispositivo (GCDR work-orders / alarms-backend incidents). */
66455
66489
  initDeviceOpsTabs() {
66456
66490
  const cfg = {
66457
66491
  gcdrDeviceId: this.config.gcdrDeviceId,
66492
+ ingestionId: this.config.ingestionId || this.lookupIngestionId(),
66458
66493
  identifier: this.config.identifier,
66459
66494
  gcdrApiBaseUrl: this.config.gcdrApiBaseUrl
66460
66495
  };
@@ -80828,6 +80863,7 @@ var SettingsController = class {
80828
80863
  // RFC-0180: Raw device name + GCDR identifiers for Alarms tab
80829
80864
  deviceName: params.deviceName,
80830
80865
  gcdrDeviceId: params.gcdrDeviceId,
80866
+ ingestionId: params.ingestionId ?? null,
80831
80867
  gcdrCustomerId: params.gcdrCustomerId,
80832
80868
  gcdrTenantId: params.gcdrTenantId,
80833
80869
  gcdrApiBaseUrl: params.gcdrApiBaseUrl,
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.583",
14
14
  description: "A clean, standalone JS SDK for MYIO projects",
15
15
  license: "MIT",
16
16
  repository: "github:gh-myio/myio-js-library",
@@ -64131,17 +64131,34 @@ async function fetchDeviceWorkOrders(config) {
64131
64131
  }
64132
64132
  async function fetchDeviceIncidents(config) {
64133
64133
  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`;
64134
+ const deviceKey = String(config.ingestionId || api.gcdrDeviceId || "");
64135
+ if (!deviceKey) return [];
64136
+ const url = `${api.alarmsBase}/incidents?device=${encodeURIComponent(deviceKey)}&sortBy=firstDetectedAt&sortDir=desc&limit=100`;
64136
64137
  const res = await fetch(url, { headers: api.headers });
64137
64138
  if (!res.ok) throw Object.assign(new Error(`Alarms incidents HTTP ${res.status}`), { status: res.status });
64138
64139
  const body = await res.json();
64139
64140
  return Array.isArray(body?.data) ? body.data : [];
64140
64141
  }
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;
64142
+ async function fetchWorkOrderUsers(config) {
64143
+ const api = resolveApi(config);
64144
+ const map = /* @__PURE__ */ new Map();
64145
+ try {
64146
+ const res = await fetch(`${api.alarmsBase}/incidents/work-order-users`, { headers: api.headers });
64147
+ if (!res.ok) return map;
64148
+ const body = await res.json();
64149
+ const list = Array.isArray(body) ? body : Array.isArray(body?.data) ? body.data : Array.isArray(body?.items) ? body.items : [];
64150
+ list.forEach((u) => u?.id && map.set(String(u.id), u));
64151
+ } catch {
64152
+ }
64153
+ return map;
64154
+ }
64155
+ function assigneeHTML(id, users) {
64156
+ if (!id) return '<span class="dops-muted">\u2014</span>';
64157
+ const u = users.get(String(id));
64158
+ if (u && (u.name || u.email)) {
64159
+ 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>`;
64160
+ }
64161
+ return `<span class="dops-muted dops-mono" title="${esc5(id)}">usu\xE1rio ${esc5(String(id).slice(0, 8))}\u2026</span>`;
64145
64162
  }
64146
64163
  function injectStyles9() {
64147
64164
  if (document.getElementById(STYLES_ID4)) return;
@@ -64163,6 +64180,9 @@ function injectStyles9() {
64163
64180
  .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
64181
  .dops-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
64165
64182
  .dops-muted { color:#9ca3af; }
64183
+ .dops-person { display:flex; flex-direction:column; gap:1px; min-width:0; }
64184
+ .dops-person b { font-weight:700; }
64185
+ .dops-person small { font-size:11px; color:#6b7280; }
64166
64186
  .theme-dark .dops-table, .theme-dark .dops-kpi { background:#111827; border-color:#374151; }
64167
64187
  .theme-dark .dops-table th { background:#1f2937; color:#9ca3af; border-color:#374151; }
64168
64188
  .theme-dark .dops-table td { color:#e5e7eb; border-color:#1f2937; }
@@ -64175,46 +64195,46 @@ function noDeviceHTML(what) {
64175
64195
  }
64176
64196
  async function renderDeviceWorkOrdersTab(container, config) {
64177
64197
  injectStyles9();
64178
- const tickets = countDeviceFreshdeskTickets(config.identifier);
64179
64198
  if (!config.gcdrDeviceId) {
64180
64199
  container.innerHTML = `<div class="dops-tab">${noDeviceHTML("OSs")}</div>`;
64181
- return tickets;
64200
+ return 0;
64182
64201
  }
64183
64202
  container.innerHTML = `<div class="dops-tab"><div class="dops-state">Carregando ordens de servi\xE7o\u2026</div></div>`;
64184
64203
  let orders = [];
64185
64204
  let errorHtml = "";
64205
+ const usersPromise = fetchWorkOrderUsers(config);
64186
64206
  try {
64187
64207
  orders = await fetchDeviceWorkOrders(config);
64188
64208
  } 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)}`;
64209
+ 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
64210
  }
64191
64211
  const open = orders.filter((o) => !["FINALIZADA", "CANCELADA"].includes(String(o.status))).length;
64212
+ const users = await usersPromise;
64192
64213
  const rows = orders.slice().sort((a, b) => String(b.createdAt || "").localeCompare(String(a.createdAt || ""))).map(
64193
64214
  (o) => `<tr>
64194
64215
  <td class="dops-mono">${esc5(o.code || o.id)}</td>
64195
64216
  <td>${esc5(o.title || "\u2014")}</td>
64196
64217
  <td>${esc5(WO_TYPE_LABELS[String(o.type)] || o.type || "\u2014")}</td>
64197
64218
  <td><span class="dops-chip">${esc5(WO_STATUS_LABELS[String(o.status)] || o.status || "\u2014")}</span></td>
64198
- <td>${esc5(o.assignedTo || "\u2014")}</td>
64219
+ <td>${assigneeHTML(o.assignedTo, users)}</td>
64199
64220
  <td>${fmtDate(o.scheduledAt)}</td>
64200
64221
  <td>${fmtDate(o.createdAt)}</td>
64201
64222
  </tr>`
64202
64223
  ).join("");
64203
64224
  container.innerHTML = `
64204
64225
  <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>
64226
+ <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
64227
  <div class="dops-summary">
64207
64228
  <div class="dops-kpi"><b>${errorHtml ? "\u2014" : orders.length}</b><span>OSs</span></div>
64208
64229
  <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
64230
  </div>
64211
64231
  ${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
64232
  </div>`;
64213
- return (errorHtml ? 0 : orders.length) + tickets;
64233
+ return errorHtml ? 0 : open;
64214
64234
  }
64215
64235
  async function renderDeviceIncidentsTab(container, config) {
64216
64236
  injectStyles9();
64217
- if (!config.gcdrDeviceId) {
64237
+ if (!config.ingestionId && !config.gcdrDeviceId) {
64218
64238
  container.innerHTML = `<div class="dops-tab">${noDeviceHTML("Incidentes")}</div>`;
64219
64239
  return 0;
64220
64240
  }
@@ -64229,6 +64249,9 @@ async function renderDeviceIncidentsTab(container, config) {
64229
64249
  return 0;
64230
64250
  }
64231
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;
64232
64255
  const rows = incidents.map((i) => {
64233
64256
  const sev = String(i.severity || "");
64234
64257
  return `<tr>
@@ -64248,10 +64271,11 @@ async function renderDeviceIncidentsTab(container, config) {
64248
64271
  <div class="dops-summary">
64249
64272
  <div class="dops-kpi"><b>${incidents.length}</b><span>Incidentes</span></div>
64250
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>
64251
64275
  </div>
64252
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>`}
64253
64277
  </div>`;
64254
- return active;
64278
+ return critical;
64255
64279
  }
64256
64280
 
64257
64281
  // src/components/premium-modals/settings/commercialCatalog.ts
@@ -64747,10 +64771,21 @@ var SettingsModalView = class _SettingsModalView {
64747
64771
  const email = String(this.config.userEmail || "").toLowerCase().trim();
64748
64772
  return !!email && email.endsWith(ALLOWED_EMAIL_DOMAIN.toLowerCase());
64749
64773
  }
64774
+ /** ingestionId do dispositivo pelo estado do dashboard (host antigo que não o envia). */
64775
+ lookupIngestionId() {
64776
+ const id = String(this.config.deviceId || "");
64777
+ const state5 = window.STATE || {};
64778
+ for (const d of ["energy", "water", "temperature"]) {
64779
+ const hit = (state5[d]?._raw || []).find((it) => String(it?.tbId || it?.id) === id);
64780
+ if (hit?.ingestionId) return String(hit.ingestionId);
64781
+ }
64782
+ return null;
64783
+ }
64750
64784
  /** Abas OSs + Incidentes do dispositivo (GCDR work-orders / alarms-backend incidents). */
64751
64785
  initDeviceOpsTabs() {
64752
64786
  const cfg = {
64753
64787
  gcdrDeviceId: this.config.gcdrDeviceId,
64788
+ ingestionId: this.config.ingestionId || this.lookupIngestionId(),
64754
64789
  identifier: this.config.identifier,
64755
64790
  gcdrApiBaseUrl: this.config.gcdrApiBaseUrl
64756
64791
  };
@@ -79124,6 +79159,7 @@ var SettingsController = class {
79124
79159
  // RFC-0180: Raw device name + GCDR identifiers for Alarms tab
79125
79160
  deviceName: params.deviceName,
79126
79161
  gcdrDeviceId: params.gcdrDeviceId,
79162
+ ingestionId: params.ingestionId ?? null,
79127
79163
  gcdrCustomerId: params.gcdrCustomerId,
79128
79164
  gcdrTenantId: params.gcdrTenantId,
79129
79165
  gcdrApiBaseUrl: params.gcdrApiBaseUrl,
@@ -5524,7 +5524,7 @@
5524
5524
 
5525
5525
  // package.json
5526
5526
  var package_default = {
5527
- version: "0.1.582"};
5527
+ version: "0.1.583"};
5528
5528
 
5529
5529
  // src/utils/format/energy.ts
5530
5530
  function formatPower(value, decimals = 2) {
@@ -69489,17 +69489,34 @@ ${this._formatFileSize(f.size)} \xB7 ${f.type || "arquivo"}`;
69489
69489
  }
69490
69490
  async function fetchDeviceIncidents(config) {
69491
69491
  const api = resolveApi(config);
69492
- if (!api.gcdrDeviceId) return [];
69493
- const url = `${api.alarmsBase}/incidents?device=${encodeURIComponent(api.gcdrDeviceId)}&sortBy=firstDetectedAt&sortDir=desc&limit=100`;
69492
+ const deviceKey = String(config.ingestionId || api.gcdrDeviceId || "");
69493
+ if (!deviceKey) return [];
69494
+ const url = `${api.alarmsBase}/incidents?device=${encodeURIComponent(deviceKey)}&sortBy=firstDetectedAt&sortDir=desc&limit=100`;
69494
69495
  const res = await fetch(url, { headers: api.headers });
69495
69496
  if (!res.ok) throw Object.assign(new Error(`Alarms incidents HTTP ${res.status}`), { status: res.status });
69496
69497
  const body = await res.json();
69497
69498
  return Array.isArray(body?.data) ? body.data : [];
69498
69499
  }
69499
- function countDeviceFreshdeskTickets(identifier) {
69500
- const tso = globalThis.window?.TicketServiceOrchestrator;
69501
- if (!identifier || typeof tso?.getTicketCountForDevice !== "function") return 0;
69502
- return Number(tso.getTicketCountForDevice(identifier)) || 0;
69500
+ async function fetchWorkOrderUsers(config) {
69501
+ const api = resolveApi(config);
69502
+ const map = /* @__PURE__ */ new Map();
69503
+ try {
69504
+ const res = await fetch(`${api.alarmsBase}/incidents/work-order-users`, { headers: api.headers });
69505
+ if (!res.ok) return map;
69506
+ const body = await res.json();
69507
+ const list = Array.isArray(body) ? body : Array.isArray(body?.data) ? body.data : Array.isArray(body?.items) ? body.items : [];
69508
+ list.forEach((u) => u?.id && map.set(String(u.id), u));
69509
+ } catch {
69510
+ }
69511
+ return map;
69512
+ }
69513
+ function assigneeHTML(id, users) {
69514
+ if (!id) return '<span class="dops-muted">\u2014</span>';
69515
+ const u = users.get(String(id));
69516
+ if (u && (u.name || u.email)) {
69517
+ 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>`;
69518
+ }
69519
+ return `<span class="dops-muted dops-mono" title="${esc5(id)}">usu\xE1rio ${esc5(String(id).slice(0, 8))}\u2026</span>`;
69503
69520
  }
69504
69521
  function injectStyles9() {
69505
69522
  if (document.getElementById(STYLES_ID4)) return;
@@ -69521,6 +69538,9 @@ ${this._formatFileSize(f.size)} \xB7 ${f.type || "arquivo"}`;
69521
69538
  .dops-chip { display:inline-block; padding:2px 8px; border-radius:999px; font-size:11px; font-weight:700; background:#f3f4f6; color:#374151; white-space:nowrap; }
69522
69539
  .dops-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
69523
69540
  .dops-muted { color:#9ca3af; }
69541
+ .dops-person { display:flex; flex-direction:column; gap:1px; min-width:0; }
69542
+ .dops-person b { font-weight:700; }
69543
+ .dops-person small { font-size:11px; color:#6b7280; }
69524
69544
  .theme-dark .dops-table, .theme-dark .dops-kpi { background:#111827; border-color:#374151; }
69525
69545
  .theme-dark .dops-table th { background:#1f2937; color:#9ca3af; border-color:#374151; }
69526
69546
  .theme-dark .dops-table td { color:#e5e7eb; border-color:#1f2937; }
@@ -69533,46 +69553,46 @@ ${this._formatFileSize(f.size)} \xB7 ${f.type || "arquivo"}`;
69533
69553
  }
69534
69554
  async function renderDeviceWorkOrdersTab(container, config) {
69535
69555
  injectStyles9();
69536
- const tickets = countDeviceFreshdeskTickets(config.identifier);
69537
69556
  if (!config.gcdrDeviceId) {
69538
69557
  container.innerHTML = `<div class="dops-tab">${noDeviceHTML("OSs")}</div>`;
69539
- return tickets;
69558
+ return 0;
69540
69559
  }
69541
69560
  container.innerHTML = `<div class="dops-tab"><div class="dops-state">Carregando ordens de servi\xE7o\u2026</div></div>`;
69542
69561
  let orders = [];
69543
69562
  let errorHtml = "";
69563
+ const usersPromise = fetchWorkOrderUsers(config);
69544
69564
  try {
69545
69565
  orders = await fetchDeviceWorkOrders(config);
69546
69566
  } catch (e) {
69547
- 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)}`;
69567
+ 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)}`;
69548
69568
  }
69549
69569
  const open = orders.filter((o) => !["FINALIZADA", "CANCELADA"].includes(String(o.status))).length;
69570
+ const users = await usersPromise;
69550
69571
  const rows = orders.slice().sort((a, b) => String(b.createdAt || "").localeCompare(String(a.createdAt || ""))).map(
69551
69572
  (o) => `<tr>
69552
69573
  <td class="dops-mono">${esc5(o.code || o.id)}</td>
69553
69574
  <td>${esc5(o.title || "\u2014")}</td>
69554
69575
  <td>${esc5(WO_TYPE_LABELS[String(o.type)] || o.type || "\u2014")}</td>
69555
69576
  <td><span class="dops-chip">${esc5(WO_STATUS_LABELS[String(o.status)] || o.status || "\u2014")}</span></td>
69556
- <td>${esc5(o.assignedTo || "\u2014")}</td>
69577
+ <td>${assigneeHTML(o.assignedTo, users)}</td>
69557
69578
  <td>${fmtDate(o.scheduledAt)}</td>
69558
69579
  <td>${fmtDate(o.createdAt)}</td>
69559
69580
  </tr>`
69560
69581
  ).join("");
69561
69582
  container.innerHTML = `
69562
69583
  <div class="dops-tab">
69563
- <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>
69584
+ <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>
69564
69585
  <div class="dops-summary">
69565
69586
  <div class="dops-kpi"><b>${errorHtml ? "\u2014" : orders.length}</b><span>OSs</span></div>
69566
69587
  <div class="dops-kpi"><b>${errorHtml ? "\u2014" : open}</b><span>OSs em aberto</span></div>
69567
- <div class="dops-kpi"><b>${tickets}</b><span>Chamados</span></div>
69568
69588
  </div>
69569
69589
  ${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>`}
69570
69590
  </div>`;
69571
- return (errorHtml ? 0 : orders.length) + tickets;
69591
+ return errorHtml ? 0 : open;
69572
69592
  }
69573
69593
  async function renderDeviceIncidentsTab(container, config) {
69574
69594
  injectStyles9();
69575
- if (!config.gcdrDeviceId) {
69595
+ if (!config.ingestionId && !config.gcdrDeviceId) {
69576
69596
  container.innerHTML = `<div class="dops-tab">${noDeviceHTML("Incidentes")}</div>`;
69577
69597
  return 0;
69578
69598
  }
@@ -69587,6 +69607,9 @@ ${this._formatFileSize(f.size)} \xB7 ${f.type || "arquivo"}`;
69587
69607
  return 0;
69588
69608
  }
69589
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;
69590
69613
  const rows = incidents.map((i) => {
69591
69614
  const sev = String(i.severity || "");
69592
69615
  return `<tr>
@@ -69606,10 +69629,11 @@ ${this._formatFileSize(f.size)} \xB7 ${f.type || "arquivo"}`;
69606
69629
  <div class="dops-summary">
69607
69630
  <div class="dops-kpi"><b>${incidents.length}</b><span>Incidentes</span></div>
69608
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>
69609
69633
  </div>
69610
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>`}
69611
69635
  </div>`;
69612
- return active;
69636
+ return critical;
69613
69637
  }
69614
69638
 
69615
69639
  // src/components/premium-modals/settings/commercialCatalog.ts
@@ -70105,10 +70129,21 @@ ${this._formatFileSize(f.size)} \xB7 ${f.type || "arquivo"}`;
70105
70129
  const email = String(this.config.userEmail || "").toLowerCase().trim();
70106
70130
  return !!email && email.endsWith(ALLOWED_EMAIL_DOMAIN.toLowerCase());
70107
70131
  }
70132
+ /** ingestionId do dispositivo pelo estado do dashboard (host antigo que não o envia). */
70133
+ lookupIngestionId() {
70134
+ const id = String(this.config.deviceId || "");
70135
+ const state5 = window.STATE || {};
70136
+ for (const d of ["energy", "water", "temperature"]) {
70137
+ const hit = (state5[d]?._raw || []).find((it) => String(it?.tbId || it?.id) === id);
70138
+ if (hit?.ingestionId) return String(hit.ingestionId);
70139
+ }
70140
+ return null;
70141
+ }
70108
70142
  /** Abas OSs + Incidentes do dispositivo (GCDR work-orders / alarms-backend incidents). */
70109
70143
  initDeviceOpsTabs() {
70110
70144
  const cfg = {
70111
70145
  gcdrDeviceId: this.config.gcdrDeviceId,
70146
+ ingestionId: this.config.ingestionId || this.lookupIngestionId(),
70112
70147
  identifier: this.config.identifier,
70113
70148
  gcdrApiBaseUrl: this.config.gcdrApiBaseUrl
70114
70149
  };
@@ -84481,6 +84516,7 @@ ${this._formatFileSize(f.size)} \xB7 ${f.type || "arquivo"}`;
84481
84516
  // RFC-0180: Raw device name + GCDR identifiers for Alarms tab
84482
84517
  deviceName: params.deviceName,
84483
84518
  gcdrDeviceId: params.gcdrDeviceId,
84519
+ ingestionId: params.ingestionId ?? null,
84484
84520
  gcdrCustomerId: params.gcdrCustomerId,
84485
84521
  gcdrTenantId: params.gcdrTenantId,
84486
84522
  gcdrApiBaseUrl: params.gcdrApiBaseUrl,