@aldb2b/common 1.0.153 → 1.0.156
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/events/authorize-user.interface.d.ts +1 -3
- package/build/events/create-company.interface.d.ts +6 -4
- package/build/middlewares/authorizer.middleware.d.ts +2 -0
- package/build/middlewares/authorizer.middleware.js +38 -19
- package/build/middlewares/authorizer.middleware.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +9 -8
- package/package.json +1 -1
|
@@ -6,10 +6,12 @@ export declare namespace CreateCompany {
|
|
|
6
6
|
data: Data;
|
|
7
7
|
}
|
|
8
8
|
interface Data {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
id?: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
website?: string;
|
|
12
|
+
eventId?: string;
|
|
13
|
+
usertype?: string;
|
|
14
|
+
contact?: string;
|
|
13
15
|
operationType: operationTypes;
|
|
14
16
|
}
|
|
15
17
|
}
|
|
@@ -7,4 +7,6 @@ export declare class AuthorizerMiddleware implements NestMiddleware {
|
|
|
7
7
|
constructor(client: ClientProxy);
|
|
8
8
|
use(request: Request, response: Response, next: NextFunction): Promise<void>;
|
|
9
9
|
private getHeaderParam;
|
|
10
|
+
private isPermitted;
|
|
11
|
+
private getUserPermissions;
|
|
10
12
|
}
|
|
@@ -17,7 +17,7 @@ const common_1 = require("@nestjs/common");
|
|
|
17
17
|
const microservices_1 = require("@nestjs/microservices");
|
|
18
18
|
const rxjs_1 = require("rxjs");
|
|
19
19
|
const redis_1 = require("redis");
|
|
20
|
-
const subjects_1 = require("
|
|
20
|
+
const subjects_1 = require("src/events/subjects");
|
|
21
21
|
class RedisClient {
|
|
22
22
|
constructor() {
|
|
23
23
|
this.redisClient = redis_1.createClient({
|
|
@@ -39,6 +39,15 @@ class RedisClient {
|
|
|
39
39
|
console.log('REDIS GET DATA ERROR--------', err);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
+
async getAllKeys() {
|
|
43
|
+
try {
|
|
44
|
+
await this.connectToRedis();
|
|
45
|
+
return this.redisClient.keys('*');
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
console.log('REDIS GET DATA ERROR--------', err);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
42
51
|
async setData(key, value) {
|
|
43
52
|
try {
|
|
44
53
|
await this.connectToRedis();
|
|
@@ -55,42 +64,52 @@ let AuthorizerMiddleware = class AuthorizerMiddleware {
|
|
|
55
64
|
this.cachManager = new RedisClient();
|
|
56
65
|
}
|
|
57
66
|
async use(request, response, next) {
|
|
58
|
-
const
|
|
67
|
+
const user = {
|
|
59
68
|
subject: subjects_1.Subjects.AuthorizeUser,
|
|
60
69
|
data: {
|
|
61
|
-
path: request.route.path,
|
|
62
|
-
method: request.method,
|
|
63
70
|
cognitoUserId: this.getHeaderParam(request.headers, 'x-cognito-userid'),
|
|
64
71
|
eventId: this.getHeaderParam(request.headers, 'event-id'),
|
|
65
72
|
},
|
|
66
73
|
};
|
|
67
|
-
const redisResponse = await this.cachManager.getData(JSON.stringify(
|
|
74
|
+
const redisResponse = await this.cachManager.getData(JSON.stringify(user.data));
|
|
68
75
|
let resp;
|
|
69
76
|
if (redisResponse) {
|
|
70
77
|
resp = JSON.parse(redisResponse);
|
|
71
|
-
console.log('FROM REDIS--------------------');
|
|
78
|
+
console.log('FROM REDIS--------------------', redisResponse);
|
|
79
|
+
await this.isPermitted(resp.type, resp.role, request.method, request.route.path);
|
|
72
80
|
}
|
|
73
81
|
else {
|
|
74
|
-
resp = await rxjs_1.firstValueFrom(this.client.send(
|
|
82
|
+
resp = await rxjs_1.firstValueFrom(this.client.send(user.subject, user.data));
|
|
75
83
|
console.log('FROM MESSAGE BROKER--------------------', resp);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
request.headers.id = resp.id;
|
|
83
|
-
request.headers.type = resp.type;
|
|
84
|
-
request.headers.role = resp.role;
|
|
85
|
-
request.headers.email = resp.email;
|
|
86
|
-
request.headers.company = resp.company;
|
|
87
|
-
request.headers.contactId = resp.contactId;
|
|
84
|
+
if (resp.isAuthorized === false) {
|
|
85
|
+
throw new common_1.UnauthorizedException();
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
await this.cachManager.setData(JSON.stringify(user.data), JSON.stringify(resp));
|
|
89
|
+
}
|
|
88
90
|
}
|
|
91
|
+
request.headers.id = resp.id;
|
|
92
|
+
request.headers.type = resp.type;
|
|
93
|
+
request.headers.role = resp.role;
|
|
94
|
+
request.headers.email = resp.email;
|
|
95
|
+
request.headers.company = resp.company;
|
|
96
|
+
request.headers.contactId = resp.contactId;
|
|
89
97
|
next();
|
|
90
98
|
}
|
|
91
99
|
getHeaderParam(headers, param) {
|
|
92
100
|
return Array.isArray(headers[param]) ? headers[param][0] : headers[param];
|
|
93
101
|
}
|
|
102
|
+
async isPermitted(type, role, method, path) {
|
|
103
|
+
const permissions = await this.getUserPermissions(type, role);
|
|
104
|
+
const permission = permissions.find(item => item.type === method && item.route === path);
|
|
105
|
+
if (!permission || !permission.isAllowed) {
|
|
106
|
+
throw new common_1.UnauthorizedException();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async getUserPermissions(type, role) {
|
|
110
|
+
let cachedPermissions = await this.cachManager.getData(`${type}-${role}`);
|
|
111
|
+
return JSON.parse(cachedPermissions);
|
|
112
|
+
}
|
|
94
113
|
};
|
|
95
114
|
AuthorizerMiddleware = __decorate([
|
|
96
115
|
common_1.Injectable(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorizer.middleware.js","sourceRoot":"","sources":["../../src/middlewares/authorizer.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"authorizer.middleware.js","sourceRoot":"","sources":["../../src/middlewares/authorizer.middleware.ts"],"names":[],"mappings":";;;;;;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H,CAAC;IAEO,KAAK,CAAC,kBAAkB,CAC9B,IAAc,EACd,IAAc;QAEd,IAAI,iBAAiB,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,CAAA;QACzE,OAAO,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAA;IACtC,CAAC;CACF,CAAA;AAjFY,oBAAoB;IADhC,mBAAU,EAAE;IAGE,WAAA,eAAM,CAAC,cAAc,CAAC,CAAA;qCAA0B,2BAAW;GAF7D,oBAAoB,CAiFhC;AAjFY,oDAAoB"}
|
|
@@ -192,8 +192,8 @@
|
|
|
192
192
|
"affectsGlobalScope": false
|
|
193
193
|
},
|
|
194
194
|
"../src/events/authorize-user.interface.ts": {
|
|
195
|
-
"version": "
|
|
196
|
-
"signature": "
|
|
195
|
+
"version": "da1d824ffa99ff9d3982cc963de94e84c9892e328e3262bcd55736d1d94a0655",
|
|
196
|
+
"signature": "e29ec6361fb4732f0ee7e7445bc5ffcb6cbf11e26c2c0d3e7e79987e31a30b91",
|
|
197
197
|
"affectsGlobalScope": false
|
|
198
198
|
},
|
|
199
199
|
"../src/events/attendee-contact.interface.ts": {
|
|
@@ -332,8 +332,8 @@
|
|
|
332
332
|
"affectsGlobalScope": false
|
|
333
333
|
},
|
|
334
334
|
"../src/events/create-company.interface.ts": {
|
|
335
|
-
"version": "
|
|
336
|
-
"signature": "
|
|
335
|
+
"version": "a8fde39bc562da3cd7888c64ba433daa2d00d84e3780428da9e063db90969b86",
|
|
336
|
+
"signature": "7029405f6c204af40afaf52158e64dd3ae68f29e0bc6337e18bb299716b41dba",
|
|
337
337
|
"affectsGlobalScope": false
|
|
338
338
|
},
|
|
339
339
|
"../src/events/get-user-by-id.interface.ts": {
|
|
@@ -6227,8 +6227,8 @@
|
|
|
6227
6227
|
"affectsGlobalScope": false
|
|
6228
6228
|
},
|
|
6229
6229
|
"../src/middlewares/authorizer.middleware.ts": {
|
|
6230
|
-
"version": "
|
|
6231
|
-
"signature": "
|
|
6230
|
+
"version": "aa473abf6c36f836fd71ccdc411c4002b817365fe7930531fe36441a6f693bde",
|
|
6231
|
+
"signature": "1c5d65c5ec5568c3946d80a9e2b43427afdbddcbbf889ec56985b5209cdaab7c",
|
|
6232
6232
|
"affectsGlobalScope": false
|
|
6233
6233
|
},
|
|
6234
6234
|
"../src/utils/create-default-directories.ts": {
|
|
@@ -11412,8 +11412,9 @@
|
|
|
11412
11412
|
"../node_modules/@types/express/index.d.ts",
|
|
11413
11413
|
"../node_modules/redis/dist/index.d.ts",
|
|
11414
11414
|
"../node_modules/rxjs/dist/types/index.d.ts",
|
|
11415
|
-
"../src/events/
|
|
11416
|
-
"../src/
|
|
11415
|
+
"../src/events/subjects.ts",
|
|
11416
|
+
"../src/types/user-role.enum.ts",
|
|
11417
|
+
"../src/types/user-type.enum.ts"
|
|
11417
11418
|
],
|
|
11418
11419
|
"../src/types/default-visibility.interface.ts": [
|
|
11419
11420
|
"../src/types/analytic-group.interface.ts",
|