"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SecretManager = void 0;
const client_secrets_manager_1 = require("@aws-sdk/client-secrets-manager");
const credential_providers_1 = require("@aws-sdk/credential-providers"); // ES6 import
const promise_error_handler_1 = __importDefault(require("../error/promise-error-handler"));
class SecretManager {
    constructor(config) {
        this.client = new client_secrets_manager_1.SecretsManagerClient({
            credentials: (0, credential_providers_1.fromNodeProviderChain)(),
            region: config.region,
        });
    }
    getSecret(secretName) {
        return __awaiter(this, void 0, void 0, function* () {
            const params = {
                SecretId: secretName
            };
            const command = new client_secrets_manager_1.GetSecretValueCommand(params);
            const { result: secret, error } = yield (0, promise_error_handler_1.default)(this.client.send(command));
            if (error) {
                return Promise.reject(error);
            }
            return JSON.parse(secret === null || secret === void 0 ? void 0 : secret.SecretString);
        });
    }
}
exports.SecretManager = SecretManager;
//# sourceMappingURL=secret-manager.js.map