1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-11 13:53:34 +00:00
Files
browser/src/models/api/responseModels.js
2017-10-24 14:48:58 -04:00

170 lines
5.1 KiB
JavaScript

var CipherResponse = function (response) {
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) {
this.attachments = [];
for (var i = 0; i < response.Attachments.length; i++) {
this.attachments.push(new AttachmentResponse(response.Attachments[i]));
}
}
};
var FolderResponse = function (response) {
this.id = response.Id;
this.name = response.Name;
this.revisionDate = response.RevisionDate;
};
var ProfileResponse = function (response) {
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;
this.organizations = [];
if (response.Organizations) {
for (var i = 0; i < response.Organizations.length; i++) {
this.organizations.push(new ProfileOrganizationResponse(response.Organizations[i]));
}
}
};
var KeysResponse = function (response) {
this.privateKey = response.PrivateKey;
this.publicKey = response.PublicKey;
};
var ProfileOrganizationResponse = function (response) {
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;
};
var AttachmentResponse = function (response) {
this.id = response.Id;
this.url = response.Url;
this.fileName = response.FileName;
this.size = response.Size;
this.sizeName = response.SizeName;
};
var IdentityTokenResponse = function (response) {
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;
};
var ListResponse = function (data) {
this.data = data;
};
var ErrorResponse = function (response, identityResponse) {
var errorModel = null;
if (identityResponse && identityResponse === true && response.responseJSON && response.responseJSON.ErrorModel) {
errorModel = response.responseJSON.ErrorModel;
}
else if (response.responseJSON) {
errorModel = response.responseJSON;
}
else if (response.responseText && response.responseText.indexOf('{') === 0) {
errorModel = JSON.parse(response.responseText);
}
if (errorModel) {
this.message = errorModel.Message;
this.validationErrors = errorModel.ValidationErrors;
}
this.statusCode = response.status;
};
var DeviceResponse = function (response) {
this.id = response.Id;
this.name = response.Name;
this.identifier = response.Identifier;
this.type = response.Type;
this.creationDate = response.CreationDate;
};
var CipherHistoryResponse = function (response) {
this.revised = [];
var revised = response.Revised;
for (var i = 0; i < revised.length; i++) {
this.revised.push(new CipherResponse(revised[i]));
}
this.deleted = response.Deleted;
};
var DomainsResponse = function (response) {
var GlobalDomainResponse = function (response) {
this.type = response.Type;
this.domains = response.Domains;
this.excluded = response.Excluded;
};
this.equivalentDomains = response.EquivalentDomains;
this.globalEquivalentDomains = [];
var globalEquivalentDomains = response.GlobalEquivalentDomains;
if (!globalEquivalentDomains) {
return;
}
for (var i = 0; i < globalEquivalentDomains.length; i++) {
this.globalEquivalentDomains.push(new GlobalDomainResponse(globalEquivalentDomains[i]));
}
};
var SyncResponse = function (response) {
if (response.Profile) {
this.profile = new ProfileResponse(response.Profile);
}
var i;
this.folders = [];
if (response.Folders) {
for (i = 0; i < response.Folders.length; i++) {
this.folders.push(new FolderResponse(response.Folders[i]));
}
}
this.ciphers = [];
if (response.Ciphers) {
for (i = 0; i < response.Ciphers.length; i++) {
this.ciphers.push(new CipherResponse(response.Ciphers[i]));
}
}
if (response.Domains) {
this.domains = new DomainsResponse(response.Domains);
}
};