123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _Utils = _interopRequireDefault(require("../Utils"));
- var _lodash = require("lodash");
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
- /**
- * @module SecurityCheck
- */
- /**
- * A security check.
- * @class
- */
- class Check {
- /**
- * Constructs a new security check.
- * @param {Object} params The parameters.
- * @param {String} params.title The title.
- * @param {String} params.warning The warning message if the check fails.
- * @param {String} params.solution The solution to fix the check.
- * @param {Promise} params.check The check as synchronous or asynchronous function.
- */
- constructor(params) {
- this._validateParams(params);
- const {
- title,
- warning,
- solution,
- check
- } = params;
- this.title = title;
- this.warning = warning;
- this.solution = solution;
- this.check = check;
- // Set default properties
- this._checkState = CheckState.none;
- this.error;
- }
- /**
- * Returns the current check state.
- * @return {CheckState} The check state.
- */
- checkState() {
- return this._checkState;
- }
- async run() {
- // Get check as synchronous or asynchronous function
- const check = this.check instanceof Promise ? await this.check : this.check;
- // Run check
- try {
- check();
- this._checkState = CheckState.success;
- } catch (e) {
- this.stateFailError = e;
- this._checkState = CheckState.fail;
- }
- }
- /**
- * Validates the constructor parameters.
- * @param {Object} params The parameters to validate.
- */
- _validateParams(params) {
- _Utils.default.validateParams(params, {
- group: {
- t: 'string',
- v: _lodash.isString
- },
- title: {
- t: 'string',
- v: _lodash.isString
- },
- warning: {
- t: 'string',
- v: _lodash.isString
- },
- solution: {
- t: 'string',
- v: _lodash.isString
- },
- check: {
- t: 'function',
- v: _lodash.isFunction
- }
- });
- }
- }
- /**
- * The check state.
- */
- const CheckState = Object.freeze({
- none: 'none',
- fail: 'fail',
- success: 'success'
- });
- var _default = exports.default = Check;
- module.exports = {
- Check,
- CheckState
- };
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfVX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