-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsessionManager.ts
More file actions
63 lines (58 loc) · 2.21 KB
/
sessionManager.ts
File metadata and controls
63 lines (58 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { StorageService } from './storage.ts';
import type { Session } from '../core/types.ts';
export class SessionManager {
static async startSession(payload?: { envData?: any, config?: any }): Promise<Session> {
const sessionId = crypto.randomUUID();
const { envData, config } = payload || {};
const session: Session = {
sessionId,
startTime: Date.now(),
issues: [],
metadata: envData || {
userAgent: navigator.userAgent,
viewport: { width: window.innerWidth, height: window.innerHeight },
url: location.href,
platform: (navigator as any).platform
},
config: config || {
slowApiThreshold: 1000,
escalationThreshold: 10,
enabledTypes: {
runtime_crash: true,
console_error: true,
console_log: false,
network_failure: true,
slow_api: true,
retry_storm: true,
resource_failure: true,
cors_failure: true,
security_risk: true,
white_screen: true
}
}
};
await StorageService.saveSession(session);
await StorageService.setCurrentSessionId(sessionId);
return session;
}
static async endSession(): Promise<Session | null> {
const sessionId = await StorageService.getCurrentSessionId();
if (!sessionId) return null;
const session = await StorageService.getSession(sessionId);
if (session) {
session.endTime = Date.now();
await StorageService.saveSession(session);
}
await StorageService.setCurrentSessionId(null);
return session || null;
}
static async isActive(): Promise<boolean> {
const id = await StorageService.getCurrentSessionId();
return !!id;
}
static async getCurrentSession(): Promise<Session | undefined> {
const id = await StorageService.getCurrentSessionId();
if (!id) return undefined;
return StorageService.getSession(id);
}
}