mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 08:43:33 +00:00
added models, crypto, and constants services
This commit is contained in:
18
src/models/response/attachmentResponse.ts
Normal file
18
src/models/response/attachmentResponse.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
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;
|
||||
44
src/models/response/cipherResponse.ts
Normal file
44
src/models/response/cipherResponse.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
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;
|
||||
14
src/models/response/collectionResponse.ts
Normal file
14
src/models/response/collectionResponse.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
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;
|
||||
20
src/models/response/deviceResponse.ts
Normal file
20
src/models/response/deviceResponse.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { DeviceType } from '../../enums/deviceType';
|
||||
|
||||
class DeviceResponse {
|
||||
id: string;
|
||||
name: number;
|
||||
identifier: string;
|
||||
type: 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;
|
||||
20
src/models/response/domainsResponse.ts
Normal file
20
src/models/response/domainsResponse.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
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;
|
||||
37
src/models/response/errorResponse.ts
Normal file
37
src/models/response/errorResponse.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
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;
|
||||
14
src/models/response/folderResponse.ts
Normal file
14
src/models/response/folderResponse.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
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;
|
||||
14
src/models/response/globalDomainResponse.ts
Normal file
14
src/models/response/globalDomainResponse.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
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;
|
||||
24
src/models/response/identityTokenResponse.ts
Normal file
24
src/models/response/identityTokenResponse.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
14
src/models/response/index.ts
Normal file
14
src/models/response/index.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export { AttachmentResponse } from './attachmentResponse';
|
||||
export { CipherResponse } from './cipherResponse';
|
||||
export { CollectionResponse } from './collectionResponse';
|
||||
export { DeviceResponse } from './deviceResponse';
|
||||
export { DomainsResponse } from './domainsResponse';
|
||||
export { ErrorResponse } from './errorResponse';
|
||||
export { FolderResponse } from './folderResponse';
|
||||
export { GlobalDomainResponse } from './globalDomainResponse';
|
||||
export { IdentityTokenResponse } from './identityTokenResponse';
|
||||
export { KeysResponse } from './keysResponse';
|
||||
export { ListResponse } from './listResponse';
|
||||
export { ProfileOrganizationResponse } from './profileOrganizationResponse';
|
||||
export { ProfileResponse } from './profileResponse';
|
||||
export { SyncResponse } from './syncResponse';
|
||||
12
src/models/response/keysResponse.ts
Normal file
12
src/models/response/keysResponse.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
class KeysResponse {
|
||||
privateKey: string;
|
||||
publicKey: string;
|
||||
|
||||
constructor(response: any) {
|
||||
this.privateKey = response.PrivateKey;
|
||||
this.publicKey = response.PublicKey;
|
||||
}
|
||||
}
|
||||
|
||||
export { KeysResponse };
|
||||
(window as any).KeysResponse = KeysResponse;
|
||||
10
src/models/response/listResponse.ts
Normal file
10
src/models/response/listResponse.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
class ListResponse {
|
||||
data: any;
|
||||
|
||||
constructor(data: any) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
export { ListResponse };
|
||||
(window as any).ListResponse = ListResponse;
|
||||
30
src/models/response/profileOrganizationResponse.ts
Normal file
30
src/models/response/profileOrganizationResponse.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
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;
|
||||
39
src/models/response/profileResponse.ts
Normal file
39
src/models/response/profileResponse.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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;
|
||||
44
src/models/response/syncResponse.ts
Normal file
44
src/models/response/syncResponse.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user