From a78b8ec79c4419122ea616f07303cff4d32c0578 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 8 Jan 2018 14:45:34 -0500 Subject: [PATCH] convert request/response models to jslib --- src/models/data/attachmentData.ts | 4 +- src/models/data/cipherData.ts | 6 +- src/models/data/collectionData.ts | 4 +- src/models/data/folderData.ts | 4 +- src/models/domain/folder.ts | 34 ------- src/models/request/cipherRequest.ts | 89 ------------------- src/models/request/deviceRequest.ts | 18 ---- src/models/request/deviceTokenRequest.ts | 10 --- src/models/request/folderRequest.ts | 12 --- src/models/request/passwordHintRequest.ts | 10 --- src/models/request/registerRequest.ts | 18 ---- src/models/request/tokenRequest.ts | 49 ---------- src/models/request/twoFactorEmailRequest.ts | 12 --- src/models/response/attachmentResponse.ts | 18 ---- src/models/response/cipherResponse.ts | 44 --------- src/models/response/collectionResponse.ts | 14 --- src/models/response/deviceResponse.ts | 20 ----- src/models/response/domainsResponse.ts | 20 ----- src/models/response/errorResponse.ts | 37 -------- src/models/response/folderResponse.ts | 14 --- src/models/response/globalDomainResponse.ts | 14 --- src/models/response/identityTokenResponse.ts | 24 ----- src/models/response/keysResponse.ts | 12 --- src/models/response/listResponse.ts | 10 --- .../response/profileOrganizationResponse.ts | 30 ------- src/models/response/profileResponse.ts | 39 -------- src/models/response/syncResponse.ts | 44 --------- src/popup/app/app.js | 24 +---- src/popup/app/services/auth.service.ts | 15 ++-- .../settings/folders/add-folder.component.ts | 5 +- .../settings/folders/edit-folder.component.ts | 9 +- .../app/settings/folders/folders.component.ts | 5 +- src/services/abstractions/crypto.service.ts | 4 +- src/services/api.service.ts | 69 +++++--------- src/services/cipher.service.ts | 16 ++-- src/services/crypto.service.ts | 5 +- src/services/folder.service.ts | 26 +++--- src/services/sync.service.ts | 19 ++-- 38 files changed, 74 insertions(+), 733 deletions(-) delete mode 100644 src/models/domain/folder.ts delete mode 100644 src/models/request/cipherRequest.ts delete mode 100644 src/models/request/deviceRequest.ts delete mode 100644 src/models/request/deviceTokenRequest.ts delete mode 100644 src/models/request/folderRequest.ts delete mode 100644 src/models/request/passwordHintRequest.ts delete mode 100644 src/models/request/registerRequest.ts delete mode 100644 src/models/request/tokenRequest.ts delete mode 100644 src/models/request/twoFactorEmailRequest.ts delete mode 100644 src/models/response/attachmentResponse.ts delete mode 100644 src/models/response/cipherResponse.ts delete mode 100644 src/models/response/collectionResponse.ts delete mode 100644 src/models/response/deviceResponse.ts delete mode 100644 src/models/response/domainsResponse.ts delete mode 100644 src/models/response/errorResponse.ts delete mode 100644 src/models/response/folderResponse.ts delete mode 100644 src/models/response/globalDomainResponse.ts delete mode 100644 src/models/response/identityTokenResponse.ts delete mode 100644 src/models/response/keysResponse.ts delete mode 100644 src/models/response/listResponse.ts delete mode 100644 src/models/response/profileOrganizationResponse.ts delete mode 100644 src/models/response/profileResponse.ts delete mode 100644 src/models/response/syncResponse.ts diff --git a/src/models/data/attachmentData.ts b/src/models/data/attachmentData.ts index 2ff3ab423c..252b608080 100644 --- a/src/models/data/attachmentData.ts +++ b/src/models/data/attachmentData.ts @@ -1,4 +1,4 @@ -import { AttachmentResponse } from '../response/attachmentResponse'; +import { Response } from '@bitwarden/jslib'; class AttachmentData { id: string; @@ -7,7 +7,7 @@ class AttachmentData { size: number; sizeName: string; - constructor(response: AttachmentResponse) { + constructor(response: Response.Attachment) { this.id = response.id; this.url = response.url; this.fileName = response.fileName; diff --git a/src/models/data/cipherData.ts b/src/models/data/cipherData.ts index 2bfed6c346..72d583490b 100644 --- a/src/models/data/cipherData.ts +++ b/src/models/data/cipherData.ts @@ -1,4 +1,4 @@ -import { Enums } from '@bitwarden/jslib'; +import { Data, Enums, Response } from '@bitwarden/jslib'; import { AttachmentData } from './attachmentData'; import { CardData } from './cardData'; @@ -7,8 +7,6 @@ import { IdentityData } from './identityData'; import { LoginData } from './loginData'; import { SecureNoteData } from './secureNoteData'; -import { CipherResponse } from '../response/cipherResponse'; - class CipherData { id: string; organizationId: string; @@ -30,7 +28,7 @@ class CipherData { attachments?: AttachmentData[]; collectionIds?: string[]; - constructor(response: CipherResponse, userId: string, collectionIds?: string[]) { + constructor(response: Response.Cipher, userId: string, collectionIds?: string[]) { this.id = response.id; this.organizationId = response.organizationId; this.folderId = response.folderId; diff --git a/src/models/data/collectionData.ts b/src/models/data/collectionData.ts index f2d5fc9f03..aaf49604ed 100644 --- a/src/models/data/collectionData.ts +++ b/src/models/data/collectionData.ts @@ -1,11 +1,11 @@ -import { CollectionResponse } from '../response/collectionResponse'; +import { Response } from '@bitwarden/jslib'; class CollectionData { id: string; organizationId: string; name: string; - constructor(response: CollectionResponse) { + constructor(response: Response.Collection) { this.id = response.id; this.organizationId = response.organizationId; this.name = response.name; diff --git a/src/models/data/folderData.ts b/src/models/data/folderData.ts index 6f03781cc7..75d4dcc4c6 100644 --- a/src/models/data/folderData.ts +++ b/src/models/data/folderData.ts @@ -1,4 +1,4 @@ -import { FolderResponse } from '../response/folderResponse'; +import { Response } from '@bitwarden/jslib'; class FolderData { id: string; @@ -6,7 +6,7 @@ class FolderData { name: string; revisionDate: string; - constructor(response: FolderResponse, userId: string) { + constructor(response: Response.Folder, userId: string) { this.userId = userId; this.name = response.name; this.id = response.id; diff --git a/src/models/domain/folder.ts b/src/models/domain/folder.ts deleted file mode 100644 index 180cd44e4f..0000000000 --- a/src/models/domain/folder.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { FolderData } from '../data/folderData'; - -import { CipherString } from './cipherString'; -import Domain from './domain'; - -class Folder extends Domain { - id: string; - name: CipherString; - - constructor(obj?: FolderData, alreadyEncrypted: boolean = false) { - super(); - if (obj == null) { - return; - } - - this.buildDomainModel(this, obj, { - id: null, - name: null, - }, alreadyEncrypted, ['id']); - } - - decrypt(): Promise { - const model = { - id: this.id, - }; - - return this.decryptObj(model, { - name: null, - }, null); - } -} - -export { Folder }; -(window as any).Folder = Folder; diff --git a/src/models/request/cipherRequest.ts b/src/models/request/cipherRequest.ts deleted file mode 100644 index 64cf9866b1..0000000000 --- a/src/models/request/cipherRequest.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { Enums } from '@bitwarden/jslib'; - -class CipherRequest { - type: Enums.CipherType; - folderId: string; - organizationId: string; - name: string; - notes: string; - favorite: boolean; - login: any; - secureNote: any; - card: any; - identity: any; - fields: any[]; - - constructor(cipher: any) { - this.type = cipher.type; - this.folderId = cipher.folderId; - this.organizationId = cipher.organizationId; - this.name = cipher.name ? cipher.name.encryptedString : null; - this.notes = cipher.notes ? cipher.notes.encryptedString : null; - this.favorite = cipher.favorite; - - switch (this.type) { - case Enums.CipherType.Login: - this.login = { - uri: cipher.login.uri ? cipher.login.uri.encryptedString : null, - username: cipher.login.username ? cipher.login.username.encryptedString : null, - password: cipher.login.password ? cipher.login.password.encryptedString : null, - totp: cipher.login.totp ? cipher.login.totp.encryptedString : null, - }; - break; - case Enums.CipherType.SecureNote: - this.secureNote = { - type: cipher.secureNote.type, - }; - break; - case Enums.CipherType.Card: - this.card = { - cardholderName: cipher.card.cardholderName ? cipher.card.cardholderName.encryptedString : null, - brand: cipher.card.brand ? cipher.card.brand.encryptedString : null, - number: cipher.card.number ? cipher.card.number.encryptedString : null, - expMonth: cipher.card.expMonth ? cipher.card.expMonth.encryptedString : null, - expYear: cipher.card.expYear ? cipher.card.expYear.encryptedString : null, - code: cipher.card.code ? cipher.card.code.encryptedString : null, - }; - break; - case Enums.CipherType.Identity: - this.identity = { - title: cipher.identity.title ? cipher.identity.title.encryptedString : null, - firstName: cipher.identity.firstName ? cipher.identity.firstName.encryptedString : null, - middleName: cipher.identity.middleName ? cipher.identity.middleName.encryptedString : null, - lastName: cipher.identity.lastName ? cipher.identity.lastName.encryptedString : null, - address1: cipher.identity.address1 ? cipher.identity.address1.encryptedString : null, - address2: cipher.identity.address2 ? cipher.identity.address2.encryptedString : null, - address3: cipher.identity.address3 ? cipher.identity.address3.encryptedString : null, - city: cipher.identity.city ? cipher.identity.city.encryptedString : null, - state: cipher.identity.state ? cipher.identity.state.encryptedString : null, - postalCode: cipher.identity.postalCode ? cipher.identity.postalCode.encryptedString : null, - country: cipher.identity.country ? cipher.identity.country.encryptedString : null, - company: cipher.identity.company ? cipher.identity.company.encryptedString : null, - email: cipher.identity.email ? cipher.identity.email.encryptedString : null, - phone: cipher.identity.phone ? cipher.identity.phone.encryptedString : null, - ssn: cipher.identity.ssn ? cipher.identity.ssn.encryptedString : null, - username: cipher.identity.username ? cipher.identity.username.encryptedString : null, - passportNumber: cipher.identity.passportNumber ? - cipher.identity.passportNumber.encryptedString : null, - licenseNumber: cipher.identity.licenseNumber ? cipher.identity.licenseNumber.encryptedString : null, - }; - break; - default: - break; - } - - if (cipher.fields) { - this.fields = []; - cipher.fields.forEach((field: any) => { - this.fields.push({ - type: field.type, - name: field.name ? field.name.encryptedString : null, - value: field.value ? field.value.encryptedString : null, - }); - }); - } - } -} - -export { CipherRequest }; -(window as any).CipherRequest = CipherRequest; diff --git a/src/models/request/deviceRequest.ts b/src/models/request/deviceRequest.ts deleted file mode 100644 index 24da902d3c..0000000000 --- a/src/models/request/deviceRequest.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Abstractions, Enums } from '@bitwarden/jslib'; - -class DeviceRequest { - type: Enums.DeviceType; - name: string; - identifier: string; - pushToken?: string; - - constructor(appId: string, platformUtilsService: Abstractions.PlatformUtilsService) { - this.type = platformUtilsService.getDevice(); - this.name = platformUtilsService.getDeviceString(); - this.identifier = appId; - this.pushToken = null; - } -} - -export { DeviceRequest }; -(window as any).DeviceRequest = DeviceRequest; diff --git a/src/models/request/deviceTokenRequest.ts b/src/models/request/deviceTokenRequest.ts deleted file mode 100644 index 69ef20bb9a..0000000000 --- a/src/models/request/deviceTokenRequest.ts +++ /dev/null @@ -1,10 +0,0 @@ -class DeviceTokenRequest { - pushToken: string; - - constructor() { - this.pushToken = null; - } -} - -export { DeviceTokenRequest }; -(window as any).DeviceTokenRequest = DeviceTokenRequest; diff --git a/src/models/request/folderRequest.ts b/src/models/request/folderRequest.ts deleted file mode 100644 index 7ff9794b18..0000000000 --- a/src/models/request/folderRequest.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Folder } from '../domain/folder'; - -class FolderRequest { - name: string; - - constructor(folder: Folder) { - this.name = folder.name ? folder.name.encryptedString : null; - } -} - -export { FolderRequest }; -(window as any).FolderRequest = FolderRequest; diff --git a/src/models/request/passwordHintRequest.ts b/src/models/request/passwordHintRequest.ts deleted file mode 100644 index 4feb92944b..0000000000 --- a/src/models/request/passwordHintRequest.ts +++ /dev/null @@ -1,10 +0,0 @@ -class PasswordHintRequest { - email: string; - - constructor(email: string) { - this.email = email; - } -} - -export { PasswordHintRequest }; -(window as any).PasswordHintRequest = PasswordHintRequest; diff --git a/src/models/request/registerRequest.ts b/src/models/request/registerRequest.ts deleted file mode 100644 index 4b80fb7884..0000000000 --- a/src/models/request/registerRequest.ts +++ /dev/null @@ -1,18 +0,0 @@ -class RegisterRequest { - name: string; - email: string; - masterPasswordHash: string; - masterPasswordHint: string; - key: string; - - constructor(email: string, masterPasswordHash: string, masterPasswordHint: string, key: string) { - this.name = null; - this.email = email; - this.masterPasswordHash = masterPasswordHash; - this.masterPasswordHint = masterPasswordHint ? masterPasswordHint : null; - this.key = key; - } -} - -export { RegisterRequest }; -(window as any).RegisterRequest = RegisterRequest; diff --git a/src/models/request/tokenRequest.ts b/src/models/request/tokenRequest.ts deleted file mode 100644 index 4cf7564615..0000000000 --- a/src/models/request/tokenRequest.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { DeviceRequest } from './deviceRequest'; - -class TokenRequest { - email: string; - masterPasswordHash: string; - token: string; - provider: number; - remember: boolean; - device?: DeviceRequest; - - constructor(email: string, masterPasswordHash: string, provider: number, - token: string, remember: boolean, device?: DeviceRequest) { - this.email = email; - this.masterPasswordHash = masterPasswordHash; - this.token = token; - this.provider = provider; - this.remember = remember; - this.device = device != null ? device : null; - } - - toIdentityToken() { - const obj: any = { - grant_type: 'password', - username: this.email, - password: this.masterPasswordHash, - scope: 'api offline_access', - client_id: 'browser', - }; - - if (this.device) { - obj.deviceType = this.device.type; - obj.deviceIdentifier = this.device.identifier; - obj.deviceName = this.device.name; - // no push tokens for browser apps yet - // obj.devicePushToken = this.device.pushToken; - } - - if (this.token && this.provider !== null && (typeof this.provider !== 'undefined')) { - obj.twoFactorToken = this.token; - obj.twoFactorProvider = this.provider; - obj.twoFactorRemember = this.remember ? '1' : '0'; - } - - return obj; - } -} - -export { TokenRequest }; -(window as any).TokenRequest = TokenRequest; diff --git a/src/models/request/twoFactorEmailRequest.ts b/src/models/request/twoFactorEmailRequest.ts deleted file mode 100644 index d540b08ecf..0000000000 --- a/src/models/request/twoFactorEmailRequest.ts +++ /dev/null @@ -1,12 +0,0 @@ -class TwoFactorEmailRequest { - email: string; - masterPasswordHash: string; - - constructor(email: string, masterPasswordHash: string) { - this.email = email; - this.masterPasswordHash = masterPasswordHash; - } -} - -export { TwoFactorEmailRequest }; -(window as any).TwoFactorEmailRequest = TwoFactorEmailRequest; diff --git a/src/models/response/attachmentResponse.ts b/src/models/response/attachmentResponse.ts deleted file mode 100644 index df5138650c..0000000000 --- a/src/models/response/attachmentResponse.ts +++ /dev/null @@ -1,18 +0,0 @@ -class AttachmentResponse { - id: string; - url: string; - fileName: string; - size: number; - sizeName: string; - - constructor(response: any) { - this.id = response.Id; - this.url = response.Url; - this.fileName = response.FileName; - this.size = response.Size; - this.sizeName = response.SizeName; - } -} - -export { AttachmentResponse }; -(window as any).AttachmentResponse = AttachmentResponse; diff --git a/src/models/response/cipherResponse.ts b/src/models/response/cipherResponse.ts deleted file mode 100644 index b2e597e23a..0000000000 --- a/src/models/response/cipherResponse.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { AttachmentResponse } from './attachmentResponse'; - -class CipherResponse { - id: string; - organizationId: string; - folderId: string; - type: number; - favorite: boolean; - edit: boolean; - organizationUseTotp: boolean; - data: any; - revisionDate: string; - attachments: AttachmentResponse[]; - collectionIds: string[]; - - constructor(response: any) { - this.id = response.Id; - this.organizationId = response.OrganizationId; - this.folderId = response.FolderId; - this.type = response.Type; - this.favorite = response.Favorite; - this.edit = response.Edit; - this.organizationUseTotp = response.OrganizationUseTotp; - this.data = response.Data; - this.revisionDate = response.RevisionDate; - - if (response.Attachments != null) { - this.attachments = []; - response.Attachments.forEach((attachment: any) => { - this.attachments.push(new AttachmentResponse(attachment)); - }); - } - - if (response.CollectionIds) { - this.collectionIds = []; - response.CollectionIds.forEach((id: string) => { - this.collectionIds.push(id); - }); - } - } -} - -export { CipherResponse }; -(window as any).CipherResponse = CipherResponse; diff --git a/src/models/response/collectionResponse.ts b/src/models/response/collectionResponse.ts deleted file mode 100644 index 8b0247720d..0000000000 --- a/src/models/response/collectionResponse.ts +++ /dev/null @@ -1,14 +0,0 @@ -class CollectionResponse { - id: string; - organizationId: string; - name: string; - - constructor(response: any) { - this.id = response.Id; - this.organizationId = response.OrganizationId; - this.name = response.Name; - } -} - -export { CollectionResponse }; -(window as any).CollectionResponse = CollectionResponse; diff --git a/src/models/response/deviceResponse.ts b/src/models/response/deviceResponse.ts deleted file mode 100644 index 9b9b5e3057..0000000000 --- a/src/models/response/deviceResponse.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Enums } from '@bitwarden/jslib'; - -class DeviceResponse { - id: string; - name: number; - identifier: string; - type: Enums.DeviceType; - creationDate: string; - - constructor(response: any) { - this.id = response.Id; - this.name = response.Name; - this.identifier = response.Identifier; - this.type = response.Type; - this.creationDate = response.CreationDate; - } -} - -export { DeviceResponse }; -(window as any).DeviceResponse = DeviceResponse; diff --git a/src/models/response/domainsResponse.ts b/src/models/response/domainsResponse.ts deleted file mode 100644 index d65077147b..0000000000 --- a/src/models/response/domainsResponse.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { GlobalDomainResponse } from './globalDomainResponse'; - -class DomainsResponse { - equivalentDomains: string[][]; - globalEquivalentDomains: GlobalDomainResponse[] = []; - - constructor(response: any) { - this.equivalentDomains = response.EquivalentDomains; - - this.globalEquivalentDomains = []; - if (response.GlobalEquivalentDomains) { - response.GlobalEquivalentDomains.forEach((domain: any) => { - this.globalEquivalentDomains.push(new GlobalDomainResponse(domain)); - }); - } - } -} - -export { DomainsResponse }; -(window as any).DomainsResponse = DomainsResponse; diff --git a/src/models/response/errorResponse.ts b/src/models/response/errorResponse.ts deleted file mode 100644 index 4d976932cd..0000000000 --- a/src/models/response/errorResponse.ts +++ /dev/null @@ -1,37 +0,0 @@ -class ErrorResponse { - message: string; - validationErrors: { [key: string]: string[]; }; - statusCode: number; - - constructor(response: any, status: number, identityResponse?: boolean) { - let errorModel = null; - if (identityResponse && response && response.ErrorModel) { - errorModel = response.ErrorModel; - } else if (response) { - errorModel = response; - } - - if (errorModel) { - this.message = errorModel.Message; - this.validationErrors = errorModel.ValidationErrors; - } - this.statusCode = status; - } - - getSingleMessage(): string { - if (this.validationErrors) { - for (const key in this.validationErrors) { - if (!this.validationErrors.hasOwnProperty(key)) { - continue; - } - if (this.validationErrors[key].length) { - return this.validationErrors[key][0]; - } - } - } - return this.message; - } -} - -export { ErrorResponse }; -(window as any).ErrorResponse = ErrorResponse; diff --git a/src/models/response/folderResponse.ts b/src/models/response/folderResponse.ts deleted file mode 100644 index c5ff0ada70..0000000000 --- a/src/models/response/folderResponse.ts +++ /dev/null @@ -1,14 +0,0 @@ -class FolderResponse { - id: string; - name: string; - revisionDate: string; - - constructor(response: any) { - this.id = response.Id; - this.name = response.Name; - this.revisionDate = response.RevisionDate; - } -} - -export { FolderResponse }; -(window as any).FolderResponse = FolderResponse; diff --git a/src/models/response/globalDomainResponse.ts b/src/models/response/globalDomainResponse.ts deleted file mode 100644 index 8e9a45df11..0000000000 --- a/src/models/response/globalDomainResponse.ts +++ /dev/null @@ -1,14 +0,0 @@ -class GlobalDomainResponse { - type: number; - domains: string[]; - excluded: number[]; - - constructor(response: any) { - this.type = response.Type; - this.domains = response.Domains; - this.excluded = response.Excluded; - } -} - -export { GlobalDomainResponse }; -(window as any).GlobalDomainResponse = GlobalDomainResponse; diff --git a/src/models/response/identityTokenResponse.ts b/src/models/response/identityTokenResponse.ts deleted file mode 100644 index 2d188707c0..0000000000 --- a/src/models/response/identityTokenResponse.ts +++ /dev/null @@ -1,24 +0,0 @@ -class IdentityTokenResponse { - accessToken: string; - expiresIn: number; - refreshToken: string; - tokenType: string; - - privateKey: string; - key: string; - twoFactorToken: string; - - constructor(response: any) { - this.accessToken = response.access_token; - this.expiresIn = response.expires_in; - this.refreshToken = response.refresh_token; - this.tokenType = response.token_type; - - this.privateKey = response.PrivateKey; - this.key = response.Key; - this.twoFactorToken = response.TwoFactorToken; - } -} - -export { IdentityTokenResponse }; -(window as any).IdentityTokenResponse = IdentityTokenResponse; diff --git a/src/models/response/keysResponse.ts b/src/models/response/keysResponse.ts deleted file mode 100644 index cb96dad51e..0000000000 --- a/src/models/response/keysResponse.ts +++ /dev/null @@ -1,12 +0,0 @@ -class KeysResponse { - privateKey: string; - publicKey: string; - - constructor(response: any) { - this.privateKey = response.PrivateKey; - this.publicKey = response.PublicKey; - } -} - -export { KeysResponse }; -(window as any).KeysResponse = KeysResponse; diff --git a/src/models/response/listResponse.ts b/src/models/response/listResponse.ts deleted file mode 100644 index 9cf5455ada..0000000000 --- a/src/models/response/listResponse.ts +++ /dev/null @@ -1,10 +0,0 @@ -class ListResponse { - data: any; - - constructor(data: any) { - this.data = data; - } -} - -export { ListResponse }; -(window as any).ListResponse = ListResponse; diff --git a/src/models/response/profileOrganizationResponse.ts b/src/models/response/profileOrganizationResponse.ts deleted file mode 100644 index 484857745a..0000000000 --- a/src/models/response/profileOrganizationResponse.ts +++ /dev/null @@ -1,30 +0,0 @@ -class ProfileOrganizationResponse { - id: string; - name: string; - useGroups: boolean; - useDirectory: boolean; - useTotp: boolean; - seats: number; - maxCollections: number; - maxStorageGb?: number; - key: string; - status: number; // TODO: map to enum - type: number; // TODO: map to enum - - constructor(response: any) { - this.id = response.Id; - this.name = response.Name; - this.useGroups = response.UseGroups; - this.useDirectory = response.UseDirectory; - this.useTotp = response.UseTotp; - this.seats = response.Seats; - this.maxCollections = response.MaxCollections; - this.maxStorageGb = response.MaxStorageGb; - this.key = response.Key; - this.status = response.Status; - this.type = response.Type; - } -} - -export { ProfileOrganizationResponse }; -(window as any).ProfileOrganizationResponse = ProfileOrganizationResponse; diff --git a/src/models/response/profileResponse.ts b/src/models/response/profileResponse.ts deleted file mode 100644 index 69e4f3e9cb..0000000000 --- a/src/models/response/profileResponse.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { ProfileOrganizationResponse } from './profileOrganizationResponse'; - -class ProfileResponse { - id: string; - name: string; - email: string; - emailVerified: boolean; - masterPasswordHint: string; - premium: boolean; - culture: string; - twoFactorEnabled: boolean; - key: string; - privateKey: string; - securityStamp: string; - organizations: ProfileOrganizationResponse[] = []; - - constructor(response: any) { - this.id = response.Id; - this.name = response.Name; - this.email = response.Email; - this.emailVerified = response.EmailVerified; - this.masterPasswordHint = response.MasterPasswordHint; - this.premium = response.Premium; - this.culture = response.Culture; - this.twoFactorEnabled = response.TwoFactorEnabled; - this.key = response.Key; - this.privateKey = response.PrivateKey; - this.securityStamp = response.SecurityStamp; - - if (response.Organizations) { - response.Organizations.forEach((org: any) => { - this.organizations.push(new ProfileOrganizationResponse(org)); - }); - } - } -} - -export { ProfileResponse }; -(window as any).ProfileResponse = ProfileResponse; diff --git a/src/models/response/syncResponse.ts b/src/models/response/syncResponse.ts deleted file mode 100644 index 8acdc5202d..0000000000 --- a/src/models/response/syncResponse.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { CipherResponse } from './cipherResponse'; -import { CollectionResponse } from './collectionResponse'; -import { DomainsResponse } from './domainsResponse'; -import { FolderResponse } from './folderResponse'; -import { ProfileResponse } from './profileResponse'; - -class SyncResponse { - profile?: ProfileResponse; - folders: FolderResponse[] = []; - collections: CollectionResponse[] = []; - ciphers: CipherResponse[] = []; - domains?: DomainsResponse; - - constructor(response: any) { - if (response.Profile) { - this.profile = new ProfileResponse(response.Profile); - } - - if (response.Folders) { - response.Folders.forEach((folder: any) => { - this.folders.push(new FolderResponse(folder)); - }); - } - - if (response.Collections) { - response.Collections.forEach((collection: any) => { - this.collections.push(new CollectionResponse(collection)); - }); - } - - if (response.Ciphers) { - response.Ciphers.forEach((cipher: any) => { - this.ciphers.push(new CipherResponse(cipher)); - }); - } - - if (response.Domains) { - this.domains = new DomainsResponse(response.Domains); - } - } -} - -export { SyncResponse }; -(window as any).SyncResponse = SyncResponse; diff --git a/src/popup/app/app.js b/src/popup/app/app.js index 5c203a41f3..8e5da30f49 100644 --- a/src/popup/app/app.js +++ b/src/popup/app/app.js @@ -34,7 +34,6 @@ import { Attachment } from '../../models/domain/attachment'; import { Card } from '../../models/domain/card'; import { Cipher } from '../../models/domain/cipher'; import { Field } from '../../models/domain/field'; -import { Folder } from '../../models/domain/folder'; import { Identity } from '../../models/domain/identity'; import { Login } from '../../models/domain/login'; import { SecureNote } from '../../models/domain/secureNote'; @@ -50,28 +49,7 @@ import { SecureNoteData } from '../../models/data/secureNoteData'; import { CipherString } from '../../models/domain/cipherString'; -import { CipherRequest } from '../../models/request/cipherRequest'; -import { DeviceRequest } from '../../models/request/deviceRequest'; -import { DeviceTokenRequest } from '../../models/request/deviceTokenRequest'; -import { FolderRequest } from '../../models/request/folderRequest'; -import { PasswordHintRequest } from '../../models/request/passwordHintRequest'; -import { RegisterRequest } from '../../models/request/registerRequest'; -import { TokenRequest } from '../../models/request/tokenRequest'; -import { TwoFactorEmailRequest } from '../../models/request/twoFactorEmailRequest'; - -import { AttachmentResponse } from '../../models/response/attachmentResponse'; -import { CipherResponse } from '../../models/response/cipherResponse'; -import { DeviceResponse } from '../../models/response/deviceResponse'; -import { DomainsResponse } from '../../models/response/domainsResponse'; -import { ErrorResponse } from '../../models/response/errorResponse'; -import { FolderResponse } from '../../models/response/folderResponse'; -import { GlobalDomainResponse } from '../../models/response/globalDomainResponse'; -import { IdentityTokenResponse } from '../../models/response/identityTokenResponse'; -import { KeysResponse } from '../../models/response/keysResponse'; -import { ListResponse } from '../../models/response/listResponse'; -import { ProfileOrganizationResponse } from '../../models/response/profileOrganizationResponse'; -import { ProfileResponse } from '../../models/response/profileResponse'; -import { SyncResponse } from '../../models/response/syncResponse'; +import { Domain, Request, Response } from '@bitwarden/jslib'; angular .module('bit', [ diff --git a/src/popup/app/services/auth.service.ts b/src/popup/app/services/auth.service.ts index 7757894ac6..18957af3f1 100644 --- a/src/popup/app/services/auth.service.ts +++ b/src/popup/app/services/auth.service.ts @@ -1,9 +1,6 @@ -import { DeviceRequest } from '../../../models/request/deviceRequest'; -import { TokenRequest } from '../../../models/request/tokenRequest'; - import { CryptoService } from '../../../services/abstractions/crypto.service'; -import { Abstractions } from '@bitwarden/jslib'; +import { Abstractions, Request } from '@bitwarden/jslib'; class AuthService { constructor(public cryptoService: CryptoService, public apiService: any, public userService: any, @@ -21,18 +18,18 @@ class AuthService { const storedTwoFactorToken = await this.tokenService.getTwoFactorToken(email); const hashedPassword = await this.cryptoService.hashPassword(masterPassword, key); - const deviceRequest = new DeviceRequest(appId, this.platformUtilsService); + const deviceRequest = new Request.Device(appId, this.platformUtilsService); - let request: TokenRequest; + let request: Request.Token; if (twoFactorToken != null && twoFactorProvider != null) { - request = new TokenRequest(email, hashedPassword, twoFactorProvider, twoFactorToken, remember, + request = new Request.Token(email, hashedPassword, twoFactorProvider, twoFactorToken, remember, deviceRequest); } else if (storedTwoFactorToken) { - request = new TokenRequest(email, hashedPassword, this.constantsService.twoFactorProvider.remember, + request = new Request.Token(email, hashedPassword, this.constantsService.twoFactorProvider.remember, storedTwoFactorToken, false, deviceRequest); } else { - request = new TokenRequest(email, hashedPassword, null, null, false, deviceRequest); + request = new Request.Token(email, hashedPassword, null, null, false, deviceRequest); } const response = await this.apiService.postIdentityToken(request); diff --git a/src/popup/app/settings/folders/add-folder.component.ts b/src/popup/app/settings/folders/add-folder.component.ts index 034fba2804..3914c0f4eb 100644 --- a/src/popup/app/settings/folders/add-folder.component.ts +++ b/src/popup/app/settings/folders/add-folder.component.ts @@ -1,8 +1,7 @@ import * as angular from 'angular'; -import { Folder } from '../../../../models/domain/folder'; import * as template from './add-folder.component.html'; -import { Abstractions } from '@bitwarden/jslib'; +import { Abstractions, Domain } from '@bitwarden/jslib'; export class AddFolderController { savePromise: any; @@ -29,7 +28,7 @@ export class AddFolderController { } this.savePromise = this.folderService.encrypt(model).then((folderModel: any) => { - const folder = new Folder(folderModel, true); + const folder = new Domain.Folder(folderModel, true); return this.folderService.saveWithServer(folder); }).then((folder: any) => { this.$analytics.eventTrack('Added Folder'); diff --git a/src/popup/app/settings/folders/edit-folder.component.ts b/src/popup/app/settings/folders/edit-folder.component.ts index 2e15c790f0..50159ed003 100644 --- a/src/popup/app/settings/folders/edit-folder.component.ts +++ b/src/popup/app/settings/folders/edit-folder.component.ts @@ -1,15 +1,14 @@ import * as angular from 'angular'; -import { Folder } from '../../../../models/domain/folder'; import * as template from './edit-folder.component.html'; -import { Abstractions } from '@bitwarden/jslib'; +import { Abstractions, Domain } from '@bitwarden/jslib'; export class EditFolderController { $transition$: any; folderId: any; savePromise: any = null; i18n: any; - folder: Folder; + folder: Domain.Folder; constructor($scope: any, $stateParams: any, private folderService: any, private toastr: any, private $state: any, private SweetAlert: any, platformUtilsService: Abstractions.PlatformUtilsService, private $analytics: any, @@ -28,7 +27,7 @@ export class EditFolderController { this.folderId = this.$transition$.params('to').folderId; this.folderService.get(this.folderId).then((folder: any) => { return folder.decrypt(); - }).then((model: Folder) => { + }).then((model: Domain.Folder) => { this.folder = model; }); } @@ -40,7 +39,7 @@ export class EditFolderController { } this.savePromise = this.folderService.encrypt(model).then((folderModel: any) => { - const folder = new Folder(folderModel, true); + const folder = new Domain.Folder(folderModel, true); return this.folderService.saveWithServer(folder); }).then((folder: any) => { this.$analytics.eventTrack('Edited Folder'); diff --git a/src/popup/app/settings/folders/folders.component.ts b/src/popup/app/settings/folders/folders.component.ts index cc7d045abb..45093a2ca3 100644 --- a/src/popup/app/settings/folders/folders.component.ts +++ b/src/popup/app/settings/folders/folders.component.ts @@ -1,8 +1,9 @@ -import { Folder } from '../../../../models/domain/folder'; import * as template from './folders.component.html'; +import { Domain } from '@bitwarden/jslib'; + export class FoldersController { - folders: Folder[] = []; + folders: Domain.Folder[] = []; i18n: any; loaded = false; diff --git a/src/services/abstractions/crypto.service.ts b/src/services/abstractions/crypto.service.ts index 1fd413d34f..8d424ec784 100644 --- a/src/services/abstractions/crypto.service.ts +++ b/src/services/abstractions/crypto.service.ts @@ -1,14 +1,14 @@ import { CipherString } from '../../models/domain/cipherString'; import SymmetricCryptoKey from '../../models/domain/symmetricCryptoKey'; -import { ProfileOrganizationResponse } from '../../models/response/profileOrganizationResponse'; +import { Response } from '@bitwarden/jslib'; export interface CryptoService { setKey(key: SymmetricCryptoKey): Promise; setKeyHash(keyHash: string): Promise<{}>; setEncKey(encKey: string): Promise<{}>; setEncPrivateKey(encPrivateKey: string): Promise<{}>; - setOrgKeys(orgs: ProfileOrganizationResponse[]): Promise<{}>; + setOrgKeys(orgs: Response.ProfileOrganization[]): Promise<{}>; getKey(): Promise; getKeyHash(): Promise; getEncKey(): Promise; diff --git a/src/services/api.service.ts b/src/services/api.service.ts index a24c674b2d..39b7c9572b 100644 --- a/src/services/api.service.ts +++ b/src/services/api.service.ts @@ -2,33 +2,10 @@ import AppIdService from './appId.service'; import ConstantsService from './constants.service'; import TokenService from './token.service'; -import { Abstractions } from '@bitwarden/jslib'; +import { Abstractions, Request as Req, Response as Res } from '@bitwarden/jslib'; import EnvironmentUrls from '../models/domain/environmentUrls'; -import { CipherRequest } from '../models/request/cipherRequest'; -import { DeviceRequest } from '../models/request/deviceRequest'; -import { DeviceTokenRequest } from '../models/request/deviceTokenRequest'; -import { FolderRequest } from '../models/request/folderRequest'; -import { PasswordHintRequest } from '../models/request/passwordHintRequest'; -import { RegisterRequest } from '../models/request/registerRequest'; -import { TokenRequest } from '../models/request/tokenRequest'; -import { TwoFactorEmailRequest } from '../models/request/twoFactorEmailRequest'; - -import { AttachmentResponse } from '../models/response/attachmentResponse'; -import { CipherResponse } from '../models/response/cipherResponse'; -import { DeviceResponse } from '../models/response/deviceResponse'; -import { DomainsResponse } from '../models/response/domainsResponse'; -import { ErrorResponse } from '../models/response/errorResponse'; -import { FolderResponse } from '../models/response/folderResponse'; -import { GlobalDomainResponse } from '../models/response/globalDomainResponse'; -import { IdentityTokenResponse } from '../models/response/identityTokenResponse'; -import { KeysResponse } from '../models/response/keysResponse'; -import { ListResponse } from '../models/response/listResponse'; -import { ProfileOrganizationResponse } from '../models/response/profileOrganizationResponse'; -import { ProfileResponse } from '../models/response/profileResponse'; -import { SyncResponse } from '../models/response/syncResponse'; - export default class ApiService { urlsSet: boolean = false; baseUrl: string; @@ -82,7 +59,7 @@ export default class ApiService { // Auth APIs - async postIdentityToken(request: TokenRequest): Promise { + async postIdentityToken(request: Req.Token): Promise { const response = await fetch(new Request(this.identityBaseUrl + '/connect/token', { body: this.qsStringify(request.toIdentityToken()), cache: 'no-cache', @@ -102,7 +79,7 @@ export default class ApiService { if (responseJson != null) { if (response.status === 200) { - return new IdentityTokenResponse(responseJson); + return new Res.IdentityToken(responseJson); } else if (response.status === 400 && responseJson.TwoFactorProviders2 && Object.keys(responseJson.TwoFactorProviders2).length) { await this.tokenService.clearTwoFactorToken(request.email); @@ -110,7 +87,7 @@ export default class ApiService { } } - return Promise.reject(new ErrorResponse(responseJson, response.status, true)); + return Promise.reject(new Res.Error(responseJson, response.status, true)); } async refreshIdentityToken(): Promise { @@ -123,7 +100,7 @@ export default class ApiService { // Two Factor APIs - async postTwoFactorEmail(request: TwoFactorEmailRequest): Promise { + async postTwoFactorEmail(request: Req.TwoFactorEmail): Promise { const response = await fetch(new Request(this.baseUrl + '/two-factor/send-email-login', { body: JSON.stringify(request), cache: 'no-cache', @@ -161,7 +138,7 @@ export default class ApiService { } } - async postPasswordHint(request: PasswordHintRequest): Promise { + async postPasswordHint(request: Req.PasswordHint): Promise { const response = await fetch(new Request(this.baseUrl + '/accounts/password-hint', { body: JSON.stringify(request), cache: 'no-cache', @@ -178,7 +155,7 @@ export default class ApiService { } } - async postRegister(request: RegisterRequest): Promise { + async postRegister(request: Req.Register): Promise { const response = await fetch(new Request(this.baseUrl + '/accounts/register', { body: JSON.stringify(request), cache: 'no-cache', @@ -197,7 +174,7 @@ export default class ApiService { // Folder APIs - async postFolder(request: FolderRequest): Promise { + async postFolder(request: Req.Folder): Promise { const authHeader = await this.handleTokenState(); const response = await fetch(new Request(this.baseUrl + '/folders', { body: JSON.stringify(request), @@ -213,14 +190,14 @@ export default class ApiService { if (response.status === 200) { const responseJson = await response.json(); - return new FolderResponse(responseJson); + return new Res.Folder(responseJson); } else { const error = await this.handleError(response, false); return Promise.reject(error); } } - async putFolder(id: string, request: FolderRequest): Promise { + async putFolder(id: string, request: Req.Folder): Promise { const authHeader = await this.handleTokenState(); const response = await fetch(new Request(this.baseUrl + '/folders/' + id, { body: JSON.stringify(request), @@ -236,7 +213,7 @@ export default class ApiService { if (response.status === 200) { const responseJson = await response.json(); - return new FolderResponse(responseJson); + return new Res.Folder(responseJson); } else { const error = await this.handleError(response, false); return Promise.reject(error); @@ -262,7 +239,7 @@ export default class ApiService { // Cipher APIs - async postCipher(request: CipherRequest): Promise { + async postCipher(request: Req.Cipher): Promise { const authHeader = await this.handleTokenState(); const response = await fetch(new Request(this.baseUrl + '/ciphers', { body: JSON.stringify(request), @@ -278,14 +255,14 @@ export default class ApiService { if (response.status === 200) { const responseJson = await response.json(); - return new CipherResponse(responseJson); + return new Res.Cipher(responseJson); } else { const error = await this.handleError(response, false); return Promise.reject(error); } } - async putCipher(id: string, request: CipherRequest): Promise { + async putCipher(id: string, request: Req.Cipher): Promise { const authHeader = await this.handleTokenState(); const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id, { body: JSON.stringify(request), @@ -301,7 +278,7 @@ export default class ApiService { if (response.status === 200) { const responseJson = await response.json(); - return new CipherResponse(responseJson); + return new Res.Cipher(responseJson); } else { const error = await this.handleError(response, false); return Promise.reject(error); @@ -327,7 +304,7 @@ export default class ApiService { // Attachments APIs - async postCipherAttachment(id: string, data: FormData): Promise { + async postCipherAttachment(id: string, data: FormData): Promise { const authHeader = await this.handleTokenState(); const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id + '/attachment', { body: data, @@ -342,7 +319,7 @@ export default class ApiService { if (response.status === 200) { const responseJson = await response.json(); - return new CipherResponse(responseJson); + return new Res.Cipher(responseJson); } else { const error = await this.handleError(response, false); return Promise.reject(error); @@ -368,7 +345,7 @@ export default class ApiService { // Sync APIs - async getSync(): Promise { + async getSync(): Promise { const authHeader = await this.handleTokenState(); const response = await fetch(new Request(this.baseUrl + '/sync', { cache: 'no-cache', @@ -381,7 +358,7 @@ export default class ApiService { if (response.status === 200) { const responseJson = await response.json(); - return new SyncResponse(responseJson); + return new Res.Sync(responseJson); } else { const error = await this.handleError(response, false); return Promise.reject(error); @@ -390,7 +367,7 @@ export default class ApiService { // Helpers - private async handleError(response: Response, tokenError: boolean): Promise { + private async handleError(response: Response, tokenError: boolean): Promise { if ((tokenError && response.status === 400) || response.status === 401 || response.status === 403) { this.logoutCallback(true); return null; @@ -402,7 +379,7 @@ export default class ApiService { responseJson = await response.json(); } - return new ErrorResponse(responseJson, response.status, tokenError); + return new Res.Error(responseJson, response.status, tokenError); } private async handleTokenState(): Promise { @@ -417,7 +394,7 @@ export default class ApiService { return 'Bearer ' + accessToken; } - private async doRefreshToken(): Promise { + private async doRefreshToken(): Promise { const refreshToken = await this.tokenService.getRefreshToken(); if (refreshToken == null || refreshToken === '') { throw new Error(); @@ -440,7 +417,7 @@ export default class ApiService { if (response.status === 200) { const responseJson = await response.json(); - const tokenResponse = new IdentityTokenResponse(responseJson); + const tokenResponse = new Res.IdentityToken(responseJson); await this.tokenService.setTokens(tokenResponse.accessToken, tokenResponse.refreshToken); return tokenResponse; } else { diff --git a/src/services/cipher.service.ts b/src/services/cipher.service.ts index 2460877db9..ce263dd6f7 100644 --- a/src/services/cipher.service.ts +++ b/src/services/cipher.service.ts @@ -1,4 +1,4 @@ -import { Abstractions, Enums } from '@bitwarden/jslib'; +import { Abstractions, Enums, Request, Response } from '@bitwarden/jslib'; import { Cipher } from '../models/domain/cipher'; import { CipherString } from '../models/domain/cipherString'; @@ -7,10 +7,6 @@ import SymmetricCryptoKey from '../models/domain/symmetricCryptoKey'; import { CipherData } from '../models/data/cipherData'; -import { CipherRequest } from '../models/request/cipherRequest'; -import { CipherResponse } from '../models/response/cipherResponse'; -import { ErrorResponse } from '../models/response/errorResponse'; - import ApiService from './api.service'; import ConstantsService from './constants.service'; import CryptoService from './crypto.service'; @@ -285,9 +281,9 @@ export default class CipherService { } async saveWithServer(cipher: Cipher): Promise { - const request = new CipherRequest(cipher); + const request = new Request.Cipher(cipher); - let response: CipherResponse; + let response: Response.Cipher; if (cipher.id == null) { response = await this.apiService.postCipher(request); cipher.id = response.id; @@ -316,11 +312,11 @@ export default class CipherService { const blob = new Blob([encData], { type: 'application/octet-stream' }); fd.append('data', blob, encFileName.encryptedString); - let response: CipherResponse; + let response: Response.Cipher; try { response = await self.apiService.postCipherAttachment(cipher.id, fd); } catch (e) { - reject((e as ErrorResponse).getSingleMessage()); + reject((e as Response.Error).getSingleMessage()); return; } @@ -418,7 +414,7 @@ export default class CipherService { try { await this.apiService.deleteCipherAttachment(id, attachmentId); } catch (e) { - return Promise.reject((e as ErrorResponse).getSingleMessage()); + return Promise.reject((e as Response.Error).getSingleMessage()); } await this.deleteAttachment(id, attachmentId); } diff --git a/src/services/crypto.service.ts b/src/services/crypto.service.ts index 5db0366c43..62dafa5621 100644 --- a/src/services/crypto.service.ts +++ b/src/services/crypto.service.ts @@ -1,11 +1,10 @@ import * as forge from 'node-forge'; -import { Abstractions, Enums, Services } from '@bitwarden/jslib'; +import { Abstractions, Enums, Response, Services } from '@bitwarden/jslib'; import { CipherString } from '../models/domain/cipherString'; import EncryptedObject from '../models/domain/encryptedObject'; import SymmetricCryptoKey from '../models/domain/symmetricCryptoKey'; -import { ProfileOrganizationResponse } from '../models/response/profileOrganizationResponse'; import ConstantsService from './constants.service'; @@ -77,7 +76,7 @@ export default class CryptoService implements CryptoServiceInterface { this.privateKey = null; } - setOrgKeys(orgs: ProfileOrganizationResponse[]): Promise<{}> { + setOrgKeys(orgs: Response.ProfileOrganization[]): Promise<{}> { const orgKeys: any = {}; orgs.forEach((org) => { orgKeys[org.id] = org.key; diff --git a/src/services/folder.service.ts b/src/services/folder.service.ts index dc3f2ae833..be822067f8 100644 --- a/src/services/folder.service.ts +++ b/src/services/folder.service.ts @@ -1,16 +1,12 @@ import { CipherString } from '../models/domain/cipherString'; -import { Folder } from '../models/domain/folder'; import { FolderData } from '../models/data/folderData'; -import { FolderRequest } from '../models/request/folderRequest'; -import { FolderResponse } from '../models/response/folderResponse'; - import ApiService from './api.service'; import CryptoService from './crypto.service'; import UserService from './user.service'; -import { Abstractions } from '@bitwarden/jslib'; +import { Abstractions, Domain, Request, Response } from '@bitwarden/jslib'; const Keys = { foldersPrefix: 'folders_', @@ -28,14 +24,14 @@ export default class FolderService { this.decryptedFolderCache = null; } - async encrypt(model: any): Promise { - const folder = new Folder(); + async encrypt(model: any): Promise { + const folder = new Domain.Folder(); folder.id = model.id; folder.name = await this.cryptoService.encrypt(model.name); return folder; } - async get(id: string): Promise { + async get(id: string): Promise { const userId = await this.userService.getUserId(); const folders = await this.storageService.get<{ [id: string]: FolderData; }>( Keys.foldersPrefix + userId); @@ -43,17 +39,17 @@ export default class FolderService { return null; } - return new Folder(folders[id]); + return new Domain.Folder(folders[id]); } - async getAll(): Promise { + async getAll(): Promise { const userId = await this.userService.getUserId(); const folders = await this.storageService.get<{ [id: string]: FolderData; }>( Keys.foldersPrefix + userId); - const response: Folder[] = []; + const response: Domain.Folder[] = []; for (const id in folders) { if (folders.hasOwnProperty(id)) { - response.push(new Folder(folders[id])); + response.push(new Domain.Folder(folders[id])); } } return response; @@ -87,10 +83,10 @@ export default class FolderService { return this.decryptedFolderCache; } - async saveWithServer(folder: Folder): Promise { - const request = new FolderRequest(folder); + async saveWithServer(folder: Domain.Folder): Promise { + const request = new Request.Folder(folder); - let response: FolderResponse; + let response: Response.Folder; if (folder.id == null) { response = await this.apiService.postFolder(request); folder.id = response.id; diff --git a/src/services/sync.service.ts b/src/services/sync.service.ts index d3b268f563..76e903b835 100644 --- a/src/services/sync.service.ts +++ b/src/services/sync.service.ts @@ -2,13 +2,6 @@ import { CipherData } from '../models/data/cipherData'; import { CollectionData } from '../models/data/collectionData'; import { FolderData } from '../models/data/folderData'; -import { CipherResponse } from '../models/response/cipherResponse'; -import { CollectionResponse } from '../models/response/collectionResponse'; -import { DomainsResponse } from '../models/response/domainsResponse'; -import { FolderResponse } from '../models/response/folderResponse'; -import { ProfileResponse } from '../models/response/profileResponse'; -import { SyncResponse } from '../models/response/syncResponse'; - import ApiService from './api.service'; import CipherService from './cipher.service'; import CollectionService from './collection.service'; @@ -17,7 +10,7 @@ import FolderService from './folder.service'; import SettingsService from './settings.service'; import UserService from './user.service'; -import { Abstractions } from '@bitwarden/jslib'; +import { Abstractions, Response } from '@bitwarden/jslib'; const Keys = { lastSyncPrefix: 'lastSync_', @@ -122,7 +115,7 @@ export default class SyncService { } } - private async syncProfile(response: ProfileResponse) { + private async syncProfile(response: Response.Profile) { const stamp = await this.userService.getSecurityStamp(); if (stamp != null && stamp !== response.securityStamp) { if (this.logoutCallback != null) { @@ -138,7 +131,7 @@ export default class SyncService { await this.userService.setSecurityStamp(response.securityStamp); } - private async syncFolders(userId: string, response: FolderResponse[]) { + private async syncFolders(userId: string, response: Response.Folder[]) { const folders: { [id: string]: FolderData; } = {}; response.forEach((f) => { folders[f.id] = new FolderData(f, userId); @@ -146,7 +139,7 @@ export default class SyncService { return await this.folderService.replace(folders); } - private async syncCollections(response: CollectionResponse[]) { + private async syncCollections(response: Response.Collection[]) { const collections: { [id: string]: CollectionData; } = {}; response.forEach((c) => { collections[c.id] = new CollectionData(c); @@ -154,7 +147,7 @@ export default class SyncService { return await this.collectionService.replace(collections); } - private async syncCiphers(userId: string, response: CipherResponse[]) { + private async syncCiphers(userId: string, response: Response.Cipher[]) { const ciphers: { [id: string]: CipherData; } = {}; response.forEach((c) => { ciphers[c.id] = new CipherData(c, userId); @@ -162,7 +155,7 @@ export default class SyncService { return await this.cipherService.replace(ciphers); } - private async syncSettings(userId: string, response: DomainsResponse) { + private async syncSettings(userId: string, response: Response.Domains) { let eqDomains: string[][] = []; if (response != null && response.equivalentDomains != null) { eqDomains = eqDomains.concat(response.equivalentDomains);