react-aws-s3-typescript
Advanced tools
Comparing version 1.0.2 to 1.1.0
import { IConfig } from './types'; | ||
export declare const throwError: (config: IConfig, file: File) => void; | ||
export declare const throwError: (config: IConfig) => void; | ||
export declare const throwUploadError: (config: IConfig, file: File) => void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.throwError = void 0; | ||
var throwError = function (config, file) { | ||
exports.throwUploadError = exports.throwError = void 0; | ||
var throwError = function (config) { | ||
if (config.bucketName === null || config.bucketName === '') { | ||
@@ -17,2 +17,6 @@ throw new Error("Your bucketName cannot be empty "); | ||
} | ||
}; | ||
exports.throwError = throwError; | ||
var throwUploadError = function (config, file) { | ||
exports.throwError(config); | ||
if (!file) { | ||
@@ -22,2 +26,2 @@ throw new Error("File cannot be empty"); | ||
}; | ||
exports.throwError = throwError; | ||
exports.throwUploadError = throwUploadError; |
@@ -1,2 +0,2 @@ | ||
import { IConfig, UploadResponse } from './types'; | ||
import { IConfig, ListFileErrorResponse, ListFileResponse, UploadResponse } from './types'; | ||
declare class ReactS3Client { | ||
@@ -7,3 +7,4 @@ private config; | ||
deleteFile(key: string): Promise<void>; | ||
listFiles(): Promise<ListFileResponse | ListFileErrorResponse>; | ||
} | ||
export default ReactS3Client; |
@@ -59,3 +59,3 @@ "use strict"; | ||
case 0: | ||
ErrorThrower_1.throwError(this.config, file); | ||
ErrorThrower_1.throwUploadError(this.config, file); | ||
fd = new FormData(); | ||
@@ -129,4 +129,61 @@ if (file.type == null) { | ||
}; | ||
ReactS3Client.prototype.listFiles = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var awsConfig, s3, req, err_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
awsConfig = (function (_a) { | ||
var region = _a.region, accessKeyId = _a.accessKeyId, secretAccessKey = _a.secretAccessKey; | ||
return ({ region: region, accessKeyId: accessKeyId, secretAccessKey: secretAccessKey }); | ||
})(this.config); | ||
aws_sdk_1.default.config.update(awsConfig); | ||
s3 = new aws_sdk_1.default.S3({ | ||
apiVersion: '2006-03-01', | ||
params: { | ||
Bucket: this.config.bucketName, | ||
}, | ||
}); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, s3 | ||
.listObjects({ | ||
Bucket: this.config.bucketName, | ||
}) | ||
.promise()]; | ||
case 2: | ||
req = _a.sent(); | ||
if (req.$response.error) { | ||
return [2 /*return*/, Promise.reject({ | ||
err: req.$response.error.name, | ||
errMessage: req.$response.error.message, | ||
data: req.$response.error, | ||
})]; | ||
} | ||
if (!req.$response.data) { | ||
return [2 /*return*/, Promise.reject({ | ||
err: 'Something went wrong!', | ||
errMessage: 'Unknown error occured. Please try again', | ||
data: null, | ||
})]; | ||
} | ||
return [2 /*return*/, Promise.resolve({ | ||
message: 'Objects listed succesfully', | ||
data: req.$response.data, | ||
})]; | ||
case 3: | ||
err_1 = _a.sent(); | ||
return [2 /*return*/, Promise.reject({ | ||
err: 'Something went wrong!', | ||
errMessage: 'Unknown error occured. Please try again', | ||
data: err_1, | ||
})]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return ReactS3Client; | ||
}()); | ||
exports.default = ReactS3Client; |
@@ -43,2 +43,11 @@ export declare type DateISOString = string; | ||
}; | ||
export declare type ListFileResponse = { | ||
message: string; | ||
data: AWS.S3.ListObjectsOutput; | ||
}; | ||
export declare type ListFileErrorResponse = { | ||
err: string; | ||
errMessage: string; | ||
data: any; | ||
}; | ||
export {}; |
{ | ||
"name": "react-aws-s3-typescript", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Open source npm package to upload your files into AWS S3 Bucket directly using react(typescript template)", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24449
384