UNPKG

passbolt-styleguide

Version:

Passbolt styleguide contains common styling assets used by the different sites, plugin, etc.

131 lines (115 loc) 3.27 kB
/** * Passbolt ~ Open source password manager for teams * Copyright (c) Passbolt SA (https://www.passbolt.com) * * Licensed under GNU Affero General Public License version 3 of the or any later version. * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @copyright Copyright (c) Passbolt SA (https://www.passbolt.com) * @license https://opensource.org/licenses/AGPL-3.0 AGPL License * @link https://www.passbolt.com Passbolt(tm) * @since 5.0.0 */ import TotpEntity from "../totp/totpEntity"; import SecretDataEntity, { SECRET_DATA_OBJECT_TYPE } from "./secretDataEntity"; import assertString from "validator/es/lib/util/assertString"; class SecretDataV5StandaloneTotpEntity extends SecretDataEntity { /** * @inheritDoc */ constructor(dto, options = {}) { super(dto, options); // Associations if (this._props.totp) { this._totp = new TotpEntity(this._props.totp, { ...options, clone: false }); delete this._props.totp; } } /** * Get the secret data default totp schema * @returns {object} */ static getSchema() { return { type: "object", required: ["object_type", "totp"], properties: { ...SecretDataEntity.getSchema().properties, totp: TotpEntity.getSchema(), }, }; } /** * @inheritDoc */ static get associations() { return { totp: TotpEntity, }; } /** * @inheritdoc */ marshall() { // Set object type in case of secret has not object_type (example: after a migration v4 to v5) if (!this._props.object_type) { this._props.object_type = SECRET_DATA_OBJECT_TYPE; } } /** * Return the default secret data v5 totp. * @param {object} data the data to override the default with * @param {object} [options] Options. * @returns {SecretDataV5StandaloneTotpEntity} */ static createFromDefault(data = {}, options) { const defaultData = { object_type: SECRET_DATA_OBJECT_TYPE, totp: TotpEntity.createFromDefault({}, { validate: false }).toDto(), }; return new SecretDataV5StandaloneTotpEntity({ ...defaultData, ...data }, options); } /** * Return the default secret property. * @param {string} propName the property * @returns {object | undefined} */ static getDefaultProp(propName) { assertString(propName); switch (propName) { case "totp": return TotpEntity.createFromDefault({}, { validate: false }).toDto(); default: return; } } /** * Are secret different * @param secretDto * @returns {boolean} */ areSecretsDifferent(secretDto) { const totp = this.totp.toDto(); return Object.keys(totp).some((key) => totp[key] !== secretDto.totp?.[key]); } /** * Get the DTO of properties managed by the form. * @returns {object} */ toDto() { const result = Object.assign({}, this._props); if (this.totp) { result.totp = this.totp.toDto(); } return result; } /** * Get the totp association. * @returns {TotpEntity} */ get totp() { return this._totp; } } export default SecretDataV5StandaloneTotpEntity;