@sdflc/backend-helpers 1.0.70 → 1.0.72
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.js +8 -2
- package/build/BaseGateway.js +11 -10
- package/build/DataCache.js +5 -2
- package/build/interfaces/BaseGatewayPropsInterface.d.ts +3 -0
- package/build/interfaces/BuildListQueryArgsInterface.d.ts +1 -0
- package/build/interfaces/CacheInterface.d.ts +1 -0
- package/build/interfaces/ExtractCredentialsArgs.d.ts +1 -0
- package/package.json +1 -1
package/build/BaseCore.js
CHANGED
|
@@ -719,7 +719,7 @@ class BaseCore {
|
|
|
719
719
|
return __awaiter(this, void 0, void 0, function* () {
|
|
720
720
|
const { req, space, authorization } = args;
|
|
721
721
|
const token = ((_a = req.cookies) === null || _a === void 0 ? void 0 : _a[space.cookieName]) || authorization;
|
|
722
|
-
const fingerprint = ((_b = req.cookies) === null || _b === void 0 ? void 0 : _b[space.fingerprintCookieName]) || '';
|
|
722
|
+
const fingerprint = ((_b = req.cookies) === null || _b === void 0 ? void 0 : _b[space.fingerprintCookieName]) || args.fingerprint || '';
|
|
723
723
|
return {
|
|
724
724
|
token,
|
|
725
725
|
fingerprint,
|
|
@@ -737,7 +737,13 @@ class BaseCore {
|
|
|
737
737
|
if (spaceResult !== true) {
|
|
738
738
|
return [spaceResult, space];
|
|
739
739
|
}
|
|
740
|
-
const { token, fingerprint } = yield this.extractCredentials({
|
|
740
|
+
const { token, fingerprint } = yield this.extractCredentials({
|
|
741
|
+
req,
|
|
742
|
+
authorization,
|
|
743
|
+
fingerprint: context.fingerprint,
|
|
744
|
+
space,
|
|
745
|
+
params,
|
|
746
|
+
});
|
|
741
747
|
const { jwtSecret, verifyTokenArgs } = yield this.getJwtTokenSecretAndSettings(params);
|
|
742
748
|
if (token && jwtSecret) {
|
|
743
749
|
const verifyResult = (0, userToken_1.verifyUserToken)(token, jwtSecret, Object.assign(Object.assign({}, verifyTokenArgs), { algorithms: (verifyTokenArgs === null || verifyTokenArgs === void 0 ? void 0 : verifyTokenArgs.algorithms) || [(0, userToken_1.getDefaultJwtAlgorithm)()], audience: (verifyTokenArgs === null || verifyTokenArgs === void 0 ? void 0 : verifyTokenArgs.audience) || space.id, issuer: (verifyTokenArgs === null || verifyTokenArgs === void 0 ? void 0 : verifyTokenArgs.issuer) || (0, userToken_1.getDefaultJwtIssuer)(), fingerprint }));
|
package/build/BaseGateway.js
CHANGED
|
@@ -54,24 +54,24 @@ class BaseGateway {
|
|
|
54
54
|
}
|
|
55
55
|
onListFilter(query, filterParams) {
|
|
56
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
const { hasStatus, hasRemovedAt, hasSpace, activeStatuses, hasLang, fieldForKeyword, filterByUserField } = this.config || {};
|
|
57
|
+
const { table, hasStatus, hasRemovedAt, hasSpace, activeStatuses, hasLang, fieldForKeyword, filterByUserField } = this.config || {};
|
|
58
58
|
// This function should be overriden
|
|
59
59
|
if (hasStatus) {
|
|
60
|
-
query.whereIn(constants_1.FIELDS.STATUS
|
|
60
|
+
query.whereIn(`${table}.${constants_1.FIELDS.STATUS}`, Array.isArray(filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.STATUS]) ? filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.STATUS] : (0, lodash_1.castArray)(activeStatuses));
|
|
61
61
|
}
|
|
62
62
|
if (hasRemovedAt) {
|
|
63
|
-
query.whereNull(constants_1.FIELDS.REMOVED_AT);
|
|
63
|
+
query.whereNull(`${table}.${constants_1.FIELDS.REMOVED_AT}`);
|
|
64
64
|
}
|
|
65
65
|
if (hasSpace && ((filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.SPACE_ID]) != undefined || this.config.context.spaceId)) {
|
|
66
66
|
query.where({
|
|
67
|
-
[constants_1.FIELDS.SPACE_ID]: (filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.SPACE_ID]) != undefined ? filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.SPACE_ID] : this.config.context.spaceId,
|
|
67
|
+
[`${table}.${constants_1.FIELDS.SPACE_ID}`]: (filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.SPACE_ID]) != undefined ? filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.SPACE_ID] : this.config.context.spaceId,
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
if (hasLang && (filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.LANG]) != undefined) {
|
|
71
|
-
query.whereIn(constants_1.FIELDS.LANG
|
|
71
|
+
query.whereIn(`${table}.${constants_1.FIELDS.LANG}`, (0, lodash_1.castArray)(filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.LANG]));
|
|
72
72
|
}
|
|
73
73
|
if (filterParams === null || filterParams === void 0 ? void 0 : filterParams[this.getIdField()]) {
|
|
74
|
-
query.whereIn(constants_1.FIELDS.ID
|
|
74
|
+
query.whereIn(`${table}.${constants_1.FIELDS.ID}`, (0, lodash_1.castArray)(filterParams === null || filterParams === void 0 ? void 0 : filterParams[this.getIdField()]));
|
|
75
75
|
}
|
|
76
76
|
if (fieldForKeyword && filterParams.keyword) {
|
|
77
77
|
query.whereRaw(`${fieldForKeyword} ILIKE ?`, `%${filterParams.keyword}%`);
|
|
@@ -295,9 +295,9 @@ class BaseGateway {
|
|
|
295
295
|
if (!this.config.table) {
|
|
296
296
|
return [];
|
|
297
297
|
}
|
|
298
|
-
const shouldUseCache = useCache != null ? useCache : this.config.noCache;
|
|
299
|
-
const fieldsToUse = shouldUseCache && Array.isArray(this.config.selectFields) ? this.config.selectFields : this.getIdField();
|
|
300
|
-
const query = this.buildListQuery({ filter, params, fieldsToUse });
|
|
298
|
+
const shouldUseCache = useCache != null ? useCache : !this.config.noCache;
|
|
299
|
+
const fieldsToUse = !shouldUseCache && Array.isArray(this.config.selectFields) ? this.config.selectFields : this.getIdField();
|
|
300
|
+
const query = this.buildListQuery({ filter, params, fieldsToUse, useCache: shouldUseCache });
|
|
301
301
|
yield this.onListFilter(query, filter);
|
|
302
302
|
if (limit && !isNaN(limit) && limit > 0) {
|
|
303
303
|
query.offset(offset).limit(limit);
|
|
@@ -306,7 +306,8 @@ class BaseGateway {
|
|
|
306
306
|
query.orderBy(sortBy);
|
|
307
307
|
}
|
|
308
308
|
const items = yield query;
|
|
309
|
-
|
|
309
|
+
const result = shouldUseCache ? yield this.getMany(items.map((row) => row.id)) : items;
|
|
310
|
+
return result;
|
|
310
311
|
});
|
|
311
312
|
}
|
|
312
313
|
create(args) {
|
package/build/DataCache.js
CHANGED
|
@@ -24,6 +24,9 @@ class DataCache {
|
|
|
24
24
|
if (!(props === null || props === void 0 ? void 0 : props.idField)) {
|
|
25
25
|
props.idField = _1.FIELDS.ID;
|
|
26
26
|
}
|
|
27
|
+
if (!(props === null || props === void 0 ? void 0 : props.idFieldAs)) {
|
|
28
|
+
props.idFieldAs = _1.FIELDS.ID;
|
|
29
|
+
}
|
|
27
30
|
this.config = props;
|
|
28
31
|
this.redisClient = redisClient;
|
|
29
32
|
this.buildKey = typeof buildKey === 'function' ? buildKey : utils_1.buildKey;
|
|
@@ -33,7 +36,7 @@ class DataCache {
|
|
|
33
36
|
this.init(fn, prefixToUse, context);
|
|
34
37
|
}
|
|
35
38
|
batchLoaderDefault(props) {
|
|
36
|
-
const { table, idField, readAll, db } = props;
|
|
39
|
+
const { table, idField, idFieldAs, readAll, db } = props;
|
|
37
40
|
if (!table) {
|
|
38
41
|
throw Error(`DataCache requires 'table' property to be setup`);
|
|
39
42
|
}
|
|
@@ -48,7 +51,7 @@ class DataCache {
|
|
|
48
51
|
const readCfg = Object.assign(Object.assign({}, props), { buildKey: this.buildKey });
|
|
49
52
|
const idsToUse = (0, lodash_1.castArray)(ids);
|
|
50
53
|
if (!readAll) {
|
|
51
|
-
readCfg.mapBy = idField;
|
|
54
|
+
readCfg.mapBy = idFieldAs || idField;
|
|
52
55
|
readCfg.whereIn = {
|
|
53
56
|
field: idField,
|
|
54
57
|
values: idsToUse.filter((id) => id),
|
|
@@ -5,6 +5,9 @@ import { LoaderInterface } from './LoaderInterface';
|
|
|
5
5
|
import { SortItemInterface } from './SortItemInterface';
|
|
6
6
|
export interface BaseGatewayPropsInterface extends CacheInterface {
|
|
7
7
|
context: ApiContext;
|
|
8
|
+
table?: string;
|
|
9
|
+
idField?: string;
|
|
10
|
+
idFieldAs?: string;
|
|
8
11
|
setFields?: string[] | string;
|
|
9
12
|
mergeFields?: string[];
|
|
10
13
|
hasStatus?: boolean;
|
package/package.json
CHANGED