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