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