1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 00:33:44 +00:00

Move to libs

This commit is contained in:
Hinton
2022-06-03 16:24:40 +02:00
parent 28d15bfe2a
commit d7492e3cf3
878 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
import { Card as CardDomain } from "../domain/card";
import { EncString } from "../domain/encString";
import { CardView } from "../view/cardView";
export class CardExport {
static template(): CardExport {
const req = new CardExport();
req.cardholderName = "John Doe";
req.brand = "visa";
req.number = "4242424242424242";
req.expMonth = "04";
req.expYear = "2023";
req.code = "123";
return req;
}
static toView(req: CardExport, view = new CardView()) {
view.cardholderName = req.cardholderName;
view.brand = req.brand;
view.number = req.number;
view.expMonth = req.expMonth;
view.expYear = req.expYear;
view.code = req.code;
return view;
}
static toDomain(req: CardExport, domain = new CardDomain()) {
domain.cardholderName = req.cardholderName != null ? new EncString(req.cardholderName) : null;
domain.brand = req.brand != null ? new EncString(req.brand) : null;
domain.number = req.number != null ? new EncString(req.number) : null;
domain.expMonth = req.expMonth != null ? new EncString(req.expMonth) : null;
domain.expYear = req.expYear != null ? new EncString(req.expYear) : null;
domain.code = req.code != null ? new EncString(req.code) : null;
return domain;
}
cardholderName: string;
brand: string;
number: string;
expMonth: string;
expYear: string;
code: string;
constructor(o?: CardView | CardDomain) {
if (o == null) {
return;
}
if (o instanceof CardView) {
this.cardholderName = o.cardholderName;
this.brand = o.brand;
this.number = o.number;
this.expMonth = o.expMonth;
this.expYear = o.expYear;
this.code = o.code;
} else {
this.cardholderName = o.cardholderName?.encryptedString;
this.brand = o.brand?.encryptedString;
this.number = o.number?.encryptedString;
this.expMonth = o.expMonth?.encryptedString;
this.expYear = o.expYear?.encryptedString;
this.code = o.code?.encryptedString;
}
}
}

View File

@@ -0,0 +1,156 @@
import { CipherRepromptType } from "../../enums/cipherRepromptType";
import { CipherType } from "../../enums/cipherType";
import { Cipher as CipherDomain } from "../domain/cipher";
import { EncString } from "../domain/encString";
import { CipherView } from "../view/cipherView";
import { CardExport } from "./cardExport";
import { FieldExport } from "./fieldExport";
import { IdentityExport } from "./identityExport";
import { LoginExport } from "./loginExport";
import { SecureNoteExport } from "./secureNoteExport";
export class CipherExport {
static template(): CipherExport {
const req = new CipherExport();
req.organizationId = null;
req.collectionIds = null;
req.folderId = null;
req.type = CipherType.Login;
req.name = "Item name";
req.notes = "Some notes about this item.";
req.favorite = false;
req.fields = [];
req.login = null;
req.secureNote = null;
req.card = null;
req.identity = null;
req.reprompt = CipherRepromptType.None;
return req;
}
static toView(req: CipherExport, view = new CipherView()) {
view.type = req.type;
view.folderId = req.folderId;
if (view.organizationId == null) {
view.organizationId = req.organizationId;
}
if (view.collectionIds || req.collectionIds) {
const set = new Set((view.collectionIds ?? []).concat(req.collectionIds ?? []));
view.collectionIds = Array.from(set.values());
}
view.name = req.name;
view.notes = req.notes;
view.favorite = req.favorite;
view.reprompt = req.reprompt ?? CipherRepromptType.None;
if (req.fields != null) {
view.fields = req.fields.map((f) => FieldExport.toView(f));
}
switch (req.type) {
case CipherType.Login:
view.login = LoginExport.toView(req.login);
break;
case CipherType.SecureNote:
view.secureNote = SecureNoteExport.toView(req.secureNote);
break;
case CipherType.Card:
view.card = CardExport.toView(req.card);
break;
case CipherType.Identity:
view.identity = IdentityExport.toView(req.identity);
break;
}
return view;
}
static toDomain(req: CipherExport, domain = new CipherDomain()) {
domain.type = req.type;
domain.folderId = req.folderId;
if (domain.organizationId == null) {
domain.organizationId = req.organizationId;
}
domain.name = req.name != null ? new EncString(req.name) : null;
domain.notes = req.notes != null ? new EncString(req.notes) : null;
domain.favorite = req.favorite;
domain.reprompt = req.reprompt ?? CipherRepromptType.None;
if (req.fields != null) {
domain.fields = req.fields.map((f) => FieldExport.toDomain(f));
}
switch (req.type) {
case CipherType.Login:
domain.login = LoginExport.toDomain(req.login);
break;
case CipherType.SecureNote:
domain.secureNote = SecureNoteExport.toDomain(req.secureNote);
break;
case CipherType.Card:
domain.card = CardExport.toDomain(req.card);
break;
case CipherType.Identity:
domain.identity = IdentityExport.toDomain(req.identity);
break;
}
return domain;
}
type: CipherType;
folderId: string;
organizationId: string;
collectionIds: string[];
name: string;
notes: string;
favorite: boolean;
fields: FieldExport[];
login: LoginExport;
secureNote: SecureNoteExport;
card: CardExport;
identity: IdentityExport;
reprompt: CipherRepromptType;
// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
build(o: CipherView | CipherDomain) {
this.organizationId = o.organizationId;
this.folderId = o.folderId;
this.type = o.type;
this.reprompt = o.reprompt;
if (o instanceof CipherView) {
this.name = o.name;
this.notes = o.notes;
} else {
this.name = o.name?.encryptedString;
this.notes = o.notes?.encryptedString;
}
this.favorite = o.favorite;
if (o.fields != null) {
if (o instanceof CipherView) {
this.fields = o.fields.map((f) => new FieldExport(f));
} else {
this.fields = o.fields.map((f) => new FieldExport(f));
}
}
switch (o.type) {
case CipherType.Login:
this.login = new LoginExport(o.login);
break;
case CipherType.SecureNote:
this.secureNote = new SecureNoteExport(o.secureNote);
break;
case CipherType.Card:
this.card = new CardExport(o.card);
break;
case CipherType.Identity:
this.identity = new IdentityExport(o.identity);
break;
}
}
}

View File

@@ -0,0 +1,16 @@
import { Cipher as CipherDomain } from "../domain/cipher";
import { CipherView } from "../view/cipherView";
import { CipherExport } from "./cipherExport";
export class CipherWithIdExport extends CipherExport {
id: string;
collectionIds: string[];
// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
build(o: CipherView | CipherDomain) {
this.id = o.id;
super.build(o);
this.collectionIds = o.collectionIds;
}
}

View File

@@ -0,0 +1,46 @@
import { Collection as CollectionDomain } from "../domain/collection";
import { EncString } from "../domain/encString";
import { CollectionView } from "../view/collectionView";
export class CollectionExport {
static template(): CollectionExport {
const req = new CollectionExport();
req.organizationId = "00000000-0000-0000-0000-000000000000";
req.name = "Collection name";
req.externalId = null;
return req;
}
static toView(req: CollectionExport, view = new CollectionView()) {
view.name = req.name;
view.externalId = req.externalId;
if (view.organizationId == null) {
view.organizationId = req.organizationId;
}
return view;
}
static toDomain(req: CollectionExport, domain = new CollectionDomain()) {
domain.name = req.name != null ? new EncString(req.name) : null;
domain.externalId = req.externalId;
if (domain.organizationId == null) {
domain.organizationId = req.organizationId;
}
return domain;
}
organizationId: string;
name: string;
externalId: string;
// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
build(o: CollectionView | CollectionDomain) {
this.organizationId = o.organizationId;
if (o instanceof CollectionView) {
this.name = o.name;
} else {
this.name = o.name?.encryptedString;
}
this.externalId = o.externalId;
}
}

View File

@@ -0,0 +1,14 @@
import { Collection as CollectionDomain } from "../domain/collection";
import { CollectionView } from "../view/collectionView";
import { CollectionExport } from "./collectionExport";
export class CollectionWithIdExport extends CollectionExport {
id: string;
// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
build(o: CollectionView | CollectionDomain) {
this.id = o.id;
super.build(o);
}
}

View File

@@ -0,0 +1,28 @@
import { EventType } from "../../enums/eventType";
import { EventView } from "../view/eventView";
export class EventExport {
message: string;
appIcon: string;
appName: string;
userId: string;
userName: string;
userEmail: string;
date: string;
ip: string;
type: string;
installationId: string;
constructor(event: EventView) {
this.message = event.humanReadableMessage;
this.appIcon = event.appIcon;
this.appName = event.appName;
this.userId = event.userId;
this.userName = event.userName;
this.userEmail = event.userEmail;
this.date = event.date;
this.ip = event.ip;
this.type = EventType[event.type];
this.installationId = event.installationId;
}
}

View File

@@ -0,0 +1,52 @@
import { FieldType } from "../../enums/fieldType";
import { LinkedIdType } from "../../enums/linkedIdType";
import { EncString } from "../domain/encString";
import { Field as FieldDomain } from "../domain/field";
import { FieldView } from "../view/fieldView";
export class FieldExport {
static template(): FieldExport {
const req = new FieldExport();
req.name = "Field name";
req.value = "Some value";
req.type = FieldType.Text;
return req;
}
static toView(req: FieldExport, view = new FieldView()) {
view.type = req.type;
view.value = req.value;
view.name = req.name;
view.linkedId = req.linkedId;
return view;
}
static toDomain(req: FieldExport, domain = new FieldDomain()) {
domain.type = req.type;
domain.value = req.value != null ? new EncString(req.value) : null;
domain.name = req.name != null ? new EncString(req.name) : null;
domain.linkedId = req.linkedId;
return domain;
}
name: string;
value: string;
type: FieldType;
linkedId: LinkedIdType;
constructor(o?: FieldView | FieldDomain) {
if (o == null) {
return;
}
if (o instanceof FieldView) {
this.name = o.name;
this.value = o.value;
} else {
this.name = o.name?.encryptedString;
this.value = o.value?.encryptedString;
}
this.type = o.type;
this.linkedId = o.linkedId;
}
}

View File

@@ -0,0 +1,32 @@
import { EncString } from "../domain/encString";
import { Folder as FolderDomain } from "../domain/folder";
import { FolderView } from "../view/folderView";
export class FolderExport {
static template(): FolderExport {
const req = new FolderExport();
req.name = "Folder name";
return req;
}
static toView(req: FolderExport, view = new FolderView()) {
view.name = req.name;
return view;
}
static toDomain(req: FolderExport, domain = new FolderDomain()) {
domain.name = req.name != null ? new EncString(req.name) : null;
return domain;
}
name: string;
// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
build(o: FolderView | FolderDomain) {
if (o instanceof FolderView) {
this.name = o.name;
} else {
this.name = o.name?.encryptedString;
}
}
}

View File

@@ -0,0 +1,14 @@
import { Folder as FolderDomain } from "../domain/folder";
import { FolderView } from "../view/folderView";
import { FolderExport } from "./folderExport";
export class FolderWithIdExport extends FolderExport {
id: string;
// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
build(o: FolderView | FolderDomain) {
this.id = o.id;
super.build(o);
}
}

View File

@@ -0,0 +1,137 @@
import { EncString } from "../domain/encString";
import { Identity as IdentityDomain } from "../domain/identity";
import { IdentityView } from "../view/identityView";
export class IdentityExport {
static template(): IdentityExport {
const req = new IdentityExport();
req.title = "Mr";
req.firstName = "John";
req.middleName = "William";
req.lastName = "Doe";
req.address1 = "123 Any St";
req.address2 = "Apt #123";
req.address3 = null;
req.city = "New York";
req.state = "NY";
req.postalCode = "10001";
req.country = "US";
req.company = "Acme Inc.";
req.email = "john@company.com";
req.phone = "5555551234";
req.ssn = "000-123-4567";
req.username = "jdoe";
req.passportNumber = "US-123456789";
req.licenseNumber = "D123-12-123-12333";
return req;
}
static toView(req: IdentityExport, view = new IdentityView()) {
view.title = req.title;
view.firstName = req.firstName;
view.middleName = req.middleName;
view.lastName = req.lastName;
view.address1 = req.address1;
view.address2 = req.address2;
view.address3 = req.address3;
view.city = req.city;
view.state = req.state;
view.postalCode = req.postalCode;
view.country = req.country;
view.company = req.company;
view.email = req.email;
view.phone = req.phone;
view.ssn = req.ssn;
view.username = req.username;
view.passportNumber = req.passportNumber;
view.licenseNumber = req.licenseNumber;
return view;
}
static toDomain(req: IdentityExport, domain = new IdentityDomain()) {
domain.title = req.title != null ? new EncString(req.title) : null;
domain.firstName = req.firstName != null ? new EncString(req.firstName) : null;
domain.middleName = req.middleName != null ? new EncString(req.middleName) : null;
domain.lastName = req.lastName != null ? new EncString(req.lastName) : null;
domain.address1 = req.address1 != null ? new EncString(req.address1) : null;
domain.address2 = req.address2 != null ? new EncString(req.address2) : null;
domain.address3 = req.address3 != null ? new EncString(req.address3) : null;
domain.city = req.city != null ? new EncString(req.city) : null;
domain.state = req.state != null ? new EncString(req.state) : null;
domain.postalCode = req.postalCode != null ? new EncString(req.postalCode) : null;
domain.country = req.country != null ? new EncString(req.country) : null;
domain.company = req.company != null ? new EncString(req.company) : null;
domain.email = req.email != null ? new EncString(req.email) : null;
domain.phone = req.phone != null ? new EncString(req.phone) : null;
domain.ssn = req.ssn != null ? new EncString(req.ssn) : null;
domain.username = req.username != null ? new EncString(req.username) : null;
domain.passportNumber = req.passportNumber != null ? new EncString(req.passportNumber) : null;
domain.licenseNumber = req.licenseNumber != null ? new EncString(req.licenseNumber) : null;
return domain;
}
title: string;
firstName: string;
middleName: string;
lastName: string;
address1: string;
address2: string;
address3: string;
city: string;
state: string;
postalCode: string;
country: string;
company: string;
email: string;
phone: string;
ssn: string;
username: string;
passportNumber: string;
licenseNumber: string;
constructor(o?: IdentityView | IdentityDomain) {
if (o == null) {
return;
}
if (o instanceof IdentityView) {
this.title = o.title;
this.firstName = o.firstName;
this.middleName = o.middleName;
this.lastName = o.lastName;
this.address1 = o.address1;
this.address2 = o.address2;
this.address3 = o.address3;
this.city = o.city;
this.state = o.state;
this.postalCode = o.postalCode;
this.country = o.country;
this.company = o.company;
this.email = o.email;
this.phone = o.phone;
this.ssn = o.ssn;
this.username = o.username;
this.passportNumber = o.passportNumber;
this.licenseNumber = o.licenseNumber;
} else {
this.title = o.title?.encryptedString;
this.firstName = o.firstName?.encryptedString;
this.middleName = o.middleName?.encryptedString;
this.lastName = o.lastName?.encryptedString;
this.address1 = o.address1?.encryptedString;
this.address2 = o.address2?.encryptedString;
this.address3 = o.address3?.encryptedString;
this.city = o.city?.encryptedString;
this.state = o.state?.encryptedString;
this.postalCode = o.postalCode?.encryptedString;
this.country = o.country?.encryptedString;
this.company = o.company?.encryptedString;
this.email = o.email?.encryptedString;
this.phone = o.phone?.encryptedString;
this.ssn = o.ssn?.encryptedString;
this.username = o.username?.encryptedString;
this.passportNumber = o.passportNumber?.encryptedString;
this.licenseNumber = o.licenseNumber?.encryptedString;
}
}
}

View File

@@ -0,0 +1,65 @@
import { EncString } from "../domain/encString";
import { Login as LoginDomain } from "../domain/login";
import { LoginView } from "../view/loginView";
import { LoginUriExport } from "./loginUriExport";
export class LoginExport {
static template(): LoginExport {
const req = new LoginExport();
req.uris = [];
req.username = "jdoe";
req.password = "myp@ssword123";
req.totp = "JBSWY3DPEHPK3PXP";
return req;
}
static toView(req: LoginExport, view = new LoginView()) {
if (req.uris != null) {
view.uris = req.uris.map((u) => LoginUriExport.toView(u));
}
view.username = req.username;
view.password = req.password;
view.totp = req.totp;
return view;
}
static toDomain(req: LoginExport, domain = new LoginDomain()) {
if (req.uris != null) {
domain.uris = req.uris.map((u) => LoginUriExport.toDomain(u));
}
domain.username = req.username != null ? new EncString(req.username) : null;
domain.password = req.password != null ? new EncString(req.password) : null;
domain.totp = req.totp != null ? new EncString(req.totp) : null;
return domain;
}
uris: LoginUriExport[];
username: string;
password: string;
totp: string;
constructor(o?: LoginView | LoginDomain) {
if (o == null) {
return;
}
if (o.uris != null) {
if (o instanceof LoginView) {
this.uris = o.uris.map((u) => new LoginUriExport(u));
} else {
this.uris = o.uris.map((u) => new LoginUriExport(u));
}
}
if (o instanceof LoginView) {
this.username = o.username;
this.password = o.password;
this.totp = o.totp;
} else {
this.username = o.username?.encryptedString;
this.password = o.password?.encryptedString;
this.totp = o.totp?.encryptedString;
}
}
}

View File

@@ -0,0 +1,41 @@
import { UriMatchType } from "../../enums/uriMatchType";
import { EncString } from "../domain/encString";
import { LoginUri as LoginUriDomain } from "../domain/loginUri";
import { LoginUriView } from "../view/loginUriView";
export class LoginUriExport {
static template(): LoginUriExport {
const req = new LoginUriExport();
req.uri = "https://google.com";
req.match = null;
return req;
}
static toView(req: LoginUriExport, view = new LoginUriView()) {
view.uri = req.uri;
view.match = req.match;
return view;
}
static toDomain(req: LoginUriExport, domain = new LoginUriDomain()) {
domain.uri = req.uri != null ? new EncString(req.uri) : null;
domain.match = req.match;
return domain;
}
uri: string;
match: UriMatchType = null;
constructor(o?: LoginUriView | LoginUriDomain) {
if (o == null) {
return;
}
if (o instanceof LoginUriView) {
this.uri = o.uri;
} else {
this.uri = o.uri?.encryptedString;
}
this.match = o.match;
}
}

View File

@@ -0,0 +1,31 @@
import { SecureNoteType } from "../../enums/secureNoteType";
import { SecureNote as SecureNoteDomain } from "../domain/secureNote";
import { SecureNoteView } from "../view/secureNoteView";
export class SecureNoteExport {
static template(): SecureNoteExport {
const req = new SecureNoteExport();
req.type = SecureNoteType.Generic;
return req;
}
static toView(req: SecureNoteExport, view = new SecureNoteView()) {
view.type = req.type;
return view;
}
static toDomain(req: SecureNoteExport, view = new SecureNoteDomain()) {
view.type = req.type;
return view;
}
type: SecureNoteType;
constructor(o?: SecureNoteView | SecureNoteDomain) {
if (o == null) {
return;
}
this.type = o.type;
}
}