@sdflc/backend-helpers 1.0.48 → 1.0.51
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/build/BaseController.js +21 -62
- package/build/BaseCore.d.ts +2 -2
- package/build/BaseCore.js +425 -690
- package/build/BaseGateway.js +358 -554
- package/build/DataCache.d.ts +1 -1
- package/build/DataCache.js +55 -104
- package/build/Database.js +104 -177
- package/build/DbMigratorAndSeeder.js +131 -238
- package/build/RedisDataLoader.d.ts +41 -0
- package/build/RedisDataLoader.js +248 -0
- package/build/apiContext.js +103 -191
- package/build/checkItHelpers.js +10 -10
- package/build/commonValidators.js +49 -91
- package/build/configBulder.js +8 -19
- package/build/constants.js +3 -3
- package/build/dbHelpers.js +72 -126
- package/build/dbSeeder.js +38 -90
- package/build/dbTableHelpers.js +25 -26
- package/build/interfaces/BaseGatewayPropsInterface.d.ts +1 -0
- package/build/interfaces/CoreActionInterface.d.ts +2 -1
- package/build/knexConfigBuilder.js +17 -28
- package/build/passwordHelpers.js +13 -59
- package/build/redisClient.d.ts +6 -0
- package/build/redisClient.js +87 -88
- package/build/resolversHelpers.js +17 -27
- package/build/userToken.js +24 -24
- package/build/utils.js +4 -5
- package/package.json +33 -34
package/build/userToken.js
CHANGED
|
@@ -4,44 +4,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.verifyUserToken = exports.createUserToken = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
+
const api_helpers_1 = require("@sdflc/api-helpers");
|
|
9
|
+
const createUserToken = (params, secret, opt) => {
|
|
10
|
+
const { algorithm, audience, issuer, jwtid, subject, noTimestamp, header, keyid, expiresIn } = opt || {};
|
|
11
11
|
if (!params || !secret) {
|
|
12
12
|
return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED, null, 'Failed to create user JWT');
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
const token = jsonwebtoken_1.default.sign(params, secret, {
|
|
15
15
|
algorithm: algorithm || 'HS256',
|
|
16
|
-
audience
|
|
17
|
-
issuer
|
|
18
|
-
jwtid
|
|
19
|
-
subject
|
|
20
|
-
noTimestamp
|
|
21
|
-
header
|
|
22
|
-
keyid
|
|
16
|
+
audience,
|
|
17
|
+
issuer,
|
|
18
|
+
jwtid,
|
|
19
|
+
subject,
|
|
20
|
+
noTimestamp,
|
|
21
|
+
header,
|
|
22
|
+
keyid,
|
|
23
23
|
expiresIn: expiresIn && !isNaN(expiresIn) ? expiresIn : undefined,
|
|
24
24
|
});
|
|
25
25
|
return api_helpers_1.OpResult.ok(token);
|
|
26
26
|
};
|
|
27
27
|
exports.createUserToken = createUserToken;
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const verifyUserToken = (token, secret, args) => {
|
|
29
|
+
const { algorithms, audience, issuer, ignoreExpiration, ignoreNotBefore, subject, clockTolerance, maxAge, clockTimestamp, nonce, } = args || {};
|
|
30
30
|
if (!args) {
|
|
31
31
|
return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED, null, 'Cannot verify user token as there are no parameters specified');
|
|
32
32
|
}
|
|
33
33
|
try {
|
|
34
|
-
|
|
34
|
+
const obj = jsonwebtoken_1.default.verify(token, secret, {
|
|
35
35
|
algorithms: algorithms || ['HS256'],
|
|
36
|
-
audience
|
|
37
|
-
issuer
|
|
38
|
-
ignoreExpiration
|
|
39
|
-
ignoreNotBefore
|
|
40
|
-
subject
|
|
41
|
-
clockTolerance
|
|
42
|
-
maxAge
|
|
43
|
-
clockTimestamp
|
|
44
|
-
nonce
|
|
36
|
+
audience,
|
|
37
|
+
issuer,
|
|
38
|
+
ignoreExpiration,
|
|
39
|
+
ignoreNotBefore,
|
|
40
|
+
subject,
|
|
41
|
+
clockTolerance,
|
|
42
|
+
maxAge,
|
|
43
|
+
clockTimestamp,
|
|
44
|
+
nonce,
|
|
45
45
|
});
|
|
46
46
|
return api_helpers_1.OpResult.ok(obj);
|
|
47
47
|
}
|
package/build/utils.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setFunctions = exports.setFunction = void 0;
|
|
4
|
-
|
|
4
|
+
const setFunction = (func, defaultFunc) => {
|
|
5
5
|
return typeof func === 'function' ? func : defaultFunc;
|
|
6
6
|
};
|
|
7
7
|
exports.setFunction = setFunction;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return keys.reduce(function (acc, key) {
|
|
8
|
+
const setFunctions = (obj, defaultFuncs = {}) => {
|
|
9
|
+
const keys = Object.keys(defaultFuncs || {});
|
|
10
|
+
return keys.reduce((acc, key) => {
|
|
12
11
|
if (typeof obj[key] === 'function') {
|
|
13
12
|
acc[key] = obj[key];
|
|
14
13
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdflc/backend-helpers",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.51",
|
|
4
4
|
"description": "Set of helper functions and classes to simplify building backend apps within @sdflc ecosystem",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -22,47 +22,46 @@
|
|
|
22
22
|
},
|
|
23
23
|
"author": "Sergey Demidenko",
|
|
24
24
|
"license": "ISC",
|
|
25
|
-
"devDependencies": {
|
|
26
|
-
"@types/bcrypt": "^5.0.0",
|
|
27
|
-
"@types/bluebird": "^3.5.36",
|
|
28
|
-
"@types/dotenv-safe": "^8.1.2",
|
|
29
|
-
"@types/jest": "^26.0.24",
|
|
30
|
-
"@types/jsonwebtoken": "^8.5.8",
|
|
31
|
-
"@types/lodash": "^4.14.179",
|
|
32
|
-
"@types/node": "^14.18.12",
|
|
33
|
-
"@types/redis": "^2.8.32",
|
|
34
|
-
"@types/uuid": "^8.3.4",
|
|
35
|
-
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
36
|
-
"@typescript-eslint/parser": "^4.33.0",
|
|
37
|
-
"eslint": "^7.32.0",
|
|
38
|
-
"eslint-config-prettier": "^6.15.0",
|
|
39
|
-
"eslint-plugin-jest": "^24.7.0",
|
|
40
|
-
"eslint-plugin-prettier": "^3.4.1",
|
|
41
|
-
"eslint-plugin-react": "^7.29.1",
|
|
42
|
-
"husky": "^6.0.0",
|
|
43
|
-
"jest": "^26.6.3",
|
|
44
|
-
"prettier": "^2.5.1",
|
|
45
|
-
"rimraf": "^3.0.2",
|
|
46
|
-
"run-script-os": "^1.1.3",
|
|
47
|
-
"ts-jest": "^26.4.4",
|
|
48
|
-
"ts-node": "^9.0.0",
|
|
49
|
-
"typescript": "^4.5.5"
|
|
50
|
-
},
|
|
51
25
|
"dependencies": {
|
|
52
|
-
"@sdflc/api-helpers": "^1.1.
|
|
53
|
-
"@sdflc/utils": "^1.0.
|
|
26
|
+
"@sdflc/api-helpers": "^1.1.9",
|
|
27
|
+
"@sdflc/utils": "^1.0.20",
|
|
54
28
|
"bcrypt": "^5.0.1",
|
|
55
29
|
"bluebird": "^3.7.2",
|
|
56
30
|
"checkit": "^0.7.0",
|
|
57
31
|
"dataloader": "^2.0.0",
|
|
58
|
-
"dayjs": "^1.
|
|
32
|
+
"dayjs": "^1.11.0",
|
|
59
33
|
"dotenv-safe": "^8.2.0",
|
|
34
|
+
"jest": "^27.5.1",
|
|
35
|
+
"json-stable-stringify": "^1.0.1",
|
|
60
36
|
"jsonwebtoken": "^8.5.1",
|
|
61
|
-
"knex": "^0.
|
|
62
|
-
"lodash": "^4.17.
|
|
37
|
+
"knex": "^1.0.5",
|
|
38
|
+
"lodash": "^4.17.21",
|
|
63
39
|
"pg": "^8.7.3",
|
|
64
|
-
"redis": "^
|
|
65
|
-
"
|
|
40
|
+
"redis": "^4.0.6",
|
|
41
|
+
"rimraf": "^3.0.2",
|
|
42
|
+
"typescript": "^4.6.3",
|
|
66
43
|
"uuid": "^8.3.2"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/bcrypt": "^5.0.0",
|
|
47
|
+
"@types/bluebird": "^3.5.36",
|
|
48
|
+
"@types/dotenv-safe": "^8.1.2",
|
|
49
|
+
"@types/json-stable-stringify": "^1.0.34",
|
|
50
|
+
"@types/jsonwebtoken": "^8.5.8",
|
|
51
|
+
"@types/lodash": "^4.14.181",
|
|
52
|
+
"@types/node": "^14.18.12",
|
|
53
|
+
"@types/redis": "^4.0.11",
|
|
54
|
+
"@types/uuid": "^8.3.4",
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "^5.19.0",
|
|
56
|
+
"@typescript-eslint/parser": "^5.19.0",
|
|
57
|
+
"eslint": "^8.13.0",
|
|
58
|
+
"eslint-config-prettier": "^8.5.0",
|
|
59
|
+
"eslint-plugin-jest": "^24.7.0",
|
|
60
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
61
|
+
"husky": "^7.0.4",
|
|
62
|
+
"prettier": "^2.6.2",
|
|
63
|
+
"run-script-os": "^1.1.6",
|
|
64
|
+
"ts-jest": "^27.1.4",
|
|
65
|
+
"ts-node": "^10.7.0"
|
|
67
66
|
}
|
|
68
67
|
}
|