diff --git a/src/abstractions/api.service.ts b/src/abstractions/api.service.ts index 54891450a1..56c668b37c 100644 --- a/src/abstractions/api.service.ts +++ b/src/abstractions/api.service.ts @@ -42,6 +42,7 @@ import { } from '../models/response/collectionResponse'; import { CollectionUserResponse } from '../models/response/collectionUserResponse'; import { DomainsResponse } from '../models/response/domainsResponse'; +import { EventResponse } from '../models/response/eventResponse'; import { FolderResponse } from '../models/response/folderResponse'; import { GroupDetailsResponse, @@ -164,4 +165,11 @@ export abstract class ApiService { postOrganization: (request: OrganizationCreateRequest) => Promise; postLeaveOrganization: (id: string) => Promise; postOrganizationLicense: (data: FormData) => Promise; + + getEvents: (start: string, end: string, token: string) => Promise>; + getEventsCipher: (id: string, start: string, end: string, token: string) => Promise>; + getEventsOrganization: (id: string, start: string, end: string, + token: string) => Promise>; + getEventsOrganizationUser: (organizationId: string, id: string, + start: string, end: string, token: string) => Promise> } diff --git a/src/enums/eventType.ts b/src/enums/eventType.ts new file mode 100644 index 0000000000..acaae31d4d --- /dev/null +++ b/src/enums/eventType.ts @@ -0,0 +1,34 @@ +export enum EventType { + User_LoggedIn = 1000, + User_ChangedPassword = 1001, + User_Enabled2fa = 1002, + User_Disabled2fa = 1003, + User_Recovered2fa = 1004, + User_FailedLogIn = 1005, + User_FailedLogIn2fa = 1006, + + Cipher_Created = 1100, + Cipher_Updated = 1101, + Cipher_Deleted = 1102, + Cipher_AttachmentCreated = 1103, + Cipher_AttachmentDeleted = 1104, + Cipher_Shared = 1105, + Cipher_UpdatedCollections = 1106, + + Collection_Created = 1300, + Collection_Updated = 1301, + Collection_Deleted = 1302, + + Group_Created = 1400, + Group_Updated = 1401, + Group_Deleted = 1402, + + OrganizationUser_Invited = 1500, + OrganizationUser_Confirmed = 1501, + OrganizationUser_Updated = 1502, + OrganizationUser_Removed = 1503, + OrganizationUser_UpdatedGroups = 1504, + + Organization_Updated = 1600, + +} diff --git a/src/models/response/eventResponse.ts b/src/models/response/eventResponse.ts new file mode 100644 index 0000000000..1a5ca70ed5 --- /dev/null +++ b/src/models/response/eventResponse.ts @@ -0,0 +1,28 @@ +import { DeviceType } from '../../enums/deviceType'; +import { EventType } from '../../enums/eventType'; + +export class EventResponse { + type: EventType; + userId: string; + organizationId: string; + cipherId: string; + groupId: string; + organizationUserId: string; + actingUserId: string; + date: Date; + deviceType: DeviceType; + ipAddress: string; + + constructor(response: any) { + this.type = response.Type; + this.userId = response.UserId; + this.organizationId = response.OrganizationId; + this.cipherId = response.CipherId; + this.groupId = response.GroupId; + this.organizationUserId = response.OrganizationUserId; + this.actingUserId = response.ActingUserId; + this.date = response.Date; + this.deviceType = response.DeviceType; + this.ipAddress = response.IpAddress; + } +} diff --git a/src/services/api.service.ts b/src/services/api.service.ts index f738e2942e..23520bf4ae 100644 --- a/src/services/api.service.ts +++ b/src/services/api.service.ts @@ -49,6 +49,7 @@ import { import { CollectionUserResponse } from '../models/response/collectionUserResponse'; import { DomainsResponse } from '../models/response/domainsResponse'; import { ErrorResponse } from '../models/response/errorResponse'; +import { EventResponse } from '../models/response/eventResponse'; import { FolderResponse } from '../models/response/folderResponse'; import { GroupDetailsResponse, @@ -553,6 +554,35 @@ export class ApiService implements ApiServiceAbstraction { return new OrganizationResponse(r); } + // Event APIs + + async getEvents(start: string, end: string, token: string): Promise> { + const r = await this.send('GET', this.addEventParameters('/events', start, end, token), null, true, true); + return new ListResponse(r, EventResponse); + } + + async getEventsCipher(id: string, start: string, end: string, + token: string): Promise> { + const r = await this.send('GET', this.addEventParameters('/ciphers/' + id + '/events', start, end, token), + null, true, true); + return new ListResponse(r, EventResponse); + } + + async getEventsOrganization(id: string, start: string, end: string, + token: string): Promise> { + const r = await this.send('GET', this.addEventParameters('/organizations/' + id + '/events', start, end, token), + null, true, true); + return new ListResponse(r, EventResponse); + } + + async getEventsOrganizationUser(organizationId: string, id: string, + start: string, end: string, token: string): Promise> { + const r = await this.send('GET', + this.addEventParameters('/organizations/' + organizationId + '/users/' + id + '/events', start, end, token), + null, true, true); + return new ListResponse(r, EventResponse); + } + // Helpers private async send(method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, body: any, @@ -671,4 +701,19 @@ export class ApiService implements ApiServiceAbstraction { } return undefined; } + + private addEventParameters(base: string, start: string, end: string, token: string) { + if (start != null) { + base += ('?start=' + start); + } + if (end != null) { + base += (base.indexOf('?') > -1 ? '&' : '?'); + base += ('end=' + end); + } + if (token != null) { + base += (base.indexOf('?') > -1 ? '&' : '?'); + base += ('continuationToken=' + token); + } + return base; + } }