mirror of
https://github.com/bitwarden/jslib
synced 2025-12-15 07:43:45 +00:00
Split jslib into multiple modules (#363)
* Split jslib into multiple modules
This commit is contained in:
66
common/src/models/export/card.ts
Normal file
66
common/src/models/export/card.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { CardView } from '../view/cardView';
|
||||
|
||||
import { Card as CardDomain } from '../domain/card';
|
||||
import { EncString } from '../domain/encString';
|
||||
|
||||
export class Card {
|
||||
static template(): Card {
|
||||
const req = new Card();
|
||||
req.cardholderName = 'John Doe';
|
||||
req.brand = 'visa';
|
||||
req.number = '4242424242424242';
|
||||
req.expMonth = '04';
|
||||
req.expYear = '2023';
|
||||
req.code = '123';
|
||||
return req;
|
||||
}
|
||||
|
||||
static toView(req: Card, 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: Card, 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
158
common/src/models/export/cipher.ts
Normal file
158
common/src/models/export/cipher.ts
Normal file
@@ -0,0 +1,158 @@
|
||||
import { CipherRepromptType } from '../../enums/cipherRepromptType';
|
||||
import { CipherType } from '../../enums/cipherType';
|
||||
|
||||
import { CipherView } from '../view/cipherView';
|
||||
|
||||
import { Cipher as CipherDomain } from '../domain/cipher';
|
||||
import { EncString } from '../domain/encString';
|
||||
|
||||
import { Card } from './card';
|
||||
import { Field } from './field';
|
||||
import { Identity } from './identity';
|
||||
import { Login } from './login';
|
||||
import { SecureNote } from './secureNote';
|
||||
|
||||
export class Cipher {
|
||||
static template(): Cipher {
|
||||
const req = new Cipher();
|
||||
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: Cipher, 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 => Field.toView(f));
|
||||
}
|
||||
|
||||
switch (req.type) {
|
||||
case CipherType.Login:
|
||||
view.login = Login.toView(req.login);
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
view.secureNote = SecureNote.toView(req.secureNote);
|
||||
break;
|
||||
case CipherType.Card:
|
||||
view.card = Card.toView(req.card);
|
||||
break;
|
||||
case CipherType.Identity:
|
||||
view.identity = Identity.toView(req.identity);
|
||||
break;
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
static toDomain(req: Cipher, 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 => Field.toDomain(f));
|
||||
}
|
||||
|
||||
switch (req.type) {
|
||||
case CipherType.Login:
|
||||
domain.login = Login.toDomain(req.login);
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
domain.secureNote = SecureNote.toDomain(req.secureNote);
|
||||
break;
|
||||
case CipherType.Card:
|
||||
domain.card = Card.toDomain(req.card);
|
||||
break;
|
||||
case CipherType.Identity:
|
||||
domain.identity = Identity.toDomain(req.identity);
|
||||
break;
|
||||
}
|
||||
|
||||
return domain;
|
||||
}
|
||||
|
||||
type: CipherType;
|
||||
folderId: string;
|
||||
organizationId: string;
|
||||
collectionIds: string[];
|
||||
name: string;
|
||||
notes: string;
|
||||
favorite: boolean;
|
||||
fields: Field[];
|
||||
login: Login;
|
||||
secureNote: SecureNote;
|
||||
card: Card;
|
||||
identity: Identity;
|
||||
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 Field(f));
|
||||
} else {
|
||||
this.fields = o.fields.map(f => new Field(f));
|
||||
}
|
||||
}
|
||||
|
||||
switch (o.type) {
|
||||
case CipherType.Login:
|
||||
this.login = new Login(o.login);
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
this.secureNote = new SecureNote(o.secureNote);
|
||||
break;
|
||||
case CipherType.Card:
|
||||
this.card = new Card(o.card);
|
||||
break;
|
||||
case CipherType.Identity:
|
||||
this.identity = new Identity(o.identity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
common/src/models/export/cipherWithIds.ts
Normal file
17
common/src/models/export/cipherWithIds.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Cipher } from './cipher';
|
||||
|
||||
import { CipherView } from '../view/cipherView';
|
||||
|
||||
import { Cipher as CipherDomain } from '../domain/cipher';
|
||||
|
||||
export class CipherWithIds extends Cipher {
|
||||
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;
|
||||
}
|
||||
}
|
||||
47
common/src/models/export/collection.ts
Normal file
47
common/src/models/export/collection.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { CollectionView } from '../view/collectionView';
|
||||
|
||||
import { Collection as CollectionDomain } from '../domain/collection';
|
||||
import { EncString } from '../domain/encString';
|
||||
|
||||
export class Collection {
|
||||
static template(): Collection {
|
||||
const req = new Collection();
|
||||
req.organizationId = '00000000-0000-0000-0000-000000000000';
|
||||
req.name = 'Collection name';
|
||||
req.externalId = null;
|
||||
return req;
|
||||
}
|
||||
|
||||
static toView(req: Collection, view = new CollectionView()) {
|
||||
view.name = req.name;
|
||||
view.externalId = req.externalId;
|
||||
if (view.organizationId == null) {
|
||||
view.organizationId = req.organizationId;
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
static toDomain(req: Collection, 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;
|
||||
}
|
||||
}
|
||||
15
common/src/models/export/collectionWithId.ts
Normal file
15
common/src/models/export/collectionWithId.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Collection } from './collection';
|
||||
|
||||
import { CollectionView } from '../view/collectionView';
|
||||
|
||||
import { Collection as CollectionDomain } from '../domain/collection';
|
||||
|
||||
export class CollectionWithId extends Collection {
|
||||
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);
|
||||
}
|
||||
}
|
||||
26
common/src/models/export/event.ts
Normal file
26
common/src/models/export/event.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { EventType } from '../../enums/eventType';
|
||||
import { EventView } from '../view/eventView';
|
||||
|
||||
export class Event {
|
||||
message: string;
|
||||
appIcon: string;
|
||||
appName: string;
|
||||
userId: string;
|
||||
userName: string;
|
||||
userEmail: string;
|
||||
date: string;
|
||||
ip: string;
|
||||
type: 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];
|
||||
}
|
||||
}
|
||||
49
common/src/models/export/field.ts
Normal file
49
common/src/models/export/field.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { FieldType } from '../../enums/fieldType';
|
||||
|
||||
import { FieldView } from '../view/fieldView';
|
||||
|
||||
import { EncString } from '../domain/encString';
|
||||
import { Field as FieldDomain } from '../domain/field';
|
||||
|
||||
export class Field {
|
||||
static template(): Field {
|
||||
const req = new Field();
|
||||
req.name = 'Field name';
|
||||
req.value = 'Some value';
|
||||
req.type = FieldType.Text;
|
||||
return req;
|
||||
}
|
||||
|
||||
static toView(req: Field, view = new FieldView()) {
|
||||
view.type = req.type;
|
||||
view.value = req.value;
|
||||
view.name = req.name;
|
||||
return view;
|
||||
}
|
||||
|
||||
static toDomain(req: Field, 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;
|
||||
return domain;
|
||||
}
|
||||
|
||||
name: string;
|
||||
value: string;
|
||||
type: FieldType;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
33
common/src/models/export/folder.ts
Normal file
33
common/src/models/export/folder.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { FolderView } from '../view/folderView';
|
||||
|
||||
import { EncString } from '../domain/encString';
|
||||
import { Folder as FolderDomain } from '../domain/folder';
|
||||
|
||||
export class Folder {
|
||||
static template(): Folder {
|
||||
const req = new Folder();
|
||||
req.name = 'Folder name';
|
||||
return req;
|
||||
}
|
||||
|
||||
static toView(req: Folder, view = new FolderView()) {
|
||||
view.name = req.name;
|
||||
return view;
|
||||
}
|
||||
|
||||
static toDomain(req: Folder, 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
15
common/src/models/export/folderWithId.ts
Normal file
15
common/src/models/export/folderWithId.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Folder } from './folder';
|
||||
|
||||
import { FolderView } from '../view/folderView';
|
||||
|
||||
import { Folder as FolderDomain } from '../domain/folder';
|
||||
|
||||
export class FolderWithId extends Folder {
|
||||
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);
|
||||
}
|
||||
}
|
||||
138
common/src/models/export/identity.ts
Normal file
138
common/src/models/export/identity.ts
Normal file
@@ -0,0 +1,138 @@
|
||||
import { IdentityView } from '../view/identityView';
|
||||
|
||||
import { EncString } from '../domain/encString';
|
||||
import { Identity as IdentityDomain } from '../domain/identity';
|
||||
|
||||
export class Identity {
|
||||
static template(): Identity {
|
||||
const req = new Identity();
|
||||
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: Identity, 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: Identity, 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
66
common/src/models/export/login.ts
Normal file
66
common/src/models/export/login.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { LoginUri } from './loginUri';
|
||||
|
||||
import { LoginView } from '../view/loginView';
|
||||
|
||||
import { EncString } from '../domain/encString';
|
||||
import { Login as LoginDomain } from '../domain/login';
|
||||
|
||||
export class Login {
|
||||
static template(): Login {
|
||||
const req = new Login();
|
||||
req.uris = [];
|
||||
req.username = 'jdoe';
|
||||
req.password = 'myp@ssword123';
|
||||
req.totp = 'JBSWY3DPEHPK3PXP';
|
||||
return req;
|
||||
}
|
||||
|
||||
static toView(req: Login, view = new LoginView()) {
|
||||
if (req.uris != null) {
|
||||
view.uris = req.uris.map(u => LoginUri.toView(u));
|
||||
}
|
||||
view.username = req.username;
|
||||
view.password = req.password;
|
||||
view.totp = req.totp;
|
||||
return view;
|
||||
}
|
||||
|
||||
static toDomain(req: Login, domain = new LoginDomain()) {
|
||||
if (req.uris != null) {
|
||||
domain.uris = req.uris.map(u => LoginUri.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: LoginUri[];
|
||||
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 LoginUri(u));
|
||||
} else {
|
||||
this.uris = o.uris.map(u => new LoginUri(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
43
common/src/models/export/loginUri.ts
Normal file
43
common/src/models/export/loginUri.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { UriMatchType } from '../../enums/uriMatchType';
|
||||
|
||||
import { LoginUriView } from '../view/loginUriView';
|
||||
|
||||
import { EncString } from '../domain/encString';
|
||||
import { LoginUri as LoginUriDomain } from '../domain/loginUri';
|
||||
|
||||
export class LoginUri {
|
||||
static template(): LoginUri {
|
||||
const req = new LoginUri();
|
||||
req.uri = 'https://google.com';
|
||||
req.match = null;
|
||||
return req;
|
||||
}
|
||||
|
||||
static toView(req: LoginUri, view = new LoginUriView()) {
|
||||
view.uri = req.uri;
|
||||
view.match = req.match;
|
||||
return view;
|
||||
}
|
||||
|
||||
static toDomain(req: LoginUri, 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;
|
||||
}
|
||||
}
|
||||
33
common/src/models/export/secureNote.ts
Normal file
33
common/src/models/export/secureNote.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { SecureNoteType } from '../../enums/secureNoteType';
|
||||
|
||||
import { SecureNoteView } from '../view/secureNoteView';
|
||||
|
||||
import { SecureNote as SecureNoteDomain } from '../domain/secureNote';
|
||||
|
||||
export class SecureNote {
|
||||
static template(): SecureNote {
|
||||
const req = new SecureNote();
|
||||
req.type = SecureNoteType.Generic;
|
||||
return req;
|
||||
}
|
||||
|
||||
static toView(req: SecureNote, view = new SecureNoteView()) {
|
||||
view.type = req.type;
|
||||
return view;
|
||||
}
|
||||
|
||||
static toDomain(req: SecureNote, view = new SecureNoteDomain()) {
|
||||
view.type = req.type;
|
||||
return view;
|
||||
}
|
||||
|
||||
type: SecureNoteType;
|
||||
|
||||
constructor(o?: SecureNoteView | SecureNoteDomain) {
|
||||
if (o == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.type = o.type;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user