@8ms/helpers 1.1.8 → 1.1.9

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,18 +2,30 @@ declare class BaseClass {
2
2
  /**
3
3
  * Shortcut to set a value to an array and return the instance.
4
4
  */
5
- protected _setArray(value: any | any[], ...fields: string[]): this;
5
+ protected _setArray({ input, fields }: {
6
+ input: any | any[];
7
+ fields: any | any[];
8
+ }): this;
6
9
  /**
7
10
  * Shortcut to set a value and return the instance.
8
11
  */
9
- protected _setValue(value: any, ...fields: any[]): this;
12
+ protected _setValue({ input, fields }: {
13
+ input: any;
14
+ fields: any | any[];
15
+ }): this;
10
16
  /**
11
17
  * Shortcut to add a value to an existing array.
12
18
  */
13
- protected _push(value: any | any[], ...fields: any[]): this;
19
+ protected _push({ input, fields }: {
20
+ input: any | any[];
21
+ fields: any | any[];
22
+ }): this;
14
23
  /**
15
24
  * Shortcut to get a value, but default if the fields don't exist.
16
25
  */
17
- protected _get(defaultValue: any, ...fields: any[]): any;
26
+ protected _get({ defaultValue, fields }: {
27
+ defaultValue: any;
28
+ fields: any | any[];
29
+ }): any;
18
30
  }
19
31
  export default BaseClass;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
- if (ar || !(i in from)) {
5
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
- ar[i] = from[i];
7
- }
8
- }
9
- return to.concat(ar || Array.prototype.slice.call(from));
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -21,44 +12,35 @@ var BaseClass = /** @class */ (function () {
21
12
  /**
22
13
  * Shortcut to set a value to an array and return the instance.
23
14
  */
24
- BaseClass.prototype._setArray = function (value) {
25
- var fields = [];
26
- for (var _i = 1; _i < arguments.length; _i++) {
27
- fields[_i - 1] = arguments[_i];
28
- }
29
- if ((0, isArray_1.default)(value)) {
30
- (0, set_1.default)(this, fields, value);
15
+ BaseClass.prototype._setArray = function (_a) {
16
+ var input = _a.input, fields = _a.fields;
17
+ if ((0, isArray_1.default)(input)) {
18
+ (0, set_1.default)(this, fields, input);
31
19
  }
32
20
  else {
33
- (0, set_1.default)(this, fields, [value]);
21
+ (0, set_1.default)(this, fields, [input]);
34
22
  }
35
23
  return this;
36
24
  };
37
25
  /**
38
26
  * Shortcut to set a value and return the instance.
39
27
  */
40
- BaseClass.prototype._setValue = function (value) {
41
- var fields = [];
42
- for (var _i = 1; _i < arguments.length; _i++) {
43
- fields[_i - 1] = arguments[_i];
44
- }
45
- (0, set_1.default)(this, fields, value);
28
+ BaseClass.prototype._setValue = function (_a) {
29
+ var input = _a.input, fields = _a.fields;
30
+ (0, set_1.default)(this, fields, input);
46
31
  return this;
47
32
  };
48
33
  /**
49
34
  * Shortcut to add a value to an existing array.
50
35
  */
51
- BaseClass.prototype._push = function (value) {
52
- var fields = [];
53
- for (var _i = 1; _i < arguments.length; _i++) {
54
- fields[_i - 1] = arguments[_i];
55
- }
56
- var temp = this._get.apply(this, __spreadArray([[]], fields, false));
57
- if ((0, isArray_1.default)(value)) {
58
- temp = temp.concat(value);
36
+ BaseClass.prototype._push = function (_a) {
37
+ var input = _a.input, fields = _a.fields;
38
+ var temp = this._get({ defaultValue: [], fields: fields });
39
+ if ((0, isArray_1.default)(input)) {
40
+ temp = temp.concat(input);
59
41
  }
60
42
  else {
61
- temp = temp.push(value);
43
+ temp = temp.push(input);
62
44
  }
63
45
  (0, set_1.default)(this, fields, temp);
64
46
  return this;
@@ -66,11 +48,8 @@ var BaseClass = /** @class */ (function () {
66
48
  /**
67
49
  * Shortcut to get a value, but default if the fields don't exist.
68
50
  */
69
- BaseClass.prototype._get = function (defaultValue) {
70
- var fields = [];
71
- for (var _i = 1; _i < arguments.length; _i++) {
72
- fields[_i - 1] = arguments[_i];
73
- }
51
+ BaseClass.prototype._get = function (_a) {
52
+ var defaultValue = _a.defaultValue, fields = _a.fields;
74
53
  return (0, defaultTo_1.default)({ defaultValue: defaultValue, instance: this, keys: fields });
75
54
  };
76
55
  return BaseClass;
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Iteratively delete all the files within a directory and delete the directory.
3
3
  */
4
- declare const deleteDirectory: ({ S3Lib, bucket, client, folder }: {
4
+ declare const deleteFolder: ({ S3Lib, bucket, client, folder }: {
5
5
  S3Lib: any;
6
6
  bucket: string;
7
7
  client: any;
8
8
  folder: string;
9
9
  }) => Promise<void>;
10
- export default deleteDirectory;
10
+ export default deleteFolder;
@@ -40,7 +40,7 @@ var string_1 = require("../../string");
40
40
  /**
41
41
  * Iteratively delete all the files within a directory and delete the directory.
42
42
  */
43
- var deleteDirectory = function (_a) {
43
+ var deleteFolder = function (_a) {
44
44
  var S3Lib = _a.S3Lib, bucket = _a.bucket, client = _a.client, folder = _a.folder;
45
45
  return __awaiter(void 0, void 0, void 0, function () {
46
46
  var cleanFolder, ListObjectsV2Command, DeleteObjectsCommand, apiResponse, keys;
@@ -71,7 +71,7 @@ var deleteDirectory = function (_a) {
71
71
  // Delete the files
72
72
  _b.sent();
73
73
  if (!apiResponse.IsTruncated) return [3 /*break*/, 4];
74
- return [4 /*yield*/, deleteDirectory({ S3Lib: S3Lib, bucket: bucket, client: client, folder: folder })];
74
+ return [4 /*yield*/, deleteFolder({ S3Lib: S3Lib, bucket: bucket, client: client, folder: folder })];
75
75
  case 3:
76
76
  _b.sent();
77
77
  _b.label = 4;
@@ -80,4 +80,4 @@ var deleteDirectory = function (_a) {
80
80
  });
81
81
  });
82
82
  };
83
- exports.default = deleteDirectory;
83
+ exports.default = deleteFolder;
@@ -1,16 +1,15 @@
1
- import deleteDirectory from './deleteDirectory';
2
1
  import deleteFile from './deleteFile';
3
2
  import deleteFiles from './deleteFiles';
3
+ import deleteFolder from './deleteFolder';
4
4
  import getClient from './getClient';
5
5
  import getPresignedPost from './getPresignedPost';
6
6
  import getSignedUrl from './getSignedUrl';
7
7
  import listFiles from './listFiles';
8
8
  import listFolders from './listFolders';
9
- import readBuffer from './readBuffer';
10
- import readFile from './readFile';
11
- import { ReadBufferType, ReadFileType, ReadType } from './types';
9
+ import readBuffer, { ReadBufferType } from './readBuffer';
10
+ import readFile, { ReadFileType, ReadType } from './readFile';
12
11
  import writeFile from './writeFile';
13
12
  import writeGlueJsonFile from './writeGlueJsonFile';
14
13
  import writePresignedPost from './writePresignedPost';
15
14
  export type { ReadType, ReadBufferType, ReadFileType, };
16
- export { deleteDirectory, deleteFile, deleteFiles, getClient, getPresignedPost, getSignedUrl, listFiles, listFolders, readBuffer, readFile, writeFile, writeGlueJsonFile, writePresignedPost, };
15
+ export { deleteFolder, deleteFile, deleteFiles, getClient, getPresignedPost, getSignedUrl, listFiles, listFolders, readBuffer, readFile, writeFile, writeGlueJsonFile, writePresignedPost, };
@@ -3,13 +3,13 @@ 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
- exports.writePresignedPost = exports.writeGlueJsonFile = exports.writeFile = exports.readFile = exports.readBuffer = exports.listFolders = exports.listFiles = exports.getSignedUrl = exports.getPresignedPost = exports.getClient = exports.deleteFiles = exports.deleteFile = exports.deleteDirectory = void 0;
7
- var deleteDirectory_1 = __importDefault(require("./deleteDirectory"));
8
- exports.deleteDirectory = deleteDirectory_1.default;
6
+ exports.writePresignedPost = exports.writeGlueJsonFile = exports.writeFile = exports.readFile = exports.readBuffer = exports.listFolders = exports.listFiles = exports.getSignedUrl = exports.getPresignedPost = exports.getClient = exports.deleteFiles = exports.deleteFile = exports.deleteFolder = void 0;
9
7
  var deleteFile_1 = __importDefault(require("./deleteFile"));
10
8
  exports.deleteFile = deleteFile_1.default;
11
9
  var deleteFiles_1 = __importDefault(require("./deleteFiles"));
12
10
  exports.deleteFiles = deleteFiles_1.default;
11
+ var deleteFolder_1 = __importDefault(require("./deleteFolder"));
12
+ exports.deleteFolder = deleteFolder_1.default;
13
13
  var getClient_1 = __importDefault(require("./getClient"));
14
14
  exports.getClient = getClient_1.default;
15
15
  var getPresignedPost_1 = __importDefault(require("./getPresignedPost"));
@@ -1,4 +1,7 @@
1
- import { ReadBufferType } from './types';
1
+ import { ReadType } from './readFile';
2
+ export declare type ReadBufferType = ReadType & {
3
+ buffer: any;
4
+ };
2
5
  /**
3
6
  * Similar function to reading the S3 file, but instead of a text file return a buffer.
4
7
  */
@@ -1,4 +1,22 @@
1
- import { ReadFileType } from './types';
1
+ export declare type ReadType = {
2
+ now: number;
3
+ modified: {
4
+ unix: null | number;
5
+ vsNow: {
6
+ months: number;
7
+ days: number;
8
+ hours: number;
9
+ minutes: number;
10
+ };
11
+ vsMidnight: {
12
+ hours: number;
13
+ minutes: number;
14
+ };
15
+ };
16
+ };
17
+ export declare type ReadFileType = ReadType & {
18
+ body: any;
19
+ };
2
20
  /**
3
21
  * Read a file from S3 and return either null, the content or JSON decoded.
4
22
  */
@@ -105,39 +105,39 @@ var SimpleEmail = /** @class */ (function (_super) {
105
105
  }
106
106
  SimpleEmail.prototype.setFrom = function (_a) {
107
107
  var from = _a.from;
108
- return this._setValue(from, 'from');
108
+ return this._setValue({ input: from, fields: 'from' });
109
109
  };
110
110
  SimpleEmail.prototype.setHtml = function (_a) {
111
111
  var html = _a.html;
112
- return this._setValue(html, 'html');
112
+ return this._setValue({ input: html, fields: 'html' });
113
113
  };
114
114
  SimpleEmail.prototype.setSubject = function (_a) {
115
115
  var subject = _a.subject;
116
- return this._setValue(subject, 'subject');
116
+ return this._setValue({ input: subject, fields: 'subject' });
117
117
  };
118
118
  SimpleEmail.prototype.pushBcc = function (_a) {
119
119
  var recipient = _a.recipient;
120
- return this._push(recipient, 'bcc');
120
+ return this._push({ input: recipient, fields: 'bcc' });
121
121
  };
122
122
  SimpleEmail.prototype.pushCc = function (_a) {
123
123
  var recipient = _a.recipient;
124
- return this._push(recipient, 'cc');
124
+ return this._push({ input: recipient, fields: 'cc' });
125
125
  };
126
126
  SimpleEmail.prototype.pushTo = function (_a) {
127
127
  var recipient = _a.recipient;
128
- return this._push(recipient, 'to');
128
+ return this._push({ input: recipient, fields: 'to' });
129
129
  };
130
130
  SimpleEmail.prototype.setBcc = function (_a) {
131
131
  var recipient = _a.recipient;
132
- return this._setArray(recipient, 'bcc');
132
+ return this._setArray({ input: recipient, fields: 'bcc' });
133
133
  };
134
134
  SimpleEmail.prototype.setCc = function (_a) {
135
135
  var recipient = _a.recipient;
136
- return this._setArray(recipient, 'cc');
136
+ return this._setArray({ input: recipient, fields: 'cc' });
137
137
  };
138
138
  SimpleEmail.prototype.setTo = function (_a) {
139
139
  var recipient = _a.recipient;
140
- return this._setArray(recipient, 'to');
140
+ return this._setArray({ input: recipient, fields: 'to' });
141
141
  };
142
142
  SimpleEmail.prototype.send = function (_a) {
143
143
  var SesLib = _a.SesLib, client = _a.client;
@@ -1,5 +1,7 @@
1
1
  /**
2
2
  * Convert an input from a variety of forms into boolean.
3
3
  */
4
- declare const getBoolean: (input: any) => boolean;
4
+ declare const getBoolean: ({ input }: {
5
+ input: any;
6
+ }) => boolean;
5
7
  export default getBoolean;
@@ -7,7 +7,8 @@ var isBoolean_1 = __importDefault(require("lodash/isBoolean"));
7
7
  /**
8
8
  * Convert an input from a variety of forms into boolean.
9
9
  */
10
- var getBoolean = function (input) {
10
+ var getBoolean = function (_a) {
11
+ var input = _a.input;
11
12
  if ((0, isBoolean_1.default)(input)) {
12
13
  return input;
13
14
  }
@@ -2,10 +2,10 @@
2
2
  * Decrypt an encoding string using a salt
3
3
  * Library: crypto-js
4
4
  */
5
- declare const getDecrypt: ({ CryptoLib, appSalt, salt, value }: {
5
+ declare const getDecrypt: ({ CryptoLib, appSalt, input, salt }: {
6
6
  CryptoLib: any;
7
- value: string;
8
- salt: string;
9
7
  appSalt: string;
8
+ input: string;
9
+ salt: string;
10
10
  }) => string;
11
11
  export default getDecrypt;
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
5
5
  * Library: crypto-js
6
6
  */
7
7
  var getDecrypt = function (_a) {
8
- var CryptoLib = _a.CryptoLib, appSalt = _a.appSalt, salt = _a.salt, value = _a.value;
8
+ var CryptoLib = _a.CryptoLib, appSalt = _a.appSalt, input = _a.input, salt = _a.salt;
9
9
  var customSalt = "".concat(appSalt, "-").concat(salt);
10
- return CryptoLib.AES.decrypt(value, customSalt)
10
+ return CryptoLib.AES.decrypt(input, customSalt)
11
11
  .toString(CryptoLib.enc.Utf8);
12
12
  };
13
13
  exports.default = getDecrypt;
@@ -2,10 +2,10 @@
2
2
  * Encrypt an encoding string using a salt
3
3
  * Library: crypto-js
4
4
  */
5
- declare const getEncrypt: ({ CryptoLib, appSalt, salt, value }: {
5
+ declare const getEncrypt: ({ CryptoLib, appSalt, input, salt }: {
6
6
  CryptoLib: any;
7
- value: string;
8
- salt: string;
9
7
  appSalt: string;
8
+ input: string;
9
+ salt: string;
10
10
  }) => string;
11
11
  export default getEncrypt;
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
5
5
  * Library: crypto-js
6
6
  */
7
7
  var getEncrypt = function (_a) {
8
- var CryptoLib = _a.CryptoLib, appSalt = _a.appSalt, salt = _a.salt, value = _a.value;
8
+ var CryptoLib = _a.CryptoLib, appSalt = _a.appSalt, input = _a.input, salt = _a.salt;
9
9
  var customSalt = "".concat(appSalt, "-").concat(salt);
10
- return CryptoLib.AES.encrypt(value, customSalt)
10
+ return CryptoLib.AES.encrypt(input, customSalt)
11
11
  .toString();
12
12
  };
13
13
  exports.default = getEncrypt;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
@@ -1,22 +0,0 @@
1
- export declare type ReadType = {
2
- now: number;
3
- modified: {
4
- unix: null | number;
5
- vsNow: {
6
- months: number;
7
- days: number;
8
- hours: number;
9
- minutes: number;
10
- };
11
- vsMidnight: {
12
- hours: number;
13
- minutes: number;
14
- };
15
- };
16
- };
17
- export declare type ReadBufferType = ReadType & {
18
- buffer: any;
19
- };
20
- export declare type ReadFileType = ReadType & {
21
- body: any;
22
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });