1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 00:33:44 +00:00

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

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