openreplay/frontend/app/services/SessionService.ts
Delirium 5e21d88e8c
feat(tracker): Msg buffering and conditional recording (#1775)
* feat(tracker) start message buffering support

* feat(tracker): buffered recordings

* feat(tracker): buffered recordings timedelay adjust

* fix(tracker): condition manager

* fix(tracker): conditions handlers

* fix(tracker): conditions

* fix(tracker): pre-fetch feature flags and conditions, fix naming and dnt check repeating

* fix(tracker): fix conditions fetch

* feat(tracker): test coverage for conditionsManager

* feat(tracker): some api connections

* feat(tracker): fix projid in session info

* feat(tracker): added fetch req status condition, partially added offline recording, type fixes

* fix(tracker): fix tests

* fix(tracker): fix network req c

* fix(tracker): fix conditions test

* feat(ui): conditional recording ui

* fix(tracker): fix prestart callbacks

* feat(ui): conditions ui and api stuff

* feat(ui): fix ?

* fix(tracker): map raw db response in tracker

* fix(tracker): fix condition processing, add cond name to trigger event, change unit tests

* fix(tracker): simplify mapping, rename functions

* fix(tracker): change toggler design, change network request condition

* fix(tracker): some formatting

* fix(tracker): reformat logging

* fix(ui): rm console log
2024-01-09 13:18:26 +01:00

100 lines
3 KiB
TypeScript

import APIClient from 'App/api_client';
import { ISession } from 'Types/session/session';
import { IErrorStack } from 'Types/session/errorStack';
import { clean as cleanParams } from 'App/api_client';
export default class SettingsService {
private client: APIClient;
constructor(client?: APIClient) {
this.client = client ? client : new APIClient();
}
initClient(client?: APIClient) {
this.client = client || new APIClient();
}
saveCaptureRate(projectId: number, data: any) {
return this.client.post(`/${projectId}/sample_rate`, data);
}
fetchCaptureRate(projectId: number) {
return this.client
.get(`/${projectId}/sample_rate`)
.then((response) => response.json())
.then((response) => response.data || 0);
}
fetchCaptureConditions(
projectId: number
): Promise<{ rate: number; captureAll: boolean; conditions: any[] }> {
return this.client
.get(`/${projectId}/conditions`)
.then((response) => response.json())
.then((response) => response.data || []);
}
saveCaptureConditions(projectId: number, data: any) {
return this.client.post(`/${projectId}/conditions`, data);
}
getSessions(filter: any): Promise<{ sessions: ISession[]; total: number }> {
return this.client
.post('/sessions/search', filter)
.then((r) => r.json())
.then((response) => response.data || [])
.catch((e) => Promise.reject(e));
}
getSessionInfo(sessionId: string, isLive?: boolean): Promise<ISession> {
return this.client
.get(isLive ? `/assist/sessions/${sessionId}` : `/sessions/${sessionId}`)
.then((r) => r.json())
.then((j) => j.data || {})
.catch(console.error);
}
getLiveSessions(filter: any): Promise<{ sessions: ISession[] }> {
return this.client
.post('/assist/sessions', cleanParams(filter))
.then((r) => r.json())
.then((response) => response.data || [])
.catch((e) => Promise.reject(e));
}
getErrorStack(sessionId: string, errorId: string): Promise<{ trace: IErrorStack[] }> {
return this.client
.get(`/sessions/${sessionId}/errors/${errorId}/sourcemaps`)
.then((r) => r.json())
.then((j) => j.data || {})
.catch((e) => Promise.reject(e));
}
getAutoplayList(params = {}): Promise<{ sessionId: string }[]> {
return this.client
.post('/sessions/search/ids', cleanParams(params))
.then((r) => r.json())
.then((j) => j.data || [])
.catch((e) => Promise.reject(e));
}
toggleFavorite(sessionId: string): Promise<any> {
return this.client.get(`/sessions/${sessionId}/favorite`).catch(Promise.reject);
}
getClickMap(params = {}): Promise<any[]> {
return this.client
.post('/heatmaps/url', params)
.then((r) => r.json())
.then((j) => j.data || [])
.catch(Promise.reject);
}
getRecordingStatus(): Promise<any> {
return this.client
.get('/check-recording-status')
.then((r) => r.json())
.then((j) => j.data || {})
.catch(Promise.reject);
}
}