mvc-common-toolkit 1.43.8 → 1.43.10
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/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/src/constants.d.ts +0 -42
- package/dist/src/constants.js +0 -50
- package/dist/src/constants.js.map +0 -1
- package/dist/src/gateways/alibaba-cloud-gateway.d.ts +0 -30
- package/dist/src/gateways/alibaba-cloud-gateway.js +0 -120
- package/dist/src/gateways/alibaba-cloud-gateway.js.map +0 -1
- package/dist/src/gateways/http-audit-gateway.d.ts +0 -20
- package/dist/src/gateways/http-audit-gateway.js +0 -76
- package/dist/src/gateways/http-audit-gateway.js.map +0 -1
- package/dist/src/gateways/index.d.ts +0 -5
- package/dist/src/gateways/index.js +0 -22
- package/dist/src/gateways/index.js.map +0 -1
- package/dist/src/gateways/internal-auth-gateway.d.ts +0 -8
- package/dist/src/gateways/internal-auth-gateway.js +0 -40
- package/dist/src/gateways/internal-auth-gateway.js.map +0 -1
- package/dist/src/gateways/stdout-audit-gateway.d.ts +0 -7
- package/dist/src/gateways/stdout-audit-gateway.js +0 -25
- package/dist/src/gateways/stdout-audit-gateway.js.map +0 -1
- package/dist/src/gateways/webhook-audit-gateway.d.ts +0 -14
- package/dist/src/gateways/webhook-audit-gateway.js +0 -27
- package/dist/src/gateways/webhook-audit-gateway.js.map +0 -1
- package/dist/src/interfaces.d.ts +0 -215
- package/dist/src/interfaces.js +0 -3
- package/dist/src/interfaces.js.map +0 -1
- package/dist/src/models/audit-log.d.ts +0 -77
- package/dist/src/models/audit-log.js +0 -92
- package/dist/src/models/audit-log.js.map +0 -1
- package/dist/src/models/index.d.ts +0 -1
- package/dist/src/models/index.js +0 -18
- package/dist/src/models/index.js.map +0 -1
- package/dist/src/pkg/array-helper.d.ts +0 -1
- package/dist/src/pkg/array-helper.js +0 -12
- package/dist/src/pkg/array-helper.js.map +0 -1
- package/dist/src/pkg/bcrypt-helper.d.ts +0 -2
- package/dist/src/pkg/bcrypt-helper.js +0 -36
- package/dist/src/pkg/bcrypt-helper.js.map +0 -1
- package/dist/src/pkg/crypto-helper.d.ts +0 -2
- package/dist/src/pkg/crypto-helper.js +0 -16
- package/dist/src/pkg/crypto-helper.js.map +0 -1
- package/dist/src/pkg/encryption-helper.d.ts +0 -18
- package/dist/src/pkg/encryption-helper.js +0 -89
- package/dist/src/pkg/encryption-helper.js.map +0 -1
- package/dist/src/pkg/encryption-helper.spec.d.ts +0 -1
- package/dist/src/pkg/encryption-helper.spec.js +0 -238
- package/dist/src/pkg/encryption-helper.spec.js.map +0 -1
- package/dist/src/pkg/filter-helper.d.ts +0 -2
- package/dist/src/pkg/filter-helper.js +0 -102
- package/dist/src/pkg/filter-helper.js.map +0 -1
- package/dist/src/pkg/filter-helper.spec.d.ts +0 -1
- package/dist/src/pkg/filter-helper.spec.js +0 -94
- package/dist/src/pkg/filter-helper.spec.js.map +0 -1
- package/dist/src/pkg/geoip-helper.d.ts +0 -2
- package/dist/src/pkg/geoip-helper.js +0 -32
- package/dist/src/pkg/geoip-helper.js.map +0 -1
- package/dist/src/pkg/hash-helper.d.ts +0 -1
- package/dist/src/pkg/hash-helper.js +0 -37
- package/dist/src/pkg/hash-helper.js.map +0 -1
- package/dist/src/pkg/http-request-utils.d.ts +0 -4
- package/dist/src/pkg/http-request-utils.js +0 -55
- package/dist/src/pkg/http-request-utils.js.map +0 -1
- package/dist/src/pkg/index.d.ts +0 -18
- package/dist/src/pkg/index.js +0 -45
- package/dist/src/pkg/index.js.map +0 -1
- package/dist/src/pkg/key-helper.d.ts +0 -2
- package/dist/src/pkg/key-helper.js +0 -20
- package/dist/src/pkg/key-helper.js.map +0 -1
- package/dist/src/pkg/logger.d.ts +0 -9
- package/dist/src/pkg/logger.js +0 -23
- package/dist/src/pkg/logger.js.map +0 -1
- package/dist/src/pkg/object-helper.d.ts +0 -2
- package/dist/src/pkg/object-helper.js +0 -37
- package/dist/src/pkg/object-helper.js.map +0 -1
- package/dist/src/pkg/paginated-cache-registry.d.ts +0 -8
- package/dist/src/pkg/paginated-cache-registry.js +0 -23
- package/dist/src/pkg/paginated-cache-registry.js.map +0 -1
- package/dist/src/pkg/query-helper.d.ts +0 -3
- package/dist/src/pkg/query-helper.js +0 -60
- package/dist/src/pkg/query-helper.js.map +0 -1
- package/dist/src/pkg/referral-tree-utils.d.ts +0 -33
- package/dist/src/pkg/referral-tree-utils.js +0 -71
- package/dist/src/pkg/referral-tree-utils.js.map +0 -1
- package/dist/src/pkg/scripts/index.d.ts +0 -1
- package/dist/src/pkg/scripts/index.js +0 -28
- package/dist/src/pkg/scripts/index.js.map +0 -1
- package/dist/src/pkg/scripts/lua.d.ts +0 -10
- package/dist/src/pkg/scripts/lua.js +0 -109
- package/dist/src/pkg/scripts/lua.js.map +0 -1
- package/dist/src/pkg/sort-helper.d.ts +0 -3
- package/dist/src/pkg/sort-helper.js +0 -18
- package/dist/src/pkg/sort-helper.js.map +0 -1
- package/dist/src/pkg/string-utils.d.ts +0 -10
- package/dist/src/pkg/string-utils.js +0 -79
- package/dist/src/pkg/string-utils.js.map +0 -1
- package/dist/src/pkg/task-helper.d.ts +0 -2
- package/dist/src/pkg/task-helper.js +0 -30
- package/dist/src/pkg/task-helper.js.map +0 -1
- package/dist/src/pkg/workflow/delayed-task-registry.d.ts +0 -10
- package/dist/src/pkg/workflow/delayed-task-registry.js +0 -67
- package/dist/src/pkg/workflow/delayed-task-registry.js.map +0 -1
- package/dist/src/pkg/workflow/delayed-task.d.ts +0 -18
- package/dist/src/pkg/workflow/delayed-task.js +0 -95
- package/dist/src/pkg/workflow/delayed-task.js.map +0 -1
- package/dist/src/pkg/workflow/index.d.ts +0 -5
- package/dist/src/pkg/workflow/index.js +0 -22
- package/dist/src/pkg/workflow/index.js.map +0 -1
- package/dist/src/pkg/workflow/processing-milestone.d.ts +0 -18
- package/dist/src/pkg/workflow/processing-milestone.js +0 -39
- package/dist/src/pkg/workflow/processing-milestone.js.map +0 -1
- package/dist/src/pkg/workflow/retry-task.d.ts +0 -24
- package/dist/src/pkg/workflow/retry-task.js +0 -89
- package/dist/src/pkg/workflow/retry-task.js.map +0 -1
- package/dist/src/pkg/workflow/retry-task.spec.d.ts +0 -1
- package/dist/src/pkg/workflow/retry-task.spec.js +0 -145
- package/dist/src/pkg/workflow/retry-task.spec.js.map +0 -1
- package/dist/src/pkg/workflow/sync-taskqueue.d.ts +0 -32
- package/dist/src/pkg/workflow/sync-taskqueue.js +0 -108
- package/dist/src/pkg/workflow/sync-taskqueue.js.map +0 -1
- package/dist/src/pkg/worksheet.utils.d.ts +0 -27
- package/dist/src/pkg/worksheet.utils.js +0 -116
- package/dist/src/pkg/worksheet.utils.js.map +0 -1
- package/dist/src/services/audit-service.d.ts +0 -7
- package/dist/src/services/audit-service.js +0 -32
- package/dist/src/services/audit-service.js.map +0 -1
- package/dist/src/services/excel.service.d.ts +0 -25
- package/dist/src/services/excel.service.js +0 -95
- package/dist/src/services/excel.service.js.map +0 -1
- package/dist/src/services/http-service.d.ts +0 -7
- package/dist/src/services/http-service.js +0 -67
- package/dist/src/services/http-service.js.map +0 -1
- package/dist/src/services/index.d.ts +0 -8
- package/dist/src/services/index.js +0 -25
- package/dist/src/services/index.js.map +0 -1
- package/dist/src/services/kafka-service.d.ts +0 -15
- package/dist/src/services/kafka-service.js +0 -68
- package/dist/src/services/kafka-service.js.map +0 -1
- package/dist/src/services/mailer-service.d.ts +0 -15
- package/dist/src/services/mailer-service.js +0 -44
- package/dist/src/services/mailer-service.js.map +0 -1
- package/dist/src/services/paginated-cache.d.ts +0 -16
- package/dist/src/services/paginated-cache.js +0 -115
- package/dist/src/services/paginated-cache.js.map +0 -1
- package/dist/src/services/paginated-cache.spec.d.ts +0 -1
- package/dist/src/services/paginated-cache.spec.js +0 -284
- package/dist/src/services/paginated-cache.spec.js.map +0 -1
- package/dist/src/services/redis-service.d.ts +0 -33
- package/dist/src/services/redis-service.js +0 -216
- package/dist/src/services/redis-service.js.map +0 -1
- package/dist/src/services/security-service.d.ts +0 -11
- package/dist/src/services/security-service.js +0 -68
- package/dist/src/services/security-service.js.map +0 -1
|
@@ -1,216 +0,0 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.RedisService = void 0;
|
|
36
|
-
const ioredis = __importStar(require("ioredis"));
|
|
37
|
-
const constants_1 = require("../constants");
|
|
38
|
-
class RedisService {
|
|
39
|
-
constructor(config) {
|
|
40
|
-
this._redis = new ioredis.Redis(config);
|
|
41
|
-
}
|
|
42
|
-
get(key) {
|
|
43
|
-
return this._redis.get(key);
|
|
44
|
-
}
|
|
45
|
-
getNumber(key) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
const result = yield this._redis.get(key);
|
|
48
|
-
if (result === null) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
return this.convertToNumber(result);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
deleteByPattern(pattern) {
|
|
55
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
let cursor = "0";
|
|
57
|
-
do {
|
|
58
|
-
const [nextCursor, keys] = yield this._redis.scan(cursor, "MATCH", pattern, "COUNT", 100);
|
|
59
|
-
cursor = nextCursor;
|
|
60
|
-
if (keys.length > 0) {
|
|
61
|
-
yield this._redis.del(...keys);
|
|
62
|
-
}
|
|
63
|
-
} while (cursor !== "0");
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
del(...keys) {
|
|
67
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
yield this._redis.del(...keys);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
multiEval(calls) {
|
|
72
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
const multi = this._redis.multi();
|
|
74
|
-
for (const [script, numberOfKeys, ...params] of calls) {
|
|
75
|
-
if (numberOfKeys !== params.slice(0, numberOfKeys).length) {
|
|
76
|
-
throw new Error(`numberOfKeys (${numberOfKeys}) does not match key count in params`);
|
|
77
|
-
}
|
|
78
|
-
multi.eval(script, numberOfKeys, ...params);
|
|
79
|
-
}
|
|
80
|
-
const execResult = yield multi.exec();
|
|
81
|
-
for (const [err] of execResult) {
|
|
82
|
-
if (err)
|
|
83
|
-
throw err;
|
|
84
|
-
}
|
|
85
|
-
return execResult.map(([, value]) => value);
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
eval(script, numberOfKeys, ...args) {
|
|
89
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
return this._redis.eval(script, numberOfKeys, ...args);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
hset(key, field, value) {
|
|
94
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
-
yield this._redis.hset(key, {
|
|
96
|
-
[field]: value,
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
lpush(key, value) {
|
|
101
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
yield this._redis.lpush(key, value);
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
lrem(key, count, element) {
|
|
106
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
-
return this._redis.lrem(key, count, element);
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
rpush(key, value) {
|
|
111
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
yield this._redis.rpush(key, value);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
lset(key, index, value) {
|
|
116
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
-
yield this._redis.lset(key, index, value);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
lrange(key, start, end) {
|
|
121
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
-
return this._redis.lrange(key, start, end);
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
lindex(key, index) {
|
|
126
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
-
return this._redis.lindex(key, index);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
llen(key) {
|
|
131
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
return this._redis.llen(key);
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
hget(key, field) {
|
|
136
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
return this._redis.hget(key, field);
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
hincrby(key, field, value = 1) {
|
|
141
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
return this._redis.hincrby(key, field, value);
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
hincrbyfloat(key, field, value = 1) {
|
|
146
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
return this._redis.hincrbyfloat(key, field, value);
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
hkeys(key) {
|
|
151
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
-
return this._redis.hkeys(key);
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
ttl(key) {
|
|
156
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
-
return this._redis.ttl(key);
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
hlen(key) {
|
|
161
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
-
return this._redis.hlen(key);
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
set(key, value, option) {
|
|
166
|
-
if (!option) {
|
|
167
|
-
return this._redis.set(key, value);
|
|
168
|
-
}
|
|
169
|
-
switch (option.policy) {
|
|
170
|
-
case constants_1.SET_CACHE_POLICY.WITH_TTL:
|
|
171
|
-
return this._redis.set(key, value, "EX", option.value);
|
|
172
|
-
case constants_1.SET_CACHE_POLICY.KEEP_TTL:
|
|
173
|
-
return this._redis.set(key, value, "KEEPTTL");
|
|
174
|
-
case constants_1.SET_CACHE_POLICY.IF_EXISTS:
|
|
175
|
-
return option.value
|
|
176
|
-
? this._redis.set(key, value, "EX", option.value, "XX")
|
|
177
|
-
: this._redis.set(key, value, "XX");
|
|
178
|
-
case constants_1.SET_CACHE_POLICY.IF_NOT_EXISTS:
|
|
179
|
-
return option.value
|
|
180
|
-
? this._redis.set(key, value, "EX", option.value, "NX")
|
|
181
|
-
: this._redis.set(key, value, "NX");
|
|
182
|
-
default:
|
|
183
|
-
throw new Error("policy not supported");
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
incrBy(key, value = 1) {
|
|
187
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
const result = yield this._redis.incrby(key, value);
|
|
189
|
-
return this.convertToNumber(result);
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
convertToNumber(value) {
|
|
193
|
-
const number = parseFloat(value);
|
|
194
|
-
if (isNaN(number)) {
|
|
195
|
-
throw new Error(`Value "${value}" is not a valid number.`);
|
|
196
|
-
}
|
|
197
|
-
return number;
|
|
198
|
-
}
|
|
199
|
-
expire(key, ttl) {
|
|
200
|
-
return this._redis.expire(key, ttl);
|
|
201
|
-
}
|
|
202
|
-
incrByFloat(key, value) {
|
|
203
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
-
const result = yield this._redis.incrbyfloat(key, value);
|
|
205
|
-
return this.convertToNumber(result);
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
decrBy(key, value = 1) {
|
|
209
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
210
|
-
const result = yield this._redis.decrby(key, value);
|
|
211
|
-
return this.convertToNumber(result);
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
exports.RedisService = RedisService;
|
|
216
|
-
//# sourceMappingURL=redis-service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"redis-service.js","sourceRoot":"","sources":["../../../src/services/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-1,11 +0,0 @@
|
|
|
1
|
-
import { CRUDService, CacheService, LockResult, OperationResult } from "../interfaces";
|
|
2
|
-
export declare class SecurityService {
|
|
3
|
-
protected cacheService: CacheService;
|
|
4
|
-
protected userService: CRUDService;
|
|
5
|
-
constructor(cacheService: CacheService, userService: CRUDService);
|
|
6
|
-
static LIMIT_TO_LOCK_USER: number;
|
|
7
|
-
static genLockUserCacheKey(userId: number): string;
|
|
8
|
-
addFailureCount(userId: number, cacheKey?: string): Promise<number>;
|
|
9
|
-
clearFailureCount(userId: number, cacheKey?: string): Promise<void>;
|
|
10
|
-
shouldLockUser(userId: number, cacheKey?: string): Promise<OperationResult<LockResult>>;
|
|
11
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
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.SecurityService = void 0;
|
|
13
|
-
class SecurityService {
|
|
14
|
-
constructor(cacheService, userService) {
|
|
15
|
-
this.cacheService = cacheService;
|
|
16
|
-
this.userService = userService;
|
|
17
|
-
}
|
|
18
|
-
static genLockUserCacheKey(userId) {
|
|
19
|
-
return `user:${userId}:lock`;
|
|
20
|
-
}
|
|
21
|
-
addFailureCount(userId, cacheKey) {
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const finalCacheKey = cacheKey || SecurityService.genLockUserCacheKey(userId);
|
|
24
|
-
yield this.cacheService.incrBy(finalCacheKey);
|
|
25
|
-
return this.cacheService.get(finalCacheKey);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
clearFailureCount(userId, cacheKey) {
|
|
29
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
const finalCacheKey = cacheKey || SecurityService.genLockUserCacheKey(userId);
|
|
31
|
-
yield this.cacheService.del(finalCacheKey);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
shouldLockUser(userId, cacheKey) {
|
|
35
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
try {
|
|
37
|
-
const incrementedAttemptsCount = yield this.addFailureCount(userId, cacheKey);
|
|
38
|
-
if (incrementedAttemptsCount >= SecurityService.LIMIT_TO_LOCK_USER) {
|
|
39
|
-
yield this.clearFailureCount(userId);
|
|
40
|
-
return {
|
|
41
|
-
success: true,
|
|
42
|
-
data: {
|
|
43
|
-
isLocked: true,
|
|
44
|
-
attemptsLeft: 0,
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
success: true,
|
|
50
|
-
data: {
|
|
51
|
-
isLocked: false,
|
|
52
|
-
attemptsLeft: Math.max(0, SecurityService.LIMIT_TO_LOCK_USER - incrementedAttemptsCount),
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
return {
|
|
58
|
-
success: false,
|
|
59
|
-
message: error.message,
|
|
60
|
-
metadata: error.stack,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
SecurityService.LIMIT_TO_LOCK_USER = 5;
|
|
67
|
-
exports.SecurityService = SecurityService;
|
|
68
|
-
//# sourceMappingURL=security-service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":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