diff --git a/src/abstractions/export.service.ts b/src/abstractions/export.service.ts index 74b506e954..4e23823a7a 100644 --- a/src/abstractions/export.service.ts +++ b/src/abstractions/export.service.ts @@ -1,5 +1,8 @@ +import { EventView } from '../models/view/eventView'; + export abstract class ExportService { getExport: (format?: 'csv' | 'json' | 'encrypted_json') => Promise; getOrganizationExport: (organizationId: string, format?: 'csv' | 'json' | 'encrypted_json') => Promise; + getEventExport: (events: EventView[]) => Promise; getFileName: (prefix?: string, extension?: string) => string; } diff --git a/src/models/export/event.ts b/src/models/export/event.ts new file mode 100644 index 0000000000..70e1f19e35 --- /dev/null +++ b/src/models/export/event.ts @@ -0,0 +1,26 @@ +import { EventType } from '../../enums/eventType'; +import { EventView } from '../view/eventView'; + +export class Event { + message: string; + appIcon: string; + appName: string; + userId: string; + userName: string; + userEmail: string; + date: string; + ip: string; + type: string; + + constructor(event: EventView) { + this.message = event.humanReadableMessage; + this.appIcon = event.appIcon; + this.appName = event.appName; + this.userId = event.userId; + this.userName = event.userName; + this.userEmail = event.userEmail; + this.date = event.date; + this.ip = event.ip; + this.type = EventType[event.type]; + } +} diff --git a/src/models/view/eventView.ts b/src/models/view/eventView.ts new file mode 100644 index 0000000000..39e40c4de0 --- /dev/null +++ b/src/models/view/eventView.ts @@ -0,0 +1,27 @@ +import { EventType } from '../../enums/eventType'; + +export class EventView { + message: string; + humanReadableMessage: string; + appIcon: string; + appName: string; + userId: string; + userName: string; + userEmail: string; + date: string; + ip: string; + type: EventType; + + constructor(data: Required) { + this.message = data.message; + this.humanReadableMessage = data.humanReadableMessage; + this.appIcon = data.appIcon; + this.appName = data.appName; + this.userId = data.userId; + this.userName = data.userName; + this.userEmail = data.userEmail; + this.date = data.date; + this.ip = data.ip; + this.type = data.type; + } +} diff --git a/src/services/export.service.ts b/src/services/export.service.ts index 51aa72a300..a8b2071526 100644 --- a/src/services/export.service.ts +++ b/src/services/export.service.ts @@ -22,7 +22,9 @@ import { CollectionDetailsResponse } from '../models/response/collectionResponse import { CipherWithIds as CipherExport } from '../models/export/cipherWithIds'; import { CollectionWithId as CollectionExport } from '../models/export/collectionWithId'; +import { Event } from '../models/export/event'; import { FolderWithId as FolderExport } from '../models/export/folderWithId'; +import { EventView } from '../models/view/eventView'; import { Utils } from '../misc/utils'; @@ -47,6 +49,10 @@ export class ExportService implements ExportServiceAbstraction { } } + async getEventExport(events: EventView[]): Promise { + return papa.unparse(events.map(e => new Event(e))); + } + getFileName(prefix: string = null, extension: string = 'csv'): string { const now = new Date(); const dateString =