@attraccess/plugin-matter 0.3.0-alpha.0 → 0.4.0-nightly.1161.1

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.
@@ -1,783 +0,0 @@
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
- var en_default = {
5
- page: {
6
- "title": "Matter",
7
- "subtitle": "Connection to the Matter sidecar.",
8
- "insecure": "Insecure connection",
9
- "insecureText": "The sidecar is reached over plain http on a non-loopback address. The token travels unencrypted. Use https, or keep the sidecar on the same host."
10
- },
11
- status: {
12
- "title": "Connection status",
13
- "state": {
14
- "not_configured": "Not configured",
15
- "connecting": "Connecting",
16
- "connected": "Connected",
17
- "degraded": "Degraded"
18
- },
19
- "reason": {
20
- "unavailable": "Unavailable",
21
- "unauthorized": "Unauthorized",
22
- "incompatible": "Incompatible",
23
- "misconfigured": "Misconfigured"
24
- },
25
- "since": "Since",
26
- "lastError": "Last error",
27
- "correlationId": "Correlation ID",
28
- "nextRetry": "Next attempt",
29
- "sidecarVersion": "Sidecar",
30
- "matterJsVersion": "matter.js",
31
- "wireVersion": "Wire version",
32
- "received": "Received",
33
- "supported": "Supported combination",
34
- "combination": "Attraccess {{attraccess}}, plugin {{plugin}}, sidecar {{sidecar}}, matter.js {{matterJs}}",
35
- "loadError": "The status could not be loaded."
36
- },
37
- hint: {
38
- "not_configured": "Enter the sidecar URL and token below to connect.",
39
- "connecting": "Connecting to the Matter sidecar…",
40
- "connected": "The plugin is connected to the Matter sidecar.",
41
- "unavailable": "The sidecar cannot be reached. Check that it is running and that the URL, port and firewall are correct. Attraccess retries automatically.",
42
- "unauthorized": "The sidecar rejected the token. Check the token (also after a rotation) and enter it again.",
43
- "incompatible": "The versions do not match. Upgrade or downgrade Attraccess, the Matter plugin or the sidecar to the supported combination shown below.",
44
- "misconfigured": "The URL, the CA certificate or the TLS setup is invalid. Check the URL and path prefix, and that the CA matches the sidecar certificate.",
45
- "hostVersion": "This Attraccess version does not report its version. Upgrade Attraccess to {{attraccess}} or newer."
46
- },
47
- form: {
48
- "title": "Connection settings",
49
- "url": "Sidecar URL",
50
- "urlPlaceholder": "http://127.0.0.1:8581",
51
- "urlDescription": "Use https for anything but the same host. A path prefix for a reverse proxy is allowed.",
52
- "credential": "Token",
53
- "credentialDescription": "The shared service token configured on the sidecar. It is never shown again after saving.",
54
- "credentialConfigured": "Configured (last changed {{time}})",
55
- "replace": "Replace",
56
- "cancelReplace": "Keep current token",
57
- "ca": "CA certificate (optional)",
58
- "caDescription": "PEM certificate(s) of a private CA. They are trusted in addition to Node.js's default root certificates, not instead of them.",
59
- "caClear": "Clear CA certificate",
60
- "caCleared": "The CA certificate will be removed when you save.",
61
- "save": "Save",
62
- "remove": "Remove configuration",
63
- "saved": "Saved",
64
- "savedText": "The connection settings were saved. The plugin reconnects now.",
65
- "saveError": "Saving failed",
66
- "removeTitle": "Remove the Matter connection?",
67
- "removeText": "The URL and token are deleted and the plugin disconnects from the sidecar.",
68
- "removeConfirm": "Remove",
69
- "removeError": "Removing failed",
70
- "loadError": "The connection settings could not be loaded."
71
- }
72
- };
73
- var de_default = {
74
- page: {
75
- "title": "Matter",
76
- "subtitle": "Verbindung zum Matter-Sidecar.",
77
- "insecure": "Unsichere Verbindung",
78
- "insecureText": "Der Sidecar wird über unverschlüsseltes http an einer Nicht-Loopback-Adresse erreicht. Das Token wird unverschlüsselt übertragen. Verwende https oder betreibe den Sidecar auf demselben Host."
79
- },
80
- status: {
81
- "title": "Verbindungsstatus",
82
- "state": {
83
- "not_configured": "Nicht konfiguriert",
84
- "connecting": "Verbindung wird aufgebaut",
85
- "connected": "Verbunden",
86
- "degraded": "Eingeschränkt"
87
- },
88
- "reason": {
89
- "unavailable": "Nicht erreichbar",
90
- "unauthorized": "Nicht autorisiert",
91
- "incompatible": "Inkompatibel",
92
- "misconfigured": "Falsch konfiguriert"
93
- },
94
- "since": "Seit",
95
- "lastError": "Letzter Fehler",
96
- "correlationId": "Korrelations-ID",
97
- "nextRetry": "Nächster Versuch",
98
- "sidecarVersion": "Sidecar",
99
- "matterJsVersion": "matter.js",
100
- "wireVersion": "Wire-Version",
101
- "received": "Empfangen",
102
- "supported": "Unterstützte Kombination",
103
- "combination": "Attraccess {{attraccess}}, Plugin {{plugin}}, Sidecar {{sidecar}}, matter.js {{matterJs}}",
104
- "loadError": "Der Status konnte nicht geladen werden."
105
- },
106
- hint: {
107
- "not_configured": "Gib unten die Sidecar-URL und das Token ein, um die Verbindung herzustellen.",
108
- "connecting": "Verbindung zum Matter-Sidecar wird aufgebaut…",
109
- "connected": "Das Plugin ist mit dem Matter-Sidecar verbunden.",
110
- "unavailable": "Der Sidecar ist nicht erreichbar. Prüfe, ob er läuft und ob URL, Port und Firewall stimmen. Attraccess versucht es automatisch erneut.",
111
- "unauthorized": "Der Sidecar hat das Token abgelehnt. Prüfe das Token (auch nach einer Rotation) und gib es erneut ein.",
112
- "incompatible": "Die Versionen passen nicht zusammen. Bringe Attraccess, das Matter-Plugin oder den Sidecar per Update oder Downgrade auf die unten gezeigte unterstützte Kombination.",
113
- "misconfigured": "URL, CA-Zertifikat oder TLS-Einrichtung sind ungültig. Prüfe URL und Pfadpräfix sowie, ob die CA zum Sidecar-Zertifikat passt.",
114
- "hostVersion": "Diese Attraccess-Version meldet ihre Version nicht. Aktualisiere Attraccess auf {{attraccess}} oder neuer."
115
- },
116
- form: {
117
- "title": "Verbindungseinstellungen",
118
- "url": "Sidecar-URL",
119
- "urlPlaceholder": "http://127.0.0.1:8581",
120
- "urlDescription": "Verwende https, außer der Sidecar läuft auf demselben Host. Ein Pfadpräfix für einen Reverse-Proxy ist erlaubt.",
121
- "credential": "Token",
122
- "credentialDescription": "Das gemeinsame Service-Token, das am Sidecar konfiguriert ist. Nach dem Speichern wird es nie wieder angezeigt.",
123
- "credentialConfigured": "Konfiguriert (zuletzt geändert {{time}})",
124
- "replace": "Ersetzen",
125
- "cancelReplace": "Aktuelles Token behalten",
126
- "ca": "CA-Zertifikat (optional)",
127
- "caDescription": "PEM-Zertifikat(e) einer privaten CA. Node.js vertraut ihnen zusätzlich zu seinen Standard-Stammzertifikaten, nicht an deren Stelle.",
128
- "caClear": "CA-Zertifikat löschen",
129
- "caCleared": "Das CA-Zertifikat wird beim Speichern entfernt.",
130
- "save": "Speichern",
131
- "remove": "Konfiguration entfernen",
132
- "saved": "Gespeichert",
133
- "savedText": "Die Verbindungseinstellungen wurden gespeichert. Das Plugin verbindet sich jetzt neu.",
134
- "saveError": "Speichern fehlgeschlagen",
135
- "removeTitle": "Matter-Verbindung entfernen?",
136
- "removeText": "URL und Token werden gelöscht und das Plugin trennt die Verbindung zum Sidecar.",
137
- "removeConfirm": "Entfernen",
138
- "removeError": "Entfernen fehlgeschlagen",
139
- "loadError": "Die Verbindungseinstellungen konnten nicht geladen werden."
140
- }
141
- };
142
- //#endregion
143
- //#region frontend/src/i18n.ts
144
- var { useTranslations } = await importShared("@attraccess/plugins-frontend-ui");
145
- var useMatterTranslations = () => useTranslations({
146
- en: en_default,
147
- de: de_default
148
- }, { escapeValues: false });
149
- //#endregion
150
- //#region ../../../node_modules/.pnpm/react@19.2.8/node_modules/react/cjs/react-jsx-runtime.production.js
151
- /**
152
- * @license React
153
- * react-jsx-runtime.production.js
154
- *
155
- * Copyright (c) Meta Platforms, Inc. and affiliates.
156
- *
157
- * This source code is licensed under the MIT license found in the
158
- * LICENSE file in the root directory of this source tree.
159
- */
160
- var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((exports) => {
161
- var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element");
162
- var REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
163
- function jsxProd(type, config, maybeKey) {
164
- var key = null;
165
- void 0 !== maybeKey && (key = "" + maybeKey);
166
- void 0 !== config.key && (key = "" + config.key);
167
- if ("key" in config) {
168
- maybeKey = {};
169
- for (var propName in config) "key" !== propName && (maybeKey[propName] = config[propName]);
170
- } else maybeKey = config;
171
- config = maybeKey.ref;
172
- return {
173
- $$typeof: REACT_ELEMENT_TYPE,
174
- type,
175
- key,
176
- ref: void 0 !== config ? config : null,
177
- props: maybeKey
178
- };
179
- }
180
- exports.Fragment = REACT_FRAGMENT_TYPE;
181
- exports.jsx = jsxProd;
182
- exports.jsxs = jsxProd;
183
- }));
184
- //#endregion
185
- //#region frontend/src/SettingsForm.tsx
186
- var import_jsx_runtime = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
187
- module.exports = require_react_jsx_runtime_production();
188
- })))();
189
- var { Button, PasswordInput, StatusDialog, useDateTimeFormatter: useDateTimeFormatter$1 } = await importShared("@attraccess/plugins-frontend-ui");
190
- var { Description, Form, Input, Label, TextArea, TextField } = await importShared("@heroui/react");
191
- var { useState: useState$1 } = await importShared("react");
192
- var messageOf$1 = (error) => error instanceof Error ? error.message : String(error);
193
- /**
194
- * The token is write-only: once saved, the form only shows that one is configured and offers to replace it. The
195
- * backend never sends it back.
196
- */
197
- function SettingsForm({ settings, onSave, onRemove }) {
198
- const { t } = useMatterTranslations();
199
- const formatDateTime = useDateTimeFormatter$1({});
200
- const [url, setUrl] = useState$1(settings.url ?? "");
201
- const [replacing, setReplacing] = useState$1(!settings.credentialConfigured);
202
- const [credential, setCredential] = useState$1("");
203
- const [ca, setCa] = useState$1(settings.caCertificate ?? "");
204
- const [caCleared, setCaCleared] = useState$1(false);
205
- const [busy, setBusy] = useState$1(false);
206
- const [notice, setNotice] = useState$1(null);
207
- const caChanged = caCleared || ca.trim() !== (settings.caCertificate ?? "").trim();
208
- const canSave = url.trim() !== "" && (!replacing || credential !== "") && !busy;
209
- const submit = async (event) => {
210
- event.preventDefault();
211
- const input = { url: url.trim() };
212
- if (replacing) input.credential = credential;
213
- if (caChanged) input.caCertificate = ca.trim() === "" || caCleared ? null : ca.trim();
214
- setBusy(true);
215
- try {
216
- const saved = await onSave(input);
217
- setUrl(saved.url ?? "");
218
- setCa(saved.caCertificate ?? "");
219
- setCaCleared(false);
220
- setCredential("");
221
- setReplacing(!saved.credentialConfigured);
222
- setNotice({ kind: "saved" });
223
- } catch (error) {
224
- setNotice({
225
- kind: "error",
226
- title: t("form.saveError"),
227
- message: messageOf$1(error)
228
- });
229
- } finally {
230
- setBusy(false);
231
- }
232
- };
233
- const remove = async () => {
234
- setBusy(true);
235
- try {
236
- await onRemove();
237
- setUrl("");
238
- setCa("");
239
- setCaCleared(false);
240
- setCredential("");
241
- setReplacing(true);
242
- setNotice(null);
243
- } catch (error) {
244
- setNotice({
245
- kind: "error",
246
- title: t("form.removeError"),
247
- message: messageOf$1(error)
248
- });
249
- } finally {
250
- setBusy(false);
251
- }
252
- };
253
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
254
- className: "mt:flex mt:flex-col mt:gap-4",
255
- "data-cy": "matter-settings",
256
- children: [
257
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", {
258
- className: "mt:text-lg mt:font-semibold",
259
- children: t("form.title")
260
- }),
261
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Form, {
262
- onSubmit: submit,
263
- className: "mt:flex mt:flex-col mt:gap-4",
264
- children: [
265
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TextField, {
266
- value: url,
267
- onChange: setUrl,
268
- className: "mt:w-full",
269
- isRequired: true,
270
- children: [
271
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Label, { children: t("form.url") }),
272
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Input, {
273
- placeholder: t("form.urlPlaceholder"),
274
- autoComplete: "off",
275
- "data-cy": "matter-url-input"
276
- }),
277
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Description, { children: t("form.urlDescription") })
278
- ]
279
- }),
280
- replacing ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
281
- className: "mt:flex mt:flex-col mt:gap-2",
282
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(PasswordInput, {
283
- label: t("form.credential"),
284
- description: t("form.credentialDescription"),
285
- autoComplete: "new-password",
286
- value: credential,
287
- onValueChange: setCredential,
288
- "data-cy": "matter-credential-input"
289
- }), settings.credentialConfigured && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
290
- variant: "tertiary",
291
- onPress: () => setReplacing(false),
292
- "data-cy": "matter-keep-credential",
293
- children: t("form.cancelReplace")
294
- })]
295
- }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
296
- className: "mt:flex mt:flex-wrap mt:items-center mt:justify-between mt:gap-2",
297
- "data-cy": "matter-credential-configured",
298
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
299
- t("form.credential"),
300
- ":",
301
- " ",
302
- t("form.credentialConfigured", { time: formatDateTime(settings.credentialUpdatedAt) })
303
- ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
304
- variant: "secondary",
305
- onPress: () => setReplacing(true),
306
- "data-cy": "matter-replace-credential",
307
- children: t("form.replace")
308
- })]
309
- }),
310
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TextField, {
311
- value: caCleared ? "" : ca,
312
- onChange: setCa,
313
- isDisabled: caCleared,
314
- className: "mt:w-full",
315
- children: [
316
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Label, { children: t("form.ca") }),
317
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TextArea, {
318
- rows: 5,
319
- spellCheck: false,
320
- "data-cy": "matter-ca-input"
321
- }),
322
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Description, { children: caCleared ? t("form.caCleared") : t("form.caDescription") })
323
- ]
324
- }),
325
- settings.caCertificate && !caCleared && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
326
- variant: "tertiary",
327
- onPress: () => setCaCleared(true),
328
- "data-cy": "matter-clear-ca",
329
- children: t("form.caClear")
330
- }),
331
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
332
- className: "mt:flex mt:flex-wrap mt:gap-2",
333
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
334
- type: "submit",
335
- isDisabled: !canSave,
336
- isPending: busy,
337
- "data-cy": "matter-save",
338
- children: t("form.save")
339
- }), settings.url !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
340
- variant: "danger-soft",
341
- isDisabled: busy,
342
- onPress: () => setNotice({ kind: "remove" }),
343
- "data-cy": "matter-remove",
344
- children: t("form.remove")
345
- })]
346
- })
347
- ]
348
- }) }),
349
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusDialog, {
350
- isOpen: notice?.kind === "saved",
351
- status: "success",
352
- title: t("form.saved"),
353
- onClose: () => setNotice(null),
354
- "data-cy": "matter-saved-dialog",
355
- children: t("form.savedText")
356
- }),
357
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusDialog, {
358
- isOpen: notice?.kind === "error",
359
- status: "error",
360
- title: notice?.kind === "error" ? notice.title : "",
361
- onClose: () => setNotice(null),
362
- "data-cy": "matter-error-dialog",
363
- children: notice?.kind === "error" ? notice.message : ""
364
- }),
365
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusDialog, {
366
- isOpen: notice?.kind === "remove",
367
- status: "warning",
368
- title: t("form.removeTitle"),
369
- onClose: () => setNotice(null),
370
- action: {
371
- label: t("form.removeConfirm"),
372
- isPending: busy,
373
- onPress: async () => {
374
- setNotice(null);
375
- await remove();
376
- }
377
- },
378
- "data-cy": "matter-remove-dialog",
379
- children: t("form.removeText")
380
- })
381
- ]
382
- });
383
- }
384
- //#endregion
385
- //#region frontend/src/StatusCard.tsx
386
- var { StatusAlert: StatusAlert$1, useDateTimeFormatter } = await importShared("@attraccess/plugins-frontend-ui");
387
- var { Card, Chip } = await importShared("@heroui/react");
388
- var STATE_COLOR = {
389
- not_configured: "default",
390
- connecting: "accent",
391
- connected: "success",
392
- degraded: "warning"
393
- };
394
- /** `unavailable` usually heals by itself; the other reasons need the administrator. */
395
- var REASON_COLOR = {
396
- unavailable: "warning",
397
- unauthorized: "danger",
398
- incompatible: "danger",
399
- misconfigured: "danger"
400
- };
401
- function Field({ label, children, dataCy }) {
402
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
403
- className: "mt:flex mt:flex-col",
404
- "data-cy": dataCy,
405
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", {
406
- className: "mt:text-xs mt:text-muted",
407
- children: label
408
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", {
409
- className: "mt:break-words",
410
- children
411
- })]
412
- });
413
- }
414
- /** What the administrator can do about the current state. */
415
- function hintKey(status) {
416
- if (status.state !== "degraded") return `hint.${status.state}`;
417
- if (status.reasonDetail === "host version unavailable") return "hint.hostVersion";
418
- return `hint.${status.reason ?? "unavailable"}`;
419
- }
420
- /** The lowest Attraccess version of the first supported combination, e.g. `1.11.0` for `^1.11.0`. */
421
- function minimumAttraccess(status) {
422
- const range = status.supported[0]?.attraccess ?? "";
423
- return range.match(/\d+\.\d+\.\d+/)?.[0] ?? range;
424
- }
425
- function Combination({ entry }) {
426
- const { t } = useMatterTranslations();
427
- const value = (key) => String(entry[key] ?? "?");
428
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: t("status.combination", {
429
- attraccess: value("attraccess"),
430
- plugin: value("plugin"),
431
- sidecar: value("sidecar"),
432
- matterJs: value("matterJs")
433
- }) });
434
- }
435
- function StatusCard({ status }) {
436
- const { t } = useMatterTranslations();
437
- const formatDateTime = useDateTimeFormatter({ showSeconds: true });
438
- const error = status.lastError;
439
- const received = error?.details?.received;
440
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card, {
441
- "data-cy": "matter-status-card",
442
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Card.Header, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Card.Title, { children: t("status.title") }) }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card.Content, {
443
- className: "mt:flex mt:flex-col mt:gap-4",
444
- children: [
445
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
446
- className: "mt:flex mt:flex-wrap mt:items-center mt:gap-2",
447
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Chip, {
448
- color: STATE_COLOR[status.state],
449
- variant: "soft",
450
- "data-cy": "matter-state-chip",
451
- children: t(`status.state.${status.state}`)
452
- }), status.reason && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Chip, {
453
- color: REASON_COLOR[status.reason],
454
- variant: "soft",
455
- "data-cy": "matter-reason-chip",
456
- children: t(`status.reason.${status.reason}`)
457
- })]
458
- }),
459
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
460
- "data-cy": "matter-hint",
461
- children: t(hintKey(status), { attraccess: minimumAttraccess(status) })
462
- }),
463
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("dl", {
464
- className: "mt:grid mt:grid-cols-1 mt:gap-3 mt:sm:grid-cols-2",
465
- children: [
466
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, {
467
- label: t("status.since"),
468
- children: formatDateTime(status.since)
469
- }),
470
- status.nextRetryAt && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, {
471
- label: t("status.nextRetry"),
472
- dataCy: "matter-next-retry",
473
- children: formatDateTime(status.nextRetryAt)
474
- }),
475
- status.sidecar && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, {
476
- label: t("status.sidecarVersion"),
477
- children: status.sidecar.sidecar
478
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, {
479
- label: t("status.matterJsVersion"),
480
- children: status.sidecar.matterJs
481
- })] }),
482
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, {
483
- label: t("status.wireVersion"),
484
- children: status.wireVersion
485
- })
486
- ]
487
- }),
488
- error && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(StatusAlert$1, {
489
- status: "warning",
490
- title: t("status.lastError"),
491
- "data-cy": "matter-last-error",
492
- children: [error.message, error.correlationId && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
493
- className: "mt:block mt:text-xs",
494
- children: [
495
- t("status.correlationId"),
496
- ": ",
497
- error.correlationId
498
- ]
499
- })]
500
- }),
501
- status.reason === "incompatible" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
502
- "data-cy": "matter-compatibility",
503
- children: [
504
- received && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
505
- className: "mt:font-medium",
506
- children: t("status.received")
507
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
508
- className: "mt:list-disc mt:pl-5",
509
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Combination, { entry: received })
510
- })] }),
511
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
512
- className: "mt:font-medium",
513
- children: t("status.supported")
514
- }),
515
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
516
- className: "mt:list-disc mt:pl-5",
517
- children: status.supported.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Combination, { entry }, `${entry.plugin}-${entry.sidecar}`))
518
- })
519
- ]
520
- })
521
- ]
522
- })]
523
- });
524
- }
525
- //#endregion
526
- //#region ../../../libs/plugins-frontend-sdk/src/lib/frontend.api-client.ts
527
- var BASE_URL_GLOBAL = "__ATTRACCESS_API_BASE_URL__";
528
- /** The API origin the host is talking to. Falls back to the current origin. */
529
- function getApiBaseUrl() {
530
- return window[BASE_URL_GLOBAL] ?? window.location.origin;
531
- }
532
- /** Thrown for any non-2xx response, carrying the status for callers that branch on it. */
533
- var PluginApiError = class extends Error {
534
- constructor(message, status) {
535
- super(message);
536
- this.status = status;
537
- this.name = "PluginApiError";
538
- }
539
- };
540
- async function toError(res) {
541
- try {
542
- const body = await res.json();
543
- const message = Array.isArray(body.message) ? body.message.join(", ") : body.message;
544
- if (message) return new PluginApiError(message, res.status);
545
- } catch {}
546
- return new PluginApiError(`Request failed (HTTP ${res.status}).`, res.status);
547
- }
548
- /**
549
- * Creates a client bound to `basePath`, which is resolved against the host's
550
- * API origin. Plugin routes are mounted under `/api/<plugin-name>`, so that is
551
- * the usual argument; pass nothing to address the host API directly.
552
- */
553
- function createPluginApiClient(basePath = "") {
554
- const url = (path, query) => {
555
- const target = new URL(`${basePath}${path}`, getApiBaseUrl());
556
- Object.entries(query ?? {}).forEach(([key, value]) => {
557
- if (value !== void 0 && value !== null) target.searchParams.set(key, String(value));
558
- });
559
- return target.toString();
560
- };
561
- const doFetch = (path, init) => fetch(url(path), {
562
- credentials: "include",
563
- ...init
564
- });
565
- return {
566
- url,
567
- fetch: doFetch,
568
- async request(path, options = {}) {
569
- const { body, query, headers, ...init } = options;
570
- const res = await fetch(url(path, query), {
571
- credentials: "include",
572
- ...init,
573
- headers: body === void 0 ? headers : {
574
- "Content-Type": "application/json",
575
- ...headers
576
- },
577
- body: body === void 0 ? void 0 : JSON.stringify(body)
578
- });
579
- if (!res.ok) throw await toError(res);
580
- const text = await res.text();
581
- return text.length > 0 ? JSON.parse(text) : null;
582
- }
583
- };
584
- }
585
- //#endregion
586
- //#region ../../../libs/plugins-frontend-sdk/src/lib/frontend.live-updates.tsx
587
- var { createContext, useCallback: useCallback$1, useContext, useEffect: useEffect$1, useRef: useRef$1 } = await importShared("react");
588
- var contextKey = Symbol.for("attraccess.plugin.live-updates.context");
589
- var contexts = globalThis;
590
- contexts[contextKey] ??= createContext(null);
591
- var identityKey = Symbol.for("attraccess.plugin.live-updates.identity");
592
- var identities = globalThis;
593
- identities[identityKey] ??= createContext(null);
594
- //#endregion
595
- //#region ../../../libs/plugins-frontend-sdk/src/lib/frontend.standard-drawer.tsx
596
- var { StandardDrawer: SharedStandardDrawer } = await importShared("@attraccess/plugins-frontend-ui");
597
- //#endregion
598
- //#region ../../../libs/plugins-frontend-sdk/src/lib/frontend.standard-modal.tsx
599
- var { StandardModal: SharedStandardModal } = await importShared("@attraccess/plugins-frontend-ui");
600
- //#endregion
601
- //#region frontend/src/api.ts
602
- var api = createPluginApiClient("/api/matter/connection");
603
- var getSettings = () => api.request("");
604
- var getStatus = () => api.request("/status");
605
- var saveSettings = (input) => api.request("", {
606
- method: "PUT",
607
- body: input
608
- });
609
- var removeSettings = () => api.request("", { method: "DELETE" });
610
- //#endregion
611
- //#region frontend/src/useMatterPage.ts
612
- var { useCallback, useEffect, useRef, useState } = await importShared("react");
613
- /** How often the open page refreshes the connection status. */
614
- var STATUS_POLL_MS = 5e3;
615
- /** A request still pending after this long counts as failed, so one hung request cannot stop the polling. */
616
- var REQUEST_TIMEOUT_MS = 2 * STATUS_POLL_MS;
617
- var messageOf = (error) => error instanceof Error ? error.message : String(error);
618
- function withTimeout(request) {
619
- return new Promise((resolve, reject) => {
620
- const timer = setTimeout(() => reject(/* @__PURE__ */ new Error("The request timed out.")), REQUEST_TIMEOUT_MS);
621
- request.then(resolve, reject).finally(() => clearTimeout(timer));
622
- });
623
- }
624
- /**
625
- * Loads the settings and polls the status while the page is open. Saving and removing refresh both. If the first
626
- * settings load failed (API briefly down), the poll retries it so the form appears without a manual reload.
627
- *
628
- * A poll tick is skipped while an earlier request is still pending, so a hanging API does not pile up requests, and
629
- * only the newest status request may update the page, so a late answer never overwrites a newer one.
630
- */
631
- function useMatterPage() {
632
- const [settings, setSettings] = useState(null);
633
- const [status, setStatus] = useState(null);
634
- const [statusError, setStatusError] = useState(null);
635
- const [settingsError, setSettingsError] = useState(null);
636
- const [loading, setLoading] = useState(true);
637
- const mounted = useRef(true);
638
- const settingsLoaded = useRef(false);
639
- const statusSeq = useRef(0);
640
- const statusPending = useRef(0);
641
- const settingsPending = useRef(false);
642
- const refreshStatus = useCallback(async () => {
643
- const seq = ++statusSeq.current;
644
- statusPending.current += 1;
645
- try {
646
- const next = await withTimeout(getStatus());
647
- if (!mounted.current || seq !== statusSeq.current) return;
648
- setStatus(next);
649
- setStatusError(null);
650
- } catch (error) {
651
- if (mounted.current && seq === statusSeq.current) setStatusError(messageOf(error));
652
- } finally {
653
- statusPending.current -= 1;
654
- }
655
- }, []);
656
- const refreshSettings = useCallback(async () => {
657
- settingsPending.current = true;
658
- try {
659
- const next = await withTimeout(getSettings());
660
- if (!mounted.current) return;
661
- settingsLoaded.current = true;
662
- setSettings(next);
663
- setSettingsError(null);
664
- } catch (error) {
665
- if (mounted.current) setSettingsError(messageOf(error));
666
- } finally {
667
- settingsPending.current = false;
668
- }
669
- }, []);
670
- useEffect(() => {
671
- mounted.current = true;
672
- Promise.all([refreshSettings(), refreshStatus()]).finally(() => mounted.current && setLoading(false));
673
- const timer = setInterval(() => {
674
- if (statusPending.current === 0) refreshStatus();
675
- if (!settingsLoaded.current && !settingsPending.current) refreshSettings();
676
- }, STATUS_POLL_MS);
677
- return () => {
678
- mounted.current = false;
679
- clearInterval(timer);
680
- };
681
- }, [refreshSettings, refreshStatus]);
682
- return {
683
- settings,
684
- settingsError,
685
- status,
686
- statusError,
687
- loading,
688
- save: useCallback(async (input) => {
689
- const saved = await saveSettings(input);
690
- if (mounted.current) {
691
- settingsLoaded.current = true;
692
- setSettings(saved);
693
- }
694
- await refreshStatus();
695
- return saved;
696
- }, [refreshStatus]),
697
- remove: useCallback(async () => {
698
- await removeSettings();
699
- await Promise.all([refreshSettings(), refreshStatus()]);
700
- }, [refreshSettings, refreshStatus])
701
- };
702
- }
703
- //#endregion
704
- //#region frontend/src/MatterPage.tsx
705
- var { PageHeader, StatusAlert } = await importShared("@attraccess/plugins-frontend-ui");
706
- var { Spinner } = await importShared("@heroui/react");
707
- var { CableIcon: CableIcon$1 } = await importShared("lucide-react");
708
- function MatterPage() {
709
- const { t } = useMatterTranslations();
710
- const { settings, settingsError, status, statusError, loading, save, remove } = useMatterPage();
711
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
712
- className: "mt:mx-auto mt:flex mt:w-full mt:max-w-5xl mt:flex-col mt:gap-6 mt:p-4 mt:md:p-6",
713
- "data-cy": "matter-page",
714
- children: [
715
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageHeader, {
716
- noMargin: true,
717
- icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CableIcon$1, { className: "mt:h-6 mt:w-6 mt:text-accent-soft-foreground" }),
718
- title: t("page.title"),
719
- subtitle: t("page.subtitle")
720
- }),
721
- loading && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, {}),
722
- status?.insecureTransport && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert, {
723
- status: "warning",
724
- title: t("page.insecure"),
725
- "data-cy": "matter-insecure-warning",
726
- children: t("page.insecureText")
727
- }),
728
- statusError && !status && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert, {
729
- status: "danger",
730
- title: t("status.loadError"),
731
- "data-cy": "matter-load-error",
732
- children: statusError
733
- }),
734
- status && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusCard, { status }),
735
- settingsError && !settings && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusAlert, {
736
- status: "danger",
737
- title: t("form.loadError"),
738
- "data-cy": "matter-settings-load-error",
739
- children: settingsError
740
- }),
741
- settings && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SettingsForm, {
742
- settings,
743
- onSave: save,
744
- onRemove: remove
745
- })
746
- ]
747
- });
748
- }
749
- //#endregion
750
- //#region frontend/src/plugin.tsx
751
- var { CableIcon } = await importShared("lucide-react");
752
- var MatterPlugin = class {
753
- getPluginName() {
754
- return "matter-plugin@0.3.0";
755
- }
756
- getDependencies() {
757
- return [];
758
- }
759
- init(store) {
760
- this.pluginStore = store;
761
- }
762
- activate() {}
763
- deactivate() {}
764
- onApiAuthStateChange(_authData) {}
765
- onApiEndpointChange(_endpoint) {}
766
- getRoutes() {
767
- return [{
768
- path: "/matter",
769
- authRequired: "system.plugins.manage",
770
- element: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MatterPage, {})
771
- }];
772
- }
773
- getSidebarItems() {
774
- return [{
775
- label: "Matter",
776
- path: "/matter",
777
- group: "devices",
778
- icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CableIcon, { className: "mt:w-5 mt:h-5" })
779
- }];
780
- }
781
- };
782
- //#endregion
783
- export { MatterPlugin as default };