@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,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/wrangler/config-schema.json",
|
|
3
|
+
"name": "{{projectSlug}}-auditor",
|
|
4
|
+
"main": "workers/platform-auditor.ts",
|
|
5
|
+
"compatibility_date": "2026-01-01",
|
|
6
|
+
"compatibility_flags": ["nodejs_compat_v2"],
|
|
7
|
+
|
|
8
|
+
"observability": {
|
|
9
|
+
"enabled": true,
|
|
10
|
+
"logs": {
|
|
11
|
+
"enabled": true,
|
|
12
|
+
"sampling_rate": 1,
|
|
13
|
+
"invocation_logs": true
|
|
14
|
+
},
|
|
15
|
+
"traces": {
|
|
16
|
+
"enabled": true,
|
|
17
|
+
"head_sampling_rate": 0.1
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"upload_source_maps": true,
|
|
21
|
+
|
|
22
|
+
"triggers": {
|
|
23
|
+
"crons": [
|
|
24
|
+
"0 0 * * SUN",
|
|
25
|
+
"0 0 * * WED"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
"d1_databases": [
|
|
30
|
+
{
|
|
31
|
+
"binding": "PLATFORM_DB",
|
|
32
|
+
"database_name": "{{projectSlug}}-metrics",
|
|
33
|
+
"database_id": "YOUR_D1_DATABASE_ID",
|
|
34
|
+
"migrations_dir": "storage/d1/migrations"
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
|
|
38
|
+
"kv_namespaces": [
|
|
39
|
+
{
|
|
40
|
+
"binding": "PLATFORM_CACHE",
|
|
41
|
+
"id": "YOUR_KV_NAMESPACE_ID"
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
|
|
45
|
+
"queues": {
|
|
46
|
+
"producers": [
|
|
47
|
+
{
|
|
48
|
+
"binding": "PLATFORM_TELEMETRY",
|
|
49
|
+
"queue": "{{projectSlug}}-telemetry"
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
"services": [
|
|
55
|
+
{
|
|
56
|
+
"binding": "ALERT_ROUTER",
|
|
57
|
+
"service": "{{projectSlug}}-alert-router"
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
|
|
61
|
+
"ai": {
|
|
62
|
+
"binding": "AI"
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
"vars": {
|
|
66
|
+
"CLOUDFLARE_ACCOUNT_ID": "YOUR_ACCOUNT_ID",
|
|
67
|
+
"GATUS_HEARTBEAT_URL": ""
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
"tail_consumers": [
|
|
71
|
+
{
|
|
72
|
+
"service": "{{projectSlug}}-error-collector"
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Contract Schema Validation
|
|
2
|
+
#
|
|
3
|
+
# Validates JSON schemas and TypeScript types match expected contracts.
|
|
4
|
+
# Runs schema validation against fixture data.
|
|
5
|
+
#
|
|
6
|
+
# Checks performed:
|
|
7
|
+
# - JSON schema validation (envelope, error_report)
|
|
8
|
+
# - TypeScript type compilation
|
|
9
|
+
# - Contract fixture validation
|
|
10
|
+
|
|
11
|
+
name: Contract Check
|
|
12
|
+
|
|
13
|
+
on:
|
|
14
|
+
push:
|
|
15
|
+
branches: [main]
|
|
16
|
+
paths:
|
|
17
|
+
- 'contracts/**'
|
|
18
|
+
- 'tests/contract/**'
|
|
19
|
+
pull_request:
|
|
20
|
+
branches: [main]
|
|
21
|
+
paths:
|
|
22
|
+
- 'contracts/**'
|
|
23
|
+
- 'tests/contract/**'
|
|
24
|
+
|
|
25
|
+
jobs:
|
|
26
|
+
validate:
|
|
27
|
+
runs-on: ubuntu-latest
|
|
28
|
+
steps:
|
|
29
|
+
- uses: actions/checkout@v4
|
|
30
|
+
|
|
31
|
+
- uses: actions/setup-node@v4
|
|
32
|
+
with:
|
|
33
|
+
node-version: '22'
|
|
34
|
+
cache: 'npm'
|
|
35
|
+
|
|
36
|
+
- run: npm ci
|
|
37
|
+
|
|
38
|
+
- name: Validate schemas
|
|
39
|
+
run: npm run validate:schemas
|
|
40
|
+
|
|
41
|
+
- name: Run contract tests
|
|
42
|
+
run: npx vitest run tests/contract/
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
name: Deploy Dashboard
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
paths:
|
|
7
|
+
- 'dashboard/**'
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
deploy:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
deployments: write
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- uses: actions/setup-node@v4
|
|
20
|
+
with:
|
|
21
|
+
node-version: 20
|
|
22
|
+
cache: npm
|
|
23
|
+
cache-dependency-path: dashboard/package-lock.json
|
|
24
|
+
|
|
25
|
+
- name: Install dependencies
|
|
26
|
+
working-directory: dashboard
|
|
27
|
+
run: npm ci
|
|
28
|
+
|
|
29
|
+
- name: Build
|
|
30
|
+
working-directory: dashboard
|
|
31
|
+
run: npm run build
|
|
32
|
+
|
|
33
|
+
- name: Deploy to Cloudflare Pages
|
|
34
|
+
uses: cloudflare/wrangler-action@v3
|
|
35
|
+
with:
|
|
36
|
+
apiToken: $\{{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
37
|
+
accountId: $\{{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
38
|
+
command: pages deploy dist --project-name={{projectSlug}}-dashboard
|
|
39
|
+
workingDirectory: dashboard
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Platform SDK Integration Check
|
|
2
|
+
#
|
|
3
|
+
# Validates Platform SDK usage, wrangler configs, and cost safety patterns.
|
|
4
|
+
# Uses the reusable workflow from the Platform SDKs repository.
|
|
5
|
+
#
|
|
6
|
+
# Checks performed:
|
|
7
|
+
# - SDK installation and version
|
|
8
|
+
# - Wrangler configs (PLATFORM_CACHE, telemetry queue, observability, tail_consumers)
|
|
9
|
+
# - Budget wrappers (withFeatureBudget, withCronBudget, withQueueBudget)
|
|
10
|
+
# - Feature ID format (project:category:feature)
|
|
11
|
+
# - CircuitBreakerError handling
|
|
12
|
+
# - Cost safety (D1 batch writes, ON CONFLICT, SELECT LIMIT, no SQL injection)
|
|
13
|
+
#
|
|
14
|
+
# See: https://github.com/littlebearapps/platform-sdks
|
|
15
|
+
|
|
16
|
+
name: Platform SDK Check
|
|
17
|
+
|
|
18
|
+
on:
|
|
19
|
+
push:
|
|
20
|
+
branches: [main]
|
|
21
|
+
pull_request:
|
|
22
|
+
branches: [main]
|
|
23
|
+
|
|
24
|
+
jobs:
|
|
25
|
+
sdk-check:
|
|
26
|
+
uses: littlebearapps/platform-sdks/.github/workflows/consumer-check.yml@main
|
|
27
|
+
with:
|
|
28
|
+
project-name: {{projectSlug}}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Security Scanning
|
|
2
|
+
#
|
|
3
|
+
# Runs dependency audit and secret detection on pushes and PRs.
|
|
4
|
+
|
|
5
|
+
name: Security
|
|
6
|
+
|
|
7
|
+
on:
|
|
8
|
+
push:
|
|
9
|
+
branches: [main]
|
|
10
|
+
pull_request:
|
|
11
|
+
branches: [main]
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
audit:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- uses: actions/setup-node@v4
|
|
20
|
+
with:
|
|
21
|
+
node-version: '22'
|
|
22
|
+
cache: 'npm'
|
|
23
|
+
|
|
24
|
+
- run: npm ci
|
|
25
|
+
|
|
26
|
+
- name: Audit dependencies
|
|
27
|
+
run: npm audit --audit-level=high
|
|
28
|
+
continue-on-error: true
|
|
29
|
+
|
|
30
|
+
- name: Check for secrets
|
|
31
|
+
uses: trufflesecurity/trufflehog@main
|
|
32
|
+
with:
|
|
33
|
+
extra_args: --only-verified
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
# Observability Configuration
|
|
2
|
+
#
|
|
3
|
+
# Single Source of Truth for Workers observability standards.
|
|
4
|
+
# Defines sampling rates, logging patterns, and audit criteria.
|
|
5
|
+
#
|
|
6
|
+
# Used by:
|
|
7
|
+
# - platform-auditor: Reference standard for audits (Full tier)
|
|
8
|
+
# - AI Judge: Audit checklist and scoring rubrics (Full tier)
|
|
9
|
+
# - Developers: Reference for wrangler config settings
|
|
10
|
+
#
|
|
11
|
+
# Version: 1.0.0
|
|
12
|
+
|
|
13
|
+
metadata:
|
|
14
|
+
version: "1.0.0"
|
|
15
|
+
lastUpdated: "{{currentDate}}"
|
|
16
|
+
linkedRegistry: "./services.yaml"
|
|
17
|
+
|
|
18
|
+
# ============================================================
|
|
19
|
+
# GLOBAL STANDARDS (Required for ALL workers)
|
|
20
|
+
# ============================================================
|
|
21
|
+
# These settings must be present in every wrangler config
|
|
22
|
+
# ============================================================
|
|
23
|
+
|
|
24
|
+
standards:
|
|
25
|
+
# Source maps - ALWAYS required for readable stack traces
|
|
26
|
+
source_maps:
|
|
27
|
+
required: true
|
|
28
|
+
setting: "upload_source_maps"
|
|
29
|
+
value: true
|
|
30
|
+
severity: critical
|
|
31
|
+
rationale: "Essential for debugging production errors"
|
|
32
|
+
|
|
33
|
+
# Observability block - ALWAYS required
|
|
34
|
+
observability:
|
|
35
|
+
required: true
|
|
36
|
+
setting: "observability.enabled"
|
|
37
|
+
value: true
|
|
38
|
+
severity: critical
|
|
39
|
+
rationale: "Base requirement for all logging and tracing"
|
|
40
|
+
|
|
41
|
+
# Logs - ALWAYS required
|
|
42
|
+
logs:
|
|
43
|
+
required: true
|
|
44
|
+
settings:
|
|
45
|
+
enabled: true
|
|
46
|
+
invocation_logs: true
|
|
47
|
+
severity: critical
|
|
48
|
+
rationale: "Essential for debugging and monitoring"
|
|
49
|
+
|
|
50
|
+
# Traces - Recommended (beta but valuable)
|
|
51
|
+
traces:
|
|
52
|
+
required: false
|
|
53
|
+
recommended: true
|
|
54
|
+
settings:
|
|
55
|
+
enabled: true
|
|
56
|
+
severity: high
|
|
57
|
+
rationale: "Automatic instrumentation for performance debugging"
|
|
58
|
+
|
|
59
|
+
# ============================================================
|
|
60
|
+
# SAMPLING RATE PROFILES
|
|
61
|
+
# ============================================================
|
|
62
|
+
# Profiles based on worker characteristics.
|
|
63
|
+
# Assign a profile to each worker in the projects section below.
|
|
64
|
+
# ============================================================
|
|
65
|
+
|
|
66
|
+
sampling_profiles:
|
|
67
|
+
# Critical path workers (auth, payments, etc.)
|
|
68
|
+
critical:
|
|
69
|
+
logs:
|
|
70
|
+
head_sampling_rate: 1.0 # 100% - never miss errors
|
|
71
|
+
traces:
|
|
72
|
+
head_sampling_rate: 0.5 # 50% - high visibility
|
|
73
|
+
applies_to:
|
|
74
|
+
- "workers with auth responsibilities"
|
|
75
|
+
- "workers handling payments"
|
|
76
|
+
- "workers with revenue impact"
|
|
77
|
+
|
|
78
|
+
# Low traffic workers (<1K requests/day)
|
|
79
|
+
low_traffic:
|
|
80
|
+
logs:
|
|
81
|
+
head_sampling_rate: 1.0 # 100%
|
|
82
|
+
traces:
|
|
83
|
+
head_sampling_rate: 1.0 # 100%
|
|
84
|
+
applies_to:
|
|
85
|
+
- "scheduled/cron workers"
|
|
86
|
+
- "admin/internal tools"
|
|
87
|
+
- "audit workers"
|
|
88
|
+
|
|
89
|
+
# Medium traffic workers (1K-100K requests/day)
|
|
90
|
+
medium_traffic:
|
|
91
|
+
logs:
|
|
92
|
+
head_sampling_rate: 0.5 # 50%
|
|
93
|
+
traces:
|
|
94
|
+
head_sampling_rate: 0.1 # 10%
|
|
95
|
+
applies_to:
|
|
96
|
+
- "API endpoints with moderate traffic"
|
|
97
|
+
- "dashboard workers"
|
|
98
|
+
|
|
99
|
+
# High traffic workers (>100K requests/day)
|
|
100
|
+
high_traffic:
|
|
101
|
+
logs:
|
|
102
|
+
head_sampling_rate: 0.1 # 10%
|
|
103
|
+
traces:
|
|
104
|
+
head_sampling_rate: 0.05 # 5%
|
|
105
|
+
applies_to:
|
|
106
|
+
- "public API endpoints"
|
|
107
|
+
- "high-volume queue consumers"
|
|
108
|
+
|
|
109
|
+
# Staging/Development (always full visibility)
|
|
110
|
+
staging:
|
|
111
|
+
logs:
|
|
112
|
+
head_sampling_rate: 1.0 # 100%
|
|
113
|
+
traces:
|
|
114
|
+
head_sampling_rate: 1.0 # 100%
|
|
115
|
+
applies_to:
|
|
116
|
+
- "any worker in staging environment"
|
|
117
|
+
- "test workers"
|
|
118
|
+
|
|
119
|
+
# ============================================================
|
|
120
|
+
# PROJECT OBSERVABILITY SETTINGS
|
|
121
|
+
# ============================================================
|
|
122
|
+
|
|
123
|
+
projects:
|
|
124
|
+
{{projectSlug}}:
|
|
125
|
+
status: pending # Update to 'compliant' after verification
|
|
126
|
+
profile: low_traffic
|
|
127
|
+
workers:
|
|
128
|
+
{{projectSlug}}-usage:
|
|
129
|
+
profile: medium_traffic
|
|
130
|
+
sampling:
|
|
131
|
+
logs: { head_sampling_rate: 1.0 }
|
|
132
|
+
traces: { head_sampling_rate: 0.1 }
|
|
133
|
+
notes: "Central data warehouse — full logging essential"
|
|
134
|
+
|
|
135
|
+
{{#if isStandard}}
|
|
136
|
+
{{projectSlug}}-error-collector:
|
|
137
|
+
profile: low_traffic
|
|
138
|
+
sampling:
|
|
139
|
+
logs: { head_sampling_rate: 1.0 }
|
|
140
|
+
traces: { head_sampling_rate: 0.5 }
|
|
141
|
+
notes: "Tail worker — captures all error outcomes"
|
|
142
|
+
|
|
143
|
+
{{projectSlug}}-sentinel:
|
|
144
|
+
profile: low_traffic
|
|
145
|
+
sampling:
|
|
146
|
+
logs: { head_sampling_rate: 1.0 }
|
|
147
|
+
traces: { head_sampling_rate: 0.5 }
|
|
148
|
+
notes: "Gap detection and cost monitoring"
|
|
149
|
+
|
|
150
|
+
{{projectSlug}}-mapper:
|
|
151
|
+
profile: low_traffic
|
|
152
|
+
sampling:
|
|
153
|
+
logs: { head_sampling_rate: 1.0 }
|
|
154
|
+
traces: { head_sampling_rate: 0.5 }
|
|
155
|
+
notes: "Resource topology mapping"
|
|
156
|
+
|
|
157
|
+
{{projectSlug}}-sdk-test-client:
|
|
158
|
+
profile: staging
|
|
159
|
+
optional: true
|
|
160
|
+
notes: "SDK validation — on-demand only"
|
|
161
|
+
{{/if}}
|
|
162
|
+
|
|
163
|
+
{{#if isFull}}
|
|
164
|
+
{{projectSlug}}-pattern-discovery:
|
|
165
|
+
profile: low_traffic
|
|
166
|
+
sampling:
|
|
167
|
+
logs: { head_sampling_rate: 1.0 }
|
|
168
|
+
traces: { head_sampling_rate: 1.0 }
|
|
169
|
+
notes: "Daily AI discovery cron — full visibility"
|
|
170
|
+
|
|
171
|
+
{{projectSlug}}-alert-router:
|
|
172
|
+
profile: critical
|
|
173
|
+
sampling:
|
|
174
|
+
logs: { head_sampling_rate: 1.0 }
|
|
175
|
+
traces: { head_sampling_rate: 0.5 }
|
|
176
|
+
notes: "Critical — routes all alerts"
|
|
177
|
+
|
|
178
|
+
{{projectSlug}}-auditor:
|
|
179
|
+
profile: low_traffic
|
|
180
|
+
sampling:
|
|
181
|
+
logs: { head_sampling_rate: 1.0 }
|
|
182
|
+
traces: { head_sampling_rate: 1.0 }
|
|
183
|
+
notes: "Weekly cron — full visibility always"
|
|
184
|
+
{{/if}}
|
|
185
|
+
|
|
186
|
+
# ============================================================
|
|
187
|
+
# STRUCTURED LOGGING SCHEMA
|
|
188
|
+
# ============================================================
|
|
189
|
+
# Standard fields for console.log() JSON objects.
|
|
190
|
+
# Use the Platform SDK createLogger() for automatic formatting.
|
|
191
|
+
# ============================================================
|
|
192
|
+
|
|
193
|
+
logging_schema:
|
|
194
|
+
required_fields:
|
|
195
|
+
- name: event
|
|
196
|
+
type: string
|
|
197
|
+
description: "Event type (e.g., 'api_request', 'db_query', 'error')"
|
|
198
|
+
|
|
199
|
+
recommended_fields:
|
|
200
|
+
- name: requestId
|
|
201
|
+
type: string
|
|
202
|
+
description: "CF ray ID or custom request ID"
|
|
203
|
+
source: "request.headers.get('cf-ray')"
|
|
204
|
+
|
|
205
|
+
- name: projectId
|
|
206
|
+
type: string
|
|
207
|
+
description: "Project identifier"
|
|
208
|
+
|
|
209
|
+
- name: featureId
|
|
210
|
+
type: string
|
|
211
|
+
description: "Feature being used (matches services.yaml)"
|
|
212
|
+
|
|
213
|
+
- name: durationMs
|
|
214
|
+
type: number
|
|
215
|
+
description: "Operation duration in milliseconds"
|
|
216
|
+
|
|
217
|
+
error_fields:
|
|
218
|
+
- name: error.message
|
|
219
|
+
type: string
|
|
220
|
+
required: true
|
|
221
|
+
|
|
222
|
+
- name: error.name
|
|
223
|
+
type: string
|
|
224
|
+
required: true
|
|
225
|
+
|
|
226
|
+
- name: error.stack
|
|
227
|
+
type: string
|
|
228
|
+
required: false
|
|
229
|
+
|
|
230
|
+
# ============================================================
|
|
231
|
+
# AUDIT CHECKLIST
|
|
232
|
+
# ============================================================
|
|
233
|
+
# Items verified by AI Judge for observability audits (Full tier).
|
|
234
|
+
# Severity: critical (must fix), high (should fix), medium (nice to have)
|
|
235
|
+
# ============================================================
|
|
236
|
+
|
|
237
|
+
audit_checklist:
|
|
238
|
+
- id: source_maps_enabled
|
|
239
|
+
check: "upload_source_maps === true"
|
|
240
|
+
severity: critical
|
|
241
|
+
message: "Source maps must be enabled for readable stack traces"
|
|
242
|
+
|
|
243
|
+
- id: observability_enabled
|
|
244
|
+
check: "observability.enabled === true"
|
|
245
|
+
severity: critical
|
|
246
|
+
message: "Observability must be enabled"
|
|
247
|
+
|
|
248
|
+
- id: logs_enabled
|
|
249
|
+
check: "observability.logs.enabled === true"
|
|
250
|
+
severity: critical
|
|
251
|
+
message: "Logs must be enabled"
|
|
252
|
+
|
|
253
|
+
- id: traces_enabled
|
|
254
|
+
check: "observability.traces.enabled === true"
|
|
255
|
+
severity: high
|
|
256
|
+
message: "Traces should be enabled for automatic instrumentation"
|
|
257
|
+
|
|
258
|
+
- id: sampling_rate_appropriate
|
|
259
|
+
check: "sampling rate matches traffic profile"
|
|
260
|
+
severity: medium
|
|
261
|
+
message: "Sampling rate should match worker traffic level"
|
|
262
|
+
|
|
263
|
+
- id: structured_logging_used
|
|
264
|
+
check: "console.log uses JSON objects, not string interpolation"
|
|
265
|
+
severity: medium
|
|
266
|
+
message: "Use structured JSON logging for queryability"
|
|
267
|
+
|
|
268
|
+
- id: error_context_included
|
|
269
|
+
check: "error logs include requestId and relevant context"
|
|
270
|
+
severity: medium
|
|
271
|
+
message: "Error logs should include request context for debugging"
|
|
272
|
+
|
|
273
|
+
- id: invocation_logs_enabled
|
|
274
|
+
check: "observability.logs.invocation_logs !== false"
|
|
275
|
+
severity: low
|
|
276
|
+
message: "Invocation logs provide request/response metadata"
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "envelope.v1.schema.json",
|
|
4
|
+
"title": "Telemetry Message Envelope v1",
|
|
5
|
+
"description": "Standard envelope for Platform SDK telemetry messages sent via queue",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["feature_key", "project", "category", "feature", "metrics", "timestamp"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"feature_key": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "Fully qualified feature key (project:category:feature)",
|
|
12
|
+
"pattern": "^[a-zA-Z0-9_-]+:[a-zA-Z0-9_-]+:[a-zA-Z0-9_-]+$"
|
|
13
|
+
},
|
|
14
|
+
"project": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"description": "Project identifier",
|
|
17
|
+
"minLength": 1
|
|
18
|
+
},
|
|
19
|
+
"category": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"description": "Feature category within the project",
|
|
22
|
+
"minLength": 1
|
|
23
|
+
},
|
|
24
|
+
"feature": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"description": "Feature name within the category",
|
|
27
|
+
"minLength": 1
|
|
28
|
+
},
|
|
29
|
+
"metrics": {
|
|
30
|
+
"type": "object",
|
|
31
|
+
"description": "Feature metrics payload (FeatureMetrics type from consumer SDK)",
|
|
32
|
+
"properties": {
|
|
33
|
+
"d1Writes": { "type": "number", "minimum": 0 },
|
|
34
|
+
"d1Reads": { "type": "number", "minimum": 0 },
|
|
35
|
+
"d1RowsRead": { "type": "number", "minimum": 0 },
|
|
36
|
+
"d1RowsWritten": { "type": "number", "minimum": 0 },
|
|
37
|
+
"kvReads": { "type": "number", "minimum": 0 },
|
|
38
|
+
"kvWrites": { "type": "number", "minimum": 0 },
|
|
39
|
+
"kvDeletes": { "type": "number", "minimum": 0 },
|
|
40
|
+
"kvLists": { "type": "number", "minimum": 0 },
|
|
41
|
+
"aiRequests": { "type": "number", "minimum": 0 },
|
|
42
|
+
"aiNeurons": { "type": "number", "minimum": 0 },
|
|
43
|
+
"vectorizeQueries": { "type": "number", "minimum": 0 },
|
|
44
|
+
"vectorizeInserts": { "type": "number", "minimum": 0 },
|
|
45
|
+
"doRequests": { "type": "number", "minimum": 0 },
|
|
46
|
+
"doGbSeconds": { "type": "number", "minimum": 0 },
|
|
47
|
+
"r2ClassA": { "type": "number", "minimum": 0 },
|
|
48
|
+
"r2ClassB": { "type": "number", "minimum": 0 },
|
|
49
|
+
"queueMessages": { "type": "number", "minimum": 0 },
|
|
50
|
+
"requests": { "type": "number", "minimum": 0 },
|
|
51
|
+
"cpuMs": { "type": "number", "minimum": 0 }
|
|
52
|
+
},
|
|
53
|
+
"additionalProperties": false
|
|
54
|
+
},
|
|
55
|
+
"timestamp": {
|
|
56
|
+
"type": "number",
|
|
57
|
+
"description": "Unix timestamp in milliseconds when the event occurred"
|
|
58
|
+
},
|
|
59
|
+
"is_heartbeat": {
|
|
60
|
+
"type": "boolean",
|
|
61
|
+
"description": "If true, this is a heartbeat message (no metrics, just liveness)"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "error_report.v1.schema.json",
|
|
4
|
+
"title": "Error Report v1",
|
|
5
|
+
"description": "Error report captured by the error-collector tail worker",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["script_name", "fingerprint", "message"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"script_name": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "Name of the worker that produced the error",
|
|
12
|
+
"minLength": 1
|
|
13
|
+
},
|
|
14
|
+
"fingerprint": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"description": "Unique error identifier for deduplication (SHA-256 hash of normalised message + script)",
|
|
17
|
+
"minLength": 1
|
|
18
|
+
},
|
|
19
|
+
"message": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"description": "Error message text",
|
|
22
|
+
"minLength": 1
|
|
23
|
+
},
|
|
24
|
+
"stack_trace": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"description": "Full stack trace if available"
|
|
27
|
+
},
|
|
28
|
+
"outcome": {
|
|
29
|
+
"type": "string",
|
|
30
|
+
"description": "Worker outcome type",
|
|
31
|
+
"enum": [
|
|
32
|
+
"exception",
|
|
33
|
+
"exceededCpu",
|
|
34
|
+
"exceededMemory",
|
|
35
|
+
"canceled",
|
|
36
|
+
"responseStreamDisconnected",
|
|
37
|
+
"scriptNotFound",
|
|
38
|
+
"soft_error",
|
|
39
|
+
"warning"
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
"priority": {
|
|
43
|
+
"type": "string",
|
|
44
|
+
"description": "Assigned priority level",
|
|
45
|
+
"enum": ["P0", "P1", "P2", "P3", "P4"]
|
|
46
|
+
},
|
|
47
|
+
"category": {
|
|
48
|
+
"type": "string",
|
|
49
|
+
"description": "Error category (e.g., unhandled-exception, quota-exhausted, rate-limited)"
|
|
50
|
+
},
|
|
51
|
+
"project": {
|
|
52
|
+
"type": "string",
|
|
53
|
+
"description": "Project the error belongs to (resolved from SCRIPT_MAP KV)"
|
|
54
|
+
},
|
|
55
|
+
"timestamp": {
|
|
56
|
+
"type": "string",
|
|
57
|
+
"format": "date-time",
|
|
58
|
+
"description": "When the error occurred (ISO 8601 UTC)"
|
|
59
|
+
},
|
|
60
|
+
"event_timestamp": {
|
|
61
|
+
"type": "number",
|
|
62
|
+
"description": "Unix timestamp in milliseconds from the tail event"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|