@aldb2b/common 1.0.189 → 1.0.190
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 +2 -0
- package/build/index.js +2 -0
- package/build/index.js.map +1 -1
- package/build/middlewares/authorizer.middleware.d.ts +0 -1
- package/build/middlewares/authorizer.middleware.js +3 -5
- package/build/middlewares/authorizer.middleware.js.map +1 -1
- package/build/middlewares/subscription-subtractor.middleware.d.ts +0 -2
- package/build/middlewares/subscription-subtractor.middleware.js +16 -26
- package/build/middlewares/subscription-subtractor.middleware.js.map +1 -1
- package/build/middlewares/subscription-validator.middleware.d.ts +0 -2
- package/build/middlewares/subscription-validator.middleware.js +10 -18
- package/build/middlewares/subscription-validator.middleware.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +39 -12
- package/build/types/endpoint-type.enum.d.ts +1 -1
- package/build/types/endpoint-type.enum.js +1 -1
- package/build/types/endpoint-type.enum.js.map +1 -1
- package/build/utils/getEndpoint.d.ts +5 -0
- package/build/utils/getEndpoint.js +14 -0
- package/build/utils/getEndpoint.js.map +1 -0
- package/build/utils/getHeaderParam.d.ts +1 -0
- package/build/utils/getHeaderParam.js +8 -0
- package/build/utils/getHeaderParam.js.map +1 -0
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -152,4 +152,6 @@ __exportStar(require("./utils/adjustForTimezone"), exports);
|
|
|
152
152
|
__exportStar(require("./utils/get-parsed-query"), exports);
|
|
153
153
|
__exportStar(require("./utils/rmq/index"), exports);
|
|
154
154
|
__exportStar(require("./utils/redis-client"), exports);
|
|
155
|
+
__exportStar(require("./utils/getHeaderParam"), exports);
|
|
156
|
+
__exportStar(require("./utils/getEndpoint"), exports);
|
|
155
157
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"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;AAC7C,sEAAmD;AACnD,yDAAsC;AACtC,yDAAsC;AACtC,gEAA6C;AAC7C,yEAAsD;AACtD,2EAAwD;AACxD,4DAAyC;AACzC,0EAAuD;AACvD,0DAAuC;AACvC,gEAA6C;AAC7C,0DAAuC;AACvC,qEAAkD;AAClD,qEAAkD;AAClD,uEAAoD;AACpD,mEAAgD;AAChD,+DAA4C;AAC5C,uEAAoD;AACpD,qEAAkD;AAClD,kEAA+C;AAC/C,oEAAiD;AACjD,iEAA8C;AAC9C,2DAAwC;AACxC,8DAA2C;AAC3C,kEAA+C;AAC/C,6DAA0C;AAC1C,4DAAyC;AACzC,6DAA0C;AAE1C,+DAA4C;AAC5C,sEAAmD;AACnD,mFAAgE;AAChE,kFAA+D;AAE/D,qEAAkD;AAClD,6DAA0C;AAC1C,uDAAoC;AACpC,sDAAmC;AACnC,qDAAkC;AAClC,mDAAgC;AAChC,4DAAyC;AACzC,2DAAwC;AACxC,oDAAiC;AACjC,uDAAoC;AACpC,yDAAsC;AACtC,sDAAmC"}
|
|
@@ -6,7 +6,6 @@ export declare class AuthorizerMiddleware implements NestMiddleware {
|
|
|
6
6
|
private cachManager;
|
|
7
7
|
constructor(client: ClientProxy);
|
|
8
8
|
use(request: Request, response: Response, next: NextFunction): Promise<void>;
|
|
9
|
-
private getHeaderParam;
|
|
10
9
|
private isPermitted;
|
|
11
10
|
private getUserPermissions;
|
|
12
11
|
}
|
|
@@ -18,6 +18,7 @@ const microservices_1 = require("@nestjs/microservices");
|
|
|
18
18
|
const rxjs_1 = require("rxjs");
|
|
19
19
|
const subjects_1 = require("../events/subjects");
|
|
20
20
|
const redis_client_1 = require("../utils/redis-client");
|
|
21
|
+
const getHeaderParam_1 = require("src/utils/getHeaderParam");
|
|
21
22
|
let AuthorizerMiddleware = class AuthorizerMiddleware {
|
|
22
23
|
constructor(client) {
|
|
23
24
|
this.client = client;
|
|
@@ -27,8 +28,8 @@ let AuthorizerMiddleware = class AuthorizerMiddleware {
|
|
|
27
28
|
const user = {
|
|
28
29
|
subject: subjects_1.Subjects.AuthorizeUser,
|
|
29
30
|
data: {
|
|
30
|
-
cognitoUserId:
|
|
31
|
-
eventId:
|
|
31
|
+
cognitoUserId: getHeaderParam_1.getHeaderParam(request.headers, 'x-cognito-userid'),
|
|
32
|
+
eventId: getHeaderParam_1.getHeaderParam(request.headers, 'event-id'),
|
|
32
33
|
},
|
|
33
34
|
};
|
|
34
35
|
const redisResponse = await this.cachManager.getData(JSON.stringify(user.data));
|
|
@@ -57,9 +58,6 @@ let AuthorizerMiddleware = class AuthorizerMiddleware {
|
|
|
57
58
|
request.headers.language = resp.language;
|
|
58
59
|
next();
|
|
59
60
|
}
|
|
60
|
-
getHeaderParam(headers, param) {
|
|
61
|
-
return Array.isArray(headers[param]) ? headers[param][0] : headers[param];
|
|
62
|
-
}
|
|
63
61
|
async isPermitted(type, role, method, path) {
|
|
64
62
|
const permissions = await this.getUserPermissions(type, role);
|
|
65
63
|
const permission = permissions.find(item => item.type === method && item.route === path);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorizer.middleware.js","sourceRoot":"","sources":["../../src/middlewares/authorizer.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAKuB;AACvB,yDAAmD;AAEnD,+BAAqC;AACrC,iDAA6C;AAG7C,wDAAmD;
|
|
1
|
+
{"version":3,"file":"authorizer.middleware.js","sourceRoot":"","sources":["../../src/middlewares/authorizer.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAKuB;AACvB,yDAAmD;AAEnD,+BAAqC;AACrC,iDAA6C;AAG7C,wDAAmD;AACnD,6DAAyD;AAGzD,IAAa,oBAAoB,GAAjC,MAAa,oBAAoB;IAE/B,YAAqD,MAAmB;QAAnB,WAAM,GAAN,MAAM,CAAa;QACtE,IAAI,CAAC,WAAW,GAAG,IAAI,0BAAW,EAAE,CAAA;IACtC,CAAC;IAED,KAAK,CAAC,GAAG,CACP,OAAgB,E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oDAAoB"}
|
|
@@ -6,7 +6,5 @@ export declare class SubscriptionSubtractorMiddleware implements NestMiddleware
|
|
|
6
6
|
private cachManager;
|
|
7
7
|
constructor(client: ClientProxy);
|
|
8
8
|
use(request: Request, response: Response, next: NextFunction): Promise<void>;
|
|
9
|
-
private getHeaderParam;
|
|
10
9
|
private subtractSubscription;
|
|
11
|
-
private getEndpoint;
|
|
12
10
|
}
|
|
@@ -16,8 +16,10 @@ exports.SubscriptionSubtractorMiddleware = void 0;
|
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
17
|
const microservices_1 = require("@nestjs/microservices");
|
|
18
18
|
const rxjs_1 = require("rxjs");
|
|
19
|
+
const getEndpoint_1 = require("../utils/getEndpoint");
|
|
19
20
|
const subjects_1 = require("../events/subjects");
|
|
20
21
|
const endpoint_type_enum_1 = require("../types/endpoint-type.enum");
|
|
22
|
+
const getHeaderParam_1 = require("../utils/getHeaderParam");
|
|
21
23
|
const redis_client_1 = require("../utils/redis-client");
|
|
22
24
|
let SubscriptionSubtractorMiddleware = class SubscriptionSubtractorMiddleware {
|
|
23
25
|
constructor(client) {
|
|
@@ -33,8 +35,8 @@ let SubscriptionSubtractorMiddleware = class SubscriptionSubtractorMiddleware {
|
|
|
33
35
|
const user = {
|
|
34
36
|
subject: subjects_1.Subjects.HasSubscription,
|
|
35
37
|
data: {
|
|
36
|
-
user:
|
|
37
|
-
eventId:
|
|
38
|
+
user: getHeaderParam_1.getHeaderParam(request.headers, 'id'),
|
|
39
|
+
eventId: getHeaderParam_1.getHeaderParam(request.headers, 'event-id'),
|
|
38
40
|
},
|
|
39
41
|
};
|
|
40
42
|
const redisKey = JSON.stringify(user.data);
|
|
@@ -42,65 +44,53 @@ let SubscriptionSubtractorMiddleware = class SubscriptionSubtractorMiddleware {
|
|
|
42
44
|
let resp;
|
|
43
45
|
if (redisResponse) {
|
|
44
46
|
resp = JSON.parse(redisResponse);
|
|
45
|
-
console.log('FROM REDIS--------------------'
|
|
47
|
+
console.log('FROM REDIS--------------------');
|
|
46
48
|
await this.subtractSubscription(resp, request.method, request.route.path, redisKey);
|
|
47
49
|
}
|
|
48
50
|
else {
|
|
49
51
|
resp = await rxjs_1.firstValueFrom(this.client.send(user.subject, user.data));
|
|
50
|
-
console.log('FROM MESSAGE BROKER--------------------'
|
|
52
|
+
console.log('FROM MESSAGE BROKER--------------------');
|
|
51
53
|
await this.cachManager.setData(redisKey, JSON.stringify(resp), 60);
|
|
52
54
|
await this.subtractSubscription(resp, request.method, request.route.path, redisKey);
|
|
53
55
|
}
|
|
54
56
|
});
|
|
55
57
|
next();
|
|
56
58
|
}
|
|
57
|
-
getHeaderParam(headers, param) {
|
|
58
|
-
return Array.isArray(headers[param]) ? headers[param][0] : headers[param];
|
|
59
|
-
}
|
|
60
59
|
async subtractSubscription(subscription, method, path, key) {
|
|
61
|
-
const { features, remainingPoints
|
|
62
|
-
const { endpoint, featureId } =
|
|
60
|
+
const { features, remainingPoints } = subscription;
|
|
61
|
+
const { endpoint, featureId } = getEndpoint_1.getEndpoint(features, method, path);
|
|
63
62
|
if (endpoint.type === endpoint_type_enum_1.EndpointType.BINARY) {
|
|
64
63
|
return;
|
|
65
64
|
}
|
|
66
65
|
else if (endpoint.type === endpoint_type_enum_1.EndpointType.LIMIT) {
|
|
67
|
-
|
|
66
|
+
subscription.features = subscription.features.map(feature => {
|
|
68
67
|
if (feature._id === featureId) {
|
|
69
68
|
feature.endpoints = feature.endpoints.map(existingEndpoint => {
|
|
70
69
|
if (existingEndpoint._id === endpoint._id) {
|
|
71
70
|
existingEndpoint.limit -= 1;
|
|
72
71
|
}
|
|
73
|
-
console.log('MODIFIED ENDPOINT---------------', existingEndpoint);
|
|
74
72
|
return existingEndpoint;
|
|
75
73
|
});
|
|
76
|
-
console.log('MODIFIED FEATURE---------------', feature);
|
|
77
74
|
}
|
|
78
75
|
return feature;
|
|
79
76
|
});
|
|
80
|
-
await this.cachManager.setData(key, JSON.stringify(
|
|
81
|
-
this.client.send(subjects_1.Subjects.SubtractSubscriptionLimit, {
|
|
77
|
+
await this.cachManager.setData(key, JSON.stringify(subscription), 60);
|
|
78
|
+
rxjs_1.firstValueFrom(this.client.send(subjects_1.Subjects.SubtractSubscriptionLimit, {
|
|
82
79
|
limit: endpoint.limit,
|
|
83
80
|
id: subscription._id,
|
|
84
81
|
featureId,
|
|
85
82
|
endpointId: endpoint._id,
|
|
86
|
-
});
|
|
83
|
+
}));
|
|
87
84
|
}
|
|
88
|
-
else if (endpoint.type === endpoint_type_enum_1.EndpointType.
|
|
85
|
+
else if (endpoint.type === endpoint_type_enum_1.EndpointType.CREDIT) {
|
|
86
|
+
console.log('INSIDE ENDPOINT CREDIT---------------');
|
|
89
87
|
const modifiedSubscription = Object.assign(Object.assign({}, subscription), { remainingPoints: remainingPoints - endpoint.point });
|
|
90
88
|
await this.cachManager.setData(key, JSON.stringify(modifiedSubscription), 60);
|
|
91
|
-
this.client.send(subjects_1.Subjects.SubtractSubscriptionPoint, {
|
|
89
|
+
rxjs_1.firstValueFrom(this.client.send(subjects_1.Subjects.SubtractSubscriptionPoint, {
|
|
92
90
|
point: endpoint.point,
|
|
93
91
|
id: subscription._id,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
getEndpoint(features, method, path) {
|
|
98
|
-
const feature = features.find(feature => feature.endpoints.find(endpoint => endpoint.method === method && endpoint.path === path));
|
|
99
|
-
if (!feature) {
|
|
100
|
-
throw new common_1.UnauthorizedException('Invalid feature for this subscription');
|
|
92
|
+
}));
|
|
101
93
|
}
|
|
102
|
-
const endpoint = feature.endpoints.find(endpoint => endpoint.method === method && endpoint.path === path);
|
|
103
|
-
return { endpoint, featureId: feature._id };
|
|
104
94
|
}
|
|
105
95
|
};
|
|
106
96
|
SubscriptionSubtractorMiddleware = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription-subtractor.middleware.js","sourceRoot":"","sources":["../../src/middlewares/subscription-subtractor.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"subscription-subtractor.middleware.js","sourceRoot":"","sources":["../../src/middlewares/subscription-subtractor.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAmE;AACnE,yDAAmD;AAEnD,+BAAqC;AACrC,sDAAkD;AAClD,iDAA6C;AAC7C,oEAA0D;AAC1D,4DAAwD;AACxD,wDAAmD;AAGnD,IAAa,gCAAgC,GAA7C,MAAa,gCAAgC;IAE3C,YACmD,MAAmB;QAAnB,WAAM,GAAN,MAAM,CAAa;QAEpE,IAAI,CAAC,WAAW,GAAG,IAAI,0BAAW,EAAE,CAAA;IACtC,CAAC;IAED,KAAK,CAAC,GAAG,CACP,OAAgB,EAChB,QAAkB,EAClB,IAAkB;QAElB,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,IAAI,EAAE;YAC9B,MAAM,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAA;YAC/B,IAAI,UAAU,GAAG,GAAG,IAAI,UAAU,GAAG,GAAG,EAAE;gBACxC,OAAM;aACP;YACD,MAAM,IAAI,GAAG;gBACX,OAAO,EAAE,mBAAQ,CAAC,eAAe;gBACjC,IAAI,EAAE;oBACJ,IAAI,EAAE,+BAAc,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC;oBAC3C,OAAO,EAAE,+BAAc,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC;iBACrD;aACF,CAAA;YACD,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAC1C,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;YAE9D,IAAI,IAAI,CAAA;YACR,IAAI,aAAa,EAAE;gBACjB,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;gBAChC,OAAO,CAAC,GAA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sBAAsB,CAAC,CAAA;qCAA0B,2BAAW;GAH3D,gCAAgC,CA2G5C;AA3GY,4EAAgC"}
|
|
@@ -6,7 +6,5 @@ export declare class SubscriptionValidatorMiddleware implements NestMiddleware {
|
|
|
6
6
|
private cachManager;
|
|
7
7
|
constructor(client: ClientProxy);
|
|
8
8
|
use(request: Request, response: Response, next: NextFunction): Promise<void>;
|
|
9
|
-
private getHeaderParam;
|
|
10
9
|
private isPermitted;
|
|
11
|
-
private getEndpoint;
|
|
12
10
|
}
|
|
@@ -16,8 +16,10 @@ exports.SubscriptionValidatorMiddleware = void 0;
|
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
17
|
const microservices_1 = require("@nestjs/microservices");
|
|
18
18
|
const rxjs_1 = require("rxjs");
|
|
19
|
+
const getEndpoint_1 = require("../utils/getEndpoint");
|
|
19
20
|
const subjects_1 = require("../events/subjects");
|
|
20
21
|
const endpoint_type_enum_1 = require("../types/endpoint-type.enum");
|
|
22
|
+
const getHeaderParam_1 = require("../utils/getHeaderParam");
|
|
21
23
|
const redis_client_1 = require("../utils/redis-client");
|
|
22
24
|
let SubscriptionValidatorMiddleware = class SubscriptionValidatorMiddleware {
|
|
23
25
|
constructor(client) {
|
|
@@ -25,11 +27,12 @@ let SubscriptionValidatorMiddleware = class SubscriptionValidatorMiddleware {
|
|
|
25
27
|
this.cachManager = new redis_client_1.RedisClient();
|
|
26
28
|
}
|
|
27
29
|
async use(request, response, next) {
|
|
30
|
+
console.log('INSIDE SUBSCRIPTION MIDDLEWARE---------------------');
|
|
28
31
|
const user = {
|
|
29
32
|
subject: subjects_1.Subjects.HasSubscription,
|
|
30
33
|
data: {
|
|
31
|
-
|
|
32
|
-
eventId:
|
|
34
|
+
user: getHeaderParam_1.getHeaderParam(request.headers, 'id'),
|
|
35
|
+
eventId: getHeaderParam_1.getHeaderParam(request.headers, 'event-id'),
|
|
33
36
|
},
|
|
34
37
|
};
|
|
35
38
|
const redisKey = JSON.stringify(user.data);
|
|
@@ -37,13 +40,13 @@ let SubscriptionValidatorMiddleware = class SubscriptionValidatorMiddleware {
|
|
|
37
40
|
let resp;
|
|
38
41
|
if (redisResponse) {
|
|
39
42
|
resp = JSON.parse(redisResponse);
|
|
40
|
-
console.log('FROM REDIS--------------------'
|
|
43
|
+
console.log('FROM REDIS--------------------');
|
|
41
44
|
await this.isPermitted(resp, request.method, request.route.path);
|
|
42
45
|
}
|
|
43
46
|
else {
|
|
44
47
|
resp = await rxjs_1.firstValueFrom(this.client.send(user.subject, user.data));
|
|
45
|
-
console.log('FROM MESSAGE BROKER--------------------'
|
|
46
|
-
if (
|
|
48
|
+
console.log('FROM MESSAGE BROKER--------------------');
|
|
49
|
+
if (resp.hasSubscription === false) {
|
|
47
50
|
throw new common_1.UnauthorizedException('Subscription is required');
|
|
48
51
|
}
|
|
49
52
|
else {
|
|
@@ -53,12 +56,9 @@ let SubscriptionValidatorMiddleware = class SubscriptionValidatorMiddleware {
|
|
|
53
56
|
}
|
|
54
57
|
next();
|
|
55
58
|
}
|
|
56
|
-
getHeaderParam(headers, param) {
|
|
57
|
-
return Array.isArray(headers[param]) ? headers[param][0] : headers[param];
|
|
58
|
-
}
|
|
59
59
|
async isPermitted(subscription, method, path) {
|
|
60
60
|
const { features, remainingPoints } = subscription;
|
|
61
|
-
const endpoint =
|
|
61
|
+
const { endpoint } = getEndpoint_1.getEndpoint(features, method, path);
|
|
62
62
|
if (endpoint.isFree) {
|
|
63
63
|
return true;
|
|
64
64
|
}
|
|
@@ -68,19 +68,11 @@ let SubscriptionValidatorMiddleware = class SubscriptionValidatorMiddleware {
|
|
|
68
68
|
else if (endpoint.type === endpoint_type_enum_1.EndpointType.LIMIT && endpoint.limit === 0) {
|
|
69
69
|
throw new common_1.UnauthorizedException('Limits exceeded');
|
|
70
70
|
}
|
|
71
|
-
else if (endpoint.type === endpoint_type_enum_1.EndpointType.
|
|
71
|
+
else if (endpoint.type === endpoint_type_enum_1.EndpointType.CREDIT &&
|
|
72
72
|
remainingPoints < endpoint.point) {
|
|
73
73
|
throw new common_1.UnauthorizedException('Insufficient credit');
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
getEndpoint(features, method, path) {
|
|
77
|
-
const feature = features.find(feature => feature.endpoints.find(endpoint => endpoint.method === method && endpoint.path === path));
|
|
78
|
-
if (!feature) {
|
|
79
|
-
throw new common_1.UnauthorizedException('Invalid feature for this subscription');
|
|
80
|
-
}
|
|
81
|
-
const endpoint = feature.endpoints.find(endpoint => endpoint.method === method && endpoint.path === path);
|
|
82
|
-
return endpoint;
|
|
83
|
-
}
|
|
84
76
|
};
|
|
85
77
|
SubscriptionValidatorMiddleware = __decorate([
|
|
86
78
|
common_1.Injectable(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription-validator.middleware.js","sourceRoot":"","sources":["../../src/middlewares/subscription-validator.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAKuB;AACvB,yDAAmD;AAEnD,+BAAqC;AACrC,iDAA6C;AAC7C,oEAA0D;
|
|
1
|
+
{"version":3,"file":"subscription-validator.middleware.js","sourceRoot":"","sources":["../../src/middlewares/subscription-validator.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAKuB;AACvB,yDAAmD;AAEnD,+BAAqC;AACrC,sDAAkD;AAClD,iDAA6C;AAC7C,oEAA0D;AAC1D,4DAAwD;AACxD,wDAAmD;AAGnD,IAAa,+BAA+B,GAA5C,MAAa,+BAA+B;IAE1C,YACmD,MAAmB;QAAnB,WAAM,GAAN,MAAM,CAAa;QAEpE,IAAI,CAAC,WAAW,GAAG,IAAI,0BAAW,EAAE,CAAA;IACtC,CAAC;IAED,KAAK,CAAC,GAAG,CACP,OAAgB,EAChB,QAAkB,EAClB,IAAkB;QAElB,OAAO,CAAC,GAAG,CAAC,qDAAqD,CAAC,CAAA;QAClE,MAAM,IAAI,GAAG;YACX,OAAO,EAAE,mBAAQ,CAAC,eAAe;YACjC,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AY,EAAE,MAAc,EAAE,IAAY;QAClE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,YAAY,CAAA;QAClD,MAAM,EAAE,QAAQ,EAAE,GAAG,yBAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;QAExD,IAAI,QAAQ,CAAC,MAAM,EAAE;YACnB,OAAO,IAAI,CAAA;SACZ;QAED,IAAI,QAAQ,CAAC,IAAI,KAAK,iCAAY,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;YAC7D,MAAM,IAAI,8BAAqB,CAAC,kCAAkC,CAAC,CAAA;SACpE;aAAM,IAAI,QAAQ,CAAC,IAAI,KAAK,iCAAY,CAAC,KAAK,IAAI,QAAQ,CAAC,KAAK,KAAK,CAAC,EAAE;YACvE,MAAM,IAAI,8BAAqB,CAAC,iBAAiB,CAAC,CAAA;SACnD;aAAM,IACL,QAAQ,CAAC,IAAI,KAAK,iCAAY,CAAC,MAAM;YACrC,eAAe,GAAG,QAAQ,CAAC,KAAK,EAChC;YACA,MAAM,IAAI,8BAAqB,CAAC,qBAAqB,CAAC,CAAA;SACvD;IACH,CAAC;CACF,CAAA;AA9DY,+BAA+B;IAD3C,mBAAU,EAAE;IAIR,WAAA,eAAM,CAAC,sBAAsB,CAAC,CAAA;qCAA0B,2BAAW;GAH3D,+BAA+B,CA8D3C;AA9DY,0EAA+B"}
|
|
@@ -3692,8 +3692,8 @@
|
|
|
3692
3692
|
"affectsGlobalScope": false
|
|
3693
3693
|
},
|
|
3694
3694
|
"../src/types/endpoint-type.enum.ts": {
|
|
3695
|
-
"version": "
|
|
3696
|
-
"signature": "
|
|
3695
|
+
"version": "b2c979667502e6374202e285b1cbc0400b12abbf3635f0a8c42ea4ad17c5855e",
|
|
3696
|
+
"signature": "c324d19901bf47cdf98d422c93d1498cc7264dbe752f55d4a16a5b4ac5f3787c",
|
|
3697
3697
|
"affectsGlobalScope": false
|
|
3698
3698
|
},
|
|
3699
3699
|
"../src/types/enddpoint.interface.ts": {
|
|
@@ -6311,19 +6311,29 @@
|
|
|
6311
6311
|
"signature": "f3983336049fdfa9c6001a0fb3949d8d692f5158952936d8eb8aad410a593318",
|
|
6312
6312
|
"affectsGlobalScope": false
|
|
6313
6313
|
},
|
|
6314
|
+
"../src/utils/getHeaderParam.ts": {
|
|
6315
|
+
"version": "fabf8d9b568b95d2fb2533293bce749490c53e1c702c7f19dcc130b13677ee54",
|
|
6316
|
+
"signature": "94e263422420c45dbde96757e6b8f9b606074b6eae87507ea7fa7d53f6cf04a9",
|
|
6317
|
+
"affectsGlobalScope": false
|
|
6318
|
+
},
|
|
6314
6319
|
"../src/middlewares/authorizer.middleware.ts": {
|
|
6315
|
-
"version": "
|
|
6316
|
-
"signature": "
|
|
6320
|
+
"version": "4cecf673ffeeab6a2ed8b535104717933aee836ada0273c21db0238ad1e378dc",
|
|
6321
|
+
"signature": "38d177f40d2e7334397b4f5774856ecce47e764752c0b42eae6e215809f81c71",
|
|
6322
|
+
"affectsGlobalScope": false
|
|
6323
|
+
},
|
|
6324
|
+
"../src/utils/getEndpoint.ts": {
|
|
6325
|
+
"version": "5282a3ef570648728dd68b3b6b94bd8d4ff7b965b8affd0431f30c5f52518f6b",
|
|
6326
|
+
"signature": "0fec59c611ff974ee3afcb1a57ff35609251cc0d531e5290cb3f309432790289",
|
|
6317
6327
|
"affectsGlobalScope": false
|
|
6318
6328
|
},
|
|
6319
6329
|
"../src/middlewares/subscription-subtractor.middleware.ts": {
|
|
6320
|
-
"version": "
|
|
6321
|
-
"signature": "
|
|
6330
|
+
"version": "16dcd1d3520b5051f69eaf536f74656dd14b5b9f116549fea7df3438cb8b3376",
|
|
6331
|
+
"signature": "da4aa169159c9b19b8e2360e75aeca1a1a284e1744a3759287d303ec53f732bb",
|
|
6322
6332
|
"affectsGlobalScope": false
|
|
6323
6333
|
},
|
|
6324
6334
|
"../src/middlewares/subscription-validator.middleware.ts": {
|
|
6325
|
-
"version": "
|
|
6326
|
-
"signature": "
|
|
6335
|
+
"version": "4bafa4b40cf95b9c0d660f8263e36b36494044daf0647926601444dd67843e16",
|
|
6336
|
+
"signature": "a7aab6356d4f7ceeafd6caf4446b8dd21651443bb023c14279cc2b583332146d",
|
|
6327
6337
|
"affectsGlobalScope": false
|
|
6328
6338
|
},
|
|
6329
6339
|
"../src/utils/create-default-directories.ts": {
|
|
@@ -6422,8 +6432,8 @@
|
|
|
6422
6432
|
"affectsGlobalScope": false
|
|
6423
6433
|
},
|
|
6424
6434
|
"../src/index.ts": {
|
|
6425
|
-
"version": "
|
|
6426
|
-
"signature": "
|
|
6435
|
+
"version": "3db4517a3a40881d1172f3c85445c81d67cc9161881eb8911464adaf36ea9735",
|
|
6436
|
+
"signature": "0a7b2cefbd61e1268c19657c9437e0e2245e28c8021e134332c232344bb47b91",
|
|
6427
6437
|
"affectsGlobalScope": false
|
|
6428
6438
|
},
|
|
6429
6439
|
"../src/events/meeting-request-updated.interface.ts": {
|
|
@@ -11516,6 +11526,8 @@
|
|
|
11516
11526
|
"../src/utils/equal-array-object.ts",
|
|
11517
11527
|
"../src/utils/equal-object.ts",
|
|
11518
11528
|
"../src/utils/get-parsed-query.ts",
|
|
11529
|
+
"../src/utils/getEndpoint.ts",
|
|
11530
|
+
"../src/utils/getHeaderParam.ts",
|
|
11519
11531
|
"../src/utils/parse-query.ts",
|
|
11520
11532
|
"../src/utils/projection.ts",
|
|
11521
11533
|
"../src/utils/redis-client.ts",
|
|
@@ -11560,6 +11572,7 @@
|
|
|
11560
11572
|
"../src/events/subjects.ts",
|
|
11561
11573
|
"../src/types/user-role.enum.ts",
|
|
11562
11574
|
"../src/types/user-type.enum.ts",
|
|
11575
|
+
"../src/utils/getHeaderParam.ts",
|
|
11563
11576
|
"../src/utils/redis-client.ts"
|
|
11564
11577
|
],
|
|
11565
11578
|
"../src/middlewares/subscription-subtractor.middleware.ts": [
|
|
@@ -11569,7 +11582,8 @@
|
|
|
11569
11582
|
"../node_modules/rxjs/dist/types/index.d.ts",
|
|
11570
11583
|
"../src/events/subjects.ts",
|
|
11571
11584
|
"../src/types/endpoint-type.enum.ts",
|
|
11572
|
-
"../src/
|
|
11585
|
+
"../src/utils/getEndpoint.ts",
|
|
11586
|
+
"../src/utils/getHeaderParam.ts",
|
|
11573
11587
|
"../src/utils/redis-client.ts"
|
|
11574
11588
|
],
|
|
11575
11589
|
"../src/middlewares/subscription-validator.middleware.ts": [
|
|
@@ -11579,7 +11593,8 @@
|
|
|
11579
11593
|
"../node_modules/rxjs/dist/types/index.d.ts",
|
|
11580
11594
|
"../src/events/subjects.ts",
|
|
11581
11595
|
"../src/types/endpoint-type.enum.ts",
|
|
11582
|
-
"../src/
|
|
11596
|
+
"../src/utils/getEndpoint.ts",
|
|
11597
|
+
"../src/utils/getHeaderParam.ts",
|
|
11583
11598
|
"../src/utils/redis-client.ts"
|
|
11584
11599
|
],
|
|
11585
11600
|
"../src/types/default-visibility.interface.ts": [
|
|
@@ -11606,6 +11621,10 @@
|
|
|
11606
11621
|
"../src/utils/equal-array-object.ts": [
|
|
11607
11622
|
"../src/utils/equal-object.ts"
|
|
11608
11623
|
],
|
|
11624
|
+
"../src/utils/getEndpoint.ts": [
|
|
11625
|
+
"../node_modules/@nestjs/common/index.d.ts",
|
|
11626
|
+
"../src/types/feature.interface.ts"
|
|
11627
|
+
],
|
|
11609
11628
|
"../src/utils/redis-client.ts": [
|
|
11610
11629
|
"../node_modules/redis/dist/index.d.ts"
|
|
11611
11630
|
],
|
|
@@ -16679,6 +16698,8 @@
|
|
|
16679
16698
|
"../src/utils/equal-array-object.ts",
|
|
16680
16699
|
"../src/utils/equal-object.ts",
|
|
16681
16700
|
"../src/utils/get-parsed-query.ts",
|
|
16701
|
+
"../src/utils/getEndpoint.ts",
|
|
16702
|
+
"../src/utils/getHeaderParam.ts",
|
|
16682
16703
|
"../src/utils/parse-query.ts",
|
|
16683
16704
|
"../src/utils/projection.ts",
|
|
16684
16705
|
"../src/utils/redis-client.ts",
|
|
@@ -16743,6 +16764,10 @@
|
|
|
16743
16764
|
"../src/types/match.interface.ts": [
|
|
16744
16765
|
"../src/types/match-group.interface.ts"
|
|
16745
16766
|
],
|
|
16767
|
+
"../src/utils/getEndpoint.ts": [
|
|
16768
|
+
"../src/index.ts",
|
|
16769
|
+
"../src/types/feature.interface.ts"
|
|
16770
|
+
],
|
|
16746
16771
|
"../src/utils/rmq/client/rabbitmq.client.ts": [
|
|
16747
16772
|
"../node_modules/@nestjs/common/index.d.ts",
|
|
16748
16773
|
"../node_modules/@nestjs/microservices/index.d.ts",
|
|
@@ -18056,6 +18081,8 @@
|
|
|
18056
18081
|
"../src/utils/equal-array-object.ts",
|
|
18057
18082
|
"../src/utils/equal-object.ts",
|
|
18058
18083
|
"../src/utils/get-parsed-query.ts",
|
|
18084
|
+
"../src/utils/getEndpoint.ts",
|
|
18085
|
+
"../src/utils/getHeaderParam.ts",
|
|
18059
18086
|
"../src/utils/parse-query.ts",
|
|
18060
18087
|
"../src/utils/projection.ts",
|
|
18061
18088
|
"../src/utils/redis-client.ts",
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EndpointType = void 0;
|
|
4
4
|
var EndpointType;
|
|
5
5
|
(function (EndpointType) {
|
|
6
|
-
EndpointType["POINT"] = "Point";
|
|
7
6
|
EndpointType["LIMIT"] = "Limit";
|
|
7
|
+
EndpointType["CREDIT"] = "Credit";
|
|
8
8
|
EndpointType["BINARY"] = "Binary";
|
|
9
9
|
})(EndpointType = exports.EndpointType || (exports.EndpointType = {}));
|
|
10
10
|
//# sourceMappingURL=endpoint-type.enum.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint-type.enum.js","sourceRoot":"","sources":["../../src/types/endpoint-type.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,+BAAe,CAAA;IACf
|
|
1
|
+
{"version":3,"file":"endpoint-type.enum.js","sourceRoot":"","sources":["../../src/types/endpoint-type.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,+BAAe,CAAA;IACf,iCAAiB,CAAA;IACjB,iCAAiB,CAAA;AACnB,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEndpoint = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
function getEndpoint(features, method, path) {
|
|
6
|
+
const feature = features.find(feature => feature.endpoints.find(endpoint => endpoint.method === method && endpoint.path === path));
|
|
7
|
+
if (!feature) {
|
|
8
|
+
throw new common_1.UnauthorizedException('Invalid feature for this subscription');
|
|
9
|
+
}
|
|
10
|
+
const endpoint = feature.endpoints.find(endpoint => endpoint.method === method && endpoint.path === path);
|
|
11
|
+
return { endpoint, featureId: feature._id };
|
|
12
|
+
}
|
|
13
|
+
exports.getEndpoint = getEndpoint;
|
|
14
|
+
//# sourceMappingURL=getEndpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getEndpoint.js","sourceRoot":"","sources":["../../src/utils/getEndpoint.ts"],"names":[],"mappings":";;;AAAA,2CAAsD;AAGtD,SAAgB,WAAW,CAAC,QAAmB,EAAE,MAAc,EAAE,IAAY;IAC3E,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CACtC,OAAO,CAAC,SAAS,CAAC,IAAI,CACpB,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,KAAK,MAAM,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,CACjE,CACF,CAAA;IAED,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,8BAAqB,CAAC,uCAAuC,CAAC,CAAA;KACzE;IACD,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,CACrC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,KAAK,MAAM,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,CACjE,CAAA;IACD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,GAAG,EAAE,CAAA;AAC7C,CAAC;AAdD,kCAcC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getHeaderParam(headers: any, param: any): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHeaderParam = void 0;
|
|
4
|
+
function getHeaderParam(headers, param) {
|
|
5
|
+
return Array.isArray(headers[param]) ? headers[param][0] : headers[param];
|
|
6
|
+
}
|
|
7
|
+
exports.getHeaderParam = getHeaderParam;
|
|
8
|
+
//# sourceMappingURL=getHeaderParam.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getHeaderParam.js","sourceRoot":"","sources":["../../src/utils/getHeaderParam.ts"],"names":[],"mappings":";;;AAAA,SAAgB,cAAc,CAAC,OAAO,EAAE,KAAK;IAC3C,OAAO,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC3E,CAAC;AAFD,wCAEC"}
|