"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.TokenExchangeModule = void 0;
const constants_1 = require("@n8n/constants");
const decorators_1 = require("@n8n/decorators");
const di_1 = require("@n8n/di");
function isFeatureFlagEnabled() {
    return process.env.N8N_ENV_FEAT_TOKEN_EXCHANGE === 'true';
}
let TokenExchangeModule = class TokenExchangeModule {
    async entities() {
        const { TokenExchangeJti } = await Promise.resolve().then(() => __importStar(require('./database/entities/token-exchange-jti.entity')));
        const { TrustedKeySourceEntity } = await Promise.resolve().then(() => __importStar(require('./database/entities/trusted-key-source.entity')));
        const { TrustedKeyEntity } = await Promise.resolve().then(() => __importStar(require('./database/entities/trusted-key.entity')));
        return [TokenExchangeJti, TrustedKeySourceEntity, TrustedKeyEntity];
    }
    async init() {
        if (!isFeatureFlagEnabled()) {
            return;
        }
        const { TrustedKeyService } = await Promise.resolve().then(() => __importStar(require('./services/trusted-key.service')));
        await di_1.Container.get(TrustedKeyService).initialize();
        await Promise.resolve().then(() => __importStar(require('./controllers/token-exchange.controller')));
        await Promise.resolve().then(() => __importStar(require('./controllers/embed-auth.controller')));
        const { JtiCleanupService } = await Promise.resolve().then(() => __importStar(require('./services/jti-cleanup.service')));
        di_1.Container.get(JtiCleanupService).init();
        const { ScopedJwtStrategy } = await Promise.resolve().then(() => __importStar(require('./services/scoped-jwt.strategy')));
        const { AuthStrategyRegistry } = await Promise.resolve().then(() => __importStar(require('../../services/auth-strategy.registry')));
        di_1.Container.get(AuthStrategyRegistry).register(di_1.Container.get(ScopedJwtStrategy));
    }
};
exports.TokenExchangeModule = TokenExchangeModule;
exports.TokenExchangeModule = TokenExchangeModule = __decorate([
    (0, decorators_1.BackendModule)({
        name: 'token-exchange',
        licenseFlag: constants_1.LICENSE_FEATURES.TOKEN_EXCHANGE,
        instanceTypes: ['main'],
    })
], TokenExchangeModule);
//# sourceMappingURL=token-exchange.module.js.map