@open-rlb/nestjs-amqp 2.0.8 → 2.0.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/README.md +44 -45
- package/modules/acl/auth-match.d.ts +6 -0
- package/modules/acl/auth-match.js +10 -0
- package/modules/acl/auth-match.js.map +1 -0
- package/modules/acl/config/acl.config.d.ts +1 -0
- package/modules/acl/const.d.ts +5 -2
- package/modules/acl/const.js +6 -3
- package/modules/acl/const.js.map +1 -1
- package/modules/acl/index.d.ts +1 -0
- package/modules/acl/index.js +1 -0
- package/modules/acl/index.js.map +1 -1
- package/modules/acl/repository/acl-action.repository.d.ts +1 -0
- package/modules/acl/repository/acl-action.repository.js.map +1 -1
- package/modules/acl/repository/acl-grant.repository.d.ts +1 -0
- package/modules/acl/repository/acl-grant.repository.js.map +1 -1
- package/modules/acl/repository/acl-role.repository.d.ts +1 -0
- package/modules/acl/repository/acl-role.repository.js.map +1 -1
- package/modules/acl/services/acl-management.service.d.ts +10 -3
- package/modules/acl/services/acl-management.service.js +60 -10
- package/modules/acl/services/acl-management.service.js.map +1 -1
- package/modules/acl/services/acl.service.d.ts +3 -4
- package/modules/acl/services/acl.service.js +24 -46
- package/modules/acl/services/acl.service.js.map +1 -1
- package/modules/broker/config/decorator-paths.js +2 -2
- package/modules/broker/config/decorator-paths.js.map +1 -1
- package/modules/broker/decorators/broker-action.decorator.d.ts +1 -1
- package/modules/broker/decorators/broker-action.decorator.js +2 -2
- package/modules/broker/decorators/broker-action.decorator.js.map +1 -1
- package/modules/broker/services/shutdown-state.service.d.ts +1 -0
- package/modules/broker/services/shutdown-state.service.js +12 -12
- package/modules/broker/services/shutdown-state.service.js.map +1 -1
- package/modules/gateway-admin/config/gateway-admin.config.d.ts +2 -0
- package/modules/gateway-admin/const.d.ts +7 -0
- package/modules/gateway-admin/const.js +7 -0
- package/modules/gateway-admin/const.js.map +1 -1
- package/modules/gateway-admin/gateway-admin.module.js +4 -1
- package/modules/gateway-admin/gateway-admin.module.js.map +1 -1
- package/modules/gateway-admin/health.d.ts +14 -0
- package/modules/gateway-admin/health.js +5 -0
- package/modules/gateway-admin/health.js.map +1 -0
- package/modules/gateway-admin/index.d.ts +5 -0
- package/modules/gateway-admin/index.js +5 -0
- package/modules/gateway-admin/index.js.map +1 -1
- package/modules/gateway-admin/models.d.ts +61 -0
- package/modules/gateway-admin/repository/auth-provider.repository.d.ts +1 -0
- package/modules/gateway-admin/repository/auth-provider.repository.js.map +1 -1
- package/modules/gateway-admin/repository/http-metric.repository.d.ts +6 -2
- package/modules/gateway-admin/repository/http-metric.repository.js.map +1 -1
- package/modules/gateway-admin/repository/http-path.repository.d.ts +3 -0
- package/modules/gateway-admin/repository/http-path.repository.js.map +1 -1
- package/modules/gateway-admin/repository/route-sync-log.repository.d.ts +4 -1
- package/modules/gateway-admin/repository/route-sync-log.repository.js.map +1 -1
- package/modules/gateway-admin/services/gateway-auth.service.d.ts +1 -0
- package/modules/gateway-admin/services/gateway-auth.service.js +12 -0
- package/modules/gateway-admin/services/gateway-auth.service.js.map +1 -1
- package/modules/gateway-admin/services/gateway-health.service.d.ts +10 -0
- package/modules/gateway-admin/services/gateway-health.service.js +64 -0
- package/modules/gateway-admin/services/gateway-health.service.js.map +1 -0
- package/modules/gateway-admin/services/gateway-metrics-rollup.service.d.ts +13 -0
- package/modules/gateway-admin/services/gateway-metrics-rollup.service.js +63 -0
- package/modules/gateway-admin/services/gateway-metrics-rollup.service.js.map +1 -0
- package/modules/gateway-admin/services/gateway-metrics.service.d.ts +5 -4
- package/modules/gateway-admin/services/gateway-metrics.service.js +56 -17
- package/modules/gateway-admin/services/gateway-metrics.service.js.map +1 -1
- package/modules/gateway-admin/services/gateway-path.service.d.ts +11 -4
- package/modules/gateway-admin/services/gateway-path.service.js +79 -11
- package/modules/gateway-admin/services/gateway-path.service.js.map +1 -1
- package/modules/gateway-admin/services/gateway-retention.service.d.ts +16 -0
- package/modules/gateway-admin/services/gateway-retention.service.js +71 -0
- package/modules/gateway-admin/services/gateway-retention.service.js.map +1 -0
- package/modules/gateway-admin/services/route-sync.service.js +12 -5
- package/modules/gateway-admin/services/route-sync.service.js.map +1 -1
- package/modules/gateway-admin/util/metrics.d.ts +10 -0
- package/modules/gateway-admin/util/metrics.js +170 -0
- package/modules/gateway-admin/util/metrics.js.map +1 -0
- package/modules/gateway-admin/util/route-diff.d.ts +7 -0
- package/modules/gateway-admin/util/route-diff.js +7 -2
- package/modules/gateway-admin/util/route-diff.js.map +1 -1
- package/modules/gateway-admin/util/route-manifest.d.ts +3 -0
- package/modules/gateway-admin/util/route-manifest.js +36 -1
- package/modules/gateway-admin/util/route-manifest.js.map +1 -1
- package/modules/proxy/config/path-definition.config.d.ts +2 -2
- package/modules/proxy/services/acl.service.d.ts +2 -2
- package/modules/proxy/services/acl.service.js.map +1 -1
- package/modules/proxy/services/http-auth-handler.service.d.ts +6 -4
- package/modules/proxy/services/http-auth-handler.service.js +15 -9
- package/modules/proxy/services/http-auth-handler.service.js.map +1 -1
- package/modules/proxy/services/http-handler.service.d.ts +1 -0
- package/modules/proxy/services/http-handler.service.js +28 -35
- package/modules/proxy/services/http-handler.service.js.map +1 -1
- package/modules/proxy/services/metrics-hook.d.ts +1 -0
- package/modules/proxy/services/websocket.service.js +5 -5
- package/modules/proxy/services/websocket.service.js.map +1 -1
- package/package.json +1 -1
- package/schematics/nest-add/files/acl/src/modules/database/repository/acl.repository.ts +3 -0
- package/schematics/nest-add/files/db-core/src/modules/database/repository/in-memory-collection.ts +29 -0
- package/schematics/nest-add/files/gateway-admin/src/modules/database/repository/gateway.repository.ts +48 -20
- package/schematics/nest-add/files/gateway-admin/src/modules/database/repository/route-sync.repository.ts +24 -1
- package/schematics/nest-add/files/skills/rlb-amqp/SKILL.md +3 -3
- package/schematics/nest-add/files/skills/rlb-amqp/references/config-schema.md +18 -14
- package/schematics/nest-add/files/skills/rlb-amqp/references/gotchas.md +42 -17
- package/schematics/nest-add/files/skills/rlb-amqp-acl/SKILL.md +57 -39
- package/schematics/nest-add/files/skills/rlb-amqp-add-action/SKILL.md +4 -3
- package/schematics/nest-add/files/skills/rlb-amqp-add-route/SKILL.md +20 -14
- package/schematics/nest-add/files/skills/rlb-amqp-add-ws-event/SKILL.md +7 -6
- package/schematics/nest-add/files/skills/rlb-amqp-gateway-admin/SKILL.md +49 -9
- package/schematics/nest-add/files/skills/rlb-amqp-scaffold/SKILL.md +4 -4
- package/schematics/nest-add/index.js +78 -9
- package/schematics/nest-add/index.js.map +1 -1
- package/schematics/nest-add/index.ts +78 -9
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var GatewayRetentionService_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.GatewayRetentionService = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const const_1 = require("../const");
|
|
19
|
+
const http_metric_repository_1 = require("../repository/http-metric.repository");
|
|
20
|
+
const route_sync_log_repository_1 = require("../repository/route-sync-log.repository");
|
|
21
|
+
const DAY_MS = 86_400_000;
|
|
22
|
+
const DEFAULT_RETENTION_DAYS = 90;
|
|
23
|
+
const DEFAULT_ROLLUP_RETENTION_DAYS = 365;
|
|
24
|
+
let GatewayRetentionService = GatewayRetentionService_1 = class GatewayRetentionService {
|
|
25
|
+
constructor(logs, metrics, options) {
|
|
26
|
+
this.logs = logs;
|
|
27
|
+
this.metrics = metrics;
|
|
28
|
+
this.logger = new common_1.Logger(GatewayRetentionService_1.name);
|
|
29
|
+
this.windowMs = (options?.retentionDays ?? DEFAULT_RETENTION_DAYS) * DAY_MS;
|
|
30
|
+
this.rollupWindowMs = (options?.rollupRetentionDays ?? DEFAULT_ROLLUP_RETENTION_DAYS) * DAY_MS;
|
|
31
|
+
}
|
|
32
|
+
onApplicationBootstrap() {
|
|
33
|
+
if (this.windowMs <= 0 && this.rollupWindowMs <= 0) {
|
|
34
|
+
this.logger.log('[retention] disabled');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
void this.prune();
|
|
38
|
+
this.timer = setInterval(() => void this.prune(), DAY_MS);
|
|
39
|
+
this.timer.unref?.();
|
|
40
|
+
}
|
|
41
|
+
onModuleDestroy() {
|
|
42
|
+
if (this.timer)
|
|
43
|
+
clearInterval(this.timer);
|
|
44
|
+
}
|
|
45
|
+
async prune() {
|
|
46
|
+
const now = Date.now();
|
|
47
|
+
try {
|
|
48
|
+
let prunedLogs = 0, prunedPoints = 0, prunedRollups = 0;
|
|
49
|
+
if (this.windowMs > 0) {
|
|
50
|
+
const cutoff = now - this.windowMs;
|
|
51
|
+
prunedLogs = await this.logs.prune(cutoff);
|
|
52
|
+
prunedPoints = await this.metrics.prunePoints(cutoff);
|
|
53
|
+
}
|
|
54
|
+
if (this.rollupWindowMs > 0)
|
|
55
|
+
prunedRollups = await this.metrics.pruneRollups(now - this.rollupWindowMs);
|
|
56
|
+
this.logger.log(`[retention] pruned ${prunedLogs} journal + ${prunedPoints} point(s) + ${prunedRollups} rollup(s)`);
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
this.logger.warn(`[retention] prune failed: ${e?.message}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
exports.GatewayRetentionService = GatewayRetentionService;
|
|
64
|
+
exports.GatewayRetentionService = GatewayRetentionService = GatewayRetentionService_1 = __decorate([
|
|
65
|
+
(0, common_1.Injectable)(),
|
|
66
|
+
__param(2, (0, common_1.Optional)()),
|
|
67
|
+
__param(2, (0, common_1.Inject)(const_1.RLB_GW_ADMIN_OPTIONS)),
|
|
68
|
+
__metadata("design:paramtypes", [route_sync_log_repository_1.RouteSyncLogRepository,
|
|
69
|
+
http_metric_repository_1.HttpMetricRepository, Object])
|
|
70
|
+
], GatewayRetentionService);
|
|
71
|
+
//# sourceMappingURL=gateway-retention.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-retention.service.js","sourceRoot":"","sources":["../../../../libs/rlb-nestjs-amqp/src/modules/gateway-admin/services/gateway-retention.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA+G;AAE/G,oCAAgD;AAChD,iFAA4E;AAC5E,uFAAiF;AAEjF,MAAM,MAAM,GAAG,UAAU,CAAC;AAC1B,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAClC,MAAM,6BAA6B,GAAG,GAAG,CAAC;AAQnC,IAAM,uBAAuB,+BAA7B,MAAM,uBAAuB;IAMlC,YACmB,IAA4B,EAC5B,OAA6B,EACJ,OAAmC;QAF5D,SAAI,GAAJ,IAAI,CAAwB;QAC5B,YAAO,GAAP,OAAO,CAAsB;QAP/B,WAAM,GAAG,IAAI,eAAM,CAAC,yBAAuB,CAAC,IAAI,CAAC,CAAC;QAUjE,IAAI,CAAC,QAAQ,GAAG,CAAC,OAAO,EAAE,aAAa,IAAI,sBAAsB,CAAC,GAAG,MAAM,CAAC;QAC5E,IAAI,CAAC,cAAc,GAA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AAC,GAAG,CAAC,sBAAsB,UAAU,cAAc,YAAY,eAAe,aAAa,YAAY,CAAC,CAAC;QACtH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,6BAA8B,CAAW,EAAE,OAAO,EAAE,CAAC,CAAC;QACzE,CAAC;IACH,CAAC;CACF,CAAA;AA7CY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,mBAAU,GAAE;IAUR,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,4BAAoB,CAAC,CAAA;qCAFlB,kDAAsB;QACnB,6CAAoB;GARrC,uBAAuB,CA6CnC"}
|
|
@@ -88,19 +88,26 @@ let RouteSyncService = RouteSyncService_1 = class RouteSyncService {
|
|
|
88
88
|
await this.paths.updateById(u.existingId, u.model);
|
|
89
89
|
else
|
|
90
90
|
await this.paths.insert(u.model);
|
|
91
|
-
|
|
91
|
+
const rendered = u.changes?.length ? (0, route_manifest_1.renderChanges)(u.changes) : undefined;
|
|
92
|
+
await this.journal({ service, level: 'info', event: u.added ? 'added' : 'updated', routeKey: u.routeKey, method: u.model.method, path: u.model.path, topic: u.model.topic, action: u.model.action, changes: u.changes, message: rendered });
|
|
93
|
+
if (rendered)
|
|
94
|
+
this.logger.log(`[route-sync] ${service}: '${u.routeKey}' updated → ${rendered}`);
|
|
92
95
|
}
|
|
93
96
|
for (const d of diff.disables) {
|
|
94
97
|
await this.paths.updateById(d.id, { enabled: false });
|
|
95
98
|
await this.journal({ service, level: 'info', event: 'removed', routeKey: d.routeKey, method: d.method, path: d.path });
|
|
96
99
|
}
|
|
100
|
+
for (const s of diff.skipped) {
|
|
101
|
+
this.logger.log(`[route-sync] ${service}: '${s.routeKey}' is user-modified → manifest update skipped (user version kept)`);
|
|
102
|
+
await this.journal({ service, level: 'info', event: 'skipped', routeKey: s.routeKey, method: s.method, path: s.path, message: 'route user-modified; manifest update skipped' });
|
|
103
|
+
}
|
|
97
104
|
if (diff.changed) {
|
|
98
105
|
await this.triggerReload();
|
|
99
|
-
await this.journal({ service, level: 'info', event: 'reload', message: `${diff.upserts.length} upserted, ${diff.disables.length} removed, ${diff.collisions.length} collision(s)` });
|
|
100
|
-
this.logger.log(`[route-sync] ${service}: ${diff.upserts.length} upserted, ${diff.disables.length} removed, ${diff.collisions.length} collision(s) → reload`);
|
|
106
|
+
await this.journal({ service, level: 'info', event: 'reload', message: `${diff.upserts.length} upserted, ${diff.disables.length} removed, ${diff.skipped.length} user-modified skipped, ${diff.collisions.length} collision(s)` });
|
|
107
|
+
this.logger.log(`[route-sync] ${service}: ${diff.upserts.length} upserted, ${diff.disables.length} removed, ${diff.skipped.length} user-modified skipped, ${diff.collisions.length} collision(s) → reload`);
|
|
101
108
|
}
|
|
102
109
|
else {
|
|
103
|
-
this.logger.log(`[route-sync] ${service}: no route changes (${diff.collisions.length} collision(s))`);
|
|
110
|
+
this.logger.log(`[route-sync] ${service}: no route changes (${diff.skipped.length} user-modified skipped, ${diff.collisions.length} collision(s))`);
|
|
104
111
|
}
|
|
105
112
|
}
|
|
106
113
|
catch (e) {
|
|
@@ -109,7 +116,7 @@ let RouteSyncService = RouteSyncService_1 = class RouteSyncService {
|
|
|
109
116
|
}
|
|
110
117
|
async journal(entry) {
|
|
111
118
|
try {
|
|
112
|
-
await this.logs.insert({ ts: Date.now(), ...entry });
|
|
119
|
+
await this.logs.insert({ ts: Date.now(), actor: 'system', ...entry });
|
|
113
120
|
}
|
|
114
121
|
catch (e) {
|
|
115
122
|
this.logger.warn(`[route-sync] journal write failed: ${e?.message}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-sync.service.js","sourceRoot":"","sources":["../../../../libs/rlb-nestjs-amqp/src/modules/gateway-admin/services/route-sync.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA8F;AAC9F,gDAAmD;AACnD,yCAA4D;AAC5D,8CAA4H;AAG5H,oCAAgD;AAEhD,6EAAwE;AACxE,uFAAiF;AACjF,mDAAgD;AAChD,
|
|
1
|
+
{"version":3,"file":"route-sync.service.js","sourceRoot":"","sources":["../../../../libs/rlb-nestjs-amqp/src/modules/gateway-admin/services/route-sync.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA8F;AAC9F,gDAAmD;AACnD,yCAA4D;AAC5D,8CAA4H;AAG5H,oCAAgD;AAEhD,6EAAwE;AACxE,uFAAiF;AACjF,mDAAgD;AAChD,2DAAmE;AAU5D,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IAG3B,YACmB,IAAoB,EACpB,MAAqB,EACrB,KAAyB,EACzB,IAA4B,EACX,aAA6C,EAGrC,YAAyD;QAPlF,SAAI,GAAJ,IAAI,CAAgB;QACpB,WAAM,GAAN,MAAM,CAAe;QACrB,UAAK,GAAL,KAAK,CAAoB;QACzB,SAAI,GAAJ,IAAI,CAAwB;QACM,kBAAa,GAAb,aAAa,CAAe;QAGpB,iBAAY,GAAZ,YAAY,CAA4B;QAVpF,WAAM,GAAG,IAAI,eAAM,CAAC,kBAAgB,CAAC,IAAI,CAAC,CAAC;IAWxD,CAAC;IAEL,KAAK,CAAC,sBAAsB;QAC1B,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,cAAc,EAAE,QAAQ,IAAI,gCAAwB,CAAC;QACzF,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,EAAE,cAAc,EAAE,KAAK,IAAI,wBAAgB,CAAC;QAC3E,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;YAC9E,MAAM,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAC9B,KAAK,EAAE,GAAkB,EAAE,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC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CAAC,MAAM,CAAC,IAAI,CAAC,sGAAsG,CAAC,CAAC;YACzH,OAAO;QACT,CAAC;QAID,IAAI,CAAC;YAAC,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,wBAAgB,EAAE,EAAE,CAAC,CAAC;QAAC,CAAC;QACtE,OAAO,CAAC,EAAE,CAAC;YAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,yCAA0C,CAAW,EAAE,OAAO,EAAE,CAAC,CAAC;QAAC,CAAC;IACpG,CAAC;CACF,CAAA;AAvHY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;IASR,WAAA,IAAA,eAAM,EAAC,gCAAwB,CAAC,CAAA;IAGhC,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,4BAAoB,CAAC,CAAA;qCAPlB,yBAAc;QACZ,sBAAa;QACd,yCAAkB;QACnB,kDAAsB;GAPpC,gBAAgB,CAuH5B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HttpMetric, HttpMetricPoint, HttpMetricRollup, MetricSeriesBucket, MetricSeriesQuery, MetricStatusClass, MetricSummary } from '../models';
|
|
2
|
+
export declare function statusClass(status?: number): MetricStatusClass | undefined;
|
|
3
|
+
export declare function percentile(sortedAsc: number[], p: number): number | undefined;
|
|
4
|
+
export declare function buildSeries(points: HttpMetricPoint[], query: MetricSeriesQuery): MetricSeriesBucket[];
|
|
5
|
+
export declare function buildSummary(points: HttpMetricPoint[], topN?: number): MetricSummary;
|
|
6
|
+
export declare function aggregateRollups(points: HttpMetricPoint[], granularityMs: number): HttpMetricRollup[];
|
|
7
|
+
export declare function toPrometheus(counters: (HttpMetric & {
|
|
8
|
+
avgDurationMs: number;
|
|
9
|
+
errorRate?: number;
|
|
10
|
+
})[]): string;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.statusClass = statusClass;
|
|
4
|
+
exports.percentile = percentile;
|
|
5
|
+
exports.buildSeries = buildSeries;
|
|
6
|
+
exports.buildSummary = buildSummary;
|
|
7
|
+
exports.aggregateRollups = aggregateRollups;
|
|
8
|
+
exports.toPrometheus = toPrometheus;
|
|
9
|
+
function statusClass(status) {
|
|
10
|
+
if (status == null)
|
|
11
|
+
return undefined;
|
|
12
|
+
if (status >= 500)
|
|
13
|
+
return '5xx';
|
|
14
|
+
if (status >= 400)
|
|
15
|
+
return '4xx';
|
|
16
|
+
if (status >= 300)
|
|
17
|
+
return '3xx';
|
|
18
|
+
if (status >= 200)
|
|
19
|
+
return '2xx';
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
function percentile(sortedAsc, p) {
|
|
23
|
+
if (!sortedAsc.length)
|
|
24
|
+
return undefined;
|
|
25
|
+
const rank = Math.ceil((p / 100) * sortedAsc.length);
|
|
26
|
+
const idx = Math.min(sortedAsc.length - 1, Math.max(0, rank - 1));
|
|
27
|
+
return sortedAsc[idx];
|
|
28
|
+
}
|
|
29
|
+
function emptyStatusClasses() {
|
|
30
|
+
return { '2xx': 0, '3xx': 0, '4xx': 0, '5xx': 0 };
|
|
31
|
+
}
|
|
32
|
+
function buildSeries(points, query) {
|
|
33
|
+
const width = query.bucketMs > 0 ? query.bucketMs : 60_000;
|
|
34
|
+
const buckets = new Map();
|
|
35
|
+
for (const p of points || []) {
|
|
36
|
+
const start = Math.floor(p.ts / width) * width;
|
|
37
|
+
let b = buckets.get(start);
|
|
38
|
+
if (!b) {
|
|
39
|
+
b = { durations: [], count: 0, errorCount: 0, total: 0, byStatus: emptyStatusClasses() };
|
|
40
|
+
buckets.set(start, b);
|
|
41
|
+
}
|
|
42
|
+
b.count++;
|
|
43
|
+
if ((p.status ?? 0) >= 400)
|
|
44
|
+
b.errorCount++;
|
|
45
|
+
const d = p.durationMs ?? 0;
|
|
46
|
+
b.total += d;
|
|
47
|
+
b.durations.push(d);
|
|
48
|
+
b.min = b.min == null ? d : Math.min(b.min, d);
|
|
49
|
+
b.max = b.max == null ? d : Math.max(b.max, d);
|
|
50
|
+
const sc = statusClass(p.status);
|
|
51
|
+
if (sc)
|
|
52
|
+
b.byStatus[sc]++;
|
|
53
|
+
}
|
|
54
|
+
return [...buckets.entries()].sort((a, b) => a[0] - b[0]).map(([bucketStart, b]) => {
|
|
55
|
+
const sorted = b.durations.sort((x, y) => x - y);
|
|
56
|
+
return {
|
|
57
|
+
bucketStart,
|
|
58
|
+
count: b.count,
|
|
59
|
+
errorCount: b.errorCount,
|
|
60
|
+
totalDurationMs: b.total,
|
|
61
|
+
avgDurationMs: b.count ? Math.round(b.total / b.count) : 0,
|
|
62
|
+
minDurationMs: b.min,
|
|
63
|
+
maxDurationMs: b.max,
|
|
64
|
+
p50: percentile(sorted, 50),
|
|
65
|
+
p95: percentile(sorted, 95),
|
|
66
|
+
p99: percentile(sorted, 99),
|
|
67
|
+
byStatus: b.byStatus,
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function buildSummary(points, topN = 10) {
|
|
72
|
+
const byStatus = emptyStatusClasses();
|
|
73
|
+
const durations = [];
|
|
74
|
+
let total = 0;
|
|
75
|
+
let errors = 0;
|
|
76
|
+
const per = new Map();
|
|
77
|
+
for (const p of points || []) {
|
|
78
|
+
const d = p.durationMs ?? 0;
|
|
79
|
+
durations.push(d);
|
|
80
|
+
total += d;
|
|
81
|
+
const isError = (p.status ?? 0) >= 400;
|
|
82
|
+
if (isError)
|
|
83
|
+
errors++;
|
|
84
|
+
const sc = statusClass(p.status);
|
|
85
|
+
if (sc)
|
|
86
|
+
byStatus[sc]++;
|
|
87
|
+
const key = `${p.method} ${p.route}`;
|
|
88
|
+
let e = per.get(key);
|
|
89
|
+
if (!e) {
|
|
90
|
+
e = { method: p.method, route: p.route, name: p.name, count: 0, errorCount: 0, total: 0, durations: [] };
|
|
91
|
+
per.set(key, e);
|
|
92
|
+
}
|
|
93
|
+
e.count++;
|
|
94
|
+
e.total += d;
|
|
95
|
+
e.durations.push(d);
|
|
96
|
+
if (isError)
|
|
97
|
+
e.errorCount++;
|
|
98
|
+
}
|
|
99
|
+
const n = points?.length || 0;
|
|
100
|
+
const sortedAll = durations.sort((a, b) => a - b);
|
|
101
|
+
const entries = [...per.values()].map((e) => {
|
|
102
|
+
const sorted = e.durations.sort((a, b) => a - b);
|
|
103
|
+
return {
|
|
104
|
+
method: e.method, route: e.route, name: e.name,
|
|
105
|
+
count: e.count, errorCount: e.errorCount,
|
|
106
|
+
errorRate: e.count ? e.errorCount / e.count : 0,
|
|
107
|
+
avgDurationMs: e.count ? Math.round(e.total / e.count) : 0,
|
|
108
|
+
p95: percentile(sorted, 95),
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
const top = (cmp) => [...entries].sort(cmp).slice(0, topN);
|
|
112
|
+
return {
|
|
113
|
+
totalRequests: n,
|
|
114
|
+
totalErrors: errors,
|
|
115
|
+
errorRate: n ? errors / n : 0,
|
|
116
|
+
avgDurationMs: n ? Math.round(total / n) : 0,
|
|
117
|
+
p50: percentile(sortedAll, 50),
|
|
118
|
+
p95: percentile(sortedAll, 95),
|
|
119
|
+
p99: percentile(sortedAll, 99),
|
|
120
|
+
byStatus,
|
|
121
|
+
topByTraffic: top((a, b) => b.count - a.count),
|
|
122
|
+
topByErrors: top((a, b) => (b.errorCount - a.errorCount) || (b.errorRate - a.errorRate)),
|
|
123
|
+
topByLatency: top((a, b) => (b.p95 ?? 0) - (a.p95 ?? 0)),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function aggregateRollups(points, granularityMs) {
|
|
127
|
+
const g = granularityMs > 0 ? granularityMs : 3_600_000;
|
|
128
|
+
const rollups = new Map();
|
|
129
|
+
for (const p of points || []) {
|
|
130
|
+
const bucketStart = Math.floor(p.ts / g) * g;
|
|
131
|
+
const key = `${bucketStart}|${p.method}|${p.route}`;
|
|
132
|
+
let r = rollups.get(key);
|
|
133
|
+
if (!r) {
|
|
134
|
+
r = { bucketStart, granularityMs: g, method: p.method, route: p.route, name: p.name, count: 0, errorCount: 0, totalDurationMs: 0, byStatus: emptyStatusClasses() };
|
|
135
|
+
rollups.set(key, r);
|
|
136
|
+
}
|
|
137
|
+
r.count++;
|
|
138
|
+
if ((p.status ?? 0) >= 400)
|
|
139
|
+
r.errorCount++;
|
|
140
|
+
const d = p.durationMs ?? 0;
|
|
141
|
+
r.totalDurationMs += d;
|
|
142
|
+
r.minDurationMs = r.minDurationMs == null ? d : Math.min(r.minDurationMs, d);
|
|
143
|
+
r.maxDurationMs = r.maxDurationMs == null ? d : Math.max(r.maxDurationMs, d);
|
|
144
|
+
const sc = statusClass(p.status);
|
|
145
|
+
if (sc && r.byStatus)
|
|
146
|
+
r.byStatus[sc]++;
|
|
147
|
+
}
|
|
148
|
+
return [...rollups.values()];
|
|
149
|
+
}
|
|
150
|
+
function escapeLabel(value) {
|
|
151
|
+
return String(value ?? '').replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, ' ');
|
|
152
|
+
}
|
|
153
|
+
function toPrometheus(counters) {
|
|
154
|
+
const labels = (m) => `method="${escapeLabel(m.method)}",route="${escapeLabel(m.route)}"${m.name ? `,name="${escapeLabel(m.name)}"` : ''}`;
|
|
155
|
+
const lines = [];
|
|
156
|
+
lines.push('# HELP gateway_requests_total Total HTTP requests handled by the gateway.');
|
|
157
|
+
lines.push('# TYPE gateway_requests_total counter');
|
|
158
|
+
for (const m of counters || [])
|
|
159
|
+
lines.push(`gateway_requests_total{${labels(m)}} ${m.count}`);
|
|
160
|
+
lines.push('# HELP gateway_request_errors_total Error responses (status >= 400).');
|
|
161
|
+
lines.push('# TYPE gateway_request_errors_total counter');
|
|
162
|
+
for (const m of counters || [])
|
|
163
|
+
lines.push(`gateway_request_errors_total{${labels(m)}} ${m.errorCount}`);
|
|
164
|
+
lines.push('# HELP gateway_request_duration_ms_sum Total request duration in milliseconds.');
|
|
165
|
+
lines.push('# TYPE gateway_request_duration_ms_sum counter');
|
|
166
|
+
for (const m of counters || [])
|
|
167
|
+
lines.push(`gateway_request_duration_ms_sum{${labels(m)}} ${m.totalDurationMs}`);
|
|
168
|
+
return lines.join('\n') + '\n';
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../../libs/rlb-nestjs-amqp/src/modules/gateway-admin/util/metrics.ts"],"names":[],"mappings":";;AAGA,kCAOC;AAGD,gCAKC;AAOD,kCAgCC;AAID,oCA8CC;AAGD,4CAkBC;AAQD,oCAaC;AAlJD,SAAgB,WAAW,CAAC,MAAe;IACzC,IAAI,MAAM,IAAI,IAAI;QAAE,OAAO,SAAS,CAAC;IACrC,IAAI,MAAM,IAAI,GAAG;QAAE,OAAO,KAAK,CAAC;IAChC,IAAI,MAAM,IAAI,GAAG;QAAE,OAAO,KAAK,CAAC;IAChC,IAAI,MAAM,IAAI,GAAG;QAAE,OAAO,KAAK,CAAC;IAChC,IAAI,MAAM,IAAI,GAAG;QAAE,OAAO,KAAK,CAAC;IAChC,OAAO,SAAS,CAAC;AACnB,CAAC;AAGD,SAAgB,UAAU,CAAC,SAAmB,EAAE,CAAS;IACvD,IAAI,CAAC,SAAS,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IACxC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;IACrD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;IAClE,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC;AAED,SAAS,kBAAkB;IACzB,OAAO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AK,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IAC9F,KAAK,CAAC,IAAI,CAAC,sEAAsE,CAAC,CAAC;IACnF,KAAK,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;IAC1D,KAAK,MAAM,CAAC,IAAI,QAAQ,IAAI,EAAE;QAAE,KAAK,CAAC,IAAI,CAAC,gCAAgC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC;IACzG,KAAK,CAAC,IAAI,CAAC,gFAAgF,CAAC,CAAC;IAC7F,KAAK,CAAC,IAAI,CAAC,gDAAgD,CAAC,CAAC;IAC7D,KAAK,MAAM,CAAC,IAAI,QAAQ,IAAI,EAAE;QAAE,KAAK,CAAC,IAAI,CAAC,mCAAmC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC;IACjH,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AACjC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PathDefinition } from '../../proxy/config/path-definition.config';
|
|
2
|
+
import { RouteFieldChange } from '../models';
|
|
2
3
|
import { StoredHttpPath } from '../repository/http-path.repository';
|
|
3
4
|
export interface RouteDiff {
|
|
4
5
|
upserts: {
|
|
@@ -6,6 +7,7 @@ export interface RouteDiff {
|
|
|
6
7
|
existingId?: string;
|
|
7
8
|
added: boolean;
|
|
8
9
|
model: StoredHttpPath;
|
|
10
|
+
changes?: RouteFieldChange[];
|
|
9
11
|
}[];
|
|
10
12
|
disables: {
|
|
11
13
|
id: string;
|
|
@@ -19,6 +21,11 @@ export interface RouteDiff {
|
|
|
19
21
|
path?: string;
|
|
20
22
|
conflictWith: string;
|
|
21
23
|
}[];
|
|
24
|
+
skipped: {
|
|
25
|
+
routeKey: string;
|
|
26
|
+
method?: string;
|
|
27
|
+
path?: string;
|
|
28
|
+
}[];
|
|
22
29
|
invalid: {
|
|
23
30
|
route: any;
|
|
24
31
|
}[];
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.diffRoutes = diffRoutes;
|
|
4
4
|
const route_manifest_1 = require("./route-manifest");
|
|
5
5
|
function diffRoutes(service, incoming, existing, reserved) {
|
|
6
|
-
const diff = { upserts: [], disables: [], collisions: [], invalid: [], changed: false };
|
|
6
|
+
const diff = { upserts: [], disables: [], collisions: [], skipped: [], invalid: [], changed: false };
|
|
7
7
|
const existingByKey = new Map();
|
|
8
8
|
for (const e of existing || [])
|
|
9
9
|
if (e.routeKey)
|
|
@@ -24,13 +24,18 @@ function diffRoutes(service, incoming, existing, reserved) {
|
|
|
24
24
|
continue;
|
|
25
25
|
}
|
|
26
26
|
const ex = existingByKey.get(key);
|
|
27
|
+
if (ex && ex.modified === true) {
|
|
28
|
+
diff.skipped.push({ routeKey: key, method: r.method, path: r.path });
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
27
31
|
if (ex && ex.enabled !== false && (0, route_manifest_1.routeContent)(ex) === (0, route_manifest_1.routeContent)(r))
|
|
28
32
|
continue;
|
|
29
33
|
diff.upserts.push({
|
|
30
34
|
routeKey: key,
|
|
31
35
|
existingId: ex?._id,
|
|
32
36
|
added: !ex,
|
|
33
|
-
model: { ...r, owner: service, routeKey: key, enabled: true },
|
|
37
|
+
model: { ...r, owner: service, routeKey: key, enabled: true, source: 'microservice', modified: false },
|
|
38
|
+
changes: ex ? (0, route_manifest_1.diffRouteFields)(ex, r) : undefined,
|
|
34
39
|
});
|
|
35
40
|
}
|
|
36
41
|
for (const [key, ex] of existingByKey) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-diff.js","sourceRoot":"","sources":["../../../../libs/rlb-nestjs-amqp/src/modules/gateway-admin/util/route-diff.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"route-diff.js","sourceRoot":"","sources":["../../../../libs/rlb-nestjs-amqp/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,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QACvF,CAAC;IACH,CAAC;IAED,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IACnE,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RouteFieldChange } from '../models';
|
|
1
2
|
export declare function routeKeyOf(r: {
|
|
2
3
|
method?: string;
|
|
3
4
|
path?: string;
|
|
@@ -5,3 +6,5 @@ export declare function routeKeyOf(r: {
|
|
|
5
6
|
export declare function stableStringify(value: any): string;
|
|
6
7
|
export declare function routeContent(r: any): string;
|
|
7
8
|
export declare function isValidRoute(r: any): boolean;
|
|
9
|
+
export declare function diffRouteFields(before: any, after: any): RouteFieldChange[];
|
|
10
|
+
export declare function renderChanges(changes: RouteFieldChange[]): string;
|
|
@@ -4,6 +4,8 @@ exports.routeKeyOf = routeKeyOf;
|
|
|
4
4
|
exports.stableStringify = stableStringify;
|
|
5
5
|
exports.routeContent = routeContent;
|
|
6
6
|
exports.isValidRoute = isValidRoute;
|
|
7
|
+
exports.diffRouteFields = diffRouteFields;
|
|
8
|
+
exports.renderChanges = renderChanges;
|
|
7
9
|
function routeKeyOf(r) {
|
|
8
10
|
return `${(r.method || '').toUpperCase()} ${r.path || ''}`;
|
|
9
11
|
}
|
|
@@ -11,12 +13,13 @@ function canonicalRoute(r) {
|
|
|
11
13
|
return {
|
|
12
14
|
name: r.name, method: r.method, path: r.path, dataSource: r.dataSource,
|
|
13
15
|
topic: r.topic, action: r.action, mode: r.mode, auth: r.auth ?? null,
|
|
14
|
-
allowAnonymous: r.allowAnonymous ?? null,
|
|
16
|
+
allowAnonymous: r.allowAnonymous ?? null, actions: r.actions ?? [],
|
|
15
17
|
successStatusCode: r.successStatusCode ?? null, timeout: r.timeout ?? null,
|
|
16
18
|
parseRaw: r.parseRaw ?? null, binary: r.binary ?? null, redirect: r.redirect ?? null,
|
|
17
19
|
headers: r.headers ?? {}, forwardHeaders: r.forwardHeaders ?? {},
|
|
18
20
|
};
|
|
19
21
|
}
|
|
22
|
+
const ROUTE_FIELDS = Object.keys(canonicalRoute({}));
|
|
20
23
|
function stableStringify(value) {
|
|
21
24
|
if (value === null || typeof value !== 'object')
|
|
22
25
|
return JSON.stringify(value) ?? 'null';
|
|
@@ -31,4 +34,36 @@ function routeContent(r) {
|
|
|
31
34
|
function isValidRoute(r) {
|
|
32
35
|
return !!(r && r.method && r.path && r.topic && r.action && (r.mode === 'rpc' || r.mode === 'event'));
|
|
33
36
|
}
|
|
37
|
+
function fmtChangeValue(v) {
|
|
38
|
+
return typeof v === 'object' && v !== null ? JSON.stringify(v) : String(v);
|
|
39
|
+
}
|
|
40
|
+
function diffRouteFields(before, after) {
|
|
41
|
+
const changes = [];
|
|
42
|
+
for (const field of ROUTE_FIELDS) {
|
|
43
|
+
const b = before?.[field];
|
|
44
|
+
const a = after?.[field];
|
|
45
|
+
if (stableStringify(b ?? null) === stableStringify(a ?? null))
|
|
46
|
+
continue;
|
|
47
|
+
if (Array.isArray(b) || Array.isArray(a)) {
|
|
48
|
+
const bArr = Array.isArray(b) ? b : [];
|
|
49
|
+
const aArr = Array.isArray(a) ? a : [];
|
|
50
|
+
const bKeys = new Set(bArr.map(stableStringify));
|
|
51
|
+
const aKeys = new Set(aArr.map(stableStringify));
|
|
52
|
+
changes.push({
|
|
53
|
+
field,
|
|
54
|
+
added: aArr.filter((x) => !bKeys.has(stableStringify(x))),
|
|
55
|
+
removed: bArr.filter((x) => !aKeys.has(stableStringify(x))),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
changes.push({ field, added: a == null ? [] : [a], removed: b == null ? [] : [b] });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return changes;
|
|
63
|
+
}
|
|
64
|
+
function renderChanges(changes) {
|
|
65
|
+
return (changes || [])
|
|
66
|
+
.map((c) => `${c.field}: [${[...(c.added || []).map((v) => `+${fmtChangeValue(v)}`), ...(c.removed || []).map((v) => `-${fmtChangeValue(v)}`)].join(', ')}]`)
|
|
67
|
+
.join(', ');
|
|
68
|
+
}
|
|
34
69
|
//# sourceMappingURL=route-manifest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-manifest.js","sourceRoot":"","sources":["../../../../libs/rlb-nestjs-amqp/src/modules/gateway-admin/util/route-manifest.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"route-manifest.js","sourceRoot":"","sources":["../../../../libs/rlb-nestjs-amqp/src/modules/gateway-admin/util/route-manifest.ts"],"names":[],"mappings":";;AAGA,gCAEC;AAwBD,0CAKC;AAOD,oCAEC;AAID,oCAEC;AAWD,0CAqBC;AAGD,sCAIC;AArFD,SAAgB,UAAU,CAAC,CAAqC;IAC9D,OAAO,GAAG,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;AAC7D,CAAC;AAGD,SAAS,cAAc,CAAC,CAAM;IAC5B,OAAO;QACL,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU;QACtE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI;QACpE,cAAc,EAAE,CAAC,CAAC,cAAc,IAAI,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,IAAI,EAAE;QAClE,iBAA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I,CAAC,CAAC;AAChB,CAAC"}
|
|
@@ -10,7 +10,7 @@ export interface PathDefinition {
|
|
|
10
10
|
mode: 'event' | 'rpc';
|
|
11
11
|
auth?: string;
|
|
12
12
|
allowAnonymous?: boolean;
|
|
13
|
-
|
|
13
|
+
actions?: string | string[];
|
|
14
14
|
timeout?: number;
|
|
15
15
|
binary?: boolean;
|
|
16
16
|
headers: {
|
|
@@ -28,7 +28,7 @@ export interface WebSocketEvent {
|
|
|
28
28
|
name: string;
|
|
29
29
|
auth?: string;
|
|
30
30
|
requireAuth?: boolean;
|
|
31
|
-
|
|
31
|
+
actions?: string | string[];
|
|
32
32
|
scopeClaim?: string;
|
|
33
33
|
payloadKey?: string;
|
|
34
34
|
url?: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { AclResourceContext } from '../../acl/auth-match';
|
|
1
2
|
export declare const RLB_GTW_ACL_ROLE_SERVICE = "RLB_GTW_ACL_ROLE_SERVICE";
|
|
2
3
|
export interface IAclRoleService {
|
|
3
|
-
|
|
4
|
-
canUserDo(roles: string | string[], userId: string, resourceId?: string): Promise<boolean>;
|
|
4
|
+
checkAction(userId: string, ctx: AclResourceContext | undefined, action: string | string[]): Promise<boolean>;
|
|
5
5
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"acl.service.js","sourceRoot":"","sources":["../../../../libs/rlb-nestjs-amqp/src/modules/proxy/services/acl.service.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"acl.service.js","sourceRoot":"","sources":["../../../../libs/rlb-nestjs-amqp/src/modules/proxy/services/acl.service.ts"],"names":[],"mappings":";;;AAEa,QAAA,wBAAwB,GAAG,0BAA0B,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Request } from 'express';
|
|
2
2
|
import { ProcessedAuthData } from '..';
|
|
3
|
+
import { AclResourceContext } from '../../acl/auth-match';
|
|
3
4
|
import { HandlerAuthConfig } from '../../broker/config/handler-auth.config';
|
|
4
5
|
import { PathDefinition } from '../config/path-definition.config';
|
|
5
6
|
import { IAclRoleService } from './acl.service';
|
|
@@ -15,12 +16,13 @@ export declare class HttpAuthHandlerService {
|
|
|
15
16
|
verifyToken(authConfig: HandlerAuthConfig, token: string): Promise<any | undefined>;
|
|
16
17
|
mapClaims(authConfig: HandlerAuthConfig, decoded: any): ProcessedAuthData;
|
|
17
18
|
checkJwt(req: Request, authConfig: HandlerAuthConfig): Promise<ProcessedAuthData>;
|
|
18
|
-
|
|
19
|
+
checkActionsForClaims(authConfig: HandlerAuthConfig, claims: {
|
|
19
20
|
[key: string]: any;
|
|
20
|
-
},
|
|
21
|
+
}, actions?: string | string[], ctx?: AclResourceContext): Promise<boolean>;
|
|
21
22
|
checkBasicAuth(req: Request, authConfig: HandlerAuthConfig): Promise<ProcessedAuthData>;
|
|
22
23
|
checkStringCompare(req: Request, authConfig: HandlerAuthConfig): Promise<ProcessedAuthData>;
|
|
23
|
-
|
|
24
|
+
extractResourceContext(req: Request): AclResourceContext;
|
|
25
|
+
checkActions(data: {
|
|
24
26
|
[key: string]: any;
|
|
25
|
-
}, path: PathDefinition): Promise<boolean>;
|
|
27
|
+
}, path: PathDefinition, ctx?: AclResourceContext): Promise<boolean>;
|
|
26
28
|
}
|
|
@@ -84,12 +84,12 @@ let HttpAuthHandlerService = HttpAuthHandlerService_1 = class HttpAuthHandlerSer
|
|
|
84
84
|
const decoded = await this.verifyToken(authConfig, jwt);
|
|
85
85
|
return this.mapClaims(authConfig, decoded);
|
|
86
86
|
}
|
|
87
|
-
async
|
|
88
|
-
const list = Array.isArray(
|
|
87
|
+
async checkActionsForClaims(authConfig, claims, actions, ctx) {
|
|
88
|
+
const list = Array.isArray(actions) ? actions : (actions ? [actions] : []);
|
|
89
89
|
if (!list.length)
|
|
90
90
|
return true;
|
|
91
91
|
if (authConfig.type !== 'jwt' && authConfig.type !== 'jwks') {
|
|
92
|
-
this.logger.error(`Auth provider '${authConfig.name}' is not a JWT/JWKS provider; cannot run
|
|
92
|
+
this.logger.error(`Auth provider '${authConfig.name}' is not a JWT/JWKS provider; cannot run authorization checks → denying.`);
|
|
93
93
|
return false;
|
|
94
94
|
}
|
|
95
95
|
if (!authConfig.uidClaim) {
|
|
@@ -97,7 +97,7 @@ let HttpAuthHandlerService = HttpAuthHandlerService_1 = class HttpAuthHandlerSer
|
|
|
97
97
|
return false;
|
|
98
98
|
}
|
|
99
99
|
if (!this.aclRoleService) {
|
|
100
|
-
this.logger.error(`ACL
|
|
100
|
+
this.logger.error(`ACL service not found (RLB_GTW_ACL_ROLE_SERVICE not registered) but a path requires actions → denying.`);
|
|
101
101
|
return false;
|
|
102
102
|
}
|
|
103
103
|
if (!claims)
|
|
@@ -105,7 +105,7 @@ let HttpAuthHandlerService = HttpAuthHandlerService_1 = class HttpAuthHandlerSer
|
|
|
105
105
|
const userId = claims[`${authConfig.headerPrefix}${authConfig.uidClaim}`];
|
|
106
106
|
if (!userId)
|
|
107
107
|
return false;
|
|
108
|
-
return this.aclRoleService.
|
|
108
|
+
return this.aclRoleService.checkAction(userId, ctx, list);
|
|
109
109
|
}
|
|
110
110
|
async checkBasicAuth(req, authConfig) {
|
|
111
111
|
let out = { success: false };
|
|
@@ -148,17 +148,23 @@ let HttpAuthHandlerService = HttpAuthHandlerService_1 = class HttpAuthHandlerSer
|
|
|
148
148
|
}
|
|
149
149
|
return out;
|
|
150
150
|
}
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
extractResourceContext(req) {
|
|
152
|
+
return {
|
|
153
|
+
companyId: req.params?.companyId ?? req.query?.companyId ?? req.body?.companyId,
|
|
154
|
+
resourceId: req.params?.resourceId ?? req.query?.resourceId ?? req.body?.resourceId,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
async checkActions(data, path, ctx) {
|
|
158
|
+
if (!path?.actions?.length)
|
|
153
159
|
return true;
|
|
154
160
|
if (!path?.auth)
|
|
155
161
|
return false;
|
|
156
162
|
const authConfig = this.authProviders.find(o => o.name === path.auth);
|
|
157
163
|
if (!authConfig) {
|
|
158
|
-
this.logger.error(`Path '${path.name || path.path}' references unknown auth provider '${path.auth}' → denying
|
|
164
|
+
this.logger.error(`Path '${path.name || path.path}' references unknown auth provider '${path.auth}' → denying authorization check.`);
|
|
159
165
|
return false;
|
|
160
166
|
}
|
|
161
|
-
return this.
|
|
167
|
+
return this.checkActionsForClaims(authConfig, data, path.actions, ctx);
|
|
162
168
|
}
|
|
163
169
|
};
|
|
164
170
|
exports.HttpAuthHandlerService = HttpAuthHandlerService;
|