identity-admin 1.26.1 → 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.
|
@@ -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;
|
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",
|