setup for client event collection
This commit is contained in:
parent
740c01c33c
commit
49a6b5046f
|
@ -12,6 +12,7 @@ import { CollectionRequest } from '../models/request/collectionRequest';
|
||||||
import { DeleteRecoverRequest } from '../models/request/deleteRecoverRequest';
|
import { DeleteRecoverRequest } from '../models/request/deleteRecoverRequest';
|
||||||
import { EmailRequest } from '../models/request/emailRequest';
|
import { EmailRequest } from '../models/request/emailRequest';
|
||||||
import { EmailTokenRequest } from '../models/request/emailTokenRequest';
|
import { EmailTokenRequest } from '../models/request/emailTokenRequest';
|
||||||
|
import { EventRequest } from '../models/request/eventRequest';
|
||||||
import { FolderRequest } from '../models/request/folderRequest';
|
import { FolderRequest } from '../models/request/folderRequest';
|
||||||
import { GroupRequest } from '../models/request/groupRequest';
|
import { GroupRequest } from '../models/request/groupRequest';
|
||||||
import { ImportCiphersRequest } from '../models/request/importCiphersRequest';
|
import { ImportCiphersRequest } from '../models/request/importCiphersRequest';
|
||||||
|
@ -98,6 +99,7 @@ export abstract class ApiService {
|
||||||
urlsSet: boolean;
|
urlsSet: boolean;
|
||||||
apiBaseUrl: string;
|
apiBaseUrl: string;
|
||||||
identityBaseUrl: string;
|
identityBaseUrl: string;
|
||||||
|
eventsBaseUrl: string;
|
||||||
|
|
||||||
setUrls: (urls: EnvironmentUrls) => void;
|
setUrls: (urls: EnvironmentUrls) => void;
|
||||||
postIdentityToken: (request: TokenRequest) => Promise<IdentityTokenResponse | IdentityTwoFactorResponse>;
|
postIdentityToken: (request: TokenRequest) => Promise<IdentityTokenResponse | IdentityTwoFactorResponse>;
|
||||||
|
@ -254,6 +256,7 @@ export abstract class ApiService {
|
||||||
token: string) => Promise<ListResponse<EventResponse>>;
|
token: string) => Promise<ListResponse<EventResponse>>;
|
||||||
getEventsOrganizationUser: (organizationId: string, id: string,
|
getEventsOrganizationUser: (organizationId: string, id: string,
|
||||||
start: string, end: string, token: string) => Promise<ListResponse<EventResponse>>;
|
start: string, end: string, token: string) => Promise<ListResponse<EventResponse>>;
|
||||||
|
postEventsCollect: (request: EventRequest) => Promise<any>;
|
||||||
|
|
||||||
getUserPublicKey: (id: string) => Promise<UserKeyResponse>;
|
getUserPublicKey: (id: string) => Promise<UserKeyResponse>;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ export abstract class EnvironmentService {
|
||||||
identityUrl: string;
|
identityUrl: string;
|
||||||
iconsUrl: string;
|
iconsUrl: string;
|
||||||
notificationsUrl: string;
|
notificationsUrl: string;
|
||||||
|
eventsUrl: string;
|
||||||
|
|
||||||
getWebVaultUrl: () => string;
|
getWebVaultUrl: () => string;
|
||||||
setUrlsFromStorage: () => Promise<void>;
|
setUrlsFromStorage: () => Promise<void>;
|
||||||
|
|
|
@ -6,6 +6,7 @@ export enum EventType {
|
||||||
User_Recovered2fa = 1004,
|
User_Recovered2fa = 1004,
|
||||||
User_FailedLogIn = 1005,
|
User_FailedLogIn = 1005,
|
||||||
User_FailedLogIn2fa = 1006,
|
User_FailedLogIn2fa = 1006,
|
||||||
|
User_ExportedVault = 1007,
|
||||||
|
|
||||||
Cipher_Created = 1100,
|
Cipher_Created = 1100,
|
||||||
Cipher_Updated = 1101,
|
Cipher_Updated = 1101,
|
||||||
|
@ -14,6 +15,12 @@ export enum EventType {
|
||||||
Cipher_AttachmentDeleted = 1104,
|
Cipher_AttachmentDeleted = 1104,
|
||||||
Cipher_Shared = 1105,
|
Cipher_Shared = 1105,
|
||||||
Cipher_UpdatedCollections = 1106,
|
Cipher_UpdatedCollections = 1106,
|
||||||
|
Cipher_ClientViewed = 1107,
|
||||||
|
Cipher_ClientToggledPasswordVisible = 1108,
|
||||||
|
Cipher_ClientToggledHiddenFieldVisible = 1109,
|
||||||
|
Cipher_ClientCopiedPassword = 1110,
|
||||||
|
Cipher_ClientCopedHiddenField = 1111,
|
||||||
|
Cipher_ClientAutofilled = 1112,
|
||||||
|
|
||||||
Collection_Created = 1300,
|
Collection_Created = 1300,
|
||||||
Collection_Updated = 1301,
|
Collection_Updated = 1301,
|
||||||
|
|
|
@ -2,4 +2,5 @@ export class EnvironmentUrls {
|
||||||
base: string;
|
base: string;
|
||||||
api: string;
|
api: string;
|
||||||
identity: string;
|
identity: string;
|
||||||
|
events: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
import { EventType } from '../../enums/eventType';
|
||||||
|
|
||||||
|
export class EventRequest {
|
||||||
|
type: EventType;
|
||||||
|
cipherId: string;
|
||||||
|
}
|
|
@ -18,6 +18,7 @@ import { CollectionRequest } from '../models/request/collectionRequest';
|
||||||
import { DeleteRecoverRequest } from '../models/request/deleteRecoverRequest';
|
import { DeleteRecoverRequest } from '../models/request/deleteRecoverRequest';
|
||||||
import { EmailRequest } from '../models/request/emailRequest';
|
import { EmailRequest } from '../models/request/emailRequest';
|
||||||
import { EmailTokenRequest } from '../models/request/emailTokenRequest';
|
import { EmailTokenRequest } from '../models/request/emailTokenRequest';
|
||||||
|
import { EventRequest } from '../models/request/eventRequest';
|
||||||
import { FolderRequest } from '../models/request/folderRequest';
|
import { FolderRequest } from '../models/request/folderRequest';
|
||||||
import { GroupRequest } from '../models/request/groupRequest';
|
import { GroupRequest } from '../models/request/groupRequest';
|
||||||
import { ImportCiphersRequest } from '../models/request/importCiphersRequest';
|
import { ImportCiphersRequest } from '../models/request/importCiphersRequest';
|
||||||
|
@ -105,6 +106,7 @@ export class ApiService implements ApiServiceAbstraction {
|
||||||
urlsSet: boolean = false;
|
urlsSet: boolean = false;
|
||||||
apiBaseUrl: string;
|
apiBaseUrl: string;
|
||||||
identityBaseUrl: string;
|
identityBaseUrl: string;
|
||||||
|
eventsBaseUrl: string;
|
||||||
|
|
||||||
private deviceType: string;
|
private deviceType: string;
|
||||||
private isWebClient = false;
|
private isWebClient = false;
|
||||||
|
@ -130,24 +132,24 @@ export class ApiService implements ApiServiceAbstraction {
|
||||||
this.usingBaseUrl = true;
|
this.usingBaseUrl = true;
|
||||||
this.apiBaseUrl = urls.base + '/api';
|
this.apiBaseUrl = urls.base + '/api';
|
||||||
this.identityBaseUrl = urls.base + '/identity';
|
this.identityBaseUrl = urls.base + '/identity';
|
||||||
|
this.eventsBaseUrl = urls.base + '/events';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (urls.api != null && urls.identity != null) {
|
|
||||||
this.apiBaseUrl = urls.api;
|
this.apiBaseUrl = urls.api;
|
||||||
this.identityBaseUrl = urls.identity;
|
this.identityBaseUrl = urls.identity;
|
||||||
return;
|
this.eventsBaseUrl = urls.events;
|
||||||
}
|
|
||||||
|
|
||||||
/* tslint:disable */
|
|
||||||
// Local Dev
|
|
||||||
//this.apiBaseUrl = 'http://localhost:4000';
|
|
||||||
//this.identityBaseUrl = 'http://localhost:33656';
|
|
||||||
|
|
||||||
// Production
|
// Production
|
||||||
|
if (this.apiBaseUrl == null) {
|
||||||
this.apiBaseUrl = 'https://api.bitwarden.com';
|
this.apiBaseUrl = 'https://api.bitwarden.com';
|
||||||
|
}
|
||||||
|
if (this.identityBaseUrl == null) {
|
||||||
this.identityBaseUrl = 'https://identity.bitwarden.com';
|
this.identityBaseUrl = 'https://identity.bitwarden.com';
|
||||||
/* tslint:enable */
|
}
|
||||||
|
if (this.eventsBaseUrl == null) {
|
||||||
|
this.eventsBaseUrl = 'https://events.bitwarden.com';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auth APIs
|
// Auth APIs
|
||||||
|
@ -839,6 +841,25 @@ export class ApiService implements ApiServiceAbstraction {
|
||||||
return new ListResponse(r, EventResponse);
|
return new ListResponse(r, EventResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async postEventsCollect(request: EventRequest): Promise<any> {
|
||||||
|
const authHeader = await this.getActiveBearerToken();
|
||||||
|
const headers = new Headers({
|
||||||
|
'Device-Type': this.deviceType,
|
||||||
|
'Authorization': 'Bearer ' + authHeader,
|
||||||
|
'Content-Type': 'application/json; charset=utf-8',
|
||||||
|
});
|
||||||
|
const response = await this.fetch(new Request(this.eventsBaseUrl + '/collect', {
|
||||||
|
cache: 'no-cache',
|
||||||
|
credentials: this.getCredentials(),
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(request),
|
||||||
|
headers: headers,
|
||||||
|
}));
|
||||||
|
if (response.status !== 200) {
|
||||||
|
return Promise.reject('Event post failed.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// User APIs
|
// User APIs
|
||||||
|
|
||||||
async getUserPublicKey(id: string): Promise<UserKeyResponse> {
|
async getUserPublicKey(id: string): Promise<UserKeyResponse> {
|
||||||
|
|
|
@ -14,6 +14,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
||||||
identityUrl: string;
|
identityUrl: string;
|
||||||
iconsUrl: string;
|
iconsUrl: string;
|
||||||
notificationsUrl: string;
|
notificationsUrl: string;
|
||||||
|
eventsUrl: string;
|
||||||
|
|
||||||
constructor(private apiService: ApiService, private storageService: StorageService,
|
constructor(private apiService: ApiService, private storageService: StorageService,
|
||||||
private notificationsService: NotificationsService) { }
|
private notificationsService: NotificationsService) { }
|
||||||
|
@ -35,6 +36,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
||||||
identity: null,
|
identity: null,
|
||||||
icons: null,
|
icons: null,
|
||||||
notifications: null,
|
notifications: null,
|
||||||
|
events: null,
|
||||||
webVault: null,
|
webVault: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -51,6 +53,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
||||||
this.identityUrl = envUrls.identity = urls.identity;
|
this.identityUrl = envUrls.identity = urls.identity;
|
||||||
this.iconsUrl = urls.icons;
|
this.iconsUrl = urls.icons;
|
||||||
this.notificationsUrl = urls.notifications;
|
this.notificationsUrl = urls.notifications;
|
||||||
|
this.eventsUrl = envUrls.events = urls.events;
|
||||||
this.apiService.setUrls(envUrls);
|
this.apiService.setUrls(envUrls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +64,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
||||||
urls.identity = this.formatUrl(urls.identity);
|
urls.identity = this.formatUrl(urls.identity);
|
||||||
urls.icons = this.formatUrl(urls.icons);
|
urls.icons = this.formatUrl(urls.icons);
|
||||||
urls.notifications = this.formatUrl(urls.notifications);
|
urls.notifications = this.formatUrl(urls.notifications);
|
||||||
|
urls.events = this.formatUrl(urls.events);
|
||||||
|
|
||||||
await this.storageService.save(ConstantsService.environmentUrlsKey, {
|
await this.storageService.save(ConstantsService.environmentUrlsKey, {
|
||||||
base: urls.base,
|
base: urls.base,
|
||||||
|
@ -69,6 +73,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
||||||
webVault: urls.webVault,
|
webVault: urls.webVault,
|
||||||
icons: urls.icons,
|
icons: urls.icons,
|
||||||
notifications: urls.notifications,
|
notifications: urls.notifications,
|
||||||
|
events: urls.events,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.baseUrl = urls.base;
|
this.baseUrl = urls.base;
|
||||||
|
@ -77,6 +82,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
||||||
this.identityUrl = urls.identity;
|
this.identityUrl = urls.identity;
|
||||||
this.iconsUrl = urls.icons;
|
this.iconsUrl = urls.icons;
|
||||||
this.notificationsUrl = urls.notifications;
|
this.notificationsUrl = urls.notifications;
|
||||||
|
this.eventsUrl = urls.events;
|
||||||
|
|
||||||
const envUrls = new EnvironmentUrls();
|
const envUrls = new EnvironmentUrls();
|
||||||
if (this.baseUrl) {
|
if (this.baseUrl) {
|
||||||
|
@ -84,6 +90,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
||||||
} else {
|
} else {
|
||||||
envUrls.api = this.apiUrl;
|
envUrls.api = this.apiUrl;
|
||||||
envUrls.identity = this.identityUrl;
|
envUrls.identity = this.identityUrl;
|
||||||
|
envUrls.events = this.eventsUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.apiService.setUrls(envUrls);
|
this.apiService.setUrls(envUrls);
|
||||||
|
|
Loading…
Reference in New Issue