@littlebearapps/platform-admin-sdk 1.4.2 → 2.0.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/templates.d.ts +1 -1
- package/dist/templates.js +232 -2
- package/package.json +1 -1
- package/templates/full/config/audit-targets.yaml +72 -0
- package/templates/full/dashboard/src/components/notifications/NotificationBell.tsx +30 -0
- package/templates/full/dashboard/src/components/notifications/NotificationList.tsx +116 -0
- package/templates/full/dashboard/src/components/notifications/index.ts +2 -0
- package/templates/full/dashboard/src/components/patterns/ActivePatterns.tsx +62 -0
- package/templates/full/dashboard/src/components/patterns/PatternStats.tsx +60 -0
- package/templates/full/dashboard/src/components/patterns/PatternTabs.tsx +116 -0
- package/templates/full/dashboard/src/components/patterns/SuggestionsQueue.tsx +115 -0
- package/templates/full/dashboard/src/components/patterns/SystemPatterns.tsx +52 -0
- package/templates/full/dashboard/src/components/patterns/index.ts +5 -0
- package/templates/full/dashboard/src/components/reports/GapDetectionReport.tsx +69 -0
- package/templates/full/dashboard/src/components/reports/SdkAuditReport.tsx +72 -0
- package/templates/full/dashboard/src/components/reports/index.ts +2 -0
- package/templates/full/dashboard/src/components/search/SearchModal.tsx +108 -0
- package/templates/full/dashboard/src/pages/api/notifications/[id]/read.ts +37 -0
- package/templates/full/dashboard/src/pages/api/notifications/index.ts +47 -0
- package/templates/full/dashboard/src/pages/api/notifications/read-all.ts +28 -0
- package/templates/full/dashboard/src/pages/api/notifications/unread-count.ts +31 -0
- package/templates/full/dashboard/src/pages/api/patterns/approve.ts +55 -0
- package/templates/full/dashboard/src/pages/api/patterns/cache-refresh.ts +38 -0
- package/templates/full/dashboard/src/pages/api/patterns/discover.ts +36 -0
- package/templates/full/dashboard/src/pages/api/patterns/index.ts +36 -0
- package/templates/full/dashboard/src/pages/api/patterns/ready-for-review.ts +39 -0
- package/templates/full/dashboard/src/pages/api/patterns/reject.ts +54 -0
- package/templates/full/dashboard/src/pages/api/patterns/stats.ts +39 -0
- package/templates/full/dashboard/src/pages/api/patterns/suggestions.ts +43 -0
- package/templates/full/dashboard/src/pages/api/reports/audit.ts +45 -0
- package/templates/full/dashboard/src/pages/api/reports/usage.ts +52 -0
- package/templates/full/dashboard/src/pages/api/search/index.ts +74 -0
- package/templates/full/dashboard/src/pages/api/search/reindex.ts +28 -0
- package/templates/full/dashboard/src/pages/api/search/stats.ts +27 -0
- package/templates/full/dashboard/src/pages/api/settings/index.ts +37 -0
- package/templates/full/dashboard/src/pages/api/settings/update.ts +41 -0
- package/templates/full/dashboard/src/pages/api/topology/index.ts +56 -0
- package/templates/full/dashboard/src/pages/notifications.astro +11 -0
- package/templates/full/migrations/008_auditor.sql +99 -0
- package/templates/full/migrations/010_pricing_versions.sql +110 -0
- package/templates/full/migrations/011_multi_account.sql +51 -0
- package/templates/full/scripts/ops/set-kv-pricing.ts +182 -0
- package/templates/full/scripts/ops/universal-backfill.ts +147 -0
- package/templates/full/workers/lib/ai-judge-schema.ts +181 -0
- package/templates/full/workers/lib/auditor/comprehensive-report.ts +407 -0
- package/templates/full/workers/lib/auditor/feature-coverage.ts +348 -0
- package/templates/full/workers/lib/auditor/index.ts +9 -0
- package/templates/full/workers/lib/auditor/types.ts +167 -0
- package/templates/full/workers/platform-auditor.ts +1071 -0
- package/templates/full/wrangler.auditor.jsonc.hbs +75 -0
- package/templates/shared/.github/workflows/contract-check.yml.hbs +42 -0
- package/templates/shared/.github/workflows/dashboard-deploy.yml.hbs +39 -0
- package/templates/shared/.github/workflows/platform-check.yml.hbs +28 -0
- package/templates/shared/.github/workflows/security.yml +33 -0
- package/templates/shared/config/observability.yaml.hbs +276 -0
- package/templates/shared/contracts/schemas/envelope.v1.schema.json +64 -0
- package/templates/shared/contracts/schemas/error_report.v1.schema.json +65 -0
- package/templates/shared/contracts/types/telemetry-envelope.types.ts +139 -0
- package/templates/shared/dashboard/astro.config.mjs +21 -0
- package/templates/shared/dashboard/package.json.hbs +29 -0
- package/templates/shared/dashboard/src/components/Header.astro +29 -0
- package/templates/shared/dashboard/src/components/Nav.astro.hbs +59 -0
- package/templates/shared/dashboard/src/components/infrastructure/AlertHistory.tsx +57 -0
- package/templates/shared/dashboard/src/components/infrastructure/InfrastructureStats.tsx +73 -0
- package/templates/shared/dashboard/src/components/infrastructure/ServiceRegistry.tsx +55 -0
- package/templates/shared/dashboard/src/components/infrastructure/UptimeStatus.tsx +56 -0
- package/templates/shared/dashboard/src/components/infrastructure/index.ts +4 -0
- package/templates/shared/dashboard/src/components/overview/ActivityFeed.tsx +134 -0
- package/templates/shared/dashboard/src/components/overview/CostQuadrant.tsx +131 -0
- package/templates/shared/dashboard/src/components/overview/ErrorsQuadrant.tsx +113 -0
- package/templates/shared/dashboard/src/components/overview/HealthQuadrant.tsx +87 -0
- package/templates/shared/dashboard/src/components/overview/MissionControl.tsx +139 -0
- package/templates/shared/dashboard/src/components/resources/AllowanceStatus.tsx +44 -0
- package/templates/shared/dashboard/src/components/resources/CostCentreOverview.tsx +42 -0
- package/templates/shared/dashboard/src/components/resources/ResourceTabs.tsx +69 -0
- package/templates/shared/dashboard/src/components/resources/index.ts +3 -0
- package/templates/shared/dashboard/src/components/settings/SettingsCard.tsx +21 -0
- package/templates/shared/dashboard/src/components/settings/index.ts +1 -0
- package/templates/shared/dashboard/src/components/ui/AlertBanner.tsx +39 -0
- package/templates/shared/dashboard/src/components/ui/Breadcrumbs.tsx +27 -0
- package/templates/shared/dashboard/src/components/ui/EmptyState.tsx +26 -0
- package/templates/shared/dashboard/src/components/ui/ErrorBoundary.tsx +42 -0
- package/templates/shared/dashboard/src/components/ui/LoadingSkeleton.tsx +18 -0
- package/templates/shared/dashboard/src/components/ui/PageShell.tsx +26 -0
- package/templates/shared/dashboard/src/components/ui/Sparkline.tsx +127 -0
- package/templates/shared/dashboard/src/components/ui/StatusDot.tsx +21 -0
- package/templates/shared/dashboard/src/components/ui/Toast.tsx +44 -0
- package/templates/shared/dashboard/src/components/ui/index.ts +9 -0
- package/templates/shared/dashboard/src/components/usage/AnomaliesWidget.tsx +68 -0
- package/templates/shared/dashboard/src/components/usage/HourlyUsageChart.tsx +55 -0
- package/templates/shared/dashboard/src/components/usage/PlanAllowanceDashboard.tsx +67 -0
- package/templates/shared/dashboard/src/components/usage/ProjectCostBreakdown.tsx +55 -0
- package/templates/shared/dashboard/src/components/usage/index.ts +4 -0
- package/templates/shared/dashboard/src/env.d.ts.hbs +34 -0
- package/templates/shared/dashboard/src/layouts/DashboardLayout.astro +37 -0
- package/templates/shared/dashboard/src/lib/cloudflare/costs.ts +21 -0
- package/templates/shared/dashboard/src/lib/fetch.ts +29 -0
- package/templates/shared/dashboard/src/lib/types.ts +72 -0
- package/templates/shared/dashboard/src/middleware/auth.ts +100 -0
- package/templates/shared/dashboard/src/middleware/index.ts +1 -0
- package/templates/shared/dashboard/src/pages/api/costs/overview.ts +65 -0
- package/templates/shared/dashboard/src/pages/api/costs/providers.ts +47 -0
- package/templates/shared/dashboard/src/pages/api/infrastructure/services.ts +55 -0
- package/templates/shared/dashboard/src/pages/api/infrastructure/stats.ts +99 -0
- package/templates/shared/dashboard/src/pages/api/overview/summary.ts +311 -0
- package/templates/shared/dashboard/src/pages/api/usage/allowances.ts +56 -0
- package/templates/shared/dashboard/src/pages/api/usage/anomalies.ts +45 -0
- package/templates/shared/dashboard/src/pages/api/usage/billing.ts +53 -0
- package/templates/shared/dashboard/src/pages/api/usage/circuit-breakers.ts +44 -0
- package/templates/shared/dashboard/src/pages/api/usage/granular.ts +50 -0
- package/templates/shared/dashboard/src/pages/api/usage/hourly.ts +45 -0
- package/templates/shared/dashboard/src/pages/api/usage/projects.ts +51 -0
- package/templates/shared/dashboard/src/pages/api/usage/status.ts +42 -0
- package/templates/shared/dashboard/src/pages/api/user/identity.ts +11 -0
- package/templates/shared/dashboard/src/pages/dashboard.astro +11 -0
- package/templates/shared/dashboard/src/pages/index.astro +3 -0
- package/templates/shared/dashboard/src/pages/resources.astro +11 -0
- package/templates/shared/dashboard/src/pages/settings/index.astro +28 -0
- package/templates/shared/dashboard/src/pages/settings/notifications.astro +34 -0
- package/templates/shared/dashboard/src/pages/settings/thresholds.astro +39 -0
- package/templates/shared/dashboard/src/pages/settings/usage.astro +28 -0
- package/templates/shared/dashboard/src/styles/global.css +29 -0
- package/templates/shared/dashboard/tailwind.config.mjs +9 -0
- package/templates/shared/dashboard/tsconfig.json +9 -0
- package/templates/shared/dashboard/wrangler.json.hbs +47 -0
- package/templates/shared/docs/architecture.md +89 -0
- package/templates/shared/docs/post-deploy-runbook.md +126 -0
- package/templates/shared/docs/troubleshooting.md +91 -0
- package/templates/shared/package.json.hbs +17 -1
- package/templates/shared/scripts/ops/backfill-cloudflare-daily.ts +145 -0
- package/templates/shared/scripts/ops/backfill-cloudflare-hourly.ts +473 -0
- package/templates/shared/scripts/ops/backfill-monthly-rollups.ts +125 -0
- package/templates/shared/scripts/ops/discover-graphql-datasets.ts +482 -0
- package/templates/shared/scripts/ops/reset-budget-state.ts +279 -0
- package/templates/shared/scripts/ops/validate-controls.js +141 -0
- package/templates/shared/scripts/ops/validate-pipeline.ts +237 -0
- package/templates/shared/scripts/ops/verify-account-completeness.ts +236 -0
- package/templates/shared/scripts/validate-schemas.js +61 -0
- package/templates/shared/tests/contract/validate-schemas.test.ts +130 -0
- package/templates/shared/tests/fixtures/telemetry-envelope-invalid.json +9 -0
- package/templates/shared/tests/fixtures/telemetry-envelope-valid.json +27 -0
- package/templates/shared/tests/helpers/mock-d1.ts +61 -0
- package/templates/shared/tests/helpers/mock-kv.ts +37 -0
- package/templates/shared/tests/unit/workers/batch-persistence.test.ts +133 -0
- package/templates/shared/tests/unit/workers/budget-enforcement.test.ts +214 -0
- package/templates/shared/vitest.config.ts +18 -0
- package/templates/shared/workers/lib/usage/collectors/anthropic.ts +114 -0
- package/templates/shared/workers/lib/usage/collectors/apify.ts +96 -0
- package/templates/shared/workers/lib/usage/collectors/custom-http.ts +151 -0
- package/templates/shared/workers/lib/usage/collectors/deepseek.ts +92 -0
- package/templates/shared/workers/lib/usage/collectors/gemini.ts +263 -0
- package/templates/shared/workers/lib/usage/collectors/github.ts +362 -0
- package/templates/shared/workers/lib/usage/collectors/index.ts +31 -15
- package/templates/shared/workers/lib/usage/collectors/minimax.ts +106 -0
- package/templates/shared/workers/lib/usage/collectors/openai.ts +171 -0
- package/templates/shared/workers/lib/usage/collectors/resend.ts +79 -0
- package/templates/shared/workers/lib/usage/collectors/stripe.ts +192 -0
- package/templates/shared/workers/lib/usage/shared/types.ts +46 -0
- package/templates/shared/workers/platform-usage.ts +98 -8
- package/templates/standard/dashboard/src/components/errors/ErrorStats.tsx +53 -0
- package/templates/standard/dashboard/src/components/errors/ErrorsTable.tsx +133 -0
- package/templates/standard/dashboard/src/components/errors/index.ts +2 -0
- package/templates/standard/dashboard/src/components/health/CircuitBreakerEvents.tsx +69 -0
- package/templates/standard/dashboard/src/components/health/CircuitBreakerPanel.tsx +97 -0
- package/templates/standard/dashboard/src/components/health/DlqStatusCard.tsx +52 -0
- package/templates/standard/dashboard/src/components/health/HealthTabs.tsx +86 -0
- package/templates/standard/dashboard/src/components/health/index.ts +4 -0
- package/templates/standard/dashboard/src/lib/errors.ts +28 -0
- package/templates/standard/dashboard/src/pages/api/errors/[fingerprint]/mute.ts +49 -0
- package/templates/standard/dashboard/src/pages/api/errors/[fingerprint]/resolve.ts +36 -0
- package/templates/standard/dashboard/src/pages/api/errors/[fingerprint].ts +55 -0
- package/templates/standard/dashboard/src/pages/api/errors/index.ts +58 -0
- package/templates/standard/dashboard/src/pages/api/errors/stats.ts +55 -0
- package/templates/standard/dashboard/src/pages/api/health/audit-history.ts +37 -0
- package/templates/standard/dashboard/src/pages/api/health/dlq.ts +43 -0
- package/templates/standard/dashboard/src/pages/circuit-breakers.astro +13 -0
- package/templates/standard/dashboard/src/pages/errors.astro +13 -0
- package/templates/standard/dashboard/src/pages/health.astro +11 -0
- package/templates/standard/migrations/009_topology_mapper.sql +65 -0
- package/templates/standard/tests/unit/error-collector/capture.test.ts +106 -0
- package/templates/standard/tests/unit/error-collector/fingerprint.test.ts +155 -0
- package/templates/standard/workers/lib/error-collector/email-health-alerts.ts +37 -3
- package/templates/standard/workers/lib/error-collector/gap-alerts.ts +32 -1
- package/templates/standard/workers/lib/mapper/attribution-check.ts +339 -0
- package/templates/standard/workers/lib/mapper/index.ts +7 -0
- package/templates/standard/workers/platform-mapper.ts +482 -0
- package/templates/standard/workers/platform-sdk-test-client.ts +125 -0
- package/templates/standard/wrangler.mapper.jsonc.hbs +85 -0
- package/templates/standard/wrangler.sdk-test-client.jsonc.hbs +62 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { APIRoute } from 'astro';
|
|
2
|
+
|
|
3
|
+
export const GET: APIRoute = async ({ request }) => {
|
|
4
|
+
// Extract identity from CF Access JWT headers
|
|
5
|
+
const email = request.headers.get('cf-access-authenticated-user-email') ?? 'unknown';
|
|
6
|
+
const name = email.split('@')[0] ?? 'User';
|
|
7
|
+
|
|
8
|
+
return new Response(JSON.stringify({ email, name }), {
|
|
9
|
+
headers: { 'Content-Type': 'application/json', 'Cache-Control': 'max-age=3600' },
|
|
10
|
+
});
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
---
|
|
2
|
+
import DashboardLayout from '../layouts/DashboardLayout.astro';
|
|
3
|
+
import { MissionControl } from '../components/overview/MissionControl';
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<DashboardLayout title="Overview">
|
|
7
|
+
<div class="max-w-7xl mx-auto">
|
|
8
|
+
<h2 class="text-xl font-bold text-gray-900 dark:text-white mb-4">Mission Control</h2>
|
|
9
|
+
<MissionControl client:load />
|
|
10
|
+
</div>
|
|
11
|
+
</DashboardLayout>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
---
|
|
2
|
+
import DashboardLayout from '../layouts/DashboardLayout.astro';
|
|
3
|
+
import { ResourceTabs } from '../components/resources/ResourceTabs';
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<DashboardLayout title="Resources">
|
|
7
|
+
<div class="max-w-7xl mx-auto">
|
|
8
|
+
<h2 class="text-xl font-bold text-gray-900 dark:text-white mb-4">Resources</h2>
|
|
9
|
+
<ResourceTabs client:load />
|
|
10
|
+
</div>
|
|
11
|
+
</DashboardLayout>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
import DashboardLayout from '../../layouts/DashboardLayout.astro';
|
|
3
|
+
import { SettingsCard } from '../../components/settings/SettingsCard';
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<DashboardLayout title="Settings">
|
|
7
|
+
<div class="max-w-3xl mx-auto space-y-4">
|
|
8
|
+
<h2 class="text-xl font-bold text-gray-900 dark:text-white mb-4">Settings</h2>
|
|
9
|
+
<SettingsCard
|
|
10
|
+
client:load
|
|
11
|
+
label="Monthly Budget"
|
|
12
|
+
description="Soft budget limit for cost alerts. Configure in budgets.yaml."
|
|
13
|
+
value="$100"
|
|
14
|
+
/>
|
|
15
|
+
<SettingsCard
|
|
16
|
+
client:load
|
|
17
|
+
label="Circuit Breakers"
|
|
18
|
+
description="Automatic feature pause when budgets are exceeded."
|
|
19
|
+
value="Enabled"
|
|
20
|
+
/>
|
|
21
|
+
<SettingsCard
|
|
22
|
+
client:load
|
|
23
|
+
label="Data Collection"
|
|
24
|
+
description="Hourly Cloudflare GraphQL snapshots and SDK telemetry."
|
|
25
|
+
value="Active"
|
|
26
|
+
/>
|
|
27
|
+
</div>
|
|
28
|
+
</DashboardLayout>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
import DashboardLayout from '../../layouts/DashboardLayout.astro';
|
|
3
|
+
import { SettingsCard } from '../../components/settings/SettingsCard';
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<DashboardLayout title="Notification Settings">
|
|
7
|
+
<div class="max-w-3xl mx-auto space-y-4">
|
|
8
|
+
<h2 class="text-xl font-bold text-gray-900 dark:text-white mb-4">Notification Settings</h2>
|
|
9
|
+
<SettingsCard
|
|
10
|
+
client:load
|
|
11
|
+
label="Slack Alerts"
|
|
12
|
+
description="Send alerts to a Slack channel via webhook URL."
|
|
13
|
+
value="Not configured"
|
|
14
|
+
/>
|
|
15
|
+
<SettingsCard
|
|
16
|
+
client:load
|
|
17
|
+
label="Email Alerts"
|
|
18
|
+
description="Send critical alerts via email."
|
|
19
|
+
value="Disabled"
|
|
20
|
+
/>
|
|
21
|
+
<SettingsCard
|
|
22
|
+
client:load
|
|
23
|
+
label="Budget Warnings"
|
|
24
|
+
description="Notify at 70% and 90% budget thresholds."
|
|
25
|
+
value="Enabled"
|
|
26
|
+
/>
|
|
27
|
+
<SettingsCard
|
|
28
|
+
client:load
|
|
29
|
+
label="Circuit Breaker Trips"
|
|
30
|
+
description="Immediate notification when a circuit breaker trips."
|
|
31
|
+
value="Enabled"
|
|
32
|
+
/>
|
|
33
|
+
</div>
|
|
34
|
+
</DashboardLayout>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
import DashboardLayout from '../../layouts/DashboardLayout.astro';
|
|
3
|
+
import { SettingsCard } from '../../components/settings/SettingsCard';
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<DashboardLayout title="Alert Thresholds">
|
|
7
|
+
<div class="max-w-3xl mx-auto space-y-4">
|
|
8
|
+
<h2 class="text-xl font-bold text-gray-900 dark:text-white mb-4">Alert Thresholds</h2>
|
|
9
|
+
<p class="text-sm text-gray-500 dark:text-gray-400 mb-4">
|
|
10
|
+
Configure when budget warnings fire. These values are defined in
|
|
11
|
+
<code class="text-xs bg-gray-100 dark:bg-gray-700 px-1 py-0.5 rounded">budgets.yaml</code>
|
|
12
|
+
and synced via <code class="text-xs bg-gray-100 dark:bg-gray-700 px-1 py-0.5 rounded">npm run sync:config</code>.
|
|
13
|
+
</p>
|
|
14
|
+
<SettingsCard
|
|
15
|
+
client:load
|
|
16
|
+
label="Warning Threshold"
|
|
17
|
+
description="Alert when feature budget usage reaches this percentage."
|
|
18
|
+
value="70%"
|
|
19
|
+
/>
|
|
20
|
+
<SettingsCard
|
|
21
|
+
client:load
|
|
22
|
+
label="Critical Threshold"
|
|
23
|
+
description="Escalate alert severity at this percentage."
|
|
24
|
+
value="90%"
|
|
25
|
+
/>
|
|
26
|
+
<SettingsCard
|
|
27
|
+
client:load
|
|
28
|
+
label="Circuit Breaker Trip"
|
|
29
|
+
description="Automatically pause feature at this percentage."
|
|
30
|
+
value="100%"
|
|
31
|
+
/>
|
|
32
|
+
<SettingsCard
|
|
33
|
+
client:load
|
|
34
|
+
label="Anomaly Sensitivity"
|
|
35
|
+
description="Deviation percentage to flag as anomaly."
|
|
36
|
+
value="200%"
|
|
37
|
+
/>
|
|
38
|
+
</div>
|
|
39
|
+
</DashboardLayout>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
import DashboardLayout from '../../layouts/DashboardLayout.astro';
|
|
3
|
+
import { SettingsCard } from '../../components/settings/SettingsCard';
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<DashboardLayout title="Usage Settings">
|
|
7
|
+
<div class="max-w-3xl mx-auto space-y-4">
|
|
8
|
+
<h2 class="text-xl font-bold text-gray-900 dark:text-white mb-4">Usage Display Settings</h2>
|
|
9
|
+
<SettingsCard
|
|
10
|
+
client:load
|
|
11
|
+
label="Default Period"
|
|
12
|
+
description="Default time range for usage charts."
|
|
13
|
+
value="24 hours"
|
|
14
|
+
/>
|
|
15
|
+
<SettingsCard
|
|
16
|
+
client:load
|
|
17
|
+
label="Cost Display"
|
|
18
|
+
description="Show costs as net (after allowances) or gross."
|
|
19
|
+
value="Net"
|
|
20
|
+
/>
|
|
21
|
+
<SettingsCard
|
|
22
|
+
client:load
|
|
23
|
+
label="Data Refresh"
|
|
24
|
+
description="How often dashboard polls for new data."
|
|
25
|
+
value="60 seconds"
|
|
26
|
+
/>
|
|
27
|
+
</div>
|
|
28
|
+
</DashboardLayout>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
@tailwind base;
|
|
2
|
+
@tailwind components;
|
|
3
|
+
@tailwind utilities;
|
|
4
|
+
|
|
5
|
+
@layer components {
|
|
6
|
+
.nav-link {
|
|
7
|
+
@apply text-gray-700 transition-colors hover:text-blue-600 dark:text-gray-300 dark:hover:text-blue-400 font-medium;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.metric-card {
|
|
11
|
+
@apply rounded-lg bg-white p-6 shadow dark:bg-gray-800;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.metric-title {
|
|
15
|
+
@apply text-sm font-medium uppercase tracking-wide text-gray-600 dark:text-gray-400;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.metric-value {
|
|
19
|
+
@apply mt-2 text-3xl font-bold text-gray-900 dark:text-white;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.alert-critical {
|
|
23
|
+
@apply rounded border-l-4 border-red-500 bg-red-50 p-4 dark:bg-red-900/20;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.alert-warning {
|
|
27
|
+
@apply rounded border-l-4 border-yellow-500 bg-yellow-50 p-4 dark:bg-yellow-900/20;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "node_modules/wrangler/config-schema.json",
|
|
3
|
+
"name": "{{projectSlug}}-dashboard",
|
|
4
|
+
"pages_build_output_dir": "dist",
|
|
5
|
+
"compatibility_date": "2026-01-01",
|
|
6
|
+
"compatibility_flags": ["nodejs_compat"],
|
|
7
|
+
"upload_source_maps": true,
|
|
8
|
+
"d1_databases": [
|
|
9
|
+
{
|
|
10
|
+
"binding": "PLATFORM_DB",
|
|
11
|
+
"database_name": "YOUR_DATABASE_NAME",
|
|
12
|
+
"database_id": "YOUR_DATABASE_ID"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"kv_namespaces": [
|
|
16
|
+
{
|
|
17
|
+
"binding": "PLATFORM_CACHE",
|
|
18
|
+
"id": "YOUR_PLATFORM_CACHE_KV_ID"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"services": [
|
|
22
|
+
{
|
|
23
|
+
"binding": "USAGE_API",
|
|
24
|
+
"service": "{{projectSlug}}-usage"
|
|
25
|
+
}{{#if isStandard}},
|
|
26
|
+
{
|
|
27
|
+
"binding": "ERROR_COLLECTOR_API",
|
|
28
|
+
"service": "{{projectSlug}}-error-collector"
|
|
29
|
+
}{{/if}}{{#if isFull}},
|
|
30
|
+
{
|
|
31
|
+
"binding": "PATTERN_DISCOVERY_API",
|
|
32
|
+
"service": "{{projectSlug}}-pattern-discovery"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"binding": "NOTIFICATIONS_API",
|
|
36
|
+
"service": "{{projectSlug}}-notifications"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"binding": "SETTINGS_API",
|
|
40
|
+
"service": "{{projectSlug}}-settings"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"binding": "SEARCH_API",
|
|
44
|
+
"service": "{{projectSlug}}-search"
|
|
45
|
+
}{{/if}}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Architecture Overview
|
|
2
|
+
|
|
3
|
+
## System Design
|
|
4
|
+
|
|
5
|
+
The platform follows a hub-and-spoke model:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Producer Projects (Scout, Brand Copilot, etc.)
|
|
9
|
+
│
|
|
10
|
+
▼ SDK telemetry via Queue
|
|
11
|
+
┌────────────────────────────┐
|
|
12
|
+
│ platform-usage worker │ ← Central data warehouse
|
|
13
|
+
│ (cron + queue consumer) │
|
|
14
|
+
└────────────┬───────────────┘
|
|
15
|
+
│
|
|
16
|
+
┌────────┼────────────┐
|
|
17
|
+
▼ ▼ ▼
|
|
18
|
+
D1 DB KV Cache Analytics Engine
|
|
19
|
+
│ │
|
|
20
|
+
▼ ▼
|
|
21
|
+
Dashboard (Astro SSR + CF Pages)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Data Flow
|
|
25
|
+
|
|
26
|
+
### Collection Pipeline
|
|
27
|
+
|
|
28
|
+
1. **SDK Telemetry**: Producer projects send telemetry via `platform-telemetry` queue
|
|
29
|
+
2. **External APIs**: Cron jobs query Cloudflare GraphQL, GitHub, Stripe, AI providers
|
|
30
|
+
3. **Queue Consumer**: Processes messages, enforces budgets, writes to D1 + Analytics Engine
|
|
31
|
+
4. **Failed messages** route to `platform-telemetry-dlq` for manual inspection
|
|
32
|
+
|
|
33
|
+
### Storage Tiers
|
|
34
|
+
|
|
35
|
+
| Storage | Use Case | Cost Profile |
|
|
36
|
+
|---------|----------|--------------|
|
|
37
|
+
| D1 | Historical data, rollups, settings | Writes: $1/M rows |
|
|
38
|
+
| KV | Circuit breakers, budgets, cache | Reads: $0.50/M, Writes: $5/M |
|
|
39
|
+
| Analytics Engine | High-cardinality metrics | Free tier generous |
|
|
40
|
+
|
|
41
|
+
### Budget Enforcement
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
Telemetry arrives → Check feature budget → Check project budget → Check global budget
|
|
45
|
+
│ │ │ │
|
|
46
|
+
│ 70% → Slack warn 90% → Slack critical 100% → CB trip
|
|
47
|
+
│ │
|
|
48
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
49
|
+
Write to D1 + Analytics Engine
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Worker Topology
|
|
53
|
+
|
|
54
|
+
### Minimal Tier
|
|
55
|
+
- **platform-usage**: Data warehouse, cron scheduler, queue consumer
|
|
56
|
+
|
|
57
|
+
### Standard Tier (adds)
|
|
58
|
+
- **error-collector**: Tail worker → error fingerprinting → GitHub issues
|
|
59
|
+
- **platform-sentinel**: Gap detection, cost monitoring
|
|
60
|
+
- **platform-mapper**: Infrastructure discovery, attribution
|
|
61
|
+
|
|
62
|
+
### Full Tier (adds)
|
|
63
|
+
- **pattern-discovery**: AI-assisted transient error pattern detection
|
|
64
|
+
- **platform-alert-router**: Unified alert normalisation
|
|
65
|
+
- **platform-notifications**: In-app notification API
|
|
66
|
+
- **platform-search**: Full-text search (FTS5)
|
|
67
|
+
- **platform-settings**: Settings management API
|
|
68
|
+
- **platform-auditor**: SDK integration auditor + AI Judge
|
|
69
|
+
|
|
70
|
+
## Dashboard Architecture
|
|
71
|
+
|
|
72
|
+
Astro SSR deployed on Cloudflare Pages with:
|
|
73
|
+
- Service bindings to backend workers
|
|
74
|
+
- D1/KV direct bindings for read-heavy pages
|
|
75
|
+
- CF Access for authentication
|
|
76
|
+
- React islands for interactive components
|
|
77
|
+
|
|
78
|
+
## Configuration
|
|
79
|
+
|
|
80
|
+
All configuration lives in Git and syncs to runtime:
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
platform/config/
|
|
84
|
+
├── services.yaml ← Project registry, feature IDs
|
|
85
|
+
├── budgets.yaml ← Limits, thresholds, CB config
|
|
86
|
+
└── observability.yaml ← Monitoring standards
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Sync via: `npm run sync:config` → D1 tables + KV keys
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# Post-Deploy Runbook
|
|
2
|
+
|
|
3
|
+
## After Initial Scaffold
|
|
4
|
+
|
|
5
|
+
### 1. Configure Cloudflare Resources
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Create D1 database
|
|
9
|
+
direnv exec . wrangler d1 create platform-metrics
|
|
10
|
+
|
|
11
|
+
# Update database IDs in all wrangler.*.jsonc files
|
|
12
|
+
# (use the ID returned from the create command)
|
|
13
|
+
|
|
14
|
+
# Run migrations
|
|
15
|
+
direnv exec . wrangler d1 migrations apply platform-metrics --remote
|
|
16
|
+
|
|
17
|
+
# Create KV namespace
|
|
18
|
+
direnv exec . wrangler kv namespace create PLATFORM_CACHE
|
|
19
|
+
# Update KV namespace IDs in wrangler configs
|
|
20
|
+
|
|
21
|
+
# Create telemetry queue
|
|
22
|
+
direnv exec . wrangler queues create platform-telemetry
|
|
23
|
+
direnv exec . wrangler queues create platform-telemetry-dlq
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 2. Sync Configuration
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Push services.yaml + budgets.yaml to D1/KV
|
|
30
|
+
npm run sync:config
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 3. Deploy Workers
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Deploy in order: usage first (it's the foundation)
|
|
37
|
+
npm run deploy:usage
|
|
38
|
+
|
|
39
|
+
# Standard tier: error collector + sentinel
|
|
40
|
+
direnv exec . wrangler deploy -c wrangler.*-error-collector.jsonc
|
|
41
|
+
direnv exec . wrangler deploy -c wrangler.*-sentinel.jsonc
|
|
42
|
+
|
|
43
|
+
# Full tier: remaining workers
|
|
44
|
+
direnv exec . wrangler deploy -c wrangler.*-pattern-discovery.jsonc
|
|
45
|
+
# ... etc
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 4. Deploy Dashboard
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
cd dashboard
|
|
52
|
+
npm install && npm run build
|
|
53
|
+
direnv exec . npx wrangler pages deploy dist
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 5. Verify
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# Check worker is responding
|
|
60
|
+
direnv exec . wrangler tail {worker-name} --format json
|
|
61
|
+
|
|
62
|
+
# Run validation
|
|
63
|
+
npm run validate:pipeline
|
|
64
|
+
npm run validate:controls
|
|
65
|
+
|
|
66
|
+
# Check dashboard loads
|
|
67
|
+
# https://your-dashboard-url.pages.dev
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## After Code Changes
|
|
71
|
+
|
|
72
|
+
### Worker Changes
|
|
73
|
+
|
|
74
|
+
1. Run tests: `npm test`
|
|
75
|
+
2. Run typecheck: `npm run typecheck`
|
|
76
|
+
3. Check D1 migrations: any new migrations need `wrangler d1 migrations apply`
|
|
77
|
+
4. Deploy affected worker(s)
|
|
78
|
+
5. Watch logs for 30 seconds: `direnv exec . wrangler tail {worker} --format json`
|
|
79
|
+
|
|
80
|
+
### Budget/Config Changes
|
|
81
|
+
|
|
82
|
+
1. Run `npm run validate:controls --strict`
|
|
83
|
+
2. Run `npm run sync:config`
|
|
84
|
+
3. Verify KV keys updated correctly
|
|
85
|
+
|
|
86
|
+
### Dashboard Changes
|
|
87
|
+
|
|
88
|
+
1. Build locally: `cd dashboard && npm run build`
|
|
89
|
+
2. Deploy: `direnv exec . npx wrangler pages deploy dist`
|
|
90
|
+
3. Verify pages load, API routes return data
|
|
91
|
+
|
|
92
|
+
## Backfill After Data Gaps
|
|
93
|
+
|
|
94
|
+
If usage collection missed data (e.g., worker was down):
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# 1. Backfill hourly data from Cloudflare GraphQL
|
|
98
|
+
npm run backfill -- --start 2026-01-01 --end 2026-01-31
|
|
99
|
+
|
|
100
|
+
# 2. Roll up to daily
|
|
101
|
+
npm run backfill:daily -- --start 2026-01-01 --end 2026-01-31
|
|
102
|
+
|
|
103
|
+
# 3. Roll up to monthly
|
|
104
|
+
npm run backfill:monthly -- --start 2026-01 --end 2026-01
|
|
105
|
+
|
|
106
|
+
# Always dry-run first:
|
|
107
|
+
npm run backfill:daily -- --dry-run --start 2026-01-01 --end 2026-01-31
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Emergency: Circuit Breaker Trip
|
|
111
|
+
|
|
112
|
+
If a circuit breaker trips unexpectedly:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# 1. Check what tripped
|
|
116
|
+
# Dashboard → Circuit Breakers page
|
|
117
|
+
|
|
118
|
+
# 2. Investigate root cause
|
|
119
|
+
direnv exec . wrangler tail {worker} --format json
|
|
120
|
+
|
|
121
|
+
# 3. If safe to reset
|
|
122
|
+
npm run reset-cb
|
|
123
|
+
|
|
124
|
+
# 4. Monitor after reset
|
|
125
|
+
direnv exec . wrangler tail {worker} --format json
|
|
126
|
+
```
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Troubleshooting Guide
|
|
2
|
+
|
|
3
|
+
## Common Issues
|
|
4
|
+
|
|
5
|
+
### Workers Not Deploying
|
|
6
|
+
|
|
7
|
+
**Symptom**: `wrangler deploy` fails or worker doesn't respond.
|
|
8
|
+
|
|
9
|
+
**Check**:
|
|
10
|
+
1. Verify wrangler config references correct `main` entry point
|
|
11
|
+
2. Check `compatibility_date` is recent
|
|
12
|
+
3. Ensure all D1 bindings use correct database IDs
|
|
13
|
+
4. Run `direnv exec . wrangler whoami` to verify credentials
|
|
14
|
+
|
|
15
|
+
### D1 Write Errors
|
|
16
|
+
|
|
17
|
+
**Symptom**: `D1_ERROR: too many requests` or budget circuit breaker trips.
|
|
18
|
+
|
|
19
|
+
**Fix**:
|
|
20
|
+
1. Check `budgets.yaml` — limits may be too low for current usage
|
|
21
|
+
2. Run `npm run validate:controls` to verify budget configuration
|
|
22
|
+
3. Check circuit breaker state: `cb:global`, `cb:project:{name}`, `cb:feature:{id}`
|
|
23
|
+
4. Reset with `npm run reset-cb` if needed
|
|
24
|
+
|
|
25
|
+
### Queue Messages Stuck in DLQ
|
|
26
|
+
|
|
27
|
+
**Symptom**: DLQ depth increasing, messages not processing.
|
|
28
|
+
|
|
29
|
+
**Check**:
|
|
30
|
+
1. View DLQ status in dashboard Health tab
|
|
31
|
+
2. Check queue consumer logs: `direnv exec . wrangler tail {worker-name}`
|
|
32
|
+
3. Common cause: malformed telemetry envelopes — validate with `npm run validate:schemas`
|
|
33
|
+
4. Retry DLQ messages via dashboard or API
|
|
34
|
+
|
|
35
|
+
### Dashboard Not Loading Data
|
|
36
|
+
|
|
37
|
+
**Symptom**: Dashboard shows empty states or loading spinners.
|
|
38
|
+
|
|
39
|
+
**Check**:
|
|
40
|
+
1. Verify D1 database has data: `direnv exec . wrangler d1 execute platform-metrics --command "SELECT COUNT(*) FROM hourly_usage_snapshots"`
|
|
41
|
+
2. Check KV cache: service registry may be stale
|
|
42
|
+
3. Run `npm run sync:config` to refresh D1/KV from YAML
|
|
43
|
+
4. Check CF Access — dashboard requires authentication
|
|
44
|
+
|
|
45
|
+
### Budget Warnings Not Firing
|
|
46
|
+
|
|
47
|
+
**Symptom**: Usage exceeds thresholds but no Slack alerts.
|
|
48
|
+
|
|
49
|
+
**Check**:
|
|
50
|
+
1. Verify `SLACK_WEBHOOK_URL` is set in wrangler config
|
|
51
|
+
2. Check KV dedup keys: `BUDGET_WARN:{feature}` (1hr TTL)
|
|
52
|
+
3. Ensure `budgets.yaml` has correct feature keys matching `services.yaml`
|
|
53
|
+
4. Run `npm run validate:controls --strict` for cross-reference check
|
|
54
|
+
|
|
55
|
+
### Backfill Scripts Failing
|
|
56
|
+
|
|
57
|
+
**Symptom**: `backfill:daily` or `backfill:monthly` errors.
|
|
58
|
+
|
|
59
|
+
**Check**:
|
|
60
|
+
1. Required env vars: `CLOUDFLARE_API_TOKEN`, `CLOUDFLARE_ACCOUNT_ID`, `D1_DATABASE_ID`
|
|
61
|
+
2. API token needs D1:Write permissions
|
|
62
|
+
3. Run with `--dry-run` first to verify date ranges
|
|
63
|
+
4. Rate limit: scripts include 200ms delay between queries
|
|
64
|
+
|
|
65
|
+
## Diagnostic Commands
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
# Check worker health
|
|
69
|
+
direnv exec . wrangler tail {worker-name} --format json
|
|
70
|
+
|
|
71
|
+
# Verify D1 schema
|
|
72
|
+
direnv exec . wrangler d1 migrations list platform-metrics --remote
|
|
73
|
+
|
|
74
|
+
# Test config sync
|
|
75
|
+
npm run sync:config -- --dry-run
|
|
76
|
+
|
|
77
|
+
# Validate all controls
|
|
78
|
+
npm run validate:controls --strict
|
|
79
|
+
|
|
80
|
+
# Run schema validation
|
|
81
|
+
npm run validate:schemas
|
|
82
|
+
|
|
83
|
+
# Check pipeline health
|
|
84
|
+
npm run validate:pipeline
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Getting Help
|
|
88
|
+
|
|
89
|
+
1. Check the [KV Key Patterns](./kv-key-patterns.md) doc for key prefix reference
|
|
90
|
+
2. Review circuit breaker states in the dashboard Circuit Breakers page
|
|
91
|
+
3. Run `npm test` to verify worker logic locally
|
|
@@ -6,7 +6,20 @@
|
|
|
6
6
|
"scripts": {
|
|
7
7
|
"typecheck": "tsc --noEmit",
|
|
8
8
|
"sync:config": "npx tsx scripts/sync-config.ts",
|
|
9
|
-
"deploy:usage": "wrangler deploy -c wrangler.{{projectSlug}}-usage.jsonc"
|
|
9
|
+
"deploy:usage": "wrangler deploy -c wrangler.{{projectSlug}}-usage.jsonc",
|
|
10
|
+
"backfill": "npx tsx scripts/ops/backfill-cloudflare-hourly.ts",
|
|
11
|
+
"backfill:daily": "npx tsx scripts/ops/backfill-cloudflare-daily.ts",
|
|
12
|
+
"backfill:monthly": "npx tsx scripts/ops/backfill-monthly-rollups.ts",
|
|
13
|
+
"validate:controls": "node scripts/ops/validate-controls.js",
|
|
14
|
+
"reset-cb": "npx tsx scripts/ops/reset-budget-state.ts",
|
|
15
|
+
"verify": "npx tsx scripts/ops/verify-account-completeness.ts",
|
|
16
|
+
"validate:pipeline": "npx tsx scripts/ops/validate-pipeline.ts",
|
|
17
|
+
"validate:schemas": "node scripts/validate-schemas.js",
|
|
18
|
+
"test": "vitest run",
|
|
19
|
+
"deploy:auditor": "wrangler deploy -c wrangler.{{projectSlug}}-auditor.jsonc",
|
|
20
|
+
"deploy:mapper": "wrangler deploy -c wrangler.{{projectSlug}}-mapper.jsonc",
|
|
21
|
+
"deploy:test-client": "wrangler deploy -c wrangler.{{projectSlug}}-sdk-test-client.jsonc",
|
|
22
|
+
"discover:datasets": "npx tsx scripts/ops/discover-graphql-datasets.ts"
|
|
10
23
|
},
|
|
11
24
|
"dependencies": {
|
|
12
25
|
"@littlebearapps/platform-consumer-sdk": "^{{sdkVersion}}",
|
|
@@ -14,8 +27,11 @@
|
|
|
14
27
|
},
|
|
15
28
|
"devDependencies": {
|
|
16
29
|
"@cloudflare/workers-types": "^4.20250214.0",
|
|
30
|
+
"ajv": "^8.17.0",
|
|
31
|
+
"ajv-formats": "^3.0.0",
|
|
17
32
|
"tsx": "^4.19.0",
|
|
18
33
|
"typescript": "^5.7.3",
|
|
34
|
+
"vitest": "^3.0.5",
|
|
19
35
|
"wrangler": "^3.100.0"
|
|
20
36
|
}
|
|
21
37
|
}
|