openreplay/frontend/app/components/DataManagement/Activity/data/Event.ts
2025-02-14 12:32:43 +01:00

48 lines
1.1 KiB
TypeScript

interface DefaultFields {
userId: string;
userCity: string;
userEnvironment: string;
}
export default class Event {
name: string;
time: string;
defaultFields: DefaultFields = {
userId: '',
userCity: '',
userEnvironment: '',
}
customFields?: Record<string,any> = undefined;
readonly $_isAutoCapture;
constructor(name: string, time: string, defaultFields: DefaultFields, customFields?: Record<string, any>, isAutoCapture = false) {
this.name = name;
this.time = time;
this.defaultFields = defaultFields;
this.customFields = customFields;
this.$_isAutoCapture = isAutoCapture;
}
toJSON() {
const obj = this.toData();
return JSON.stringify(obj, 4);
}
toData() {
const obj: any = {
name: this.name,
time: this.time,
$_isAutoCapture: this.$_isAutoCapture,
}
Object.entries(this.defaultFields).forEach(([key, value]) => {
obj[key] = value;
});
if (this.customFields) {
Object.entries(this.customFields).forEach(([key, value]) => {
obj[key] = value;
});
}
return obj;
}
}