@carrierllc/mcp 0.2.8 → 0.2.9

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
@@ -3149,15 +3149,42 @@ function registerIntelligenceTools(server2, ctx) {
3149
3149
  )
3150
3150
  ]);
3151
3151
  const sections = ["# Fleet Health Dashboard\n"];
3152
+ const statusRaw = statusResult.data;
3153
+ const statusAccounts = Array.isArray(statusRaw) ? statusRaw : statusRaw?.account ?? [];
3154
+ const statusOk = statusResult.data !== null && (statusAccounts.length > 0 || statusResult.error === null);
3155
+ const countByState = (account) => {
3156
+ const sponsors = account.sponsor ?? [];
3157
+ let active = 0, suspended = 0, inventory = 0, other = 0;
3158
+ for (const sp of sponsors) {
3159
+ const esim = sp.esim ?? {};
3160
+ const statuses = esim.status ?? [];
3161
+ for (const s of statuses) {
3162
+ const name = String(s.name ?? "").toUpperCase();
3163
+ const count = Number(s.count ?? 0);
3164
+ if (name === "ACTIVE" || name === "ACTIVATED") active += count;
3165
+ else if (name === "SUSPENDED") suspended += count;
3166
+ else if (name === "INVENTORY" || name === "NOT_ACTIVATED" || name === "AVAILABLE") inventory += count;
3167
+ else other += count;
3168
+ }
3169
+ }
3170
+ return { active, suspended, inventory, other };
3171
+ };
3152
3172
  let totalActive = 0, totalSuspended = 0, totalInventory = 0, totalOther = 0;
3153
- const statusOk = statusResult.data && Array.isArray(statusResult.data);
3154
- const statusAccounts = statusOk ? statusResult.data : [];
3155
3173
  if (statusOk) {
3156
3174
  for (const account of statusAccounts) {
3157
- totalActive += Number(account.active ?? 0);
3158
- totalSuspended += Number(account.suspended ?? 0);
3159
- totalInventory += Number(account.inventory ?? account.notActivated ?? 0);
3160
- totalOther += Number(account.other ?? account.terminated ?? 0);
3175
+ const hasSponsors = Array.isArray(account.sponsor);
3176
+ if (hasSponsors) {
3177
+ const c = countByState(account);
3178
+ totalActive += c.active;
3179
+ totalSuspended += c.suspended;
3180
+ totalInventory += c.inventory;
3181
+ totalOther += c.other;
3182
+ } else {
3183
+ totalActive += Number(account.active ?? 0);
3184
+ totalSuspended += Number(account.suspended ?? 0);
3185
+ totalInventory += Number(account.inventory ?? account.notActivated ?? 0);
3186
+ totalOther += Number(account.other ?? account.terminated ?? 0);
3187
+ }
3161
3188
  }
3162
3189
  const total = totalActive + totalSuspended + totalInventory + totalOther;
3163
3190
  const utilization = total > 0 ? (totalActive / total * 100).toFixed(1) : "0";
@@ -3183,8 +3210,9 @@ High suspension rate (${totalSuspended} suspended vs ${totalActive} active)`);
3183
3210
  sections.push(`## eSIM Fleet Status`);
3184
3211
  sections.push(`Unavailable: ${statusResult.error ?? "esimStatusPerAccount returned no data"}`);
3185
3212
  }
3186
- const accountsOk = accountsResult.data && Array.isArray(accountsResult.data);
3187
- const accounts = accountsOk ? accountsResult.data : [];
3213
+ const accountsRaw = accountsResult.data;
3214
+ const accounts = Array.isArray(accountsRaw) ? accountsRaw : (accountsRaw?.reseller ?? []).flatMap((r) => r.account ?? []);
3215
+ const accountsOk = accountsResult.data !== null && (accounts.length > 0 || accountsResult.error === null);
3188
3216
  if (accountsOk) {
3189
3217
  const lowBalance = accounts.filter(
3190
3218
  (a) => Number(a.balance ?? 0) < 10