@sdflc/backend-helpers 1.0.52 → 1.0.55
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/BaseCore.d.ts +2 -1
- package/build/BaseCore.js +15 -3
- package/build/BaseGateway.js +1 -1
- package/build/apiContext.js +6 -2
- package/build/checkItHelpers.d.ts +1 -1
- package/build/commonValidators.d.ts +6 -0
- package/build/commonValidators.js +125 -1
- package/build/configBulder.d.ts +1 -1
- package/build/dbHelpers.js +20 -0
- package/build/dbTableHelpers.d.ts +1 -1
- package/build/dbTableHelpers.js +6 -2
- package/build/index.d.ts +20 -20
- package/build/index.js +34 -62
- package/build/interfaces/ApiContextInterface.d.ts +1 -0
- package/build/interfaces/DbFieldAddDefaultInterface.d.ts +2 -0
- package/build/userToken.d.ts +2 -1
- package/build/userToken.js +11 -3
- package/package.json +25 -25
package/build/BaseCore.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { OpResult } from '@sdflc/api-helpers';
|
|
1
2
|
import { Logger, MeasureTool } from '@sdflc/utils';
|
|
2
3
|
import { Database } from './Database';
|
|
3
4
|
import { BaseCorePropsInterface, BaseCoreActionsInterface, CoreActionInterface, JwtTokenSecretAndSettings, ApiContext } from './interfaces';
|
|
@@ -13,7 +14,7 @@ declare class BaseCore {
|
|
|
13
14
|
getValidators(): any;
|
|
14
15
|
success(data: any, code?: number): any;
|
|
15
16
|
failure(code: number, errorMsg: string, data?: any): any;
|
|
16
|
-
validationFailure(ex: any): any;
|
|
17
|
+
validationFailure(ex: OpResult | any): any;
|
|
17
18
|
exceptionFailure(ex: any, doingWhat: string | any, data?: any): any;
|
|
18
19
|
checkResult(args: any): Promise<void>;
|
|
19
20
|
runAction(opt: CoreActionInterface): Promise<any>;
|
package/build/BaseCore.js
CHANGED
|
@@ -73,8 +73,20 @@ class BaseCore {
|
|
|
73
73
|
}
|
|
74
74
|
validationFailure(ex) {
|
|
75
75
|
const result = new api_helpers_1.OpResult({ code: api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED });
|
|
76
|
-
|
|
77
|
-
result.
|
|
76
|
+
if (ex instanceof api_helpers_1.OpResult) {
|
|
77
|
+
return result.toJS();
|
|
78
|
+
}
|
|
79
|
+
Object.keys((ex === null || ex === void 0 ? void 0 : ex.errors) || {}).forEach((key) => {
|
|
80
|
+
const obj = ex.errors[key];
|
|
81
|
+
if (Array.isArray(obj.errors)) {
|
|
82
|
+
// if we have multiple rules failures the add them all
|
|
83
|
+
obj.errors.forEach((item) => {
|
|
84
|
+
result.addError(key, item.message);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
result.addError(key, obj.message);
|
|
89
|
+
}
|
|
78
90
|
});
|
|
79
91
|
return result.toJS();
|
|
80
92
|
}
|
|
@@ -126,7 +138,7 @@ class BaseCore {
|
|
|
126
138
|
// this.measureTool.threadBlockTime(doingWhat, ({ name, durationMs }: any) => {
|
|
127
139
|
// this.logger.debug(`The ${name} blocked thread for the time of ${durationMs} ms`);
|
|
128
140
|
// });
|
|
129
|
-
this.logger.
|
|
141
|
+
this.logger.debug(`The ${doingWhat} started:`, args);
|
|
130
142
|
this.measureTool.start();
|
|
131
143
|
let step = doingWhat || '';
|
|
132
144
|
const setStep = (stepName) => {
|
package/build/BaseGateway.js
CHANGED
|
@@ -86,7 +86,7 @@ class BaseGateway {
|
|
|
86
86
|
const { hasStatus, hasVersion } = this.config;
|
|
87
87
|
const idName = this.getIdField();
|
|
88
88
|
if (filterParams[idName]) {
|
|
89
|
-
query.
|
|
89
|
+
query.whereIn(idName, (0, lodash_1.castArray)(filterParams[idName]));
|
|
90
90
|
}
|
|
91
91
|
if (hasVersion) {
|
|
92
92
|
if (filterParams[constants_1.FIELDS.VERSION] != null && !isNaN(filterParams[constants_1.FIELDS.VERSION])) {
|
package/build/apiContext.js
CHANGED
|
@@ -20,7 +20,7 @@ const constants_1 = require("./constants");
|
|
|
20
20
|
* @returns {object} A context object with all available cores
|
|
21
21
|
*/
|
|
22
22
|
const createApiContext = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
-
const { cores, gateways, req, getCoreContext, getGatewayContext, extendContext, requestId: inRequestId } = args || {};
|
|
23
|
+
const { cores, gateways, req, res, getCoreContext, getGatewayContext, extendContext, requestId: inRequestId, } = args || {};
|
|
24
24
|
const requestId = inRequestId || (0, uuid_1.v4)();
|
|
25
25
|
const coreContext = typeof getCoreContext === 'function' ? yield getCoreContext({ req }) : {};
|
|
26
26
|
const gatewayContext = typeof getGatewayContext === 'function' ? yield getGatewayContext({ req }) : {};
|
|
@@ -30,6 +30,7 @@ const createApiContext = (args) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
30
30
|
gateways: {},
|
|
31
31
|
usedKeyPrefixes: {},
|
|
32
32
|
req,
|
|
33
|
+
res,
|
|
33
34
|
};
|
|
34
35
|
context.cores = Object.keys(cores || {}).reduce((acc, key) => {
|
|
35
36
|
acc[(0, lodash_1.camelCase)(key)] = new cores[key](Object.assign(Object.assign({}, coreContext), { context }));
|
|
@@ -50,7 +51,7 @@ exports.createApiContext = createApiContext;
|
|
|
50
51
|
* @returns {object} A context object with all available cores
|
|
51
52
|
*/
|
|
52
53
|
const createContextDefault = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
-
const { knexConfig, isProduction, logger, doAuth, spaceGw, interserviceApiKey, jwtSecret, verifyTokenArgs, dbSchema, cores, gateways, req, extendContext, getCoreContext, getGatewayContext, } = args || {};
|
|
54
|
+
const { knexConfig, isProduction, logger, doAuth, spaceGw, interserviceApiKey, jwtSecret, verifyTokenArgs, dbSchema, cores, gateways, req, res, extendContext, getCoreContext, getGatewayContext, } = args || {};
|
|
54
55
|
const authorization = req.headers[constants_1.HEADERS.AUTHORIZATION]
|
|
55
56
|
? req.headers[constants_1.HEADERS.AUTHORIZATION].replace('Bearer ', '')
|
|
56
57
|
: undefined;
|
|
@@ -85,11 +86,14 @@ const createContextDefault = (args) => __awaiter(void 0, void 0, void 0, functio
|
|
|
85
86
|
accountId,
|
|
86
87
|
roleId,
|
|
87
88
|
userId,
|
|
89
|
+
req,
|
|
90
|
+
res,
|
|
88
91
|
};
|
|
89
92
|
return yield (0, exports.createApiContext)({
|
|
90
93
|
cores,
|
|
91
94
|
gateways,
|
|
92
95
|
req,
|
|
96
|
+
res,
|
|
93
97
|
requestId,
|
|
94
98
|
extendContext: ({ context, req }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
99
|
context.db = db;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { OpResult } from '@sdflc/api-helpers';
|
|
2
|
-
export declare const checkArray: (arr: any, validator: any, prefix?: string
|
|
2
|
+
export declare const checkArray: (arr: any, validator: any, prefix?: string) => OpResult;
|
|
3
3
|
export declare const createErrorOnCheckError: (checkItResult: any) => OpResult;
|
|
@@ -2,6 +2,12 @@ import { OpResult } from '@sdflc/api-helpers';
|
|
|
2
2
|
import { BaseCoreActionsInterface, CommonValidatorArgs } from './interfaces';
|
|
3
3
|
export declare const shouldHaveParams: (args: any) => boolean[] | OpResult[];
|
|
4
4
|
export declare const shouldHaveId: (id: any) => boolean[] | OpResult[];
|
|
5
|
+
export declare const validateSingleIntId: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
6
|
+
export declare const validateSingleUuidId: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
7
|
+
export declare const validateSingleTextId: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
8
|
+
export declare const validateMultipleIntIds: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
9
|
+
export declare const validateMultipleUuidIds: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
10
|
+
export declare const validateMultipleTextIds: (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
5
11
|
export declare const validateList: ({ rules }: CommonValidatorArgs) => (args: any, opt: BaseCoreActionsInterface) => Promise<OpResult[] | {}[]>;
|
|
6
12
|
export declare const validateCreate: ({ rules }: CommonValidatorArgs) => (args: any, opt: BaseCoreActionsInterface) => Promise<{}[] | {}[]>;
|
|
7
13
|
export declare const validateUpdate: ({ rules }: CommonValidatorArgs) => (args: any, opt: BaseCoreActionsInterface) => Promise<{}[] | {}[]>;
|
|
@@ -8,10 +8,86 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.validateUpdate = exports.validateCreate = exports.validateList = exports.shouldHaveId = exports.shouldHaveParams = void 0;
|
|
15
|
+
exports.validateUpdate = exports.validateCreate = exports.validateList = exports.validateMultipleTextIds = exports.validateMultipleUuidIds = exports.validateMultipleIntIds = exports.validateSingleTextId = exports.validateSingleUuidId = exports.validateSingleIntId = exports.shouldHaveId = exports.shouldHaveParams = void 0;
|
|
13
16
|
const api_helpers_1 = require("@sdflc/api-helpers");
|
|
14
17
|
const checkItHelpers_1 = require("./checkItHelpers");
|
|
18
|
+
const checkit_1 = __importDefault(require("checkit"));
|
|
19
|
+
const rulesSingleIntId = new checkit_1.default({
|
|
20
|
+
id: [
|
|
21
|
+
{
|
|
22
|
+
rule: 'required',
|
|
23
|
+
message: 'ID is required',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
rule: 'integer',
|
|
27
|
+
message: 'ID should be an integer',
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
const rulesSingleUuidId = new checkit_1.default({
|
|
32
|
+
id: [
|
|
33
|
+
{
|
|
34
|
+
rule: 'required',
|
|
35
|
+
message: 'ID is required',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
rule: 'uuid',
|
|
39
|
+
message: 'ID should be an integer',
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
const rulesSingleTextId = new checkit_1.default({
|
|
44
|
+
id: [
|
|
45
|
+
{
|
|
46
|
+
rule: 'required',
|
|
47
|
+
message: 'ID is required',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
rule: 'string',
|
|
51
|
+
message: 'ID should be a string',
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
const rulesMultipleIntIds = new checkit_1.default({
|
|
56
|
+
ids: [
|
|
57
|
+
{
|
|
58
|
+
rule: 'required',
|
|
59
|
+
message: 'IDs is required',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
rule: 'array',
|
|
63
|
+
message: 'IDs should be an array of integer',
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
});
|
|
67
|
+
const rulesMultipleUuidIds = new checkit_1.default({
|
|
68
|
+
ids: [
|
|
69
|
+
{
|
|
70
|
+
rule: 'required',
|
|
71
|
+
message: 'IDs is required',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
rule: 'array',
|
|
75
|
+
message: 'IDs should be an array of UUIDs',
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
});
|
|
79
|
+
const rulesMultipleTextIds = new checkit_1.default({
|
|
80
|
+
ids: [
|
|
81
|
+
{
|
|
82
|
+
rule: 'required',
|
|
83
|
+
message: 'IDs is required',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
rule: 'array',
|
|
87
|
+
message: 'IDs should be an array of strings',
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
});
|
|
15
91
|
const shouldHaveParams = (args) => {
|
|
16
92
|
const keys = Object.keys(args || {});
|
|
17
93
|
if (keys.length === 0) {
|
|
@@ -31,6 +107,54 @@ const shouldHaveId = (id) => {
|
|
|
31
107
|
return [true];
|
|
32
108
|
};
|
|
33
109
|
exports.shouldHaveId = shouldHaveId;
|
|
110
|
+
const validateSingleIntId = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
111
|
+
const [result] = rulesSingleIntId.validateSync(args);
|
|
112
|
+
if (result) {
|
|
113
|
+
return [(0, checkItHelpers_1.createErrorOnCheckError)(result)];
|
|
114
|
+
}
|
|
115
|
+
return [true, {}];
|
|
116
|
+
});
|
|
117
|
+
exports.validateSingleIntId = validateSingleIntId;
|
|
118
|
+
const validateSingleUuidId = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
119
|
+
const [result] = rulesSingleUuidId.validateSync(args);
|
|
120
|
+
if (result) {
|
|
121
|
+
return [(0, checkItHelpers_1.createErrorOnCheckError)(result)];
|
|
122
|
+
}
|
|
123
|
+
return [true, {}];
|
|
124
|
+
});
|
|
125
|
+
exports.validateSingleUuidId = validateSingleUuidId;
|
|
126
|
+
const validateSingleTextId = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
+
const [result] = rulesSingleTextId.validateSync(args);
|
|
128
|
+
if (result) {
|
|
129
|
+
return [(0, checkItHelpers_1.createErrorOnCheckError)(result)];
|
|
130
|
+
}
|
|
131
|
+
return [true, {}];
|
|
132
|
+
});
|
|
133
|
+
exports.validateSingleTextId = validateSingleTextId;
|
|
134
|
+
const validateMultipleIntIds = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
|
+
const [result] = rulesMultipleIntIds.validateSync(args);
|
|
136
|
+
if (result) {
|
|
137
|
+
return [(0, checkItHelpers_1.createErrorOnCheckError)(result)];
|
|
138
|
+
}
|
|
139
|
+
return [true, {}];
|
|
140
|
+
});
|
|
141
|
+
exports.validateMultipleIntIds = validateMultipleIntIds;
|
|
142
|
+
const validateMultipleUuidIds = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
143
|
+
const [result] = rulesMultipleUuidIds.validateSync(args);
|
|
144
|
+
if (result) {
|
|
145
|
+
return [(0, checkItHelpers_1.createErrorOnCheckError)(result)];
|
|
146
|
+
}
|
|
147
|
+
return [true, {}];
|
|
148
|
+
});
|
|
149
|
+
exports.validateMultipleUuidIds = validateMultipleUuidIds;
|
|
150
|
+
const validateMultipleTextIds = (args, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
151
|
+
const [result] = rulesMultipleTextIds.validateSync(args);
|
|
152
|
+
if (result) {
|
|
153
|
+
return [(0, checkItHelpers_1.createErrorOnCheckError)(result)];
|
|
154
|
+
}
|
|
155
|
+
return [true, {}];
|
|
156
|
+
});
|
|
157
|
+
exports.validateMultipleTextIds = validateMultipleTextIds;
|
|
34
158
|
const validateList = ({ rules }) =>
|
|
35
159
|
// eslint-disable-next-line
|
|
36
160
|
(args, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
package/build/configBulder.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { BuildConfigOptions } from './interfaces';
|
|
2
|
-
export declare const buildConfig: (dirName: string, opt?: BuildConfigOptions
|
|
2
|
+
export declare const buildConfig: (dirName: string, opt?: BuildConfigOptions) => any;
|
package/build/dbHelpers.js
CHANGED
|
@@ -36,6 +36,26 @@ const SQLS = {
|
|
|
36
36
|
FROM INFORMATION_SCHEMA.TABLES';
|
|
37
37
|
`,
|
|
38
38
|
},
|
|
39
|
+
mssql: {
|
|
40
|
+
listTablesSchema: (appSettings) => `
|
|
41
|
+
SELECT TABLE_NAME as table_name
|
|
42
|
+
FROM INFORMATION_SCHEMA.TABLES
|
|
43
|
+
WHERE TABLE_SCHEMA = '${appSettings === null || appSettings === void 0 ? void 0 : appSettings.dbSchema}';
|
|
44
|
+
`,
|
|
45
|
+
listTables: () => `
|
|
46
|
+
SELECT TABLE_NAME as table_name
|
|
47
|
+
FROM INFORMATION_SCHEMA.TABLES
|
|
48
|
+
`,
|
|
49
|
+
dropTablesSchema: (appSettings) => `
|
|
50
|
+
SELECT 'DROP TABLE IF EXISTS [${appSettings === null || appSettings === void 0 ? void 0 : appSettings.dbSchema}].[' + TABLE_NAME + '];' as cmd
|
|
51
|
+
FROM INFORMATION_SCHEMA.TABLES
|
|
52
|
+
WHERE TABLE_SCHEMA = '${appSettings === null || appSettings === void 0 ? void 0 : appSettings.dbSchema}';
|
|
53
|
+
`,
|
|
54
|
+
dropTables: () => `
|
|
55
|
+
SELECT 'DROP TABLE IF EXISTS ' + TABLE_NAME + ';' as cmd
|
|
56
|
+
FROM INFORMATION_SCHEMA.TABLES';
|
|
57
|
+
`,
|
|
58
|
+
},
|
|
39
59
|
};
|
|
40
60
|
/**
|
|
41
61
|
* Removes all the records from provided table.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DbFieldAddDefaultInterface } from './interfaces';
|
|
2
|
-
export declare const dbFieldAddDefaults: (table: any, opt?: DbFieldAddDefaultInterface
|
|
2
|
+
export declare const dbFieldAddDefaults: (table: any, opt?: DbFieldAddDefaultInterface) => void;
|
|
3
3
|
export declare const addOrderNo: (table: any, opt?: any) => any;
|
|
4
4
|
export declare const addAmount: (table: any, fieldName: string) => any;
|
|
5
5
|
export declare const addSpaceId: (table: any, opt?: any) => any;
|
package/build/dbTableHelpers.js
CHANGED
|
@@ -9,10 +9,14 @@ const dbFieldAddDefaults = (table, opt) => {
|
|
|
9
9
|
table
|
|
10
10
|
.integer(constants_1.FIELDS.STATUS)
|
|
11
11
|
.defaultTo(utils_1.STATUSES.ACTIVE)
|
|
12
|
-
.comment(
|
|
12
|
+
.comment((opt === null || opt === void 0 ? void 0 : opt.statusComment) ||
|
|
13
|
+
'The field is used to specify record status: 50 - Test, 100 - Active, 200 - Draft, 300 - Pending, 1000 - Blocked, 5000 - Disabled, 10000 - Removed');
|
|
13
14
|
}
|
|
14
15
|
if (addVersion) {
|
|
15
|
-
table
|
|
16
|
+
table
|
|
17
|
+
.integer(constants_1.FIELDS.VERSION)
|
|
18
|
+
.defaultTo(0)
|
|
19
|
+
.comment((opt === null || opt === void 0 ? void 0 : opt.versionComment) || 'The field is used to control versioning');
|
|
16
20
|
}
|
|
17
21
|
if (addUserInfo) {
|
|
18
22
|
table.uuid(constants_1.FIELDS.CREATED_BY).comment('ID of user who created the record');
|
package/build/index.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
20
|
-
export
|
|
1
|
+
export * from './constants';
|
|
2
|
+
export * from './interfaces';
|
|
3
|
+
export * from './configBulder';
|
|
4
|
+
export * from './Database';
|
|
5
|
+
export * from './dbHelpers';
|
|
6
|
+
export * from './DbMigratorAndSeeder';
|
|
7
|
+
export * from './dbSeeder';
|
|
8
|
+
export * from './knexConfigBuilder';
|
|
9
|
+
export * from './redisClient';
|
|
10
|
+
export * from './checkItHelpers';
|
|
11
|
+
export * from './DataCache';
|
|
12
|
+
export * from './BaseGateway';
|
|
13
|
+
export * from './BaseCore';
|
|
14
|
+
export * from './apiContext';
|
|
15
|
+
export * from './BaseController';
|
|
16
|
+
export * from './dbTableHelpers';
|
|
17
|
+
export * from './resolversHelpers';
|
|
18
|
+
export * from './userToken';
|
|
19
|
+
export * from './passwordHelpers';
|
|
20
|
+
export * from './commonValidators';
|
package/build/index.js
CHANGED
|
@@ -1,64 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Object.defineProperty(exports, "dbSeed", { enumerable: true, get: function () { return dbSeeder_1.dbSeed; } });
|
|
24
|
-
var knexConfigBuilder_1 = require("./knexConfigBuilder");
|
|
25
|
-
Object.defineProperty(exports, "buildKnexConfig", { enumerable: true, get: function () { return knexConfigBuilder_1.buildKnexConfig; } });
|
|
26
|
-
var redisClient_1 = require("./redisClient");
|
|
27
|
-
Object.defineProperty(exports, "createRedisClient", { enumerable: true, get: function () { return redisClient_1.createRedisClient; } });
|
|
28
|
-
var checkItHelpers_1 = require("./checkItHelpers");
|
|
29
|
-
Object.defineProperty(exports, "checkArray", { enumerable: true, get: function () { return checkItHelpers_1.checkArray; } });
|
|
30
|
-
Object.defineProperty(exports, "createErrorOnCheckError", { enumerable: true, get: function () { return checkItHelpers_1.createErrorOnCheckError; } });
|
|
31
|
-
var DataCache_1 = require("./DataCache");
|
|
32
|
-
Object.defineProperty(exports, "DataCache", { enumerable: true, get: function () { return DataCache_1.DataCache; } });
|
|
33
|
-
var BaseGateway_1 = require("./BaseGateway");
|
|
34
|
-
Object.defineProperty(exports, "BaseGateway", { enumerable: true, get: function () { return BaseGateway_1.BaseGateway; } });
|
|
35
|
-
var BaseCore_1 = require("./BaseCore");
|
|
36
|
-
Object.defineProperty(exports, "BaseCore", { enumerable: true, get: function () { return BaseCore_1.BaseCore; } });
|
|
37
|
-
var apiContext_1 = require("./apiContext");
|
|
38
|
-
Object.defineProperty(exports, "createApiContext", { enumerable: true, get: function () { return apiContext_1.createApiContext; } });
|
|
39
|
-
Object.defineProperty(exports, "createContextDefault", { enumerable: true, get: function () { return apiContext_1.createContextDefault; } });
|
|
40
|
-
var BaseController_1 = require("./BaseController");
|
|
41
|
-
Object.defineProperty(exports, "BaseController", { enumerable: true, get: function () { return BaseController_1.BaseController; } });
|
|
42
|
-
var dbTableHelpers_1 = require("./dbTableHelpers");
|
|
43
|
-
Object.defineProperty(exports, "dbFieldAddDefaults", { enumerable: true, get: function () { return dbTableHelpers_1.dbFieldAddDefaults; } });
|
|
44
|
-
Object.defineProperty(exports, "addOrderNo", { enumerable: true, get: function () { return dbTableHelpers_1.addOrderNo; } });
|
|
45
|
-
Object.defineProperty(exports, "addAmount", { enumerable: true, get: function () { return dbTableHelpers_1.addAmount; } });
|
|
46
|
-
Object.defineProperty(exports, "addSpaceId", { enumerable: true, get: function () { return dbTableHelpers_1.addSpaceId; } });
|
|
47
|
-
Object.defineProperty(exports, "addUserId", { enumerable: true, get: function () { return dbTableHelpers_1.addUserId; } });
|
|
48
|
-
Object.defineProperty(exports, "addAccountId", { enumerable: true, get: function () { return dbTableHelpers_1.addAccountId; } });
|
|
49
|
-
Object.defineProperty(exports, "addLang", { enumerable: true, get: function () { return dbTableHelpers_1.addLang; } });
|
|
50
|
-
Object.defineProperty(exports, "defaultFields", { enumerable: true, get: function () { return dbTableHelpers_1.defaultFields; } });
|
|
51
|
-
var resolversHelpers_1 = require("./resolversHelpers");
|
|
52
|
-
Object.defineProperty(exports, "buildDefaultResolvers", { enumerable: true, get: function () { return resolversHelpers_1.buildDefaultResolvers; } });
|
|
53
|
-
var userToken_1 = require("./userToken");
|
|
54
|
-
Object.defineProperty(exports, "createUserToken", { enumerable: true, get: function () { return userToken_1.createUserToken; } });
|
|
55
|
-
Object.defineProperty(exports, "verifyUserToken", { enumerable: true, get: function () { return userToken_1.verifyUserToken; } });
|
|
56
|
-
var passwordHelpers_1 = require("./passwordHelpers");
|
|
57
|
-
Object.defineProperty(exports, "getSaltAndHash", { enumerable: true, get: function () { return passwordHelpers_1.getSaltAndHash; } });
|
|
58
|
-
Object.defineProperty(exports, "checkPassword", { enumerable: true, get: function () { return passwordHelpers_1.checkPassword; } });
|
|
59
|
-
var commonValidators_1 = require("./commonValidators");
|
|
60
|
-
Object.defineProperty(exports, "shouldHaveParams", { enumerable: true, get: function () { return commonValidators_1.shouldHaveParams; } });
|
|
61
|
-
Object.defineProperty(exports, "shouldHaveId", { enumerable: true, get: function () { return commonValidators_1.shouldHaveId; } });
|
|
62
|
-
Object.defineProperty(exports, "validateList", { enumerable: true, get: function () { return commonValidators_1.validateList; } });
|
|
63
|
-
Object.defineProperty(exports, "validateCreate", { enumerable: true, get: function () { return commonValidators_1.validateCreate; } });
|
|
64
|
-
Object.defineProperty(exports, "validateUpdate", { enumerable: true, get: function () { return commonValidators_1.validateUpdate; } });
|
|
17
|
+
__exportStar(require("./constants"), exports);
|
|
18
|
+
__exportStar(require("./interfaces"), exports);
|
|
19
|
+
__exportStar(require("./configBulder"), exports);
|
|
20
|
+
__exportStar(require("./Database"), exports);
|
|
21
|
+
__exportStar(require("./dbHelpers"), exports);
|
|
22
|
+
__exportStar(require("./DbMigratorAndSeeder"), exports);
|
|
23
|
+
__exportStar(require("./dbSeeder"), exports);
|
|
24
|
+
__exportStar(require("./knexConfigBuilder"), exports);
|
|
25
|
+
__exportStar(require("./redisClient"), exports);
|
|
26
|
+
__exportStar(require("./checkItHelpers"), exports);
|
|
27
|
+
__exportStar(require("./DataCache"), exports);
|
|
28
|
+
__exportStar(require("./BaseGateway"), exports);
|
|
29
|
+
__exportStar(require("./BaseCore"), exports);
|
|
30
|
+
__exportStar(require("./apiContext"), exports);
|
|
31
|
+
__exportStar(require("./BaseController"), exports);
|
|
32
|
+
__exportStar(require("./dbTableHelpers"), exports);
|
|
33
|
+
__exportStar(require("./resolversHelpers"), exports);
|
|
34
|
+
__exportStar(require("./userToken"), exports);
|
|
35
|
+
__exportStar(require("./passwordHelpers"), exports);
|
|
36
|
+
__exportStar(require("./commonValidators"), exports);
|
package/build/userToken.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OpResult } from '@sdflc/api-helpers';
|
|
2
2
|
import { UserTokenParams, CreateUserTokenArgs, VerifyUserTokenArgs } from './interfaces';
|
|
3
|
+
export declare const setDefaultJwtAlgorithm: (algorithm: string) => void;
|
|
3
4
|
export declare const createUserToken: (params: UserTokenParams, secret: string, opt: CreateUserTokenArgs) => OpResult;
|
|
4
|
-
export declare const verifyUserToken: (token: string, secret: string, args?: VerifyUserTokenArgs
|
|
5
|
+
export declare const verifyUserToken: (token: string, secret: string, args?: VerifyUserTokenArgs) => OpResult;
|
package/build/userToken.js
CHANGED
|
@@ -3,16 +3,21 @@ 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.verifyUserToken = exports.createUserToken = void 0;
|
|
6
|
+
exports.verifyUserToken = exports.createUserToken = exports.setDefaultJwtAlgorithm = void 0;
|
|
7
7
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
8
|
const api_helpers_1 = require("@sdflc/api-helpers");
|
|
9
|
+
let defaultJwtAlgorithm = 'HS256';
|
|
10
|
+
const setDefaultJwtAlgorithm = (algorithm) => {
|
|
11
|
+
defaultJwtAlgorithm = algorithm;
|
|
12
|
+
};
|
|
13
|
+
exports.setDefaultJwtAlgorithm = setDefaultJwtAlgorithm;
|
|
9
14
|
const createUserToken = (params, secret, opt) => {
|
|
10
15
|
const { algorithm, audience, issuer, jwtid, subject, noTimestamp, header, keyid, expiresIn } = opt || {};
|
|
11
16
|
if (!params || !secret) {
|
|
12
17
|
return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED, null, 'Failed to create user JWT');
|
|
13
18
|
}
|
|
14
19
|
const token = jsonwebtoken_1.default.sign(params, secret, {
|
|
15
|
-
algorithm: algorithm ||
|
|
20
|
+
algorithm: algorithm || defaultJwtAlgorithm,
|
|
16
21
|
audience,
|
|
17
22
|
issuer,
|
|
18
23
|
jwtid,
|
|
@@ -32,7 +37,7 @@ const verifyUserToken = (token, secret, args) => {
|
|
|
32
37
|
}
|
|
33
38
|
try {
|
|
34
39
|
const obj = jsonwebtoken_1.default.verify(token, secret, {
|
|
35
|
-
algorithms: algorithms || [
|
|
40
|
+
algorithms: algorithms || [defaultJwtAlgorithm],
|
|
36
41
|
audience,
|
|
37
42
|
issuer,
|
|
38
43
|
ignoreExpiration,
|
|
@@ -46,6 +51,9 @@ const verifyUserToken = (token, secret, args) => {
|
|
|
46
51
|
return api_helpers_1.OpResult.ok(obj);
|
|
47
52
|
}
|
|
48
53
|
catch (ex) {
|
|
54
|
+
if (ex.name === 'TokenExpiredError') {
|
|
55
|
+
return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.EXPIRED, null, 'User authorization has expired');
|
|
56
|
+
}
|
|
49
57
|
return api_helpers_1.OpResult.fail(api_helpers_1.OP_RESULT_CODES.UNAUTHORIZED, null, 'User unauthenticated');
|
|
50
58
|
}
|
|
51
59
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdflc/backend-helpers",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.55",
|
|
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",
|
|
@@ -23,45 +23,45 @@
|
|
|
23
23
|
"author": "Sergey Demidenko",
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@sdflc/api-helpers": "^1.1.
|
|
27
|
-
"@sdflc/utils": "^1.0.
|
|
28
|
-
"bcrypt": "^5.0
|
|
26
|
+
"@sdflc/api-helpers": "^1.1.10",
|
|
27
|
+
"@sdflc/utils": "^1.0.22",
|
|
28
|
+
"bcrypt": "^5.1.0",
|
|
29
29
|
"bluebird": "^3.7.2",
|
|
30
30
|
"checkit": "^0.7.0",
|
|
31
|
-
"dataloader": "^2.
|
|
32
|
-
"dayjs": "^1.11.
|
|
31
|
+
"dataloader": "^2.1.0",
|
|
32
|
+
"dayjs": "^1.11.6",
|
|
33
33
|
"dotenv-safe": "^8.2.0",
|
|
34
|
-
"jest": "^27.5.1",
|
|
35
34
|
"json-stable-stringify": "^1.0.1",
|
|
36
35
|
"jsonwebtoken": "^8.5.1",
|
|
37
|
-
"knex": "^
|
|
36
|
+
"knex": "^2.3.0",
|
|
38
37
|
"lodash": "^4.17.21",
|
|
39
|
-
"pg": "^8.
|
|
38
|
+
"pg": "^8.8.0",
|
|
40
39
|
"redis": "^4.0.6",
|
|
41
|
-
"
|
|
42
|
-
"typescript": "^4.6.3",
|
|
43
|
-
"uuid": "^8.3.2"
|
|
40
|
+
"uuid": "^9.0.0"
|
|
44
41
|
},
|
|
45
42
|
"devDependencies": {
|
|
46
43
|
"@types/bcrypt": "^5.0.0",
|
|
47
|
-
"@types/bluebird": "^3.5.
|
|
44
|
+
"@types/bluebird": "^3.5.37",
|
|
48
45
|
"@types/dotenv-safe": "^8.1.2",
|
|
46
|
+
"@types/jest": "^29.2.0",
|
|
49
47
|
"@types/json-stable-stringify": "^1.0.34",
|
|
50
|
-
"@types/jsonwebtoken": "^8.5.
|
|
48
|
+
"@types/jsonwebtoken": "^8.5.9",
|
|
51
49
|
"@types/lodash": "^4.14.181",
|
|
52
|
-
"@types/node": "^
|
|
53
|
-
"@types/redis": "^4.0.11",
|
|
50
|
+
"@types/node": "^18.11.7",
|
|
54
51
|
"@types/uuid": "^8.3.4",
|
|
55
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
56
|
-
"@typescript-eslint/parser": "^5.
|
|
57
|
-
"eslint": "^8.
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "^5.41.0",
|
|
53
|
+
"@typescript-eslint/parser": "^5.41.0",
|
|
54
|
+
"eslint": "^8.26.0",
|
|
58
55
|
"eslint-config-prettier": "^8.5.0",
|
|
59
|
-
"eslint-plugin-jest": "^
|
|
60
|
-
"eslint-plugin-prettier": "^4.
|
|
61
|
-
"husky": "^
|
|
62
|
-
"
|
|
56
|
+
"eslint-plugin-jest": "^27.1.3",
|
|
57
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
58
|
+
"husky": "^8.0.1",
|
|
59
|
+
"jest": "^29.2.2",
|
|
60
|
+
"prettier": "^2.7.1",
|
|
61
|
+
"rimraf": "^3.0.2",
|
|
63
62
|
"run-script-os": "^1.1.6",
|
|
64
|
-
"ts-jest": "^
|
|
65
|
-
"ts-node": "^10.
|
|
63
|
+
"ts-jest": "^29.0.3",
|
|
64
|
+
"ts-node": "^10.9.1",
|
|
65
|
+
"typescript": "^4.8.4"
|
|
66
66
|
}
|
|
67
67
|
}
|