1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

Some groundwork for Send (#192)

* send work

* New method to update the last used index (#184)

Instead of updating it every time you call getNext(), it will be updated in a separate call, to avoid updating the index when the cipher did not auto-fill correctly (e.g wrong frame)
Fixes #1392

* added OnlyOrg to PolicyType enum (#183)

* [Require SSO] Add policy type enumeration (#186)

* Added SsoAuthentication policy type

* Updated policy type name // added comments for clarification of what each type controls

* [SSO] New user provision flow (#173)

* Initial commit of new user sso flow

* Adjusted stateSplit conditional per review

* Add logging to lowdb storage service (#188)

* Fix lint errors/warnings (#187)

* remove password api

* access id

* makeSendKey

Co-authored-by: Josep Marí <xusoo@users.noreply.github.com>
Co-authored-by: Addison Beck <abeck@bitwarden.com>
Co-authored-by: Vincent Salucci <26154748+vincentsalucci@users.noreply.github.com>
Co-authored-by: Chad Scharf <3904944+cscharf@users.noreply.github.com>
This commit is contained in:
Kyle Spearrin
2020-11-02 15:58:18 -05:00
committed by GitHub
parent 5e50aa1a19
commit 0e9e73ce95
26 changed files with 783 additions and 18 deletions

View File

@@ -46,6 +46,8 @@ import { PreloginRequest } from '../models/request/preloginRequest';
import { RegisterRequest } from '../models/request/registerRequest';
import { SeatRequest } from '../models/request/seatRequest';
import { SelectionReadOnlyRequest } from '../models/request/selectionReadOnlyRequest';
import { SendAccessRequest } from '../models/request/sendAccessRequest';
import { SendRequest } from '../models/request/sendRequest';
import { SetPasswordRequest } from '../models/request/setPasswordRequest';
import { StorageRequest } from '../models/request/storageRequest';
import { TaxInfoUpdateRequest } from '../models/request/taxInfoUpdateRequest';
@@ -97,6 +99,8 @@ import { PolicyResponse } from '../models/response/policyResponse';
import { PreloginResponse } from '../models/response/preloginResponse';
import { ProfileResponse } from '../models/response/profileResponse';
import { SelectionReadOnlyResponse } from '../models/response/selectionReadOnlyResponse';
import { SendAccessResponse } from '../models/response/sendAccessResponse';
import { SendResponse } from '../models/response/sendResponse';
import { SubscriptionResponse } from '../models/response/subscriptionResponse';
import { SyncResponse } from '../models/response/syncResponse';
import { TaxInfoResponse } from '../models/response/taxInfoResponse';
@@ -377,6 +381,47 @@ export class ApiService implements ApiServiceAbstraction {
return this.send('DELETE', '/folders/' + id, null, true, false);
}
// Send APIs
async getSend(id: string): Promise<SendResponse> {
const r = await this.send('GET', '/sends/' + id, null, true, true);
return new SendResponse(r);
}
async postSendAccess(id: string, request: SendAccessRequest): Promise<SendAccessResponse> {
const r = await this.send('POST', '/sends/access/' + id, request, false, true);
return new SendAccessResponse(r);
}
async getSends(): Promise<ListResponse<SendResponse>> {
const r = await this.send('GET', '/sends', null, true, true);
return new ListResponse(r, SendResponse);
}
async postSend(request: SendRequest): Promise<SendResponse> {
const r = await this.send('POST', '/sends', request, true, true);
return new SendResponse(r);
}
async postSendFile(data: FormData): Promise<SendResponse> {
const r = await this.send('POST', '/sends/file', data, true, true);
return new SendResponse(r);
}
async putSend(id: string, request: SendRequest): Promise<SendResponse> {
const r = await this.send('PUT', '/sends/' + id, request, true, true);
return new SendResponse(r);
}
async putSendRemovePassword(id: string): Promise<SendResponse> {
const r = await this.send('PUT', '/sends/' + id + '/remove-password', null, true, true);
return new SendResponse(r);
}
deleteSend(id: string): Promise<any> {
return this.send('DELETE', '/sends/' + id, null, true, false);
}
// Cipher APIs
async getCipher(id: string): Promise<CipherResponse> {
@@ -1040,7 +1085,6 @@ export class ApiService implements ApiServiceAbstraction {
}
async preValidateSso(identifier: string): Promise<boolean> {
if (identifier == null || identifier === '') {
throw new Error('Organization Identifier was not provided.');
}
@@ -1063,7 +1107,7 @@ export class ApiService implements ApiServiceAbstraction {
if (response.status === 200) {
return true;
} else {
const error = await this.handleError(response, false);
const error = await this.handleError(response, false, true);
return Promise.reject(error);
}
}
@@ -1111,13 +1155,13 @@ export class ApiService implements ApiServiceAbstraction {
const responseJson = await response.json();
return responseJson;
} else if (response.status !== 200) {
const error = await this.handleError(response, false);
const error = await this.handleError(response, false, authed);
return Promise.reject(error);
}
}
private async handleError(response: Response, tokenError: boolean): Promise<ErrorResponse> {
if ((tokenError && response.status === 400) || response.status === 401 || response.status === 403) {
private async handleError(response: Response, tokenError: boolean, authed: boolean): Promise<ErrorResponse> {
if (authed && ((tokenError && response.status === 400) || response.status === 401 || response.status === 403)) {
await this.logoutCallback(true);
return null;
}
@@ -1163,7 +1207,7 @@ export class ApiService implements ApiServiceAbstraction {
await this.tokenService.setTokens(tokenResponse.accessToken, tokenResponse.refreshToken);
return tokenResponse;
} else {
const error = await this.handleError(response, true);
const error = await this.handleError(response, true, true);
return Promise.reject(error);
}
}