"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildRateLimiter = void 0;
const tslib_1 = require("tslib");
const express_rate_limit_1 = tslib_1.__importDefault(require("express-rate-limit"));
const auth_1 = require("./auth");
const whitelistRoles = new Set([0, 1]);
function buildRateLimiter(options) {
    return (0, express_rate_limit_1.default)({
        windowMs: options.windowMs,
        max: options.max,
        skipFailedRequests: options.skipFailedRequests,
        handler: (req, res, next, options) => {
            return (0, auth_1.optionalAuthenticate)(req, res, () => {
                if (res.locals.authenticated === true && whitelistRoles.has(res.locals.oauth.token.User.role)) {
                    return next();
                }
                return res.status(options.statusCode).send(options.message);
            });
        }
    });
}
exports.buildRateLimiter = buildRateLimiter;
//# sourceMappingURL=rate-limiter.js.map