@littlebearapps/platform-admin-sdk 1.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/README.md +112 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +89 -0
- package/dist/prompts.d.ts +27 -0
- package/dist/prompts.js +80 -0
- package/dist/scaffold.d.ts +5 -0
- package/dist/scaffold.js +65 -0
- package/dist/templates.d.ts +16 -0
- package/dist/templates.js +131 -0
- package/package.json +46 -0
- package/templates/full/migrations/006_pattern_discovery.sql +199 -0
- package/templates/full/migrations/007_notifications_search.sql +127 -0
- package/templates/full/workers/lib/pattern-discovery/ai-prompt.ts +644 -0
- package/templates/full/workers/lib/pattern-discovery/clustering.ts +278 -0
- package/templates/full/workers/lib/pattern-discovery/shadow-evaluation.ts +603 -0
- package/templates/full/workers/lib/pattern-discovery/storage.ts +806 -0
- package/templates/full/workers/lib/pattern-discovery/types.ts +159 -0
- package/templates/full/workers/lib/pattern-discovery/validation.ts +278 -0
- package/templates/full/workers/pattern-discovery.ts +661 -0
- package/templates/full/workers/platform-alert-router.ts +1809 -0
- package/templates/full/workers/platform-notifications.ts +424 -0
- package/templates/full/workers/platform-search.ts +480 -0
- package/templates/full/workers/platform-settings.ts +436 -0
- package/templates/full/wrangler.alert-router.jsonc.hbs +34 -0
- package/templates/full/wrangler.notifications.jsonc.hbs +23 -0
- package/templates/full/wrangler.pattern-discovery.jsonc.hbs +33 -0
- package/templates/full/wrangler.search.jsonc.hbs +16 -0
- package/templates/full/wrangler.settings.jsonc.hbs +23 -0
- package/templates/shared/README.md.hbs +69 -0
- package/templates/shared/config/budgets.yaml.hbs +72 -0
- package/templates/shared/config/services.yaml.hbs +45 -0
- package/templates/shared/migrations/001_core_tables.sql +117 -0
- package/templates/shared/migrations/002_usage_warehouse.sql +830 -0
- package/templates/shared/migrations/003_feature_tracking.sql +250 -0
- package/templates/shared/migrations/004_settings_alerts.sql +452 -0
- package/templates/shared/migrations/seed.sql.hbs +4 -0
- package/templates/shared/package.json.hbs +21 -0
- package/templates/shared/scripts/sync-config.ts +242 -0
- package/templates/shared/tsconfig.json +12 -0
- package/templates/shared/workers/lib/analytics-engine.ts +357 -0
- package/templates/shared/workers/lib/billing.ts +293 -0
- package/templates/shared/workers/lib/circuit-breaker-middleware.ts +25 -0
- package/templates/shared/workers/lib/control.ts +292 -0
- package/templates/shared/workers/lib/economics.ts +368 -0
- package/templates/shared/workers/lib/metrics.ts +103 -0
- package/templates/shared/workers/lib/platform-settings.ts +407 -0
- package/templates/shared/workers/lib/shared/allowances.ts +333 -0
- package/templates/shared/workers/lib/shared/cloudflare.ts +1362 -0
- package/templates/shared/workers/lib/shared/types.ts +58 -0
- package/templates/shared/workers/lib/telemetry-sampling.ts +360 -0
- package/templates/shared/workers/lib/usage/collectors/example.ts +96 -0
- package/templates/shared/workers/lib/usage/collectors/index.ts +128 -0
- package/templates/shared/workers/lib/usage/handlers/audit.ts +306 -0
- package/templates/shared/workers/lib/usage/handlers/backfill.ts +845 -0
- package/templates/shared/workers/lib/usage/handlers/behavioral.ts +429 -0
- package/templates/shared/workers/lib/usage/handlers/data-queries.ts +507 -0
- package/templates/shared/workers/lib/usage/handlers/dlq-admin.ts +364 -0
- package/templates/shared/workers/lib/usage/handlers/health-trends.ts +222 -0
- package/templates/shared/workers/lib/usage/handlers/index.ts +35 -0
- package/templates/shared/workers/lib/usage/handlers/usage-admin.ts +421 -0
- package/templates/shared/workers/lib/usage/handlers/usage-features.ts +1262 -0
- package/templates/shared/workers/lib/usage/handlers/usage-metrics.ts +2420 -0
- package/templates/shared/workers/lib/usage/handlers/usage-settings.ts +610 -0
- package/templates/shared/workers/lib/usage/queue/budget-enforcement.ts +1032 -0
- package/templates/shared/workers/lib/usage/queue/cost-budget-enforcement.ts +128 -0
- package/templates/shared/workers/lib/usage/queue/cost-calculator.ts +77 -0
- package/templates/shared/workers/lib/usage/queue/dlq-handler.ts +161 -0
- package/templates/shared/workers/lib/usage/queue/index.ts +19 -0
- package/templates/shared/workers/lib/usage/queue/telemetry-processor.ts +790 -0
- package/templates/shared/workers/lib/usage/scheduled/anomaly-detection.ts +732 -0
- package/templates/shared/workers/lib/usage/scheduled/data-collection.ts +956 -0
- package/templates/shared/workers/lib/usage/scheduled/error-digest.ts +343 -0
- package/templates/shared/workers/lib/usage/scheduled/index.ts +18 -0
- package/templates/shared/workers/lib/usage/scheduled/rollups.ts +1561 -0
- package/templates/shared/workers/lib/usage/shared/constants.ts +362 -0
- package/templates/shared/workers/lib/usage/shared/index.ts +14 -0
- package/templates/shared/workers/lib/usage/shared/types.ts +1066 -0
- package/templates/shared/workers/lib/usage/shared/utils.ts +795 -0
- package/templates/shared/workers/platform-usage.ts +1915 -0
- package/templates/shared/wrangler.usage.jsonc.hbs +58 -0
- package/templates/standard/migrations/005_error_collection.sql +162 -0
- package/templates/standard/workers/error-collector.ts +2670 -0
- package/templates/standard/workers/lib/error-collector/capture.ts +213 -0
- package/templates/standard/workers/lib/error-collector/digest.ts +448 -0
- package/templates/standard/workers/lib/error-collector/email-health-alerts.ts +262 -0
- package/templates/standard/workers/lib/error-collector/fingerprint.ts +258 -0
- package/templates/standard/workers/lib/error-collector/gap-alerts.ts +293 -0
- package/templates/standard/workers/lib/error-collector/github.ts +329 -0
- package/templates/standard/workers/lib/error-collector/types.ts +262 -0
- package/templates/standard/workers/lib/sentinel/gap-detection.ts +734 -0
- package/templates/standard/workers/lib/shared/slack-alerts.ts +585 -0
- package/templates/standard/workers/platform-sentinel.ts +1744 -0
- package/templates/standard/wrangler.error-collector.jsonc.hbs +44 -0
- package/templates/standard/wrangler.sentinel.jsonc.hbs +45 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Collector Types
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Cloudflare Tail Event types (from Cloudflare docs)
|
|
6
|
+
export type TailOutcome =
|
|
7
|
+
| 'ok'
|
|
8
|
+
| 'exception'
|
|
9
|
+
| 'exceededCpu'
|
|
10
|
+
| 'exceededMemory'
|
|
11
|
+
| 'canceled'
|
|
12
|
+
| 'scriptNotFound'
|
|
13
|
+
| 'responseStreamDisconnected';
|
|
14
|
+
|
|
15
|
+
export interface TailLog {
|
|
16
|
+
level: 'log' | 'warn' | 'error' | 'debug' | 'info';
|
|
17
|
+
message: unknown[];
|
|
18
|
+
timestamp: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface TailException {
|
|
22
|
+
name: string;
|
|
23
|
+
message: string;
|
|
24
|
+
timestamp: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface TailDiagnosticEvent {
|
|
28
|
+
channel: string;
|
|
29
|
+
message: unknown;
|
|
30
|
+
timestamp: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface TailEvent {
|
|
34
|
+
scriptName: string;
|
|
35
|
+
outcome: TailOutcome;
|
|
36
|
+
eventTimestamp: number;
|
|
37
|
+
cpuTime?: number;
|
|
38
|
+
wallTime?: number;
|
|
39
|
+
// Script version for identifying deployment
|
|
40
|
+
scriptVersion?: {
|
|
41
|
+
id?: string;
|
|
42
|
+
tag?: string;
|
|
43
|
+
message?: string;
|
|
44
|
+
};
|
|
45
|
+
// Event type: fetch, scheduled, queue, alarm, email, etc.
|
|
46
|
+
eventType?: string;
|
|
47
|
+
// Execution model: stateless, durableObject
|
|
48
|
+
executionModel?: string;
|
|
49
|
+
event?: {
|
|
50
|
+
request?: {
|
|
51
|
+
url: string;
|
|
52
|
+
method: string;
|
|
53
|
+
headers: Record<string, string>;
|
|
54
|
+
cf?: {
|
|
55
|
+
colo?: string;
|
|
56
|
+
country?: string;
|
|
57
|
+
city?: string;
|
|
58
|
+
region?: string;
|
|
59
|
+
regionCode?: string;
|
|
60
|
+
continent?: string;
|
|
61
|
+
timezone?: string;
|
|
62
|
+
httpProtocol?: string;
|
|
63
|
+
asn?: number;
|
|
64
|
+
asOrganization?: string;
|
|
65
|
+
[key: string]: unknown;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
response?: {
|
|
69
|
+
status?: number;
|
|
70
|
+
};
|
|
71
|
+
// Queue event context
|
|
72
|
+
queue?: string;
|
|
73
|
+
batchSize?: number;
|
|
74
|
+
// Scheduled event context
|
|
75
|
+
scheduledTime?: number;
|
|
76
|
+
cron?: string;
|
|
77
|
+
// Ray ID for request tracing
|
|
78
|
+
rayId?: string;
|
|
79
|
+
};
|
|
80
|
+
logs: TailLog[];
|
|
81
|
+
exceptions: TailException[];
|
|
82
|
+
diagnosticsChannelEvents?: TailDiagnosticEvent[];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Error Collector types
|
|
86
|
+
export type ErrorType = 'exception' | 'cpu_limit' | 'memory_limit' | 'soft_error' | 'warning';
|
|
87
|
+
export type Priority = 'P0' | 'P1' | 'P2' | 'P3' | 'P4';
|
|
88
|
+
export type ErrorStatus = 'open' | 'resolved' | 'wont_fix' | 'pending_digest' | 'digested';
|
|
89
|
+
|
|
90
|
+
export interface CaptureDecision {
|
|
91
|
+
capture: boolean;
|
|
92
|
+
type?: ErrorType;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface ScriptMapping {
|
|
96
|
+
project: string;
|
|
97
|
+
repository: string;
|
|
98
|
+
tier: number;
|
|
99
|
+
displayName: string;
|
|
100
|
+
synced_at?: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface ErrorFingerprint {
|
|
104
|
+
issueNumber?: number;
|
|
105
|
+
issueUrl?: string;
|
|
106
|
+
status: ErrorStatus;
|
|
107
|
+
lastSeen: number;
|
|
108
|
+
firstSeen: number;
|
|
109
|
+
occurrenceCount: number;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface ErrorOccurrence {
|
|
113
|
+
id: string;
|
|
114
|
+
fingerprint: string;
|
|
115
|
+
script_name: string;
|
|
116
|
+
project: string;
|
|
117
|
+
error_type: ErrorType;
|
|
118
|
+
priority: Priority;
|
|
119
|
+
github_issue_number?: number;
|
|
120
|
+
github_issue_url?: string;
|
|
121
|
+
github_repo: string;
|
|
122
|
+
status: ErrorStatus;
|
|
123
|
+
resolved_at?: number;
|
|
124
|
+
resolved_by?: string;
|
|
125
|
+
first_seen_at: number;
|
|
126
|
+
last_seen_at: number;
|
|
127
|
+
occurrence_count: number;
|
|
128
|
+
last_request_url?: string;
|
|
129
|
+
last_request_method?: string;
|
|
130
|
+
last_colo?: string;
|
|
131
|
+
last_country?: string;
|
|
132
|
+
last_cf_ray?: string;
|
|
133
|
+
last_exception_name?: string;
|
|
134
|
+
last_exception_message?: string;
|
|
135
|
+
last_logs_json?: string;
|
|
136
|
+
// Digest-related fields (for P4 warnings)
|
|
137
|
+
digest_date?: string; // YYYY-MM-DD format
|
|
138
|
+
digest_issue_number?: number;
|
|
139
|
+
normalized_message?: string; // For grouping in digests
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Pending warning for digest aggregation
|
|
144
|
+
*/
|
|
145
|
+
export interface PendingDigestWarning {
|
|
146
|
+
id: string;
|
|
147
|
+
fingerprint: string;
|
|
148
|
+
script_name: string;
|
|
149
|
+
project: string;
|
|
150
|
+
github_repo: string;
|
|
151
|
+
normalized_message: string;
|
|
152
|
+
raw_message: string;
|
|
153
|
+
event_timestamp: number;
|
|
154
|
+
occurrence_count: number;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export type GitHubIssueType = 'Bug' | 'Task' | 'Feature';
|
|
158
|
+
|
|
159
|
+
export interface GitHubIssueCreate {
|
|
160
|
+
owner: string;
|
|
161
|
+
repo: string;
|
|
162
|
+
title: string;
|
|
163
|
+
body: string;
|
|
164
|
+
labels: string[];
|
|
165
|
+
type?: GitHubIssueType;
|
|
166
|
+
assignees?: string[];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface GitHubIssueUpdate {
|
|
170
|
+
owner: string;
|
|
171
|
+
repo: string;
|
|
172
|
+
issue_number: number;
|
|
173
|
+
body?: string;
|
|
174
|
+
state?: 'open' | 'closed';
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export interface Env {
|
|
178
|
+
// D1
|
|
179
|
+
PLATFORM_DB: D1Database;
|
|
180
|
+
// KV
|
|
181
|
+
PLATFORM_CACHE: KVNamespace;
|
|
182
|
+
// Service Bindings
|
|
183
|
+
NOTIFICATIONS_API?: Fetcher; // Optional: for creating dashboard notifications
|
|
184
|
+
// Secrets
|
|
185
|
+
GITHUB_APP_ID: string;
|
|
186
|
+
GITHUB_APP_PRIVATE_KEY: string;
|
|
187
|
+
GITHUB_APP_INSTALLATION_ID: string;
|
|
188
|
+
GITHUB_WEBHOOK_SECRET: string;
|
|
189
|
+
// Vars
|
|
190
|
+
GITHUB_ORG: string;
|
|
191
|
+
GITHUB_PROJECT_NUMBER: string;
|
|
192
|
+
GITHUB_PROJECT_ID: string;
|
|
193
|
+
AUTO_CLOSE_HOURS: string;
|
|
194
|
+
WARNING_AUTO_CLOSE_DAYS: string;
|
|
195
|
+
DEFAULT_ASSIGNEE: string;
|
|
196
|
+
// Gatus heartbeat ping URLs for cron monitoring
|
|
197
|
+
GATUS_HEARTBEAT_URL_15M?: string; // For 15-minute tail handler health
|
|
198
|
+
GATUS_HEARTBEAT_URL_DIGEST?: string; // For daily digest processing
|
|
199
|
+
GATUS_TOKEN?: string; // Bearer token for Gatus external endpoints
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// =============================================================================
|
|
203
|
+
// GAP ALERT TYPES (from platform-sentinel)
|
|
204
|
+
// =============================================================================
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Resource-level coverage breakdown
|
|
208
|
+
*/
|
|
209
|
+
export interface ResourceCoverage {
|
|
210
|
+
resourceType: string;
|
|
211
|
+
hoursWithData: number;
|
|
212
|
+
coveragePct: number;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Gap alert event sent by platform-sentinel when a project has
|
|
217
|
+
* less than the threshold coverage (default 90%) in the last 24 hours.
|
|
218
|
+
*/
|
|
219
|
+
export interface GapAlertEvent {
|
|
220
|
+
/** Project identifier (e.g., 'my-project') */
|
|
221
|
+
project: string;
|
|
222
|
+
/** Number of hours with data in the last 24h */
|
|
223
|
+
hoursWithData: number;
|
|
224
|
+
/** Expected hours (always 24) */
|
|
225
|
+
expectedHours: number;
|
|
226
|
+
/** Coverage percentage (0-100) */
|
|
227
|
+
coveragePct: number;
|
|
228
|
+
/** ISO timestamps of missing hours */
|
|
229
|
+
missingHours: string[];
|
|
230
|
+
/** GitHub repository in owner/repo format (from project_registry) */
|
|
231
|
+
repository?: string;
|
|
232
|
+
/** Per-resource type coverage breakdown */
|
|
233
|
+
resourceBreakdown?: ResourceCoverage[];
|
|
234
|
+
/** Most recent hour with data (YYYY-MM-DD HH:00 format) */
|
|
235
|
+
lastDataHour?: string;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// =============================================================================
|
|
239
|
+
// EMAIL HEALTH ALERT TYPES (from platform-email-healthcheck)
|
|
240
|
+
// =============================================================================
|
|
241
|
+
|
|
242
|
+
/** Individual check failure from email health check worker */
|
|
243
|
+
export interface EmailHealthCheckFailure {
|
|
244
|
+
check_type: string;
|
|
245
|
+
status: 'fail';
|
|
246
|
+
error_msg: string;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Email health alert event sent by platform-email-healthcheck when
|
|
251
|
+
* a brand has one or more failing health checks.
|
|
252
|
+
*/
|
|
253
|
+
export interface EmailHealthAlertEvent {
|
|
254
|
+
/** Brand identifier */
|
|
255
|
+
brand_id: string;
|
|
256
|
+
/** List of failing checks */
|
|
257
|
+
failures: EmailHealthCheckFailure[];
|
|
258
|
+
/** GitHub repository in owner/repo format */
|
|
259
|
+
repository: string;
|
|
260
|
+
/** Run ID from the health check execution */
|
|
261
|
+
run_id: string;
|
|
262
|
+
}
|