import apis

This commit is contained in:
Kyle Spearrin 2018-06-23 15:41:22 -04:00
parent ce40a803d8
commit 1609ed5419
6 changed files with 84 additions and 0 deletions

View File

@ -9,7 +9,9 @@ import { CipherShareRequest } from '../models/request/cipherShareRequest';
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 { FolderRequest } from '../models/request/folderRequest'; import { FolderRequest } from '../models/request/folderRequest';
import { ImportCiphersRequest } from '../models/request/importCiphersRequest';
import { ImportDirectoryRequest } from '../models/request/importDirectoryRequest'; import { ImportDirectoryRequest } from '../models/request/importDirectoryRequest';
import { ImportOrganizationCiphersRequest } from '../models/request/importOrganizationCiphersRequest';
import { PasswordHintRequest } from '../models/request/passwordHintRequest'; import { PasswordHintRequest } from '../models/request/passwordHintRequest';
import { PasswordRequest } from '../models/request/passwordRequest'; import { PasswordRequest } from '../models/request/passwordRequest';
import { PasswordVerificationRequest } from '../models/request/passwordVerificationRequest'; import { PasswordVerificationRequest } from '../models/request/passwordVerificationRequest';
@ -56,6 +58,8 @@ export abstract class ApiService {
putShareCiphers: (request: CipherBulkShareRequest) => Promise<any>; putShareCiphers: (request: CipherBulkShareRequest) => Promise<any>;
putCipherCollections: (id: string, request: CipherCollectionsRequest) => Promise<any>; putCipherCollections: (id: string, request: CipherCollectionsRequest) => Promise<any>;
postPurgeCiphers: (request: PasswordVerificationRequest) => Promise<any>; postPurgeCiphers: (request: PasswordVerificationRequest) => Promise<any>;
postImportCiphers: (request: ImportCiphersRequest) => Promise<any>;
postImportOrganizationCiphers: (request: ImportOrganizationCiphersRequest) => Promise<any>;
postCipherAttachment: (id: string, data: FormData) => Promise<CipherResponse>; postCipherAttachment: (id: string, data: FormData) => Promise<CipherResponse>;
deleteCipherAttachment: (id: string, attachmentId: string) => Promise<any>; deleteCipherAttachment: (id: string, attachmentId: string) => Promise<any>;
postShareCipherAttachment: (id: string, attachmentId: string, data: FormData, postShareCipherAttachment: (id: string, attachmentId: string, data: FormData,

View File

@ -0,0 +1,9 @@
import { Collection } from '../domain/collection';
export class CollectionRequest {
name: string;
constructor(collection: Collection) {
this.name = collection.name ? collection.name.encryptedString : null;
}
}

View File

@ -0,0 +1,9 @@
import { CipherRequest } from './cipherRequest';
import { FolderRequest } from './folderRequest';
import { KvpRequest } from './kvpRequest';
export class ImportCiphersRequest {
ciphers: CipherRequest[];
folders: FolderRequest[];
folderRelationships: Array<KvpRequest<number, number>>;
}

View File

@ -0,0 +1,9 @@
import { CipherRequest } from './cipherRequest';
import { CollectionRequest } from './collectionRequest';
import { KvpRequest } from './kvpRequest';
export class ImportOrganizationCiphersRequest {
ciphers: CipherRequest[];
collections: CollectionRequest[];
collectionRelationships: Array<KvpRequest<number, number>>;
}

View File

@ -0,0 +1,9 @@
export class KvpRequest<TK, TV> {
key: TK;
value: TV;
constructor(key: TK, value: TV) {
this.key = key;
this.value = value;
}
}

View File

@ -15,7 +15,9 @@ import { CipherShareRequest } from '../models/request/cipherShareRequest';
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 { FolderRequest } from '../models/request/folderRequest'; import { FolderRequest } from '../models/request/folderRequest';
import { ImportCiphersRequest } from '../models/request/importCiphersRequest';
import { ImportDirectoryRequest } from '../models/request/importDirectoryRequest'; import { ImportDirectoryRequest } from '../models/request/importDirectoryRequest';
import { ImportOrganizationCiphersRequest } from '../models/request/importOrganizationCiphersRequest';
import { PasswordHintRequest } from '../models/request/passwordHintRequest'; import { PasswordHintRequest } from '../models/request/passwordHintRequest';
import { PasswordRequest } from '../models/request/passwordRequest'; import { PasswordRequest } from '../models/request/passwordRequest';
import { PasswordVerificationRequest } from '../models/request/passwordVerificationRequest'; import { PasswordVerificationRequest } from '../models/request/passwordVerificationRequest';
@ -607,6 +609,48 @@ export class ApiService implements ApiServiceAbstraction {
} }
} }
async postImportCiphers(request: ImportCiphersRequest): Promise<any> {
const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.apiBaseUrl + '/ciphers/import', {
body: JSON.stringify(request),
cache: 'no-cache',
credentials: this.getCredentials(),
headers: new Headers({
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8',
'Authorization': authHeader,
'Device-Type': this.deviceType,
}),
method: 'POST',
}));
if (response.status !== 200) {
const error = await this.handleError(response, false);
return Promise.reject(error);
}
}
async postImportOrganizationCiphers(request: ImportOrganizationCiphersRequest): Promise<any> {
const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.apiBaseUrl + '/ciphers/import-organization', {
body: JSON.stringify(request),
cache: 'no-cache',
credentials: this.getCredentials(),
headers: new Headers({
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8',
'Authorization': authHeader,
'Device-Type': this.deviceType,
}),
method: 'POST',
}));
if (response.status !== 200) {
const error = await this.handleError(response, false);
return Promise.reject(error);
}
}
// Attachments APIs // Attachments APIs
async postCipherAttachment(id: string, data: FormData): Promise<CipherResponse> { async postCipherAttachment(id: string, data: FormData): Promise<CipherResponse> {