@8ms/helpers 1.3.16 → 1.3.18

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.
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const getCleanFolder_1 = __importDefault(require("../../string/getCleanFolder"));
6
+ const getFolder_1 = __importDefault(require("../../string/getFolder"));
7
7
  /**
8
8
  * Iteratively delete all the files within a directory and delete the directory.
9
9
  */
10
10
  const deleteFolder = async ({ bucket, folder }) => {
11
- const cleanFolder = (0, getCleanFolder_1.default)({ input: folder });
11
+ const cleanFolder = (0, getFolder_1.default)({ input: folder });
12
12
  const { ListObjectsV2Command, DeleteObjectsCommand } = require('@aws-sdk/client-s3');
13
13
  // Get a list of all files to be deleted
14
14
  const apiResponse = await global.awsS3Client.send(new ListObjectsV2Command({
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const getCleanFolder_1 = __importDefault(require("../../string/getCleanFolder"));
6
+ const getFolder_1 = __importDefault(require("../../string/getFolder"));
7
7
  /**
8
8
  * List the files in the given bucket and option folder
9
9
  */
10
10
  const listFiles = async ({ bucket, folder = '' }) => {
11
- const cleanFolder = (0, getCleanFolder_1.default)({ input: folder });
11
+ const cleanFolder = (0, getFolder_1.default)({ input: folder });
12
12
  let response = [];
13
13
  let valid = [];
14
14
  const { ListObjectsV2Command } = require('@aws-sdk/client-s3');
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const getCleanFolder_1 = __importDefault(require("../../string/getCleanFolder"));
6
+ const getFolder_1 = __importDefault(require("../../string/getFolder"));
7
7
  /**
8
8
  * List the files in the given bucket and option folder.
9
9
  */
10
10
  const listFolders = async ({ bucket, folder }) => {
11
- const cleanFolder = (0, getCleanFolder_1.default)({ input: folder });
11
+ const cleanFolder = (0, getFolder_1.default)({ input: folder });
12
12
  let response = [];
13
13
  const { ListObjectsV2Command } = require('@aws-sdk/client-s3');
14
14
  const apiResponse = await global.awsS3Client.send(new ListObjectsV2Command({
@@ -2,9 +2,10 @@ type CopyToCloud = {
2
2
  bucket: string;
3
3
  localFile: string;
4
4
  options?: object;
5
+ projectId?: string;
5
6
  };
6
7
  /**
7
8
  * Copy a local file to Google Cloud Storage.
8
9
  */
9
- export declare const copyToCloud: ({ bucket, localFile, options }: CopyToCloud) => Promise<any>;
10
+ export declare const copyToCloud: ({ bucket, localFile, options, projectId }: CopyToCloud) => Promise<any>;
10
11
  export default copyToCloud;
@@ -1,11 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.copyToCloud = void 0;
7
+ const getClient_1 = __importDefault(require("./getClient"));
4
8
  /**
5
9
  * Copy a local file to Google Cloud Storage.
6
10
  */
7
- const copyToCloud = async ({ bucket, localFile, options }) => {
8
- const bucketInstance = global.googleStorageClient.bucket(bucket);
11
+ const copyToCloud = async ({ bucket, localFile, options, projectId }) => {
12
+ const bucketInstance = (0, getClient_1.default)({ projectId })
13
+ .bucket(bucket);
9
14
  const apiResponse = await bucketInstance.upload(localFile, options);
10
15
  return apiResponse;
11
16
  };
@@ -2,10 +2,11 @@ type WriteFile = {
2
2
  bucket: string;
3
3
  data: any;
4
4
  key: string;
5
+ projectId?: string;
5
6
  [options: string]: any;
6
7
  };
7
8
  /**
8
9
  * Write a file to Google Cloud Storage.
9
10
  */
10
- export declare const writeFile: ({ bucket, contentType, data, key, ...options }: WriteFile) => Promise<any>;
11
+ export declare const writeFile: ({ bucket, contentType, data, key, projectId, ...options }: WriteFile) => Promise<any>;
11
12
  export default writeFile;
@@ -1,13 +1,18 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.writeFile = void 0;
7
+ const getClient_1 = __importDefault(require("./getClient"));
4
8
  /**
5
9
  * Write a file to Google Cloud Storage.
6
10
  */
7
- const writeFile = async ({ bucket, contentType, data, key, ...options }) => {
11
+ const writeFile = async ({ bucket, contentType, data, key, projectId, ...options }) => {
8
12
  const stream = require('stream');
9
13
  const dataStream = new stream.PassThrough();
10
- const googleFile = global.googleStorageClient.bucket(bucket)
14
+ const googleFile = (0, getClient_1.default)({ projectId })
15
+ .bucket(bucket)
11
16
  .file(key);
12
17
  dataStream.push(data);
13
18
  dataStream.push(null);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "1.3.16",
4
+ "version": "1.3.18",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
@@ -0,0 +1,8 @@
1
+ type GetFolder = {
2
+ input: string;
3
+ };
4
+ /**
5
+ * Take an input that may have a / before or after the input and return just the folder.
6
+ */
7
+ declare const getFolder: ({ input }: GetFolder) => string;
8
+ export default getFolder;
@@ -7,8 +7,8 @@ const trim_1 = __importDefault(require("lodash/trim"));
7
7
  /**
8
8
  * Take an input that may have a / before or after the input and return just the folder.
9
9
  */
10
- const getCleanFolder = ({ input }) => {
10
+ const getFolder = ({ input }) => {
11
11
  return (0, trim_1.default)(input, '/')
12
12
  .trim();
13
13
  };
14
- exports.default = getCleanFolder;
14
+ exports.default = getFolder;
@@ -1,8 +0,0 @@
1
- type GetCleanFolder = {
2
- input: string;
3
- };
4
- /**
5
- * Take an input that may have a / before or after the input and return just the folder.
6
- */
7
- declare const getCleanFolder: ({ input }: GetCleanFolder) => string;
8
- export default getCleanFolder;