1
0
mirror of https://github.com/bitwarden/jslib synced 2025-12-21 10:43:23 +00:00

Split jslib into multiple modules (#363)

* Split jslib into multiple modules
This commit is contained in:
Oscar Hinton
2021-06-03 18:58:57 +02:00
committed by GitHub
parent b1d9b84eae
commit 1016bbfb9e
509 changed files with 8838 additions and 1887 deletions

View File

@@ -0,0 +1,22 @@
import { AttachmentResponse } from '../response/attachmentResponse';
export class AttachmentData {
id: string;
url: string;
fileName: string;
key: string;
size: string;
sizeName: string;
constructor(response?: AttachmentResponse) {
if (response == null) {
return;
}
this.id = response.id;
this.url = response.url;
this.fileName = response.fileName;
this.key = response.key;
this.size = response.size;
this.sizeName = response.sizeName;
}
}

View File

@@ -0,0 +1,23 @@
import { CardApi } from '../api/cardApi';
export class CardData {
cardholderName: string;
brand: string;
number: string;
expMonth: string;
expYear: string;
code: string;
constructor(data?: CardApi) {
if (data == null) {
return;
}
this.cardholderName = data.cardholderName;
this.brand = data.brand;
this.number = data.number;
this.expMonth = data.expMonth;
this.expYear = data.expYear;
this.code = data.code;
}
}

View File

@@ -0,0 +1,87 @@
import { CipherRepromptType } from '../../enums/cipherRepromptType';
import { CipherType } from '../../enums/cipherType';
import { AttachmentData } from './attachmentData';
import { CardData } from './cardData';
import { FieldData } from './fieldData';
import { IdentityData } from './identityData';
import { LoginData } from './loginData';
import { PasswordHistoryData } from './passwordHistoryData';
import { SecureNoteData } from './secureNoteData';
import { CipherResponse } from '../response/cipherResponse';
export class CipherData {
id: string;
organizationId: string;
folderId: string;
userId: string;
edit: boolean;
viewPassword: boolean;
organizationUseTotp: boolean;
favorite: boolean;
revisionDate: string;
type: CipherType;
sizeName: string;
name: string;
notes: string;
login?: LoginData;
secureNote?: SecureNoteData;
card?: CardData;
identity?: IdentityData;
fields?: FieldData[];
attachments?: AttachmentData[];
passwordHistory?: PasswordHistoryData[];
collectionIds?: string[];
deletedDate: string;
reprompt: CipherRepromptType;
constructor(response?: CipherResponse, userId?: string, collectionIds?: string[]) {
if (response == null) {
return;
}
this.id = response.id;
this.organizationId = response.organizationId;
this.folderId = response.folderId;
this.userId = userId;
this.edit = response.edit;
this.viewPassword = response.viewPassword;
this.organizationUseTotp = response.organizationUseTotp;
this.favorite = response.favorite;
this.revisionDate = response.revisionDate;
this.type = response.type;
this.name = response.name;
this.notes = response.notes;
this.collectionIds = collectionIds != null ? collectionIds : response.collectionIds;
this.deletedDate = response.deletedDate;
this.reprompt = response.reprompt;
switch (this.type) {
case CipherType.Login:
this.login = new LoginData(response.login);
break;
case CipherType.SecureNote:
this.secureNote = new SecureNoteData(response.secureNote);
break;
case CipherType.Card:
this.card = new CardData(response.card);
break;
case CipherType.Identity:
this.identity = new IdentityData(response.identity);
break;
default:
break;
}
if (response.fields != null) {
this.fields = response.fields.map(f => new FieldData(f));
}
if (response.attachments != null) {
this.attachments = response.attachments.map(a => new AttachmentData(a));
}
if (response.passwordHistory != null) {
this.passwordHistory = response.passwordHistory.map(ph => new PasswordHistoryData(ph));
}
}
}

View File

@@ -0,0 +1,17 @@
import { CollectionDetailsResponse } from '../response/collectionResponse';
export class CollectionData {
id: string;
organizationId: string;
name: string;
externalId: string;
readOnly: boolean;
constructor(response: CollectionDetailsResponse) {
this.id = response.id;
this.organizationId = response.organizationId;
this.name = response.name;
this.externalId = response.externalId;
this.readOnly = response.readOnly;
}
}

View File

@@ -0,0 +1,7 @@
import { EventType } from '../../enums/eventType';
export class EventData {
type: EventType;
cipherId: string;
date: string;
}

View File

@@ -0,0 +1,18 @@
import { FieldType } from '../../enums/fieldType';
import { FieldApi } from '../api/fieldApi';
export class FieldData {
type: FieldType;
name: string;
value: string;
constructor(response?: FieldApi) {
if (response == null) {
return;
}
this.type = response.type;
this.name = response.name;
this.value = response.value;
}
}

View File

@@ -0,0 +1,15 @@
import { FolderResponse } from '../response/folderResponse';
export class FolderData {
id: string;
userId: string;
name: string;
revisionDate: string;
constructor(response: FolderResponse, userId: string) {
this.userId = userId;
this.name = response.name;
this.id = response.id;
this.revisionDate = response.revisionDate;
}
}

View File

@@ -0,0 +1,47 @@
import { IdentityApi } from '../api/identityApi';
export class IdentityData {
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(data?: IdentityApi) {
if (data == null) {
return;
}
this.title = data.title;
this.firstName = data.firstName;
this.middleName = data.middleName;
this.lastName = data.lastName;
this.address1 = data.address1;
this.address2 = data.address2;
this.address3 = data.address3;
this.city = data.city;
this.state = data.state;
this.postalCode = data.postalCode;
this.country = data.country;
this.company = data.company;
this.email = data.email;
this.phone = data.phone;
this.ssn = data.ssn;
this.username = data.username;
this.passportNumber = data.passportNumber;
this.licenseNumber = data.licenseNumber;
}
}

View File

@@ -0,0 +1,10 @@
export { AttachmentData } from './attachmentData';
export { CardData } from './cardData';
export { CipherData } from './cipherData';
export { CollectionData } from './collectionData';
export { FieldData } from './fieldData';
export { FolderData } from './folderData';
export { IdentityData } from './identityData';
export { LoginData } from './loginData';
export { LoginUriData } from './loginUriData';
export { SecureNoteData } from './secureNoteData';

View File

@@ -0,0 +1,28 @@
import { LoginApi } from '../api/loginApi';
import { LoginUriData } from './loginUriData';
export class LoginData {
uris: LoginUriData[];
username: string;
password: string;
passwordRevisionDate: string;
totp: string;
autofillOnPageLoad: boolean;
constructor(data?: LoginApi) {
if (data == null) {
return;
}
this.username = data.username;
this.password = data.password;
this.passwordRevisionDate = data.passwordRevisionDate;
this.totp = data.totp;
this.autofillOnPageLoad = data.autofillOnPageLoad;
if (data.uris) {
this.uris = data.uris.map(u => new LoginUriData(u));
}
}
}

View File

@@ -0,0 +1,16 @@
import { UriMatchType } from '../../enums/uriMatchType';
import { LoginUriApi } from '../api/loginUriApi';
export class LoginUriData {
uri: string;
match: UriMatchType = null;
constructor(data?: LoginUriApi) {
if (data == null) {
return;
}
this.uri = data.uri;
this.match = data.match;
}
}

View File

@@ -0,0 +1,63 @@
import { ProfileOrganizationResponse } from '../response/profileOrganizationResponse';
import { OrganizationUserStatusType } from '../../enums/organizationUserStatusType';
import { OrganizationUserType } from '../../enums/organizationUserType';
import { PermissionsApi } from '../api/permissionsApi';
export class OrganizationData {
id: string;
name: string;
status: OrganizationUserStatusType;
type: OrganizationUserType;
enabled: boolean;
usePolicies: boolean;
useGroups: boolean;
useDirectory: boolean;
useEvents: boolean;
useTotp: boolean;
use2fa: boolean;
useApi: boolean;
useBusinessPortal: boolean;
useSso: boolean;
useResetPassword: boolean;
selfHost: boolean;
usersGetPremium: boolean;
seats: number;
maxCollections: number;
maxStorageGb?: number;
ssoBound: boolean;
identifier: string;
permissions: PermissionsApi;
resetPasswordEnrolled: boolean;
userId: string;
hasPublicAndPrivateKeys: boolean;
constructor(response: ProfileOrganizationResponse) {
this.id = response.id;
this.name = response.name;
this.status = response.status;
this.type = response.type;
this.enabled = response.enabled;
this.usePolicies = response.usePolicies;
this.useGroups = response.useGroups;
this.useDirectory = response.useDirectory;
this.useEvents = response.useEvents;
this.useTotp = response.useTotp;
this.use2fa = response.use2fa;
this.useApi = response.useApi;
this.useBusinessPortal = response.useBusinessPortal;
this.useSso = response.useSso;
this.useResetPassword = response.useResetPassword;
this.selfHost = response.selfHost;
this.usersGetPremium = response.usersGetPremium;
this.seats = response.seats;
this.maxCollections = response.maxCollections;
this.maxStorageGb = response.maxStorageGb;
this.ssoBound = response.ssoBound;
this.identifier = response.identifier;
this.permissions = response.permissions;
this.resetPasswordEnrolled = response.resetPasswordEnrolled;
this.userId = response.userId;
this.hasPublicAndPrivateKeys = response.hasPublicAndPrivateKeys;
}
}

View File

@@ -0,0 +1,15 @@
import { PasswordHistoryResponse } from '../response/passwordHistoryResponse';
export class PasswordHistoryData {
password: string;
lastUsedDate: string;
constructor(response?: PasswordHistoryResponse) {
if (response == null) {
return;
}
this.password = response.password;
this.lastUsedDate = response.lastUsedDate;
}
}

View File

@@ -0,0 +1,19 @@
import { PolicyResponse } from '../response/policyResponse';
import { PolicyType } from '../../enums/policyType';
export class PolicyData {
id: string;
organizationId: string;
type: PolicyType;
data: any;
enabled: boolean;
constructor(response: PolicyResponse) {
this.id = response.id;
this.organizationId = response.organizationId;
this.type = response.type;
this.data = response.data;
this.enabled = response.enabled;
}
}

View File

@@ -0,0 +1,15 @@
import { SecureNoteType } from '../../enums/secureNoteType';
import { SecureNoteApi } from '../api/secureNoteApi';
export class SecureNoteData {
type: SecureNoteType;
constructor(data?: SecureNoteApi) {
if (data == null) {
return;
}
this.type = data.type;
}
}

View File

@@ -0,0 +1,59 @@
import { SendType } from '../../enums/sendType';
import { SendFileData } from './sendFileData';
import { SendTextData } from './sendTextData';
import { SendResponse } from '../response/sendResponse';
export class SendData {
id: string;
accessId: string;
userId: string;
type: SendType;
name: string;
notes: string;
file: SendFileData;
text: SendTextData;
key: string;
maxAccessCount?: number;
accessCount: number;
revisionDate: string;
expirationDate: string;
deletionDate: string;
password: string;
disabled: boolean;
hideEmail: boolean;
constructor(response?: SendResponse, userId?: string) {
if (response == null) {
return;
}
this.id = response.id;
this.accessId = response.accessId;
this.userId = userId;
this.type = response.type;
this.name = response.name;
this.notes = response.notes;
this.key = response.key;
this.maxAccessCount = response.maxAccessCount;
this.accessCount = response.accessCount;
this.revisionDate = response.revisionDate;
this.expirationDate = response.expirationDate;
this.deletionDate = response.deletionDate;
this.password = response.password;
this.disabled = response.disable;
this.hideEmail = response.hideEmail;
switch (this.type) {
case SendType.Text:
this.text = new SendTextData(response.text);
break;
case SendType.File:
this.file = new SendFileData(response.file);
break;
default:
break;
}
}
}

View File

@@ -0,0 +1,21 @@
import { SendFileApi } from '../api/sendFileApi';
export class SendFileData {
id: string;
fileName: string;
key: string;
size: string;
sizeName: string;
constructor(data?: SendFileApi) {
if (data == null) {
return;
}
this.id = data.id;
this.fileName = data.fileName;
this.key = data.key;
this.size = data.size;
this.sizeName = data.sizeName;
}
}

View File

@@ -0,0 +1,15 @@
import { SendTextApi } from '../api/sendTextApi';
export class SendTextData {
text: string;
hidden: boolean;
constructor(data?: SendTextApi) {
if (data == null) {
return;
}
this.text = data.text;
this.hidden = data.hidden;
}
}