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 { S3Client, PutObjectCommand, GetObjectCommand } from "@aws-sdk/client-s3";
import { fromNodeProviderChain } from "@aws-sdk/credential-providers"; // ES6 import
import catchable from "../error/promise-error-handler";
export class S3 {
    constructor(config) {
        this.put = (bucketName, key, data) => __awaiter(this, void 0, void 0, function* () {
            const params = {
                Bucket: bucketName,
                Key: key,
                Body: data
            };
            const command = new PutObjectCommand(params);
            const { error } = yield catchable(this.client.send(command));
            if (error) {
                return Promise.reject(error);
            }
            // Return true if upload succeded
            return true;
        });
        this.get = (bucketName, key) => __awaiter(this, void 0, void 0, function* () {
            const bucketParams = {
                Bucket: bucketName,
                Key: key
            };
            const { result: data, error } = yield catchable(this.client.send(new GetObjectCommand(bucketParams)));
            if (error) {
                return Promise.reject(error);
            }
            return data === null || data === void 0 ? void 0 : data.Body;
        });
        const settings = {
            credentials: fromNodeProviderChain(),
            region: config.region,
        };
        this.client = new S3Client(settings);
    }
}
//# sourceMappingURL=s3.js.map