/**
 * CSRF 防护插件
 * 自动为请求添加 CSRF Token
 */ "use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "createCSRFPlugin", {
    enumerable: true,
    get: function() {
        return createCSRFPlugin;
    }
});
const _RequestPlugin = require("./RequestPlugin");
const _csrf = require("../../utils/csrf");
function createCSRFPlugin() {
    return {
        name: 'csrf-protection',
        priority: _RequestPlugin.PluginPriority.HIGH,
        async onBeforeRequest (context) {
            const csrfManager = (0, _csrf.getCSRFManager)();
            if (!csrfManager) {
                // CSRF 管理器未初始化，跳过
                return;
            }
            // 获取 CSRF Token
            const token = await csrfManager.getToken();
            if (token) {
                // 添加 CSRF Token 到请求头
                const headerName = csrfManager.getHeaderName();
                context.request.headers = {
                    ...context.request.headers,
                    [headerName]: token
                };
            }
        }
    };
}

//# sourceMappingURL=csrfPlugin.js.map