@8ms/helpers 1.2.3 → 1.2.5

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.
package/package.json CHANGED
@@ -1,47 +1,48 @@
1
1
  {
2
- "name": "@8ms/helpers",
3
- "license": "UNLICENSED",
4
- "version": "1.2.3",
5
- "repository": {
6
- "type": "git",
7
- "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
8
- },
9
- "main": "index.js",
10
- "types": "index.d.ts",
11
- "scripts": {
12
- "build": "tsc",
13
- "jest": "jest --watch"
14
- },
15
- "dependencies": {
16
- "axios": "1.1.3",
17
- "crypto-js": "4.1.1",
18
- "date-fns": "2.29.3",
19
- "date-fns-tz": "1.3.7",
20
- "lodash": "4.17.21"
21
- },
22
- "devDependencies": {
23
- "@aws-sdk/client-s3": "3.211.0",
24
- "@aws-sdk/client-ses": "3.211.0",
25
- "@aws-sdk/client-sqs": "3.211.0",
26
- "@aws-sdk/client-ssm": "3.211.0",
27
- "@aws-sdk/s3-request-presigner": "3.211.0",
28
- "@babel/preset-env": "7.20.2",
29
- "@babel/preset-flow": "7.18.6",
30
- "@babel/preset-typescript": "7.18.6",
31
- "@google-cloud/bigquery": "6.0.3",
32
- "@google-cloud/storage": "6.7.0",
33
- "@prisma/client": "4.6.1",
34
- "@types/jest": "29.2.3",
35
- "@types/lodash": "4.14.189",
36
- "@types/node": "18.11.9",
37
- "babel-jest": "29.3.1",
38
- "jest": "29.3.1",
39
- "node-fetch": "3.3.0",
40
- "numbro": "2.3.6",
41
- "prisma-query-log": "3.2.0",
42
- "timezone-mock": "1.3.4",
43
- "ts-node": "10.9.1",
44
- "tslib": "2.4.1",
45
- "typescript": "4.9.3"
46
- }
2
+ "name": "@8ms/helpers",
3
+ "license": "UNLICENSED",
4
+ "version": "1.2.5",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
8
+ },
9
+ "main": "index.js",
10
+ "types": "index.d.ts",
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "jest": "jest --watch"
14
+ },
15
+ "dependencies": {
16
+ "axios": "1.2.5",
17
+ "crypto-js": "4.1.1",
18
+ "date-fns": "2.29.3",
19
+ "date-fns-tz": "1.3.7",
20
+ "lodash": "4.17.21",
21
+ "zod": "3.20.2"
22
+ },
23
+ "devDependencies": {
24
+ "@aws-sdk/client-s3": "3.258.0",
25
+ "@aws-sdk/client-ses": "3.258.0",
26
+ "@aws-sdk/client-sqs": "3.258.0",
27
+ "@aws-sdk/client-ssm": "3.258.0",
28
+ "@aws-sdk/s3-request-presigner": "3.258.0",
29
+ "@babel/preset-env": "7.20.2",
30
+ "@babel/preset-flow": "7.18.6",
31
+ "@babel/preset-typescript": "7.18.6",
32
+ "@google-cloud/bigquery": "6.0.3",
33
+ "@google-cloud/storage": "6.9.1",
34
+ "@prisma/client": "4.9.0",
35
+ "@types/jest": "29.4.0",
36
+ "@types/lodash": "4.14.191",
37
+ "@types/node": "18.11.18",
38
+ "babel-jest": "29.4.1",
39
+ "jest": "29.4.1",
40
+ "node-fetch": "3.3.0",
41
+ "numbro": "2.3.6",
42
+ "prisma-query-log": "3.2.0",
43
+ "timezone-mock": "1.3.6",
44
+ "ts-node": "10.9.1",
45
+ "tslib": "2.4.1",
46
+ "typescript": "4.9.4"
47
+ }
47
48
  }
package/swr/isData.js CHANGED
@@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  /**
4
4
  * Check to see if a single SWR has an error.
5
5
  */
6
- const isData = ({ swr }) => undefined !== swr.fetcher.data && 'undefined' !== swr.fetcher.data;
6
+ const isData = ({ swr }) => undefined !== swr.data && 'undefined' !== swr.data;
7
7
  exports.default = isData;
package/swr/isError.js CHANGED
@@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  /**
4
4
  * Check to see if a single SWR has an error.
5
5
  */
6
- const isError = ({ swr }) => undefined !== swr.fetcher.error;
6
+ const isError = ({ swr }) => undefined !== swr.error;
7
7
  exports.default = isError;
@@ -0,0 +1,12 @@
1
+ type SaveUrlContents = {
2
+ fileName: string;
3
+ path?: string;
4
+ url: string;
5
+ };
6
+ /**
7
+ * Downloads a given URL's contents to a local file.
8
+ *
9
+ * Requires fs-extra
10
+ */
11
+ declare const saveUrlContents: ({ fileName, path, url }: SaveUrlContents) => Promise<unknown>;
12
+ export default saveUrlContents;
@@ -0,0 +1,35 @@
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 axios_1 = __importDefault(require("axios"));
7
+ /**
8
+ * Downloads a given URL's contents to a local file.
9
+ *
10
+ * Requires fs-extra
11
+ */
12
+ const saveUrlContents = ({ fileName, path, url }) => {
13
+ const fs = require('fs-extra');
14
+ let finalPath = path ? path : '/tmp';
15
+ // Must begin with slash
16
+ if ('/' !== finalPath[0]) {
17
+ finalPath = '/' + finalPath;
18
+ }
19
+ // Must end without slash
20
+ if ('/' === finalPath[finalPath.length - 1]) {
21
+ finalPath = finalPath.substring(0, finalPath.length - 2);
22
+ }
23
+ return new Promise(async (resolve, reject) => {
24
+ (0, axios_1.default)({
25
+ method: "get",
26
+ url,
27
+ responseType: "stream"
28
+ })
29
+ .then(function (response) {
30
+ response.data.pipe(fs.createWriteStream(`${finalPath}/${fileName}`));
31
+ resolve(true);
32
+ });
33
+ });
34
+ };
35
+ exports.default = saveUrlContents;