2018-06-13 20:08:43 +02:00
|
|
|
import { DeviceType } from '../enums/deviceType';
|
2018-01-09 22:19:55 +01:00
|
|
|
|
2018-02-19 19:07:19 +01:00
|
|
|
import { ApiService as ApiServiceAbstraction } from '../abstractions/api.service';
|
|
|
|
import { PlatformUtilsService } from '../abstractions/platformUtils.service';
|
|
|
|
import { TokenService } from '../abstractions/token.service';
|
|
|
|
|
|
|
|
import { EnvironmentUrls } from '../models/domain/environmentUrls';
|
|
|
|
|
2018-06-12 23:12:27 +02:00
|
|
|
import { CipherBulkDeleteRequest } from '../models/request/cipherBulkDeleteRequest';
|
|
|
|
import { CipherBulkMoveRequest } from '../models/request/cipherBulkMoveRequest';
|
2018-06-13 06:02:15 +02:00
|
|
|
import { CipherBulkShareRequest } from '../models/request/cipherBulkShareRequest';
|
2018-06-12 19:07:06 +02:00
|
|
|
import { CipherCollectionsRequest } from '../models/request/cipherCollectionsRequest';
|
2018-02-19 19:07:19 +01:00
|
|
|
import { CipherRequest } from '../models/request/cipherRequest';
|
2018-06-12 17:45:02 +02:00
|
|
|
import { CipherShareRequest } from '../models/request/cipherShareRequest';
|
2018-07-06 18:40:43 +02:00
|
|
|
import { CollectionRequest } from '../models/request/collectionRequest';
|
2018-07-13 21:55:02 +02:00
|
|
|
import { DeleteRecoverRequest } from '../models/request/deleteRecoverRequest';
|
2018-06-21 20:28:49 +02:00
|
|
|
import { EmailRequest } from '../models/request/emailRequest';
|
|
|
|
import { EmailTokenRequest } from '../models/request/emailTokenRequest';
|
2018-02-19 19:07:19 +01:00
|
|
|
import { FolderRequest } from '../models/request/folderRequest';
|
2018-07-06 18:40:43 +02:00
|
|
|
import { GroupRequest } from '../models/request/groupRequest';
|
2018-06-23 21:41:22 +02:00
|
|
|
import { ImportCiphersRequest } from '../models/request/importCiphersRequest';
|
2018-04-30 23:00:31 +02:00
|
|
|
import { ImportDirectoryRequest } from '../models/request/importDirectoryRequest';
|
2018-06-23 21:41:22 +02:00
|
|
|
import { ImportOrganizationCiphersRequest } from '../models/request/importOrganizationCiphersRequest';
|
2018-07-03 18:06:01 +02:00
|
|
|
import { KeysRequest } from '../models/request/keysRequest';
|
2018-07-02 21:36:32 +02:00
|
|
|
import { OrganizationCreateRequest } from '../models/request/organizationCreateRequest';
|
2018-07-16 18:30:45 +02:00
|
|
|
import { OrganizationUpdateRequest } from '../models/request/organizationUpdateRequest';
|
2018-07-10 19:03:24 +02:00
|
|
|
import { OrganizationUserAcceptRequest } from '../models/request/organizationUserAcceptRequest';
|
|
|
|
import { OrganizationUserConfirmRequest } from '../models/request/organizationUserConfirmRequest';
|
|
|
|
import { OrganizationUserInviteRequest } from '../models/request/organizationUserInviteRequest';
|
|
|
|
import { OrganizationUserUpdateGroupsRequest } from '../models/request/organizationUserUpdateGroupsRequest';
|
|
|
|
import { OrganizationUserUpdateRequest } from '../models/request/organizationUserUpdateRequest';
|
2018-02-19 19:07:19 +01:00
|
|
|
import { PasswordHintRequest } from '../models/request/passwordHintRequest';
|
2018-06-21 20:28:49 +02:00
|
|
|
import { PasswordRequest } from '../models/request/passwordRequest';
|
2018-06-21 23:15:43 +02:00
|
|
|
import { PasswordVerificationRequest } from '../models/request/passwordVerificationRequest';
|
2018-06-30 19:22:21 +02:00
|
|
|
import { PaymentRequest } from '../models/request/paymentRequest';
|
2018-02-19 19:07:19 +01:00
|
|
|
import { RegisterRequest } from '../models/request/registerRequest';
|
2018-07-17 18:05:19 +02:00
|
|
|
import { SeatRequest } from '../models/request/seatRequest';
|
2018-06-30 05:40:10 +02:00
|
|
|
import { StorageRequest } from '../models/request/storageRequest';
|
2018-02-19 19:07:19 +01:00
|
|
|
import { TokenRequest } from '../models/request/tokenRequest';
|
|
|
|
import { TwoFactorEmailRequest } from '../models/request/twoFactorEmailRequest';
|
2018-06-26 21:17:14 +02:00
|
|
|
import { TwoFactorProviderRequest } from '../models/request/twoFactorProviderRequest';
|
|
|
|
import { TwoFactorRecoveryRequest } from '../models/request/twoFactorRecoveryRequest';
|
2018-06-26 05:04:59 +02:00
|
|
|
import { UpdateDomainsRequest } from '../models/request/updateDomainsRequest';
|
2018-07-17 23:22:45 +02:00
|
|
|
import { UpdateKeyRequest } from '../models/request/updateKeyRequest';
|
2018-06-21 05:40:59 +02:00
|
|
|
import { UpdateProfileRequest } from '../models/request/updateProfileRequest';
|
2018-06-26 21:17:14 +02:00
|
|
|
import { UpdateTwoFactorAuthenticatorRequest } from '../models/request/updateTwoFactorAuthenticatorRequest';
|
|
|
|
import { UpdateTwoFactorDuoRequest } from '../models/request/updateTwoFactorDuoRequest';
|
|
|
|
import { UpdateTwoFactorEmailRequest } from '../models/request/updateTwoFactorEmailRequest';
|
|
|
|
import { UpdateTwoFactorU2fRequest } from '../models/request/updateTwoFactorU2fRequest';
|
|
|
|
import { UpdateTwoFactorYubioOtpRequest } from '../models/request/updateTwoFactorYubioOtpRequest';
|
2018-07-17 17:04:19 +02:00
|
|
|
import { VerifyBankRequest } from '../models/request/verifyBankRequest';
|
2018-07-13 21:55:02 +02:00
|
|
|
import { VerifyDeleteRecoverRequest } from '../models/request/verifyDeleteRecoverRequest';
|
2018-07-12 17:35:04 +02:00
|
|
|
import { VerifyEmailRequest } from '../models/request/verifyEmailRequest';
|
2018-02-19 19:07:19 +01:00
|
|
|
|
2018-06-29 17:29:24 +02:00
|
|
|
import { BillingResponse } from '../models/response/billingResponse';
|
2018-02-19 19:07:19 +01:00
|
|
|
import { CipherResponse } from '../models/response/cipherResponse';
|
2018-07-06 18:40:43 +02:00
|
|
|
import {
|
|
|
|
CollectionGroupDetailsResponse,
|
|
|
|
CollectionResponse,
|
|
|
|
} from '../models/response/collectionResponse';
|
|
|
|
import { CollectionUserResponse } from '../models/response/collectionUserResponse';
|
2018-06-26 05:04:59 +02:00
|
|
|
import { DomainsResponse } from '../models/response/domainsResponse';
|
2018-02-19 19:07:19 +01:00
|
|
|
import { ErrorResponse } from '../models/response/errorResponse';
|
2018-07-07 05:06:38 +02:00
|
|
|
import { EventResponse } from '../models/response/eventResponse';
|
2018-02-19 19:07:19 +01:00
|
|
|
import { FolderResponse } from '../models/response/folderResponse';
|
2018-07-06 18:40:43 +02:00
|
|
|
import {
|
|
|
|
GroupDetailsResponse,
|
|
|
|
GroupResponse,
|
|
|
|
} from '../models/response/groupResponse';
|
|
|
|
import { GroupUserResponse } from '../models/response/groupUserResponse';
|
2018-02-19 19:07:19 +01:00
|
|
|
import { IdentityTokenResponse } from '../models/response/identityTokenResponse';
|
|
|
|
import { IdentityTwoFactorResponse } from '../models/response/identityTwoFactorResponse';
|
2018-06-26 21:17:14 +02:00
|
|
|
import { ListResponse } from '../models/response/listResponse';
|
2018-07-16 23:16:15 +02:00
|
|
|
import { OrganizationBillingResponse } from '../models/response/organizationBillingResponse';
|
2018-07-02 21:36:32 +02:00
|
|
|
import { OrganizationResponse } from '../models/response/organizationResponse';
|
2018-07-10 19:03:24 +02:00
|
|
|
import {
|
|
|
|
OrganizationUserDetailsResponse,
|
|
|
|
OrganizationUserUserDetailsResponse,
|
|
|
|
} from '../models/response/organizationUserResponse';
|
2018-05-03 18:46:49 +02:00
|
|
|
import { ProfileResponse } from '../models/response/profileResponse';
|
2018-02-19 19:07:19 +01:00
|
|
|
import { SyncResponse } from '../models/response/syncResponse';
|
2018-06-26 21:17:14 +02:00
|
|
|
import { TwoFactorAuthenticatorResponse } from '../models/response/twoFactorAuthenticatorResponse';
|
|
|
|
import { TwoFactorDuoResponse } from '../models/response/twoFactorDuoResponse';
|
|
|
|
import { TwoFactorEmailResponse } from '../models/response/twoFactorEmailResponse';
|
|
|
|
import { TwoFactorProviderResponse } from '../models/response/twoFactorProviderResponse';
|
|
|
|
import { TwoFactorRecoverResponse } from '../models/response/twoFactorRescoverResponse';
|
|
|
|
import { TwoFactorU2fResponse } from '../models/response/twoFactorU2fResponse';
|
|
|
|
import { TwoFactorYubiKeyResponse } from '../models/response/twoFactorYubiKeyResponse';
|
2018-07-11 19:30:06 +02:00
|
|
|
import { UserKeyResponse } from '../models/response/userKeyResponse';
|
2018-01-09 22:19:55 +01:00
|
|
|
|
2018-01-31 20:27:11 +01:00
|
|
|
export class ApiService implements ApiServiceAbstraction {
|
2018-01-09 22:19:55 +01:00
|
|
|
urlsSet: boolean = false;
|
2018-06-14 04:12:23 +02:00
|
|
|
apiBaseUrl: string;
|
|
|
|
identityBaseUrl: string;
|
2018-06-14 04:09:47 +02:00
|
|
|
|
|
|
|
private deviceType: string;
|
|
|
|
private isWebClient = false;
|
2018-06-26 04:47:01 +02:00
|
|
|
private isDesktopClient = false;
|
2018-06-14 04:09:47 +02:00
|
|
|
private usingBaseUrl = false;
|
2018-01-09 22:19:55 +01:00
|
|
|
|
2018-03-21 16:19:05 +01:00
|
|
|
constructor(private tokenService: TokenService, private platformUtilsService: PlatformUtilsService,
|
2018-05-16 05:40:15 +02:00
|
|
|
private logoutCallback: (expired: boolean) => Promise<void>) {
|
2018-06-13 20:08:43 +02:00
|
|
|
const device = platformUtilsService.getDevice();
|
|
|
|
this.deviceType = device.toString();
|
2018-07-09 15:04:47 +02:00
|
|
|
this.isWebClient = device === DeviceType.IEBrowser || device === DeviceType.ChromeBrowser ||
|
|
|
|
device === DeviceType.EdgeBrowser || device === DeviceType.FirefoxBrowser ||
|
|
|
|
device === DeviceType.OperaBrowser || device === DeviceType.SafariBrowser ||
|
|
|
|
device === DeviceType.UnknownBrowser || device === DeviceType.VivaldiBrowser;
|
|
|
|
this.isDesktopClient = device === DeviceType.WindowsDesktop || device === DeviceType.MacOsDesktop ||
|
|
|
|
device === DeviceType.LinuxDesktop;
|
2018-01-09 22:19:55 +01:00
|
|
|
}
|
|
|
|
|
2018-01-09 22:23:27 +01:00
|
|
|
setUrls(urls: EnvironmentUrls): void {
|
2018-01-09 22:19:55 +01:00
|
|
|
this.urlsSet = true;
|
|
|
|
|
|
|
|
if (urls.base != null) {
|
2018-06-05 21:45:19 +02:00
|
|
|
this.usingBaseUrl = true;
|
2018-06-14 04:09:47 +02:00
|
|
|
this.apiBaseUrl = urls.base + '/api';
|
2018-01-09 22:19:55 +01:00
|
|
|
this.identityBaseUrl = urls.base + '/identity';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (urls.api != null && urls.identity != null) {
|
2018-06-14 04:09:47 +02:00
|
|
|
this.apiBaseUrl = urls.api;
|
2018-01-09 22:19:55 +01:00
|
|
|
this.identityBaseUrl = urls.identity;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* tslint:disable */
|
2018-06-22 04:12:26 +02:00
|
|
|
// Local Dev
|
2018-06-14 04:09:47 +02:00
|
|
|
//this.apiBaseUrl = 'http://localhost:4000';
|
|
|
|
//this.identityBaseUrl = 'http://localhost:33656';
|
2018-01-09 22:19:55 +01:00
|
|
|
|
|
|
|
// Production
|
2018-06-22 04:12:26 +02:00
|
|
|
this.apiBaseUrl = 'https://api.bitwarden.com';
|
|
|
|
this.identityBaseUrl = 'https://identity.bitwarden.com';
|
2018-01-09 22:19:55 +01:00
|
|
|
/* tslint:enable */
|
|
|
|
}
|
|
|
|
|
|
|
|
// Auth APIs
|
|
|
|
|
2018-02-02 04:55:49 +01:00
|
|
|
async postIdentityToken(request: TokenRequest): Promise<IdentityTokenResponse | IdentityTwoFactorResponse> {
|
2018-07-08 05:48:58 +02:00
|
|
|
const response = await this.fetch(new Request(this.identityBaseUrl + '/connect/token', {
|
2018-03-21 16:19:05 +01:00
|
|
|
body: this.qsStringify(request.toIdentityToken(this.platformUtilsService.identityClientId)),
|
2018-06-05 21:45:19 +02:00
|
|
|
credentials: this.getCredentials(),
|
2018-01-09 22:19:55 +01:00
|
|
|
cache: 'no-cache',
|
|
|
|
headers: new Headers({
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
|
|
|
|
'Accept': 'application/json',
|
|
|
|
'Device-Type': this.deviceType,
|
|
|
|
}),
|
|
|
|
method: 'POST',
|
|
|
|
}));
|
|
|
|
|
|
|
|
let responseJson: any = null;
|
|
|
|
const typeHeader = response.headers.get('content-type');
|
|
|
|
if (typeHeader != null && typeHeader.indexOf('application/json') > -1) {
|
|
|
|
responseJson = await response.json();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (responseJson != null) {
|
|
|
|
if (response.status === 200) {
|
|
|
|
return new IdentityTokenResponse(responseJson);
|
|
|
|
} else if (response.status === 400 && responseJson.TwoFactorProviders2 &&
|
|
|
|
Object.keys(responseJson.TwoFactorProviders2).length) {
|
|
|
|
await this.tokenService.clearTwoFactorToken(request.email);
|
2018-02-02 04:55:49 +01:00
|
|
|
return new IdentityTwoFactorResponse(responseJson);
|
2018-01-09 22:19:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.reject(new ErrorResponse(responseJson, response.status, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
async refreshIdentityToken(): Promise<any> {
|
|
|
|
try {
|
|
|
|
await this.doRefreshToken();
|
|
|
|
} catch (e) {
|
|
|
|
return Promise.reject(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Account APIs
|
|
|
|
|
2018-05-03 18:46:49 +02:00
|
|
|
async getProfile(): Promise<ProfileResponse> {
|
2018-06-26 04:42:57 +02:00
|
|
|
const r = await this.send('GET', '/accounts/profile', null, true, true);
|
|
|
|
return new ProfileResponse(r);
|
2018-05-03 18:46:49 +02:00
|
|
|
}
|
|
|
|
|
2018-06-29 17:29:24 +02:00
|
|
|
async getUserBilling(): Promise<BillingResponse> {
|
|
|
|
const r = await this.send('GET', '/accounts/billing', null, true, true);
|
|
|
|
return new BillingResponse(r);
|
|
|
|
}
|
|
|
|
|
2018-06-21 05:40:59 +02:00
|
|
|
async putProfile(request: UpdateProfileRequest): Promise<ProfileResponse> {
|
2018-06-26 04:42:57 +02:00
|
|
|
const r = await this.send('PUT', '/accounts/profile', request, true, true);
|
|
|
|
return new ProfileResponse(r);
|
2018-06-21 05:40:59 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
postEmailToken(request: EmailTokenRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/accounts/email-token', request, true, false);
|
2018-06-21 20:28:49 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
postEmail(request: EmailRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/accounts/email', request, true, false);
|
2018-06-21 20:28:49 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
postPassword(request: PasswordRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/accounts/password', request, true, false);
|
2018-06-21 20:28:49 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
postSecurityStamp(request: PasswordVerificationRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/accounts/security-stamp', request, true, false);
|
2018-06-21 23:15:43 +02:00
|
|
|
}
|
|
|
|
|
2018-07-16 23:16:15 +02:00
|
|
|
deleteAccount(request: PasswordVerificationRequest): Promise<any> {
|
|
|
|
return this.send('DELETE', '/accounts/delete', request, true, false);
|
2018-06-21 23:15:43 +02:00
|
|
|
}
|
|
|
|
|
2018-01-09 22:19:55 +01:00
|
|
|
async getAccountRevisionDate(): Promise<number> {
|
2018-06-26 04:42:57 +02:00
|
|
|
const r = await this.send('GET', '/accounts/revision-date', null, true, true);
|
|
|
|
return r as number;
|
2018-01-09 22:19:55 +01:00
|
|
|
}
|
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
postPasswordHint(request: PasswordHintRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/accounts/password-hint', request, false, false);
|
2018-01-09 22:19:55 +01:00
|
|
|
}
|
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
postRegister(request: RegisterRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/accounts/register', request, false, false);
|
2018-01-09 22:19:55 +01:00
|
|
|
}
|
|
|
|
|
2018-06-29 05:05:25 +02:00
|
|
|
postPremium(data: FormData): Promise<any> {
|
2018-06-29 19:58:01 +02:00
|
|
|
return this.send('POST', '/accounts/premium', data, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
postReinstatePremium(): Promise<any> {
|
|
|
|
return this.send('POST', '/accounts/reinstate-premium', null, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
postCancelPremium(): Promise<any> {
|
|
|
|
return this.send('POST', '/accounts/cancel-premium', null, true, false);
|
2018-06-29 05:05:25 +02:00
|
|
|
}
|
|
|
|
|
2018-06-30 05:40:10 +02:00
|
|
|
postAccountStorage(request: StorageRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/accounts/storage', request, true, false);
|
|
|
|
}
|
|
|
|
|
2018-06-30 19:22:21 +02:00
|
|
|
postAccountPayment(request: PaymentRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/accounts/payment', request, true, false);
|
|
|
|
}
|
|
|
|
|
2018-07-02 15:53:43 +02:00
|
|
|
postAccountLicense(data: FormData): Promise<any> {
|
|
|
|
return this.send('POST', '/accounts/license', data, true, false);
|
|
|
|
}
|
|
|
|
|
2018-07-03 18:06:01 +02:00
|
|
|
postAccountKeys(request: KeysRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/accounts/keys', request, true, false);
|
|
|
|
}
|
|
|
|
|
2018-07-17 23:22:45 +02:00
|
|
|
postAccountKey(request: UpdateKeyRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/accounts/key', request, true, false);
|
|
|
|
}
|
|
|
|
|
2018-07-12 17:35:04 +02:00
|
|
|
postAccountVerifyEmail(): Promise<any> {
|
|
|
|
return this.send('POST', '/accounts/verify-email', null, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
postAccountVerifyEmailToken(request: VerifyEmailRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/accounts/verify-email-token', request, false, false);
|
|
|
|
}
|
|
|
|
|
2018-07-13 21:55:02 +02:00
|
|
|
postAccountRecoverDelete(request: DeleteRecoverRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/accounts/delete-recover', request, false, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
postAccountRecoverDeleteToken(request: VerifyDeleteRecoverRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/accounts/delete-recover-token', request, false, false);
|
|
|
|
}
|
|
|
|
|
2018-01-09 22:19:55 +01:00
|
|
|
// Folder APIs
|
|
|
|
|
|
|
|
async postFolder(request: FolderRequest): Promise<FolderResponse> {
|
2018-06-26 04:42:57 +02:00
|
|
|
const r = await this.send('POST', '/folders', request, true, true);
|
|
|
|
return new FolderResponse(r);
|
2018-01-09 22:19:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async putFolder(id: string, request: FolderRequest): Promise<FolderResponse> {
|
2018-06-26 04:42:57 +02:00
|
|
|
const r = await this.send('PUT', '/folders/' + id, request, true, true);
|
|
|
|
return new FolderResponse(r);
|
2018-01-09 22:19:55 +01:00
|
|
|
}
|
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
deleteFolder(id: string): Promise<any> {
|
|
|
|
return this.send('DELETE', '/folders/' + id, null, true, false);
|
2018-01-09 22:19:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cipher APIs
|
|
|
|
|
2018-07-05 15:42:13 +02:00
|
|
|
async getCipher(id: string): Promise<CipherResponse> {
|
|
|
|
const r = await this.send('GET', '/ciphers/' + id, null, true, true);
|
|
|
|
return new CipherResponse(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getCipherAdmin(id: string): Promise<CipherResponse> {
|
|
|
|
const r = await this.send('GET', '/ciphers/' + id + '/admin', null, true, true);
|
|
|
|
return new CipherResponse(r);
|
|
|
|
}
|
|
|
|
|
2018-07-04 05:33:15 +02:00
|
|
|
async getCiphersOrganization(organizationId: string): Promise<ListResponse<CipherResponse>> {
|
|
|
|
const r = await this.send('GET', '/ciphers/organization-details?organizationId=' + organizationId,
|
|
|
|
null, true, true);
|
|
|
|
return new ListResponse(r, CipherResponse);
|
|
|
|
}
|
|
|
|
|
2018-01-09 22:19:55 +01:00
|
|
|
async postCipher(request: CipherRequest): Promise<CipherResponse> {
|
2018-06-26 04:42:57 +02:00
|
|
|
const r = await this.send('POST', '/ciphers', request, true, true);
|
|
|
|
return new CipherResponse(r);
|
2018-01-09 22:19:55 +01:00
|
|
|
}
|
|
|
|
|
2018-07-05 15:42:13 +02:00
|
|
|
async postCipherAdmin(request: CipherRequest): Promise<CipherResponse> {
|
|
|
|
const r = await this.send('POST', '/ciphers/admin', request, true, true);
|
|
|
|
return new CipherResponse(r);
|
|
|
|
}
|
|
|
|
|
2018-01-09 22:19:55 +01:00
|
|
|
async putCipher(id: string, request: CipherRequest): Promise<CipherResponse> {
|
2018-06-26 04:42:57 +02:00
|
|
|
const r = await this.send('PUT', '/ciphers/' + id, request, true, true);
|
|
|
|
return new CipherResponse(r);
|
2018-01-09 22:19:55 +01:00
|
|
|
}
|
|
|
|
|
2018-07-05 15:42:13 +02:00
|
|
|
async putCipherAdmin(id: string, request: CipherRequest): Promise<CipherResponse> {
|
|
|
|
const r = await this.send('PUT', '/ciphers/' + id + '/admin', request, true, true);
|
|
|
|
return new CipherResponse(r);
|
|
|
|
}
|
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
deleteCipher(id: string): Promise<any> {
|
|
|
|
return this.send('DELETE', '/ciphers/' + id, null, true, false);
|
2018-06-12 19:07:06 +02:00
|
|
|
}
|
|
|
|
|
2018-07-05 15:42:13 +02:00
|
|
|
deleteCipherAdmin(id: string): Promise<any> {
|
|
|
|
return this.send('DELETE', '/ciphers/' + id + '/admin', null, true, false);
|
|
|
|
}
|
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
deleteManyCiphers(request: CipherBulkDeleteRequest): Promise<any> {
|
|
|
|
return this.send('DELETE', '/ciphers', request, true, false);
|
2018-06-12 23:12:27 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
putMoveCiphers(request: CipherBulkMoveRequest): Promise<any> {
|
|
|
|
return this.send('PUT', '/ciphers/move', request, true, false);
|
2018-06-12 23:12:27 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
putShareCipher(id: string, request: CipherShareRequest): Promise<any> {
|
|
|
|
return this.send('PUT', '/ciphers/' + id + '/share', request, true, false);
|
2018-06-13 06:02:15 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
putShareCiphers(request: CipherBulkShareRequest): Promise<any> {
|
|
|
|
return this.send('PUT', '/ciphers/share', request, true, false);
|
2018-06-12 17:45:02 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
putCipherCollections(id: string, request: CipherCollectionsRequest): Promise<any> {
|
|
|
|
return this.send('PUT', '/ciphers/' + id + '/collections', request, true, false);
|
2018-01-09 22:19:55 +01:00
|
|
|
}
|
|
|
|
|
2018-07-05 15:42:13 +02:00
|
|
|
putCipherCollectionsAdmin(id: string, request: CipherCollectionsRequest): Promise<any> {
|
|
|
|
return this.send('PUT', '/ciphers/' + id + '/collections-admin', request, true, false);
|
|
|
|
}
|
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
postPurgeCiphers(request: PasswordVerificationRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/ciphers/purge', request, true, false);
|
2018-06-23 21:41:22 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
postImportCiphers(request: ImportCiphersRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/ciphers/import', request, true, false);
|
2018-06-23 21:41:22 +02:00
|
|
|
}
|
|
|
|
|
2018-07-06 05:38:27 +02:00
|
|
|
postImportOrganizationCiphers(organizationId: string, request: ImportOrganizationCiphersRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/ciphers/import-organization?organizationId=' + organizationId, request, true, false);
|
2018-06-21 23:15:43 +02:00
|
|
|
}
|
|
|
|
|
2018-01-09 22:19:55 +01:00
|
|
|
// Attachments APIs
|
|
|
|
|
|
|
|
async postCipherAttachment(id: string, data: FormData): Promise<CipherResponse> {
|
2018-06-26 04:42:57 +02:00
|
|
|
const r = await this.send('POST', '/ciphers/' + id + '/attachment', data, true, true);
|
|
|
|
return new CipherResponse(r);
|
2018-06-12 17:45:02 +02:00
|
|
|
}
|
|
|
|
|
2018-07-05 15:42:13 +02:00
|
|
|
async postCipherAttachmentAdmin(id: string, data: FormData): Promise<CipherResponse> {
|
|
|
|
const r = await this.send('POST', '/ciphers/' + id + '/attachment-admin', data, true, true);
|
|
|
|
return new CipherResponse(r);
|
|
|
|
}
|
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
deleteCipherAttachment(id: string, attachmentId: string): Promise<any> {
|
|
|
|
return this.send('DELETE', '/ciphers/' + id + '/attachment/' + attachmentId, null, true, false);
|
2018-06-12 19:07:06 +02:00
|
|
|
}
|
|
|
|
|
2018-07-05 15:42:13 +02:00
|
|
|
deleteCipherAttachmentAdmin(id: string, attachmentId: string): Promise<any> {
|
|
|
|
return this.send('DELETE', '/ciphers/' + id + '/attachment/' + attachmentId + '/admin', null, true, false);
|
|
|
|
}
|
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
postShareCipherAttachment(id: string, attachmentId: string, data: FormData,
|
2018-06-12 17:45:02 +02:00
|
|
|
organizationId: string): Promise<any> {
|
2018-06-26 04:42:57 +02:00
|
|
|
return this.send('POST', '/ciphers/' + id + '/attachment/' +
|
|
|
|
attachmentId + '/share?organizationId=' + organizationId, data, true, false);
|
2018-01-09 22:19:55 +01:00
|
|
|
}
|
|
|
|
|
2018-07-04 05:33:15 +02:00
|
|
|
// Collections APIs
|
|
|
|
|
2018-07-06 18:40:43 +02:00
|
|
|
async getCollectionDetails(organizationId: string, id: string): Promise<CollectionGroupDetailsResponse> {
|
|
|
|
const r = await this.send('GET', '/organizations/' + organizationId + '/collections/' + id + '/details',
|
|
|
|
null, true, true);
|
|
|
|
return new CollectionGroupDetailsResponse(r);
|
|
|
|
}
|
|
|
|
|
2018-07-04 05:33:15 +02:00
|
|
|
async getCollections(organizationId: string): Promise<ListResponse<CollectionResponse>> {
|
|
|
|
const r = await this.send('GET', '/organizations/' + organizationId + '/collections', null, true, true);
|
|
|
|
return new ListResponse(r, CollectionResponse);
|
|
|
|
}
|
|
|
|
|
2018-07-06 18:40:43 +02:00
|
|
|
async getCollectionUsers(organizationId: string, id: string): Promise<ListResponse<CollectionUserResponse>> {
|
|
|
|
const r = await this.send('GET', '/organizations/' + organizationId + '/collections/' + id + '/users',
|
|
|
|
null, true, true);
|
|
|
|
return new ListResponse(r, CollectionUserResponse);
|
|
|
|
}
|
|
|
|
|
2018-07-09 22:27:03 +02:00
|
|
|
async postCollection(organizationId: string, request: CollectionRequest): Promise<CollectionResponse> {
|
|
|
|
const r = await this.send('POST', '/organizations/' + organizationId + '/collections', request, true, true);
|
2018-07-06 18:40:43 +02:00
|
|
|
return new CollectionResponse(r);
|
|
|
|
}
|
|
|
|
|
2018-07-09 22:27:03 +02:00
|
|
|
async putCollection(organizationId: string, id: string, request: CollectionRequest): Promise<CollectionResponse> {
|
|
|
|
const r = await this.send('PUT', '/organizations/' + organizationId + '/collections/' + id,
|
|
|
|
request, true, true);
|
2018-07-06 18:40:43 +02:00
|
|
|
return new CollectionResponse(r);
|
|
|
|
}
|
|
|
|
|
2018-07-09 22:27:03 +02:00
|
|
|
deleteCollection(organizationId: string, id: string): Promise<any> {
|
|
|
|
return this.send('DELETE', '/organizations/' + organizationId + '/collections/' + id, null, true, false);
|
2018-07-06 18:40:43 +02:00
|
|
|
}
|
|
|
|
|
2018-07-10 05:47:12 +02:00
|
|
|
deleteCollectionUser(organizationId: string, id: string, organizationUserId: string): Promise<any> {
|
|
|
|
return this.send('DELETE',
|
|
|
|
'/organizations/' + organizationId + '/collections/' + id + '/user/' + organizationUserId,
|
|
|
|
null, true, false);
|
|
|
|
}
|
|
|
|
|
2018-07-06 18:40:43 +02:00
|
|
|
// Groups APIs
|
|
|
|
|
|
|
|
async getGroupDetails(organizationId: string, id: string): Promise<GroupDetailsResponse> {
|
|
|
|
const r = await this.send('GET', '/organizations/' + organizationId + '/groups/' + id + '/details',
|
|
|
|
null, true, true);
|
|
|
|
return new GroupDetailsResponse(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getGroups(organizationId: string): Promise<ListResponse<GroupResponse>> {
|
|
|
|
const r = await this.send('GET', '/organizations/' + organizationId + '/groups', null, true, true);
|
|
|
|
return new ListResponse(r, GroupResponse);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getGroupUsers(organizationId: string, id: string): Promise<ListResponse<GroupUserResponse>> {
|
|
|
|
const r = await this.send('GET', '/organizations/' + organizationId + '/groups/' + id + '/users',
|
|
|
|
null, true, true);
|
|
|
|
return new ListResponse(r, GroupUserResponse);
|
|
|
|
}
|
|
|
|
|
2018-07-09 22:27:03 +02:00
|
|
|
async postGroup(organizationId: string, request: GroupRequest): Promise<GroupResponse> {
|
|
|
|
const r = await this.send('POST', '/organizations/' + organizationId + '/groups', request, true, true);
|
2018-07-06 18:40:43 +02:00
|
|
|
return new GroupResponse(r);
|
|
|
|
}
|
|
|
|
|
2018-07-09 22:27:03 +02:00
|
|
|
async putGroup(organizationId: string, id: string, request: GroupRequest): Promise<GroupResponse> {
|
|
|
|
const r = await this.send('PUT', '/organizations/' + organizationId + '/groups/' + id, request, true, true);
|
2018-07-06 18:40:43 +02:00
|
|
|
return new GroupResponse(r);
|
|
|
|
}
|
|
|
|
|
2018-07-09 22:27:03 +02:00
|
|
|
deleteGroup(organizationId: string, id: string): Promise<any> {
|
|
|
|
return this.send('DELETE', '/organizations/' + organizationId + '/groups/' + id, null, true, false);
|
2018-07-06 18:40:43 +02:00
|
|
|
}
|
|
|
|
|
2018-07-10 05:47:12 +02:00
|
|
|
deleteGroupUser(organizationId: string, id: string, organizationUserId: string): Promise<any> {
|
|
|
|
return this.send('DELETE',
|
|
|
|
'/organizations/' + organizationId + '/groups/' + id + '/user/' + organizationUserId, null, true, false);
|
|
|
|
}
|
|
|
|
|
2018-07-06 21:00:55 +02:00
|
|
|
// Organization User APIs
|
|
|
|
|
2018-07-10 19:03:24 +02:00
|
|
|
async getOrganizationUser(organizationId: string, id: string): Promise<OrganizationUserDetailsResponse> {
|
|
|
|
const r = await this.send('GET', '/organizations/' + organizationId + '/users/' + id, null, true, true);
|
|
|
|
return new OrganizationUserDetailsResponse(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getOrganizationUserGroups(organizationId: string, id: string): Promise<string[]> {
|
|
|
|
const r = await this.send('GET', '/organizations/' + organizationId + '/users/' + id + '/groups',
|
|
|
|
null, true, true);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2018-07-06 21:00:55 +02:00
|
|
|
async getOrganizationUsers(organizationId: string): Promise<ListResponse<OrganizationUserUserDetailsResponse>> {
|
|
|
|
const r = await this.send('GET', '/organizations/' + organizationId + '/users', null, true, true);
|
|
|
|
return new ListResponse(r, OrganizationUserUserDetailsResponse);
|
|
|
|
}
|
|
|
|
|
2018-07-10 19:03:24 +02:00
|
|
|
postOrganizationUserInvite(organizationId: string, request: OrganizationUserInviteRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/organizations/' + organizationId + '/users/invite', request, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
postOrganizationUserReinvite(organizationId: string, id: string): Promise<any> {
|
|
|
|
return this.send('POST', '/organizations/' + organizationId + '/users/' + id + '/reinvite', null, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
postOrganizationUserAccept(organizationId: string, id: string,
|
|
|
|
request: OrganizationUserAcceptRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/organizations/' + organizationId + '/users/' + id + '/accept', request, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
postOrganizationUserConfirm(organizationId: string, id: string,
|
|
|
|
request: OrganizationUserConfirmRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/organizations/' + organizationId + '/users/' + id + '/confirm',
|
|
|
|
request, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
putOrganizationUser(organizationId: string, id: string, request: OrganizationUserUpdateRequest): Promise<any> {
|
|
|
|
return this.send('PUT', '/organizations/' + organizationId + '/users/' + id, request, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
putOrganizationUserGroups(organizationId: string, id: string,
|
|
|
|
request: OrganizationUserUpdateGroupsRequest): Promise<any> {
|
|
|
|
return this.send('PUT', '/organizations/' + organizationId + '/users/' + id + '/groups', request, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteOrganizationUser(organizationId: string, id: string): Promise<any> {
|
|
|
|
return this.send('DELETE', '/organizations/' + organizationId + '/users/' + id, null, true, false);
|
|
|
|
}
|
|
|
|
|
2018-01-09 22:19:55 +01:00
|
|
|
// Sync APIs
|
|
|
|
|
|
|
|
async getSync(): Promise<SyncResponse> {
|
2018-06-26 04:47:01 +02:00
|
|
|
const path = this.isDesktopClient || this.isWebClient ? '/sync?excludeDomains=true' : '/sync';
|
|
|
|
const r = await this.send('GET', path, null, true, true);
|
2018-06-26 04:42:57 +02:00
|
|
|
return new SyncResponse(r);
|
2018-01-09 22:19:55 +01:00
|
|
|
}
|
|
|
|
|
2018-04-30 23:00:31 +02:00
|
|
|
async postImportDirectory(organizationId: string, request: ImportDirectoryRequest): Promise<any> {
|
2018-06-26 04:42:57 +02:00
|
|
|
return this.send('POST', '/organizations/' + organizationId + '/import', request, true, false);
|
|
|
|
}
|
|
|
|
|
2018-06-27 23:50:12 +02:00
|
|
|
// Settings APIs
|
2018-06-26 05:04:59 +02:00
|
|
|
|
|
|
|
async getSettingsDomains(): Promise<DomainsResponse> {
|
|
|
|
const r = await this.send('GET', '/settings/domains', null, true, true);
|
|
|
|
return new DomainsResponse(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
async putSettingsDomains(request: UpdateDomainsRequest): Promise<DomainsResponse> {
|
|
|
|
const r = await this.send('PUT', '/settings/domains', request, true, true);
|
|
|
|
return new DomainsResponse(r);
|
|
|
|
}
|
|
|
|
|
2018-06-27 23:50:12 +02:00
|
|
|
// Two-factor APIs
|
2018-06-26 21:17:14 +02:00
|
|
|
|
|
|
|
async getTwoFactorProviders(): Promise<ListResponse<TwoFactorProviderResponse>> {
|
|
|
|
const r = await this.send('GET', '/two-factor', null, true, true);
|
|
|
|
return new ListResponse(r, TwoFactorProviderResponse);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getTwoFactorAuthenticator(request: PasswordVerificationRequest): Promise<TwoFactorAuthenticatorResponse> {
|
|
|
|
const r = await this.send('POST', '/two-factor/get-authenticator', request, true, true);
|
|
|
|
return new TwoFactorAuthenticatorResponse(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getTwoFactorEmail(request: PasswordVerificationRequest): Promise<TwoFactorEmailResponse> {
|
|
|
|
const r = await this.send('POST', '/two-factor/get-email', request, true, true);
|
|
|
|
return new TwoFactorEmailResponse(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getTwoFactorDuo(request: PasswordVerificationRequest): Promise<TwoFactorDuoResponse> {
|
|
|
|
const r = await this.send('POST', '/two-factor/get-duo', request, true, true);
|
|
|
|
return new TwoFactorDuoResponse(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getTwoFactorYubiKey(request: PasswordVerificationRequest): Promise<TwoFactorYubiKeyResponse> {
|
|
|
|
const r = await this.send('POST', '/two-factor/get-yubikey', request, true, true);
|
|
|
|
return new TwoFactorYubiKeyResponse(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getTwoFactorU2f(request: PasswordVerificationRequest): Promise<TwoFactorU2fResponse> {
|
|
|
|
const r = await this.send('POST', '/two-factor/get-u2f', request, true, true);
|
|
|
|
return new TwoFactorU2fResponse(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getTwoFactorRecover(request: PasswordVerificationRequest): Promise<TwoFactorRecoverResponse> {
|
|
|
|
const r = await this.send('POST', '/two-factor/get-recover', request, true, true);
|
|
|
|
return new TwoFactorRecoverResponse(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
async putTwoFactorAuthenticator(
|
|
|
|
request: UpdateTwoFactorAuthenticatorRequest): Promise<TwoFactorAuthenticatorResponse> {
|
|
|
|
const r = await this.send('PUT', '/two-factor/authenticator', request, true, true);
|
|
|
|
return new TwoFactorAuthenticatorResponse(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
async putTwoFactorEmail(request: UpdateTwoFactorEmailRequest): Promise<TwoFactorEmailResponse> {
|
|
|
|
const r = await this.send('PUT', '/two-factor/email', request, true, true);
|
|
|
|
return new TwoFactorEmailResponse(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
async putTwoFactorDuo(request: UpdateTwoFactorDuoRequest): Promise<TwoFactorDuoResponse> {
|
|
|
|
const r = await this.send('PUT', '/two-factor/duo', request, true, true);
|
|
|
|
return new TwoFactorDuoResponse(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
async putTwoFactorYubiKey(request: UpdateTwoFactorYubioOtpRequest): Promise<TwoFactorYubiKeyResponse> {
|
|
|
|
const r = await this.send('PUT', '/two-factor/yubikey', request, true, true);
|
|
|
|
return new TwoFactorYubiKeyResponse(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
async putTwoFactorU2f(request: UpdateTwoFactorU2fRequest): Promise<TwoFactorU2fResponse> {
|
|
|
|
const r = await this.send('PUT', '/two-factor/u2f', request, true, true);
|
|
|
|
return new TwoFactorU2fResponse(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
async putTwoFactorDisable(request: TwoFactorProviderRequest): Promise<TwoFactorProviderResponse> {
|
|
|
|
const r = await this.send('PUT', '/two-factor/disable', request, true, true);
|
|
|
|
return new TwoFactorProviderResponse(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
postTwoFactorRecover(request: TwoFactorRecoveryRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/two-factor/recover', request, false, false);
|
|
|
|
}
|
|
|
|
|
2018-06-27 23:50:12 +02:00
|
|
|
postTwoFactorEmailSetup(request: TwoFactorEmailRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/two-factor/send-email', request, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
postTwoFactorEmail(request: TwoFactorEmailRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/two-factor/send-email-login', request, false, false);
|
|
|
|
}
|
|
|
|
|
2018-07-02 21:36:32 +02:00
|
|
|
// Organization APIs
|
|
|
|
|
2018-07-16 18:30:45 +02:00
|
|
|
async getOrganization(id: string): Promise<OrganizationResponse> {
|
|
|
|
const r = await this.send('GET', '/organizations/' + id, null, true, true);
|
|
|
|
return new OrganizationResponse(r);
|
|
|
|
}
|
|
|
|
|
2018-07-16 23:16:15 +02:00
|
|
|
async getOrganizationBilling(id: string): Promise<OrganizationBillingResponse> {
|
|
|
|
const r = await this.send('GET', '/organizations/' + id + '/billing', null, true, true);
|
|
|
|
return new OrganizationBillingResponse(r);
|
|
|
|
}
|
|
|
|
|
2018-07-17 17:25:15 +02:00
|
|
|
async getOrganizationLicense(id: string, installationId: string): Promise<any> {
|
|
|
|
return this.send('GET', '/organizations/' + id + '/license?installationId=' + installationId,
|
|
|
|
null, true, true);
|
|
|
|
}
|
|
|
|
|
2018-07-02 21:36:32 +02:00
|
|
|
async postOrganization(request: OrganizationCreateRequest): Promise<OrganizationResponse> {
|
|
|
|
const r = await this.send('POST', '/organizations', request, true, true);
|
|
|
|
return new OrganizationResponse(r);
|
|
|
|
}
|
|
|
|
|
2018-07-16 18:30:45 +02:00
|
|
|
async putOrganization(id: string, request: OrganizationUpdateRequest): Promise<OrganizationResponse> {
|
|
|
|
const r = await this.send('PUT', '/organizations/' + id, request, true, true);
|
|
|
|
return new OrganizationResponse(r);
|
|
|
|
}
|
|
|
|
|
2018-07-04 15:54:14 +02:00
|
|
|
postLeaveOrganization(id: string): Promise<any> {
|
|
|
|
return this.send('POST', '/organizations/' + id + '/leave', null, true, false);
|
|
|
|
}
|
|
|
|
|
2018-07-02 21:36:32 +02:00
|
|
|
async postOrganizationLicense(data: FormData): Promise<OrganizationResponse> {
|
|
|
|
const r = await this.send('POST', '/organizations/license', data, true, true);
|
|
|
|
return new OrganizationResponse(r);
|
|
|
|
}
|
|
|
|
|
2018-07-18 04:50:04 +02:00
|
|
|
async postOrganizationLicenseUpdate(id: string, data: FormData): Promise<any> {
|
|
|
|
return this.send('POST', '/organizations/' + id + '/license', data, true, false);
|
|
|
|
}
|
|
|
|
|
2018-07-17 18:05:19 +02:00
|
|
|
postOrganizationSeat(id: string, request: SeatRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/organizations/' + id + '/seat', request, true, false);
|
|
|
|
}
|
|
|
|
|
2018-07-16 23:16:15 +02:00
|
|
|
postOrganizationStorage(id: string, request: StorageRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/organizations/' + id + '/storage', request, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
postOrganizationPayment(id: string, request: PaymentRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/organizations/' + id + '/payment', request, true, false);
|
|
|
|
}
|
|
|
|
|
2018-07-17 17:04:19 +02:00
|
|
|
postOrganizationVerifyBank(id: string, request: VerifyBankRequest): Promise<any> {
|
|
|
|
return this.send('POST', '/organizations/' + id + '/verify-bank', request, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
postOrganizationCancel(id: string): Promise<any> {
|
|
|
|
return this.send('POST', '/organizations/' + id + '/cancel', null, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
postOrganizationReinstate(id: string): Promise<any> {
|
|
|
|
return this.send('POST', '/organizations/' + id + '/reinstate', null, true, false);
|
|
|
|
}
|
|
|
|
|
2018-07-16 23:16:15 +02:00
|
|
|
deleteOrganization(id: string, request: PasswordVerificationRequest): Promise<any> {
|
|
|
|
return this.send('DELETE', '/organizations/' + id, request, true, false);
|
2018-07-16 18:30:45 +02:00
|
|
|
}
|
|
|
|
|
2018-07-07 05:06:38 +02:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2018-07-11 19:30:06 +02:00
|
|
|
// User APIs
|
|
|
|
|
|
|
|
async getUserPublicKey(id: string): Promise<UserKeyResponse> {
|
|
|
|
const r = await this.send('GET', '/users/' + id + '/public-key', null, true, true);
|
|
|
|
return new UserKeyResponse(r);
|
|
|
|
}
|
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
// Helpers
|
|
|
|
|
2018-07-08 05:48:58 +02:00
|
|
|
fetch(request: Request): Promise<Response> {
|
|
|
|
if (request.method === 'GET') {
|
|
|
|
request.headers.set('Cache-Control', 'no-cache');
|
|
|
|
request.headers.set('Pragma', 'no-cache');
|
|
|
|
}
|
|
|
|
return fetch(request);
|
|
|
|
}
|
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
private async send(method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, body: any,
|
|
|
|
authed: boolean, hasResponse: boolean): Promise<any> {
|
|
|
|
const headers = new Headers({
|
|
|
|
'Device-Type': this.deviceType,
|
|
|
|
});
|
|
|
|
|
|
|
|
const requestInit: RequestInit = {
|
2018-04-30 23:00:31 +02:00
|
|
|
cache: 'no-cache',
|
2018-06-05 21:45:19 +02:00
|
|
|
credentials: this.getCredentials(),
|
2018-06-26 04:42:57 +02:00
|
|
|
method: method,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (authed) {
|
|
|
|
const authHeader = await this.handleTokenState();
|
|
|
|
headers.set('Authorization', authHeader);
|
|
|
|
}
|
|
|
|
if (body != null) {
|
|
|
|
if (typeof body === 'string') {
|
|
|
|
requestInit.body = body;
|
|
|
|
headers.set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
|
|
|
|
} else if (typeof body === 'object') {
|
|
|
|
if (body instanceof FormData) {
|
|
|
|
requestInit.body = body;
|
|
|
|
} else {
|
|
|
|
headers.set('Content-Type', 'application/json; charset=utf-8');
|
|
|
|
requestInit.body = JSON.stringify(body);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hasResponse) {
|
|
|
|
headers.set('Accept', 'application/json');
|
|
|
|
}
|
|
|
|
|
|
|
|
requestInit.headers = headers;
|
2018-07-08 05:48:58 +02:00
|
|
|
const response = await this.fetch(new Request(this.apiBaseUrl + path, requestInit));
|
2018-04-30 23:00:31 +02:00
|
|
|
|
2018-06-26 04:42:57 +02:00
|
|
|
if (hasResponse && response.status === 200) {
|
|
|
|
const responseJson = await response.json();
|
|
|
|
return responseJson;
|
|
|
|
} else if (response.status !== 200) {
|
2018-04-30 23:00:31 +02:00
|
|
|
const error = await this.handleError(response, false);
|
|
|
|
return Promise.reject(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-09 22:19:55 +01:00
|
|
|
private async handleError(response: Response, tokenError: boolean): Promise<ErrorResponse> {
|
|
|
|
if ((tokenError && response.status === 400) || response.status === 401 || response.status === 403) {
|
2018-05-16 05:40:15 +02:00
|
|
|
await this.logoutCallback(true);
|
2018-01-09 22:19:55 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let responseJson: any = null;
|
|
|
|
const typeHeader = response.headers.get('content-type');
|
|
|
|
if (typeHeader != null && typeHeader.indexOf('application/json') > -1) {
|
|
|
|
responseJson = await response.json();
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ErrorResponse(responseJson, response.status, tokenError);
|
|
|
|
}
|
|
|
|
|
|
|
|
private async handleTokenState(): Promise<string> {
|
2018-05-15 05:56:27 +02:00
|
|
|
let accessToken = await this.tokenService.getToken();
|
2018-01-09 22:19:55 +01:00
|
|
|
if (this.tokenService.tokenNeedsRefresh()) {
|
|
|
|
const tokenResponse = await this.doRefreshToken();
|
|
|
|
accessToken = tokenResponse.accessToken;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'Bearer ' + accessToken;
|
|
|
|
}
|
|
|
|
|
|
|
|
private async doRefreshToken(): Promise<IdentityTokenResponse> {
|
|
|
|
const refreshToken = await this.tokenService.getRefreshToken();
|
|
|
|
if (refreshToken == null || refreshToken === '') {
|
|
|
|
throw new Error();
|
|
|
|
}
|
|
|
|
|
2018-03-29 03:54:21 +02:00
|
|
|
const decodedToken = this.tokenService.decodeToken();
|
2018-07-08 05:48:58 +02:00
|
|
|
const response = await this.fetch(new Request(this.identityBaseUrl + '/connect/token', {
|
2018-01-09 22:19:55 +01:00
|
|
|
body: this.qsStringify({
|
|
|
|
grant_type: 'refresh_token',
|
2018-03-29 03:54:21 +02:00
|
|
|
client_id: decodedToken.client_id,
|
2018-01-09 22:19:55 +01:00
|
|
|
refresh_token: refreshToken,
|
|
|
|
}),
|
|
|
|
cache: 'no-cache',
|
2018-06-05 21:45:19 +02:00
|
|
|
credentials: this.getCredentials(),
|
2018-01-09 22:19:55 +01:00
|
|
|
headers: new Headers({
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
|
|
|
|
'Accept': 'application/json',
|
|
|
|
'Device-Type': this.deviceType,
|
|
|
|
}),
|
|
|
|
method: 'POST',
|
|
|
|
}));
|
|
|
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
const responseJson = await response.json();
|
|
|
|
const tokenResponse = new IdentityTokenResponse(responseJson);
|
|
|
|
await this.tokenService.setTokens(tokenResponse.accessToken, tokenResponse.refreshToken);
|
|
|
|
return tokenResponse;
|
|
|
|
} else {
|
|
|
|
const error = await this.handleError(response, true);
|
|
|
|
return Promise.reject(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private qsStringify(params: any): string {
|
|
|
|
return Object.keys(params).map((key) => {
|
|
|
|
return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]);
|
|
|
|
}).join('&');
|
|
|
|
}
|
2018-06-05 21:45:19 +02:00
|
|
|
|
|
|
|
private getCredentials(): RequestCredentials {
|
|
|
|
if (!this.isWebClient || this.usingBaseUrl) {
|
|
|
|
return 'include';
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
2018-07-07 05:06:38 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2018-01-09 22:19:55 +01:00
|
|
|
}
|