"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get interceptRoles () {
        return interceptRoles;
    },
    get validateWizardCompleted () {
        return validateWizardCompleted;
    }
});
const _awilixexpress = require("awilix-express");
const _runtimeexceptions = require("../exceptions/runtime.exceptions");
const validateWizardCompleted = (0, _awilixexpress.inject)((configService, settingsStore, loggerFactory)=>async (req, _res, next)=>{
        const logger = loggerFactory(validateWizardCompleted.name);
        const isDemoMode = configService.isDemoMode();
        if (isDemoMode || !!settingsStore.getWizardSettings()?.wizardCompleted) {
            next();
            return;
        }
        const allowedPaths = [
            "/api/v2/first-time-setup/complete",
            "/api/v2/first-time-setup/validate",
            "/api/v2/first-time-setup/yaml-import",
            "/api/v2/test",
            "/api/v2/auth/login-required"
        ];
        if (allowedPaths.includes(req.path) || !req.path.startsWith("/api/v2") || req.path.startsWith("/api-docs")) {
            next();
        } else {
            logger.error("Wizard not completed", req.path);
            throw new _runtimeexceptions.ForbiddenError(`First-time-setup not completed, these api paths are enabled: ${allowedPaths.join(", ")}`);
        }
    });
const interceptRoles = (0, _awilixexpress.inject)((settingsStore, roleService)=>async (req, _res, next)=>{
        const serverSettings = settingsStore.getSettings();
        req.roles = req.user?.roles ?? [];
        if (serverSettings && !req.user) {
            req.roles = await roleService.getAppDefaultRoleNames();
        }
        next();
    });

//# sourceMappingURL=global.middleware.js.map