@attraccess/plugin-rabbitmq 0.1.0-nightly.991.1 → 0.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/dist/index.js CHANGED
@@ -33,18 +33,52 @@ __export(plugin_exports, {
33
33
  default: () => plugin_default
34
34
  });
35
35
  module.exports = __toCommonJS(plugin_exports);
36
- var import_plugins_backend_sdk3 = require("@attraccess/plugins-backend-sdk");
37
- var import_common7 = require("@nestjs/common");
38
-
39
- // backend/rabbitmq-detection.controller.ts
40
- var import_plugins_backend_sdk = require("@attraccess/plugins-backend-sdk");
41
- var import_common2 = require("@nestjs/common");
36
+ var import_plugins_backend_sdk7 = require("@attraccess/plugins-backend-sdk");
37
+ var import_common9 = require("@nestjs/common");
42
38
 
43
- // backend/rabbitmq-detection.service.ts
39
+ // backend/detection/service.ts
40
+ var import_plugins_backend_sdk2 = require("@attraccess/plugins-backend-sdk");
44
41
  var import_common = require("@nestjs/common");
45
42
  var import_node_crypto2 = require("node:crypto");
46
43
 
47
- // backend/rabbitmq-management-transport.ts
44
+ // backend/permissions.ts
45
+ var import_plugins_backend_sdk = require("@attraccess/plugins-backend-sdk");
46
+
47
+ // backend/permission-keys.ts
48
+ var RABBITMQ_BROKER_READ = "rabbitmq.broker.read";
49
+ var RABBITMQ_BROKER_MANAGE = "rabbitmq.broker.manage";
50
+
51
+ // backend/permissions.ts
52
+ var RABBITMQ_PERMISSIONS = (0, import_plugins_backend_sdk.definePluginPermissions)({
53
+ category: { en: "RabbitMQ", de: "RabbitMQ" },
54
+ permissions: [
55
+ {
56
+ // View tier — detection/status, user list, connections list and broker stats.
57
+ key: RABBITMQ_BROKER_READ,
58
+ label: { en: "View RabbitMQ broker", de: "RabbitMQ-Broker anzeigen" },
59
+ description: {
60
+ en: "View the RabbitMQ detection, broker users, connections and statistics",
61
+ de: "RabbitMQ-Erkennung, Broker-Benutzer, Verbindungen und Statistiken anzeigen"
62
+ },
63
+ defaultRoles: ["administrator", "resource-manager", "system-admin"]
64
+ },
65
+ {
66
+ // Manage tier — everything that changes the broker: user create/update/delete, permissions and closing
67
+ // connections. The live MQTT message explorer is not part of the plugin: it is a core feature for every broker.
68
+ key: RABBITMQ_BROKER_MANAGE,
69
+ label: { en: "Manage RabbitMQ broker", de: "RabbitMQ-Broker verwalten" },
70
+ description: {
71
+ en: "Create, change and delete broker users and their permissions, and close connections",
72
+ de: "Broker-Benutzer und deren Berechtigungen anlegen, \xE4ndern und l\xF6schen sowie Verbindungen schlie\xDFen"
73
+ },
74
+ defaultRoles: ["administrator", "system-admin"]
75
+ }
76
+ ]
77
+ });
78
+ var RABBITMQ_VIEW_PERMISSION = RABBITMQ_PERMISSIONS.keys[RABBITMQ_BROKER_READ];
79
+ var RABBITMQ_MANAGE_PERMISSION = RABBITMQ_PERMISSIONS.keys[RABBITMQ_BROKER_MANAGE];
80
+
81
+ // backend/management/transport.ts
48
82
  var import_node_crypto = require("node:crypto");
49
83
  var import_node_https = require("node:https");
50
84
  var import_node_net = require("node:net");
@@ -88,8 +122,8 @@ function trustOptions(config) {
88
122
  ...servername != null ? { servername } : {}
89
123
  };
90
124
  }
91
- async function managementRequest(config, url, method, body, timeoutMs) {
92
- const headers = { accept: "application/json" };
125
+ async function managementRequest(config, url, method, body, timeoutMs, extraHeaders) {
126
+ const headers = { accept: "application/json", ...extraHeaders };
93
127
  if (config.username !== null) {
94
128
  headers.authorization = `Basic ${Buffer.from(`${config.username}:${config.password ?? ""}`, "utf8").toString("base64")}`;
95
129
  }
@@ -175,7 +209,7 @@ function describeManagementError(error, timeoutMs) {
175
209
  }
176
210
  }
177
211
 
178
- // backend/rabbitmq-detection.service.ts
212
+ // backend/detection/service.ts
179
213
  var PLUGIN_CONTEXT = /* @__PURE__ */ Symbol.for("attraccess.plugin.context");
180
214
  var CACHE_TTL_MS = 6e4;
181
215
  var PROBE_TIMEOUT_MS = 5e3;
@@ -302,8 +336,6 @@ RabbitmqDetectionService = __decorateClass([
302
336
  (0, import_common.Injectable)(),
303
337
  __decorateParam(0, (0, import_common.Inject)(PLUGIN_CONTEXT))
304
338
  ], RabbitmqDetectionService);
305
-
306
- // backend/rabbitmq-detection.controller.ts
307
339
  var RabbitmqDetectionController = class {
308
340
  // esbuild does not emit decorator metadata, so Nest cannot infer constructor
309
341
  // types for injection — always inject by an explicit token.
@@ -315,19 +347,20 @@ var RabbitmqDetectionController = class {
315
347
  }
316
348
  };
317
349
  __decorateClass([
318
- (0, import_common2.Get)("detection/:mqttServerId"),
319
- __decorateParam(0, (0, import_common2.Param)("mqttServerId", import_common2.ParseIntPipe)),
320
- __decorateParam(1, (0, import_common2.Query)("refresh"))
350
+ (0, import_common.Get)("detection/:mqttServerId"),
351
+ __decorateParam(0, (0, import_common.Param)("mqttServerId", import_common.ParseIntPipe)),
352
+ __decorateParam(1, (0, import_common.Query)("refresh"))
321
353
  ], RabbitmqDetectionController.prototype, "detect", 1);
322
354
  RabbitmqDetectionController = __decorateClass([
323
- (0, import_plugins_backend_sdk.Auth)("resources.update"),
324
- (0, import_common2.Controller)("rabbitmq"),
325
- __decorateParam(0, (0, import_common2.Inject)(RabbitmqDetectionService))
355
+ (0, import_plugins_backend_sdk2.Auth)(RABBITMQ_VIEW_PERMISSION),
356
+ (0, import_common.Controller)("rabbitmq"),
357
+ __decorateParam(0, (0, import_common.Inject)(RabbitmqDetectionService))
326
358
  ], RabbitmqDetectionController);
327
359
 
328
- // backend/rabbitmq-management-client.ts
329
- var import_common3 = require("@nestjs/common");
360
+ // backend/management/client.ts
361
+ var import_common2 = require("@nestjs/common");
330
362
  var REQUEST_TIMEOUT_MS = 1e4;
363
+ var MISSING_PRIVILEGE_ERROR = "not_authorised";
331
364
  var RabbitmqManagementClient = class {
332
365
  // Builds the management API base URL from the generic MQTT config (same
333
366
  // convention as RabbitmqDetectionService).
@@ -337,15 +370,15 @@ var RabbitmqManagementClient = class {
337
370
  // Performs one management API request. `path` is relative to `/api`, with
338
371
  // every variable segment already URL-encoded by the caller. Returns the
339
372
  // parsed JSON body (or null for empty responses, e.g. 201/204).
340
- async request(config, method, path, body) {
373
+ async request(config, method, path, body, headers) {
341
374
  const base = this.managementApiBase(config);
342
375
  let response;
343
376
  try {
344
- response = await managementRequest(config, `${base}/api${path}`, method, body, REQUEST_TIMEOUT_MS);
377
+ response = await managementRequest(config, `${base}/api${path}`, method, body, REQUEST_TIMEOUT_MS, headers);
345
378
  } catch (error) {
346
- throw new import_common3.HttpException(
379
+ throw new import_common2.HttpException(
347
380
  `Cannot reach the RabbitMQ management API at ${base}: ${describeManagementError(error, REQUEST_TIMEOUT_MS)}`,
348
- import_common3.HttpStatus.BAD_GATEWAY
381
+ import_common2.HttpStatus.BAD_GATEWAY
349
382
  );
350
383
  }
351
384
  if (!response.ok) {
@@ -359,27 +392,28 @@ var RabbitmqManagementClient = class {
359
392
  async toHttpException(response) {
360
393
  const upstream = await this.parseErrorBody(response);
361
394
  const reason = upstream?.reason || upstream?.error || "";
362
- if (response.status === 401) {
363
- return new import_common3.HttpException(
395
+ const missingPrivilege = upstream?.error === MISSING_PRIVILEGE_ERROR;
396
+ if (response.status === 401 && !missingPrivilege) {
397
+ return new import_common2.HttpException(
364
398
  "The RabbitMQ management API rejected the configured MQTT server credentials (401). Check the username/password configured for this MQTT server.",
365
- import_common3.HttpStatus.BAD_GATEWAY
399
+ import_common2.HttpStatus.BAD_GATEWAY
366
400
  );
367
401
  }
368
- if (response.status === 403 || /not.?authori[sz]ed/i.test(reason)) {
369
- return new import_common3.HttpException(
370
- 'The configured MQTT server user lacks management privileges on RabbitMQ. User management requires a user with the "administrator" tag.',
371
- import_common3.HttpStatus.BAD_GATEWAY
402
+ if (response.status === 403 || missingPrivilege || /not.?authori[sz]ed/i.test(reason)) {
403
+ return new import_common2.HttpException(
404
+ 'The configured MQTT server user lacks management privileges on RabbitMQ. Viewing requires the "monitoring" tag; managing users and closing connections requires "administrator".',
405
+ import_common2.HttpStatus.BAD_GATEWAY
372
406
  );
373
407
  }
374
408
  if (response.status === 404) {
375
- return new import_common3.HttpException("Not found on the RabbitMQ side.", import_common3.HttpStatus.NOT_FOUND);
409
+ return new import_common2.HttpException("Not found on the RabbitMQ side.", import_common2.HttpStatus.NOT_FOUND);
376
410
  }
377
411
  if (response.status === 400) {
378
- return new import_common3.HttpException("RabbitMQ rejected the request.", import_common3.HttpStatus.BAD_REQUEST);
412
+ return new import_common2.HttpException("RabbitMQ rejected the request.", import_common2.HttpStatus.BAD_REQUEST);
379
413
  }
380
- return new import_common3.HttpException(
414
+ return new import_common2.HttpException(
381
415
  `RabbitMQ management API request failed (HTTP ${response.status}).`,
382
- import_common3.HttpStatus.BAD_GATEWAY
416
+ import_common2.HttpStatus.BAD_GATEWAY
383
417
  );
384
418
  }
385
419
  async parseBody(response) {
@@ -390,9 +424,9 @@ var RabbitmqManagementClient = class {
390
424
  try {
391
425
  return JSON.parse(text);
392
426
  } catch {
393
- throw new import_common3.HttpException(
427
+ throw new import_common2.HttpException(
394
428
  "The RabbitMQ management API returned a response that is not valid JSON.",
395
- import_common3.HttpStatus.BAD_GATEWAY
429
+ import_common2.HttpStatus.BAD_GATEWAY
396
430
  );
397
431
  }
398
432
  }
@@ -405,15 +439,36 @@ var RabbitmqManagementClient = class {
405
439
  }
406
440
  };
407
441
  RabbitmqManagementClient = __decorateClass([
408
- (0, import_common3.Injectable)()
442
+ (0, import_common2.Injectable)()
409
443
  ], RabbitmqManagementClient);
410
444
 
411
- // backend/rabbitmq-users.controller.ts
412
- var import_plugins_backend_sdk2 = require("@attraccess/plugins-backend-sdk");
413
- var import_common5 = require("@nestjs/common");
414
-
415
- // backend/rabbitmq-users.service.ts
445
+ // backend/users/service.ts
446
+ var import_plugins_backend_sdk3 = require("@attraccess/plugins-backend-sdk");
416
447
  var import_common4 = require("@nestjs/common");
448
+
449
+ // backend/management/config.ts
450
+ var import_common3 = require("@nestjs/common");
451
+ async function requireMqttServerConfig(context, mqttServerId) {
452
+ const config = await context.getMqttServerConfig(mqttServerId);
453
+ if (!config) {
454
+ throw new import_common3.HttpException("MQTT server not found.", import_common3.HttpStatus.NOT_FOUND);
455
+ }
456
+ return config;
457
+ }
458
+ function num(value) {
459
+ return typeof value === "number" && Number.isFinite(value) ? value : null;
460
+ }
461
+ function str(value) {
462
+ return typeof value === "string" && value.length > 0 ? value : null;
463
+ }
464
+ function rec(value) {
465
+ return value !== null && typeof value === "object" ? value : {};
466
+ }
467
+ function list(value) {
468
+ return Array.isArray(value) ? value.map(rec) : [];
469
+ }
470
+
471
+ // backend/users/service.ts
417
472
  var PLUGIN_CONTEXT2 = /* @__PURE__ */ Symbol.for("attraccess.plugin.context");
418
473
  var RabbitmqUsersService = class {
419
474
  constructor(context, client) {
@@ -423,7 +478,7 @@ var RabbitmqUsersService = class {
423
478
  // Lists all users with their per-vhost permissions, plus the vhost list for
424
479
  // the UI's vhost choices. Three management calls, joined here.
425
480
  async listUsers(mqttServerId) {
426
- const config = await this.requireConfig(mqttServerId);
481
+ const config = await requireMqttServerConfig(this.context, mqttServerId);
427
482
  const [rawUsers, rawPermissions, rawVhosts] = await Promise.all([
428
483
  this.client.request(config, "GET", "/users"),
429
484
  this.client.request(config, "GET", "/permissions"),
@@ -431,14 +486,14 @@ var RabbitmqUsersService = class {
431
486
  ]);
432
487
  const permissionsByUser = /* @__PURE__ */ new Map();
433
488
  for (const permission of rawPermissions ?? []) {
434
- const list = permissionsByUser.get(permission.user) ?? [];
435
- list.push({
489
+ const list2 = permissionsByUser.get(permission.user) ?? [];
490
+ list2.push({
436
491
  vhost: permission.vhost,
437
492
  configure: permission.configure,
438
493
  write: permission.write,
439
494
  read: permission.read
440
495
  });
441
- permissionsByUser.set(permission.user, list);
496
+ permissionsByUser.set(permission.user, list2);
442
497
  }
443
498
  const users = (rawUsers ?? []).map((user) => ({
444
499
  name: user.name,
@@ -456,7 +511,7 @@ var RabbitmqUsersService = class {
456
511
  // the same operation (used by the create form's "default MQTT permissions").
457
512
  async upsertUser(mqttServerId, username, dto) {
458
513
  this.assertValidName(username, "Username");
459
- const config = await this.requireConfig(mqttServerId);
514
+ const config = await requireMqttServerConfig(this.context, mqttServerId);
460
515
  const existing = await this.findUser(config, username);
461
516
  const password = dto.password?.length ? dto.password : void 0;
462
517
  if (!existing && !password) {
@@ -478,7 +533,7 @@ var RabbitmqUsersService = class {
478
533
  }
479
534
  async deleteUser(mqttServerId, username) {
480
535
  this.assertValidName(username, "Username");
481
- const config = await this.requireConfig(mqttServerId);
536
+ const config = await requireMqttServerConfig(this.context, mqttServerId);
482
537
  if (config.username !== null && config.username === username) {
483
538
  throw new import_common4.HttpException(
484
539
  "Refusing to delete the user the MQTT server connection is configured with.",
@@ -490,13 +545,13 @@ var RabbitmqUsersService = class {
490
545
  async setPermissions(mqttServerId, username, dto) {
491
546
  this.assertValidName(username, "Username");
492
547
  this.assertValidName(dto.vhost, "Vhost");
493
- const config = await this.requireConfig(mqttServerId);
548
+ const config = await requireMqttServerConfig(this.context, mqttServerId);
494
549
  await this.putPermission(config, username, dto);
495
550
  }
496
551
  async clearPermissions(mqttServerId, username, vhost) {
497
552
  this.assertValidName(username, "Username");
498
553
  this.assertValidName(vhost, "Vhost");
499
- const config = await this.requireConfig(mqttServerId);
554
+ const config = await requireMqttServerConfig(this.context, mqttServerId);
500
555
  await this.client.request(
501
556
  config,
502
557
  "DELETE",
@@ -526,13 +581,6 @@ var RabbitmqUsersService = class {
526
581
  throw error;
527
582
  }
528
583
  }
529
- async requireConfig(mqttServerId) {
530
- const config = await this.context.getMqttServerConfig(mqttServerId);
531
- if (!config) {
532
- throw new import_common4.HttpException("MQTT server not found.", import_common4.HttpStatus.NOT_FOUND);
533
- }
534
- return config;
535
- }
536
584
  normalizeTags(tags) {
537
585
  if (Array.isArray(tags)) {
538
586
  return tags.filter((tag) => tag.length > 0);
@@ -556,8 +604,6 @@ RabbitmqUsersService = __decorateClass([
556
604
  __decorateParam(0, (0, import_common4.Inject)(PLUGIN_CONTEXT2)),
557
605
  __decorateParam(1, (0, import_common4.Inject)(RabbitmqManagementClient))
558
606
  ], RabbitmqUsersService);
559
-
560
- // backend/rabbitmq-users.controller.ts
561
607
  var RabbitmqUsersController = class {
562
608
  // esbuild does not emit decorator metadata, so Nest cannot infer constructor
563
609
  // types for injection — always inject by an explicit token.
@@ -575,53 +621,56 @@ var RabbitmqUsersController = class {
575
621
  }
576
622
  setPermissions(mqttServerId, username, dto) {
577
623
  if (!dto || typeof dto.vhost !== "string") {
578
- throw new import_common5.HttpException("A vhost is required.", import_common5.HttpStatus.BAD_REQUEST);
624
+ throw new import_common4.HttpException("A vhost is required.", import_common4.HttpStatus.BAD_REQUEST);
579
625
  }
580
626
  return this.users.setPermissions(mqttServerId, username, dto);
581
627
  }
582
628
  clearPermissions(mqttServerId, username, vhost) {
583
629
  if (typeof vhost !== "string" || vhost.length === 0) {
584
- throw new import_common5.HttpException("A vhost query parameter is required.", import_common5.HttpStatus.BAD_REQUEST);
630
+ throw new import_common4.HttpException("A vhost query parameter is required.", import_common4.HttpStatus.BAD_REQUEST);
585
631
  }
586
632
  return this.users.clearPermissions(mqttServerId, username, vhost);
587
633
  }
588
634
  };
589
635
  __decorateClass([
590
- (0, import_common5.Get)("users/:mqttServerId"),
591
- __decorateParam(0, (0, import_common5.Param)("mqttServerId", import_common5.ParseIntPipe))
636
+ (0, import_plugins_backend_sdk3.Auth)(RABBITMQ_VIEW_PERMISSION),
637
+ (0, import_common4.Get)("users/:mqttServerId"),
638
+ __decorateParam(0, (0, import_common4.Param)("mqttServerId", import_common4.ParseIntPipe))
592
639
  ], RabbitmqUsersController.prototype, "list", 1);
593
640
  __decorateClass([
594
- (0, import_common5.Put)("users/:mqttServerId/:username"),
595
- __decorateParam(0, (0, import_common5.Param)("mqttServerId", import_common5.ParseIntPipe)),
596
- __decorateParam(1, (0, import_common5.Param)("username")),
597
- __decorateParam(2, (0, import_common5.Body)())
641
+ (0, import_plugins_backend_sdk3.Auth)(RABBITMQ_MANAGE_PERMISSION),
642
+ (0, import_common4.Put)("users/:mqttServerId/:username"),
643
+ __decorateParam(0, (0, import_common4.Param)("mqttServerId", import_common4.ParseIntPipe)),
644
+ __decorateParam(1, (0, import_common4.Param)("username")),
645
+ __decorateParam(2, (0, import_common4.Body)())
598
646
  ], RabbitmqUsersController.prototype, "upsert", 1);
599
647
  __decorateClass([
600
- (0, import_common5.Delete)("users/:mqttServerId/:username"),
601
- __decorateParam(0, (0, import_common5.Param)("mqttServerId", import_common5.ParseIntPipe)),
602
- __decorateParam(1, (0, import_common5.Param)("username"))
648
+ (0, import_plugins_backend_sdk3.Auth)(RABBITMQ_MANAGE_PERMISSION),
649
+ (0, import_common4.Delete)("users/:mqttServerId/:username"),
650
+ __decorateParam(0, (0, import_common4.Param)("mqttServerId", import_common4.ParseIntPipe)),
651
+ __decorateParam(1, (0, import_common4.Param)("username"))
603
652
  ], RabbitmqUsersController.prototype, "remove", 1);
604
653
  __decorateClass([
605
- (0, import_common5.Put)("users/:mqttServerId/:username/permissions"),
606
- __decorateParam(0, (0, import_common5.Param)("mqttServerId", import_common5.ParseIntPipe)),
607
- __decorateParam(1, (0, import_common5.Param)("username")),
608
- __decorateParam(2, (0, import_common5.Body)())
654
+ (0, import_plugins_backend_sdk3.Auth)(RABBITMQ_MANAGE_PERMISSION),
655
+ (0, import_common4.Put)("users/:mqttServerId/:username/permissions"),
656
+ __decorateParam(0, (0, import_common4.Param)("mqttServerId", import_common4.ParseIntPipe)),
657
+ __decorateParam(1, (0, import_common4.Param)("username")),
658
+ __decorateParam(2, (0, import_common4.Body)())
609
659
  ], RabbitmqUsersController.prototype, "setPermissions", 1);
610
660
  __decorateClass([
611
- (0, import_common5.Delete)("users/:mqttServerId/:username/permissions"),
612
- __decorateParam(0, (0, import_common5.Param)("mqttServerId", import_common5.ParseIntPipe)),
613
- __decorateParam(1, (0, import_common5.Param)("username")),
614
- __decorateParam(2, (0, import_common5.Query)("vhost"))
661
+ (0, import_plugins_backend_sdk3.Auth)(RABBITMQ_MANAGE_PERMISSION),
662
+ (0, import_common4.Delete)("users/:mqttServerId/:username/permissions"),
663
+ __decorateParam(0, (0, import_common4.Param)("mqttServerId", import_common4.ParseIntPipe)),
664
+ __decorateParam(1, (0, import_common4.Param)("username")),
665
+ __decorateParam(2, (0, import_common4.Query)("vhost"))
615
666
  ], RabbitmqUsersController.prototype, "clearPermissions", 1);
616
667
  RabbitmqUsersController = __decorateClass([
617
- (0, import_plugins_backend_sdk2.Auth)("resources.update"),
618
- (0, import_common5.Controller)("rabbitmq"),
619
- __decorateParam(0, (0, import_common5.Inject)(RabbitmqUsersService))
668
+ (0, import_common4.Controller)("rabbitmq"),
669
+ __decorateParam(0, (0, import_common4.Inject)(RabbitmqUsersService))
620
670
  ], RabbitmqUsersController);
621
671
 
622
- // backend/rabbitmq-credential-provisioning.provider.ts
623
- var import_crypto = require("crypto");
624
- var import_common6 = require("@nestjs/common");
672
+ // backend/credentials/provider.ts
673
+ var import_common5 = require("@nestjs/common");
625
674
 
626
675
  // ../../../node_modules/.pnpm/async-mutex@0.5.0/node_modules/async-mutex/index.mjs
627
676
  var E_TIMEOUT = new Error("timeout while waiting for mutex to become available");
@@ -829,7 +878,31 @@ var Mutex = class {
829
878
  }
830
879
  };
831
880
 
832
- // backend/rabbitmq-credential-provisioning.provider.ts
881
+ // backend/credentials/provider.ts
882
+ var import_crypto = require("crypto");
883
+ function escapeRegex(value) {
884
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
885
+ }
886
+ function mqttFilterToRegex(filter) {
887
+ const terminalMultiLevel = filter.endsWith("/#");
888
+ const prefix = terminalMultiLevel ? filter.slice(0, -2) : filter;
889
+ const translated = prefix.split("/").map((segment) => {
890
+ if (segment === "+") {
891
+ return "[^.]+";
892
+ }
893
+ if (segment === "#") {
894
+ return ".*";
895
+ }
896
+ return segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
897
+ }).join("\\.");
898
+ return terminalMultiLevel ? `${translated}(?:\\..*)?` : translated;
899
+ }
900
+ function mqttFiltersToRegex(filters) {
901
+ if (filters.length === 0) {
902
+ return "$(?!)";
903
+ }
904
+ return `^(?:${filters.map(mqttFilterToRegex).join("|")})$`;
905
+ }
833
906
  var _RabbitmqCredentialProvisioningProvider = class _RabbitmqCredentialProvisioningProvider {
834
907
  constructor(context) {
835
908
  __publicField(this, "context", context);
@@ -839,46 +912,114 @@ var _RabbitmqCredentialProvisioningProvider = class _RabbitmqCredentialProvision
839
912
  __publicField(this, "detection");
840
913
  this.detection = new RabbitmqDetectionService(context);
841
914
  }
842
- async supports(config) {
843
- return (await this.detection.detect(config.id)).isRabbitMQ;
915
+ assertNotManagementUser(config, username) {
916
+ if (config.username === username) {
917
+ throw new import_common5.BadRequestException("Refusing to modify the MQTT server management identity.");
918
+ }
844
919
  }
845
- provision(request2) {
846
- return this.writeCredential(request2);
920
+ assertName(value, label) {
921
+ if (typeof value !== "string" || value.trim().length === 0 || value.length > 255) {
922
+ throw new import_common5.BadRequestException(`${label} must be a non-empty string no longer than 255 characters.`);
923
+ }
847
924
  }
848
- rotate(request2) {
849
- return this.writeCredential(request2);
925
+ assertTopicFilter(filter) {
926
+ if (filter.includes(".")) {
927
+ throw new import_common5.BadRequestException("RabbitMQ MQTT topic policies cannot contain dots.");
928
+ }
929
+ const segments = filter.split("/");
930
+ for (const [index, segment] of segments.entries()) {
931
+ if (segment.includes("+") && segment !== "+" || segment.includes("#") && (segment !== "#" || index !== segments.length - 1)) {
932
+ throw new import_common5.BadRequestException(
933
+ "MQTT wildcards must occupy a complete topic level, and # must be the final level."
934
+ );
935
+ }
936
+ }
850
937
  }
851
- async revoke(request2) {
938
+ assertRequest(request2) {
939
+ this.assertName(request2.identity, "Identity");
852
940
  this.assertName(request2.username, "Username");
853
- const config = await this.requireConfig(request2.mqttServerId);
854
- this.assertNotManagementUser(config, request2.username);
941
+ this.assertName(request2.vhost, "Vhost");
942
+ if (!Array.isArray(request2.topicPolicy.publish) || !Array.isArray(request2.topicPolicy.subscribe)) {
943
+ throw new import_common5.BadRequestException("Publish and subscribe topic policies must be arrays.");
944
+ }
945
+ for (const filter of [...request2.topicPolicy.publish, ...request2.topicPolicy.subscribe]) {
946
+ if (typeof filter !== "string" || filter.length === 0 || filter.length > 1024) {
947
+ throw new import_common5.BadRequestException("MQTT topic filters must be non-empty strings no longer than 1024 characters.");
948
+ }
949
+ this.assertTopicFilter(filter);
950
+ }
951
+ }
952
+ async requireConfig(mqttServerId) {
953
+ const config = await this.context.getMqttServerConfig(mqttServerId);
954
+ if (!config) {
955
+ throw new import_common5.BadRequestException("MQTT server not found.");
956
+ }
957
+ return config;
958
+ }
959
+ async failAfterRollback(error, rollback) {
960
+ const results = await Promise.allSettled(rollback.map((operation) => operation()));
961
+ const failures = results.filter((result) => result.status === "rejected").map((result) => result.reason);
962
+ if (failures.length > 0) {
963
+ throw new AggregateError([error, ...failures], "Credential provisioning failed and rollback was incomplete.");
964
+ }
965
+ throw error;
966
+ }
967
+ async restorePermission(config, path, permissions) {
968
+ await this.client.request(config, permissions ? "PUT" : "DELETE", path, permissions ?? void 0);
969
+ }
970
+ async restorePermissions(config, vhost, username, permissions, topicPermissions) {
971
+ const results = await Promise.allSettled([
972
+ this.restorePermission(config, `/permissions/${vhost}/${username}`, permissions),
973
+ this.restorePermission(config, `/topic-permissions/${vhost}/${username}`, topicPermissions)
974
+ ]);
975
+ const failures = results.filter((result) => result.status === "rejected").map((result) => result.reason);
976
+ if (failures.length > 0) {
977
+ throw new AggregateError(failures, "Failed to restore RabbitMQ permissions.");
978
+ }
979
+ }
980
+ async getOptional(config, path) {
855
981
  try {
856
- await this.client.request(config, "DELETE", `/users/${encodeURIComponent(request2.username)}`);
982
+ return await this.client.request(config, "GET", path);
857
983
  } catch (error) {
858
- if (error instanceof import_common6.HttpException && error.getStatus() === import_common6.HttpStatus.NOT_FOUND) return;
984
+ if (error instanceof import_common5.HttpException && error.getStatus() === import_common5.HttpStatus.NOT_FOUND) {
985
+ return null;
986
+ }
859
987
  throw error;
860
988
  }
861
989
  }
862
- async writeCredential(request2) {
863
- this.assertRequest(request2);
864
- const config = await this.requireConfig(request2.mqttServerId);
865
- this.assertNotManagementUser(config, request2.username);
866
- const lockKey = `${config.id}:${request2.vhost}`;
867
- let lock = _RabbitmqCredentialProvisioningProvider.vhostLocks.get(lockKey);
868
- if (!lock) {
869
- lock = { mutex: new Mutex(), users: 0 };
870
- _RabbitmqCredentialProvisioningProvider.vhostLocks.set(lockKey, lock);
871
- }
872
- lock.users += 1;
990
+ async getTopicPermissions(config, vhost, username) {
991
+ return this.getOptional(config, `/topic-permissions/${vhost}/${username}`);
992
+ }
993
+ async getPermissions(config, vhost, username) {
994
+ return this.getOptional(config, `/permissions/${vhost}/${username}`);
995
+ }
996
+ async exists(config, path) {
873
997
  try {
874
- return await lock.mutex.runExclusive(() => this.writeCredentialLocked(request2, config));
875
- } finally {
876
- lock.users -= 1;
877
- if (lock.users === 0 && _RabbitmqCredentialProvisioningProvider.vhostLocks.get(lockKey) === lock) {
878
- _RabbitmqCredentialProvisioningProvider.vhostLocks.delete(lockKey);
998
+ await this.client.request(config, "GET", path);
999
+ return true;
1000
+ } catch (error) {
1001
+ if (error instanceof import_common5.HttpException && error.getStatus() === import_common5.HttpStatus.NOT_FOUND) {
1002
+ return false;
879
1003
  }
1004
+ throw error;
880
1005
  }
881
1006
  }
1007
+ async userExists(config, username) {
1008
+ return this.exists(config, `/users/${username}`);
1009
+ }
1010
+ async writePermissions(config, request2, vhost, username) {
1011
+ const subscriptionQueue = `mqtt-subscription-${escapeRegex(request2.identity)}.*`;
1012
+ await this.client.request(config, "PUT", `/permissions/${vhost}/${username}`, {
1013
+ configure: `^${subscriptionQueue}$`,
1014
+ write: `^(amq\\.topic|${subscriptionQueue})$`,
1015
+ read: `^(amq\\.topic|${subscriptionQueue})$`
1016
+ });
1017
+ await this.client.request(config, "PUT", `/topic-permissions/${vhost}/${username}`, {
1018
+ exchange: "amq.topic",
1019
+ write: mqttFiltersToRegex(request2.topicPolicy.publish),
1020
+ read: mqttFiltersToRegex(request2.topicPolicy.subscribe)
1021
+ });
1022
+ }
882
1023
  async writeCredentialLocked(request2, config) {
883
1024
  const password = (0, import_crypto.randomBytes)(24).toString("base64url");
884
1025
  const vhost = encodeURIComponent(request2.vhost);
@@ -915,143 +1056,289 @@ var _RabbitmqCredentialProvisioningProvider = class _RabbitmqCredentialProvision
915
1056
  password
916
1057
  };
917
1058
  }
918
- async writePermissions(config, request2, vhost, username) {
919
- const subscriptionQueue = `mqtt-subscription-${escapeRegex(request2.identity)}.*`;
920
- await this.client.request(config, "PUT", `/permissions/${vhost}/${username}`, {
921
- configure: `^${subscriptionQueue}$`,
922
- write: `^(amq\\.topic|${subscriptionQueue})$`,
923
- read: `^(amq\\.topic|${subscriptionQueue})$`
924
- });
925
- await this.client.request(config, "PUT", `/topic-permissions/${vhost}/${username}`, {
926
- exchange: "amq.topic",
927
- write: mqttFiltersToRegex(request2.topicPolicy.publish),
928
- read: mqttFiltersToRegex(request2.topicPolicy.subscribe)
929
- });
930
- }
931
- async userExists(config, username) {
932
- return this.exists(config, `/users/${username}`);
933
- }
934
- async exists(config, path) {
1059
+ async writeCredential(request2) {
1060
+ this.assertRequest(request2);
1061
+ const config = await this.requireConfig(request2.mqttServerId);
1062
+ this.assertNotManagementUser(config, request2.username);
1063
+ const lockKey = `${config.id}:${request2.vhost}`;
1064
+ let lock = _RabbitmqCredentialProvisioningProvider.vhostLocks.get(lockKey);
1065
+ if (!lock) {
1066
+ lock = { mutex: new Mutex(), users: 0 };
1067
+ _RabbitmqCredentialProvisioningProvider.vhostLocks.set(lockKey, lock);
1068
+ }
1069
+ lock.users += 1;
935
1070
  try {
936
- await this.client.request(config, "GET", path);
937
- return true;
938
- } catch (error) {
939
- if (error instanceof import_common6.HttpException && error.getStatus() === import_common6.HttpStatus.NOT_FOUND) {
940
- return false;
1071
+ return await lock.mutex.runExclusive(() => this.writeCredentialLocked(request2, config));
1072
+ } finally {
1073
+ lock.users -= 1;
1074
+ if (lock.users === 0 && _RabbitmqCredentialProvisioningProvider.vhostLocks.get(lockKey) === lock) {
1075
+ _RabbitmqCredentialProvisioningProvider.vhostLocks.delete(lockKey);
941
1076
  }
942
- throw error;
943
1077
  }
944
1078
  }
945
- async getPermissions(config, vhost, username) {
946
- return this.getOptional(config, `/permissions/${vhost}/${username}`);
947
- }
948
- async getTopicPermissions(config, vhost, username) {
949
- return this.getOptional(config, `/topic-permissions/${vhost}/${username}`);
950
- }
951
- async getOptional(config, path) {
1079
+ async revoke(request2) {
1080
+ this.assertName(request2.username, "Username");
1081
+ const config = await this.requireConfig(request2.mqttServerId);
1082
+ this.assertNotManagementUser(config, request2.username);
952
1083
  try {
953
- return await this.client.request(config, "GET", path);
1084
+ await this.client.request(config, "DELETE", `/users/${encodeURIComponent(request2.username)}`);
954
1085
  } catch (error) {
955
- if (error instanceof import_common6.HttpException && error.getStatus() === import_common6.HttpStatus.NOT_FOUND) {
956
- return null;
957
- }
1086
+ if (error instanceof import_common5.HttpException && error.getStatus() === import_common5.HttpStatus.NOT_FOUND) return;
958
1087
  throw error;
959
1088
  }
960
1089
  }
961
- async restorePermissions(config, vhost, username, permissions, topicPermissions) {
962
- const results = await Promise.allSettled([
963
- this.restorePermission(config, `/permissions/${vhost}/${username}`, permissions),
964
- this.restorePermission(config, `/topic-permissions/${vhost}/${username}`, topicPermissions)
965
- ]);
966
- const failures = results.filter((result) => result.status === "rejected").map((result) => result.reason);
967
- if (failures.length > 0) {
968
- throw new AggregateError(failures, "Failed to restore RabbitMQ permissions.");
969
- }
1090
+ rotate(request2) {
1091
+ return this.writeCredential(request2);
970
1092
  }
971
- async restorePermission(config, path, permissions) {
972
- await this.client.request(config, permissions ? "PUT" : "DELETE", path, permissions ?? void 0);
1093
+ provision(request2) {
1094
+ return this.writeCredential(request2);
973
1095
  }
974
- async failAfterRollback(error, rollback) {
975
- const results = await Promise.allSettled(rollback.map((operation) => operation()));
976
- const failures = results.filter((result) => result.status === "rejected").map((result) => result.reason);
977
- if (failures.length > 0) {
978
- throw new AggregateError([error, ...failures], "Credential provisioning failed and rollback was incomplete.");
979
- }
980
- throw error;
1096
+ async supports(config) {
1097
+ return (await this.detection.detect(config.id)).isRabbitMQ;
981
1098
  }
982
- async requireConfig(mqttServerId) {
983
- const config = await this.context.getMqttServerConfig(mqttServerId);
984
- if (!config) {
985
- throw new import_common6.BadRequestException("MQTT server not found.");
986
- }
987
- return config;
1099
+ };
1100
+ __publicField(_RabbitmqCredentialProvisioningProvider, "vhostLocks", /* @__PURE__ */ new Map());
1101
+ var RabbitmqCredentialProvisioningProvider = _RabbitmqCredentialProvisioningProvider;
1102
+
1103
+ // backend/capabilities.ts
1104
+ var import_plugins_backend_sdk4 = require("@attraccess/plugins-backend-sdk");
1105
+ var import_common6 = require("@nestjs/common");
1106
+ var RabbitmqCapabilitiesController = class {
1107
+ capabilities(request2) {
1108
+ return { canManage: request2.user.effectivePermissions?.has(RABBITMQ_MANAGE_PERMISSION) === true };
988
1109
  }
989
- assertRequest(request2) {
990
- this.assertName(request2.identity, "Identity");
991
- this.assertName(request2.username, "Username");
992
- this.assertName(request2.vhost, "Vhost");
993
- if (!Array.isArray(request2.topicPolicy.publish) || !Array.isArray(request2.topicPolicy.subscribe)) {
994
- throw new import_common6.BadRequestException("Publish and subscribe topic policies must be arrays.");
995
- }
996
- for (const filter of [...request2.topicPolicy.publish, ...request2.topicPolicy.subscribe]) {
997
- if (typeof filter !== "string" || filter.length === 0 || filter.length > 1024) {
998
- throw new import_common6.BadRequestException("MQTT topic filters must be non-empty strings no longer than 1024 characters.");
999
- }
1000
- this.assertTopicFilter(filter);
1001
- }
1110
+ };
1111
+ __decorateClass([
1112
+ (0, import_plugins_backend_sdk4.Auth)(RABBITMQ_VIEW_PERMISSION),
1113
+ (0, import_common6.Get)("capabilities"),
1114
+ __decorateParam(0, (0, import_common6.Req)())
1115
+ ], RabbitmqCapabilitiesController.prototype, "capabilities", 1);
1116
+ RabbitmqCapabilitiesController = __decorateClass([
1117
+ (0, import_common6.Controller)("rabbitmq")
1118
+ ], RabbitmqCapabilitiesController);
1119
+
1120
+ // backend/connections/service.ts
1121
+ var import_plugins_backend_sdk5 = require("@attraccess/plugins-backend-sdk");
1122
+ var import_common7 = require("@nestjs/common");
1123
+ var PLUGIN_CONTEXT3 = /* @__PURE__ */ Symbol.for("attraccess.plugin.context");
1124
+ var MAX_CONNECTIONS = 1e3;
1125
+ var MAX_REASON_LENGTH = 200;
1126
+ var CONNECTION_COLUMNS = [
1127
+ "name",
1128
+ "client_properties",
1129
+ "user",
1130
+ "vhost",
1131
+ "peer_host",
1132
+ "peer_port",
1133
+ "protocol",
1134
+ "state",
1135
+ "ssl",
1136
+ "connected_at",
1137
+ "channels",
1138
+ "recv_oct",
1139
+ "send_oct",
1140
+ "recv_oct_details",
1141
+ "send_oct_details"
1142
+ ].join(",");
1143
+ function toConnection(row) {
1144
+ const name = str(row.name);
1145
+ if (!name) return null;
1146
+ const properties = rec(row.client_properties);
1147
+ return {
1148
+ name,
1149
+ clientId: str(properties.connection_name) ?? str(properties.client_id),
1150
+ user: str(row.user),
1151
+ vhost: str(row.vhost),
1152
+ peerHost: str(row.peer_host),
1153
+ peerPort: num(row.peer_port),
1154
+ protocol: str(row.protocol),
1155
+ state: str(row.state),
1156
+ ssl: row.ssl === true,
1157
+ connectedAt: num(row.connected_at),
1158
+ channels: num(row.channels),
1159
+ recvBytes: num(row.recv_oct),
1160
+ sendBytes: num(row.send_oct),
1161
+ recvRate: num(rec(row.recv_oct_details).rate),
1162
+ sendRate: num(rec(row.send_oct_details).rate)
1163
+ };
1164
+ }
1165
+ var RabbitmqConnectionsService = class {
1166
+ constructor(context, client) {
1167
+ __publicField(this, "context", context);
1168
+ __publicField(this, "client", client);
1002
1169
  }
1003
- assertTopicFilter(filter) {
1004
- if (filter.includes(".")) {
1005
- throw new import_common6.BadRequestException("RabbitMQ MQTT topic policies cannot contain dots.");
1170
+ async listConnections(mqttServerId) {
1171
+ const config = await requireMqttServerConfig(this.context, mqttServerId);
1172
+ const raw = await this.client.request(config, "GET", `/connections?columns=${CONNECTION_COLUMNS}`);
1173
+ const all = list(raw).map(toConnection).filter((row) => row !== null).sort((a, b) => (a.clientId ?? a.name).localeCompare(b.clientId ?? b.name));
1174
+ return {
1175
+ mqttServerId,
1176
+ total: all.length,
1177
+ truncated: all.length > MAX_CONNECTIONS,
1178
+ connections: all.slice(0, MAX_CONNECTIONS)
1179
+ };
1180
+ }
1181
+ // Query values arrive as arrays when repeated (`?reason=a&reason=b`), so both
1182
+ // parameters are checked at runtime rather than trusted to be strings.
1183
+ async closeConnection(mqttServerId, name, reason) {
1184
+ if (typeof name !== "string" || name.length === 0 || name.length > 1024) {
1185
+ throw new import_common7.HttpException("A connection name is required.", import_common7.HttpStatus.BAD_REQUEST);
1006
1186
  }
1007
- const segments = filter.split("/");
1008
- for (const [index, segment] of segments.entries()) {
1009
- if (segment.includes("+") && segment !== "+" || segment.includes("#") && (segment !== "#" || index !== segments.length - 1)) {
1010
- throw new import_common6.BadRequestException(
1011
- "MQTT wildcards must occupy a complete topic level, and # must be the final level."
1012
- );
1013
- }
1187
+ if (name === "." || name === "..") {
1188
+ throw new import_common7.HttpException("Invalid connection name.", import_common7.HttpStatus.BAD_REQUEST);
1014
1189
  }
1190
+ const config = await requireMqttServerConfig(this.context, mqttServerId);
1191
+ const headers = {};
1192
+ const cleaned = (typeof reason === "string" ? reason : "").normalize("NFKD").replace(/[\u0300-\u036f]/g, "").replace(/[^\x20-\x7e]/g, "?").trim().slice(0, MAX_REASON_LENGTH);
1193
+ if (cleaned.length > 0) headers["x-reason"] = cleaned;
1194
+ await this.client.request(config, "DELETE", `/connections/${encodeURIComponent(name)}`, void 0, headers);
1015
1195
  }
1016
- assertName(value, label) {
1017
- if (typeof value !== "string" || value.trim().length === 0 || value.length > 255) {
1018
- throw new import_common6.BadRequestException(`${label} must be a non-empty string no longer than 255 characters.`);
1019
- }
1196
+ };
1197
+ RabbitmqConnectionsService = __decorateClass([
1198
+ (0, import_common7.Injectable)(),
1199
+ __decorateParam(0, (0, import_common7.Inject)(PLUGIN_CONTEXT3)),
1200
+ __decorateParam(1, (0, import_common7.Inject)(RabbitmqManagementClient))
1201
+ ], RabbitmqConnectionsService);
1202
+ var RabbitmqConnectionsController = class {
1203
+ // esbuild does not emit decorator metadata, so Nest cannot infer constructor
1204
+ // types for injection — always inject by an explicit token.
1205
+ constructor(connections) {
1206
+ __publicField(this, "connections", connections);
1020
1207
  }
1021
- assertNotManagementUser(config, username) {
1022
- if (config.username === username) {
1023
- throw new import_common6.BadRequestException("Refusing to modify the MQTT server management identity.");
1024
- }
1208
+ list(mqttServerId) {
1209
+ return this.connections.listConnections(mqttServerId);
1210
+ }
1211
+ close(mqttServerId, name, reason) {
1212
+ return this.connections.closeConnection(mqttServerId, name, reason);
1025
1213
  }
1026
1214
  };
1027
- __publicField(_RabbitmqCredentialProvisioningProvider, "vhostLocks", /* @__PURE__ */ new Map());
1028
- var RabbitmqCredentialProvisioningProvider = _RabbitmqCredentialProvisioningProvider;
1029
- function mqttFiltersToRegex(filters) {
1030
- if (filters.length === 0) {
1031
- return "$(?!)";
1215
+ __decorateClass([
1216
+ (0, import_plugins_backend_sdk5.Auth)(RABBITMQ_VIEW_PERMISSION),
1217
+ (0, import_common7.Get)("connections/:mqttServerId"),
1218
+ __decorateParam(0, (0, import_common7.Param)("mqttServerId", import_common7.ParseIntPipe))
1219
+ ], RabbitmqConnectionsController.prototype, "list", 1);
1220
+ __decorateClass([
1221
+ (0, import_plugins_backend_sdk5.Auth)(RABBITMQ_MANAGE_PERMISSION),
1222
+ (0, import_common7.Delete)("connections/:mqttServerId"),
1223
+ __decorateParam(0, (0, import_common7.Param)("mqttServerId", import_common7.ParseIntPipe)),
1224
+ __decorateParam(1, (0, import_common7.Query)("name")),
1225
+ __decorateParam(2, (0, import_common7.Query)("reason"))
1226
+ ], RabbitmqConnectionsController.prototype, "close", 1);
1227
+ RabbitmqConnectionsController = __decorateClass([
1228
+ (0, import_common7.Controller)("rabbitmq"),
1229
+ __decorateParam(0, (0, import_common7.Inject)(RabbitmqConnectionsService))
1230
+ ], RabbitmqConnectionsController);
1231
+
1232
+ // backend/stats/service.ts
1233
+ var import_plugins_backend_sdk6 = require("@attraccess/plugins-backend-sdk");
1234
+ var import_common8 = require("@nestjs/common");
1235
+ var PLUGIN_CONTEXT4 = /* @__PURE__ */ Symbol.for("attraccess.plugin.context");
1236
+ var MAX_QUEUES = 1e3;
1237
+ var NODE_COLUMNS = [
1238
+ "name",
1239
+ "running",
1240
+ "mem_used",
1241
+ "mem_limit",
1242
+ "mem_alarm",
1243
+ "disk_free",
1244
+ "disk_free_limit",
1245
+ "disk_free_alarm",
1246
+ "fd_used",
1247
+ "fd_total",
1248
+ "sockets_used",
1249
+ "sockets_total",
1250
+ "uptime"
1251
+ ].join(",");
1252
+ var bool = (value) => typeof value === "boolean" ? value : null;
1253
+ var RabbitmqStatsService = class {
1254
+ constructor(context, client) {
1255
+ __publicField(this, "context", context);
1256
+ __publicField(this, "client", client);
1032
1257
  }
1033
- return `^(?:${filters.map(mqttFilterToRegex).join("|")})$`;
1034
- }
1035
- function mqttFilterToRegex(filter) {
1036
- const terminalMultiLevel = filter.endsWith("/#");
1037
- const prefix = terminalMultiLevel ? filter.slice(0, -2) : filter;
1038
- const translated = prefix.split("/").map((segment) => {
1039
- if (segment === "+") {
1040
- return "[^.]+";
1041
- }
1042
- if (segment === "#") {
1043
- return ".*";
1044
- }
1045
- return segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1046
- }).join("\\.");
1047
- return terminalMultiLevel ? `${translated}(?:\\..*)?` : translated;
1048
- }
1049
- function escapeRegex(value) {
1050
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1051
- }
1258
+ async getStats(mqttServerId) {
1259
+ const config = await requireMqttServerConfig(this.context, mqttServerId);
1260
+ const [rawOverview, rawNodes, rawQueues] = await Promise.all([
1261
+ this.client.request(config, "GET", "/overview"),
1262
+ this.client.request(config, "GET", `/nodes?columns=${NODE_COLUMNS}`),
1263
+ this.client.request(
1264
+ config,
1265
+ "GET",
1266
+ "/queues?columns=vhost,name,type,state,messages_ready,messages_unacknowledged,consumers"
1267
+ )
1268
+ ]);
1269
+ const overview = rec(rawOverview);
1270
+ const totals = rec(overview.object_totals);
1271
+ const queueTotals = rec(overview.queue_totals);
1272
+ const messageStats = rec(overview.message_stats);
1273
+ const queues = list(rawQueues).map((row) => ({
1274
+ vhost: str(row.vhost) ?? "/",
1275
+ name: str(row.name) ?? "",
1276
+ type: str(row.type),
1277
+ state: str(row.state),
1278
+ messagesReady: num(row.messages_ready),
1279
+ messagesUnacknowledged: num(row.messages_unacknowledged),
1280
+ consumers: num(row.consumers)
1281
+ })).sort((a, b) => a.vhost.localeCompare(b.vhost) || a.name.localeCompare(b.name));
1282
+ return {
1283
+ mqttServerId,
1284
+ overview: {
1285
+ rabbitmqVersion: str(overview.rabbitmq_version),
1286
+ erlangVersion: str(overview.erlang_version),
1287
+ clusterName: str(overview.cluster_name),
1288
+ connections: num(totals.connections),
1289
+ channels: num(totals.channels),
1290
+ queues: num(totals.queues),
1291
+ consumers: num(totals.consumers),
1292
+ messagesReady: num(queueTotals.messages_ready),
1293
+ messagesUnacknowledged: num(queueTotals.messages_unacknowledged),
1294
+ publishRate: num(rec(messageStats.publish_details).rate),
1295
+ deliverRate: num(rec(messageStats.deliver_get_details).rate)
1296
+ },
1297
+ nodes: list(rawNodes).map((row) => ({
1298
+ name: str(row.name) ?? "",
1299
+ running: bool(row.running),
1300
+ memUsed: num(row.mem_used),
1301
+ memLimit: num(row.mem_limit),
1302
+ memAlarm: bool(row.mem_alarm),
1303
+ diskFree: num(row.disk_free),
1304
+ diskFreeLimit: num(row.disk_free_limit),
1305
+ diskFreeAlarm: bool(row.disk_free_alarm),
1306
+ fdUsed: num(row.fd_used),
1307
+ fdTotal: num(row.fd_total),
1308
+ socketsUsed: num(row.sockets_used),
1309
+ socketsTotal: num(row.sockets_total),
1310
+ uptime: num(row.uptime)
1311
+ })).sort((a, b) => a.name.localeCompare(b.name)),
1312
+ queues: queues.slice(0, MAX_QUEUES),
1313
+ totalQueues: queues.length
1314
+ };
1315
+ }
1316
+ };
1317
+ RabbitmqStatsService = __decorateClass([
1318
+ (0, import_common8.Injectable)(),
1319
+ __decorateParam(0, (0, import_common8.Inject)(PLUGIN_CONTEXT4)),
1320
+ __decorateParam(1, (0, import_common8.Inject)(RabbitmqManagementClient))
1321
+ ], RabbitmqStatsService);
1322
+ var RabbitmqStatsController = class {
1323
+ constructor(stats) {
1324
+ __publicField(this, "stats", stats);
1325
+ }
1326
+ get(mqttServerId) {
1327
+ return this.stats.getStats(mqttServerId);
1328
+ }
1329
+ };
1330
+ __decorateClass([
1331
+ (0, import_common8.Get)("stats/:mqttServerId"),
1332
+ __decorateParam(0, (0, import_common8.Param)("mqttServerId", import_common8.ParseIntPipe))
1333
+ ], RabbitmqStatsController.prototype, "get", 1);
1334
+ RabbitmqStatsController = __decorateClass([
1335
+ (0, import_plugins_backend_sdk6.Auth)(RABBITMQ_VIEW_PERMISSION),
1336
+ (0, import_common8.Controller)("rabbitmq"),
1337
+ __decorateParam(0, (0, import_common8.Inject)(RabbitmqStatsService))
1338
+ ], RabbitmqStatsController);
1052
1339
 
1053
1340
  // backend/plugin.ts
1054
- var PLUGIN_CONTEXT3 = /* @__PURE__ */ Symbol.for("attraccess.plugin.context");
1341
+ var PLUGIN_CONTEXT5 = /* @__PURE__ */ Symbol.for("attraccess.plugin.context");
1055
1342
  var RabbitmqService = class {
1056
1343
  constructor(context) {
1057
1344
  __publicField(this, "context", context);
@@ -1064,8 +1351,8 @@ var RabbitmqService = class {
1064
1351
  }
1065
1352
  };
1066
1353
  RabbitmqService = __decorateClass([
1067
- (0, import_common7.Injectable)(),
1068
- __decorateParam(0, (0, import_common7.Inject)(PLUGIN_CONTEXT3))
1354
+ (0, import_common9.Injectable)(),
1355
+ __decorateParam(0, (0, import_common9.Inject)(PLUGIN_CONTEXT5))
1069
1356
  ], RabbitmqService);
1070
1357
  var RabbitmqController = class {
1071
1358
  // esbuild does not emit decorator metadata, so Nest cannot infer constructor
@@ -1078,29 +1365,40 @@ var RabbitmqController = class {
1078
1365
  }
1079
1366
  };
1080
1367
  __decorateClass([
1081
- (0, import_common7.Get)("status")
1368
+ (0, import_common9.Get)("status")
1082
1369
  ], RabbitmqController.prototype, "status", 1);
1083
1370
  RabbitmqController = __decorateClass([
1084
- (0, import_plugins_backend_sdk3.Auth)("resources.update"),
1085
- (0, import_common7.Controller)("rabbitmq"),
1086
- __decorateParam(0, (0, import_common7.Inject)(RabbitmqService))
1371
+ (0, import_plugins_backend_sdk7.Auth)(RABBITMQ_VIEW_PERMISSION),
1372
+ (0, import_common9.Controller)("rabbitmq"),
1373
+ __decorateParam(0, (0, import_common9.Inject)(RabbitmqService))
1087
1374
  ], RabbitmqController);
1088
1375
  var RabbitmqPluginModule = class {
1089
1376
  };
1090
1377
  var plugin = {
1378
+ // ATT-1003: the plugin's own view and manage keys (see ./permissions).
1379
+ permissions: RABBITMQ_PERMISSIONS,
1091
1380
  credentialProvisioningProvider(context) {
1092
1381
  return new RabbitmqCredentialProvisioningProvider(context);
1093
1382
  },
1094
1383
  register(context) {
1095
1384
  return {
1096
1385
  module: RabbitmqPluginModule,
1097
- controllers: [RabbitmqController, RabbitmqDetectionController, RabbitmqUsersController],
1386
+ controllers: [
1387
+ RabbitmqController,
1388
+ RabbitmqCapabilitiesController,
1389
+ RabbitmqDetectionController,
1390
+ RabbitmqUsersController,
1391
+ RabbitmqConnectionsController,
1392
+ RabbitmqStatsController
1393
+ ],
1098
1394
  providers: [
1099
- { provide: PLUGIN_CONTEXT3, useValue: context },
1395
+ { provide: PLUGIN_CONTEXT5, useValue: context },
1100
1396
  RabbitmqService,
1101
1397
  RabbitmqDetectionService,
1102
1398
  RabbitmqManagementClient,
1103
- RabbitmqUsersService
1399
+ RabbitmqUsersService,
1400
+ RabbitmqConnectionsService,
1401
+ RabbitmqStatsService
1104
1402
  ]
1105
1403
  };
1106
1404
  }