support camel or pascal case in API responses

This commit is contained in:
Kyle Spearrin 2019-03-01 00:13:37 -05:00
parent 62e9c75357
commit 48164a31d9
43 changed files with 637 additions and 449 deletions

View File

@ -1,4 +1,6 @@
export class CardApi { import { BaseResponse } from '../response/baseResponse';
export class CardApi extends BaseResponse {
cardholderName: string; cardholderName: string;
brand: string; brand: string;
number: string; number: string;
@ -6,12 +8,16 @@ export class CardApi {
expYear: string; expYear: string;
code: string; code: string;
constructor(data: any) { constructor(data: any = null) {
this.cardholderName = data.CardholderName; super(data);
this.brand = data.Brand; if (data == null) {
this.number = data.Number; return;
this.expMonth = data.ExpMonth; }
this.expYear = data.ExpYear; this.cardholderName = this.getResponseProperty('CardholderName');
this.code = data.Code; this.brand = this.getResponseProperty('Brand');
this.number = this.getResponseProperty('Number');
this.expMonth = this.getResponseProperty('ExpMonth');
this.expYear = this.getResponseProperty('ExpYear');
this.code = this.getResponseProperty('Code');
} }
} }

View File

@ -1,13 +1,19 @@
import { BaseResponse } from '../response/baseResponse';
import { FieldType } from '../../enums/fieldType'; import { FieldType } from '../../enums/fieldType';
export class FieldApi { export class FieldApi extends BaseResponse {
name: string; name: string;
value: string; value: string;
type: FieldType; type: FieldType;
constructor(response: any) { constructor(data: any = null) {
this.type = response.Type; super(data);
this.name = response.Name; if (data == null) {
this.value = response.Value; return;
}
this.type = this.getResponseProperty('Type');
this.name = this.getResponseProperty('Name');
this.value = this.getResponseProperty('Value');
} }
} }

View File

@ -1,4 +1,6 @@
export class IdentityApi { import { BaseResponse } from '../response/baseResponse';
export class IdentityApi extends BaseResponse {
title: string; title: string;
firstName: string; firstName: string;
middleName: string; middleName: string;
@ -18,24 +20,28 @@ export class IdentityApi {
passportNumber: string; passportNumber: string;
licenseNumber: string; licenseNumber: string;
constructor(data: any) { constructor(data: any = null) {
this.title = data.Title; super(data);
this.firstName = data.FirstName; if (data == null) {
this.middleName = data.MiddleName; return;
this.lastName = data.LastName; }
this.address1 = data.Address1; this.title = this.getResponseProperty('Title');
this.address2 = data.Address2; this.firstName = this.getResponseProperty('FirstName');
this.address3 = data.Address3; this.middleName = this.getResponseProperty('MiddleName');
this.city = data.City; this.lastName = this.getResponseProperty('LastName');
this.state = data.State; this.address1 = this.getResponseProperty('Address1');
this.postalCode = data.PostalCode; this.address2 = this.getResponseProperty('Address2');
this.country = data.Country; this.address3 = this.getResponseProperty('Address3');
this.company = data.Company; this.city = this.getResponseProperty('City');
this.email = data.Email; this.state = this.getResponseProperty('State');
this.phone = data.Phone; this.postalCode = this.getResponseProperty('PostalCode');
this.ssn = data.SSN; this.country = this.getResponseProperty('Country');
this.username = data.Username; this.company = this.getResponseProperty('Company');
this.passportNumber = data.PassportNumber; this.email = this.getResponseProperty('Email');
this.licenseNumber = data.LicenseNumber; this.phone = this.getResponseProperty('Phone');
this.ssn = this.getResponseProperty('SSN');
this.username = this.getResponseProperty('Username');
this.passportNumber = this.getResponseProperty('PassportNumber');
this.licenseNumber = this.getResponseProperty('LicenseNumber');
} }
} }

View File

@ -1,23 +1,27 @@
import { BaseResponse } from '../response/baseResponse';
import { LoginUriApi } from './loginUriApi'; import { LoginUriApi } from './loginUriApi';
export class LoginApi { export class LoginApi extends BaseResponse {
uris: LoginUriApi[]; uris: LoginUriApi[];
username: string; username: string;
password: string; password: string;
passwordRevisionDate: string; passwordRevisionDate: string;
totp: string; totp: string;
constructor(data: any) { constructor(data: any = null) {
this.username = data.Username; super(data);
this.password = data.Password; if (data == null) {
this.passwordRevisionDate = data.PasswordRevisionDate; return;
this.totp = data.Totp; }
this.username = this.getResponseProperty('Username');
this.password = this.getResponseProperty('Password');
this.passwordRevisionDate = this.getResponseProperty('PasswordRevisionDate');
this.totp = this.getResponseProperty('Totp');
if (data.Uris) { const uris = this.getResponseProperty('Uris');
this.uris = []; if (uris != null) {
data.Uris.forEach((u: any) => { this.uris = uris.map((u: any) => new LoginUriApi(u));
this.uris.push(new LoginUriApi(u));
});
} }
} }
} }

View File

@ -1,11 +1,18 @@
import { BaseResponse } from '../response/baseResponse';
import { UriMatchType } from '../../enums/uriMatchType'; import { UriMatchType } from '../../enums/uriMatchType';
export class LoginUriApi { export class LoginUriApi extends BaseResponse {
uri: string; uri: string;
match: UriMatchType = null; match: UriMatchType = null;
constructor(data: any) { constructor(data: any = null) {
this.uri = data.Uri; super(data);
this.match = data.Match != null ? data.Match : null; if (data == null) {
return;
}
this.uri = this.getResponseProperty('Uri');
const match = this.getResponseProperty('Match');
this.match = match != null ? match : null;
} }
} }

View File

@ -1,9 +1,15 @@
import { BaseResponse } from '../response/baseResponse';
import { SecureNoteType } from '../../enums/secureNoteType'; import { SecureNoteType } from '../../enums/secureNoteType';
export class SecureNoteApi { export class SecureNoteApi extends BaseResponse {
type: SecureNoteType; type: SecureNoteType;
constructor(data: any) { constructor(data: any = null) {
this.type = data.Type; super(data);
if (data == null) {
return;
}
this.type = this.getResponseProperty('Type');
} }
} }

View File

@ -6,6 +6,7 @@ import { CardApi } from '../api/cardApi';
import { FieldApi } from '../api/fieldApi'; import { FieldApi } from '../api/fieldApi';
import { IdentityApi } from '../api/identityApi'; import { IdentityApi } from '../api/identityApi';
import { LoginApi } from '../api/loginApi'; import { LoginApi } from '../api/loginApi';
import { LoginUriApi } from '../api/loginUriApi';
import { SecureNoteApi } from '../api/secureNoteApi'; import { SecureNoteApi } from '../api/secureNoteApi';
import { AttachmentRequest } from './attachmentRequest'; import { AttachmentRequest } from './attachmentRequest';
@ -38,79 +39,85 @@ export class CipherRequest {
switch (this.type) { switch (this.type) {
case CipherType.Login: case CipherType.Login:
this.login = { this.login = new LoginApi();
uris: null, this.login.uris = null;
username: cipher.login.username ? cipher.login.username.encryptedString : null, this.login.username = cipher.login.username ? cipher.login.username.encryptedString : null;
password: cipher.login.password ? cipher.login.password.encryptedString : null, this.login.password = cipher.login.password ? cipher.login.password.encryptedString : null;
passwordRevisionDate: cipher.login.passwordRevisionDate != null ? this.login.passwordRevisionDate = cipher.login.passwordRevisionDate != null ?
cipher.login.passwordRevisionDate.toISOString() : null, cipher.login.passwordRevisionDate.toISOString() : null;
totp: cipher.login.totp ? cipher.login.totp.encryptedString : null, this.login.totp = cipher.login.totp ? cipher.login.totp.encryptedString : null;
};
if (cipher.login.uris) { if (cipher.login.uris != null) {
this.login.uris = []; this.login.uris = cipher.login.uris.map((u) => {
cipher.login.uris.forEach((u) => { const uri = new LoginUriApi();
this.login.uris.push({ uri.uri = u.uri != null ? u.uri.encryptedString : null;
uri: u.uri ? u.uri.encryptedString : null, uri.match = u.match != null ? u.match : null;
match: u.match != null ? u.match : null, return uri;
});
}); });
} }
break; break;
case CipherType.SecureNote: case CipherType.SecureNote:
this.secureNote = { this.secureNote = new SecureNoteApi();
type: cipher.secureNote.type, this.secureNote.type = cipher.secureNote.type;
};
break; break;
case CipherType.Card: case CipherType.Card:
this.card = { this.card = new CardApi();
cardholderName: cipher.card.cardholderName ? cipher.card.cardholderName.encryptedString : null, this.card.cardholderName = cipher.card.cardholderName != null ?
brand: cipher.card.brand ? cipher.card.brand.encryptedString : null, cipher.card.cardholderName.encryptedString : null;
number: cipher.card.number ? cipher.card.number.encryptedString : null, this.card.brand = cipher.card.brand != null ? cipher.card.brand.encryptedString : null;
expMonth: cipher.card.expMonth ? cipher.card.expMonth.encryptedString : null, this.card.number = cipher.card.number != null ? cipher.card.number.encryptedString : null;
expYear: cipher.card.expYear ? cipher.card.expYear.encryptedString : null, this.card.expMonth = cipher.card.expMonth != null ? cipher.card.expMonth.encryptedString : null;
code: cipher.card.code ? cipher.card.code.encryptedString : null, this.card.expYear = cipher.card.expYear != null ? cipher.card.expYear.encryptedString : null;
}; this.card.code = cipher.card.code != null ? cipher.card.code.encryptedString : null;
break; break;
case CipherType.Identity: case CipherType.Identity:
this.identity = { this.identity = new IdentityApi();
title: cipher.identity.title ? cipher.identity.title.encryptedString : null, this.identity.title = cipher.identity.title != null ? cipher.identity.title.encryptedString : null;
firstName: cipher.identity.firstName ? cipher.identity.firstName.encryptedString : null, this.identity.firstName = cipher.identity.firstName != null ?
middleName: cipher.identity.middleName ? cipher.identity.middleName.encryptedString : null, cipher.identity.firstName.encryptedString : null;
lastName: cipher.identity.lastName ? cipher.identity.lastName.encryptedString : null, this.identity.middleName = cipher.identity.middleName != null ?
address1: cipher.identity.address1 ? cipher.identity.address1.encryptedString : null, cipher.identity.middleName.encryptedString : null;
address2: cipher.identity.address2 ? cipher.identity.address2.encryptedString : null, this.identity.lastName = cipher.identity.lastName != null ?
address3: cipher.identity.address3 ? cipher.identity.address3.encryptedString : null, cipher.identity.lastName.encryptedString : null;
city: cipher.identity.city ? cipher.identity.city.encryptedString : null, this.identity.address1 = cipher.identity.address1 != null ?
state: cipher.identity.state ? cipher.identity.state.encryptedString : null, cipher.identity.address1.encryptedString : null;
postalCode: cipher.identity.postalCode ? cipher.identity.postalCode.encryptedString : null, this.identity.address2 = cipher.identity.address2 != null ?
country: cipher.identity.country ? cipher.identity.country.encryptedString : null, cipher.identity.address2.encryptedString : null;
company: cipher.identity.company ? cipher.identity.company.encryptedString : null, this.identity.address3 = cipher.identity.address3 != null ?
email: cipher.identity.email ? cipher.identity.email.encryptedString : null, cipher.identity.address3.encryptedString : null;
phone: cipher.identity.phone ? cipher.identity.phone.encryptedString : null, this.identity.city = cipher.identity.city != null ? cipher.identity.city.encryptedString : null;
ssn: cipher.identity.ssn ? cipher.identity.ssn.encryptedString : null, this.identity.state = cipher.identity.state != null ? cipher.identity.state.encryptedString : null;
username: cipher.identity.username ? cipher.identity.username.encryptedString : null, this.identity.postalCode = cipher.identity.postalCode != null ?
passportNumber: cipher.identity.passportNumber ? cipher.identity.postalCode.encryptedString : null;
cipher.identity.passportNumber.encryptedString : null, this.identity.country = cipher.identity.country != null ?
licenseNumber: cipher.identity.licenseNumber ? cipher.identity.licenseNumber.encryptedString : null, cipher.identity.country.encryptedString : null;
}; this.identity.company = cipher.identity.company != null ?
cipher.identity.company.encryptedString : null;
this.identity.email = cipher.identity.email != null ? cipher.identity.email.encryptedString : null;
this.identity.phone = cipher.identity.phone != null ? cipher.identity.phone.encryptedString : null;
this.identity.ssn = cipher.identity.ssn != null ? cipher.identity.ssn.encryptedString : null;
this.identity.username = cipher.identity.username != null ?
cipher.identity.username.encryptedString : null;
this.identity.passportNumber = cipher.identity.passportNumber != null ?
cipher.identity.passportNumber.encryptedString : null;
this.identity.licenseNumber = cipher.identity.licenseNumber != null ?
cipher.identity.licenseNumber.encryptedString : null;
break; break;
default: default:
break; break;
} }
if (cipher.fields) { if (cipher.fields != null) {
this.fields = []; this.fields = cipher.fields.map((f) => {
cipher.fields.forEach((field) => { const field = new FieldApi();
this.fields.push({ field.type = f.type;
type: field.type, field.name = f.name ? f.name.encryptedString : null;
name: field.name ? field.name.encryptedString : null, field.value = f.value ? f.value.encryptedString : null;
value: field.value ? field.value.encryptedString : null, return field;
});
}); });
} }
if (cipher.passwordHistory) { if (cipher.passwordHistory != null) {
this.passwordHistory = []; this.passwordHistory = [];
cipher.passwordHistory.forEach((ph) => { cipher.passwordHistory.forEach((ph) => {
this.passwordHistory.push({ this.passwordHistory.push({
@ -120,7 +127,7 @@ export class CipherRequest {
}); });
} }
if (cipher.attachments) { if (cipher.attachments != null) {
this.attachments = {}; this.attachments = {};
this.attachments2 = {}; this.attachments2 = {};
cipher.attachments.forEach((attachment) => { cipher.attachments.forEach((attachment) => {

View File

@ -1,4 +1,6 @@
export class AttachmentResponse { import { BaseResponse } from './baseResponse';
export class AttachmentResponse extends BaseResponse {
id: string; id: string;
url: string; url: string;
fileName: string; fileName: string;
@ -7,11 +9,12 @@ export class AttachmentResponse {
sizeName: string; sizeName: string;
constructor(response: any) { constructor(response: any) {
this.id = response.Id; super(response);
this.url = response.Url; this.id = this.getResponseProperty('Id');
this.fileName = response.FileName; this.url = this.getResponseProperty('Url');
this.key = response.Key; this.fileName = this.getResponseProperty('FileName');
this.size = response.Size; this.key = this.getResponseProperty('Key');
this.sizeName = response.SizeName; this.size = this.getResponseProperty('Size');
this.sizeName = this.getResponseProperty('SizeName');
} }
} }

View File

@ -0,0 +1,36 @@
export abstract class BaseResponse {
protected response: any;
constructor(response: any) {
this.response = response;
}
protected getResponseProperty(propertyName: string, response: any = null, exactName = false): any {
if (propertyName == null || propertyName === '') {
throw new Error('propertyName must not be null/empty.');
}
if (response == null) {
response = this.response;
}
if (!exactName && response[propertyName] === undefined) {
let otherCasePropertyName: string = null;
if (propertyName.charAt(0) === propertyName.charAt(0).toUpperCase()) {
otherCasePropertyName = propertyName.charAt(0).toLowerCase();
} else {
otherCasePropertyName = propertyName.charAt(0).toUpperCase();
}
if (propertyName.length > 1) {
otherCasePropertyName += propertyName.slice(1);
}
propertyName = otherCasePropertyName;
if (response[propertyName] === undefined) {
propertyName = propertyName.toLowerCase();
}
if (response[propertyName] === undefined) {
propertyName = propertyName.toUpperCase();
}
}
return response[propertyName];
}
}

View File

@ -1,39 +1,46 @@
import { BaseResponse } from './baseResponse';
import { PaymentMethodType } from '../../enums/paymentMethodType'; import { PaymentMethodType } from '../../enums/paymentMethodType';
import { TransactionType } from '../../enums/transactionType'; import { TransactionType } from '../../enums/transactionType';
export class BillingResponse { export class BillingResponse extends BaseResponse {
balance: number; balance: number;
paymentSource: BillingSourceResponse; paymentSource: BillingSourceResponse;
invoices: BillingInvoiceResponse[] = []; invoices: BillingInvoiceResponse[] = [];
transactions: BillingTransactionResponse[] = []; transactions: BillingTransactionResponse[] = [];
constructor(response: any) { constructor(response: any) {
this.balance = response.Balance; super(response);
this.paymentSource = response.PaymentSource == null ? null : new BillingSourceResponse(response.PaymentSource); this.balance = this.getResponseProperty('Balance');
if (response.Transactions != null) { const paymentSource = this.getResponseProperty('PaymentSource');
this.transactions = response.Transactions.map((t: any) => new BillingTransactionResponse(t)); const transactions = this.getResponseProperty('Transactions');
const invoices = this.getResponseProperty('Invoices');
this.paymentSource = paymentSource == null ? null : new BillingSourceResponse(paymentSource);
if (transactions != null) {
this.transactions = transactions.map((t: any) => new BillingTransactionResponse(t));
} }
if (response.Invoices != null) { if (invoices != null) {
this.invoices = response.Invoices.map((i: any) => new BillingInvoiceResponse(i)); this.invoices = invoices.map((i: any) => new BillingInvoiceResponse(i));
} }
} }
} }
export class BillingSourceResponse { export class BillingSourceResponse extends BaseResponse {
type: PaymentMethodType; type: PaymentMethodType;
cardBrand: string; cardBrand: string;
description: string; description: string;
needsVerification: boolean; needsVerification: boolean;
constructor(response: any) { constructor(response: any) {
this.type = response.Type; super(response);
this.cardBrand = response.CardBrand; this.type = this.getResponseProperty('Type');
this.description = response.Description; this.cardBrand = this.getResponseProperty('CardBrand');
this.needsVerification = response.NeedsVerification; this.description = this.getResponseProperty('Description');
this.needsVerification = this.getResponseProperty('NeedsVerification');
} }
} }
export class BillingInvoiceResponse { export class BillingInvoiceResponse extends BaseResponse {
url: string; url: string;
pdfUrl: string; pdfUrl: string;
number: string; number: string;
@ -42,16 +49,17 @@ export class BillingInvoiceResponse {
amount: number; amount: number;
constructor(response: any) { constructor(response: any) {
this.url = response.Url; super(response);
this.pdfUrl = response.PdfUrl; this.url = this.getResponseProperty('Url');
this.number = response.Number; this.pdfUrl = this.getResponseProperty('PdfUrl');
this.paid = response.Paid; this.number = this.getResponseProperty('Number');
this.date = response.Date; this.paid = this.getResponseProperty('Paid');
this.amount = response.Amount; this.date = this.getResponseProperty('Date');
this.amount = this.getResponseProperty('Amount');
} }
} }
export class BillingTransactionResponse { export class BillingTransactionResponse extends BaseResponse {
createdDate: string; createdDate: string;
amount: number; amount: number;
refunded: boolean; refunded: boolean;
@ -62,13 +70,14 @@ export class BillingTransactionResponse {
details: string; details: string;
constructor(response: any) { constructor(response: any) {
this.createdDate = response.CreatedDate; super(response);
this.amount = response.Amount; this.createdDate = this.getResponseProperty('CreatedDate');
this.refunded = response.Refunded; this.amount = this.getResponseProperty('Amount');
this.partiallyRefunded = response.PartiallyRefunded; this.refunded = this.getResponseProperty('Refunded');
this.refundedAmount = response.RefundedAmount; this.partiallyRefunded = this.getResponseProperty('PartiallyRefunded');
this.type = response.Type; this.refundedAmount = this.getResponseProperty('RefundedAmount');
this.paymentMethodType = response.PaymentMethodType; this.type = this.getResponseProperty('Type');
this.details = response.Details; this.paymentMethodType = this.getResponseProperty('PaymentMethodType');
this.details = this.getResponseProperty('Details');
} }
} }

View File

@ -1,4 +1,6 @@
export class BreachAccountResponse { import { BaseResponse } from './baseResponse';
export class BreachAccountResponse extends BaseResponse {
addedDate: string; addedDate: string;
breachDate: string; breachDate: string;
dataClasses: string[]; dataClasses: string[];
@ -13,17 +15,18 @@ export class BreachAccountResponse {
title: string; title: string;
constructor(response: any) { constructor(response: any) {
this.addedDate = response.AddedDate; super(response);
this.breachDate = response.BreachDate; this.addedDate = this.getResponseProperty('AddedDate');
this.dataClasses = response.DataClasses; this.breachDate = this.getResponseProperty('BreachDate');
this.description = response.Description; this.dataClasses = this.getResponseProperty('DataClasses');
this.domain = response.Domain; this.description = this.getResponseProperty('Description');
this.isActive = response.IsActive; this.domain = this.getResponseProperty('Domain');
this.isVerified = response.IsVerified; this.isActive = this.getResponseProperty('IsActive');
this.logoPath = response.LogoPath; this.isVerified = this.getResponseProperty('IsVerified');
this.modifiedDate = response.ModifiedDate; this.logoPath = this.getResponseProperty('LogoPath');
this.name = response.Name; this.modifiedDate = this.getResponseProperty('ModifiedDate');
this.pwnCount = response.PwnCount; this.name = this.getResponseProperty('Name');
this.title = response.Title; this.pwnCount = this.getResponseProperty('PwnCount');
this.title = this.getResponseProperty('Title');
} }
} }

View File

@ -1,4 +1,5 @@
import { AttachmentResponse } from './attachmentResponse'; import { AttachmentResponse } from './attachmentResponse';
import { BaseResponse } from './baseResponse';
import { PasswordHistoryResponse } from './passwordHistoryResponse'; import { PasswordHistoryResponse } from './passwordHistoryResponse';
import { CardApi } from '../api/cardApi'; import { CardApi } from '../api/cardApi';
@ -7,7 +8,7 @@ import { IdentityApi } from '../api/identityApi';
import { LoginApi } from '../api/loginApi'; import { LoginApi } from '../api/loginApi';
import { SecureNoteApi } from '../api/secureNoteApi'; import { SecureNoteApi } from '../api/secureNoteApi';
export class CipherResponse { export class CipherResponse extends BaseResponse {
id: string; id: string;
organizationId: string; organizationId: string;
folderId: string; folderId: string;
@ -28,59 +29,52 @@ export class CipherResponse {
collectionIds: string[]; collectionIds: string[];
constructor(response: any) { constructor(response: any) {
this.id = response.Id; super(response);
this.organizationId = response.OrganizationId; this.id = this.getResponseProperty('Id');
this.folderId = response.FolderId || null; this.organizationId = this.getResponseProperty('OrganizationId');
this.type = response.Type; this.folderId = this.getResponseProperty('FolderId') || null;
this.name = response.Name; this.type = this.getResponseProperty('Type');
this.notes = response.Notes; this.name = this.getResponseProperty('Name');
this.favorite = response.Favorite || false; this.notes = this.getResponseProperty('Notes');
this.edit = response.Edit || true; this.favorite = this.getResponseProperty('Favorite') || false;
this.organizationUseTotp = response.OrganizationUseTotp; this.edit = this.getResponseProperty('Edit') || true;
this.revisionDate = response.RevisionDate; this.organizationUseTotp = this.getResponseProperty('OrganizationUseTotp');
this.revisionDate = this.getResponseProperty('RevisionDate');
this.collectionIds = this.getResponseProperty('CollectionIds');
if (response.Login != null) { const login = this.getResponseProperty('Login');
this.login = new LoginApi(response.Login); if (login != null) {
this.login = new LoginApi(login);
} }
if (response.Card != null) { const card = this.getResponseProperty('Card');
this.card = new CardApi(response.Card); if (card != null) {
this.card = new CardApi(card);
} }
if (response.Identity != null) { const identity = this.getResponseProperty('Identity');
this.identity = new IdentityApi(response.Identity); if (identity != null) {
this.identity = new IdentityApi(identity);
} }
if (response.SecureNote != null) { const secureNote = this.getResponseProperty('SecureNote');
this.secureNote = new SecureNoteApi(response.SecureNote); if (secureNote != null) {
this.secureNote = new SecureNoteApi(secureNote);
} }
if (response.Fields != null) { const fields = this.getResponseProperty('Fields');
this.fields = []; if (fields != null) {
response.Fields.forEach((field: any) => { this.fields = fields.map((f: any) => new FieldApi(f));
this.fields.push(new FieldApi(field));
});
} }
if (response.Attachments != null) { const attachments = this.getResponseProperty('Attachments');
this.attachments = []; if (attachments != null) {
response.Attachments.forEach((attachment: any) => { this.attachments = attachments.map((a: any) => new AttachmentResponse(a));
this.attachments.push(new AttachmentResponse(attachment));
});
} }
if (response.PasswordHistory != null) { const passwordHistory = this.getResponseProperty('PasswordHistory');
this.passwordHistory = []; if (passwordHistory != null) {
response.PasswordHistory.forEach((ph: any) => { this.passwordHistory = passwordHistory.map((h: any) => new PasswordHistoryResponse(h));
this.passwordHistory.push(new PasswordHistoryResponse(ph));
});
}
if (response.CollectionIds) {
this.collectionIds = [];
response.CollectionIds.forEach((id: string) => {
this.collectionIds.push(id);
});
} }
} }
} }

View File

@ -1,14 +1,16 @@
import { BaseResponse } from './baseResponse';
import { SelectionReadOnlyResponse } from './selectionReadOnlyResponse'; import { SelectionReadOnlyResponse } from './selectionReadOnlyResponse';
export class CollectionResponse { export class CollectionResponse extends BaseResponse {
id: string; id: string;
organizationId: string; organizationId: string;
name: string; name: string;
constructor(response: any) { constructor(response: any) {
this.id = response.Id; super(response);
this.organizationId = response.OrganizationId; this.id = this.getResponseProperty('Id');
this.name = response.Name; this.organizationId = this.getResponseProperty('OrganizationId');
this.name = this.getResponseProperty('Name');
} }
} }
@ -17,7 +19,7 @@ export class CollectionDetailsResponse extends CollectionResponse {
constructor(response: any) { constructor(response: any) {
super(response); super(response);
this.readOnly = response.ReadOnly || false; this.readOnly = this.getResponseProperty('ReadOnly') || false;
} }
} }
@ -26,8 +28,9 @@ export class CollectionGroupDetailsResponse extends CollectionResponse {
constructor(response: any) { constructor(response: any) {
super(response); super(response);
if (response.Groups != null) { const groups = this.getResponseProperty('Groups');
this.groups = response.Groups.map((g: any) => new SelectionReadOnlyResponse(g)); if (groups != null) {
this.groups = groups.map((g: any) => new SelectionReadOnlyResponse(g));
} }
} }
} }

View File

@ -1,6 +1,8 @@
import { BaseResponse } from './baseResponse';
import { DeviceType } from '../../enums/deviceType'; import { DeviceType } from '../../enums/deviceType';
export class DeviceResponse { export class DeviceResponse extends BaseResponse {
id: string; id: string;
name: number; name: number;
identifier: string; identifier: string;
@ -8,10 +10,11 @@ export class DeviceResponse {
creationDate: string; creationDate: string;
constructor(response: any) { constructor(response: any) {
this.id = response.Id; super(response);
this.name = response.Name; this.id = this.getResponseProperty('Id');
this.identifier = response.Identifier; this.name = this.getResponseProperty('Name');
this.type = response.Type; this.identifier = this.getResponseProperty('Identifier');
this.creationDate = response.CreationDate; this.type = this.getResponseProperty('Type');
this.creationDate = this.getResponseProperty('CreationDate');
} }
} }

View File

@ -1,17 +1,18 @@
import { BaseResponse } from './baseResponse';
import { GlobalDomainResponse } from './globalDomainResponse'; import { GlobalDomainResponse } from './globalDomainResponse';
export class DomainsResponse { export class DomainsResponse extends BaseResponse {
equivalentDomains: string[][]; equivalentDomains: string[][];
globalEquivalentDomains: GlobalDomainResponse[] = []; globalEquivalentDomains: GlobalDomainResponse[] = [];
constructor(response: any) { constructor(response: any) {
this.equivalentDomains = response.EquivalentDomains; super(response);
this.equivalentDomains = this.getResponseProperty('EquivalentDomains');
this.globalEquivalentDomains = []; const globalEquivalentDomains = this.getResponseProperty('GlobalEquivalentDomains');
if (response.GlobalEquivalentDomains) { if (globalEquivalentDomains != null) {
response.GlobalEquivalentDomains.forEach((domain: any) => { this.globalEquivalentDomains = globalEquivalentDomains.map((d: any) => new GlobalDomainResponse(d));
this.globalEquivalentDomains.push(new GlobalDomainResponse(domain)); } else {
}); this.globalEquivalentDomains = [];
} }
} }
} }

View File

@ -1,19 +1,23 @@
export class ErrorResponse { import { BaseResponse } from './baseResponse';
export class ErrorResponse extends BaseResponse {
message: string; message: string;
validationErrors: { [key: string]: string[]; }; validationErrors: { [key: string]: string[]; };
statusCode: number; statusCode: number;
constructor(response: any, status: number, identityResponse?: boolean) { constructor(response: any, status: number, identityResponse?: boolean) {
super(response);
let errorModel = null; let errorModel = null;
if (identityResponse && response && response.ErrorModel) { const responseErrorModel = this.getResponseProperty('ErrorModel');
errorModel = response.ErrorModel; if (responseErrorModel && identityResponse && response) {
errorModel = responseErrorModel;
} else if (response) { } else if (response) {
errorModel = response; errorModel = response;
} }
if (errorModel) { if (errorModel) {
this.message = errorModel.Message; this.message = this.getResponseProperty('Message', errorModel);
this.validationErrors = errorModel.ValidationErrors; this.validationErrors = this.getResponseProperty('ValidationErrors', errorModel);
} else { } else {
if (status === 429) { if (status === 429) {
this.message = 'Rate limit exceeded. Try again later.'; this.message = 'Rate limit exceeded. Try again later.';

View File

@ -1,7 +1,9 @@
import { BaseResponse } from './baseResponse';
import { DeviceType } from '../../enums/deviceType'; import { DeviceType } from '../../enums/deviceType';
import { EventType } from '../../enums/eventType'; import { EventType } from '../../enums/eventType';
export class EventResponse { export class EventResponse extends BaseResponse {
type: EventType; type: EventType;
userId: string; userId: string;
organizationId: string; organizationId: string;
@ -15,16 +17,17 @@ export class EventResponse {
ipAddress: string; ipAddress: string;
constructor(response: any) { constructor(response: any) {
this.type = response.Type; super(response);
this.userId = response.UserId; this.type = this.getResponseProperty('Type');
this.organizationId = response.OrganizationId; this.userId = this.getResponseProperty('UserId');
this.cipherId = response.CipherId; this.organizationId = this.getResponseProperty('OrganizationId');
this.collectionId = response.CollectionId; this.cipherId = this.getResponseProperty('CipherId');
this.groupId = response.GroupId; this.collectionId = this.getResponseProperty('CollectionId');
this.organizationUserId = response.OrganizationUserId; this.groupId = this.getResponseProperty('GroupId');
this.actingUserId = response.ActingUserId; this.organizationUserId = this.getResponseProperty('OrganizationUserId');
this.date = response.Date; this.actingUserId = this.getResponseProperty('ActingUserId');
this.deviceType = response.DeviceType; this.date = this.getResponseProperty('Date');
this.ipAddress = response.IpAddress; this.deviceType = this.getResponseProperty('DeviceType');
this.ipAddress = this.getResponseProperty('IpAddress');
} }
} }

View File

@ -1,11 +1,14 @@
export class FolderResponse { import { BaseResponse } from './baseResponse';
export class FolderResponse extends BaseResponse {
id: string; id: string;
name: string; name: string;
revisionDate: string; revisionDate: string;
constructor(response: any) { constructor(response: any) {
this.id = response.Id; super(response);
this.name = response.Name; this.id = this.getResponseProperty('Id');
this.revisionDate = response.RevisionDate; this.name = this.getResponseProperty('Name');
this.revisionDate = this.getResponseProperty('RevisionDate');
} }
} }

View File

@ -1,11 +1,14 @@
export class GlobalDomainResponse { import { BaseResponse } from './baseResponse';
export class GlobalDomainResponse extends BaseResponse {
type: number; type: number;
domains: string[]; domains: string[];
excluded: number[]; excluded: number[];
constructor(response: any) { constructor(response: any) {
this.type = response.Type; super(response);
this.domains = response.Domains; this.type = this.getResponseProperty('Type');
this.excluded = response.Excluded; this.domains = this.getResponseProperty('Domains');
this.excluded = this.getResponseProperty('Excluded');
} }
} }

View File

@ -1,6 +1,7 @@
import { BaseResponse } from './baseResponse';
import { SelectionReadOnlyResponse } from './selectionReadOnlyResponse'; import { SelectionReadOnlyResponse } from './selectionReadOnlyResponse';
export class GroupResponse { export class GroupResponse extends BaseResponse {
id: string; id: string;
organizationId: string; organizationId: string;
name: string; name: string;
@ -8,11 +9,12 @@ export class GroupResponse {
externalId: string; externalId: string;
constructor(response: any) { constructor(response: any) {
this.id = response.Id; super(response);
this.organizationId = response.OrganizationId; this.id = this.getResponseProperty('Id');
this.name = response.Name; this.organizationId = this.getResponseProperty('OrganizationId');
this.accessAll = response.AccessAll; this.name = this.getResponseProperty('Name');
this.externalId = response.ExternalId; this.accessAll = this.getResponseProperty('AccessAll');
this.externalId = this.getResponseProperty('ExternalId');
} }
} }
@ -21,8 +23,9 @@ export class GroupDetailsResponse extends GroupResponse {
constructor(response: any) { constructor(response: any) {
super(response); super(response);
if (response.Collections != null) { const collections = this.getResponseProperty('Collections');
this.collections = response.Collections.map((c: any) => new SelectionReadOnlyResponse(c)); if (collections != null) {
this.collections = collections.map((c: any) => new SelectionReadOnlyResponse(c));
} }
} }
} }

View File

@ -1,4 +1,6 @@
export class IdentityTokenResponse { import { BaseResponse } from './baseResponse';
export class IdentityTokenResponse extends BaseResponse {
accessToken: string; accessToken: string;
expiresIn: number; expiresIn: number;
refreshToken: string; refreshToken: string;
@ -9,13 +11,14 @@ export class IdentityTokenResponse {
twoFactorToken: string; twoFactorToken: string;
constructor(response: any) { constructor(response: any) {
super(response);
this.accessToken = response.access_token; this.accessToken = response.access_token;
this.expiresIn = response.expires_in; this.expiresIn = response.expires_in;
this.refreshToken = response.refresh_token; this.refreshToken = response.refresh_token;
this.tokenType = response.token_type; this.tokenType = response.token_type;
this.privateKey = response.PrivateKey; this.privateKey = this.getResponseProperty('PrivateKey');
this.key = response.Key; this.key = this.getResponseProperty('Key');
this.twoFactorToken = response.TwoFactorToken; this.twoFactorToken = this.getResponseProperty('TwoFactorToken');
} }
} }

View File

@ -1,15 +1,19 @@
import { BaseResponse } from './baseResponse';
import { TwoFactorProviderType } from '../../enums/twoFactorProviderType'; import { TwoFactorProviderType } from '../../enums/twoFactorProviderType';
export class IdentityTwoFactorResponse { export class IdentityTwoFactorResponse extends BaseResponse {
twoFactorProviders: TwoFactorProviderType[]; twoFactorProviders: TwoFactorProviderType[];
twoFactorProviders2 = new Map<TwoFactorProviderType, { [key: string]: string; }>(); twoFactorProviders2 = new Map<TwoFactorProviderType, { [key: string]: string; }>();
constructor(response: any) { constructor(response: any) {
this.twoFactorProviders = response.TwoFactorProviders; super(response);
if (response.TwoFactorProviders2 != null) { this.twoFactorProviders = this.getResponseProperty('TwoFactorProviders');
for (const prop in response.TwoFactorProviders2) { const twoFactorProviders2 = this.getResponseProperty('TwoFactorProviders2');
if (response.TwoFactorProviders2.hasOwnProperty(prop)) { if (twoFactorProviders2 != null) {
this.twoFactorProviders2.set(parseInt(prop, null), response.TwoFactorProviders2[prop]); for (const prop in twoFactorProviders2) {
if (twoFactorProviders2.hasOwnProperty(prop)) {
this.twoFactorProviders2.set(parseInt(prop, null), twoFactorProviders2[prop]);
} }
} }
} }

View File

@ -1,9 +1,12 @@
export class KeysResponse { import { BaseResponse } from './baseResponse';
export class KeysResponse extends BaseResponse {
privateKey: string; privateKey: string;
publicKey: string; publicKey: string;
constructor(response: any) { constructor(response: any) {
this.privateKey = response.PrivateKey; super(response);
this.publicKey = response.PublicKey; this.privateKey = this.getResponseProperty('PrivateKey');
this.publicKey = this.getResponseProperty('PublicKey');
} }
} }

View File

@ -1,9 +1,13 @@
export class ListResponse<T> { import { BaseResponse } from './baseResponse';
export class ListResponse<T> extends BaseResponse {
data: T[]; data: T[];
continuationToken: string; continuationToken: string;
constructor(response: any, t: new (dataResponse: any) => T) { constructor(response: any, t: new (dataResponse: any) => T) {
this.data = response.Data == null ? [] : response.Data.map((dr: any) => new t(dr)); super(response);
this.continuationToken = response.ContinuationToken; const data = this.getResponseProperty('Data');
this.data = data == null ? [] : data.map((dr: any) => new t(dr));
this.continuationToken = this.getResponseProperty('ContinuationToken');
} }
} }

View File

@ -1,15 +1,18 @@
import { BaseResponse } from './baseResponse';
import { NotificationType } from '../../enums/notificationType'; import { NotificationType } from '../../enums/notificationType';
export class NotificationResponse { export class NotificationResponse extends BaseResponse {
contextId: string; contextId: string;
type: NotificationType; type: NotificationType;
payload: any; payload: any;
constructor(response: any) { constructor(response: any) {
this.contextId = response.contextId || response.ContextId; super(response);
this.type = response.type != null ? response.type : response.Type; this.contextId = this.getResponseProperty('ContextId');
this.type = this.getResponseProperty('Type');
const payload = response.payload || response.Payload; const payload = this.getResponseProperty('Payload');
switch (this.type) { switch (this.type) {
case NotificationType.SyncCipherCreate: case NotificationType.SyncCipherCreate:
case NotificationType.SyncCipherDelete: case NotificationType.SyncCipherDelete:
@ -35,7 +38,7 @@ export class NotificationResponse {
} }
} }
export class SyncCipherNotification { export class SyncCipherNotification extends BaseResponse {
id: string; id: string;
userId: string; userId: string;
organizationId: string; organizationId: string;
@ -43,32 +46,35 @@ export class SyncCipherNotification {
revisionDate: Date; revisionDate: Date;
constructor(response: any) { constructor(response: any) {
this.id = response.id || response.Id; super(response);
this.userId = response.userId || response.UserId; this.id = this.getResponseProperty('Id');
this.organizationId = response.organizationId || response.OrganizationId; this.userId = this.getResponseProperty('UserId');
this.collectionIds = response.collectionIds || response.CollectionIds; this.organizationId = this.getResponseProperty('OrganizationId');
this.revisionDate = new Date(response.revisionDate || response.RevisionDate); this.collectionIds = this.getResponseProperty('CollectionIds');
this.revisionDate = new Date(this.getResponseProperty('RevisionDate'));
} }
} }
export class SyncFolderNotification { export class SyncFolderNotification extends BaseResponse {
id: string; id: string;
userId: string; userId: string;
revisionDate: Date; revisionDate: Date;
constructor(response: any) { constructor(response: any) {
this.id = response.id || response.Id; super(response);
this.userId = response.userId || response.UserId; this.id = this.getResponseProperty('Id');
this.revisionDate = new Date(response.revisionDate || response.RevisionDate); this.userId = this.getResponseProperty('UserId');
this.revisionDate = new Date(this.getResponseProperty('RevisionDate'));
} }
} }
export class UserNotification { export class UserNotification extends BaseResponse {
userId: string; userId: string;
date: Date; date: Date;
constructor(response: any) { constructor(response: any) {
this.userId = response.userId || response.UserId; super(response);
this.date = new Date(response.date || response.Date); this.userId = this.getResponseProperty('UserId');
this.date = new Date(this.getResponseProperty('Date'));
} }
} }

View File

@ -1,6 +1,8 @@
import { BaseResponse } from './baseResponse';
import { PlanType } from '../../enums/planType'; import { PlanType } from '../../enums/planType';
export class OrganizationResponse { export class OrganizationResponse extends BaseResponse {
id: string; id: string;
name: string; name: string;
businessName: string; businessName: string;
@ -22,24 +24,25 @@ export class OrganizationResponse {
use2fa: boolean; use2fa: boolean;
constructor(response: any) { constructor(response: any) {
this.id = response.Id; super(response);
this.name = response.Name; this.id = this.getResponseProperty('Id');
this.businessName = response.BusinessName; this.name = this.getResponseProperty('Name');
this.businessAddress1 = response.BusinessAddress1; this.businessName = this.getResponseProperty('BusinessName');
this.businessAddress2 = response.BusinessAddress2; this.businessAddress1 = this.getResponseProperty('BusinessAddress1');
this.businessAddress3 = response.BusinessAddress3; this.businessAddress2 = this.getResponseProperty('BusinessAddress2');
this.businessCountry = response.BusinessCountry; this.businessAddress3 = this.getResponseProperty('BusinessAddress3');
this.businessTaxNumber = response.BusinessTaxNumber; this.businessCountry = this.getResponseProperty('BusinessCountry');
this.billingEmail = response.BillingEmail; this.businessTaxNumber = this.getResponseProperty('BusinessTaxNumber');
this.plan = response.Plan; this.billingEmail = this.getResponseProperty('BillingEmail');
this.planType = response.PlanType; this.plan = this.getResponseProperty('Plan');
this.seats = response.Seats; this.planType = this.getResponseProperty('PlanType');
this.maxCollections = response.MaxCollections; this.seats = this.getResponseProperty('Seats');
this.maxStorageGb = response.MaxStorageGb; this.maxCollections = this.getResponseProperty('MaxCollections');
this.useGroups = response.UseGroups; this.maxStorageGb = this.getResponseProperty('MaxStorageGb');
this.useDirectory = response.UseDirectory; this.useGroups = this.getResponseProperty('UseGroups');
this.useEvents = response.UseEvents; this.useDirectory = this.getResponseProperty('UseDirectory');
this.useTotp = response.UseTotp; this.useEvents = this.getResponseProperty('UseEvents');
this.use2fa = response.Use2fa; this.useTotp = this.getResponseProperty('UseTotp');
this.use2fa = this.getResponseProperty('Use2fa');
} }
} }

View File

@ -13,12 +13,13 @@ export class OrganizationSubscriptionResponse extends OrganizationResponse {
constructor(response: any) { constructor(response: any) {
super(response); super(response);
this.storageName = response.StorageName; this.storageName = this.getResponseProperty('StorageName');
this.storageGb = response.StorageGb; this.storageGb = this.getResponseProperty('StorageGb');
this.subscription = response.Subscription == null ? const subscription = this.getResponseProperty('Subscription');
null : new BillingSubscriptionResponse(response.Subscription); this.subscription = subscription == null ? null : new BillingSubscriptionResponse(subscription);
this.upcomingInvoice = response.UpcomingInvoice == null ? const upcomingInvoice = this.getResponseProperty('UpcomingInvoice');
null : new BillingSubscriptionUpcomingInvoiceResponse(response.UpcomingInvoice); this.upcomingInvoice = upcomingInvoice == null ? null :
this.expiration = response.Expiration; new BillingSubscriptionUpcomingInvoiceResponse(upcomingInvoice);
this.expiration = this.getResponseProperty('Expiration');
} }
} }

View File

@ -1,8 +1,10 @@
import { OrganizationUserStatusType } from '../../enums/organizationUserStatusType'; import { OrganizationUserStatusType } from '../../enums/organizationUserStatusType';
import { OrganizationUserType } from '../../enums/organizationUserType'; import { OrganizationUserType } from '../../enums/organizationUserType';
import { BaseResponse } from './baseResponse';
import { SelectionReadOnlyResponse } from './selectionReadOnlyResponse'; import { SelectionReadOnlyResponse } from './selectionReadOnlyResponse';
export class OrganizationUserResponse { export class OrganizationUserResponse extends BaseResponse {
id: string; id: string;
userId: string; userId: string;
type: OrganizationUserType; type: OrganizationUserType;
@ -10,11 +12,12 @@ export class OrganizationUserResponse {
accessAll: boolean; accessAll: boolean;
constructor(response: any) { constructor(response: any) {
this.id = response.Id; super(response);
this.userId = response.UserId; this.id = this.getResponseProperty('Id');
this.type = response.Type; this.userId = this.getResponseProperty('UserId');
this.status = response.Status; this.type = this.getResponseProperty('Type');
this.accessAll = response.AccessAll; this.status = this.getResponseProperty('Status');
this.accessAll = this.getResponseProperty('AccessAll');
} }
} }
@ -25,9 +28,9 @@ export class OrganizationUserUserDetailsResponse extends OrganizationUserRespons
constructor(response: any) { constructor(response: any) {
super(response); super(response);
this.name = response.Name; this.name = this.getResponseProperty('Name');
this.email = response.Email; this.email = this.getResponseProperty('Email');
this.twoFactorEnabled = response.TwoFactorEnabled; this.twoFactorEnabled = this.getResponseProperty('TwoFactorEnabled');
} }
} }
@ -36,8 +39,9 @@ export class OrganizationUserDetailsResponse extends OrganizationUserResponse {
constructor(response: any) { constructor(response: any) {
super(response); super(response);
if (response.Collections != null) { const collections = this.getResponseProperty('Collections');
this.collections = response.Collections.map((c: any) => new SelectionReadOnlyResponse(c)); if (collections != null) {
this.collections = collections.map((c: any) => new SelectionReadOnlyResponse(c));
} }
} }
} }

View File

@ -1,9 +1,12 @@
export class PasswordHistoryResponse { import { BaseResponse } from './baseResponse';
export class PasswordHistoryResponse extends BaseResponse {
password: string; password: string;
lastUsedDate: string; lastUsedDate: string;
constructor(response: any) { constructor(response: any) {
this.password = response.Password; super(response);
this.lastUsedDate = response.LastUsedDate; this.password = this.getResponseProperty('Password');
this.lastUsedDate = this.getResponseProperty('LastUsedDate');
} }
} }

View File

@ -1,11 +1,14 @@
import { BaseResponse } from './baseResponse';
import { KdfType } from '../../enums/kdfType'; import { KdfType } from '../../enums/kdfType';
export class PreloginResponse { export class PreloginResponse extends BaseResponse {
kdf: KdfType; kdf: KdfType;
kdfIterations: number; kdfIterations: number;
constructor(response: any) { constructor(response: any) {
this.kdf = response.Kdf; super(response);
this.kdfIterations = response.KdfIterations; this.kdf = this.getResponseProperty('Kdf');
this.kdfIterations = this.getResponseProperty('KdfIterations');
} }
} }

View File

@ -1,7 +1,9 @@
import { BaseResponse } from './baseResponse';
import { OrganizationUserStatusType } from '../../enums/organizationUserStatusType'; import { OrganizationUserStatusType } from '../../enums/organizationUserStatusType';
import { OrganizationUserType } from '../../enums/organizationUserType'; import { OrganizationUserType } from '../../enums/organizationUserType';
export class ProfileOrganizationResponse { export class ProfileOrganizationResponse extends BaseResponse {
id: string; id: string;
name: string; name: string;
useGroups: boolean; useGroups: boolean;
@ -20,21 +22,22 @@ export class ProfileOrganizationResponse {
enabled: boolean; enabled: boolean;
constructor(response: any) { constructor(response: any) {
this.id = response.Id; super(response);
this.name = response.Name; this.id = this.getResponseProperty('Id');
this.useGroups = response.UseGroups; this.name = this.getResponseProperty('Name');
this.useDirectory = response.UseDirectory; this.useGroups = this.getResponseProperty('UseGroups');
this.useEvents = response.UseEvents; this.useDirectory = this.getResponseProperty('UseDirectory');
this.useTotp = response.UseTotp; this.useEvents = this.getResponseProperty('UseEvents');
this.use2fa = response.Use2fa; this.useTotp = this.getResponseProperty('UseTotp');
this.selfHost = response.SelfHost; this.use2fa = this.getResponseProperty('Use2fa');
this.usersGetPremium = response.UsersGetPremium; this.selfHost = this.getResponseProperty('SelfHost');
this.seats = response.Seats; this.usersGetPremium = this.getResponseProperty('UsersGetPremium');
this.maxCollections = response.MaxCollections; this.seats = this.getResponseProperty('Seats');
this.maxStorageGb = response.MaxStorageGb; this.maxCollections = this.getResponseProperty('MaxCollections');
this.key = response.Key; this.maxStorageGb = this.getResponseProperty('MaxStorageGb');
this.status = response.Status; this.key = this.getResponseProperty('Key');
this.type = response.Type; this.status = this.getResponseProperty('Status');
this.enabled = response.Enabled; this.type = this.getResponseProperty('Type');
this.enabled = this.getResponseProperty('Enabled');
} }
} }

View File

@ -1,6 +1,7 @@
import { BaseResponse } from './baseResponse';
import { ProfileOrganizationResponse } from './profileOrganizationResponse'; import { ProfileOrganizationResponse } from './profileOrganizationResponse';
export class ProfileResponse { export class ProfileResponse extends BaseResponse {
id: string; id: string;
name: string; name: string;
email: string; email: string;
@ -15,22 +16,22 @@ export class ProfileResponse {
organizations: ProfileOrganizationResponse[] = []; organizations: ProfileOrganizationResponse[] = [];
constructor(response: any) { constructor(response: any) {
this.id = response.Id; super(response);
this.name = response.Name; this.id = this.getResponseProperty('Id');
this.email = response.Email; this.name = this.getResponseProperty('Name');
this.emailVerified = response.EmailVerified; this.email = this.getResponseProperty('Email');
this.masterPasswordHint = response.MasterPasswordHint; this.emailVerified = this.getResponseProperty('EmailVerified');
this.premium = response.Premium; this.masterPasswordHint = this.getResponseProperty('MasterPasswordHint');
this.culture = response.Culture; this.premium = this.getResponseProperty('Premium');
this.twoFactorEnabled = response.TwoFactorEnabled; this.culture = this.getResponseProperty('Culture');
this.key = response.Key; this.twoFactorEnabled = this.getResponseProperty('TwoFactorEnabled');
this.privateKey = response.PrivateKey; this.key = this.getResponseProperty('Key');
this.securityStamp = response.SecurityStamp; this.privateKey = this.getResponseProperty('PrivateKey');
this.securityStamp = this.getResponseProperty('SecurityStamp');
if (response.Organizations) { const organizations = this.getResponseProperty('Organizations');
response.Organizations.forEach((org: any) => { if (organizations != null) {
this.organizations.push(new ProfileOrganizationResponse(org)); this.organizations = organizations.map((o: any) => new ProfileOrganizationResponse(o));
});
} }
} }
} }

View File

@ -1,9 +1,12 @@
export class SelectionReadOnlyResponse { import { BaseResponse } from './baseResponse';
export class SelectionReadOnlyResponse extends BaseResponse {
id: string; id: string;
readOnly: boolean; readOnly: boolean;
constructor(response: any) { constructor(response: any) {
this.id = response.Id; super(response);
this.readOnly = response.ReadOnly; this.id = this.getResponseProperty('Id');
this.readOnly = this.getResponseProperty('ReadOnly');
} }
} }

View File

@ -1,4 +1,6 @@
export class SubscriptionResponse { import { BaseResponse } from './baseResponse';
export class SubscriptionResponse extends BaseResponse {
storageName: string; storageName: string;
storageGb: number; storageGb: number;
maxStorageGb: number; maxStorageGb: number;
@ -8,19 +10,21 @@ export class SubscriptionResponse {
expiration: string; expiration: string;
constructor(response: any) { constructor(response: any) {
this.storageName = response.StorageName; super(response);
this.storageGb = response.StorageGb; this.storageName = this.getResponseProperty('StorageName');
this.maxStorageGb = response.MaxStorageGb; this.storageGb = this.getResponseProperty('StorageGb');
this.subscription = response.Subscription == null ? this.maxStorageGb = this.getResponseProperty('MaxStorageGb');
null : new BillingSubscriptionResponse(response.Subscription); this.license = this.getResponseProperty('License');
this.upcomingInvoice = response.UpcomingInvoice == null ? this.expiration = this.getResponseProperty('Expiration');
null : new BillingSubscriptionUpcomingInvoiceResponse(response.UpcomingInvoice); const subscription = this.getResponseProperty('Subscription');
this.license = response.License; const upcomingInvoice = this.getResponseProperty('UpcomingInvoice');
this.expiration = response.Expiration; this.subscription = subscription == null ? null : new BillingSubscriptionResponse(subscription);
this.upcomingInvoice = upcomingInvoice == null ? null :
new BillingSubscriptionUpcomingInvoiceResponse(upcomingInvoice);
} }
} }
export class BillingSubscriptionResponse { export class BillingSubscriptionResponse extends BaseResponse {
trialStartDate: string; trialStartDate: string;
trialEndDate: string; trialEndDate: string;
periodStartDate: string; periodStartDate: string;
@ -32,40 +36,44 @@ export class BillingSubscriptionResponse {
items: BillingSubscriptionItemResponse[] = []; items: BillingSubscriptionItemResponse[] = [];
constructor(response: any) { constructor(response: any) {
this.trialEndDate = response.TrialStartDate; super(response);
this.trialEndDate = response.TrialEndDate; this.trialEndDate = this.getResponseProperty('TrialStartDate');
this.periodStartDate = response.PeriodStartDate; this.trialEndDate = this.getResponseProperty('TrialEndDate');
this.periodEndDate = response.PeriodEndDate; this.periodStartDate = this.getResponseProperty('PeriodStartDate');
this.cancelledDate = response.CancelledDate; this.periodEndDate = this.getResponseProperty('PeriodEndDate');
this.cancelAtEndDate = response.CancelAtEndDate; this.cancelledDate = this.getResponseProperty('CancelledDate');
this.status = response.Status; this.cancelAtEndDate = this.getResponseProperty('CancelAtEndDate');
this.cancelled = response.Cancelled; this.status = this.getResponseProperty('Status');
if (response.Items != null) { this.cancelled = this.getResponseProperty('Cancelled');
this.items = response.Items.map((i: any) => new BillingSubscriptionItemResponse(i)); const items = this.getResponseProperty('Items');
if (items != null) {
this.items = items.map((i: any) => new BillingSubscriptionItemResponse(i));
} }
} }
} }
export class BillingSubscriptionItemResponse { export class BillingSubscriptionItemResponse extends BaseResponse {
name: string; name: string;
amount: number; amount: number;
quantity: number; quantity: number;
interval: string; interval: string;
constructor(response: any) { constructor(response: any) {
this.name = response.Name; super(response);
this.amount = response.Amount; this.name = this.getResponseProperty('Name');
this.quantity = response.Quantity; this.amount = this.getResponseProperty('Amount');
this.interval = response.Interval; this.quantity = this.getResponseProperty('Quantity');
this.interval = this.getResponseProperty('Interval');
} }
} }
export class BillingSubscriptionUpcomingInvoiceResponse { export class BillingSubscriptionUpcomingInvoiceResponse extends BaseResponse {
date: string; date: string;
amount: number; amount: number;
constructor(response: any) { constructor(response: any) {
this.date = response.Date; super(response);
this.amount = response.Amount; this.date = this.getResponseProperty('Date');
this.amount = this.getResponseProperty('Amount');
} }
} }

View File

@ -1,10 +1,11 @@
import { BaseResponse } from './baseResponse';
import { CipherResponse } from './cipherResponse'; import { CipherResponse } from './cipherResponse';
import { CollectionDetailsResponse } from './collectionResponse'; import { CollectionDetailsResponse } from './collectionResponse';
import { DomainsResponse } from './domainsResponse'; import { DomainsResponse } from './domainsResponse';
import { FolderResponse } from './folderResponse'; import { FolderResponse } from './folderResponse';
import { ProfileResponse } from './profileResponse'; import { ProfileResponse } from './profileResponse';
export class SyncResponse { export class SyncResponse extends BaseResponse {
profile?: ProfileResponse; profile?: ProfileResponse;
folders: FolderResponse[] = []; folders: FolderResponse[] = [];
collections: CollectionDetailsResponse[] = []; collections: CollectionDetailsResponse[] = [];
@ -12,30 +13,31 @@ export class SyncResponse {
domains?: DomainsResponse; domains?: DomainsResponse;
constructor(response: any) { constructor(response: any) {
if (response.Profile) { super(response);
this.profile = new ProfileResponse(response.Profile);
const profile = this.getResponseProperty('Profile');
if (profile != null) {
this.profile = new ProfileResponse(profile);
} }
if (response.Folders) { const folders = this.getResponseProperty('Folders');
response.Folders.forEach((folder: any) => { if (folders != null) {
this.folders.push(new FolderResponse(folder)); this.folders = folders.map((f: any) => new FolderResponse(f));
});
} }
if (response.Collections) { const collections = this.getResponseProperty('Collections');
response.Collections.forEach((collection: any) => { if (collections != null) {
this.collections.push(new CollectionDetailsResponse(collection)); this.collections = collections.map((c: any) => new CollectionDetailsResponse(c));
});
} }
if (response.Ciphers) { const ciphers = this.getResponseProperty('Ciphers');
response.Ciphers.forEach((cipher: any) => { if (ciphers != null) {
this.ciphers.push(new CipherResponse(cipher)); this.ciphers = ciphers.map((c: any) => new CipherResponse(c));
});
} }
if (response.Domains) { const domains = this.getResponseProperty('Domains');
this.domains = new DomainsResponse(response.Domains); if (domains != null) {
this.domains = new DomainsResponse(domains);
} }
} }
} }

View File

@ -1,9 +1,12 @@
export class TwoFactorAuthenticatorResponse { import { BaseResponse } from './baseResponse';
export class TwoFactorAuthenticatorResponse extends BaseResponse {
enabled: boolean; enabled: boolean;
key: string; key: string;
constructor(response: any) { constructor(response: any) {
this.enabled = response.Enabled; super(response);
this.key = response.Key; this.enabled = this.getResponseProperty('Enabled');
this.key = this.getResponseProperty('Key');
} }
} }

View File

@ -1,13 +1,16 @@
export class TwoFactorDuoResponse { import { BaseResponse } from './baseResponse';
export class TwoFactorDuoResponse extends BaseResponse {
enabled: boolean; enabled: boolean;
host: string; host: string;
secretKey: string; secretKey: string;
integrationKey: string; integrationKey: string;
constructor(response: any) { constructor(response: any) {
this.enabled = response.Enabled; super(response);
this.host = response.Host; this.enabled = this.getResponseProperty('Enabled');
this.secretKey = response.SecretKey; this.host = this.getResponseProperty('Host');
this.integrationKey = response.IntegrationKey; this.secretKey = this.getResponseProperty('SecretKey');
this.integrationKey = this.getResponseProperty('IntegrationKey');
} }
} }

View File

@ -1,9 +1,12 @@
export class TwoFactorEmailResponse { import { BaseResponse } from './baseResponse';
export class TwoFactorEmailResponse extends BaseResponse {
enabled: boolean; enabled: boolean;
email: string; email: string;
constructor(response: any) { constructor(response: any) {
this.enabled = response.Enabled; super(response);
this.email = response.Email; this.enabled = this.getResponseProperty('Enabled');
this.email = this.getResponseProperty('Email');
} }
} }

View File

@ -1,11 +1,14 @@
import { BaseResponse } from './baseResponse';
import { TwoFactorProviderType } from '../../enums/twoFactorProviderType'; import { TwoFactorProviderType } from '../../enums/twoFactorProviderType';
export class TwoFactorProviderResponse { export class TwoFactorProviderResponse extends BaseResponse {
enabled: boolean; enabled: boolean;
type: TwoFactorProviderType; type: TwoFactorProviderType;
constructor(response: any) { constructor(response: any) {
this.enabled = response.Enabled; super(response);
this.type = response.Type; this.enabled = this.getResponseProperty('Enabled');
this.type = this.getResponseProperty('Type');
} }
} }

View File

@ -1,7 +1,10 @@
export class TwoFactorRecoverResponse { import { BaseResponse } from './baseResponse';
export class TwoFactorRecoverResponse extends BaseResponse {
code: string; code: string;
constructor(response: any) { constructor(response: any) {
this.code = response.Code; super(response);
this.code = this.getResponseProperty('Code');
} }
} }

View File

@ -1,35 +1,41 @@
export class TwoFactorU2fResponse { import { BaseResponse } from './baseResponse';
export class TwoFactorU2fResponse extends BaseResponse {
enabled: boolean; enabled: boolean;
keys: KeyResponse[]; keys: KeyResponse[];
constructor(response: any) { constructor(response: any) {
this.enabled = response.Enabled; super(response);
this.keys = response.Keys == null ? null : response.Keys.map((k: any) => new KeyResponse(k)); this.enabled = this.getResponseProperty('Enabled');
const keys = this.getResponseProperty('Keys');
this.keys = keys == null ? null : keys.map((k: any) => new KeyResponse(k));
} }
} }
export class KeyResponse { export class KeyResponse extends BaseResponse {
name: string; name: string;
id: number; id: number;
compromised: boolean; compromised: boolean;
constructor(response: any) { constructor(response: any) {
this.name = response.Name; super(response);
this.id = response.Id; this.name = this.getResponseProperty('Name');
this.compromised = response.Compromised; this.id = this.getResponseProperty('Id');
this.compromised = this.getResponseProperty('Compromised');
} }
} }
export class ChallengeResponse { export class ChallengeResponse extends BaseResponse {
userId: string; userId: string;
appId: string; appId: string;
challenge: string; challenge: string;
version: string; version: string;
constructor(response: any) { constructor(response: any) {
this.userId = response.UserId; super(response);
this.appId = response.AppId; this.userId = this.getResponseProperty('UserId');
this.challenge = response.Challenge; this.appId = this.getResponseProperty('AppId');
this.version = response.Version; this.challenge = this.getResponseProperty('Challenge');
this.version = this.getResponseProperty('Version');
} }
} }

View File

@ -1,4 +1,6 @@
export class TwoFactorYubiKeyResponse { import { BaseResponse } from './baseResponse';
export class TwoFactorYubiKeyResponse extends BaseResponse {
enabled: boolean; enabled: boolean;
key1: string; key1: string;
key2: string; key2: string;
@ -8,12 +10,13 @@ export class TwoFactorYubiKeyResponse {
nfc: boolean; nfc: boolean;
constructor(response: any) { constructor(response: any) {
this.enabled = response.Enabled; super(response);
this.key1 = response.Key1; this.enabled = this.getResponseProperty('Enable');
this.key2 = response.Key2; this.key1 = this.getResponseProperty('Key1');
this.key3 = response.Key3; this.key2 = this.getResponseProperty('Key2');
this.key4 = response.Key4; this.key3 = this.getResponseProperty('Key3');
this.key5 = response.Key5; this.key4 = this.getResponseProperty('Key4');
this.nfc = response.Nfc; this.key5 = this.getResponseProperty('Key5');
this.nfc = this.getResponseProperty('Nfc');
} }
} }

View File

@ -1,9 +1,12 @@
export class UserKeyResponse { import { BaseResponse } from './baseResponse';
export class UserKeyResponse extends BaseResponse {
userId: string; userId: string;
publicKey: string; publicKey: string;
constructor(response: any) { constructor(response: any) {
this.userId = response.UserId; super(response);
this.publicKey = response.PublicKey; this.userId = this.getResponseProperty('UserId');
this.publicKey = this.getResponseProperty('PublicKey');
} }
} }