@8ms/helpers 1.1.103 → 1.1.105

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.
@@ -2,6 +2,7 @@ declare type WriteFile = {
2
2
  bucket: string;
3
3
  data: any;
4
4
  key: string;
5
+ [options: string]: any;
5
6
  };
6
7
  /**
7
8
  * Write a file to S3.
@@ -0,0 +1,10 @@
1
+ declare type WriteUrlContents = {
2
+ bucket: string;
3
+ key: string;
4
+ url: string;
5
+ };
6
+ /**
7
+ * Download a file and write to S3.
8
+ */
9
+ declare const writeUrlContents: ({ bucket, key, url }: WriteUrlContents) => Promise<void>;
10
+ export default writeUrlContents;
@@ -0,0 +1,29 @@
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 get_1 = __importDefault(require("../../axios/get"));
7
+ const writeFile_1 = __importDefault(require("./writeFile"));
8
+ /**
9
+ * Download a file and write to S3.
10
+ */
11
+ const writeUrlContents = async ({ bucket, key, url }) => {
12
+ return (0, get_1.default)({
13
+ config: {
14
+ responseType: "arraybuffer",
15
+ responseEncoding: "binary",
16
+ },
17
+ url,
18
+ })
19
+ .then(async (response) => {
20
+ await (0, writeFile_1.default)({
21
+ bucket,
22
+ data: response.data,
23
+ key,
24
+ ContentType: response.headers["content-type"],
25
+ ContentLength: response.headers["content-length"],
26
+ });
27
+ });
28
+ };
29
+ exports.default = writeUrlContents;
package/axios/get.d.ts CHANGED
@@ -1,8 +1,10 @@
1
+ import ApiResponse from '../api/ApiResponse';
1
2
  export declare type Get = {
2
3
  config?: object;
3
4
  onError?: Function;
4
5
  onSuccess?: Function;
6
+ returnApiResponse?: boolean;
5
7
  url: string;
6
8
  };
7
- declare const get: ({ config, onError, onSuccess, url }: Get) => Promise<any>;
9
+ declare const get: ({ config, onError, onSuccess, returnApiResponse, url }: Get) => Promise<any | ApiResponse>;
8
10
  export default get;
package/axios/get.js CHANGED
@@ -4,9 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const axios_1 = __importDefault(require("axios"));
7
+ const ApiResponse_1 = __importDefault(require("../api/ApiResponse"));
7
8
  const states_1 = __importDefault(require("../api/states"));
8
- const get = async ({ config = {}, onError, onSuccess, url }) => {
9
- const response = await axios_1.default.get(url, config)
9
+ const get = async ({ config = {}, onError, onSuccess, returnApiResponse, url }) => {
10
+ let response = await axios_1.default.get(url, config)
10
11
  .then(async (response) => {
11
12
  if (200 === response.status) {
12
13
  // Is an API request
@@ -39,6 +40,10 @@ const get = async ({ config = {}, onError, onSuccess, url }) => {
39
40
  throw Error;
40
41
  }
41
42
  });
43
+ // Convert the response into an ApiResponse instance
44
+ if (returnApiResponse) {
45
+ response = new ApiResponse_1.default(response);
46
+ }
42
47
  return response;
43
48
  };
44
49
  exports.default = get;
package/axios/post.d.ts CHANGED
@@ -1,12 +1,14 @@
1
+ import ApiResponse from '../api/ApiResponse';
1
2
  export declare type Post = {
2
3
  config?: object;
3
4
  data?: object;
4
5
  onError?: Function;
5
6
  onSuccess?: Function;
7
+ returnApiResponse?: boolean;
6
8
  url: string;
7
9
  };
8
10
  /**
9
11
  * Make a POST request.
10
12
  */
11
- declare const post: ({ config, data, onError, onSuccess, url }: Post) => Promise<any>;
13
+ declare const post: ({ config, data, onError, onSuccess, returnApiResponse, url }: Post) => Promise<any | ApiResponse>;
12
14
  export default post;
package/axios/post.js CHANGED
@@ -4,12 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const axios_1 = __importDefault(require("axios"));
7
+ const ApiResponse_1 = __importDefault(require("../api/ApiResponse"));
7
8
  const states_1 = __importDefault(require("../api/states"));
8
9
  /**
9
10
  * Make a POST request.
10
11
  */
11
- const post = async ({ config = {}, data = {}, onError, onSuccess, url }) => {
12
- const response = await axios_1.default.post(url, data, config)
12
+ const post = async ({ config = {}, data = {}, onError, onSuccess, returnApiResponse, url }) => {
13
+ let response = await axios_1.default.post(url, data, config)
13
14
  .then(async (response) => {
14
15
  if (200 === response.status) {
15
16
  // Is an API request
@@ -42,6 +43,10 @@ const post = async ({ config = {}, data = {}, onError, onSuccess, url }) => {
42
43
  throw Error;
43
44
  }
44
45
  });
46
+ // Convert the response into an ApiResponse instance
47
+ if (returnApiResponse) {
48
+ response = new ApiResponse_1.default(response);
49
+ }
45
50
  return response;
46
51
  };
47
52
  exports.default = post;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "1.1.103",
4
+ "version": "1.1.105",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"