5 Commits
Author SHA1 Message Date
Mateusz PstruchaandClaude Opus 5.5 0f497d88de Deploy tern-server on its own; accept hex keys; fix cross-origin auth
CI / test (push) Successful in 3m56s
The integrated stack is gone: deploy/compose.yml is just the server and
its Postgres, published on 11901 behind the existing nginx as
tern-api.mtps.pl, and this repo's release deploys it after pushing the
image. The webapp deploys separately from tern-web.

CREDENTIAL_KEY may now be 64 hex digits as well as base64, and a wrong
length says how to generate a right one. The database password reaches
the server as PGPASSWORD rather than inside DATABASE_URL, so it needs
no URL-escaping.

CORS now names Authorization and Content-Type instead of `*`: browsers
don't let the wildcard cover Authorization, so every signed-in request
from the webapp's own origin would have been refused. A route test
checks the preflight.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 12:44:22 +02:00
Mateusz PstruchaandClaude Opus 5.5 22c55854f3 Add the tern.mtps.pl deployment, a registration gate and a healthcheck
CI / test (push) Successful in 4m39s
deploy/tern.yml is the whole stack as one compose project for
ygg/actions/deploy (deploy/compose on kara): Postgres, the server at the
released version, ygg/static-server serving the matching tern-web
release, and an nginx proxy putting webapp and API (incl. /api/ws) on
one origin on port 11901, with sign-in rate-limited. Kara's nginx
fronts it as tern.mtps.pl. tern-web's release triggers the deploy.

Only the first user may now register unless OPEN_REGISTRATION=true,
so a public deployment isn't open sign-up; an advisory lock keeps two
racing first registrations from both succeeding.

`tern-server healthcheck` backs a Dockerfile HEALTHCHECK, so
`docker compose up --wait` waits for the server to serve — and fails a
deploy whose server can't start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 20:47:32 +02:00
Mateusz PstruchaandClaude Opus 5.5 b718bc4c3a Add UnifiedPush delivery, device API and sliding sessions
CI / test (push) Successful in 6m31s
New mail whose notify decision is true now wakes the user's registered
phones: a content-free {"kind":"sync"} payload, encrypted per RFC 8291
and VAPID-signed per RFC 8292 (key generated on first start, stored
encrypted with CREDENTIAL_KEY). Bursts coalesce into one push, and a
404/410 from the push server removes the device.

/api/devices registers, updates, lists and removes endpoints, and can
send a test push; GET /api/push returns the VAPID public key. For
self-hosted push servers, PUSH_URL_REWRITE maps the public endpoint
prefix to an internal one, and PUSH_CA_CERT / PUSH_TLS_INSECURE handle
private certificates.

Sessions now slide: each use extends expiry to the full TTL (at most
one write an hour), so a phone in regular use is never signed out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 19:46:33 +02:00
Mateusz PstruchaandClaude Opus 5.5 3f1d9227c6 Add trash retention, stop-after-match and run-now
CI / test (push) Successful in 46s
Mail in Trash is purged after TRASH_RETENTION_DAYS (default 30, 0
disables), hourly. Stored files are content-addressed and shared, so a
file is only removed once nothing references it — and not if written or
reused in the last hour, since ingest writes a file before inserting the
row that points at it. Reusing an existing blob now refreshes its mtime
so that grace period protects it too. Trash rows report when they purge.

"Stop processing further rules" moves from an action to a per-rule
option (stop_after_match): it's a property of the rule, not something
done to a message. Migration 0007 converts existing stop actions, and a
stop submitted as an action is now rejected.

Rules can be run now against existing mail outside Trash, disabled ones
included so a rule can be tried before it's switched on. It pages by
key, one transaction per page, and only re-reads stored raw messages
when the rule tests a header.

All JSON bodies now go through an AppJson extractor so malformed or
mistyped bodies return the API's {"error": …} shape. Axum's default was
a plain-text 422 the webapp could only show as "request failed: 422" —
losing the useful part, e.g. "unknown variant `stop`".

Verified live: the stop flag blocks a lower rule on arriving mail; run
now on a disabled header rule archived 2 of 4 messages; a purge removed
an expired message and its unique raw file while keeping an attachment
file still shared with a live copy, with no orphaned rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 12:00:04 +02:00
Mateusz PstruchaandClaude Opus 5 4c1a6457c5 Initial sync server: IMAP engine, schema, and read API
Covers phases 1-2 of the build order in the architecture spec: the IMAP
sync engine (IDLE + UIDVALIDITY tracking + jittered reconnect, headers
first with lazy body fetch), the full data model, and a minimal REST API
for auth, accounts, folders, messages and delta polling.

Credentials are encrypted at rest with ChaCha20-Poly1305 rather than
libsodium secretbox, to avoid a system dependency for the same
construction.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 19:00:59 +02:00