@littlebearapps/platform-admin-sdk 2.1.0 → 2.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.
Files changed (115) hide show
  1. package/README.md +2 -5
  2. package/dist/templates.d.ts +1 -1
  3. package/dist/templates.js +121 -3
  4. package/package.json +1 -1
  5. package/templates/full/dashboard/src/components/notifications/NotificationDropdown.tsx +130 -0
  6. package/templates/full/dashboard/src/components/notifications/NotificationItem.tsx +264 -0
  7. package/templates/full/dashboard/src/components/patterns/PatternInfoButton.tsx +60 -0
  8. package/templates/full/dashboard/src/components/reports/FeatureUsageReport.tsx +339 -0
  9. package/templates/full/dashboard/src/components/search/SearchResultGroup.tsx +46 -0
  10. package/templates/full/dashboard/src/components/search/SearchResultItem.tsx +212 -0
  11. package/templates/full/dashboard/src/pages/api/patterns/[id]/approve.ts +49 -0
  12. package/templates/full/dashboard/src/pages/api/patterns/[id]/reject.ts +50 -0
  13. package/templates/full/dashboard/src/pages/api/reports/digests/stats.ts +38 -0
  14. package/templates/full/dashboard/src/pages/api/reports/digests.ts +39 -0
  15. package/templates/full/dashboard/src/pages/api/search/reindex/[type].ts +56 -0
  16. package/templates/full/dashboard/src/pages/api/test-reports/[id].ts +102 -0
  17. package/templates/full/dashboard/src/pages/feedback.astro +365 -0
  18. package/templates/full/dashboard/src/pages/kiosk.astro +206 -0
  19. package/templates/full/dashboard/src/pages/map.astro +561 -0
  20. package/templates/full/dashboard/src/pages/revenue.astro +72 -0
  21. package/templates/full/dashboard/src/pages/tests.astro +431 -0
  22. package/templates/full/scripts/ops/audit-cost-anomaly.ts +430 -0
  23. package/templates/full/scripts/ops/verify-account-total.ts +256 -0
  24. package/templates/full/tests/integration/feedback-schema.test.ts +361 -0
  25. package/templates/full/tests/integration/r2-archive.test.ts +108 -0
  26. package/templates/shared/.github/workflows/dependabot-automerge.yml +41 -0
  27. package/templates/shared/.github/workflows/validate-controls.yml +27 -0
  28. package/templates/shared/dashboard/src/components/Breadcrumbs.astro +101 -0
  29. package/templates/shared/dashboard/src/components/EmptyState.astro +46 -0
  30. package/templates/shared/dashboard/src/components/ErrorBoundary.astro +79 -0
  31. package/templates/shared/dashboard/src/components/LoadingSkeleton.astro +105 -0
  32. package/templates/shared/dashboard/src/components/PageShell.astro +72 -0
  33. package/templates/shared/dashboard/src/components/SkipLinks.astro +22 -0
  34. package/templates/shared/dashboard/src/components/Toast.astro +170 -0
  35. package/templates/shared/dashboard/src/components/ToastContainer.astro +156 -0
  36. package/templates/shared/dashboard/src/components/costs/ProviderCostsGrid.tsx +401 -0
  37. package/templates/shared/dashboard/src/components/costs/index.ts +4 -0
  38. package/templates/shared/dashboard/src/components/overview/AlertBanner.tsx +94 -0
  39. package/templates/shared/dashboard/src/components/overview/index.ts +9 -0
  40. package/templates/shared/dashboard/src/components/resources/CostChart.tsx +170 -0
  41. package/templates/shared/dashboard/src/components/resources/ProviderCard.tsx +272 -0
  42. package/templates/shared/dashboard/src/components/resources/ProviderDetail.tsx +293 -0
  43. package/templates/shared/dashboard/src/components/settings/SettingsCard.astro +102 -0
  44. package/templates/shared/dashboard/src/components/usage/AllowanceGauge.astro +170 -0
  45. package/templates/shared/dashboard/src/components/usage/AnomalyAlerts.astro +633 -0
  46. package/templates/shared/dashboard/src/components/usage/BillingCycleCountdown.astro +192 -0
  47. package/templates/shared/dashboard/src/components/usage/BurnRateHero.astro +539 -0
  48. package/templates/shared/dashboard/src/components/usage/CircuitBreakerEventLog.astro +542 -0
  49. package/templates/shared/dashboard/src/components/usage/CircuitBreakerPanel.tsx +292 -0
  50. package/templates/shared/dashboard/src/components/usage/CircuitBreakerStatus.astro +669 -0
  51. package/templates/shared/dashboard/src/components/usage/CompactThresholdBanner.astro +531 -0
  52. package/templates/shared/dashboard/src/components/usage/ComparisonModeSelector.astro +651 -0
  53. package/templates/shared/dashboard/src/components/usage/CostBreakdownChart.astro +381 -0
  54. package/templates/shared/dashboard/src/components/usage/CostBreakdownTable.astro +210 -0
  55. package/templates/shared/dashboard/src/components/usage/CostDataTable.astro +0 -0
  56. package/templates/shared/dashboard/src/components/usage/CostDonutChart.astro +311 -0
  57. package/templates/shared/dashboard/src/components/usage/DailyCostChart.astro +632 -0
  58. package/templates/shared/dashboard/src/components/usage/ExportButton.astro +114 -0
  59. package/templates/shared/dashboard/src/components/usage/FeatureBudgetsTable.astro +872 -0
  60. package/templates/shared/dashboard/src/components/usage/FilterBar.astro +190 -0
  61. package/templates/shared/dashboard/src/components/usage/FilterToggles.astro +175 -0
  62. package/templates/shared/dashboard/src/components/usage/GitHubUsageCard.astro +537 -0
  63. package/templates/shared/dashboard/src/components/usage/OverageCostCard.astro +212 -0
  64. package/templates/shared/dashboard/src/components/usage/PlanUtilizationCard.astro +193 -0
  65. package/templates/shared/dashboard/src/components/usage/ProjectCard.astro +640 -0
  66. package/templates/shared/dashboard/src/components/usage/ProjectCardsGrid.astro +272 -0
  67. package/templates/shared/dashboard/src/components/usage/ResourceSearch.astro +279 -0
  68. package/templates/shared/dashboard/src/components/usage/ServiceUtilizationList.astro +604 -0
  69. package/templates/shared/dashboard/src/components/usage/SparklineCard.astro +399 -0
  70. package/templates/shared/dashboard/src/components/usage/StatsHero.astro +600 -0
  71. package/templates/shared/dashboard/src/components/usage/TableFilters.astro +1033 -0
  72. package/templates/shared/dashboard/src/components/usage/ThresholdAlert.astro +271 -0
  73. package/templates/shared/dashboard/src/components/usage/ThresholdSettings.astro +618 -0
  74. package/templates/shared/dashboard/src/components/usage/TopSpenderCard.astro +170 -0
  75. package/templates/shared/dashboard/src/components/usage/UnifiedResourceTable.astro +1737 -0
  76. package/templates/shared/dashboard/src/components/usage/UsageCard.astro +135 -0
  77. package/templates/shared/dashboard/src/components/usage/UsageHealthBanner.astro +387 -0
  78. package/templates/shared/dashboard/src/components/usage/UtilizationBar.astro +159 -0
  79. package/templates/shared/dashboard/src/components/usage/WorkersBreakdownTable.astro +659 -0
  80. package/templates/shared/dashboard/src/components/usage/daily/CostChart.astro +461 -0
  81. package/templates/shared/dashboard/src/components/usage/daily/CostTable.astro +946 -0
  82. package/templates/shared/dashboard/src/components/usage/daily/DailyOverview.astro +1079 -0
  83. package/templates/shared/dashboard/src/components/usage/design-tokens.ts +187 -0
  84. package/templates/shared/dashboard/src/components/usage/filters/InlineDateRange.astro +285 -0
  85. package/templates/shared/dashboard/src/components/usage/filters/PeriodButtons.astro +157 -0
  86. package/templates/shared/dashboard/src/components/usage/filters/ProjectSelect.astro +284 -0
  87. package/templates/shared/dashboard/src/components/usage/scripts/ai-tab-controller.ts +419 -0
  88. package/templates/shared/dashboard/src/components/usage/scripts/constants.ts +60 -0
  89. package/templates/shared/dashboard/src/components/usage/scripts/formatters.ts +62 -0
  90. package/templates/shared/dashboard/src/components/usage/scripts/overview-controller.ts +1633 -0
  91. package/templates/shared/dashboard/src/components/usage/scripts/resource-table-builder.ts +294 -0
  92. package/templates/shared/dashboard/src/components/usage/scripts/tabs-filters-controller.ts +464 -0
  93. package/templates/shared/dashboard/src/components/usage/state/index.ts +55 -0
  94. package/templates/shared/dashboard/src/components/usage/state/usageActions.ts +439 -0
  95. package/templates/shared/dashboard/src/components/usage/state/usageStore.ts +376 -0
  96. package/templates/shared/dashboard/src/components/usage/types.ts +283 -0
  97. package/templates/shared/dashboard/src/components/usage/usage-colors.ts +292 -0
  98. package/templates/shared/dashboard/src/pages/api/usage/ai-models.ts +235 -0
  99. package/templates/shared/dashboard/src/pages/api/usage/billing-context.ts +296 -0
  100. package/templates/shared/scripts/test-telemetry-flow.ts +464 -0
  101. package/templates/shared/tests/e2e/usage-export.test.ts +784 -0
  102. package/templates/shared/tests/e2e/usage-mobile.test.ts +531 -0
  103. package/templates/standard/dashboard/src/components/errors/PriorityBadge.astro +27 -0
  104. package/templates/standard/dashboard/src/components/infrastructure/HealthchecksStatus.tsx +293 -0
  105. package/templates/standard/dashboard/src/components/infrastructure/InfrastructureTabs.tsx +268 -0
  106. package/templates/standard/dashboard/src/pages/analytics.astro +64 -0
  107. package/templates/standard/dashboard/src/pages/api/infrastructure/alerts.ts +85 -0
  108. package/templates/standard/dashboard/src/pages/api/infrastructure/healthchecks/[id]/flips.ts +110 -0
  109. package/templates/standard/dashboard/src/pages/api/infrastructure/healthchecks.ts +101 -0
  110. package/templates/standard/dashboard/src/pages/api/infrastructure/uptime/[id]/response-times.ts +121 -0
  111. package/templates/standard/dashboard/src/pages/api/infrastructure/uptime.ts +89 -0
  112. package/templates/standard/dashboard/src/pages/api/test/service-auth.ts +178 -0
  113. package/templates/standard/tests/integration/connectors.test.ts +241 -0
  114. package/templates/standard/tests/integration/github-monitor.test.ts +143 -0
  115. package/templates/standard/tests/integration/ingestion.test.ts +211 -0
@@ -0,0 +1,170 @@
1
+ ---
2
+ /**
3
+ * TopSpenderCard - Shows resource with highest cost
4
+ *
5
+ * Part of task-usage-rebuild: Single Pane of Glass
6
+ * Displays the service type with highest cost in the period
7
+ */
8
+ ---
9
+
10
+ <div
11
+ class="bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg p-4 shadow-sm h-full flex flex-col"
12
+ >
13
+ <!-- Header -->
14
+ <div class="flex items-center gap-2 mb-3">
15
+ <div
16
+ class="w-8 h-8 rounded-lg bg-amber-100 dark:bg-amber-900/30 flex items-center justify-center"
17
+ >
18
+ <svg
19
+ class="w-4 h-4 text-amber-600 dark:text-amber-400"
20
+ fill="none"
21
+ stroke="currentColor"
22
+ viewBox="0 0 24 24"
23
+ >
24
+ <path
25
+ stroke-linecap="round"
26
+ stroke-linejoin="round"
27
+ stroke-width="2"
28
+ d="M13 7h8m0 0v8m0-8l-8 8-4-4-6 6"></path>
29
+ </svg>
30
+ </div>
31
+ <div>
32
+ <h3 class="text-sm font-medium text-gray-500 dark:text-gray-400">Top Spender</h3>
33
+ </div>
34
+ </div>
35
+
36
+ <!-- Main metric -->
37
+ <div class="mb-3">
38
+ <div class="flex items-baseline gap-2">
39
+ <span id="top-spender-cost" class="text-3xl font-bold text-gray-900 dark:text-gray-100"
40
+ >$--</span
41
+ >
42
+ <span id="top-spender-pct" class="text-sm text-gray-500 dark:text-gray-400">-- of total</span>
43
+ </div>
44
+ <div id="top-spender-name" class="text-sm font-medium text-amber-600 dark:text-amber-400 mt-1">
45
+ Loading...
46
+ </div>
47
+ </div>
48
+
49
+ <!-- Breakdown mini-bars -->
50
+ <div id="top-spender-breakdown" class="space-y-1.5 flex-grow flex flex-col justify-end">
51
+ <!-- Populated by JavaScript -->
52
+ </div>
53
+ </div>
54
+
55
+ <script>
56
+ interface BurnRateData {
57
+ mtdCost?: number;
58
+ projectedMonthlyCost?: number;
59
+ breakdown?: Record<string, number>;
60
+ }
61
+
62
+ const SERVICE_LABELS: Record<string, string> = {
63
+ workers: 'Workers',
64
+ d1: 'D1 Database',
65
+ kv: 'KV Storage',
66
+ r2: 'R2 Storage',
67
+ durableObjects: 'Durable Objects',
68
+ vectorize: 'Vectorize',
69
+ aiGateway: 'AI Gateway',
70
+ workersAI: 'Workers AI',
71
+ queues: 'Queues',
72
+ };
73
+
74
+ const SERVICE_COLORS: Record<string, string> = {
75
+ workers: 'bg-blue-500',
76
+ d1: 'bg-green-500',
77
+ kv: 'bg-purple-500',
78
+ r2: 'bg-orange-500',
79
+ durableObjects: 'bg-pink-500',
80
+ vectorize: 'bg-cyan-500',
81
+ aiGateway: 'bg-indigo-500',
82
+ workersAI: 'bg-red-500',
83
+ queues: 'bg-yellow-500',
84
+ };
85
+
86
+ function formatCost(cost: number): string {
87
+ if (cost >= 1000) return `$${(cost / 1000).toFixed(1)}K`;
88
+ if (cost >= 1) return `$${cost.toFixed(2)}`;
89
+ if (cost >= 0.01) return `$${cost.toFixed(3)}`;
90
+ return `$${cost.toFixed(4)}`;
91
+ }
92
+
93
+ function createBreakdownRow(service: string, cost: number, maxCost: number): HTMLDivElement {
94
+ const widthPct = (cost / maxCost) * 100;
95
+ const label = SERVICE_LABELS[service] || service;
96
+ const color = SERVICE_COLORS[service] || 'bg-gray-500';
97
+
98
+ const row = document.createElement('div');
99
+ row.className = 'flex items-center gap-2 text-xs';
100
+
101
+ const labelSpan = document.createElement('span');
102
+ labelSpan.className = 'w-24 truncate text-gray-600 dark:text-gray-400';
103
+ labelSpan.textContent = label;
104
+ labelSpan.title = label; // Tooltip shows full name on hover
105
+
106
+ const barContainer = document.createElement('div');
107
+ barContainer.className =
108
+ 'flex-1 h-1.5 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden';
109
+
110
+ const bar = document.createElement('div');
111
+ bar.className = `h-full ${color} rounded-full`;
112
+ bar.style.width = `${widthPct}%`;
113
+ barContainer.appendChild(bar);
114
+
115
+ const costSpan = document.createElement('span');
116
+ costSpan.className = 'w-14 text-right text-gray-500 dark:text-gray-400';
117
+ costSpan.textContent = formatCost(cost);
118
+
119
+ row.appendChild(labelSpan);
120
+ row.appendChild(barContainer);
121
+ row.appendChild(costSpan);
122
+
123
+ return row;
124
+ }
125
+
126
+ function updateTopSpender(data: BurnRateData) {
127
+ const breakdown = data.breakdown || {};
128
+ const totalCost = data.mtdCost || Object.values(breakdown).reduce((sum, v) => sum + v, 0);
129
+
130
+ // Sort by cost descending
131
+ const sorted = Object.entries(breakdown)
132
+ .filter(([_, cost]) => cost > 0)
133
+ .sort((a, b) => b[1] - a[1]);
134
+
135
+ if (sorted.length === 0) {
136
+ const costEl = document.getElementById('top-spender-cost');
137
+ const nameEl = document.getElementById('top-spender-name');
138
+ if (costEl) costEl.textContent = '$0.00';
139
+ if (nameEl) nameEl.textContent = 'No costs recorded';
140
+ return;
141
+ }
142
+
143
+ const [topService, topCost] = sorted[0];
144
+ const pctOfTotal = totalCost > 0 ? (topCost / totalCost) * 100 : 0;
145
+
146
+ const costEl = document.getElementById('top-spender-cost');
147
+ const pctEl = document.getElementById('top-spender-pct');
148
+ const nameEl = document.getElementById('top-spender-name');
149
+ const breakdownEl = document.getElementById('top-spender-breakdown');
150
+
151
+ if (costEl) costEl.textContent = formatCost(topCost);
152
+ if (pctEl) pctEl.textContent = `${pctOfTotal.toFixed(0)}% of total`;
153
+ if (nameEl) nameEl.textContent = SERVICE_LABELS[topService] || topService;
154
+
155
+ // Build mini breakdown bars (top 4) using safe DOM methods
156
+ if (breakdownEl) {
157
+ breakdownEl.replaceChildren(); // Clear existing content safely
158
+ const topFour = sorted.slice(0, 4);
159
+ const maxCost = topFour[0][1];
160
+
161
+ for (const [service, cost] of topFour) {
162
+ breakdownEl.appendChild(createBreakdownRow(service, cost, maxCost));
163
+ }
164
+ }
165
+ }
166
+
167
+ // Expose globally for index.astro to call
168
+ (window as unknown as { updateTopSpender: typeof updateTopSpender }).updateTopSpender =
169
+ updateTopSpender;
170
+ </script>