implement sepearte replay/heatmap enabled routes and collection

This commit is contained in:
Francis Cao committed 2026-05-19 15:46:01 -07:00
1 parent 4b40be6b5a
commit 5bd92ce950
39 files changed
+586 -295

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
export interface RecorderConfig {
replayEnabled?: boolean;
heatmapEnabled?: boolean;
sampleRate?: number;
heatmapSampleRate?: number;
maskLevel?: 'strict' | 'moderate';
maxDuration?: number;
blockSelector?: string;
}
export function getRecorderConfig(value: unknown): RecorderConfig {
if (!value || typeof value !== 'object' || Array.isArray(value)) {
return {};
}
const config = value as Record<string, unknown>;
const nextConfig: RecorderConfig = {};
if (config.replayEnabled === true) {
nextConfig.replayEnabled = true;
}
if (config.heatmapEnabled === true) {
nextConfig.heatmapEnabled = true;
}
if (typeof config.sampleRate === 'number') {
nextConfig.sampleRate = config.sampleRate;
}
if (typeof config.heatmapSampleRate === 'number') {
nextConfig.heatmapSampleRate = config.heatmapSampleRate;
}
if (config.maskLevel === 'strict' || config.maskLevel === 'moderate') {
nextConfig.maskLevel = config.maskLevel;
}
if (typeof config.maxDuration === 'number' && Number.isFinite(config.maxDuration)) {
nextConfig.maxDuration = Math.round(config.maxDuration);
}
if (typeof config.blockSelector === 'string') {
nextConfig.blockSelector = config.blockSelector;
}
return nextConfig;
}
export function getRecorderEnabled(config: unknown) {
const { replayEnabled, heatmapEnabled } = getRecorderConfig(config);
return replayEnabled === true || heatmapEnabled === true;
}