feat(api): maintenance operations with the operator's opt-in
Builds on #625 (and #623). Their commits come first here until they merge.
What
This runs only with the Ever Platform connection loaded (TR_EVER_CONNECT_ENABLED=true, still off by default) and connected. There is no new env switch: the operator's opt-in is stored in the database, and it is off by default.
An owner or admin of the organization requests an operation from app.ever.co. It arrives as ever.registry.managed_operation.requested on the feed. It runs only when all of these hold:
- the organization enabled
managed_operationsin app.ever.co (consent), andTR_EVER_CONNECT_INTEGRATIONS_DENYdoes not name it; - the operator opted in here (
PUT /api/v1/ever-connect/managed, operator only); - the operator allows that kind;
- now is inside one of the operator's weekly UTC windows (overnight windows supported).
Otherwise the answer is failed, the history records why (no_consent, no_operator_opt_in, kind_not_allowed, outside_window, ...), and nothing else happens. A TR_EVER_INSTALL_SOURCE=cloud installation takes none (operated_by_ever), and its routes answer 404.
| Kind | Here | Databases |
|---|---|---|
health_report | API up, database reachable | all |
backup | better-sqlite3 online backup plus a manifest (size, SHA-256) in the operator's backup directory | SQLite |
restore_check | the named (or newest) backup still matches its manifest | SQLite |
backup / restore_check on PostgreSQL or MySQL | refused, unsupported_dialect: the image ships no pg_dump/mysqldump, and a consistent dump needs them | n/a |
update | never run, update_not_supported: the API cannot replace its own container image from inside it | n/a |
- Requests go through the SDK
createManagedOperationRunner(event validation, expiry,not_before, dry run first). This module sends the result itself. A result Ever Platform could not receive is kept (unsent_result) and sent again: the feed page stays unacknowledged, and each scheduler round retries. A request with a later start time waits in the history and runs then. - Ever Platform receives
status,version, and a backup's opaque reference and size only. Never a path or a file name (tested). - The backup directory is write-only: stored AES-256-GCM encrypted under
TR_SECRET, and the view shows onlybackupDirSet. - History: the last 50 operations. Audit rows:
managed.opt_in/opt_out/policy/refused/result. - New tables
ever_connect_managed_policyandever_connect_managed_operation. They share one renderer for postgres/mysql/sqlite with the person tables of #625 (utils/ever-platform-tables.ts). managed_operationsis now listed with Traduora's integrations (it showscoming_soonuntil the platform offers it).
Not in this PR: a web app panel for the opt-in. The operator uses the API for now; it is documented in docs/ever-platform/connection.md#maintenance-operations.
Tests
ever-connect-managed.service.spec.ts(8 tests, real migrations on in-memory SQLite) covers:- windows, including overnight
- refusals without consent, without opt-in, outside a window, for a kind not allowed, and for
update(no file written, every resultfailed) - backup, then restore check, then a damaged backup fails the check
- the result carries only status, size and reference, and no path
- a repeated delivery changes nothing
- deferred until its start time
- an unsent result is kept and resent
- settings validation; the directory is write-only; the cloud install gets 404
- a consent and a request in the same feed page
ever-connect-managed.e2e-spec.tsis dialect-aware: SQLite backs up for real, PostgreSQL/MySQL refuseunsupported_dialect. It also covers operator-only routes, refusal before opt-in, and the audit.ever-connect-off.e2e-spec.ts:/ever-connect/manageddoes not exist with the module off.- Run locally on SQLite: all
test/ever-connect*e2e suites andsrc/ever-connectunit suites green; tslint and prettier clean. The three-databasecimatrix will run in-cluster.
🤖 Generated with Claude Code
Summary by cubic
Adds maintenance operations to the Ever Platform connection (loaded with TR_EVER_CONNECT_ENABLED=true, still off by default). An organization owner or admin can request a health report, SQLite backup, or backup check from app.ever.co.
Each runs only with the organization's consent (managed_operations), the operator's opt-in for that kind (PUT /api/v1/ever-connect/managed, off by default), and inside the operator's weekly UTC windows; otherwise it fails with the reason recorded (no_consent, no_operator_opt_in, kind_not_allowed, outside_window). The dialect comes from the API's own TypeORM connection. PostgreSQL/MySQL backups are refused (unsupported_dialect) and update is never run. Ever Platform receives only status, version, and size — never a path or a filename — and backups are stored encrypted under TR_SECRET.
Deferred requests wait for their start time and check consent, opt-in, and window only when they start; each run is claimed, so a second API process never runs the same backup. The outcome is stored before the result is audited or sent, so an interrupted process never leaves a finished backup "running" or loses a result. Unsent results are retried without holding back due work, and due work waits while a feed page's state refresh failed (a revoked consent may not be applied yet). An ended connection cancels its deferred work and unsent results; operation entries record the connection that received them, so work is never run through the next connection.
Person export and deletion requests are answered for accounts linked to the person's Ever ID: encrypted exports downloadable by that account for 7 days, or deletion that unlinks the Ever ID and ends its sessions. Person links are reported with ids only. Each request's answer is decided once and kept 90 days, so a repeated request gets the same answer.
Also in this diff
- A failed backup removes the files it created; the backup directory and file are created owner-only before any data goes into it (the dry run verifies the directory too), and backups are hashed as a stream.
- Anonymous usage statistics now default to on;
TR_EVER_STATS_ENABLED=falseturns them off entirely. Tests and CI set it off so no run telephones an Ever Platform host. - The new tables and the person tables share one renderer that writes the SQL per database (PostgreSQL booleans, in particular).