mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
cipher collection apis
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { EnvironmentUrls } from '../models/domain/environmentUrls';
|
import { EnvironmentUrls } from '../models/domain/environmentUrls';
|
||||||
|
|
||||||
|
import { CipherCollectionsRequest } from '../models/request/cipherCollectionsRequest';
|
||||||
import { CipherRequest } from '../models/request/cipherRequest';
|
import { CipherRequest } from '../models/request/cipherRequest';
|
||||||
import { CipherShareRequest } from '../models/request/cipherShareRequest';
|
import { CipherShareRequest } from '../models/request/cipherShareRequest';
|
||||||
import { FolderRequest } from '../models/request/folderRequest';
|
import { FolderRequest } from '../models/request/folderRequest';
|
||||||
@@ -37,11 +38,13 @@ export abstract class ApiService {
|
|||||||
deleteFolder: (id: string) => Promise<any>;
|
deleteFolder: (id: string) => Promise<any>;
|
||||||
postCipher: (request: CipherRequest) => Promise<CipherResponse>;
|
postCipher: (request: CipherRequest) => Promise<CipherResponse>;
|
||||||
putCipher: (id: string, request: CipherRequest) => Promise<CipherResponse>;
|
putCipher: (id: string, request: CipherRequest) => Promise<CipherResponse>;
|
||||||
shareCipher: (id: string, request: CipherShareRequest) => Promise<any>;
|
|
||||||
deleteCipher: (id: string) => Promise<any>;
|
deleteCipher: (id: string) => Promise<any>;
|
||||||
|
putShareCipher: (id: string, request: CipherShareRequest) => Promise<any>;
|
||||||
|
putCipherCollections: (id: string, request: CipherCollectionsRequest) => Promise<any>;
|
||||||
postCipherAttachment: (id: string, data: FormData) => Promise<CipherResponse>;
|
postCipherAttachment: (id: string, data: FormData) => Promise<CipherResponse>;
|
||||||
shareCipherAttachment: (id: string, attachmentId: string, data: FormData, organizationId: string) => Promise<any>;
|
|
||||||
deleteCipherAttachment: (id: string, attachmentId: string) => Promise<any>;
|
deleteCipherAttachment: (id: string, attachmentId: string) => Promise<any>;
|
||||||
|
postShareCipherAttachment: (id: string, attachmentId: string, data: FormData,
|
||||||
|
organizationId: string) => Promise<any>;
|
||||||
getSync: () => Promise<SyncResponse>;
|
getSync: () => Promise<SyncResponse>;
|
||||||
postImportDirectory: (organizationId: string, request: ImportDirectoryRequest) => Promise<any>;
|
postImportDirectory: (organizationId: string, request: ImportDirectoryRequest) => Promise<any>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export abstract class CipherService {
|
|||||||
organizationId: string) => Promise<any>;
|
organizationId: string) => Promise<any>;
|
||||||
saveAttachmentWithServer: (cipher: Cipher, unencryptedFile: any) => Promise<Cipher>;
|
saveAttachmentWithServer: (cipher: Cipher, unencryptedFile: any) => Promise<Cipher>;
|
||||||
saveAttachmentRawWithServer: (cipher: Cipher, filename: string, data: ArrayBuffer) => Promise<Cipher>;
|
saveAttachmentRawWithServer: (cipher: Cipher, filename: string, data: ArrayBuffer) => Promise<Cipher>;
|
||||||
|
saveCollectionsWithServer: (cipher: Cipher) => Promise<any>;
|
||||||
upsert: (cipher: CipherData | CipherData[]) => Promise<any>;
|
upsert: (cipher: CipherData | CipherData[]) => Promise<any>;
|
||||||
replace: (ciphers: { [id: string]: CipherData; }) => Promise<any>;
|
replace: (ciphers: { [id: string]: CipherData; }) => Promise<any>;
|
||||||
clear: (userId: string) => Promise<any>;
|
clear: (userId: string) => Promise<any>;
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ export class CipherCollectionsRequest {
|
|||||||
collectionIds: string[];
|
collectionIds: string[];
|
||||||
|
|
||||||
constructor(collectionIds: string[]) {
|
constructor(collectionIds: string[]) {
|
||||||
this.collectionIds = collectionIds;
|
this.collectionIds = collectionIds == null ? [] : collectionIds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { TokenService } from '../abstractions/token.service';
|
|||||||
|
|
||||||
import { EnvironmentUrls } from '../models/domain/environmentUrls';
|
import { EnvironmentUrls } from '../models/domain/environmentUrls';
|
||||||
|
|
||||||
|
import { CipherCollectionsRequest } from '../models/request/cipherCollectionsRequest';
|
||||||
import { CipherRequest } from '../models/request/cipherRequest';
|
import { CipherRequest } from '../models/request/cipherRequest';
|
||||||
import { CipherShareRequest } from '../models/request/cipherShareRequest';
|
import { CipherShareRequest } from '../models/request/cipherShareRequest';
|
||||||
import { FolderRequest } from '../models/request/folderRequest';
|
import { FolderRequest } from '../models/request/folderRequest';
|
||||||
@@ -335,7 +336,25 @@ export class ApiService implements ApiServiceAbstraction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async shareCipher(id: string, request: CipherShareRequest): Promise<any> {
|
async deleteCipher(id: string): Promise<any> {
|
||||||
|
const authHeader = await this.handleTokenState();
|
||||||
|
const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id, {
|
||||||
|
cache: 'no-cache',
|
||||||
|
credentials: this.getCredentials(),
|
||||||
|
headers: new Headers({
|
||||||
|
'Authorization': authHeader,
|
||||||
|
'Device-Type': this.deviceType,
|
||||||
|
}),
|
||||||
|
method: 'DELETE',
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (response.status !== 200) {
|
||||||
|
const error = await this.handleError(response, false);
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async putShareCipher(id: string, request: CipherShareRequest): Promise<any> {
|
||||||
const authHeader = await this.handleTokenState();
|
const authHeader = await this.handleTokenState();
|
||||||
const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id + '/share', {
|
const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id + '/share', {
|
||||||
body: JSON.stringify(request),
|
body: JSON.stringify(request),
|
||||||
@@ -356,16 +375,19 @@ export class ApiService implements ApiServiceAbstraction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteCipher(id: string): Promise<any> {
|
async putCipherCollections(id: string, request: CipherCollectionsRequest): Promise<any> {
|
||||||
const authHeader = await this.handleTokenState();
|
const authHeader = await this.handleTokenState();
|
||||||
const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id, {
|
const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id + '/collections', {
|
||||||
|
body: JSON.stringify(request),
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
credentials: this.getCredentials(),
|
credentials: this.getCredentials(),
|
||||||
headers: new Headers({
|
headers: new Headers({
|
||||||
|
'Accept': 'application/json',
|
||||||
'Authorization': authHeader,
|
'Authorization': authHeader,
|
||||||
|
'Content-Type': 'application/json; charset=utf-8',
|
||||||
'Device-Type': this.deviceType,
|
'Device-Type': this.deviceType,
|
||||||
}),
|
}),
|
||||||
method: 'DELETE',
|
method: 'PUT',
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
@@ -399,7 +421,25 @@ export class ApiService implements ApiServiceAbstraction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async shareCipherAttachment(id: string, attachmentId: string, data: FormData,
|
async deleteCipherAttachment(id: string, attachmentId: string): Promise<any> {
|
||||||
|
const authHeader = await this.handleTokenState();
|
||||||
|
const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id + '/attachment/' + attachmentId, {
|
||||||
|
cache: 'no-cache',
|
||||||
|
credentials: this.getCredentials(),
|
||||||
|
headers: new Headers({
|
||||||
|
'Authorization': authHeader,
|
||||||
|
'Device-Type': this.deviceType,
|
||||||
|
}),
|
||||||
|
method: 'DELETE',
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (response.status !== 200) {
|
||||||
|
const error = await this.handleError(response, false);
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async postShareCipherAttachment(id: string, attachmentId: string, data: FormData,
|
||||||
organizationId: string): Promise<any> {
|
organizationId: string): Promise<any> {
|
||||||
const authHeader = await this.handleTokenState();
|
const authHeader = await this.handleTokenState();
|
||||||
const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id + '/attachment/' +
|
const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id + '/attachment/' +
|
||||||
@@ -421,24 +461,6 @@ export class ApiService implements ApiServiceAbstraction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteCipherAttachment(id: string, attachmentId: string): Promise<any> {
|
|
||||||
const authHeader = await this.handleTokenState();
|
|
||||||
const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id + '/attachment/' + attachmentId, {
|
|
||||||
cache: 'no-cache',
|
|
||||||
credentials: this.getCredentials(),
|
|
||||||
headers: new Headers({
|
|
||||||
'Authorization': authHeader,
|
|
||||||
'Device-Type': this.deviceType,
|
|
||||||
}),
|
|
||||||
method: 'DELETE',
|
|
||||||
}));
|
|
||||||
|
|
||||||
if (response.status !== 200) {
|
|
||||||
const error = await this.handleError(response, false);
|
|
||||||
return Promise.reject(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sync APIs
|
// Sync APIs
|
||||||
|
|
||||||
async getSync(): Promise<SyncResponse> {
|
async getSync(): Promise<SyncResponse> {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { LoginUri } from '../models/domain/loginUri';
|
|||||||
import { SecureNote } from '../models/domain/secureNote';
|
import { SecureNote } from '../models/domain/secureNote';
|
||||||
import { SymmetricCryptoKey } from '../models/domain/symmetricCryptoKey';
|
import { SymmetricCryptoKey } from '../models/domain/symmetricCryptoKey';
|
||||||
|
|
||||||
|
import { CipherCollectionsRequest } from '../models/request/cipherCollectionsRequest';
|
||||||
import { CipherRequest } from '../models/request/cipherRequest';
|
import { CipherRequest } from '../models/request/cipherRequest';
|
||||||
|
|
||||||
import { CipherResponse } from '../models/response/cipherResponse';
|
import { CipherResponse } from '../models/response/cipherResponse';
|
||||||
@@ -357,7 +358,7 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
|
|
||||||
async shareWithServer(cipher: Cipher): Promise<any> {
|
async shareWithServer(cipher: Cipher): Promise<any> {
|
||||||
const request = new CipherShareRequest(cipher);
|
const request = new CipherShareRequest(cipher);
|
||||||
await this.apiService.shareCipher(cipher.id, request);
|
await this.apiService.putShareCipher(cipher.id, request);
|
||||||
const userId = await this.userService.getUserId();
|
const userId = await this.userService.getUserId();
|
||||||
await this.upsert(cipher.toCipherData(userId));
|
await this.upsert(cipher.toCipherData(userId));
|
||||||
}
|
}
|
||||||
@@ -392,7 +393,8 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
|
|
||||||
let response: CipherResponse;
|
let response: CipherResponse;
|
||||||
try {
|
try {
|
||||||
response = await this.apiService.shareCipherAttachment(cipherId, attachmentView.id, fd, organizationId);
|
response = await this.apiService.postShareCipherAttachment(cipherId, attachmentView.id, fd,
|
||||||
|
organizationId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error((e as ErrorResponse).getSingleMessage());
|
throw new Error((e as ErrorResponse).getSingleMessage());
|
||||||
}
|
}
|
||||||
@@ -450,6 +452,14 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
return new Cipher(cData);
|
return new Cipher(cData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async saveCollectionsWithServer(cipher: Cipher): Promise<any> {
|
||||||
|
const request = new CipherCollectionsRequest(cipher.collectionIds);
|
||||||
|
const response = await this.apiService.putCipherCollections(cipher.id, request);
|
||||||
|
const userId = await this.userService.getUserId();
|
||||||
|
const data = cipher.toCipherData(userId);
|
||||||
|
await this.upsert(data);
|
||||||
|
}
|
||||||
|
|
||||||
async upsert(cipher: CipherData | CipherData[]): Promise<any> {
|
async upsert(cipher: CipherData | CipherData[]): Promise<any> {
|
||||||
const userId = await this.userService.getUserId();
|
const userId = await this.userService.getUserId();
|
||||||
let ciphers = await this.storageService.get<{ [id: string]: CipherData; }>(
|
let ciphers = await this.storageService.get<{ [id: string]: CipherData; }>(
|
||||||
|
|||||||
Reference in New Issue
Block a user