Add Syncova Ticket with tested Gitea image publishing and persistent Compose deployment
This commit is contained in:
commit
9c561cb574
19
.dockerignore
Normal file
19
.dockerignore
Normal file
@ -0,0 +1,19 @@
|
||||
node_modules
|
||||
dist
|
||||
styled-system
|
||||
data
|
||||
docs
|
||||
.git
|
||||
.env*
|
||||
*.log
|
||||
.codex
|
||||
.gitea
|
||||
.runner
|
||||
.npmrc
|
||||
*.db
|
||||
*.db-*
|
||||
*.sqlite
|
||||
*.sqlite-*
|
||||
*.sqlite3
|
||||
*.sqlite3-*
|
||||
*.key
|
||||
9
.env.docker.example
Normal file
9
.env.docker.example
Normal file
@ -0,0 +1,9 @@
|
||||
SYNCOVA_IMAGE=git.jfritzsche.de/jf/syncova-ticket:latest
|
||||
SYNCOVA_PULL_POLICY=always
|
||||
SYNCOVA_BIND=127.0.0.1
|
||||
SYNCOVA_PORT=3002
|
||||
APP_ORIGIN=http://localhost:3002
|
||||
COOKIE_SECURE=false
|
||||
ADMIN_EMAIL=admin@example.org
|
||||
# Vor dem ersten Start durch ein eigenes langes Passwort ersetzen.
|
||||
ADMIN_PASSWORD=replace-this-with-a-long-unique-password
|
||||
29
.env.example
Normal file
29
.env.example
Normal file
@ -0,0 +1,29 @@
|
||||
# Copy to .env. Never commit the populated file.
|
||||
PORT=3001
|
||||
HOST=127.0.0.1
|
||||
DB_PATH=data/syncova.db
|
||||
MAIL_MODE=development
|
||||
# Queue SMTP credentials are encrypted in SQLite (AES-256-GCM).
|
||||
# Optional: fixed 32-byte key as 64 hex characters from your secret manager.
|
||||
# SMTP_ENCRYPTION_KEY=
|
||||
# Otherwise a server-local key is created here; back it up and restrict file access.
|
||||
# SMTP_KEY_FILE=data/smtp.key
|
||||
# External origin for CSRF validation and notification links (production).
|
||||
# APP_ORIGIN=https://tickets.example.org
|
||||
# NODE_ENV=production
|
||||
# COOKIE_SECURE=true
|
||||
# First production start requires a NEW database and this bootstrap credential.
|
||||
# ADMIN_EMAIL=admin@example.org
|
||||
# ADMIN_PASSWORD=replace-with-a-long-unique-password
|
||||
# MAIL_MODE=smtp
|
||||
# SMTP_HOST=smtp.example.org
|
||||
# SMTP_PORT=465
|
||||
# SMTP_TLS=true
|
||||
# SMTP_USER=tickets@example.org
|
||||
# SMTP_PASSWORD=server-side-secret
|
||||
# Legacy initial values only: prefer per-queue settings in the UI.
|
||||
# These seed a queue's IMAP settings once; later changes use the saved UI configuration.
|
||||
# IMAP_HOST=imap.example.org
|
||||
# IMAP_PORT=993
|
||||
# IMAP_USER=tickets@example.org
|
||||
# IMAP_PASSWORD=server-side-secret
|
||||
5
.gitattributes
vendored
Normal file
5
.gitattributes
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
* text=auto eol=lf
|
||||
*.png binary
|
||||
*.jpg binary
|
||||
*.jpeg binary
|
||||
*.woff2 binary
|
||||
87
.gitea/workflows/ci.yaml
Normal file
87
.gitea/workflows/ci.yaml
Normal file
@ -0,0 +1,87 @@
|
||||
name: Tests und Docker-Image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ['**']
|
||||
tags: ['v*']
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Tests und Frontend-Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Quellcode auschecken
|
||||
uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Node.js 22
|
||||
uses: https://github.com/actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
|
||||
with:
|
||||
node-version: '22'
|
||||
- run: npm ci
|
||||
- run: npm test
|
||||
- run: npm run build
|
||||
|
||||
image:
|
||||
name: Leeres Produktionsimage bauen und veröffentlichen
|
||||
needs: test
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
REGISTRY_IMAGE: git.jfritzsche.de/jf/syncova-ticket
|
||||
COMMIT_SHA: ${{ gitea.sha }}
|
||||
steps:
|
||||
- name: Quellcode auschecken
|
||||
uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Node.js 22 für Image-Prüfung
|
||||
uses: https://github.com/actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
|
||||
with:
|
||||
node-version: '22'
|
||||
- name: Docker Buildx einrichten
|
||||
uses: https://github.com/docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
|
||||
- name: Produktionsimage bauen
|
||||
uses: https://github.com/docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6
|
||||
with:
|
||||
context: .
|
||||
load: true
|
||||
push: false
|
||||
tags: git.jfritzsche.de/jf/syncova-ticket:sha-${{ gitea.sha }}
|
||||
labels: |
|
||||
org.opencontainers.image.source=https://git.jfritzsche.de/jf/syncova-ticket
|
||||
org.opencontainers.image.revision=${{ gitea.sha }}
|
||||
- name: Leere Daten und Produktionsstart prüfen
|
||||
run: npm run test:image
|
||||
env:
|
||||
SYNCOVA_IMAGE: git.jfritzsche.de/jf/syncova-ticket:sha-${{ gitea.sha }}
|
||||
- name: An der Registry anmelden
|
||||
if: gitea.event_name == 'push' && (gitea.ref == 'refs/heads/main' || startsWith(gitea.ref, 'refs/tags/v'))
|
||||
uses: https://github.com/docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
|
||||
with:
|
||||
registry: git.jfritzsche.de
|
||||
username: jf
|
||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||
- name: Geprüftes Image veröffentlichen
|
||||
if: gitea.event_name == 'push' && (gitea.ref == 'refs/heads/main' || startsWith(gitea.ref, 'refs/tags/v'))
|
||||
env:
|
||||
REF: ${{ gitea.ref }}
|
||||
REF_NAME: ${{ gitea.ref_name }}
|
||||
run: |
|
||||
set -eu
|
||||
image="$REGISTRY_IMAGE:sha-$COMMIT_SHA"
|
||||
docker push "$image"
|
||||
if [ "$REF" = 'refs/heads/main' ]; then
|
||||
current_main="$(git ls-remote origin refs/heads/main | cut -f1)"
|
||||
if [ "$current_main" = "$COMMIT_SHA" ]; then
|
||||
docker tag "$image" "$REGISTRY_IMAGE:latest"
|
||||
docker push "$REGISTRY_IMAGE:latest"
|
||||
else
|
||||
echo 'Neuerer main-Commit vorhanden; latest bleibt beim neueren Build.'
|
||||
fi
|
||||
else
|
||||
printf '%s' "$REF_NAME" | grep -Eq '^[a-zA-Z0-9_][a-zA-Z0-9_.-]{0,127}$'
|
||||
docker tag "$image" "$REGISTRY_IMAGE:$REF_NAME"
|
||||
docker push "$REGISTRY_IMAGE:$REF_NAME"
|
||||
fi
|
||||
21
.gitignore
vendored
Normal file
21
.gitignore
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
node_modules/
|
||||
dist/
|
||||
styled-system/
|
||||
data/
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
!.env.docker.example
|
||||
*.log
|
||||
*.db
|
||||
*.db-*
|
||||
*.sqlite
|
||||
*.sqlite-*
|
||||
*.sqlite3
|
||||
*.sqlite3-*
|
||||
*.key
|
||||
.runner
|
||||
.npmrc
|
||||
docs/*.png
|
||||
docs/*.jpg
|
||||
docs/*.jpeg
|
||||
1
.prettierrc.json
Normal file
1
.prettierrc.json
Normal file
@ -0,0 +1 @@
|
||||
{ "singleQuote": true, "semi": false, "printWidth": 100, "trailingComma": "all" }
|
||||
20
Dockerfile
Normal file
20
Dockerfile
Normal file
@ -0,0 +1,20 @@
|
||||
FROM node:22-bookworm-slim AS build
|
||||
WORKDIR /app
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends python3 make g++ ca-certificates && rm -rf /var/lib/apt/lists/*
|
||||
COPY package*.json panda.config.ts tsconfig.json ./
|
||||
COPY src/theme ./src/theme
|
||||
RUN npm ci
|
||||
COPY . .
|
||||
RUN npm test && npm run build && npm prune --omit=dev --ignore-scripts
|
||||
|
||||
FROM node:22-bookworm-slim AS runtime
|
||||
ENV NODE_ENV=production HOST=0.0.0.0 PORT=3001 DB_PATH=/app/data/syncova.db SMTP_KEY_FILE=/app/data/smtp.key
|
||||
WORKDIR /app
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/* && mkdir -p /app/data && chown node:node /app/data
|
||||
COPY --from=build --chown=node:node /app/node_modules ./node_modules
|
||||
COPY --from=build --chown=node:node /app/package.json ./package.json
|
||||
COPY --from=build --chown=node:node /app/server ./server
|
||||
COPY --from=build --chown=node:node /app/dist ./dist
|
||||
USER node
|
||||
EXPOSE 3001
|
||||
CMD ["node", "server/index.js"]
|
||||
21
PARK-UI-LICENSE
Normal file
21
PARK-UI-LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 cschroeter
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
222
README.md
Normal file
222
README.md
Normal file
@ -0,0 +1,222 @@
|
||||
# Syncova Ticket
|
||||
|
||||
Deutschsprachiges Ticketsystem mit React, Park UI, Ark UI, Panda CSS, Express und SQLite. Die Oberfläche und die API sind tatsächlich verbunden; Daten, E-Mail-Aufträge, Termine, Sitzungen und Benachrichtigungen bleiben nach Neustarts erhalten.
|
||||
|
||||
## Schnellstart
|
||||
|
||||
Voraussetzung für neue Installationen: Node.js 22.12 oder neuer und npm (Docker verwendet Node 22). Unter Windows enthält `better-sqlite3` üblicherweise eine passende vorkompilierte Binärdatei; bei anderen Node-Versionen können native Build-Werkzeuge erforderlich sein.
|
||||
|
||||
```powershell
|
||||
npm ci
|
||||
npm run dev
|
||||
```
|
||||
|
||||
Oberfläche: http://127.0.0.1:5173. Backend: http://127.0.0.1:3001.
|
||||
|
||||
Entwicklungsanmeldung: `admin@syncova.local` / `Syncova-Demo-2026!`. Weitere Testbenutzer: `leon@syncova.local` (Bearbeiter, nur Support) und `mira@syncova.local` (Leser, nur Support), gleiches Entwicklungspasswort. Die Demo enthält drei Queues und acht Tickets. Diese Konten und Beispieltickets werden **nur bei der ersten Initialisierung außerhalb des Produktionsmodus** angelegt.
|
||||
|
||||
Die Datenbank liegt in `data/syncova.db`, ist von Git ausgeschlossen und wird nicht bei jedem Start zurückgesetzt. Eine bereits angelegte Entwicklungsdatenbank nicht unverändert produktiv verwenden.
|
||||
|
||||
## Bedienung
|
||||
|
||||
- Übersicht: Suche nach Nummer, Betreff oder Kontakt, Queue-, Status- und Benutzerfilter sowie Sortierung; Detailansicht über den Betreff.
|
||||
- „Manuelles Ticket erstellen“ erfasst Kundenname, E-Mail-Adresse, Betreff und Beschreibung direkt im Produktivbetrieb. Erforderlich sind `view` und `reply` in der gewählten Queue. Die Anfrage wird als manuell erfasst protokolliert, ein wiederholter Speicherversuch mit demselben Schlüssel erzeugt kein zweites Ticket. Es wird keine Kunden-Eingangsbestätigung ausgelöst; Team-Benachrichtigungen folgen den persönlichen Einstellungen.
|
||||
- Antworten: erlaubten Queue-Absender und Signatur wählen. Der Signaturblock wird vor dem Versand angezeigt und separat vom Nachrichtentext verwaltet. Interne Notizen werden niemals in die Versandwarteschlange geschrieben.
|
||||
- Anhänge: „Dateien hinzufügen“ im Antworteditor; maximal 20 Dateien, 10 MiB pro Datei und 20 MiB insgesamt. Dateien werden zusammen mit der Nachricht transaktional gespeichert und beim Versand als MIME-Anhänge angefügt. Eingehende IMAP-Anhänge erscheinen direkt im Nachrichtenverlauf und sind als berechtigungsgeschützter Download verfügbar. Dateiname, Typ und Inhalt bleiben nach Neustarts erhalten. Ein wiederholter Versandauftrag erzeugt keine zusätzlichen Anhänge. Auch eine Antwort nur mit Anhang ist möglich.
|
||||
- HTML-Signaturen: unter **Einstellungen → Queue → Signaturen** Format „HTML“ wählen. HTML-Quelltext, sichere Vorschau, Formatierungen, Tabellen, Links und Logos werden unterstützt. Skripte, Ereignishandler, gefährliche URLs und aktive Inhalte werden entfernt. Die Vorschau läuft isoliert ohne externe Bildabrufe; im versendeten HTML bleiben erlaubte HTTPS-Logos erhalten. Antworten und Eingangsbestätigungen enthalten immer eine Klartextalternative. Die gesendete Signatur wird als unveränderlicher Nachrichtensnapshot gespeichert; spätere Änderungen ändern alte E-Mails nicht.
|
||||
- Queue löschen: **Einstellungen → Queue → Allgemein → Queue löschen**. Exakten Queue-Namen bestätigen. Bei vorhandenen Tickets sind eine berechtigte Zielqueue und gültige Statuszuordnung erforderlich; Zuständigkeiten werden aufgehoben. Nachrichten, Anhänge und Audit-Einträge bleiben erhalten. Die Queue verschwindet aus der aktiven Verwaltung, Adressen werden freigegeben und Mailzugänge/Abrufpläne entfernt. Ein Historien-Datensatz bleibt in der Datenbank erhalten. Aktiven IMAP-Empfang zuerst deaktivieren; laufende Abrufe und Versandvorgänge abwarten. Erforderlich sind `queue` in der Quelle sowie bei Ticketübernahme `move`/`view` in der Quelle und `move`/`view`/`status` im Ziel.
|
||||
- Status: „Warten auf Kunde“ öffnet sich bei einer zugeordneten Kundenantwort; „Warten auf Termin“ benötigt Datum, Uhrzeit und IANA-Zeitzone (z. B. `Europe/Berlin`); „Warten auf Ware“ bietet die berechtigte Bestätigungsaktion. „Erledigt“ schließt das Ticket aus der laufenden Übersicht aus.
|
||||
- Queue-Wechsel: Zielrechte und Absender werden geprüft, ein aktiver Status gleichen Verhaltens wird bevorzugt, alternativ „Offen“. Die Zuständigkeit wird aufgehoben. Eine manuelle Zielstatusauswahl ist möglich. Der Editor verwendet anschließend die Signaturen und Adressen der Zielqueue.
|
||||
- Einstellungen: „Allgemein“ verwaltet Queue-Name und Farbe. **Mail-Einstellungen** bündelt Adressen, SMTP-Versand, IMAP-Empfang, Abrufzeitplan und Eingangsbestätigung. Status und Signaturen besitzen eigene Tabs. Verwendete deaktivierte Status benötigen eine gültige Nachfolgezuordnung. Ein aktiver Offen-Status muss erhalten bleiben. Für verwendete Status ist das Verhalten unveränderlich; hierfür einen neuen Status anlegen und zuordnen.
|
||||
- Benutzer & Gruppen: Benutzer anlegen/deaktivieren, Gruppenmitgliedschaften und Berechtigungsmatrix bearbeiten. Die Administratorgruppe und der eigene Administratorzugriff sind geschützt.
|
||||
- Glocke: Benachrichtigungen lesen und Tickets öffnen; unter „Benachrichtigungen konfigurieren“ pro Ereignis E-Mail und Glocke auswählen. Aktualisierung alle fünf Sekunden ohne Seitenneuladen.
|
||||
- Darstellung: Kopfzeilen-Schalter wechselt zwischen System, Hell und Dunkel; Auswahl bleibt im Browser erhalten.
|
||||
|
||||
## E-Mail im Entwicklungsbetrieb
|
||||
|
||||
Ohne explizite Queue-Konfiguration legt `MAIL_MODE=development` den Versandstandard fest. **Der Entwicklungsadapter einer Queue erzeugt keine echten ausgehenden E-Mails. Sobald in dieser Queue SMTP aktiviert wird, werden Antworten, aktivierte Eingangsbestätigungen und E-Mail-Benachrichtigungen tatsächlich über ihren SMTP-Server versendet.** Der Entwicklungs-API-Endpunkt `/api/dev/incoming` bleibt für Integrationstests erhalten, besitzt jedoch keine Schaltfläche mehr in der Oberfläche. „Manuelles Ticket erstellen“ nutzt einen eigenen authentifizierten Produktiv-Endpunkt (`POST /api/tickets`). Für eine E-Mail-Antwort auf ein bestehendes Ticket muss eine passende Message-ID über References/In-Reply-To und dieselbe Kundenadresse vorhanden sein; ein geänderter Betreff beeinflusst die Zuordnung nicht.
|
||||
|
||||
### SMTP und Eingangsbestätigung pro Queue
|
||||
|
||||
**Einstellungen → Queue wählen → Mail-Einstellungen** benötigt die Aktion `queue`. Im oberen Bereich zuerst Eingangs- und Ausgangsadressen sowie Standardabsender verwalten. Für den Versand „SMTP“ auswählen, Server/Port/Benutzer/Passwort eintragen und TLS ab Verbindungsaufbau (typisch 465) oder zwingendes STARTTLS (typisch 587) wählen. Unverschlüsselter Versand und das Abschalten der Zertifikatsprüfung werden nicht angeboten. „Speichern & SMTP prüfen“ speichert und prüft SMTP ohne Test-E-Mail. Leere Passwortfelder behalten gespeicherte Zugangsdaten bei. Bei geändertem Server oder Benutzer müssen die Zugangsdaten erneut eingegeben werden.
|
||||
|
||||
### Empfang und Abrufzeitplan pro Queue
|
||||
|
||||
Im selben Tab unter **Empfangen · IMAP** Server, Port, TLS-Modus, Benutzername, Passwort und Postfachordner (meist `INBOX`) hinterlegen und den Empfang aktivieren. Standardports: 993 mit direktem TLS, 143 mit zwingendem STARTTLS. Passwörter sind wie SMTP-Zugangsdaten verschlüsselt; Schlüssel und Sicherungshinweise im nächsten Absatz gelten für beide Protokolle. „Speichern & IMAP prüfen“ testet Anmeldung und Ordnerzugriff ohne Import. „Speichern & jetzt abrufen“ führt einen echten Import aus und kann bei aktivierter Eingangsbestätigung Kundenmails auslösen.
|
||||
|
||||
**Abrufzeitplan / Cron-Job:** je Queue Intervall (15–86.400 Sekunden) oder Cron-Ausdruck mit fünf Feldern und IANA-Zeitzone wählen. Beispiele: `*/5 * * * *` alle fünf Minuten; `0 8-18 * * 1-5` werktags stündlich von 8 bis 18 Uhr. Die Zeitzone berücksichtigt Sommer- und Winterzeit. Die Anzeige enthält letzten Versuch, letzten erfolgreichen Abruf, nächsten Termin und Fehlerstatus; sie aktualisiert sich alle fünf Sekunden.
|
||||
|
||||
Der Job läuft im Syncova-Serverprozess, nicht in einem externen Windows-/Linux-Cron-Dienst. Ein Scheduler prüft jede Sekunde die persistenten Queue-Termine. Der Server muss laufen, der Browser darf geschlossen sein. Fällige bzw. während eines Serverabbruchs begonnene geplante Abrufe bleiben nach einem Neustart fällig und werden einmal nachgeholt. Pro Queue kann nur ein Abruf gleichzeitig laufen. Das Deaktivieren oder Ändern der Mailkonfiguration stoppt die weitere Verarbeitung einer laufenden alten Konfiguration und ersetzt ihren Termin. Standardmäßig ist der Empfang ohne vorkonfiguriertes Konto deaktiviert.
|
||||
|
||||
„Nur ungelesene Nachrichten“ und „nach erfolgreichem Import als gelesen markieren“ sind getrennt wählbar. Es werden keine E-Mails gelöscht. Importierte IMAP-UIDs werden zusammen mit Postfach und UIDVALIDITY gespeichert; wiederholte Abrufe und Abstürze erzeugen keine doppelten Nachrichten. Ein gemeinsam genutztes Postfach ist möglich: jede Queue verarbeitet nur ihre Empfängeradressen und lässt fremde Nachrichten ungelesen. Je Durchlauf werden höchstens 100 noch nicht betrachtete UIDs untersucht; weitere folgen beim nächsten Abruf. Fehlerhafte Nachrichten bleiben im Postfach und werden im queuegeschützten Systemprotokoll vermerkt. Bcc ohne erkennbare To/Cc-Zuordnung und mehrdeutige Queue-Empfänger benötigen eine Korrektur der Zustellung.
|
||||
|
||||
SMTP-Passwörter werden mit AES-256-GCM verschlüsselt in `queue_mail` gespeichert. Schlüssel: `SMTP_ENCRYPTION_KEY` (64 Hexzeichen aus dem Secret Manager), alternativ `SMTP_KEY_FILE` bzw. automatisch `data/smtp.key`. Unter Windows den Zugriff per NTFS-ACL auf den Dienstbenutzer begrenzen. Schlüssel separat sichern; geht er verloren, müssen die SMTP-Passwörter neu eingegeben werden. API und Protokolle enthalten lediglich `passwordSet`/Änderungsflags, niemals das Passwort oder den verschlüsselten Wert. Das Passwort wird nur für den jeweiligen Versand serverseitig entschlüsselt. Globale SMTP-Umgebungsvariablen bleiben als kompatibler Fallback für noch nicht explizit konfigurierte Queues bestehen.
|
||||
|
||||
Eingangsbestätigung ist anfangs **deaktiviert**. Betreff/Text sind pro Queue konfigurierbar. Platzhalter: `{ticketnummer}`, `{betreff}`, `{kundenname}`, `{queue}`. Die optionale Standardsignatur wird genau einmal angehängt, eine Vorschau zeigt das Ergebnis mit Beispieldaten. Bestätigungen entstehen nur bei einer neuen Anfrage, in derselben Transaktion wie das Ticket und mit einer stabilen Message-ID. Duplikate, Kundenantworten im vorhandenen Thread, eigene Absender und automatische Nachrichten lösen keine zweite Bestätigung aus. Standardabsender, Queue-SMTP und Thread-References werden auch für diese Nachrichten verwendet. Konfiguration und Versand erscheinen in System- bzw. Ticketprotokoll. Es erfolgt kein nachträglicher Bestätigungsversand für vorhandene Tickets.
|
||||
|
||||
Entwicklungsendpunkte erfordern eine angemeldete Administratorberechtigung und sind im Produktionsmodus deaktiviert:
|
||||
|
||||
- `POST /api/dev/incoming`: `{messageId, from, to:[], subject, body, references:[], inReplyTo?, attachments?:[{name,mime,content:<base64>}]}`.
|
||||
- `GET /api/dev/mail`: persistent gespeicherte, simuliert zugestellte E-Mails (einschließlich aktivierter E-Mail-Benachrichtigungen).
|
||||
|
||||
Mehrere Queue-Adressen sind vorhanden, etwa `support@syncova.local` und `support.team@syncova.local`. Eingehende Nachrichten müssen genau einer Queue zugeordnet werden. Eigene Adressen, `Auto-Submitted` außer `no` und `Precedence: bulk/list/junk` werden gegen Schleifen ignoriert. Message-IDs sind global eindeutig; erneuter Empfang erzeugt weder Nachrichten noch Benachrichtigungen doppelt.
|
||||
|
||||
## Datenmodell und Berechtigungen
|
||||
|
||||
`users` → `memberships` → `groups_`; jede Gruppe enthält pro Queue-ID oder `*` eine Liste erlaubter Aktionen. **Union/Allow-only:** Alle Erlaubnisse aus allen Gruppen werden addiert; es gibt keine impliziten Verweigerungsregeln. Ohne `view` werden keine Tickets der Queue ausgeliefert. Eine Aktionsberechtigung allein ersetzt `view` nicht. `users` gilt workspaceweit; Queue-, Status-, Signatur- und Logrechte können queuespezifisch vergeben werden. Neue Queues sind zunächst für die Administratorgruppe sichtbar; weitere Gruppen gezielt ergänzen.
|
||||
|
||||
Aktionen: `view`, `reply`, `note`, `status`, `assign`, `move`, `goods`, `queue`, `statuses`, `signatures`, `users`, `logs`. Die API prüft sie unabhängig von sichtbaren UI-Schaltern. Auch Direktzugriffe, Anhänge, Notification-Anzeige und Notification-Versand werden geprüft. Berechtigte Teammitglieder sehen die Namen anderer aktiver Benutzer für Zuweisungen; eine unzulässige Zuweisung wird abgewiesen.
|
||||
|
||||
`queues` besitzen Adressen und Signaturen; `statuses` besitzen stabile IDs und interne Verhaltenskennungen. `tickets` referenzieren Queue/Status/Zuständigkeit und besitzen UTC-Termin, IANA-Zone und eine Revisionsnummer zur Konflikterkennung. `messages` enthalten Klartext und Thread-IDs, `attachments` gesicherte Binärdaten. `audits` speichern Vorher-/Nachher-Werte, Akteur, Zeit und Entität. SQLite-Trigger verhindern Audit-Änderung und -Löschung. `notifications` besitzen eine eindeutige Kombination aus Benutzer und Ereignisschlüssel. `outbox` und `dev_mail` sichern Versandaufträge bzw. simulierte Zustellungen.
|
||||
|
||||
Ticketänderungen, Aktivitäten und Benachrichtigungen erfolgen in SQLite-Transaktionen. Die Abfrage fälliger Tickets prüft alle fünf Sekunden den **aktuellen** Wartestatus und **aktuellen** Termin. Es gibt keine veralteten Timer-Jobs; abgeschaffte oder geänderte Termine können nicht nachträglich feuern. Beim Prozessstart werden fällige Termine nachgeholt. Sommerzeitlücken bei lokaler Termineingabe werden abgewiesen.
|
||||
|
||||
## Produktion und echte Konten
|
||||
|
||||
1. `Copy-Item .env.example .env`; serverseitige Variablen ausfüllen. Keine Geheimnisse im Frontend oder Git speichern. Für den Betrieb einen Secret Manager oder geschützte Umgebungsvariablen verwenden; `.env` mittels Dateisystemrechten auf den Dienstbenutzer beschränken.
|
||||
2. `NODE_ENV=production`, eine **neue** `DB_PATH`, `ADMIN_EMAIL` und ein individuelles `ADMIN_PASSWORD` vor dem ersten Start setzen. Der Produktionsstart ohne Bootstrap-Passwort wird abgewiesen. Nach der Initialisierung kann die Bootstrap-Variable entfernt werden.
|
||||
3. SMTP pro Queue in **Einstellungen → Mail-Einstellungen** einrichten. Für bestehende Installationen bleibt alternativ `MAIL_MODE=smtp` mit `SMTP_HOST`, `SMTP_PORT`, `SMTP_TLS`, `SMTP_USER`, `SMTP_PASSWORD` als globaler Versand-Fallback verfügbar. Der jeweilige SMTP-Account muss die Queue-Absender erlauben.
|
||||
4. IMAP-Konto und Zeitplan ebenfalls pro Queue in **Mail-Einstellungen** konfigurieren. Bestehende `IMAP_HOST`, `IMAP_PORT`, `IMAP_USER`, `IMAP_PASSWORD` werden bei erstmaliger Anlage der Empfangseinstellungen als Startwerte übernommen (Intervall 30 Sekunden); anschließend ist die gespeicherte Queue-Konfiguration maßgeblich. Ohne diese Umgebungsvariablen bleibt Empfang zunächst aus. Ein eigenes Postfach je Queue oder ein gemeinsames Sammelpostfach sind möglich.
|
||||
5. `npm run build` und `npm start`. Der Node-Prozess liefert dann auch das gebaute Frontend unter Port 3001 aus. Dauerbetrieb als **eine** beaufsichtigte Dienstinstanz einrichten (z. B. systemd/Windows-Dienst mit automatischem Neustart). Ein reiner statischer Webhost kann dieses Backend nicht ausführen.
|
||||
6. Hinter einem HTTPS-Reverse-Proxy betreiben, `APP_ORIGIN=https://tickets.example.org` und `COOKIE_SECURE=true` setzen. Auf demselben Ursprung ausliefern; keine offene CORS-Konfiguration. Nur den Reverse-Proxy öffentlich zugänglich machen. Health-/Prozessüberwachung und Sicherungen einrichten.
|
||||
|
||||
SMTP-Aufträge verwenden eine stabile Message-ID. Definitiv fehlgeschlagene Verbindungen werden mit Backoff wiederholt. Bei einem unklaren Ergebnis oder Neustart während `sending` wird der Auftrag **uncertain**, damit er nicht blind doppelt versendet wird. Solche Aufträge erscheinen unter Systemprotokoll → Versandaufträge. Der Administrator muss die Zustellung am Mailserver prüfen; es gibt absichtlich keine ungesicherte „erneut senden“-Schaltfläche. Entfernte Absender nach einem Queue-Wechsel blockieren einen noch wartenden Antwortauftrag. Im Entwicklungsadapter ist die Zustellung durch die gemeinsame Datenbanktransaktion exakt einmalig.
|
||||
|
||||
## Tests und Qualität
|
||||
|
||||
```powershell
|
||||
npm test
|
||||
npm run build
|
||||
npm audit
|
||||
npm run test:docker
|
||||
npm run test:image
|
||||
```
|
||||
|
||||
Integrationsprüfungen verwenden isolierte SQLite-Datenbanken und einen echten lokalen HTTP-Server. Sie decken Queue-Isolation inklusive HTTP-Direktzugriff/Anhängen, Gruppenunion und Rechteentzug, mehrere Empfangsadressen und Queues, Threadzuordnung unabhängig vom Betreff, Duplikate, Schleifen, alle Wartestatus, Prozessneustart, Statusablösung und Rollback, erlaubte Absender, interne Notizen, idempotenten Entwicklungsversand, unveränderliche Audits, Benachrichtigungs-Deduplizierung, Zuständigkeits- und Queue-Wechsel sowie veraltete Revisionen und Cross-Origin-Schreibzugriffe ab. Zusätzlich Tests für IANA-Zonen und Sommerzeitlücken.
|
||||
|
||||
Die weiteren Tests prüfen Queue-Löschung inklusive vollständiger Ticket-/Anhangübernahme und Rollback, HTML-Bereinigung sowie echte MIME-Erzeugung und erneutes Parsen von HTML-/Klartext-Mails mit Binäranhängen. `test:docker` benötigt ein zuvor gebautes Image, erzeugt eine isolierte Compose-Testumgebung und entfernt nur deren eigene Container und Testvolumes. Es prüft Daten, Anhänge, HTML, Schlüsselentschlüsselung, Sitzungen und Protokolle nach einem vollständigen Container-Neuerstellen. `test:image` prüft zusätzlich das unveränderte Image auf ein leeres Datenverzeichnis und eingebettete Zugangsdaten; danach startet es einen flüchtigen Produktionscontainer ohne veröffentlichte Ports und prüft Bootstrap-Anmeldung, leere Tickets/Nachrichten/Anhänge und das Fehlen von Demobenutzern. Beide verwenden standardmäßig `syncova-ticket:local`, überschreibbar mit `SYNCOVA_IMAGE`.
|
||||
|
||||
## Gitea Actions und Container Registry
|
||||
|
||||
Repository: [jf/syncova-ticket](https://git.jfritzsche.de/jf/syncova-ticket). Der Workflow [.gitea/workflows/ci.yaml](.gitea/workflows/ci.yaml) läuft bei Branch-Pushes, Tags `v*` und Pull Requests nach `main`:
|
||||
|
||||
1. `npm ci`, Integrationstests und Produktionsbuild mit Node.js 22.
|
||||
2. Nur nach erfolgreichen Tests: Docker-Image bauen und den leeren Produktionsstart mit `npm run test:image` prüfen.
|
||||
3. Nur für Pushes nach `main` oder Versionstags: Anmeldung mit dem Repository-Secret `REGISTRY_TOKEN` und Veröffentlichung nach `git.jfritzsche.de/jf/syncova-ticket`.
|
||||
|
||||
Jeder veröffentlichte Build erhält `sha-<vollständiger Commit-SHA>`. Der aktuelle erfolgreiche `main`-Build erhält zusätzlich `latest`; ein älterer parallel laufender Build überschreibt diesen Tag nicht. Versionstags wie `v1.0.0` erzeugen denselben Image-Tag. Pull Requests und sonstige Branches veröffentlichen keine Images und erhalten keinen Registry-Token. Actions sind auf konkrete Commit-SHAs festgelegt. Der Runner muss das Label `ubuntu-latest`, Node-Action-Unterstützung, Docker CLI und Zugriff auf einen Docker-Daemon besitzen. Das Secret benötigt Schreibzugriff auf Pakete des Benutzers `jf`; es gehört weder ins Repository noch in die Compose-Datei.
|
||||
|
||||
Das Image enthält keine lokale SQLite-Datenbank, Anhänge, Mailzugangsdaten oder Schlüssel. Produktionsstarts mit einem neuen Volume erzeugen nur das konfigurierte Administratorkonto sowie Standardqueues, Status und Gruppen; keine Demotickets oder weiteren Benutzer. Bestehende Volumes werden unverändert weiterverwendet.
|
||||
|
||||
## Docker Compose mit persistenten Daten
|
||||
|
||||
```powershell
|
||||
Copy-Item .env.docker.example .env.docker
|
||||
# .env.docker bearbeiten: eigenes ADMIN_PASSWORD und gewünschte URL setzen.
|
||||
docker compose --env-file .env.docker pull
|
||||
docker compose --env-file .env.docker up -d
|
||||
```
|
||||
|
||||
Standardadresse: **http://localhost:3002**. Die vorhandene lokale Entwicklung auf Port 3001 bleibt getrennt. Der erste Docker-Start verwendet eine neue Datenbank; vorhandene lokale Daten werden nicht stillschweigend ersetzt oder übernommen. Für die Übernahme siehe unten. `APP_ORIGIN` muss exakt zur aufgerufenen Adresse einschließlich Port passen. Für HTTPS `COOKIE_SECURE=true` setzen. SMTP/IMAP werden anschließend in der Oberfläche pro Queue konfiguriert.
|
||||
|
||||
Das benannte Volume `<Compose-Projekt>_syncova_data` wird unter `/app/data` eingebunden. Darin liegen SQLite samt WAL, Tickets, Benutzer, Gruppen, Sitzungen, Nachrichten, **alle Anhänge als BLOBs**, HTML-Nachrichten, Signaturen, Mailkonfigurationen, Benachrichtigungen, Audit-Historie, Versandaufträge, Abrufzeitpläne/UID-Deduplizierung und der automatisch erzeugte Verschlüsselungsschlüssel `smtp.key`. Container können aktualisiert oder neu erstellt werden; das Volume bleibt bestehen. Bei extern vorgegebenem `SMTP_ENCRYPTION_KEY` diesen zusätzlich zur Datenbanksicherung sicher verwahren.
|
||||
|
||||
```powershell
|
||||
docker compose --env-file .env.docker ps
|
||||
docker compose --env-file .env.docker logs --tail 100 syncova
|
||||
docker compose --env-file .env.docker down
|
||||
docker compose --env-file .env.docker up -d
|
||||
```
|
||||
|
||||
`compose.yaml` verwendet das fertige Registry-Image und baut nicht lokal. `SYNCOVA_IMAGE` kann auf einen festen `sha-...`- oder Versionstag gesetzt werden. Standardmäßig wird das aktuelle Image beim Start abgerufen (`SYNCOVA_PULL_POLICY=always`). Für private Pakete vorher mit `docker login git.jfritzsche.de --username jf` anmelden und einen Token am Passwortprompt eingeben; niemals in die Compose-Datei schreiben.
|
||||
|
||||
`down` ohne `--volumes` behält alle Daten. **`down --volumes` löscht das Datenvolume** und gehört nicht zum normalen Updateablauf. Für Updates `pull` und anschließend `up -d` verwenden. Das Image läuft als Benutzer `node`, mit schreibgeschütztem Root-Dateisystem, Healthcheck und automatischem Neustart; Scheduler und Versandworker laufen im selben Dienst. Es wird nur eine Instanz unterstützt. `ADMIN_PASSWORD` ist das Bootstrap-Passwort der Ersteinrichtung; bei bestehender Datenbank setzt ein anderer Variablenwert das Benutzerpasswort nicht zurück. Compose benötigt die Variable weiterhin zur Konfigurationsprüfung.
|
||||
|
||||
Für einen bewussten lokalen Build und die Docker-Tests:
|
||||
|
||||
```powershell
|
||||
docker build -t syncova-ticket:local .
|
||||
npm run test:image
|
||||
npm run test:docker
|
||||
# Optional mit Compose lokal starten:
|
||||
$env:SYNCOVA_IMAGE = 'syncova-ticket:local'
|
||||
$env:SYNCOVA_PULL_POLICY = 'never'
|
||||
docker compose --env-file .env.docker up -d
|
||||
```
|
||||
|
||||
### Vorhandene lokale Daten nach Docker übernehmen
|
||||
|
||||
Den lokalen Syncova-Server zuerst beenden und bis zum Abschluss nicht erneut starten; zwei aktive Mailworker auf kopierten Datenbeständen können doppelt versenden. Nur ein **neues, noch leeres Docker-Volume** verwenden. Im Projektordner:
|
||||
|
||||
```powershell
|
||||
$syncovaImportPath = (Resolve-Path .\data).Path
|
||||
docker compose --env-file .env.docker pull
|
||||
docker compose --env-file .env.docker run --rm --no-deps --entrypoint node --volume "${syncovaImportPath}:/import:ro" syncova server/import-data.js
|
||||
docker compose --env-file .env.docker up -d
|
||||
```
|
||||
|
||||
Der Import überschreibt keine vorhandene Zieldatenbank. Er übernimmt `syncova.db`, gegebenenfalls WAL und `smtp.key`, prüft Integrität und Mail-Schlüssel und erhält vorhandene Benutzerkonten/Passwörter. Bei einem abweichenden `DB_PATH`/`SMTP_KEY_FILE` die Quelldateien zuvor unter diesen Namen bereitstellen. Wurde lokal ein externer `SMTP_ENCRYPTION_KEY` verwendet, denselben Wert in `.env.docker` setzen. Bei einem Importfehler bleiben bereits kopierte Daten zur Prüfung erhalten; die Quelle wird nie verändert.
|
||||
|
||||
### Sicherung
|
||||
|
||||
Den Dienst stoppen und das gesamte Datenverzeichnis einschließlich Schlüssel sichern:
|
||||
|
||||
```powershell
|
||||
docker compose --env-file .env.docker stop
|
||||
docker compose --env-file .env.docker cp syncova:/app/data ./syncova-backup
|
||||
docker compose --env-file .env.docker start
|
||||
```
|
||||
|
||||
Sicherungen enthalten vertrauliche Daten und müssen entsprechend geschützt werden. Zusätzlich `.env.docker` bzw. extern verwaltete Schlüssel sichern. Eine Wiederherstellung erfolgt bei gestopptem Dienst in ein leeres Volume; die Dateien müssen für UID/GID 1000 (`node`) schreibbar sein. Das benannte Volume allein schützt vor Container-Neuerstellung, ersetzt aber keine externe Sicherung.
|
||||
|
||||
Park UI wurde gemäß aktueller [Installation](https://park-ui.com/docs/installation) und [Theming-Dokumentation](https://park-ui.com/docs/theming) als Quellcode aus der offiziellen Registry übernommen. Die CLI konnte hier ihre Initialisierung nicht abschließen; `scripts/install-park.ps1` und `scripts/configure-park.mjs` dokumentieren den Registry-Import und die Panda-Konfiguration. Die generierten Komponenten und Rezepte sind Bestandteil des Projekts; im normalen Build ist weder die Registry noch die CLI nötig. Farben basieren auf Neutral/Violet, im Darkmode auf Anthrazit mit violetten Akzenten. Radius-Tokens betragen 2/3/4 Pixel. Modale verwenden einen Portal-Layer, ausgerichtete Kopfzeilen, volle Formularbreite und scrollbaren Inhalt. CSS/Panda-Pakete sind durch die Sperrdatei fixiert; zwei transitive Build-Abhängigkeiten werden auf gepatchte Versionen überschrieben. Die Tests prüfen zusätzlich Queue-SMTP-Routing, Geheimnisverschlüsselung und -redaktion sowie die einmalige automatische Eingangsbestätigung.
|
||||
|
||||
## Benutzer und Gruppen löschen
|
||||
|
||||
Unter **Benutzer & Gruppen** befindet sich neben jedem Benutzer ein Papierkorb; Gruppen haben eine eigene Aktion **Löschen**. Vor dem Löschen zeigt der Dialog die Auswirkungen und verlangt die E-Mail-Adresse bzw. den Gruppennamen zur Bestätigung. Beide Aktionen erfordern die workspaceweite Berechtigung „Benutzer verwalten“ und werden protokolliert.
|
||||
|
||||
Beim Löschen eines Benutzers werden Sitzungen und Mitgliedschaften entfernt, ausstehende Benachrichtigungsmails abgebrochen und alle zugewiesenen Tickets freigegeben. Das Konto verschwindet aus der Verwaltung und allen Auswahllisten und kann weder angemeldet noch über einen alten Editor reaktiviert werden. Die E-Mail-Adresse kann für ein neues Konto verwendet werden. Ein gesperrter interner Datensatz mit dem bisherigen Namen bleibt erhalten, damit Ticket- und Auditverläufe nachvollziehbar bleiben; Nachrichten, Anhänge und bereits vorgemerkte Kundenantworten bleiben erhalten.
|
||||
|
||||
Beim Löschen einer Gruppe werden deren Mitgliedschaften und Rechte entfernt. Benutzerkonten und Rechte aus anderen Gruppen bleiben erhalten. Zugewiesene Tickets werden nur dann freigegeben, wenn der jeweilige Bearbeiter dadurch seinen Lesezugriff verliert. Der eigene Benutzer, der letzte aktive Administrator und die Administratorgruppe sind geschützt; auch die einzige eigene Gruppe mit Zugriff auf die Benutzerverwaltung lässt sich nicht löschen. Löschungen bleiben nach einem Neustart bestehen.
|
||||
|
||||
## Platzhalter in Signaturen
|
||||
|
||||
Unter **Einstellungen → Queue → Signaturen → Platzhalter einfügen** lassen sich Variablen an der Cursorposition einfügen. Sie funktionieren in Klartext und HTML. Die Vorschau zeigt wahlweise eine Antwort des angemeldeten Benutzers mit Beispielticket oder eine automatische Eingangsmeldung. Im Ticket erscheint die Signatur mit den tatsächlichen Ticketdaten; beim Versand wird sie serverseitig erneut aufgelöst und dauerhaft in der Nachricht gespeichert.
|
||||
|
||||
| Bereich | Platzhalter |
|
||||
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| Antwortender Benutzer | `{benutzer.name}`, `{benutzer.vorname}`, `{benutzer.nachname}`, `{benutzer.email}`, `{benutzer.telefon}`, `{benutzer.position}`, `{benutzer.abteilung}` |
|
||||
| Queue und Versand | `{queue.name}`, `{queue.email}` (Standardabsender), `{absender.email}` (ausgewählter Absender) |
|
||||
| Ticket | `{ticket.nummer}`, `{ticket.betreff}`, `{ticket.status}` |
|
||||
| Kundenkontakt | `{kunde.name}`, `{kunde.email}` |
|
||||
| Zugewiesener Bearbeiter | `{bearbeiter.name}`, `{bearbeiter.email}` |
|
||||
| Zeitpunkt | `{datum}`, `{uhrzeit}` in `Europe/Berlin` |
|
||||
|
||||
Telefon, Position/Funktion und Abteilung sind optionale Felder in **Einstellungen → Benutzer → Benutzer bearbeiten**. Vorname ist das erste Wort des Anzeigenamens, Nachname der Rest. Fehlende persönliche Angaben und nicht zugewiesene oder nicht mehr zugriffsberechtigte Bearbeiter ergeben einen leeren Wert. Automatische Eingangsmeldungen verwenden für `{benutzer.name}` den Queue-Namen und für `{benutzer.email}` den Queue-Absender; Vorname, Nachname, Telefon, Position und Abteilung bleiben dabei leer. Die Eingangsbestätigung muss die Signatur weiterhin explizit einschließen.
|
||||
|
||||
Vorhandene Vorlagen mit `{%user.firstName%}`, `{%user.lastName%}`, `{%user.phone%}` und `{%mailbox.email%}` funktionieren ebenfalls. `{%mailbox.email%}` entspricht dem ausgewählten Queue-Absender. Beide Schreibweisen (`{...}` und `{%...%}`) werden unterstützt.
|
||||
|
||||
Beispiel für HTML:
|
||||
|
||||
```html
|
||||
<p>
|
||||
Freundliche Grüße<br />
|
||||
<strong>{benutzer.name}</strong><br />
|
||||
{benutzer.position} · {benutzer.abteilung}<br />
|
||||
<a href="mailto:{benutzer.email}">{benutzer.email}</a><br />
|
||||
{queue.name} · Ticket {ticket.nummer}
|
||||
</p>
|
||||
```
|
||||
|
||||
Unbekannte Platzhalter werden mit einer Fehlermeldung abgewiesen. HTML-Werte werden maskiert, danach wird die gesamte Signatur erneut bereinigt. Daten mit geschweiften Klammern werden nicht rekursiv als weitere Platzhalter interpretiert. Englische Aliase wie `{user.name}`, `{user.email}`, `{user.phone}`, `{user.job_title}`, `{user.department}`, `{ticket.number}`, `{customer.name}` und `{assignee.name}` werden ebenfalls unterstützt. Datum und Uhrzeit beziehen sich auf das Erstellen der Antwort, nicht auf einen späteren Zustellversuch.
|
||||
|
||||
## Bekannte Grenzen und Betriebsentscheidungen
|
||||
|
||||
- **Echte SMTP-/IMAP-Zustellung wurde mangels Kontodaten nicht extern getestet.** Entwicklung, API, Persistenz und Hintergrundverarbeitung sind lokal geprüft. Kein öffentlicher Server oder Cloud-Deployment wurde eingerichtet.
|
||||
- Klassisches SMTP bietet keine transaktionale Exactly-once-Zustellung mit der lokalen Datenbank. Unklare Zustellungen erfordern die oben beschriebene manuelle Prüfung; dafür ist kein automatischer Doppelversand vorgesehen. Für vollautomatische Exactly-once-Annahme wäre ein Mailprovider mit serverseitigem Idempotenzschlüssel nötig.
|
||||
- SMTP und IMAP einschließlich separater Konten sind pro Queue konfigurierbar. Noch keine OAuth2-Konfiguration und kein POP3. Bcc-/Envelope-only-Zustellung ohne erkennbare To/Cc-Zuordnung und Nachrichten mit Empfängern mehrerer Queues werden zur Prüfung zurückgehalten.
|
||||
- Threads werden aus Gründen der Queue-Isolation nur bei gleicher Kundenadresse und aktueller Queue verbunden. Antworten an eine frühere Queue-Adresse nach einem Verschieben erzeugen ein neues Ticket; entsprechend die Zieladresse in weiteren Antworten verwenden. Kein automatisches Zusammenführen verschiedener Kundenkontakte.
|
||||
- Fremdes HTML wird nicht ausgeführt; IMAP nutzt die Textalternative, bei fehlender Alternative einen Hinweis. HTML-Signaturen werden bereinigt und nur isoliert angezeigt. Anhänge werden als Download mit `application/octet-stream`, `nosniff` und Sandbox ausgeliefert. Maximal 10 MiB pro Anhang, 20 MiB pro eingehender IMAP-Nachricht; ausgehende Anhänge insgesamt höchstens 20 MiB. MIME-Kodierung vergrößert die versendete Nachricht, daher gelten zusätzlich die Größenlimits des Mailproviders. Kein Virenscanner integriert.
|
||||
- Single-instance SQLite, Polling statt WebSockets, keine horizontale Skalierung und keine serverseitige Pagination. Für große Installationen wären PostgreSQL, Worker-Leases und paginierte Suche die nächsten Schritte.
|
||||
- Keine MFA, SSO, Passwort-Selbstzurücksetzung oder Zustell-Webhooks. Benutzerverwaltung erlaubt Administratoren Passwortsetzung. Sitzungen sind 12 Stunden gültig, HttpOnly und SameSite=Strict; Anmeldung ist rate-limitiert. Produktive Einrichtung mit HTTPS und sicherer Passwortverteilung erforderlich.
|
||||
- Datenbanksicherungen müssen konsistent erfolgen (SQLite-Backup API oder gestoppter Prozess; bei Live-Dateikopie auch WAL beachten). Datenträgerverschlüsselung, Aufbewahrungsfristen und Monitoring sind Betriebsaufgaben. Audit-Trigger schützen vor normalen API-Benutzern, nicht vor einem Datenbankadministrator mit Dateizugriff.
|
||||
50
compose.yaml
Normal file
50
compose.yaml
Normal file
@ -0,0 +1,50 @@
|
||||
services:
|
||||
syncova:
|
||||
image: ${SYNCOVA_IMAGE:-git.jfritzsche.de/jf/syncova-ticket:latest}
|
||||
pull_policy: ${SYNCOVA_PULL_POLICY:-always}
|
||||
restart: unless-stopped
|
||||
init: true
|
||||
ports:
|
||||
- '${SYNCOVA_BIND:-127.0.0.1}:${SYNCOVA_PORT:-3002}:3001'
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
HOST: 0.0.0.0
|
||||
PORT: 3001
|
||||
TZ: Europe/Berlin
|
||||
DB_PATH: /app/data/syncova.db
|
||||
SMTP_KEY_FILE: /app/data/smtp.key
|
||||
SMTP_ENCRYPTION_KEY: ${SMTP_ENCRYPTION_KEY:-}
|
||||
APP_ORIGIN: ${APP_ORIGIN:-http://localhost:3002}
|
||||
COOKIE_SECURE: ${COOKIE_SECURE:-false}
|
||||
ADMIN_EMAIL: ${ADMIN_EMAIL:-admin@example.org}
|
||||
ADMIN_PASSWORD: ${ADMIN_PASSWORD:?Bitte ADMIN_PASSWORD in .env.docker setzen}
|
||||
MAIL_MODE: development
|
||||
volumes:
|
||||
- syncova_data:/app/data
|
||||
read_only: true
|
||||
tmpfs:
|
||||
- /tmp:rw,noexec,nosuid,size=64m
|
||||
cap_drop:
|
||||
- ALL
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
stop_grace_period: 45s
|
||||
healthcheck:
|
||||
test:
|
||||
[
|
||||
'CMD',
|
||||
'node',
|
||||
'-e',
|
||||
"fetch('http://127.0.0.1:3001/healthz').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))",
|
||||
]
|
||||
interval: 15s
|
||||
timeout: 5s
|
||||
start_period: 20s
|
||||
retries: 3
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: '10m'
|
||||
max-file: '3'
|
||||
volumes:
|
||||
syncova_data:
|
||||
1
docs/attachment-demo.txt
Normal file
1
docs/attachment-demo.txt
Normal file
@ -0,0 +1 @@
|
||||
Lokale Testdatei zur Prüfung der Anhang-Auswahl.
|
||||
1
index.html
Normal file
1
index.html
Normal file
@ -0,0 +1 @@
|
||||
<!doctype html><html lang="de"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><meta name="theme-color" content="#0f766e"/><title>Syncova Ticket · Kundenservice, verbunden.</title><script>try{let t=localStorage.getItem('syncova-theme')||'system';document.documentElement.classList.toggle('dark',t==='dark'||t==='system'&&matchMedia('(prefers-color-scheme: dark)').matches)}catch{}</script></head><body><div id="root"></div><script type="module" src="/src/main.tsx"></script></body></html>
|
||||
33
neutral-registry.json
Normal file
33
neutral-registry.json
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"$schema": "https://park-ui.com/schema/registry-item.json",
|
||||
"name": "neutral",
|
||||
"type": "registry:color",
|
||||
"dependencies": ["@pandacss/dev"],
|
||||
"files": [
|
||||
{
|
||||
"content": "import { defineSemanticTokens } from '@pandacss/dev'\n\nexport const neutral = defineSemanticTokens.colors({\n '1': { value: { _light: '#fcfcfc', _dark: '#111111' } },\n '2': { value: { _light: '#f9f9f9', _dark: '#191919' } },\n '3': { value: { _light: '#f0f0f0', _dark: '#222222' } },\n '4': { value: { _light: '#e8e8e8', _dark: '#2a2a2a' } },\n '5': { value: { _light: '#e0e0e0', _dark: '#313131' } },\n '6': { value: { _light: '#d9d9d9', _dark: '#3a3a3a' } },\n '7': { value: { _light: '#cecece', _dark: '#484848' } },\n '8': { value: { _light: '#bbbbbb', _dark: '#606060' } },\n '9': { value: { _light: '#8d8d8d', _dark: '#6e6e6e' } },\n '10': { value: { _light: '#838383', _dark: '#7b7b7b' } },\n '11': { value: { _light: '#646464', _dark: '#b4b4b4' } },\n '12': { value: { _light: '#202020', _dark: '#eeeeee' } },\n a1: { value: { _light: '#00000003', _dark: '#00000000' } },\n a2: { value: { _light: '#00000006', _dark: '#ffffff09' } },\n a3: { value: { _light: '#0000000f', _dark: '#ffffff12' } },\n a4: { value: { _light: '#00000017', _dark: '#ffffff1b' } },\n a5: { value: { _light: '#0000001f', _dark: '#ffffff22' } },\n a6: { value: { _light: '#00000026', _dark: '#ffffff2c' } },\n a7: { value: { _light: '#00000031', _dark: '#ffffff3b' } },\n a8: { value: { _light: '#00000044', _dark: '#ffffff55' } },\n a9: { value: { _light: '#00000072', _dark: '#ffffff64' } },\n a10: { value: { _light: '#0000007c', _dark: '#ffffff72' } },\n a11: { value: { _light: '#0000009b', _dark: '#ffffffaf' } },\n a12: { value: { _light: '#000000df', _dark: '#ffffffed' } },\n solid: {\n bg: {\n DEFAULT: { value: { _light: '{colors.black}', _dark: '{colors.white}' } },\n hover: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } },\n },\n fg: { DEFAULT: { value: { _light: '{colors.white}', _dark: '{colors.black}' } } },\n },\n subtle: {\n bg: {\n DEFAULT: { value: { _light: '{colors.gray.a3}', _dark: '{colors.gray.a3}' } },\n hover: { value: { _light: '{colors.gray.a4}', _dark: '{colors.gray.a4}' } },\n active: { value: { _light: '{colors.gray.a5}', _dark: '{colors.gray.a5}' } },\n },\n fg: { DEFAULT: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } } },\n },\n surface: {\n bg: {\n DEFAULT: { value: { _light: '{colors.white}', _dark: '{colors.gray.1}' } },\n hover: { value: { _light: '{colors.gray.2}', _dark: '{colors.gray.2}' } },\n active: { value: { _light: '{colors.gray.3}', _dark: '{colors.gray.3}' } },\n },\n border: {\n DEFAULT: { value: { _light: '{colors.gray.6}', _dark: '{colors.gray.6}' } },\n hover: { value: { _light: '{colors.gray.7}', _dark: '{colors.gray.7}' } },\n },\n fg: { DEFAULT: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } } },\n },\n outline: {\n bg: {\n hover: { value: { _light: '{colors.gray.a2}', _dark: '{colors.gray.a2}' } },\n active: { value: { _light: '{colors.gray.a3}', _dark: '{colors.gray.a3}' } },\n },\n border: { DEFAULT: { value: { _light: '{colors.gray.6}', _dark: '{colors.gray.6}' } } },\n fg: { DEFAULT: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } } },\n },\n plain: {\n bg: {\n hover: { value: { _light: '{colors.gray.a3}', _dark: '{colors.gray.a3}' } },\n active: { value: { _light: '{colors.gray.a4}', _dark: '{colors.gray.a4}' } },\n },\n fg: { DEFAULT: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } } },\n },\n})\n",
|
||||
"type": "registry:color",
|
||||
"path": "colors/neutral.ts"
|
||||
}
|
||||
],
|
||||
"panda": {
|
||||
"imports": [
|
||||
{
|
||||
"type": "registry:color",
|
||||
"name": "neutral",
|
||||
"from": "colors/neutral"
|
||||
}
|
||||
],
|
||||
"extension": {
|
||||
"theme": {
|
||||
"extend": {
|
||||
"semanticTokens": {
|
||||
"colors": {
|
||||
"gray": "$ref:neutral"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
7061
package-lock.json
generated
Normal file
7061
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
45
package.json
Normal file
45
package.json
Normal file
@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "syncova-ticket",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "concurrently -k \"node --watch server/index.js\" \"vite --host 127.0.0.1\"",
|
||||
"start": "node server/index.js",
|
||||
"build": "panda codegen && tsc --noEmit && vite build",
|
||||
"test": "node --test tests/service.test.js",
|
||||
"prepare": "panda codegen",
|
||||
"test:docker": "node tests/docker-smoke.mjs",
|
||||
"test:image": "node tests/image-smoke.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ark-ui/react": "^5.0.0",
|
||||
"better-sqlite3": "^11.10.0",
|
||||
"cron-parser": "^5.10.3",
|
||||
"dotenv": "^18.0.9",
|
||||
"express": "^5.1.0",
|
||||
"html-to-text": "^10.0.1",
|
||||
"imapflow": "^1.0.0",
|
||||
"lucide-react": "^0.468.0",
|
||||
"mailparser": "^3.7.0",
|
||||
"nodemailer": "^10.3.1",
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0",
|
||||
"sanitize-html": "^2.17.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@pandacss/dev": "^1.0.0",
|
||||
"@types/node": "^26.6.6",
|
||||
"@types/react": "^19.0.0",
|
||||
"@types/react-dom": "^19.0.0",
|
||||
"@vitejs/plugin-react": "^4.3.0",
|
||||
"concurrently": "^9.0.0",
|
||||
"prettier": "^3.9.10",
|
||||
"typescript": "^5.7.0",
|
||||
"vite": "^6.0.0"
|
||||
},
|
||||
"overrides": {
|
||||
"postcss-selector-parser": "7.1.6",
|
||||
"minimatch": "11.0.1"
|
||||
}
|
||||
}
|
||||
92
panda.config.ts
Normal file
92
panda.config.ts
Normal file
@ -0,0 +1,92 @@
|
||||
import { defineConfig } from '@pandacss/dev'
|
||||
import { red } from './src/theme/colors/red'
|
||||
import { green } from './src/theme/colors/green'
|
||||
import { slotRecipes } from './src/theme/recipes'
|
||||
import { recipes } from './src/theme/recipes'
|
||||
import { conditions } from './src/theme/conditions'
|
||||
import { globalCss } from './src/theme/global-css'
|
||||
import { keyframes } from './src/theme/keyframes'
|
||||
import { layerStyles } from './src/theme/layer-styles'
|
||||
import { textStyles } from './src/theme/text-styles'
|
||||
import { colors } from './src/theme/tokens/colors'
|
||||
import { durations } from './src/theme/tokens/durations'
|
||||
import { shadows } from './src/theme/tokens/shadows'
|
||||
import { zIndex } from './src/theme/tokens/z-index'
|
||||
import { animationStyles } from './src/theme/animation-styles'
|
||||
import { violet } from './src/theme/colors/violet'
|
||||
import { neutral } from './src/theme/colors/neutral'
|
||||
export default defineConfig({
|
||||
preflight: true,
|
||||
include: ['./src/**/*.{ts,tsx}'],
|
||||
outdir: 'styled-system',
|
||||
jsxFramework: 'react',
|
||||
theme: {
|
||||
extend: {
|
||||
semanticTokens: {
|
||||
colors: {
|
||||
red: red,
|
||||
green: green,
|
||||
fg: {
|
||||
default: {
|
||||
value: {
|
||||
_light: '{colors.gray.12}',
|
||||
_dark: '{colors.gray.12}',
|
||||
},
|
||||
},
|
||||
muted: {
|
||||
value: {
|
||||
_light: '{colors.gray.11}',
|
||||
_dark: '{colors.gray.11}',
|
||||
},
|
||||
},
|
||||
subtle: {
|
||||
value: {
|
||||
_light: '{colors.gray.10}',
|
||||
_dark: '{colors.gray.10}',
|
||||
},
|
||||
},
|
||||
},
|
||||
border: {
|
||||
value: {
|
||||
_light: '{colors.gray.4}',
|
||||
_dark: '{colors.gray.4}',
|
||||
},
|
||||
},
|
||||
error: {
|
||||
value: {
|
||||
_light: '{colors.red.9}',
|
||||
_dark: '{colors.red.9}',
|
||||
},
|
||||
},
|
||||
violet: violet,
|
||||
gray: neutral,
|
||||
},
|
||||
shadows: shadows,
|
||||
radii: {
|
||||
l1: {
|
||||
value: '2px',
|
||||
},
|
||||
l2: {
|
||||
value: '3px',
|
||||
},
|
||||
l3: {
|
||||
value: '4px',
|
||||
},
|
||||
},
|
||||
},
|
||||
animationStyles: animationStyles,
|
||||
recipes: recipes,
|
||||
slotRecipes: slotRecipes,
|
||||
keyframes: keyframes,
|
||||
layerStyles: layerStyles,
|
||||
textStyles: textStyles,
|
||||
tokens: {
|
||||
colors: colors,
|
||||
durations: durations,
|
||||
zIndex: zIndex,
|
||||
},
|
||||
},
|
||||
},
|
||||
globalCss: globalCss,
|
||||
conditions: conditions,
|
||||
})
|
||||
184
park-init.json
Normal file
184
park-init.json
Normal file
@ -0,0 +1,184 @@
|
||||
{
|
||||
"$schema": "https://park-ui.com/schema/registry-item.json",
|
||||
"name": "__init",
|
||||
"type": "registry:theme",
|
||||
"dependencies": ["@pandacss/dev"],
|
||||
"files": [
|
||||
{
|
||||
"content": "export const recipes = {}\nexport const slotRecipes = {}\n",
|
||||
"type": "registry:recipe",
|
||||
"path": "index.ts"
|
||||
},
|
||||
{
|
||||
"content": "import { defineTokens } from '@pandacss/dev'\n\nconst black = defineTokens.colors({\n DEFAULT: { value: '#000000' },\n a1: { value: 'rgba(0, 0, 0, 0.05)' },\n a2: { value: 'rgba(0, 0, 0, 0.1)' },\n a3: { value: 'rgba(0, 0, 0, 0.15)' },\n a4: { value: 'rgba(0, 0, 0, 0.2)' },\n a5: { value: 'rgba(0, 0, 0, 0.3)' },\n a6: { value: 'rgba(0, 0, 0, 0.4)' },\n a7: { value: 'rgba(0, 0, 0, 0.5)' },\n a8: { value: 'rgba(0, 0, 0, 0.6)' },\n a9: { value: 'rgba(0, 0, 0, 0.7)' },\n a10: { value: 'rgba(0, 0, 0, 0.8)' },\n a11: { value: 'rgba(0, 0, 0, 0.9)' },\n a12: { value: 'rgba(0, 0, 0, 0.95)' },\n})\n\nconst white = defineTokens.colors({\n DEFAULT: { value: '#ffffff' },\n a1: { value: 'rgba(255, 255, 255, 0.05)' },\n a2: { value: 'rgba(255, 255, 255, 0.1)' },\n a3: { value: 'rgba(255, 255, 255, 0.15)' },\n a4: { value: 'rgba(255, 255, 255, 0.2)' },\n a5: { value: 'rgba(255, 255, 255, 0.3)' },\n a6: { value: 'rgba(255, 255, 255, 0.4)' },\n a7: { value: 'rgba(255, 255, 255, 0.5)' },\n a8: { value: 'rgba(255, 255, 255, 0.6)' },\n a9: { value: 'rgba(255, 255, 255, 0.7)' },\n a10: { value: 'rgba(255, 255, 255, 0.8)' },\n a11: { value: 'rgba(255, 255, 255, 0.9)' },\n a12: { value: 'rgba(255, 255, 255, 0.95)' },\n})\n\nexport const colors = { black, white }\n",
|
||||
"type": "registry:theme",
|
||||
"path": "tokens/colors.ts"
|
||||
},
|
||||
{
|
||||
"content": "import { defineTokens } from '@pandacss/dev'\n\nexport const durations = defineTokens.durations({\n fastest: { value: '50ms' },\n faster: { value: '100ms' },\n fast: { value: '150ms' },\n normal: { value: '200ms' },\n slow: { value: '250ms' },\n slower: { value: '300ms' },\n slowest: { value: '400ms' },\n})\n",
|
||||
"type": "registry:theme",
|
||||
"path": "tokens/durations.ts"
|
||||
},
|
||||
{
|
||||
"content": "import { defineSemanticTokens } from '@pandacss/dev'\n\nexport const shadows = defineSemanticTokens.shadows({\n xs: {\n value: {\n _light: '0px 1px 2px {colors.gray.a6}, 0px 0px 1px {colors.gray.a7}',\n _dark: '0px 1px 1px {colors.black.a8}, 0px 0px 1px inset {colors.gray.a8}',\n },\n },\n sm: {\n value: {\n _light: '0px 2px 4px {colors.gray.a4}, 0px 0px 1px {colors.gray.a4}',\n _dark: '0px 2px 4px {colors.black.a8}, 0px 0px 1px inset {colors.gray.a8}',\n },\n },\n md: {\n value: {\n _light: '0px 4px 8px {colors.gray.a4}, 0px 0px 1px {colors.gray.a4}',\n _dark: '0px 4px 8px {colors.black.a8}, 0px 0px 1px inset {colors.gray.a8}',\n },\n },\n lg: {\n value: {\n _light: '0px 8px 16px {colors.gray.a4}, 0px 0px 1px {colors.gray.a4}',\n _dark: '0px 8px 16px {colors.black.a8}, 0px 0px 1px inset {colors.gray.a8}',\n },\n },\n xl: {\n value: {\n _light: '0px 16px 24px {colors.gray.a4}, 0px 0px 1px {colors.gray.a4}',\n _dark: '0px 16px 24px {colors.black.a8}, 0px 0px 1px inset {colors.gray.a8}',\n },\n },\n '2xl': {\n value: {\n _light: '0px 24px 40px {colors.gray.a4}, 0px 0px 1px {colors.gray.a4}',\n _dark: '0px 24px 40px {colors.black.a8}, 0px 0px 1px inset {colors.gray.a8}',\n },\n },\n inset: {\n value: {\n _light: 'inset 8px 0 12px -8px {colors.gray.a4}',\n _dark: 'inset 8px 0 12px -8px {colors.black.a6}',\n },\n },\n})\n",
|
||||
"type": "registry:theme",
|
||||
"path": "tokens/shadows.ts"
|
||||
},
|
||||
{
|
||||
"content": "import { defineTokens } from '@pandacss/dev'\n\nexport const zIndex = defineTokens.zIndex({\n hide: {\n value: -1,\n },\n base: {\n value: 0,\n },\n docked: {\n value: 10,\n },\n dropdown: {\n value: 1000,\n },\n sticky: {\n value: 1100,\n },\n banner: {\n value: 1200,\n },\n overlay: {\n value: 1300,\n },\n modal: {\n value: 1400,\n },\n popover: {\n value: 1500,\n },\n skipLink: {\n value: 1600,\n },\n toast: {\n value: 1700,\n },\n tooltip: {\n value: 1800,\n },\n})\n",
|
||||
"type": "registry:theme",
|
||||
"path": "tokens/z-index.ts"
|
||||
},
|
||||
{
|
||||
"content": "import { defineAnimationStyles } from '@pandacss/dev'\n\nexport const animationStyles = defineAnimationStyles({\n 'slide-fade-in': {\n value: {\n transformOrigin: 'var(--transform-origin)',\n '&[data-placement^=top]': {\n animationName: 'slide-from-bottom, fade-in',\n },\n '&[data-placement^=bottom]': {\n animationName: 'slide-from-top, fade-in',\n },\n '&[data-placement^=left]': {\n animationName: 'slide-from-right, fade-in',\n },\n '&[data-placement^=right]': {\n animationName: 'slide-from-left, fade-in',\n },\n },\n },\n 'slide-fade-out': {\n value: {\n transformOrigin: 'var(--transform-origin)',\n '&[data-placement^=top]': {\n animationName: 'slide-to-bottom, fade-out',\n },\n '&[data-placement^=bottom]': {\n animationName: 'slide-to-top, fade-out',\n },\n '&[data-placement^=left]': {\n animationName: 'slide-to-right, fade-out',\n },\n '&[data-placement^=right]': {\n animationName: 'slide-to-left, fade-out',\n },\n },\n },\n 'scale-fade-in': {\n value: {\n transformOrigin: 'var(--transform-origin)',\n animationName: 'scale-in, fade-in',\n },\n },\n 'scale-fade-out': {\n value: {\n transformOrigin: 'var(--transform-origin)',\n animationName: 'scale-out, fade-out',\n },\n },\n})\n",
|
||||
"type": "registry:theme",
|
||||
"path": "animation-styles.ts"
|
||||
},
|
||||
{
|
||||
"content": "export const conditions = {\n extend: {\n light: ':root &, .light &',\n invalid: '&:is(:user-invalid, [data-invalid], [aria-invalid=true])',\n hover: '&:not(:disabled):hover',\n active: '&:not(:disabled):active',\n checked:\n '&:is(:checked, [data-checked], [data-state=checked], [aria-checked=true], [data-state=indeterminate])',\n on: '&:is([data-state=on])',\n pinned: '&:is([data-pinned])',\n },\n} as const\n",
|
||||
"type": "registry:theme",
|
||||
"path": "conditions.ts"
|
||||
},
|
||||
{
|
||||
"content": "export const globalCss = {\n extend: {\n '*': {\n '--global-color-border': 'colors.border',\n '--global-color-placeholder': 'colors.fg.subtle',\n '--global-color-selection': 'colors.colorPalette.subtle.bg',\n '--global-color-focus-ring': 'colors.colorPalette.solid.bg',\n },\n html: {\n colorPalette: 'gray',\n },\n body: {\n background: 'canvas',\n color: 'fg.default',\n },\n },\n}\n",
|
||||
"type": "registry:theme",
|
||||
"path": "global-css.ts"
|
||||
},
|
||||
{
|
||||
"content": "import { defineKeyframes } from '@pandacss/dev'\n\nexport const keyframes = defineKeyframes({\n // collapse\n 'expand-height': {\n from: { height: '0' },\n to: { height: 'var(--height)' },\n },\n 'collapse-height': {\n from: { height: 'var(--height)' },\n to: { height: '0' },\n },\n 'expand-width': {\n from: { width: '0' },\n to: { width: 'var(--width)' },\n },\n 'collapse-width': {\n from: { width: 'var(--width)' },\n to: { width: '0' },\n },\n // fade\n 'fade-in': {\n from: { opacity: '0' },\n to: { opacity: '1' },\n },\n 'fade-out': {\n from: { opacity: '1' },\n to: { opacity: '0' },\n },\n // slide from (full)\n 'slide-from-left-full': {\n from: { translate: '-100% 0' },\n to: { translate: '0 0' },\n },\n 'slide-from-right-full': {\n from: { translate: '100% 0' },\n to: { translate: '0 0' },\n },\n 'slide-from-top-full': {\n from: { translate: '0 -100%' },\n to: { translate: '0 0' },\n },\n 'slide-from-bottom-full': {\n from: { translate: '0 100%' },\n to: { translate: '0 0' },\n },\n // slide to (full)\n 'slide-to-left-full': {\n from: { translate: '0 0' },\n to: { translate: '-100% 0' },\n },\n 'slide-to-right-full': {\n from: { translate: '0 0' },\n to: { translate: '100% 0' },\n },\n 'slide-to-top-full': {\n from: { translate: '0 0' },\n to: { translate: '0 -100%' },\n },\n 'slide-to-bottom-full': {\n from: { translate: '0 0' },\n to: { translate: '0 100%' },\n },\n // slide from\n 'slide-from-top': {\n '0%': { translate: '0 -0.5rem' },\n to: { translate: '0' },\n },\n 'slide-from-bottom': {\n '0%': { translate: '0 0.5rem' },\n to: { translate: '0' },\n },\n 'slide-from-left': {\n '0%': { translate: '-0.5rem 0' },\n to: { translate: '0' },\n },\n 'slide-from-right': {\n '0%': { translate: '0.5rem 0' },\n to: { translate: '0' },\n },\n // slide to\n 'slide-to-top': {\n '0%': { translate: '0' },\n to: { translate: '0 -0.5rem' },\n },\n 'slide-to-bottom': {\n '0%': { translate: '0' },\n to: { translate: '0 0.5rem' },\n },\n 'slide-to-left': {\n '0%': { translate: '0' },\n to: { translate: '-0.5rem 0' },\n },\n 'slide-to-right': {\n '0%': { translate: '0' },\n to: { translate: '0.5rem 0' },\n },\n // scale\n 'scale-in': {\n from: { scale: '0.95' },\n to: { scale: '1' },\n },\n 'scale-out': {\n from: { scale: '1' },\n to: { scale: '0.95' },\n },\n 'bg-position': {\n from: {\n backgroundPosition: 'var(--animate-from, 1rem) 0',\n },\n to: {\n backgroundPosition: 'var(--animate-to, 0) 0',\n },\n },\n position: {\n from: {\n insetInlineStart: 'var(--animate-from-x)',\n insetBlockStart: 'var(--animate-from-y)',\n },\n to: {\n insetInlineStart: 'var(--animate-to-x)',\n insetBlockStart: 'var(--animate-to-y)',\n },\n },\n})\n",
|
||||
"type": "registry:theme",
|
||||
"path": "keyframes.ts"
|
||||
},
|
||||
{
|
||||
"content": "import { defineLayerStyles } from '@pandacss/dev'\n\nexport const layerStyles = defineLayerStyles({\n disabled: {\n value: {\n cursor: 'not-allowed',\n opacity: '0.67',\n filter: 'grayscale(100%)',\n },\n },\n})\n",
|
||||
"type": "registry:theme",
|
||||
"path": "layer-styles.ts"
|
||||
},
|
||||
{
|
||||
"content": "import { defineTextStyles } from '@pandacss/dev'\n\nexport const textStyles = defineTextStyles({\n xs: { value: { fontSize: 'xs', lineHeight: '1.125rem' } },\n sm: { value: { fontSize: 'sm', lineHeight: '1.25rem' } },\n md: { value: { fontSize: 'md', lineHeight: '1.5rem' } },\n lg: { value: { fontSize: 'lg', lineHeight: '1.75rem' } },\n xl: { value: { fontSize: 'xl', lineHeight: '1.875rem' } },\n '2xl': { value: { fontSize: '2xl', lineHeight: '2rem' } },\n '3xl': { value: { fontSize: '3xl', lineHeight: '2.375rem' } },\n '4xl': { value: { fontSize: '4xl', lineHeight: '2.75rem', letterSpacing: '-0.02em' } },\n '5xl': { value: { fontSize: '5xl', lineHeight: '3.75rem', letterSpacing: '-0.02em' } },\n '6xl': { value: { fontSize: '6xl', lineHeight: '4.5rem', letterSpacing: '-0.02em' } },\n '7xl': { value: { fontSize: '7xl', lineHeight: '5.75rem', letterSpacing: '-0.02em' } },\n\n label: { value: { fontSize: 'sm', lineHeight: '1.25rem', fontWeight: 'medium' } },\n})\n",
|
||||
"type": "registry:theme",
|
||||
"path": "text-styles.ts"
|
||||
}
|
||||
],
|
||||
"panda": {
|
||||
"imports": [
|
||||
{
|
||||
"type": "registry:theme",
|
||||
"from": "recipes",
|
||||
"name": "slotRecipes"
|
||||
},
|
||||
{
|
||||
"type": "registry:theme",
|
||||
"from": "recipes",
|
||||
"name": "recipes"
|
||||
},
|
||||
{
|
||||
"type": "registry:theme",
|
||||
"name": "conditions",
|
||||
"from": "conditions"
|
||||
},
|
||||
{
|
||||
"type": "registry:theme",
|
||||
"name": "globalCss",
|
||||
"from": "global-css"
|
||||
},
|
||||
{
|
||||
"type": "registry:theme",
|
||||
"name": "keyframes",
|
||||
"from": "keyframes"
|
||||
},
|
||||
{
|
||||
"type": "registry:theme",
|
||||
"name": "layerStyles",
|
||||
"from": "layer-styles"
|
||||
},
|
||||
{
|
||||
"type": "registry:theme",
|
||||
"name": "textStyles",
|
||||
"from": "text-styles"
|
||||
},
|
||||
{
|
||||
"type": "registry:theme",
|
||||
"name": "colors",
|
||||
"from": "tokens/colors"
|
||||
},
|
||||
{
|
||||
"type": "registry:theme",
|
||||
"name": "durations",
|
||||
"from": "tokens/durations"
|
||||
},
|
||||
{
|
||||
"type": "registry:theme",
|
||||
"name": "shadows",
|
||||
"from": "tokens/shadows"
|
||||
},
|
||||
{
|
||||
"type": "registry:theme",
|
||||
"name": "zIndex",
|
||||
"from": "tokens/z-index"
|
||||
},
|
||||
{
|
||||
"type": "registry:theme",
|
||||
"name": "animationStyles",
|
||||
"from": "animation-styles"
|
||||
}
|
||||
],
|
||||
"extension": {
|
||||
"globalCss": "$ref:globalCss",
|
||||
"conditions": "$ref:conditions",
|
||||
"theme": {
|
||||
"extend": {
|
||||
"animationStyles": "$ref:animationStyles",
|
||||
"recipes": "$ref:recipes",
|
||||
"slotRecipes": "$ref:slotRecipes",
|
||||
"keyframes": "$ref:keyframes",
|
||||
"layerStyles": "$ref:layerStyles",
|
||||
"textStyles": "$ref:textStyles",
|
||||
"tokens": {
|
||||
"colors": "$ref:colors",
|
||||
"durations": "$ref:durations",
|
||||
"zIndex": "$ref:zIndex"
|
||||
},
|
||||
"semanticTokens": {
|
||||
"colors": {
|
||||
"fg": {
|
||||
"default": {
|
||||
"value": {
|
||||
"_light": "{colors.gray.12}",
|
||||
"_dark": "{colors.gray.12}"
|
||||
}
|
||||
},
|
||||
"muted": {
|
||||
"value": {
|
||||
"_light": "{colors.gray.11}",
|
||||
"_dark": "{colors.gray.11}"
|
||||
}
|
||||
},
|
||||
"subtle": {
|
||||
"value": {
|
||||
"_light": "{colors.gray.10}",
|
||||
"_dark": "{colors.gray.10}"
|
||||
}
|
||||
}
|
||||
},
|
||||
"border": {
|
||||
"value": {
|
||||
"_light": "{colors.gray.4}",
|
||||
"_dark": "{colors.gray.4}"
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"value": {
|
||||
"_light": "{colors.red.9}",
|
||||
"_dark": "{colors.red.9}"
|
||||
}
|
||||
}
|
||||
},
|
||||
"shadows": "$ref:shadows"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"registryDependencies": ["red", "green"]
|
||||
}
|
||||
659
park-registry.json
Normal file
659
park-registry.json
Normal file
File diff suppressed because one or more lines are too long
1
postcss.config.cjs
Normal file
1
postcss.config.cjs
Normal file
@ -0,0 +1 @@
|
||||
module.exports = { plugins: { '@pandacss/dev/postcss': {} } }
|
||||
66
scripts/configure-park.mjs
Normal file
66
scripts/configure-park.mjs
Normal file
@ -0,0 +1,66 @@
|
||||
import fs from 'node:fs'
|
||||
const items = JSON.parse(fs.readFileSync('park-registry.json', 'utf8').replace(/^\uFEFF/, ''))
|
||||
const imports = new Set()
|
||||
let config = {
|
||||
preflight: true,
|
||||
include: ['./src/**/*.{ts,tsx}'],
|
||||
outdir: 'styled-system',
|
||||
jsxFramework: 'react',
|
||||
}
|
||||
function merge(a, b) {
|
||||
for (const [k, v] of Object.entries(b || {})) {
|
||||
if (v && typeof v === 'object' && !Array.isArray(v)) {
|
||||
a[k] ??= {}
|
||||
merge(a[k], v)
|
||||
} else a[k] = v
|
||||
}
|
||||
return a
|
||||
}
|
||||
const recipes = [],
|
||||
slots = []
|
||||
for (const item of items) {
|
||||
for (const i of item.panda?.imports || [])
|
||||
imports.add(`import { ${i.name} } from './src/theme/${i.from.replaceAll('\\', '/')}'`)
|
||||
merge(config, item.panda?.extension)
|
||||
for (const f of item.files || [])
|
||||
if (f.type === 'registry:recipe' && f.path !== 'index.ts') {
|
||||
let n = f.content.match(/export const (\w+)/)?.[1]
|
||||
if (n)
|
||||
(f.content.includes('defineSlotRecipe') ? slots : recipes).push([
|
||||
n,
|
||||
f.path.replace(/\.ts$/, ''),
|
||||
])
|
||||
}
|
||||
}
|
||||
fs.writeFileSync(
|
||||
'src/theme/recipes/index.ts',
|
||||
[...recipes, ...slots].map(([n, p]) => `import {${n}} from './${p}'`).join('\n') +
|
||||
`\nexport const recipes = {${recipes.map(([n]) => n)}}\nexport const slotRecipes = {${slots.map(([n]) => n)}}\n`,
|
||||
)
|
||||
merge(config, {
|
||||
theme: {
|
||||
extend: {
|
||||
semanticTokens: {
|
||||
radii: {
|
||||
l1: { value: '2px' },
|
||||
l2: { value: '3px' },
|
||||
l3: { value: '4px' },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
let code = JSON.stringify(config, null, 2).replace(/"\$ref:([^"]+)"/g, '$1')
|
||||
fs.writeFileSync(
|
||||
'panda.config.ts',
|
||||
`import {defineConfig} from '@pandacss/dev'\n${[...imports].join('\n')}\nexport default defineConfig(${code})\n`,
|
||||
)
|
||||
for (const [file, from, to] of [
|
||||
['src/theme/global-css.ts', "colorPalette: 'gray'", "colorPalette: 'violet'"],
|
||||
[
|
||||
'src/theme/conditions.ts',
|
||||
"light: ':root &, .light &'",
|
||||
"light: ':root:not(.dark) &, .light &'",
|
||||
],
|
||||
])
|
||||
fs.writeFileSync(file, fs.readFileSync(file, 'utf8').replace(from, to))
|
||||
18
scripts/install-park.ps1
Normal file
18
scripts/install-park.ps1
Normal file
@ -0,0 +1,18 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$seen = @{}
|
||||
$items = [System.Collections.Generic.List[object]]::new()
|
||||
function Fetch-Item([string]$name) {
|
||||
if ($seen.ContainsKey($name)) { return }
|
||||
$seen[$name] = $true
|
||||
$item = Invoke-RestMethod "https://park-ui.com/registry/react/$name.json"
|
||||
foreach ($dep in $item.registryDependencies) { Fetch-Item $dep }
|
||||
$items.Add($item)
|
||||
foreach ($file in $item.files) {
|
||||
$base = if ($file.type -eq 'registry:ui') { 'src/components/ui' } elseif ($file.type -eq 'registry:recipe') { 'src/theme/recipes' } else { 'src/theme' }
|
||||
$dest = Join-Path $base $file.path
|
||||
New-Item -ItemType Directory -Force (Split-Path $dest) | Out-Null
|
||||
[System.IO.File]::WriteAllText((Join-Path (Get-Location) $dest), $file.content)
|
||||
}
|
||||
}
|
||||
foreach ($name in @('__init','violet','neutral','button','input','textarea','badge','dialog')) { Fetch-Item $name }
|
||||
$items | ConvertTo-Json -Depth 100 | Set-Content park-registry.json
|
||||
267
server/app.js
Normal file
267
server/app.js
Normal file
@ -0,0 +1,267 @@
|
||||
import express from 'express'
|
||||
import { randomBytes, createHash } from 'node:crypto'
|
||||
import { now, verifyPassword } from './db.js'
|
||||
import { Service, HttpError } from './service.js'
|
||||
import { readMailSettings, saveMailSettings, verifySmtp } from './mail-config.js'
|
||||
import { signatureValue } from './content.js'
|
||||
import { signatureTokens, signatureContext } from './signature-placeholders.js'
|
||||
export function createApp(db) {
|
||||
const app = express(),
|
||||
s = new Service(db)
|
||||
app.disable('x-powered-by')
|
||||
app.use((req, res, next) => {
|
||||
res.set({
|
||||
'X-Content-Type-Options': 'nosniff',
|
||||
'Referrer-Policy': 'same-origin',
|
||||
'Content-Security-Policy':
|
||||
"default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; script-src 'self' 'unsafe-inline'; frame-ancestors 'none'",
|
||||
})
|
||||
if (req.path.startsWith('/api')) res.set('Cache-Control', 'no-store')
|
||||
if (
|
||||
!['GET', 'HEAD', 'OPTIONS'].includes(req.method) &&
|
||||
req.headers.origin &&
|
||||
!new Set([
|
||||
process.env.APP_ORIGIN || `${req.protocol}://${req.headers.host}`,
|
||||
...(process.env.NODE_ENV !== 'production' && !process.env.APP_ORIGIN
|
||||
? ['http://127.0.0.1:5173', 'http://localhost:5173']
|
||||
: []),
|
||||
]).has(req.headers.origin)
|
||||
) {
|
||||
return res.status(403).json({ error: 'Ungültiger Ursprung.' })
|
||||
}
|
||||
next()
|
||||
})
|
||||
app.use(express.json({ limit: '30mb' }))
|
||||
app.get('/healthz', (req, res) => {
|
||||
s.get('SELECT 1 ok')
|
||||
res.json({ status: 'ok' })
|
||||
})
|
||||
const sessions = (req) => {
|
||||
const raw = req.headers.cookie
|
||||
?.split(';')
|
||||
.map((c) => c.trim())
|
||||
.find((c) => c.startsWith('syncova='))
|
||||
?.slice(8)
|
||||
return raw ? createHash('sha256').update(raw).digest('hex') : ''
|
||||
}
|
||||
const attempts = new Map()
|
||||
app.post('/api/login', (req, res) => {
|
||||
const key = req.ip
|
||||
const entry = attempts.get(key) || { n: 0, until: Date.now() + 900000 }
|
||||
if (entry.until < Date.now()) {
|
||||
entry.n = 0
|
||||
entry.until = Date.now() + 900000
|
||||
}
|
||||
if (entry.n >= 15)
|
||||
return res
|
||||
.status(429)
|
||||
.json({ error: 'Zu viele Anmeldeversuche. Bitte später erneut versuchen.' })
|
||||
entry.n++
|
||||
attempts.set(key, entry)
|
||||
if (
|
||||
typeof req.body.email !== 'string' ||
|
||||
typeof req.body.password !== 'string' ||
|
||||
req.body.password.length > 256
|
||||
)
|
||||
return res.status(400).json({ error: 'Ungültige Anmeldung.' })
|
||||
const u = s.get('SELECT * FROM users WHERE email=? AND active=1', req.body.email.toLowerCase())
|
||||
if (!u || !verifyPassword(req.body.password, u.password))
|
||||
return res.status(401).json({ error: 'E-Mail-Adresse oder Passwort falsch.' })
|
||||
attempts.delete(key)
|
||||
const raw = randomBytes(32).toString('hex')
|
||||
s.run('DELETE FROM sessions WHERE expires<?', now())
|
||||
s.run(
|
||||
'INSERT INTO sessions VALUES(?,?,?)',
|
||||
createHash('sha256').update(raw).digest('hex'),
|
||||
u.id,
|
||||
new Date(Date.now() + 43200000).toISOString(),
|
||||
)
|
||||
res.setHeader(
|
||||
'Set-Cookie',
|
||||
`syncova=${raw}; HttpOnly; SameSite=Strict; Path=/; Max-Age=43200${process.env.COOKIE_SECURE === 'true' ? '; Secure' : ''}`,
|
||||
)
|
||||
res.json({ ok: true })
|
||||
})
|
||||
app.use('/api', (req, res, next) => {
|
||||
try {
|
||||
const session = s.get(
|
||||
'SELECT user_id FROM sessions WHERE id=? AND expires>?',
|
||||
sessions(req),
|
||||
now(),
|
||||
)
|
||||
if (!session) throw new HttpError(401, 'Bitte anmelden.')
|
||||
req.user = s.user(session.user_id)
|
||||
next()
|
||||
} catch (e) {
|
||||
next(e)
|
||||
}
|
||||
})
|
||||
app.post('/api/logout', (req, res) => {
|
||||
s.run('DELETE FROM sessions WHERE id=?', sessions(req))
|
||||
res.setHeader('Set-Cookie', 'syncova=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0')
|
||||
res.json({ ok: true })
|
||||
})
|
||||
app.get('/api/bootstrap', (req, res) => res.json(s.bootstrap(req.user)))
|
||||
app.get('/api/signature-placeholders', (req, res) => res.json(signatureTokens))
|
||||
app.get('/api/tickets', (req, res) => res.json(s.tickets(req.user, req.query)))
|
||||
app.post('/api/tickets', (req, res) => res.json(s.createTicket(req.user, req.body)))
|
||||
app.get('/api/tickets/:id', (req, res) => res.json(s.detail(req.user, Number(req.params.id))))
|
||||
app.patch('/api/tickets/:id', (req, res) =>
|
||||
res.json(s.updateTicket(req.user, Number(req.params.id), req.body)),
|
||||
)
|
||||
app.post('/api/tickets/:id/goods', (req, res) =>
|
||||
res.json(s.goods(req.user, Number(req.params.id))),
|
||||
)
|
||||
app.post('/api/tickets/:id/messages', (req, res) =>
|
||||
res.json(s.reply(req.user, Number(req.params.id), req.body)),
|
||||
)
|
||||
app.post('/api/tickets/:id/signature-preview', (req, res) => {
|
||||
const t = s.ticket(req.user, Number(req.params.id), 'reply'),
|
||||
q = s.queue(t.queue_id)
|
||||
const signature = req.body.signature_id
|
||||
? q.signatures.find((v) => v.id === req.body.signature_id)
|
||||
: q.signatures.find((v) => v.default)
|
||||
if (!signature) throw new HttpError(400, 'Signatur gehört nicht zur Queue.')
|
||||
const from = req.body.from || q.addresses.find((a) => a.default && a.outgoing)?.email
|
||||
if (!q.addresses.some((a) => a.email === from && a.outgoing))
|
||||
throw new HttpError(400, 'Absender ist für diese Queue nicht freigegeben.')
|
||||
res.json(signatureValue(signature, signatureContext(s, req.user, q, t, from)))
|
||||
})
|
||||
app.get('/api/attachments/:id', (req, res) => {
|
||||
const a = s.get(
|
||||
'SELECT a.*,m.ticket_id FROM attachments a JOIN messages m ON m.id=a.message_id WHERE a.id=?',
|
||||
req.params.id,
|
||||
)
|
||||
if (!a) throw new HttpError(404, 'Anhang nicht gefunden.')
|
||||
s.ticket(req.user, a.ticket_id)
|
||||
res.set({
|
||||
'Content-Type': 'application/octet-stream',
|
||||
'Content-Disposition': `attachment; filename*=UTF-8''${encodeURIComponent(a.name)}`,
|
||||
'Content-Security-Policy': "sandbox; default-src 'none'",
|
||||
})
|
||||
res.send(a.content)
|
||||
})
|
||||
app.get('/api/notifications', (req, res) => res.json(s.notifications(req.user)))
|
||||
app.post('/api/notifications/read', (req, res) => {
|
||||
s.readNotifications(req.user, req.body.id)
|
||||
res.json({ ok: true })
|
||||
})
|
||||
app.put('/api/preferences', (req, res) => {
|
||||
const clean = {}
|
||||
for (const e of ['new', 'reply', 'assigned', 'reopened'])
|
||||
clean[e] = { bell: !!req.body[e]?.bell, email: !!req.body[e]?.email }
|
||||
s.run('UPDATE users SET prefs=? WHERE id=?', JSON.stringify(clean), req.user.id)
|
||||
res.json(clean)
|
||||
})
|
||||
app.post('/api/queues', (req, res) => res.json(s.saveQueue(req.user, null, req.body)))
|
||||
app.put('/api/queues/:id', (req, res) => res.json(s.saveQueue(req.user, req.params.id, req.body)))
|
||||
app.get('/api/queues/:id/mail', (req, res) => {
|
||||
const settings = readMailSettings(s, req.user, req.params.id)
|
||||
settings.imap.runtime.running = !!app.locals.worker?.inbound.running.has(req.params.id)
|
||||
res.json(settings)
|
||||
})
|
||||
app.put('/api/queues/:id/mail', (req, res) =>
|
||||
res.json(saveMailSettings(s, req.user, req.params.id, req.body)),
|
||||
)
|
||||
app.post('/api/queues/:id/mail/verify', async (req, res) =>
|
||||
res.json(await verifySmtp(s, req.user, req.params.id)),
|
||||
)
|
||||
app.post('/api/queues/:id/mail/verify-imap', async (req, res) => {
|
||||
s.require(req.user, req.params.id, 'queue')
|
||||
res.json(await app.locals.worker.inbound.verify(req.user, req.params.id))
|
||||
})
|
||||
app.post('/api/queues/:id/mail/fetch', async (req, res) => {
|
||||
s.require(req.user, req.params.id, 'queue')
|
||||
res.json(await app.locals.worker.inbound.run(req.params.id, { actor: req.user.id }))
|
||||
})
|
||||
app.put('/api/queues/:id/statuses', (req, res) =>
|
||||
res.json(s.saveStatuses(req.user, req.params.id, req.body.statuses, req.body.mapping)),
|
||||
)
|
||||
app.put('/api/queues/:id/signatures', (req, res) => {
|
||||
s.saveSignatures(req.user, req.params.id, req.body.signatures)
|
||||
res.json({ ok: true })
|
||||
})
|
||||
app.post('/api/queues/:id/signatures/preview', (req, res) => {
|
||||
s.require(req.user, req.params.id, 'signatures')
|
||||
const q = s.queue(req.params.id),
|
||||
body = req.body.body ?? req.body.html
|
||||
const format = req.body.format || (req.body.html !== undefined ? 'html' : 'text')
|
||||
if (typeof body !== 'string' || body.length > 100000 || !['text', 'html'].includes(format))
|
||||
throw new HttpError(400, 'Ungültige Signatur (max. 100.000 Zeichen).')
|
||||
const automatic = req.body.mode === 'system'
|
||||
const example = {
|
||||
id: 123,
|
||||
subject: 'Beispielanfrage',
|
||||
customer_name: 'Anna Beispiel',
|
||||
customer: 'kunde@example.org',
|
||||
status_id: q.statuses.find((v) => v.behavior === 'open')?.id,
|
||||
assignee: automatic ? null : req.user.id,
|
||||
}
|
||||
res.json(
|
||||
signatureValue(
|
||||
{ body, format },
|
||||
signatureContext(s, automatic ? null : req.user, q, example),
|
||||
),
|
||||
)
|
||||
})
|
||||
app.get('/api/queues/:id/deletion', (req, res) =>
|
||||
res.json(s.queueDeletion(req.user, req.params.id)),
|
||||
)
|
||||
app.delete('/api/queues/:id', (req, res) => {
|
||||
if (app.locals.worker?.inbound.running.has(req.params.id))
|
||||
throw new HttpError(
|
||||
409,
|
||||
'Postfachabruf läuft. Empfang zuerst deaktivieren und den Abruf abwarten.',
|
||||
)
|
||||
res.json(s.deleteQueue(req.user, req.params.id, req.body))
|
||||
})
|
||||
app.get('/api/admin', (req, res) => res.json(s.admin(req.user)))
|
||||
app.post('/api/users', (req, res) => res.json(s.saveUser(req.user, req.body)))
|
||||
app.post('/api/groups', (req, res) => res.json(s.saveGroup(req.user, req.body)))
|
||||
app.get('/api/users/:id/deletion', (req, res) =>
|
||||
res.json(s.userDeletion(req.user, req.params.id)),
|
||||
)
|
||||
app.delete('/api/users/:id', (req, res) =>
|
||||
res.json(s.deleteUser(req.user, req.params.id, req.body)),
|
||||
)
|
||||
app.get('/api/groups/:id/deletion', (req, res) =>
|
||||
res.json(s.groupDeletion(req.user, req.params.id)),
|
||||
)
|
||||
app.delete('/api/groups/:id', (req, res) =>
|
||||
res.json(s.deleteGroup(req.user, req.params.id, req.body)),
|
||||
)
|
||||
app.get('/api/logs', (req, res) => res.json(s.logs(req.user)))
|
||||
app.get('/api/outbox', (req, res) => {
|
||||
s.require(req.user, '*', 'logs')
|
||||
res.json(
|
||||
s.all('SELECT id,state,attempts,error,next_at FROM outbox ORDER BY next_at DESC LIMIT 100'),
|
||||
)
|
||||
})
|
||||
app.post('/api/dev/incoming', (req, res) => {
|
||||
if (process.env.MAIL_MODE === 'smtp' || process.env.NODE_ENV === 'production')
|
||||
throw new HttpError(404, 'Entwicklungsadapter deaktiviert.')
|
||||
s.require(req.user, '*', 'queue')
|
||||
try {
|
||||
res.json(s.ingest(req.body))
|
||||
} catch (e) {
|
||||
s.audit(req.user.id, 'E-Mail-Verarbeitung fehlgeschlagen', 'development', null, {
|
||||
error: e.name,
|
||||
})
|
||||
throw e
|
||||
}
|
||||
})
|
||||
app.get('/api/dev/mail', (req, res) => {
|
||||
if (process.env.NODE_ENV === 'production')
|
||||
throw new HttpError(404, 'Entwicklungsadapter deaktiviert.')
|
||||
s.require(req.user, '*', 'logs')
|
||||
res.json(s.all('SELECT * FROM dev_mail ORDER BY created_at DESC LIMIT 100'))
|
||||
})
|
||||
app.use((e, req, res, next) => {
|
||||
res.status(e.status || 500).json({
|
||||
error: e.status
|
||||
? e.message
|
||||
: 'Die Aktion konnte nicht ausgeführt werden. Bitte Eingaben und Serverkonfiguration prüfen.',
|
||||
})
|
||||
})
|
||||
return { app, service: s }
|
||||
}
|
||||
130
server/content.js
Normal file
130
server/content.js
Normal file
@ -0,0 +1,130 @@
|
||||
import sanitizeHtml from 'sanitize-html'
|
||||
import { convert } from 'html-to-text'
|
||||
import { HttpError } from './service.js'
|
||||
import { expandSignature } from './signature-placeholders.js'
|
||||
export const escapeHtml = (value) =>
|
||||
String(value).replace(
|
||||
/[&<>"']/g,
|
||||
(c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c],
|
||||
)
|
||||
export function safeHtml(html) {
|
||||
return sanitizeHtml(html, {
|
||||
allowedTags: [
|
||||
'p',
|
||||
'br',
|
||||
'b',
|
||||
'strong',
|
||||
'i',
|
||||
'em',
|
||||
'u',
|
||||
's',
|
||||
'div',
|
||||
'span',
|
||||
'a',
|
||||
'ul',
|
||||
'ol',
|
||||
'li',
|
||||
'table',
|
||||
'thead',
|
||||
'tbody',
|
||||
'tr',
|
||||
'td',
|
||||
'th',
|
||||
'img',
|
||||
'hr',
|
||||
],
|
||||
allowedAttributes: {
|
||||
'*': ['style'],
|
||||
a: ['href', 'title'],
|
||||
img: ['src', 'alt', 'width', 'height'],
|
||||
td: ['colspan', 'rowspan'],
|
||||
th: ['colspan', 'rowspan'],
|
||||
},
|
||||
allowedSchemes: ['https', 'http', 'mailto', 'tel'],
|
||||
allowedSchemesByTag: { img: ['https', 'data'] },
|
||||
allowProtocolRelative: false,
|
||||
allowedStyles: {
|
||||
'*': {
|
||||
color: [/^#[0-9a-f]{3,8}$/i, /^[a-z]+$/i, /^rgb\([\d\s,]+\)$/i],
|
||||
'background-color': [/^#[0-9a-f]{3,8}$/i, /^[a-z]+$/i],
|
||||
'font-family': [/^[a-z\s,\-']+$/i],
|
||||
'font-size': [/^\d{1,2}(px|pt)$/],
|
||||
'font-weight': [/^(normal|bold|[1-9]00)$/],
|
||||
'text-align': [/^(left|right|center|justify)$/],
|
||||
'text-decoration': [/^(none|underline|line-through)$/],
|
||||
'line-height': [/^[\d.]+(px|em|%)?$/],
|
||||
padding: [/^[\d\s.]+(px|pt)$/],
|
||||
'border-collapse': [/^(collapse|separate)$/],
|
||||
},
|
||||
},
|
||||
transformTags: {
|
||||
img: (tag, attribs) => {
|
||||
if (
|
||||
attribs.src?.startsWith('data:') &&
|
||||
!/^data:image\/(png|jpeg|gif|webp);base64,[a-z\d+/=]+$/i.test(attribs.src)
|
||||
)
|
||||
delete attribs.src
|
||||
return { tagName: tag, attribs }
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
export function plainHtml(html) {
|
||||
return convert(html, {
|
||||
wordwrap: false,
|
||||
selectors: [
|
||||
{ selector: 'img', format: 'skip' },
|
||||
{ selector: 'a', options: { hideLinkHrefIfSameAsText: true } },
|
||||
],
|
||||
}).trim()
|
||||
}
|
||||
export function signatureValue(s, context) {
|
||||
return s?.format === 'html'
|
||||
? (() => {
|
||||
const html = safeHtml(expandSignature(safeHtml(s.body), context, escapeHtml))
|
||||
return { html, text: plainHtml(html) }
|
||||
})()
|
||||
: { html: null, text: expandSignature(s?.body || '', context) }
|
||||
}
|
||||
export function composeContent(body, signature, context) {
|
||||
const sig = signatureValue(signature, context)
|
||||
let base = body.trimEnd()
|
||||
if (sig.text && base.endsWith(sig.text)) base = base.slice(0, -sig.text.length).trimEnd()
|
||||
return {
|
||||
text: base + (sig.text ? '\n\n' + sig.text : ''),
|
||||
html: sig.html
|
||||
? `<div style="white-space:pre-wrap">${escapeHtml(base).replace(/\n/g, '<br>')}</div><br>${sig.html}`
|
||||
: null,
|
||||
}
|
||||
}
|
||||
export function normaliseAttachments(values = []) {
|
||||
if (!Array.isArray(values) || values.length > 20)
|
||||
throw new HttpError(400, 'Höchstens 20 Anhänge pro Nachricht.')
|
||||
let total = 0
|
||||
return values.map((a) => {
|
||||
if (
|
||||
!a ||
|
||||
typeof a.content !== 'string' ||
|
||||
a.content.length > 13981016 ||
|
||||
a.content.length % 4 !== 0 ||
|
||||
/[^a-z\d+/=]/i.test(a.content)
|
||||
)
|
||||
throw new HttpError(400, 'Ungültiger Anhang (maximal 10 MB pro Datei).')
|
||||
const content = Buffer.from(a.content, 'base64')
|
||||
if (content.length > 10 * 1024 * 1024 || content.toString('base64') !== a.content)
|
||||
throw new HttpError(413, 'Anhang ist zu groß oder ungültig.')
|
||||
total += content.length
|
||||
if (total > 20 * 1024 * 1024)
|
||||
throw new HttpError(413, 'Anhänge dürfen zusammen höchstens 20 MB groß sein.')
|
||||
return {
|
||||
name: String(a.name || 'Anhang')
|
||||
.replace(/[\x00-\x1f\x7f/\\]/g, '_')
|
||||
.slice(0, 200),
|
||||
mime:
|
||||
typeof a.mime === 'string' && /^[a-z\d!#$&^_.+-]+\/[a-z\d!#$&^_.+-]+$/i.test(a.mime)
|
||||
? a.mime
|
||||
: 'application/octet-stream',
|
||||
content,
|
||||
}
|
||||
})
|
||||
}
|
||||
234
server/db.js
Normal file
234
server/db.js
Normal file
@ -0,0 +1,234 @@
|
||||
import Database from 'better-sqlite3'
|
||||
import { randomUUID, scryptSync, randomBytes, timingSafeEqual } from 'node:crypto'
|
||||
import { mkdirSync } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
export const uid = () => randomUUID()
|
||||
export const now = () => new Date().toISOString()
|
||||
export const actions = [
|
||||
'view',
|
||||
'reply',
|
||||
'note',
|
||||
'status',
|
||||
'assign',
|
||||
'move',
|
||||
'goods',
|
||||
'queue',
|
||||
'statuses',
|
||||
'signatures',
|
||||
'users',
|
||||
'logs',
|
||||
]
|
||||
export const behaviors = [
|
||||
'new',
|
||||
'open',
|
||||
'active',
|
||||
'wait_customer',
|
||||
'wait_date',
|
||||
'wait_goods',
|
||||
'closed',
|
||||
]
|
||||
export function passwordHash(p) {
|
||||
const salt = randomBytes(16).toString('hex')
|
||||
return salt + ':' + scryptSync(p, salt, 64).toString('hex')
|
||||
}
|
||||
export function verifyPassword(p, hash) {
|
||||
const [salt, h] = hash.split(':')
|
||||
return timingSafeEqual(scryptSync(p, salt, 64), Buffer.from(h, 'hex'))
|
||||
}
|
||||
export function openDb(file = process.env.DB_PATH || 'data/syncova.db') {
|
||||
if (file !== ':memory:') mkdirSync(path.dirname(file), { recursive: true })
|
||||
const db = new Database(file)
|
||||
db.pragma('journal_mode = WAL')
|
||||
db.pragma('foreign_keys = ON')
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS users(id TEXT PRIMARY KEY,name TEXT NOT NULL,email TEXT UNIQUE NOT NULL,password TEXT NOT NULL,active INTEGER NOT NULL DEFAULT 1,prefs TEXT NOT NULL DEFAULT '{}');
|
||||
CREATE TABLE IF NOT EXISTS groups_(id TEXT PRIMARY KEY,name TEXT NOT NULL,permissions TEXT NOT NULL);
|
||||
CREATE TABLE IF NOT EXISTS memberships(user_id TEXT REFERENCES users(id),group_id TEXT REFERENCES groups_(id),PRIMARY KEY(user_id,group_id));
|
||||
CREATE TABLE IF NOT EXISTS sessions(id TEXT PRIMARY KEY,user_id TEXT REFERENCES users(id),expires TEXT NOT NULL);
|
||||
CREATE TABLE IF NOT EXISTS queues(id TEXT PRIMARY KEY,name TEXT NOT NULL,color TEXT NOT NULL,addresses TEXT NOT NULL,signatures TEXT NOT NULL);
|
||||
CREATE TABLE IF NOT EXISTS queue_mail(queue_id TEXT PRIMARY KEY REFERENCES queues(id),smtp TEXT NOT NULL,password TEXT NOT NULL DEFAULT '',acknowledgement TEXT NOT NULL);
|
||||
CREATE TABLE IF NOT EXISTS queue_inbound(queue_id TEXT PRIMARY KEY REFERENCES queues(id),config TEXT NOT NULL,password TEXT NOT NULL DEFAULT '',next_run TEXT,last_run TEXT,last_success TEXT,error TEXT,revision INTEGER NOT NULL DEFAULT 0);
|
||||
CREATE TABLE IF NOT EXISTS inbound_receipts(queue_id TEXT REFERENCES queues(id),mailbox_key TEXT NOT NULL,uid INTEGER NOT NULL,outcome TEXT NOT NULL DEFAULT 'imported',PRIMARY KEY(queue_id,mailbox_key,uid));
|
||||
CREATE TABLE IF NOT EXISTS manual_requests(user_id TEXT REFERENCES users(id),request_key TEXT NOT NULL,ticket_id INTEGER REFERENCES tickets(id),PRIMARY KEY(user_id,request_key));
|
||||
CREATE TABLE IF NOT EXISTS statuses(id TEXT PRIMARY KEY,queue_id TEXT REFERENCES queues(id),name TEXT NOT NULL,color TEXT NOT NULL,behavior TEXT NOT NULL,position INTEGER NOT NULL,active INTEGER NOT NULL DEFAULT 1);
|
||||
CREATE TABLE IF NOT EXISTS tickets(id INTEGER PRIMARY KEY AUTOINCREMENT,subject TEXT NOT NULL,customer TEXT NOT NULL,customer_name TEXT NOT NULL,queue_id TEXT REFERENCES queues(id),status_id TEXT REFERENCES statuses(id),assignee TEXT REFERENCES users(id),due_at TEXT,timezone TEXT,revision INTEGER NOT NULL DEFAULT 0,created_at TEXT NOT NULL,updated_at TEXT NOT NULL);
|
||||
CREATE TABLE IF NOT EXISTS messages(id TEXT PRIMARY KEY,ticket_id INTEGER REFERENCES tickets(id),kind TEXT NOT NULL,sender TEXT NOT NULL,recipient TEXT NOT NULL,body TEXT NOT NULL,message_id TEXT UNIQUE NOT NULL,refs TEXT NOT NULL DEFAULT '[]',created_at TEXT NOT NULL,delivery TEXT NOT NULL DEFAULT 'received');
|
||||
CREATE TABLE IF NOT EXISTS attachments(id TEXT PRIMARY KEY,message_id TEXT REFERENCES messages(id),name TEXT NOT NULL,mime TEXT NOT NULL,content BLOB NOT NULL);
|
||||
CREATE TABLE IF NOT EXISTS message_html(message_id TEXT PRIMARY KEY REFERENCES messages(id),html TEXT NOT NULL);
|
||||
CREATE TABLE IF NOT EXISTS audits(id INTEGER PRIMARY KEY AUTOINCREMENT,ticket_id INTEGER REFERENCES tickets(id),queue_id TEXT,actor TEXT NOT NULL,action TEXT NOT NULL,entity TEXT NOT NULL,before_value TEXT,after_value TEXT,created_at TEXT NOT NULL);
|
||||
CREATE TRIGGER IF NOT EXISTS audit_no_update BEFORE UPDATE ON audits BEGIN SELECT RAISE(ABORT,'Audit is immutable'); END;
|
||||
CREATE TRIGGER IF NOT EXISTS audit_no_delete BEFORE DELETE ON audits BEGIN SELECT RAISE(ABORT,'Audit is immutable'); END;
|
||||
CREATE TABLE IF NOT EXISTS notifications(id TEXT PRIMARY KEY,user_id TEXT REFERENCES users(id),ticket_id INTEGER REFERENCES tickets(id),event TEXT NOT NULL,event_key TEXT NOT NULL,title TEXT NOT NULL,is_read INTEGER NOT NULL DEFAULT 0,created_at TEXT NOT NULL,UNIQUE(user_id,event_key));
|
||||
CREATE TABLE IF NOT EXISTS outbox(id TEXT PRIMARY KEY,message_id TEXT REFERENCES messages(id),notification_id TEXT REFERENCES notifications(id),payload TEXT NOT NULL,state TEXT NOT NULL DEFAULT 'pending',attempts INTEGER NOT NULL DEFAULT 0,next_at TEXT NOT NULL,error TEXT);
|
||||
CREATE TABLE IF NOT EXISTS dev_mail(id TEXT PRIMARY KEY,payload TEXT NOT NULL,created_at TEXT NOT NULL);
|
||||
CREATE INDEX IF NOT EXISTS tickets_due ON tickets(due_at);
|
||||
CREATE INDEX IF NOT EXISTS messages_ticket ON messages(ticket_id);
|
||||
CREATE INDEX IF NOT EXISTS notifications_user ON notifications(user_id);
|
||||
`)
|
||||
for (const column of ['phone', 'job_title', 'department'])
|
||||
if (!db.pragma('table_info(users)').some((c) => c.name === column))
|
||||
db.exec(`ALTER TABLE users ADD COLUMN ${column} TEXT NOT NULL DEFAULT ''`)
|
||||
if (!db.pragma('table_info(queues)').some((c) => c.name === 'deleted_at'))
|
||||
db.exec('ALTER TABLE queues ADD COLUMN deleted_at TEXT')
|
||||
if (!db.pragma('table_info(users)').some((c) => c.name === 'deleted_at'))
|
||||
db.exec('ALTER TABLE users ADD COLUMN deleted_at TEXT')
|
||||
if (!db.pragma('table_info(inbound_receipts)').some((column) => column.name === 'outcome'))
|
||||
db.exec("ALTER TABLE inbound_receipts ADD COLUMN outcome TEXT NOT NULL DEFAULT 'imported'")
|
||||
return db
|
||||
}
|
||||
export function createQueue(db, { id = uid(), name, color = '#0f766e', addresses, signatures }) {
|
||||
db.prepare('INSERT INTO queues(id,name,color,addresses,signatures) VALUES(?,?,?,?,?)').run(
|
||||
id,
|
||||
name,
|
||||
color,
|
||||
JSON.stringify(addresses),
|
||||
JSON.stringify(signatures),
|
||||
)
|
||||
const names = [
|
||||
'Neu',
|
||||
'Offen',
|
||||
'In Bearbeitung',
|
||||
'Warten auf Kunde',
|
||||
'Warten auf Termin',
|
||||
'Warten auf Ware',
|
||||
'Erledigt',
|
||||
]
|
||||
const colors = ['#3b82f6', '#0d9488', '#8b5cf6', '#d97706', '#6366f1', '#c26b31', '#64748b']
|
||||
names.forEach((n, i) =>
|
||||
db
|
||||
.prepare('INSERT INTO statuses VALUES(?,?,?,?,?,?,1)')
|
||||
.run(uid(), id, n, colors[i], behaviors[i], i),
|
||||
)
|
||||
return id
|
||||
}
|
||||
export function seed(db) {
|
||||
if (db.prepare('SELECT count(*) n FROM users').get().n) return
|
||||
if (process.env.NODE_ENV === 'production' && !process.env.ADMIN_PASSWORD)
|
||||
throw Error('ADMIN_PASSWORD ist für die Ersteinrichtung erforderlich.')
|
||||
db.transaction(() => {
|
||||
db.prepare('INSERT INTO users(id,name,email,password) VALUES(?,?,?,?)').run(
|
||||
'admin',
|
||||
'Jana Weber',
|
||||
process.env.ADMIN_EMAIL || 'admin@syncova.local',
|
||||
passwordHash(process.env.ADMIN_PASSWORD || 'Syncova-Demo-2026!'),
|
||||
)
|
||||
db.prepare('INSERT INTO groups_ VALUES(?,?,?)').run(
|
||||
'admins',
|
||||
'Administrator',
|
||||
JSON.stringify({ '*': actions }),
|
||||
)
|
||||
db.prepare('INSERT INTO memberships VALUES(?,?)').run('admin', 'admins')
|
||||
for (const [id, name, email, color] of [
|
||||
['support', 'Support', 'support@syncova.local', '#0d9488'],
|
||||
['vertrieb', 'Vertrieb', 'vertrieb@syncova.local', '#8b5cf6'],
|
||||
['service', 'Service', 'service@syncova.local', '#d97706'],
|
||||
]) {
|
||||
createQueue(db, {
|
||||
id,
|
||||
name,
|
||||
color,
|
||||
addresses: [
|
||||
{ email, incoming: true, outgoing: true, default: true },
|
||||
{ email: `${id}.team@syncova.local`, incoming: true, outgoing: true, default: false },
|
||||
],
|
||||
signatures: [
|
||||
{
|
||||
id: uid(),
|
||||
name: 'Standard',
|
||||
body: `Freundliche Grüße\nIhr ${name}-Team\nSyncova`,
|
||||
default: true,
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
for (const [id, name, perms] of [
|
||||
['manager', 'Queue-Verantwortlicher', actions.filter((a) => a !== 'users')],
|
||||
['agent', 'Bearbeiter', ['view', 'reply', 'note', 'status', 'assign', 'move', 'goods']],
|
||||
['reader', 'Leser', ['view']],
|
||||
])
|
||||
db.prepare('INSERT INTO groups_ VALUES(?,?,?)').run(
|
||||
id,
|
||||
name,
|
||||
JSON.stringify({ support: perms }),
|
||||
)
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
for (const [id, name, email, group] of [
|
||||
['leon', 'Leon Fischer', 'leon@syncova.local', 'agent'],
|
||||
['mira', 'Mira Hoffmann', 'mira@syncova.local', 'reader'],
|
||||
]) {
|
||||
db.prepare('INSERT INTO users(id,name,email,password) VALUES(?,?,?,?)').run(
|
||||
id,
|
||||
name,
|
||||
email,
|
||||
passwordHash('Syncova-Demo-2026!'),
|
||||
)
|
||||
db.prepare('INSERT INTO memberships VALUES(?,?)').run(id, group)
|
||||
}
|
||||
const subjects = [
|
||||
'Rückfrage zu meiner Bestellung #8042',
|
||||
'Zugang zum Kundenportal nicht möglich',
|
||||
'Angebot für 25 Arbeitsplätze',
|
||||
'Liefertermin für Ersatzteile',
|
||||
'Rechnungskorrektur für Oktober',
|
||||
'Vielen Dank für die schnelle Hilfe',
|
||||
'Frage zur Einrichtung der Schnittstelle',
|
||||
'Austauschgerät noch nicht angekommen',
|
||||
]
|
||||
subjects.forEach((subject, i) => {
|
||||
const q = i === 2 ? 'vertrieb' : i === 3 || i === 7 ? 'service' : 'support'
|
||||
const behavior = [
|
||||
'new',
|
||||
'open',
|
||||
'open',
|
||||
'wait_goods',
|
||||
'active',
|
||||
'closed',
|
||||
'wait_customer',
|
||||
'wait_date',
|
||||
][i]
|
||||
const status = db
|
||||
.prepare('SELECT id FROM statuses WHERE queue_id=? AND behavior=?')
|
||||
.get(q, behavior)
|
||||
const at = new Date(Date.now() - (i + 1) * 3500000).toISOString()
|
||||
const name = [
|
||||
'Anna Bergmann',
|
||||
'Thomas Klein',
|
||||
'Sarah Wagner',
|
||||
'Michael Braun',
|
||||
'Laura Schneider',
|
||||
'Felix Richter',
|
||||
'Julia Neumann',
|
||||
'David Schulz',
|
||||
][i]
|
||||
const id = db
|
||||
.prepare(
|
||||
'INSERT INTO tickets(subject,customer,customer_name,queue_id,status_id,assignee,due_at,timezone,created_at,updated_at) VALUES(?,?,?,?,?,?,?,?,?,?)',
|
||||
)
|
||||
.run(
|
||||
subject,
|
||||
`kunde${i + 1}@example.com`,
|
||||
name,
|
||||
q,
|
||||
status.id,
|
||||
i % 2 ? 'admin' : null,
|
||||
behavior === 'wait_date' ? new Date(Date.now() + 86400000).toISOString() : null,
|
||||
behavior === 'wait_date' ? 'Europe/Berlin' : null,
|
||||
at,
|
||||
at,
|
||||
).lastInsertRowid
|
||||
db.prepare(
|
||||
'INSERT INTO messages(id,ticket_id,kind,sender,recipient,body,message_id,created_at) VALUES(?,?,?,?,?,?,?,?)',
|
||||
).run(
|
||||
uid(),
|
||||
id,
|
||||
'incoming',
|
||||
`kunde${i + 1}@example.com`,
|
||||
`${q}@syncova.local`,
|
||||
`Guten Tag,\n\n${subject}. Können Sie mir hierzu bitte weiterhelfen?\n\nVielen Dank und freundliche Grüße\n${name}`,
|
||||
`<seed-${id}@example.com>`,
|
||||
at,
|
||||
)
|
||||
})
|
||||
}
|
||||
})()
|
||||
}
|
||||
33
server/import-data.js
Normal file
33
server/import-data.js
Normal file
@ -0,0 +1,33 @@
|
||||
// One-shot import into a NEW Docker volume. Stop the source server before running.
|
||||
import { existsSync, copyFileSync, chmodSync, constants } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import Database from 'better-sqlite3'
|
||||
import { decryptSecret } from './secrets.js'
|
||||
const source = '/import',
|
||||
target = path.dirname(process.env.DB_PATH || '/app/data/syncova.db')
|
||||
if (existsSync(path.join(target, 'syncova.db')))
|
||||
throw Error('Ziel enthält bereits eine Datenbank. Es wird nichts überschrieben.')
|
||||
if (!existsSync(path.join(source, 'syncova.db')))
|
||||
throw Error('Quelldatei /import/syncova.db fehlt.')
|
||||
for (const file of ['syncova.db', 'syncova.db-wal', 'smtp.key'])
|
||||
if (existsSync(path.join(source, file))) {
|
||||
copyFileSync(path.join(source, file), path.join(target, file), constants.COPYFILE_EXCL)
|
||||
chmodSync(path.join(target, file), 0o600)
|
||||
}
|
||||
const db = new Database(path.join(target, 'syncova.db'))
|
||||
try {
|
||||
for (const table of ['queue_mail', 'queue_inbound'])
|
||||
if (db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name=?").get(table)) {
|
||||
const row = db.prepare(`SELECT password FROM ${table} WHERE password!='' LIMIT 1`).get()
|
||||
if (row && !process.env.SMTP_ENCRYPTION_KEY && !existsSync(path.join(target, 'smtp.key')))
|
||||
throw Error('Mail-Schlüssel fehlt. smtp.key übernehmen oder SMTP_ENCRYPTION_KEY setzen.')
|
||||
if (row && !decryptSecret(row.password)) throw Error('Mail-Schlüssel fehlt oder passt nicht.')
|
||||
}
|
||||
if (db.pragma('integrity_check', { simple: true }) !== 'ok')
|
||||
throw Error('Datenbankprüfung fehlgeschlagen.')
|
||||
} finally {
|
||||
db.close()
|
||||
}
|
||||
console.log(
|
||||
'Import erfolgreich: Datenbank, Nachrichten, Anhänge, Konfiguration und Mail-Schlüssel übernommen. Bestehende Benutzerkonten bleiben gültig.',
|
||||
)
|
||||
407
server/inbound.js
Normal file
407
server/inbound.js
Normal file
@ -0,0 +1,407 @@
|
||||
import { ImapFlow } from 'imapflow'
|
||||
import { simpleParser } from 'mailparser'
|
||||
import { CronExpressionParser } from 'cron-parser'
|
||||
import { encryptSecret, decryptSecret } from './secrets.js'
|
||||
import { HttpError } from './service.js'
|
||||
import { now } from './db.js'
|
||||
export function nextFetch(config, at = new Date()) {
|
||||
if (!config.enabled) return null
|
||||
if (config.schedule.mode === 'interval')
|
||||
return new Date(+at + config.schedule.seconds * 1000).toISOString()
|
||||
return CronExpressionParser.parse(config.schedule.cron, {
|
||||
currentDate: at,
|
||||
tz: config.schedule.timezone,
|
||||
})
|
||||
.next()
|
||||
.toDate()
|
||||
.toISOString()
|
||||
}
|
||||
function ensure(s, id) {
|
||||
s.queue(id)
|
||||
let row = s.get('SELECT * FROM queue_inbound WHERE queue_id=?', id)
|
||||
if (!row) {
|
||||
const config = {
|
||||
enabled: !!process.env.IMAP_HOST,
|
||||
host: process.env.IMAP_HOST || '',
|
||||
port: Number(process.env.IMAP_PORT || 993),
|
||||
security: 'tls',
|
||||
username: process.env.IMAP_USER || '',
|
||||
folder: 'INBOX',
|
||||
onlyUnread: true,
|
||||
markRead: true,
|
||||
schedule: { mode: 'interval', seconds: 30, cron: '* * * * *', timezone: 'Europe/Berlin' },
|
||||
}
|
||||
s.run(
|
||||
'INSERT INTO queue_inbound(queue_id,config,password,next_run) VALUES(?,?,?,?)',
|
||||
id,
|
||||
JSON.stringify(config),
|
||||
process.env.IMAP_PASSWORD ? encryptSecret(process.env.IMAP_PASSWORD) : '',
|
||||
config.enabled ? now() : null,
|
||||
)
|
||||
row = s.get('SELECT * FROM queue_inbound WHERE queue_id=?', id)
|
||||
}
|
||||
return row
|
||||
}
|
||||
export function inboundSettings(s, id) {
|
||||
const r = ensure(s, id)
|
||||
return {
|
||||
...JSON.parse(r.config),
|
||||
passwordSet: !!r.password,
|
||||
runtime: {
|
||||
nextRun: r.next_run,
|
||||
lastRun: r.last_run,
|
||||
lastSuccess: r.last_success,
|
||||
error: r.error,
|
||||
},
|
||||
}
|
||||
}
|
||||
export function saveInbound(s, user, id, data, password) {
|
||||
s.require(user, id, 'queue')
|
||||
const row = ensure(s, id),
|
||||
before = inboundSettings(s, id)
|
||||
if (
|
||||
!data ||
|
||||
typeof data.enabled !== 'boolean' ||
|
||||
!['tls', 'starttls'].includes(data.security) ||
|
||||
typeof data.host !== 'string' ||
|
||||
typeof data.username !== 'string' ||
|
||||
!Number.isInteger(Number(data.port)) ||
|
||||
Number(data.port) < 1 ||
|
||||
Number(data.port) > 65535 ||
|
||||
typeof data.folder !== 'string' ||
|
||||
!data.folder.trim() ||
|
||||
data.folder.length > 200 ||
|
||||
/[\r\n\0]/.test(data.folder) ||
|
||||
typeof data.onlyUnread !== 'boolean' ||
|
||||
typeof data.markRead !== 'boolean'
|
||||
)
|
||||
throw new HttpError(400, 'Gültige IMAP-Einstellungen und einen Postfachordner angeben.')
|
||||
if (data.enabled && (!/^[a-z0-9][a-z0-9.:-]*$/i.test(data.host) || !data.username.trim()))
|
||||
throw new HttpError(400, 'IMAP-Server und Benutzername fehlen.')
|
||||
const p = data.schedule
|
||||
if (
|
||||
!p ||
|
||||
!['interval', 'cron'].includes(p.mode) ||
|
||||
!Number.isInteger(Number(p.seconds)) ||
|
||||
Number(p.seconds) < 15 ||
|
||||
Number(p.seconds) > 86400 ||
|
||||
typeof p.cron !== 'string' ||
|
||||
p.cron.length > 120 ||
|
||||
typeof p.timezone !== 'string'
|
||||
)
|
||||
throw new HttpError(400, 'Abrufintervall muss zwischen 15 und 86.400 Sekunden liegen.')
|
||||
try {
|
||||
new Intl.DateTimeFormat('de', { timeZone: p.timezone }).format()
|
||||
if (!p.timezone) throw Error()
|
||||
if (p.mode === 'cron') {
|
||||
if (p.cron.trim().split(/\s+/).length !== 5 || /[H?]/.test(p.cron)) throw Error()
|
||||
CronExpressionParser.parse(p.cron, { currentDate: new Date(), tz: p.timezone }).next()
|
||||
}
|
||||
} catch {
|
||||
throw new HttpError(
|
||||
400,
|
||||
'Gültigen Cron-Ausdruck mit fünf Feldern und eine IANA-Zeitzone angeben.',
|
||||
)
|
||||
}
|
||||
if (password !== undefined && (typeof password !== 'string' || password.length > 1024))
|
||||
throw new HttpError(400, 'Ungültiges IMAP-Passwort.')
|
||||
if (
|
||||
row.password &&
|
||||
data.enabled &&
|
||||
!password &&
|
||||
(before.host !== data.host.trim() || before.username !== data.username.trim())
|
||||
)
|
||||
throw new HttpError(
|
||||
400,
|
||||
'Bei geändertem IMAP-Server oder Benutzer das Passwort erneut eingeben.',
|
||||
)
|
||||
const secret = password ? encryptSecret(password) : row.password
|
||||
if (data.enabled && !secret) throw new HttpError(400, 'IMAP-Passwort erforderlich.')
|
||||
const config = {
|
||||
enabled: data.enabled,
|
||||
host: data.host.trim(),
|
||||
port: Number(data.port),
|
||||
security: data.security,
|
||||
username: data.username.trim(),
|
||||
folder: data.folder.trim(),
|
||||
onlyUnread: data.onlyUnread,
|
||||
markRead: data.markRead,
|
||||
schedule: {
|
||||
mode: p.mode,
|
||||
seconds: Number(p.seconds),
|
||||
cron: p.cron.trim(),
|
||||
timezone: p.timezone,
|
||||
},
|
||||
}
|
||||
s.run(
|
||||
'UPDATE queue_inbound SET config=?,password=?,next_run=?,error=NULL,revision=revision+1 WHERE queue_id=?',
|
||||
JSON.stringify(config),
|
||||
secret,
|
||||
nextFetch(config),
|
||||
id,
|
||||
)
|
||||
const after = inboundSettings(s, id)
|
||||
s.audit(
|
||||
user.id,
|
||||
'IMAP und Abrufzeitplan konfiguriert',
|
||||
id,
|
||||
before,
|
||||
{ ...after, passwordChanged: !!password },
|
||||
null,
|
||||
id,
|
||||
)
|
||||
return after
|
||||
}
|
||||
export function imapOptions(s, id) {
|
||||
const r = ensure(s, id),
|
||||
c = JSON.parse(r.config)
|
||||
if (!c.enabled) throw new HttpError(400, 'IMAP-Empfang ist für diese Queue deaktiviert.')
|
||||
return {
|
||||
host: c.host,
|
||||
port: c.port,
|
||||
secure: c.security === 'tls',
|
||||
doSTARTTLS: c.security === 'starttls',
|
||||
auth: { user: c.username, pass: decryptSecret(r.password) },
|
||||
connectionTimeout: 10000,
|
||||
greetingTimeout: 10000,
|
||||
socketTimeout: 30000,
|
||||
logger: false,
|
||||
}
|
||||
}
|
||||
export class InboundWorker {
|
||||
constructor(
|
||||
s,
|
||||
{ clientFactory = (options) => new ImapFlow(options), clock = () => new Date() } = {},
|
||||
) {
|
||||
this.s = s
|
||||
this.clientFactory = clientFactory
|
||||
this.clock = clock
|
||||
this.running = new Set()
|
||||
}
|
||||
async verify(user, id) {
|
||||
this.s.require(user, id, 'queue')
|
||||
const c = inboundSettings(this.s, id),
|
||||
client = this.clientFactory(imapOptions(this.s, id))
|
||||
try {
|
||||
await client.connect()
|
||||
const lock = await client.getMailboxLock(c.folder)
|
||||
lock.release()
|
||||
await client.logout()
|
||||
this.s.audit(user.id, 'IMAP-Verbindung geprüft', id, null, { success: true }, null, id)
|
||||
return {
|
||||
ok: true,
|
||||
message:
|
||||
'IMAP-Anmeldung und Postfachzugriff erfolgreich. Keine Nachrichten wurden importiert.',
|
||||
}
|
||||
} catch (e) {
|
||||
this.s.audit(
|
||||
user.id,
|
||||
'IMAP-Verbindungsprüfung fehlgeschlagen',
|
||||
id,
|
||||
null,
|
||||
{ code: String(e.code || 'unknown') },
|
||||
null,
|
||||
id,
|
||||
)
|
||||
throw new HttpError(
|
||||
400,
|
||||
'IMAP-Verbindung fehlgeschlagen. Server, TLS, Zugangsdaten und Ordner prüfen.',
|
||||
)
|
||||
} finally {
|
||||
client.close()
|
||||
}
|
||||
}
|
||||
async due() {
|
||||
const jobs = []
|
||||
for (const q of this.s.all('SELECT id FROM queues WHERE deleted_at IS NULL')) {
|
||||
const r = ensure(this.s, q.id)
|
||||
if (
|
||||
JSON.parse(r.config).enabled &&
|
||||
r.next_run &&
|
||||
r.next_run <= this.clock().toISOString() &&
|
||||
!this.running.has(q.id)
|
||||
)
|
||||
jobs.push(this.run(q.id).catch(() => {}))
|
||||
}
|
||||
await Promise.all(jobs)
|
||||
}
|
||||
async run(id, { actor = 'IMAP-Abrufprozess' } = {}) {
|
||||
if (this.running.has(id)) throw new HttpError(409, 'Für diese Queue läuft bereits ein Abruf.')
|
||||
const row = ensure(this.s, id),
|
||||
config = JSON.parse(row.config)
|
||||
if (!config.enabled) throw new HttpError(400, 'IMAP-Empfang ist deaktiviert.')
|
||||
this.running.add(id)
|
||||
let client,
|
||||
imported = 0,
|
||||
failed = 0
|
||||
const started = this.clock().toISOString()
|
||||
this.s.run(
|
||||
'UPDATE queue_inbound SET last_run=?,next_run=? WHERE queue_id=? AND revision=?',
|
||||
started,
|
||||
started,
|
||||
id,
|
||||
row.revision,
|
||||
)
|
||||
try {
|
||||
client = this.clientFactory(imapOptions(this.s, id))
|
||||
await client.connect()
|
||||
const lock = await client.getMailboxLock(config.folder)
|
||||
try {
|
||||
const addresses = this.s
|
||||
.queue(id)
|
||||
.addresses.filter((a) => a.incoming)
|
||||
.map((a) => a.email.toLowerCase())
|
||||
.sort()
|
||||
const validity = String(client.mailbox.uidValidity),
|
||||
mailboxKey = JSON.stringify([
|
||||
config.host,
|
||||
config.port,
|
||||
config.username,
|
||||
config.folder,
|
||||
validity,
|
||||
addresses,
|
||||
])
|
||||
const ids =
|
||||
(await client.search(config.onlyUnread ? { seen: false } : { all: true }, {
|
||||
uid: true,
|
||||
})) || []
|
||||
if (
|
||||
this.s.get('SELECT revision FROM queue_inbound WHERE queue_id=?', id).revision !==
|
||||
row.revision
|
||||
)
|
||||
return {
|
||||
ok: false,
|
||||
imported: 0,
|
||||
failed: 0,
|
||||
message: 'Abruf wegen geänderter Mail-Einstellungen beendet.',
|
||||
}
|
||||
const storedReceipts = this.s.all(
|
||||
'SELECT uid,outcome FROM inbound_receipts WHERE queue_id=? AND mailbox_key=?',
|
||||
id,
|
||||
mailboxKey,
|
||||
)
|
||||
const receipts = new Set(storedReceipts.map((r) => r.uid))
|
||||
const processed = new Set(
|
||||
storedReceipts.filter((r) => r.outcome !== 'skipped').map((r) => r.uid),
|
||||
)
|
||||
const known = ids.filter((uid) => processed.has(uid))
|
||||
if (config.markRead && known.length)
|
||||
await client.messageFlagsAdd(known.slice(0, 100), ['\\Seen'], { uid: true })
|
||||
for (const uid of ids.filter((uid) => !receipts.has(uid)).slice(0, 100)) {
|
||||
if (
|
||||
this.s.get('SELECT revision FROM queue_inbound WHERE queue_id=?', id).revision !==
|
||||
row.revision
|
||||
)
|
||||
break
|
||||
try {
|
||||
const meta = await client.fetchOne(uid, { size: true }, { uid: true })
|
||||
if (!meta) continue
|
||||
if (meta.size > 20 * 1024 * 1024) throw Error('MessageTooLarge')
|
||||
const message = await client.fetchOne(uid, { source: true }, { uid: true })
|
||||
if (!message) continue
|
||||
if (message.source.length > 20 * 1024 * 1024) throw Error('MessageTooLarge')
|
||||
const p = await simpleParser(message.source)
|
||||
const to = [...(p.to?.value || []), ...(p.cc?.value || [])]
|
||||
.map((x) => x.address)
|
||||
.filter(Boolean)
|
||||
if (
|
||||
this.s.get('SELECT revision FROM queue_inbound WHERE queue_id=?', id).revision !==
|
||||
row.revision
|
||||
)
|
||||
break
|
||||
if (!to.some((a) => addresses.includes(a.toLowerCase()))) {
|
||||
this.s.run(
|
||||
"INSERT OR IGNORE INTO inbound_receipts VALUES(?,?,?,'skipped')",
|
||||
id,
|
||||
mailboxKey,
|
||||
uid,
|
||||
)
|
||||
continue
|
||||
}
|
||||
const data = {
|
||||
messageId: p.messageId,
|
||||
from: p.from?.value[0]?.address,
|
||||
name: p.from?.value[0]?.name,
|
||||
to,
|
||||
subject: p.subject,
|
||||
body: p.text || '(HTML-Nachricht ohne Textalternative)',
|
||||
inReplyTo: p.inReplyTo,
|
||||
references: typeof p.references === 'string' ? [p.references] : p.references || [],
|
||||
autoSubmitted: p.headers.get('auto-submitted'),
|
||||
precedence: p.headers.get('precedence'),
|
||||
attachments: p.attachments.map((a) => ({
|
||||
name: a.filename,
|
||||
mime: a.contentType,
|
||||
content: a.content.toString('base64'),
|
||||
})),
|
||||
}
|
||||
const result = this.s.tx(() => {
|
||||
const r = this.s.ingest(data, id)
|
||||
this.s.run(
|
||||
"INSERT OR IGNORE INTO inbound_receipts VALUES(?,?,?,'imported')",
|
||||
id,
|
||||
mailboxKey,
|
||||
uid,
|
||||
)
|
||||
return r
|
||||
})
|
||||
if (!result.ignored && !result.duplicate) imported++
|
||||
if (config.markRead) await client.messageFlagsAdd(uid, ['\\Seen'], { uid: true })
|
||||
} catch (e) {
|
||||
failed++
|
||||
this.s.audit(
|
||||
actor,
|
||||
'Nachricht konnte nicht importiert werden',
|
||||
`${id}:${uid}`,
|
||||
null,
|
||||
{ code: String(e.code || e.name || 'Error') },
|
||||
null,
|
||||
id,
|
||||
)
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
lock.release()
|
||||
}
|
||||
await client.logout()
|
||||
this.s.run(
|
||||
'UPDATE queue_inbound SET last_success=?,error=?,next_run=? WHERE queue_id=? AND revision=?',
|
||||
failed ? row.last_success : this.clock().toISOString(),
|
||||
failed
|
||||
? `${failed} Nachricht(en) konnten nicht verarbeitet werden. Systemprotokoll prüfen.`
|
||||
: null,
|
||||
nextFetch(config, this.clock()),
|
||||
id,
|
||||
row.revision,
|
||||
)
|
||||
this.s.audit(actor, 'Postfach abgerufen', id, null, { imported, failed }, null, id)
|
||||
return {
|
||||
ok: !failed,
|
||||
imported,
|
||||
failed,
|
||||
message: `Abruf abgeschlossen: ${imported} neue Nachricht(en), ${failed} Fehler.`,
|
||||
}
|
||||
} catch (e) {
|
||||
this.s.run(
|
||||
'UPDATE queue_inbound SET error=?,next_run=? WHERE queue_id=? AND revision=?',
|
||||
'Abruf fehlgeschlagen. Zugangsdaten und Ordner prüfen.',
|
||||
nextFetch(config, this.clock()),
|
||||
id,
|
||||
row.revision,
|
||||
)
|
||||
this.s.audit(
|
||||
actor,
|
||||
'Postfachabruf fehlgeschlagen',
|
||||
id,
|
||||
null,
|
||||
{ code: String(e.code || e.name || 'Error') },
|
||||
null,
|
||||
id,
|
||||
)
|
||||
throw new HttpError(400, 'Postfachabruf fehlgeschlagen. Zugangsdaten und Ordner prüfen.')
|
||||
} finally {
|
||||
this.running.delete(id)
|
||||
client?.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
27
server/index.js
Normal file
27
server/index.js
Normal file
@ -0,0 +1,27 @@
|
||||
import 'dotenv/config'
|
||||
import express from 'express'
|
||||
import path from 'node:path'
|
||||
import { openDb, seed } from './db.js'
|
||||
import { createApp } from './app.js'
|
||||
import { Worker } from './worker.js'
|
||||
const db = openDb()
|
||||
seed(db)
|
||||
const { app, service } = createApp(db)
|
||||
const worker = new Worker(service)
|
||||
app.locals.worker = worker
|
||||
app.use(express.static(path.resolve('dist')))
|
||||
app.get('/{*path}', (req, res) => res.sendFile(path.resolve('dist/index.html')))
|
||||
const server = app.listen(Number(process.env.PORT || 3001), process.env.HOST || '127.0.0.1', () => {
|
||||
console.log(
|
||||
`Syncova Ticket: http://127.0.0.1:${process.env.PORT || 3001} · E-Mail: ${process.env.MAIL_MODE || 'development'}`,
|
||||
)
|
||||
worker.start()
|
||||
})
|
||||
for (const signal of ['SIGINT', 'SIGTERM'])
|
||||
process.on(signal, () => {
|
||||
worker.stop()
|
||||
server.close(() => {
|
||||
db.close()
|
||||
process.exit(0)
|
||||
})
|
||||
})
|
||||
256
server/mail-config.js
Normal file
256
server/mail-config.js
Normal file
@ -0,0 +1,256 @@
|
||||
import nodemailer from 'nodemailer'
|
||||
import { encryptSecret, decryptSecret } from './secrets.js'
|
||||
import { HttpError } from './service.js'
|
||||
import { uid, now } from './db.js'
|
||||
import { inboundSettings, saveInbound } from './inbound.js'
|
||||
import { composeContent } from './content.js'
|
||||
import { signatureContext } from './signature-placeholders.js'
|
||||
export const defaultAcknowledgement = {
|
||||
enabled: false,
|
||||
subject: 'Ihre Anfrage {ticketnummer} ist eingegangen',
|
||||
body: 'Guten Tag {kundenname},\n\nvielen Dank für Ihre Nachricht. Wir haben Ihre Anfrage erhalten und bearbeiten sie schnellstmöglich.\n\nIhre Ticketnummer: {ticketnummer}',
|
||||
includeSignature: true,
|
||||
}
|
||||
export function mailSettings(s, id) {
|
||||
const row = s.get('SELECT * FROM queue_mail WHERE queue_id=?', id)
|
||||
return {
|
||||
imap: inboundSettings(s, id),
|
||||
smtp: row
|
||||
? JSON.parse(row.smtp)
|
||||
: {
|
||||
mode: process.env.MAIL_MODE === 'smtp' ? 'legacy' : 'development',
|
||||
host: '',
|
||||
port: 465,
|
||||
security: 'tls',
|
||||
username: '',
|
||||
},
|
||||
passwordSet: !!row?.password,
|
||||
acknowledgement: row ? JSON.parse(row.acknowledgement) : { ...defaultAcknowledgement },
|
||||
}
|
||||
}
|
||||
export function readMailSettings(s, user, id) {
|
||||
s.require(user, id, 'queue')
|
||||
s.queue(id)
|
||||
return mailSettings(s, id)
|
||||
}
|
||||
export function saveMailSettings(s, user, id, data) {
|
||||
return s.tx(() => {
|
||||
s.require(user, id, 'queue')
|
||||
s.queue(id)
|
||||
const before = mailSettings(s, id),
|
||||
smtp = data.smtp,
|
||||
ack = data.acknowledgement || before.acknowledgement
|
||||
if (
|
||||
!smtp ||
|
||||
!['smtp', 'development', 'legacy'].includes(smtp.mode) ||
|
||||
!['tls', 'starttls'].includes(smtp.security) ||
|
||||
!Number.isInteger(Number(smtp.port)) ||
|
||||
Number(smtp.port) < 1 ||
|
||||
Number(smtp.port) > 65535
|
||||
)
|
||||
throw new HttpError(400, 'Gültigen Versandmodus, Port und TLS-Modus auswählen.')
|
||||
if (smtp.mode === 'legacy' && before.smtp.mode !== 'legacy')
|
||||
throw new HttpError(400, 'Globale SMTP-Konfiguration ist nicht verfügbar.')
|
||||
if (
|
||||
smtp.mode === 'smtp' &&
|
||||
(!/^[a-z0-9][a-z0-9.:-]*$/i.test(smtp.host || '') || !smtp.username?.trim())
|
||||
)
|
||||
throw new HttpError(400, 'SMTP-Server und Benutzername sind erforderlich.')
|
||||
if (
|
||||
typeof ack.enabled !== 'boolean' ||
|
||||
typeof ack.includeSignature !== 'boolean' ||
|
||||
typeof ack.subject !== 'string' ||
|
||||
typeof ack.body !== 'string' ||
|
||||
!ack.subject.trim() ||
|
||||
!ack.body.trim() ||
|
||||
ack.subject.length > 500 ||
|
||||
ack.body.length > 20000 ||
|
||||
/[\r\n]/.test(ack.subject)
|
||||
)
|
||||
throw new HttpError(
|
||||
400,
|
||||
'Betreff und Text der Eingangsbestätigung ausfüllen (max. 500 / 20.000 Zeichen).',
|
||||
)
|
||||
const tokens = (ack.subject + ' ' + ack.body).match(/\{[^{}]+\}/g) || []
|
||||
if (tokens.some((t) => !['{ticketnummer}', '{betreff}', '{kundenname}', '{queue}'].includes(t)))
|
||||
throw new HttpError(400, 'Unbekannter Platzhalter in der Eingangsbestätigung.')
|
||||
if (
|
||||
data.password !== undefined &&
|
||||
(typeof data.password !== 'string' || data.password.length > 1024)
|
||||
)
|
||||
throw new HttpError(400, 'Ungültiges SMTP-Passwort.')
|
||||
const old = s.get('SELECT password FROM queue_mail WHERE queue_id=?', id)
|
||||
if (
|
||||
old?.password &&
|
||||
smtp.mode === 'smtp' &&
|
||||
!data.password &&
|
||||
(smtp.host.trim() !== before.smtp.host || smtp.username.trim() !== before.smtp.username)
|
||||
)
|
||||
throw new HttpError(
|
||||
400,
|
||||
'Bei einem anderen SMTP-Server oder Benutzernamen das Passwort erneut eingeben.',
|
||||
)
|
||||
let password = data.clearPassword ? '' : old?.password || ''
|
||||
if (data.password) password = encryptSecret(data.password)
|
||||
if (smtp.mode === 'smtp' && !password)
|
||||
throw new HttpError(400, 'Ein SMTP-Passwort ist erforderlich.')
|
||||
const clean = {
|
||||
mode: smtp.mode,
|
||||
host: String(smtp.host || '').trim(),
|
||||
port: Number(smtp.port),
|
||||
security: smtp.security,
|
||||
username: String(smtp.username || '').trim(),
|
||||
}
|
||||
const cleanAck = {
|
||||
enabled: ack.enabled,
|
||||
subject: ack.subject.trim(),
|
||||
body: ack.body.trim(),
|
||||
includeSignature: ack.includeSignature,
|
||||
}
|
||||
s.run(
|
||||
'INSERT INTO queue_mail VALUES(?,?,?,?) ON CONFLICT(queue_id) DO UPDATE SET smtp=excluded.smtp,password=excluded.password,acknowledgement=excluded.acknowledgement',
|
||||
id,
|
||||
JSON.stringify(clean),
|
||||
password,
|
||||
JSON.stringify(cleanAck),
|
||||
)
|
||||
if (data.imap) saveInbound(s, user, id, data.imap, data.imapPassword)
|
||||
const after = mailSettings(s, id)
|
||||
s.audit(
|
||||
user.id,
|
||||
'SMTP und Eingangsbestätigung konfiguriert',
|
||||
id,
|
||||
before,
|
||||
{ ...after, passwordChanged: !!data.password || !!data.clearPassword },
|
||||
null,
|
||||
id,
|
||||
)
|
||||
return after
|
||||
})
|
||||
}
|
||||
export function smtpTransport(s, id, factory = nodemailer.createTransport) {
|
||||
const row = s.get('SELECT * FROM queue_mail WHERE queue_id=?', id)
|
||||
const smtp = row ? JSON.parse(row.smtp) : null
|
||||
if (smtp?.mode === 'development' || (!smtp && process.env.MAIL_MODE !== 'smtp')) return null
|
||||
if (!smtp || smtp.mode === 'legacy')
|
||||
return factory({
|
||||
host: process.env.SMTP_HOST,
|
||||
port: Number(process.env.SMTP_PORT || 465),
|
||||
secure: process.env.SMTP_TLS !== 'false',
|
||||
requireTLS: process.env.SMTP_TLS === 'false',
|
||||
auth: { user: process.env.SMTP_USER, pass: process.env.SMTP_PASSWORD },
|
||||
connectionTimeout: 10000,
|
||||
greetingTimeout: 10000,
|
||||
socketTimeout: 30000,
|
||||
disableFileAccess: true,
|
||||
disableUrlAccess: true,
|
||||
})
|
||||
return factory({
|
||||
host: smtp.host,
|
||||
port: smtp.port,
|
||||
secure: smtp.security === 'tls',
|
||||
requireTLS: smtp.security === 'starttls',
|
||||
auth: { user: smtp.username, pass: decryptSecret(row.password) },
|
||||
connectionTimeout: 10000,
|
||||
greetingTimeout: 10000,
|
||||
socketTimeout: 30000,
|
||||
disableFileAccess: true,
|
||||
disableUrlAccess: true,
|
||||
})
|
||||
}
|
||||
export async function verifySmtp(s, user, id) {
|
||||
s.require(user, id, 'queue')
|
||||
s.queue(id)
|
||||
const transport = smtpTransport(s, id)
|
||||
if (!transport) throw new HttpError(400, 'Für diese Queue ist der Entwicklungsadapter aktiv.')
|
||||
try {
|
||||
await transport.verify()
|
||||
s.audit(user.id, 'SMTP-Verbindung geprüft', id, null, { success: true }, null, id)
|
||||
return {
|
||||
ok: true,
|
||||
message: 'Verbindung und Anmeldung erfolgreich. Es wurde keine E-Mail gesendet.',
|
||||
}
|
||||
} catch (e) {
|
||||
s.audit(
|
||||
user.id,
|
||||
'SMTP-Verbindungsprüfung fehlgeschlagen',
|
||||
id,
|
||||
null,
|
||||
{ success: false, code: String(e.code || 'unknown') },
|
||||
null,
|
||||
id,
|
||||
)
|
||||
throw new HttpError(
|
||||
400,
|
||||
'SMTP-Verbindung fehlgeschlagen. Server, Port, TLS-Modus und Zugangsdaten prüfen.',
|
||||
)
|
||||
} finally {
|
||||
transport.close?.()
|
||||
}
|
||||
}
|
||||
export function acknowledge(s, t, incoming) {
|
||||
const q = s.queue(t.queue_id),
|
||||
config = mailSettings(s, q.id).acknowledgement
|
||||
if (!config.enabled) return
|
||||
const sender = q.addresses.find((a) => a.outgoing && a.default)
|
||||
if (!sender) throw new HttpError(409, 'Standardabsender für die Eingangsbestätigung fehlt.')
|
||||
const values = {
|
||||
ticketnummer: `SYN-${String(t.id).padStart(5, '0')}`,
|
||||
betreff: t.subject,
|
||||
kundenname: t.customer_name,
|
||||
queue: q.name,
|
||||
}
|
||||
const render = (v) =>
|
||||
v.replace(/\{(ticketnummer|betreff|kundenname|queue)\}/g, (_, k) => values[k])
|
||||
const signature = config.includeSignature ? q.signatures.find((x) => x.default) : null
|
||||
const content = composeContent(
|
||||
render(config.body),
|
||||
signature,
|
||||
signatureContext(s, null, q, t, sender.email),
|
||||
)
|
||||
const body = content.text
|
||||
const subject = render(config.subject)
|
||||
.replace(/[\r\n]/g, ' ')
|
||||
.slice(0, 998),
|
||||
messageId = `<ack-${t.id}@syncova.local>`,
|
||||
id = uid()
|
||||
s.run(
|
||||
'INSERT INTO messages VALUES(?,?,?,?,?,?,?,?,?,?)',
|
||||
id,
|
||||
t.id,
|
||||
'outgoing',
|
||||
sender.email,
|
||||
t.customer,
|
||||
body,
|
||||
messageId,
|
||||
JSON.stringify([incoming.messageId]),
|
||||
now(),
|
||||
'queued',
|
||||
)
|
||||
s.run(
|
||||
'INSERT INTO outbox(id,message_id,payload,next_at) VALUES(?,?,?,?)',
|
||||
uid(),
|
||||
id,
|
||||
JSON.stringify({
|
||||
from: sender.email,
|
||||
to: t.customer,
|
||||
subject,
|
||||
text: body,
|
||||
...(content.html ? { html: content.html } : {}),
|
||||
messageId,
|
||||
inReplyTo: incoming.messageId,
|
||||
references: [incoming.messageId],
|
||||
}),
|
||||
now(),
|
||||
)
|
||||
if (content.html) s.run('INSERT INTO message_html VALUES(?,?)', id, content.html)
|
||||
s.audit(
|
||||
'Eingangsbestätigung',
|
||||
'Automatische Eingangsbestätigung vorgemerkt',
|
||||
id,
|
||||
null,
|
||||
{ from: sender.email, messageId },
|
||||
t.id,
|
||||
t.queue_id,
|
||||
)
|
||||
}
|
||||
40
server/secrets.js
Normal file
40
server/secrets.js
Normal file
@ -0,0 +1,40 @@
|
||||
import { createCipheriv, createDecipheriv, randomBytes } from 'node:crypto'
|
||||
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
function key() {
|
||||
if (process.env.SMTP_ENCRYPTION_KEY) {
|
||||
if (!/^[a-f0-9]{64}$/i.test(process.env.SMTP_ENCRYPTION_KEY))
|
||||
throw Error('SMTP_ENCRYPTION_KEY muss 32 Byte in Hex enthalten.')
|
||||
return Buffer.from(process.env.SMTP_ENCRYPTION_KEY, 'hex')
|
||||
}
|
||||
const file =
|
||||
process.env.SMTP_KEY_FILE ||
|
||||
path.join(path.dirname(process.env.DB_PATH || 'data/syncova.db'), 'smtp.key')
|
||||
mkdirSync(path.dirname(file), { recursive: true })
|
||||
try {
|
||||
return readFileSync(file)
|
||||
} catch (e) {
|
||||
if (e.code !== 'ENOENT') throw e
|
||||
}
|
||||
const value = randomBytes(32)
|
||||
try {
|
||||
writeFileSync(file, value, { flag: 'wx', mode: 0o600 })
|
||||
return value
|
||||
} catch (e) {
|
||||
if (e.code === 'EEXIST') return readFileSync(file)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
export function encryptSecret(value) {
|
||||
const iv = randomBytes(12),
|
||||
cipher = createCipheriv('aes-256-gcm', key(), iv)
|
||||
const encrypted = Buffer.concat([cipher.update(value, 'utf8'), cipher.final()])
|
||||
return [iv, cipher.getAuthTag(), encrypted].map((b) => b.toString('base64')).join('.')
|
||||
}
|
||||
export function decryptSecret(value) {
|
||||
if (!value) return ''
|
||||
const [iv, tag, data] = value.split('.').map((s) => Buffer.from(s, 'base64'))
|
||||
const cipher = createDecipheriv('aes-256-gcm', key(), iv)
|
||||
cipher.setAuthTag(tag)
|
||||
return Buffer.concat([cipher.update(data), cipher.final()]).toString('utf8')
|
||||
}
|
||||
1134
server/service.js
Normal file
1134
server/service.js
Normal file
File diff suppressed because it is too large
Load Diff
110
server/signature-placeholders.js
Normal file
110
server/signature-placeholders.js
Normal file
@ -0,0 +1,110 @@
|
||||
import { HttpError } from './service.js'
|
||||
export const signatureTokens = [
|
||||
['benutzer.name', 'Benutzer', 'Vollständiger Name des antwortenden Benutzers'],
|
||||
['benutzer.vorname', 'Benutzer', 'Erstes Wort des Anzeigenamens'],
|
||||
['benutzer.nachname', 'Benutzer', 'Übriger Anzeigename'],
|
||||
['benutzer.email', 'Benutzer', 'E-Mail-Adresse des Benutzerkontos'],
|
||||
['benutzer.telefon', 'Benutzer', 'Telefonnummer aus der Benutzerverwaltung'],
|
||||
['benutzer.position', 'Benutzer', 'Position / Funktion aus der Benutzerverwaltung'],
|
||||
['benutzer.abteilung', 'Benutzer', 'Abteilung aus der Benutzerverwaltung'],
|
||||
['queue.name', 'Queue', 'Name der aktuellen Queue'],
|
||||
['queue.email', 'Queue', 'Standardabsender der Queue'],
|
||||
['absender.email', 'Queue', 'Für diese Antwort ausgewählte Absenderadresse'],
|
||||
['ticket.nummer', 'Ticket', 'Ticketnummer, z. B. SYN-00123'],
|
||||
['ticket.betreff', 'Ticket', 'Betreff des Tickets'],
|
||||
['ticket.status', 'Ticket', 'Aktueller Statusname'],
|
||||
['kunde.name', 'Kunde', 'Name des Kundenkontakts'],
|
||||
['kunde.email', 'Kunde', 'E-Mail-Adresse des Kunden'],
|
||||
['bearbeiter.name', 'Ticket', 'Name des zuständigen Benutzers, falls zugewiesen'],
|
||||
['bearbeiter.email', 'Ticket', 'E-Mail-Adresse des zuständigen Benutzers'],
|
||||
['datum', 'Zeit', 'Aktuelles Datum in Europe/Berlin'],
|
||||
['uhrzeit', 'Zeit', 'Aktuelle Uhrzeit in Europe/Berlin'],
|
||||
].map(([key, group, description]) => ({ key, group, description, token: `{${key}}` }))
|
||||
const aliases = {
|
||||
benutzername: 'benutzer.name',
|
||||
benutzeremail: 'benutzer.email',
|
||||
vorname: 'benutzer.vorname',
|
||||
nachname: 'benutzer.nachname',
|
||||
telefon: 'benutzer.telefon',
|
||||
position: 'benutzer.position',
|
||||
abteilung: 'benutzer.abteilung',
|
||||
queue: 'queue.name',
|
||||
ticketnummer: 'ticket.nummer',
|
||||
betreff: 'ticket.betreff',
|
||||
kundenname: 'kunde.name',
|
||||
kundenemail: 'kunde.email',
|
||||
'user.name': 'benutzer.name',
|
||||
'user.email': 'benutzer.email',
|
||||
'user.first_name': 'benutzer.vorname',
|
||||
'user.last_name': 'benutzer.nachname',
|
||||
'user.firstname': 'benutzer.vorname',
|
||||
'user.lastname': 'benutzer.nachname',
|
||||
'user.phone': 'benutzer.telefon',
|
||||
'user.job_title': 'benutzer.position',
|
||||
'user.jobtitle': 'benutzer.position',
|
||||
'user.department': 'benutzer.abteilung',
|
||||
'mailbox.email': 'absender.email',
|
||||
'mailbox.name': 'queue.name',
|
||||
'ticket.number': 'ticket.nummer',
|
||||
'ticket.subject': 'ticket.betreff',
|
||||
'ticket.status': 'ticket.status',
|
||||
'customer.name': 'kunde.name',
|
||||
'customer.email': 'kunde.email',
|
||||
'assignee.name': 'bearbeiter.name',
|
||||
'assignee.email': 'bearbeiter.email',
|
||||
}
|
||||
const keys = new Set(signatureTokens.map((t) => t.key))
|
||||
const pattern = /\{(?:([a-zA-Z_][a-zA-Z0-9_.]*)|%([a-zA-Z_][a-zA-Z0-9_.]*)%)\}/g
|
||||
export function validateSignatureTemplate(body) {
|
||||
const unknown = [...body.matchAll(pattern)]
|
||||
.map((m) => m[1] || m[2])
|
||||
.filter((k) => !keys.has(k.toLowerCase()) && !Object.hasOwn(aliases, k.toLowerCase()))
|
||||
if (unknown.length)
|
||||
throw new HttpError(
|
||||
400,
|
||||
`Unbekannte Signatur-Platzhalter: ${[...new Set(unknown)].map((k) => '{' + k + '}').join(', ')}`,
|
||||
)
|
||||
}
|
||||
export function expandSignature(body, values, escape = (v) => v) {
|
||||
validateSignatureTemplate(body)
|
||||
return body.replace(pattern, (_, raw, wrapped) => {
|
||||
const key = (raw || wrapped).toLowerCase()
|
||||
return escape(String(values?.[Object.hasOwn(aliases, key) ? aliases[key] : key] ?? ''))
|
||||
})
|
||||
}
|
||||
export function signatureContext(s, user, q, t, from, at = new Date()) {
|
||||
const sender = from || q.addresses.find((a) => a.default && a.outgoing)?.email || ''
|
||||
const name = user?.name || q.name,
|
||||
parts = user?.name?.trim().split(/\s+/) || []
|
||||
const assignee = t?.assignee
|
||||
? s.get('SELECT id,name,email FROM users WHERE id=? AND active=1', t.assignee)
|
||||
: null
|
||||
const assigned = assignee && s.can(assignee, q.id, 'view') ? assignee : null
|
||||
return {
|
||||
'benutzer.name': name,
|
||||
'benutzer.vorname': parts[0] || '',
|
||||
'benutzer.nachname': parts.slice(1).join(' '),
|
||||
'benutzer.email': user?.email || sender,
|
||||
'benutzer.telefon': user?.phone || '',
|
||||
'benutzer.position': user?.job_title || '',
|
||||
'benutzer.abteilung': user?.department || '',
|
||||
'queue.name': q.name,
|
||||
'queue.email': q.addresses.find((a) => a.default && a.outgoing)?.email || '',
|
||||
'absender.email': sender,
|
||||
'ticket.nummer': t?.id ? `SYN-${String(t.id).padStart(5, '0')}` : '',
|
||||
'ticket.betreff': t?.subject || '',
|
||||
'ticket.status': t?.status_id ? q.statuses.find((st) => st.id === t.status_id)?.name || '' : '',
|
||||
'kunde.name': t?.customer_name || '',
|
||||
'kunde.email': t?.customer || '',
|
||||
'bearbeiter.name': assigned?.name || '',
|
||||
'bearbeiter.email': assigned?.email || '',
|
||||
datum: new Intl.DateTimeFormat('de-DE', {
|
||||
timeZone: 'Europe/Berlin',
|
||||
dateStyle: 'medium',
|
||||
}).format(at),
|
||||
uhrzeit: new Intl.DateTimeFormat('de-DE', {
|
||||
timeZone: 'Europe/Berlin',
|
||||
timeStyle: 'short',
|
||||
}).format(at),
|
||||
}
|
||||
}
|
||||
30
server/time.js
Normal file
30
server/time.js
Normal file
@ -0,0 +1,30 @@
|
||||
// Resolve a wall-clock timestamp in an IANA zone, rejecting DST gaps.
|
||||
export function scheduledTime(value, zone) {
|
||||
if (!zone || typeof value !== 'string') throw Error('Termin und Zeitzone fehlen')
|
||||
const fmt = new Intl.DateTimeFormat('sv-SE', {
|
||||
timeZone: zone,
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
hourCycle: 'h23',
|
||||
})
|
||||
if (/[zZ]$|[+-]\d{2}:\d{2}$/.test(value)) {
|
||||
const d = new Date(value)
|
||||
if (!Number.isFinite(+d)) throw Error('Ungültiger Termin')
|
||||
return d.toISOString()
|
||||
}
|
||||
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?$/.test(value)) throw Error('Ungültiger Termin')
|
||||
const target = value.length === 16 ? value + ':00' : value
|
||||
const utc = Date.parse(target + 'Z')
|
||||
let guess = utc
|
||||
for (let i = 0; i < 4; i++) {
|
||||
const wall = fmt.format(new Date(guess)).replace(' ', 'T')
|
||||
const delta = utc - Date.parse(wall + 'Z')
|
||||
if (!delta) return new Date(guess).toISOString()
|
||||
guess += delta
|
||||
}
|
||||
throw Error('Die Uhrzeit existiert in dieser Zeitzone nicht (Sommerzeitwechsel).')
|
||||
}
|
||||
173
server/worker.js
Normal file
173
server/worker.js
Normal file
@ -0,0 +1,173 @@
|
||||
import { smtpTransport } from './mail-config.js'
|
||||
import { InboundWorker } from './inbound.js'
|
||||
import { uid, now } from './db.js'
|
||||
export class Worker {
|
||||
constructor(service, { transportFactory, inboundOptions } = {}) {
|
||||
this.s = service
|
||||
this.busy = false
|
||||
this.inbound = new InboundWorker(service, inboundOptions)
|
||||
this.transportFactory = transportFactory
|
||||
// An interrupted SMTP transaction may already have been accepted. Never silently resend it.
|
||||
this.s.run(
|
||||
"UPDATE outbox SET state='uncertain',error='Versand beim Neustart unbestätigt; Zustellung am Mailserver prüfen.' WHERE state='sending'",
|
||||
)
|
||||
}
|
||||
async tick() {
|
||||
if (this.busy) return
|
||||
this.busy = true
|
||||
try {
|
||||
this.s.due()
|
||||
for (const job of this.s.all(
|
||||
"SELECT * FROM outbox WHERE state='pending' AND next_at<=? ORDER BY next_at LIMIT 20",
|
||||
now(),
|
||||
)) {
|
||||
let t
|
||||
if (job.message_id)
|
||||
t = this.s.get(
|
||||
'SELECT t.* FROM tickets t JOIN messages m ON m.ticket_id=t.id WHERE m.id=?',
|
||||
job.message_id,
|
||||
)
|
||||
if (job.notification_id) {
|
||||
const n = this.s.get('SELECT * FROM notifications WHERE id=?', job.notification_id)
|
||||
t = this.s.get('SELECT * FROM tickets WHERE id=?', n.ticket_id)
|
||||
const u = this.s.get('SELECT * FROM users WHERE id=? AND active=1', n.user_id)
|
||||
if (!u || !this.s.can(u, t.queue_id, 'view') || !JSON.parse(u.prefs)[n.event]?.email) {
|
||||
this.s.run("UPDATE outbox SET state='cancelled' WHERE id=?", job.id)
|
||||
continue
|
||||
}
|
||||
}
|
||||
const payload = JSON.parse(job.payload)
|
||||
const attachments = job.message_id
|
||||
? this.s
|
||||
.all('SELECT name,mime,content FROM attachments WHERE message_id=?', job.message_id)
|
||||
.map((a) => ({ filename: a.name, contentType: a.mime, content: a.content }))
|
||||
: []
|
||||
if (
|
||||
job.message_id &&
|
||||
!this.s.queue(t.queue_id).addresses.some((a) => a.outgoing && a.email === payload.from)
|
||||
) {
|
||||
this.s.run(
|
||||
"UPDATE outbox SET state='blocked',error='Absender nach Queue-Wechsel nicht mehr erlaubt' WHERE id=?",
|
||||
job.id,
|
||||
)
|
||||
continue
|
||||
}
|
||||
let transport
|
||||
try {
|
||||
transport = smtpTransport(this.s, t.queue_id, this.transportFactory)
|
||||
} catch {
|
||||
this.s.run(
|
||||
"UPDATE outbox SET state='blocked',error='SMTP-Zugangsdaten können nicht entschlüsselt werden; Queue-Konfiguration prüfen.' WHERE id=?",
|
||||
job.id,
|
||||
)
|
||||
this.s.audit(
|
||||
'Versandprozess',
|
||||
'SMTP-Konfiguration nicht verwendbar',
|
||||
job.id,
|
||||
null,
|
||||
{ state: 'blocked' },
|
||||
null,
|
||||
t.queue_id,
|
||||
)
|
||||
continue
|
||||
}
|
||||
if (!transport) {
|
||||
this.s.tx(() => {
|
||||
this.s.run(
|
||||
'INSERT OR IGNORE INTO dev_mail VALUES(?,?,?)',
|
||||
job.id,
|
||||
JSON.stringify({
|
||||
...payload,
|
||||
...(attachments.length
|
||||
? {
|
||||
attachments: attachments.map((a) => ({
|
||||
...a,
|
||||
content: a.content.toString('base64'),
|
||||
encoding: 'base64',
|
||||
})),
|
||||
}
|
||||
: {}),
|
||||
}),
|
||||
now(),
|
||||
)
|
||||
this.finish(job, t, 'development')
|
||||
})
|
||||
continue
|
||||
}
|
||||
this.s.run("UPDATE outbox SET state='sending',attempts=attempts+1 WHERE id=?", job.id)
|
||||
try {
|
||||
await transport.sendMail({
|
||||
...payload,
|
||||
attachments,
|
||||
headers: { 'Auto-Submitted': 'auto-generated', 'X-Auto-Response-Suppress': 'All' },
|
||||
})
|
||||
this.s.tx(() => this.finish(job, t, 'smtp'))
|
||||
} catch (e) {
|
||||
const definite =
|
||||
['EAUTH', 'ECONNECTION', 'EDNS', 'ETLS'].includes(e.code) || e.responseCode >= 400
|
||||
const state = definite ? 'pending' : 'uncertain'
|
||||
this.s.run(
|
||||
'UPDATE outbox SET state=?,error=?,next_at=? WHERE id=?',
|
||||
state,
|
||||
'Versand fehlgeschlagen; Serverkonfiguration oder Zustellung prüfen.',
|
||||
new Date(
|
||||
Date.now() + Math.min(3600000, 30000 * 2 ** Math.min(job.attempts, 7)),
|
||||
).toISOString(),
|
||||
job.id,
|
||||
)
|
||||
this.s.audit(
|
||||
'Versandprozess',
|
||||
'E-Mail-Versand fehlgeschlagen',
|
||||
job.id,
|
||||
null,
|
||||
{ state, code: String(e.code || 'unknown') },
|
||||
null,
|
||||
t?.queue_id || null,
|
||||
)
|
||||
} finally {
|
||||
transport.close?.()
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
this.s.audit('Hintergrundprozess', 'Automatisierung fehlgeschlagen', 'worker', null, {
|
||||
error: e instanceof Error ? e.name : 'Error',
|
||||
})
|
||||
} finally {
|
||||
this.busy = false
|
||||
}
|
||||
}
|
||||
finish(job, t, adapter) {
|
||||
this.s.run("UPDATE outbox SET state='sent',error=NULL WHERE id=?", job.id)
|
||||
if (job.message_id) {
|
||||
this.s.run("UPDATE messages SET delivery='sent' WHERE id=?", job.message_id)
|
||||
this.s.audit(
|
||||
'Versandprozess',
|
||||
'E-Mail versendet',
|
||||
job.message_id,
|
||||
null,
|
||||
{ adapter },
|
||||
t.id,
|
||||
t.queue_id,
|
||||
)
|
||||
}
|
||||
}
|
||||
async pollImap() {
|
||||
try {
|
||||
await this.inbound.due()
|
||||
} catch (e) {
|
||||
this.s.audit('Abrufprozess', 'Abrufzeitplan fehlgeschlagen', 'scheduler', null, {
|
||||
error: e.name,
|
||||
})
|
||||
}
|
||||
}
|
||||
start() {
|
||||
this.tick()
|
||||
this.pollImap()
|
||||
this.timer = setInterval(() => this.tick(), 5000)
|
||||
this.imapTimer = setInterval(() => this.pollImap(), 1000)
|
||||
}
|
||||
stop() {
|
||||
clearInterval(this.timer)
|
||||
clearInterval(this.imapTimer)
|
||||
}
|
||||
}
|
||||
1424
src/App.tsx
Normal file
1424
src/App.tsx
Normal file
File diff suppressed because it is too large
Load Diff
83
src/AttachmentPicker.tsx
Normal file
83
src/AttachmentPicker.tsx
Normal file
@ -0,0 +1,83 @@
|
||||
import { useState } from 'react'
|
||||
import { Paperclip, X } from 'lucide-react'
|
||||
export function AttachmentPicker({ files, setFiles, disabled, onBusy }: any) {
|
||||
const [error, setError] = useState('')
|
||||
const read = (file: File) =>
|
||||
new Promise<any>((resolve, reject) => {
|
||||
const reader = new FileReader()
|
||||
reader.onerror = () => reject(new Error('Datei konnte nicht gelesen werden.'))
|
||||
reader.onload = () =>
|
||||
resolve({
|
||||
id: crypto.randomUUID(),
|
||||
name: file.name,
|
||||
mime: file.type || 'application/octet-stream',
|
||||
size: file.size,
|
||||
content: String(reader.result).split(',')[1],
|
||||
})
|
||||
reader.readAsDataURL(file)
|
||||
})
|
||||
return (
|
||||
<div className="attachment-picker">
|
||||
<label className={`upload-trigger ${disabled ? 'disabled' : ''}`}>
|
||||
<Paperclip size={16} />
|
||||
<span>Dateien hinzufügen</span>
|
||||
<input
|
||||
type="file"
|
||||
multiple
|
||||
aria-label="Dateien als E-Mail-Anhang auswählen"
|
||||
disabled={disabled}
|
||||
onChange={async (e) => {
|
||||
const selected = Array.from(e.target.files || [])
|
||||
e.target.value = ''
|
||||
setError('')
|
||||
if (
|
||||
selected.length + files.length > 20 ||
|
||||
selected.some((f) => f.size > 10 * 1024 * 1024) ||
|
||||
[...files, ...selected].reduce((n: number, f: any) => n + f.size, 0) >
|
||||
20 * 1024 * 1024
|
||||
) {
|
||||
setError('Maximal 20 Dateien, 10 MB pro Datei und 20 MB insgesamt.')
|
||||
return
|
||||
}
|
||||
onBusy(true)
|
||||
try {
|
||||
const added = await Promise.all(selected.map(read))
|
||||
setFiles((old: any[]) => [...old, ...added])
|
||||
} catch (e) {
|
||||
setError((e as Error).message)
|
||||
} finally {
|
||||
onBusy(false)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
<small>10 MB pro Datei · 20 MB insgesamt</small>
|
||||
{error && (
|
||||
<div className="error" role="alert">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
{files.length > 0 && (
|
||||
<ul className="selected-attachments">
|
||||
{files.map((f: any) => (
|
||||
<li key={f.id}>
|
||||
<Paperclip size={14} />
|
||||
<span>
|
||||
{f.name}
|
||||
<small>{(f.size / 1024).toFixed(1)} KB</small>
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
aria-label={`${f.name} entfernen`}
|
||||
onClick={() => setFiles(files.filter((a: any) => a.id !== f.id))}
|
||||
>
|
||||
<X size={15} />
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
110
src/DeleteIdentity.tsx
Normal file
110
src/DeleteIdentity.tsx
Normal file
@ -0,0 +1,110 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Trash2 } from 'lucide-react'
|
||||
import { api } from './api'
|
||||
import { Field, Modal } from './App'
|
||||
import { Button } from './components/ui/button'
|
||||
import { Input } from './components/ui/input'
|
||||
|
||||
export function DeleteIdentity({ target, onClose, onDeleted }: any) {
|
||||
const [info, setInfo] = useState<any>(null),
|
||||
[confirm, setConfirm] = useState(''),
|
||||
[error, setError] = useState(''),
|
||||
[busy, setBusy] = useState(false)
|
||||
const isUser = target.kind === 'users',
|
||||
label = isUser ? 'Benutzer' : 'Gruppe'
|
||||
const url = `/${target.kind}/${encodeURIComponent(target.id)}`
|
||||
useEffect(() => {
|
||||
let alive = true
|
||||
api(url + '/deletion')
|
||||
.then((r) => {
|
||||
if (alive) setInfo(r)
|
||||
})
|
||||
.catch((e) => {
|
||||
if (alive) setError(e.message)
|
||||
})
|
||||
return () => {
|
||||
alive = false
|
||||
}
|
||||
}, [url])
|
||||
return (
|
||||
<Modal
|
||||
open
|
||||
onClose={() => {
|
||||
if (!busy) onClose()
|
||||
}}
|
||||
title={`${label} löschen`}
|
||||
>
|
||||
<p>
|
||||
<strong>{target.name}</strong>
|
||||
</p>
|
||||
{error && (
|
||||
<div className="error" role="alert">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
{!info ? (
|
||||
<p className="muted">
|
||||
{error ? 'Löschprüfung nicht verfügbar.' : 'Löschprüfung wird geladen …'}
|
||||
</p>
|
||||
) : (
|
||||
<>
|
||||
<div className="delete-notice">
|
||||
<Trash2 size={20} />
|
||||
<span>
|
||||
{isUser
|
||||
? `Das Konto wird aus der Benutzerverwaltung entfernt. Alle Sitzungen werden beendet. ${info.assignedTickets} zugewiesene Ticket(s) werden auf „Nicht zugewiesen“ gesetzt. Ticketverläufe, Nachrichten und der bisherige Name im Audit-Protokoll bleiben erhalten.`
|
||||
: `Die Gruppe wird gelöscht und aus ${info.members} Mitgliedschaft(en) entfernt. Rechte aus anderen Gruppen bleiben erhalten. Tickets ohne weiterhin berechtigten Bearbeiter werden auf „Nicht zugewiesen“ gesetzt. Benutzerkonten und Ticketverläufe bleiben erhalten.`}
|
||||
</span>
|
||||
</div>
|
||||
{info.blockedReason ? (
|
||||
<div className="error" role="alert">
|
||||
{info.blockedReason}
|
||||
</div>
|
||||
) : (
|
||||
<form
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault()
|
||||
if (busy) return
|
||||
setBusy(true)
|
||||
setError('')
|
||||
try {
|
||||
await api(url, 'DELETE', { confirm })
|
||||
await onDeleted()
|
||||
} catch (e) {
|
||||
setError((e as Error).message)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Field
|
||||
label={`Zum Bestätigen ${isUser ? 'die E-Mail-Adresse' : 'den Gruppennamen'} „${info.confirm}“ eingeben`}
|
||||
>
|
||||
<Input
|
||||
required
|
||||
autoComplete="off"
|
||||
disabled={busy}
|
||||
value={confirm}
|
||||
onChange={(e) => setConfirm(e.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
<div className="identity-actions">
|
||||
<Button type="button" variant="outline" disabled={busy} onClick={onClose}>
|
||||
Abbrechen
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
className="danger-button"
|
||||
disabled={busy || confirm !== info.confirm}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
{busy ? 'Wird gelöscht …' : `${label} löschen`}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
176
src/DeleteQueue.tsx
Normal file
176
src/DeleteQueue.tsx
Normal file
@ -0,0 +1,176 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Trash2, AlertTriangle } from 'lucide-react'
|
||||
import { Modal, Field, Select } from './App'
|
||||
import { Input } from './components/ui/input'
|
||||
import { Button } from './components/ui/button'
|
||||
import { api } from './api'
|
||||
export function DeleteQueue({ q, refresh }: any) {
|
||||
const [open, setOpen] = useState(false),
|
||||
[info, setInfo] = useState<any>(null),
|
||||
[target, setTarget] = useState(''),
|
||||
[mapping, setMapping] = useState<any>({}),
|
||||
[confirm, setConfirm] = useState(''),
|
||||
[error, setError] = useState(''),
|
||||
[busy, setBusy] = useState(false)
|
||||
useEffect(() => {
|
||||
if (!open) return
|
||||
let alive = true
|
||||
setInfo(null)
|
||||
setError('')
|
||||
api(`/queues/${q.id}/deletion`)
|
||||
.then((r) => {
|
||||
if (alive) setInfo(r)
|
||||
})
|
||||
.catch((e) => {
|
||||
if (alive) setError(e.message)
|
||||
})
|
||||
return () => {
|
||||
alive = false
|
||||
}
|
||||
}, [q.id, open])
|
||||
const destination = info?.targets.find((t: any) => t.id === target)
|
||||
return (
|
||||
<>
|
||||
<div className="danger-zone">
|
||||
<div>
|
||||
<h3>Queue löschen</h3>
|
||||
<p>
|
||||
Die Queue und ihre Mailkonfiguration entfernen. Vorhandene Tickets müssen in eine andere
|
||||
Queue verschoben werden.
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
setTarget('')
|
||||
setMapping({})
|
||||
setConfirm('')
|
||||
setOpen(true)
|
||||
}}
|
||||
>
|
||||
<Trash2 size={16} /> Queue löschen
|
||||
</Button>
|
||||
</div>
|
||||
<Modal
|
||||
open={open}
|
||||
onClose={() => !busy && setOpen(false)}
|
||||
title={`Queue „${q.name}“ löschen`}
|
||||
>
|
||||
<div className="delete-notice">
|
||||
<AlertTriangle size={19} />
|
||||
<span>
|
||||
Die Queue wird aus der aktiven Verwaltung entfernt. Die Audit-Historie bleibt erhalten.
|
||||
Ein aktiver IMAP-Abruf muss vorher deaktiviert und beendet sein.
|
||||
</span>
|
||||
</div>
|
||||
{error && (
|
||||
<div className="error" role="alert">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
{!info ? (
|
||||
<p className="muted">
|
||||
{error ? 'Löschprüfung nicht verfügbar.' : 'Queue wird geprüft …'}
|
||||
</p>
|
||||
) : (
|
||||
<form
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault()
|
||||
setBusy(true)
|
||||
setError('')
|
||||
try {
|
||||
await api(`/queues/${q.id}`, 'DELETE', { target, mapping, confirm })
|
||||
setOpen(false)
|
||||
await refresh()
|
||||
} catch (e) {
|
||||
setError((e as Error).message)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<p>
|
||||
<strong>{info.tickets} Ticket(s)</strong> in dieser Queue. Die Zuständigkeit wird beim
|
||||
Verschieben aufgehoben; Nachrichten und Anhänge bleiben erhalten.
|
||||
</p>
|
||||
{info.tickets > 0 && (
|
||||
<>
|
||||
<Field label="Zielqueue für vorhandene Tickets">
|
||||
<Select
|
||||
value={target}
|
||||
required
|
||||
onChange={(v: string) => {
|
||||
setTarget(v)
|
||||
setMapping({})
|
||||
}}
|
||||
>
|
||||
<option value="">Zielqueue auswählen</option>
|
||||
{info.targets.map((t: any) => (
|
||||
<option key={t.id} value={t.id}>
|
||||
{t.name}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
</Field>
|
||||
{!info.targets.length && (
|
||||
<div className="error">
|
||||
Keine berechtigte Zielqueue vorhanden. Zuerst eine geeignete Queue und
|
||||
Zugriffsrechte einrichten.
|
||||
</div>
|
||||
)}
|
||||
{destination && (
|
||||
<fieldset>
|
||||
<legend>Statuszuordnung</legend>
|
||||
{info.statuses
|
||||
.filter((s: any) => s.count > 0)
|
||||
.map((s: any) => (
|
||||
<Field key={s.id} label={`${s.name} (${s.count} Tickets)`}>
|
||||
<Select
|
||||
value={mapping[s.id] || ''}
|
||||
onChange={(v: string) => setMapping({ ...mapping, [s.id]: v })}
|
||||
>
|
||||
<option value="">
|
||||
{destination.statuses.find(
|
||||
(t: any) => t.active && t.behavior === s.behavior,
|
||||
)?.name ||
|
||||
destination.statuses.find(
|
||||
(t: any) => t.active && t.behavior === 'open',
|
||||
)?.name}{' '}
|
||||
(automatisch)
|
||||
</option>
|
||||
{destination.statuses
|
||||
.filter((s: any) => s.active)
|
||||
.map((s: any) => (
|
||||
<option key={s.id} value={s.id}>
|
||||
{s.name}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
</Field>
|
||||
))}
|
||||
</fieldset>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
<Field label={`Zum Bestätigen „${q.name}“ eingeben`}>
|
||||
<Input
|
||||
required
|
||||
autoComplete="off"
|
||||
value={confirm}
|
||||
onChange={(e) => setConfirm(e.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
<Button
|
||||
type="submit"
|
||||
className="danger-button"
|
||||
disabled={busy || confirm !== q.name || (info.tickets > 0 && !target)}
|
||||
>
|
||||
<Trash2 size={16} />
|
||||
{busy ? 'Wird gelöscht …' : 'Queue löschen'}
|
||||
</Button>
|
||||
</form>
|
||||
)}
|
||||
</Modal>
|
||||
</>
|
||||
)
|
||||
}
|
||||
167
src/HtmlPreview.tsx
Normal file
167
src/HtmlPreview.tsx
Normal file
@ -0,0 +1,167 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { api } from './api'
|
||||
import { Field, Select } from './App'
|
||||
import { Textarea } from './components/ui/textarea'
|
||||
export function HtmlPreview({ html, title = 'HTML-Vorschau' }: { html: string; title?: string }) {
|
||||
return (
|
||||
<div className="html-preview">
|
||||
<iframe
|
||||
title={title}
|
||||
sandbox=""
|
||||
referrerPolicy="no-referrer"
|
||||
srcDoc={`<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'"><style>body{font:14px Arial,sans-serif;color:#252329;background:#fff;margin:16px;overflow-wrap:anywhere}img{max-width:100%;height:auto}table{max-width:100%}a{color:#6d3bd1}</style></head><body>${html}</body></html>`}
|
||||
/>
|
||||
<small>Geschützte HTML-Vorschau · externe Bilder werden nicht geladen.</small>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
export function SignatureBodyEditor({ signature: s, queueId, disabled, onChange }: any) {
|
||||
const [preview, setPreview] = useState<{ html: string | null; text: string } | null>(null),
|
||||
[error, setError] = useState(''),
|
||||
[mode, setMode] = useState('user'),
|
||||
[tokens, setTokens] = useState<{ token: string; group: string; description: string }[]>([])
|
||||
const editor = useRef<HTMLTextAreaElement>(null)
|
||||
useEffect(() => {
|
||||
let alive = true
|
||||
api('/signature-placeholders')
|
||||
.then((r) => {
|
||||
if (alive) setTokens(r)
|
||||
})
|
||||
.catch(() => {})
|
||||
return () => {
|
||||
alive = false
|
||||
}
|
||||
}, [])
|
||||
useEffect(() => {
|
||||
setPreview(null)
|
||||
setError('')
|
||||
if (disabled) return
|
||||
let alive = true
|
||||
const timer = setTimeout(
|
||||
() =>
|
||||
api(`/queues/${queueId}/signatures/preview`, 'POST', {
|
||||
body: s.body,
|
||||
format: s.format || 'text',
|
||||
mode,
|
||||
})
|
||||
.then((r) => {
|
||||
if (alive) {
|
||||
setPreview(r)
|
||||
setError('')
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
if (alive) {
|
||||
setPreview(null)
|
||||
setError(e.message)
|
||||
}
|
||||
}),
|
||||
350,
|
||||
)
|
||||
return () => {
|
||||
alive = false
|
||||
clearTimeout(timer)
|
||||
}
|
||||
}, [s.body, s.format, queueId, disabled, mode])
|
||||
const insert = (token: string) => {
|
||||
const el = editor.current
|
||||
const start = el?.selectionStart ?? s.body.length,
|
||||
end = el?.selectionEnd ?? start
|
||||
onChange({ ...s, body: s.body.slice(0, start) + token + s.body.slice(end) })
|
||||
requestAnimationFrame(() => {
|
||||
el?.focus()
|
||||
el?.setSelectionRange(start + token.length, start + token.length)
|
||||
})
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<Field label="Signaturformat">
|
||||
<Select
|
||||
value={s.format || 'text'}
|
||||
disabled={disabled}
|
||||
onChange={(format: string) => onChange({ ...s, format })}
|
||||
>
|
||||
<option value="text">Klartext</option>
|
||||
<option value="html">HTML</option>
|
||||
</Select>
|
||||
</Field>
|
||||
<Textarea
|
||||
ref={editor}
|
||||
aria-label={s.format === 'html' ? 'HTML-Signatur' : 'Signaturtext'}
|
||||
required
|
||||
rows={6}
|
||||
className={s.format === 'html' ? 'code-editor' : ''}
|
||||
value={s.body}
|
||||
disabled={disabled}
|
||||
onChange={(e) => onChange({ ...s, body: e.target.value })}
|
||||
/>
|
||||
{s.format === 'html' && (
|
||||
<p className="muted signature-help">
|
||||
HTML für Formatierung, Tabellen, Links und Logos. Nicht unterstützte oder aktive Inhalte
|
||||
werden entfernt.
|
||||
</p>
|
||||
)}
|
||||
{!disabled && (
|
||||
<>
|
||||
<details className="signature-tokens">
|
||||
<summary>Platzhalter einfügen</summary>
|
||||
<p className="muted">
|
||||
Klicken zum Einfügen an der Cursorposition. Benutzer ist die Person, die antwortet;
|
||||
Bearbeiter ist die zugewiesene Person.
|
||||
</p>
|
||||
<p className="muted">
|
||||
Bestehende Vorlagen mit {'{%user.firstName%}'}, {'{%user.lastName%}'},{' '}
|
||||
{'{%user.phone%}'} und {'{%mailbox.email%}'} funktionieren ebenfalls.
|
||||
</p>
|
||||
{[...new Set(tokens.map((t) => t.group))].map((group) => (
|
||||
<div className="signature-token-group" key={group}>
|
||||
<strong>{group}</strong>
|
||||
<div>
|
||||
{tokens
|
||||
.filter((t) => t.group === group)
|
||||
.map((t) => (
|
||||
<button
|
||||
type="button"
|
||||
title={t.description}
|
||||
aria-label={`${t.token} einfügen: ${t.description}`}
|
||||
key={t.token}
|
||||
onClick={() => insert(t.token)}
|
||||
>
|
||||
{t.token}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</details>
|
||||
<Field label="Vorschau mit Beispielticket">
|
||||
<Select value={mode} onChange={setMode}>
|
||||
<option value="user">Antwort von mir</option>
|
||||
<option value="system">Automatische Eingangsmeldung</option>
|
||||
</Select>
|
||||
</Field>
|
||||
<p className="muted signature-help">
|
||||
Telefon, Position und Abteilung kommen aus der Benutzerverwaltung. Bei automatischen
|
||||
Eingangsmeldungen stehen Benutzername und E-Mail für die Queue; persönliche Felder
|
||||
bleiben leer.
|
||||
</p>
|
||||
{error ? (
|
||||
<div className="error" role="alert">
|
||||
{error}
|
||||
</div>
|
||||
) : !preview ? (
|
||||
<p className="muted" role="status">
|
||||
Vorschau wird geladen …
|
||||
</p>
|
||||
) : preview.html !== null ? (
|
||||
<HtmlPreview html={preview.html} title="Vorschau der HTML-Signatur" />
|
||||
) : (
|
||||
<pre className="signature-text-preview" aria-label="Vorschau der Klartext-Signatur">
|
||||
{preview.text || 'Leere Signatur'}
|
||||
</pre>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
229
src/InboundSettings.tsx
Normal file
229
src/InboundSettings.tsx
Normal file
@ -0,0 +1,229 @@
|
||||
import { Download, Clock3, PlugZap, RefreshCw } from 'lucide-react'
|
||||
import { Input } from './components/ui/input'
|
||||
import { Button } from './components/ui/button'
|
||||
import { Field, Select } from './App'
|
||||
import { date } from './api'
|
||||
export function InboundSettings({ config: c, update, password, setPassword, busy, action }: any) {
|
||||
const schedule = c.schedule
|
||||
const runtime = c.runtime || {}
|
||||
return (
|
||||
<>
|
||||
<div className="settings-divider" />
|
||||
<div className="settings-section-heading">
|
||||
<span className="section-icon">
|
||||
<Download size={20} />
|
||||
</span>
|
||||
<div>
|
||||
<h2>Empfangen · IMAP</h2>
|
||||
<p>Postfach, Zugang und Verarbeitung eingehender Nachrichten.</p>
|
||||
</div>
|
||||
</div>
|
||||
<label className="toggle-setting">
|
||||
<span>
|
||||
<strong>Automatischen E-Mail-Empfang aktivieren</strong>
|
||||
<small>Neue Nachrichten werden nach dem Abrufzeitplan in diese Queue importiert.</small>
|
||||
</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
aria-label="IMAP-Empfang aktivieren"
|
||||
checked={c.enabled}
|
||||
onChange={(e) => update('enabled', e.target.checked)}
|
||||
/>
|
||||
</label>
|
||||
<div className="smtp-grid">
|
||||
<Field label="IMAP-Server">
|
||||
<Input
|
||||
required={c.enabled}
|
||||
value={c.host}
|
||||
placeholder="imap.example.de"
|
||||
autoComplete="off"
|
||||
onChange={(e) => update('host', e.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="IMAP-Port">
|
||||
<Input
|
||||
type="number"
|
||||
required
|
||||
min={1}
|
||||
max={65535}
|
||||
value={c.port}
|
||||
onChange={(e) => update('port', Number(e.target.value))}
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
<Field label="IMAP-Verbindungssicherheit">
|
||||
<Select
|
||||
value={c.security}
|
||||
onChange={(v: string) => {
|
||||
update('security', v)
|
||||
update('port', v === 'tls' ? 993 : 143)
|
||||
}}
|
||||
>
|
||||
<option value="tls">TLS · verschlüsselt ab Verbindungsaufbau (Port 993)</option>
|
||||
<option value="starttls">
|
||||
STARTTLS · Verschlüsselung zwingend erforderlich (Port 143)
|
||||
</option>
|
||||
</Select>
|
||||
</Field>
|
||||
<div className="form-columns">
|
||||
<Field label="IMAP-Benutzername">
|
||||
<Input
|
||||
required={c.enabled}
|
||||
autoComplete="off"
|
||||
value={c.username}
|
||||
placeholder="support@example.de"
|
||||
onChange={(e) => update('username', e.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
<Field label={c.passwordSet ? 'IMAP-Passwort ersetzen (optional)' : 'IMAP-Passwort'}>
|
||||
<Input
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
required={c.enabled && !c.passwordSet}
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder={
|
||||
c.passwordSet ? 'Gespeichert · leer lassen zum Beibehalten' : 'Passwort eingeben'
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
<Field label="Postfachordner">
|
||||
<Input
|
||||
required
|
||||
value={c.folder}
|
||||
onChange={(e) => update('folder', e.target.value)}
|
||||
placeholder="INBOX"
|
||||
/>
|
||||
</Field>
|
||||
<div className="imap-options">
|
||||
<label className="check-label">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={c.onlyUnread}
|
||||
onChange={(e) => update('onlyUnread', e.target.checked)}
|
||||
/>{' '}
|
||||
Nur ungelesene Nachrichten abrufen
|
||||
</label>
|
||||
<label className="check-label">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={c.markRead}
|
||||
onChange={(e) => update('markRead', e.target.checked)}
|
||||
/>{' '}
|
||||
Nach erfolgreicher Verarbeitung als gelesen markieren
|
||||
</label>
|
||||
</div>
|
||||
<div className="settings-hint">
|
||||
Die Empfängeradresse muss zu einer Eingangsadresse dieser Queue passen. Nachrichten werden
|
||||
nicht gelöscht. Zugangsdaten werden verschlüsselt gespeichert.
|
||||
</div>
|
||||
<div className="settings-divider" />
|
||||
<div className="settings-section-heading">
|
||||
<span className="section-icon">
|
||||
<Clock3 size={20} />
|
||||
</span>
|
||||
<div>
|
||||
<h2>Abrufzeitplan / Cron-Job</h2>
|
||||
<p>Serverseitiger Hintergrundabruf, auch ohne geöffneten Browser.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-columns">
|
||||
<Field label="Zeitplan">
|
||||
<Select
|
||||
value={schedule.mode}
|
||||
onChange={(v: string) => update('schedule', { ...schedule, mode: v })}
|
||||
>
|
||||
<option value="interval">Regelmäßiges Intervall</option>
|
||||
<option value="cron">Cron-Ausdruck</option>
|
||||
</Select>
|
||||
</Field>
|
||||
{schedule.mode === 'interval' ? (
|
||||
<Field label="Abrufintervall in Sekunden">
|
||||
<Input
|
||||
type="number"
|
||||
required
|
||||
min={15}
|
||||
max={86400}
|
||||
value={schedule.seconds}
|
||||
onChange={(e) => update('schedule', { ...schedule, seconds: Number(e.target.value) })}
|
||||
/>
|
||||
</Field>
|
||||
) : (
|
||||
<Field label="Cron-Ausdruck (fünf Felder)">
|
||||
<Input
|
||||
required
|
||||
value={schedule.cron}
|
||||
onChange={(e) => update('schedule', { ...schedule, cron: e.target.value })}
|
||||
placeholder="*/5 * * * *"
|
||||
/>
|
||||
</Field>
|
||||
)}
|
||||
</div>
|
||||
<Field label="Zeitzone des Abrufzeitplans">
|
||||
<Input
|
||||
required
|
||||
value={schedule.timezone}
|
||||
onChange={(e) => update('schedule', { ...schedule, timezone: e.target.value })}
|
||||
placeholder="Europe/Berlin"
|
||||
/>
|
||||
</Field>
|
||||
{schedule.mode === 'cron' && (
|
||||
<p className="cron-help">
|
||||
<code>*/5 * * * *</code> alle 5 Minuten · <code>0 8-18 * * 1-5</code> werktags stündlich
|
||||
von 8 bis 18 Uhr. Reihenfolge: Minute, Stunde, Tag, Monat, Wochentag.
|
||||
</p>
|
||||
)}
|
||||
<div className="fetch-runtime">
|
||||
<div>
|
||||
<span>Status</span>
|
||||
<strong>
|
||||
{runtime.running
|
||||
? 'Abruf läuft …'
|
||||
: runtime.error
|
||||
? 'Abruffehler'
|
||||
: c.enabled
|
||||
? 'Zeitplan aktiviert'
|
||||
: 'Empfang deaktiviert'}
|
||||
</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>Letzter Abruf</span>
|
||||
<strong>{runtime.lastRun ? date(runtime.lastRun) : 'Noch nicht ausgeführt'}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>Zuletzt erfolgreich</span>
|
||||
<strong>{runtime.lastSuccess ? date(runtime.lastSuccess) : '—'}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>Nächster Abruf</span>
|
||||
<strong>{c.enabled && runtime.nextRun ? date(runtime.nextRun) : '—'}</strong>
|
||||
</div>
|
||||
{runtime.error && <p role="status">{runtime.error}</p>}
|
||||
</div>
|
||||
<div className="fetch-actions">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={busy || !c.enabled}
|
||||
onClick={() => action('verify-imap')}
|
||||
>
|
||||
<PlugZap size={16} /> Speichern & IMAP prüfen
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={busy || !c.enabled}
|
||||
onClick={() => action('fetch')}
|
||||
>
|
||||
<RefreshCw size={16} /> Speichern & jetzt abrufen
|
||||
</Button>
|
||||
</div>
|
||||
<p className="cron-help">
|
||||
Der Abruf läuft im Syncova-Serverprozess. Der Server muss gestartet sein; nach einem
|
||||
Neustart wird ein überfälliger Abruf einmal nachgeholt.
|
||||
</p>
|
||||
</>
|
||||
)
|
||||
}
|
||||
347
src/QueueMailSettings.tsx
Normal file
347
src/QueueMailSettings.tsx
Normal file
@ -0,0 +1,347 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Mail, Server, ShieldCheck, Save, CheckCircle2, PlugZap, Info } from 'lucide-react'
|
||||
import { Button } from './components/ui/button'
|
||||
import { Input } from './components/ui/input'
|
||||
import { Textarea } from './components/ui/textarea'
|
||||
import { Field, Select } from './App'
|
||||
import { api } from './api'
|
||||
import { InboundSettings } from './InboundSettings'
|
||||
function fingerprint(c: any) {
|
||||
return JSON.stringify({ ...c, imap: c.imap ? { ...c.imap, runtime: undefined } : undefined })
|
||||
}
|
||||
type D = any
|
||||
export function QueueMailSettings({ q }: D) {
|
||||
const [config, setConfig] = useState<D>(null),
|
||||
[savedConfig, setSavedConfig] = useState(''),
|
||||
[password, setPassword] = useState(''),
|
||||
[imapPassword, setImapPassword] = useState(''),
|
||||
[busy, setBusy] = useState(false),
|
||||
[error, setError] = useState(''),
|
||||
[success, setSuccess] = useState('')
|
||||
useEffect(() => {
|
||||
let alive = true
|
||||
api(`/queues/${q.id}/mail`)
|
||||
.then((c) => {
|
||||
if (alive) {
|
||||
setConfig(c)
|
||||
setSavedConfig(fingerprint(c))
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
if (alive) setError(e.message)
|
||||
})
|
||||
const timer = setInterval(() => {
|
||||
api(`/queues/${q.id}/mail`)
|
||||
.then((fresh) => {
|
||||
if (alive)
|
||||
setConfig((current: D) =>
|
||||
current
|
||||
? { ...current, imap: { ...current.imap, runtime: fresh.imap.runtime } }
|
||||
: current,
|
||||
)
|
||||
})
|
||||
.catch(() => {})
|
||||
}, 5000)
|
||||
return () => {
|
||||
alive = false
|
||||
clearInterval(timer)
|
||||
}
|
||||
}, [q.id])
|
||||
const smtp = config?.smtp,
|
||||
ack = config?.acknowledgement
|
||||
const dirty = !!config && (fingerprint(config) !== savedConfig || !!password || !!imapPassword)
|
||||
const save = async () => {
|
||||
setError('')
|
||||
setSuccess('')
|
||||
const c = await api(`/queues/${q.id}/mail`, 'PUT', { ...config, password, imapPassword })
|
||||
setConfig(c)
|
||||
setSavedConfig(fingerprint(c))
|
||||
setPassword('')
|
||||
setImapPassword('')
|
||||
return c
|
||||
}
|
||||
const updateSmtp = (key: string, value: D) =>
|
||||
setConfig({ ...config, smtp: { ...smtp, [key]: value } })
|
||||
const updateAck = (key: string, value: D) =>
|
||||
setConfig({ ...config, acknowledgement: { ...ack, [key]: value } })
|
||||
const updateImap = (key: string, value: D) =>
|
||||
setConfig((current: D) => ({ ...current, imap: { ...current.imap, [key]: value } }))
|
||||
const imapAction = async (action: string) => {
|
||||
setBusy(true)
|
||||
setError('')
|
||||
setSuccess('')
|
||||
try {
|
||||
await save()
|
||||
const result = await api(`/queues/${q.id}/mail/${action}`, 'POST', {})
|
||||
setSuccess(result.message)
|
||||
const fresh = await api(`/queues/${q.id}/mail`)
|
||||
setConfig((c: D) => ({ ...c, imap: { ...c.imap, runtime: fresh.imap.runtime } }))
|
||||
} catch (e) {
|
||||
setError((e as Error).message)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
const placeholders: D = {
|
||||
ticketnummer: 'SYN-00123',
|
||||
betreff: 'Frage zu meiner Bestellung',
|
||||
kundenname: 'Anna Beispiel',
|
||||
queue: q.name,
|
||||
}
|
||||
const preview = (value: string) =>
|
||||
value.replace(/\{(ticketnummer|betreff|kundenname|queue)\}/g, (_, k) => placeholders[k])
|
||||
return (
|
||||
<div className="queue-mail-settings">
|
||||
{error && (
|
||||
<div className="error" role="alert">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
{success && (
|
||||
<div className="save-feedback" role="status">
|
||||
<CheckCircle2 size={17} />
|
||||
{success}
|
||||
</div>
|
||||
)}
|
||||
{!config ? (
|
||||
<div className="empty">
|
||||
{error
|
||||
? 'Einstellungen konnten nicht geladen werden.'
|
||||
: 'E-Mail-Einstellungen werden geladen …'}
|
||||
</div>
|
||||
) : (
|
||||
<form
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault()
|
||||
setBusy(true)
|
||||
try {
|
||||
await save()
|
||||
setSuccess('E-Mail-Einstellungen für ' + q.name + ' gespeichert.')
|
||||
} catch (e) {
|
||||
setError((e as Error).message)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="settings-section-heading">
|
||||
<span className="section-icon">
|
||||
<Server size={20} />
|
||||
</span>
|
||||
<div>
|
||||
<h2>Senden · SMTP</h2>
|
||||
<p>Eigener Postausgang für die Queue {q.name}.</p>
|
||||
</div>
|
||||
<span className={`config-badge ${smtp.mode === 'smtp' && !dirty ? 'configured' : ''}`}>
|
||||
{dirty
|
||||
? 'Ungespeicherte Änderungen'
|
||||
: smtp.mode === 'smtp'
|
||||
? 'SMTP konfiguriert'
|
||||
: smtp.mode === 'legacy'
|
||||
? 'Globale Konfiguration'
|
||||
: 'Entwicklungsadapter'}
|
||||
</span>
|
||||
</div>
|
||||
<Field label="Versandmodus">
|
||||
<Select
|
||||
value={smtp.mode}
|
||||
disabled={busy}
|
||||
onChange={(v: string) => updateSmtp('mode', v)}
|
||||
>
|
||||
<option value="development">Entwicklungsadapter · keine echten E-Mails</option>
|
||||
<option value="smtp">SMTP · E-Mails über den Queue-Server versenden</option>
|
||||
{smtp.mode === 'legacy' && (
|
||||
<option value="legacy">Bestehende globale SMTP-Konfiguration</option>
|
||||
)}
|
||||
</Select>
|
||||
</Field>
|
||||
{smtp.mode === 'smtp' && (
|
||||
<>
|
||||
<div className="smtp-grid">
|
||||
<Field label="SMTP-Server">
|
||||
<Input
|
||||
required
|
||||
placeholder="smtp.example.de"
|
||||
autoComplete="off"
|
||||
value={smtp.host}
|
||||
onChange={(e) => updateSmtp('host', e.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Port">
|
||||
<Input
|
||||
type="number"
|
||||
required
|
||||
min={1}
|
||||
max={65535}
|
||||
value={smtp.port}
|
||||
onChange={(e) => updateSmtp('port', Number(e.target.value))}
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
<Field label="Verbindungssicherheit">
|
||||
<Select
|
||||
value={smtp.security}
|
||||
onChange={(v: string) =>
|
||||
setConfig({
|
||||
...config,
|
||||
smtp: { ...smtp, security: v, port: v === 'tls' ? 465 : 587 },
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="tls">
|
||||
TLS · verschlüsselt ab Verbindungsaufbau (üblicherweise Port 465)
|
||||
</option>
|
||||
<option value="starttls">
|
||||
STARTTLS · Verschlüsselung zwingend erforderlich (üblicherweise Port 587)
|
||||
</option>
|
||||
</Select>
|
||||
</Field>
|
||||
<div className="form-columns">
|
||||
<Field label="Benutzername">
|
||||
<Input
|
||||
required
|
||||
autoComplete="off"
|
||||
value={smtp.username}
|
||||
onChange={(e) => updateSmtp('username', e.target.value)}
|
||||
placeholder="support@example.de"
|
||||
/>
|
||||
</Field>
|
||||
<Field
|
||||
label={config.passwordSet ? 'Passwort ersetzen (optional)' : 'SMTP-Passwort'}
|
||||
>
|
||||
<Input
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
required={!config.passwordSet}
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder={
|
||||
config.passwordSet
|
||||
? 'Gespeichert · leer lassen zum Beibehalten'
|
||||
: 'Passwort eingeben'
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
<div className="settings-hint">
|
||||
<ShieldCheck size={17} />
|
||||
<span>
|
||||
Das Passwort wird verschlüsselt gespeichert. Der SMTP-Server muss die unter
|
||||
„Adressen“ freigegebenen Absender erlauben.
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{smtp.mode === 'development' && (
|
||||
<div className="settings-hint">
|
||||
<Info size={17} />
|
||||
<span>
|
||||
Antworten und Eingangsbestätigungen dieser Queue werden nur lokal im
|
||||
Entwicklungs-Postausgang gespeichert.
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<InboundSettings
|
||||
config={config.imap}
|
||||
update={updateImap}
|
||||
password={imapPassword}
|
||||
setPassword={setImapPassword}
|
||||
busy={busy}
|
||||
action={imapAction}
|
||||
/>
|
||||
<div className="settings-divider" />
|
||||
<div className="settings-section-heading">
|
||||
<span className="section-icon">
|
||||
<Mail size={20} />
|
||||
</span>
|
||||
<div>
|
||||
<h2>Automatische Eingangsbestätigung</h2>
|
||||
<p>Geben Sie Ihren Kunden Sicherheit, dass ihre Anfrage angekommen ist.</p>
|
||||
</div>
|
||||
</div>
|
||||
<label className="toggle-setting">
|
||||
<span>
|
||||
<strong>Eingangsbestätigung aktivieren</strong>
|
||||
<small>Einmal pro neuem Ticket. Keine erneute Bestätigung bei Kundenantworten.</small>
|
||||
</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
aria-label="Eingangsbestätigung aktivieren"
|
||||
checked={ack.enabled}
|
||||
onChange={(e) => updateAck('enabled', e.target.checked)}
|
||||
/>
|
||||
</label>
|
||||
<div className={ack.enabled ? 'ack-fields' : 'ack-fields ack-disabled'}>
|
||||
<Field label="Betreff der Eingangsbestätigung">
|
||||
<Input
|
||||
required
|
||||
maxLength={500}
|
||||
value={ack.subject}
|
||||
onChange={(e) => updateAck('subject', e.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Nachricht der Eingangsbestätigung">
|
||||
<Textarea
|
||||
required
|
||||
maxLength={20000}
|
||||
rows={7}
|
||||
value={ack.body}
|
||||
onChange={(e) => updateAck('body', e.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
<div className="placeholder-list">
|
||||
<span>Verfügbare Platzhalter</span>
|
||||
{Object.keys(placeholders).map((key) => (
|
||||
<code key={key}>{'{' + key + '}'}</code>
|
||||
))}
|
||||
</div>
|
||||
<label className="check-label">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={ack.includeSignature}
|
||||
onChange={(e) => updateAck('includeSignature', e.target.checked)}
|
||||
/>{' '}
|
||||
Standardsignatur der Queue anhängen
|
||||
</label>
|
||||
<details className="ack-preview" open={ack.enabled}>
|
||||
<summary>Vorschau mit Beispieldaten</summary>
|
||||
<strong>{preview(ack.subject)}</strong>
|
||||
<div>
|
||||
{preview(ack.body)}
|
||||
{ack.includeSignature &&
|
||||
'\n\n' + (q.signatures.find((s: D) => s.default)?.body || '')}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
<div className="form-footer mail-actions">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={busy || smtp.mode === 'development'}
|
||||
onClick={async () => {
|
||||
setBusy(true)
|
||||
try {
|
||||
await save()
|
||||
const result = await api(`/queues/${q.id}/mail/verify`, 'POST', {})
|
||||
setSuccess(result.message)
|
||||
} catch (e) {
|
||||
setError((e as Error).message)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<PlugZap size={16} />
|
||||
{busy ? 'Wird geprüft …' : 'Speichern & SMTP prüfen'}
|
||||
</Button>
|
||||
<Button type="submit" disabled={busy}>
|
||||
<Save size={16} />
|
||||
{busy ? 'Bitte warten …' : 'Einstellungen speichern'}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
960
src/Settings.tsx
Normal file
960
src/Settings.tsx
Normal file
@ -0,0 +1,960 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import {
|
||||
Plus,
|
||||
Trash2,
|
||||
ArrowUp,
|
||||
ArrowDown,
|
||||
Save,
|
||||
Bell,
|
||||
Mail,
|
||||
ShieldCheck,
|
||||
Settings2,
|
||||
RefreshCw,
|
||||
} from 'lucide-react'
|
||||
import { Button } from './components/ui/button'
|
||||
import { Input } from './components/ui/input'
|
||||
import { Textarea } from './components/ui/textarea'
|
||||
import { Field, Select, Modal } from './App'
|
||||
import { api, date } from './api'
|
||||
import { DeleteQueue } from './DeleteQueue'
|
||||
import { DeleteIdentity } from './DeleteIdentity'
|
||||
import { SignatureBodyEditor } from './HtmlPreview'
|
||||
import { QueueMailSettings } from './QueueMailSettings'
|
||||
type D = any
|
||||
const behaviorNames: D = {
|
||||
new: 'Neue Anfrage',
|
||||
open: 'Offen',
|
||||
active: 'In Bearbeitung',
|
||||
wait_customer: 'Auf Kundenantwort warten',
|
||||
wait_date: 'Auf Termin warten',
|
||||
wait_goods: 'Auf Ware warten',
|
||||
closed: 'Erledigt',
|
||||
}
|
||||
const actionNames: D = {
|
||||
view: 'Tickets lesen',
|
||||
reply: 'Antworten',
|
||||
note: 'Interne Notizen',
|
||||
status: 'Status ändern',
|
||||
assign: 'Zuweisen',
|
||||
move: 'Queue wechseln',
|
||||
goods: 'Wareneingang bestätigen',
|
||||
queue: 'Queue konfigurieren',
|
||||
statuses: 'Status verwalten',
|
||||
signatures: 'Signaturen verwalten',
|
||||
users: 'Benutzer verwalten',
|
||||
logs: 'Systemprotokoll lesen',
|
||||
}
|
||||
export function SettingsPage({ page, boot, refresh, run, can }: D) {
|
||||
const [qid, setQid] = useState(boot.queues[0]?.id || ''),
|
||||
[newQueue, setNewQueue] = useState(false),
|
||||
[logs, setLogs] = useState<D[]>([]),
|
||||
[outbox, setOutbox] = useState<D[]>([]),
|
||||
[admin, setAdmin] = useState<D>(null),
|
||||
[editUser, setEditUser] = useState<D>(null),
|
||||
[editGroup, setEditGroup] = useState<D>(null),
|
||||
[deletion, setDeletion] = useState<D>(null),
|
||||
[prefs, setPrefs] = useState<D>(boot.user.prefs),
|
||||
[error, setError] = useState('')
|
||||
useEffect(() => {
|
||||
if (!boot.queues.some((q: D) => q.id === qid)) setQid(boot.queues[0]?.id || '')
|
||||
}, [boot.queues, qid])
|
||||
const load = async () => {
|
||||
try {
|
||||
if (page === 'users') setAdmin(await api('/admin'))
|
||||
if (page === 'logs') {
|
||||
setLogs(await api('/logs'))
|
||||
if (can('*', 'logs')) setOutbox(await api('/outbox'))
|
||||
}
|
||||
} catch (e) {
|
||||
setError((e as Error).message)
|
||||
}
|
||||
}
|
||||
useEffect(() => {
|
||||
load()
|
||||
}, [page])
|
||||
return (
|
||||
<>
|
||||
<div className="page-heading">
|
||||
<div>
|
||||
<div className="eyebrow">WORKSPACE VERWALTEN</div>
|
||||
<h1>
|
||||
{
|
||||
(
|
||||
{
|
||||
settings: 'Queue-Einstellungen',
|
||||
users: 'Benutzer & Gruppen',
|
||||
logs: 'Systemprotokoll',
|
||||
preferences: 'Benachrichtigungen',
|
||||
} as D
|
||||
)[page]
|
||||
}
|
||||
</h1>
|
||||
<p>
|
||||
{
|
||||
(
|
||||
{
|
||||
settings: 'Queues, Mail-Einstellungen, Abrufzeitpläne und Signaturen.',
|
||||
users: 'Klare Rollen. Passender Zugriff für Ihr Team.',
|
||||
logs: 'Änderungen und Hintergrundprozesse nachvollziehen.',
|
||||
preferences: 'Sie entscheiden, wann und wie Sie informiert werden.',
|
||||
} as D
|
||||
)[page]
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
{page === 'settings' && can('*', 'queue') && (
|
||||
<Button onClick={() => setNewQueue(true)}>
|
||||
<Plus size={16} /> Neue Queue
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
{error && (
|
||||
<div className="error" role="alert">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
{page === 'settings' && (
|
||||
<>
|
||||
<div className="queue-switcher">
|
||||
{boot.queues.map((q: D) => (
|
||||
<button
|
||||
key={q.id}
|
||||
className={qid === q.id ? 'active' : ''}
|
||||
onClick={() => setQid(q.id)}
|
||||
>
|
||||
<span className="queue-dot" style={{ background: q.color }} />
|
||||
{q.name}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{boot.queues.find((q: D) => q.id === qid) && (
|
||||
<QueueEditor
|
||||
key={qid}
|
||||
q={boot.queues.find((q: D) => q.id === qid)}
|
||||
run={run}
|
||||
refresh={refresh}
|
||||
can={can}
|
||||
/>
|
||||
)}
|
||||
<Modal open={newQueue} onClose={() => setNewQueue(false)} title="Neue Queue">
|
||||
<NewQueue
|
||||
run={run}
|
||||
onDone={async (q: D) => {
|
||||
await refresh()
|
||||
setQid(q.id)
|
||||
setNewQueue(false)
|
||||
}}
|
||||
/>
|
||||
</Modal>
|
||||
</>
|
||||
)}
|
||||
{page === 'preferences' && (
|
||||
<form
|
||||
className="settings-card preference-card"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault()
|
||||
run(
|
||||
() => api('/preferences', 'PUT', prefs),
|
||||
'Benachrichtigungseinstellungen gespeichert',
|
||||
)
|
||||
}}
|
||||
>
|
||||
<h2>Ihre Ereignisse & Kanäle</h2>
|
||||
<p className="muted">
|
||||
Benachrichtigungen erhalten Sie ausschließlich für Queues, auf die Sie zugreifen dürfen.
|
||||
</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Ereignis</th>
|
||||
<th>
|
||||
<Bell size={16} /> Glocke
|
||||
</th>
|
||||
<th>
|
||||
<Mail size={16} /> E-Mail
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{[
|
||||
['new', 'Neues Ticket'],
|
||||
['reply', 'Neue Kundenantwort'],
|
||||
['assigned', 'Persönliche Zuweisung'],
|
||||
['reopened', 'Automatisch wieder geöffnet'],
|
||||
].map(([event, label]) => (
|
||||
<tr key={event}>
|
||||
<td>{label}</td>
|
||||
{['bell', 'email'].map((ch) => (
|
||||
<td key={ch}>
|
||||
<input
|
||||
aria-label={`${label}: ${ch === 'bell' ? 'Glocke' : 'E-Mail'}`}
|
||||
type="checkbox"
|
||||
checked={prefs[event]?.[ch] ?? ch === 'bell'}
|
||||
onChange={(e) =>
|
||||
setPrefs({
|
||||
...prefs,
|
||||
[event]: {
|
||||
bell: prefs[event]?.bell ?? true,
|
||||
email: prefs[event]?.email ?? false,
|
||||
[ch]: e.target.checked,
|
||||
},
|
||||
})
|
||||
}
|
||||
/>
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
<Button type="submit">
|
||||
<Save size={16} /> Einstellungen speichern
|
||||
</Button>
|
||||
</form>
|
||||
)}
|
||||
{page === 'logs' && (
|
||||
<>
|
||||
<section className="settings-card">
|
||||
<div className="flex between">
|
||||
<h2>Audit-Protokoll</h2>
|
||||
<Button variant="outline" size="sm" onClick={load}>
|
||||
<RefreshCw size={15} /> Aktualisieren
|
||||
</Button>
|
||||
</div>
|
||||
<p className="muted">
|
||||
Unveränderliche Einträge mit Akteur, Entität und Vorher-/Nachher-Werten.
|
||||
</p>
|
||||
{logs.length === 0 && <div className="empty">Noch keine Systemereignisse.</div>}
|
||||
{logs.map((a) => (
|
||||
<div className="log-entry" key={a.id}>
|
||||
<div>
|
||||
<strong>{a.action}</strong>
|
||||
<small>
|
||||
{date(a.created_at)} ·{' '}
|
||||
{a.actor_name || boot.users.find((u: D) => u.id === a.actor)?.name || a.actor} ·{' '}
|
||||
{a.entity}
|
||||
</small>
|
||||
</div>
|
||||
<details>
|
||||
<summary>Details</summary>
|
||||
<pre>
|
||||
{JSON.stringify(
|
||||
{ vorher: JSON.parse(a.before_value), nachher: JSON.parse(a.after_value) },
|
||||
null,
|
||||
2,
|
||||
)}
|
||||
</pre>
|
||||
</details>
|
||||
</div>
|
||||
))}
|
||||
</section>
|
||||
{can('*', 'logs') && (
|
||||
<section className="settings-card">
|
||||
<h2>Versandaufträge</h2>
|
||||
<p className="muted">
|
||||
„uncertain“ erfordert die Prüfung am SMTP-Server. „blocked“ kennzeichnet einen
|
||||
inzwischen ungültigen Absender.
|
||||
</p>
|
||||
{outbox.length === 0 ? (
|
||||
<p>Keine Versandaufträge.</p>
|
||||
) : (
|
||||
outbox.map((o) => (
|
||||
<div className="log-entry" key={o.id}>
|
||||
<code>{o.id.slice(0, 8)}</code>
|
||||
<strong>{o.state}</strong>
|
||||
<span>{o.attempts} Versuche</span>
|
||||
<small>{o.error}</small>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</section>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{page === 'users' && admin && (
|
||||
<>
|
||||
<section className="settings-card">
|
||||
<div className="flex between">
|
||||
<h2>
|
||||
Teammitglieder <span className="title-count">{admin.users.length}</span>
|
||||
</h2>
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() =>
|
||||
setEditUser({ name: '', email: '', password: '', active: 1, groups: [] })
|
||||
}
|
||||
>
|
||||
<Plus size={16} /> Benutzer hinzufügen
|
||||
</Button>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>E-Mail</th>
|
||||
<th>Gruppen</th>
|
||||
<th>Status</th>
|
||||
<th />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{admin.users.map((u: D) => (
|
||||
<tr key={u.id}>
|
||||
<td>
|
||||
<strong>{u.name}</strong>
|
||||
</td>
|
||||
<td>{u.email}</td>
|
||||
<td>
|
||||
{u.groups
|
||||
.map((id: string) => admin.groups.find((g: D) => g.id === id)?.name)
|
||||
.join(', ')}
|
||||
</td>
|
||||
<td>{u.active ? 'Aktiv' : 'Deaktiviert'}</td>
|
||||
<td>
|
||||
<div className="identity-actions">
|
||||
<Button
|
||||
variant="plain"
|
||||
size="sm"
|
||||
onClick={() => setEditUser({ ...u, password: '' })}
|
||||
>
|
||||
Bearbeiten
|
||||
</Button>
|
||||
<Button
|
||||
variant="plain"
|
||||
size="sm"
|
||||
aria-label={`Benutzer ${u.name} löschen`}
|
||||
title={
|
||||
u.id === boot.user.id
|
||||
? 'Das eigene Konto ist geschützt.'
|
||||
: 'Benutzer löschen'
|
||||
}
|
||||
disabled={u.id === boot.user.id}
|
||||
onClick={() => setDeletion({ ...u, kind: 'users' })}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</Button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
<section className="settings-card">
|
||||
<div className="flex between">
|
||||
<h2>Berechtigungsgruppen</h2>
|
||||
<Button size="sm" onClick={() => setEditGroup({ name: '', permissions: {} })}>
|
||||
<Plus size={16} /> Gruppe erstellen
|
||||
</Button>
|
||||
</div>
|
||||
<p className="muted">
|
||||
Berechtigungen aller Gruppen werden addiert (Union). Eine leere Auswahl gewährt keinen
|
||||
Zugriff. „Alle Queues“ gilt auch für neue Queues. Benutzerverwaltung ist
|
||||
workspaceweit.
|
||||
</p>
|
||||
<div className="group-grid">
|
||||
{admin.groups.map((g: D) => (
|
||||
<div className="group-tile" key={g.id}>
|
||||
<button className="group-card" onClick={() => setEditGroup(structuredClone(g))}>
|
||||
<ShieldCheck size={22} />
|
||||
<strong>{g.name}</strong>
|
||||
<small>
|
||||
{Object.keys(g.permissions)
|
||||
.map((k) =>
|
||||
k === '*'
|
||||
? 'Alle Queues'
|
||||
: boot.queues.find((q: D) => q.id === k)?.name || k,
|
||||
)
|
||||
.join(', ')}
|
||||
</small>
|
||||
<span>Berechtigungen ansehen →</span>
|
||||
</button>
|
||||
<div className="group-tile-footer">
|
||||
<small>
|
||||
{admin.users.filter((u: D) => u.groups.includes(g.id)).length} Mitglieder
|
||||
</small>
|
||||
{g.id === 'admins' ? (
|
||||
<small>Geschützt</small>
|
||||
) : (
|
||||
<Button
|
||||
variant="plain"
|
||||
size="sm"
|
||||
aria-label={`Gruppe ${g.name} löschen`}
|
||||
onClick={() => setDeletion({ ...g, kind: 'groups' })}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
Löschen
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
{deletion && (
|
||||
<DeleteIdentity
|
||||
key={`${deletion.kind}/${deletion.id}`}
|
||||
target={deletion}
|
||||
onClose={() => setDeletion(null)}
|
||||
onDeleted={async () => {
|
||||
await load()
|
||||
await refresh()
|
||||
setDeletion(null)
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<Modal
|
||||
open={!!editUser}
|
||||
onClose={() => setEditUser(null)}
|
||||
title={editUser?.id ? 'Benutzer bearbeiten' : 'Benutzer hinzufügen'}
|
||||
>
|
||||
{editUser && (
|
||||
<form
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault()
|
||||
if (
|
||||
await run(async () => {
|
||||
await api('/users', 'POST', editUser)
|
||||
await load()
|
||||
}, 'Benutzer gespeichert')
|
||||
)
|
||||
setEditUser(null)
|
||||
}}
|
||||
>
|
||||
<Field label="Name">
|
||||
<Input
|
||||
required
|
||||
value={editUser.name}
|
||||
onChange={(e) => setEditUser({ ...editUser, name: e.target.value })}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="E-Mail">
|
||||
<Input
|
||||
type="email"
|
||||
required
|
||||
value={editUser.email}
|
||||
onChange={(e) => setEditUser({ ...editUser, email: e.target.value })}
|
||||
/>
|
||||
</Field>
|
||||
{(
|
||||
[
|
||||
['phone', 'Telefon'],
|
||||
['job_title', 'Position / Funktion'],
|
||||
['department', 'Abteilung'],
|
||||
] as const
|
||||
).map(([key, label]) => (
|
||||
<Field label={`${label} (optional für Signaturen)`} key={key}>
|
||||
<Input
|
||||
type={key === 'phone' ? 'tel' : 'text'}
|
||||
maxLength={200}
|
||||
value={editUser[key] || ''}
|
||||
onChange={(e) => setEditUser({ ...editUser, [key]: e.target.value })}
|
||||
/>
|
||||
</Field>
|
||||
))}
|
||||
<Field
|
||||
label={
|
||||
editUser.id
|
||||
? 'Neues Passwort (optional, mindestens 12 Zeichen)'
|
||||
: 'Passwort (mindestens 12 Zeichen)'
|
||||
}
|
||||
>
|
||||
<Input
|
||||
type="password"
|
||||
minLength={12}
|
||||
required={!editUser.id}
|
||||
value={editUser.password}
|
||||
onChange={(e) => setEditUser({ ...editUser, password: e.target.value })}
|
||||
/>
|
||||
</Field>
|
||||
<label className="check-label">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={!!editUser.active}
|
||||
onChange={(e) => setEditUser({ ...editUser, active: e.target.checked })}
|
||||
/>{' '}
|
||||
Benutzer aktiv
|
||||
</label>
|
||||
<fieldset>
|
||||
<legend>Gruppenmitgliedschaften</legend>
|
||||
{admin.groups.map((g: D) => (
|
||||
<label className="check-label" key={g.id}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={editUser.groups.includes(g.id)}
|
||||
onChange={(e) =>
|
||||
setEditUser({
|
||||
...editUser,
|
||||
groups: e.target.checked
|
||||
? [...editUser.groups, g.id]
|
||||
: editUser.groups.filter((id: string) => id !== g.id),
|
||||
})
|
||||
}
|
||||
/>
|
||||
{g.name}
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
<Button type="submit">Benutzer speichern</Button>
|
||||
</form>
|
||||
)}
|
||||
</Modal>
|
||||
<Modal open={!!editGroup} onClose={() => setEditGroup(null)} title="Berechtigungsgruppe">
|
||||
{editGroup && (
|
||||
<form
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault()
|
||||
if (
|
||||
await run(async () => {
|
||||
await api('/groups', 'POST', editGroup)
|
||||
await load()
|
||||
}, 'Gruppe gespeichert')
|
||||
)
|
||||
setEditGroup(null)
|
||||
}}
|
||||
>
|
||||
<Field label="Gruppenname">
|
||||
<Input
|
||||
required
|
||||
disabled={editGroup.id === 'admins'}
|
||||
value={editGroup.name}
|
||||
onChange={(e) => setEditGroup({ ...editGroup, name: e.target.value })}
|
||||
/>
|
||||
</Field>
|
||||
{[{ id: '*', name: 'Alle Queues / Workspace' }, ...boot.queues].map((q: D) => (
|
||||
<fieldset key={q.id}>
|
||||
<legend>{q.name}</legend>
|
||||
<div className="permission-grid">
|
||||
{admin.actions
|
||||
.filter((a: string) => q.id === '*' || a !== 'users')
|
||||
.map((a: string) => (
|
||||
<label className="check-label" key={a}>
|
||||
<input
|
||||
type="checkbox"
|
||||
disabled={editGroup.id === 'admins'}
|
||||
checked={(editGroup.permissions[q.id] || []).includes(a)}
|
||||
onChange={(e) =>
|
||||
setEditGroup({
|
||||
...editGroup,
|
||||
permissions: {
|
||||
...editGroup.permissions,
|
||||
[q.id]: e.target.checked
|
||||
? [...(editGroup.permissions[q.id] || []), a]
|
||||
: (editGroup.permissions[q.id] || []).filter(
|
||||
(x: string) => x !== a,
|
||||
),
|
||||
},
|
||||
})
|
||||
}
|
||||
/>
|
||||
{actionNames[a]}
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</fieldset>
|
||||
))}
|
||||
{editGroup.id !== 'admins' && <Button type="submit">Gruppe speichern</Button>}
|
||||
</form>
|
||||
)}
|
||||
</Modal>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
function NewQueue({ run, onDone }: D) {
|
||||
const [name, setName] = useState(''),
|
||||
[email, setEmail] = useState('')
|
||||
return (
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault()
|
||||
run(async () => {
|
||||
const q = await api('/queues', 'POST', {
|
||||
name,
|
||||
addresses: [{ email, incoming: true, outgoing: true, default: true }],
|
||||
})
|
||||
await onDone(q)
|
||||
}, 'Queue angelegt')
|
||||
}}
|
||||
>
|
||||
<Field label="Name">
|
||||
<Input required value={name} onChange={(e) => setName(e.target.value)} />
|
||||
</Field>
|
||||
<Field label="Erste Ein- und Ausgangsadresse">
|
||||
<Input type="email" required value={email} onChange={(e) => setEmail(e.target.value)} />
|
||||
</Field>
|
||||
<p className="muted">Die Standardstatus und eine Signatur werden automatisch erstellt.</p>
|
||||
<Button type="submit">Queue erstellen</Button>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
function QueueEditor({ q, run, refresh, can }: D) {
|
||||
const [name, setName] = useState(q.name),
|
||||
[color, setColor] = useState(q.color),
|
||||
[addresses, setAddresses] = useState<D[]>(structuredClone(q.addresses)),
|
||||
[statuses, setStatuses] = useState<D[]>(structuredClone(q.statuses)),
|
||||
[signatures, setSignatures] = useState<D[]>(structuredClone(q.signatures)),
|
||||
[mapping, setMapping] = useState<D>({}),
|
||||
[tab, setTab] = useState('addresses')
|
||||
useEffect(() => {
|
||||
setName(q.name)
|
||||
setColor(q.color)
|
||||
setAddresses(structuredClone(q.addresses))
|
||||
setStatuses(structuredClone(q.statuses))
|
||||
setSignatures(structuredClone(q.signatures))
|
||||
setMapping({})
|
||||
}, [q])
|
||||
const save = async (path: string, data: D) =>
|
||||
run(async () => {
|
||||
await api(path, 'PUT', data)
|
||||
await refresh()
|
||||
}, 'Queue-Einstellungen gespeichert')
|
||||
return (
|
||||
<section className="settings-card">
|
||||
<div className="list-tabs">
|
||||
{[
|
||||
['addresses', 'Allgemein'],
|
||||
...(can(q.id, 'queue') ? [['mail', 'Mail-Einstellungen']] : []),
|
||||
['statuses', 'Status & Automatisierung'],
|
||||
['signatures', 'Signaturen'],
|
||||
].map(([id, label]) => (
|
||||
<button key={id} className={tab === id ? 'selected' : ''} onClick={() => setTab(id)}>
|
||||
{label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{tab === 'mail' && can(q.id, 'queue') && (
|
||||
<>
|
||||
<form
|
||||
className="queue-address-settings"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault()
|
||||
save('/queues/' + q.id, { name, color, addresses })
|
||||
}}
|
||||
>
|
||||
{' '}
|
||||
<h3>E-Mail-Adressen</h3>
|
||||
<p className="muted">
|
||||
Jede Adresse gehört zu genau einer Queue. Wählen Sie einen freigegebenen
|
||||
Standardabsender.
|
||||
</p>
|
||||
{addresses.map((a: D, i: number) => (
|
||||
<div className="address-row" key={i}>
|
||||
<Input
|
||||
aria-label={`E-Mail-Adresse ${i + 1}`}
|
||||
type="email"
|
||||
required
|
||||
value={a.email}
|
||||
disabled={!can(q.id, 'queue')}
|
||||
onChange={(e) =>
|
||||
setAddresses(
|
||||
addresses.map((a, j) => (j === i ? { ...a, email: e.target.value } : a)),
|
||||
)
|
||||
}
|
||||
/>
|
||||
{['incoming', 'outgoing', 'default'].map((key, j) => (
|
||||
<label className="check-label" key={key}>
|
||||
<input
|
||||
type="checkbox"
|
||||
disabled={!can(q.id, 'queue')}
|
||||
checked={!!a[key]}
|
||||
onChange={(e) =>
|
||||
setAddresses(
|
||||
addresses.map((a, k) =>
|
||||
key === 'default'
|
||||
? { ...a, default: k === i ? e.target.checked : false }
|
||||
: k === i
|
||||
? { ...a, [key]: e.target.checked }
|
||||
: a,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
{['Eingang', 'Ausgang', 'Standard'][j]}
|
||||
</label>
|
||||
))}
|
||||
{can(q.id, 'queue') && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="plain"
|
||||
aria-label="Adresse entfernen"
|
||||
onClick={() => setAddresses(addresses.filter((_, j) => j !== i))}
|
||||
>
|
||||
<Trash2 size={16} />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
{can(q.id, 'queue') && (
|
||||
<>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
setAddresses([
|
||||
...addresses,
|
||||
{ email: '', incoming: true, outgoing: false, default: false },
|
||||
])
|
||||
}
|
||||
>
|
||||
<Plus size={16} /> Adresse hinzufügen
|
||||
</Button>
|
||||
<div className="form-footer">
|
||||
<Button type="submit">
|
||||
<Save size={16} /> Änderungen speichern
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</form>
|
||||
<div className="settings-divider" />
|
||||
<QueueMailSettings q={q} />
|
||||
</>
|
||||
)}
|
||||
{tab === 'addresses' && (
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault()
|
||||
save(`/queues/${q.id}`, { name, color, addresses })
|
||||
}}
|
||||
>
|
||||
<div className="two-fields">
|
||||
<Field label="Queue-Name">
|
||||
<Input
|
||||
required
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
disabled={!can(q.id, 'queue')}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Queue-Farbe">
|
||||
<Input
|
||||
type="color"
|
||||
value={color}
|
||||
onChange={(e) => setColor(e.target.value)}
|
||||
disabled={!can(q.id, 'queue')}
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
{can(q.id, 'queue') && (
|
||||
<div className="form-footer">
|
||||
<Button type="submit">Änderungen speichern</Button>
|
||||
</div>
|
||||
)}
|
||||
</form>
|
||||
)}
|
||||
{tab === 'addresses' && can(q.id, 'queue') && <DeleteQueue q={q} refresh={refresh} />}
|
||||
{tab === 'statuses' && (
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault()
|
||||
save(`/queues/${q.id}/statuses`, { statuses, mapping })
|
||||
}}
|
||||
>
|
||||
<h3>Status dieser Queue</h3>
|
||||
<p className="muted">
|
||||
Namen sind frei anpassbar. Interne Verhaltenskennungen steuern Automatisierungen
|
||||
unabhängig vom Namen.
|
||||
</p>
|
||||
{statuses.map((s: D, i: number) => (
|
||||
<div className="status-editor" key={s.id || i}>
|
||||
<Input
|
||||
aria-label="Statusfarbe"
|
||||
type="color"
|
||||
value={s.color}
|
||||
disabled={!can(q.id, 'statuses')}
|
||||
onChange={(e) =>
|
||||
setStatuses(
|
||||
statuses.map((s, j) => (j === i ? { ...s, color: e.target.value } : s)),
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Input
|
||||
aria-label="Statusname"
|
||||
required
|
||||
value={s.name}
|
||||
disabled={!can(q.id, 'statuses')}
|
||||
onChange={(e) =>
|
||||
setStatuses(
|
||||
statuses.map((s, j) => (j === i ? { ...s, name: e.target.value } : s)),
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Select
|
||||
aria-label="Systemverhalten"
|
||||
value={s.behavior}
|
||||
disabled={!can(q.id, 'statuses')}
|
||||
onChange={(v: string) =>
|
||||
setStatuses(statuses.map((s, j) => (j === i ? { ...s, behavior: v } : s)))
|
||||
}
|
||||
>
|
||||
{Object.entries(behaviorNames).map(([id, n]: D) => (
|
||||
<option key={id} value={id}>
|
||||
{n}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
<label className="check-label">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={!!s.active}
|
||||
disabled={!can(q.id, 'statuses')}
|
||||
onChange={(e) =>
|
||||
setStatuses(
|
||||
statuses.map((s, j) => (j === i ? { ...s, active: e.target.checked } : s)),
|
||||
)
|
||||
}
|
||||
/>{' '}
|
||||
Aktiv
|
||||
</label>
|
||||
{can(q.id, 'statuses') && (
|
||||
<div className="flex">
|
||||
<Button
|
||||
type="button"
|
||||
variant="plain"
|
||||
aria-label="Status nach oben"
|
||||
disabled={!i}
|
||||
onClick={() => {
|
||||
const a = [...statuses]
|
||||
;[a[i - 1], a[i]] = [a[i], a[i - 1]]
|
||||
setStatuses(a)
|
||||
}}
|
||||
>
|
||||
<ArrowUp size={15} />
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="plain"
|
||||
aria-label="Status nach unten"
|
||||
disabled={i === statuses.length - 1}
|
||||
onClick={() => {
|
||||
const a = [...statuses]
|
||||
;[a[i + 1], a[i]] = [a[i], a[i + 1]]
|
||||
setStatuses(a)
|
||||
}}
|
||||
>
|
||||
<ArrowDown size={15} />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
{!s.active && s.id && (
|
||||
<Field label="Verwendete Tickets zuordnen">
|
||||
<Select
|
||||
value={mapping[s.id] || ''}
|
||||
onChange={(id: string) => setMapping({ ...mapping, [s.id]: id })}
|
||||
>
|
||||
<option value="">Zielstatus auswählen</option>
|
||||
{statuses
|
||||
.filter((z) => z.active && z.id !== s.id && z.behavior !== 'wait_date')
|
||||
.map((z) => (
|
||||
<option key={z.id} value={z.id}>
|
||||
{z.name}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
</Field>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
{can(q.id, 'statuses') && (
|
||||
<>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
setStatuses([
|
||||
...statuses,
|
||||
{ name: '', color: '#64748b', behavior: 'open', active: 1 },
|
||||
])
|
||||
}
|
||||
>
|
||||
<Plus size={16} /> Status hinzufügen
|
||||
</Button>
|
||||
<div className="form-footer">
|
||||
<Button type="submit">Status speichern</Button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</form>
|
||||
)}
|
||||
{tab === 'signatures' && (
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault()
|
||||
save(`/queues/${q.id}/signatures`, { signatures })
|
||||
}}
|
||||
>
|
||||
<h3>Signaturen für {q.name}</h3>
|
||||
<p className="muted">
|
||||
Die Standardsignatur erscheint automatisch im Antworteditor. HTML-Signaturen werden mit
|
||||
einer Klartextalternative versendet.
|
||||
</p>
|
||||
{signatures.map((s: D, i: number) => (
|
||||
<div className="signature-editor" key={s.id || i}>
|
||||
<div className="flex">
|
||||
<Input
|
||||
aria-label="Signaturname"
|
||||
required
|
||||
value={s.name}
|
||||
disabled={!can(q.id, 'signatures')}
|
||||
onChange={(e) =>
|
||||
setSignatures(
|
||||
signatures.map((s, j) => (j === i ? { ...s, name: e.target.value } : s)),
|
||||
)
|
||||
}
|
||||
/>
|
||||
<label className="check-label">
|
||||
<input
|
||||
type="radio"
|
||||
name="default-signature"
|
||||
checked={!!s.default}
|
||||
disabled={!can(q.id, 'signatures')}
|
||||
onChange={() =>
|
||||
setSignatures(signatures.map((s, j) => ({ ...s, default: j === i })))
|
||||
}
|
||||
/>{' '}
|
||||
Standard
|
||||
</label>
|
||||
{can(q.id, 'signatures') && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="plain"
|
||||
aria-label="Signatur entfernen"
|
||||
onClick={() => setSignatures(signatures.filter((_, j) => j !== i))}
|
||||
>
|
||||
<Trash2 size={16} />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<SignatureBodyEditor
|
||||
signature={s}
|
||||
queueId={q.id}
|
||||
disabled={!can(q.id, 'signatures')}
|
||||
onChange={(next: D) =>
|
||||
setSignatures(signatures.map((s, j) => (j === i ? next : s)))
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
{can(q.id, 'signatures') && (
|
||||
<>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
setSignatures([...signatures, { name: '', body: '', default: false }])
|
||||
}
|
||||
>
|
||||
<Plus size={16} /> Signatur hinzufügen
|
||||
</Button>
|
||||
<div className="form-footer">
|
||||
<Button type="submit">Signaturen speichern</Button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</form>
|
||||
)}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
22
src/api.ts
Normal file
22
src/api.ts
Normal file
@ -0,0 +1,22 @@
|
||||
export async function api(path: string, method = 'GET', data?: unknown) {
|
||||
const r = await fetch('/api' + path, {
|
||||
method,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: data === undefined ? undefined : JSON.stringify(data),
|
||||
})
|
||||
const result = await r.json()
|
||||
if (!r.ok) {
|
||||
const error = new Error(result.error || 'Anfrage fehlgeschlagen.') as Error & { status: number }
|
||||
error.status = r.status
|
||||
throw error
|
||||
}
|
||||
return result
|
||||
}
|
||||
export const date = (d: string) =>
|
||||
new Intl.DateTimeFormat('de-DE', {
|
||||
day: '2-digit',
|
||||
month: 'short',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
}).format(new Date(d))
|
||||
export const number = (id: number) => `SYN-${String(id).padStart(5, '0')}`
|
||||
7
src/components/ui/absolute-center.tsx
Normal file
7
src/components/ui/absolute-center.tsx
Normal file
@ -0,0 +1,7 @@
|
||||
import { ark } from '@ark-ui/react/factory'
|
||||
import type { ComponentProps } from 'react'
|
||||
import { styled } from 'styled-system/jsx'
|
||||
import { absoluteCenter } from 'styled-system/recipes'
|
||||
|
||||
export type AbsoluteCenterProps = ComponentProps<typeof AbsoluteCenter>
|
||||
export const AbsoluteCenter = styled(ark.div, absoluteCenter)
|
||||
7
src/components/ui/badge.tsx
Normal file
7
src/components/ui/badge.tsx
Normal file
@ -0,0 +1,7 @@
|
||||
import { ark } from '@ark-ui/react/factory'
|
||||
import type { ComponentProps } from 'react'
|
||||
import { styled } from 'styled-system/jsx'
|
||||
import { badge } from 'styled-system/recipes'
|
||||
|
||||
export type BadgeProps = ComponentProps<typeof Badge>
|
||||
export const Badge = styled(ark.div, badge)
|
||||
81
src/components/ui/button.tsx
Normal file
81
src/components/ui/button.tsx
Normal file
@ -0,0 +1,81 @@
|
||||
'use client'
|
||||
import { ark } from '@ark-ui/react/factory'
|
||||
import { createContext, mergeProps } from '@ark-ui/react/utils'
|
||||
import { type ComponentProps, forwardRef, useMemo } from 'react'
|
||||
import { styled } from 'styled-system/jsx'
|
||||
import { type ButtonVariantProps, button } from 'styled-system/recipes'
|
||||
import { Group, type GroupProps } from './group'
|
||||
import { Loader } from './loader'
|
||||
|
||||
interface ButtonLoadingProps {
|
||||
/**
|
||||
* If `true`, the button will show a loading spinner.
|
||||
* @default false
|
||||
*/
|
||||
loading?: boolean | undefined
|
||||
/**
|
||||
* The text to show while loading.
|
||||
*/
|
||||
loadingText?: React.ReactNode | undefined
|
||||
/**
|
||||
* The spinner to show while loading.
|
||||
*/
|
||||
spinner?: React.ReactNode | undefined
|
||||
/**
|
||||
* The placement of the spinner
|
||||
* @default "start"
|
||||
*/
|
||||
spinnerPlacement?: 'start' | 'end' | undefined
|
||||
}
|
||||
|
||||
type BaseButtonProps = ComponentProps<typeof BaseButton>
|
||||
const BaseButton = styled(ark.button, button)
|
||||
|
||||
export interface ButtonProps extends BaseButtonProps, ButtonLoadingProps {}
|
||||
|
||||
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button(props, ref) {
|
||||
const propsContext = useButtonPropsContext()
|
||||
const buttonProps = useMemo(
|
||||
() => mergeProps<ButtonProps>(propsContext, props),
|
||||
[propsContext, props],
|
||||
)
|
||||
|
||||
const { loading, loadingText, children, spinner, spinnerPlacement, ...rest } = buttonProps
|
||||
return (
|
||||
<BaseButton
|
||||
type="button"
|
||||
ref={ref}
|
||||
{...rest}
|
||||
data-loading={loading ? '' : undefined}
|
||||
disabled={loading || rest.disabled}
|
||||
>
|
||||
{!props.asChild && loading ? (
|
||||
<Loader spinner={spinner} text={loadingText} spinnerPlacement={spinnerPlacement}>
|
||||
{children}
|
||||
</Loader>
|
||||
) : (
|
||||
children
|
||||
)}
|
||||
</BaseButton>
|
||||
)
|
||||
})
|
||||
|
||||
export interface ButtonGroupProps extends GroupProps, ButtonVariantProps {}
|
||||
|
||||
export const ButtonGroup = forwardRef<HTMLDivElement, ButtonGroupProps>(
|
||||
function ButtonGroup(props, ref) {
|
||||
const [variantProps, otherProps] = useMemo(() => button.splitVariantProps(props), [props])
|
||||
return (
|
||||
<ButtonPropsProvider value={variantProps}>
|
||||
<Group ref={ref} {...otherProps} />
|
||||
</ButtonPropsProvider>
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
const [ButtonPropsProvider, useButtonPropsContext] = createContext<ButtonVariantProps>({
|
||||
name: 'ButtonPropsContext',
|
||||
hookName: 'useButtonPropsContext',
|
||||
providerName: '<PropsProvider />',
|
||||
strict: false,
|
||||
})
|
||||
37
src/components/ui/dialog.tsx
Normal file
37
src/components/ui/dialog.tsx
Normal file
@ -0,0 +1,37 @@
|
||||
'use client'
|
||||
import { Dialog, useDialogContext } from '@ark-ui/react/dialog'
|
||||
import { ark } from '@ark-ui/react/factory'
|
||||
import { type ComponentProps, forwardRef } from 'react'
|
||||
import { createStyleContext, styled } from 'styled-system/jsx'
|
||||
import { dialog } from 'styled-system/recipes'
|
||||
|
||||
const { withRootProvider, withContext } = createStyleContext(dialog)
|
||||
|
||||
export type RootProps = ComponentProps<typeof Root>
|
||||
export const Root = withRootProvider(Dialog.Root, {
|
||||
defaultProps: { unmountOnExit: true, lazyMount: true },
|
||||
})
|
||||
export const RootProvider = withRootProvider(Dialog.RootProvider, {
|
||||
defaultProps: { unmountOnExit: true, lazyMount: true },
|
||||
})
|
||||
export const Backdrop = withContext(Dialog.Backdrop, 'backdrop')
|
||||
export const CloseTrigger = withContext(Dialog.CloseTrigger, 'closeTrigger')
|
||||
export const Content = withContext(Dialog.Content, 'content')
|
||||
export const Description = withContext(Dialog.Description, 'description')
|
||||
export const Positioner = withContext(Dialog.Positioner, 'positioner')
|
||||
export const Title = withContext(Dialog.Title, 'title')
|
||||
export const Trigger = withContext(Dialog.Trigger, 'trigger')
|
||||
export const Body = withContext(ark.div, 'body')
|
||||
export const Header = withContext(ark.div, 'header')
|
||||
export const Footer = withContext(ark.div, 'footer')
|
||||
|
||||
const StyledButton = styled(ark.button)
|
||||
|
||||
export const ActionTrigger = forwardRef<HTMLButtonElement, ComponentProps<typeof StyledButton>>(
|
||||
function ActionTrigger(props, ref) {
|
||||
const dialog = useDialogContext()
|
||||
return <StyledButton {...props} ref={ref} onClick={() => dialog.setOpen(false)} />
|
||||
},
|
||||
)
|
||||
|
||||
export { DialogContext as Context } from '@ark-ui/react/dialog'
|
||||
7
src/components/ui/group.tsx
Normal file
7
src/components/ui/group.tsx
Normal file
@ -0,0 +1,7 @@
|
||||
import { ark } from '@ark-ui/react'
|
||||
import type { ComponentProps } from 'react'
|
||||
import { styled } from 'styled-system/jsx'
|
||||
import { group } from 'styled-system/recipes'
|
||||
|
||||
export type GroupProps = ComponentProps<typeof Group>
|
||||
export const Group = styled(ark.div, group)
|
||||
7
src/components/ui/input.tsx
Normal file
7
src/components/ui/input.tsx
Normal file
@ -0,0 +1,7 @@
|
||||
import { Field } from '@ark-ui/react/field'
|
||||
import type { ComponentProps } from 'react'
|
||||
import { styled } from 'styled-system/jsx'
|
||||
import { input } from 'styled-system/recipes'
|
||||
|
||||
export type InputProps = ComponentProps<typeof Input>
|
||||
export const Input = styled(Field.Input, input)
|
||||
69
src/components/ui/loader.tsx
Normal file
69
src/components/ui/loader.tsx
Normal file
@ -0,0 +1,69 @@
|
||||
'use client'
|
||||
import { forwardRef } from 'react'
|
||||
import type { HTMLStyledProps } from 'styled-system/jsx'
|
||||
import { AbsoluteCenter } from './absolute-center'
|
||||
import { Span } from './span'
|
||||
import { Spinner } from './spinner'
|
||||
|
||||
export interface LoaderProps extends HTMLStyledProps<'span'> {
|
||||
/**
|
||||
* Whether the loader is visible
|
||||
* @default true
|
||||
*/
|
||||
visible?: boolean | undefined
|
||||
/**
|
||||
* The spinner to display when loading
|
||||
*/
|
||||
spinner?: React.ReactNode | undefined
|
||||
/**
|
||||
* The placement of the spinner
|
||||
* @default "start"
|
||||
*/
|
||||
spinnerPlacement?: 'start' | 'end' | undefined
|
||||
/**
|
||||
* The text to display when loading
|
||||
*/
|
||||
text?: React.ReactNode | undefined
|
||||
|
||||
children?: React.ReactNode
|
||||
}
|
||||
|
||||
export const Loader = forwardRef<HTMLSpanElement, LoaderProps>(function Loader(props, ref) {
|
||||
const {
|
||||
spinner = <Spinner size="inherit" borderWidth="0.125em" color="inherit" />,
|
||||
spinnerPlacement = 'start',
|
||||
children,
|
||||
text,
|
||||
visible = true,
|
||||
...rest
|
||||
} = props
|
||||
|
||||
if (!visible) return children
|
||||
|
||||
if (text) {
|
||||
return (
|
||||
<Span ref={ref} display="contents" {...rest}>
|
||||
{spinnerPlacement === 'start' && spinner}
|
||||
{text}
|
||||
{spinnerPlacement === 'end' && spinner}
|
||||
</Span>
|
||||
)
|
||||
}
|
||||
|
||||
if (spinner) {
|
||||
return (
|
||||
<Span ref={ref} display="contents" {...rest}>
|
||||
<AbsoluteCenter display="inline-flex">{spinner}</AbsoluteCenter>
|
||||
<Span visibility="hidden" display="contents">
|
||||
{children}
|
||||
</Span>
|
||||
</Span>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Span ref={ref} display="contents" {...rest}>
|
||||
{children}
|
||||
</Span>
|
||||
)
|
||||
})
|
||||
5
src/components/ui/span.tsx
Normal file
5
src/components/ui/span.tsx
Normal file
@ -0,0 +1,5 @@
|
||||
import type { ComponentProps } from 'react'
|
||||
import { styled } from 'styled-system/jsx'
|
||||
|
||||
export type SpanProps = ComponentProps<typeof Span>
|
||||
export const Span = styled('span')
|
||||
7
src/components/ui/spinner.tsx
Normal file
7
src/components/ui/spinner.tsx
Normal file
@ -0,0 +1,7 @@
|
||||
import { ark } from '@ark-ui/react/factory'
|
||||
import type { ComponentProps } from 'react'
|
||||
import { styled } from 'styled-system/jsx'
|
||||
import { spinner } from 'styled-system/recipes'
|
||||
|
||||
export type SpinnerProps = ComponentProps<typeof Spinner>
|
||||
export const Spinner = styled(ark.span, spinner)
|
||||
7
src/components/ui/textarea.tsx
Normal file
7
src/components/ui/textarea.tsx
Normal file
@ -0,0 +1,7 @@
|
||||
import { Field } from '@ark-ui/react/field'
|
||||
import type { ComponentProps } from 'react'
|
||||
import { styled } from 'styled-system/jsx'
|
||||
import { textarea } from 'styled-system/recipes'
|
||||
|
||||
export type TextareaProps = ComponentProps<typeof Textarea>
|
||||
export const Textarea = styled(Field.Textarea, textarea)
|
||||
1
src/fonts.css
Normal file
1
src/fonts.css
Normal file
@ -0,0 +1 @@
|
||||
/* System fonts keep the application private, fast, and usable offline. */
|
||||
9
src/main.tsx
Normal file
9
src/main.tsx
Normal file
@ -0,0 +1,9 @@
|
||||
import React from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import App from './App'
|
||||
import './styles.css'
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
)
|
||||
2375
src/styles.css
Normal file
2375
src/styles.css
Normal file
File diff suppressed because it is too large
Load Diff
50
src/theme/animation-styles.ts
Normal file
50
src/theme/animation-styles.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { defineAnimationStyles } from '@pandacss/dev'
|
||||
|
||||
export const animationStyles = defineAnimationStyles({
|
||||
'slide-fade-in': {
|
||||
value: {
|
||||
transformOrigin: 'var(--transform-origin)',
|
||||
'&[data-placement^=top]': {
|
||||
animationName: 'slide-from-bottom, fade-in',
|
||||
},
|
||||
'&[data-placement^=bottom]': {
|
||||
animationName: 'slide-from-top, fade-in',
|
||||
},
|
||||
'&[data-placement^=left]': {
|
||||
animationName: 'slide-from-right, fade-in',
|
||||
},
|
||||
'&[data-placement^=right]': {
|
||||
animationName: 'slide-from-left, fade-in',
|
||||
},
|
||||
},
|
||||
},
|
||||
'slide-fade-out': {
|
||||
value: {
|
||||
transformOrigin: 'var(--transform-origin)',
|
||||
'&[data-placement^=top]': {
|
||||
animationName: 'slide-to-bottom, fade-out',
|
||||
},
|
||||
'&[data-placement^=bottom]': {
|
||||
animationName: 'slide-to-top, fade-out',
|
||||
},
|
||||
'&[data-placement^=left]': {
|
||||
animationName: 'slide-to-right, fade-out',
|
||||
},
|
||||
'&[data-placement^=right]': {
|
||||
animationName: 'slide-to-left, fade-out',
|
||||
},
|
||||
},
|
||||
},
|
||||
'scale-fade-in': {
|
||||
value: {
|
||||
transformOrigin: 'var(--transform-origin)',
|
||||
animationName: 'scale-in, fade-in',
|
||||
},
|
||||
},
|
||||
'scale-fade-out': {
|
||||
value: {
|
||||
transformOrigin: 'var(--transform-origin)',
|
||||
animationName: 'scale-out, fade-out',
|
||||
},
|
||||
},
|
||||
})
|
||||
69
src/theme/colors/green.ts
Normal file
69
src/theme/colors/green.ts
Normal file
@ -0,0 +1,69 @@
|
||||
import { defineSemanticTokens } from '@pandacss/dev'
|
||||
|
||||
export const green = defineSemanticTokens.colors({
|
||||
'1': { value: { _light: '#fbfefc', _dark: '#0e1512' } },
|
||||
'2': { value: { _light: '#f4fbf6', _dark: '#121b17' } },
|
||||
'3': { value: { _light: '#e6f6eb', _dark: '#132d21' } },
|
||||
'4': { value: { _light: '#d6f1df', _dark: '#113b29' } },
|
||||
'5': { value: { _light: '#c4e8d1', _dark: '#174933' } },
|
||||
'6': { value: { _light: '#adddc0', _dark: '#20573e' } },
|
||||
'7': { value: { _light: '#8eceaa', _dark: '#28684a' } },
|
||||
'8': { value: { _light: '#5bb98b', _dark: '#2f7c57' } },
|
||||
'9': { value: { _light: '#30a46c', _dark: '#30a46c' } },
|
||||
'10': { value: { _light: '#2b9a66', _dark: '#33b074' } },
|
||||
'11': { value: { _light: '#218358', _dark: '#3dd68c' } },
|
||||
'12': { value: { _light: '#193b2d', _dark: '#b1f1cb' } },
|
||||
a1: { value: { _light: '#00c04004', _dark: '#00de4505' } },
|
||||
a2: { value: { _light: '#00a32f0b', _dark: '#29f99d0b' } },
|
||||
a3: { value: { _light: '#00a43319', _dark: '#22ff991e' } },
|
||||
a4: { value: { _light: '#00a83829', _dark: '#11ff992d' } },
|
||||
a5: { value: { _light: '#019c393b', _dark: '#2bffa23c' } },
|
||||
a6: { value: { _light: '#00963c52', _dark: '#44ffaa4b' } },
|
||||
a7: { value: { _light: '#00914071', _dark: '#50fdac5e' } },
|
||||
a8: { value: { _light: '#00924ba4', _dark: '#54ffad73' } },
|
||||
a9: { value: { _light: '#008f4acf', _dark: '#44ffa49e' } },
|
||||
a10: { value: { _light: '#008647d4', _dark: '#43fea4ab' } },
|
||||
a11: { value: { _light: '#00713fde', _dark: '#46fea5d4' } },
|
||||
a12: { value: { _light: '#002616e6', _dark: '#bbffd7f0' } },
|
||||
solid: {
|
||||
bg: {
|
||||
DEFAULT: { value: { _light: '{colors.green.9}', _dark: '{colors.green.9}' } },
|
||||
hover: { value: { _light: '{colors.green.10}', _dark: '{colors.green.10}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: 'white', _dark: 'white' } } },
|
||||
},
|
||||
subtle: {
|
||||
bg: {
|
||||
DEFAULT: { value: { _light: '{colors.green.a3}', _dark: '{colors.green.a3}' } },
|
||||
hover: { value: { _light: '{colors.green.a4}', _dark: '{colors.green.a4}' } },
|
||||
active: { value: { _light: '{colors.green.a5}', _dark: '{colors.green.a5}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.green.a11}', _dark: '{colors.green.a11}' } } },
|
||||
},
|
||||
surface: {
|
||||
bg: {
|
||||
DEFAULT: { value: { _light: '{colors.green.a2}', _dark: '{colors.green.a2}' } },
|
||||
active: { value: { _light: '{colors.green.a3}', _dark: '{colors.green.a3}' } },
|
||||
},
|
||||
border: {
|
||||
DEFAULT: { value: { _light: '{colors.green.a6}', _dark: '{colors.green.a6}' } },
|
||||
hover: { value: { _light: '{colors.green.a7}', _dark: '{colors.green.a7}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.green.a11}', _dark: '{colors.green.a11}' } } },
|
||||
},
|
||||
outline: {
|
||||
bg: {
|
||||
hover: { value: { _light: '{colors.green.a2}', _dark: '{colors.green.a2}' } },
|
||||
active: { value: { _light: '{colors.green.a3}', _dark: '{colors.green.a3}' } },
|
||||
},
|
||||
border: { DEFAULT: { value: { _light: '{colors.green.a7}', _dark: '{colors.green.a7}' } } },
|
||||
fg: { DEFAULT: { value: { _light: '{colors.green.a11}', _dark: '{colors.green.a11}' } } },
|
||||
},
|
||||
plain: {
|
||||
bg: {
|
||||
hover: { value: { _light: '{colors.green.a3}', _dark: '{colors.green.a3}' } },
|
||||
active: { value: { _light: '{colors.green.a4}', _dark: '{colors.green.a4}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.green.a11}', _dark: '{colors.green.a11}' } } },
|
||||
},
|
||||
})
|
||||
70
src/theme/colors/neutral.ts
Normal file
70
src/theme/colors/neutral.ts
Normal file
@ -0,0 +1,70 @@
|
||||
import { defineSemanticTokens } from '@pandacss/dev'
|
||||
|
||||
export const neutral = defineSemanticTokens.colors({
|
||||
'1': { value: { _light: '#fcfcfc', _dark: '#111111' } },
|
||||
'2': { value: { _light: '#f9f9f9', _dark: '#191919' } },
|
||||
'3': { value: { _light: '#f0f0f0', _dark: '#222222' } },
|
||||
'4': { value: { _light: '#e8e8e8', _dark: '#2a2a2a' } },
|
||||
'5': { value: { _light: '#e0e0e0', _dark: '#313131' } },
|
||||
'6': { value: { _light: '#d9d9d9', _dark: '#3a3a3a' } },
|
||||
'7': { value: { _light: '#cecece', _dark: '#484848' } },
|
||||
'8': { value: { _light: '#bbbbbb', _dark: '#606060' } },
|
||||
'9': { value: { _light: '#8d8d8d', _dark: '#6e6e6e' } },
|
||||
'10': { value: { _light: '#838383', _dark: '#7b7b7b' } },
|
||||
'11': { value: { _light: '#646464', _dark: '#b4b4b4' } },
|
||||
'12': { value: { _light: '#202020', _dark: '#eeeeee' } },
|
||||
a1: { value: { _light: '#00000003', _dark: '#00000000' } },
|
||||
a2: { value: { _light: '#00000006', _dark: '#ffffff09' } },
|
||||
a3: { value: { _light: '#0000000f', _dark: '#ffffff12' } },
|
||||
a4: { value: { _light: '#00000017', _dark: '#ffffff1b' } },
|
||||
a5: { value: { _light: '#0000001f', _dark: '#ffffff22' } },
|
||||
a6: { value: { _light: '#00000026', _dark: '#ffffff2c' } },
|
||||
a7: { value: { _light: '#00000031', _dark: '#ffffff3b' } },
|
||||
a8: { value: { _light: '#00000044', _dark: '#ffffff55' } },
|
||||
a9: { value: { _light: '#00000072', _dark: '#ffffff64' } },
|
||||
a10: { value: { _light: '#0000007c', _dark: '#ffffff72' } },
|
||||
a11: { value: { _light: '#0000009b', _dark: '#ffffffaf' } },
|
||||
a12: { value: { _light: '#000000df', _dark: '#ffffffed' } },
|
||||
solid: {
|
||||
bg: {
|
||||
DEFAULT: { value: { _light: '{colors.black}', _dark: '{colors.white}' } },
|
||||
hover: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.white}', _dark: '{colors.black}' } } },
|
||||
},
|
||||
subtle: {
|
||||
bg: {
|
||||
DEFAULT: { value: { _light: '{colors.gray.a3}', _dark: '{colors.gray.a3}' } },
|
||||
hover: { value: { _light: '{colors.gray.a4}', _dark: '{colors.gray.a4}' } },
|
||||
active: { value: { _light: '{colors.gray.a5}', _dark: '{colors.gray.a5}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } } },
|
||||
},
|
||||
surface: {
|
||||
bg: {
|
||||
DEFAULT: { value: { _light: '{colors.white}', _dark: '{colors.gray.1}' } },
|
||||
hover: { value: { _light: '{colors.gray.2}', _dark: '{colors.gray.2}' } },
|
||||
active: { value: { _light: '{colors.gray.3}', _dark: '{colors.gray.3}' } },
|
||||
},
|
||||
border: {
|
||||
DEFAULT: { value: { _light: '{colors.gray.6}', _dark: '{colors.gray.6}' } },
|
||||
hover: { value: { _light: '{colors.gray.7}', _dark: '{colors.gray.7}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } } },
|
||||
},
|
||||
outline: {
|
||||
bg: {
|
||||
hover: { value: { _light: '{colors.gray.a2}', _dark: '{colors.gray.a2}' } },
|
||||
active: { value: { _light: '{colors.gray.a3}', _dark: '{colors.gray.a3}' } },
|
||||
},
|
||||
border: { DEFAULT: { value: { _light: '{colors.gray.6}', _dark: '{colors.gray.6}' } } },
|
||||
fg: { DEFAULT: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } } },
|
||||
},
|
||||
plain: {
|
||||
bg: {
|
||||
hover: { value: { _light: '{colors.gray.a3}', _dark: '{colors.gray.a3}' } },
|
||||
active: { value: { _light: '{colors.gray.a4}', _dark: '{colors.gray.a4}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } } },
|
||||
},
|
||||
})
|
||||
69
src/theme/colors/red.ts
Normal file
69
src/theme/colors/red.ts
Normal file
@ -0,0 +1,69 @@
|
||||
import { defineSemanticTokens } from '@pandacss/dev'
|
||||
|
||||
export const red = defineSemanticTokens.colors({
|
||||
'1': { value: { _light: '#fffcfc', _dark: '#191111' } },
|
||||
'2': { value: { _light: '#fff7f7', _dark: '#201314' } },
|
||||
'3': { value: { _light: '#feebec', _dark: '#3b1219' } },
|
||||
'4': { value: { _light: '#ffdbdc', _dark: '#500f1c' } },
|
||||
'5': { value: { _light: '#ffcdce', _dark: '#611623' } },
|
||||
'6': { value: { _light: '#fdbdbe', _dark: '#72232d' } },
|
||||
'7': { value: { _light: '#f4a9aa', _dark: '#8c333a' } },
|
||||
'8': { value: { _light: '#eb8e90', _dark: '#b54548' } },
|
||||
'9': { value: { _light: '#e5484d', _dark: '#e5484d' } },
|
||||
'10': { value: { _light: '#dc3e42', _dark: '#ec5d5e' } },
|
||||
'11': { value: { _light: '#ce2c31', _dark: '#ff9592' } },
|
||||
'12': { value: { _light: '#641723', _dark: '#ffd1d9' } },
|
||||
a1: { value: { _light: '#ff000003', _dark: '#f4121209' } },
|
||||
a2: { value: { _light: '#ff000008', _dark: '#f22f3e11' } },
|
||||
a3: { value: { _light: '#f3000d14', _dark: '#ff173f2d' } },
|
||||
a4: { value: { _light: '#ff000824', _dark: '#fe0a3b44' } },
|
||||
a5: { value: { _light: '#ff000632', _dark: '#ff204756' } },
|
||||
a6: { value: { _light: '#f8000442', _dark: '#ff3e5668' } },
|
||||
a7: { value: { _light: '#df000356', _dark: '#ff536184' } },
|
||||
a8: { value: { _light: '#d2000571', _dark: '#ff5d61b0' } },
|
||||
a9: { value: { _light: '#db0007b7', _dark: '#fe4e54e4' } },
|
||||
a10: { value: { _light: '#d10005c1', _dark: '#ff6465eb' } },
|
||||
a11: { value: { _light: '#c40006d3', _dark: '#ff9592' } },
|
||||
a12: { value: { _light: '#55000de8', _dark: '#ffd1d9' } },
|
||||
solid: {
|
||||
bg: {
|
||||
DEFAULT: { value: { _light: '{colors.red.9}', _dark: '{colors.red.9}' } },
|
||||
hover: { value: { _light: '{colors.red.10}', _dark: '{colors.red.10}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: 'white', _dark: 'white' } } },
|
||||
},
|
||||
subtle: {
|
||||
bg: {
|
||||
DEFAULT: { value: { _light: '{colors.red.a3}', _dark: '{colors.red.a3}' } },
|
||||
hover: { value: { _light: '{colors.red.a4}', _dark: '{colors.red.a4}' } },
|
||||
active: { value: { _light: '{colors.red.a5}', _dark: '{colors.red.a5}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.red.a11}', _dark: '{colors.red.a11}' } } },
|
||||
},
|
||||
surface: {
|
||||
bg: {
|
||||
DEFAULT: { value: { _light: '{colors.red.a2}', _dark: '{colors.red.a2}' } },
|
||||
active: { value: { _light: '{colors.red.a3}', _dark: '{colors.red.a3}' } },
|
||||
},
|
||||
border: {
|
||||
DEFAULT: { value: { _light: '{colors.red.a6}', _dark: '{colors.red.a6}' } },
|
||||
hover: { value: { _light: '{colors.red.a7}', _dark: '{colors.red.a7}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.red.a11}', _dark: '{colors.red.a11}' } } },
|
||||
},
|
||||
outline: {
|
||||
bg: {
|
||||
hover: { value: { _light: '{colors.red.a2}', _dark: '{colors.red.a2}' } },
|
||||
active: { value: { _light: '{colors.red.a3}', _dark: '{colors.red.a3}' } },
|
||||
},
|
||||
border: { DEFAULT: { value: { _light: '{colors.red.a7}', _dark: '{colors.red.a7}' } } },
|
||||
fg: { DEFAULT: { value: { _light: '{colors.red.a11}', _dark: '{colors.red.a11}' } } },
|
||||
},
|
||||
plain: {
|
||||
bg: {
|
||||
hover: { value: { _light: '{colors.red.a3}', _dark: '{colors.red.a3}' } },
|
||||
active: { value: { _light: '{colors.red.a4}', _dark: '{colors.red.a4}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.red.a11}', _dark: '{colors.red.a11}' } } },
|
||||
},
|
||||
})
|
||||
70
src/theme/colors/slate.ts
Normal file
70
src/theme/colors/slate.ts
Normal file
@ -0,0 +1,70 @@
|
||||
import { defineSemanticTokens } from '@pandacss/dev'
|
||||
|
||||
export const slate = defineSemanticTokens.colors({
|
||||
'1': { value: { _light: '#fcfcfd', _dark: '#111113' } },
|
||||
'2': { value: { _light: '#f9f9fb', _dark: '#18191b' } },
|
||||
'3': { value: { _light: '#f0f0f3', _dark: '#212225' } },
|
||||
'4': { value: { _light: '#e8e8ec', _dark: '#272a2d' } },
|
||||
'5': { value: { _light: '#e0e1e6', _dark: '#2e3135' } },
|
||||
'6': { value: { _light: '#d9d9e0', _dark: '#363a3f' } },
|
||||
'7': { value: { _light: '#cdced6', _dark: '#43484e' } },
|
||||
'8': { value: { _light: '#b9bbc6', _dark: '#5a6169' } },
|
||||
'9': { value: { _light: '#8b8d98', _dark: '#696e77' } },
|
||||
'10': { value: { _light: '#80838d', _dark: '#777b84' } },
|
||||
'11': { value: { _light: '#60646c', _dark: '#b0b4ba' } },
|
||||
'12': { value: { _light: '#1c2024', _dark: '#edeef0' } },
|
||||
a1: { value: { _light: '#00005503', _dark: '#00000000' } },
|
||||
a2: { value: { _light: '#00005506', _dark: '#d8f4f609' } },
|
||||
a3: { value: { _light: '#0000330f', _dark: '#ddeaf814' } },
|
||||
a4: { value: { _light: '#00002d17', _dark: '#d3edf81d' } },
|
||||
a5: { value: { _light: '#0009321f', _dark: '#d9edfe25' } },
|
||||
a6: { value: { _light: '#00002f26', _dark: '#d6ebfd30' } },
|
||||
a7: { value: { _light: '#00062e32', _dark: '#d9edff40' } },
|
||||
a8: { value: { _light: '#00083046', _dark: '#d9edff5d' } },
|
||||
a9: { value: { _light: '#00051d74', _dark: '#dfebfd6d' } },
|
||||
a10: { value: { _light: '#00071b7f', _dark: '#e5edfd7b' } },
|
||||
a11: { value: { _light: '#0007149f', _dark: '#f1f7feb5' } },
|
||||
a12: { value: { _light: '#000509e3', _dark: '#fcfdffef' } },
|
||||
solid: {
|
||||
bg: {
|
||||
DEFAULT: { value: { _light: '{colors.black}', _dark: '{colors.white}' } },
|
||||
hover: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.white}', _dark: '{colors.black}' } } },
|
||||
},
|
||||
subtle: {
|
||||
bg: {
|
||||
DEFAULT: { value: { _light: '{colors.gray.a3}', _dark: '{colors.gray.a3}' } },
|
||||
hover: { value: { _light: '{colors.gray.a4}', _dark: '{colors.gray.a4}' } },
|
||||
active: { value: { _light: '{colors.gray.a5}', _dark: '{colors.gray.a5}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } } },
|
||||
},
|
||||
surface: {
|
||||
bg: {
|
||||
DEFAULT: { value: { _light: '{colors.white}', _dark: '{colors.gray.1}' } },
|
||||
hover: { value: { _light: '{colors.gray.2}', _dark: '{colors.gray.2}' } },
|
||||
active: { value: { _light: '{colors.gray.3}', _dark: '{colors.gray.3}' } },
|
||||
},
|
||||
border: {
|
||||
DEFAULT: { value: { _light: '{colors.gray.6}', _dark: '{colors.gray.6}' } },
|
||||
hover: { value: { _light: '{colors.gray.7}', _dark: '{colors.gray.7}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } } },
|
||||
},
|
||||
outline: {
|
||||
bg: {
|
||||
hover: { value: { _light: '{colors.gray.a2}', _dark: '{colors.gray.a2}' } },
|
||||
active: { value: { _light: '{colors.gray.a3}', _dark: '{colors.gray.a3}' } },
|
||||
},
|
||||
border: { DEFAULT: { value: { _light: '{colors.gray.6}', _dark: '{colors.gray.6}' } } },
|
||||
fg: { DEFAULT: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } } },
|
||||
},
|
||||
plain: {
|
||||
bg: {
|
||||
hover: { value: { _light: '{colors.gray.a3}', _dark: '{colors.gray.a3}' } },
|
||||
active: { value: { _light: '{colors.gray.a4}', _dark: '{colors.gray.a4}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } } },
|
||||
},
|
||||
})
|
||||
69
src/theme/colors/teal.ts
Normal file
69
src/theme/colors/teal.ts
Normal file
@ -0,0 +1,69 @@
|
||||
import { defineSemanticTokens } from '@pandacss/dev'
|
||||
|
||||
export const teal = defineSemanticTokens.colors({
|
||||
'1': { value: { _light: '#fafefd', _dark: '#0d1514' } },
|
||||
'2': { value: { _light: '#f3fbf9', _dark: '#111c1b' } },
|
||||
'3': { value: { _light: '#e0f8f3', _dark: '#0d2d2a' } },
|
||||
'4': { value: { _light: '#ccf3ea', _dark: '#023b37' } },
|
||||
'5': { value: { _light: '#b8eae0', _dark: '#084843' } },
|
||||
'6': { value: { _light: '#a1ded2', _dark: '#145750' } },
|
||||
'7': { value: { _light: '#83cdc1', _dark: '#1c6961' } },
|
||||
'8': { value: { _light: '#53b9ab', _dark: '#207e73' } },
|
||||
'9': { value: { _light: '#12a594', _dark: '#12a594' } },
|
||||
'10': { value: { _light: '#0d9b8a', _dark: '#0eb39e' } },
|
||||
'11': { value: { _light: '#008573', _dark: '#0bd8b6' } },
|
||||
'12': { value: { _light: '#0d3d38', _dark: '#adf0dd' } },
|
||||
a1: { value: { _light: '#00cc9905', _dark: '#00deab05' } },
|
||||
a2: { value: { _light: '#00aa800c', _dark: '#12fbe60c' } },
|
||||
a3: { value: { _light: '#00c69d1f', _dark: '#00ffe61e' } },
|
||||
a4: { value: { _light: '#00c39633', _dark: '#00ffe92d' } },
|
||||
a5: { value: { _light: '#00b49047', _dark: '#00ffea3b' } },
|
||||
a6: { value: { _light: '#00a6855e', _dark: '#1cffe84b' } },
|
||||
a7: { value: { _light: '#0099807c', _dark: '#2efde85f' } },
|
||||
a8: { value: { _light: '#009783ac', _dark: '#32ffe775' } },
|
||||
a9: { value: { _light: '#009e8ced', _dark: '#13ffe49f' } },
|
||||
a10: { value: { _light: '#009684f2', _dark: '#0dffe0ae' } },
|
||||
a11: { value: { _light: '#008573', _dark: '#0afed5d6' } },
|
||||
a12: { value: { _light: '#00332df2', _dark: '#b8ffebef' } },
|
||||
solid: {
|
||||
bg: {
|
||||
DEFAULT: { value: { _light: '{colors.teal.9}', _dark: '{colors.teal.9}' } },
|
||||
hover: { value: { _light: '{colors.teal.10}', _dark: '{colors.teal.10}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: 'white', _dark: 'white' } } },
|
||||
},
|
||||
subtle: {
|
||||
bg: {
|
||||
DEFAULT: { value: { _light: '{colors.teal.a3}', _dark: '{colors.teal.a3}' } },
|
||||
hover: { value: { _light: '{colors.teal.a4}', _dark: '{colors.teal.a4}' } },
|
||||
active: { value: { _light: '{colors.teal.a5}', _dark: '{colors.teal.a5}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.teal.a11}', _dark: '{colors.teal.a11}' } } },
|
||||
},
|
||||
surface: {
|
||||
bg: {
|
||||
DEFAULT: { value: { _light: '{colors.teal.a2}', _dark: '{colors.teal.a2}' } },
|
||||
active: { value: { _light: '{colors.teal.a3}', _dark: '{colors.teal.a3}' } },
|
||||
},
|
||||
border: {
|
||||
DEFAULT: { value: { _light: '{colors.teal.a6}', _dark: '{colors.teal.a6}' } },
|
||||
hover: { value: { _light: '{colors.teal.a7}', _dark: '{colors.teal.a7}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.teal.a11}', _dark: '{colors.teal.a11}' } } },
|
||||
},
|
||||
outline: {
|
||||
bg: {
|
||||
hover: { value: { _light: '{colors.teal.a2}', _dark: '{colors.teal.a2}' } },
|
||||
active: { value: { _light: '{colors.teal.a3}', _dark: '{colors.teal.a3}' } },
|
||||
},
|
||||
border: { DEFAULT: { value: { _light: '{colors.teal.a7}', _dark: '{colors.teal.a7}' } } },
|
||||
fg: { DEFAULT: { value: { _light: '{colors.teal.a11}', _dark: '{colors.teal.a11}' } } },
|
||||
},
|
||||
plain: {
|
||||
bg: {
|
||||
hover: { value: { _light: '{colors.teal.a3}', _dark: '{colors.teal.a3}' } },
|
||||
active: { value: { _light: '{colors.teal.a4}', _dark: '{colors.teal.a4}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.teal.a11}', _dark: '{colors.teal.a11}' } } },
|
||||
},
|
||||
})
|
||||
69
src/theme/colors/violet.ts
Normal file
69
src/theme/colors/violet.ts
Normal file
@ -0,0 +1,69 @@
|
||||
import { defineSemanticTokens } from '@pandacss/dev'
|
||||
|
||||
export const violet = defineSemanticTokens.colors({
|
||||
'1': { value: { _light: '#fdfcfe', _dark: '#14121f' } },
|
||||
'2': { value: { _light: '#faf8ff', _dark: '#1b1525' } },
|
||||
'3': { value: { _light: '#f4f0fe', _dark: '#291f43' } },
|
||||
'4': { value: { _light: '#ebe4ff', _dark: '#33255b' } },
|
||||
'5': { value: { _light: '#e1d9ff', _dark: '#3c2e69' } },
|
||||
'6': { value: { _light: '#d4cafe', _dark: '#473876' } },
|
||||
'7': { value: { _light: '#c2b5f5', _dark: '#56468b' } },
|
||||
'8': { value: { _light: '#aa99ec', _dark: '#6958ad' } },
|
||||
'9': { value: { _light: '#6e56cf', _dark: '#6e56cf' } },
|
||||
'10': { value: { _light: '#654dc4', _dark: '#7d66d9' } },
|
||||
'11': { value: { _light: '#6550b9', _dark: '#baa7ff' } },
|
||||
'12': { value: { _light: '#2f265f', _dark: '#e2ddfe' } },
|
||||
a1: { value: { _light: '#5500aa03', _dark: '#4422ff0f' } },
|
||||
a2: { value: { _light: '#4900ff07', _dark: '#853ff916' } },
|
||||
a3: { value: { _light: '#4400ee0f', _dark: '#8354fe36' } },
|
||||
a4: { value: { _light: '#4300ff1b', _dark: '#7d51fd50' } },
|
||||
a5: { value: { _light: '#3600ff26', _dark: '#845ffd5f' } },
|
||||
a6: { value: { _light: '#3100fb35', _dark: '#8f6cfd6d' } },
|
||||
a7: { value: { _light: '#2d01dd4a', _dark: '#9879ff83' } },
|
||||
a8: { value: { _light: '#2b00d066', _dark: '#977dfea8' } },
|
||||
a9: { value: { _light: '#2400b7a9', _dark: '#8668ffcc' } },
|
||||
a10: { value: { _light: '#2300abb2', _dark: '#9176fed7' } },
|
||||
a11: { value: { _light: '#1f0099af', _dark: '#baa7ff' } },
|
||||
a12: { value: { _light: '#0b0043d9', _dark: '#e3defffe' } },
|
||||
solid: {
|
||||
bg: {
|
||||
DEFAULT: { value: { _light: '{colors.violet.9}', _dark: '{colors.violet.9}' } },
|
||||
hover: { value: { _light: '{colors.violet.10}', _dark: '{colors.violet.10}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: 'white', _dark: 'white' } } },
|
||||
},
|
||||
subtle: {
|
||||
bg: {
|
||||
DEFAULT: { value: { _light: '{colors.violet.a3}', _dark: '{colors.violet.a3}' } },
|
||||
hover: { value: { _light: '{colors.violet.a4}', _dark: '{colors.violet.a4}' } },
|
||||
active: { value: { _light: '{colors.violet.a5}', _dark: '{colors.violet.a5}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.violet.a11}', _dark: '{colors.violet.a11}' } } },
|
||||
},
|
||||
surface: {
|
||||
bg: {
|
||||
DEFAULT: { value: { _light: '{colors.violet.a2}', _dark: '{colors.violet.a2}' } },
|
||||
active: { value: { _light: '{colors.violet.a3}', _dark: '{colors.violet.a3}' } },
|
||||
},
|
||||
border: {
|
||||
DEFAULT: { value: { _light: '{colors.violet.a6}', _dark: '{colors.violet.a6}' } },
|
||||
hover: { value: { _light: '{colors.violet.a7}', _dark: '{colors.violet.a7}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.violet.a11}', _dark: '{colors.violet.a11}' } } },
|
||||
},
|
||||
outline: {
|
||||
bg: {
|
||||
hover: { value: { _light: '{colors.violet.a2}', _dark: '{colors.violet.a2}' } },
|
||||
active: { value: { _light: '{colors.violet.a3}', _dark: '{colors.violet.a3}' } },
|
||||
},
|
||||
border: { DEFAULT: { value: { _light: '{colors.violet.a7}', _dark: '{colors.violet.a7}' } } },
|
||||
fg: { DEFAULT: { value: { _light: '{colors.violet.a11}', _dark: '{colors.violet.a11}' } } },
|
||||
},
|
||||
plain: {
|
||||
bg: {
|
||||
hover: { value: { _light: '{colors.violet.a3}', _dark: '{colors.violet.a3}' } },
|
||||
active: { value: { _light: '{colors.violet.a4}', _dark: '{colors.violet.a4}' } },
|
||||
},
|
||||
fg: { DEFAULT: { value: { _light: '{colors.violet.a11}', _dark: '{colors.violet.a11}' } } },
|
||||
},
|
||||
})
|
||||
12
src/theme/conditions.ts
Normal file
12
src/theme/conditions.ts
Normal file
@ -0,0 +1,12 @@
|
||||
export const conditions = {
|
||||
extend: {
|
||||
light: ':root:not(.dark) &, .light &',
|
||||
invalid: '&:is(:user-invalid, [data-invalid], [aria-invalid=true])',
|
||||
hover: '&:not(:disabled):hover',
|
||||
active: '&:not(:disabled):active',
|
||||
checked:
|
||||
'&:is(:checked, [data-checked], [data-state=checked], [aria-checked=true], [data-state=indeterminate])',
|
||||
on: '&:is([data-state=on])',
|
||||
pinned: '&:is([data-pinned])',
|
||||
},
|
||||
} as const
|
||||
17
src/theme/global-css.ts
Normal file
17
src/theme/global-css.ts
Normal file
@ -0,0 +1,17 @@
|
||||
export const globalCss = {
|
||||
extend: {
|
||||
'*': {
|
||||
'--global-color-border': 'colors.border',
|
||||
'--global-color-placeholder': 'colors.fg.subtle',
|
||||
'--global-color-selection': 'colors.colorPalette.subtle.bg',
|
||||
'--global-color-focus-ring': 'colors.colorPalette.solid.bg',
|
||||
},
|
||||
html: {
|
||||
colorPalette: 'violet',
|
||||
},
|
||||
body: {
|
||||
background: 'canvas',
|
||||
color: 'fg.default',
|
||||
},
|
||||
},
|
||||
}
|
||||
125
src/theme/keyframes.ts
Normal file
125
src/theme/keyframes.ts
Normal file
@ -0,0 +1,125 @@
|
||||
import { defineKeyframes } from '@pandacss/dev'
|
||||
|
||||
export const keyframes = defineKeyframes({
|
||||
// collapse
|
||||
'expand-height': {
|
||||
from: { height: '0' },
|
||||
to: { height: 'var(--height)' },
|
||||
},
|
||||
'collapse-height': {
|
||||
from: { height: 'var(--height)' },
|
||||
to: { height: '0' },
|
||||
},
|
||||
'expand-width': {
|
||||
from: { width: '0' },
|
||||
to: { width: 'var(--width)' },
|
||||
},
|
||||
'collapse-width': {
|
||||
from: { width: 'var(--width)' },
|
||||
to: { width: '0' },
|
||||
},
|
||||
// fade
|
||||
'fade-in': {
|
||||
from: { opacity: '0' },
|
||||
to: { opacity: '1' },
|
||||
},
|
||||
'fade-out': {
|
||||
from: { opacity: '1' },
|
||||
to: { opacity: '0' },
|
||||
},
|
||||
// slide from (full)
|
||||
'slide-from-left-full': {
|
||||
from: { translate: '-100% 0' },
|
||||
to: { translate: '0 0' },
|
||||
},
|
||||
'slide-from-right-full': {
|
||||
from: { translate: '100% 0' },
|
||||
to: { translate: '0 0' },
|
||||
},
|
||||
'slide-from-top-full': {
|
||||
from: { translate: '0 -100%' },
|
||||
to: { translate: '0 0' },
|
||||
},
|
||||
'slide-from-bottom-full': {
|
||||
from: { translate: '0 100%' },
|
||||
to: { translate: '0 0' },
|
||||
},
|
||||
// slide to (full)
|
||||
'slide-to-left-full': {
|
||||
from: { translate: '0 0' },
|
||||
to: { translate: '-100% 0' },
|
||||
},
|
||||
'slide-to-right-full': {
|
||||
from: { translate: '0 0' },
|
||||
to: { translate: '100% 0' },
|
||||
},
|
||||
'slide-to-top-full': {
|
||||
from: { translate: '0 0' },
|
||||
to: { translate: '0 -100%' },
|
||||
},
|
||||
'slide-to-bottom-full': {
|
||||
from: { translate: '0 0' },
|
||||
to: { translate: '0 100%' },
|
||||
},
|
||||
// slide from
|
||||
'slide-from-top': {
|
||||
'0%': { translate: '0 -0.5rem' },
|
||||
to: { translate: '0' },
|
||||
},
|
||||
'slide-from-bottom': {
|
||||
'0%': { translate: '0 0.5rem' },
|
||||
to: { translate: '0' },
|
||||
},
|
||||
'slide-from-left': {
|
||||
'0%': { translate: '-0.5rem 0' },
|
||||
to: { translate: '0' },
|
||||
},
|
||||
'slide-from-right': {
|
||||
'0%': { translate: '0.5rem 0' },
|
||||
to: { translate: '0' },
|
||||
},
|
||||
// slide to
|
||||
'slide-to-top': {
|
||||
'0%': { translate: '0' },
|
||||
to: { translate: '0 -0.5rem' },
|
||||
},
|
||||
'slide-to-bottom': {
|
||||
'0%': { translate: '0' },
|
||||
to: { translate: '0 0.5rem' },
|
||||
},
|
||||
'slide-to-left': {
|
||||
'0%': { translate: '0' },
|
||||
to: { translate: '-0.5rem 0' },
|
||||
},
|
||||
'slide-to-right': {
|
||||
'0%': { translate: '0' },
|
||||
to: { translate: '0.5rem 0' },
|
||||
},
|
||||
// scale
|
||||
'scale-in': {
|
||||
from: { scale: '0.95' },
|
||||
to: { scale: '1' },
|
||||
},
|
||||
'scale-out': {
|
||||
from: { scale: '1' },
|
||||
to: { scale: '0.95' },
|
||||
},
|
||||
'bg-position': {
|
||||
from: {
|
||||
backgroundPosition: 'var(--animate-from, 1rem) 0',
|
||||
},
|
||||
to: {
|
||||
backgroundPosition: 'var(--animate-to, 0) 0',
|
||||
},
|
||||
},
|
||||
position: {
|
||||
from: {
|
||||
insetInlineStart: 'var(--animate-from-x)',
|
||||
insetBlockStart: 'var(--animate-from-y)',
|
||||
},
|
||||
to: {
|
||||
insetInlineStart: 'var(--animate-to-x)',
|
||||
insetBlockStart: 'var(--animate-to-y)',
|
||||
},
|
||||
},
|
||||
})
|
||||
11
src/theme/layer-styles.ts
Normal file
11
src/theme/layer-styles.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { defineLayerStyles } from '@pandacss/dev'
|
||||
|
||||
export const layerStyles = defineLayerStyles({
|
||||
disabled: {
|
||||
value: {
|
||||
cursor: 'not-allowed',
|
||||
opacity: '0.67',
|
||||
filter: 'grayscale(100%)',
|
||||
},
|
||||
},
|
||||
})
|
||||
37
src/theme/recipes/absolute-center.ts
Normal file
37
src/theme/recipes/absolute-center.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { defineRecipe } from '@pandacss/dev'
|
||||
|
||||
export const absoluteCenter = defineRecipe({
|
||||
className: 'absolute-center',
|
||||
base: {
|
||||
position: 'absolute',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
},
|
||||
defaultVariants: {
|
||||
axis: 'both',
|
||||
},
|
||||
variants: {
|
||||
axis: {
|
||||
horizontal: {
|
||||
insetStart: '50%',
|
||||
translate: '-50%',
|
||||
_rtl: {
|
||||
translate: '50%',
|
||||
},
|
||||
},
|
||||
vertical: {
|
||||
top: '50%',
|
||||
translate: '0 -50%',
|
||||
},
|
||||
both: {
|
||||
insetStart: '50%',
|
||||
top: '50%',
|
||||
translate: '-50% -50%',
|
||||
_rtl: {
|
||||
translate: '50% -50%',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
49
src/theme/recipes/badge.ts
Normal file
49
src/theme/recipes/badge.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import { defineRecipe } from '@pandacss/dev'
|
||||
|
||||
export const badge = defineRecipe({
|
||||
className: 'badge',
|
||||
base: {
|
||||
display: 'inline-flex',
|
||||
alignItems: 'center',
|
||||
borderRadius: 'l2',
|
||||
lineHeight: '1',
|
||||
fontWeight: 'medium',
|
||||
fontVariantNumeric: 'tabular-nums',
|
||||
whiteSpace: 'nowrap',
|
||||
userSelect: 'none',
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: 'subtle',
|
||||
size: 'md',
|
||||
},
|
||||
variants: {
|
||||
variant: {
|
||||
solid: {
|
||||
bg: 'colorPalette.solid.bg',
|
||||
color: 'colorPalette.solid.fg',
|
||||
},
|
||||
surface: {
|
||||
bg: 'colorPalette.surface.bg',
|
||||
borderWidth: '1px',
|
||||
borderColor: 'colorPalette.surface.border',
|
||||
color: 'colorPalette.surface.fg',
|
||||
},
|
||||
subtle: {
|
||||
bg: 'colorPalette.subtle.bg',
|
||||
color: 'colorPalette.subtle.fg',
|
||||
},
|
||||
outline: {
|
||||
borderWidth: '1px',
|
||||
borderColor: 'colorPalette.outline.border',
|
||||
color: 'colorPalette.outline.fg',
|
||||
},
|
||||
},
|
||||
size: {
|
||||
sm: { fontSize: 'xs', px: '1.5', h: '4.5', gap: '0.5', _icon: { boxSize: '2.5' } },
|
||||
md: { fontSize: 'xs', px: '2', h: '5', gap: '1', _icon: { boxSize: '3' } },
|
||||
lg: { fontSize: 'xs', px: '2.5', h: '5.5', gap: '1', _icon: { boxSize: '3.5' } },
|
||||
xl: { fontSize: 'sm', px: '2.5', h: '6', gap: '1.5', _icon: { boxSize: '4' } },
|
||||
'2xl': { fontSize: 'md', px: '3', h: '7', gap: '1.5', _icon: { boxSize: '4.5' } },
|
||||
},
|
||||
},
|
||||
})
|
||||
110
src/theme/recipes/button.ts
Normal file
110
src/theme/recipes/button.ts
Normal file
@ -0,0 +1,110 @@
|
||||
import { defineRecipe } from '@pandacss/dev'
|
||||
|
||||
export const button = defineRecipe({
|
||||
className: 'button',
|
||||
jsx: ['Button', 'IconButton', 'CloseButton', 'ButtonGroup'],
|
||||
base: {
|
||||
alignItems: 'center',
|
||||
appearance: 'none',
|
||||
borderRadius: 'l2',
|
||||
cursor: 'pointer',
|
||||
display: 'inline-flex',
|
||||
flexShrink: '0',
|
||||
fontWeight: 'semibold',
|
||||
gap: '2',
|
||||
isolation: 'isolate',
|
||||
justifyContent: 'center',
|
||||
outline: '0',
|
||||
position: 'relative',
|
||||
transition: 'colors',
|
||||
transitionProperty: 'background-color, border-color, color, box-shadow',
|
||||
userSelect: 'none',
|
||||
verticalAlign: 'middle',
|
||||
whiteSpace: 'nowrap',
|
||||
_icon: {
|
||||
flexShrink: '0',
|
||||
},
|
||||
_disabled: {
|
||||
layerStyle: 'disabled',
|
||||
},
|
||||
focusVisibleRing: 'outside',
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: 'solid',
|
||||
size: 'md',
|
||||
},
|
||||
variants: {
|
||||
variant: {
|
||||
solid: {
|
||||
bg: 'colorPalette.solid.bg',
|
||||
color: 'colorPalette.solid.fg',
|
||||
_hover: {
|
||||
bg: 'colorPalette.solid.bg.hover',
|
||||
},
|
||||
},
|
||||
surface: {
|
||||
bg: 'colorPalette.surface.bg',
|
||||
borderWidth: '1px',
|
||||
borderColor: 'colorPalette.surface.border',
|
||||
color: 'colorPalette.surface.fg',
|
||||
_hover: {
|
||||
borderColor: 'colorPalette.surface.border.hover',
|
||||
},
|
||||
_active: {
|
||||
bg: 'colorPalette.surface.bg.active',
|
||||
},
|
||||
_on: {
|
||||
bg: 'colorPalette.surface.bg.active',
|
||||
},
|
||||
},
|
||||
subtle: {
|
||||
bg: 'colorPalette.subtle.bg',
|
||||
color: 'colorPalette.subtle.fg',
|
||||
_hover: {
|
||||
bg: 'colorPalette.subtle.bg.hover',
|
||||
},
|
||||
_active: {
|
||||
bg: 'colorPalette.subtle.bg.active',
|
||||
},
|
||||
_on: {
|
||||
bg: 'colorPalette.subtle.bg.active',
|
||||
},
|
||||
},
|
||||
outline: {
|
||||
borderWidth: '1px',
|
||||
borderColor: 'colorPalette.outline.border',
|
||||
color: 'colorPalette.outline.fg',
|
||||
_hover: {
|
||||
bg: 'colorPalette.outline.bg.hover',
|
||||
},
|
||||
_active: {
|
||||
bg: 'colorPalette.outline.bg.active',
|
||||
},
|
||||
_on: {
|
||||
bg: 'colorPalette.outline.bg.active',
|
||||
},
|
||||
},
|
||||
plain: {
|
||||
color: 'colorPalette.plain.fg',
|
||||
_hover: {
|
||||
bg: 'colorPalette.plain.bg.hover',
|
||||
},
|
||||
_active: {
|
||||
bg: 'colorPalette.plain.bg.active',
|
||||
},
|
||||
_on: {
|
||||
bg: 'colorPalette.plain.bg.active',
|
||||
},
|
||||
},
|
||||
},
|
||||
size: {
|
||||
'2xs': { h: '6', minW: '6', textStyle: 'xs', px: '2', _icon: { boxSize: '3.5' } },
|
||||
xs: { h: '8', minW: '8', textStyle: 'sm', px: '2.5', _icon: { boxSize: '4' } },
|
||||
sm: { h: '9', minW: '9', textStyle: 'sm', px: '3', _icon: { boxSize: '4' } },
|
||||
md: { h: '10', minW: '10', textStyle: 'sm', px: '3.5', _icon: { boxSize: '5' } },
|
||||
lg: { h: '11', minW: '11', textStyle: 'md', px: '4', _icon: { boxSize: '5' } },
|
||||
xl: { h: '12', minW: '12', textStyle: 'md', px: '4.5', _icon: { boxSize: '5.5' } },
|
||||
'2xl': { h: '16', minW: '16', textStyle: 'xl', px: '6', _icon: { boxSize: '6' } },
|
||||
},
|
||||
},
|
||||
})
|
||||
210
src/theme/recipes/dialog.ts
Normal file
210
src/theme/recipes/dialog.ts
Normal file
@ -0,0 +1,210 @@
|
||||
import { dialogAnatomy } from '@ark-ui/react/anatomy'
|
||||
import { defineSlotRecipe } from '@pandacss/dev'
|
||||
|
||||
export const dialog = defineSlotRecipe({
|
||||
className: 'dialog',
|
||||
slots: dialogAnatomy.extendWith('header', 'body', 'footer').keys(),
|
||||
base: {
|
||||
backdrop: {
|
||||
background: 'black.a7',
|
||||
height: '100dvh',
|
||||
left: '0',
|
||||
position: 'fixed',
|
||||
top: '0',
|
||||
width: '100dvw',
|
||||
zIndex: 'var(--z-index)',
|
||||
_open: {
|
||||
animationName: 'fade-in',
|
||||
animationTimingFunction: 'emphasized-in',
|
||||
animationDuration: 'normal',
|
||||
},
|
||||
_closed: {
|
||||
animationName: 'fade-out',
|
||||
animationTimingFunction: 'emphasized-out',
|
||||
animationDuration: 'fast',
|
||||
},
|
||||
},
|
||||
positioner: {
|
||||
'--dialog-z-index': 'zIndex.modal',
|
||||
display: 'flex',
|
||||
height: '100dvh',
|
||||
justifyContent: 'center',
|
||||
left: 0,
|
||||
overscrollBehaviorY: 'none',
|
||||
position: 'fixed',
|
||||
top: 0,
|
||||
width: '100dvw',
|
||||
zIndex: 'calc(var(--dialog-z-index) + var(--layer-index, 0))',
|
||||
},
|
||||
|
||||
title: {
|
||||
fontWeight: 'semibold',
|
||||
textStyle: 'lg',
|
||||
},
|
||||
description: {
|
||||
color: 'fg.muted',
|
||||
textStyle: 'sm',
|
||||
},
|
||||
closeTrigger: {
|
||||
pos: 'absolute',
|
||||
top: '3',
|
||||
insetEnd: '3',
|
||||
},
|
||||
content: {
|
||||
'--dialog-z-index': 'zIndex.modal',
|
||||
bg: 'gray.surface.bg',
|
||||
borderRadius: 'l3',
|
||||
boxShadow: 'lg',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
my: 'var(--dialog-margin, var(--dialog-base-margin))',
|
||||
outline: 0,
|
||||
position: 'relative',
|
||||
textStyle: 'sm',
|
||||
width: '100%',
|
||||
zIndex: 'calc(var(--dialog-z-index) + var(--layer-index, 0))',
|
||||
py: { base: '4', md: '6' },
|
||||
gap: { base: '4', md: '6' },
|
||||
_open: {
|
||||
animationDuration: 'slowest',
|
||||
},
|
||||
_closed: {
|
||||
animationDuration: 'normal',
|
||||
},
|
||||
},
|
||||
header: {
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: '0.5',
|
||||
px: { base: '4', md: '6' },
|
||||
flex: '0',
|
||||
},
|
||||
body: {
|
||||
display: 'flex',
|
||||
flex: '1',
|
||||
flexDirection: 'column',
|
||||
alignItems: 'flex-start',
|
||||
px: { base: '4', md: '6' },
|
||||
},
|
||||
footer: {
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'flex-end',
|
||||
flex: '0',
|
||||
gap: '3',
|
||||
px: { base: '4', md: '6' },
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
size: 'md',
|
||||
scrollBehavior: 'outside',
|
||||
placement: 'center',
|
||||
motionPreset: 'scale',
|
||||
},
|
||||
variants: {
|
||||
motionPreset: {
|
||||
scale: {
|
||||
content: {
|
||||
_open: { animationName: 'scale-in, fade-in' },
|
||||
_closed: { animationName: 'scale-out, fade-out' },
|
||||
},
|
||||
},
|
||||
'slide-in-bottom': {
|
||||
content: {
|
||||
_open: { animationName: 'slide-from-bottom, fade-in' },
|
||||
_closed: { animationName: 'slide-to-bottom, fade-out' },
|
||||
},
|
||||
},
|
||||
'slide-in-top': {
|
||||
content: {
|
||||
_open: { animationName: 'slide-from-top, fade-in' },
|
||||
_closed: { animationName: 'slide-to-top, fade-out' },
|
||||
},
|
||||
},
|
||||
'slide-in-left': {
|
||||
content: {
|
||||
_open: { animationName: 'slide-from-left, fade-in' },
|
||||
_closed: { animationName: 'slide-to-left, fade-out' },
|
||||
},
|
||||
},
|
||||
'slide-in-right': {
|
||||
content: {
|
||||
_open: { animationName: 'slide-from-right, fade-in' },
|
||||
_closed: { animationName: 'slide-to-right, fade-out' },
|
||||
},
|
||||
},
|
||||
none: {},
|
||||
},
|
||||
size: {
|
||||
xs: { content: { maxW: 'xs' } },
|
||||
sm: { content: { maxW: 'sm' } },
|
||||
md: { content: { maxW: 'md' } },
|
||||
lg: { content: { maxW: 'lg' } },
|
||||
xl: { content: { maxW: 'xl' } },
|
||||
cover: {
|
||||
positioner: { padding: '8' },
|
||||
content: {
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
'--dialog-margin': '0',
|
||||
},
|
||||
},
|
||||
full: {
|
||||
content: {
|
||||
maxW: '100dvw',
|
||||
minH: '100dvh',
|
||||
'--dialog-margin': '0',
|
||||
borderRadius: '0',
|
||||
},
|
||||
},
|
||||
},
|
||||
placement: {
|
||||
center: {
|
||||
positioner: {
|
||||
alignItems: 'center',
|
||||
},
|
||||
content: {
|
||||
'--dialog-base-margin': 'auto',
|
||||
mx: 'auto',
|
||||
},
|
||||
},
|
||||
top: {
|
||||
positioner: {
|
||||
alignItems: 'flex-start',
|
||||
},
|
||||
content: {
|
||||
'--dialog-base-margin': 'spacing.16',
|
||||
mx: 'auto',
|
||||
},
|
||||
},
|
||||
bottom: {
|
||||
positioner: {
|
||||
alignItems: 'flex-end',
|
||||
},
|
||||
content: {
|
||||
'--dialog-base-margin': 'spacing.16',
|
||||
mx: 'auto',
|
||||
},
|
||||
},
|
||||
},
|
||||
scrollBehavior: {
|
||||
inside: {
|
||||
positioner: {
|
||||
overflow: 'hidden',
|
||||
},
|
||||
content: {
|
||||
maxH: 'calc(100% - 7.5rem)',
|
||||
},
|
||||
body: {
|
||||
overflow: 'auto',
|
||||
},
|
||||
},
|
||||
outside: {
|
||||
positioner: {
|
||||
overflow: 'auto',
|
||||
pointerEvents: 'auto',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
77
src/theme/recipes/group.ts
Normal file
77
src/theme/recipes/group.ts
Normal file
@ -0,0 +1,77 @@
|
||||
import { defineRecipe } from '@pandacss/dev'
|
||||
|
||||
export const group = defineRecipe({
|
||||
className: 'group',
|
||||
base: {
|
||||
display: 'inline-flex',
|
||||
position: 'relative',
|
||||
gap: '2',
|
||||
'& > *': {
|
||||
_focusVisible: {
|
||||
zIndex: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
orientation: 'horizontal',
|
||||
},
|
||||
variants: {
|
||||
orientation: {
|
||||
horizontal: {
|
||||
flexDirection: 'row',
|
||||
},
|
||||
vertical: {
|
||||
flexDirection: 'column',
|
||||
},
|
||||
},
|
||||
attached: {
|
||||
true: {
|
||||
gap: '0',
|
||||
},
|
||||
},
|
||||
grow: {
|
||||
true: {
|
||||
display: 'flex',
|
||||
'& > *': {
|
||||
flex: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
compoundVariants: [
|
||||
{
|
||||
orientation: 'horizontal',
|
||||
attached: true,
|
||||
css: {
|
||||
'& > *:first-child': {
|
||||
borderEndRadius: '0',
|
||||
marginEnd: '-1px',
|
||||
},
|
||||
'& > *:last-child': {
|
||||
borderStartRadius: '0',
|
||||
},
|
||||
'& > *:not(:first-child):not(:last-child)': {
|
||||
borderRadius: '0',
|
||||
marginEnd: '-1px',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
orientation: 'vertical',
|
||||
attached: true,
|
||||
css: {
|
||||
'& > *:first-child': {
|
||||
borderBottomRadius: '0',
|
||||
marginBottom: '-1px',
|
||||
},
|
||||
'& > *:last-child': {
|
||||
borderTopRadius: '0',
|
||||
},
|
||||
'& > *:not(:first-child):not(:last-child)': {
|
||||
borderRadius: '0',
|
||||
marginBottom: '-1px',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
10
src/theme/recipes/index.ts
Normal file
10
src/theme/recipes/index.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { button } from './button'
|
||||
import { group } from './group'
|
||||
import { absoluteCenter } from './absolute-center'
|
||||
import { spinner } from './spinner'
|
||||
import { input } from './input'
|
||||
import { textarea } from './textarea'
|
||||
import { badge } from './badge'
|
||||
import { dialog } from './dialog'
|
||||
export const recipes = { button, group, absoluteCenter, spinner, input, textarea, badge }
|
||||
export const slotRecipes = { dialog }
|
||||
89
src/theme/recipes/input.ts
Normal file
89
src/theme/recipes/input.ts
Normal file
@ -0,0 +1,89 @@
|
||||
import type { RecipeConfig } from '@pandacss/dev'
|
||||
|
||||
export const input = {
|
||||
className: 'input',
|
||||
jsx: ['Input', 'Field.Input'],
|
||||
base: {
|
||||
appearance: 'none',
|
||||
borderRadius: 'l2',
|
||||
height: 'var(--input-height)',
|
||||
minHeight: 'var(--input-height)',
|
||||
minW: 'var(--input-height)',
|
||||
outline: '0',
|
||||
position: 'relative',
|
||||
textAlign: 'start',
|
||||
transition: 'colors',
|
||||
width: '100%',
|
||||
_disabled: {
|
||||
layerStyle: 'disabled',
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
size: 'md',
|
||||
variant: 'outline',
|
||||
},
|
||||
variants: {
|
||||
variant: {
|
||||
outline: {
|
||||
borderWidth: '1px',
|
||||
borderColor: 'gray.outline.border',
|
||||
focusVisibleRing: 'inside',
|
||||
_invalid: {
|
||||
focusRingColor: 'error',
|
||||
borderColor: 'error',
|
||||
},
|
||||
},
|
||||
surface: {
|
||||
bg: 'gray.surface.bg',
|
||||
borderWidth: '1px',
|
||||
borderColor: 'gray.surface.border',
|
||||
focusVisibleRing: 'inside',
|
||||
|
||||
_invalid: {
|
||||
focusRingColor: 'error',
|
||||
borderColor: 'error',
|
||||
},
|
||||
},
|
||||
subtle: {
|
||||
borderWidth: '1px',
|
||||
borderColor: 'transparent',
|
||||
bg: 'gray.subtle.bg',
|
||||
color: 'gray.subtle.fg',
|
||||
focusVisibleRing: 'inside',
|
||||
|
||||
_invalid: {
|
||||
focusRingColor: 'error',
|
||||
borderColor: 'error',
|
||||
},
|
||||
},
|
||||
flushed: {
|
||||
borderBottomWidth: '1px',
|
||||
borderBottomColor: 'gray.outline.border',
|
||||
borderRadius: '0',
|
||||
color: 'fg.default',
|
||||
px: '0',
|
||||
_invalid: {
|
||||
borderColor: 'error',
|
||||
},
|
||||
_focus: {
|
||||
borderColor: 'colorPalette.solid.bg',
|
||||
boxShadowColor: 'colorPalette.solid.bg',
|
||||
boxShadow: '0 1px 0 0 var(--shadow-color)',
|
||||
_invalid: {
|
||||
borderColor: 'error',
|
||||
boxShadowColor: 'error',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
size: {
|
||||
'2xs': { textStyle: 'xs', px: '1.5', '--input-height': 'sizes.7' },
|
||||
xs: { textStyle: 'sm', px: '2', '--input-height': 'sizes.8' },
|
||||
sm: { textStyle: 'sm', px: '2.5', '--input-height': 'sizes.9' },
|
||||
md: { textStyle: 'md', px: '3', '--input-height': 'sizes.10' },
|
||||
lg: { textStyle: 'md', px: '3.5', '--input-height': 'sizes.11' },
|
||||
xl: { textStyle: 'lg', px: '4', '--input-height': 'sizes.12' },
|
||||
'2xl': { textStyle: '3xl', px: '4.5', '--input-height': 'sizes.16' },
|
||||
},
|
||||
},
|
||||
} satisfies RecipeConfig
|
||||
33
src/theme/recipes/spinner.ts
Normal file
33
src/theme/recipes/spinner.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { defineRecipe } from '@pandacss/dev'
|
||||
|
||||
export const spinner = defineRecipe({
|
||||
className: 'spinner',
|
||||
base: {
|
||||
'--spinner-track-color': 'transparent',
|
||||
animation: 'spin',
|
||||
animationDuration: 'slowest',
|
||||
borderBottomColor: 'var(--spinner-track-color)',
|
||||
borderColor: 'currentColor',
|
||||
borderInlineStartColor: 'var(--spinner-track-color)',
|
||||
borderRadius: 'full',
|
||||
borderStyle: 'solid',
|
||||
borderWidth: '2px',
|
||||
display: 'inline-block',
|
||||
height: 'var(--spinner-size)',
|
||||
width: 'var(--spinner-size)',
|
||||
},
|
||||
defaultVariants: {
|
||||
size: 'md',
|
||||
},
|
||||
variants: {
|
||||
size: {
|
||||
inherit: { '--spinner-size': '1em' },
|
||||
xs: { '--spinner-size': 'sizes.3' },
|
||||
sm: { '--spinner-size': 'sizes.4' },
|
||||
md: { '--spinner-size': 'sizes.5' },
|
||||
lg: { '--spinner-size': 'sizes.6' },
|
||||
xl: { '--spinner-size': 'sizes.7' },
|
||||
'2xl': { '--spinner-size': 'sizes.8' },
|
||||
},
|
||||
},
|
||||
})
|
||||
82
src/theme/recipes/textarea.ts
Normal file
82
src/theme/recipes/textarea.ts
Normal file
@ -0,0 +1,82 @@
|
||||
import { defineRecipe } from '@pandacss/dev'
|
||||
|
||||
export const textarea = defineRecipe({
|
||||
className: 'textarea',
|
||||
base: {
|
||||
appearance: 'none',
|
||||
borderRadius: 'l2',
|
||||
minWidth: '0',
|
||||
outline: '0',
|
||||
position: 'relative',
|
||||
transition: 'colors',
|
||||
transitionProperty: 'box-shadow, border-color',
|
||||
width: '100%',
|
||||
_disabled: {
|
||||
layerStyle: 'disabled',
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
size: 'md',
|
||||
variant: 'surface',
|
||||
},
|
||||
variants: {
|
||||
variant: {
|
||||
outline: {
|
||||
borderWidth: '1px',
|
||||
borderColor: 'gray.outline.border',
|
||||
focusVisibleRing: 'inside',
|
||||
_invalid: {
|
||||
borderColor: 'error',
|
||||
focusRingColor: 'error',
|
||||
},
|
||||
},
|
||||
surface: {
|
||||
bg: 'gray.surface.bg',
|
||||
borderWidth: '1px',
|
||||
borderColor: 'gray.surface.border',
|
||||
focusVisibleRing: 'inside',
|
||||
_invalid: {
|
||||
borderColor: 'error',
|
||||
focusRingColor: 'error',
|
||||
},
|
||||
},
|
||||
subtle: {
|
||||
borderWidth: '1px',
|
||||
borderColor: 'transparent',
|
||||
bg: 'gray.subtle.bg',
|
||||
color: 'gray.subtle.fg',
|
||||
focusVisibleRing: 'inside',
|
||||
_invalid: {
|
||||
borderColor: 'error',
|
||||
focusRingColor: 'error',
|
||||
},
|
||||
},
|
||||
flushed: {
|
||||
borderBottomWidth: '1px',
|
||||
borderBottomColor: 'gray.outline.border',
|
||||
borderRadius: '0',
|
||||
color: 'fg.default',
|
||||
px: '0',
|
||||
_invalid: {
|
||||
borderColor: 'error',
|
||||
},
|
||||
_focus: {
|
||||
borderColor: 'colorPalette.solid.bg',
|
||||
boxShadowColor: 'colorPalette.solid.bg',
|
||||
boxShadow: '0 1px 0 0 var(--shadow-color)',
|
||||
_invalid: {
|
||||
borderColor: 'error',
|
||||
boxShadowColor: 'error',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
size: {
|
||||
xs: { textStyle: 'sm', px: '2', py: '5px', scrollPaddingBottom: '5px' },
|
||||
sm: { textStyle: 'sm', px: '2.5', py: '7px', scrollPaddingBottom: '7px' },
|
||||
md: { textStyle: 'md', px: '3', py: '7px', scrollPaddingBottom: '7px' },
|
||||
lg: { textStyle: 'md', px: '3.5', py: '9px', scrollPaddingBottom: '9px' },
|
||||
xl: { textStyle: 'lg', px: '4', py: '9px', scrollPaddingBottom: '9px' },
|
||||
},
|
||||
},
|
||||
})
|
||||
17
src/theme/text-styles.ts
Normal file
17
src/theme/text-styles.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { defineTextStyles } from '@pandacss/dev'
|
||||
|
||||
export const textStyles = defineTextStyles({
|
||||
xs: { value: { fontSize: 'xs', lineHeight: '1.125rem' } },
|
||||
sm: { value: { fontSize: 'sm', lineHeight: '1.25rem' } },
|
||||
md: { value: { fontSize: 'md', lineHeight: '1.5rem' } },
|
||||
lg: { value: { fontSize: 'lg', lineHeight: '1.75rem' } },
|
||||
xl: { value: { fontSize: 'xl', lineHeight: '1.875rem' } },
|
||||
'2xl': { value: { fontSize: '2xl', lineHeight: '2rem' } },
|
||||
'3xl': { value: { fontSize: '3xl', lineHeight: '2.375rem' } },
|
||||
'4xl': { value: { fontSize: '4xl', lineHeight: '2.75rem', letterSpacing: '-0.02em' } },
|
||||
'5xl': { value: { fontSize: '5xl', lineHeight: '3.75rem', letterSpacing: '-0.02em' } },
|
||||
'6xl': { value: { fontSize: '6xl', lineHeight: '4.5rem', letterSpacing: '-0.02em' } },
|
||||
'7xl': { value: { fontSize: '7xl', lineHeight: '5.75rem', letterSpacing: '-0.02em' } },
|
||||
|
||||
label: { value: { fontSize: 'sm', lineHeight: '1.25rem', fontWeight: 'medium' } },
|
||||
})
|
||||
35
src/theme/tokens/colors.ts
Normal file
35
src/theme/tokens/colors.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { defineTokens } from '@pandacss/dev'
|
||||
|
||||
const black = defineTokens.colors({
|
||||
DEFAULT: { value: '#000000' },
|
||||
a1: { value: 'rgba(0, 0, 0, 0.05)' },
|
||||
a2: { value: 'rgba(0, 0, 0, 0.1)' },
|
||||
a3: { value: 'rgba(0, 0, 0, 0.15)' },
|
||||
a4: { value: 'rgba(0, 0, 0, 0.2)' },
|
||||
a5: { value: 'rgba(0, 0, 0, 0.3)' },
|
||||
a6: { value: 'rgba(0, 0, 0, 0.4)' },
|
||||
a7: { value: 'rgba(0, 0, 0, 0.5)' },
|
||||
a8: { value: 'rgba(0, 0, 0, 0.6)' },
|
||||
a9: { value: 'rgba(0, 0, 0, 0.7)' },
|
||||
a10: { value: 'rgba(0, 0, 0, 0.8)' },
|
||||
a11: { value: 'rgba(0, 0, 0, 0.9)' },
|
||||
a12: { value: 'rgba(0, 0, 0, 0.95)' },
|
||||
})
|
||||
|
||||
const white = defineTokens.colors({
|
||||
DEFAULT: { value: '#ffffff' },
|
||||
a1: { value: 'rgba(255, 255, 255, 0.05)' },
|
||||
a2: { value: 'rgba(255, 255, 255, 0.1)' },
|
||||
a3: { value: 'rgba(255, 255, 255, 0.15)' },
|
||||
a4: { value: 'rgba(255, 255, 255, 0.2)' },
|
||||
a5: { value: 'rgba(255, 255, 255, 0.3)' },
|
||||
a6: { value: 'rgba(255, 255, 255, 0.4)' },
|
||||
a7: { value: 'rgba(255, 255, 255, 0.5)' },
|
||||
a8: { value: 'rgba(255, 255, 255, 0.6)' },
|
||||
a9: { value: 'rgba(255, 255, 255, 0.7)' },
|
||||
a10: { value: 'rgba(255, 255, 255, 0.8)' },
|
||||
a11: { value: 'rgba(255, 255, 255, 0.9)' },
|
||||
a12: { value: 'rgba(255, 255, 255, 0.95)' },
|
||||
})
|
||||
|
||||
export const colors = { black, white }
|
||||
11
src/theme/tokens/durations.ts
Normal file
11
src/theme/tokens/durations.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { defineTokens } from '@pandacss/dev'
|
||||
|
||||
export const durations = defineTokens.durations({
|
||||
fastest: { value: '50ms' },
|
||||
faster: { value: '100ms' },
|
||||
fast: { value: '150ms' },
|
||||
normal: { value: '200ms' },
|
||||
slow: { value: '250ms' },
|
||||
slower: { value: '300ms' },
|
||||
slowest: { value: '400ms' },
|
||||
})
|
||||
46
src/theme/tokens/shadows.ts
Normal file
46
src/theme/tokens/shadows.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import { defineSemanticTokens } from '@pandacss/dev'
|
||||
|
||||
export const shadows = defineSemanticTokens.shadows({
|
||||
xs: {
|
||||
value: {
|
||||
_light: '0px 1px 2px {colors.gray.a6}, 0px 0px 1px {colors.gray.a7}',
|
||||
_dark: '0px 1px 1px {colors.black.a8}, 0px 0px 1px inset {colors.gray.a8}',
|
||||
},
|
||||
},
|
||||
sm: {
|
||||
value: {
|
||||
_light: '0px 2px 4px {colors.gray.a4}, 0px 0px 1px {colors.gray.a4}',
|
||||
_dark: '0px 2px 4px {colors.black.a8}, 0px 0px 1px inset {colors.gray.a8}',
|
||||
},
|
||||
},
|
||||
md: {
|
||||
value: {
|
||||
_light: '0px 4px 8px {colors.gray.a4}, 0px 0px 1px {colors.gray.a4}',
|
||||
_dark: '0px 4px 8px {colors.black.a8}, 0px 0px 1px inset {colors.gray.a8}',
|
||||
},
|
||||
},
|
||||
lg: {
|
||||
value: {
|
||||
_light: '0px 8px 16px {colors.gray.a4}, 0px 0px 1px {colors.gray.a4}',
|
||||
_dark: '0px 8px 16px {colors.black.a8}, 0px 0px 1px inset {colors.gray.a8}',
|
||||
},
|
||||
},
|
||||
xl: {
|
||||
value: {
|
||||
_light: '0px 16px 24px {colors.gray.a4}, 0px 0px 1px {colors.gray.a4}',
|
||||
_dark: '0px 16px 24px {colors.black.a8}, 0px 0px 1px inset {colors.gray.a8}',
|
||||
},
|
||||
},
|
||||
'2xl': {
|
||||
value: {
|
||||
_light: '0px 24px 40px {colors.gray.a4}, 0px 0px 1px {colors.gray.a4}',
|
||||
_dark: '0px 24px 40px {colors.black.a8}, 0px 0px 1px inset {colors.gray.a8}',
|
||||
},
|
||||
},
|
||||
inset: {
|
||||
value: {
|
||||
_light: 'inset 8px 0 12px -8px {colors.gray.a4}',
|
||||
_dark: 'inset 8px 0 12px -8px {colors.black.a6}',
|
||||
},
|
||||
},
|
||||
})
|
||||
40
src/theme/tokens/z-index.ts
Normal file
40
src/theme/tokens/z-index.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { defineTokens } from '@pandacss/dev'
|
||||
|
||||
export const zIndex = defineTokens.zIndex({
|
||||
hide: {
|
||||
value: -1,
|
||||
},
|
||||
base: {
|
||||
value: 0,
|
||||
},
|
||||
docked: {
|
||||
value: 10,
|
||||
},
|
||||
dropdown: {
|
||||
value: 1000,
|
||||
},
|
||||
sticky: {
|
||||
value: 1100,
|
||||
},
|
||||
banner: {
|
||||
value: 1200,
|
||||
},
|
||||
overlay: {
|
||||
value: 1300,
|
||||
},
|
||||
modal: {
|
||||
value: 1400,
|
||||
},
|
||||
popover: {
|
||||
value: 1500,
|
||||
},
|
||||
skipLink: {
|
||||
value: 1600,
|
||||
},
|
||||
toast: {
|
||||
value: 1700,
|
||||
},
|
||||
tooltip: {
|
||||
value: 1800,
|
||||
},
|
||||
})
|
||||
173
tests/docker-smoke.mjs
Normal file
173
tests/docker-smoke.mjs
Normal file
@ -0,0 +1,173 @@
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import { randomUUID } from 'node:crypto'
|
||||
import { createServer } from 'node:net'
|
||||
import assert from 'node:assert/strict'
|
||||
import { mkdirSync, mkdtempSync, existsSync, rmSync, realpathSync } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
const listener = createServer()
|
||||
await new Promise((resolve) => listener.listen(0, '127.0.0.1', resolve))
|
||||
const port = listener.address().port
|
||||
await new Promise((resolve) => listener.close(resolve))
|
||||
const project = `syncova-smoke-${Date.now()}`,
|
||||
password = `Test-${randomUUID()}!`
|
||||
Object.assign(process.env, {
|
||||
SYNCOVA_IMAGE: process.env.SYNCOVA_IMAGE || 'syncova-ticket:local',
|
||||
SYNCOVA_PULL_POLICY: 'never',
|
||||
ADMIN_PASSWORD: password,
|
||||
ADMIN_EMAIL: 'docker-test@example.invalid',
|
||||
SYNCOVA_PORT: String(port),
|
||||
SYNCOVA_BIND: '127.0.0.1',
|
||||
APP_ORIGIN: `http://127.0.0.1:${port}`,
|
||||
COOKIE_SECURE: 'false',
|
||||
})
|
||||
const args = ['compose', '--env-file', '.env.docker.example', '-p', project]
|
||||
function compose(extra, selectedProject = project) {
|
||||
const selectedArgs = [...args]
|
||||
selectedArgs[selectedArgs.length - 1] = selectedProject
|
||||
const result = spawnSync('docker', [...selectedArgs, ...extra], {
|
||||
encoding: 'utf8',
|
||||
timeout: 120000,
|
||||
})
|
||||
if (result.status !== 0)
|
||||
throw new Error(
|
||||
(result.stderr || result.error?.message || 'Docker fehlgeschlagen').replaceAll(
|
||||
password,
|
||||
'[redacted]',
|
||||
),
|
||||
)
|
||||
return result.stdout
|
||||
}
|
||||
const base = `http://127.0.0.1:${port}`
|
||||
let cookie = ''
|
||||
const importProject = project + '-import'
|
||||
let importSource
|
||||
async function api(url, method = 'GET', data) {
|
||||
const options = {
|
||||
method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Connection: 'close',
|
||||
...(cookie ? { cookie } : {}),
|
||||
},
|
||||
body: data === undefined ? undefined : JSON.stringify(data),
|
||||
}
|
||||
let response
|
||||
try {
|
||||
response = await fetch(base + '/api' + url, options)
|
||||
} catch (error) {
|
||||
if (method !== 'GET') throw error
|
||||
await new Promise((resolve) => setTimeout(resolve, 500))
|
||||
response = await fetch(base + '/api' + url, options)
|
||||
}
|
||||
assert.equal(response.status, 200, `HTTP ${response.status} ${url}`)
|
||||
if (url === '/login') cookie = response.headers.get('set-cookie').split(';')[0]
|
||||
return response.json()
|
||||
}
|
||||
try {
|
||||
compose(['up', '-d', '--no-build', '--wait', '--wait-timeout', '60'])
|
||||
console.log('Docker-Container ist gesund.')
|
||||
await api('/login', 'POST', { email: process.env.ADMIN_EMAIL, password })
|
||||
const ticket = await api('/tickets', 'POST', {
|
||||
queue_id: 'support',
|
||||
customer: 'customer@example.invalid',
|
||||
customer_name: 'Persistenztest',
|
||||
subject: 'Docker-Persistenz',
|
||||
body: 'Container-Neustart prüfen',
|
||||
key: randomUUID(),
|
||||
})
|
||||
await api('/queues/support/signatures', 'PUT', {
|
||||
signatures: [
|
||||
{
|
||||
id: 'docker-signature',
|
||||
name: 'HTML',
|
||||
default: true,
|
||||
format: 'html',
|
||||
body: '<p><strong>Docker Support</strong><br><a href="https://example.org">Kontakt</a></p>',
|
||||
},
|
||||
],
|
||||
})
|
||||
const config = await api('/queues/support/mail')
|
||||
await api('/queues/support/mail', 'PUT', { ...config, password: 'test-fixture-secret' })
|
||||
await api(`/tickets/${ticket.id}/messages`, 'POST', {
|
||||
kind: 'outgoing',
|
||||
from: 'support@syncova.local',
|
||||
body: 'Anbei die Datei.',
|
||||
signature_id: 'docker-signature',
|
||||
key: randomUUID(),
|
||||
attachments: [
|
||||
{
|
||||
name: 'persistenz.txt',
|
||||
mime: 'text/plain',
|
||||
content: Buffer.from('PERSISTENT-BYTES').toString('base64'),
|
||||
},
|
||||
],
|
||||
})
|
||||
await api('/queues/service', 'DELETE', { confirm: 'Service' })
|
||||
const first = await api(`/tickets/${ticket.id}`)
|
||||
const attachment = first.messages.flatMap((m) => m.attachments)[0]
|
||||
compose(['up', '-d', '--force-recreate', '--no-build', '--wait', '--wait-timeout', '60'])
|
||||
console.log('Container wurde vollständig neu erstellt; dasselbe Volume wird verwendet.')
|
||||
const restored = await api(`/tickets/${ticket.id}`)
|
||||
assert(restored.messages.some((m) => m.html?.includes('<strong>Docker Support</strong>')))
|
||||
assert.equal(restored.messages.flatMap((m) => m.attachments)[0].id, attachment.id)
|
||||
const bytes = await fetch(base + '/api/attachments/' + attachment.id, { headers: { cookie } })
|
||||
assert.equal(bytes.status, 200)
|
||||
assert.equal(await bytes.text(), 'PERSISTENT-BYTES')
|
||||
const restoredConfig = await api('/queues/support/mail')
|
||||
assert.equal(restoredConfig.passwordSet, true)
|
||||
assert(!(await api('/bootstrap')).queues.some((q) => q.id === 'service'))
|
||||
assert((await api('/logs')).some((a) => a.action === 'Queue gelöscht'))
|
||||
compose([
|
||||
'exec',
|
||||
'-T',
|
||||
'syncova',
|
||||
'node',
|
||||
'--input-type=module',
|
||||
'-e',
|
||||
"import {openDb} from './server/db.js'; import {decryptSecret} from './server/secrets.js'; const db=openDb();if(!decryptSecret(db.prepare('SELECT password FROM queue_mail WHERE queue_id=?').get('support').password))throw Error('Missing key');db.close();",
|
||||
])
|
||||
console.log(
|
||||
'Persistenz erfolgreich geprüft: Tickets, Nachrichten, Anhänge, HTML-Signaturen, Mailkonfiguration, Schlüssel, Sitzungen und Audit-Historie.',
|
||||
)
|
||||
compose(['stop'])
|
||||
mkdirSync('data', { recursive: true })
|
||||
importSource = mkdtempSync(path.join(path.resolve('data'), 'docker-import-test-'))
|
||||
compose(['cp', 'syncova:/app/data/.', importSource])
|
||||
assert(existsSync(path.join(importSource, 'syncova.db')))
|
||||
compose(
|
||||
[
|
||||
'run',
|
||||
'--rm',
|
||||
'--no-deps',
|
||||
'--entrypoint',
|
||||
'node',
|
||||
'--volume',
|
||||
`${importSource}:/import:ro`,
|
||||
'syncova',
|
||||
'server/import-data.js',
|
||||
],
|
||||
importProject,
|
||||
)
|
||||
compose(['up', '-d', '--no-build', '--wait', '--wait-timeout', '60'], importProject)
|
||||
assert.equal(
|
||||
(await api(`/tickets/${ticket.id}`)).messages.flatMap((m) => m.attachments)[0].id,
|
||||
attachment.id,
|
||||
)
|
||||
const importedFile = await fetch(base + '/api/attachments/' + attachment.id, {
|
||||
headers: { cookie },
|
||||
})
|
||||
assert.equal(await importedFile.text(), 'PERSISTENT-BYTES')
|
||||
console.log(
|
||||
'Datenübernahme in ein neues Docker-Volume einschließlich Mail-Schlüssel erfolgreich geprüft.',
|
||||
)
|
||||
} finally {
|
||||
compose(['down', '--volumes', '--remove-orphans'], importProject)
|
||||
compose(['down', '--volumes', '--remove-orphans'])
|
||||
if (importSource) {
|
||||
const actual = realpathSync(importSource),
|
||||
root = realpathSync('data') + path.sep
|
||||
if (!actual.toLowerCase().startsWith(root.toLowerCase())) throw Error('Unerwarteter Testpfad')
|
||||
rmSync(actual, { recursive: true, force: true })
|
||||
}
|
||||
console.log('Isolierte Docker-Testumgebung entfernt.')
|
||||
}
|
||||
97
tests/image-smoke.mjs
Normal file
97
tests/image-smoke.mjs
Normal file
@ -0,0 +1,97 @@
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import { randomUUID } from 'node:crypto'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
const image = process.env.SYNCOVA_IMAGE || 'syncova-ticket:local'
|
||||
const name = `syncova-image-check-${randomUUID()}`
|
||||
const password = `Test-${randomUUID()}!`
|
||||
const env = { ...process.env, ADMIN_EMAIL: 'image-check@example.invalid', ADMIN_PASSWORD: password }
|
||||
function docker(args, required = true) {
|
||||
const result = spawnSync('docker', args, { encoding: 'utf8', timeout: 60000, env })
|
||||
if (required && result.status !== 0)
|
||||
throw Error(
|
||||
(result.stderr || result.error?.message || 'Docker fehlgeschlagen').replaceAll(
|
||||
password,
|
||||
'[redacted]',
|
||||
),
|
||||
)
|
||||
return result
|
||||
}
|
||||
const configuration = JSON.parse(docker(['image', 'inspect', image]).stdout)[0].Config
|
||||
assert.equal(configuration.User, 'node')
|
||||
assert(
|
||||
!configuration.Env.some((v) => /^(ADMIN_PASSWORD|REGISTRY_TOKEN|SMTP_ENCRYPTION_KEY)=.+/.test(v)),
|
||||
'Keine Zugangsdaten im Image',
|
||||
)
|
||||
docker([
|
||||
'run',
|
||||
'--rm',
|
||||
'--entrypoint',
|
||||
'node',
|
||||
image,
|
||||
'--input-type=module',
|
||||
'-e',
|
||||
`
|
||||
import assert from 'node:assert/strict'; import fs from 'node:fs';
|
||||
assert.deepEqual(fs.readdirSync('/app/data'), [], 'Image muss ein leeres Datenverzeichnis enthalten');
|
||||
for(const file of ['/app/.env','/app/.env.docker','/app/.git','/app/docs','/app/tests']) assert(!fs.existsSync(file),file+' darf nicht im Laufzeitimage liegen');
|
||||
`,
|
||||
])
|
||||
try {
|
||||
docker([
|
||||
'run',
|
||||
'--detach',
|
||||
'--name',
|
||||
name,
|
||||
'--read-only',
|
||||
'--tmpfs',
|
||||
'/app/data:rw,noexec,nosuid,uid=1000,gid=1000,mode=0700',
|
||||
'--tmpfs',
|
||||
'/tmp:rw,noexec,nosuid',
|
||||
'--env',
|
||||
'ADMIN_EMAIL',
|
||||
'--env',
|
||||
'ADMIN_PASSWORD',
|
||||
image,
|
||||
])
|
||||
let healthy = false
|
||||
for (let attempt = 0; attempt < 30; attempt++) {
|
||||
const result = docker(
|
||||
[
|
||||
'exec',
|
||||
name,
|
||||
'node',
|
||||
'-e',
|
||||
"fetch('http://127.0.0.1:3001/healthz').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))",
|
||||
],
|
||||
false,
|
||||
)
|
||||
if (result.status === 0) {
|
||||
healthy = true
|
||||
break
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 500))
|
||||
}
|
||||
assert(healthy, 'Produktionsimage muss starten und gesund werden')
|
||||
docker([
|
||||
'exec',
|
||||
name,
|
||||
'node',
|
||||
'--input-type=module',
|
||||
'-e',
|
||||
`
|
||||
import Database from 'better-sqlite3'; import assert from 'node:assert/strict';
|
||||
const db=new Database('/app/data/syncova.db',{readonly:true});
|
||||
for(const table of ['tickets','messages','attachments','notifications','outbox']) assert.equal(db.prepare('SELECT count(*) n FROM '+table).get().n,0,table+' muss leer sein');
|
||||
const users=db.prepare('SELECT email FROM users').all(); assert.equal(users.length,1); assert.equal(users[0].email,process.env.ADMIN_EMAIL);
|
||||
db.close();
|
||||
const login=await fetch('http://127.0.0.1:3001/api/login',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({email:process.env.ADMIN_EMAIL,password:process.env.ADMIN_PASSWORD})});
|
||||
assert.equal(login.status,200,'Bootstrap-Anmeldung muss funktionieren');
|
||||
`,
|
||||
])
|
||||
console.log(
|
||||
'Image geprüft: leeres Datenverzeichnis, keine lokalen Daten oder Zugangsdaten, frische Produktion ohne Demotickets/-benutzer, Bootstrap-Anmeldung erfolgreich.',
|
||||
)
|
||||
} finally {
|
||||
docker(['rm', '--force', name], false)
|
||||
}
|
||||
1478
tests/service.test.js
Normal file
1478
tests/service.test.js
Normal file
File diff suppressed because it is too large
Load Diff
16
tsconfig.json
Normal file
16
tsconfig.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"jsx": "react-jsx",
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"allowImportingTsExtensions": true,
|
||||
"noEmit": true,
|
||||
"baseUrl": ".",
|
||||
"paths": { "@/*": ["src/*"], "styled-system/*": ["styled-system/*"] }
|
||||
},
|
||||
"include": ["src", "panda.config.ts", "vite.config.ts"]
|
||||
}
|
||||
33
violet-registry.json
Normal file
33
violet-registry.json
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"$schema": "https://park-ui.com/schema/registry-item.json",
|
||||
"name": "violet",
|
||||
"type": "registry:color",
|
||||
"dependencies": ["@pandacss/dev"],
|
||||
"files": [
|
||||
{
|
||||
"content": "import { defineSemanticTokens } from '@pandacss/dev'\n\nexport const violet = defineSemanticTokens.colors({\n '1': { value: { _light: '#fdfcfe', _dark: '#14121f' } },\n '2': { value: { _light: '#faf8ff', _dark: '#1b1525' } },\n '3': { value: { _light: '#f4f0fe', _dark: '#291f43' } },\n '4': { value: { _light: '#ebe4ff', _dark: '#33255b' } },\n '5': { value: { _light: '#e1d9ff', _dark: '#3c2e69' } },\n '6': { value: { _light: '#d4cafe', _dark: '#473876' } },\n '7': { value: { _light: '#c2b5f5', _dark: '#56468b' } },\n '8': { value: { _light: '#aa99ec', _dark: '#6958ad' } },\n '9': { value: { _light: '#6e56cf', _dark: '#6e56cf' } },\n '10': { value: { _light: '#654dc4', _dark: '#7d66d9' } },\n '11': { value: { _light: '#6550b9', _dark: '#baa7ff' } },\n '12': { value: { _light: '#2f265f', _dark: '#e2ddfe' } },\n a1: { value: { _light: '#5500aa03', _dark: '#4422ff0f' } },\n a2: { value: { _light: '#4900ff07', _dark: '#853ff916' } },\n a3: { value: { _light: '#4400ee0f', _dark: '#8354fe36' } },\n a4: { value: { _light: '#4300ff1b', _dark: '#7d51fd50' } },\n a5: { value: { _light: '#3600ff26', _dark: '#845ffd5f' } },\n a6: { value: { _light: '#3100fb35', _dark: '#8f6cfd6d' } },\n a7: { value: { _light: '#2d01dd4a', _dark: '#9879ff83' } },\n a8: { value: { _light: '#2b00d066', _dark: '#977dfea8' } },\n a9: { value: { _light: '#2400b7a9', _dark: '#8668ffcc' } },\n a10: { value: { _light: '#2300abb2', _dark: '#9176fed7' } },\n a11: { value: { _light: '#1f0099af', _dark: '#baa7ff' } },\n a12: { value: { _light: '#0b0043d9', _dark: '#e3defffe' } },\n solid: {\n bg: {\n DEFAULT: { value: { _light: '{colors.violet.9}', _dark: '{colors.violet.9}' } },\n hover: { value: { _light: '{colors.violet.10}', _dark: '{colors.violet.10}' } },\n },\n fg: { DEFAULT: { value: { _light: 'white', _dark: 'white' } } },\n },\n subtle: {\n bg: {\n DEFAULT: { value: { _light: '{colors.violet.a3}', _dark: '{colors.violet.a3}' } },\n hover: { value: { _light: '{colors.violet.a4}', _dark: '{colors.violet.a4}' } },\n active: { value: { _light: '{colors.violet.a5}', _dark: '{colors.violet.a5}' } },\n },\n fg: { DEFAULT: { value: { _light: '{colors.violet.a11}', _dark: '{colors.violet.a11}' } } },\n },\n surface: {\n bg: {\n DEFAULT: { value: { _light: '{colors.violet.a2}', _dark: '{colors.violet.a2}' } },\n active: { value: { _light: '{colors.violet.a3}', _dark: '{colors.violet.a3}' } },\n },\n border: {\n DEFAULT: { value: { _light: '{colors.violet.a6}', _dark: '{colors.violet.a6}' } },\n hover: { value: { _light: '{colors.violet.a7}', _dark: '{colors.violet.a7}' } },\n },\n fg: { DEFAULT: { value: { _light: '{colors.violet.a11}', _dark: '{colors.violet.a11}' } } },\n },\n outline: {\n bg: {\n hover: { value: { _light: '{colors.violet.a2}', _dark: '{colors.violet.a2}' } },\n active: { value: { _light: '{colors.violet.a3}', _dark: '{colors.violet.a3}' } },\n },\n border: { DEFAULT: { value: { _light: '{colors.violet.a7}', _dark: '{colors.violet.a7}' } } },\n fg: { DEFAULT: { value: { _light: '{colors.violet.a11}', _dark: '{colors.violet.a11}' } } },\n },\n plain: {\n bg: {\n hover: { value: { _light: '{colors.violet.a3}', _dark: '{colors.violet.a3}' } },\n active: { value: { _light: '{colors.violet.a4}', _dark: '{colors.violet.a4}' } },\n },\n fg: { DEFAULT: { value: { _light: '{colors.violet.a11}', _dark: '{colors.violet.a11}' } } },\n },\n})\n",
|
||||
"type": "registry:color",
|
||||
"path": "colors/violet.ts"
|
||||
}
|
||||
],
|
||||
"panda": {
|
||||
"imports": [
|
||||
{
|
||||
"type": "registry:color",
|
||||
"name": "violet",
|
||||
"from": "colors/violet"
|
||||
}
|
||||
],
|
||||
"extension": {
|
||||
"theme": {
|
||||
"extend": {
|
||||
"semanticTokens": {
|
||||
"colors": {
|
||||
"violet": "$ref:violet"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
vite.config.ts
Normal file
8
vite.config.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import path from 'node:path'
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
resolve: { alias: { '@': path.resolve('src'), 'styled-system': path.resolve('styled-system') } },
|
||||
server: { proxy: { '/api': 'http://127.0.0.1:3001' } },
|
||||
})
|
||||
Loading…
Reference in New Issue
Block a user