@8ms/helpers 1.0.20 → 1.0.23
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/dist/array/tests/contains.test.d.ts +1 -0
- package/dist/array/tests/contains.test.js +18 -0
- package/dist/aws/s3/deleteDirectory.js +1 -1
- package/dist/aws/s3/listFiles.js +1 -1
- package/dist/aws/s3/listFolders.js +1 -1
- package/dist/aws/s3/readFile.js +1 -1
- package/dist/aws/ses/SimpleEmail.d.ts +1 -0
- package/dist/aws/ses/SimpleEmail.js +17 -9
- package/dist/aws/ses/getClient.js +1 -1
- package/dist/number/getNumber.d.ts +1 -1
- package/dist/number/getNumber.js +15 -4
- package/dist/number/tests/getNumber.test.d.ts +1 -0
- package/dist/number/tests/getNumber.test.js +21 -0
- package/dist/string/getCleanFolder.d.ts +3 -1
- package/dist/string/getCleanFolder.js +5 -2
- package/dist/string/getStringFromStream.d.ts +3 -1
- package/dist/string/getStringFromStream.js +2 -1
- package/dist/string/tests/getCleanFolder.test.js +1 -1
- package/dist/util/defaultTo.d.ts +3 -0
- package/dist/util/defaultTo.js +1 -1
- package/dist/util/tests/defaultTo.test.d.ts +1 -0
- package/dist/util/tests/defaultTo.test.js +27 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var index_1 = require("../index");
|
|
4
|
+
test('contains - does contain', function () {
|
|
5
|
+
var haystack = [1, 2, 3, 4];
|
|
6
|
+
expect((0, index_1.contains)({ haystack: haystack, needle: 1 }))
|
|
7
|
+
.toBeTruthy();
|
|
8
|
+
expect((0, index_1.contains)({ haystack: haystack, needle: 2 }))
|
|
9
|
+
.toBeTruthy();
|
|
10
|
+
expect((0, index_1.contains)({ haystack: haystack, needle: 3 }))
|
|
11
|
+
.toBeTruthy();
|
|
12
|
+
expect((0, index_1.contains)({ haystack: haystack, needle: 4 }))
|
|
13
|
+
.toBeTruthy();
|
|
14
|
+
});
|
|
15
|
+
test('contains - does not contain', function () {
|
|
16
|
+
expect((0, index_1.contains)({ haystack: [1, 2, 3, 4], needle: 9 }))
|
|
17
|
+
.toBeFalsy();
|
|
18
|
+
});
|
|
@@ -47,7 +47,7 @@ var deleteDirectory = function (_a) {
|
|
|
47
47
|
return __generator(this, function (_b) {
|
|
48
48
|
switch (_b.label) {
|
|
49
49
|
case 0:
|
|
50
|
-
cleanFolder = (0, string_1.getCleanFolder)(folder);
|
|
50
|
+
cleanFolder = (0, string_1.getCleanFolder)({ input: folder });
|
|
51
51
|
ListObjectsV2Command = S3Lib.ListObjectsV2Command, DeleteObjectsCommand = S3Lib.DeleteObjectsCommand;
|
|
52
52
|
return [4 /*yield*/, client.send(new ListObjectsV2Command({
|
|
53
53
|
Bucket: bucket,
|
package/dist/aws/s3/listFiles.js
CHANGED
|
@@ -47,7 +47,7 @@ var listFiles = function (_a) {
|
|
|
47
47
|
return __generator(this, function (_c) {
|
|
48
48
|
switch (_c.label) {
|
|
49
49
|
case 0:
|
|
50
|
-
cleanFolder = (0, string_1.getCleanFolder)(folder);
|
|
50
|
+
cleanFolder = (0, string_1.getCleanFolder)({ input: folder });
|
|
51
51
|
response = [];
|
|
52
52
|
valid = [];
|
|
53
53
|
ListObjectsV2Command = S3Lib.ListObjectsV2Command;
|
|
@@ -47,7 +47,7 @@ var listFolders = function (_a) {
|
|
|
47
47
|
return __generator(this, function (_c) {
|
|
48
48
|
switch (_c.label) {
|
|
49
49
|
case 0:
|
|
50
|
-
cleanFolder = (0, string_1.getCleanFolder)(folder);
|
|
50
|
+
cleanFolder = (0, string_1.getCleanFolder)({ input: folder });
|
|
51
51
|
response = [];
|
|
52
52
|
ListObjectsV2Command = S3Lib.ListObjectsV2Command;
|
|
53
53
|
return [4 /*yield*/, client.send(new ListObjectsV2Command({
|
package/dist/aws/s3/readFile.js
CHANGED
|
@@ -97,7 +97,7 @@ var readFile = function (_a) {
|
|
|
97
97
|
response.modified.vsMidnight.minutes = (0, getMinutes_1.default)(now);
|
|
98
98
|
// Convert stream into a string
|
|
99
99
|
_b = response;
|
|
100
|
-
return [4 /*yield*/, (0, string_1.getStringFromStream)(apiResponse.Body)];
|
|
100
|
+
return [4 /*yield*/, (0, string_1.getStringFromStream)({ stream: apiResponse.Body })];
|
|
101
101
|
case 2:
|
|
102
102
|
// Convert stream into a string
|
|
103
103
|
_b.body = _c.sent();
|
|
@@ -142,22 +142,17 @@ var SimpleEmail = /** @class */ (function (_super) {
|
|
|
142
142
|
SimpleEmail.prototype.send = function (_a) {
|
|
143
143
|
var SesLib = _a.SesLib, client = _a.client;
|
|
144
144
|
return __awaiter(this, void 0, void 0, function () {
|
|
145
|
-
var SendEmailCommand, response,
|
|
145
|
+
var SendEmailCommand, response, params, command, apiResponse, error_1;
|
|
146
146
|
return __generator(this, function (_b) {
|
|
147
147
|
switch (_b.label) {
|
|
148
148
|
case 0:
|
|
149
149
|
SendEmailCommand = SesLib.SendEmailCommand;
|
|
150
150
|
response = __assign({}, api_1.ApiPlaceholder);
|
|
151
|
-
clean = {
|
|
152
|
-
bcc: (0, uniq_1.default)(this.bcc.filter(function (value) { return value !== undefined && value !== null; })),
|
|
153
|
-
cc: (0, uniq_1.default)(this.cc.filter(function (value) { return value !== undefined && value !== null; })),
|
|
154
|
-
to: (0, uniq_1.default)(this.to.filter(function (value) { return value !== undefined && value !== null; })),
|
|
155
|
-
};
|
|
156
151
|
params = {
|
|
157
152
|
Destination: {
|
|
158
|
-
BccAddresses:
|
|
159
|
-
CcAddresses:
|
|
160
|
-
ToAddresses:
|
|
153
|
+
BccAddresses: this._filterRecipients({ field: 'bcc' }),
|
|
154
|
+
CcAddresses: this._filterRecipients({ field: 'cc' }),
|
|
155
|
+
ToAddresses: this._filterRecipients({ field: 'to' }),
|
|
161
156
|
},
|
|
162
157
|
Message: {
|
|
163
158
|
Body: {
|
|
@@ -204,6 +199,19 @@ var SimpleEmail = /** @class */ (function (_super) {
|
|
|
204
199
|
});
|
|
205
200
|
});
|
|
206
201
|
};
|
|
202
|
+
SimpleEmail.prototype._filterRecipients = function (_a) {
|
|
203
|
+
var field = _a.field;
|
|
204
|
+
// Remove all undefined and null values
|
|
205
|
+
var response = this[field].filter(function (recipient) { return undefined !== recipient && null !== recipient; });
|
|
206
|
+
// Clean all the values
|
|
207
|
+
response = response.map(function (recipient) { return recipient.toLowerCase()
|
|
208
|
+
.trim(); });
|
|
209
|
+
// Remove all empty values
|
|
210
|
+
response = response.filter(function (recipient) { return '' !== recipient; });
|
|
211
|
+
// Return only unique values
|
|
212
|
+
response = (0, uniq_1.default)(response);
|
|
213
|
+
return response;
|
|
214
|
+
};
|
|
207
215
|
return SimpleEmail;
|
|
208
216
|
}(Class_1.BaseClass));
|
|
209
217
|
exports.default = SimpleEmail;
|
|
@@ -14,7 +14,7 @@ var getClient = function (_a) {
|
|
|
14
14
|
if (!global.awsSesClient) {
|
|
15
15
|
var SESClient = SesLib.SESClient;
|
|
16
16
|
var formattedConfig = (0, getConfig_1.default)({ config: config, isAthenaExpress: false });
|
|
17
|
-
global.
|
|
17
|
+
global.awsSesClient = new SESClient(formattedConfig);
|
|
18
18
|
}
|
|
19
19
|
sesClient = global.awsSesClient;
|
|
20
20
|
return sesClient;
|
package/dist/number/getNumber.js
CHANGED
|
@@ -5,15 +5,26 @@ var json_1 = require("../json");
|
|
|
5
5
|
* Take an input and return a number.
|
|
6
6
|
*/
|
|
7
7
|
var getNumber = function (_a) {
|
|
8
|
-
var _b = _a === void 0 ?
|
|
8
|
+
var _b = _a.defaultValue, defaultValue = _b === void 0 ? 0 : _b, _c = _a.input, input = _c === void 0 ? '' : _c;
|
|
9
9
|
var actualDefaultValue = defaultValue || 0;
|
|
10
|
-
var response;
|
|
10
|
+
var response = input;
|
|
11
11
|
// JSON - Decode the value
|
|
12
12
|
if ((0, json_1.isJson)({ input: input })) {
|
|
13
|
-
|
|
13
|
+
// Only parse this if it's a string
|
|
14
|
+
if ('string' === typeof input) {
|
|
15
|
+
response = JSON.parse(input);
|
|
16
|
+
}
|
|
17
|
+
// Already decoded
|
|
18
|
+
else {
|
|
19
|
+
response = input;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// Already a number
|
|
23
|
+
if ('number' === typeof response) {
|
|
24
|
+
response = response;
|
|
14
25
|
}
|
|
15
26
|
// String input
|
|
16
|
-
if ('string' === typeof response) {
|
|
27
|
+
else if ('string' === typeof response) {
|
|
17
28
|
// Attempt to convert to number
|
|
18
29
|
response = Number(response);
|
|
19
30
|
// Not a number, try extracting the number value
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var index_1 = require("../index");
|
|
4
|
+
test('getNumber - should be number', function () {
|
|
5
|
+
expect((0, index_1.getNumber)({ defaultValue: 10, input: 99 }))
|
|
6
|
+
.toBe(99);
|
|
7
|
+
expect((0, index_1.getNumber)({ defaultValue: 10, input: '99' }))
|
|
8
|
+
.toBe(99);
|
|
9
|
+
expect((0, index_1.getNumber)({ defaultValue: 10, input: 5 * 25 }))
|
|
10
|
+
.toBe(125);
|
|
11
|
+
expect((0, index_1.getNumber)({ defaultValue: 10, input: '_50' }))
|
|
12
|
+
.toBe(50);
|
|
13
|
+
expect((0, index_1.getNumber)({ defaultValue: 10, input: '33.3232%' }))
|
|
14
|
+
.toBe(33.3232);
|
|
15
|
+
});
|
|
16
|
+
test('getNumber - revert to default', function () {
|
|
17
|
+
expect((0, index_1.getNumber)({ defaultValue: 10, input: {} }))
|
|
18
|
+
.toBe(10);
|
|
19
|
+
expect((0, index_1.getNumber)({ input: {} }))
|
|
20
|
+
.toBe(0);
|
|
21
|
+
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Take an input that may have a / before or after the input and return just the folder.
|
|
3
3
|
*/
|
|
4
|
-
declare const getCleanFolder: (input:
|
|
4
|
+
declare const getCleanFolder: ({ input }: {
|
|
5
|
+
input: string;
|
|
6
|
+
}) => string;
|
|
5
7
|
export default getCleanFolder;
|
|
@@ -7,6 +7,9 @@ var 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
|
-
var getCleanFolder = function (
|
|
11
|
-
.
|
|
10
|
+
var getCleanFolder = function (_a) {
|
|
11
|
+
var input = _a.input;
|
|
12
|
+
return (0, trim_1.default)(input, '/')
|
|
13
|
+
.trim();
|
|
14
|
+
};
|
|
12
15
|
exports.default = getCleanFolder;
|
|
@@ -2,5 +2,7 @@
|
|
|
2
2
|
* Converts a stream into a string.
|
|
3
3
|
* https://stackoverflow.com/a/49428486
|
|
4
4
|
*/
|
|
5
|
-
declare const getStringFromStream: (stream:
|
|
5
|
+
declare const getStringFromStream: ({ stream }: {
|
|
6
|
+
stream: any;
|
|
7
|
+
}) => Promise<string>;
|
|
6
8
|
export default getStringFromStream;
|
|
@@ -4,7 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
* Converts a stream into a string.
|
|
5
5
|
* https://stackoverflow.com/a/49428486
|
|
6
6
|
*/
|
|
7
|
-
var getStringFromStream = function (
|
|
7
|
+
var getStringFromStream = function (_a) {
|
|
8
|
+
var stream = _a.stream;
|
|
8
9
|
var chunks = [];
|
|
9
10
|
return new Promise(function (resolve, reject) {
|
|
10
11
|
stream.on('data', function (chunk) { return chunks.push(Buffer.from(chunk)); });
|
package/dist/util/defaultTo.d.ts
CHANGED
package/dist/util/defaultTo.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var array_1 = require("../array");
|
|
3
4
|
/**
|
|
4
5
|
* Function to default to a value, whilst filtering through an instance
|
|
5
6
|
*/
|
|
6
|
-
var array_1 = require("../array");
|
|
7
7
|
var defaultTo = function (_a) {
|
|
8
8
|
var defaultValue = _a.defaultValue, instance = _a.instance, keys = _a.keys;
|
|
9
9
|
var keysArray = (0, array_1.getArray)({ input: keys });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var index_1 = require("../index");
|
|
4
|
+
test('defaultTo - exists', function () {
|
|
5
|
+
var instance = {
|
|
6
|
+
'something': 'a b c',
|
|
7
|
+
'level one': {
|
|
8
|
+
'level two': 'inner',
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
expect((0, index_1.defaultTo)({ defaultValue: 'not found', instance: instance, keys: 'something' }))
|
|
12
|
+
.toBe('a b c');
|
|
13
|
+
expect((0, index_1.defaultTo)({ defaultValue: 'not found', instance: instance, keys: ['level one', 'level two'] }))
|
|
14
|
+
.toBe('inner');
|
|
15
|
+
});
|
|
16
|
+
test('defaultTo - doesnt exist', function () {
|
|
17
|
+
var instance = {
|
|
18
|
+
'something': 'a b c',
|
|
19
|
+
'level one': {
|
|
20
|
+
'level two': 'inner',
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
expect((0, index_1.defaultTo)({ defaultValue: true, instance: instance, keys: 'not here' }))
|
|
24
|
+
.toBeTruthy();
|
|
25
|
+
expect((0, index_1.defaultTo)({ defaultValue: 'not found', instance: instance, keys: ['level one', 'level two', 'level three'] }))
|
|
26
|
+
.toBe('not found');
|
|
27
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@8ms/helpers",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.23",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@babel/preset-flow": "7.16.7",
|
|
25
25
|
"@babel/preset-typescript": "7.16.7",
|
|
26
26
|
"@types/jest": "27.4.1",
|
|
27
|
-
"@types/lodash": "4.14.
|
|
27
|
+
"@types/lodash": "4.14.180",
|
|
28
28
|
"@types/node": "17.0.21",
|
|
29
29
|
"babel-jest": "27.5.1",
|
|
30
30
|
"jest": "27.5.1",
|