@jpbs/common 1.1.7 → 1.2.0

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/index.d.ts CHANGED
@@ -9,3 +9,4 @@ export * from './middlewares/authProtect';
9
9
  export * from './middlewares/errorHandler';
10
10
  export * from './middlewares/validateRequest';
11
11
  export * from './middlewares/verifyGatewayToken';
12
+ export * from './redisClient';
package/build/index.js CHANGED
@@ -25,3 +25,4 @@ __exportStar(require("./middlewares/authProtect"), exports);
25
25
  __exportStar(require("./middlewares/errorHandler"), exports);
26
26
  __exportStar(require("./middlewares/validateRequest"), exports);
27
27
  __exportStar(require("./middlewares/verifyGatewayToken"), exports);
28
+ __exportStar(require("./redisClient"), exports);
@@ -12,5 +12,5 @@ interface IDecodedUser {
12
12
  username: string;
13
13
  role: Role;
14
14
  }
15
- export declare const authenticationGuard: (jwtSecret: string) => (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
15
+ export declare const authenticationGuard: (jwtSecret: string) => (req: AuthenticatedRequest, res: Response, next: NextFunction) => Promise<Response<any, Record<string, any>> | undefined>;
16
16
  export {};
@@ -1,4 +1,13 @@
1
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
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
@@ -6,17 +15,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
15
  exports.authenticationGuard = exports.Role = void 0;
7
16
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
17
  const http_status_codes_1 = require("http-status-codes");
18
+ const redisClient_1 = require("../redisClient");
9
19
  var Role;
10
20
  (function (Role) {
11
21
  Role["ADMINISTRATOR"] = "Administrator";
12
22
  Role["USER"] = "User";
13
23
  })(Role || (exports.Role = Role = {}));
14
- const authenticationGuard = (jwtSecret) => (req, res, next) => {
24
+ const authenticationGuard = (jwtSecret) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
15
25
  try {
16
26
  const token = req.cookies.auth_token;
17
27
  if (!token) {
18
- res.status(http_status_codes_1.StatusCodes.UNAUTHORIZED).json({ error: "Unauthorized" });
19
- return;
28
+ return res.status(http_status_codes_1.StatusCodes.UNAUTHORIZED).json({ error: "Unauthorized" });
29
+ }
30
+ const isRevoked = yield (0, redisClient_1.isTokenRevoked)(token);
31
+ if (isRevoked) {
32
+ return res.status(http_status_codes_1.StatusCodes.UNAUTHORIZED).json({ error: "Token has been revoked" });
20
33
  }
21
34
  const decoded = jsonwebtoken_1.default.verify(token, jwtSecret);
22
35
  req.currentUser = decoded;
@@ -25,5 +38,5 @@ const authenticationGuard = (jwtSecret) => (req, res, next) => {
25
38
  catch (error) {
26
39
  res.status(http_status_codes_1.StatusCodes.UNAUTHORIZED).json({ error: "Invalid or expired token" });
27
40
  }
28
- };
41
+ });
29
42
  exports.authenticationGuard = authenticationGuard;
@@ -5,14 +5,18 @@ const axios_1 = require("axios");
5
5
  const custom_error_1 = require("../errors/custom-error");
6
6
  const http_status_codes_1 = require("http-status-codes");
7
7
  const errorHandler = (err, _req, res, _next) => {
8
- var _a, _b;
8
+ var _a;
9
9
  if (err instanceof custom_error_1.CustomError) {
10
10
  res.status(err.statusCode).send({ errors: err.serializeErrors() });
11
11
  return;
12
12
  }
13
13
  if (err instanceof axios_1.AxiosError) {
14
- const message = ((_b = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) || 'An error occurred with the external service';
15
- res.status(http_status_codes_1.StatusCodes.BAD_GATEWAY).send({ errors: [{ message }] });
14
+ if (err.response && err.response.data && err.response.data.errors) {
15
+ const message = ((_a = err.response.data.errors[0]) === null || _a === void 0 ? void 0 : _a.message) || 'An error';
16
+ res.status(http_status_codes_1.StatusCodes.BAD_GATEWAY).send({ errors: [{ message }] });
17
+ return;
18
+ }
19
+ res.status(http_status_codes_1.StatusCodes.BAD_GATEWAY).send({ errors: [{ message: 'An error occurred with the external service' }] });
16
20
  return;
17
21
  }
18
22
  res.status(http_status_codes_1.StatusCodes.BAD_REQUEST).send({ errors: [{ message: 'Something went wrong' }] });
@@ -0,0 +1,294 @@
1
+ declare const redisClient: import("@redis/client").RedisClientType<{
2
+ graph: {
3
+ CONFIG_GET: typeof import("@redis/graph/dist/commands/CONFIG_GET");
4
+ configGet: typeof import("@redis/graph/dist/commands/CONFIG_GET");
5
+ CONFIG_SET: typeof import("@redis/graph/dist/commands/CONFIG_SET");
6
+ configSet: typeof import("@redis/graph/dist/commands/CONFIG_SET");
7
+ DELETE: typeof import("@redis/graph/dist/commands/DELETE");
8
+ delete: typeof import("@redis/graph/dist/commands/DELETE");
9
+ EXPLAIN: typeof import("@redis/graph/dist/commands/EXPLAIN");
10
+ explain: typeof import("@redis/graph/dist/commands/EXPLAIN");
11
+ LIST: typeof import("@redis/graph/dist/commands/LIST");
12
+ list: typeof import("@redis/graph/dist/commands/LIST");
13
+ PROFILE: typeof import("@redis/graph/dist/commands/PROFILE");
14
+ profile: typeof import("@redis/graph/dist/commands/PROFILE");
15
+ QUERY: typeof import("@redis/graph/dist/commands/QUERY");
16
+ query: typeof import("@redis/graph/dist/commands/QUERY");
17
+ RO_QUERY: typeof import("@redis/graph/dist/commands/RO_QUERY");
18
+ roQuery: typeof import("@redis/graph/dist/commands/RO_QUERY");
19
+ SLOWLOG: typeof import("@redis/graph/dist/commands/SLOWLOG");
20
+ slowLog: typeof import("@redis/graph/dist/commands/SLOWLOG");
21
+ };
22
+ json: {
23
+ ARRAPPEND: typeof import("@redis/json/dist/commands/ARRAPPEND");
24
+ arrAppend: typeof import("@redis/json/dist/commands/ARRAPPEND");
25
+ ARRINDEX: typeof import("@redis/json/dist/commands/ARRINDEX");
26
+ arrIndex: typeof import("@redis/json/dist/commands/ARRINDEX");
27
+ ARRINSERT: typeof import("@redis/json/dist/commands/ARRINSERT");
28
+ arrInsert: typeof import("@redis/json/dist/commands/ARRINSERT");
29
+ ARRLEN: typeof import("@redis/json/dist/commands/ARRLEN");
30
+ arrLen: typeof import("@redis/json/dist/commands/ARRLEN");
31
+ ARRPOP: typeof import("@redis/json/dist/commands/ARRPOP");
32
+ arrPop: typeof import("@redis/json/dist/commands/ARRPOP");
33
+ ARRTRIM: typeof import("@redis/json/dist/commands/ARRTRIM");
34
+ arrTrim: typeof import("@redis/json/dist/commands/ARRTRIM");
35
+ DEBUG_MEMORY: typeof import("@redis/json/dist/commands/DEBUG_MEMORY");
36
+ debugMemory: typeof import("@redis/json/dist/commands/DEBUG_MEMORY");
37
+ DEL: typeof import("@redis/json/dist/commands/DEL");
38
+ del: typeof import("@redis/json/dist/commands/DEL");
39
+ FORGET: typeof import("@redis/json/dist/commands/FORGET");
40
+ forget: typeof import("@redis/json/dist/commands/FORGET");
41
+ GET: typeof import("@redis/json/dist/commands/GET");
42
+ get: typeof import("@redis/json/dist/commands/GET");
43
+ MERGE: typeof import("@redis/json/dist/commands/MERGE");
44
+ merge: typeof import("@redis/json/dist/commands/MERGE");
45
+ MGET: typeof import("@redis/json/dist/commands/MGET");
46
+ mGet: typeof import("@redis/json/dist/commands/MGET");
47
+ MSET: typeof import("@redis/json/dist/commands/MSET");
48
+ mSet: typeof import("@redis/json/dist/commands/MSET");
49
+ NUMINCRBY: typeof import("@redis/json/dist/commands/NUMINCRBY");
50
+ numIncrBy: typeof import("@redis/json/dist/commands/NUMINCRBY");
51
+ NUMMULTBY: typeof import("@redis/json/dist/commands/NUMMULTBY");
52
+ numMultBy: typeof import("@redis/json/dist/commands/NUMMULTBY");
53
+ OBJKEYS: typeof import("@redis/json/dist/commands/OBJKEYS");
54
+ objKeys: typeof import("@redis/json/dist/commands/OBJKEYS");
55
+ OBJLEN: typeof import("@redis/json/dist/commands/OBJLEN");
56
+ objLen: typeof import("@redis/json/dist/commands/OBJLEN");
57
+ RESP: typeof import("@redis/json/dist/commands/RESP");
58
+ resp: typeof import("@redis/json/dist/commands/RESP");
59
+ SET: typeof import("@redis/json/dist/commands/SET");
60
+ set: typeof import("@redis/json/dist/commands/SET");
61
+ STRAPPEND: typeof import("@redis/json/dist/commands/STRAPPEND");
62
+ strAppend: typeof import("@redis/json/dist/commands/STRAPPEND");
63
+ STRLEN: typeof import("@redis/json/dist/commands/STRLEN");
64
+ strLen: typeof import("@redis/json/dist/commands/STRLEN");
65
+ TYPE: typeof import("@redis/json/dist/commands/TYPE");
66
+ type: typeof import("@redis/json/dist/commands/TYPE");
67
+ };
68
+ ft: {
69
+ _LIST: typeof import("@redis/search/dist/commands/_LIST");
70
+ _list: typeof import("@redis/search/dist/commands/_LIST");
71
+ ALTER: typeof import("@redis/search/dist/commands/ALTER");
72
+ alter: typeof import("@redis/search/dist/commands/ALTER");
73
+ AGGREGATE_WITHCURSOR: typeof import("@redis/search/dist/commands/AGGREGATE_WITHCURSOR");
74
+ aggregateWithCursor: typeof import("@redis/search/dist/commands/AGGREGATE_WITHCURSOR");
75
+ AGGREGATE: typeof import("@redis/search/dist/commands/AGGREGATE");
76
+ aggregate: typeof import("@redis/search/dist/commands/AGGREGATE");
77
+ ALIASADD: typeof import("@redis/search/dist/commands/ALIASADD");
78
+ aliasAdd: typeof import("@redis/search/dist/commands/ALIASADD");
79
+ ALIASDEL: typeof import("@redis/search/dist/commands/ALIASDEL");
80
+ aliasDel: typeof import("@redis/search/dist/commands/ALIASDEL");
81
+ ALIASUPDATE: typeof import("@redis/search/dist/commands/ALIASUPDATE");
82
+ aliasUpdate: typeof import("@redis/search/dist/commands/ALIASUPDATE");
83
+ CONFIG_GET: typeof import("@redis/search/dist/commands/CONFIG_GET");
84
+ configGet: typeof import("@redis/search/dist/commands/CONFIG_GET");
85
+ CONFIG_SET: typeof import("@redis/search/dist/commands/CONFIG_SET");
86
+ configSet: typeof import("@redis/search/dist/commands/CONFIG_SET");
87
+ CREATE: typeof import("@redis/search/dist/commands/CREATE");
88
+ create: typeof import("@redis/search/dist/commands/CREATE");
89
+ CURSOR_DEL: typeof import("@redis/search/dist/commands/CURSOR_DEL");
90
+ cursorDel: typeof import("@redis/search/dist/commands/CURSOR_DEL");
91
+ CURSOR_READ: typeof import("@redis/search/dist/commands/CURSOR_READ");
92
+ cursorRead: typeof import("@redis/search/dist/commands/CURSOR_READ");
93
+ DICTADD: typeof import("@redis/search/dist/commands/DICTADD");
94
+ dictAdd: typeof import("@redis/search/dist/commands/DICTADD");
95
+ DICTDEL: typeof import("@redis/search/dist/commands/DICTDEL");
96
+ dictDel: typeof import("@redis/search/dist/commands/DICTDEL");
97
+ DICTDUMP: typeof import("@redis/search/dist/commands/DICTDUMP");
98
+ dictDump: typeof import("@redis/search/dist/commands/DICTDUMP");
99
+ DROPINDEX: typeof import("@redis/search/dist/commands/DROPINDEX");
100
+ dropIndex: typeof import("@redis/search/dist/commands/DROPINDEX");
101
+ EXPLAIN: typeof import("@redis/search/dist/commands/EXPLAIN");
102
+ explain: typeof import("@redis/search/dist/commands/EXPLAIN");
103
+ EXPLAINCLI: typeof import("@redis/search/dist/commands/EXPLAINCLI");
104
+ explainCli: typeof import("@redis/search/dist/commands/EXPLAINCLI");
105
+ INFO: typeof import("@redis/search/dist/commands/INFO");
106
+ info: typeof import("@redis/search/dist/commands/INFO");
107
+ PROFILESEARCH: typeof import("@redis/search/dist/commands/PROFILE_SEARCH");
108
+ profileSearch: typeof import("@redis/search/dist/commands/PROFILE_SEARCH");
109
+ PROFILEAGGREGATE: typeof import("@redis/search/dist/commands/PROFILE_AGGREGATE");
110
+ profileAggregate: typeof import("@redis/search/dist/commands/PROFILE_AGGREGATE");
111
+ SEARCH: typeof import("@redis/search/dist/commands/SEARCH");
112
+ search: typeof import("@redis/search/dist/commands/SEARCH");
113
+ SEARCH_NOCONTENT: typeof import("@redis/search/dist/commands/SEARCH_NOCONTENT");
114
+ searchNoContent: typeof import("@redis/search/dist/commands/SEARCH_NOCONTENT");
115
+ SPELLCHECK: typeof import("@redis/search/dist/commands/SPELLCHECK");
116
+ spellCheck: typeof import("@redis/search/dist/commands/SPELLCHECK");
117
+ SUGADD: typeof import("@redis/search/dist/commands/SUGADD");
118
+ sugAdd: typeof import("@redis/search/dist/commands/SUGADD");
119
+ SUGDEL: typeof import("@redis/search/dist/commands/SUGDEL");
120
+ sugDel: typeof import("@redis/search/dist/commands/SUGDEL");
121
+ SUGGET_WITHPAYLOADS: typeof import("@redis/search/dist/commands/SUGGET_WITHPAYLOADS");
122
+ sugGetWithPayloads: typeof import("@redis/search/dist/commands/SUGGET_WITHPAYLOADS");
123
+ SUGGET_WITHSCORES_WITHPAYLOADS: typeof import("@redis/search/dist/commands/SUGGET_WITHSCORES_WITHPAYLOADS");
124
+ sugGetWithScoresWithPayloads: typeof import("@redis/search/dist/commands/SUGGET_WITHSCORES_WITHPAYLOADS");
125
+ SUGGET_WITHSCORES: typeof import("@redis/search/dist/commands/SUGGET_WITHSCORES");
126
+ sugGetWithScores: typeof import("@redis/search/dist/commands/SUGGET_WITHSCORES");
127
+ SUGGET: typeof import("@redis/search/dist/commands/SUGGET");
128
+ sugGet: typeof import("@redis/search/dist/commands/SUGGET");
129
+ SUGLEN: typeof import("@redis/search/dist/commands/SUGLEN");
130
+ sugLen: typeof import("@redis/search/dist/commands/SUGLEN");
131
+ SYNDUMP: typeof import("@redis/search/dist/commands/SYNDUMP");
132
+ synDump: typeof import("@redis/search/dist/commands/SYNDUMP");
133
+ SYNUPDATE: typeof import("@redis/search/dist/commands/SYNUPDATE");
134
+ synUpdate: typeof import("@redis/search/dist/commands/SYNUPDATE");
135
+ TAGVALS: typeof import("@redis/search/dist/commands/TAGVALS");
136
+ tagVals: typeof import("@redis/search/dist/commands/TAGVALS");
137
+ };
138
+ ts: {
139
+ ADD: typeof import("@redis/time-series/dist/commands/ADD");
140
+ add: typeof import("@redis/time-series/dist/commands/ADD");
141
+ ALTER: typeof import("@redis/time-series/dist/commands/ALTER");
142
+ alter: typeof import("@redis/time-series/dist/commands/ALTER");
143
+ CREATE: typeof import("@redis/time-series/dist/commands/CREATE");
144
+ create: typeof import("@redis/time-series/dist/commands/CREATE");
145
+ CREATERULE: typeof import("@redis/time-series/dist/commands/CREATERULE");
146
+ createRule: typeof import("@redis/time-series/dist/commands/CREATERULE");
147
+ DECRBY: typeof import("@redis/time-series/dist/commands/DECRBY");
148
+ decrBy: typeof import("@redis/time-series/dist/commands/DECRBY");
149
+ DEL: typeof import("@redis/time-series/dist/commands/DEL");
150
+ del: typeof import("@redis/time-series/dist/commands/DEL");
151
+ DELETERULE: typeof import("@redis/time-series/dist/commands/DELETERULE");
152
+ deleteRule: typeof import("@redis/time-series/dist/commands/DELETERULE");
153
+ GET: typeof import("@redis/time-series/dist/commands/GET");
154
+ get: typeof import("@redis/time-series/dist/commands/GET");
155
+ INCRBY: typeof import("@redis/time-series/dist/commands/INCRBY");
156
+ incrBy: typeof import("@redis/time-series/dist/commands/INCRBY");
157
+ INFO_DEBUG: typeof import("@redis/time-series/dist/commands/INFO_DEBUG");
158
+ infoDebug: typeof import("@redis/time-series/dist/commands/INFO_DEBUG");
159
+ INFO: typeof import("@redis/time-series/dist/commands/INFO");
160
+ info: typeof import("@redis/time-series/dist/commands/INFO");
161
+ MADD: typeof import("@redis/time-series/dist/commands/MADD");
162
+ mAdd: typeof import("@redis/time-series/dist/commands/MADD");
163
+ MGET: typeof import("@redis/time-series/dist/commands/MGET");
164
+ mGet: typeof import("@redis/time-series/dist/commands/MGET");
165
+ MGET_WITHLABELS: typeof import("@redis/time-series/dist/commands/MGET_WITHLABELS");
166
+ mGetWithLabels: typeof import("@redis/time-series/dist/commands/MGET_WITHLABELS");
167
+ QUERYINDEX: typeof import("@redis/time-series/dist/commands/QUERYINDEX");
168
+ queryIndex: typeof import("@redis/time-series/dist/commands/QUERYINDEX");
169
+ RANGE: typeof import("@redis/time-series/dist/commands/RANGE");
170
+ range: typeof import("@redis/time-series/dist/commands/RANGE");
171
+ REVRANGE: typeof import("@redis/time-series/dist/commands/REVRANGE");
172
+ revRange: typeof import("@redis/time-series/dist/commands/REVRANGE");
173
+ MRANGE: typeof import("@redis/time-series/dist/commands/MRANGE");
174
+ mRange: typeof import("@redis/time-series/dist/commands/MRANGE");
175
+ MRANGE_WITHLABELS: typeof import("@redis/time-series/dist/commands/MRANGE_WITHLABELS");
176
+ mRangeWithLabels: typeof import("@redis/time-series/dist/commands/MRANGE_WITHLABELS");
177
+ MREVRANGE: typeof import("@redis/time-series/dist/commands/MREVRANGE");
178
+ mRevRange: typeof import("@redis/time-series/dist/commands/MREVRANGE");
179
+ MREVRANGE_WITHLABELS: typeof import("@redis/time-series/dist/commands/MREVRANGE_WITHLABELS");
180
+ mRevRangeWithLabels: typeof import("@redis/time-series/dist/commands/MREVRANGE_WITHLABELS");
181
+ };
182
+ bf: {
183
+ ADD: typeof import("@redis/bloom/dist/commands/bloom/ADD");
184
+ add: typeof import("@redis/bloom/dist/commands/bloom/ADD");
185
+ CARD: typeof import("@redis/bloom/dist/commands/bloom/CARD");
186
+ card: typeof import("@redis/bloom/dist/commands/bloom/CARD");
187
+ EXISTS: typeof import("@redis/bloom/dist/commands/bloom/EXISTS");
188
+ exists: typeof import("@redis/bloom/dist/commands/bloom/EXISTS");
189
+ INFO: typeof import("@redis/bloom/dist/commands/bloom/INFO");
190
+ info: typeof import("@redis/bloom/dist/commands/bloom/INFO");
191
+ INSERT: typeof import("@redis/bloom/dist/commands/bloom/INSERT");
192
+ insert: typeof import("@redis/bloom/dist/commands/bloom/INSERT");
193
+ LOADCHUNK: typeof import("@redis/bloom/dist/commands/bloom/LOADCHUNK");
194
+ loadChunk: typeof import("@redis/bloom/dist/commands/bloom/LOADCHUNK");
195
+ MADD: typeof import("@redis/bloom/dist/commands/bloom/MADD");
196
+ mAdd: typeof import("@redis/bloom/dist/commands/bloom/MADD");
197
+ MEXISTS: typeof import("@redis/bloom/dist/commands/bloom/MEXISTS");
198
+ mExists: typeof import("@redis/bloom/dist/commands/bloom/MEXISTS");
199
+ RESERVE: typeof import("@redis/bloom/dist/commands/bloom/RESERVE");
200
+ reserve: typeof import("@redis/bloom/dist/commands/bloom/RESERVE");
201
+ SCANDUMP: typeof import("@redis/bloom/dist/commands/bloom/SCANDUMP");
202
+ scanDump: typeof import("@redis/bloom/dist/commands/bloom/SCANDUMP");
203
+ };
204
+ cms: {
205
+ INCRBY: typeof import("@redis/bloom/dist/commands/count-min-sketch/INCRBY");
206
+ incrBy: typeof import("@redis/bloom/dist/commands/count-min-sketch/INCRBY");
207
+ INFO: typeof import("@redis/bloom/dist/commands/count-min-sketch/INFO");
208
+ info: typeof import("@redis/bloom/dist/commands/count-min-sketch/INFO");
209
+ INITBYDIM: typeof import("@redis/bloom/dist/commands/count-min-sketch/INITBYDIM");
210
+ initByDim: typeof import("@redis/bloom/dist/commands/count-min-sketch/INITBYDIM");
211
+ INITBYPROB: typeof import("@redis/bloom/dist/commands/count-min-sketch/INITBYPROB");
212
+ initByProb: typeof import("@redis/bloom/dist/commands/count-min-sketch/INITBYPROB");
213
+ MERGE: typeof import("@redis/bloom/dist/commands/count-min-sketch/MERGE");
214
+ merge: typeof import("@redis/bloom/dist/commands/count-min-sketch/MERGE");
215
+ QUERY: typeof import("@redis/bloom/dist/commands/count-min-sketch/QUERY");
216
+ query: typeof import("@redis/bloom/dist/commands/count-min-sketch/QUERY");
217
+ };
218
+ cf: {
219
+ ADD: typeof import("@redis/bloom/dist/commands/cuckoo/ADD");
220
+ add: typeof import("@redis/bloom/dist/commands/cuckoo/ADD");
221
+ ADDNX: typeof import("@redis/bloom/dist/commands/cuckoo/ADDNX");
222
+ addNX: typeof import("@redis/bloom/dist/commands/cuckoo/ADDNX");
223
+ COUNT: typeof import("@redis/bloom/dist/commands/cuckoo/COUNT");
224
+ count: typeof import("@redis/bloom/dist/commands/cuckoo/COUNT");
225
+ DEL: typeof import("@redis/bloom/dist/commands/cuckoo/DEL");
226
+ del: typeof import("@redis/bloom/dist/commands/cuckoo/DEL");
227
+ EXISTS: typeof import("@redis/bloom/dist/commands/cuckoo/EXISTS");
228
+ exists: typeof import("@redis/bloom/dist/commands/cuckoo/EXISTS");
229
+ INFO: typeof import("@redis/bloom/dist/commands/cuckoo/INFO");
230
+ info: typeof import("@redis/bloom/dist/commands/cuckoo/INFO");
231
+ INSERT: typeof import("@redis/bloom/dist/commands/cuckoo/INSERT");
232
+ insert: typeof import("@redis/bloom/dist/commands/cuckoo/INSERT");
233
+ INSERTNX: typeof import("@redis/bloom/dist/commands/cuckoo/INSERTNX");
234
+ insertNX: typeof import("@redis/bloom/dist/commands/cuckoo/INSERTNX");
235
+ LOADCHUNK: typeof import("@redis/bloom/dist/commands/cuckoo/LOADCHUNK");
236
+ loadChunk: typeof import("@redis/bloom/dist/commands/cuckoo/LOADCHUNK");
237
+ RESERVE: typeof import("@redis/bloom/dist/commands/cuckoo/RESERVE");
238
+ reserve: typeof import("@redis/bloom/dist/commands/cuckoo/RESERVE");
239
+ SCANDUMP: typeof import("@redis/bloom/dist/commands/cuckoo/SCANDUMP");
240
+ scanDump: typeof import("@redis/bloom/dist/commands/cuckoo/SCANDUMP");
241
+ };
242
+ tDigest: {
243
+ ADD: typeof import("@redis/bloom/dist/commands/t-digest/ADD");
244
+ add: typeof import("@redis/bloom/dist/commands/t-digest/ADD");
245
+ BYRANK: typeof import("@redis/bloom/dist/commands/t-digest/BYRANK");
246
+ byRank: typeof import("@redis/bloom/dist/commands/t-digest/BYRANK");
247
+ BYREVRANK: typeof import("@redis/bloom/dist/commands/t-digest/BYREVRANK");
248
+ byRevRank: typeof import("@redis/bloom/dist/commands/t-digest/BYREVRANK");
249
+ CDF: typeof import("@redis/bloom/dist/commands/t-digest/CDF");
250
+ cdf: typeof import("@redis/bloom/dist/commands/t-digest/CDF");
251
+ CREATE: typeof import("@redis/bloom/dist/commands/t-digest/CREATE");
252
+ create: typeof import("@redis/bloom/dist/commands/t-digest/CREATE");
253
+ INFO: typeof import("@redis/bloom/dist/commands/t-digest/INFO");
254
+ info: typeof import("@redis/bloom/dist/commands/t-digest/INFO");
255
+ MAX: typeof import("@redis/bloom/dist/commands/t-digest/MAX");
256
+ max: typeof import("@redis/bloom/dist/commands/t-digest/MAX");
257
+ MERGE: typeof import("@redis/bloom/dist/commands/t-digest/MERGE");
258
+ merge: typeof import("@redis/bloom/dist/commands/t-digest/MERGE");
259
+ MIN: typeof import("@redis/bloom/dist/commands/t-digest/MIN");
260
+ min: typeof import("@redis/bloom/dist/commands/t-digest/MIN");
261
+ QUANTILE: typeof import("@redis/bloom/dist/commands/t-digest/QUANTILE");
262
+ quantile: typeof import("@redis/bloom/dist/commands/t-digest/QUANTILE");
263
+ RANK: typeof import("@redis/bloom/dist/commands/t-digest/RANK");
264
+ rank: typeof import("@redis/bloom/dist/commands/t-digest/RANK");
265
+ RESET: typeof import("@redis/bloom/dist/commands/t-digest/RESET");
266
+ reset: typeof import("@redis/bloom/dist/commands/t-digest/RESET");
267
+ REVRANK: typeof import("@redis/bloom/dist/commands/t-digest/REVRANK");
268
+ revRank: typeof import("@redis/bloom/dist/commands/t-digest/REVRANK");
269
+ TRIMMED_MEAN: typeof import("@redis/bloom/dist/commands/t-digest/TRIMMED_MEAN");
270
+ trimmedMean: typeof import("@redis/bloom/dist/commands/t-digest/TRIMMED_MEAN");
271
+ };
272
+ topK: {
273
+ ADD: typeof import("@redis/bloom/dist/commands/top-k/ADD");
274
+ add: typeof import("@redis/bloom/dist/commands/top-k/ADD");
275
+ COUNT: typeof import("@redis/bloom/dist/commands/top-k/COUNT");
276
+ count: typeof import("@redis/bloom/dist/commands/top-k/COUNT");
277
+ INCRBY: typeof import("@redis/bloom/dist/commands/top-k/INCRBY");
278
+ incrBy: typeof import("@redis/bloom/dist/commands/top-k/INCRBY");
279
+ INFO: typeof import("@redis/bloom/dist/commands/top-k/INFO");
280
+ info: typeof import("@redis/bloom/dist/commands/top-k/INFO");
281
+ LIST_WITHCOUNT: typeof import("@redis/bloom/dist/commands/top-k/LIST_WITHCOUNT");
282
+ listWithCount: typeof import("@redis/bloom/dist/commands/top-k/LIST_WITHCOUNT");
283
+ LIST: typeof import("@redis/bloom/dist/commands/top-k/LIST");
284
+ list: typeof import("@redis/bloom/dist/commands/top-k/LIST");
285
+ QUERY: typeof import("@redis/bloom/dist/commands/top-k/QUERY");
286
+ query: typeof import("@redis/bloom/dist/commands/top-k/QUERY");
287
+ RESERVE: typeof import("@redis/bloom/dist/commands/top-k/RESERVE");
288
+ reserve: typeof import("@redis/bloom/dist/commands/top-k/RESERVE");
289
+ };
290
+ } & import("redis").RedisModules, import("redis").RedisFunctions, import("redis").RedisScripts>;
291
+ declare const initializeRedis: () => Promise<void>;
292
+ declare const revokeToken: (token: string) => Promise<void>;
293
+ declare const isTokenRevoked: (token: string) => Promise<boolean>;
294
+ export { redisClient, initializeRedis, revokeToken, isTokenRevoked };
@@ -0,0 +1,75 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.isTokenRevoked = exports.revokeToken = exports.initializeRedis = exports.redisClient = void 0;
16
+ const redis_1 = require("redis");
17
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
18
+ const redisClient = (0, redis_1.createClient)({ url: 'redis://default:8WgIdGy1PhWSNIISbTeGsz2Q6g24vYSQ@redis-10351.c321.us-east-1-2.ec2.redns.redis-cloud.com:10351' });
19
+ exports.redisClient = redisClient;
20
+ const initializeRedis = () => __awaiter(void 0, void 0, void 0, function* () {
21
+ try {
22
+ redisClient.on('error', (err) => console.error('❌ Redis error:', err));
23
+ redisClient.on('reconnecting', () => console.log('🔄 Reconnecting to Redis...'));
24
+ redisClient.on('ready', () => console.log('🚀 Redis client is ready'));
25
+ yield redisClient.connect();
26
+ console.log('✅ Connected to Redis');
27
+ }
28
+ catch (error) {
29
+ console.error('❌ Failed to connect to Redis:', error);
30
+ process.exit(1);
31
+ }
32
+ });
33
+ exports.initializeRedis = initializeRedis;
34
+ const getTokenTTL = (token) => {
35
+ try {
36
+ const decoded = jsonwebtoken_1.default.decode(token);
37
+ if (!decoded || typeof decoded !== 'object' || !decoded.exp) {
38
+ return 3600;
39
+ }
40
+ const now = Math.floor(Date.now() / 1000);
41
+ const ttl = decoded.exp - now;
42
+ return ttl > 0 ? ttl : 0;
43
+ }
44
+ catch (error) {
45
+ console.error('❌ Failed to decode token:', error);
46
+ return 0;
47
+ }
48
+ };
49
+ const revokeToken = (token) => __awaiter(void 0, void 0, void 0, function* () {
50
+ try {
51
+ const ttl = getTokenTTL(token);
52
+ if (ttl > 0) {
53
+ yield redisClient.set(`revokedToken:${token}`, 'revoked', { EX: ttl });
54
+ console.log(`🚫 Token revoked: ${token}`);
55
+ }
56
+ else {
57
+ console.log('⚠️ Token already expired, no need to revoke.');
58
+ }
59
+ }
60
+ catch (error) {
61
+ console.error('❌ Failed to revoke token:', error);
62
+ }
63
+ });
64
+ exports.revokeToken = revokeToken;
65
+ const isTokenRevoked = (token) => __awaiter(void 0, void 0, void 0, function* () {
66
+ try {
67
+ const result = yield redisClient.get(`revokedToken:${token}`);
68
+ return result !== null;
69
+ }
70
+ catch (error) {
71
+ console.error('❌ Failed to check token revocation:', error);
72
+ return false;
73
+ }
74
+ });
75
+ exports.isTokenRevoked = isTokenRevoked;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jpbs/common",
3
- "version": "1.1.7",
3
+ "version": "1.2.0",
4
4
  "main": "./build/index.js",
5
5
  "types": "./build/index.d.ts",
6
6
  "files": [
@@ -24,7 +24,8 @@
24
24
  "express": "^4.21.2",
25
25
  "express-validator": "^7.2.1",
26
26
  "http-status-codes": "^2.3.0",
27
- "jsonwebtoken": "^9.0.2"
27
+ "jsonwebtoken": "^9.0.2",
28
+ "redis": "^4.7.0"
28
29
  },
29
30
  "devDependencies": {
30
31
  "del-cli": "^6.0.0",