bitwarden-estensione-browser/src/models/api/responseModels.js

170 lines
5.1 KiB
JavaScript
Raw Normal View History

window.CipherResponse = function (response) {
2016-09-03 07:13:09 +02:00
this.id = response.Id;
this.organizationId = response.OrganizationId;
2016-09-03 07:13:09 +02:00
this.folderId = response.FolderId;
this.type = response.Type;
2016-09-07 05:30:49 +02:00
this.favorite = response.Favorite;
2017-07-11 19:00:47 +02:00
this.edit = response.Edit;
this.organizationUseTotp = response.OrganizationUseTotp;
2016-09-03 07:13:09 +02:00
this.data = response.Data;
this.revisionDate = response.RevisionDate;
2017-07-11 19:00:47 +02:00
if (response.Attachments) {
this.attachments = [];
for (var i = 0; i < response.Attachments.length; i++) {
this.attachments.push(new AttachmentResponse(response.Attachments[i]));
}
}
2016-09-03 07:13:09 +02:00
};
window.FolderResponse = function (response) {
2016-09-03 07:13:09 +02:00
this.id = response.Id;
this.name = response.Name;
this.revisionDate = response.RevisionDate;
};
window.ProfileResponse = function (response) {
2016-09-03 07:13:09 +02:00
this.id = response.Id;
this.name = response.Name;
this.email = response.Email;
2017-07-11 19:00:47 +02:00
this.emailVerified = response.EmailVerified;
2016-09-03 07:13:09 +02:00
this.masterPasswordHint = response.MasterPasswordHint;
2017-07-11 19:00:47 +02:00
this.premium = response.Premium;
2016-09-03 07:13:09 +02:00
this.culture = response.Culture;
this.twoFactorEnabled = response.TwoFactorEnabled;
2017-06-02 06:10:29 +02:00
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]));
}
}
};
window.KeysResponse = function (response) {
this.privateKey = response.PrivateKey;
this.publicKey = response.PublicKey;
};
window.ProfileOrganizationResponse = function (response) {
this.id = response.Id;
this.name = response.Name;
2017-07-11 19:00:47 +02:00
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;
2017-07-11 19:00:47 +02:00
};
window.AttachmentResponse = function (response) {
2017-07-11 19:00:47 +02:00
this.id = response.Id;
this.url = response.Url;
this.fileName = response.FileName;
this.size = response.Size;
this.sizeName = response.SizeName;
2016-09-03 07:13:09 +02:00
};
window.IdentityTokenResponse = function (response) {
2017-01-18 05:07:46 +01:00
this.accessToken = response.access_token;
this.expiresIn = response.expires_in;
this.refreshToken = response.refresh_token;
this.tokenType = response.token_type;
this.privateKey = response.PrivateKey;
2017-06-02 06:10:29 +02:00
this.key = response.Key;
2017-06-27 04:24:10 +02:00
this.twoFactorToken = response.TwoFactorToken;
2017-01-18 05:07:46 +01:00
};
window.ListResponse = function (data) {
2016-09-07 05:30:49 +02:00
this.data = data;
2016-09-03 07:13:09 +02:00
};
window.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;
}
2017-10-24 20:48:58 +02:00
else if (response.responseText && response.responseText.indexOf('{') === 0) {
errorModel = JSON.parse(response.responseText);
}
if (errorModel) {
this.message = errorModel.Message;
this.validationErrors = errorModel.ValidationErrors;
2016-09-20 23:47:21 +02:00
}
this.statusCode = response.status;
2016-09-03 07:13:09 +02:00
};
window.DeviceResponse = function (response) {
2016-09-03 07:13:09 +02:00
this.id = response.Id;
this.name = response.Name;
this.identifier = response.Identifier;
this.type = response.Type;
this.creationDate = response.CreationDate;
};
window.CipherHistoryResponse = function (response) {
2016-09-03 07:13:09 +02:00
this.revised = [];
var revised = response.Revised;
for (var i = 0; i < revised.length; i++) {
2017-01-14 17:20:44 +01:00
this.revised.push(new CipherResponse(revised[i]));
2016-09-03 07:13:09 +02:00
}
this.deleted = response.Deleted;
};
2017-01-14 17:20:44 +01:00
window.DomainsResponse = function (response) {
2017-01-14 17:20:44 +01:00
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]));
}
};
2017-09-20 18:28:41 +02:00
window.SyncResponse = function (response) {
2017-09-20 18:28:41 +02:00
if (response.Profile) {
this.profile = new ProfileResponse(response.Profile);
}
2017-09-22 04:45:24 +02:00
var i;
2017-09-20 18:28:41 +02:00
this.folders = [];
if (response.Folders) {
2017-09-22 04:45:24 +02:00
for (i = 0; i < response.Folders.length; i++) {
2017-09-20 18:28:41 +02:00
this.folders.push(new FolderResponse(response.Folders[i]));
}
}
this.ciphers = [];
if (response.Ciphers) {
2017-09-22 04:45:24 +02:00
for (i = 0; i < response.Ciphers.length; i++) {
2017-09-20 18:28:41 +02:00
this.ciphers.push(new CipherResponse(response.Ciphers[i]));
}
}
if (response.Domains) {
this.domains = new DomainsResponse(response.Domains);
}
};