browsertrack 0.0.1 → 0.1.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 +143 -0
- package/dist/chunk-6A7FFDIB.js +221 -0
- package/dist/chunk-6A7FFDIB.js.map +1 -0
- package/dist/chunk-ANMR5WBH.js +659 -0
- package/dist/chunk-ANMR5WBH.js.map +1 -0
- package/dist/chunk-BSKNG4V7.js +1199 -0
- package/dist/chunk-BSKNG4V7.js.map +1 -0
- package/dist/chunk-X7C5CHBO.js +2080 -0
- package/dist/chunk-X7C5CHBO.js.map +1 -0
- package/dist/chunk-ZLNGOOH2.js +554 -0
- package/dist/chunk-ZLNGOOH2.js.map +1 -0
- package/dist/cli/index.js +2829 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/client/index.cjs +2218 -0
- package/dist/client/index.d.ts +197 -0
- package/dist/client/index.js +20 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client.iife.js +309 -0
- package/dist/core/index.d.ts +78 -0
- package/dist/core/index.js +31 -0
- package/dist/core/index.js.map +1 -0
- package/dist/daemon/index.d.ts +58 -0
- package/dist/daemon/index.js +32 -0
- package/dist/daemon/index.js.map +1 -0
- package/dist/engine-DKloFjvs.d.ts +157 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/index.d.ts +11 -0
- package/dist/mcp/index.js +12 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/notes-CBvN91Wf.d.ts +260 -0
- package/dist/projects-CY8ungMt.d.ts +99 -0
- package/dist/server-CN-se8td.d.ts +55 -0
- package/examples/test-app/index.html +299 -0
- package/package.json +52 -7
- package/packages/cli/src/index.ts +413 -0
- package/packages/client/package.json +28 -0
- package/packages/client/src/breadcrumbs.ts +30 -0
- package/packages/client/src/client.ts +278 -0
- package/packages/client/src/commands/handler.ts +301 -0
- package/packages/client/src/config.ts +37 -0
- package/packages/client/src/index.ts +50 -0
- package/packages/client/src/interceptors/console.ts +68 -0
- package/packages/client/src/interceptors/interaction.ts +119 -0
- package/packages/client/src/interceptors/navigation.ts +93 -0
- package/packages/client/src/interceptors/network.ts +165 -0
- package/packages/client/src/interceptors/runtime.ts +65 -0
- package/packages/client/src/notes/inspector.ts +943 -0
- package/packages/client/src/screenshot/browser-script-driver.ts +192 -0
- package/packages/client/src/screenshot/driver.ts +14 -0
- package/packages/client/src/transport/websocket.ts +179 -0
- package/packages/client/tsconfig.json +8 -0
- package/packages/core/dist/index.d.ts +317 -0
- package/packages/core/dist/index.js +221 -0
- package/packages/core/package.json +23 -0
- package/packages/core/src/fingerprint.ts +120 -0
- package/packages/core/src/index.ts +9 -0
- package/packages/core/src/redaction.ts +139 -0
- package/packages/core/src/selector.ts +77 -0
- package/packages/core/src/types/commands.ts +101 -0
- package/packages/core/src/types/events.ts +108 -0
- package/packages/core/src/types/incidents.ts +54 -0
- package/packages/core/src/types/notes.ts +106 -0
- package/packages/core/src/types/probes.ts +44 -0
- package/packages/core/src/types/projects.ts +20 -0
- package/packages/core/tsconfig.json +8 -0
- package/packages/daemon/src/config.ts +29 -0
- package/packages/daemon/src/incidents/engine.ts +211 -0
- package/packages/daemon/src/index.ts +18 -0
- package/packages/daemon/src/notes/engine.ts +92 -0
- package/packages/daemon/src/notes/verification.ts +191 -0
- package/packages/daemon/src/server/daemon.ts +112 -0
- package/packages/daemon/src/server/http.ts +165 -0
- package/packages/daemon/src/server/ws.ts +175 -0
- package/packages/daemon/src/session/manager.ts +126 -0
- package/packages/daemon/src/storage/db.ts +733 -0
- package/packages/daemon/src/storage/screenshot-store.ts +49 -0
- package/packages/daemon/src/verification/engine.ts +264 -0
- package/packages/mcp/src/handlers.ts +398 -0
- package/packages/mcp/src/index.ts +3 -0
- package/packages/mcp/src/server.ts +86 -0
- package/packages/mcp/src/tools.ts +236 -0
- package/src/index.ts +4 -0
- package/test/client/interceptors.test.ts +69 -0
- package/test/core/fingerprint.test.ts +53 -0
- package/test/core/notes.test.ts +66 -0
- package/test/core/redaction.test.ts +48 -0
- package/test/daemon/incident-engine.test.ts +98 -0
- package/test/daemon/notes-storage.test.ts +130 -0
- package/test/daemon/notes-verification.test.ts +135 -0
- package/test/daemon/storage.test.ts +123 -0
- package/test/daemon/verification-engine.test.ts +88 -0
- package/test/e2e/daemon-mcp-e2e.test.ts +153 -0
- package/test/e2e/visual-notes-e2e.test.ts +205 -0
- package/test/mcp/handlers.test.ts +116 -0
- package/test/mcp/notes.test.ts +107 -0
- package/tsconfig.base.json +17 -0
- package/tsconfig.json +26 -0
- package/tsup.config.ts +54 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { WebSocket } from 'ws';
|
|
2
|
+
import type { ClientCommand, CommandResponse, Session } from '../../../core/src/index.js';
|
|
3
|
+
import type { StorageDB } from '../storage/db.js';
|
|
4
|
+
|
|
5
|
+
interface ActiveSessionSocket {
|
|
6
|
+
sessionId: string;
|
|
7
|
+
ws: WebSocket;
|
|
8
|
+
origin: string;
|
|
9
|
+
projectId: string;
|
|
10
|
+
pendingCommands: Map<
|
|
11
|
+
string,
|
|
12
|
+
{
|
|
13
|
+
resolve: (res: CommandResponse) => void;
|
|
14
|
+
reject: (err: Error) => void;
|
|
15
|
+
timer: any;
|
|
16
|
+
}
|
|
17
|
+
>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class SessionManager {
|
|
21
|
+
private activeSockets: Map<string, ActiveSessionSocket> = new Map();
|
|
22
|
+
private db: StorageDB;
|
|
23
|
+
|
|
24
|
+
constructor(db: StorageDB) {
|
|
25
|
+
this.db = db;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public registerSocket(sessionId: string, ws: WebSocket, origin: string, projectId: string): void {
|
|
29
|
+
this.activeSockets.set(sessionId, {
|
|
30
|
+
sessionId,
|
|
31
|
+
ws,
|
|
32
|
+
origin,
|
|
33
|
+
projectId,
|
|
34
|
+
pendingCommands: new Map(),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public unregisterSocket(sessionId: string): void {
|
|
39
|
+
const active = this.activeSockets.get(sessionId);
|
|
40
|
+
if (active) {
|
|
41
|
+
for (const pending of active.pendingCommands.values()) {
|
|
42
|
+
clearTimeout(pending.timer);
|
|
43
|
+
pending.reject(new Error('Session disconnected before command completed'));
|
|
44
|
+
}
|
|
45
|
+
active.pendingCommands.clear();
|
|
46
|
+
this.activeSockets.delete(sessionId);
|
|
47
|
+
this.db.deactivateSession(sessionId);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public handleCommandResponse(sessionId: string, response: CommandResponse): void {
|
|
52
|
+
const active = this.activeSockets.get(sessionId);
|
|
53
|
+
if (!active) return;
|
|
54
|
+
|
|
55
|
+
const pending = active.pendingCommands.get(response.id);
|
|
56
|
+
if (pending) {
|
|
57
|
+
clearTimeout(pending.timer);
|
|
58
|
+
active.pendingCommands.delete(response.id);
|
|
59
|
+
pending.resolve(response);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public async sendCommand<T = any>(sessionId: string, command: ClientCommand<T>, timeoutMs = 5000): Promise<CommandResponse> {
|
|
64
|
+
const active = this.activeSockets.get(sessionId);
|
|
65
|
+
if (!active || active.ws.readyState !== 1 /* WebSocket.OPEN */) {
|
|
66
|
+
return {
|
|
67
|
+
id: command.id,
|
|
68
|
+
ok: false,
|
|
69
|
+
error: `Session ${sessionId} is not actively connected`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return new Promise<CommandResponse>((resolve, reject) => {
|
|
74
|
+
const timer = setTimeout(() => {
|
|
75
|
+
active.pendingCommands.delete(command.id);
|
|
76
|
+
resolve({
|
|
77
|
+
id: command.id,
|
|
78
|
+
ok: false,
|
|
79
|
+
error: `Command ${command.type} timed out after ${timeoutMs}ms`,
|
|
80
|
+
});
|
|
81
|
+
}, timeoutMs);
|
|
82
|
+
|
|
83
|
+
active.pendingCommands.set(command.id, {
|
|
84
|
+
resolve,
|
|
85
|
+
reject,
|
|
86
|
+
timer,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
active.ws.send(
|
|
91
|
+
JSON.stringify({
|
|
92
|
+
type: 'command',
|
|
93
|
+
command,
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
} catch (err: any) {
|
|
97
|
+
clearTimeout(timer);
|
|
98
|
+
active.pendingCommands.delete(command.id);
|
|
99
|
+
resolve({
|
|
100
|
+
id: command.id,
|
|
101
|
+
ok: false,
|
|
102
|
+
error: err?.message || 'Failed to send command over WebSocket',
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public getActiveSessionForProject(projectId: string): Session | null {
|
|
109
|
+
for (const active of this.activeSockets.values()) {
|
|
110
|
+
if (active.projectId === projectId) {
|
|
111
|
+
return this.db.getSession(active.sessionId);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public getAnyActiveSession(): Session | null {
|
|
118
|
+
const first = this.activeSockets.keys().next().value;
|
|
119
|
+
if (!first) return null;
|
|
120
|
+
return this.db.getSession(first);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
public getActiveCount(): number {
|
|
124
|
+
return this.activeSockets.size;
|
|
125
|
+
}
|
|
126
|
+
}
|