zenit-sdk 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2008,6 +2008,152 @@ function useGeolocation(options) {
2008
2008
 
2009
2009
  // src/react/map/map-utils.ts
2010
2010
  var import_leaflet2 = __toESM(require("leaflet"));
2011
+
2012
+ // src/config/modalWhitelist.ts
2013
+ function normalizeKey(value) {
2014
+ return value.normalize("NFD").replace(/\p{Diacritic}/gu, "").replace(/[_\s-]+/g, "").toLowerCase().trim();
2015
+ }
2016
+ var CLIENTE_MODAL_WHITELIST = [
2017
+ {
2018
+ id: "nombre_cliente",
2019
+ label: "Nombre del Cliente",
2020
+ aliases: ["nombre_del_cliente", "nombre cliente", "nombre_del_cliente ", "NOMBRE_CLIENTE"]
2021
+ },
2022
+ {
2023
+ id: "dpi",
2024
+ label: "DPI",
2025
+ aliases: ["dpi", "DPI"]
2026
+ },
2027
+ {
2028
+ id: "kpi",
2029
+ label: "Estado",
2030
+ aliases: ["kpi", "KPI"],
2031
+ hint: "kpi_badge"
2032
+ },
2033
+ {
2034
+ id: "tel_principal",
2035
+ label: "Tel\xE9fono",
2036
+ aliases: ["tel_principal", "tel principal", "telefono", "telefono_principal", "TEL_PRINCIPAL"],
2037
+ hint: "phone_link"
2038
+ },
2039
+ {
2040
+ id: "capital_concedido",
2041
+ label: "Capital Concedido",
2042
+ aliases: ["capital_concedido", "capital concedido", "CAPITAL_CONCEDIDO"]
2043
+ },
2044
+ {
2045
+ id: "mora",
2046
+ label: "Monto en Mora",
2047
+ aliases: ["mora", "MORA"],
2048
+ hint: "mora_alert"
2049
+ },
2050
+ {
2051
+ id: "etapa",
2052
+ label: "Etapa del Cr\xE9dito",
2053
+ aliases: ["etapa", "ETAPA"]
2054
+ },
2055
+ {
2056
+ id: "prestamo",
2057
+ label: "No. de Pr\xE9stamo",
2058
+ aliases: ["prestamo", "prestamo_id", "no_prestamo", "numero_prestamo", "PRESTAMO"]
2059
+ },
2060
+ {
2061
+ id: "sucursal",
2062
+ label: "Sucursal",
2063
+ aliases: ["sucursal", "nombre_sucursal", "nombre sucursal", "SUCURSAL"]
2064
+ }
2065
+ ];
2066
+ var SECTOR_MODAL_WHITELIST = [
2067
+ { id: "sector", label: "Sector", aliases: ["nom_sector", "NOM_SECTOR", "sector", "SECTOR"] },
2068
+ { id: "promotor", label: "Promotor", aliases: ["promotor", "PROMOTOR"] },
2069
+ { id: "capital_total", label: "Capital Total", aliases: ["capital_total", "capital total", "CAPITAL_TOTAL"] },
2070
+ {
2071
+ id: "total_capital_mora",
2072
+ label: "Total Capital Mora",
2073
+ aliases: ["total_capital_mora", "total capital mora", "TOTAL_CAPITAL_MORA"]
2074
+ },
2075
+ {
2076
+ id: "tendencia_mora",
2077
+ label: "Tendencia Mora",
2078
+ aliases: ["tendencia_mora", "tendencia mora", "TENDENCIA_MORA"],
2079
+ hint: "trend_icon"
2080
+ },
2081
+ {
2082
+ id: "tendencia_capital",
2083
+ label: "Tendencia Capital",
2084
+ aliases: ["tendencia_capital", "tendencia capital", "TENDENCIA_CAPITAL"],
2085
+ hint: "trend_icon"
2086
+ },
2087
+ {
2088
+ id: "tendencia_castigos",
2089
+ label: "Tendencia Castigos",
2090
+ aliases: ["tendencia_castigos", "tendencia castigos", "TENDENCIA_CASTIGOS"],
2091
+ hint: "trend_icon"
2092
+ },
2093
+ {
2094
+ id: "impacto_sector",
2095
+ label: "Impacto Sector",
2096
+ aliases: ["impacto_sector", "impacto sector", "IMPACTO_SECTOR"]
2097
+ },
2098
+ {
2099
+ id: "total_clientes_sector",
2100
+ label: "Total Clientes Sector",
2101
+ aliases: ["total_clientes_sector", "total clientes sector", "TOTAL_CLIENTES_SECTOR"]
2102
+ },
2103
+ {
2104
+ id: "total_clientes_sanos",
2105
+ label: "Total Clientes Sanos",
2106
+ aliases: ["total_clientes_sanos", "total clientes sanos", "TOTAL_CLIENTES_SANOS"]
2107
+ },
2108
+ {
2109
+ id: "total_clientes_morosos",
2110
+ label: "Total Clientes Morosos",
2111
+ aliases: ["total_clientes_morosos", "total clientes morosos", "TOTAL_CLIENTES_MOROSOS"]
2112
+ },
2113
+ {
2114
+ id: "total_clientes_castigados",
2115
+ label: "Total Clientes Castigados",
2116
+ aliases: ["total_clientes_castigados", "total clientes castigados", "TOTAL_CLIENTES_CASTIGADOS"]
2117
+ },
2118
+ {
2119
+ id: "total_clientes_nuevos",
2120
+ label: "Total Clientes Nuevos",
2121
+ aliases: ["total_clientes_nuevos", "total clientes nuevos", "TOTAL_CLIENTES_NUEVOS"]
2122
+ },
2123
+ {
2124
+ id: "total_clientes_salidos",
2125
+ label: "Total Clientes Salidos",
2126
+ aliases: ["total_clientes_salidos", "total clientes salidos", "TOTAL_CLIENTES_SALIDOS"]
2127
+ },
2128
+ { id: "insights", label: "Insights", aliases: ["insights", "INSIGHTS"], hint: "collapsible" },
2129
+ {
2130
+ id: "recomendaciones",
2131
+ label: "Recomendaciones",
2132
+ aliases: ["recomendaciones", "RECOMENDACIONES"],
2133
+ hint: "collapsible"
2134
+ }
2135
+ ];
2136
+ function applyModalWhitelist(rawData, whitelist) {
2137
+ const keyByNormalized = /* @__PURE__ */ new Map();
2138
+ Object.keys(rawData ?? {}).forEach((rawKey) => {
2139
+ const normalized = normalizeKey(rawKey);
2140
+ if (!normalized || keyByNormalized.has(normalized)) return;
2141
+ keyByNormalized.set(normalized, rawKey);
2142
+ });
2143
+ return whitelist.map(({ id, label, hint, aliases }) => {
2144
+ const candidates = [...aliases, id];
2145
+ for (const candidate of candidates) {
2146
+ const matchedKey = keyByNormalized.get(normalizeKey(candidate));
2147
+ if (!matchedKey) continue;
2148
+ const value = rawData[matchedKey];
2149
+ if (value === null || value === void 0) continue;
2150
+ return { id, label, value, hint: hint ?? null, matchedKey };
2151
+ }
2152
+ return null;
2153
+ }).filter((entry) => Boolean(entry));
2154
+ }
2155
+
2156
+ // src/react/map/map-utils.ts
2011
2157
  var POPUP_STYLE_ID = "zenit-leaflet-popup-styles";
2012
2158
  var POPUP_EXCLUDED_KEYS = /* @__PURE__ */ new Set(["geom", "geometry", "_private"]);
2013
2159
  var POPUP_TITLE_KEYS = ["id", "nombre", "name", "title", "titulo", "cluster"];
@@ -2267,6 +2413,10 @@ function createPopupContent(properties) {
2267
2413
  const descriptionHtml = header.description ? `<div style="margin-bottom:10px; padding:8px 10px; background:#f8fafc; border-left:3px solid #38bdf8; border-radius:6px; color:#334155; font-size:12px;">${escapeHtml(
2268
2414
  header.description.value
2269
2415
  )}</div>` : "";
2416
+ const whitelistedRows = buildWhitelistedRows(properties, { colorBar, headerHtml, descriptionHtml });
2417
+ if (whitelistedRows) {
2418
+ return whitelistedRows;
2419
+ }
2270
2420
  const rowsHtml = entries.map(([key, value]) => {
2271
2421
  const label = escapeHtml(formatLabel(key));
2272
2422
  const normalizedKey = key.trim().toLowerCase();
@@ -2283,6 +2433,74 @@ function createPopupContent(properties) {
2283
2433
  }).join("");
2284
2434
  return `<div>${colorBar}${headerHtml}${descriptionHtml}${rowsHtml}</div>`;
2285
2435
  }
2436
+ function buildWhitelistedRows(properties, headerSections) {
2437
+ const selection = selectModalWhitelist(properties);
2438
+ if (!selection) {
2439
+ logModalWhitelistDebug({
2440
+ modalType: "generic",
2441
+ properties,
2442
+ entries: [],
2443
+ whitelist: null,
2444
+ fallbackToGeneric: true
2445
+ });
2446
+ return null;
2447
+ }
2448
+ const { whitelist, modalType } = selection;
2449
+ const entries = applyModalWhitelist(properties, whitelist);
2450
+ if (entries.length === 0) {
2451
+ logModalWhitelistDebug({
2452
+ modalType,
2453
+ properties,
2454
+ entries,
2455
+ whitelist,
2456
+ fallbackToGeneric: true
2457
+ });
2458
+ return null;
2459
+ }
2460
+ logModalWhitelistDebug({
2461
+ modalType,
2462
+ properties,
2463
+ entries,
2464
+ whitelist,
2465
+ fallbackToGeneric: false
2466
+ });
2467
+ const rowsHtml = entries.map(({ label, value }) => {
2468
+ const valueHtml = renderPopupValue(value);
2469
+ return `
2470
+ <div style="display:grid; grid-template-columns:minmax(90px, 35%) 1fr; gap:8px; padding:6px 0; border-bottom:1px solid #e2e8f0;">
2471
+ <div style="font-size:11px; font-weight:600; text-transform:uppercase; letter-spacing:0.04em; color:#64748b;">${escapeHtml(label)}</div>
2472
+ <div style="font-size:13px; color:#0f172a; word-break:break-word;">${valueHtml}</div>
2473
+ </div>
2474
+ `;
2475
+ }).join("");
2476
+ return `<div>${headerSections.colorBar}${headerSections.headerHtml}${headerSections.descriptionHtml}${rowsHtml}</div>`;
2477
+ }
2478
+ function hasAnyKey(properties, candidates) {
2479
+ const normalizedKeys = new Set(Object.keys(properties).map((key) => normalizeKey(key)));
2480
+ return candidates.some((candidate) => normalizedKeys.has(normalizeKey(candidate)));
2481
+ }
2482
+ function selectModalWhitelist(properties) {
2483
+ if (hasAnyKey(properties, ["nombre_del_cliente", "dpi", "capital_concedido", "kpi"])) {
2484
+ return { modalType: "cliente", whitelist: CLIENTE_MODAL_WHITELIST };
2485
+ }
2486
+ if (hasAnyKey(properties, ["nom_sector", "NOM_SECTOR", "total_clientes_sector", "capital_total", "impacto_sector"])) {
2487
+ return { modalType: "sector", whitelist: SECTOR_MODAL_WHITELIST };
2488
+ }
2489
+ return null;
2490
+ }
2491
+ function logModalWhitelistDebug(options) {
2492
+ if (process.env.NODE_ENV === "production") return;
2493
+ const { modalType, properties, entries, whitelist, fallbackToGeneric } = options;
2494
+ const matchedIds = new Set(entries.map((entry) => entry.id));
2495
+ const missingFields = (whitelist ?? []).filter((item) => !matchedIds.has(item.id)).map((item) => item.id);
2496
+ console.info("[modal-whitelist]", {
2497
+ modalType,
2498
+ keys: Object.keys(properties),
2499
+ matchedFields: entries.map((entry) => ({ id: entry.id, matchedKey: entry.matchedKey })),
2500
+ missingFields,
2501
+ fallbackToGeneric
2502
+ });
2503
+ }
2286
2504
  function isPolygonType(layerType, geometryType) {
2287
2505
  const candidate = (layerType ?? geometryType ?? "").toLowerCase();
2288
2506
  return candidate === "polygon" || candidate === "multipolygon";