event apis

This commit is contained in:
Kyle Spearrin 2018-07-06 23:06:38 -04:00
parent c44e633f42
commit 1b7ace0495
4 changed files with 115 additions and 0 deletions

View File

@ -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<OrganizationResponse>;
postLeaveOrganization: (id: string) => Promise<any>;
postOrganizationLicense: (data: FormData) => Promise<OrganizationResponse>;
getEvents: (start: string, end: string, token: string) => Promise<ListResponse<EventResponse>>;
getEventsCipher: (id: string, start: string, end: string, token: string) => Promise<ListResponse<EventResponse>>;
getEventsOrganization: (id: string, start: string, end: string,
token: string) => Promise<ListResponse<EventResponse>>;
getEventsOrganizationUser: (organizationId: string, id: string,
start: string, end: string, token: string) => Promise<ListResponse<EventResponse>>
}

34
src/enums/eventType.ts Normal file
View File

@ -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,
}

View File

@ -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;
}
}

View File

@ -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<ListResponse<EventResponse>> {
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<ListResponse<EventResponse>> {
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<ListResponse<EventResponse>> {
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<ListResponse<EventResponse>> {
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;
}
}