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

copy common ts code over from browser repo

This commit is contained in:
Kyle Spearrin
2018-01-03 21:20:41 -05:00
parent ace8bd5e85
commit a95632294f
77 changed files with 6179 additions and 0 deletions

View 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;

View 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;

View 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;

View File

@@ -0,0 +1,20 @@
import { BrowserType } from '../../enums/browserType.enum';
class DeviceResponse {
id: string;
name: number;
identifier: string;
type: BrowserType;
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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View File

@@ -0,0 +1,10 @@
class ListResponse {
data: any;
constructor(data: any) {
this.data = data;
}
}
export { ListResponse };
(window as any).ListResponse = ListResponse;

View 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;

View 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;

View 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;