@8ms/helpers 1.23.0 → 1.24.0

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.
@@ -5,5 +5,5 @@ type IsFileExists = {
5
5
  /**
6
6
  * Check to see if a file exists but don't get the contents.
7
7
  */
8
- declare const isFileExists: ({ bucket, key }: IsFileExists) => Promise<boolean>;
8
+ declare const isFileExists: (props: IsFileExists) => Promise<boolean>;
9
9
  export default isFileExists;
@@ -7,14 +7,14 @@ const isResponse200_1 = __importDefault(require("../isResponse200"));
7
7
  /**
8
8
  * Check to see if a file exists but don't get the contents.
9
9
  */
10
- const isFileExists = async ({ bucket, key }) => {
10
+ const isFileExists = async (props) => {
11
11
  let response = false;
12
12
  try {
13
- const { HeadObjectCommand } = require('@aws-sdk/client-s3');
13
+ const { HeadObjectCommand } = require("@aws-sdk/client-s3");
14
14
  // Fetch from S3
15
15
  const apiResponse = await global.awsS3Client.send(new HeadObjectCommand({
16
- Bucket: bucket,
17
- Key: key,
16
+ Bucket: props.bucket,
17
+ Key: props.key,
18
18
  }));
19
19
  // If the status is 200 then it does exist
20
20
  response = (0, isResponse200_1.default)({ apiResponse });
@@ -0,0 +1,10 @@
1
+ type IsFileExists = {
2
+ bucket: string;
3
+ key: string;
4
+ projectId?: string;
5
+ };
6
+ /**
7
+ * Check to see if a file exists but don't get the contents.
8
+ */
9
+ declare const isFileExists: (props: IsFileExists) => Promise<boolean>;
10
+ export default isFileExists;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const getClient_1 = __importDefault(require("./getClient"));
7
+ /**
8
+ * Check to see if a file exists but don't get the contents.
9
+ */
10
+ const isFileExists = async (props) => {
11
+ const { bucket, key, projectId, } = props;
12
+ const googleFile = await (0, getClient_1.default)({ projectId })
13
+ .bucket(bucket)
14
+ .file(key)
15
+ .exists();
16
+ const response = googleFile?.[0];
17
+ return response;
18
+ };
19
+ exports.default = isFileExists;
@@ -2,11 +2,10 @@ type WriteFile = {
2
2
  bucket: string;
3
3
  data: any;
4
4
  key: string;
5
- projectId?: string;
6
5
  [options: string]: any;
7
6
  };
8
7
  /**
9
8
  * Write a file to Google Cloud Storage.
10
9
  */
11
- export declare const writeFile: ({ bucket, contentType, data, key, projectId, ...options }: WriteFile) => Promise<any>;
10
+ export declare const writeFile: (props: WriteFile) => Promise<any>;
12
11
  export default writeFile;
@@ -8,8 +8,9 @@ const getClient_1 = __importDefault(require("./getClient"));
8
8
  /**
9
9
  * Write a file to Google Cloud Storage.
10
10
  */
11
- const writeFile = async ({ bucket, contentType, data, key, projectId, ...options }) => {
12
- const stream = require('stream');
11
+ const writeFile = async (props) => {
12
+ const { bucket, contentType, data, key, projectId, ...options } = props;
13
+ const stream = require("stream");
13
14
  const dataStream = new stream.PassThrough();
14
15
  const googleFile = (0, getClient_1.default)({ projectId })
15
16
  .bucket(bucket)
@@ -18,16 +19,16 @@ const writeFile = async ({ bucket, contentType, data, key, projectId, ...options
18
19
  dataStream.push(null);
19
20
  return await new Promise((resolve, reject) => {
20
21
  dataStream.pipe(googleFile.createWriteStream({
21
- contentType: 'auto',
22
+ contentType: "auto",
22
23
  resumable: false,
23
24
  validation: false,
24
25
  metadata: {},
25
26
  ...options,
26
27
  }))
27
- .on('error', (error) => {
28
+ .on("error", (error) => {
28
29
  reject(error);
29
30
  })
30
- .on('finish', () => {
31
+ .on("finish", () => {
31
32
  resolve(true);
32
33
  });
33
34
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "1.23.0",
4
+ "version": "1.24.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"