identity-admin 1.26.0 → 1.26.2
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/lib/helpers/ResourceHelper.d.ts +2 -2
- package/lib/helpers/ResourceHelper.js +39 -22
- package/lib/middlewares/cache/decorator.d.ts +2 -0
- package/lib/middlewares/cache/decorator.js +56 -0
- package/lib/middlewares/cache/deletionMethods.d.ts +3 -0
- package/lib/middlewares/cache/deletionMethods.js +23 -0
- package/lib/types/IResourceFile.d.ts +4 -0
- package/package.json +2 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IResourceFile } from
|
|
2
|
-
import { IModelConfigurationDocument } from
|
|
1
|
+
import { IResourceFile } from '../types/IResourceFile';
|
|
2
|
+
import { IModelConfigurationDocument } from '../models/modelConfiguration/IModelConfigurations';
|
|
3
3
|
export default class ResourcesHelper {
|
|
4
4
|
static getSchemaTitle(schema: any, resource: any, modelConfiguration: IModelConfigurationDocument | undefined): any;
|
|
5
5
|
static prepareProperties(properties: string[], modelName: string, model: any, resource: IResourceFile): {}[];
|
|
@@ -52,12 +52,12 @@ class ResourcesHelper {
|
|
|
52
52
|
}
|
|
53
53
|
static prepareProperties(properties, modelName, model, resource) {
|
|
54
54
|
var preparedProperties = [];
|
|
55
|
-
properties.forEach(key => {
|
|
55
|
+
properties.forEach((key) => {
|
|
56
56
|
if (model[key]) {
|
|
57
57
|
// const refCheck = model[key].type === FieldTypes.REFERENCE
|
|
58
58
|
// var path = undefined
|
|
59
59
|
// if (refCheck) {
|
|
60
|
-
// path = model[key].path
|
|
60
|
+
// path = model[key].path
|
|
61
61
|
// }
|
|
62
62
|
// const translation = this.checkResourceTranslation(resource, key)
|
|
63
63
|
// const propertyObject = {
|
|
@@ -85,15 +85,21 @@ class ResourcesHelper {
|
|
|
85
85
|
const translatedKey = rawKey ? rawKey : key;
|
|
86
86
|
const propertyObject = {
|
|
87
87
|
key,
|
|
88
|
-
value: translation
|
|
89
|
-
|
|
88
|
+
value: translation
|
|
89
|
+
? translation
|
|
90
|
+
: model.value
|
|
91
|
+
? model.value
|
|
92
|
+
: StringUtils_1.default.checkRefId(translatedKey)
|
|
93
|
+
? StringUtils_1.default.convertCamelCaseToWord(translatedKey.slice(0, -2))
|
|
94
|
+
: StringUtils_1.default.convertCamelCaseToWord(translatedKey),
|
|
95
|
+
path: path,
|
|
90
96
|
};
|
|
91
97
|
return propertyObject;
|
|
92
98
|
}
|
|
93
99
|
static getRawName(key) {
|
|
94
100
|
if (key.includes('.')) {
|
|
95
101
|
const nestedProperties = key.split('.');
|
|
96
|
-
return
|
|
102
|
+
return nestedProperties[nestedProperties.length - 1];
|
|
97
103
|
}
|
|
98
104
|
return undefined;
|
|
99
105
|
}
|
|
@@ -115,7 +121,12 @@ class ResourcesHelper {
|
|
|
115
121
|
var filterProperties = [];
|
|
116
122
|
for (var i = 0; i < properties.length; i++) {
|
|
117
123
|
const property = properties[i];
|
|
118
|
-
if (!schema[property] ||
|
|
124
|
+
if (!schema[property] ||
|
|
125
|
+
!schema[property].type ||
|
|
126
|
+
schema[property].type === helpers_1.FieldTypes.ARRAY ||
|
|
127
|
+
schema[property].type === helpers_1.FieldTypes.NESTEDSCHEMA ||
|
|
128
|
+
schema[property].type === helpers_1.FieldTypes.IMAGE ||
|
|
129
|
+
schema[property].type === helpers_1.FieldTypes.PASSWORD) {
|
|
119
130
|
continue;
|
|
120
131
|
}
|
|
121
132
|
filterProperties.push(property);
|
|
@@ -144,12 +155,12 @@ class ResourcesHelper {
|
|
|
144
155
|
var arrayOfOptions = [];
|
|
145
156
|
arrayOfOptions.push({
|
|
146
157
|
key: 'all',
|
|
147
|
-
value: (0, i18n_1.__)({ phrase: 'ALL', locale: i18n_1.default.getLocale() })
|
|
158
|
+
value: (0, i18n_1.__)({ phrase: 'ALL', locale: i18n_1.default.getLocale() }),
|
|
148
159
|
});
|
|
149
160
|
options.forEach((key) => {
|
|
150
161
|
const optionObject = {
|
|
151
162
|
key,
|
|
152
|
-
value: (0, i18n_1.__)({ phrase: key, locale: i18n_1.default.getLocale() })
|
|
163
|
+
value: (0, i18n_1.__)({ phrase: key, locale: i18n_1.default.getLocale() }),
|
|
153
164
|
};
|
|
154
165
|
arrayOfOptions.push(optionObject);
|
|
155
166
|
});
|
|
@@ -158,22 +169,22 @@ class ResourcesHelper {
|
|
|
158
169
|
static getFilters(filters) {
|
|
159
170
|
var filterObject = {
|
|
160
171
|
scopes: {},
|
|
161
|
-
searchBar: {}
|
|
172
|
+
searchBar: {},
|
|
162
173
|
};
|
|
163
174
|
if (!filters || Object.keys(filters).length === 0) {
|
|
164
175
|
filterObject = {
|
|
165
176
|
scopes: {
|
|
166
|
-
isAccessible: false
|
|
177
|
+
isAccessible: false,
|
|
167
178
|
},
|
|
168
179
|
searchBar: {
|
|
169
|
-
isAccessible: true
|
|
170
|
-
}
|
|
180
|
+
isAccessible: true,
|
|
181
|
+
},
|
|
171
182
|
};
|
|
172
183
|
return filterObject;
|
|
173
184
|
}
|
|
174
185
|
if (!filters.searchBar || !filters.searchBar.hasOwnProperty('isAccessible')) {
|
|
175
186
|
filterObject.searchBar = {
|
|
176
|
-
isAccessible: true
|
|
187
|
+
isAccessible: true,
|
|
177
188
|
};
|
|
178
189
|
}
|
|
179
190
|
else {
|
|
@@ -181,7 +192,7 @@ class ResourcesHelper {
|
|
|
181
192
|
}
|
|
182
193
|
if (!filters.scopes || !filters.scopes.hasOwnProperty('isAccessible')) {
|
|
183
194
|
filterObject.scopes = {
|
|
184
|
-
isAccessible: false
|
|
195
|
+
isAccessible: false,
|
|
185
196
|
};
|
|
186
197
|
}
|
|
187
198
|
else {
|
|
@@ -193,7 +204,8 @@ class ResourcesHelper {
|
|
|
193
204
|
return __awaiter(this, void 0, void 0, function* () {
|
|
194
205
|
for (var i = 0; i < showProperties.length; i++) {
|
|
195
206
|
const key = showProperties[i].key;
|
|
196
|
-
if ((model[key].type === helpers_1.FieldTypes.REFERENCE && model.virtuals && model.virtuals[key]) ||
|
|
207
|
+
if ((model[key].type === helpers_1.FieldTypes.REFERENCE && model.virtuals && model.virtuals[key]) ||
|
|
208
|
+
(model[key].type === helpers_1.FieldTypes.ARRAY && model.virtuals && model.virtuals[key] && model[key].arrayType === helpers_1.FieldTypes.REFERENCE)) {
|
|
197
209
|
const resourceModel = resource.properties.model;
|
|
198
210
|
if (!resourceModel) {
|
|
199
211
|
return;
|
|
@@ -207,16 +219,15 @@ class ResourcesHelper {
|
|
|
207
219
|
return;
|
|
208
220
|
}
|
|
209
221
|
const repository = new Repository_1.default(virtualModel);
|
|
210
|
-
|
|
222
|
+
const oneToManyFilterKey = virtuals[key].filterBy ? virtuals[key].filterBy : filterBy + 'Id';
|
|
211
223
|
const filterQuery = {};
|
|
212
|
-
filterQuery[
|
|
224
|
+
filterQuery[oneToManyFilterKey] = record._id;
|
|
213
225
|
const extraRecords = yield repository.findMany({
|
|
214
|
-
filter: filterQuery
|
|
226
|
+
filter: filterQuery,
|
|
215
227
|
});
|
|
216
228
|
record[showProperties[i].key] = extraRecords;
|
|
217
229
|
}
|
|
218
230
|
}
|
|
219
|
-
;
|
|
220
231
|
return record;
|
|
221
232
|
});
|
|
222
233
|
}
|
|
@@ -251,7 +262,7 @@ class ResourcesHelper {
|
|
|
251
262
|
var listProperties = JSON.parse(JSON.stringify(arrayOfFields));
|
|
252
263
|
var formProperties = JSON.parse(JSON.stringify(arrayOfFields));
|
|
253
264
|
var filterProperties = JSON.parse(JSON.stringify(arrayOfFields));
|
|
254
|
-
if (!model || !model.virtuals || !
|
|
265
|
+
if (!model || !model.virtuals || !Object.keys(model.virtuals)) {
|
|
255
266
|
return [listProperties, showProperties, formProperties, filterProperties];
|
|
256
267
|
}
|
|
257
268
|
const virtualFields = model.virtuals;
|
|
@@ -304,7 +315,13 @@ class ResourcesHelper {
|
|
|
304
315
|
return arrayOfFields;
|
|
305
316
|
}
|
|
306
317
|
static checkUnwantedFields(fieldKey, title) {
|
|
307
|
-
if (fieldKey === '__v' ||
|
|
318
|
+
if (fieldKey === '__v' ||
|
|
319
|
+
fieldKey === '_id' ||
|
|
320
|
+
fieldKey === title ||
|
|
321
|
+
fieldKey === 'salt' ||
|
|
322
|
+
fieldKey === 'hash' ||
|
|
323
|
+
fieldKey === 'forgotPasswordToken' ||
|
|
324
|
+
fieldKey === 'encryptedPassword') {
|
|
308
325
|
return true;
|
|
309
326
|
}
|
|
310
327
|
return false;
|
|
@@ -315,7 +332,7 @@ class ResourcesHelper {
|
|
|
315
332
|
}
|
|
316
333
|
static removeUnWantedFieldsFromCreateOrUpdate(arrayOfFields) {
|
|
317
334
|
var modifiedArrayOfFields = [];
|
|
318
|
-
arrayOfFields.forEach(field => {
|
|
335
|
+
arrayOfFields.forEach((field) => {
|
|
319
336
|
if (field !== '_id' && field !== 'createdAt' && field !== 'updatedAt') {
|
|
320
337
|
modifiedArrayOfFields.push(field);
|
|
321
338
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.cached = void 0;
|
|
13
|
+
require("reflect-metadata");
|
|
14
|
+
var cache = require('memory-cache');
|
|
15
|
+
function cached(
|
|
16
|
+
/*
|
|
17
|
+
Duration in ms
|
|
18
|
+
*/
|
|
19
|
+
duration, cachedResponseModifier) {
|
|
20
|
+
return function (target, propertyKey, descriptor) {
|
|
21
|
+
const originalMethod = descriptor.value;
|
|
22
|
+
descriptor.value = function (req, res, ...args) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const headers = req.headers;
|
|
25
|
+
const requestLanguage = headers['language'] || 'en';
|
|
26
|
+
const requestPath = req.path;
|
|
27
|
+
const requestQuery = Object.keys(req.query).length > 0 ? JSON.stringify(sortObject(req.query)) : undefined;
|
|
28
|
+
var cacheKey = `${requestPath}_${requestLanguage}`;
|
|
29
|
+
if (requestQuery)
|
|
30
|
+
cacheKey += `_${requestQuery}`;
|
|
31
|
+
const cachedData = cache.get(cacheKey);
|
|
32
|
+
if (cachedData) {
|
|
33
|
+
const parsedData = JSON.parse(cachedData);
|
|
34
|
+
return res.send(cachedResponseModifier ? cachedResponseModifier(parsedData) : parsedData);
|
|
35
|
+
}
|
|
36
|
+
const originalSend = res.send;
|
|
37
|
+
res.send = function (body) {
|
|
38
|
+
cache.put(cacheKey, body, duration);
|
|
39
|
+
return originalSend.call(this, body);
|
|
40
|
+
};
|
|
41
|
+
const result = yield originalMethod.apply(this, [req, res, ...args]);
|
|
42
|
+
return result;
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
return descriptor;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
exports.cached = cached;
|
|
49
|
+
function sortObject(obj) {
|
|
50
|
+
return Object.keys(obj)
|
|
51
|
+
.sort()
|
|
52
|
+
.reduce((sorted, key) => {
|
|
53
|
+
sorted[key] = obj[key];
|
|
54
|
+
return sorted;
|
|
55
|
+
}, {});
|
|
56
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteAllCacheEntriesByPathName = exports.deleteCacheEntry = exports.deleteAllCacheEntries = void 0;
|
|
4
|
+
var cache = require('memory-cache');
|
|
5
|
+
function deleteAllCacheEntries() {
|
|
6
|
+
cache.clear();
|
|
7
|
+
}
|
|
8
|
+
exports.deleteAllCacheEntries = deleteAllCacheEntries;
|
|
9
|
+
function deleteCacheEntry(key) {
|
|
10
|
+
cache.del(key);
|
|
11
|
+
}
|
|
12
|
+
exports.deleteCacheEntry = deleteCacheEntry;
|
|
13
|
+
function deleteAllCacheEntriesByPathName(pathName) {
|
|
14
|
+
const cacheEntriesKeys = cache.keys();
|
|
15
|
+
cacheEntriesKeys.forEach((cacheEntryKey) => {
|
|
16
|
+
const parsedKey = cacheEntryKey.split('_');
|
|
17
|
+
const cachedPathName = parsedKey[0];
|
|
18
|
+
if (pathName === cachedPathName) {
|
|
19
|
+
cache.del(cacheEntryKey);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
exports.deleteAllCacheEntriesByPathName = deleteAllCacheEntriesByPathName;
|
|
@@ -333,6 +333,10 @@ export interface IVirtualValue {
|
|
|
333
333
|
* 3) array: If this field is an array
|
|
334
334
|
*/
|
|
335
335
|
type: VirtualFieldTypes;
|
|
336
|
+
/**
|
|
337
|
+
* Specify the key that should be filtered by in case of 1 to many realtionship
|
|
338
|
+
*/
|
|
339
|
+
filterBy?: string;
|
|
336
340
|
/**
|
|
337
341
|
* Array type exists only if the type is array
|
|
338
342
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "identity-admin",
|
|
3
|
-
"version": "1.26.
|
|
3
|
+
"version": "1.26.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/Dashboard.js",
|
|
6
6
|
"types": "lib/Dashbord.d.ts",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"cookie-parser": "^1.4.6",
|
|
49
49
|
"express-session": "^1.17.3",
|
|
50
50
|
"lodash": "^4.17.21",
|
|
51
|
+
"memory-cache": "^0.2.0",
|
|
51
52
|
"node-xlsx": "^0.21.0",
|
|
52
53
|
"passport": "^0.6.0",
|
|
53
54
|
"passport-local": "^1.0.0",
|