mirror of
https://github.com/bitwarden/browser
synced 2026-01-03 09:03:32 +00:00
setup for client event collection
This commit is contained in:
@@ -18,6 +18,7 @@ import { CollectionRequest } from '../models/request/collectionRequest';
|
||||
import { DeleteRecoverRequest } from '../models/request/deleteRecoverRequest';
|
||||
import { EmailRequest } from '../models/request/emailRequest';
|
||||
import { EmailTokenRequest } from '../models/request/emailTokenRequest';
|
||||
import { EventRequest } from '../models/request/eventRequest';
|
||||
import { FolderRequest } from '../models/request/folderRequest';
|
||||
import { GroupRequest } from '../models/request/groupRequest';
|
||||
import { ImportCiphersRequest } from '../models/request/importCiphersRequest';
|
||||
@@ -105,6 +106,7 @@ export class ApiService implements ApiServiceAbstraction {
|
||||
urlsSet: boolean = false;
|
||||
apiBaseUrl: string;
|
||||
identityBaseUrl: string;
|
||||
eventsBaseUrl: string;
|
||||
|
||||
private deviceType: string;
|
||||
private isWebClient = false;
|
||||
@@ -130,24 +132,24 @@ export class ApiService implements ApiServiceAbstraction {
|
||||
this.usingBaseUrl = true;
|
||||
this.apiBaseUrl = urls.base + '/api';
|
||||
this.identityBaseUrl = urls.base + '/identity';
|
||||
this.eventsBaseUrl = urls.base + '/events';
|
||||
return;
|
||||
}
|
||||
|
||||
if (urls.api != null && urls.identity != null) {
|
||||
this.apiBaseUrl = urls.api;
|
||||
this.identityBaseUrl = urls.identity;
|
||||
return;
|
||||
}
|
||||
|
||||
/* tslint:disable */
|
||||
// Local Dev
|
||||
//this.apiBaseUrl = 'http://localhost:4000';
|
||||
//this.identityBaseUrl = 'http://localhost:33656';
|
||||
this.apiBaseUrl = urls.api;
|
||||
this.identityBaseUrl = urls.identity;
|
||||
this.eventsBaseUrl = urls.events;
|
||||
|
||||
// Production
|
||||
this.apiBaseUrl = 'https://api.bitwarden.com';
|
||||
this.identityBaseUrl = 'https://identity.bitwarden.com';
|
||||
/* tslint:enable */
|
||||
if (this.apiBaseUrl == null) {
|
||||
this.apiBaseUrl = 'https://api.bitwarden.com';
|
||||
}
|
||||
if (this.identityBaseUrl == null) {
|
||||
this.identityBaseUrl = 'https://identity.bitwarden.com';
|
||||
}
|
||||
if (this.eventsBaseUrl == null) {
|
||||
this.eventsBaseUrl = 'https://events.bitwarden.com';
|
||||
}
|
||||
}
|
||||
|
||||
// Auth APIs
|
||||
@@ -839,6 +841,25 @@ export class ApiService implements ApiServiceAbstraction {
|
||||
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
|
||||
|
||||
async getUserPublicKey(id: string): Promise<UserKeyResponse> {
|
||||
|
||||
@@ -14,6 +14,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
||||
identityUrl: string;
|
||||
iconsUrl: string;
|
||||
notificationsUrl: string;
|
||||
eventsUrl: string;
|
||||
|
||||
constructor(private apiService: ApiService, private storageService: StorageService,
|
||||
private notificationsService: NotificationsService) { }
|
||||
@@ -35,6 +36,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
||||
identity: null,
|
||||
icons: null,
|
||||
notifications: null,
|
||||
events: null,
|
||||
webVault: null,
|
||||
};
|
||||
|
||||
@@ -51,6 +53,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
||||
this.identityUrl = envUrls.identity = urls.identity;
|
||||
this.iconsUrl = urls.icons;
|
||||
this.notificationsUrl = urls.notifications;
|
||||
this.eventsUrl = envUrls.events = urls.events;
|
||||
this.apiService.setUrls(envUrls);
|
||||
}
|
||||
|
||||
@@ -61,6 +64,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
||||
urls.identity = this.formatUrl(urls.identity);
|
||||
urls.icons = this.formatUrl(urls.icons);
|
||||
urls.notifications = this.formatUrl(urls.notifications);
|
||||
urls.events = this.formatUrl(urls.events);
|
||||
|
||||
await this.storageService.save(ConstantsService.environmentUrlsKey, {
|
||||
base: urls.base,
|
||||
@@ -69,6 +73,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
||||
webVault: urls.webVault,
|
||||
icons: urls.icons,
|
||||
notifications: urls.notifications,
|
||||
events: urls.events,
|
||||
});
|
||||
|
||||
this.baseUrl = urls.base;
|
||||
@@ -77,6 +82,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
||||
this.identityUrl = urls.identity;
|
||||
this.iconsUrl = urls.icons;
|
||||
this.notificationsUrl = urls.notifications;
|
||||
this.eventsUrl = urls.events;
|
||||
|
||||
const envUrls = new EnvironmentUrls();
|
||||
if (this.baseUrl) {
|
||||
@@ -84,6 +90,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
||||
} else {
|
||||
envUrls.api = this.apiUrl;
|
||||
envUrls.identity = this.identityUrl;
|
||||
envUrls.events = this.eventsUrl;
|
||||
}
|
||||
|
||||
this.apiService.setUrls(envUrls);
|
||||
|
||||
Reference in New Issue
Block a user