"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createClientLogValidator = exports.getAuditLogsValidator = exports.getLogsValidator = void 0;
const express_validator_1 = require("express-validator");
const misc_1 = require("../../helpers/custom-validators/activitypub/misc");
const search_1 = require("../../helpers/custom-validators/search");
const config_1 = require("../../initializers/config");
const core_utils_1 = require("../../../shared/core-utils");
const logs_1 = require("../../helpers/custom-validators/logs");
const misc_2 = require("../../helpers/custom-validators/misc");
const shared_1 = require("./shared");
const createClientLogValidator = [
    (0, express_validator_1.body)('message')
        .custom(logs_1.isValidClientLogMessage),
    (0, express_validator_1.body)('url')
        .custom(misc_1.isUrlValid),
    (0, express_validator_1.body)('level')
        .custom(logs_1.isValidClientLogLevel),
    (0, express_validator_1.body)('stackTrace')
        .optional()
        .custom(logs_1.isValidClientLogStackTrace),
    (0, express_validator_1.body)('meta')
        .optional()
        .custom(logs_1.isValidClientLogMeta),
    (0, express_validator_1.body)('userAgent')
        .optional()
        .custom(logs_1.isValidClientLogUserAgent),
    (req, res, next) => {
        if (config_1.CONFIG.LOG.ACCEPT_CLIENT_LOG !== true) {
            return res.sendStatus(403);
        }
        if ((0, shared_1.areValidationErrors)(req, res))
            return;
        return next();
    }
];
exports.createClientLogValidator = createClientLogValidator;
const getLogsValidator = [
    (0, express_validator_1.query)('startDate')
        .custom(misc_2.isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
    (0, express_validator_1.query)('level')
        .optional()
        .custom(logs_1.isValidLogLevel),
    (0, express_validator_1.query)('tagsOneOf')
        .optional()
        .customSanitizer(core_utils_1.arrayify)
        .custom(search_1.isStringArray).withMessage('Should have a valid one of tags array'),
    (0, express_validator_1.query)('endDate')
        .optional()
        .custom(misc_2.isDateValid).withMessage('Should have an end date that conforms to ISO 8601'),
    (req, res, next) => {
        if ((0, shared_1.areValidationErrors)(req, res))
            return;
        return next();
    }
];
exports.getLogsValidator = getLogsValidator;
const getAuditLogsValidator = [
    (0, express_validator_1.query)('startDate')
        .custom(misc_2.isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
    (0, express_validator_1.query)('endDate')
        .optional()
        .custom(misc_2.isDateValid).withMessage('Should have a end date that conforms to ISO 8601'),
    (req, res, next) => {
        if ((0, shared_1.areValidationErrors)(req, res))
            return;
        return next();
    }
];
exports.getAuditLogsValidator = getAuditLogsValidator;
//# sourceMappingURL=logs.js.map