brakit 0.6.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/LICENSE +21 -0
- package/README.md +189 -0
- package/dist/bin/brakit.d.ts +2 -0
- package/dist/bin/brakit.js +5679 -0
- package/dist/index.d.ts +203 -0
- package/dist/index.js +1603 -0
- package/dist/instrument/preload.d.ts +2 -0
- package/dist/instrument/preload.js +739 -0
- package/package.json +79 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse, Server } from 'node:http';
|
|
2
|
+
|
|
3
|
+
type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS" | (string & {});
|
|
4
|
+
type FlatHeaders = Record<string, string>;
|
|
5
|
+
interface TracedRequest {
|
|
6
|
+
id: string;
|
|
7
|
+
method: HttpMethod;
|
|
8
|
+
url: string;
|
|
9
|
+
path: string;
|
|
10
|
+
headers: FlatHeaders;
|
|
11
|
+
requestBody: string | null;
|
|
12
|
+
statusCode: number;
|
|
13
|
+
responseHeaders: FlatHeaders;
|
|
14
|
+
responseBody: string | null;
|
|
15
|
+
startedAt: number;
|
|
16
|
+
durationMs: number;
|
|
17
|
+
responseSize: number;
|
|
18
|
+
isStatic: boolean;
|
|
19
|
+
}
|
|
20
|
+
type RequestListener = (req: TracedRequest) => void;
|
|
21
|
+
|
|
22
|
+
type Framework = "nextjs" | "remix" | "nuxt" | "vite" | "astro" | "custom" | "unknown";
|
|
23
|
+
interface DetectedProject {
|
|
24
|
+
framework: Framework;
|
|
25
|
+
devCommand: string;
|
|
26
|
+
devBin: string;
|
|
27
|
+
defaultPort: number;
|
|
28
|
+
packageManager: "npm" | "yarn" | "pnpm" | "bun" | "unknown";
|
|
29
|
+
}
|
|
30
|
+
interface BrakitConfig {
|
|
31
|
+
proxyPort: number;
|
|
32
|
+
targetPort: number;
|
|
33
|
+
showStatic: boolean;
|
|
34
|
+
maxBodyCapture: number;
|
|
35
|
+
customCommand?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type RequestCategory = "auth-handshake" | "auth-check" | "middleware" | "server-action" | "api-call" | "data-fetch" | "page-load" | "navigation" | "polling" | "static" | "unknown";
|
|
39
|
+
interface LabeledRequest extends TracedRequest {
|
|
40
|
+
label: string;
|
|
41
|
+
category: RequestCategory;
|
|
42
|
+
sourcePage?: string;
|
|
43
|
+
isDuplicate?: boolean;
|
|
44
|
+
isStrictModeDupe?: boolean;
|
|
45
|
+
pollingCount?: number;
|
|
46
|
+
pollingDurationMs?: number;
|
|
47
|
+
}
|
|
48
|
+
interface RequestFlow {
|
|
49
|
+
id: string;
|
|
50
|
+
label: string;
|
|
51
|
+
requests: LabeledRequest[];
|
|
52
|
+
startTime: number;
|
|
53
|
+
totalDurationMs: number;
|
|
54
|
+
hasErrors: boolean;
|
|
55
|
+
warnings: string[];
|
|
56
|
+
sourcePage: string;
|
|
57
|
+
redundancyPct: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface TelemetryEntry {
|
|
61
|
+
id: string;
|
|
62
|
+
parentRequestId: string | null;
|
|
63
|
+
timestamp: number;
|
|
64
|
+
}
|
|
65
|
+
interface TracedFetch extends TelemetryEntry {
|
|
66
|
+
url: string;
|
|
67
|
+
method: string;
|
|
68
|
+
statusCode: number;
|
|
69
|
+
durationMs: number;
|
|
70
|
+
}
|
|
71
|
+
interface TracedLog extends TelemetryEntry {
|
|
72
|
+
level: "log" | "warn" | "error" | "info" | "debug";
|
|
73
|
+
message: string;
|
|
74
|
+
}
|
|
75
|
+
interface TracedError extends TelemetryEntry {
|
|
76
|
+
name: string;
|
|
77
|
+
message: string;
|
|
78
|
+
stack: string;
|
|
79
|
+
}
|
|
80
|
+
type NormalizedOp = "SELECT" | "INSERT" | "UPDATE" | "DELETE" | "OTHER";
|
|
81
|
+
interface TracedQuery extends TelemetryEntry {
|
|
82
|
+
driver: "pg" | "mysql2" | "prisma" | string;
|
|
83
|
+
sql?: string;
|
|
84
|
+
model?: string;
|
|
85
|
+
operation?: string;
|
|
86
|
+
durationMs: number;
|
|
87
|
+
rowCount?: number;
|
|
88
|
+
normalizedOp?: NormalizedOp;
|
|
89
|
+
table?: string;
|
|
90
|
+
source?: string;
|
|
91
|
+
}
|
|
92
|
+
type TelemetryEvent = {
|
|
93
|
+
type: "fetch";
|
|
94
|
+
data: Omit<TracedFetch, "id">;
|
|
95
|
+
} | {
|
|
96
|
+
type: "log";
|
|
97
|
+
data: Omit<TracedLog, "id">;
|
|
98
|
+
} | {
|
|
99
|
+
type: "error";
|
|
100
|
+
data: Omit<TracedError, "id">;
|
|
101
|
+
} | {
|
|
102
|
+
type: "query";
|
|
103
|
+
data: Omit<TracedQuery, "id">;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
type SecuritySeverity = "critical" | "warning" | "info";
|
|
107
|
+
interface SecurityFinding {
|
|
108
|
+
severity: SecuritySeverity;
|
|
109
|
+
rule: string;
|
|
110
|
+
title: string;
|
|
111
|
+
desc: string;
|
|
112
|
+
hint: string;
|
|
113
|
+
endpoint: string;
|
|
114
|
+
count: number;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
interface BrakitAdapter {
|
|
118
|
+
name: string;
|
|
119
|
+
detect(): boolean;
|
|
120
|
+
patch(emit: (event: TelemetryEvent) => void): void;
|
|
121
|
+
unpatch?(): void;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
interface SecurityContext {
|
|
125
|
+
requests: readonly TracedRequest[];
|
|
126
|
+
logs: readonly TracedLog[];
|
|
127
|
+
}
|
|
128
|
+
interface SecurityRule {
|
|
129
|
+
id: string;
|
|
130
|
+
severity: SecuritySeverity;
|
|
131
|
+
name: string;
|
|
132
|
+
hint: string;
|
|
133
|
+
check(ctx: SecurityContext): SecurityFinding[];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
declare class SecurityScanner {
|
|
137
|
+
private rules;
|
|
138
|
+
register(rule: SecurityRule): void;
|
|
139
|
+
scan(ctx: SecurityContext): SecurityFinding[];
|
|
140
|
+
getRules(): readonly SecurityRule[];
|
|
141
|
+
}
|
|
142
|
+
declare function createDefaultScanner(): SecurityScanner;
|
|
143
|
+
|
|
144
|
+
type InsightSeverity = "critical" | "warning" | "info";
|
|
145
|
+
type InsightType = "n1" | "cross-endpoint" | "redundant-query" | "error" | "error-hotspot" | "duplicate" | "slow" | "query-heavy" | "auth-overhead" | "select-star" | "high-rows" | "large-response" | "security";
|
|
146
|
+
interface Insight {
|
|
147
|
+
severity: InsightSeverity;
|
|
148
|
+
type: InsightType;
|
|
149
|
+
title: string;
|
|
150
|
+
desc: string;
|
|
151
|
+
hint: string;
|
|
152
|
+
detail?: string;
|
|
153
|
+
nav?: string;
|
|
154
|
+
}
|
|
155
|
+
interface InsightContext {
|
|
156
|
+
requests: readonly TracedRequest[];
|
|
157
|
+
queries: readonly TracedQuery[];
|
|
158
|
+
errors: readonly TracedError[];
|
|
159
|
+
flows: readonly RequestFlow[];
|
|
160
|
+
securityFindings?: readonly SecurityFinding[];
|
|
161
|
+
}
|
|
162
|
+
declare function computeInsights(ctx: InsightContext): Insight[];
|
|
163
|
+
|
|
164
|
+
type DashboardHandler = (req: IncomingMessage, res: ServerResponse, config: BrakitConfig) => void;
|
|
165
|
+
declare function createProxyServer(config: BrakitConfig, handleDashboard: DashboardHandler): Server;
|
|
166
|
+
|
|
167
|
+
declare function detectProject(rootDir: string): Promise<DetectedProject>;
|
|
168
|
+
|
|
169
|
+
declare class AdapterRegistry {
|
|
170
|
+
private adapters;
|
|
171
|
+
private active;
|
|
172
|
+
register(adapter: BrakitAdapter): void;
|
|
173
|
+
patchAll(emit: (event: TelemetryEvent) => void): void;
|
|
174
|
+
unpatchAll(): void;
|
|
175
|
+
getActive(): readonly BrakitAdapter[];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
type AnalysisListener = (insights: Insight[], findings: SecurityFinding[]) => void;
|
|
179
|
+
declare class AnalysisEngine {
|
|
180
|
+
private debounceMs;
|
|
181
|
+
private scanner;
|
|
182
|
+
private cachedInsights;
|
|
183
|
+
private cachedFindings;
|
|
184
|
+
private debounceTimer;
|
|
185
|
+
private listeners;
|
|
186
|
+
private boundRequestListener;
|
|
187
|
+
private boundQueryListener;
|
|
188
|
+
private boundErrorListener;
|
|
189
|
+
private boundLogListener;
|
|
190
|
+
constructor(debounceMs?: number);
|
|
191
|
+
start(): void;
|
|
192
|
+
stop(): void;
|
|
193
|
+
onUpdate(fn: AnalysisListener): void;
|
|
194
|
+
offUpdate(fn: AnalysisListener): void;
|
|
195
|
+
getInsights(): readonly Insight[];
|
|
196
|
+
getFindings(): readonly SecurityFinding[];
|
|
197
|
+
private scheduleRecompute;
|
|
198
|
+
recompute(): void;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
declare const VERSION: string;
|
|
202
|
+
|
|
203
|
+
export { AdapterRegistry, AnalysisEngine, type BrakitAdapter, type BrakitConfig, type DetectedProject, type FlatHeaders, type Framework, type HttpMethod, type Insight, type InsightContext, type NormalizedOp, type RequestCategory, type RequestListener, type SecurityContext, type SecurityFinding, type SecurityRule, SecurityScanner, type SecuritySeverity, type TracedRequest, VERSION, computeInsights, createDefaultScanner, createProxyServer, detectProject };
|