@8ms/helpers 1.1.9 → 1.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Delete a single file.
3
3
  */
4
- declare const deleteFile: ({ S3Lib, bucket, client, file }: {
4
+ declare const deleteFile: ({ S3Lib, bucket, client, key }: {
5
5
  S3Lib: any;
6
6
  bucket: string;
7
7
  client: any;
8
- file: string;
8
+ key: string;
9
9
  }) => Promise<void>;
10
10
  export default deleteFile;
@@ -40,7 +40,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
40
40
  * Delete a single file.
41
41
  */
42
42
  var deleteFile = function (_a) {
43
- var S3Lib = _a.S3Lib, bucket = _a.bucket, client = _a.client, file = _a.file;
43
+ var S3Lib = _a.S3Lib, bucket = _a.bucket, client = _a.client, key = _a.key;
44
44
  return __awaiter(void 0, void 0, void 0, function () {
45
45
  var DeleteObjectCommand;
46
46
  return __generator(this, function (_b) {
@@ -49,7 +49,7 @@ var deleteFile = function (_a) {
49
49
  DeleteObjectCommand = S3Lib.DeleteObjectCommand;
50
50
  return [4 /*yield*/, client.send(new DeleteObjectCommand({
51
51
  Bucket: bucket,
52
- Key: file,
52
+ Key: key,
53
53
  }))];
54
54
  case 1:
55
55
  _b.sent();
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Delete multiple files.
3
3
  */
4
- declare const deleteFiles: ({ S3Lib, bucket, client, files }: {
4
+ declare const deleteFiles: ({ S3Lib, bucket, client, keys }: {
5
5
  S3Lib: any;
6
6
  bucket: string;
7
7
  client: any;
8
- files: string[];
8
+ keys: string[];
9
9
  }) => Promise<void>;
10
10
  export default deleteFiles;
@@ -40,7 +40,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
40
40
  * Delete multiple files.
41
41
  */
42
42
  var deleteFiles = function (_a) {
43
- var S3Lib = _a.S3Lib, bucket = _a.bucket, client = _a.client, files = _a.files;
43
+ var S3Lib = _a.S3Lib, bucket = _a.bucket, client = _a.client, keys = _a.keys;
44
44
  return __awaiter(void 0, void 0, void 0, function () {
45
45
  var DeleteObjectsCommand;
46
46
  return __generator(this, function (_b) {
@@ -50,8 +50,8 @@ var deleteFiles = function (_a) {
50
50
  return [4 /*yield*/, client.send(new DeleteObjectsCommand({
51
51
  Bucket: bucket,
52
52
  Delete: {
53
- Objects: files.map(function (file) { return ({
54
- Key: file,
53
+ Objects: keys.map(function (key) { return ({
54
+ Key: key,
55
55
  }); }),
56
56
  },
57
57
  }))];
@@ -4,17 +4,17 @@ declare type PresignedPostType = {
4
4
  client: any;
5
5
  conditions: any[];
6
6
  expires: number;
7
- file: string;
8
7
  fields: {
9
8
  [key: string]: string;
10
9
  };
10
+ key: string;
11
11
  };
12
12
  /**
13
13
  * Returns a presigned post to upload a file directly to S3.
14
14
  * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_s3_presigned_post.html
15
15
  * https://github.com/8millionstories-organisation/test-vercel-upload-2/blob/50eb12fcb3870a59ab455811bfaa1bdcb886edf2/pages/api/upload-url.js
16
16
  */
17
- declare const getPresignedPost: ({ S3Lib, bucket, client, conditions, expires, file, fields }: PresignedPostType) => Promise<{
17
+ declare const getPresignedPost: ({ S3Lib, bucket, client, conditions, expires, fields, key }: PresignedPostType) => Promise<{
18
18
  url: any;
19
19
  fields: any;
20
20
  }>;
@@ -42,7 +42,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
42
42
  * https://github.com/8millionstories-organisation/test-vercel-upload-2/blob/50eb12fcb3870a59ab455811bfaa1bdcb886edf2/pages/api/upload-url.js
43
43
  */
44
44
  var getPresignedPost = function (_a) {
45
- var S3Lib = _a.S3Lib, bucket = _a.bucket, client = _a.client, conditions = _a.conditions, expires = _a.expires, file = _a.file, fields = _a.fields;
45
+ var S3Lib = _a.S3Lib, bucket = _a.bucket, client = _a.client, conditions = _a.conditions, expires = _a.expires, fields = _a.fields, key = _a.key;
46
46
  return __awaiter(void 0, void 0, void 0, function () {
47
47
  var createPresignedPost, apiResponse;
48
48
  return __generator(this, function (_b) {
@@ -51,7 +51,7 @@ var getPresignedPost = function (_a) {
51
51
  createPresignedPost = S3Lib.createPresignedPost;
52
52
  return [4 /*yield*/, createPresignedPost(client, {
53
53
  Bucket: bucket,
54
- Key: file,
54
+ Key: key,
55
55
  Conditions: undefined === conditions ? [] : conditions,
56
56
  Fields: undefined === fields ? {} : fields,
57
57
  Expires: undefined === expires ? 60 : expires, // Seconds
@@ -5,11 +5,11 @@ declare type GetSignedUrlType = {
5
5
  bucket: string;
6
6
  client: any;
7
7
  expires: number;
8
- file: string;
8
+ key: string;
9
9
  };
10
10
  /**
11
11
  * Returns a signed for URL to allow download of private buckets for a given duration.
12
12
  * Library: @aws-sdk/s3-request-presigner
13
13
  */
14
- declare const getSignedUrl: ({ S3Lib, S3PresignerLib, bucket, client, expires, file }: GetSignedUrlType) => Promise<ResponseType>;
14
+ declare const getSignedUrl: ({ S3Lib, S3PresignerLib, bucket, client, expires, key }: GetSignedUrlType) => Promise<ResponseType>;
15
15
  export default getSignedUrl;
@@ -53,7 +53,7 @@ var api_1 = require("../../api");
53
53
  * Library: @aws-sdk/s3-request-presigner
54
54
  */
55
55
  var getSignedUrl = function (_a) {
56
- var S3Lib = _a.S3Lib, S3PresignerLib = _a.S3PresignerLib, bucket = _a.bucket, client = _a.client, expires = _a.expires, file = _a.file;
56
+ var S3Lib = _a.S3Lib, S3PresignerLib = _a.S3PresignerLib, bucket = _a.bucket, client = _a.client, expires = _a.expires, key = _a.key;
57
57
  return __awaiter(void 0, void 0, void 0, function () {
58
58
  var response, GetObjectCommand, getSignedUrl, command, awsResponse;
59
59
  return __generator(this, function (_b) {
@@ -64,7 +64,7 @@ var getSignedUrl = function (_a) {
64
64
  getSignedUrl = S3PresignerLib.getSignedUrl;
65
65
  command = new GetObjectCommand({
66
66
  Bucket: bucket,
67
- Key: file,
67
+ Key: key,
68
68
  });
69
69
  return [4 /*yield*/, getSignedUrl(client, command, { expiresIn: expires })];
70
70
  case 1:
@@ -5,10 +5,10 @@ export declare type ReadBufferType = ReadType & {
5
5
  /**
6
6
  * Similar function to reading the S3 file, but instead of a text file return a buffer.
7
7
  */
8
- declare const readBuffer: ({ S3Lib, bucket, client, file }: {
8
+ declare const readBuffer: ({ S3Lib, bucket, client, key }: {
9
9
  S3Lib: any;
10
10
  bucket: string;
11
11
  client: any;
12
- file: string;
12
+ key: string;
13
13
  }) => Promise<ReadBufferType>;
14
14
  export default readBuffer;
@@ -45,7 +45,7 @@ var isResponse200_1 = __importDefault(require("../isResponse200"));
45
45
  * Similar function to reading the S3 file, but instead of a text file return a buffer.
46
46
  */
47
47
  var readBuffer = function (_a) {
48
- var S3Lib = _a.S3Lib, bucket = _a.bucket, client = _a.client, file = _a.file;
48
+ var S3Lib = _a.S3Lib, bucket = _a.bucket, client = _a.client, key = _a.key;
49
49
  return __awaiter(void 0, void 0, void 0, function () {
50
50
  var response, GetObjectCommand, apiResponse, chunks_1, _b;
51
51
  return __generator(this, function (_c) {
@@ -71,7 +71,7 @@ var readBuffer = function (_a) {
71
71
  GetObjectCommand = S3Lib.GetObjectCommand;
72
72
  return [4 /*yield*/, client.send(new GetObjectCommand({
73
73
  Bucket: bucket,
74
- Key: file,
74
+ Key: key,
75
75
  }))];
76
76
  case 1:
77
77
  apiResponse = _c.sent();
@@ -20,11 +20,11 @@ export declare type ReadFileType = ReadType & {
20
20
  /**
21
21
  * Read a file from S3 and return either null, the content or JSON decoded.
22
22
  */
23
- declare const readFile: ({ S3Lib, bucket, client, file, isJson }: {
23
+ declare const readFile: ({ S3Lib, bucket, client, key, isJson }: {
24
24
  S3Lib: any;
25
25
  bucket: string;
26
26
  client: any;
27
- file: string;
27
+ key: string;
28
28
  isJson: boolean;
29
29
  }) => Promise<ReadFileType>;
30
30
  export default readFile;
@@ -52,7 +52,7 @@ var isResponse200_1 = __importDefault(require("../isResponse200"));
52
52
  * Read a file from S3 and return either null, the content or JSON decoded.
53
53
  */
54
54
  var readFile = function (_a) {
55
- var S3Lib = _a.S3Lib, bucket = _a.bucket, client = _a.client, file = _a.file, isJson = _a.isJson;
55
+ var S3Lib = _a.S3Lib, bucket = _a.bucket, client = _a.client, key = _a.key, isJson = _a.isJson;
56
56
  return __awaiter(void 0, void 0, void 0, function () {
57
57
  var response, GetObjectCommand, apiResponse, now, modified, _b;
58
58
  return __generator(this, function (_c) {
@@ -78,7 +78,7 @@ var readFile = function (_a) {
78
78
  GetObjectCommand = S3Lib.GetObjectCommand;
79
79
  return [4 /*yield*/, client.send(new GetObjectCommand({
80
80
  Bucket: bucket,
81
- Key: file,
81
+ Key: key,
82
82
  }))];
83
83
  case 1:
84
84
  apiResponse = _c.sent();
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Write a file to S3.
3
3
  */
4
- export declare const writeFile: ({ S3Lib, bucket, client, file, content }: {
4
+ export declare const writeFile: ({ S3Lib, bucket, client, data, key }: {
5
5
  S3Lib: any;
6
6
  bucket: string;
7
7
  client: any;
8
- file: string;
9
- content: any;
8
+ data: any;
9
+ key: string;
10
10
  }) => Promise<any>;
11
11
  export default writeFile;
@@ -41,7 +41,7 @@ exports.writeFile = void 0;
41
41
  * Write a file to S3.
42
42
  */
43
43
  var writeFile = function (_a) {
44
- var S3Lib = _a.S3Lib, bucket = _a.bucket, client = _a.client, file = _a.file, content = _a.content;
44
+ var S3Lib = _a.S3Lib, bucket = _a.bucket, client = _a.client, data = _a.data, key = _a.key;
45
45
  return __awaiter(void 0, void 0, void 0, function () {
46
46
  var PutObjectCommand, apiResponse;
47
47
  return __generator(this, function (_b) {
@@ -50,8 +50,8 @@ var writeFile = function (_a) {
50
50
  PutObjectCommand = S3Lib.PutObjectCommand;
51
51
  return [4 /*yield*/, client.send(new PutObjectCommand({
52
52
  Bucket: bucket,
53
- Body: content,
54
- Key: file,
53
+ Body: data,
54
+ Key: key,
55
55
  }))];
56
56
  case 1:
57
57
  apiResponse = _b.sent();
@@ -5,11 +5,11 @@ declare type WritePresignedPostType = {
5
5
  config: ConfigType;
6
6
  fields: any;
7
7
  file: any;
8
- fileName: string;
8
+ key: string;
9
9
  url: string;
10
10
  };
11
11
  /**
12
12
  * Get a presigned post URL so we can upload directly to S3 via frontend.
13
13
  */
14
- declare const writePresignedPost: ({ bucket, config, fields, file, fileName, url }: WritePresignedPostType) => Promise<ResponseType>;
14
+ declare const writePresignedPost: ({ bucket, config, fields, file, key, url }: WritePresignedPostType) => Promise<ResponseType>;
15
15
  export default writePresignedPost;
@@ -52,7 +52,7 @@ var api_1 = require("../../api");
52
52
  * Get a presigned post URL so we can upload directly to S3 via frontend.
53
53
  */
54
54
  var writePresignedPost = function (_a) {
55
- var bucket = _a.bucket, config = _a.config, fields = _a.fields, file = _a.file, fileName = _a.fileName, url = _a.url;
55
+ var bucket = _a.bucket, config = _a.config, fields = _a.fields, file = _a.file, key = _a.key, url = _a.url;
56
56
  return __awaiter(void 0, void 0, void 0, function () {
57
57
  return __generator(this, function (_b) {
58
58
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
@@ -78,7 +78,7 @@ var writePresignedPost = function (_a) {
78
78
  if (upload.ok) {
79
79
  response.state = api_1.states.SUCCESS;
80
80
  response.body = {
81
- url: "https://".concat(bucket, ".s3.").concat(config.region, ".amazonaws.com/").concat(fileName),
81
+ url: "https://".concat(bucket, ".s3.").concat(config.region, ".amazonaws.com/").concat(key),
82
82
  };
83
83
  resolve(response);
84
84
  }
@@ -48,7 +48,7 @@ var getCache = function (_a) {
48
48
  switch (_b.label) {
49
49
  case 0:
50
50
  client = (0, s3_1.getClient)({ S3Lib: S3Lib, config: config });
51
- return [4 /*yield*/, (0, s3_1.readFile)({ S3Lib: S3Lib, bucket: bucket, client: client, file: key, isJson: isJson })];
51
+ return [4 /*yield*/, (0, s3_1.readFile)({ S3Lib: S3Lib, bucket: bucket, client: client, key: key, isJson: isJson })];
52
52
  case 1:
53
53
  _b.sent();
54
54
  return [2 /*return*/];
@@ -48,7 +48,7 @@ var saveCache = function (_a) {
48
48
  switch (_b.label) {
49
49
  case 0:
50
50
  client = (0, s3_1.getClient)({ S3Lib: S3Lib, config: config });
51
- return [4 /*yield*/, (0, s3_1.writeFile)({ S3Lib: S3Lib, bucket: bucket, client: client, file: key, content: data })];
51
+ return [4 /*yield*/, (0, s3_1.writeFile)({ S3Lib: S3Lib, bucket: bucket, client: client, data: data, key: key })];
52
52
  case 1:
53
53
  _b.sent();
54
54
  return [2 /*return*/];
@@ -52,7 +52,7 @@ var updateCache = function (_a) {
52
52
  switch (_b.label) {
53
53
  case 0:
54
54
  client = (0, s3_1.getClient)({ S3Lib: S3Lib, config: config });
55
- return [4 /*yield*/, (0, s3_1.deleteFile)({ S3Lib: S3Lib, bucket: bucket, client: client, file: key })];
55
+ return [4 /*yield*/, (0, s3_1.deleteFile)({ S3Lib: S3Lib, bucket: bucket, client: client, key: key })];
56
56
  case 1:
57
57
  _b.sent();
58
58
  return [4 /*yield*/, (0, saveCache_1.default)({ S3Lib: S3Lib, bucket: bucket, config: config, data: data, key: key })];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
- "version": "1.1.9",
3
+ "version": "1.1.10",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"