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

convert cipher service to ts

This commit is contained in:
Kyle Spearrin
2017-11-06 10:58:32 -05:00
parent 38e235302c
commit b05426f953
13 changed files with 543 additions and 23 deletions

View File

@@ -1,3 +1,5 @@
import { CipherType } from '../../enums/cipherType.enum';
import { AttachmentData } from './attachmentData';
import { CardData } from './cardData';
import { FieldData } from './fieldData';
@@ -16,7 +18,7 @@ class CipherData {
organizationUseTotp: boolean;
favorite: boolean;
revisionDate: string;
type: number; // TODO: enum
type: CipherType;
sizeName: string;
name: string;
notes: string;
@@ -41,32 +43,31 @@ class CipherData {
this.name = response.data.Name;
this.notes = response.data.Notes;
const constantsService = chrome.extension.getBackgroundPage().bg_constantsService; // TODO: enum
switch (this.type) {
case constantsService.cipherType.login:
case CipherType.Login:
this.login = new LoginData(response.data);
break;
case constantsService.cipherType.secureNote:
case CipherType.SecureNote:
this.secureNote = new SecureNoteData(response.data);
break;
case constantsService.cipherType.card:
case CipherType.Card:
this.card = new CardData(response.data);
break;
case constantsService.cipherType.identity:
case CipherType.Identity:
this.identity = new IdentityData(response.data);
break;
default:
break;
}
if (response.data.Fields) {
if (response.data.Fields != null) {
this.fields = [];
for (const field of response.data.Fields) {
this.fields.push(new FieldData(field));
}
}
if (response.attachments) {
if (response.attachments != null) {
this.attachments = [];
for (const attachment of response.attachments) {
this.attachments.push(new AttachmentData(attachment));

View File

@@ -33,7 +33,7 @@ class Attachment extends Domain {
url: this.url,
};
return this.decryptObj(model, this, {
return this.decryptObj(model, {
fileName: null,
}, orgId);
}

View File

@@ -28,7 +28,7 @@ class Card extends Domain {
}
decrypt(orgId: string): Promise<any> {
return this.decryptObj({}, this, {
return this.decryptObj({}, {
cardholderName: null,
brand: null,
number: null,

View File

@@ -103,7 +103,7 @@ class Cipher extends Domain {
fields: null as any[],
};
await this.decryptObj(model, this, {
await this.decryptObj(model, {
name: null,
notes: null,
}, this.organizationId);

View File

@@ -16,8 +16,10 @@ export default abstract class Domain {
}
}
protected async decryptObj(model: any, self: any, map: any, orgId: string) {
protected async decryptObj(model: any, map: any, orgId: string) {
const promises = [];
const self: any = this;
for (const prop in map) {
if (!map.hasOwnProperty(prop)) {
continue;
@@ -33,7 +35,6 @@ export default abstract class Domain {
return null;
}).then((val: any) => {
model[theProp] = val;
return;
});
promises.push(p);
})(prop);

View File

@@ -28,7 +28,7 @@ class Field extends Domain {
type: this.type,
};
return this.decryptObj(model, this, {
return this.decryptObj(model, {
name: null,
value: null,
}, orgId);

View File

@@ -24,7 +24,7 @@ class Folder extends Domain {
id: this.id,
};
return this.decryptObj(model, this, {
return this.decryptObj(model, {
name: null,
}, null);
}

View File

@@ -52,7 +52,7 @@ class Identity extends Domain {
}
decrypt(orgId: string): Promise<any> {
return this.decryptObj({}, this, {
return this.decryptObj({}, {
title: null,
firstName: null,
middleName: null,

View File

@@ -24,7 +24,7 @@ class Login extends Domain {
}
decrypt(orgId: string): Promise<any> {
return this.decryptObj({}, this, {
return this.decryptObj({}, {
uri: null,
username: null,
password: null,

View File

@@ -10,7 +10,7 @@ class CipherResponse {
organizationUseTotp: boolean;
data: any;
revisionDate: string;
attachments: AttachmentResponse[] = [];
attachments: AttachmentResponse[];
constructor(response: any) {
this.id = response.Id;
@@ -23,7 +23,8 @@ class CipherResponse {
this.data = response.Data;
this.revisionDate = response.RevisionDate;
if (response.Attachments) {
if (response.Attachments != null) {
this.attachments = [];
for (const attachment of response.Attachments) {
this.attachments.push(new AttachmentResponse(attachment));
}