@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.
@@ -0,0 +1,1942 @@
1
+ import { r as importShared } from "./_virtual___federation_fn_import-D2E5es2p.js";
2
+ // \0rolldown/runtime.js
3
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
4
+ // ../../../libs/plugins-frontend-sdk/src/lib/frontend.api-client.ts
5
+ var BASE_URL_GLOBAL = "__ATTRACCESS_API_BASE_URL__";
6
+ /** The API origin the host is talking to. Falls back to the current origin. */
7
+ function getApiBaseUrl() {
8
+ return window[BASE_URL_GLOBAL] ?? window.location.origin;
9
+ }
10
+ /** Thrown for any non-2xx response, carrying the status for callers that branch on it. */
11
+ var PluginApiError = class extends Error {
12
+ constructor(message, status) {
13
+ super(message);
14
+ this.status = status;
15
+ this.name = "PluginApiError";
16
+ }
17
+ };
18
+ async function toError(res) {
19
+ try {
20
+ const body = await res.json();
21
+ const message = Array.isArray(body.message) ? body.message.join(", ") : body.message;
22
+ if (message) return new PluginApiError(message, res.status);
23
+ } catch {}
24
+ return new PluginApiError(`Request failed (HTTP ${res.status}).`, res.status);
25
+ }
26
+ /**
27
+ * Creates a client bound to `basePath`, which is resolved against the host's
28
+ * API origin. Plugin routes are mounted under `/api/<plugin-name>`, so that is
29
+ * the usual argument; pass nothing to address the host API directly.
30
+ */
31
+ function createPluginApiClient(basePath = "") {
32
+ const url = (path, query) => {
33
+ const target = new URL(`${basePath}${path}`, getApiBaseUrl());
34
+ Object.entries(query ?? {}).forEach(([key, value]) => {
35
+ if (value !== void 0 && value !== null) target.searchParams.set(key, String(value));
36
+ });
37
+ return target.toString();
38
+ };
39
+ const doFetch = (path, init) => fetch(url(path), {
40
+ credentials: "include",
41
+ ...init
42
+ });
43
+ return {
44
+ url,
45
+ fetch: doFetch,
46
+ async request(path, options = {}) {
47
+ const { body, query, headers, ...init } = options;
48
+ const res = await fetch(url(path, query), {
49
+ credentials: "include",
50
+ ...init,
51
+ headers: body === void 0 ? headers : {
52
+ "Content-Type": "application/json",
53
+ ...headers
54
+ },
55
+ body: body === void 0 ? void 0 : JSON.stringify(body)
56
+ });
57
+ if (!res.ok) throw await toError(res);
58
+ const text = await res.text();
59
+ return text.length > 0 ? JSON.parse(text) : null;
60
+ }
61
+ };
62
+ }
63
+ // ../../../libs/plugins-frontend-sdk/src/lib/frontend.license.ts
64
+ var { useCallback: useCallback$5, useEffect: useEffect$7, useState: useState$8 } = await importShared("react");
65
+ // ../../../node_modules/.pnpm/react@19.3.1/node_modules/react/cjs/react-jsx-runtime.production.js
66
+ /**
67
+ * @license React
68
+ * react-jsx-runtime.production.js
69
+ *
70
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
71
+ *
72
+ * This source code is licensed under the MIT license found in the
73
+ * LICENSE file in the root directory of this source tree.
74
+ */
75
+ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((exports) => {
76
+ var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element");
77
+ var REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
78
+ function jsxProd(type, config, maybeKey) {
79
+ var key = null;
80
+ void 0 !== maybeKey && (key = "" + maybeKey);
81
+ void 0 !== config.key && (key = "" + config.key);
82
+ if ("key" in config) {
83
+ maybeKey = {};
84
+ for (var propName in config) "key" !== propName && (maybeKey[propName] = config[propName]);
85
+ } else maybeKey = config;
86
+ config = maybeKey.ref;
87
+ return {
88
+ $$typeof: REACT_ELEMENT_TYPE,
89
+ type,
90
+ key,
91
+ ref: void 0 !== config ? config : null,
92
+ props: maybeKey
93
+ };
94
+ }
95
+ exports.Fragment = REACT_FRAGMENT_TYPE;
96
+ exports.jsx = jsxProd;
97
+ exports.jsxs = jsxProd;
98
+ }));
99
+ // ../../../libs/plugins-frontend-sdk/src/lib/frontend.live-updates.tsx
100
+ var import_jsx_runtime = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
101
+ module.exports = require_react_jsx_runtime_production();
102
+ })))();
103
+ var { createContext, useCallback: useCallback$4, useContext, useEffect: useEffect$6, useRef: useRef$4 } = await importShared("react");
104
+ var contextKey = Symbol.for("attraccess.plugin.live-updates.context");
105
+ var contexts = globalThis;
106
+ contexts[contextKey] ??= createContext(null);
107
+ var identityKey = Symbol.for("attraccess.plugin.live-updates.identity");
108
+ var identities = globalThis;
109
+ identities[identityKey] ??= createContext(null);
110
+ // ../../../libs/plugins-frontend-sdk/src/lib/frontend.pluggable.ts
111
+ /** Whether the signed-in user holds `permission`. False when signed out or when the host sends no permissions. */
112
+ function hasPluginAuthPermission(authData, permission) {
113
+ return (authData?.effectivePermissions ?? (authData?.user)?.effectivePermissions)?.includes(permission) ?? false;
114
+ }
115
+ // ../../../libs/plugins-frontend-sdk/src/lib/frontend.standard-drawer.tsx
116
+ var { StandardDrawer: SharedStandardDrawer } = await importShared("@attraccess/plugins-frontend-ui");
117
+ // ../../../libs/plugins-frontend-sdk/src/lib/frontend.standard-modal.tsx
118
+ var { StandardModal: SharedStandardModal } = await importShared("@attraccess/plugins-frontend-ui");
119
+ // frontend/src/detection/detection.ts
120
+ var { useCallback: useCallback$3, useEffect: useEffect$5, useState: useState$7 } = await importShared("react");
121
+ var api$4 = createPluginApiClient("/api/rabbitmq/detection");
122
+ function fetchDetection(mqttServerId, refresh) {
123
+ return api$4.request(`/${mqttServerId}`, { query: { refresh: refresh ? "true" : void 0 } });
124
+ }
125
+ var CACHE_TTL_MS = 6e4;
126
+ var EMPTY_ENTRY = {
127
+ result: null,
128
+ loading: true,
129
+ error: null,
130
+ inFlight: null,
131
+ expiresAt: 0
132
+ };
133
+ var store = /* @__PURE__ */ new Map();
134
+ var subscribers = /* @__PURE__ */ new Map();
135
+ function now() {
136
+ return Date.now();
137
+ }
138
+ function notify(mqttServerId) {
139
+ subscribers.get(mqttServerId)?.forEach((fn) => fn());
140
+ }
141
+ function ensureLoaded(mqttServerId, refresh) {
142
+ const current = store.get(mqttServerId);
143
+ if (current?.inFlight) return;
144
+ if (!refresh && current?.result && current.expiresAt > now()) return;
145
+ const entry = {
146
+ result: current?.result ?? null,
147
+ loading: true,
148
+ error: null,
149
+ inFlight: null,
150
+ expiresAt: current?.expiresAt ?? 0
151
+ };
152
+ entry.inFlight = fetchDetection(mqttServerId, refresh).then((data) => {
153
+ entry.result = data;
154
+ entry.error = null;
155
+ entry.expiresAt = now() + CACHE_TTL_MS;
156
+ }).catch((err) => {
157
+ entry.error = err.message;
158
+ }).finally(() => {
159
+ entry.loading = false;
160
+ entry.inFlight = null;
161
+ notify(mqttServerId);
162
+ });
163
+ store.set(mqttServerId, entry);
164
+ notify(mqttServerId);
165
+ }
166
+ function useDetection(mqttServerId) {
167
+ const [, forceRender] = useState$7(0);
168
+ useEffect$5(() => {
169
+ const rerender = () => forceRender((n) => n + 1);
170
+ let set = subscribers.get(mqttServerId);
171
+ if (!set) {
172
+ set = /* @__PURE__ */ new Set();
173
+ subscribers.set(mqttServerId, set);
174
+ }
175
+ set.add(rerender);
176
+ ensureLoaded(mqttServerId, false);
177
+ return () => {
178
+ set?.delete(rerender);
179
+ if (set && set.size === 0) subscribers.delete(mqttServerId);
180
+ };
181
+ }, [mqttServerId]);
182
+ const refresh = useCallback$3(() => ensureLoaded(mqttServerId, true), [mqttServerId]);
183
+ const entry = store.get(mqttServerId) ?? EMPTY_ENTRY;
184
+ return {
185
+ result: entry.result,
186
+ loading: entry.loading,
187
+ error: entry.error,
188
+ refresh
189
+ };
190
+ }
191
+ // backend/permission-keys.ts
192
+ var RABBITMQ_BROKER_READ = "rabbitmq.broker.read";
193
+ // frontend/src/access.ts
194
+ var { useSyncExternalStore } = await importShared("react");
195
+ var authData = null;
196
+ var listeners = /* @__PURE__ */ new Set();
197
+ function setRabbitmqAuthData(next) {
198
+ authData = next;
199
+ for (const listener of listeners) listener();
200
+ }
201
+ var subscribe = (listener) => {
202
+ listeners.add(listener);
203
+ return () => listeners.delete(listener);
204
+ };
205
+ function useCanViewBroker() {
206
+ return hasPluginAuthPermission(useSyncExternalStore(subscribe, () => authData), RABBITMQ_BROKER_READ);
207
+ }
208
+ // frontend/src/users/RabbitmqListBadge.tsx
209
+ var { Chip: Chip$4 } = await importShared("@heroui/react");
210
+ var { RabbitIcon: RabbitIcon$1 } = await importShared("lucide-react");
211
+ function RabbitmqListBadge({ mqttServerId }) {
212
+ return useCanViewBroker() ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DetectedBadge, { mqttServerId }) : null;
213
+ }
214
+ function DetectedBadge({ mqttServerId }) {
215
+ const { result } = useDetection(mqttServerId);
216
+ if (!result?.isRabbitMQ) return null;
217
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Chip$4, {
218
+ "data-cy": `rabbitmq-list-badge-${mqttServerId}`,
219
+ color: "accent",
220
+ variant: "soft",
221
+ size: "sm",
222
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitIcon$1, { className: "rmq:w-3.5 rmq:h-3.5" }), "RabbitMQ"]
223
+ });
224
+ }
225
+ var en_default = {
226
+ status: {
227
+ "detected": "detected",
228
+ "refresh": "Refresh RabbitMQ status",
229
+ "reachable": "Management API reachable",
230
+ "auth": "Authentication",
231
+ "ok": "OK",
232
+ "failed": "Failed",
233
+ "managementVersion": "Management API version",
234
+ "version": "RabbitMQ version",
235
+ "api": "Management API"
236
+ },
237
+ users: {
238
+ "title": "RabbitMQ users",
239
+ "reload": "Reload RabbitMQ users",
240
+ "add": "Add user",
241
+ "username": "Username",
242
+ "tags": "Tags",
243
+ "access": "Vhost access",
244
+ "none": "none",
245
+ "edit": "Edit user",
246
+ "permissions": "Edit permissions",
247
+ "deleteTitle": "Delete user",
248
+ "deleteDescription": "Delete the RabbitMQ user {{name}}? Connected clients using this account will be disconnected and its permissions removed.",
249
+ "loadError": "Loading users failed.",
250
+ "deleteError": "Deleting the user failed."
251
+ },
252
+ form: {
253
+ "editTitle": "Edit user \"{{name}}\"",
254
+ "createTitle": "Create RabbitMQ user",
255
+ "usernamePlaceholder": "e.g. shop-floor-sensor",
256
+ "newPassword": "New password (leave blank to keep current)",
257
+ "password": "Password",
258
+ "tags": "Tags (comma-separated, e.g. management, administrator)",
259
+ "grant": "Grant default MQTT permissions",
260
+ "defaults": "Allows the user to publish and subscribe over MQTT: configure {{configure}}, write/read {{write}}.",
261
+ "vhost": "Vhost",
262
+ "available": " (available: {{vhosts}})",
263
+ "save": "Save changes",
264
+ "create": "Create user",
265
+ "usernameRequired": "Username is required.",
266
+ "usernameTaken": "A user with this name already exists. Edit it instead.",
267
+ "passwordRequired": "Password is required when creating a user.",
268
+ "saveError": "Saving the user failed."
269
+ },
270
+ permissions: {
271
+ "title": "Permissions of \"{{name}}\"",
272
+ "remove": "Remove permissions on {{vhost}}",
273
+ "configure": "Configure",
274
+ "write": "Write",
275
+ "read": "Read",
276
+ "defaults": "Use MQTT defaults",
277
+ "empty": "This user has no permissions on any vhost — it cannot connect yet.",
278
+ "addVhost": "Add vhost",
279
+ "add": "Add",
280
+ "saveError": "Saving permissions failed.",
281
+ "removeError": "Removing permissions failed.",
282
+ "duplicate": "Permissions for vhost \"{{vhost}}\" are already listed.",
283
+ "summary": "configure: {{configure}}\nwrite: {{write}}\nread: {{read}}"
284
+ },
285
+ common: {
286
+ "cancel": "Cancel",
287
+ "close": "Close",
288
+ "save": "Save",
289
+ "delete": "Delete",
290
+ "state": "State",
291
+ "yes": "Yes",
292
+ "no": "No"
293
+ },
294
+ connections: {
295
+ "title": "Connections",
296
+ "reload": "Reload connections",
297
+ "loadError": "Loading connections failed.",
298
+ "empty": "No clients are connected.",
299
+ "truncated": "Showing the first {{shown}} of {{total}} connections.",
300
+ "client": "Client",
301
+ "user": "User",
302
+ "peer": "Peer",
303
+ "protocol": "Protocol",
304
+ "connectedSince": "Connected since",
305
+ "channels": "Channels",
306
+ "traffic": "Traffic (received / sent)",
307
+ "closeTitle": "Close connection",
308
+ "closeDescription": "Close the connection of {{name}}? The client is disconnected and may reconnect on its own.",
309
+ "closeConfirm": "Close connection",
310
+ "reason": "Reason (optional)",
311
+ "closeError": "Closing the connection failed.",
312
+ "received": "received",
313
+ "sent": "sent"
314
+ },
315
+ stats: {
316
+ "title": "Broker statistics",
317
+ "reload": "Reload statistics",
318
+ "loadError": "Loading statistics failed.",
319
+ "version": "RabbitMQ version",
320
+ "erlang": "Erlang version",
321
+ "cluster": "Cluster",
322
+ "connections": "Connections",
323
+ "channels": "Channels",
324
+ "queues": "Queues",
325
+ "consumers": "Consumers",
326
+ "ready": "Ready messages",
327
+ "unacked": "Unacknowledged messages",
328
+ "alarm": "Alarm active",
329
+ "publishRate": "Publish rate",
330
+ "deliverRate": "Deliver rate",
331
+ "nodes": "Nodes",
332
+ "noNodes": "No nodes reported.",
333
+ "nodeName": "Node",
334
+ "running": "Running",
335
+ "memory": "Memory (used / limit)",
336
+ "disk": "Disk (free / limit)",
337
+ "fileDescriptors": "File descriptors",
338
+ "sockets": "Sockets",
339
+ "uptime": "Uptime",
340
+ "queueList": "Queues",
341
+ "noQueues": "No queues.",
342
+ "queueName": "Name",
343
+ "vhost": "Vhost",
344
+ "type": "Type",
345
+ "queuesTruncated": "Showing the first {{shown}} of {{total}} queues."
346
+ }
347
+ };
348
+ var de_default = {
349
+ status: {
350
+ "detected": "erkannt",
351
+ "refresh": "RabbitMQ-Status aktualisieren",
352
+ "reachable": "Management-API erreichbar",
353
+ "auth": "Authentifizierung",
354
+ "ok": "OK",
355
+ "failed": "Fehlgeschlagen",
356
+ "managementVersion": "Version der Management-API",
357
+ "version": "RabbitMQ-Version",
358
+ "api": "Management-API"
359
+ },
360
+ users: {
361
+ "title": "RabbitMQ-Benutzer",
362
+ "reload": "RabbitMQ-Benutzer neu laden",
363
+ "add": "Benutzer hinzufügen",
364
+ "username": "Benutzername",
365
+ "tags": "Tags",
366
+ "access": "Vhost-Zugriff",
367
+ "none": "keine",
368
+ "edit": "Benutzer bearbeiten",
369
+ "permissions": "Berechtigungen bearbeiten",
370
+ "deleteTitle": "Benutzer löschen",
371
+ "deleteDescription": "RabbitMQ-Benutzer {{name}} löschen? Verbundene Clients mit diesem Konto werden getrennt und seine Berechtigungen entfernt.",
372
+ "loadError": "Benutzer konnten nicht geladen werden.",
373
+ "deleteError": "Benutzer konnte nicht gelöscht werden."
374
+ },
375
+ form: {
376
+ "editTitle": "Benutzer \"{{name}}\" bearbeiten",
377
+ "createTitle": "RabbitMQ-Benutzer erstellen",
378
+ "usernamePlaceholder": "z. B. werkstatt-sensor",
379
+ "newPassword": "Neues Passwort (leer lassen, um das aktuelle beizubehalten)",
380
+ "password": "Passwort",
381
+ "tags": "Tags (kommagetrennt, z. B. management, administrator)",
382
+ "grant": "Standard-MQTT-Berechtigungen vergeben",
383
+ "defaults": "Erlaubt Veröffentlichen und Abonnieren über MQTT: Konfigurieren {{configure}}, Schreiben/Lesen {{write}}.",
384
+ "vhost": "Vhost",
385
+ "available": " (verfügbar: {{vhosts}})",
386
+ "save": "Änderungen speichern",
387
+ "create": "Benutzer erstellen",
388
+ "usernameRequired": "Ein Benutzername ist erforderlich.",
389
+ "usernameTaken": "Ein Benutzer mit diesem Namen existiert bereits. Bearbeite ihn stattdessen.",
390
+ "passwordRequired": "Zum Erstellen eines Benutzers ist ein Passwort erforderlich.",
391
+ "saveError": "Benutzer konnte nicht gespeichert werden."
392
+ },
393
+ permissions: {
394
+ "title": "Berechtigungen von \"{{name}}\"",
395
+ "remove": "Berechtigungen für {{vhost}} entfernen",
396
+ "configure": "Konfigurieren",
397
+ "write": "Schreiben",
398
+ "read": "Lesen",
399
+ "defaults": "MQTT-Standardwerte verwenden",
400
+ "empty": "Dieser Benutzer hat keine Berechtigungen für einen Vhost und kann sich noch nicht verbinden.",
401
+ "addVhost": "Vhost hinzufügen",
402
+ "add": "Hinzufügen",
403
+ "saveError": "Berechtigungen konnten nicht gespeichert werden.",
404
+ "removeError": "Berechtigungen konnten nicht entfernt werden.",
405
+ "duplicate": "Berechtigungen für Vhost \"{{vhost}}\" sind bereits aufgeführt.",
406
+ "summary": "Konfigurieren: {{configure}}\nSchreiben: {{write}}\nLesen: {{read}}"
407
+ },
408
+ common: {
409
+ "cancel": "Abbrechen",
410
+ "close": "Schließen",
411
+ "save": "Speichern",
412
+ "delete": "Löschen",
413
+ "state": "Status",
414
+ "yes": "Ja",
415
+ "no": "Nein"
416
+ },
417
+ connections: {
418
+ "title": "Verbindungen",
419
+ "reload": "Verbindungen neu laden",
420
+ "loadError": "Verbindungen konnten nicht geladen werden.",
421
+ "empty": "Es sind keine Clients verbunden.",
422
+ "truncated": "Die ersten {{shown}} von {{total}} Verbindungen werden angezeigt.",
423
+ "client": "Client",
424
+ "user": "Benutzer",
425
+ "peer": "Gegenstelle",
426
+ "protocol": "Protokoll",
427
+ "connectedSince": "Verbunden seit",
428
+ "channels": "Kanäle",
429
+ "traffic": "Datenverkehr (empfangen / gesendet)",
430
+ "closeTitle": "Verbindung schließen",
431
+ "closeDescription": "Die Verbindung von {{name}} schließen? Der Client wird getrennt und kann sich selbstständig neu verbinden.",
432
+ "closeConfirm": "Verbindung schließen",
433
+ "reason": "Grund (optional)",
434
+ "closeError": "Die Verbindung konnte nicht geschlossen werden.",
435
+ "received": "empfangen",
436
+ "sent": "gesendet"
437
+ },
438
+ stats: {
439
+ "title": "Broker-Statistiken",
440
+ "reload": "Statistiken neu laden",
441
+ "loadError": "Statistiken konnten nicht geladen werden.",
442
+ "version": "RabbitMQ-Version",
443
+ "erlang": "Erlang-Version",
444
+ "cluster": "Cluster",
445
+ "connections": "Verbindungen",
446
+ "channels": "Kanäle",
447
+ "queues": "Queues",
448
+ "consumers": "Consumer",
449
+ "ready": "Bereite Nachrichten",
450
+ "unacked": "Unbestätigte Nachrichten",
451
+ "alarm": "Alarm aktiv",
452
+ "publishRate": "Veröffentlichungsrate",
453
+ "deliverRate": "Zustellrate",
454
+ "nodes": "Knoten",
455
+ "noNodes": "Keine Knoten gemeldet.",
456
+ "nodeName": "Knoten",
457
+ "running": "Läuft",
458
+ "memory": "Arbeitsspeicher (belegt / Limit)",
459
+ "disk": "Festplatte (frei / Limit)",
460
+ "fileDescriptors": "Dateideskriptoren",
461
+ "sockets": "Sockets",
462
+ "uptime": "Laufzeit",
463
+ "queueList": "Queues",
464
+ "noQueues": "Keine Queues.",
465
+ "queueName": "Name",
466
+ "vhost": "Vhost",
467
+ "type": "Typ",
468
+ "queuesTruncated": "Die ersten {{shown}} von {{total}} Queues werden angezeigt."
469
+ }
470
+ };
471
+ // frontend/src/i18n.ts
472
+ var { useTranslations } = await importShared("@attraccess/plugins-frontend-ui");
473
+ var useRabbitmqTranslations = () => useTranslations({
474
+ en: en_default,
475
+ de: de_default
476
+ }, { escapeValues: false });
477
+ // frontend/src/useRabbitmqFormatters.ts
478
+ var { useDateTimeFormatter, useNumberFormatter } = await importShared("@attraccess/plugins-frontend-ui");
479
+ var { useCallback: useCallback$2, useMemo } = await importShared("react");
480
+ var BYTE_UNITS = [
481
+ "B",
482
+ "KiB",
483
+ "MiB",
484
+ "GiB",
485
+ "TiB"
486
+ ];
487
+ var ONE_DECIMAL = {
488
+ minimumFractionDigits: 1,
489
+ maximumFractionDigits: 1
490
+ };
491
+ var TIME_ONLY = {
492
+ showDate: false,
493
+ showSeconds: true
494
+ };
495
+ function scaleBytes(value) {
496
+ let size = value;
497
+ let unit = 0;
498
+ while (Math.abs(size) >= 1024 && unit < BYTE_UNITS.length - 1) {
499
+ size /= 1024;
500
+ unit += 1;
501
+ }
502
+ return {
503
+ value: size,
504
+ unit: BYTE_UNITS[unit]
505
+ };
506
+ }
507
+ function useRabbitmqFormatters() {
508
+ const integer = useNumberFormatter();
509
+ const decimal = useNumberFormatter(ONE_DECIMAL);
510
+ const formatDateTime = useDateTimeFormatter();
511
+ const formatTime = useDateTimeFormatter(TIME_ONLY);
512
+ const number = useCallback$2((value) => value == null ? "—" : integer(value), [integer]);
513
+ const bytes = useCallback$2((value) => {
514
+ if (value == null) return "—";
515
+ const scaled = scaleBytes(value);
516
+ return `${scaled.unit === "B" ? integer(scaled.value) : decimal(scaled.value)} ${scaled.unit}`;
517
+ }, [integer, decimal]);
518
+ const rate = useCallback$2((value, suffix) => value == null ? "—" : `${decimal(value)} ${suffix}`, [decimal]);
519
+ const dateTime = useCallback$2((ms) => ms == null ? "—" : String(formatDateTime(ms, "—")), [formatDateTime]);
520
+ const time = useCallback$2((ms) => ms == null ? "—" : String(formatTime(ms, "—")), [formatTime]);
521
+ return useMemo(() => ({
522
+ number,
523
+ bytes,
524
+ rate,
525
+ dateTime,
526
+ time
527
+ }), [
528
+ number,
529
+ bytes,
530
+ rate,
531
+ dateTime,
532
+ time
533
+ ]);
534
+ }
535
+ // frontend/src/detection/RabbitmqStatusPanel.tsx
536
+ var { Button: Button$5 } = await importShared("@attraccess/plugins-frontend-ui");
537
+ var { Alert: Alert$2, AlertContent: AlertContent$2, AlertDescription: AlertDescription$2, Card: Card$4, Chip: Chip$3 } = await importShared("@heroui/react");
538
+ var { CheckCircle2Icon, RabbitIcon, RefreshCwIcon: RefreshCwIcon$3, XCircleIcon } = await importShared("lucide-react");
539
+ function StatusRow({ ok, label, value }) {
540
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
541
+ className: "rmq:flex rmq:items-center rmq:justify-between rmq:gap-3 rmq:py-1.5",
542
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
543
+ className: "rmq:flex rmq:items-center rmq:gap-2",
544
+ children: [ok ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CheckCircle2Icon, { className: "rmq:w-4 rmq:h-4 rmq:text-success" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(XCircleIcon, { className: "rmq:w-4 rmq:h-4 rmq:text-danger" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
545
+ className: "rmq:text-sm rmq:text-default-600",
546
+ children: label
547
+ })]
548
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
549
+ className: "rmq:text-sm rmq:font-medium rmq:text-default-700",
550
+ children: value
551
+ })]
552
+ });
553
+ }
554
+ function RabbitmqStatusPanel({ mqttServerId }) {
555
+ const { t } = useRabbitmqTranslations();
556
+ const { result, loading, refresh } = useDetection(mqttServerId);
557
+ if (!result?.isRabbitMQ) return null;
558
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$4, {
559
+ "data-cy": `rabbitmq-status-panel-${mqttServerId}`,
560
+ className: "rmq:w-full rmq:border rmq:border-default-200 rmq:dark:border-default-100",
561
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$4.Header, {
562
+ className: "rmq:flex rmq:flex-row rmq:items-center rmq:justify-between rmq:gap-2",
563
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
564
+ className: "rmq:flex rmq:items-center rmq:gap-2",
565
+ children: [
566
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitIcon, { className: "rmq:w-5 rmq:h-5 rmq:text-accent-soft-foreground" }),
567
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
568
+ className: "rmq:text-base rmq:font-semibold rmq:text-default-700",
569
+ children: "RabbitMQ"
570
+ }),
571
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Chip$3, {
572
+ color: "accent",
573
+ variant: "soft",
574
+ size: "sm",
575
+ children: t("status.detected")
576
+ })
577
+ ]
578
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$5, {
579
+ isIconOnly: true,
580
+ size: "sm",
581
+ variant: "ghost",
582
+ "aria-label": t("status.refresh"),
583
+ "data-cy": `rabbitmq-status-refresh-${mqttServerId}`,
584
+ onPress: refresh,
585
+ isPending: loading,
586
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RefreshCwIcon$3, { className: "rmq:w-4 rmq:h-4" })
587
+ })]
588
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$4.Content, {
589
+ className: "rmq:flex rmq:flex-col rmq:gap-1",
590
+ children: [
591
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusRow, {
592
+ ok: result.reachable,
593
+ label: t("status.reachable"),
594
+ value: t(result.reachable ? "common.yes" : "common.no")
595
+ }),
596
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusRow, {
597
+ ok: result.authOk,
598
+ label: t("status.auth"),
599
+ value: t(result.authOk ? "status.ok" : "status.failed")
600
+ }),
601
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
602
+ className: "rmq:flex rmq:items-center rmq:justify-between rmq:gap-3 rmq:py-1.5",
603
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
604
+ className: "rmq:text-sm rmq:text-default-600",
605
+ children: t("status.managementVersion")
606
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
607
+ className: "rmq:text-sm rmq:font-medium rmq:text-default-700",
608
+ children: result.managementVersion ?? "—"
609
+ })]
610
+ }),
611
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
612
+ className: "rmq:flex rmq:items-center rmq:justify-between rmq:gap-3 rmq:py-1.5",
613
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
614
+ className: "rmq:text-sm rmq:text-default-600",
615
+ children: t("status.version")
616
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
617
+ className: "rmq:text-sm rmq:font-medium rmq:text-default-700",
618
+ children: result.rabbitmqVersion ?? "—"
619
+ })]
620
+ }),
621
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
622
+ className: "rmq:flex rmq:items-center rmq:justify-between rmq:gap-3 rmq:py-1.5",
623
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
624
+ className: "rmq:text-sm rmq:text-default-600",
625
+ children: t("status.api")
626
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", {
627
+ className: "rmq:text-xs rmq:text-default-500",
628
+ children: result.managementApi || "—"
629
+ })]
630
+ }),
631
+ result.error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Alert$2, {
632
+ status: result.reachable ? "warning" : "danger",
633
+ className: "rmq:mt-2",
634
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertContent$2, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertDescription$2, { children: result.error }) })
635
+ })
636
+ ]
637
+ })]
638
+ });
639
+ }
640
+ // frontend/src/users/users-api.ts
641
+ var DEFAULT_MQTT_PERMISSIONS = {
642
+ configure: "^mqtt-subscription-.*$",
643
+ write: "^(amq\\.topic|mqtt-subscription-.*)$",
644
+ read: "^(amq\\.topic|mqtt-subscription-.*)$"
645
+ };
646
+ var api$3 = createPluginApiClient("/api/rabbitmq/users");
647
+ function fetchUsers(mqttServerId) {
648
+ return api$3.request(`/${mqttServerId}`);
649
+ }
650
+ function upsertUser(mqttServerId, username, body) {
651
+ return api$3.request(`/${mqttServerId}/${encodeURIComponent(username)}`, {
652
+ method: "PUT",
653
+ body
654
+ });
655
+ }
656
+ function deleteUser(mqttServerId, username) {
657
+ return api$3.request(`/${mqttServerId}/${encodeURIComponent(username)}`, { method: "DELETE" });
658
+ }
659
+ function setPermissions(mqttServerId, username, permission) {
660
+ return api$3.request(`/${mqttServerId}/${encodeURIComponent(username)}/permissions`, {
661
+ method: "PUT",
662
+ body: permission
663
+ });
664
+ }
665
+ function clearPermissions(mqttServerId, username, vhost) {
666
+ return api$3.request(`/${mqttServerId}/${encodeURIComponent(username)}/permissions`, {
667
+ method: "DELETE",
668
+ query: { vhost }
669
+ });
670
+ }
671
+ // frontend/src/users/permissions/RabbitmqPermissionsModal.tsx
672
+ var { Button: Button$4, EmptyState: EmptyState$2, StandardModal: StandardModal$1 } = await importShared("@attraccess/plugins-frontend-ui");
673
+ var { Alert: Alert$1, AlertContent: AlertContent$1, AlertDescription: AlertDescription$1, Input: Input$2, Label: Label$2, ModalBody: ModalBody$1, ModalFooter: ModalFooter$1, ModalHeader: ModalHeader$1, ModalHeading: ModalHeading$1, TextField: TextField$2 } = await importShared("@heroui/react");
674
+ var { PlusIcon: PlusIcon$1, Trash2Icon: Trash2Icon$1 } = await importShared("lucide-react");
675
+ var { useEffect: useEffect$4, useState: useState$6 } = await importShared("react");
676
+ function PermissionEditor({ row, busy, onChange, onSave, onRemove }) {
677
+ const { t } = useRabbitmqTranslations();
678
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
679
+ className: "rmq:flex rmq:flex-col rmq:gap-3 rmq:rounded-lg rmq:border rmq:border-default-200 rmq:dark:border-default-100 rmq:p-3",
680
+ "data-cy": `rabbitmq-permissions-row-${row.vhost}`,
681
+ children: [
682
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
683
+ className: "rmq:flex rmq:items-center rmq:justify-between rmq:gap-2",
684
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
685
+ className: "rmq:text-sm rmq:font-semibold rmq:text-default-700",
686
+ children: [
687
+ t("form.vhost"),
688
+ " ",
689
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: row.vhost })
690
+ ]
691
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$4, {
692
+ isIconOnly: true,
693
+ size: "sm",
694
+ variant: "ghost",
695
+ "aria-label": t("permissions.remove", { vhost: row.vhost }),
696
+ onPress: onRemove,
697
+ isDisabled: busy,
698
+ "data-cy": `rabbitmq-permissions-remove-button-${row.vhost}`,
699
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Trash2Icon$1, { className: "rmq:w-4 rmq:h-4 rmq:text-danger" })
700
+ })]
701
+ }),
702
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
703
+ className: "rmq:grid rmq:grid-cols-1 rmq:md:grid-cols-3 rmq:gap-3",
704
+ children: [
705
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TextField$2, {
706
+ value: row.configure,
707
+ onChange: (v) => onChange({
708
+ ...row,
709
+ configure: v
710
+ }),
711
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Label$2, { children: t("permissions.configure") }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Input$2, {
712
+ autoComplete: "off",
713
+ "data-cy": `rabbitmq-permissions-configure-input-${row.vhost}`
714
+ })]
715
+ }),
716
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TextField$2, {
717
+ value: row.write,
718
+ onChange: (v) => onChange({
719
+ ...row,
720
+ write: v
721
+ }),
722
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Label$2, { children: t("permissions.write") }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Input$2, {
723
+ autoComplete: "off",
724
+ "data-cy": `rabbitmq-permissions-write-input-${row.vhost}`
725
+ })]
726
+ }),
727
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TextField$2, {
728
+ value: row.read,
729
+ onChange: (v) => onChange({
730
+ ...row,
731
+ read: v
732
+ }),
733
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Label$2, { children: t("permissions.read") }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Input$2, {
734
+ autoComplete: "off",
735
+ "data-cy": `rabbitmq-permissions-read-input-${row.vhost}`
736
+ })]
737
+ })
738
+ ]
739
+ }),
740
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
741
+ className: "rmq:flex rmq:flex-wrap rmq:justify-end rmq:gap-2",
742
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$4, {
743
+ size: "sm",
744
+ variant: "ghost",
745
+ onPress: () => onChange({
746
+ ...row,
747
+ ...DEFAULT_MQTT_PERMISSIONS
748
+ }),
749
+ isDisabled: busy,
750
+ "data-cy": `rabbitmq-permissions-mqtt-defaults-button-${row.vhost}`,
751
+ children: t("permissions.defaults")
752
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$4, {
753
+ size: "sm",
754
+ variant: "primary",
755
+ onPress: onSave,
756
+ isPending: busy,
757
+ "data-cy": `rabbitmq-permissions-save-button-${row.vhost}`,
758
+ children: t("common.save")
759
+ })]
760
+ })
761
+ ]
762
+ });
763
+ }
764
+ function RabbitmqPermissionsModal({ mqttServerId, isOpen, user, vhosts, onClose, onSaved }) {
765
+ const { t, tMessage } = useRabbitmqTranslations();
766
+ const [rows, setRows] = useState$6([]);
767
+ const [newVhost, setNewVhost] = useState$6("");
768
+ const [busyVhost, setBusyVhost] = useState$6(null);
769
+ const [error, setError] = useState$6(null);
770
+ useEffect$4(() => {
771
+ if (!isOpen) return;
772
+ setRows((user?.permissions ?? []).map((permission) => ({
773
+ ...permission,
774
+ persisted: true
775
+ })));
776
+ setNewVhost("");
777
+ setBusyVhost(null);
778
+ setError(null);
779
+ }, [isOpen, user]);
780
+ if (!user) return null;
781
+ const updateRow = (index, next) => {
782
+ setRows((current) => current.map((row, i) => i === index ? next : row));
783
+ };
784
+ const saveRow = async (index) => {
785
+ const row = rows[index];
786
+ setBusyVhost(row.vhost);
787
+ setError(null);
788
+ try {
789
+ await setPermissions(mqttServerId, user.name, {
790
+ vhost: row.vhost,
791
+ configure: row.configure,
792
+ write: row.write,
793
+ read: row.read
794
+ });
795
+ updateRow(index, {
796
+ ...row,
797
+ persisted: true
798
+ });
799
+ onSaved();
800
+ } catch (err) {
801
+ setError(err instanceof Error ? err.message : { key: "permissions.saveError" });
802
+ } finally {
803
+ setBusyVhost(null);
804
+ }
805
+ };
806
+ const removeRow = async (index) => {
807
+ const row = rows[index];
808
+ if (!row.persisted) {
809
+ setRows((current) => current.filter((_, i) => i !== index));
810
+ return;
811
+ }
812
+ setBusyVhost(row.vhost);
813
+ setError(null);
814
+ try {
815
+ await clearPermissions(mqttServerId, user.name, row.vhost);
816
+ setRows((current) => current.filter((_, i) => i !== index));
817
+ onSaved();
818
+ } catch (err) {
819
+ setError(err instanceof Error ? err.message : { key: "permissions.removeError" });
820
+ } finally {
821
+ setBusyVhost(null);
822
+ }
823
+ };
824
+ const addVhost = () => {
825
+ const vhost = newVhost.trim();
826
+ if (vhost.length === 0) return;
827
+ if (rows.some((row) => row.vhost === vhost)) {
828
+ setError({
829
+ key: "permissions.duplicate",
830
+ data: { vhost }
831
+ });
832
+ return;
833
+ }
834
+ setRows((current) => [...current, {
835
+ vhost,
836
+ persisted: false,
837
+ ...DEFAULT_MQTT_PERMISSIONS
838
+ }]);
839
+ setNewVhost("");
840
+ setError(null);
841
+ };
842
+ const unusedVhosts = vhosts.filter((vhost) => !rows.some((row) => row.vhost === vhost));
843
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StandardModal$1, {
844
+ size: "lg",
845
+ isOpen,
846
+ onOpenChange: (open) => {
847
+ if (!open) onClose();
848
+ },
849
+ "data-cy": `rabbitmq-permissions-modal-${mqttServerId}`,
850
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
851
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModalHeader$1, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModalHeading$1, { children: t("permissions.title", { name: user.name }) }) }),
852
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ModalBody$1, {
853
+ className: "rmq:flex rmq:flex-col rmq:gap-4 rmq:w-full",
854
+ children: [
855
+ rows.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
856
+ "data-cy": "rabbitmq-permissions-empty",
857
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyState$2, { message: t("permissions.empty") })
858
+ }),
859
+ rows.map((row, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PermissionEditor, {
860
+ row,
861
+ busy: busyVhost === row.vhost,
862
+ onChange: (next) => updateRow(index, next),
863
+ onSave: () => saveRow(index),
864
+ onRemove: () => removeRow(index)
865
+ }, row.vhost)),
866
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
867
+ className: "rmq:flex rmq:items-end rmq:gap-2",
868
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TextField$2, {
869
+ value: newVhost,
870
+ onChange: setNewVhost,
871
+ className: "rmq:flex-1",
872
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Label$2, { children: [t("permissions.addVhost"), unusedVhosts.length > 0 ? t("form.available", { vhosts: unusedVhosts.join(", ") }) : ""] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Input$2, {
873
+ placeholder: "/",
874
+ autoComplete: "off",
875
+ "data-cy": "rabbitmq-permissions-add-vhost-input"
876
+ })]
877
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button$4, {
878
+ variant: "secondary",
879
+ onPress: addVhost,
880
+ isDisabled: newVhost.trim().length === 0,
881
+ "data-cy": "rabbitmq-permissions-add-vhost-button",
882
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlusIcon$1, { className: "rmq:w-4 rmq:h-4" }), t("permissions.add")]
883
+ })]
884
+ }),
885
+ error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Alert$1, {
886
+ status: "danger",
887
+ "data-cy": "rabbitmq-permissions-error-alert",
888
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertContent$1, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertDescription$1, { children: tMessage(error) }) })
889
+ })
890
+ ]
891
+ }),
892
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModalFooter$1, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$4, {
893
+ variant: "secondary",
894
+ onPress: onClose,
895
+ "data-cy": "rabbitmq-permissions-close-button",
896
+ children: t("common.close")
897
+ }) })
898
+ ] })
899
+ });
900
+ }
901
+ // frontend/src/users/RabbitmqUserFormModal.tsx
902
+ var { Button: Button$3, StandardModal } = await importShared("@attraccess/plugins-frontend-ui");
903
+ var { Alert, AlertContent, AlertDescription, Checkbox, Form, Input: Input$1, Label: Label$1, ModalBody, ModalFooter, ModalHeader, ModalHeading, TextField: TextField$1 } = await importShared("@heroui/react");
904
+ var { useEffect: useEffect$3, useState: useState$5 } = await importShared("react");
905
+ function parseTags(value) {
906
+ return value.split(",").map((tag) => tag.trim()).filter((tag) => tag.length > 0);
907
+ }
908
+ function RabbitmqUserFormModal({ mqttServerId, isOpen, user, vhosts, existingUsernames = [], onClose, onSaved }) {
909
+ const { t, tMessage } = useRabbitmqTranslations();
910
+ const isEdit = user !== null;
911
+ const [username, setUsername] = useState$5("");
912
+ const [password, setPassword] = useState$5("");
913
+ const [tags, setTags] = useState$5("");
914
+ const [grantMqttDefaults, setGrantMqttDefaults] = useState$5(true);
915
+ const [vhost, setVhost] = useState$5("/");
916
+ const [saving, setSaving] = useState$5(false);
917
+ const [error, setError] = useState$5(null);
918
+ useEffect$3(() => {
919
+ if (!isOpen) return;
920
+ setUsername(user?.name ?? "");
921
+ setPassword("");
922
+ setTags(user?.tags.join(", ") ?? "");
923
+ setGrantMqttDefaults(true);
924
+ setVhost(vhosts.includes("/") || vhosts.length === 0 ? "/" : vhosts[0]);
925
+ setError(null);
926
+ }, [
927
+ isOpen,
928
+ user,
929
+ vhosts
930
+ ]);
931
+ const handleSubmit = async (e) => {
932
+ e.preventDefault();
933
+ const name = username.trim();
934
+ if (name.length === 0) {
935
+ setError({ key: "form.usernameRequired" });
936
+ return;
937
+ }
938
+ if (!isEdit && existingUsernames.includes(name)) {
939
+ setError({ key: "form.usernameTaken" });
940
+ return;
941
+ }
942
+ if (!isEdit && password.length === 0) {
943
+ setError({ key: "form.passwordRequired" });
944
+ return;
945
+ }
946
+ const body = { tags: parseTags(tags) };
947
+ if (password.length > 0) body.password = password;
948
+ if (!isEdit && grantMqttDefaults && vhost.trim().length > 0) body.permissions = [{
949
+ vhost: vhost.trim(),
950
+ ...DEFAULT_MQTT_PERMISSIONS
951
+ }];
952
+ setSaving(true);
953
+ setError(null);
954
+ try {
955
+ await upsertUser(mqttServerId, name, body);
956
+ onSaved();
957
+ onClose();
958
+ } catch (err) {
959
+ setError(err instanceof Error ? err.message : { key: "form.saveError" });
960
+ } finally {
961
+ setSaving(false);
962
+ }
963
+ };
964
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StandardModal, {
965
+ size: "md",
966
+ isOpen,
967
+ onOpenChange: (open) => {
968
+ if (!open) onClose();
969
+ },
970
+ "data-cy": `rabbitmq-user-form-modal-${mqttServerId}`,
971
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModalHeader, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModalHeading, { children: isEdit ? t("form.editTitle", { name: user.name }) : t("form.createTitle") }) }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Form, {
972
+ onSubmit: handleSubmit,
973
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ModalBody, {
974
+ className: "rmq:flex rmq:flex-col rmq:gap-4 rmq:w-full",
975
+ children: [
976
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TextField$1, {
977
+ value: username,
978
+ onChange: setUsername,
979
+ className: "rmq:w-full",
980
+ isDisabled: isEdit,
981
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Label$1, { children: t("users.username") }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Input$1, {
982
+ name: "rabbitmq-username",
983
+ placeholder: t("form.usernamePlaceholder"),
984
+ autoComplete: "off",
985
+ "data-cy": "rabbitmq-user-form-username-input"
986
+ })]
987
+ }),
988
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TextField$1, {
989
+ value: password,
990
+ onChange: setPassword,
991
+ className: "rmq:w-full",
992
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Label$1, { children: t(isEdit ? "form.newPassword" : "form.password") }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Input$1, {
993
+ name: "rabbitmq-password",
994
+ type: "password",
995
+ autoComplete: "new-password",
996
+ "data-cy": "rabbitmq-user-form-password-input"
997
+ })]
998
+ }),
999
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TextField$1, {
1000
+ value: tags,
1001
+ onChange: setTags,
1002
+ className: "rmq:w-full",
1003
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Label$1, { children: t("form.tags") }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Input$1, {
1004
+ name: "rabbitmq-tags",
1005
+ placeholder: t("users.none"),
1006
+ autoComplete: "off",
1007
+ "data-cy": "rabbitmq-user-form-tags-input"
1008
+ })]
1009
+ }),
1010
+ !isEdit && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1011
+ className: "rmq:flex rmq:flex-col rmq:gap-3 rmq:rounded-lg rmq:border rmq:border-default-200 rmq:dark:border-default-100 rmq:p-3",
1012
+ children: [
1013
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Checkbox, {
1014
+ isSelected: grantMqttDefaults,
1015
+ onChange: setGrantMqttDefaults,
1016
+ "data-cy": "rabbitmq-user-form-mqtt-defaults-checkbox",
1017
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Checkbox.Content, {
1018
+ className: "rmq:items-start",
1019
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Checkbox.Control, {
1020
+ className: "rmq:mt-0.5",
1021
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Checkbox.Indicator, {})
1022
+ }), t("form.grant")]
1023
+ })
1024
+ }),
1025
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
1026
+ className: "rmq:text-xs rmq:text-default-500",
1027
+ children: t("form.defaults", DEFAULT_MQTT_PERMISSIONS)
1028
+ }),
1029
+ grantMqttDefaults && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TextField$1, {
1030
+ value: vhost,
1031
+ onChange: setVhost,
1032
+ className: "rmq:w-full",
1033
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Label$1, { children: [t("form.vhost"), vhosts.length > 0 ? t("form.available", { vhosts: vhosts.join(", ") }) : ""] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Input$1, {
1034
+ name: "rabbitmq-vhost",
1035
+ placeholder: "/",
1036
+ autoComplete: "off",
1037
+ "data-cy": "rabbitmq-user-form-vhost-input"
1038
+ })]
1039
+ })
1040
+ ]
1041
+ }),
1042
+ error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Alert, {
1043
+ status: "danger",
1044
+ "data-cy": "rabbitmq-user-form-error-alert",
1045
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertContent, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertDescription, { children: tMessage(error) }) })
1046
+ })
1047
+ ]
1048
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ModalFooter, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$3, {
1049
+ variant: "secondary",
1050
+ onPress: onClose,
1051
+ "data-cy": "rabbitmq-user-form-cancel-button",
1052
+ children: t("common.cancel")
1053
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$3, {
1054
+ variant: "primary",
1055
+ type: "submit",
1056
+ isPending: saving,
1057
+ "data-cy": "rabbitmq-user-form-save-button",
1058
+ children: t(isEdit ? "form.save" : "form.create")
1059
+ })] })]
1060
+ })] })
1061
+ });
1062
+ }
1063
+ // frontend/src/users/RabbitmqUserPanelCardHeader.tsx
1064
+ var { Button: Button$2 } = await importShared("@attraccess/plugins-frontend-ui");
1065
+ var { Card: Card$3 } = await importShared("@heroui/react");
1066
+ var { PlusIcon, RefreshCwIcon: RefreshCwIcon$2, UsersIcon } = await importShared("lucide-react");
1067
+ function RabbitmqUserPanelCardHeader({ reload, loading, mqttServerId, onCreate, canManage }) {
1068
+ const { t } = useRabbitmqTranslations();
1069
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$3.Header, {
1070
+ className: "rmq:flex rmq:flex-row rmq:items-center rmq:justify-between rmq:gap-2",
1071
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1072
+ className: "rmq:flex rmq:items-center rmq:gap-2",
1073
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(UsersIcon, { className: "rmq:w-5 rmq:h-5 rmq:text-accent-soft-foreground" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
1074
+ className: "rmq:text-base rmq:font-semibold rmq:text-default-700",
1075
+ children: t("users.title")
1076
+ })]
1077
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1078
+ className: "rmq:flex rmq:items-center rmq:gap-2",
1079
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$2, {
1080
+ isIconOnly: true,
1081
+ size: "sm",
1082
+ variant: "ghost",
1083
+ "aria-label": t("users.reload"),
1084
+ onPress: () => void reload(),
1085
+ isPending: loading,
1086
+ "data-cy": `rabbitmq-user-panel-reload-${mqttServerId}`,
1087
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RefreshCwIcon$2, { className: "rmq:w-4 rmq:h-4" })
1088
+ }), canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button$2, {
1089
+ size: "sm",
1090
+ variant: "primary",
1091
+ onPress: onCreate,
1092
+ "data-cy": `rabbitmq-user-panel-create-button-${mqttServerId}`,
1093
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlusIcon, { className: "rmq:w-4 rmq:h-4" }), t("users.add")]
1094
+ })]
1095
+ })]
1096
+ });
1097
+ }
1098
+ // frontend/src/users/errorTitle.ts
1099
+ function errorTitle(error, title) {
1100
+ return typeof error === "string" ? title : void 0;
1101
+ }
1102
+ // frontend/src/users/RabbitmqUserDeleteMessage.tsx
1103
+ var { StatusAlert: StatusAlert$4 } = await importShared("@attraccess/plugins-frontend-ui");
1104
+ var { useImperativeHandle: useImperativeHandle$1, useState: useState$4 } = await importShared("react");
1105
+ function RabbitmqUserDeleteMessage({ name, ref }) {
1106
+ const { t, tMessage } = useRabbitmqTranslations();
1107
+ const [error, setError] = useState$4(null);
1108
+ useImperativeHandle$1(ref, () => ({ showError: setError }), []);
1109
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1110
+ className: "rmq:flex rmq:flex-col rmq:gap-3",
1111
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: t("users.deleteDescription", { name }) }), error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$4, {
1112
+ status: "danger",
1113
+ title: errorTitle(error, t("users.deleteError")),
1114
+ "data-cy": "rabbitmq-user-delete-error-alert",
1115
+ children: tMessage(error)
1116
+ })]
1117
+ });
1118
+ }
1119
+ // frontend/src/users/RabbitmqUserTable.tsx
1120
+ var { TableActionsColumnHeader: TableActionsColumnHeader$1, TableRowActions: TableRowActions$1 } = await importShared("@attraccess/plugins-frontend-ui");
1121
+ var { Chip: Chip$2, Table: Table$2, TableBody: TableBody$2, TableCell: TableCell$2, TableColumn: TableColumn$2, TableContent: TableContent$2, TableHeader: TableHeader$2, TableRow: TableRow$2, TableScrollContainer: TableScrollContainer$2 } = await importShared("@heroui/react");
1122
+ var { KeyRoundIcon, PencilIcon, Trash2Icon } = await importShared("lucide-react");
1123
+ var { useRef: useRef$3 } = await importShared("react");
1124
+ function PermissionChips({ user }) {
1125
+ const { t } = useRabbitmqTranslations();
1126
+ if (user.permissions.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1127
+ className: "rmq:text-xs rmq:text-default-400",
1128
+ children: t("users.none")
1129
+ });
1130
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
1131
+ className: "rmq:flex rmq:flex-wrap rmq:gap-1",
1132
+ children: user.permissions.map((permission) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Chip$2, {
1133
+ size: "sm",
1134
+ variant: "soft",
1135
+ title: t("permissions.summary", { ...permission }),
1136
+ children: permission.vhost
1137
+ }, permission.vhost))
1138
+ });
1139
+ }
1140
+ function RabbitmqUserTable({ users, canManage, onEdit, onPermissions, onDelete }) {
1141
+ const { t, language } = useRabbitmqTranslations();
1142
+ const deleteMessage = useRef$3(null);
1143
+ const confirmDelete = async (user) => {
1144
+ deleteMessage.current?.showError(null);
1145
+ try {
1146
+ await onDelete(user);
1147
+ } catch (err) {
1148
+ deleteMessage.current?.showError(err instanceof Error ? err.message : { key: "users.deleteError" });
1149
+ throw err;
1150
+ }
1151
+ };
1152
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Table$2, {
1153
+ "data-cy": "rabbitmq-user-panel-table",
1154
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableScrollContainer$2, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableContent$2, {
1155
+ "aria-label": t("users.title"),
1156
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableHeader$2, { children: [
1157
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$2, {
1158
+ isRowHeader: true,
1159
+ children: t("users.username")
1160
+ }),
1161
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$2, { children: t("users.tags") }),
1162
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$2, { children: t("users.access") }),
1163
+ canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$2, {
1164
+ id: "actions",
1165
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableActionsColumnHeader$1, {})
1166
+ })
1167
+ ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableBody$2, {
1168
+ items: users,
1169
+ dependencies: [language],
1170
+ children: (user) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableRow$2, {
1171
+ id: user.name,
1172
+ children: [
1173
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$2, {
1174
+ className: "rmq:whitespace-nowrap rmq:font-medium",
1175
+ children: user.name
1176
+ }),
1177
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$2, { children: user.tags.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1178
+ className: "rmq:text-xs rmq:text-default-400",
1179
+ children: t("users.none")
1180
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
1181
+ className: "rmq:flex rmq:flex-wrap rmq:gap-1",
1182
+ children: user.tags.map((tag) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Chip$2, {
1183
+ size: "sm",
1184
+ color: "accent",
1185
+ variant: "soft",
1186
+ children: tag
1187
+ }, tag))
1188
+ }) }),
1189
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$2, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PermissionChips, { user }) }),
1190
+ canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$2, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableRowActions$1, {
1191
+ itemName: user.name,
1192
+ actions: [
1193
+ {
1194
+ key: "edit",
1195
+ label: t("users.edit"),
1196
+ icon: PencilIcon,
1197
+ onPress: () => onEdit(user),
1198
+ "data-cy": `rabbitmq-user-edit-button-${user.name}`
1199
+ },
1200
+ {
1201
+ key: "permissions",
1202
+ label: t("users.permissions"),
1203
+ icon: KeyRoundIcon,
1204
+ onPress: () => onPermissions(user),
1205
+ "data-cy": `rabbitmq-user-permissions-button-${user.name}`
1206
+ },
1207
+ {
1208
+ key: "delete",
1209
+ label: t("users.deleteTitle"),
1210
+ icon: Trash2Icon,
1211
+ tone: "danger",
1212
+ onPress: () => confirmDelete(user),
1213
+ "data-cy": `rabbitmq-user-delete-button-${user.name}`,
1214
+ confirm: {
1215
+ title: t("users.deleteTitle"),
1216
+ message: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqUserDeleteMessage, {
1217
+ name: user.name,
1218
+ ref: deleteMessage
1219
+ }),
1220
+ confirmLabel: t("common.delete"),
1221
+ cancelLabel: t("common.cancel"),
1222
+ "data-cy": `rabbitmq-user-delete-modal-${user.name}`,
1223
+ confirmDataCy: "rabbitmq-user-delete-confirm-button",
1224
+ cancelDataCy: "rabbitmq-user-delete-cancel-button"
1225
+ }
1226
+ }
1227
+ ]
1228
+ }) })
1229
+ ]
1230
+ }, user.name)
1231
+ })]
1232
+ }) })
1233
+ });
1234
+ }
1235
+ // frontend/src/users/RabbitmqUserPanel.tsx
1236
+ var { StatusAlert: StatusAlert$3, TableDataLoadingIndicator: TableDataLoadingIndicator$2 } = await importShared("@attraccess/plugins-frontend-ui");
1237
+ var { Card: Card$2 } = await importShared("@heroui/react");
1238
+ var { useCallback: useCallback$1, useEffect: useEffect$2, useRef: useRef$2, useState: useState$3 } = await importShared("react");
1239
+ function RabbitmqUserPanel({ mqttServerId, canManage = false }) {
1240
+ const { t, tMessage } = useRabbitmqTranslations();
1241
+ const { result } = useDetection(mqttServerId);
1242
+ const [data, setData] = useState$3(null);
1243
+ const [loading, setLoading] = useState$3(false);
1244
+ const [loadError, setLoadError] = useState$3(null);
1245
+ const [formOpen, setFormOpen] = useState$3(false);
1246
+ const [formUser, setFormUser] = useState$3(null);
1247
+ const [permissionsUser, setPermissionsUser] = useState$3(null);
1248
+ const mounted = useRef$2(true);
1249
+ useEffect$2(() => {
1250
+ mounted.current = true;
1251
+ return () => {
1252
+ mounted.current = false;
1253
+ };
1254
+ }, []);
1255
+ const reload = useCallback$1(async () => {
1256
+ setLoading(true);
1257
+ setLoadError(null);
1258
+ try {
1259
+ const list = await fetchUsers(mqttServerId);
1260
+ if (mounted.current) {
1261
+ setData(list);
1262
+ setPermissionsUser((current) => current ? list.users.find((user) => user.name === current.name) ?? current : null);
1263
+ }
1264
+ } catch (err) {
1265
+ if (mounted.current) setLoadError(err instanceof Error ? err.message : { key: "users.loadError" });
1266
+ } finally {
1267
+ if (mounted.current) setLoading(false);
1268
+ }
1269
+ }, [mqttServerId]);
1270
+ const manageable = result?.isRabbitMQ === true && result.authOk;
1271
+ useEffect$2(() => {
1272
+ if (manageable) reload();
1273
+ }, [manageable, reload]);
1274
+ if (!manageable) return null;
1275
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$2, {
1276
+ "data-cy": `rabbitmq-user-panel-${mqttServerId}`,
1277
+ className: "rmq:w-full rmq:border rmq:border-default-200 rmq:dark:border-default-100",
1278
+ children: [
1279
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqUserPanelCardHeader, {
1280
+ reload,
1281
+ loading,
1282
+ mqttServerId,
1283
+ onCreate: () => {
1284
+ setFormUser(null);
1285
+ setFormOpen(true);
1286
+ },
1287
+ canManage
1288
+ }),
1289
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$2.Content, {
1290
+ className: "rmq:flex rmq:flex-col rmq:gap-3",
1291
+ children: [
1292
+ loadError && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$3, {
1293
+ status: "danger",
1294
+ title: errorTitle(loadError, t("users.loadError")),
1295
+ "data-cy": "rabbitmq-user-panel-error-alert",
1296
+ children: tMessage(loadError)
1297
+ }),
1298
+ !data && !loadError && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
1299
+ "data-cy": "rabbitmq-user-panel-loading-spinner",
1300
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableDataLoadingIndicator$2, {})
1301
+ }),
1302
+ data && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqUserTable, {
1303
+ users: data.users,
1304
+ canManage,
1305
+ onEdit: (user) => {
1306
+ setFormUser(user);
1307
+ setFormOpen(true);
1308
+ },
1309
+ onPermissions: setPermissionsUser,
1310
+ onDelete: async (user) => {
1311
+ await deleteUser(mqttServerId, user.name);
1312
+ reload();
1313
+ }
1314
+ })
1315
+ ]
1316
+ }),
1317
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqUserFormModal, {
1318
+ mqttServerId,
1319
+ isOpen: formOpen,
1320
+ user: formUser,
1321
+ vhosts: data?.vhosts ?? [],
1322
+ existingUsernames: data?.users.map((user) => user.name),
1323
+ onClose: () => setFormOpen(false),
1324
+ onSaved: () => void reload()
1325
+ }),
1326
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqPermissionsModal, {
1327
+ mqttServerId,
1328
+ isOpen: permissionsUser !== null,
1329
+ user: permissionsUser,
1330
+ vhosts: data?.vhosts ?? [],
1331
+ onClose: () => setPermissionsUser(null),
1332
+ onSaved: () => void reload()
1333
+ })
1334
+ ]
1335
+ });
1336
+ }
1337
+ // frontend/src/usePolledResource.ts
1338
+ var { useCallback, useEffect: useEffect$1, useRef: useRef$1, useState: useState$2 } = await importShared("react");
1339
+ function usePolledResource(fetcher, intervalMs, fallbackError) {
1340
+ const [data, setData] = useState$2(null);
1341
+ const [error, setError] = useState$2(null);
1342
+ const [loading, setLoading] = useState$2(false);
1343
+ const latest = useRef$1({
1344
+ fetcher,
1345
+ fallbackError
1346
+ });
1347
+ latest.current = {
1348
+ fetcher,
1349
+ fallbackError
1350
+ };
1351
+ const mounted = useRef$1(true);
1352
+ const inFlight = useRef$1(false);
1353
+ const again = useRef$1(false);
1354
+ const load = useCallback(async (queueIfBusy) => {
1355
+ if (inFlight.current) {
1356
+ if (queueIfBusy) again.current = true;
1357
+ return;
1358
+ }
1359
+ inFlight.current = true;
1360
+ setLoading(true);
1361
+ try {
1362
+ do {
1363
+ again.current = false;
1364
+ try {
1365
+ const result = await latest.current.fetcher();
1366
+ if (mounted.current) {
1367
+ setData(result);
1368
+ setError(null);
1369
+ }
1370
+ } catch (err) {
1371
+ if (mounted.current) setError(err instanceof Error && err.message ? err.message : latest.current.fallbackError);
1372
+ }
1373
+ } while (again.current && mounted.current);
1374
+ } finally {
1375
+ inFlight.current = false;
1376
+ again.current = false;
1377
+ if (mounted.current) setLoading(false);
1378
+ }
1379
+ }, []);
1380
+ const reload = useCallback(() => load(true), [load]);
1381
+ useEffect$1(() => {
1382
+ mounted.current = true;
1383
+ load(false);
1384
+ const timer = setInterval(() => {
1385
+ if (!document.hidden) load(false);
1386
+ }, intervalMs);
1387
+ const onVisible = () => {
1388
+ if (!document.hidden) load(false);
1389
+ };
1390
+ document.addEventListener("visibilitychange", onVisible);
1391
+ return () => {
1392
+ mounted.current = false;
1393
+ clearInterval(timer);
1394
+ document.removeEventListener("visibilitychange", onVisible);
1395
+ };
1396
+ }, [intervalMs, load]);
1397
+ return {
1398
+ data,
1399
+ error,
1400
+ loading,
1401
+ reload
1402
+ };
1403
+ }
1404
+ // frontend/src/connections/RabbitmqConnectionCloseMessage.tsx
1405
+ var { StatusAlert: StatusAlert$2 } = await importShared("@attraccess/plugins-frontend-ui");
1406
+ var { Input, Label, TextField } = await importShared("@heroui/react");
1407
+ var { useImperativeHandle, useState: useState$1 } = await importShared("react");
1408
+ function RabbitmqConnectionCloseMessage({ name, ref }) {
1409
+ const { t } = useRabbitmqTranslations();
1410
+ const [reason, setReason] = useState$1("");
1411
+ const [error, setError] = useState$1(null);
1412
+ useImperativeHandle(ref, () => ({
1413
+ reason,
1414
+ showError: setError
1415
+ }), [reason]);
1416
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1417
+ className: "rmq:flex rmq:flex-col rmq:gap-3",
1418
+ children: [
1419
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: t("connections.closeDescription", { name }) }),
1420
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TextField, {
1421
+ value: reason,
1422
+ onChange: setReason,
1423
+ className: "rmq:w-full",
1424
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Label, { children: t("connections.reason") }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Input, {
1425
+ autoComplete: "off",
1426
+ "data-cy": "rabbitmq-connection-close-reason-input"
1427
+ })]
1428
+ }),
1429
+ error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$2, {
1430
+ status: "danger",
1431
+ title: t("connections.closeError"),
1432
+ "data-cy": "rabbitmq-connection-close-error",
1433
+ children: error === t("connections.closeError") ? void 0 : error
1434
+ })
1435
+ ]
1436
+ });
1437
+ }
1438
+ // frontend/src/connections/connections-api.ts
1439
+ var api$2 = createPluginApiClient("/api/rabbitmq/connections");
1440
+ function fetchConnections(mqttServerId) {
1441
+ return api$2.request(`/${mqttServerId}`);
1442
+ }
1443
+ function closeConnection(mqttServerId, name, reason) {
1444
+ return api$2.request(`/${mqttServerId}`, {
1445
+ method: "DELETE",
1446
+ query: {
1447
+ name,
1448
+ reason: reason?.trim() ? reason.trim() : void 0
1449
+ }
1450
+ });
1451
+ }
1452
+ // frontend/src/connections/RabbitmqConnectionsPanel.tsx
1453
+ var { Button: Button$1, EmptyState: EmptyState$1, StatusAlert: StatusAlert$1, TableActionsColumnHeader, TableDataLoadingIndicator: TableDataLoadingIndicator$1, TableRowActions } = await importShared("@attraccess/plugins-frontend-ui");
1454
+ var { Card: Card$1, Chip: Chip$1, Table: Table$1, TableBody: TableBody$1, TableCell: TableCell$1, TableColumn: TableColumn$1, TableContent: TableContent$1, TableHeader: TableHeader$1, TableRow: TableRow$1, TableScrollContainer: TableScrollContainer$1 } = await importShared("@heroui/react");
1455
+ var { PlugZapIcon, RefreshCwIcon: RefreshCwIcon$1, UnplugIcon } = await importShared("lucide-react");
1456
+ var { useRef } = await importShared("react");
1457
+ var CONNECTIONS_POLL_INTERVAL_MS = 1e4;
1458
+ function RabbitmqConnectionsPanel({ mqttServerId, canManage }) {
1459
+ const { t } = useRabbitmqTranslations();
1460
+ const format = useRabbitmqFormatters();
1461
+ const { data, error, loading, reload } = usePolledResource(() => fetchConnections(mqttServerId), CONNECTIONS_POLL_INTERVAL_MS, t("connections.loadError"));
1462
+ const closeMessage = useRef(null);
1463
+ const confirmClose = async (connection) => {
1464
+ const message = closeMessage.current;
1465
+ message?.showError(null);
1466
+ try {
1467
+ await closeConnection(mqttServerId, connection.name, message?.reason ?? "");
1468
+ reload();
1469
+ } catch (err) {
1470
+ message?.showError(err instanceof Error && err.message ? err.message : t("connections.closeError"));
1471
+ reload();
1472
+ throw err;
1473
+ }
1474
+ };
1475
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$1, {
1476
+ "data-cy": `rabbitmq-connections-panel-${mqttServerId}`,
1477
+ className: "rmq:w-full rmq:border rmq:border-default-200 rmq:dark:border-default-100",
1478
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$1.Header, {
1479
+ className: "rmq:flex rmq:flex-row rmq:items-center rmq:justify-between rmq:gap-2",
1480
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1481
+ className: "rmq:flex rmq:items-center rmq:gap-2",
1482
+ children: [
1483
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlugZapIcon, { className: "rmq:w-5 rmq:h-5 rmq:text-accent-soft-foreground" }),
1484
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
1485
+ className: "rmq:text-base rmq:font-semibold rmq:text-default-700",
1486
+ children: t("connections.title")
1487
+ }),
1488
+ data && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Chip$1, {
1489
+ size: "sm",
1490
+ variant: "soft",
1491
+ children: format.number(data.total)
1492
+ })
1493
+ ]
1494
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button$1, {
1495
+ isIconOnly: true,
1496
+ size: "sm",
1497
+ variant: "ghost",
1498
+ "aria-label": t("connections.reload"),
1499
+ onPress: () => void reload(),
1500
+ isPending: loading,
1501
+ "data-cy": `rabbitmq-connections-reload-${mqttServerId}`,
1502
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RefreshCwIcon$1, { className: "rmq:w-4 rmq:h-4" })
1503
+ })]
1504
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card$1.Content, {
1505
+ className: "rmq:flex rmq:flex-col rmq:gap-3",
1506
+ children: [
1507
+ error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$1, {
1508
+ status: "danger",
1509
+ title: t("connections.loadError"),
1510
+ "data-cy": "rabbitmq-connections-error-alert",
1511
+ children: error === t("connections.loadError") ? void 0 : error
1512
+ }),
1513
+ !data && !error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableDataLoadingIndicator$1, {}),
1514
+ data && data.connections.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyState$1, { message: t("connections.empty") }),
1515
+ data && data.truncated && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert$1, {
1516
+ status: "warning",
1517
+ children: t("connections.truncated", {
1518
+ shown: format.number(data.connections.length),
1519
+ total: format.number(data.total)
1520
+ })
1521
+ }),
1522
+ data && data.connections.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Table$1, {
1523
+ "data-cy": "rabbitmq-connections-table",
1524
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableScrollContainer$1, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableContent$1, {
1525
+ "aria-label": t("connections.title"),
1526
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableHeader$1, { children: [
1527
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, {
1528
+ isRowHeader: true,
1529
+ children: t("connections.client")
1530
+ }),
1531
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.user") }),
1532
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.peer") }),
1533
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.protocol") }),
1534
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("common.state") }),
1535
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.connectedSince") }),
1536
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.channels") }),
1537
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, { children: t("connections.traffic") }),
1538
+ canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn$1, {
1539
+ id: "actions",
1540
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableActionsColumnHeader, {})
1541
+ })
1542
+ ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableBody$1, {
1543
+ items: data.connections,
1544
+ children: (connection) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableRow$1, {
1545
+ id: connection.name,
1546
+ children: [
1547
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, {
1548
+ className: "rmq:font-medium rmq:whitespace-nowrap",
1549
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1550
+ title: connection.name,
1551
+ children: connection.clientId ?? connection.name
1552
+ })
1553
+ }),
1554
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, { children: connection.user ?? "—" }),
1555
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, {
1556
+ className: "rmq:whitespace-nowrap",
1557
+ children: connection.peerHost ? `${connection.peerHost}:${connection.peerPort ?? ""}` : "—"
1558
+ }),
1559
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, {
1560
+ className: "rmq:whitespace-nowrap",
1561
+ children: connection.protocol ?? "—"
1562
+ }),
1563
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, { children: connection.state ?? "—" }),
1564
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, {
1565
+ className: "rmq:whitespace-nowrap",
1566
+ children: format.dateTime(connection.connectedAt)
1567
+ }),
1568
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, { children: format.number(connection.channels) }),
1569
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableCell$1, {
1570
+ className: "rmq:whitespace-nowrap rmq:text-xs",
1571
+ children: [
1572
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1573
+ "aria-hidden": true,
1574
+ children: "↓ "
1575
+ }),
1576
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
1577
+ className: "rmq:sr-only",
1578
+ children: [t("connections.received"), ": "]
1579
+ }),
1580
+ format.bytes(connection.recvBytes),
1581
+ " (",
1582
+ format.rate(connection.recvRate, "B/s"),
1583
+ ")",
1584
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {}),
1585
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1586
+ "aria-hidden": true,
1587
+ children: "↑ "
1588
+ }),
1589
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
1590
+ className: "rmq:sr-only",
1591
+ children: [t("connections.sent"), ": "]
1592
+ }),
1593
+ format.bytes(connection.sendBytes),
1594
+ " (",
1595
+ format.rate(connection.sendRate, "B/s"),
1596
+ ")"
1597
+ ]
1598
+ }),
1599
+ canManage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell$1, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableRowActions, {
1600
+ itemName: connection.clientId ?? connection.name,
1601
+ actions: [{
1602
+ key: "close",
1603
+ label: t("connections.closeTitle"),
1604
+ icon: UnplugIcon,
1605
+ tone: "danger",
1606
+ onPress: () => confirmClose(connection),
1607
+ "data-cy": `rabbitmq-connection-close-button-${connection.name}`,
1608
+ confirm: {
1609
+ title: t("connections.closeTitle"),
1610
+ message: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqConnectionCloseMessage, {
1611
+ name: connection.clientId ?? connection.name,
1612
+ ref: closeMessage
1613
+ }),
1614
+ confirmLabel: t("connections.closeConfirm"),
1615
+ cancelLabel: t("common.cancel"),
1616
+ "data-cy": `rabbitmq-connection-close-modal-${mqttServerId}`,
1617
+ confirmDataCy: "rabbitmq-connection-close-confirm-button"
1618
+ }
1619
+ }]
1620
+ }) })
1621
+ ]
1622
+ }, connection.name)
1623
+ })]
1624
+ }) })
1625
+ })
1626
+ ]
1627
+ })]
1628
+ });
1629
+ }
1630
+ // frontend/src/Duration.tsx
1631
+ var { useFormatedDuration } = await importShared("@attraccess/plugins-frontend-ui");
1632
+ function Duration({ ms }) {
1633
+ const formatted = useFormatedDuration(ms == null ? 0 : Math.floor(ms / 6e4));
1634
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: ms == null ? "—" : formatted });
1635
+ }
1636
+ // frontend/src/stats/stats-api.ts
1637
+ var api$1 = createPluginApiClient("/api/rabbitmq/stats");
1638
+ function fetchStats(mqttServerId) {
1639
+ return api$1.request(`/${mqttServerId}`);
1640
+ }
1641
+ // frontend/src/stats/RabbitmqStatsPanel.tsx
1642
+ var { Button, EmptyState, StatusAlert, TableDataLoadingIndicator } = await importShared("@attraccess/plugins-frontend-ui");
1643
+ var { Card, Chip, Table, TableBody, TableCell, TableColumn, TableContent, TableHeader, TableRow, TableScrollContainer } = await importShared("@heroui/react");
1644
+ var { BarChart3Icon, RefreshCwIcon, TriangleAlertIcon } = await importShared("lucide-react");
1645
+ var STATS_POLL_INTERVAL_MS = 15e3;
1646
+ function Stat({ label, value }) {
1647
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1648
+ className: "rmq:flex rmq:flex-col rmq:rounded-lg rmq:border rmq:border-default-200 rmq:dark:border-default-100 rmq:p-3",
1649
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1650
+ className: "rmq:text-xs rmq:text-default-500",
1651
+ children: label
1652
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1653
+ className: "rmq:text-lg rmq:font-semibold rmq:text-default-700",
1654
+ children: value
1655
+ })]
1656
+ });
1657
+ }
1658
+ function Alarm({ alarm, children }) {
1659
+ const { t } = useRabbitmqTranslations();
1660
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
1661
+ className: "rmq:flex rmq:items-center rmq:gap-1 rmq:whitespace-nowrap",
1662
+ children: [children, alarm === true && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Chip, {
1663
+ size: "sm",
1664
+ color: "danger",
1665
+ variant: "soft",
1666
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TriangleAlertIcon, {
1667
+ className: "rmq:w-3 rmq:h-3",
1668
+ "aria-hidden": true
1669
+ }), t("stats.alarm")]
1670
+ })]
1671
+ });
1672
+ }
1673
+ function RabbitmqStatsPanel({ mqttServerId }) {
1674
+ const { t } = useRabbitmqTranslations();
1675
+ const format = useRabbitmqFormatters();
1676
+ const ratio = (used, total) => used === null ? "—" : `${format.number(used)} / ${format.number(total)}`;
1677
+ const { data, error, loading, reload } = usePolledResource(() => fetchStats(mqttServerId), STATS_POLL_INTERVAL_MS, t("stats.loadError"));
1678
+ const overview = data?.overview;
1679
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card, {
1680
+ "data-cy": `rabbitmq-stats-panel-${mqttServerId}`,
1681
+ className: "rmq:w-full rmq:border rmq:border-default-200 rmq:dark:border-default-100",
1682
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card.Header, {
1683
+ className: "rmq:flex rmq:flex-row rmq:items-center rmq:justify-between rmq:gap-2",
1684
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1685
+ className: "rmq:flex rmq:items-center rmq:gap-2",
1686
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(BarChart3Icon, { className: "rmq:w-5 rmq:h-5 rmq:text-accent-soft-foreground" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
1687
+ className: "rmq:text-base rmq:font-semibold rmq:text-default-700",
1688
+ children: t("stats.title")
1689
+ })]
1690
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
1691
+ isIconOnly: true,
1692
+ size: "sm",
1693
+ variant: "ghost",
1694
+ "aria-label": t("stats.reload"),
1695
+ onPress: () => void reload(),
1696
+ isPending: loading,
1697
+ "data-cy": `rabbitmq-stats-reload-${mqttServerId}`,
1698
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RefreshCwIcon, { className: "rmq:w-4 rmq:h-4" })
1699
+ })]
1700
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card.Content, {
1701
+ className: "rmq:flex rmq:flex-col rmq:gap-4",
1702
+ children: [
1703
+ error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert, {
1704
+ status: "danger",
1705
+ title: t("stats.loadError"),
1706
+ "data-cy": "rabbitmq-stats-error-alert",
1707
+ children: error === t("stats.loadError") ? void 0 : error
1708
+ }),
1709
+ !data && !error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableDataLoadingIndicator, {}),
1710
+ overview && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1711
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1712
+ className: "rmq:grid rmq:grid-cols-2 rmq:md:grid-cols-4 rmq:gap-3",
1713
+ "data-cy": "rabbitmq-stats-overview",
1714
+ children: [
1715
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Stat, {
1716
+ label: t("stats.version"),
1717
+ value: overview.rabbitmqVersion ?? "—"
1718
+ }),
1719
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Stat, {
1720
+ label: t("stats.erlang"),
1721
+ value: overview.erlangVersion ?? "—"
1722
+ }),
1723
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Stat, {
1724
+ label: t("stats.cluster"),
1725
+ value: overview.clusterName ?? "—"
1726
+ }),
1727
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Stat, {
1728
+ label: t("stats.connections"),
1729
+ value: format.number(overview.connections)
1730
+ }),
1731
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Stat, {
1732
+ label: t("stats.channels"),
1733
+ value: format.number(overview.channels)
1734
+ }),
1735
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Stat, {
1736
+ label: t("stats.queues"),
1737
+ value: format.number(overview.queues)
1738
+ }),
1739
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Stat, {
1740
+ label: t("stats.consumers"),
1741
+ value: format.number(overview.consumers)
1742
+ }),
1743
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Stat, {
1744
+ label: t("stats.ready"),
1745
+ value: format.number(overview.messagesReady)
1746
+ }),
1747
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Stat, {
1748
+ label: t("stats.unacked"),
1749
+ value: format.number(overview.messagesUnacknowledged)
1750
+ }),
1751
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Stat, {
1752
+ label: t("stats.publishRate"),
1753
+ value: format.rate(overview.publishRate, "/s")
1754
+ }),
1755
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Stat, {
1756
+ label: t("stats.deliverRate"),
1757
+ value: format.rate(overview.deliverRate, "/s")
1758
+ })
1759
+ ]
1760
+ }),
1761
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", {
1762
+ className: "rmq:text-sm rmq:font-semibold rmq:text-default-700",
1763
+ children: t("stats.nodes")
1764
+ }),
1765
+ data.nodes.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyState, { message: t("stats.noNodes") }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Table, {
1766
+ "data-cy": "rabbitmq-stats-nodes-table",
1767
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableScrollContainer, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableContent, {
1768
+ "aria-label": t("stats.nodes"),
1769
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableHeader, { children: [
1770
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn, {
1771
+ isRowHeader: true,
1772
+ children: t("stats.nodeName")
1773
+ }),
1774
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn, { children: t("stats.running") }),
1775
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn, { children: t("stats.memory") }),
1776
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn, { children: t("stats.disk") }),
1777
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn, { children: t("stats.fileDescriptors") }),
1778
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn, { children: t("stats.sockets") }),
1779
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn, { children: t("stats.uptime") })
1780
+ ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableBody, {
1781
+ items: data.nodes,
1782
+ children: (node) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableRow, {
1783
+ id: node.name,
1784
+ children: [
1785
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
1786
+ className: "rmq:font-medium",
1787
+ children: node.name
1788
+ }),
1789
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, { children: node.running === null ? "—" : node.running ? t("common.yes") : t("common.no") }),
1790
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Alarm, {
1791
+ alarm: node.memAlarm,
1792
+ children: [
1793
+ format.bytes(node.memUsed),
1794
+ " / ",
1795
+ format.bytes(node.memLimit)
1796
+ ]
1797
+ }) }),
1798
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Alarm, {
1799
+ alarm: node.diskFreeAlarm,
1800
+ children: [
1801
+ format.bytes(node.diskFree),
1802
+ " / ",
1803
+ format.bytes(node.diskFreeLimit)
1804
+ ]
1805
+ }) }),
1806
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, { children: ratio(node.fdUsed, node.fdTotal) }),
1807
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, { children: ratio(node.socketsUsed, node.socketsTotal) }),
1808
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
1809
+ className: "rmq:whitespace-nowrap",
1810
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Duration, { ms: node.uptime })
1811
+ })
1812
+ ]
1813
+ }, node.name)
1814
+ })]
1815
+ }) })
1816
+ }),
1817
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", {
1818
+ className: "rmq:text-sm rmq:font-semibold rmq:text-default-700",
1819
+ children: t("stats.queueList")
1820
+ }),
1821
+ data.queues.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyState, { message: t("stats.noQueues") }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Table, {
1822
+ "data-cy": "rabbitmq-stats-queues-table",
1823
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableScrollContainer, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableContent, {
1824
+ "aria-label": t("stats.queueList"),
1825
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableHeader, { children: [
1826
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn, {
1827
+ isRowHeader: true,
1828
+ children: t("stats.queueName")
1829
+ }),
1830
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn, { children: t("stats.vhost") }),
1831
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn, { children: t("stats.type") }),
1832
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn, { children: t("stats.ready") }),
1833
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn, { children: t("stats.unacked") }),
1834
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn, { children: t("stats.consumers") }),
1835
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableColumn, { children: t("common.state") })
1836
+ ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableBody, {
1837
+ items: data.queues,
1838
+ children: (queue) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TableRow, {
1839
+ id: JSON.stringify([queue.vhost, queue.name]),
1840
+ children: [
1841
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, {
1842
+ className: "rmq:font-medium",
1843
+ children: queue.name
1844
+ }),
1845
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, { children: queue.vhost }),
1846
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, { children: queue.type ?? "—" }),
1847
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, { children: format.number(queue.messagesReady) }),
1848
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, { children: format.number(queue.messagesUnacknowledged) }),
1849
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, { children: format.number(queue.consumers) }),
1850
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TableCell, { children: queue.state ?? "—" })
1851
+ ]
1852
+ }, JSON.stringify([queue.vhost, queue.name]))
1853
+ })]
1854
+ }) })
1855
+ }),
1856
+ data.totalQueues > data.queues.length && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert, {
1857
+ status: "warning",
1858
+ children: t("stats.queuesTruncated", {
1859
+ shown: format.number(data.queues.length),
1860
+ total: format.number(data.totalQueues)
1861
+ })
1862
+ })
1863
+ ] })
1864
+ ]
1865
+ })]
1866
+ });
1867
+ }
1868
+ // frontend/src/capabilities.ts
1869
+ var { useEffect, useState } = await importShared("react");
1870
+ var api = createPluginApiClient("/api/rabbitmq/capabilities");
1871
+ function useCapabilities(enabled = true) {
1872
+ const [capabilities, setCapabilities] = useState({ canManage: false });
1873
+ useEffect(() => {
1874
+ if (!enabled) return void 0;
1875
+ let active = true;
1876
+ api.request("").then((result) => {
1877
+ if (active) setCapabilities({ canManage: result?.canManage === true });
1878
+ }).catch(() => void 0);
1879
+ return () => {
1880
+ active = false;
1881
+ };
1882
+ }, [enabled]);
1883
+ return capabilities;
1884
+ }
1885
+ // frontend/src/plugin.tsx
1886
+ var MQTT_SERVER_DETAIL_SLOT = "mqtt.server.detail";
1887
+ var MQTT_SERVER_LIST_ROW_SLOT = "mqtt.server.list.row";
1888
+ function RabbitmqDataPanels({ mqttServerId, canManage }) {
1889
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqConnectionsPanel, {
1890
+ mqttServerId,
1891
+ canManage
1892
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqStatsPanel, { mqttServerId })] });
1893
+ }
1894
+ function RabbitmqDetailSlot({ mqttServerId }) {
1895
+ return useCanViewBroker() ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqDetailPanels, { mqttServerId }) : null;
1896
+ }
1897
+ function RabbitmqDetailPanels({ mqttServerId }) {
1898
+ const { result } = useDetection(mqttServerId);
1899
+ const { canManage } = useCapabilities(result?.isRabbitMQ === true);
1900
+ if (!result?.isRabbitMQ) return null;
1901
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1902
+ className: "rmq:flex rmq:flex-col rmq:gap-4 rmq:w-full",
1903
+ children: [
1904
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqStatusPanel, { mqttServerId }),
1905
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqUserPanel, {
1906
+ mqttServerId,
1907
+ canManage
1908
+ }),
1909
+ result.authOk && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqDataPanels, {
1910
+ mqttServerId,
1911
+ canManage
1912
+ })
1913
+ ]
1914
+ }, mqttServerId);
1915
+ }
1916
+ var RabbitmqPlugin = class {
1917
+ getPluginName() {
1918
+ return "rabbitmq-plugin@0.2.0";
1919
+ }
1920
+ getDependencies() {
1921
+ return [];
1922
+ }
1923
+ init(_store) {}
1924
+ activate() {}
1925
+ deactivate() {}
1926
+ onApiAuthStateChange(authData) {
1927
+ setRabbitmqAuthData(authData);
1928
+ }
1929
+ onApiEndpointChange(_endpoint) {}
1930
+ getSlotContributions() {
1931
+ return [{
1932
+ slotId: MQTT_SERVER_DETAIL_SLOT,
1933
+ key: "rabbitmq-mqtt-detail",
1934
+ render: (context) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqDetailSlot, { mqttServerId: context.mqttServerId })
1935
+ }, {
1936
+ slotId: MQTT_SERVER_LIST_ROW_SLOT,
1937
+ key: "rabbitmq-mqtt-list-row",
1938
+ render: (context) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RabbitmqListBadge, { mqttServerId: context.mqttServerId })
1939
+ }];
1940
+ }
1941
+ };
1942
+ export { RabbitmqDetailSlot, RabbitmqPlugin as default };