@carrierllc/mcp 0.2.8 → 0.2.10

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,50 @@ 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 count = Number(s.count ?? 0);
3163
+ const num = s.statusNum;
3164
+ if (typeof num === "number") {
3165
+ if (num === 1) active += count;
3166
+ else if (num === 2) suspended += count;
3167
+ else if (num === 0) inventory += count;
3168
+ else other += count;
3169
+ continue;
3170
+ }
3171
+ const str = String(s.statusStr ?? s.name ?? "").toUpperCase();
3172
+ if (str === "ACTIVATED" || str === "ACTIVE") active += count;
3173
+ else if (str === "SUSPENDED") suspended += count;
3174
+ else if (str === "FREE" || str === "INVENTORY" || str === "NOT_ACTIVATED" || str === "AVAILABLE") inventory += count;
3175
+ else other += count;
3176
+ }
3177
+ }
3178
+ return { active, suspended, inventory, other };
3179
+ };
3152
3180
  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
3181
  if (statusOk) {
3156
3182
  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);
3183
+ const hasSponsors = Array.isArray(account.sponsor);
3184
+ if (hasSponsors) {
3185
+ const c = countByState(account);
3186
+ totalActive += c.active;
3187
+ totalSuspended += c.suspended;
3188
+ totalInventory += c.inventory;
3189
+ totalOther += c.other;
3190
+ } else {
3191
+ totalActive += Number(account.active ?? 0);
3192
+ totalSuspended += Number(account.suspended ?? 0);
3193
+ totalInventory += Number(account.inventory ?? account.notActivated ?? 0);
3194
+ totalOther += Number(account.other ?? account.terminated ?? 0);
3195
+ }
3161
3196
  }
3162
3197
  const total = totalActive + totalSuspended + totalInventory + totalOther;
3163
3198
  const utilization = total > 0 ? (totalActive / total * 100).toFixed(1) : "0";
@@ -3183,8 +3218,9 @@ High suspension rate (${totalSuspended} suspended vs ${totalActive} active)`);
3183
3218
  sections.push(`## eSIM Fleet Status`);
3184
3219
  sections.push(`Unavailable: ${statusResult.error ?? "esimStatusPerAccount returned no data"}`);
3185
3220
  }
3186
- const accountsOk = accountsResult.data && Array.isArray(accountsResult.data);
3187
- const accounts = accountsOk ? accountsResult.data : [];
3221
+ const accountsRaw = accountsResult.data;
3222
+ const accounts = Array.isArray(accountsRaw) ? accountsRaw : (accountsRaw?.reseller ?? []).flatMap((r) => r.account ?? []);
3223
+ const accountsOk = accountsResult.data !== null && (accounts.length > 0 || accountsResult.error === null);
3188
3224
  if (accountsOk) {
3189
3225
  const lowBalance = accounts.filter(
3190
3226
  (a) => Number(a.balance ?? 0) < 10