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());
    });
};
import { SecretsManagerClient, GetSecretValueCommand } from "@aws-sdk/client-secrets-manager";
import { fromNodeProviderChain } from "@aws-sdk/credential-providers"; // ES6 import
import catchable from "../error/promise-error-handler";
export class SecretManager {
    constructor(config) {
        this.client = new SecretsManagerClient({
            credentials: fromNodeProviderChain(),
            region: config.region,
        });
    }
    getSecret(secretName) {
        return __awaiter(this, void 0, void 0, function* () {
            const params = {
                SecretId: secretName
            };
            const command = new GetSecretValueCommand(params);
            const { result: secret, error } = yield catchable(this.client.send(command));
            if (error) {
                return Promise.reject(error);
            }
            return JSON.parse(secret === null || secret === void 0 ? void 0 : secret.SecretString);
        });
    }
}
//# sourceMappingURL=secret-manager.js.map